org.apache.tuscany.sdo.generate
Class JavaGenerator

java.lang.Object
  extended by org.apache.tuscany.sdo.generate.JavaGenerator
Direct Known Subclasses:
Interface2JavaGenerator, XSD2JavaGenerator

public abstract class JavaGenerator
extends Object

Abstract base class for static SDO code generators. See XSD2JavaGenerator and Interface2JavaGenerator for concrete generator commands. Supports the following command line options: [ -targetDirectory ] [ -javaPackage ] [ -prefix ] [ -noInterfaces ] [ -noContainment ] [ -noNotification ] [ -noUnsettable ] Not supported (future options): [ -arrayAccessors ] [ -generateLoader ] [ -interfaceDataObject ] [ -sparsePattern | -storePattern ] [ -noGenerate ] Basic options: -javaPackage Overrides the Java package for the generated classes. By default the package name is derived from the targetNamespace of the XML schema being generated. For example, if the targetNamespace is "http://www.example.com/simple", the default package will be "com.example.simple". -prefix Specifies the prefix string to use for naming the generated factory. For example "-prefix Foo" will result in a factory interface with the name "FooFactory". -targetDirectory Generates the Java source code in the specified directory. By default, the code is generated in the same directory as the input xsd or wsdl file. is not necessary. Extended options: -noContainment Turns off container management for containment properties. DataObject.getContainer() will always return null for data objects generated with this option, even if a containment reference is set. Setting a containment reference will also not automatically remove the target object from its previous container, if it had one, so it will need to be explicitly removed by the client. Use of this option is only recommended for scenarios where this kind of container movement/management -noInterfaces By default, each DataObject generates both a Java interface and a corresponding implementation class. If an SDO metamodel does not use multiple inheritance (which is always the case for XML Schema derived models), then this option can be used to eliminate the interface and to generate only an implementation class. -noNotification This option eliminates all change notification overhead in the generated classes. Changes to DataObjects generated using this option cannot be recorded, and consequently the classes cannot be used with an SDO ChangeSummary or DataGraph. -noUnsettable By default, some XML constructs result in SDO property implementations that maintain additional state information to record when the property has been set to the "default value", as opposed to being truly unset (see DataObject.isSet() and DataObject.unset()). The SDO specification allows an implementation to choose to provide this behavior or not. With this option, all generated properties will not record their unset state. The generated isSet() methods simply returns whether the current value is equal to the property's "default value". Following are planned but not supported yet: -arrayAccessors Generates Java array getters/setters for multiplicity-many properties. With this option, the set of "standard" JavaBean array accessor methods (e.g., Foo[] getFoo(), Foo getFoo(int), int getFooLength(), setFoo(Foo[]), and void setFoo(int, Foo)) are generated. The normal List-returning accessor is renamed with the suffix "List" (e.g., List getFooList()). The array returned by the generated method is not a copy, but instead a pointer to the underlying storage array, so directly modifying it can have undesirable consequences and should be avoided. -generateLoader Generate a fast XML parser/loader for instances of the model. The details of this option are subject to change, but currently it generates two additional classes in a "util" package: ResourceImpl and ResourceFactoryImpl. To use the generated loader at runtime, you need to pass an option to the XMLHelper.load() method like this: Map options = new HashMap(); options.put("GENERATED_LOADER", ResourceFactoryImpl.class); XMLDocument doc = XMLHelper.INSTANCE.load(new FileInputStream("somefile.xml"), null, options); Note: this option currently only works for simple schemas without substitution groups or wildcards. -interfaceDataObject This option is used to generate static interfaces that extend commonj.sdo.DataObject -sparsePattern For SDO metamodels that have classes with many properties of which only a few are typically set at runtime, this option can be used to produce a space-optimized implementation (at the expense of speed). -storePattern This option can be used to generate static classes that work with a Store-based DataObject implementation. It changes the generator pattern to generate accessors which delegate to the reflective methods (as opposed to the other way around) and changes the DataObject base class to org.apache.tuscany.sdo.impl.StoreDataObjectImpl. Note that this option generates classes that require a Store implementation to be provided before they can be run. -noGenerate A basic implementation of this switch is in place, but is not fully implemented. An intention behind this is to provide commentary on the artifacts that would be generated.


Nested Class Summary
static class JavaGenerator.PackageInfo
           
 
Field Summary
protected  int genOptions
           
protected  int inputIndex
           
protected  String javaPackage
           
static int OPTION_ARRAY_ACCESSORS
           
static int OPTION_GENERATE_LOADER
           
static int OPTION_GENERATE_SWITCH
           
static int OPTION_INTERFACE_DO
           
static int OPTION_NO_CONTAINMENT
           
static int OPTION_NO_GENERATE
           
static int OPTION_NO_INTERFACES
           
static int OPTION_NO_NOTIFICATION
           
static int OPTION_NO_UNSETTABLE
           
static int OPTION_SPARSE_PATTERN
           
static int OPTION_STORE_PATTERN
           
protected  String prefix
           
protected  String targetDirectory
           
protected  String xsdFileName
           
 
Constructor Summary
JavaGenerator()
           
 
Method Summary
static org.eclipse.emf.codegen.ecore.genmodel.GenPackage createGenPackage(org.eclipse.emf.ecore.EPackage ePackage, String basePackage, String prefix, int genOptions, org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
           
protected static org.eclipse.emf.codegen.ecore.genmodel.GenModel createGenPackages(Collection ePackages, Hashtable packageInfoTable, int genOptions, org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
           
static org.eclipse.emf.codegen.ecore.genmodel.GenModel ecore2GenModel(org.eclipse.emf.ecore.EPackage ePackage, String basePackage, String prefix, int genOptions)
           
static String extractBasePackageName(org.eclipse.emf.ecore.EPackage ePackage, String javaPackage)
           
static void generateFromEPackage(org.eclipse.emf.ecore.EPackage ePackage, String targetDirectory, String basePackage, String prefix, int genOptions)
           
static void generateFromGenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel genModel, String targetDirectory, int genOptions)
           
static void generateFromXMLSchema(String xsdFileName, String targetDirectory, String javaPackage, String prefix, int genOptions)
          Deprecated. moved to XSD2JavaGenerator
protected static org.eclipse.emf.codegen.ecore.genmodel.GenModel generatePackages(Collection packageList, String targetDirectory, Hashtable packageInfoTable, int genOptions, boolean allNamespaces)
           
protected static void generatePackages(Collection packageList, String packageURI, String shortName, String targetDirectory, String javaPackage, String prefix, int genOptions)
           
static String getSchemaNamespace(String xsdFileName)
          Deprecated.  
protected  int handleArgument(String[] args, int index)
           
static void main(String[] args)
          Deprecated. replaced by XSD2JavaGenerator
protected static void printDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, String indent)
           
protected static void printUsage()
           
protected  void processArguments(String[] args)
           
protected abstract  void run(String[] args)
           
static String safeQualifiedName(String qualifiedName)
           
static String shortName(String qualifiedName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_NO_INTERFACES

public static int OPTION_NO_INTERFACES

OPTION_SPARSE_PATTERN

public static int OPTION_SPARSE_PATTERN

OPTION_STORE_PATTERN

public static int OPTION_STORE_PATTERN

OPTION_NO_CONTAINMENT

public static int OPTION_NO_CONTAINMENT

OPTION_NO_NOTIFICATION

public static int OPTION_NO_NOTIFICATION

OPTION_ARRAY_ACCESSORS

public static int OPTION_ARRAY_ACCESSORS

OPTION_GENERATE_LOADER

public static int OPTION_GENERATE_LOADER

OPTION_NO_UNSETTABLE

public static int OPTION_NO_UNSETTABLE

OPTION_GENERATE_SWITCH

public static int OPTION_GENERATE_SWITCH

OPTION_INTERFACE_DO

public static int OPTION_INTERFACE_DO

OPTION_NO_GENERATE

public static int OPTION_NO_GENERATE

targetDirectory

protected String targetDirectory

javaPackage

protected String javaPackage

prefix

protected String prefix

genOptions

protected int genOptions

xsdFileName

protected String xsdFileName

inputIndex

protected int inputIndex
Constructor Detail

JavaGenerator

public JavaGenerator()
Method Detail

main

public static void main(String[] args)
Deprecated. replaced by XSD2JavaGenerator


processArguments

protected void processArguments(String[] args)

handleArgument

protected int handleArgument(String[] args,
                             int index)

run

protected abstract void run(String[] args)

generateFromXMLSchema

public static void generateFromXMLSchema(String xsdFileName,
                                         String targetDirectory,
                                         String javaPackage,
                                         String prefix,
                                         int genOptions)
Deprecated. moved to XSD2JavaGenerator


generatePackages

protected static void generatePackages(Collection packageList,
                                       String packageURI,
                                       String shortName,
                                       String targetDirectory,
                                       String javaPackage,
                                       String prefix,
                                       int genOptions)

generatePackages

protected static org.eclipse.emf.codegen.ecore.genmodel.GenModel generatePackages(Collection packageList,
                                                                                  String targetDirectory,
                                                                                  Hashtable packageInfoTable,
                                                                                  int genOptions,
                                                                                  boolean allNamespaces)

getSchemaNamespace

public static String getSchemaNamespace(String xsdFileName)
Deprecated. 


createGenPackages

protected static org.eclipse.emf.codegen.ecore.genmodel.GenModel createGenPackages(Collection ePackages,
                                                                                   Hashtable packageInfoTable,
                                                                                   int genOptions,
                                                                                   org.eclipse.emf.ecore.resource.ResourceSet resourceSet)

createGenPackage

public static org.eclipse.emf.codegen.ecore.genmodel.GenPackage createGenPackage(org.eclipse.emf.ecore.EPackage ePackage,
                                                                                 String basePackage,
                                                                                 String prefix,
                                                                                 int genOptions,
                                                                                 org.eclipse.emf.ecore.resource.ResourceSet resourceSet)

generateFromEPackage

public static void generateFromEPackage(org.eclipse.emf.ecore.EPackage ePackage,
                                        String targetDirectory,
                                        String basePackage,
                                        String prefix,
                                        int genOptions)

generateFromGenModel

public static void generateFromGenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel genModel,
                                        String targetDirectory,
                                        int genOptions)

ecore2GenModel

public static org.eclipse.emf.codegen.ecore.genmodel.GenModel ecore2GenModel(org.eclipse.emf.ecore.EPackage ePackage,
                                                                             String basePackage,
                                                                             String prefix,
                                                                             int genOptions)

extractBasePackageName

public static String extractBasePackageName(org.eclipse.emf.ecore.EPackage ePackage,
                                            String javaPackage)

shortName

public static String shortName(String qualifiedName)

safeQualifiedName

public static String safeQualifiedName(String qualifiedName)

printDiagnostic

protected static void printDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic,
                                      String indent)

printUsage

protected static void printUsage()


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.