org.exolab.castor.builder
Class SourceGenerator

java.lang.Object
  extended byorg.exolab.castor.builder.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.77 $ $Date: 2001/12/30 07:34:07 $
Author:
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 java.lang.String appDesc
          The application description
(package private) static java.lang.String appName
          The application name
(package private) static java.lang.String appURI
          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.
 
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.
 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.util.Properties getDefault()
          Returns the default configuration file.
static java.lang.String getJavaPackage(java.lang.String nsURL)
          Gets a Java package to an XML namespace URL
static java.lang.String getProperty(java.lang.String name, java.lang.String defValue)
          Returns a property from the default configuration file.
static java.lang.String getQualifiedClassName(java.lang.String nsURL, java.lang.String className)
          Gets the qualified class name given an XML namespace URL
static java.lang.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 void main(java.lang.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.
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.
 void setDefaultProperties(java.util.Properties properties)
           
 void setDescriptorCreation(boolean createDescriptors)
          Sets whether or not to create ClassDescriptors for the generated classes.
 void setDestDir(java.lang.String destDir)
           
static void setEqualsMethod(boolean equals)
          Sets the 'equalsmethod' property
 void setLineSeparator(java.lang.String lineSeparator)
          Sets the line separator to use when printing the source code
static void setPrimitiveWrapper(boolean wrapper)
          Sets the 'primitivetowrapper' property
 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 java.lang.String toURIRepresentation(java.lang.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

appName

static final java.lang.String appName
The application name

See Also:
Constant Field Values

appDesc

static final java.lang.String appDesc
The application description

See Also:
Constant Field Values

version

static final java.lang.String version
The application version

See Also:
Constant Field Values

appURI

static final java.lang.String appURI
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.
Method Detail

generateSource

public void generateSource(Schema schema,
                           java.lang.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

generateSource

public void generateSource(org.xml.sax.InputSource source,
                           java.lang.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(java.io.Reader reader,
                           java.lang.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(java.lang.String filename,
                           java.lang.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
Throws:
java.io.FileNotFoundException

getVersion

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

Returns:
the version number of this SourceGenerator

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

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

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.


setDefaultProperties

public void setDefaultProperties(java.util.Properties properties)

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

setDestDir

public void setDestDir(java.lang.String destDir)

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"
 

getDefault

public static java.util.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 java.lang.String getProperty(java.lang.String name,
                                           java.lang.String defValue)
Returns a property from the default configuration file. Equivalent to calling getProperty on the result of getDefault().

Parameters:
name - The property name
Returns:
The property's value

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.

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.

setEqualsMethod

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


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.

setClassDescFieldNames

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


usePrimitiveWrapper

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


setPrimitiveWrapper

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


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.

getJavaPackage

public static java.lang.String getJavaPackage(java.lang.String nsURL)
Gets a Java package to an XML namespace URL


getQualifiedClassName

public static java.lang.String getQualifiedClassName(java.lang.String nsURL,
                                                     java.lang.String className)
Gets the qualified class name given an XML namespace URL


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.


initBindingType

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


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-2001. All rights reserved http://www.intalio.com