Class SourceGenerator
java.lang.Object
org.exolab.castor.builder.BuilderConfiguration
org.exolab.castor.builder.SourceGenerator
A Java Source generation tool which uses XML Schema definitions
to create an Object model.
- Version:
- $Revision: 9147 $ $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 BuilderConfiguration
BuilderConfiguration.PropertyModifier and TypeClassDescriptionstatic classNames of properties used in the configuration file. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionfinal voidgenerateSource(Reader reader, String packageName) Creates Java Source code (Object model) for the given XML Schema.final voidgenerateSource(String filename, String packageName) Creates Java Source code (Object model) for the given XML Schema.final voidgenerateSource(Schema schema, 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.booleanIndicates whether classes should be created for imported XML schemas as well.Returns the registry forJClassPrinterFactoryinstances.static StringReturns the version number of this SourceGenerator.Returns theJClassRegistryinstance associated with this source generator.static voidDeprecated.final booleanTests the org.exolab.castor.builder.javaclassmapping property for the 'element' value.final booleanTests the org.exolab.castor.builder.javaclassmapping property for the 'type' value.final voidsetBinding(String fileName) Sets the binding to use given the path name of a Castor Binding File.final voidsetBinding(ExtendedBinding binding) Sets the binding to use with this instance of the SourceGenerator.final voidsetBinding(InputSource source) Sets the binding to use given an InputSource identifying a Castor Binding File.final voidsetCaseInsensitive(boolean caseInsensitive) Set to true if enumerated type lookups should be performed in a case insensitive manner.voidsetClassNameConflictResolver(String resolverName) Sets the ClassNameConflictResolver instance to be used for automatic class name conflict resolution.final voidsetCreateMarshalMethods(boolean createMarshalMethods) Sets whether or not to create the XML marshaling framework specific methods (marshal, unmarshal, validate) in the generated classes.final voidsetDescriptorCreation(boolean createDescriptors) Sets whether or not to create ClassDescriptors for the generated classes.final voidsetDestDir(String destDir) Sets the destination directory.final voidsetFailOnFirstError(boolean failOnFirstError) If true, the source generator will fail on the first error encountered.final voidsetGenerateImportedSchemas(boolean generate) Sets whether or not to generate Java sources for imported XML Schema.final voidsetGenerateMappingFile(boolean generateMapping) Sets whether or not a mapping file should be generated, this is false by default.final voidsetJClassPrinterType(String jClassPrinterType) Sets the jclassPrinter type.final voidsetJdoDescriptorCreation(boolean createJdoDescriptors) Sets whether or not to create JDO-specific class descriptors for the generated classes.final voidsetLineSeparator(String lineSeparator) Sets the line separator to use when printing the source code.final voidsetMappingFilename(String filename) Sets the filename of the mapping file.final voidsetNameConflictStrategy(String nameConflictStrategy) Sets the strategy for handling name conflicts.final voidsetResourceDestination(String destination) Sets the destination directory for resources, e.g.final voidsetSAX1(boolean sax1) Set to true if SAX1 should be used in the marshal method.final voidsetSuppressNonFatalWarnings(boolean suppress) Sets whether or not to suppress non-fatal warnings encountered during source generation.final 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.Methods inherited from class 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, useCycleBreaker, useEnumeratedTypeInterface, useJava50, useJava5Enums, useOldFieldNaming, usePrimitiveWrapperModifier and TypeMethodDescriptionvoidaddAnnotationBuilder(AnnotationBuilder annotationBuilder) adds a custom annotation builder.final booleanReturns true if bound properties are enabled.final booleanReturns true if we generate a 'public static final String' for the name of each attribute and element described by the class descriptorfinal booleanReturns true if we generate an 'equals' method for each generated class.final voidAdd support to set java version programmatically.final booleanReturns true if extra methods for collection fields should be generated.final booleanReturns true if extra methods for accessing XML schema documentation should be generated; default to 'false'.returns all applied annotation builders.Returns the type 'suffix' used for the type strategy during automatic class name conflict resolution during XML code generation; default to "" unless a value is specified.final PropertiesReturns the default configuration file.To get theJavaNamingimplementation to be used.final StringReturns a String representing the list ofinstances configured in the Castor XML code generator property file.invalid reference
JClassPrinterFactoryfinal intReturns the maximum number of static constant definitions that are acceptable within one class file; default is 1000.final StringgetProperty(String name, String defValue) Returns a property from the default configuration file.booleanindicates whether automatic class name conflict resolution during XML code generation should take place or not.protected final voidload()Called byBuilderConfiguration.getDefault()to load the configuration the first time.static PropertiesloadProperties(String resourceName, String fileName) Load the configuration 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.final StringlookupPackageByLocation(String schemaLocation) Converts a schema location into a Java package.final StringlookupPackageByNamespace(String nsURL) Gets a Java package to an XML namespace URL.protected final voidprocessNamespacePackageMappings(String mappings) processes the given String which contains namespace-to-package mappings.final voidsetClassDescFieldNames(boolean classDescFieldNames) Sets the 'classDescFieldNames' property.final voidsetDefaultProperties(Properties properties) Overrides the current set of properties with the given properties.final voidsetEqualsMethod(boolean equals) Sets the 'equalsmethod' property.voidsetJavaNaming(JavaNaming javaNaming) To set theJavaNamingimplementation to be used.final voidsetLocationPackageMapping(String schemaLocation, String packageName) Sets the schemaLocation to package mapping.final voidsetNamespacePackageMapping(String ns, String packageName) Sets the namespace to package mapping.final voidsetPrimitiveWrapper(boolean wrapper) Sets the 'primitivetowrapper' property.final voidsetUseEnumeratedTypeInterface(boolean flag) Sets the 'enumTypeAccessInterface' property.final booleanReturns true if the classshould be used during code generation; defaults to 'true'.invalid reference
CycleBreakerfinal booleanReturns true if we generate the implements EnumeratedTypeAccess interface for enumerated type classes.final booleanReturns true if we generate the implements EnumeratedTypeAccess interface for enumerated type classes.final booleanIndicates what kind of enumeration should be created for <xs:simpleType> enumerations.booleanfinal booleanReturns true if primitive types have to be used as Objects (eg.
-
Field Details
-
_sInfo
-
-
Constructor Details
-
SourceGenerator
public SourceGenerator()Creates a SourceGenerator using the default FieldInfo factory. -
SourceGenerator
Creates a SourceGenerator using the specific field info Factory.- Parameters:
infoFactory- the FieldInfoFactory to use.
-
SourceGenerator
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
-
setMappingFilename
Sets the filename of the mapping file.- Parameters:
filename- filename of the mapping file
-
setNameConflictStrategy
Sets the strategy for handling name conflicts.- Parameters:
nameConflictStrategy- the name of the stretegy to use for handling name conflicts.
-
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
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
Sets the destination directory.- Parameters:
destDir- the destination directory.
-
setResourceDestination
Sets the destination directory for resources, e.g. '.castor.cdr' files.- Parameters:
destDir- the destination directory for resources.
-
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
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
Sets the binding to use given the path name of a Castor Binding File.- Parameters:
fileName- the file that represents a Binding
-
setBinding
Sets the binding to use given an InputSource identifying a Castor Binding File.- Parameters:
source- an InputSource identifying a Castor Binding File.
-
setLineSeparator
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:
mappingSchemaElement2Javain classBuilderConfiguration- 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:
mappingSchemaType2Javain classBuilderConfiguration- Returns:
- True if the Source Generator is mapping schema types to Java classes.
-
generateSource
Creates Java Source code (Object model) for the given XML Schema. If the file exists, opens a FileReader and passes control togenerateSource(InputSource, String).- Parameters:
filename- the full path to the XML Schema definitionpackageName- the package for the generated source files- Throws:
IOException- if an IOException occurs writing the new source files
-
generateSource
Creates Java Source code (Object model) for the given XML Schema. This method just passes control togenerateSource(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:
IOException- if an IOException occurs writing the new source files
-
generateSource
Creates Java Source code (Object model) for the given XML Schema. Parses the schema provided by the InputSource and then callsgenerateSource(Schema, String)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
Creates Java Source code (Object model) for the given XML Schema. Convenience methods exist if you don't have aSchemaalready 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:
-
toURIRepresentation
Returns a string which is the URI of a file.- file:///DOSpath
- file://UnixPath
- Parameters:
path- The absolute path of the file.- Returns:
- A string representing the URI of the file.
-
main
Deprecated.Please useSourceGeneratorMain.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
Returns theJClassRegistryinstance associated with this source generator.- Returns:
- the
JClassRegistryinstance currently in use.
-
setJClassPrinterType
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
Returns the registry forJClassPrinterFactoryinstances.- Returns:
- the registry for
JClassPrinterFactoryinstances.
-
SourceGeneratorMain.main(String[])