You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2003/12/13 08:56:29 UTC

cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar ExplodedTylarImpl.java TylarWriter.java

pcal        2003/12/12 23:56:29

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompiler.java BindingCompilerTask.java
                        Java2Schema.java Schema2Java.java
                        Schema2JavaTask.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/joust
                        Expression.java FileWriterFactory.java
                        JavaOutputStream.java SourceJavaOutputStream.java
                        ValidatingJavaOutputStream.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        ExplodedTylarImpl.java TylarWriter.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/joust
                        CompilingJavaOutputStream.java
  Log:
  finish schema2java upgrade, fix bugs.  javac runs on generated sources now.
  
  Revision  Changes    Path
  1.2       +113 -19   xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java
  
  Index: BindingCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingCompiler.java	12 Dec 2003 01:12:55 -0000	1.1
  +++ BindingCompiler.java	13 Dec 2003 07:56:28 -0000	1.2
  @@ -55,10 +55,8 @@
   */
   package org.apache.xmlbeans.impl.binding.compile;
   
  -import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylar;
  -import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
  -import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
  -import org.apache.xmlbeans.impl.binding.tylar.Tylar;
  +import org.apache.xmlbeans.impl.binding.tylar.*;
  +import org.apache.xmlbeans.impl.binding.joust.CompilingJavaOutputStream;
   import org.apache.xmlbeans.impl.jam.JElement;
   import java.io.File;
   import java.io.IOException;
  @@ -89,11 +87,26 @@
     // Variables
   
     private BindingLogger mLogger = DEFAULT_LOG;
  -  private boolean mAnyErrors = false;
  +  private boolean mAnyErrorsFound = false;
     private boolean mIgnoreErrors = false;
  +  private boolean mVerbose = false;
  +  private boolean mDoCompile = true;
  +
  +  // this is the joust we use to build up the tylar that is passed to
  +  // the subclass' bind() methods in all cases.  However, BindingCompiler
  +  // makes no assumption that the subclass will actually make use of any
  +  // of the codegen facilities - they're just there if you want them.
  +  private CompilingJavaOutputStream mJoust;
  +
  +  // ========================================================================
  +  // Constructors
  +
  +  public BindingCompiler() {
  +    mJoust = new CompilingJavaOutputStream();
  +  }
   
     // ========================================================================
  -  // Abstract methods
  +  // Abstract/Overrideable methods
   
     /**
      * Implemented by extending class, does the real binding work using the
  @@ -112,9 +125,14 @@
      */
     public ExplodedTylar bindAsExplodedTylar(File tylarDestDir)
     {
  -    ExplodedTylarImpl tylar = null;
  +    mJoust.setSourceDir(new File(tylarDestDir,TylarConstants.SRC_ROOT));
  +    if (mDoCompile) {
  +      // signal the compile outputstream to compile classes
  +      mJoust.setCompilationDir(tylarDestDir);
  +    }
  +    ExplodedTylarImpl tylar;
       try {
  -      tylar = ExplodedTylarImpl.create(tylarDestDir);
  +      tylar = ExplodedTylarImpl.create(tylarDestDir,mJoust);
       } catch(IOException ioe) {
         logError(ioe);
         return null;
  @@ -125,8 +143,16 @@
           return null;
         }
       }
  -    bind(tylar);
  -    return !mAnyErrors || mIgnoreErrors ? tylar : null;
  +    bind((TylarWriter)tylar);
  +    try {
  +      // close it up.  this may cause the generated code to be compiled.
  +      System.out.println("COMPILE!!!!!!!!!!!!!!!!!!");
  +      if (mDoCompile) logVerbose("Compiling java sources...");
  +      tylar.close();
  +    } catch(IOException ioe) {
  +      logError(ioe);
  +    }
  +    return !mAnyErrorsFound || mIgnoreErrors ? tylar : null;
     }
   
     /**
  @@ -167,6 +193,53 @@
       mIgnoreErrors = true;
     }
   
  +  /**
  +   * Sets whether this BindingCompiler should keep any generated java source
  +   * code it generates.  The default is true.  Note that not all
  +   * BindingCompilers generate any source code at all, so setting this may
  +   * have no effect.
  +   */
  +  public void setCompileJava(boolean b) {
  +    mDoCompile = b;
  +  }
  +
  +  /**
  +   * Sets the location of javac to be invoked.  Default compiler is used
  +   * if this is not set.  Ignored if doCompile is set to false.  Also note
  +   * that not all BindingCompilers generate any source code at all, so
  +   * setting this may have no effect.
  +   */
  +  public void setJavac(String javacPath) {
  +    mJoust.setJavac(javacPath);
  +  }
  +
  +  /**
  +   * Sets the classpath to use for compilation of generated sources.
  +   * The System classpath is used by default.  This is ignored if doCompile is
  +   * false.  Also note that not all BindingCompilers generate any source
  +   * code at all, so setting this may have no effect.
  +   */
  +  public void setJavacClasspath(File[] classpath) {
  +    mJoust.setJavacClasspath(classpath);
  +  }
  +
  +  /**
  +   * Sets whether this BindingCompiler should keep any generated java source
  +   * code it generates.  The default is true.  This will have no effect if
  +   * doCompile is set to false.  Also note that not all BindingCompilers
  +   * generate any source code at all, so setting this may have no effect.
  +   */
  +  public void setKeepGeneratedJava(boolean b) {
  +    mJoust.setKeepGenerated(b);
  +  }
  +
  +  /**
  +   * Enables verbose output to our BindingLogger.
  +   */
  +  public void setVerbose(boolean b) {
  +    mJoust.setVerbose(b);
  +    mVerbose = b;
  +  }
   
     // ========================================================================
     // Protected logging methods
  @@ -176,10 +249,13 @@
      * on the given java construct.  The binding process should attempt
      * to continue even after such errors are encountered so as to identify
      * as many errors as possible in a single pass.
  +   *
  +   * @return true if processing should attempt to continue.
      */
  -  protected void logError(JElement context, Throwable error) {
  -    mAnyErrors = true;
  +  protected boolean logError(JElement context, Throwable error) {
  +    mAnyErrorsFound = true;
       mLogger.log(Level.SEVERE,null,error,context);
  +    return mIgnoreErrors;
     }
   
     /**
  @@ -187,10 +263,14 @@
      * on the given java construct.  The binding process should attempt
      * to continue even after such errors are encountered so as to identify
      * as many errors as possible in a single pass.
  +   *
  +   * @return true if processing should attempt to continue.
  +   *
      */
  -  protected void logError(JElement context, String msg) {
  -    mAnyErrors = true;
  +  protected boolean logError(JElement context, String msg) {
  +    mAnyErrorsFound = true;
       mLogger.log(Level.SEVERE,msg,null,context);
  +    return mIgnoreErrors;
     }
   
     /**
  @@ -198,18 +278,24 @@
      * on the given java construct.  The binding process should attempt
      * to continue even after such errors are encountered so as to identify
      * as many errors as possible in a single pass.
  +   *
  +   * @return true if processing should attempt to continue.
      */
  -  protected void logError(String msg) {
  -    mAnyErrors = true;
  +  protected boolean logError(String msg) {
  +    mAnyErrorsFound = true;
       mLogger.log(Level.SEVERE,msg,null);
  +    return mIgnoreErrors;
     }
   
     /**
      * Logs a message that fatal error that occurred.
  +   *
  +   * @return true if processing should attempt to continue.
      */
  -  protected void logError(Throwable t) {
  -    mAnyErrors = true;
  +  protected boolean logError(Throwable t) {
  +    mAnyErrorsFound = true;
       mLogger.log(Level.SEVERE,null,t);
  +    return mIgnoreErrors;
     }
   
     /**
  @@ -217,7 +303,15 @@
      * mode.
      */
     protected void logVerbose(JElement context, String msg) {
  -    mLogger.log(Level.FINEST,msg,null,context);
  +    if (mVerbose) mLogger.log(Level.FINEST,msg,null,context);
  +  }
  +
  +  /**
  +   * Logs an informative message that should be printed only in 'verbose'
  +   * mode.
  +   */
  +  protected void logVerbose(String msg) {
  +    if (mVerbose) mLogger.log(Level.FINEST,msg,null);
     }
   
     // ========================================================================
  
  
  
  1.2       +27 -10    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompilerTask.java
  
  Index: BindingCompilerTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompilerTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingCompilerTask.java	12 Dec 2003 01:12:56 -0000	1.1
  +++ BindingCompilerTask.java	13 Dec 2003 07:56:28 -0000	1.2
  @@ -55,7 +55,6 @@
   */
   package org.apache.xmlbeans.impl.binding.compile;
   
  -import org.apache.tools.ant.Task;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.xmlbeans.impl.binding.tylar.Tylar;
  @@ -77,14 +76,15 @@
     private File mDestDir = null;
     private File mDestJar = null;
     private boolean mVerbose = false;
  +  private boolean mIgnoreErrors = false;
   
     // ========================================================================
     // Abstract methods
   
     /**
      * Subclasses are only responsible for getting additional attributes
  -   * and creating a BindingCompiler - this is how we get it.  This will
  -   * never be called until after the execute() method has begun.
  +   * from the ant script and creating a BindingCompiler; this is how we get
  +   * that compiler.  This will method    * never be called until after the execute() method has begun.
      */
     protected abstract BindingCompiler createCompiler() throws BuildException;
   
  @@ -105,7 +105,11 @@
       mDestJar = jar;
     }
   
  -  public void setVerbose(boolean v) { mVerbose = v; }
  +  public void setVerbose(boolean v) {
  +    mVerbose = v;
  +  }
  +
  +  public void setIgnoreErrors(boolean v) { mIgnoreErrors = v; }
   
     // ========================================================================
     // Task implementation
  @@ -116,19 +120,32 @@
      * BindingCompiler.
      */
     public final void execute() throws BuildException {
  -    BindingCompiler bc = createCompiler();
  -    bc.setLogger(createLogger());
  +    if (mDestDir == null && mDestJar == null) {
  +      throw new BuildException("must specify destdir or destjar");
  +    }
       Tylar tylar = null;
  -    if (mDestDir != null) {
  -      tylar = bc.bindAsExplodedTylar(mDestDir);
  -    } else if (mDestJar != null) {
  -      tylar = bc.bindAsJarredTylar(mDestJar);
  +    try {
  +      BindingCompiler bc = createCompiler();
  +      bc.setIgnoreSeverErrors(mIgnoreErrors);
  +      bc.setLogger(createLogger());
  +      bc.setVerbose(mVerbose);
  +      if (mDestDir != null) {
  +        tylar = bc.bindAsExplodedTylar(mDestDir);
  +      } else if (mDestJar != null) {
  +        tylar = bc.bindAsJarredTylar(mDestJar);
  +      } else {
  +        throw new IllegalStateException();
  +      }
  +    } catch(Exception unexpected) {
  +      unexpected.printStackTrace();
  +      throw new BuildException(unexpected);
       }
       if (tylar == null) {
         throw new BuildException("fatal errors encountered, "+
                                  "see log for details.");
       }
       log("binding task complete, output at "+tylar.getLocation());
  +
     }
   
     // ========================================================================
  
  
  
  1.20      +0 -5      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
  
  Index: Java2Schema.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Java2Schema.java	12 Dec 2003 01:12:56 -0000	1.19
  +++ Java2Schema.java	13 Dec 2003 07:56:28 -0000	1.20
  @@ -101,11 +101,6 @@
     private static final String TAG_AT               = "xsdgen:attribute";
     private static final String TAG_AT_NAME          = TAG_AT+".name";
   
  -  // If true, the 'bind' methods will always try to return something,
  -  // even if severe errors were encountered.  Turn this on only for
  -  // debugging.
  -  private static final boolean IGNORE_SEVERE_ERRORS = false;
  -
     // =========================================================================
     // Variables
   
  
  
  
  1.4       +49 -20    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java
  
  Index: Schema2Java.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2Java.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Schema2Java.java	12 Dec 2003 01:12:56 -0000	1.3
  +++ Schema2Java.java	13 Dec 2003 07:56:28 -0000	1.4
  @@ -70,11 +70,7 @@
   import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
   import org.apache.xmlbeans.impl.binding.joust.Variable;
   import org.apache.xmlbeans.impl.common.NameUtil;
  -import org.apache.xmlbeans.SchemaType;
  -import org.apache.xmlbeans.SchemaTypeSystem;
  -import org.apache.xmlbeans.SchemaProperty;
  -import org.apache.xmlbeans.SchemaLocalAttribute;
  -import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.*;
   import org.apache.xmlbeans.soap.SOAPArrayType;
   import org.apache.xmlbeans.soap.SchemaWSDLArrayType;
   
  @@ -117,15 +113,13 @@
     // ========================================================================
     // Constructors
   
  +
     /**
      * Consturcts a Schema2Java to work on the given inputs and using the given
      * logger.
      */
     public Schema2Java(SchemaSourceSet input) {
  -    if (input == null) throw new IllegalArgumentException("null input");
  -    this.sourceSet = input;
  -    this.sts = input.getSchemaTypeSystem();
  -    this.path = input.getTylarLoader().getBindingLoader();
  +    setInput(input);
     }
   
     // ========================================================================
  @@ -135,18 +129,40 @@
      * Computes the binding.
      */
     public void bind(TylarWriter writer) {
  +    if (sourceSet == null) throw new IllegalStateException("input never set");
       mJoust = writer.getJavaOutputStream();
  +    if (mJoust == null) throw new IllegalStateException("joust is null");
       bind();
       try {
         writer.writeBindingFile(bindingFile);
  -      //FIXME we want to also write out the input schemas, but we can't
  -      //currently get at them via SchemaSourceSet
       } catch (IOException ioe) {
  -      logError(ioe);
  +      if (!logError(ioe)) return;
  +    }
  +    //FIXME also write the input schemas
  +    try {
  +      writeJavaFiles(writer.getJavaOutputStream());
  +    } catch(IOException ioe) {
  +      if (!logError(ioe)) return;
       }
     }
   
     // ========================================================================
  +  // Package methods
  +
  +  /**
  +   * If you use this, you absolutely have to call setInput later.  This is
  +   * here just as a convenience for Schema2JavaTask.
  +   */
  +  /*package*/ Schema2Java() {}
  +
  +  /*package*/ void setInput(SchemaSourceSet input) {
  +    if (input == null) throw new IllegalArgumentException("null input");
  +    this.sourceSet = input;
  +    this.sts = input.getSchemaTypeSystem();
  +    this.path = input.getTylarLoader().getBindingLoader();
  +  }
  +
  +  // ========================================================================
     // Private methods
   
     private void bind() {
  @@ -867,6 +883,21 @@
     }
   
   
  +  // ========================================================================
  +  // Java Codegen methods
  +  //
  +  // REVIEW it may be worth factoring these methods back out into a separate
  +  // class someday.  Somebody conceivably might want to plug in here (at their
  +  // own risk, of course).   pcal 12/12/03
  +
  +  private void writeJavaFiles(JavaOutputStream joust) throws IOException {
  +    Collection classnames = getToplevelClasses();
  +    for (Iterator i = classnames.iterator(); i.hasNext();) {
  +      String className = (String) i.next();
  +      printSourceCode(className, joust);
  +    }
  +  }
  +
     /**
      * Returns a collection of fully-qualified Java class name strings
      * generated by this binding.
  @@ -886,7 +917,7 @@
     /**
      * Prints the Java source code for the given generated java class name.
      */
  -  public void printSourceCode(String topLevelClassName) {
  +  private void printSourceCode(String topLevelClassName, JavaOutputStream out) {
       Scratch scratch = scratchForJavaNameString(topLevelClassName);
       if (scratch == null) {
         logError("Could not find scratch for " + topLevelClassName); //?
  @@ -917,12 +948,10 @@
         if (baseJavaname.equals("java.lang.Object"))
           baseJavaname = null;
       }
  -    // begin writing
  +    // begin writing class
  +    mJoust.startFile(packageName,shortClassName);
       mJoust.writeComment("Generated from schema type " + scratch.getXmlName());
  -    mJoust.startClass(Modifier.PUBLIC,
  -                      packageName, shortClassName,
  -                      baseJavaname, null);
  -
  +    mJoust.startClass(Modifier.PUBLIC,baseJavaname, null);
       Collection props = scratch.getQNameProperties();
       Map fieldNames = new HashMap();
       Set seenFieldNames = new HashSet();
  @@ -961,11 +990,11 @@
                                                new String[]{jType.toString()},
                                                new String[]{fieldName},
                                                null);
  -      mJoust.writeAssignmentStatement(propertyField, params[0]);//FIXME
  -      mJoust.endMethodOrConstructor();
  +      mJoust.writeAssignmentStatement(propertyField, params[0]);
         mJoust.endMethodOrConstructor();
       }
       mJoust.endClassOrInterface();
  +    mJoust.endFile();
     }
   
     private String pickUniqueFieldName(String getter, Set seenNames) {
  
  
  
  1.4       +179 -153  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2JavaTask.java
  
  Index: Schema2JavaTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2JavaTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Schema2JavaTask.java	12 Dec 2003 01:12:56 -0000	1.3
  +++ Schema2JavaTask.java	13 Dec 2003 07:56:28 -0000	1.4
  @@ -58,175 +58,201 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
  -import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
   
   import java.io.File;
   import java.io.IOException;
   import java.util.List;
   import java.util.ArrayList;
   
  -public class Schema2JavaTask extends BindingCompilerTask
  -{
  +public class Schema2JavaTask extends BindingCompilerTask {
   
  -    // =========================================================================
  -    // Variables
  +  // =========================================================================
  +  // Variables
   
  -    private File mDestDir = null;
  -    private Path mSrc = null;
  -    private Path mClasspath = null;
  -    private List mXsdFiles = null;
  -
  -    // =========================================================================
  -    // Task attributes
  -
  -    public void setDestDir(File dir)
  -    {
  -        mDestDir = dir;
  -    }
  -
  -    /**
  -     * Set the source directories to find the source XSD files.
  -     */
  -    public void setSrcdir(Path srcDir)
  -    {
  -        if (mSrc == null) {
  -            mSrc = srcDir;
  -        }
  -        else {
  -            mSrc.append(srcDir);
  -        }
  -    }
  -
  -    /**
  -     * Adds a path for source compilation.
  -     *
  -     * @return a nested src element.
  -     */
  -    public Path createSrc() {
  -        if (mSrc == null) {
  -            mSrc = new Path(getProject());
  -        }
  -        return mSrc.createPath();
  -    }
  -
  -
  -    public void setClasspath(Path path)
  -    {
  -        if (mClasspath == null) {
  -            mClasspath = path;
  -        }
  -        else {
  -            mClasspath.append(path);
  -        }
  -    }
  -
  -    public void setClasspathRef(Reference r)
  -    {
  -        createClasspath().setRefid(r);
  -    }
  -
  -    public Path createClasspath()
  -    {
  -        if (mClasspath == null) {
  -            mClasspath = new Path(getProject());
  -        }
  -        return mClasspath.createPath();
  -    }
  -
  -    // =========================================================================
  -    // BindingCompilerTask implementation
  -
  -    /**
  -     * Execute the task.
  -     */
  -    protected BindingCompiler createCompiler() throws BuildException
  -    {
  -        //get the files
  -        checkParameters();
  -        // scan source directories and dest directory to build up
  -        startScan();
  -        
  -        String[] list = mSrc.list();
  -        for (int i = 0; i < list.length; i++) {
  -            File srcDir = getProject().resolveFile(list[i]);
  -            if (!srcDir.exists()) {
  -                throw new BuildException("srcdir \""
  -                                         + srcDir.getPath()
  -                                         + "\" does not exist!", getLocation());
  -            }
  -
  -            DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  -            String[] files = ds.getIncludedFiles();
  -
  -            scanDir(srcDir, files);
  -        }
  -        File[] xsdFiles = (File[])mXsdFiles.toArray(new File[mXsdFiles.size()]);
  -
  -        TylarLoader tylarLoader = null;
  -
  -        if (mClasspath != null) {
  -          File[] classpath = namesToFiles(mClasspath.list());
  -          tylarLoader = SimpleTylarLoader.forClassPath(classpath);
  +  private Path mXsdPath = null;
  +  private Path mClasspath = null;
  +  private List mXsdFiles = null;
  +  private Schema2Java mCompiler;
  +
  +  // ========================================================================
  +  // Constructors
  +
  +  public Schema2JavaTask() {
  +    mCompiler = new Schema2Java();
  +  }
  +
  +  // =========================================================================
  +  // Task attributes
  +
  +  /**
  +   * Sets whether this BindingCompiler should keep any generated java source
  +   * code it generates.  The default is true.  Note that not all
  +   * BindingCompilers generate any source code at all, so setting this may
  +   * have no effect.
  +   */
  +  public void setCompileJava(boolean b) {
  +    mCompiler.setCompileJava(b);
  +  }
  +
  +  /**
  +   * Sets whether this BindingCompiler should keep any generated java source
  +   * code it generates.  The default is true.  This will have no effect if
  +   * doCompile is set to false.
  +   */
  +  public void setKeepGeneratedJava(boolean b) {
  +    mCompiler.setKeepGeneratedJava(b);
  +  }
  +
  +  /**
  +   * Sets the location of javac to be invoked.  Default compiler is used
  +   * if this is not set.  Ignored if doCompile is set to false.
  +   */
  +  public void setJavac(String javacPath) {
  +    mCompiler.setJavac(javacPath);
  +  }
  +
  +  /**
  +   * Sets the classpath to use for compilation of generated sources.
  +   * The System classpath is used by default.  This is ignored if doCompile is
  +   * false.
  +   */
  +  public void setJavacClasspath(File[] classpath) {
  +    mCompiler.setJavacClasspath(classpath);
  +  }
  +
  +
  +
  +  /**
  +   * Set the source directories to find the source XSD files.
  +   */
  +  public void setSrcdir(Path srcDir) {//FIXME this is a bad name
  +    if (mXsdPath == null) {
  +      mXsdPath = srcDir;
  +    } else {
  +      mXsdPath.append(srcDir);
  +    }
  +  }
  +
  +  /**
  +   * Adds a path for source compilation.
  +   *
  +   * @return a nested src element.
  +   */
  +  public Path createSrc() {
  +    if (mXsdPath == null) {
  +      mXsdPath = new Path(getProject());
  +    }
  +    return mXsdPath.createPath();
  +  }
  +
  +
  +  public void setClasspath(Path path) {
  +    if (mClasspath == null) {
  +      mClasspath = path;
  +    } else {
  +      mClasspath.append(path);
  +    }
  +  }
  +
  +  public void setClasspathRef(Reference r) {
  +    createClasspath().setRefid(r);
  +  }
  +
  +  public Path createClasspath() {
  +    if (mClasspath == null) {
  +      mClasspath = new Path(getProject());
  +    }
  +    return mClasspath.createPath();
  +  }
  +
  +  // =========================================================================
  +  // BindingCompilerTask implementation
  +
  +  /**
  +   * Execute the task.
  +   */
  +  protected BindingCompiler createCompiler() throws BuildException {
  +    //get the files
  +    checkParameters();
  +    // scan source directories and dest directory to build up
  +    startScan();
  +
  +    String[] list = mXsdPath.list();
  +    for (int i = 0; i < list.length; i++) {
  +      File srcDir = getProject().resolveFile(list[i]);
  +      if (!srcDir.exists()) {
  +        throw new BuildException("srcdir \""
  +                                 + srcDir.getPath()
  +                                 + "\" does not exist!", getLocation());
         }
   
  -      //build up the inputs
  -      SchemaSourceSet input = null;
  -      try {
  -          input = SimpleSourceSet.forXsdFiles(xsdFiles, tylarLoader);
  -      } catch (IOException e) {
  -          log(e.getMessage());
  -          throw new BuildException(e);
  -      } catch (XmlException e) {
  -          log(e.getMessage());
  -          throw new BuildException(e);
  -      }
  -      //return the compiler
  -      return new Schema2Java(input);
  -    }
  -    
  -    protected void startScan()
  -    {
  -        mXsdFiles = new ArrayList();
  -    }
  -    
  -    protected void scanDir(File srcDir, String[] files) {
  -        for (int i = 0; i < files.length; i++)
  -            if (files[i].endsWith(".xsd"))
  -                mXsdFiles.add(new File(srcDir, files[i]));
  -    }
  -    
  -    protected File[] namesToFiles(String[] names)
  -    {
  -        File[] result = new File[names.length];
  -        for (int i = 0; i < names.length; i++)
  -            result[i] = new File(names[i]);
  -        return result;
  +      DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  +      String[] files = ds.getIncludedFiles();
  +
  +      scanDir(srcDir, files);
       }
  +    File[] xsdFiles = (File[]) mXsdFiles.toArray(new File[mXsdFiles.size()]);
   
  +    TylarLoader tylarLoader = null;
   
  -    // =========================================================================
  -    // Private methods
  -
  -    protected void checkParameters() throws BuildException {
  -        if (mSrc == null) {
  -            throw new BuildException("srcdir attribute must be set!",
  -                                     getLocation());
  -        }
  -        if (mSrc.size() == 0) {
  -            throw new BuildException("srcdir attribute must be set!",
  -                                     getLocation());
  -        }
  -
  -        if (mDestDir != null && !mDestDir.isDirectory()) {
  -            throw new BuildException("destination directory \""
  -                                     + mDestDir
  -                                     + "\" does not exist "
  -                                     + "or is not a directory", getLocation());
  -        }
  +    /* commenting this out because it's not working correctly
  +       and i'm not sure it's the right thing to do anyway
  +      if (mClasspath != null) {
  +        File[] classpath = namesToFiles(mClasspath.list());
  +        tylarLoader = SimpleTylarLoader.forClassPath(classpath);
  +      }
  +      */
  +
  +    //build up the inputs
  +    SchemaSourceSet input = null;
  +    try {
  +      input = SimpleSourceSet.forXsdFiles(xsdFiles, tylarLoader);
  +    } catch (IOException e) {
  +      log(e.getMessage());
  +      throw new BuildException(e);
  +    } catch (XmlException e) {
  +      log(e.getMessage());
  +      throw new BuildException(e);
  +    }
  +    //return the compiler
  +    mCompiler.setInput(input);
  +    return mCompiler;
  +  }
  +
  +  protected void startScan() {
  +    mXsdFiles = new ArrayList();
  +  }
  +
  +  protected void scanDir(File srcDir, String[] files) {
  +    for (int i = 0; i < files.length; i++)
  +      if (files[i].endsWith(".xsd"))
  +        mXsdFiles.add(new File(srcDir, files[i]));
  +  }
  +
  +  protected File[] namesToFiles(String[] names) {
  +    File[] result = new File[names.length];
  +    for (int i = 0; i < names.length; i++)
  +      result[i] = new File(names[i]);
  +    return result;
  +  }
  +
  +
  +  // =========================================================================
  +  // Private methods
  +
  +  protected void checkParameters() throws BuildException {
  +    if (mXsdPath == null) {
  +      throw new BuildException("srcdir attribute must be set!",
  +                               getLocation());
  +    }
  +    if (mXsdPath.size() == 0) {
  +      throw new BuildException("srcdir attribute must be set!",
  +                               getLocation());
       }
  +
  +  }
   
   }
  
  
  
  1.2       +3 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/Expression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Expression.java	5 Dec 2003 19:59:10 -0000	1.1
  +++ Expression.java	13 Dec 2003 07:56:28 -0000	1.2
  @@ -69,6 +69,9 @@
      * represents.
      */
     public Object getMemento();
  +  //REVIEW maybe we don't need to expose memento at all - just let them
  +  //implement it however they want and cast down to get the info.  Often
  +  //as not, they may just want to implement toString().
   
     /**
      * Provides a textual representation of the expression.  This should
  
  
  
  1.3       +14 -2     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/FileWriterFactory.java
  
  Index: FileWriterFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/FileWriterFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileWriterFactory.java	10 Dec 2003 03:24:03 -0000	1.2
  +++ FileWriterFactory.java	13 Dec 2003 07:56:28 -0000	1.3
  @@ -91,6 +91,19 @@
   
     public Writer createWriter(String packageName, String className)
             throws IOException {
  +    return new FileWriter(createFile(packageName,className));
  +  }
  +
  +  // ========================================================================
  +  // Public methods
  +
  +  /**
  +   * Returns the raw file instead, in case the caller is clever and knows we
  +   * are a FileWriterFactory.
  +   */
  +  public File createFile(String packageName, String className)
  +          throws IOException
  +  {
       File dir = new File(mSourceRoot, packageName.replace
                                        (PACKAGE_SEPARATOR, File.separatorChar));
       if (!dir.exists()) {
  @@ -98,7 +111,6 @@
           throw new IOException("Failed to create directory " + dir);
         }
       }
  -    File outFile = new File(dir, className + EXTENSION);
  -    return new FileWriter(outFile);
  +    return new File(dir, className + EXTENSION);
     }
   }
  
  
  
  1.2       +37 -16    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/JavaOutputStream.java
  
  Index: JavaOutputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/JavaOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JavaOutputStream.java	5 Dec 2003 19:59:10 -0000	1.1
  +++ JavaOutputStream.java	13 Dec 2003 07:56:28 -0000	1.2
  @@ -86,13 +86,27 @@
   public interface JavaOutputStream {
   
     /**
  +   * Instructs the stream to begin writing a new interface.
  +   *
  +   * @param packageName Fully-qualified name of the package which should
  +   *        contain the new interface.
  +   * @param interfaceOrClassName Unqualified name of the new class or
  +   *        interface that will be written in this file.
  +   *
  +   * @throws IllegalStateException if startFile has already been called
  +   *         without a call to endFile.
  +   * @throws IllegalArgumentException if classname is null or if any classname
  +   *         parameters is malformed.
  +   */
  +  public void startFile(String packageName,
  +                        String interfaceOrClassName)
  +          throws IOException;
  +
  +  /**
      * Instructs the stream to begin writing a class with the given attributes.
      *
      * @param modifiers A java.lang.reflect.Modifier value describing the
      *        modifiers which apply to the new class.
  -   * @param packageName Fully-qualified name of the package which should
  -   *        contain the new class.
  -   * @param simpleName Unqualified name of the new class.
      * @param extendsClassName Name the class which the new class extends, or
      *        null if it should not extend anything.  The class name must be
      *        fully-qualified.
  @@ -108,8 +122,6 @@
      *         any class name parameter is malformed.
      */
     public void startClass(int modifiers,
  -                         String packageName,
  -                         String simpleName,
                            String extendsClassName,
                            String[] implementsInterfaceNames)
             throws IOException;
  @@ -117,9 +129,6 @@
     /**
      * Instructs the stream to begin writing a new interface.
      *
  -   * @param packageName Fully-qualified name of the package which should
  -   *        contain the new interface.
  -   * @param simpleName Unqualified name of the new interface.
      * @param extendsInterfaceNames Array of interface names, one
      *        for each interface extendded by the new interface, or null if
      *        the interface does not extend anything.  Each class name must be
  @@ -130,9 +139,7 @@
      * @throws IllegalArgumentException if classname is null or if any classname
      *         parameters is malformed.
      */
  -  public void startInterface(String packageName,
  -                             String simpleName,
  -                             String[] extendsInterfaceNames)
  +  public void startInterface(String[] extendsInterfaceNames)
             throws IOException;
   
     /**
  @@ -296,16 +303,30 @@
     public void endClassOrInterface() throws IOException;
   
     /**
  -   * Returns the ExpressionFactory that should be to create instances of
  -   * Expression to be used in conjunction with this JavaOutputStream.
  +   * Instructs the stream to finish writing the current file.
  +   * Every call to startFile must be balanced by a call to endFile().
      *
  -   * @return An ExpressionFactory.  Must never return null.
  +   * @throws IllegalStateException if no file has been started.
      */
  -  public ExpressionFactory getExpressionFactory();
  +  public void endFile() throws IOException;
  +
  +
   
     /**
      * Closes the JavaOutputStream.  This should be called exactly once and
  -   * only when you are completely finished with the stream.
  +   * only when you are completely finished with the stream.  Note that in
  +   * the case where java sources are being generated, calling this method may
  +   * cause the sources to be javac'ed.
      */
     public void close() throws IOException;
  +
  +  /**
  +   * Returns the ExpressionFactory that should be to create instances of
  +   * Expression to be used in conjunction with this JavaOutputStream.
  +   *
  +   * @return An ExpressionFactory.  Must never return null.
  +   */
  +  public ExpressionFactory getExpressionFactory();
  +
  +
   }
  
  
  
  1.3       +107 -43   xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/SourceJavaOutputStream.java
  
  Index: SourceJavaOutputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/SourceJavaOutputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SourceJavaOutputStream.java	12 Dec 2003 01:12:56 -0000	1.2
  +++ SourceJavaOutputStream.java	13 Dec 2003 07:56:28 -0000	1.3
  @@ -58,8 +58,10 @@
   import java.io.IOException;
   import java.io.PrintWriter;
   import java.io.Writer;
  +import java.io.File;
   import java.lang.reflect.Modifier;
   import java.util.StringTokenizer;
  +import java.util.Collection;
   
   /**
    * <p>Implementation of JavaOutputStream which outputs Java source code.</p>
  @@ -126,39 +128,68 @@
   
     private PrintWriter mOut = null;
     private int mIndentLevel = 0;
  -  private String mConstructorName;
  +  private String mPackageName = null;
  +  private String mClassOrInterfaceName = null;
     private WriterFactory mWriterFactory;
  +  protected boolean mVerbose = false;
  +
   
     // ========================================================================
     // Constructors
   
     public SourceJavaOutputStream(WriterFactory factory) {
  +    setWriterFactory(factory);
  +  }
  +
  +  protected SourceJavaOutputStream() {}
  +
  +  protected void setWriterFactory(WriterFactory factory) {
       if (factory == null) throw new IllegalArgumentException();
       mWriterFactory = factory;
     }
   
     // ========================================================================
  +  // Public methods
  +
  +  public void setVerbose(boolean b) { mVerbose = b; }
  +
  +  // ========================================================================
     // JavaOutputStream implementation
   
  +  public void startFile(String packageName,
  +                           String classOrInterfaceName) throws IOException {
  +    if (packageName == null) {
  +      throw new IllegalArgumentException("null package");
  +    }
  +    if (classOrInterfaceName == null) {
  +      throw new IllegalArgumentException("null classname");
  +    }
  +    if (mOut != null) {
  +      throw new IllegalStateException("Start new file without calling "+
  +                                      "endFile on existing file");
  +    }
  +    if (mIndentLevel != 0) throw new IllegalStateException(); //sanity check
  +    mOut = new PrintWriter(mWriterFactory.createWriter(packageName,
  +                                                       classOrInterfaceName));
  +    mPackageName = makeI18nSafe(packageName);
  +    mClassOrInterfaceName = makeI18nSafe(classOrInterfaceName);
  +  }
  +
     public void startClass(int modifiers,
  -                         String packageName,
  -                         String simpleName,
                            String extendsClassName,
                            String[] interfaceNames)
             throws IOException {
  -    simpleName = makeI18nSafe(simpleName);
  -    packageName = makeI18nSafe(packageName);
  +    checkStateForWrite();
  +    if (mVerbose) verbose("startClass "+mPackageName+"."+mClassOrInterfaceName);
       extendsClassName = makeI18nSafe(extendsClassName);
  -    mConstructorName = simpleName;
  -    mOut = startNewFile(packageName, simpleName);
  -    mOut.println("package " + packageName + ";");
  +    mOut.println("package " + mPackageName + ";");
       mOut.println();
       // We need to write up the actual class declaration and save it until
       // after the imports have been written
       //FIXME we should format this code more nicely
       mOut.print(Modifier.toString(modifiers));
       mOut.print(" class ");
  -    mOut.print(simpleName);
  +    mOut.print(mClassOrInterfaceName);
       if (extendsClassName != null) {
         mOut.print(" extends ");
         mOut.print(extendsClassName);
  @@ -175,26 +206,24 @@
       increaseIndent();
     }
   
  -
  -  public void startInterface(String packageName,
  -                             String simpleName,
  -                             String[] interfaceNames)
  +  public void startInterface(String[] extendsInterfaceNames)
             throws IOException {
  -    simpleName = makeI18nSafe(simpleName);
  -    packageName = makeI18nSafe(packageName);
  -    mConstructorName = null;
  -    mOut = startNewFile(packageName, simpleName);
  -    mOut.println("package " + packageName + ";");
  +    if (mVerbose) verbose("startInterface "+mPackageName+"."+mClassOrInterfaceName);
  +    checkStateForWrite();
  +    mClassOrInterfaceName = makeI18nSafe(mClassOrInterfaceName);
  +    mPackageName = makeI18nSafe(mPackageName);
  +    this.mClassOrInterfaceName = null;
  +    mOut.println("package " + mPackageName + ";");
       // We need to write up the actual class declaration and save it until
       // after the imports have been written
       //FIXME we should format this code more nicely
       mOut.print("public interface ");
  -    mOut.print(simpleName);
  -    if (interfaceNames != null && interfaceNames.length > 0) {
  +    mOut.print(mClassOrInterfaceName);
  +    if (extendsInterfaceNames != null && extendsInterfaceNames.length > 0) {
         mOut.print(" extends ");
  -      for (int i = 0; i < interfaceNames.length; i++) {
  -        mOut.print(makeI18nSafe(interfaceNames[i]));
  -        if (i < interfaceNames.length - 1) mOut.print(", ");
  +      for (int i = 0; i < extendsInterfaceNames.length; i++) {
  +        mOut.print(makeI18nSafe(extendsInterfaceNames[i]));
  +        if (i < extendsInterfaceNames.length - 1) mOut.print(", ");
         }
       }
       mOut.println("{");
  @@ -206,6 +235,8 @@
                                String typeName,
                                String fieldName,
                                Expression defaultValue) throws IOException {
  +    if (mVerbose) verbose("writeField "+typeName+" "+fieldName);
  +    checkStateForWrite();
       printIndents();
       typeName = makeI18nSafe(typeName);
       fieldName = makeI18nSafe(fieldName);
  @@ -228,17 +259,19 @@
                                        String[] paramNames,
                                        String[] exceptionClassNames)
             throws IOException {
  -    return startMethod(modifiers, mConstructorName, null,
  +    return startMethod(modifiers, mClassOrInterfaceName, null,
                          paramTypeNames, paramNames, exceptionClassNames);
     }
   
     public Variable[] startMethod(int modifiers,
  -                                String methodName,
                                   String returnTypeName,
  +                                String methodName,
                                   String[] paramTypeNames,
                                   String[] paramNames,
                                   String[] exceptionClassNames)
             throws IOException {
  +    if (mVerbose) verbose("startMethod "+methodName);
  +    checkStateForWrite();
       methodName = makeI18nSafe(methodName);
       returnTypeName = makeI18nSafe(returnTypeName);
       printIndents();
  @@ -252,7 +285,7 @@
       // print the parameter list
       Variable[] ret;
       if (paramTypeNames == null || paramTypeNames.length == 0) {
  -      mOut.print("(}");
  +      mOut.print("()");
         ret = new Variable[0];
       } else {
         ret = new Variable[paramTypeNames.length];
  @@ -272,12 +305,14 @@
           mOut.print(makeI18nSafe(exceptionClassNames[i]));
         }
       }
  -    mOut.println();
  +    mOut.println(" {");
       increaseIndent();
       return ret;
     }
   
     public void writeComment(String comment) throws IOException {
  +    if (mVerbose) verbose("comment");
  +    checkStateForWrite();
       printIndents();
       mOut.println("/**");
       StringTokenizer st = new StringTokenizer(makeI18nSafe(comment),
  @@ -292,6 +327,8 @@
     }
   
     public void writeReturnStatement(Expression expression) throws IOException {
  +    if (mVerbose) verbose("return");
  +    checkStateForWrite();
       printIndents();
       mOut.print("return ");
       mOut.print(((String) expression.getMemento()));
  @@ -300,6 +337,8 @@
   
     public void writeAssignmentStatement(Variable left, Expression right)
             throws IOException {
  +    if (mVerbose) verbose("assignment");
  +    checkStateForWrite();
       printIndents();
       mOut.print(((String) left.getMemento()));
       mOut.print(" = ");
  @@ -308,6 +347,8 @@
     }
   
     public void endMethodOrConstructor() throws IOException {
  +    if (mVerbose) verbose("endMethodOrConstructor");
  +    checkStateForWrite();
       reduceIndent();
       printIndents();
       mOut.println('}');
  @@ -315,17 +356,26 @@
     }
   
     public void endClassOrInterface() throws IOException {
  +    if (mVerbose) verbose("endClassOrInterface");
  +    checkStateForWrite();
       reduceIndent();
       printIndents();
       mOut.println('}');
     }
   
  +  public void endFile() throws IOException {
  +    checkStateForWrite();
  +    if (mVerbose) verbose("endFile");
  +    closeOut();
  +  }
  +
     public ExpressionFactory getExpressionFactory() {
       return this;
     }
   
     public void close() throws IOException {
  -    closeOut();
  +    if (mVerbose) verbose("close");
  +    closeOut();//just to be safe
     }
   
     // ========================================================================
  @@ -354,13 +404,15 @@
     // ========================================================================
     // Private methods
   
  -  private PrintWriter startNewFile(String packageName,
  -                                   String simpleName) throws IOException {
  -    closeOut();
  -    if (mIndentLevel != 0) throw new IllegalStateException(); //sanity check
  -    return new PrintWriter(mWriterFactory.createWriter(packageName, simpleName));
  +  private void checkStateForWrite() {
  +    if (mOut == null) {
  +      throw new IllegalStateException("Attempt to generate code when no "+
  +                                      "file open.  This is due to broken" +
  +                                      "logic in the calling class");
  +    }
     }
   
  +
     private void printIndents() {
       for (int i = 0; i < mIndentLevel; i++) mOut.print(INDENT_STRING);
     }
  @@ -371,11 +423,16 @@
   
     private void reduceIndent() {
       mIndentLevel--;
  -    if (mIndentLevel < 0) throw new IllegalStateException(); //sanity check
  +    if (mIndentLevel < 0) {
  +      throw new IllegalStateException("Indent level reduced below zero. "+
  +                                      "This is a result of an error in the "+
  +                                      "calling code.");
  +    }
     }
   
     private void closeOut() {
       if (mOut != null) {
  +      mOut.flush();
         mOut.close();
         mOut = null;
       }
  @@ -400,6 +457,7 @@
     }
   
     private static String makeI18nSafe(String s) {
  +    if (s == null) return null;
       for (int i = 0; i < s.length(); i++) {
         if (s.charAt(i) > 127)
           return buildI18nSafe(s);
  @@ -434,22 +492,26 @@
       }
     }
   
  +  private void verbose(String msg) {
  +    if (mVerbose) System.out.println(msg);
  +  }
  +
     // ========================================================================
     // main() - quick test
   
     public static void main(String[] args) throws IOException {
       SourceJavaOutputStream sjos = new SourceJavaOutputStream
  -            (new WriterFactory() {
  -              private PrintWriter OUT = new PrintWriter(System.out);
  +             (new WriterFactory() {
  +               private PrintWriter OUT = new PrintWriter(System.out);
   
  -              public Writer createWriter(String x, String y) {
  -                return OUT;
  -              }
  -            });
  -    JavaOutputStream joust = new ValidatingJavaOutputStream(sjos);
  +               public Writer createWriter(String x, String y) {
  +                 return OUT;
  +               }
  +             });
  +     JavaOutputStream joust = new ValidatingJavaOutputStream(sjos);
       ExpressionFactory exp = joust.getExpressionFactory();
  -    joust.startClass(Modifier.PUBLIC | Modifier.FINAL,
  -                     "foo.bar.baz", "MyClass", "MyBaseClass", null);
  +    joust.startFile("foo.bar.baz","MyClass");
  +    joust.startClass(Modifier.PUBLIC | Modifier.FINAL,"MyBaseClass", null);
       String[] paramNames = {"count", "fooList"};
       String[] paramTypes = {"int", "List"};
       String[] exceptions = {"IOException"};
  @@ -461,6 +523,8 @@
       joust.writeAssignmentStatement(counter, params[0]);
       joust.endMethodOrConstructor();
       joust.endClassOrInterface();
  +    joust.endFile();
       joust.close();
     }
  +
   }
  
  
  
  1.2       +13 -8     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/ValidatingJavaOutputStream.java
  
  Index: ValidatingJavaOutputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/ValidatingJavaOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatingJavaOutputStream.java	5 Dec 2003 19:59:10 -0000	1.1
  +++ ValidatingJavaOutputStream.java	13 Dec 2003 07:56:28 -0000	1.2
  @@ -105,21 +105,22 @@
     // ========================================================================
     // JavaOutputStream implementation
   
  +  public void startFile(String packageName,
  +                        String interfaceOrClassName)
  +          throws IOException {
  +    mDest.startFile(packageName,interfaceOrClassName);
  +  }
  +
     public void startClass(int modifiers,
  -                         String packageName,
  -                         String simpleName,
                            String extendsClassName,
                            String[] implementsInterfaceNames)
             throws IOException {
  -    mDest.startClass(modifiers, packageName, simpleName,
  -                     extendsClassName, implementsInterfaceNames);
  +    mDest.startClass(modifiers, extendsClassName, implementsInterfaceNames);
     }
   
  -  public void startInterface(String packageName,
  -                             String simpleName,
  -                             String[] extendsInterfaceNames)
  +  public void startInterface(String[] extendsInterfaceNames)
             throws IOException {
  -    mDest.startInterface(packageName, simpleName, extendsInterfaceNames);
  +    mDest.startInterface(extendsInterfaceNames);
     }
   
     public Variable writeField(int modifiers,
  @@ -168,6 +169,10 @@
   
     public void endClassOrInterface() throws IOException {
       mDest.endClassOrInterface();
  +  }
  +
  +  public void endFile() throws IOException {
  +    mDest.endFile();
     }
   
     public ExpressionFactory getExpressionFactory() {
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/CompilingJavaOutputStream.java
  
  Index: CompilingJavaOutputStream.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  package org.apache.xmlbeans.impl.binding.joust;
  
  import java.io.Writer;
  import java.io.IOException;
  import java.io.File;
  import java.io.FileWriter;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Iterator;
  import org.apache.xmlbeans.impl.tool.CodeGenUtil;
  
  /**
   * This a SourceJavaOutputStream which can compile it's results when
   * close() is called.  It always writes source files to disk.
   *
   * @author Patrick Calaham <pc...@bea.com>
   */
  public class CompilingJavaOutputStream extends SourceJavaOutputStream
          implements WriterFactory
   {
    // ========================================================================
    // Variables
  
    private FileWriterFactory mWriterFactoryDelegate;
    private List mSourceFiles;
    private File mSourceDir = null;
    private File mCompileDir = null;
    private File[] mJavacClasspath = null;
    private boolean mKeepGenerated;
    private String mJavacPath = null;
  
    // ========================================================================
    // Constructors
  
    /**
     * Construct a new CompilingJavaOutputStream which generates java sources
     * in the given directory.  In order to enable compilation of those sources,
     * you must call enableCompilation.
     *
     * @param srcDir Directory in which sources get generated.
     */
    public CompilingJavaOutputStream(File srcDir) {
      this();
      setSourceDir(srcDir);
    }
  
    /**
     * Constructs a new CompilingJavaOutputStream.  Note that if you use
     * this default constructor, you *must* call setSourceDir at some point
     * before the stream is used; failure to do so will produce an
     * IllegalStateException.
     */
    public CompilingJavaOutputStream() {
      super();
      setWriterFactory(this);
      mSourceFiles = new ArrayList();
    }
  
    // ========================================================================
    // Public methods
  
    /**
     * Sets the source directory to which files will be written.  This can
     * safely be changed mistream if desired.
     */
    public void setSourceDir(File srcDir) {
      if (srcDir == null) throw new IllegalArgumentException("null srcDir");
      mWriterFactoryDelegate = new FileWriterFactory(mSourceDir = srcDir);
    }
  
    /**
     * Enables compilation of the generated source files into the given
     * directory.  If this method is never called, no compilation will occur.
     */
    public void setCompilationDir(File destDir) {
      mCompileDir = destDir;
    }
  
    /**
     * Sets the location of javac to be invoked.  Default compiler is used
     * if this is not set.  Ignored if compilationDir is never set.
     */
    public void setJavac(String javacPath) {
      mJavacPath = javacPath;
    }
  
    /**
     * Sets the classpath to use for compilation.  System classpath is used
     * by default.  This is ignored if compilationDir is never set.
     */
    public void setJavacClasspath(File[] classpath) {
      mJavacClasspath = classpath;
    }
  
    /**
     * Sets whether generated sources should be kept after compilation.
     * Default is true.  This is ignored if compilationDir is never set.
     */
    public void setKeepGenerated(boolean b) {
      mKeepGenerated = b;
    }
  
    // ========================================================================
    // WriterFactory implementation
  
    /**
     * Delegate to FileWriterFactory, but ask it for Files instead of Writers
     * so that we can keep track of what we need to compile later.
     */
    public Writer createWriter(String packageName, String className)
            throws IOException {
      if (mWriterFactoryDelegate == null) {
        throw new IllegalStateException("setSourceDir never called on the "+
                                        "CompilingJavaOutputStream");
      }
      File out = mWriterFactoryDelegate.createFile(packageName,className);
      mSourceFiles.add(out);
      return new FileWriter(out);
    }
  
    // ========================================================================
    // JavaOutputStream implementation
  
    public void close() throws IOException {
      super.close();
      if (mCompileDir != null) {
        if (mVerbose) {
          System.out.println("compileDir = "+mCompileDir);
          Iterator i = mSourceFiles.iterator();
          while(i.hasNext()) {
            System.out.println(i.next().toString());
          }
        }
        boolean result = CodeGenUtil.externalCompile
                (mSourceFiles,mCompileDir,mJavacClasspath,
                 mVerbose,mJavacPath,null,null,!mVerbose,mVerbose);
        if (!result) {
          throw new IOException("Compilation of sources failed, " +
                                "check log for details.");
        }
        if (!mKeepGenerated) mSourceDir.delete();
      }
    }
  }
  
  
  1.3       +13 -10    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java
  
  Index: ExplodedTylarImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExplodedTylarImpl.java	11 Dec 2003 01:49:03 -0000	1.2
  +++ ExplodedTylarImpl.java	13 Dec 2003 07:56:29 -0000	1.3
  @@ -66,10 +66,7 @@
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  -import org.apache.xmlbeans.impl.binding.joust.FileWriterFactory;
  -import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
  -import org.apache.xmlbeans.impl.binding.joust.SourceJavaOutputStream;
  -import org.apache.xmlbeans.impl.binding.joust.ValidatingJavaOutputStream;
  +import org.apache.xmlbeans.impl.binding.joust.*;
   import org.apache.xmlbeans.impl.common.JarHelper;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   
  @@ -121,7 +118,6 @@
       return load(dir, createDefaultJoust(dir));
     }
   
  -
     /**
      * Creates a new tylar from the given directory.  The directory must exist
      * or be creatable.
  @@ -129,7 +125,7 @@
     public static ExplodedTylarImpl create(File dir, JavaOutputStream joust)
             throws IOException {
       if (dir.exists()) {
  -      if (dir.isFile()) throw new IOException("already a file at '" + dir + "'");
  +      if (dir.isFile()) throw new IOException("Already a file at " + dir);
       } else {
         if (!dir.mkdirs()) throw new IOException("Failed to create " + dir);
       }
  @@ -193,6 +189,10 @@
       return mJoust;
     }
   
  +  public void close() throws IOException {
  +    mJoust.close();
  +  }
  +
     // ========================================================================
     // Tylar implementation
   
  @@ -258,16 +258,19 @@
     // Private methods
   
     private static JavaOutputStream createDefaultJoust(File dir) {
  +    File srcDir = new File(dir,TylarConstants.SRC_ROOT);
       return new ValidatingJavaOutputStream
  -            (new SourceJavaOutputStream(new FileWriterFactory(dir)));
  +            (new SourceJavaOutputStream(new FileWriterFactory(srcDir)));
     }
   
     private static void parseSchemas(File schemaDir, Collection out)
             throws IOException, XmlException {
       File[] xsds = schemaDir.listFiles();
  -    for (int i = 0; i < xsds.length; i++) {
  -      if (VERBOSE) System.out.println("parsing "+xsds[i]);
  -      out.add(parseXsd(xsds[i]));
  +    if (xsds != null) {
  +      for (int i = 0; i < xsds.length; i++) {
  +        if (VERBOSE) System.out.println("parsing "+xsds[i]);
  +        out.add(parseXsd(xsds[i]));
  +      }
       }
     }
   
  
  
  
  1.3       +11 -1     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarWriter.java
  
  Index: TylarWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TylarWriter.java	11 Dec 2003 01:49:03 -0000	1.2
  +++ TylarWriter.java	13 Dec 2003 07:56:29 -0000	1.3
  @@ -86,8 +86,18 @@
   
     /**
      * Returns the JavaOutputStream which should be used for creating new java
  -   * code to be stored in this tylar.
  +   * code to be stored in this tylar.  Note that the caller should never
  +   * close this stream directly; it will be closed by TylarWriter.close();
      */
     public JavaOutputStream getJavaOutputStream();
  +
  +  /**
  +   * Should be exactly once called when the tylar is complete.  This signals
  +   * the implementation that any outstanding files should be flushed to disk,
  +   * for example.  It also signals that the JavaOutputStream associated with
  +   * this tylar should be closed (which in some cases may trigger compilation
  +   * of java sources).
  +   */
  +  public void close() throws IOException;
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org