グループ

グループは、選択グループ、複合グループ、またはコレクション・グループのいずれかになります。 これらのグループは、複合タイプおよび特定の動的メソッドを使用してマップされます。

グループ・マッピングに関しては以下の 3 つのサブセクションに説明があります。

各セクションで、さまざまなタイプのマッピングを示す例を使用します。 例には、 スキーマ、XML 文書および XOM 表記が含まれています。 選択グループ・マッピングの例、および複合グループ・マッピングの例には、説明を分かりやすくするためのルールも含まれています。

選択グループ

選択グループは、エレメントの XSD グループです。 グループ・スキーマに関連する XML 文書に、これらの エレメントのうちの 1 つだけが使用されます。

選択グループの処理を容易にするため、追加の動的メソッドが生成されます。 例えば、動的メソッド getChoice は、グループ内で選択された 動的属性値を返します。また、動的メソッド getChosenAttribute は、グループ内で 選択された動的属性名を返します。 String パラメーターは、複合タイプに 複数のグループが存在する場合に、グループを見つけるために役立ちます。 選択されたグループは、いずれかの子のフィールドの XOM 名によって識別されます。 引数を持たないメソッドを使用した場合、最初の選択項目はディープ検索によって選択されます。

選択グループ・マッピングの例

以下の例では、3 つのエレメント (temperature、pressure、 および velocity) を持つ複合タイプ observation を使用します。

以下にスキーマを示します。

<complexType name="observation">
  <choice>
    <element name="temperature" type="double"/>
    <element name="pressure" type="double"/>
    <element name="velocity" type="double"/>
  </choice>
</complexType>

以下に XML 文書からの抜粋を示します。

<observation>
  <pressure>10.0</pressure>
</observation>

以下に XOM 表記を示します。

class Observation extends IlrXmlObject
{
  double temperature ;
  double pressure ;
  double velocity ;
…
  // choice dynamic methods
  Object getChoice ( String attrName ) ;
  String getChosenAttribute ( String attrName );
  Object getChoice();
  String getChosenAttribute();
}

以下に規則を示します。

rule findTemperatureObservation
{
   when {
      Observation ( temperature isknown );
   }
   then {
   …
   }
}
rule processObservationValue
{
   when {
      obs: Observation ( );
      v: Double () from obs.getChoice ( );
      attr: String () from obs.getChosenAttribute ( );
   }
   then {
   …
   }
}

複合グループ

複合グループは、エレメントとグループを組み合わせたものです。

注:

W3C 規格は、複数の要素からなる複合タイプの概念を定義していません。 ここでは、新しいマッピング状態を 解説し、順序グループまたは選択グループと区別するために、この概念を使用します。

複合グループ・マッピングの例

以下の例では、選択グループでも使用した 同じ複合タイプ observation を再利用します。 複合グループのマッピングという目的のために、observation タイプには 選択グループがもう 1 つ追加されています。 この追加された選択グループには、error と comment の 2 つのオプションがあります。

以下にスキーマを示します。

<complexType name="observation">
  <sequence>
    <choice>
     <element name="temperature" type="double"/>
     <element name="pressure" type="double"/>
     <element name="velocity" type="double"/>
    </choice>
    <choice>
      <element name="error" type="double"/>
      <element name="comment" type="string" />
    </choice>
  <sequence>
</complexType>

以下に XML 文書からの抜粋を示します。

<observation>
  <pressure>10</pressure>
  <error>0.2</error>
</observation>

以下に XOM 表記を示します。

class Observation extends IlrXmlObject
{
  double temperature ;
  double pressure ;
  double velocity ;
  double error;
  String comment;
…
  // choice dynamic methods
  Object getChoice ( String attrName ) ;
  String getChosenAttribute ( String attrName );
}

以下に規則を示します。

rule findTemperatureWithErrorObservation
{
   when {
      Observation ( temperature isknown; error isknown );
   }
   then {
   …
   }
}
rule processObservationValue
{
   when {
      obs: Observation ( );
      v: Double () from obs.getChoice ( "velocity" );
      attr: String () from obs.getChosenAttribute ( "velocity" );
   }
   then {
   …
   }
}
rule displayErrorOrComment
{
   when {
      obs: Observation ( );
      c: Object () from obs.getChoice ( "error" );
      attr: String () from obs.getChosenAttribute ( "error" );
   }
   then {
     out.println ( attr + '=' + c.toString() );
   }
}

コレクション・グループ

以下の例は、選択グループのコレクションをマップする方法を示しています。 この例でも、選択グループおよび複合グループの 各セクションで使用した複合タイプ observation を再利用します。 選択グループのコレクションは、maxOccurs="unbounded" を指定して複合タイプ内に定義されます。

以下にスキーマを示します。

<complexType name="observations">
  <choice maxOccurs="unbounded">
    <element name="temperature" type="double"/>
    <element name="pressure" type="double"/>
    <element name="velocity" type="double"/>
  <choice>
</complexType>

以下に XML 文書からの抜粋を示します。

<observations>
  <velocity>12.3</velocity>
  <temperature>11.5</temperature>
  <velocity>9.2</velocity>
</observations>

以下に XOM 表記を示します。

class Observations extends IlrXmlObject 
{
  Vector temperatureList;
  Vector pressureList;
  Vector velocityList;
…
}