Groups
Group mapping is presented in three subsections:
In each sections, an example is used to demonstrate the various types of mapping. The examples include a schema, an XML document, and the XOM representation. The examples of choice group mapping and composite group mapping also include the rules to help clarify the explanation.
Choice groups
A choice group is an XSD group of elements. Only one of them is shown in the XML document related to the group schema.
Additional dynamic methods are
generated to help handle the choice group. For example, the dynamic
method getChoice returns the dynamic attribute value
selected in a group, and the dynamic method getChosenAttribute returns
the dynamic attribute name selected in a group. The String parameter
helps to locate the group when there are multiple groups in a complex
type. The selected group is identified by the XOM name of a field
of one of its children. When the method is used with no argument,
the first choice is selected by deep search.
Example of choice group mapping
The
following example uses the complex type observation which
contains three elements: temperature, pressure,
and velocity.
Here is the schema:
<complexType name="observation">
<choice>
<element name="temperature" type="double"/>
<element name="pressure" type="double"/>
<element name="velocity" type="double"/>
</choice>
</complexType>
Here is the excerpt from an XML document:
<observation>
<pressure>10.0</pressure>
</observation>
Here is the XOM representation:
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();
}
And here are the rules:
rule findTemperatureObservation
{
when {
Observation ( temperature isknown );
}
then {
…
}
}
rule processObservationValue
{
when {
obs: Observation ( );
v: Double () from obs.getChoice ( );
attr: String () from obs.getChosenAttribute ( );
}
then {
…
}
}
Composite groups
A composite group is a combination of elements and groups.
The W3C specification does not define the concept of a composite complex type. This concept has been introduced here to describe a new mapping state and differentiate it from the sequence or choice groups.
Example of composite group mapping
The
following example reuses the same complex type observation already
used in Choice groups.
For the purpose of mapping a composite group, one more choice group
has been added to the observation type. This additional
choice group has two options: error and comment.
Here is the schema:
<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>
Here is the excerpt from an XML document:
<observation>
<pressure>10</pressure>
<error>0.2</error>
</observation>
Here is the XOM representation:
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 );
}
And here are the rules:
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() );
}
}
Collection groups
The following
example demonstrates how to map a collection of choice groups. This
example reuses again the complex type observation already
used in the Choice groups and Composite groups sections.
The collection of the choice group is defined in the complex type
with maxOccurs="unbounded".
Here is the schema:
<complexType name="observations">
<choice maxOccurs="unbounded">
<element name="temperature" type="double"/>
<element name="pressure" type="double"/>
<element name="velocity" type="double"/>
<choice>
</complexType>
Here is the excerpt from an XML document:
<observations>
<velocity>12.3</velocity>
<temperature>11.5</temperature>
<velocity>9.2</velocity>
</observations>
And here is the XOM representation:
class Observations extends IlrXmlObject
{
Vector temperatureList;
Vector pressureList;
Vector velocityList;
…
}