org.exolab.castor.builder
Class SourceGenerator

java.lang.Object
  extended by org.exolab.castor.builder.BuilderConfiguration
      extended by org.exolab.castor.builder.SourceGenerator

public class SourceGenerator
extends BuilderConfiguration

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

Version:
$Revision: 1.20 $ $Date: 2005/06/07 04:02:28 $
Author:
Keith Visco - Main author., Arnaud Blandin - Contributions., Nathan Green - Contributions.

Nested Class Summary
 
Nested classes/interfaces inherited from class org.exolab.castor.builder.BuilderConfiguration
BuilderConfiguration.Property
 
Field Summary
(package private) static java.lang.String APP_DESC
          The application description
(package private) static java.lang.String APP_NAME
          The application name
(package private) static java.lang.String APP_URI
          The application URI
(package private) static java.lang.String VERSION
          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
 void generateSource(org.xml.sax.InputSource source, java.lang.String packageName)
          Creates Java Source code (Object model) for the given XML Schema
 void generateSource(java.io.Reader reader, java.lang.String packageName)
          Creates Java Source code (Object model) for the given XML Schema.
 void generateSource(Schema schema, java.lang.String packageName)
          Creates Java Source code (Object model) for the given XML Schema.
 void generateSource(java.lang.String filename, java.lang.String packageName)
          Creates Java Source code (Object model) for the given XML Schema.
static java.lang.String getVersion()
          Returns the version number of this SourceGenerator
static void main(java.lang.String[] args)
          main class used for command line invocation
 boolean mappingSchemaElement2Java()
          Tests the org.exolab.castor.builder.javaclassmapping property for the 'element' value.
 boolean mappingSchemaType2Java()
          Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.
 void setBinding(ExtendedBinding binding)
          Sets the binding to use with this instance of the SourceGenerator.
 void setBinding(org.xml.sax.InputSource source)
          Sets the binding to use given an InputSource identifying a Castor Binding File.
 void setBinding(java.lang.String fileName)
          Sets the binding to use given the path name of a Castor Binding File.
 void setCreateMarshalMethods(boolean createMarshalMethods)
          Sets whether or not to create the XML marshalling framework specific methods (marshall, unmarshall, validate) in the generated classes.
 void setDescriptorCreation(boolean createDescriptors)
          Sets whether or not to create ClassDescriptors for the generated classes.
 void setDestDir(java.lang.String destDir)
          Sets the destination directory.
 void setGenerateImportedSchemas(boolean generate)
          Sets whether or not to generate Java sources for imported XML Schema.
 void setGenerateMappingFile(boolean generateMapping)
          Sets whether or not a mapping file should be generated, this is false by default.
 void setLineSeparator(java.lang.String lineSeparator)
          Sets the line separator to use when printing the source code
 void setSAX1(boolean sax1)
          Set to true if SAX1 should be used in the marshall method
 void setSuppressNonFatalWarnings(boolean suppress)
           
 void setTestable(boolean testable)
          Sets whether or not to implement CastorTestable
 void setVerbose(boolean verbose)
          Sets whether or not the source code generator prints additional messages during generating source code
static java.lang.String toURIRepresentation(java.lang.String path)
          Returns a string which is the URI of a file.
 
Methods inherited from class org.exolab.castor.builder.BuilderConfiguration
boundPropertiesEnabled, classDescFieldNames, equalsMethod, generateExtraCollectionMethods, getDefault, getProperty, load, lookupPackageByLocation, lookupPackageByNamespace, processNamespacePackageMappings, setClassDescFieldNames, setDefaultProperties, setEqualsMethod, setLocationPackageMapping, setNamespacePackageMapping, setPrimitiveWrapper, setUseEnumeratedTypeInterface, useEnumeratedTypeInterface, usePrimitiveWrapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APP_NAME

static final java.lang.String APP_NAME
The application name

See Also:
Constant Field Values

APP_DESC

static final java.lang.String APP_DESC
The application description

See Also:
Constant Field Values

VERSION

static final java.lang.String VERSION
The application version

See Also:
Constant Field Values

APP_URI

static final java.lang.String APP_URI
The application URI

See Also:
Constant Field Values
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(Schema schema,
                           java.lang.String packageName)
                    throws java.io.IOException
Creates Java Source code (Object model) for the given XML Schema.

Parameters:
schema - the XML schema to generate the Java sources for.
packageName - the package for the generated source files.
Throws:
java.io.IOException

generateSource

public void generateSource(org.xml.sax.InputSource source,
                           java.lang.String packageName)
                    throws java.io.IOException
Creates Java Source code (Object model) for the given XML Schema

Parameters:
source - - the InputSource representing the XML schema.
packageName - the package for the generated source files
Throws:
java.io.IOException

generateSource

public void generateSource(java.io.Reader reader,
                           java.lang.String packageName)
                    throws java.io.IOException
Creates Java Source code (Object model) for the given XML Schema.

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:
java.io.IOException

generateSource

public void generateSource(java.lang.String filename,
                           java.lang.String packageName)
                    throws java.io.FileNotFoundException,
                           java.io.IOException
Creates Java Source code (Object model) for the given XML Schema.

Parameters:
filename - the full path to the XML Schema definition
packageName - the package for the generated source files
Throws:
java.io.FileNotFoundException
java.io.IOException

getVersion

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

Returns:
the version number of this SourceGenerator

setSAX1

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


setSuppressNonFatalWarnings

public void setSuppressNonFatalWarnings(boolean suppress)

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

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(java.lang.String destDir)
Sets the destination directory.

Parameters:
destDir - the destination directory.

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

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.

setTestable

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

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

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(java.lang.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(org.xml.sax.InputSource source)
Sets the binding to use given an InputSource identifying a Castor Binding File.

Parameters:
source - an InputSource identifying a Castor Binding File.

main

public static void main(java.lang.String[] args)
main class used for command line invocation

Parameters:
args - the String[] consisting of the command line arguments

setLineSeparator

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

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.
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"
 

mappingSchemaElement2Java

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

Overrides:
mappingSchemaElement2Java in class BuilderConfiguration
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.

Overrides:
mappingSchemaType2Java in class BuilderConfiguration
Returns:
True if the Source Generator is mapping schema types to Java classes.

toURIRepresentation

public static java.lang.String toURIRepresentation(java.lang.String path)

Returns a string which is the URI of a file.

No validation is done to check wether 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.


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