Oracle9i Supplied Java Packages Reference Release 2 (9.2) Part Number A96609-01 |
|
This chapter describes package oracle.xml.classgen, which contains the classes for the XML Class Generator in the Oracle9i XDK for Java. A class generator is a utility that accepts an input file and creates a set of output classes that have corresponding functionality. For the XML Class Generator, the input file is a DTD and the output is a series of classes that can be used to create XML documents conforming with the DTD.
This chapter contains these sections:
The XML Class Generator for Java creates Java source files from an XML DTD or XML Schema. This is useful when an application wants to send an XML message to another application based on an agreed-upon DTD or Schema, or as the back end of a Web form to construct and XML document. Using these classes, Java applications can construct, validate, and print XML documents that comply with the input DTD or Schema. The Class Generator works in conjunction with the Oracle XML Parser for Java, which parses the DTD or Schema and passes the parsed document to the class generator.
For more information, refer to Oracle resources for the XDK for Java on the Oracle Technology Network (OTN) Web site.
This class serves as the base document class for the DTD class Generator generated classes.
public abstract class CGDocument extendsoracle.xml.classgen.CGNode
implements java.io.Externalizableoracle.xml.classgen.CGNode
| +--oracle.xml.classgen.CGDocument
java.io.Externalizable, java.io.Serializable
Method | Description |
---|---|
Constructor for the root element of the DTD. |
|
Prints the constructed XML document. |
|
Reads the compressed stream and creates the object corresponding to the root element. |
Constructor for the root element of the DTD.
protected CGDocument( java.lang.String doctype,
oracle.xml.parser.v2.DTD dtd);
doctype |
Name of the root Element of the DTD. |
dtd |
The DTD used to generate the classes. |
Prints the constructed XML Document. Throws InvalidContentException
if the document's content does not match the grammer specified by DTD; the validation mode should be set to TRUE. See also setValidationMode()
in DTDClassGenerator Class. The options are described in the following table.
out |
Output stream to which the document will be printed. |
enc |
Encoding of the output stream. |
Reads the compressed stream and creates the object corresponding to the root element. Used for instantiating the generated classes with XML instance document.
protected void readExternal( java.io.ObjectInput inArg,
oracle.xml.comp.CXMLContext cxmlContext);
in |
ObjectInput stream passed to read the compressed stream |
cxmlContext |
The context of the compressed stream |
This class serves as the base class for the classes corresponding to the nodes of XML document generated by the DTD class generator.
public abstract class CGNode oracle.xml.classgen.CGNode
CGDocument
protected boolean isValidating
Boolean to indicate the validating mode.
Constructor for the Elements of the DOM Tree.
protected CGNode( java.lang.String elementName);
elementName |
Name of the element. |
Adds CDATA Section to the Element. Throws InvalidContentException
if theData
has illegal characters; validation must be set to TRUE. See also setValidationMode()
in DTDClassGenerator Class.
protected void addCDATASection( java.lang.String theData);
theData |
Text to be added as CDATA Section to the element. |
Adds PCDATA to the element node. Throws InvalidContentException
if theData
has illegal characters; validation must be set to TRUE. See also setValidationMode()
in DTDClassGenerator Class.
protected void addData( java.lang.String theData);
theData |
Text to be added a to the element. |
Adds a node as a child to the element. Throws InvalidContentException
if theData
has illegal characters; validation must be set to TRUE. See also setValidationMode()
in DTDClassGenerator Class.
protected void addNode( CGNode
theNode);
theNode |
The node to be added as child. |
Deletes PCDATA from the element node. Throws InvalidContentException
if theData
has illegal characters; validation must be set to TRUE. See also setValidationMode()
in DTDClassGenerator Class.
protected void deleteData( java.lang.String theData);
theNode |
Text to be deleted from an element. |
Returns the value of the attribute.
protected java.lang.String getAttribute( java.lang.String attName);
attName |
Name of the attribute. |
Gets the base document (root Element).
protected CGDocument
getCGDocument();
Gets the PCDATA of the Element. Throws InvalidContentException
if the data is not present.
protected java.lang.String getData();
Retrieves the static DTD from the base CGDocument.
protected abstract oracle.xml.parser.v2.DTD getDTDNode();
Retrieves the XMLElement node corresponding to this CGNode.
protected oracle.xml.parser.v2.XMLElement getElementNode();
Retrieves the CGNode which is one of the children of the element corresponding to the node whose name matches the input string.
protected java.lang.Object getNode(java.lang.String theNode);
theNode |
The name of the string corresponding to the CGNode returned. |
Reads the compressed stream and instantiate the corresponding node. Throws the following exceptions:
IOException |
When an IO Error occurs |
ClassNotFoundException |
When the corresponding class could not be instantiated. |
protected void readExternal(oracle.xml.io.XMLObjectInput in,
oracle.xml.comp.CXMLContext cxmlContext)
in |
The |
cxmlContext |
The context of the compressed stream. |
Sets the value of the attribute.
protected void setAttribute(java.lang.String attName,
java.lang.String value);
attName |
Name of the attribute. |
value |
Value of the attribute. |
Sets the base document (root element).
public void setDocument( CGDocument
d);
d |
Base CGDocument. |
Sets the XMLElement node corresponding to this CGNode.
protected void setElementNode(oracle.xml.parser.v2.XMLElement node);
node |
The XMLElement. |
Store this value for an ID identifier, which can be verified with IDREF values.
protected void storeID(java.lang.String attName,
java.lang.String id);
attName |
Name of the ID attribute. |
id |
Value of the ID |
Store this value for an IDREF identifier, which can be verified by the corresponding ID.
protected void storeIDREF( java.lang.String attName,
java.lang.String idref);
attName |
Name of the IDREF attribute. |
idref |
Value of the IDREF |
Checks if the content of the element is valid according to the Content Model specified in DTD.
protected void validateContent();
Checks if the ENTITY identifier is valid. Returns TRUE
if ENTITY is valid, FALSE
otherwise.
protected boolean validEntity( java.lang.String entity);
name |
Value of the ENTITY attribute |
Checks if the ID identifier is valid. Returns TRUE
if ID is valid, FALSE
otherwise.
protected boolean validID( java.lang.String name);
name |
Value of the ID attribute. |
Checks if the NMTOKEN identifier is valid. Returns TRUE
if NMTOKEN is valid, FALSE
otherwise.
protected boolean validNMTOKEN( java.lang.String name);
name |
Value of the NMTOKEN attribute. |
Writes the compressed stream corresponding to this node.
protected void writeExternal( oracle.xml.io.XMLObjectOutput out,
oracle.xml.comp.CXMLContext cxmlContext);
out |
ObjectOutput stream to write the compressed data. |
cxmlContext |
The context of the compressed stream. |
This class serves as the base class for the all the generated classes corresponding to the XML Schema generated by Schema Class Generator.
public abstract class CGXSDElement extends java.lang.Object java.lang.Object | +--oracle.xml.classgen.CGXSDElement
Field | Syntax | Description |
---|---|---|
type |
protected java.lang.Object type |
Type information of a node |
Default constructor.
public CGXSDElement();
Adds the attribute of a given node to the hashtable.
protected void addAttribute(java.lang.String attName,
java.lang.Object attValue);
attName |
The attribute name. |
attValue |
The attribute value. |
Adds the local elements of an element node to the vector correspondig to the elements.
protected void addElement( java.lang.Object elem);
elem |
The object which needs to be added. |
Returns the attributes as a hashtable of attribute names and values.
public java.util.Hashtable getAttributes();
Retrieves the vector of all local elements.
public java.util.Vector getChildElements();
Returns the value of the node.
public java.lang.String getNodeValue();
Prints an element node. Throws an IOException
if not able to print to the output stream
public void print( oracle.xml.parser.v2.XMLOutputStream out);
out |
The XMLObjectOutput stream to which the output is printed. |
Prints an attribute node. Throws an IOException
if not able to print to the XMLObjectOutput
stream.
public void printAttributes( oracle.xml.parser.v2.XMLOutputStream out,
java.lang.String name,
java.lang.String namespace);
out |
The XMLObjectOutput stream to which the output is printed. |
name |
The attribute name |
namespace |
The namespace |
Sets the node value of an element.
protected void setNodeValue( java.lang.String value);
value |
The node vale. |
Generates the data binding classes corresponding to a DTD or an XML file based on a DTD.
public class DTDClassGenerator extends java.lang.Object java.lang.Object | +--oracle.xml.classgen.DTDClassGenerator
Default constructor for DTDClassGenerator.
public DTDClassGenerator();
Traverses the DTD with element doctype
as root and generates Java classes.
public void generate( oracle.xml.parser.v2.DTD dtd,
java.lang.String doctype);
DTD |
The DTD used to generate the classes. |
doctype |
Name of the root element. |
Sets the switch to determine whether to generate java doc comments for the generated classes. Default value is TRUE.
public void setGenerateComments(boolean comments);
comments |
The boolean flag for turning on/off the java doc comment generation. |
Sets the package for the classes generated. Default - no package set.
public void setJavaPackage( java.util.Vector packageName);
packageName |
Name of the package. |
Sets the output directory where the java source code for the DTD is generated. Default value is the current directory.
public void setOutputDirectory( java.lang.String dir);
dir |
Output directory. |
Sets the switch to determine if the DTD should be saved as a serialized object or as text file. Serializing the DTD improves the performance when the generated classes are used to author XML files.
public void setSerializationMode( boolean yes);
yes |
The boolean falg for turning on/off saving of DTD as serialized object ( |
Sets the switch to determine whether the classes generated should validate the XML document being constructed. Default value is TRUE
.
public void setValidationMode( boolean yes);
yes |
The boolean falg for turning on/off validation of XML document. Default is |
Defines the Exception thrown by DTD ClassGenerator and Schema Class Generator.
public class InvalidContentException extends java.lang.Exception java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--oracle.xml.classgen.InvalidContentException
java.io.Serializable
Constructor. The options are described in the following table.
s |
String that contains the information about the exception. |
Provides a command-line interface to generate java classes corresponding to the DTD or XML
public class oracg extends java.lang.Object java.lang.Object | +--oracle.xml.classgen.oracg
This class generates the classes corresponding to an XML Schema.
public class SchemaClassGenerator extends java.lang.Object java.lang.Object | +--oracle.xml.classgen.SchemaClassGenerator
Constructor. The options are described in the following table.
fileName |
The input XML Schema. |
Generates the Schema classes corresponding to top level elements, simpleType elements and complexType elements by calling createSchemaClass() on each of these nodes.
public void generate( oracle.xml.parser.schema.XMLSchema schema);
XML |
Schema object. |
Sets the switch to determine whether to generate java doc comments. TRUE
by default.
public void setGenerateComments(boolean comments)
comments |
Turns on/off the java doc comment generation. |
Assigns user-defined Java package name for each namespace. The Namespaces defined in the schema are queried, and their number should match the number of package names provided by the user; otherwise, an error is thrown.
public void setJavaPackage( oracle.xml.parser.schema.XMLSchema schema,
java.util.Vector pkgName);
schema |
The XML Schema |
pkgName |
A vector containing user defined package names given through command line. |
Sets the output directory where the java source code for the Schema class are generated. The current directory is the default.
public void setOutputDirectory( java.lang.String dir);
dir |
The output directory. |
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|