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: 7996 $ $Date: 2006-03-30 14:58:45 -0700 (Thu, 30 Mar 2006) $
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
protected  SGStateInfo _sInfo
           
 
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.
 boolean getGenerateImportedSchemas()
          Indicates whether classes should be created for imported XML schemas as well.
 JClassPrinterFactoryRegistry getJClassPrinterFactoryRegistry()
          Returns the registry for JClassPrinterFactory instances.
static java.lang.String getVersion()
          Returns the version number of this SourceGenerator.
 JClassRegistry getXMLInfoRegistry()
          Returns the JClassRegistry instance associated with this source generator.
static void main(java.lang.String[] args)
          Deprecated. Please use SourceGeneratorMain.main(String[])
 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 setCaseInsensitive(boolean caseInsensitive)
          Set to true if enumerated type lookups should be performed in a case insensitive manner.
 void setClassNameConflictResolver(java.lang.String resolverName)
          Sets the ClassNameConflictResolver instance to be used for automatic class name conflict resolution.
 void setCreateMarshalMethods(boolean createMarshalMethods)
          Sets whether or not to create the XML marshaling framework specific methods (marshal, unmarshal, 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 setFailOnFirstError(boolean failOnFirstError)
          If true, the source generator will fail on the first error encountered.
 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 setJClassPrinterType(java.lang.String jClassPrinterType)
          Sets the jclassPrinter type.
 void setJdoDescriptorCreation(boolean createJdoDescriptors)
          Sets whether or not to create JDO-specific class descriptors for the generated classes.
 void setLineSeparator(java.lang.String lineSeparator)
          Sets the line separator to use when printing the source code.
 void setMappingFilename(java.lang.String filename)
          Sets the filename of the mapping file.
 void setNameConflictStrategy(java.lang.String nameConflictStrategy)
          Sets the strategy for handling name conflicts.
 void setSAX1(boolean sax1)
          Set to true if SAX1 should be used in the marshal method.
 void setSuppressNonFatalWarnings(boolean suppress)
          Sets whether or not to suppress non-fatal warnings encountered during source generation.
 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
addAnnotationBuilder, boundPropertiesEnabled, classDescFieldNames, equalsMethod, forceUseJava50, generateExtraCollectionMethods, generateExtraDocumentationMethods, getAnnotationBuilders, getAutomaticConflictResolutionTypeSuffix, getDefault, getJavaNaming, getJClassPrinterFactories, getMaximumNumberOfConstants, getProperty, isAutomaticConflictResolution, load, loadProperties, lookupPackageByLocation, lookupPackageByNamespace, processNamespacePackageMappings, setClassDescFieldNames, setDefaultProperties, setEqualsMethod, setJavaNaming, setLocationPackageMapping, setNamespacePackageMapping, setPrimitiveWrapper, setUseEnumeratedTypeInterface, useEnumeratedTypeInterface, useJava50, useJava5Enums, usePrimitiveWrapper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sInfo

protected SGStateInfo _sInfo
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

setMappingFilename

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

Parameters:
filename - filename of the mapping file

setNameConflictStrategy

public final void setNameConflictStrategy(java.lang.String nameConflictStrategy)
Sets the strategy for handling name conflicts.

Parameters:
nameConflictStrategy - the name of the stretegy to use for handling name conflicts.

getVersion

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

Returns:
the version number of this SourceGenerator

setSAX1

public final 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

setCaseInsensitive

public final 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.

setFailOnFirstError

public final 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.

setSuppressNonFatalWarnings

public final 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.

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

setClassNameConflictResolver

public void setClassNameConflictResolver(java.lang.String resolverName)
Sets the ClassNameConflictResolver instance to be used for automatic class name conflict resolution.

Parameters:
resolverName - The name of the resolver to be used for automatic class name conflict resolution

setDescriptorCreation

public final 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

setJdoDescriptorCreation

public final void setJdoDescriptorCreation(boolean createJdoDescriptors)
Sets whether or not to create JDO-specific class descriptors for the generated classes. By default, JDO-specific class descriptors are NOT generated.

Parameters:
createJdoDescriptors - a boolean, when true indicates to generated JDO-specific class descriptors

setDestDir

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

Parameters:
destDir - the destination directory.

setCreateMarshalMethods

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

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

setGenerateImportedSchemas

public final 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 final 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 final void setTestable(boolean testable)
Sets whether or not to implement CastorTestable.

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

setBinding

public final 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 final 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 final 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.

setLineSeparator

public final void setLineSeparator(java.lang.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.

mappingSchemaElement2Java

public final 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 final 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.

generateSource

public final void generateSource(java.lang.String filename,
                                 java.lang.String packageName)
                          throws java.io.IOException
Creates Java Source code (Object model) for the given XML Schema. If the file exists, opens a FileReader and passes control to generateSource(InputSource, String).

Parameters:
filename - the full path to the XML Schema definition
packageName - the package for the generated source files
Throws:
java.io.IOException - if an IOException occurs writing the new source files

generateSource

public final 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. This method just passes control to generateSource(InputSource, String).

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 - if an IOException occurs writing the new source files

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. Parses the schema provided by the InputSource and then calls generateSource(Schema, String) to actually generate the source.

Parameters:
source - - the InputSource representing the XML schema.
packageName - the package for the generated source files
Throws:
java.io.IOException - if an IOException occurs writing the new source files

generateSource

public final void generateSource(Schema schema,
                                 java.lang.String packageName)
                          throws java.io.IOException
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:
java.io.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

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

main

public static void main(java.lang.String[] args)
Deprecated. Please use SourceGeneratorMain.main(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.

getXMLInfoRegistry

public JClassRegistry getXMLInfoRegistry()
Returns the JClassRegistry instance associated with this source generator.

Returns:
the JClassRegistry instance currently in use.

setJClassPrinterType

public final void setJClassPrinterType(java.lang.String jClassPrinterType)
Sets the jclassPrinter type.

Parameters:
jClassPrinterType - The string identifier of the printer to use.

getGenerateImportedSchemas

public boolean getGenerateImportedSchemas()
Indicates whether classes should be created for imported XML schemas as well.

Returns:
true if classes should be created for imported schemas.

getJClassPrinterFactoryRegistry

public JClassPrinterFactoryRegistry getJClassPrinterFactoryRegistry()
Returns the registry for JClassPrinterFactory instances.

Returns:
the registry for JClassPrinterFactory instances.


Copyright © 2011. All Rights Reserved.