4 Replies Latest reply on Mar 2, 2006 9:58 AM by bkeh12

    demandType Schema wondering

    bkeh12

       


      <xsd:complexType name="beanType">
      <xsd:annotation>
      <xsd:documentation>
      [CDATA[
      The bean is an instance of a pojo.
      e.g.
      <bean name="MyName" class="com.acme.POJO">
      <classloader .../>
      <constructor .../>
      <property .../>
      <property .../>
      <depends .../>
      </bean>
      ]]
      </xsd:documentation>
      </xsd:annotation>
      <xsd:sequence>
      <xsd:element name="annotation" type="annotationType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="classloader" type="classloaderType" minOccurs="0"/>
      <xsd:element name="constructor" type="constructorType" minOccurs="0"/>
      <xsd:element name="property" type="propertyType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="create" type="lifecycleType" minOccurs="0"/>
      <xsd:element name="start" type="lifecycleType" minOccurs="0"/>
      <xsd:element name="stop" type="lifecycleType" minOccurs="0"/>
      <xsd:element name="destroy" type="lifecycleType" minOccurs="0"/>
      <xsd:element name="depends" type="dependsType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="demand" type="demandType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="supply" type="supplyType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="install" type="installType" minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="uninstall" type="installType" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
      <xsd:attribute name="name" type="xsd:string" use="optional"/>
      <xsd:attribute name="class" type="xsd:token" use="required"/>
      <xsd:attribute name="mode" type="controllerModeType" use="optional"/>
      </xsd:complexType>

      <xsd:complexType name="demandType">
      <xsd:annotation>
      <xsd:documentation>
      [CDATA[
      The demand is used to specify a dependency on a supply
      and when the demand is should be deplied
      e.g.:
      ISupply must be installed before IDemand is constructed
      <bean name="IDemand" ...whenRequired="Instantiated">
      <,demand >theSupply<,/demand>
      </bean>
      <bean name="ISupply" ...>
      <,supply>theSupply<,/supply>
      </bean>
      ]]
      </xsd:documentation>
      </xsd:annotation>
      <xsd:simpleContent>
      <xsd:extension base="xsd:string">
      <xsd:attribute name="whenRequired" type="controllerStateType" use="optional"/>
      </xsd:extension>
      </xsd:simpleContent>
      </xsd:complexType>

      is it update as below?

      e.g.:
      ISupply must be installed before IDemand is constructed
      <bean name="IDemand" ...
      <,demand whenRequired="Instantiated">>theSupply<,/demand>
      </bean>
      <bean name="ISupply" ...>
      <,supply>theSupply<,/supply>
      </bean>
      ]]

      I try to work two samples,resoult as same.

      
      sample1:
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
       xmlns="urn:jboss:bean-deployer:2.0">
       <bean name="Integer" class="org.jboss.example.microcontainer.constructor.ConstructorBean" whenRequired="Instantiated">
       <constructor>
       <parameter class="int">4</parameter>
       </constructor>
       <demand >HAPPY</demand>
       </bean>
       <bean name="StringLong" class="org.jboss.example.microcontainer.constructor.ConstructorBean" >
       <constructor>
       <parameter>a string</parameter>
       <parameter class="long">10</parameter>
       </constructor>
       <supply>HAPPY</supply>
       </bean>
      </deployment>
      
      sample2:
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_2_0.xsd"
       xmlns="urn:jboss:bean-deployer:2.0">
       <bean name="Integer" class="org.jboss.example.microcontainer.constructor.ConstructorBean" >
       <constructor>
       <parameter class="int">4</parameter>
       </constructor>
       <demand whenRequired="Instantiated" >HAPPY</demand>
       </bean>
       <bean name="StringLong" class="org.jboss.example.microcontainer.constructor.ConstructorBean" >
       <constructor>
       <parameter>a string</parameter>
       <parameter class="long">10</parameter>
       </constructor>
       <supply>HAPPY</supply>
       </bean>
      </deployment>
      


      Visit node AbstractDemandMetaData@5e176f{demand=HAPPY whenRequiredDescribed}
      Dependencies for Integer: [AbstractDemandMetaData$DemandDependencyItem@c9131c{name=Integer dependsOn=null whenRequired=Described resolved=false demand=HAPPY}]
      Still unresolved Described:....
      Installing name=StringLong..
      .....
      StringLong Installed
      Dependencies resolved Integer for Described
      .....
      Integer Installed
      .....


      Is Visit node AbstractDemandMetaData@5e176f{demand=HAPPY whenRequiredDescribed} correct ?
      Or is Visit node AbstractDemandMetaData@5e176f{demand=HAPPY whenRequiredInstantiated}.



        • 1. Re:  demandType Schema wondering

           

           e.g.:
           ISupply must be installed before IDemand is constructed
           <bean name="IDemand" ...
           <demand whenRequired="Instantiated">theSupply</demand>
           </bean>
          


          The xsd is wrong.

           public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
           {
           AbstractDemandMetaData demand = (AbstractDemandMetaData) o;
           for (int i = 0; i < attrs.getLength(); ++i)
           {
           String localName = attrs.getLocalName(i);
           if ("state".equals(localName))
           demand.setWhenRequired(new ControllerState(attrs.getValue(i)));
           }
           }
          


          So it should be:

           e.g.:
           ISupply must be installed before IDemand is constructed
           <bean name="IDemand" ...
           <demand state="Instantiated">theSupply</demand>
           </bean>
          



          • 2. Re:  demandType Schema wondering
            • 3. Re:  demandType Schema wondering
              bkeh12

              Thank you for telling me :-)
              So do this:

               TypeBinding beanType = schemaBinding.getType(beanTypeQName);
              
               /*
               ClassMetaData classMetaData = new ClassMetaData();
               classMetaData.setImpl(AbstractBeanMetaData.class.getName());
               beanType.setClassMetaData(classMetaData);
              
               QName CLASS = new QName("class");
               AttributeBinding attribute = beanType.getAttribute(CLASS);
               PropertyMetaData propertyMetaData = new PropertyMetaData();
               propertyMetaData.setName("bean");
               attribute.setPropertyMetaData(propertyMetaData);
              
               QName MODE = new QName("mode");
               attribute = beanType.getAttribute(MODE);
               ValueAdapter modeAdapter = new ValueAdapter()
               {
               public Object cast(Object o, Class c)
               {
               String string = (String) o;
               return new ControllerMode(string);
               }
               };
               attribute.setValueAdapter(modeAdapter);
               */
               beanType.setHandler(new DefaultElementHandler()
               {
              
               public Object startElement(Object parent, QName name, ElementBinding element)
               {
               return new AbstractBeanMetaData();
               }
              
               public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
               {
               AbstractBeanMetaData bean = (AbstractBeanMetaData) o;
               for (int i = 0; i < attrs.getLength(); ++i)
               {
               String localName = attrs.getLocalName(i);
               if ("name".equals(localName))
               bean.setName(attrs.getValue(i));
               else if ("class".equals(localName))
               bean.setBean(attrs.getValue(i));
               else if ("mode".equals(localName))
               bean.setMode(new ControllerMode(attrs.getValue(i)));
               else if ("whenRequired".equals(localName))
               bean.set........
               }
               }
               });
              
               <xsd:complexType name="beanType">
               <xsd:annotation>
               <xsd:documentation>
               [CDATA[
               The bean is an instance of a pojo.
              
               e.g.
               <bean name="MyName" class="com.acme.POJO">
               <classloader .../>
               <constructor .../>
               <property .../>
               <property .../>
               <depends .../>
               </bean>
               ]]
               </xsd:documentation>
               </xsd:annotation>
               <xsd:sequence>
               <xsd:element name="annotation" type="annotationType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="classloader" type="classloaderType" minOccurs="0"/>
               <xsd:element name="constructor" type="constructorType" minOccurs="0"/>
               <xsd:element name="property" type="propertyType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="create" type="lifecycleType" minOccurs="0"/>
               <xsd:element name="start" type="lifecycleType" minOccurs="0"/>
               <xsd:element name="stop" type="lifecycleType" minOccurs="0"/>
               <xsd:element name="destroy" type="lifecycleType" minOccurs="0"/>
               <xsd:element name="depends" type="dependsType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="demand" type="demandType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="supply" type="supplyType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="install" type="installType" minOccurs="0" maxOccurs="unbounded"/>
               <xsd:element name="uninstall" type="installType" minOccurs="0" maxOccurs="unbounded"/>
               </xsd:sequence>
               <xsd:attribute name="name" type="xsd:string" use="optional"/>
               <xsd:attribute name="class" type="xsd:token" use="required"/>
               <xsd:attribute name="mode" type="controllerModeType" use="optional"/>
               <xsd:attribute name="WhenRequired" type="controllerStateType" use="optional"/>
               </xsd:complexType>
              


              Or do this
               public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx)
               {
               AbstractDemandMetaData demand = (AbstractDemandMetaData) o;
               for (int i = 0; i < attrs.getLength(); ++i)
               {
               String localName = attrs.getLocalName(i);
               if ("whenRequired".equals(localName))
               demand.setWhenRequired(new ControllerState(attrs.getValue(i)));
               }
               }
              



              • 4. Re:  demandType Schema wondering
                bkeh12

                Hi,

                I see Bug report

                thank for your help....:-)