Using the Source Code Generator
Documentation Author(s): Keith Visco Arnaud Blandin
API Reference: The Source Builder API News Source generation & Java 5.0 Introduction Source Generator Options Command Line Options
Collection Types XML Schema
News
Source generation & Java 5.0
Since release 1.0.2, the Castor source generator now supports the
generation of Java 5.0 compliant code. The generated code - with the
new feature enabled - will make use of the following Java 5.0-specific
artefacts:
|
- | Use of parameterized collections, e.g. ArrayList<String>. |
- | Use of @Override annotations with the generated methods
that require it. |
- | Use of @SupressWarnings with "unused" method parameters
on the generated methods that needed it. |
- | Added "enum" to the list of reserved keywords. |
To enable this feature (off by default), please uncomment the
following property in your custom castorbuilder.properties
file:
# This property specifies whether the sources generated
# should comply with java 1.4 or 5.0; defaults to 1.4
org.exolab.castor.builder.javaVersion=5.0
|
|
Introduction
Castor's Source Code Generator creates
a set of Java classes
which represent an object model for an XML Schema
(W3C XML Schema, 20010502 Recommendation)1, as well as the
necessary Class Descriptors used by the marshalling framework
to obtain information about the generated classes.
|
Currently the generated source files will need to be compiled. We
will be adding an Ant taskdef eventually to handle this automatically.
|
|
Example: |
java org.exolab.castor.builder.SourceGeneratorMain -i foo-schema.xsd \
-package com.xyz
|
|
This will generate a set of source files from the the XML Schema, foo-schema.xsd,
and place them in the com/xyz/* package.
To compile the generated classes simply run javac, or your favorite compiler:
Created class will have marshal and unmarshal methods which are used to go back
and forth between XML and an Object instance.
Source Generator Options
Tip: | For additional information about the Source Generator and options, you can
download the Source Generator User
Document(PDF). Please note that the usage of the binding file is
not dicussed in that document. |
|
The source code generator has a number of different options which
may be set. Some of these are done using the command line, and
others are done using a properties file located at
"org/exolab/castor/builder/castorbuilder.properties".
Command Line Options
Option |
Args |
Description |
Optional? |
i |
filename |
The input XML Schema file |
Required |
package |
package-name |
The package for the generated source |
Optional |
dest |
path |
The destination in which to put the generated source |
Optional |
line-separator |
unix | mac | win |
Sets the line separator style for the desired platform. This is
useful if you are generating source on one platform, but will
be compiling/modifying on another platform. |
Optional |
types |
type-factory |
Sets which type factory to use. This is useful if you want JDK 1.2
collections instead of JDK 1.1 or if you want to pass in your own
FieldInfoFactory (see Collection types).
|
Optional |
h |
|
Shows the help/usage screen. |
Optional |
f |
|
Forces the source generator to supress all non-fatal errors, such
as overwriting of pre-existing files. |
Optional |
nodesc |
|
Do not generate the class descriptors |
Optional |
nomarshall |
|
Do not generate the marshalling framework methods (marshall, unmarshall, validate) |
Optional |
testable |
|
Generate the specific methods used by the Castor Marshalling Framework |
Optional |
sax1 |
|
Generate marshalling methods that are using SAX1 framework (default is false). |
Optional |
binding-file | The binding file name. |
Allows the setting of a Binding File to allow a fine-grained control
the classes generated |
Optional |
generateImportedSchemas |
|
Generates automatically sources for imported XML Schemas (default is false). |
Optional |
case-insensitive |
|
The generated classes will use a case insensitive method for looking up
enumerated type values. |
Optional |
|
Collection Types
The source code generator has the ability to use the following types
of collections when generating source code:
|
Type |
Value |
Default |
Java 1.1 |
default |
java.util.Vector |
Java 1.2 |
-type j2 |
java.util.Collection |
ODMG 3.0 |
-types odmg |
odmg.DArray |
|
You can also write your own FieldInfoFactory to handle specific collection
types. All you have to do is to pass in the fully qualified name of
that FieldInfoFactory as follows:
-types com.personal.MyCoolFactory |
|
XML Schema
The input file to the source code generator is an XML Schema2.
The current supported version is the W3C XML Schema Recommendation1.
For more information about XML Schema Support, check the XML Schema page
1Castor 0.9.4.1 uses XML Schema Recommendation 20010502
2XML Schema is a W3C Recommendation
3XPath is a W3C Recommendation
|