그룹
그룹은 선택 그룹, 복합 그룹 또는 콜렉션 그룹일 수 있습니다. 이들 그룹은 복합 유형 및 특정 동적 메소드를 사용하여 맵핑됩니다.
그룹 맵핑은 세 개의 하위 섹션으로 제공됩니다.
각 섹션에서는 다양한 맵핑 유형을 나타내는 예제가 사용됩니다. 이 예제에는 스키마, XML 문서 및 XOM 표현이 포함됩니다. 선택 그룹 맵핑 및 복합 그룹 맵핑의 예제에는 설명을 명확히 하는 데 도움이 되는 규칙도 포함되어 있습니다.
선택 그룹
선택 그룹은 요소의 XSD 그룹입니다. 이러한 그룹 중 하나만 그룹 스키마와 관련된 XML 문서에 나타납니다.
선택 그룹을 처리하는 데 도움이 되도록 추가 동적 메소드가 생성됩니다. 예를 들어, 동적 메소드 getChoice는 그룹에서 선택된 동적 속성 값을 리턴하고 동적 메소드 getChosenAttribute는 그룹에서 선택된 동적 속성 이름을 리턴합니다. 복합 유형에 그룹이 여러 개 있는 경우 String 매개변수를 사용하여 그룹을 찾을 수 있습니다. 선택된 그룹은 하위 항목 중 하나에서 필드의 XOM 이름으로 식별합니다. 메소드가 인수 없이 사용된 경우 첫 번째 선택 항목은 자세한 검색을 통해 선택합니다.
선택 그룹 맵핑의 예제
다음 예제에서는 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 유형에 선택 그룹이 하나 더 추가되었습니다. 이 추가 선택 그룹에는 error 및 comment의 두 개의 옵션이 있습니다.
스키마는 다음과 같습니다.
<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;
…
}