Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [TEXO] ModelXMLLoader mapping
[TEXO] ModelXMLLoader mapping [message #957693] Thu, 25 October 2012 08:17 Go to next message
Gary Godfrey is currently offline Gary Godfrey
Messages: 31
Registered: February 2012
Member
Hi,

I am getting an error using ModelXMLLoader when trying to unmarshal an XML document into Java objects using Texo.

I get this error:
java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.emf.ecore.EAttribute


Example schema:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by OMAR (EMBRACE) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:process="http://www.foo.com/test" xmlns:xdb="http://xmlns.oracle.com/xdb" targetNamespace="http://www.foo.com/test" version="1.0" xdb:schemaURL="ddd" xdb:mapStringToNCHAR="true" xdb:mapUnboundedStringToLob="true" xdb:storeVarrayAsTable="true">
	<xs:simpleType name="ClientCountry">
		<xs:restriction base="xs:string">
			<xs:enumeration value="CLCO1">
				<xs:annotation>
					<xs:documentation>Spain</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="CLCO2">
				<xs:annotation>
					<xs:documentation>Portugal</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ClientSectorActivity">
		<xs:restriction base="xs:string">
			<xs:enumeration value="CLSE0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="CLSE1">
				<xs:annotation>
					<xs:documentation>ABC</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ProductType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="PRTY0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="PRTY1">
				<xs:annotation>
					<xs:documentation>DEF</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Channel">
		<xs:restriction base="xs:string">
			<xs:enumeration value="CHAN0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="CHAN1">
				<xs:annotation>
					<xs:documentation>QUI</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="MainApplicantType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="MAPT0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="MAPT1">
				<xs:annotation>
					<xs:documentation>Male</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="MAPT2">
				<xs:annotation>
					<xs:documentation>Female</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="PrescriptorCountry">
		<xs:restriction base="xs:string">
			<xs:enumeration value="PRCO0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="PRCO1">
				<xs:annotation>
					<xs:documentation>Spain</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="PRCO2">
				<xs:annotation>
					<xs:documentation>Portugal</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ApplicationStatus">
		<xs:restriction base="xs:string">
			<xs:enumeration value="APST0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="APST1">
				<xs:annotation>
					<xs:documentation>OK</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="ApplicantType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="APTY0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="APTY1">
				<xs:annotation>
					<xs:documentation>Titular</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="APTY2">
				<xs:annotation>
					<xs:documentation>Cotitular</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="IDType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="IDTY0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="IDTY1">
				<xs:annotation>
					<xs:documentation>A</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="IDTY2">
				<xs:annotation>
					<xs:documentation>B</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="Gender">
		<xs:restriction base="xs:string">
			<xs:enumeration value="GEND0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="GEND1">
				<xs:annotation>
					<xs:documentation>male</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="GEND2">
				<xs:annotation>
					<xs:documentation>female</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="MaritalStatus">
		<xs:restriction base="xs:string">
			<xs:enumeration value="MAST0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="MAST1">
				<xs:annotation>
					<xs:documentation>Single</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="MAST2">
				<xs:annotation>
					<xs:documentation>Married</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="AddressType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="ADTY0">
				<xs:annotation>
					<xs:documentation>Not Informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="ADTY1">
				<xs:annotation>
					<xs:documentation>Main Address</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="ADTY2">
				<xs:annotation>
					<xs:documentation>Secondary Address</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="TelephoneType">
		<xs:restriction base="xs:string">
			<xs:enumeration value="TETY0">
				<xs:annotation>
					<xs:documentation>Not informed</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="TETY1">
				<xs:annotation>
					<xs:documentation>Mobile</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
			<xs:enumeration value="TETY2">
				<xs:annotation>
					<xs:documentation>LandLine</xs:documentation>
				</xs:annotation>
			</xs:enumeration>
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="applicationRequest" type="process:Application"/>
	<xs:element name="applicationResponse" type="process:Application"/>
	<xs:complexType name="Application">
		<xs:sequence>
			<xs:element name="applicants" type="process:Applicant" maxOccurs="unbounded"/>
			<xs:element name="clientCountry" type="process:ClientCountry" default="CLCO1"/>
			<xs:element name="clientSectorActivity" type="process:ClientSectorActivity" default="CLSE0"/>
			<xs:element name="productType" type="process:ProductType" default="PRTY0"/>
			<xs:element name="channel" type="process:Channel" default="CHAN0"/>
			<xs:element name="mainApplicantType" type="process:MainApplicantType" default="MAPT0"/>
			<xs:element name="prescriptorCountry" type="process:PrescriptorCountry" default="PRCO0"/>
			<xs:element name="applicationStatus" type="process:ApplicationStatus" default="APST0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="Applicant">
		<xs:sequence>
			<xs:element name="telephones" type="process:Telephone" maxOccurs="unbounded"/>
			<xs:element name="addresses" type="process:Address" maxOccurs="unbounded"/>
			<xs:element name="applicantType" type="process:ApplicantType" default="APTY0"/>
			<xs:element name="idType" type="process:IDType" default="IDTY0"/>
			<xs:element name="gender" type="process:Gender" default="GEND0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="Address">
		<xs:sequence>
			<xs:element name="addressType" type="process:AddressType" default="ADTY0"/>
			<xs:element name="addressLine1" type="xs:string" minOccurs="0"/>
			<xs:element name="addressLine2" type="xs:string" minOccurs="0"/>
			<xs:element name="postCode" type="xs:string" minOccurs="0"/>
			<xs:element name="country" type="xs:string" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="Telephone">
		<xs:sequence>
			<xs:element name="telephoneType" type="process:TelephoneType" default="TETY0" minOccurs="0"/>
			<xs:element name="telephoneNumber" type="xs:string" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="MatchingCondition">
		<xs:sequence>
			<xs:element name="attributeName" type="xs:string"/>
			<xs:element name="attributeValue" type="xs:string"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>


Example XML:
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2012 rel. 2 sp1 (x64) (http://www.altova.com)-->
<process:applicationRequest xsi:schemaLocation="http://www.foo.com/test exampleSchema.xsd" xmlns:process="http://www.foo.com/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<applicants>
		<telephones/>
		<addresses>
			<addressType>ADTY0</addressType>
		</addresses>
		<applicantType>APTY0</applicantType>
		<idType>IDTY0</idType>
		<gender>GEND0</gender>
	</applicants>
	<clientCountry>CLCO1</clientCountry>
	<clientSectorActivity>CLSE0</clientSectorActivity>
	<productType>PRTY0</productType>
	<channel>CHAN0</channel>
	<mainApplicantType>MAPT0</mainApplicantType>
	<prescriptorCountry>PRCO0</prescriptorCountry>
	<applicationStatus>APST0</applicationStatus>
</process:applicationRequest>


The ModelXMLLoader code:
final ModelXMLLoader xmlLoader = new ModelXMLLoader();
xmlLoader.setLoadAsXMI(false);
Map<String, Object> defaultOptions = xmlLoader.getOptions();
// Allow expected value to be within either an attribute or an element. 
defaultOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, true);
defaultOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
xmlLoader.setOptions(defaultOptions);
xmlLoader.setReader(new StringReader(writer.toString()));

xmlParsedList = xmlLoader.read(); ******FAILS HERE******
marshalObject = xmlParsedList.get(0);


If I change the root element of the XML to process:application the TEXO load works. How do I configure ModelXMLLoader to use the Application Java class when mapping the applicationRequest / applicationResponse please?
I know using JAXB the ObjectFactory would annotate with @XmlElementDecl. I guess I need something similar.

Regards,
Gary
Re: [TEXO] ModelXMLLoader mapping [message #957844 is a reply to message #957693] Thu, 25 October 2012 10:41 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Gary,
Can you also pass in this additional option:
XMLResource.OPTION_SUPPRESS_DOCUMENT_ROOT

with the value false

If it does not help then I will for sure test/debug your example.

gr. Martin

On 10/25/2012 02:18 PM, Gary Godfrey wrote:
> Hi,
>
> I am getting an error using ModelXMLLoader when trying to unmarshal an XML document into Java objects using Texo.
>
> I get this error:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.emf.ecore.EAttribute
>
>
> Example schema:
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by OMAR (EMBRACE) -->
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:process="http://www.foo.com/test"
> xmlns:xdb="http://xmlns.oracle.com/xdb" targetNamespace="http://www.foo.com/test" version="1.0" xdb:schemaURL="ddd"
> xdb:mapStringToNCHAR="true" xdb:mapUnboundedStringToLob="true" xdb:storeVarrayAsTable="true">
> <xs:simpleType name="ClientCountry">
> <xs:restriction base="xs:string">
> <xs:enumeration value="CLCO1">
> <xs:annotation>
> <xs:documentation>Spain</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="CLCO2">
> <xs:annotation>
> <xs:documentation>Portugal</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="ClientSectorActivity">
> <xs:restriction base="xs:string">
> <xs:enumeration value="CLSE0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="CLSE1">
> <xs:annotation>
> <xs:documentation>ABC</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="ProductType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="PRTY0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="PRTY1">
> <xs:annotation>
> <xs:documentation>DEF</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="Channel">
> <xs:restriction base="xs:string">
> <xs:enumeration value="CHAN0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="CHAN1">
> <xs:annotation>
> <xs:documentation>QUI</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="MainApplicantType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="MAPT0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="MAPT1">
> <xs:annotation>
> <xs:documentation>Male</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="MAPT2">
> <xs:annotation>
> <xs:documentation>Female</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="PrescriptorCountry">
> <xs:restriction base="xs:string">
> <xs:enumeration value="PRCO0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="PRCO1">
> <xs:annotation>
> <xs:documentation>Spain</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="PRCO2">
> <xs:annotation>
> <xs:documentation>Portugal</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="ApplicationStatus">
> <xs:restriction base="xs:string">
> <xs:enumeration value="APST0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="APST1">
> <xs:annotation>
> <xs:documentation>OK</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="ApplicantType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="APTY0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="APTY1">
> <xs:annotation>
> <xs:documentation>Titular</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="APTY2">
> <xs:annotation>
> <xs:documentation>Cotitular</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="IDType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="IDTY0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="IDTY1">
> <xs:annotation>
> <xs:documentation>A</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="IDTY2">
> <xs:annotation>
> <xs:documentation>B</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="Gender">
> <xs:restriction base="xs:string">
> <xs:enumeration value="GEND0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="GEND1">
> <xs:annotation>
> <xs:documentation>male</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="GEND2">
> <xs:annotation>
> <xs:documentation>female</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="MaritalStatus">
> <xs:restriction base="xs:string">
> <xs:enumeration value="MAST0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="MAST1">
> <xs:annotation>
> <xs:documentation>Single</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="MAST2">
> <xs:annotation>
> <xs:documentation>Married</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="AddressType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="ADTY0">
> <xs:annotation>
> <xs:documentation>Not Informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="ADTY1">
> <xs:annotation>
> <xs:documentation>Main Address</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="ADTY2">
> <xs:annotation>
> <xs:documentation>Secondary Address</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:simpleType name="TelephoneType">
> <xs:restriction base="xs:string">
> <xs:enumeration value="TETY0">
> <xs:annotation>
> <xs:documentation>Not informed</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="TETY1">
> <xs:annotation>
> <xs:documentation>Mobile</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> <xs:enumeration value="TETY2">
> <xs:annotation>
> <xs:documentation>LandLine</xs:documentation>
> </xs:annotation>
> </xs:enumeration>
> </xs:restriction>
> </xs:simpleType>
> <xs:element name="applicationRequest" type="process:Application"/>
> <xs:element name="applicationResponse" type="process:Application"/>
> <xs:complexType name="Application">
> <xs:sequence>
> <xs:element name="applicants" type="process:Applicant" maxOccurs="unbounded"/>
> <xs:element name="clientCountry" type="process:ClientCountry" default="CLCO1"/>
> <xs:element name="clientSectorActivity" type="process:ClientSectorActivity" default="CLSE0"/>
> <xs:element name="productType" type="process:ProductType" default="PRTY0"/>
> <xs:element name="channel" type="process:Channel" default="CHAN0"/>
> <xs:element name="mainApplicantType" type="process:MainApplicantType" default="MAPT0"/>
> <xs:element name="prescriptorCountry" type="process:PrescriptorCountry" default="PRCO0"/>
> <xs:element name="applicationStatus" type="process:ApplicationStatus" default="APST0"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Applicant">
> <xs:sequence>
> <xs:element name="telephones" type="process:Telephone" maxOccurs="unbounded"/>
> <xs:element name="addresses" type="process:Address" maxOccurs="unbounded"/>
> <xs:element name="applicantType" type="process:ApplicantType" default="APTY0"/>
> <xs:element name="idType" type="process:IDType" default="IDTY0"/>
> <xs:element name="gender" type="process:Gender" default="GEND0"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Address">
> <xs:sequence>
> <xs:element name="addressType" type="process:AddressType" default="ADTY0"/>
> <xs:element name="addressLine1" type="xs:string" minOccurs="0"/>
> <xs:element name="addressLine2" type="xs:string" minOccurs="0"/>
> <xs:element name="postCode" type="xs:string" minOccurs="0"/>
> <xs:element name="country" type="xs:string" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Telephone">
> <xs:sequence>
> <xs:element name="telephoneType" type="process:TelephoneType" default="TETY0" minOccurs="0"/>
> <xs:element name="telephoneNumber" type="xs:string" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="MatchingCondition">
> <xs:sequence>
> <xs:element name="attributeName" type="xs:string"/>
> <xs:element name="attributeValue" type="xs:string"/>
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
>
> Example XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!--Sample XML file generated by XMLSpy v2012 rel. 2 sp1 (x64) (http://www.altova.com)-->
> <process:applicationRequest xsi:schemaLocation="http://www.foo.com/test exampleSchema.xsd"
> xmlns:process="http://www.foo.com/test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <applicants>
> <telephones/>
> <addresses>
> <addressType>ADTY0</addressType>
> </addresses>
> <applicantType>APTY0</applicantType>
> <idType>IDTY0</idType>
> <gender>GEND0</gender>
> </applicants>
> <clientCountry>CLCO1</clientCountry>
> <clientSectorActivity>CLSE0</clientSectorActivity>
> <productType>PRTY0</productType>
> <channel>CHAN0</channel>
> <mainApplicantType>MAPT0</mainApplicantType>
> <prescriptorCountry>PRCO0</prescriptorCountry>
> <applicationStatus>APST0</applicationStatus>
> </process:applicationRequest>
>
>
> The ModelXMLLoader code:
>
> final ModelXMLLoader xmlLoader = new ModelXMLLoader();
> xmlLoader.setLoadAsXMI(false);
> Map<String, Object> defaultOptions = xmlLoader.getOptions();
> // Allow expected value to be within either an attribute or an element.
> defaultOptions.put(XMLResource.OPTION_LAX_FEATURE_PROCESSING, true);
> defaultOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
> xmlLoader.setOptions(defaultOptions);
> xmlLoader.setReader(new StringReader(writer.toString()));
>
> xmlParsedList = xmlLoader.read(); ******FAILS HERE******
> marshalObject = xmlParsedList.get(0);
>
>
> If I change the root element of the XML to process:application the TEXO load works. How do I configure ModelXMLLoader to
> use the Application Java class when mapping the applicationRequest / applicationResponse please?
> I know using JAXB the ObjectFactory would annotate with @XmlElementDecl. I guess I need something similar.
>
> Regards,
> Gary


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [TEXO] ModelXMLLoader mapping [message #964119 is a reply to message #957844] Tue, 30 October 2012 05:14 Go to previous messageGo to next message
Gary Godfrey is currently offline Gary Godfrey
Messages: 31
Registered: February 2012
Member
Hi,

The root cause of this issue was the ecore model and generated classes being out of sync. Now able to unmarshal the XML to the Java structure.

The XSD we need to use has the same schema for both the request and response. After processing I am using ModelXMLSaver to marshal the Java structure back to XML. This currently maps the Application object to applicationRequest. Is there a way to configure ModelXMLSaver so it uses applicationResponse?

The ModelXMLSaver code:
		final ModelXMLSaver xmlSaver = new ModelXMLSaver();
		xmlSaver.setSaveAsXMI(false);
		xmlSaver.setObjects(Collections.singletonList(application));

		final StringWriter sw = new StringWriter();
		xmlSaver.setWriter(sw);
		xmlSaver.write();

		Source source = new StreamSource(new StringReader(sw.toString()));


DocumentRoot has applicationRequest and applicationResponse.
	private Application applicationRequest = null;
	private Application applicationResponse = null;


Regards,
Gary
Re: [TEXO] ModelXMLLoader mapping [message #964231 is a reply to message #964119] Tue, 30 October 2012 07:01 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Gary,
Have you tried creating a document root object and then on that object either call setApplicationRequest or
setApplicationResponse. Then serialize the document root object to xml and see what you get.

You can also try different settings of the document root option. I think it is best that when you de-serialize that you
get a document root object as the root object back, then you know what you got (request or response) and then when
serializing back it should work.

Let me know if this helps or not ofcourse.

gr. Martin

On 10/30/2012 10:14 AM, Gary Godfrey wrote:
> Hi,
>
> The root cause of this issue was the ecore model and generated classes being out of sync. Now able to unmarshal the XML
> to the Java structure.
>
> The XSD we need to use has the same schema for both the request and response. After processing I am using ModelXMLSaver
> to marshal the Java structure back to XML. This currently maps the Application object to applicationRequest. Is there a
> way to configure ModelXMLSaver so it uses applicationResponse?
>
> The ModelXMLSaver code:
>
> final ModelXMLSaver xmlSaver = new ModelXMLSaver();
> xmlSaver.setSaveAsXMI(false);
> xmlSaver.setObjects(Collections.singletonList(application));
>
> final StringWriter sw = new StringWriter();
> xmlSaver.setWriter(sw);
> xmlSaver.write();
>
> Source source = new StreamSource(new StringReader(sw.toString()));
>
>
> DocumentRoot has applicationRequest and applicationResponse.
>
> private Application applicationRequest = null;
> private Application applicationResponse = null;
>
>
> Regards,
> Gary


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [TEXO] ModelXMLLoader mapping [message #964364 is a reply to message #964231] Tue, 30 October 2012 09:14 Go to previous messageGo to next message
Gary Godfrey is currently offline Gary Godfrey
Messages: 31
Registered: February 2012
Member
Hi Martin,

I now create DocumentRoot and setApplicationResponse. If I use DocumentRoot as the object sent into ModelXMLSaver:
		DocumentRoot documentRoot = new DocumentRoot();		
		documentRoot.setApplicationResponse(new Application());
		
		List<Object> objList = new ArrayList<Object>();
		objList.add(documentRoot);
		final ModelXMLSaver xmlSaver = new ModelXMLSaver();
		xmlSaver.setSaveAsXMI(false);
		xmlSaver.setObjects(objList);
	
		final StringWriter docRootWriter = new StringWriter();
		xmlSaver.setWriter(docRootWriter);
		xmlSaver.write();


This produces:
<?xml version="1.0" encoding="UTF-8"?>
/>


If I instead set the objList:
objList.add(documentRoot.getApplicationResponse());


The output is still written as applicationRequest:
<?xml version="1.0" encoding="UTF-8"?>
<process:applicationRequest xmlns:process="http://www.foo.com/test">
.....
</process:applicationRequest>



Regards,
Gary
Re: [TEXO] ModelXMLLoader mapping [message #964825 is a reply to message #964364] Tue, 30 October 2012 16:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Gary,
Have you tried with setting the XMLResource.OPTION_SUPPRESS_DOCUMENT_ROOT option to different values?

gr. Martin

On 10/30/2012 02:14 PM, Gary Godfrey wrote:
> Hi Martin,
>
> I now create DocumentRoot and setApplicationResponse. If I use DocumentRoot as the object sent into ModelXMLSaver:
>
> DocumentRoot documentRoot = new DocumentRoot();
> documentRoot.setApplicationResponse(new Application());
>
> List<Object> objList = new ArrayList<Object>();
> objList.add(documentRoot);
> final ModelXMLSaver xmlSaver = new ModelXMLSaver();
> xmlSaver.setSaveAsXMI(false);
> xmlSaver.setObjects(objList);
>
> final StringWriter docRootWriter = new StringWriter();
> xmlSaver.setWriter(docRootWriter);
> xmlSaver.write();
>
>
> This produces:
> <?xml version="1.0" encoding="UTF-8"?>
> />
>
>
> If I instead set the objList:
>
> objList.add(documentRoot.getApplicationResponse());
>
>
> The output is still written as applicationRequest:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <process:applicationRequest xmlns:process="http://www.foo.com/test">
> .....
> </process:applicationRequest>
>
>
>
> Regards,
> Gary


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [TEXO] ModelXMLLoader mapping [message #965771 is a reply to message #964825] Wed, 31 October 2012 09:45 Go to previous messageGo to next message
Gary Godfrey is currently offline Gary Godfrey
Messages: 31
Registered: February 2012
Member
Hi Martin,

I have debugged and have found the reason. It is because DocumentRoot has two variables of type Application. When the code calls org.eclipse.emf.ecore.xmi.impl.ElementHandlerImpl.getRoot(...) it selects the first type that matches the supplied eClassifier.

If I re-order applicationResponse to appear above applicationRequest, the XML is saved correctly. I would prefer not to rely on this manual step in case the ecore is re-generated.

I have tried setting various attributes in the ecore file for DocumentRoot. I think the use of extended_meta_data may be the answer, though not sure how to configure it correctly.

Regards,
Gary

Re: [TEXO] ModelXMLLoader mapping [message #965789 is a reply to message #965771] Wed, 31 October 2012 10:00 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5329
Registered: July 2009
Senior Member
Hi Gary,
Seems almost like a bug, or at least a missing feature. Can you enter a bugzilla for me on this?

gr. Martin

On 10/31/2012 02:45 PM, Gary Godfrey wrote:
> Hi Martin,
>
> I have debugged and have found the reason. It is because DocumentRoot has two variables of type Application. When the
> code calls org.eclipse.emf.ecore.xmi.impl.ElementHandlerImpl.getRoot(...) it selects the first type that matches the
> supplied eClassifier.
>
> If I re-order applicationResponse to appear above applicationRequest, the XML is saved correctly. I would prefer not to
> rely on this manual step in case the ecore is re-generated.
>
> I have tried setting various attributes in the ecore file for DocumentRoot. I think the use of extended_meta_data may be
> the answer, though not sure how to configure it correctly.
>
> Regards,
> Gary
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:[CDO] Repository recovery fails after crash with stanalone CDO sever with postgresql
Next Topic:[Xcore] produces non-compiling Java code when using closures
Goto Forum:
  


Current Time: Fri Aug 22 00:17:18 EDT 2014

Powered by FUDForum. Page generated in 0.01830 seconds