Powered by SmartDoc

dataType

The extention syntax dataType specifies a datatype name for data in Java.

Target

A target of the dataType attribute is the data.

Parameters

The dataType attribute takes a string value for a Java class or a Java interface name of the target data.

If the dataType attribute takes the Java interface There are two options to create a concrete object with regard to the Java interface:

  1. Uses the dataClass attribute
  2. Uses the factory option and creates a concrete object in the factory object.

Artifact

A implementation type for the target property will be the Java class or interface specified by the dataType attribute.

Example

List 8.5.4.1[grammarDataType.rng] is a sample schema for the dataType attribute.

There are two places where the dataType attribute are used. One place is the definition of the balance element. In this case, a datatype of the property balance will be MyBalance instead of int.

Another one is the definition of the owner element. In this case, a datatype of the property balance will be IMyOwner instead of String.

grammarDataType.rng
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:java="http://www.relaxer.org/xmlns/relaxer/java"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <start>
    <ref name="account"/>
  </start>
  <define name="account">
    <element name="account">
      <attribute name="accountNo">
        <data type="token"/>
      </attribute>
      <element name="balance" java:dataType="MyBalance">
        <data type="int"/>
      </element>
<element name="owner" java:dataType="IMyOwner" java:dataClass="MyOwner">
        <data type="token"/>
      </element>
      <ref name="address"/>
      <zeroOrMore>
        <ref name="phone"/>
      </zeroOrMore>
    </element>
  </define>
  <define name="address">
    <element name="address">
      <attribute name="zip">
        <data type="token"/>
      </attribute>
      <text/>
    </element>
  </define>
  <define name="phone">
    <element name="phone">
      <attribute name="area">
        <data type="token"/>
      </attribute>
      <data type="token"/>
    </element>
  </define>
</grammar>

A MyBalance shown in List 8.5.4.2[MyBalance.java] and a MyOwner shown in List 8.5.4.4[MyOwner.java] are sample user defined classes. And a IMyOwner shown in List 8.5.4.3[IMyOwner.java] is a sample user defined interface. The MyOwner implements IMyOwner.

MyBalance.java
import java.io.Serializable;

public class MyBalance implements Cloneable, Serializable {
    private String data;

    public MyBalance(String data) {
	this.data = data;
    }

    public String toString() {
	return (data);
    }

    public Object clone() {
	return (new MyBalance(data));
    }
}
IMyOwner.java
public interface IMyOwner {
}
MyOwner.java
import java.io.Serializable;

public class MyOwner implements IMyOwner, Cloneable, Serializable {
    private String data;

    public MyOwner(String data) {
	this.data = data;
    }

    public String toString() {
	return (data);
    }

    public Object clone() {
	return (new MyBalance(data));
    }
}