The Java generator supports various options shown in Table 7.1.2.1[Java options].
option | function | value | default |
---|---|---|---|
java | Executes the Java generator. | true | false | true |
java.jaxp | Uses JAXP as an XML processor to access xml documents. | true | false | true |
java.jaxp.validation | Enables the JAXP validation function. | true | false | false |
java.jaxp.dtd | Uses the DTD in the resource for JAXP validation. | true | false | false |
java.xml.pi | Uses processing instructions in a Relaxer object. | true | false | false |
java.xml.namespace | Uses namespace in a Relaxer object. | true | false | false |
java.xml.element | Retains source DOM elements in a Relaxer object. | true | false | false |
java.jarv.verify | Specifies the validation policy for JARV validation framework. 'auto' means automatic selection. 'rng' means RELAX NG. 'rxm' means RELAX Core. 'rxg' means RELAX Namespace. 'dtd' means DTD. 'xsd' means XML Schema. none' means no validation using JARV. | auto | rng | rxm | dtd | xsd | none | none |
java.verify | Enables the validation function in a Relaxer object. | true | false | false |
java.verify.assertion | Enables the assertion function in a Relaxer object. | true | false | false |
java.robust | Specifies the stability level for Relaxer objects. plain means no protection. stable means protecting for structural illegalness. protect means for both structural and data value illegalness. |
plain | stable | protect | plain |
java.sax | Enables the saxInput and saxOutput facility. | true | false | false |
java.sax.input | Enables a SAX event for Relaxer objects construction. | true | false | false |
java.sax.output | Enables a SAX event output facility. | true | false | false |
java.sax.version | Specifies a sax version. | 2 | 1 | 2 |
java.text | Enables a text output facility. | true | false | true |
java.pattern.factory | Enables a factory facility in Relaxer objects. | true | false | false |
java.pattern.composite | Enables a composite facility in Relaxer objects. | true | false | false |
java.pattern.visitor | Enables a visitor facility in Relaxer objects. | true | false | false |
java.pattern.visitor.style | Specifies a visitor style. light means to use lightweight simple visitor. plain means to use default visitor, which is easy to use and has enough functionality for ordinary operation. heavy means to use heavyweight visitor. |
light | plain | heavy | plain |
java.pattern.interpreter | Enables an interpreter facility in Relaxer objects. | true | false | false |
java.pattern.context | Enables a context facility in Relaxer objects. | true | false | false |
java.idmap | Enables an idmap facility in Relaxer objects. | true | false | false |
java.pathlist | Enables a pathlist facility in Relaxer objects. | true | false | false |
java.package | Specifies package name for Relaxer objects. | Package name | - |
java.package.provider | Specifies package name for service providers. | Package name | - |
java.name.style | Specifies a name style of Relaxer objects. java means java style naming convension. c means C style naming convension. |
java | c | java |
java.name.class.prefix | Specifies a prefix name for class name of Relaxer objects. | A prefix name | - |
java.name.class.prefixes | Specifies prefix names for class name of Relaxer objects. | A prefix name definition | - |
java.data.config | Specifies a configuration for data mapping. | A file name | - |
java.data.profile | Specifies a profile for data mapping. | A file name | - |
Formal name of options would be pretty long to represent meaning of option. To specify options more conveniently, some options has nick names shown as Table 7.1.2.2[Nicknames].
Nickname | Formal Option |
---|---|
sax | java.sax |
text | java.text |
factory | java.pattern.factory |
composite | java.pattern.composite |
visitor | java.pattern.visitor |
visitor.style | java.pattern.visitor.style |
interpreter | java.pattern.interpreter |
context | java.pattern.context |
idmap | java.pattern.idmap |
pathlist | java.pathlist |
package | java.package |
package.provider | java.package.provider |
classPrefix | java.name.class.prefix |
classPrefixes | java.name.class.prefixes |
In the reference manual, two types of schemas are used. One is a plain shcema, which does not use a namespace. Another one is a namespace schema, which uses a namespace.
If nessesary, these base schemas are altered for explanatory purposes. You can recognize more deeply to see what part of a schema is modified for explanation.
List 7.1.3.1.1[base.rng] is a base schema that does not use a namespace. This schema is used because it is simple enough to recognize and complex enough to explain an option's feature.
<grammar xmlns="http://relaxng.org/ns/structure/1.0" 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"> <data type="int"/> </element> <element name="owner"> <data type="token"/> </element> <optional> <ref name="address"/> </optional> <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>
List 7.1.3.1.2[base.xml] is an XML document that is valid with regard to the schema.
<account accountNo="12345"> <balance>102030</balance> <owner>XML Taro</owner> <address zip="213">Yokohama</address> <phone area="123">456-7890</phone> <phone area="090">123-4567</phone> </account>
List 7.1.3.2.1[baseNs.rng] is a base schema that uses a namespace.
This schema is an extension from the plain schema shown in
List 7.1.3.1.1[base.rng].
The namespace name is http://example.com/account
, which is
specified in the element grammar
.
This schema is used when a namespace is an importernt factor.
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="http://example.com/account"> <start> <ref name="account"/> </start> <define name="account"> <element name="account"> <attribute name="accountNo"> <data type="token"/> </attribute> <element name="balance"> <data type="int"/> </element> <element name="owner"> <data type="token"/> </element> <optional> <ref name="address"/> </optional> <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>
There are two sort of XML documents to explain. One is not using a prefix. Another one is using a prefix.
List 7.1.3.2.2[baseNs.xml] is an XML document for the shcema.
In this document, an explicit prefix is not used.
The namespace is declared as a default namespace with
http://example.com/account
.
<account xmlns="http://example.com/account" accountNo="12345"> <balance>102030</balance> <owner>XML Taro</owner> <address zip="213">Yokohama</address> <phone area="123">456-7890</phone> <phone area="090">123-4567</phone> </account>
When a prefix is an important issue, List 7.1.3.2.3[baseNsPrefix.xml] is
also used for a document.
In the document, prefix z
is declared
with the namespace http://example.com/account
.
<z:account xmlns:z="http://example.com/account" accountNo="12345"> <z:balance>102030</z:balance> <z:owner>XML Taro</z:owner> <z:address zip="213">Yokohama</z:address> <z:phone area="123">456-7890</z:phone> <z:phone area="090">123-4567</z:phone> </z:account>
List 7.1.3.3.1[Base.java] is a Java program that explains target features.
This program composed of three static methods,
main
, makeAccount
, and printAccount
.
The main
method is a main routine for the program.
The method handles command line parameters and controls
work flows.
The makeAccount
method creates an instance of the
Relaxer object Account
.
When such an option is related to object creation,
this method will be modified.
The printAccount
method prints the contents of the
Account
object.
This method demonstrates effects of the option.
The showAccount
method prints an Relaxer Object itself.
Normally an XML document is showed.
import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import org.xml.sax.SAXException; public class Base { public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException { String uri = args[0]; Account account = makeAccount(uri); printAccount(account); showAccount(account); } private static Account makeAccount(String uri) throws IOException, SAXException, ParserConfigurationException { System.out.println("*** makeAccount ***"); Account account = new Account(uri); return (account); } private static void printAccount(Account account) { System.out.println("*** printAccount ***"); String accountNo = account.getAccountNo(); long balance = account.getBalance(); String owner = account.getOwner(); System.out.println("AccountNo:" + accountNo); System.out.println("Balance:" + balance); System.out.println("Owner:" + owner); Address address = account.getAddress(); if (address != null) { String zip = address.getZip(); String place = address.getContent(); System.out.println("Address: [" + zip + "] " + place); } Phone[] phones = account.getPhone(); for (int i = 0;i < phones.length;i++) { Phone phone = phones[i]; String area = phone.getArea(); String number = phone.getContent(); System.out.println("Phone: [" + area + "] " + number); } } private static void showAccount(Account account) { System.out.println("*** showAccount ***"); System.out.println("XML:" + account); } }