Powered by SmartDoc

The java.data.config option

The java.data.config option specifies a configuration name for data configuration.

Parameters

The java.data.config option takes a predefined configuration name or a configuration file name as a parameter. The Predefined configuration names are as follows:

concise
concise mapping
convenient
easy to use
object
does not use primitive datatype
precise
precise mapping
string
all string

Artifacts

The java.data.config option generates no additional classes.

The java.data.config option adds no additional methods to Relaxer objects.

The string specified by a parameter of the java.data.config option is used as a configuration name for Relaxer objects.

Example

List 7.30.3.1[javaDataConfig.rng] is a sample schema for the java.data.config option.

javaDataConfig.rng
<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>
      <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>

Build

Execution of Relaxer with the java.data.config option is as follows:

$ relaxer -java -java.data.config:string javaDataConfig.rng

Because the java generator is a default generator, execution of Relaxer as shown below has the same effect:

$ relaxer -java.data.config:string javaDataConfig.rng

As a result, Relaxer generates six files:

Since the java.data.config option takes a parameter 'string', types of all properties in the Relaxer objects are java.lang.String.

List 7.30.3.1.1[JavaDataConfig.java] is a sample program for the java.data.config option.

JavaDataConfig.java
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

public class JavaDataConfig {
    public static void main(String[] args)
	throws IOException, SAXException, ParserConfigurationException {

	String uri = args[0];
	Account account = makeAccount(uri);
	printAccount(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();
	String balance = account.getBalance();
	String owner = account.getOwner();
	Address address = account.getAddress();
	String zip = address.getZip();
	String place = address.getContent();
	System.out.println("AccountNo:" + accountNo);
	System.out.println("Balance:" + balance);
	System.out.println("Owner:" + owner);
	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);
	}
	System.out.println("XML:" + account);
    }
}

Compilation of JavaDataConfig.java class is shown here:

$ javac JavaDataConfig.java

Execution

List 7.30.3.2.1[javaDataConfig.xml] is an XML document file for test.

javaDataConfig.xml
<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>

Execution of the JavaDataConfig class is shown here:

$ java JavaDataConfig javaDataConfig.xml
*** makeAccount ***
*** printAccount ***
AccountNo:12345
Balance:102030
Owner:XML Taro
Address: [213] Yokohama
Phone: [123] 456-7890
Phone: [090] 123-4567
XML:<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>