Hi all,
I am currently involved with a critical project where I need to create and
populate OAGIS style XML documents using Java.
I decided to use JIBX 1.2.3 as the tool to create the XML Documents. After
reviewing all the other Java to XML maping tools (JAXB, Castor), I found
Jibx to be the simplest and fastest one to use.
I am several weeks into the coding effort and everything has been going
smoothly except for one major road-block. which as caused me some distress.
At a high level, the OAGIS XML document structure is a following:
<BODName>
<ApplicationArea>
<DataArea>
<Verb> ... </Verb>
<Noun> ... </Noun>
</BODName>
A more concrete example of the above would be (Example 1):
<SyncLocation>
<ApplicationArea>
<DataArea>
<Sync> ... </Sync>
<Location> ... </Location>
</SyncLocation>
As you can hopefully see from the above concrete example, the <DataArea> parent
element can have endless combinations of <Verb> / <Noun> child elements.
The <DataArea> parent element would never have the elements <Verb> and <Noun>,
but always a substitution of the <Verb> / <Noun>.
After reading and performing the tutorials in the JIBX 1.2.3 site, I have
decided to create the following java classes and bindings to extend the
<DataArea> element.
1. The Class that represents the <SyncLocation> looks like this
public class SyncLocation
{
private ApplicationArea applicationArea;
private DataArea dataArea;
private String versionID;
private String releaseID;
private String systemEnvironmentCode;
private String languageCode;
2. The abstract Class that represents the <DataArea> looks like this
public abstract class DataArea
{
private Verb verb;
private Noun noun;
3. I created a separate Class called SyncLocationDataArea that extends the
<DataArea> to add the <Sync> and <Location> child element
public class SyncLocationDataArea extends DataArea
{
private Sync sync;
private Location location;
The XML Bindings I created for the above classes are as follows:
1. For the <SyncLocation> parent element
<mapping class="com.infor.schema.inforoagis.SyncLocation" name="SyncLocation">
<structure type="com.infor.schema.inforoagis.ApplicationArea"
get-method="getApplicationArea" set-method="setApplicationArea"/>
<structure type="com.infor.schema.inforoagis.DataArea"
get-method="getDataArea" set-method="setDataArea"/>
<value style="attribute" name="versionID" get-method="getVersionID"
set-method="setVersionID"/>
<value style="attribute" name="releaseID" get-method="getReleaseID"
set-method="setReleaseID"/>
<value style="attribute" name="systemEnvironmentCode"
get-method="getSystemEnvironmentCode" set-method="setSystemEnvironmentCode"/>
<value style="attribute" name="languageCode" get-method="getLanguageCode"
set-method="setLanguageCode"/>
</mapping>
2. For the <DataArea> parent (abstract class)
<mapping abstract="true" class="com.infor.schema.inforoagis.DataArea"
name="DataArea">
<structure map-as="ns2:Verb" get-method="getVerb" set-method="setVerb"
name="Verb"/>
<structure map-as="ns2:Noun" get-method="getNoun" set-method="setNoun"
name="Noun"/>
</mapping>
<mapping abstract="true" type-name="ns2:Verb"
class="com.infor.schema.inforoagis.Verb"/>
<mapping abstract="true" type-name="ns2:Noun"
class="com.infor.schema.inforoagis.Noun"/>
4. For the <SyncLocationDataArea> instance of <DataArea>
<mapping class="com.infor.schema.inforoagis.SyncLocationDataArea"
name="SyncLocationDataArea"
extends="com.infor.schema.inforoagis.DataArea" >
<structure map-as="com.infor.schema.inforoagis.DataArea"/>
<structure type="com.infor.schema.inforoagis.Sync" get-method="getSync"
set-method="setSync"/>
<structure type="com.infor.schema.inforoagis.Location"
get-method="getLocation" set-method="setLocation"/>
</mapping>
Test Results of above Java Pojo's and Jibx XML Mappings
1. All the above classes compile cleanly.
2. All the above class bind cleanly and a full set of jibx_binding classes are
created successfully.
3. However, when I attempt to marshall / unmarshall an input XML <SyncLocation>
document, I get the following error in my test program:
org.jibx.runtime.JiBXException: Element
"{http://schema.infor.com/InforOAGIS/2}DataArea" has no mapping that extends
com.infor.schema.inforoagis.DataArea
at com.infor.schema.inforoagis.JiBX_bindingDataArea_access.unmarshal()
at
com.infor.schema.inforoagis.SyncLocation.JiBX_binding_unmarshal_1_0(SyncLocation.java)
at com.infor.schema.inforoagis.JiBX_bindingSyncLocation_access.unmarshal()
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalElement(UnmarshallingContext.java:2757)
at
org.jibx.runtime.impl.UnmarshallingContext.unmarshalDocument(UnmarshallingContext.java:2900)
at com.infor.schema.inforoagis.unitTest.XMLBodTest1.main(XMLBodTest1.java:39)
Any ideas what I am doing wrong? Any help would be appreciated as I'm afraid
our project will fail if I can't figure this out.
Best regards... Ted Rollins
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users