<Quick>  <JXML>  <Download>  <QDML>

 

QJML Binding Schema

A QJML binding schema is used by Quick to bind the elements and attributes of an XML markup language to various Java classes.

Each QDML element is described as follows:

The following color scheme is used:

QJML has 14 elements:

 

 
ELEMENT: qjml
DTD: <!ELEMENT qjml (element+)> <!ATTLIST qjml root CDATA #REQUIRED> QDML: <element name="qjml"> <attribute name="root" status="REQUIRED"/> <child element="element" repeating="True"/> </element>

 

The qjml element is the root element of the document. It serves the purpose of providing the single root element that is required of a well-formed XML document, as well as identifying the document as a QJML binding schema.

 

Sample XML

<timesheet name="Bill la Forge">
    <day date="19990913">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990914">
        <entry hours="6" project="quite"/>
        <entry hours="2" project="admin"/>
    </day>
    <day date="19990915">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990916">
        <entry hours="8" project="vacation"/>
    </day>
    <day date="19990917">
        <entry hours="8" project="quite"/>
    </day>
</timesheet>

QDML

<qdml root="timesheet">
.
. <!--timesheet elements-->
.
</qdml>

QJML

<qjml root="timesheet">
.
. <!--timesheet elements-->
.
</qjml>

Java: none

This is an example of a fragment of a QJML binding schema. In this example, we are defining a markup language, timesheet, which has a root element of timesheet.

 

Attributes

A qjml element has a required attribute, root. This attribute identifies the outermost element of the markup language being defined by the QJML binding schema.

 

Content Model

Every qjml element must contain one or more element elements. These subordinate elements specify the various elements that comprise the markup language being defined by the QJML binding schema.

 

 
ELEMENT: targetEditor
DTD: <!ELEMENT targetEditor EMPTY> <!ATTLIST targetEditor target CDATA #REQUIRED editor CDATA #IMPLIED> QDML: <element name="targetEditor" content="EMPTY"> <attribute name="target" status="REQUIRED"/> <attribute name="editor"/> </element>

 

Property Editors are easy to write and provide a standard interface for data validation and for conversion of that data into an object. In the QJML binding schema, the programmer can identify the appropriate Property Editor for validating every data item held by an XML document.

Property Editors are bi-directional, in that they also contain the logic for converting an object into text when the object's toString method does not return appropriate values.

The targetEditor element binds a JavaBeans[tm] PropertyEditor to an attribute or to an element:

Quick uses the Property Editors identified in the QJML binding schema to convert the attribute value or element content to an object, and also to convert an object into an attribute value or element content.

Perhaps most importantly, the Property Editor is used to validate the element content or attribute value when a document is parsed. By specifying the appropriate Property Editors, the programmer can be assured that only valid data will be passed to the application.

 

Sample XML

<date>19990916</date>

QDML

<element name="date"
         content="PCDATA">
</element>

QJML

<element name="date"
    content="PCDATA">
    <targetEditor target="com.jxml.quick.examples.timesheet.Date"
                  editor="com.jxml.quick.examples.timesheet.YYYYMMDDEditor"/>
</element>

Java

package com.jxml.quick.examples.timesheet;
import java.beans.*;

public class YYYYMMDDEditor extends PropertyEditorSupport 
{
	public static final int[] maxDay=
	{
		31,29,31,30,31,30,31,31,30,31,30,31
	};

	public void setAsText(String text) throws java.lang.IllegalArgumentException 
	{
		if (text.length()!=8)
			throw new IllegalArgumentException
				("YYYYMMDD length is not 8: "+text);
		int i=Integer.parseInt(text);
		int d=i%100;
		int m=(i/100)%100;
		if (m==0 || m>12)
			throw new IllegalArgumentException
				("YYYYMMDD month is invalid: "+text);
		if (d==0 || d>maxDay[m])
			throw new IllegalArgumentException
				("YYYYMMDD day is invalid: "+text);
		Date date=new Date(i);
		setValue(date);
	}
}

In this example we have bound the property editor YYYYMMDDEditor to element date.

The property editor overrides the setAsText method on the class PropertyEditorSupport, which gives the property editor the ability to validate the text content of the element and to create a Date object.

In the case of the Date class, the toString method returns a reasonable value, so nothing more is required of the property editor. In cases where the toString method does not return a reasonable value, the property editor must also override the getAsText method.

 

Attributes

The targetEditor element has the following attributes:

 

Content Model: EMPTY

 

 
ELEMENT: targetClass
DTD: <!ELEMENT targetClass (#PCDATA)> QDML: <element name="targetClass" content="PCDATA"/>

 

The targetClass element binds an XML element or attribute directly to a Java class. When the element or attribute are parsed, that Java class is used to create an object. And when expressing a structure of objects, instances of that class are expressed as the element or attribute to which it is bound.

(The binding of a Java class to an element need not be unique, so long as it is not ambiguous within the scope of a content model. A Java class can be bound to more than one element or attribute.)

There are several cases when we can bind to a Java class using targetClass:

  1. When an attribute is bound to a Java class and the type attribute in the attribute definition has not been specified.

    In this case, there are several requirements placed on the Java class:

    If any of these conditions are not met by the Java class, then you will need to write your own Property Editor and bind it to the attribute using targetEditor.

  2. When an element is bound to a Java class and the content attribute in the element definition has been assigned a value of PCDATA.

    In this case, there are several requirements placed on the Java class:

    If any of these conditions are not met by the Java class, then you will need to write your own Property Editor and bind it to the element using targetEditor.

  3. When an element is bound to a Java class and the content attribute in the element definition has been assigned a value of EMPTY or the content attribute has not been specified.

    In this case, the Java class must have a public constructor which has no parameters (sometimes called a null-constructor).

  4. When an element is bound to a Java class and the content attribute in the element definition has been assigned a value of BIMODAL.

    In this case, the Java class must have a public constructor which has no parameters sometimes called a null-constructor).

    The Java class must also implement the QBiModal interface. (The getQText and setQText methods in this interface are used by Quick to pass and retrieve the element's text content.)

 

Sample XML

<configuration href="http://www.jxml.com/quick/test32/test.cfg"/>

QDML

<element name="configuration"
         content="EMPTY">
    <attribute name="href"
               status="REQUIRED">
</element>

QJML

<element name="configuration"
    content="EMPTY">
    <targetClass>com.jxml.quick.test32.Configuration</targetClass>
    <attribute name="href"
               status="REQUIRED"
               field="href">
        <targetClass>java.net.URL</targetClass>
    </attribute>
</element>

Java

package com.jxml.quick.test32;
import java.net.*;

public class Configuration
{
	public URL href=null;

	public Configuration()
	{
	};
}

In this example we have bound the configuration element to the Configuration class (case 3 above), and bound the href attribute to the URL class (case 1 above) using targetClass.

 

Attributes: none

 

Content Model

The content of a targetClass element is the full class name of a Java class.

 

 
ELEMENT: targetFactory
DTD: <!ELEMENT targetFactory (#PCDATA)> QDML: <element name="targetFactory" content="PCDATA"/>

 

The targetFactory element binds an implementation of QTargetFactory.

Target factories are largely used in the implementation of Quick. There is a small speed advantage to using target factories rather than depending on Java reflection, as is the case with targetClass.

 

Attributes: none

 

Content Model

The content of a targetClass element is the full class name of a Java class which implements QTargetFactory.

 

 
ELEMENT: extends
DTD: <!ELEMENT extends (#PCDATA)> QDML: <element name="extends" content="PCDATA"/>

 

The extends element is used to model Java inheritance. An element defined with an extends element can occur anywhere the element referenced by the extends element can occur. (For example, if the referenced element can be a root element, then so can the new element being defined with extends.)

 

Attributes: none

 

Content Model

The content of an extends element is the tag name (or label) of the element being referenced.

 

 
ELEMENT: implements
DTD: <!ELEMENT implements (#PCDATA)> QDML: <element name="implements" content="PCDATA"/>

 

The implements element is used to model Java inheritance. An element defined with an implements element can occur anywhere the element referenced by the implements element can occur. (For example, if the referenced element can be a root element, then so can the new element being defined with implements.)

 

Attributes: none

 

Content Model

The content of an implements element is the tag name (or label) of the element being referenced.

 

 
ELEMENT: element
DTD: <!ELEMENT element (rem*,extends*,implements*, (targetClass|targetEditor|targetFactory)?, attribute*, (child|selection|sequence|cref)*)> <!ATTLIST element name CDATA #REQUIRED label CDATA #IMPLIED wild CDATA "False" content (PCDATA,CDATA,BIMODAL,EMPTY,int,short,long,byte,boolean,float, double,string,base64,url,char,BigDecimal) abstract CDATA "False" interface CDATA "False"> QDML: <element name="element"> <attribute name="name" status="REQUIRED"/> <attribute name="label"/> <attribute name="wild" value="False"/> <attribute name="content"> <value>PCDATA</value> <value>CDATA</value> <value>BIMODAL</value> <value>EMPTY</value> <value>int</value> <value>short</value> <value>long</value> <value>byte</value> <value>boolean</value> <value>float</value> <value>double</value> <value>string</value> <value>base64</value> <value>url</value> <value>char</value> <value>BigDecimal</value> </attribute> <attribute name="abstract" value="False"/> <attribute name="interface" value="False"/> <child element="rem" optional="True" repeating="True"/> <selection optional="True"> <child element="targetClass"/> <child element="targetEditor"/> <child element="targetFactory"/> </selection> <child element="attribute" optional="True" repeating="True"/> <selection optional="True" repeating="True"> <child element="child"/> <child element="selection"/> <child element="sequence"/> <child element="cref"/> </selection> </element>

 

The element element specifies both the validation requirements and the binding of an XML element.

The QJML element differs from the QDML element with the inclusion of extends and implements elements, a targetClass, targetEditor, or targetFactory element, and cref elements. The content attribute can be assigned additional values, which serve as an implicit specification of a targetEditor. The label, abstract, and interface attributes have been added as well.

 

Sample XML

<timesheet name="Bill la Forge">
    <day date="19990913">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990914">
        <entry hours="6" project="quite"/>
        <entry hours="2" project="admin"/>
    </day>
    <day date="19990915">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990916">
        <entry hours="8" project="vacation"/>
    </day>
    <day date="19990917">
        <entry hours="8" project="quite"/>
    </day>
</timesheet>

QDML

<qdml root="timesheet">

    <element name="timesheet">
    .
    . <!--attribute, child, selection, and sequence elements-->
    .
    </element">

    <element name="day">
    .
    . <!--attribute, child, selection, and sequence elements-->
    .
    </element">

    <element name="entry" content="EMPTY">
    .
    . <!--attribute elements-->
    .
    </element">

</qdml>

QJML

<qjml root="timesheet">

    <element name="timesheet">
        <targetClass>com.jxml.quick.examples.timesheet.Timesheet</targetClass>
        .
        . <!--attribute, child, selection, and sequence elements-->
        .
    </element">

    <element name="day">
        <targetClass>com.jxml.quick.examples.timesheet.Day</targetClass>
        .
        . <!--attribute, child, selection, and sequence elements-->
        .
    </element">

    <<element name="entry" content="EMPTY">
        <targetClass>com.jxml.quick.examples.timesheet.Entry</targetClass>
        .
        . <!--attribute elements-->
        .
    </element">

</qjml>

In this fragment of the QJML binding schema for the timesheet markup language, we have now specified and bound three elements: timesheet, day, and entry.

The assignment of EMPTY to the content attribute on the specification of the entry element indicates that this element will contain neither text nor elements.

 

Attributes

An element element has the following attributes:

 

Content Model

An element element contains the following elements:

 

 
ELEMENT: attribute
DTD: <!ELEMENT attribute (rem*, (targetEditor|targetClass|targetFactory)?, value*)> <!ATTLIST attribute name CDATA #REQUIRED type (id,idref,int,short,long,byte, boolean,float,double,string, base64,url,char,BigDecimal) #IMPLIED status (REQUIRED,FIXED) #IMPLIED value CDATA #IMPLIED field CDATA #IMPLIED property CDATA #IMPLIED class CDATA #IMPLIED> QDML: <element name="attribute"> <attribute name="name" status="REQUIRED"/> <attribute name="type" field="type"> <value>id</value> <value>idref</value> <value>int</value> <value>short</value> <value>long</value> <value>byte</value> <value>boolean</value> <value>float</value> <value>double</value> <value>string</value> <value>base64</value> <value>url</value> <value>char</value> <value>BigDecimal</value> </attribute> <attribute name="status"> <value>REQUIRED</value> <value>FIXED</value> </attribute> <attribute name="value"/> <attribute name="field"/> <attribute name="property"/> <attribute name="class"/> <child element="rem" optional="True" repeating="True"/> <selection optional="True"> <child element="targetEditor"/> <child element="targetClass"/> <child element="targetFactory"/> </selection> <child element="value" optional="True" repeating="True"/> </element>

 

The attribute element specifies the validation requirements, the binding of an XML attribute, and the relationship between the object bound to the attribute and the object bound to the parent element.

The QJML attribute differs from the QDML attribute:

 

Sample XML

<timesheet name="Bill la Forge">
    <day date="19990913">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990914">
        <entry hours="6" project="quite"/>
        <entry hours="2" project="admin"/>
    </day>
    <day date="19990915">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990916">
        <entry hours="8" project="vacation"/>
    </day>
    <day date="19990917">
        <entry hours="8" project="quite"/>
    </day>
</timesheet>

QDML

<qdml root="timesheet">

    <element name="timesheet">
        <attribute name="name"
                   status="REQUIRED"/>
        .
        . <!--child, selection, and sequence elements-->
        .
    </element">

    <element name="day">
        <attribute name="date"
                   status="REQUIRED"/>
        .
        . <!--child, selection, and sequence elements-->
        .
    </element">

    <element name="entry"
             content="EMPTY">
        <attribute name="hours"
                   status="REQUIRED"/>
        <attribute name="project"
                   status="REQUIRED"/>
    </element">

</qdml>

QJML

<qjml root="timesheet">

    <element name="timesheet">
        <targetClass>com.jxml.quick.examples.timesheet.Timesheet</targetClass>
        <attribute name="name"
                   status="REQUIRED"
                   type="string"
                   field="name"/>
        .
        . <!--child, selection, and sequence elements-->
        .
    </element">

    <element name="day">
        <targetClass>com.jxml.quick.examples.timesheet.Day</targetClass>
        <attribute name="date"
                   status="REQUIRED"
                   field="date">
            <targetEditor target="com.jxml.quick.examples.timesheet.Date"
                          editor="com.jxml.quick.examples.timesheet.YYYYMMDDEditor"/>
        </attribute>
        .
        . <!--child, selection, and sequence elements-->
        .
    </element">

    <element name="entry"
             content="EMPTY">
        <targetClass>com.jxml.quick.examples.timesheet.Entry</targetClass>
        <attribute name="hours"
                   status="REQUIRED"
                   type="float"
                   field="hours"/>
        <attribute name="project"
                   status="REQUIRED"
                   type="string"
                   field="project"/>
    </element">

</qjml>

This QJML fragment binds the attributes used in the timesheet markup language:

 

Attributes

An attribute element has the following attributes:

 

Content Model

An attribute element contains the following elements:

 

 
ELEMENT: rem
DTD: <!ELEMENT rem (#PCDATA)> QDML: <element name="rem" content="PCDATA"/>

 

The rem element is used to describe elements and attributes.

The QJML rem is identical to the QDML rem.

 

 
ELEMENT: value
DTD: <!ELEMENT value (#PCDATA)> QDML: <element name="value" content="PCDATA"/>

 

The value element enumerates through the legal values of an attribute.

The QJML value is identical to the QDML value.

 

 
ELEMENT: child
DTD: <!ELEMENT child EMPTY> <!ATTLIST child label CDATA #IMPLIED element CDATA #REQUIRED optional CDATA "False" repeating CDATA "False" field CDATA #IMPLIED property CDATA #IMPLIED class CDATA #IMPLIED listField CDATA #IMPLIED listProperty CDATA #IMPLIED> QDML: <element name="child" content="EMPTY"> <attribute name="label"/> <attribute name="element" status="REQUIRED"/> <attribute name="optional" value="False"/> <attribute name="repeating" value="False"/> <attribute name="field"/> <attribute name="property"/> <attribute name="class"/> <attribute name="listField"/> <attribute name="listProperty"> </element>

 

A child element is used to specify a child element that is contained within the content model of another element and to describe the relationship between the child and parent objects bound to the these elements.

 

Sample XML

<timesheet name="Bill la Forge">
    <day date="19990913">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990914">
        <entry hours="6" project="quite"/>
        <entry hours="2" project="admin"/>
    </day>
    <day date="19990915">
        <entry hours="8" project="quite"/>
    </day>
    <day date="19990916">
        <entry hours="8" project="vacation"/>
    </day>
    <day date="19990917">
        <entry hours="8" project="quite"/>
    </day>
</timesheet>

QDML

<qdml root="timesheet">

    <element name="timesheet">
        <attribute name="name"
                   status="REQUIRED"/>
        <child element="day"
               repeating="True"/>
    </element">

    <element name="day">
        <attribute name="date"
                   status="REQUIRED"/>
        <child element="entry"
               repeating="True"/>
    </element">

    <element name="entry"
             content="EMPTY">
        <attribute name="hours"
                   status="REQUIRED"/>
        <attribute name="project"
                   status="REQUIRED"/>
    </element">

</qdml>

QJML

<qjml root="timesheet">

    <element name="timesheet">
        <targetClass>com.jxml.quick.examples.timesheet.Timesheet</targetClass>
        <attribute name="name"
                   status="REQUIRED"
                   type="string"
                   field="name"/>
        <child element="day"
               repeating="True"
               listField="days"/>
    </element">

    <element name="day">
        <targetClass>com.jxml.quick.examples.timesheet.Day</targetClass>
        <attribute name="date"
                   status="REQUIRED"
                   field="date">
            <targetEditor target="com.jxml.quick.examples.timesheet.Date"
                          editor="com.jxml.quick.examples.timesheet.YYYYMMDDEditor"/>
        </attribute>
        <child element="entry"
               repeating="True"
               listField="entries"/>
    </element">

    <element name="entry"
             content="EMPTY">
        <targetClass>com.jxml.quick.examples.timesheet.Entry</targetClass>
        <attribute name="hours"
                   status="REQUIRED"
                   type="float"
                   field="hours"/>
        <attribute name="project"
                   status="REQUIRED"
                   type="string"
                   field="project"/>
    </element">

</qjml>

Here we have the complete QJML binding schema for the timesheet markup language. We have now bound the content model of the timesheet element to the public days variable of the Timesheet class and we have bound the content model of the day element to the public entries variable of the Day class.

 

Attributes

 

Content Model: EMPTY

 

 
ELEMENT: selection
DTD: <!ELEMENT selection ((child|selection|sequence|cref)+)> <!ATTLIST selection label CDATA #IMPLIED optional CDATA "False" repeating CDATA "False" field CDATA #IMPLIED property CDATA #IMPLIED class CDATA #IMPLIED listField CDATA #IMPLIED listProperty CDATA #IMPLIED> QDML: <element name="selection"> <attribute name="label"/> <attribute name="optional" value="False"/> <attribute name="repeating" value="False"/> <attribute name="field"/> <attribute name="property"/> <attribute name="class"/> <attribute name="listField"/> <attribute name="listProperty"> <selection repeating="True"> <child element="child"/> <child element="selection"/> <child element="sequence"/> <child element="cref"/> </selection> </element>

 

The sequence element is used to introduce alternatives to the content model and to describe the relationship between child objects and the parent object which contains them.

 

Sample XML

    <automobile>
        <standardTransmission/>
    </automobile>

QDML

    <element name="automobile">
        <selection>
            <child element="standardTransmission"/>
            <child element="automaticTransmission"/>
        </selection>
    </element">

QJML

    <element name="automobile">
        <targetClass>Auto</targetClass>
        <selection property="transmission">
            <child element="standardTransmission"/>
            <child element="automaticTransmission"/>
        </selection>
    </element">

Java

    public class Auto
    {
        protected Transmission trans;

        public Transmission getTransmission()
        {
            return trans;
        }

        public void setTransmission(Transmission t)
        {
            trans=t;
        }
    }

    public class StandardTransmission implements Transmission
    {
        .
        .
        .
    }

    public class AutomaticTransmission implements Transmission
    {
        .
        .
        .
    }

Here we see a QJML fragment which identifies a JavaBean property, transmission, as the means for connecting the children of Auto. When expressing an Auto object in XML, Quick will make use of the Java instanceof operator to determine which element to express as the child of the automobile element.

 

Attributes

 

Content Model

The child, selection, sequence, and cref elements are used to specify alternative content models.

These elements are optional, repeatable, and can occur in any order, so long as there is at least one child, selection, sequence, or cref element present in the selection element content.

 

 
ELEMENT: sequence
DTD: <!ELEMENT sequence ((child|selection|sequence|cref)+)> <!ATTLIST sequence label CDATA #IMPLIED optional CDATA "False" repeating CDATA "False" class CDATA #IMPLIED listField CDATA #IMPLIED listProperty CDATA #IMPLIED> QDML: <element name="sequence"> <attribute name="label"/> <attribute name="optional" value="False"/> <attribute name="repeating" value="False"/> <attribute name="class"/> <attribute name="listField"/> <attribute name="listProperty"> <selection repeating="True"> <child element="child"/> <child element="selection"/> <child element="sequence"/> <child element="cref"/> </selection> </element>

 

The sequence element lets us define sequences in the content model and to describe the relationship between child objects and the parent object which contains them.

 

Sample XML

<map name="Bill la Forge">
    <key>Fred Smith</key>
    <ssn>101-33-9320</ssn>
    <key>John Spade</key>
    <ssn>221-56-7890</ssn>
    <key>Big Little, Inc.</key>
    <cid>04-98789234</cid>
</map>

QDML

<qdml root="map">

    <element name="map">
        <sequence optional="True"
                  repeating="True">
            <child element="key"/>
            <selection>
                <child element="ssn"/>
                <child element="opaque"/>
            </selection>
        </sequence>
    </element>

    <element name="key"
             content="PCDATA"/>

    <element name="ssn"
             content="PCDATA"/>

    <element name="opaque"
             wild="True">
             content="BIMODAL">
        <attribute name="#ANY"/>
        <child element="opaque"
               optional="True" 
               repeating="True"/>
    </element>

</qdml>

QJML

<qjml root="map">

    <element name="map">
        <targetClass>java.util.ArrayList</targetClass>
        <sequence optional="True"
                  repeating="True"
                  class="com.jxml.quick.access.QListAccess">
            <child element="key"/>
            <selection>
                <child element="ssn"/>
                <child element="opaque"/>
            </selection>
        </sequence>
    </element>

    <element name="key"
             content="string"/>

    <element name="ssn"
             content="string"/>

    <element name="opaque"
             wild="True">
             content="BIMODAL">
        <targetClass>com.jxml.quick.QDOMEleImpl</targetClass>
        <attribute name="#ANY"
                   class="com.jxml.quick.access.QDOMAttAccess">
            <targetClass>com.jxml.quick.QDOMAtt</targetClass>
        </attribute>
        <child element="opaque"
               optional="True" 
               repeating="True"
               listProperty="QElements"/>
    </element>

</qjml>

Here we see a QJML schema for a MAP markup language. When a map document is parsed, Quick builds an ArrayList object. The ArrayList will always have an even number of entries, the odd entries being Strings created from the key elements. When the even entry is a String, the input was a ssn element; otherwise the even entry will be an instance of the QDOMEleImpl class.

 

Attributes

 

Content Model

The child, selection, sequence, and cref elements are used to specify a series of content models.

These elements are optional, repeatable, and can occur in any order, so long as there is at least one child, selection, sequence, or cref, element present in the sequence element content.

 

 
ELEMENT: cref
DTD: <!ELEMENT cref (#PCDATA)> QDML: <element name="cref" content="PCDATA"/>

 

The cref element is used to reference a child, selection, or sequence element used in the definition of another element.

 

Attributes: none

 

Content Model

The content of a cref element is the label of the child, selection, or sequence element being referenced.

 

 <Quick>  <JXML>  <Download>  <QDML>