4 Replies Latest reply on Feb 13, 2006 8:26 AM by adrian.brock

    Allow bean instance to be created by custom schema

    starksm64

      Consider creating a bean using a custom schema. Right now this requires a wrapper bean:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
       xmlns="urn:jboss:bean-deployer">
       <bean name="jboss.xb:service=SchemaResolverConfig"
       class="org.jboss.util.xml.SchemaResolverConfig">
      
       <!-- The locations (path name on the "classpath") -->
       <property name="schemaLocations">
       urn:urn:jboss:mbean-service=legacy-mbean-service_1_0.xsd
       </property>
       </bean>
      
       <bean name="MBeanServices"
       class="org.jboss.test.kernel.config.support.mbeanserver.ServicesWrapper">
       <property name="services">
       <mbean:server
       xmlns:mbean="urn:jboss:mbean-service">
       <mbean:mbean code="org.jboss.test.kernel.config.support.mbeanserver.SomeBean"
       name="jboss.security.tests:service=SomeBean">
      
       <mbean:attribute name="UserHome" replace="true">
       ${user.home}
       </mbean:attribute>
       <mbean:depends optional-attribute-name="LoginConfigService">
       jboss.security:service=XMLLoginConfig
       </mbean:depends>
       <mbean:depends optional-attribute-name="SecurityManagerService">
       jboss.security:service=JaasSecurityManager
       </mbean:depends>
       </mbean:mbean>
       </mbean:server>
       </property>
       </bean>
      </deployment>
      
      


      what I would like to be able to do is create the bean instance via a constructor element whose content is the custom schema doc fragment that creates a fully initialized instance:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
       xmlns="urn:jboss:bean-deployer">
       <bean name="jboss.xb:service=SchemaResolverConfig"
       class="org.jboss.util.xml.SchemaResolverConfig">
      
       <!-- The locations (path name on the "classpath") -->
       <property name="schemaLocations">
       urn:urn:jboss:mbean-service=legacy-mbean-service_1_0.xsd
       </property>
       </bean>
      
       <bean name="MBeanServices"
       class="org.jboss.test.kernel.config.support.mbeanserver.Services">
       <constructor>
       <mbean:server
       xmlns:mbean="urn:jboss:mbean-service">
       <mbean:mbean code="org.jboss.test.kernel.config.support.mbeanserver.SomeBean"
       name="jboss.security.tests:service=SomeBean">
      
       <mbean:attribute name="UserHome" replace="true">
       ${user.home}
       </mbean:attribute>
       <mbean:depends optional-attribute-name="LoginConfigService">
       jboss.security:service=XMLLoginConfig
       </mbean:depends>
       <mbean:depends optional-attribute-name="SecurityManagerService">
       jboss.security:service=JaasSecurityManager
       </mbean:depends>
       </mbean:mbean>
       </mbean:server>
       </constructor>
       </bean>
      </deployment>
      




        • 1. Re: Allow bean instance to be created by custom schema
          • 2. Re: Allow bean instance to be created by custom schema

            I did anticpate this when I decided the factory should have its own element,
            but I didn't have any reason to implement it (other than convienance - less xml).

            Factory wilcard

            <constructor>
             <factory>
             <other/>
            ...
            


            In practice, this
            <mbean:depends optional-attribute-name="LoginConfigService">
            


            Shows that it is not a POJO and it needs to be "dissected" to determine its state actions/dependencies.

            • 3. Re: Allow bean instance to be created by custom schema

              Incidently, you know you can write this more succintly by changing the default namespace?

               <constructor>
               <server xmlns="urn:jboss:mbean-service"> <!-- DEFAULT NAMESPACE CHANGE -->
               <mbean code="org.jboss.test.kernel.config.support.mbeanserver.SomeBean"
               name="jboss.security.tests:service=SomeBean">
              
               <attribute name="UserHome" replace="true">
               ${user.home}
               </attribute>
               <depends optional-attribute-name="LoginConfigService">
               jboss.security:service=XMLLoginConfig
               </depends>
               <depends optional-attribute-name="SecurityManagerService">
               jboss.security:service=JaasSecurityManager
               </depends>
               </mbean>
               </server>
               </constructor>
              


              I assume you don't need to access the bean-deployer elements in the mbean elements.

              • 4. Re: Allow bean instance to be created by custom schema

                This has been added.

                I see you started to commit a testcase (you created the directory).
                I've added some simpler testcases. The supported elements can be seen in the .xsd
                basically you can't do:
                inject - would create an alias (duplicate lifecycle invocation)
                null - doesn't make sense
                this - impossible :-)