You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ri...@apache.org on 2006/05/15 21:19:34 UTC

svn commit: r406719 - in /incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin: GeneratorMojo.java SchemaFileOption.java

Author: rineholt
Date: Mon May 15 12:19:33 2006
New Revision: 406719

URL: http://svn.apache.org/viewcvs?rev=406719&view=rev
Log:
TUSCANY-263
http://issues.apache.org/jira/browse/TUSCANY-263
Applied Kapil D Katyal patch Thanks!!

Added:
    incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/SchemaFileOption.java
Modified:
    incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java

Modified: incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java?rev=406719&r1=406718&r2=406719&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java (original)
+++ incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/GeneratorMojo.java Mon May 15 12:19:33 2006
@@ -23,7 +23,9 @@
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+
 import org.apache.tuscany.sdo.generate.JavaGenerator;
+import org.apache.tuscany.sdo.generate.XSD2JavaGenerator;
 
 /**
  * @version $Rev$ $Date$
@@ -34,71 +36,80 @@
 public class GeneratorMojo extends AbstractMojo {
     /**
      * The directory containing schema files; defaults to ${basedir}/src/main/xsd
+     * 
      * @parameter expression="${basedir}/src/main/xsd"
      */
     private String schemaDir;
 
     /**
      * Name of the schema file; if omitted all files in the directory are processed
+     * 
      * @parameter
      */
     private File schemaFile;
 
     /**
      * The Java package to generate into. By default the value is derived from the schema URI.
-     *
+     * 
      * @parameter
      */
     private String javaPackage;
 
     /**
      * The directory to generate into; defaults to ${project.build.directory}/sdo-source
-     *
+     * 
      * @parameter expression="${project.build.directory}/sdo-source"
      */
     private String targetDirectory;
 
     /**
-     * Specifies the prefix string to use for naming the generated factory. 
+     * Specifies the prefix string to use for naming the generated factory.
+     * 
      * @parameter
      */
     private String prefix;
 
     /**
-     * This option can be used to eliminate the generated interface and to generate only an implementation class. 
+     * This option can be used to eliminate the generated interface and to generate only an implementation class.
+     * 
      * @parameter
      */
-    private boolean noInterfaces;
+    private Boolean noInterfaces;
 
     /**
-     * Turns off container management for containment properties.  
+     * Turns off container management for containment properties.
+     * 
      * @parameter
      */
-    private boolean noContainment;
+    private Boolean noContainment;
 
     /**
-     * This option eliminates all change notification overhead in the generated classes.   
+     * This option eliminates all change notification overhead in the generated classes.
+     * 
      * @parameter
      */
-    private boolean noNotification;
+    private Boolean noNotification;
 
     /**
-     * With this option, all generated properties will not record their unset state. 
+     * With this option, all generated properties will not record their unset state.
+     * 
      * @parameter
      */
-    private boolean noUnsettable;
+    private Boolean noUnsettable;
 
     /**
-     * Generate a fast XML parser/loader for instances of the model.   
+     * Generate a fast XML parser/loader for instances of the model.
+     * 
      * @parameter
      */
-    private boolean generateLoader;
+    private Boolean generateLoader;
 
     /**
-     * Generate a Switch class for the model.   
+     * Generate a Switch class for the model.
+     * 
      * @parameter
      */
-    private boolean generateSwitch;
+    private Boolean generateSwitch;
 
     /**
      * @parameter expression="${project.compileSourceRoots}"
@@ -106,47 +117,138 @@
      */
     private List compilerSourceRoots;
 
+    /**
+     * With this option, generated code will not have EMF references.
+     * 
+     * @parameter
+     */
+    private Boolean noEMF;
+
+    /**
+     * Support for generating multiple schema files.
+     * 
+     * @parameter
+     */
+    private SchemaFileOption[] schemaFiles;
+
     public void execute() throws MojoExecutionException {
-        File[] files;
-        if (schemaFile == null) {
-            files = new File(schemaDir).listFiles(FILTER);
-        } else {
-            files = new File[]{schemaFile};
-        }
         
-        int genOptions = 0;
-        if (noInterfaces) {
-          genOptions |= JavaGenerator.OPTION_NO_INTERFACES;
-        }
-        if (noContainment) {
-          genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT;
-        }
-        if (noNotification) {
-          genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION;
-        }
-        if (generateLoader) {
-          genOptions |= JavaGenerator.OPTION_GENERATE_LOADER;
-        }
-        if (noUnsettable) {
-          genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE;
+        // check for schemaFiles parameter first, if properties are not set, use global property
+        if (null != schemaFiles) {
+            for (int i = 0; i < schemaFiles.length; ++i) {
+                SchemaFileOption sf = schemaFiles[i];
+
+                if (null == sf.getTargetDirectory()) {
+                    sf.setTargetDirectory(targetDirectory);
+                }
+                if (null == sf.getJavaPackage()) {
+                    sf.setJavaPackage(javaPackage);
+                }
+                if (null == sf.isNoInterfaces()) {
+                    sf.setNoInterfaces(noInterfaces);
+                }
+                if (null == sf.isNoContainment()) {
+                    sf.setNoContainment(noContainment);
+                }
+                if (null == sf.isNoNotification()) {
+                    sf.setNoNotification(noNotification);
+                }
+                if (null == sf.isNoUnsettable()) {
+                    sf.setNoUnsettable(noUnsettable);
+                }
+                if (null == sf.isGenerateLoader()) {
+                    sf.setGenerateLoader(generateLoader);
+                }
+                if (null == sf.isGenerateSwitch()) {
+                    sf.setGenerateSwitch(generateSwitch);
+                }
+                if (null == sf.getCompilerSourceRoots()) {
+                    sf.setCompilerSourceRoots(compilerSourceRoots);
+                }
+                if (null == sf.isNoEMF()) {
+                    sf.setNoEMF(noEMF);
+                }
+                if (sf.getFileName() == null || sf.getFileName().length() == 0) {
+                    throw new MojoExecutionException("no fileName specfied for schema.");
+                }
+                if (!sf.getFileName().canRead() || !sf.getFileName().isFile()) {
+
+                    throw new MojoExecutionException("file can not be read:" + sf.getFileName());
+                }
+            }
+        } else {
+            
+            if (schemaFile == null) {
+                File[] files = new File(schemaDir).listFiles(FILTER);
+                schemaFiles = new SchemaFileOption[files.length];
+                for (int i = files.length - 1; i > -1; --i) {
+                    schemaFiles[i] = new SchemaFileOption();
+                    schemaFiles[i].setFileName(files[i]);
+                    schemaFiles[i].setJavaPackage(javaPackage);
+                    schemaFiles[i].setCompilerSourceRoots(compilerSourceRoots);
+                    schemaFiles[i].setGenerateLoader(generateLoader);
+                    schemaFiles[i].setGenerateSwitch(generateSwitch);
+                    schemaFiles[i].setNoContainment(noContainment);
+                    schemaFiles[i].setNoEMF(noEMF);
+                    schemaFiles[i].setNoInterfaces(noInterfaces);
+                    schemaFiles[i].setNoNotification(noNotification);
+                    schemaFiles[i].setNoUnsettable(noUnsettable);
+                    schemaFiles[i].setPrefix(prefix);
+                    schemaFiles[i].setTargetDirectory(targetDirectory);
+                }
+            } else {
+                schemaFiles = new SchemaFileOption[] { new SchemaFileOption() };
+                schemaFiles[0].setFileName(schemaFile);
+                schemaFiles[0].setJavaPackage(javaPackage);
+                schemaFiles[0].setCompilerSourceRoots(compilerSourceRoots);
+                schemaFiles[0].setGenerateLoader(generateLoader);
+                schemaFiles[0].setGenerateSwitch(generateSwitch);
+                schemaFiles[0].setNoContainment(noContainment);
+                schemaFiles[0].setNoEMF(noEMF);
+                schemaFiles[0].setNoInterfaces(noInterfaces);
+                schemaFiles[0].setNoNotification(noNotification);
+                schemaFiles[0].setNoUnsettable(noUnsettable);
+                schemaFiles[0].setPrefix(prefix);
+                schemaFiles[0].setTargetDirectory(targetDirectory);
+            }
         }
-        if (generateSwitch) {
-            genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH;
-          }
-
-        for (int i = 0; i < files.length; i++) {
-            File file = files[i];
-            if(!file.exists())
-                throw new MojoExecutionException("The following WSDL file not found '" +file.getAbsolutePath()+"'.");
-            File marker = new File(targetDirectory, ".gen#" + file.getName()+".xsd2java");
-            if ( file.lastModified() > marker.lastModified()) {
+
+        for (int i = 0; i < schemaFiles.length; i++) {
+            File file = schemaFiles[i].getFileName();
+            File marker = new File(targetDirectory, ".gen#" + file.getName());
+            if (file.lastModified() > marker.lastModified()) {
                 getLog().info("Generating SDO interfaces from " + file);
-                JavaGenerator.generateFromXMLSchema(file.toString(), targetDirectory, javaPackage, prefix, genOptions);
+                
+                int genOptions = 0;
+
+                if (schemaFiles[i].isNoInterfaces() != null && schemaFiles[i].isNoInterfaces().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_NO_INTERFACES;
+                }
+                if (schemaFiles[i].isNoContainment() != null && schemaFiles[i].isNoContainment().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT;
+                }
+                if (schemaFiles[i].isNoNotification() != null && schemaFiles[i].isNoNotification().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION;
+                }
+                if (schemaFiles[i].isGenerateLoader() != null && schemaFiles[i].isGenerateLoader().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_GENERATE_LOADER;
+                }
+                if (schemaFiles[i].isNoUnsettable() != null && schemaFiles[i].isNoUnsettable().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE;
+                }
+                if (schemaFiles[i].isGenerateSwitch() != null && schemaFiles[i].isGenerateSwitch().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH;
+                }
+                if (schemaFiles[i].isNoEMF() != null && schemaFiles[i].isNoEMF().booleanValue()) {
+                    genOptions |= JavaGenerator.OPTION_NO_EMF;
+                }
+                
+                XSD2JavaGenerator.generateFromXMLSchema(file.toString(), targetDirectory, javaPackage, prefix, genOptions);
             }
             try {
                 marker.createNewFile();
             } catch (IOException e) {
-                throw new MojoExecutionException(e.getMessage() + "'"+ marker.getAbsolutePath()+ "'", e);
+                throw new MojoExecutionException(e.getMessage() + "'" + marker.getAbsolutePath() + "'", e);
             }
             marker.setLastModified(System.currentTimeMillis());
         }
@@ -159,4 +261,4 @@
             return (pathname.isFile() || !pathname.isHidden());
         }
     };
-}
\ No newline at end of file
+}

Added: incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/SchemaFileOption.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/SchemaFileOption.java?rev=406719&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/SchemaFileOption.java (added)
+++ incubator/tuscany/java/sdo/plugin/src/main/java/org/apache/tuscany/sdo/plugin/SchemaFileOption.java Mon May 15 12:19:33 2006
@@ -0,0 +1,189 @@
+package org.apache.tuscany.sdo.plugin;
+
+import java.io.File;
+import java.util.List;
+
+public class SchemaFileOption {
+    
+    /**
+     * Name of the schema file
+     * 
+     */
+    private File fileName;
+    
+    /**
+     * The Java package to generate into. By default the value is derived from the schema URI.
+     * 
+     * @parameter
+     */
+    private String javaPackage;
+
+    /**
+     * The directory to generate into; defaults to ${project.build.directory}/sdo-source
+     * 
+     * @parameter expression="${project.build.directory}/sdo-source"
+     */
+    private String targetDirectory;
+
+    /**
+     * Specifies the prefix string to use for naming the generated factory.
+     * 
+     * @parameter
+     */
+    private String prefix;
+
+    /**
+     * This option can be used to eliminate the generated interface and to generate only an implementation class.
+     * 
+     * @parameter
+     */
+    private Boolean noInterfaces;
+
+    /**
+     * Turns off container management for containment properties.
+     * 
+     * @parameter
+     */
+    private Boolean noContainment;
+
+    /**
+     * This option eliminates all change notification overhead in the generated classes.
+     * 
+     * @parameter
+     */
+    private Boolean noNotification;
+
+    /**
+     * With this option, all generated properties will not record their unset state.
+     * 
+     * @parameter
+     */
+    private Boolean noUnsettable;
+
+    /**
+     * Generate a fast XML parser/loader for instances of the model.
+     * 
+     * @parameter
+     */
+    private Boolean generateLoader;
+
+    /**
+     * Generate a Switch class for the model.
+     * 
+     * @parameter
+     */
+    private Boolean generateSwitch;
+
+    /**
+     * @parameter expression="${project.compileSourceRoots}"
+     * @readonly
+     */
+    private List compilerSourceRoots;
+
+    /**
+     * With this option, generated code will not have EMF references.
+     * 
+     * @parameter
+     */
+    private Boolean noEMF;
+
+    public SchemaFileOption() {
+    }
+
+    public List getCompilerSourceRoots() {
+        return compilerSourceRoots;
+    }
+
+    public void setCompilerSourceRoots(List compilerSourceRoots) {
+        this.compilerSourceRoots = compilerSourceRoots;
+    }
+
+    public Boolean isGenerateLoader() {
+        return generateLoader;
+    }
+
+    public void setGenerateLoader(Boolean generateLoader) {
+        this.generateLoader = generateLoader;
+    }
+
+    public Boolean isGenerateSwitch() {
+        return generateSwitch;
+    }
+
+    public void setGenerateSwitch(Boolean generateSwitch) {
+        this.generateSwitch = generateSwitch;
+    }
+
+    public String getJavaPackage() {
+        return javaPackage;
+    }
+
+    public void setJavaPackage(String javaPackage) {
+        this.javaPackage = javaPackage;
+    }
+
+    public Boolean isNoContainment() {
+        return noContainment;
+    }
+
+    public void setNoContainment(Boolean noContainment) {
+        this.noContainment = noContainment;
+    }
+
+    public Boolean isNoEMF() {
+        return noEMF;
+    }
+
+    public void setNoEMF(Boolean noEMF) {
+        this.noEMF = noEMF;
+    }
+
+    public Boolean isNoInterfaces() {
+        return noInterfaces;
+    }
+
+    public void setNoInterfaces(Boolean noInterfaces) {
+        this.noInterfaces = noInterfaces;
+    }
+
+    public Boolean isNoNotification() {
+        return noNotification;
+    }
+
+    public void setNoNotification(Boolean noNotification) {
+        this.noNotification = noNotification;
+    }
+
+    public Boolean isNoUnsettable() {
+        return noUnsettable;
+    }
+
+    public void setNoUnsettable(Boolean noUnsettable) {
+        this.noUnsettable = noUnsettable;
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public void setPrefix(String prefix) {
+        this.prefix = prefix;
+    }
+
+    public String getTargetDirectory() {
+        return targetDirectory;
+    }
+
+    public void setTargetDirectory(String targetDirectory) {
+        this.targetDirectory = targetDirectory;
+    }
+
+    public File getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(File fileName) {
+        this.fileName = fileName;
+    }
+
+}