|
Re: [TEXO] ModelXMLLoader mapping [message #957844 is a reply to message #957693] |
Thu, 25 October 2012 14:41 |
Martin Taal Messages: 5468 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 #965789 is a reply to message #965771] |
Wed, 31 October 2012 14:00 |
Martin Taal Messages: 5468 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
|
|
|
Powered by
FUDForum. Page generated in 0.03626 seconds