org.exolab.castor.builder

Class SourceGenerator

public class SourceGenerator extends BuilderConfiguration

A Java Source generation tool which uses XML Schema definitions to create an Object model.

Version: $Revision: 6371 $ $Date: 2006-03-30 14:58:45 -0700 (Thu, 30 Mar 2006) $

Author: Keith Visco - Main author. Arnaud Blandin - Contributions. Nathan Green - Contributions.

Field Summary
static StringAPP_DESC
The application description
static StringAPP_NAME
The application name
static StringAPP_URI
The application URI
static StringVERSION
The application version
Constructor Summary
SourceGenerator()
Creates a SourceGenerator using the default FieldInfo factory
SourceGenerator(FieldInfoFactory infoFactory)
Creates a SourceGenerator using the specific field info Factory.
SourceGenerator(FieldInfoFactory infoFactory, ExtendedBinding binding)
Creates a SourceGenerator using the specific field info Factory and the given Binding element.
Method Summary
voidgenerateSource(String filename, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
voidgenerateSource(Reader reader, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
voidgenerateSource(InputSource source, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
voidgenerateSource(Schema schema, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
static StringgetVersion()
Returns the version number of this SourceGenerator
static voidmain(String[] args)
For backwards compability, when we are called as the main() routine, delegate the command-line usage to the proper class.
booleanmappingSchemaElement2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'element' value.
booleanmappingSchemaType2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.
voidsetBinding(ExtendedBinding binding)
Sets the binding to use with this instance of the SourceGenerator.
voidsetBinding(String fileName)
Sets the binding to use given the path name of a Castor Binding File.
voidsetBinding(InputSource source)
Sets the binding to use given an InputSource identifying a Castor Binding File.
voidsetCaseInsensitive(boolean caseInsensitive)
Set to true if enumerated type lookups should be performed in a case insensitive manner.
voidsetCreateMarshalMethods(boolean createMarshalMethods)
Sets whether or not to create the XML marshalling framework specific methods (marshall, unmarshall, validate) in the generated classes.
voidsetDescriptorCreation(boolean createDescriptors)
Sets whether or not to create ClassDescriptors for the generated classes.
voidsetDestDir(String destDir)
Sets the destination directory.
voidsetFailOnFirstError(boolean failOnFirstError)
If true, the source generator will fail on the first error encountered.
voidsetGenerateImportedSchemas(boolean generate)
Sets whether or not to generate Java sources for imported XML Schema.
voidsetGenerateMappingFile(boolean generateMapping)
Sets whether or not a mapping file should be generated, this is false by default.
voidsetLineSeparator(String lineSeparator)
Sets the line separator to use when printing the source code.
voidsetMappingFilename(String filename)
Sets the filename of the mapping file.
voidsetSAX1(boolean sax1)
Set to true if SAX1 should be used in the marshal method
voidsetSuppressNonFatalWarnings(boolean suppress)
Sets whether or not to suppress non-fatal warnings encountered during source generation.
voidsetTestable(boolean testable)
Sets whether or not to implement CastorTestable
voidsetVerbose(boolean verbose)
Sets whether or not the source code generator prints additional messages during generating source code
static StringtoURIRepresentation(String path)
Returns a string which is the URI of a file.

Field Detail

APP_DESC

static final String APP_DESC
The application description

APP_NAME

static final String APP_NAME
The application name

APP_URI

static final String APP_URI
The application URI

VERSION

static final String VERSION
The application version

Constructor Detail

SourceGenerator

public SourceGenerator()
Creates a SourceGenerator using the default FieldInfo factory

SourceGenerator

public SourceGenerator(FieldInfoFactory infoFactory)
Creates a SourceGenerator using the specific field info Factory.

Parameters: infoFactory the FieldInfoFactory to use.

SourceGenerator

public SourceGenerator(FieldInfoFactory infoFactory, ExtendedBinding binding)
Creates a SourceGenerator using the specific field info Factory and the given Binding element.

Parameters: infoFactory the FieldInfoFactory to use. binding the binding element to use.

Method Detail

generateSource

public void generateSource(String filename, String packageName)
Creates Java Source code (Object model) for the given XML Schema. If the file exists, opens a FileReader and passes control to SourceGenerator.

Parameters: filename the full path to the XML Schema definition packageName the package for the generated source files

Throws: IOException if an IOException occurs writing the new source files

generateSource

public void generateSource(Reader reader, String packageName)
Creates Java Source code (Object model) for the given XML Schema. This method just passes control to SourceGenerator.

Parameters: reader the Reader with which to read the XML Schema definition. The caller should close the reader, since thie method will not do so. packageName the package for the generated source files

Throws: IOException if an IOException occurs writing the new source files

generateSource

public void generateSource(InputSource source, String packageName)
Creates Java Source code (Object model) for the given XML Schema. Parses the schema provided by the InputSource and then calls SourceGenerator to actually generate the source.

Parameters: source - the InputSource representing the XML schema. packageName the package for the generated source files

Throws: IOException if an IOException occurs writing the new source files

generateSource

public void generateSource(Schema schema, String packageName)
Creates Java Source code (Object model) for the given XML Schema. Convenience methods exist if you don't have a Schema already parsed.

Parameters: schema the XML schema to generate the Java sources for. packageName the package for the generated source files.

Throws: IOException if this Exception occurs while generating source

See Also: to provide the schema filename to provide a Reader for the schema to provide an InputSource for the schema

getVersion

public static String getVersion()
Returns the version number of this SourceGenerator

Returns: the version number of this SourceGenerator

main

public static void main(String[] args)

Deprecated: Please use (String[])

For backwards compability, when we are called as the main() routine, delegate the command-line usage to the proper class.

Parameters: args our command line arguments.

mappingSchemaElement2Java

public boolean mappingSchemaElement2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'element' value.

Returns: True if the Source Generator is mapping schema elements to Java classes.

mappingSchemaType2Java

public boolean mappingSchemaType2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.

Returns: True if the Source Generator is mapping schema types to Java classes.

setBinding

public void setBinding(ExtendedBinding binding)
Sets the binding to use with this instance of the SourceGenerator.

Parameters: binding the binding to use, null indicates that the default binding will be used.

setBinding

public void setBinding(String fileName)
Sets the binding to use given the path name of a Castor Binding File.

Parameters: fileName the file that represents a Binding

setBinding

public void setBinding(InputSource source)
Sets the binding to use given an InputSource identifying a Castor Binding File.

Parameters: source an InputSource identifying a Castor Binding File.

setCaseInsensitive

public void setCaseInsensitive(boolean caseInsensitive)
Set to true if enumerated type lookups should be performed in a case insensitive manner.

Parameters: caseInsensitive when true, enumerated type lookups will be performed in a case insensitive manner.

setCreateMarshalMethods

public void setCreateMarshalMethods(boolean createMarshalMethods)
Sets whether or not to create the XML marshalling framework specific methods (marshall, unmarshall, validate) in the generated classes. By default, these methods are generated.

Parameters: createMarshalMethods a boolean, when true indicates to generated the marshalling framework methods

setDescriptorCreation

public void setDescriptorCreation(boolean createDescriptors)
Sets whether or not to create ClassDescriptors for the generated classes. By default, descriptors are generated.

Parameters: createDescriptors a boolean, when true indicates to generated ClassDescriptors

setDestDir

public void setDestDir(String destDir)
Sets the destination directory.

Parameters: destDir the destination directory.

setFailOnFirstError

public void setFailOnFirstError(boolean failOnFirstError)
If true, the source generator will fail on the first error encountered. Otherwise, the source generator will continue on certain errors.

Parameters: failOnFirstError if true, the source generator will fail on the first error encountered.

setGenerateImportedSchemas

public void setGenerateImportedSchemas(boolean generate)
Sets whether or not to generate Java sources for imported XML Schema. By default Java sources for imported XML schemas are not generated.

Parameters: generate true to generate the java classes for the imported XML Schema

setGenerateMappingFile

public void setGenerateMappingFile(boolean generateMapping)
Sets whether or not a mapping file should be generated, this is false by default. Note that this will only be used when generation of descriptors has been disabled.

Parameters: generateMapping a flag that indicates whether or not a mapping file should be generated.

setLineSeparator

public void setLineSeparator(String lineSeparator)
Sets the line separator to use when printing the source code.

Note:This can be any string, so be careful. I recommend either using the default or using one of the following:

 windows systems use: "\r\n"
 unix systems use: "\n"
 mac systems use: "\r"
 

Parameters: lineSeparator the line separator to use when printing the source code. This method is useful if you are generating source on one platform, but will be compiling the source on a different platform.

setMappingFilename

public void setMappingFilename(String filename)
Sets the filename of the mapping file.

Parameters: filename filename of the mapping file

setSAX1

public void setSAX1(boolean sax1)
Set to true if SAX1 should be used in the marshal method

Parameters: sax1 true if SAX1 should be used in the marshal method

setSuppressNonFatalWarnings

public void setSuppressNonFatalWarnings(boolean suppress)
Sets whether or not to suppress non-fatal warnings encountered during source generation.

Parameters: suppress true if non-fatal warnings should be suppressed.

setTestable

public void setTestable(boolean testable)
Sets whether or not to implement CastorTestable

Parameters: testable a boolean, when true indicates to implement CastorTestable

setVerbose

public void setVerbose(boolean verbose)
Sets whether or not the source code generator prints additional messages during generating source code

Parameters: verbose a boolean, when true indicates to print additional messages

toURIRepresentation

public static String toURIRepresentation(String path)
Returns a string which is the URI of a file. No validation is done to check whether the file exists or not. This method will be no longer used when the JDK URL.toString() is fixed.

Parameters: path The absolute path of the file.

Returns: A string representing the URI of the file.

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com