org.exolab.castor.builder

Class SourceGenerator


public class SourceGenerator
extends java.lang.Object

A Java Source generation tool which uses XML Schema definitions to create an Object model.
Version:
$Revision: 1.6 $ $Date: 2003/06/02 13:24:10 $
Authors:
Keith Visco - Main author.
Arnaud Blandin - Contributions.
Nathan Green - Contributions.

Nested Class Summary

static class
SourceGenerator.Property
Names of properties used in the configuration file.

Field Summary

(package private) static String
APP_DESC
The application description
(package private) static String
APP_NAME
The application name
(package private) static String
APP_URI
The application URI
(package private) static 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

static boolean
boundPropertiesEnabled()
Returns true if bound properties are enabled.
static boolean
classDescFieldNames()
Returns true if we generate a 'public static final String' for the name of each attribute and element described by the class descriptor Enabling this property is controlled via the org.exolab.castor.builder.classdescfieldnames item in the castorbuilder.properties file.
static boolean
equalsMethod()
Returns true if we generate an 'equals' method for each generated class.
static boolean
generateExtraCollectionMethods()
Returns true if extra methods for collection fields should be generated.
void
generateSource(InputSource source, String packageName)
Creates Java Source code (Object model) for the given XML Schema
void
generateSource(Reader reader, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
void
generateSource(String filename, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
void
generateSource(Schema schema, String packageName)
Creates Java Source code (Object model) for the given XML Schema.
static Properties
getDefault()
Returns the default configuration file.
static String
getProperty(String name, String defValue)
Returns a property from the default configuration file.
static String
getVersion()
Returns the version number of this SourceGenerator
protected static void
initBindingType()
Called by #load to initialize the binding type
protected static void
load()
Called by getDefault() to load the configuration the first time.
static String
lookupPackageLocation(String schemaLocation)
Gets a Java package to a schema location.
static String
lookupPackageNamespace(String nsURL)
Gets a Java package to an XML namespace URL
static void
main(String[] args)
main class used for command line invocation
static boolean
mappingSchemaElement2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'element' value.
static boolean
mappingSchemaType2Java()
Tests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.
protected static void
processNamespacePackageMappings(String mappings)
void
setBinding(InputSource source)
Sets the binding to use given an InputSource identifying a Castor Binding File.
void
setBinding(String fileName)
Sets the binding to use given the path name of a Castor Binding File.
void
setBinding(ExtendedBinding binding)
Sets the binding to use with this instance of the SourceGenerator.
static void
setClassDescFieldNames(boolean classDescFieldNames)
Sets the 'classDescFieldNames' property
void
setCreateMarshalMethods(boolean createMarshalMethods)
Sets whether or not to create the XML marshalling framework specific methods (marshall, unmarshall, validate) in the generated classes.
static void
setDefaultProperties(Properties properties)
Override the properties
void
setDescriptorCreation(boolean createDescriptors)
Sets whether or not to create ClassDescriptors for the generated classes.
void
setDestDir(String destDir)
Sets the destination directory.
static void
setEqualsMethod(boolean equals)
Sets the 'equalsmethod' property
void
setLineSeparator(String lineSeparator)
Sets the line separator to use when printing the source code
static void
setPrimitiveWrapper(boolean wrapper)
Sets the 'primitivetowrapper' property
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 create the XML marshalling framework specific methods (marshall, unmarshall, validate) in the generated classes.
void
setVerbose(boolean verbose)
Sets whether or not the source code generator prints additional messages during generating source code
static String
toURIRepresentation(String path)
Returns a string which is the URI of a file.
static boolean
usePrimitiveWrapper()
Returns true if primitive types have to be used as Objects (eg.

Field Details

APP_DESC

(package private) static final String APP_DESC
The application description

APP_NAME

(package private) static final String APP_NAME
The application name

APP_URI

(package private) static final String APP_URI
The application URI

VERSION

(package private) static final String VERSION
The application version

Constructor Details

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 Details

boundPropertiesEnabled

public static boolean boundPropertiesEnabled()
Returns true if bound properties are enabled. Enabling bound properties is controlled via the org.exolab.castor.builder.boundproperties item in the castorbuilder.properties file. The value is either 'true' or 'false'.
Returns:
true if bound properties are enabled.

classDescFieldNames

public static boolean classDescFieldNames()
Returns true if we generate a 'public static final String' for the name of each attribute and element described by the class descriptor Enabling this property is controlled via the org.exolab.castor.builder.classdescfieldnames item in the castorbuilder.properties file. The value is either 'true' or 'false'.
Returns:
true if bound properties are enabled.

equalsMethod

public static boolean equalsMethod()
Returns true if we generate an 'equals' method for each generated class. Enabling this property is controlled via the org.exolab.castor.builder.equalsmethod item in the castorbuilder.properties file. The value is either 'true' or 'false'.
Returns:
true if bound properties are enabled.

generateExtraCollectionMethods

public static boolean generateExtraCollectionMethods()
Returns true if extra methods for collection fields should be generated. Such methods include set/get methods for the actual collection in addition to the array methods. Enabling extra collection methods is controlled via the org.exolab.castor.builder.extraCollectionMethods property in the castorbuilder.properties file. The value is either 'true' or 'false'.
Returns:
true if extra collection methods are enabled.

generateSource

public void generateSource(InputSource source,
                           String packageName)
Creates Java Source code (Object model) for the given XML Schema
Parameters:
packageName - the package for the generated source files

generateSource

public void generateSource(Reader reader,
                           String packageName)
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

generateSource

public void generateSource(String filename,
                           String packageName)
            throws java.io.FileNotFoundException
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

generateSource

public void generateSource(Schema schema,
                           String packageName)
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.

getDefault

public static Properties getDefault()
Returns the default configuration file. Changes to the returned properties set will affect all Castor functions relying on the default configuration.
Returns:
The default configuration

getProperty

public static String getProperty(String name,
                                 String defValue)
Parameters:
name - The property name
Returns:
The property's value

getVersion

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

initBindingType

protected static void initBindingType()
Called by #load to initialize the binding type

load

protected static void load()
Called by getDefault() to load the configuration the first time. Will not complain about inability to load configuration file from one of the default directories, but if it cannot find the JAR's configuration file, will throw a run time exception.

lookupPackageLocation

public static String lookupPackageLocation(String schemaLocation)
Gets a Java package to a schema location.

lookupPackageNamespace

public static String lookupPackageNamespace(String nsURL)
Gets a Java package to an XML namespace URL

main

public static void main(String[] args)
main class used for command line invocation
Parameters:
args - the String[] consisting of the command line arguments

mappingSchemaElement2Java

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

processNamespacePackageMappings

protected static void processNamespacePackageMappings(String mappings)

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.

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

setClassDescFieldNames

public static void setClassDescFieldNames(boolean classDescFieldNames)
Sets the 'classDescFieldNames' property
Parameters:

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

setDefaultProperties

public static void setDefaultProperties(Properties properties)
Override the properties

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.

setEqualsMethod

public static void setEqualsMethod(boolean equals)
Sets the 'equalsmethod' property
Parameters:

setLineSeparator

public void setLineSeparator(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"

setPrimitiveWrapper

public static void setPrimitiveWrapper(boolean wrapper)
Sets the 'primitivetowrapper' property
Parameters:

setSAX1

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

setSuppressNonFatalWarnings

public void setSuppressNonFatalWarnings(boolean suppress)

setTestable

public void setTestable(boolean testable)
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:

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.
  • file:///DOSpath
  • file://UnixPath
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.

usePrimitiveWrapper

public static boolean usePrimitiveWrapper()
Returns true if primitive types have to be used as Objects (eg. replacing float by java.lang.Float).

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