9 Replies Latest reply on Apr 30, 2008 11:24 AM by aloubyansky

    Mixing wildcards and elements

    kabirkhan

      Alex,

      Can you please take a quick look at the XmlLoadableAopTestCase in the aop-mc-int project?

      Basically we have

      @JBossXmlSchema(namespace="urn:jboss:aop-beans:1.0", elementFormDefault=XmlNsForm.QUALIFIED)
      @XmlRootElement(name="aspect")
      public class AspectBeanMetaDataFactory extends AspectManagerAwareBeanMetaDataFactory
       implements BeanMetaDataFactory
      {
       ...
       private List<Element> elements;
      
      
       public List<Element> getElements()
       {
       return elements;
       }
      
       @XmlAnyElement(lax=true)
       public void setElements(List<Element> elements)
       {
       this.elements = elements;
       }
      
       @Override
       public List<BeanMetaData> getBeans()
       {
       ArrayList<BeanMetaData> result = new ArrayList<BeanMetaData>();
       this.name = super.getBean();
       }
      
      }
      
      @XmlRootElement(name="beanfactory")
      @XmlType(name="beanfactoryType", propOrder={"aliases", "annotations", "classLoader", "constructor", "properties", "create", "start", "depends", "demands", "supplies", "installs", "uninstalls", "installCallbacks", "uninstallCallbacks"})
      public class GenericBeanFactoryMetaData extends JBossObject implements BeanMetaDataFactory, Serializable
      {
       ...
       protected Set<PropertyMetaData> properties;
      
       public Set<PropertyMetaData> getProperties()
       {
       return properties;
       }
      
       @XmlElement(name="property", type=AbstractPropertyMetaData.class)
       public void setProperties(Set<PropertyMetaData> properties)
       {
       this.properties = properties;
       }
      
       public List<BeanMetaData> getBeans()
       {
       ...
       if (properties != null && properties.size() > 0)
       {
       PropertyMap propertyMap = new PropertyMap();
       for (PropertyMetaData property : properties) //CCE as explained below
       {
       propertyMap.put(property.getName(), property.getValue());
       }
       builder.addPropertyMetaData("properties", propertyMap);
       }
       ...
       }
      }
      


      In XmlLoadableAopTestCase.xml I have the following defined:
       <aspect class="org.jboss.test.microcontainer.beans.XmlLoadableAspect">
       <somexml>hello</somexml>
       <attribute name="IntAttr">12</attribute>
       <!-- <property name="property">Test1</property> -->
       </aspect>
      


      "attribute" and "somexml" are wildcards, while "property" is declared on GBFMD. As it is the test is fine. If I remove somexml and attribute, and uncomment property it also parses fine. If I enable all three elements, I get a CCE at the point shown in GBFMD.getBEans(), since the properties map now contains one element of type org.apache.xerces.dom.ElementNSImpl instead of PropertyMetaData. I tried to reproduce this in the jbossxb project, but it worked as expected there, so I have probably missed some minor detail?





        • 1. Re: Mixing wildcards and elements
          aloubyansky

          I can't build the project. There are classes missing, e.g. XmlLoadableRootElementUtil.

          • 2. Re: Mixing wildcards and elements
            kabirkhan

            Sorry, they should be there now

            • 3. Re: Mixing wildcards and elements
              aloubyansky

              When you run the test do you see an error coming from XB? I see a huge stacktrace with NoClassDefFoundError and warn:

              "log" wrote:
              2974 WARN [BeanAnnotationAdapterFactory] Exception while creating bean annotation adapter instance: java.lang.IllegalAccessException: Class org.jboss.reflect.plugins.introspection.ReflectionUtils can not access a member of class org.jboss.kernel.plugins.annotations.BasicBeanAnnotationAdapter with modifiers "protected"


              • 4. Re: Mixing wildcards and elements
                kabirkhan

                I do not see this when running from within Eclipse. All I see in the console is:

                0 DEBUG [XmlLoadableTest] ==== setUp org.jboss.test.microcontainer.beans.test.XmlLoadableTest ====
                453 DEBUG [KernelFactory] Starting JBoss Kernel construction...
                2766 DEBUG [KernelFactory] Completed JBoss Kernel construction. Duration: 2313 milliseconds
                3312 DEBUG [XmlLoadableTest] No test specific deployment org/jboss/test/microcontainer/beans/test/XmlLoadableTest-aop.xml
                3312 DEBUG [XmlLoadableTest] Deploying file:/C:/cygwin/home/Kabir/sourcecontrol/microcontainer/aop-mc-int/target/tests-classes/org/jboss/tes
                t/microcontainer/beans/test/XmlLoadableTest.xml
                3672 DEBUG [SaxJBossXBParser] Created parser: org.apache.xerces.jaxp.SAXParserImpl@d3db51, isNamespaceAware: true, isValidating: true, isXIn
                cludeAware: true
                3672 DEBUG [SaxJBossXBParser] http://xml.org/sax/features/validation set to: true
                3672 DEBUG [SaxJBossXBParser] http://xml.org/sax/features/namespaces set to: true
                3672 DEBUG [SaxJBossXBParser] http://apache.org/xml/features/validation/dynamic set to: true
                3703 DEBUG [SaxJBossXBParser] Created parser: org.apache.xerces.jaxp.SAXParserImpl@d3db51, isNamespaceAware: true, isValidating: true, isXIn
                cludeAware: true
                11719 DEBUG [XmlLoadableTest] ==== tornDown org.jboss.test.microcontainer.beans.test.XmlLoadableTest ====
                11797 DEBUG [XmlLoadableTest] ==== Starting testAspectInterceptorAndDynamicCFlow ====
                11812 DEBUG [XmlLoadableTest] testAspectInterceptorAndDynamicCFlow took 15ms
                11812 DEBUG [XmlLoadableTest] ==== Stopping testAspectInterceptorAndDynamicCFlow ====
                


                And for the test
                java.lang.ClassCastException: org.apache.xerces.dom.ElementNSImpl
                 at org.jboss.beans.metadata.spi.factory.GenericBeanFactoryMetaData.getBeans(GenericBeanFactoryMetaData.java:609)
                 at org.jboss.aop.microcontainer.beans.metadata.AspectBeanMetaDataFactory.getBeans(AspectBeanMetaDataFactory.java:134)
                 at org.jboss.kernel.plugins.deployment.AbstractKernelDeployment.getBeans(AbstractKernelDeployment.java:229)
                 at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:304)
                 at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:130)
                 at org.jboss.kernel.plugins.deployment.BasicKernelDeployer.deploy(BasicKernelDeployer.java:76)
                 at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:88)
                 at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:158)
                 at org.jboss.test.kernel.junit.MicrocontainerTestDelegate.deploy(MicrocontainerTestDelegate.java:294)
                 at org.jboss.test.kernel.junit.MicrocontainerTestDelegate.deploy(MicrocontainerTestDelegate.java:438)
                 at org.jboss.test.aop.junit.AOPMicrocontainerTestDelegate.deploy(AOPMicrocontainerTestDelegate.java:74)
                 at org.jboss.test.kernel.junit.MicrocontainerTestDelegate.setUp(MicrocontainerTestDelegate.java:83)
                 at org.jboss.test.aop.junit.AOPMicrocontainerTestDelegate.setUp(AOPMicrocontainerTestDelegate.java:58)
                 at org.jboss.test.AbstractTestSetup.setUp(AbstractTestSetup.java:63)
                 at org.jboss.test.AbstractTestCaseWithSetup.setUp(AbstractTestCaseWithSetup.java:103)
                 at org.jboss.test.kernel.junit.MicrocontainerTest.setUp(MicrocontainerTest.java:82)
                 at junit.framework.TestCase.runBare(TestCase.java:132)
                 at junit.framework.TestResult$1.protect(TestResult.java:110)
                 at junit.framework.TestResult.runProtected(TestResult.java:128)
                 at junit.framework.TestResult.run(TestResult.java:113)
                 at junit.framework.TestCase.run(TestCase.java:124)
                 at junit.framework.TestSuite.runTest(TestSuite.java:232)
                 at junit.framework.TestSuite.run(TestSuite.java:227)
                 at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
                 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
                 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
                 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
                



                • 5. Re: Mixing wildcards and elements
                  aloubyansky

                  Once again, which test are you running?
                  I just refreshed my microcontainer. The XmlLoadableAopTestCase passed. And the XmlLoadableTest has one error
                  "java.lang.IllegalStateException: Bean not found Bean at state ControllerState@87a5cc{Installed}" and

                  junit.framework.AssertionFailedError: expected:<1> but was:<0>
                   at junit.framework.Assert.fail(Assert.java:47)
                   at junit.framework.Assert.failNotEquals(Assert.java:277)
                   at junit.framework.Assert.assertEquals(Assert.java:64)
                   at junit.framework.Assert.assertEquals(Assert.java:195)
                   at junit.framework.Assert.assertEquals(Assert.java:201)
                   at org.jboss.test.microcontainer.beans.test.XmlLoadableTest.testClassMetaDataLoader(XmlLoadableTest.java:56)


                  But I don't see the XB error.

                  • 6. Re: Mixing wildcards and elements
                    kabirkhan

                    XmlLoadableAopTestCase, I get the XB error if I change XmlLoadableAopTestCase.xml from

                     <aspect class="org.jboss.test.microcontainer.beans.XmlLoadableAspect">
                     <somexml>hello</somexml>
                     <attribute name="IntAttr">12</attribute>
                     <!-- <property name="property">Test1</property> -->
                     </aspect>
                    


                    to

                     <aspect class="org.jboss.test.microcontainer.beans.XmlLoadableAspect">
                     <somexml>hello</somexml>
                     <attribute name="IntAttr">12</attribute>
                     <property name="property">Test1</property>
                     </aspect>
                    



                    • 7. Re: Mixing wildcards and elements
                      aloubyansky

                      If you try

                      <aspect class="org.jboss.test.microcontainer.beans.XmlLoadableAspect">
                       <property name="property">Test1</property>
                       <somexml>hello</somexml>
                       <attribute name="IntAttr">12</attribute>
                       </aspect>


                      It'll pass. The reason is the order of particles in the sequence. property is preceding the wildcard. So, in your case, when somexml is encountered before the property, the cursor in sequence moves to the repeated wildcard. And everything after the somexml is considered to be a wildcard content.

                      • 8. Re: Mixing wildcards and elements
                        kabirkhan

                        Aha!

                        Is there any way to avoid this ordering? If not, I guess I could document this.

                        • 9. Re: Mixing wildcards and elements
                          aloubyansky

                          No, the wildcard property is added the last in the sequence.