1

OXM フレームワークを使用して、RESTful API 呼び出しへの要求の HTTP POST ペイロードとして渡される次の XML のアンマーシャリングをサポートすることに興味があります。

OXM フレームワークを使用するのはこれが初めてで、モデル クラスに正しく注釈を付けるのに問題があります。私は Spring 3.0 と JAXB2 Marshaller を使用していますが、特定のマーシャラーの実装については無関心です。

質問:

1) 目的の XML 構造を反映するためにモデル クラスに注釈を付けるための最良の戦略は何ですか? 以下に、クラスに注釈を付ける方法の例を示しますClass has two properties with the same name "XXX"。マーシャラーを作成しようとすると、XmlElements になります。

2) 注釈とクラスでサポートするために、どのような戦略を取ることができますか? 私は SpatialExtent をインターフェイスとして定義していましたが、GeoBoundingBox XmlElement を実装するクラスがこのインターフェイスを実装しました。これは Java では機能しますが、JAXB では機能しません。

3) マーシャリング/アンマーシャリングを簡素化するために、必要な XML を改善できる場所はありますか?

どんな助けでも大歓迎です!--ステファン

バックグラウンド:

使用したい XML の例を次に示します。

<?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 と TimePeriod は、空間的および時間的範囲の唯一の可能なタイプではありませんが、まだ他のタイプを定義する必要はありません。

Spring パッケージ アノテーションを使用しています。

モデルクラスに注釈を付ける方法の例:

@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...
}

すべての XmlElements 注釈は、モデル オブジェクトを参照するクラス メソッド上にあり、すべての XmlAttribute 注釈は、データ型 (例: private String id) を参照するクラス メソッド上にあります。

初期の 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