[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-user
Subject:    XMLBeans with Derived ComplexTypes
From:       shyenuganti <shyenuganti () gmail ! com>
Date:       2010-03-08 20:54:02
Message-ID: 27827393.post () talk ! nabble ! com
[Download RAW message or body]


Hi,

I have a schema which takes a list of "Record" types. Each 'Record' is
complex type of SenderDetails, Recipientdetails, shipdate, description and
Ref elements. The main.xsd is as follows:

---------------------------------------------------------------------------------------------
  <xs:element name="records">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="record" maxOccurs="unbounded">
			   <xs:complexType>
					<xs:sequence>
					<xs:element name="SenderDetail" type="cmn:AddressType" />
					<xs:element name="Shipdate" type="xs:string"/>
					<xs:element name="RecipientDetail" type="cmn:AddressType" />
					<xs:element name="Description" type="xs:string"/>
					<xs:element name="Ref" type="xs:string"/>
					</xs:sequence>
				</xs:complexType>
		</xs:element>
     </xs:sequence>
    </xs:complexType>
      

</xs:element>

</xs:schema>	

-------------------------------------------------------------------------------------------------


Now, the SenderDetail and the RecipientDetail may be of type 'Employee' or
'Department'. Employee and Department are both derived from 'AddressType' as
shown.

---------------------------------------------------------
 <xs:complexType name="Department">
	   <xs:complexContent> 
			<xs:extension base="cmn:AddressType"> 
				<xs:sequence>
					<xs:element name="Name" type="xs:string" />
					<xs:element name="keyvalues" type="cmn:Valuelist"/>
				</xs:sequence>
			</xs:extension> 
		</xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="Employee">
    <xs:complexContent> 
		<xs:extension base="cmn:AddressType"> 
			<xs:sequence>
				<xs:element name="Name" type="xs:string" />
				<xs:element name="Title" type="xs:string" />
				<xs:element name="Empid" type="xs:string"/>
			</xs:sequence>
		</xs:extension> 
	</xs:complexContent>
  </xs:complexType>
  
---------------------------------------------------------

After mapping the schema to java objects, here I am using the following code
to check whether the 'SenderDetail' in the incoming xml is of type
'Employee' or 'Department'. 

'records[]' is the array of records already extracted from incoming xml.

Here the output of "System.out.println( records[i].getSenderDetail() ); "

Output:

<xml-fragment xsi:type="o:Employee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:p="SomeX/Records" 
xmlns:o="SomeX/Stakeholder" 
xmlns:c="SomeX/CommonTypes">

  <c:street1>456 Oak Lane</c:street1>
  <c:street2>Second floor bld I</c:street2>
  <c:city>xxx</c:city>
  <c:state>xxx</c:state>
  <c:country>US</c:country>
  <c:zipcode>xxx</c:zipcode>
  <c:phone>xxx</c:phone>
  <c:comail>xxx</c:comail>
  <o:Name>xxx</o:Name>
  <o:Title>xxx</o:Title>
  <o:Empid>xxx</o:Empid>
</xml-fragment>

Now I am expecting the output of the following code 

---------------------------------
AddressType p = records[i].getSenderDetail();

if (p instanceof Employee){
	System.out.println("Sender is of type Employee");
}else if (p instanceof AddressType){
	System.out.println("Sender is of type AddressType");
}
---------------------------------

to be "Sender is of type Employee"

But I am getting "Sender is of type AddressType"

records[i].getSenderDetail().schemaType() on this record is giving me the
base schema type "AddressType"

How can I get the derived schema type ? How can i know whether this is a
Employee/Department type?

Thank You.

 

-- 
View this message in context: \
http://old.nabble.com/XMLBeans-with-Derived-ComplexTypes-tp27827393p27827393.html \
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic