You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by kujunguo kujunguo <ku...@gmail.com> on 2008/12/17 07:51:35 UTC

Should I define a java class for complextype property?

My composite likes:
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://assembly-tests"
	name="Assemby-component--Composite">

	<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.com/Customer"
targetNamespace="http://www.example.com/Customer">

    <xsd:element name="customer" type="Customer"/>
    <xsd:complexType name="Customer">
        <xsd:sequence>
            <xsd:element name="firstName"  type="xsd:string"/>
            <xsd:element name="middleName" type="xsd:string"/>
            <xsd:element name="lastName"   type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
   </xsd:schema>

    <component name="CComponent">
	    <implementation.java
class="org.apache.tuscany.sca.vtest.assembly.component.property.ServiceCImpl"/>
	    <property name="customerInfo" xsi:type="Customer">
	
		    <firstName>Ku</firstName>
		    <middleName>Jun</middleName>
		    <lastName>Guo</lastName>
	
	    </property>	
	
     </component>

</composite>

So I have to define a Customer class if I want to use it in my
implementation as following:
...
@Property Customer customer;
...

is it a valid scenario for complextype property?

Re: Should I define a java class for complextype property?

Posted by Scott Kurz <sc...@gmail.com>.
You have the right idea but I think your SCDL syntax is a bit off.

Instead of:

         <property name="customerInfo" xsi:type="Customer">
                   <firstName>Ku</firstName>
                   <middleName>Jun</middleName>
                   <lastName>Guo</lastName>
           </property>

you could write:

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:cust="http://www.example.com/Customer"
       targetNamespace="http://assembly-tests"
       name="Assemby-component--Composite">

         <property name="customerInfo" element="cust:customer">
             <cust:customer>
                   <firstName>Ku</firstName>
                   <middleName>Jun</middleName>
                   <lastName>Guo</lastName>
             </cust:customer>
         </property>


Note how the <property> element contains an element of type Customer in this
rework, rather than
merely the contents of a Customer-type element like it did in your example.

There are some other variants, but the <property> element I think would only
take 'element' or 'type' attributes, (not 'xsi:type').  Though 'xsi:type'
could be helpful when using an undefined element of type Customer rather
than a global element like the <cust:customer> one you defined in your
schema.

The itest/properties test shows some more valid variations (though mostly
using SDO rather than JAXB .. though the
SCDL should be basically the same).

And yes, having written the SCDL correctly, you would in your implementation
use this property like (note the field name change):

@Property protected Customer customerInfo;  // Customer is generated from
your schema def and '
                                                                   //  and
'customerInfo' matches the property name

And you also need to package all the generated JAXB classes corresponding to
your original schema definitions (elem/types) along with your application in
order for the runtime JAXBContext to be aware of these schema definitions.

Hope that helps,
Scott