1

I am interested in using a OXM framework to support unmarshalling of the following XML that will be passed as the HTTP POST payload of a request to a RESTful API call.

This is my first time trying to use a OXM framework and I am having problems annotating my model classes correctly. I am using Spring 3.0 and the JAXB2 Marshaller, but I am indifferent as to the specific marshaller implementation.

Questions:

1) What is the best strategy for annotating my model classes to reflect my desired XML structure? I have an example of how I have been annotating my classes below, and it is resulting in Class has two properties with the same name "XXX" for my XmlElements when I try to create the Marshaller.

2) What strategy can I take to support in my annotations and classes? I was defining SpatialExtent as an interface and then the class that implements a GeoBoundingBox XmlElement implemented this interface. This works for Java but not for JAXB.

3) Are there any places where the desired XML can be improved to simplify marshalling/unmarshalling?

Any help is appreciated! --Stephan

Background:

Here is an example of the XML I would like to consume:

<?xml version="1.0" encoding="UTF-8"?>
<AnalysisSettings>
    <service id="urn:nasa:giovanni:latlonplot"/>
    <spatialExtent>
        <GeoBoundingBox>
            <south>20.0</south>
            <north>90.0</north>
            <west>0.0</west>
            <east>180.0</east>
        </GeoBoundingBox>
    </spatialExtent>
    <temporalExtent>
        <TimePeriod>
            <startTime>2008-01-01T00:00:00Z</startTime>
            <endTime>2008-01-31T00:00:00Z</endTime>
        </TimePeriod>
    </temporalExtent>
    <variables>
        <Variable>
            <dataset id="urn:nasa:modis:MYD08_D3.005"/>
            <parameter id="urn:nasa:modis:Optical_Depth_Land_And_Ocean_Mean"/>
        </Variable>
        <Variable>
            <dataset id="urn:nasa:modis:M0D08_D3.005"/>
            <parameter id="urn:nasa:modis:Optical_Depth_Land_And_Ocean_Mean"/>
        </Variable>
    </variables>
</AnalysisSettings>

GeoBoundingBox and TimePeriod are not the only possible types for spatial and temporal extents, but I have not had to define any other types as of yet.

I am using Spring package annotations.

An example of how I have been annotating my model classes:

@XmlRootElement
@XmlType(name="AnalysisSettings")
public class AnalysisSettings {

    @XmlElement(name="service")
    private Service service;

    @XmlElement(name="spatialExtent")
    private SpatialExtent spatialExtent;

    @XmlElement(name="temporalExtent")
    private TemporalExtent temporalExtent ;

    @XmlElement(name="variables")
    private Variable[] variables;

    // standard getter and setter methods...
}

All XmlElements annotations are on class methods that reference model objects and all XmlAttribute annotations are on class methods that reference datatypes (e.g. private String id).

I have an early XSD:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="AnalysisSettings" type="AnalysisSettingsType" />
  <xsd:complexType name="AnalysisSettingsType">
    <xsd:sequence>
      <xsd:element name="service" type="serviceType" />
      <xsd:element name="spatialExtent" type="spatialExtentType" />
      <xsd:element name="temporalExtent" type="temporalExtentType" />
      <xsd:element name="variables" type="variablesType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="variablesType">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="Variable" type="variableType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="variableType">
    <xsd:sequence>
      <xsd:element name="dataset" type="datasetType" />
      <xsd:element name="parameter" type="parameterType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="parameterType">
    <xsd:attribute name="id" type="xsd:anyURI" />
  </xsd:complexType>
  <xsd:complexType name="datasetType">
    <xsd:attribute name="id" type="xsd:anyURI" />
  </xsd:complexType>
  <xsd:complexType name="temporalExtentType">
    <xsd:sequence>
      <xsd:element name="TimePeriod" type="TimePeriodType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="TimePeriodType">
    <xsd:sequence>
      <xsd:element name="startTime" type="xsd:dateTime" />
      <xsd:element name="endTime" type="xsd:dateTime" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="spatialExtentType">
    <xsd:sequence>
      <xsd:element name="GeoBoundingBox" type="GeoBoundingBoxType" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="GeoBoundingBoxType">
    <xsd:sequence>
      <xsd:element name="south" type="xsd:decimal" />
      <xsd:element name="north" type="xsd:decimal" />
      <xsd:element name="west" type="xsd:decimal" />
      <xsd:element name="east" type="xsd:decimal" />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="serviceType">
    <xsd:attribute name="id" type="xsd:anyURI" />
  </xsd:complexType>
</xsd:schema>
4

0 回答 0