The extention syntax dataClass
attribute specifies a class name
for data in Java.
A target for the dataClass attribute is data.
The dataClass attribute takes a string value for a Java class name of target data.
A implementation class for the target property
will be the Java class or interface specified by
the dataClass
attribute.
List 8.6.4.1[grammarDataClass.rng] is a sample schema for the dataClass attribute.
There are two places where the dataClass
attribute are used.
One place is the definition of the balance
element.
In this case, a datatype of the property balance
will be
"?" instead of "?".
<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:dataClass="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.6.4.2[MyBalance.java] and
a MyOwner
shown in List 8.6.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
.
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)); } }
public interface IMyOwner { }
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)); } }