tuscany-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luciano Resende" <luckbr1...@gmail.com>
Subject SDO fix for TUSCANY-1233 breaking DAS, was Fwd: svn commit: r543520 - in /incubator/tuscany/java/sdo/tools: src/main/java/org/apache/tuscany/sdo/generate/ src/main/java/org/apache/tuscany/sdo/generate/templates/model/ templates/models/
Date Sat, 02 Jun 2007 08:29:27 GMT
After this commit, DAS test cases are failing as described on the
continuum build failure report[1]. I tried updating SDO to the
revision prior to this commit (>svn update -r 543519), and then I get
a clean DAS build.

I have created JIRA TUSCANY-1323 to track the issue, Could someone on
the SDO team please take a look at this ?

[1] http://www.mail-archive.com/tuscany-dev%40ws.apache.org/msg18484.html
[2] https://issues.apache.org/jira/browse/TUSCANY-1323

---------- Forwarded message ----------
From: kelvingoodson@apache.org <kelvingoodson@apache.org>
Date: Jun 1, 2007 9:04 AM
Subject: svn commit: r543520 - in /incubator/tuscany/java/sdo/tools:
src/main/java/org/apache/tuscany/sdo/generate/
src/main/java/org/apache/tuscany/sdo/generate/templates/model/
templates/models/
To: tuscany-commits@ws.apache.org


Author: kelvingoodson
Date: Fri Jun  1 09:04:20 2007
New Revision: 543520

URL: http://svn.apache.org/viewvc?view=rev&rev=543520
Log:
Fix for TUSCANY-1233

Modified:
    incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
    incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java
    incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
    incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet

Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java?view=diff&rev=543520&r1=543519&r2=543520
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
(original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/JavaGenerator.java
Fri Jun  1 09:04:20 2007
@@ -27,6 +27,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -84,6 +85,7 @@
  *     [ -generateLoader ]
  *     [ -interfaceDataObject ]
  *     [ -sparsePattern | -storePattern ]
+ *     [ -noGenerate ]
  *
  *   Basic options:
  *
@@ -152,7 +154,10 @@
  *         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.
+ *         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.
  *
  *
  */
@@ -169,6 +174,7 @@
   //FIXME Temporary, I need this option for now to get Switch classes
generated for the SCDL models
   public static int OPTION_GENERATE_SWITCH=0x100;
   public static int OPTION_INTERFACE_DO=0x400;
+  public static int OPTION_NO_GENERATE=0x800;

   static
   {
@@ -279,6 +285,10 @@
     {
       genOptions |= OPTION_INTERFACE_DO;
     }
+    else if (args[index].equalsIgnoreCase("-noGenerate"))
+    {
+      genOptions |= OPTION_NO_GENERATE;
+    }
     //else if (...)
     else
     {
@@ -340,29 +350,50 @@
     }
   }

-  public static void generatePackages(Collection packageList, String
packageURI, String shortName, String targetDirectory, String
javaPackage, String prefix, int genOptions)
+  protected static void generatePackages(Collection packageList,
String packageURI, String shortName, String targetDirectory, String
javaPackage, String prefix, int genOptions)
+  {
+    Hashtable packageInfoTable = new Hashtable();
+    packageInfoTable.put(packageURI, new PackageInfo(javaPackage,
prefix, packageURI, shortName ));
+    generatePackages(packageList, targetDirectory, packageInfoTable,
genOptions, false);
+  }
+
+  protected static GenModel generatePackages(Collection packageList,
String targetDirectory, Hashtable packageInfoTable, int genOptions,
boolean allNamespaces )
   {
     ResourceSet resourceSet = DataObjectUtil.createResourceSet();
     List usedGenPackages = new ArrayList();
     GenModel genModel = null;
+    ArrayList packagesToModel = new ArrayList();
     for (Iterator iter = packageList.iterator(); iter.hasNext();)
     {
       EPackage currentEPackage = (EPackage)iter.next();
-      boolean generateCurrent = currentEPackage.getNsURI().equals(packageURI);
-      String currentBasePackage =
extractBasePackageName(currentEPackage, generateCurrent ? javaPackage
: null);
-      String currentPrefix = generateCurrent && prefix != null ?
prefix : CodeGenUtil.capName(shortName != null ? shortName :
currentEPackage.getName());
-      GenPackage currentGenPackage =
createGenPackage(currentEPackage, currentBasePackage, currentPrefix,
genOptions, resourceSet);
-      if (generateCurrent)
-      {
-        genModel = currentGenPackage.getGenModel();
-      }
+      String packageNamespace  = currentEPackage.getNsURI();
+      PackageInfo packageInfo  =
(PackageInfo)packageInfoTable.get(packageNamespace);
+      boolean bTargetPackage   = allNamespaces;
+      String javaPackage       = null;
+      String prefix            = null;
+      String shortName         = null;
+      if( packageInfo != null )
+      {
+        bTargetPackage = true;
+        javaPackage    = packageInfo.getBasePackage();
+        prefix         = packageInfo.getPrefix();
+        shortName      = packageInfo.getShortName();
+      }
+      String currentBasePackage =
extractBasePackageName(currentEPackage, bTargetPackage ? javaPackage :
null);
+      String currentPrefix = bTargetPackage && prefix != null ?
prefix : CodeGenUtil.capName(shortName != null ? shortName :
currentEPackage.getName());
+      packageInfoTable.put(currentEPackage, new
PackageInfo(currentBasePackage, currentPrefix, null, null ));
+
+      if( allNamespaces || packageInfo != null )
+          packagesToModel.add(currentEPackage);
       else
-      {
-        usedGenPackages.add(currentGenPackage);
-      }
-    }
-
-    if (genModel == null) return; // nothing to generate
+      {
+          GenPackage currentGenPackage =
createGenPackage(currentEPackage, currentBasePackage, currentPrefix,
genOptions, resourceSet);
+          usedGenPackages.add(currentGenPackage);
+      }
+    }
+    genModel = createGenPackages(packagesToModel, packageInfoTable,
genOptions, resourceSet);
+
+    if (genModel == null) return null; // nothing to generate

     //TODO Figure out which predefined packages are really "used"
     usedGenPackages.add(createGenPackage(SDOPackageImpl.eINSTANCE,
"org.apache.tuscany", "SDO", 0, resourceSet));
@@ -372,16 +403,22 @@
     //usedGenPackages.add(createGenPackage((EPackage)XMLFactory.INSTANCE,
"org.apache.tuscany.sdo.model", "XML", 0, resourceSet));

     genModel.getUsedGenPackages().addAll(usedGenPackages);
-
-    // Invoke the SDO JavaGenerator to generate the SDO classes
-    try
-    {
-      generateFromGenModel(genModel, new
File(targetDirectory).getCanonicalPath(), genOptions);
-    }
-    catch (IOException e)
+
+    // If the display namespace option is selected, Don't generate
+    if( (genOptions & OPTION_NO_GENERATE) == 0)
     {
-      e.printStackTrace();
+      // Invoke the SDO JavaGenerator to generate the SDO classes
+      try
+      {
+        generateFromGenModel(genModel, new
File(targetDirectory).getCanonicalPath(), genOptions);
+      }
+      catch (IOException e)
+      {
+        e.printStackTrace();
+      }
     }
+
+    return genModel;
   }

   /**
@@ -396,6 +433,27 @@
     return schema.getTargetNamespace();
   }

+  protected static GenModel createGenPackages(Collection ePackages,
Hashtable packageInfoTable, int genOptions, ResourceSet resourceSet)
+  {
+    GenModel genModel = ecore2GenModel(ePackages, packageInfoTable,
genOptions);
+
+    for (Iterator iter = ePackages.iterator(); iter.hasNext();)
+    {
+      EPackage ePackage = (EPackage)iter.next();
+
+      URI ecoreURI = URI.createURI("file:///" + ePackage.getName() + ".ecore");
+      URI genModelURI =
ecoreURI.trimFileExtension().appendFileExtension("genmodel");
+
+      Resource ecoreResource = resourceSet.createResource(ecoreURI);
+      ecoreResource.getContents().add(ePackage);
+
+      Resource genModelResource = resourceSet.createResource(genModelURI);
+      genModelResource.getContents().add(genModel);
+    }
+
+    return genModel;
+  }
+
   public static GenPackage createGenPackage(EPackage ePackage, String
basePackage, String prefix, int genOptions, ResourceSet resourceSet)
   {
     GenModel genModel = ecore2GenModel(ePackage, basePackage, prefix,
genOptions);
@@ -449,8 +507,8 @@

     //if ((genOptions & OPTION_USE_EMF_PATTERNS) == 0)
     {
-       generator.getAdapterFactoryDescriptorRegistry().addDescriptor
-        (GenModelPackage.eNS_URI,
SDOGenModelGeneratorAdapterFactory.DESCRIPTOR);
+      generator.getAdapterFactoryDescriptorRegistry().addDescriptor
+      (GenModelPackage.eNS_URI, SDOGenModelGeneratorAdapterFactory.DESCRIPTOR);
     }

     generator.setInput(genModel);
@@ -470,8 +528,17 @@

   public static GenModel ecore2GenModel(EPackage ePackage, String
basePackage, String prefix, int genOptions)
   {
+      ArrayList ePackages = new ArrayList();
+      ePackages.add(ePackage);
+      Hashtable packageInfoTable = new Hashtable();
+      packageInfoTable.put(ePackage, new PackageInfo(basePackage,
prefix, null, null ));
+      return ecore2GenModel(ePackages, packageInfoTable, genOptions );
+  }
+
+  private static GenModel ecore2GenModel(Collection ePackages,
Hashtable packageInfoTable, int genOptions)
+  {
     GenModel genModel = GenModelFactory.eINSTANCE.createGenModel();
-    genModel.initialize(Collections.singleton(ePackage));
+    genModel.initialize(ePackages);

     genModel.setRootExtendsInterface("");
     genModel.setRootImplementsInterface("commonj.sdo.DataObject");
@@ -536,43 +603,48 @@
       genModel.setRootExtendsInterface("java.io.Serializable");
     }

-    GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
-
-    if (basePackage != null)
-    {
-      genPackage.setBasePackage(basePackage);
-    }
-    if (prefix != null)
+    //GenPackage genPackage = (GenPackage)genModel.getGenPackages().get(0);
+    Collection packages = genModel.getGenPackages();
+    for (Iterator iter1 = packages.iterator(); iter1.hasNext();)
     {
-      genPackage.setPrefix(prefix);
-    }
+      GenPackage genPackage   = (GenPackage)iter1.next();
+      PackageInfo packageInfo =
(PackageInfo)packageInfoTable.get(genPackage.getEcorePackage());
+
+      if (packageInfo.getBasePackage() != null)
+      {
+          genPackage.setBasePackage(packageInfo.getBasePackage());
+      }
+      if (packageInfo.getPrefix() != null)
+      {
+          genPackage.setPrefix(packageInfo.getPrefix());
+      }

-    //FIXME Temporary, I need this option for now to get Switch
classes generated for the SCDL models
-    if ((genOptions & OPTION_GENERATE_SWITCH) == 0)
-    {
-        genPackage.setAdapterFactory(false);
-    }
+      //FIXME Temporary, I need this option for now to get Switch
classes generated for the SCDL models
+      if ((genOptions & OPTION_GENERATE_SWITCH) == 0)
+      {
+          genPackage.setAdapterFactory(false);
+      }

-    if ((genOptions & OPTION_GENERATE_LOADER) != 0)
-    {
-      //FIXME workaround compile error with 02162006 build, generated
code references non-existent EcoreResourceImpl class
-      genPackage.setResource(GenResourceKind.XML_LITERAL);
-      //genPackage.setDataTypeConverters(true);
-    }
-    else
-    {
-      genPackage.setResource(GenResourceKind.NONE_LITERAL);
-      for (Iterator iter = genPackage.getGenClasses().iterator();
iter.hasNext();)
+      if ((genOptions & OPTION_GENERATE_LOADER) != 0)
       {
-        GenClass genClass = (GenClass)iter.next();
-        if ("DocumentRoot".equals(genClass.getName()))
+        //FIXME workaround compile error with 02162006 build,
generated code references non-existent EcoreResourceImpl class
+        genPackage.setResource(GenResourceKind.XML_LITERAL);
+        //genPackage.setDataTypeConverters(true);
+      }
+      else
+      {
+        genPackage.setResource(GenResourceKind.NONE_LITERAL);
+        for (Iterator iter2 = genPackage.getGenClasses().iterator();
iter2.hasNext();)
         {
-          genClass.setDynamic(true); // Don't generate DocumentRoot class
-          break;
-        }
+          GenClass genClass = (GenClass)iter2.next();
+          if ("DocumentRoot".equals(genClass.getName()))
+          {
+            genClass.setDynamic(true); // Don't generate DocumentRoot class
+            break;
+          }
+        }
       }
     }
-
     return genModel;
   }

@@ -624,4 +696,28 @@
     System.out.println("Usage: this is a deprecated command replaced
by XSD2JavaGenerator");
   }

+  public static class PackageInfo
+  {
+    private String   basePackage;
+    private String   prefix;
+    private String   namespace;
+    private String   shortName;
+
+    public PackageInfo(String basePackage, String prefix, String
namespace, String shortName )
+    {
+      setBasePackage(basePackage);
+      setPrefix(prefix);
+      setNamespace(namespace);
+      setShortName(shortName);
+    }
+
+    public void setBasePackage(String basePackage) { this.basePackage
= basePackage; }
+    public String getBasePackage() { return basePackage; }
+    public void setPrefix(String prefix) { this.prefix = prefix; }
+    public String getPrefix() { return prefix; }
+    public void setNamespace(String namespace) { this.namespace = namespace; }
+    public String getNamespace() { return namespace; }
+    public void setShortName(String shortName) { this.shortName = shortName; }
+    public String getShortName() { return shortName; }
+  }
 }

Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java?view=diff&rev=543520&r1=543519&r2=543520
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java
(original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/XSD2JavaGenerator.java
Fri Jun  1 09:04:20 2007
@@ -19,15 +19,27 @@
  */
 package org.apache.tuscany.sdo.generate;

+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;

 import org.apache.tuscany.sdo.helper.XSDHelperImpl;
 import org.apache.tuscany.sdo.util.DataObjectUtil;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
 import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
 import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.resource.ResourceSet;
@@ -47,6 +59,7 @@
    *     [ -targetDirectory <target-root-directory> ]
    *     [ -javaPackage <java-package-name> ]
    *     [ -schemaNamespace <namespace-uri> ]
+   *     [ -namespaceInfo <namespaces-file> ]
    *     [ other options ... ]
    *     <xsd-file> | <wsdl-file>
    *
@@ -54,7 +67,14 @@
    *
    *     -schemaNamespace
    *         Generate classes for XSD types in the specified
targetNamespace. By default, types in the
-   *         targetNamespace of the first schema in the specified xsd
or wsdl file are generated.
+   *         targetNamespace of the first schema in the specified xsd
or wsdl file are generated. Specify
+   *         'all' and this parameter will act as a wildcard
selecting all namespaces for code generation.
+   *     -namespaceInfo
+   *         Specifies the name of a file that should contain a list
of namespaces and their associated package names.
+   *         Optionally, a prefix may be assigned to each namespace
as well.  These values are separated by semicolons.
+   *         So each line in the file would look something like this:
+   *
+   *         some\namespace;custom.package.name;optionalPrefix
    *
    *     NOTE: see the base class JavaGenerator for other options.
    *
@@ -78,21 +98,34 @@
       printUsage();
     }
   }
+

   protected String schemaNamespace = null;
+  protected String namespaceInfo = null;
   protected String generateBuiltIn = null;
+  protected static GeneratedPackages generatedPackages = null;
+  protected boolean allNamespaces = false;

   protected int handleArgument(String args[], int index)
   {
     if (args[index].equalsIgnoreCase("-schemaNamespace"))
     {
       schemaNamespace = args[++index];
+      if( "all".equalsIgnoreCase(schemaNamespace) )
+      {
+        schemaNamespace = null;
+        allNamespaces = true;
+      }
     }
     else if (args[index].equalsIgnoreCase("-generateBuiltIn"))
     {
       // Internal option used when regenerating one of the built-in
(predefined) models (e.g., commonj.sdo).
       generateBuiltIn = args[++index];
     }
+    else if (args[index].equalsIgnoreCase("-namespaceInfo"))
+    {
+        namespaceInfo = args[++index];
+    }
     else
     {
       return super.handleArgument(args, index);
@@ -104,21 +137,36 @@
   protected void run(String args[])
   {
     String xsdFileName = args[inputIndex];
-    generateFromXMLSchema(xsdFileName, schemaNamespace,
targetDirectory, javaPackage, prefix, genOptions, generateBuiltIn);
+    EPackage.Registry packageRegistry = new
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
+    ExtendedMetaData extendedMetaData = new
BasicExtendedMetaData(packageRegistry);
+    String packageURI = getSchemaNamespace(xsdFileName);
+    Hashtable packageInfoTable = createPackageInfoTable(packageURI,
schemaNamespace, javaPackage, prefix, namespaceInfo );
+    generateFromXMLSchema(xsdFileName, packageRegistry,
extendedMetaData, targetDirectory, packageInfoTable, genOptions,
generateBuiltIn, allNamespaces);
   }

   public static void generateFromXMLSchema(String xsdFileName, String
namespace, String targetDirectory, String javaPackage, String prefix,
int genOptions)
   {
-    generateFromXMLSchema(xsdFileName, namespace, targetDirectory,
javaPackage, prefix, genOptions, null);
+    EPackage.Registry packageRegistry = new
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
+    ExtendedMetaData extendedMetaData = new
BasicExtendedMetaData(packageRegistry);
+    String packageURI = getSchemaNamespace(xsdFileName);
+    Hashtable packageInfoTable = createPackageInfoTable(packageURI,
namespace, javaPackage, prefix, null );
+    generateFromXMLSchema(xsdFileName, packageRegistry,
extendedMetaData, targetDirectory, packageInfoTable, genOptions, null,
false );
   }

-  protected static void generateFromXMLSchema(String xsdFileName,
String namespace, String targetDirectory, String javaPackage, String
prefix, int genOptions, String regenerateBuiltIn)
+
+  protected static GenModel generateFromXMLSchema(String xsdFileName,
+                                                  EPackage.Registry
packageRegistry,
+                                                  ExtendedMetaData
extendedMetaData,
+                                                  String targetDirectory,
+                                                  Hashtable packageInfoTable,
+                                                  int genOptions,
+                                                  String regenerateBuiltIn,
+                                                  boolean allNamespaces )
   {
+    GenModel genModel = null;
+
     DataObjectUtil.initRuntime();
-    EPackage.Registry packageRegistry = new
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
-    ExtendedMetaData extendedMetaData = new
BasicExtendedMetaData(packageRegistry);
     XSDHelper xsdHelper = new XSDHelperImpl(extendedMetaData,
regenerateBuiltIn);
-
     try
     {
       File inputFile = new File(xsdFileName).getAbsoluteFile();
@@ -136,10 +184,27 @@

       if (!packageRegistry.values().isEmpty())
       {
-        String packageURI = namespace != null ? namespace :
getSchemaNamespace(xsdFileName);
-        generatePackages(packageRegistry.values(), packageURI, null,
targetDirectory, javaPackage, prefix, genOptions);
+        genModel = generatePackages(packageRegistry.values(),
targetDirectory, packageInfoTable, genOptions, allNamespaces );
+        // For now, this option is not supported
+        /*
+        if(  (genModel != null) )
+        {
+          if((extendedMetaData != null))
+          {
+            // Display only, will report all namespaces and
associated packages found
+            List genPackages = genModel.getGenPackages();
+            for (Iterator iter = genPackages.iterator(); iter.hasNext();)
+            {
+              GenPackage genPackage = (GenPackage)iter.next();
+              EPackage ecorePackage = genPackage.getEcorePackage();
+              if( (genOptions & OPTION_DISPLAY_NAMESPACES) != 0)
+
System.out.println(extendedMetaData.getNamespace(ecorePackage)+";"+genPackage.getInterfacePackageName()+"."+ecorePackage.getName());
+            }
+          }
+        }
+        */
       }
-
+
       /*
       for (Iterator iter = packageRegistry.values().iterator();
iter.hasNext();)
       {
@@ -157,6 +222,7 @@
     {
       e.printStackTrace();
     }
+    return genModel;
   }

   public static String getSchemaNamespace(String xsdFileName)
@@ -175,6 +241,7 @@
     System.out.println("  [ -javaPackage <java-package-name> ]");
     System.out.println("  [ -prefix <prefix-string> ]");
     System.out.println("  [ -schemaNamespace <namespace-uri> ]");
+    System.out.println("  [ -namespaceInfo <namespaces-file> ]");
     System.out.println("  [ -noInterfaces ]");
     System.out.println("  [ -noContainment ]");
     System.out.println("  [ -noNotification ]");
@@ -190,4 +257,208 @@
     System.out.println("  generate somedir/somefile.xsd");
   }

+  public void generateFromXMLSchema(String args[])
+  {
+    try
+    {
+      processArguments(args);
+      EPackage.Registry packageRegistry = new
EPackageRegistryImpl(EPackage.Registry.INSTANCE);
+      ExtendedMetaData extendedMetaData = new
BasicExtendedMetaData(packageRegistry);
+      String xsdFileName = args[inputIndex];
+      String packageURI = getSchemaNamespace(xsdFileName);
+      Hashtable packageInfoTable = createPackageInfoTable(packageURI,
schemaNamespace, javaPackage, prefix, namespaceInfo );
+      GenModel genModel = generateFromXMLSchema(xsdFileName,
packageRegistry, extendedMetaData, targetDirectory, packageInfoTable,
genOptions, generateBuiltIn, allNamespaces);
+      generatedPackages = new GeneratedPackages(genModel,extendedMetaData);
+    }
+    catch (IllegalArgumentException e)
+    {
+      printUsage();
+    }
+  }
+
+  private static Hashtable createPackageInfoTable( String packageURI,
String schemaNamespace, String javaPackage, String prefix, String
namespaceInfo )
+  {
+    Hashtable packageInfoTable = new Hashtable();
+
+    if( namespaceInfo != null )
+    {
+      try
+      {
+        FileReader inputFile = new FileReader(namespaceInfo);
+        BufferedReader bufRead = new BufferedReader(inputFile);
+
+        String line = bufRead.readLine();
+        while( line != null )
+        {
+          if( line.length() > 0 )
+          {
+            String [] options = line.split(";");
+            if( options.length > 1 )
+            {
+              if( options.length > 2 )
+                packageInfoTable.put(options[0], new
PackageInfo(options[1], options[2], options[0], null ));
+              else
+                packageInfoTable.put(options[0], new
PackageInfo(options[1], null, options[0], null ));
+            }
+            else
+              packageInfoTable.put(options[0], new PackageInfo(null,
null, options[0], null ));
+          }
+              line = bufRead.readLine();
+        }
+      }
+      catch (IOException e)
+      {
+        e.printStackTrace();
+      }
+    }
+    else
+    {
+        if( schemaNamespace != null )
+            packageInfoTable.put(schemaNamespace, new
PackageInfo(javaPackage, prefix, schemaNamespace, null ));
+        else
+            packageInfoTable.put(packageURI, new
PackageInfo(javaPackage, prefix, null, null ));
+    }
+    return packageInfoTable;
+  }
+
+  public List getGeneratedPackageInfo()
+  {
+    if( generatedPackages != null )
+      return generatedPackages.getPackageList();
+    else
+      return null;
+  }
+
+  protected class GeneratedPackages
+  {
+    private List genPackages = null;
+
+    GeneratedPackages(GenModel genModel, ExtendedMetaData extendedMetaData)
+    {
+      List packages = genModel.getGenPackages();
+      Hashtable genClasses = new Hashtable();
+      for (Iterator iter = packages.iterator(); iter.hasNext();)
+      {
+        // loop through the list, once to build up the eclass to
genclass mapper
+        GenPackage genPackage = (GenPackage)iter.next();
+        List classes = genPackage.getGenClasses();
+        for (Iterator classIter = classes.iterator(); classIter.hasNext();)
+        {
+          GenClass genClass = (GenClass)classIter.next();
+          genClasses.put(genClass.getEcoreClass(), genClass);
+        }
+      }
+      genPackages = new ArrayList();
+      for (Iterator iter = packages.iterator(); iter.hasNext();)
+      {
+        // now process the pckage list
+        GenPackage genPackage = (GenPackage)iter.next();
+        genPackages.add(new
GeneratedPackage(genPackage,extendedMetaData,genClasses));
+      }
+    }
+
+    List getPackageList() {return genPackages;}
+  }
+
+  public class GeneratedPackage
+  {
+    private String namespace;
+    private List   classes;
+
+    public String getNamespace() {return namespace;}
+    public List getClasses() {return classes;}
+
+    GeneratedPackage(GenPackage genPackage, ExtendedMetaData
extendedMetaData, Hashtable eclassGenClassMap )
+    {
+      classes = new ArrayList();
+
+      EPackage ePackage = genPackage.getEcorePackage();
+      namespace     = extendedMetaData.getNamespace(ePackage);
+
+      List genClasses = genPackage.getGenClasses();
+      for (Iterator iterClass = genClasses.iterator(); iterClass.hasNext();)
+      {
+        GenClass genClass = (GenClass)iterClass.next();
+        if( !("DocumentRoot".equals(genClass.getInterfaceName())))
+        {
+          String name  = extendedMetaData.getName(genClass.getEcoreClass());
+          String className = genPackage.getInterfacePackageName() +
"." + genClass.getInterfaceName();
+          classes.add( new PackageClassInfo( name, className, false, null ) );
+          EClass documentRoot = extendedMetaData.getDocumentRoot(ePackage);
+          if( documentRoot != null )
+          {
+            List rootElements = extendedMetaData.getElements(documentRoot);
+            for (Iterator iterRoot = rootElements.iterator();
iterRoot.hasNext();)
+            {
+              EStructuralFeature element = (EStructuralFeature)iterRoot.next();
+              EClassifier elementType = element.getEType();
+              if( elementType instanceof EClass )
+              {
+                // complex type
+                EClass eClass = (EClass)elementType;
+                GenClass genEClass =
(GenClass)eclassGenClassMap.get(elementType);
+                name = extendedMetaData.getName(element);
+                String interfaceName =
genEClass.getGenPackage().getInterfacePackageName()
+                       + '.' + genEClass.getInterfaceName();
+                boolean anonymous = extendedMetaData.isAnonymous(eClass);
+
+                // Build list of property class names
+                List propertyClassNames = new ArrayList();
+                List properties = eClass.getEStructuralFeatures();
+                for (Iterator iterProperties = properties.iterator();
iterProperties.hasNext();)
+                {
+                  EStructuralFeature feature =
(EStructuralFeature)iterProperties.next();
+                  EClassifier propertyType = feature.getEType();
+                  if (propertyType instanceof EClass)
+                  {
+                    GenClass propertyGenClass =
(GenClass)eclassGenClassMap.get(propertyType);
+                    if( propertyGenClass != null )
+                    {
+                      String propertyClassName =
propertyGenClass.getGenPackage().getInterfacePackageName() + '.'
+                                                  +
propertyGenClass.getInterfaceName();
+                      propertyClassNames.add(propertyClassName);
+                    }
+                  }
+                  else if (propertyType instanceof EClassifier)
+                  {
+                    String propertyClassName =
propertyType.getInstanceClass().getName();
+                    propertyClassNames.add(propertyClassName);
+                  }
+                }
+                classes.add( new PackageClassInfo( name,
interfaceName, anonymous, propertyClassNames ) );
+              }
+              else
+              {
+                // simple type
+                name  = extendedMetaData.getName(element);
+                className = elementType.getInstanceClass().getName();
+                classes.add( new PackageClassInfo( name, className,
false, null ) );
+              }
+            }
+          }
+        }
+      }
+    }
+
+    public class PackageClassInfo
+    {
+      private String name;
+      private String className = null;
+      private boolean anonymous = false;
+      private List properties = null;
+
+      PackageClassInfo( String name, String className, boolean
anonymous, List properties )
+      {
+        this.name = name;
+        this.className = className;
+        this.anonymous = anonymous;
+        this.properties = properties;
+      }
+
+      public String getName() {return name;}
+      public String getClassName() {return className;}
+      public boolean getAnonymous() {return anonymous;}
+      public List getProperties() {return properties;}
+    }
+  }
 }

Modified: incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java?view=diff&rev=543520&r1=543519&r2=543520
==============================================================================
--- incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
(original)
+++ incubator/tuscany/java/sdo/tools/src/main/java/org/apache/tuscany/sdo/generate/templates/model/SDOFactoryClass.java
Fri Jun  1 09:04:20 2007
@@ -139,7 +139,7 @@
   protected final String TEXT_99 = ".NAMESPACE_URI);" + NL + "\t\t";
   protected final String TEXT_100 = " the";
   protected final String TEXT_101 = " = new ";
-  protected final String TEXT_102 = "();" + NL + "\t\tisInited =
true;" + NL + "" + NL + "\t\t// Initialize simple dependencies";
+  protected final String TEXT_102 = "();" + NL + "\t\tisInited =
true;" + NL + "" + NL + "\t\t// Initialize dependencies";
   protected final String TEXT_103 = NL + "\t\t";
   protected final String TEXT_104 = ".registerStaticTypes(";
   protected final String TEXT_105 = ".class);";
@@ -623,7 +623,9 @@
     stringBuffer.append(TEXT_101);
     stringBuffer.append(factoryType);
     stringBuffer.append(TEXT_102);
-    for (Iterator
p=genPackage.getPackageSimpleDependencies().iterator(); p.hasNext();)
{ GenPackage dep = (GenPackage)p.next();
+    HashSet packages = new HashSet(genPackage.getPackageSimpleDependencies());
+    for (Iterator
p=genPackage.getPackageInitializationDependencies().iterator();
p.hasNext();) { packages.add(p.next()); }
+    for (Iterator p=packages.iterator(); p.hasNext();) { GenPackage
dep = (GenPackage)p.next();
     stringBuffer.append(TEXT_103);
     stringBuffer.append(genModel.getImportedName("org.apache.tuscany.sdo.util.SDOUtil"));
     stringBuffer.append(TEXT_104);

Modified: incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet?view=diff&rev=543520&r1=543519&r2=543520
==============================================================================
--- incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet
(original)
+++ incubator/tuscany/java/sdo/tools/templates/models/SDOFactoryClass.javajet
Fri Jun  1 09:04:20 2007
@@ -258,8 +258,10 @@
                <%=factoryType%> the<%=factoryType%> = new <%=factoryType%>();
                isInited = true;

-               // Initialize simple dependencies
-  <%for (Iterator
p=genPackage.getPackageSimpleDependencies().iterator(); p.hasNext();)
{ GenPackage dep = (GenPackage)p.next();%>
+               // Initialize dependencies
+  <%HashSet packages = new
HashSet(genPackage.getPackageSimpleDependencies());%>
+  <%for (Iterator
p=genPackage.getPackageInitializationDependencies().iterator();
p.hasNext();) { packages.add(p.next()); }%>
+  <%for (Iterator p=packages.iterator(); p.hasNext();) { GenPackage
dep = (GenPackage)p.next();%>

<%=genModel.getImportedName("org.apache.tuscany.sdo.util.SDOUtil")%>.registerStaticTypes(<%=dep.getImportedFactoryInterfaceName()%>.class);
   <%}%>




---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org



-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Mime
View raw message