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 2004/01/13 20:21:56 UTC

cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust CompilingJavaOutputStream.java

pcal        2004/01/13 11:21:56

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompiler.java Schema2Java.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/joust
                        CompilingJavaOutputStream.java
  Log:
  fix Schema2Java IllegalStateException
  
  Revision  Changes    Path
  1.8       +10 -4     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BindingCompiler.java	13 Jan 2004 05:40:11 -0000	1.7
  +++ BindingCompiler.java	13 Jan 2004 19:21:56 -0000	1.8
  @@ -117,10 +117,16 @@
     public abstract void bind(TylarWriter writer);
   
     /**
  -   * Should be overridden by subclasses which want a java output stream
  -   * attached to TylarWriters.
  +   * Creates the ExplodedTylarImpl/Writer to be used when one of the bindAs...
  +   * methods is invoked.  This can be overridden by subclasses that need
  +   * to do more than simply create an ExplodedTylarImpl (such as attach
  +   * a JavaOutputStream).
      */
  -  protected JavaOutputStream getJoust(File tylarDestDir) { return null; }
  +  protected ExplodedTylarImpl createDefaultExplodedTylarImpl(File destDir)
  +          throws IOException
  +  {
  +    return ExplodedTylarImpl.create(destDir,null);
  +  }
   
     // ========================================================================
     // Public methods
  @@ -132,7 +138,7 @@
     public ExplodedTylar bindAsExplodedTylar(File tylarDestDir)  {
       ExplodedTylarImpl tylar;
       try {
  -      tylar = ExplodedTylarImpl.create(tylarDestDir,getJoust(tylarDestDir));
  +      tylar = createDefaultExplodedTylarImpl(tylarDestDir);
       } catch(IOException ioe) {
         logError(ioe);
         return null;
  
  
  
  1.8       +40 -17    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Schema2Java.java	13 Jan 2004 05:40:11 -0000	1.7
  +++ Schema2Java.java	13 Jan 2004 19:21:56 -0000	1.8
  @@ -59,9 +59,10 @@
   import org.apache.xmlbeans.impl.binding.bts.*;
   import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
   import org.apache.xmlbeans.impl.binding.tylar.TylarConstants;
  -import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
  +import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
   import org.apache.xmlbeans.impl.binding.joust.Variable;
   import org.apache.xmlbeans.impl.binding.joust.CompilingJavaOutputStream;
  +import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
   import org.apache.xmlbeans.impl.common.NameUtil;
   import org.apache.xmlbeans.*;
   import org.apache.xmlbeans.soap.SOAPArrayType;
  @@ -100,7 +101,8 @@
     private BindingLoader mLoader;
     private int structureCount;
     private BindingFile bindingFile = new BindingFile();
  -  private CompilingJavaOutputStream mJoust;
  +  private JavaOutputStream mJoust = null;
  +  private CompilingJavaOutputStream mDefaultJoust = null;
   
     // ========================================================================
     // Constructors
  @@ -110,8 +112,6 @@
      */
     public Schema2Java(SchemaTypeSystem s) {
       setSchemaTypeSystem(s);
  -    mJoust = new CompilingJavaOutputStream();
  -    mJoust.setLogger(this);
     }
   
     /**
  @@ -134,7 +134,7 @@
      */
     public void setCompileJava(boolean b) {
       assertCompilationStarted(false);
  -    mJoust.setDoCompile(b);
  +    getDefaultJoust().setDoCompile(b);
     }
   
     /**
  @@ -145,7 +145,7 @@
      */
     public void setJavac(String javacPath) {
       assertCompilationStarted(false);
  -    mJoust.setJavac(javacPath);
  +    getDefaultJoust().setJavac(javacPath);
     }
   
     /**
  @@ -156,7 +156,7 @@
      */
     public void setJavacClasspath(File[] classpath) {
       assertCompilationStarted(false);
  -    mJoust.setJavacClasspath(classpath);
  +    getDefaultJoust().setJavacClasspath(classpath);
     }
   
     /**
  @@ -168,28 +168,41 @@
      */
     public void setKeepGeneratedJava(boolean b) {
       assertCompilationStarted(false);
  -    mJoust.setKeepGenerated(b);
  -  }
  +    getDefaultJoust().setKeepGenerated(b);
  + }
   
     // ========================================================================
     // BindingCompiler implementation
   
  -  public JavaOutputStream getJoust(File tylarDestDir) {
  -    mJoust.setSourceDir(new File(tylarDestDir,TylarConstants.SRC_ROOT));
  -    mJoust.setCompilationDir(tylarDestDir);
  -    return mJoust;
  +  /**
  +   * We override this method because we need the bindAs... tylar to include
  +   * the defaultJoust.
  +   */
  +  protected ExplodedTylarImpl createDefaultExplodedTylarImpl(File tylarDestDir)
  +          throws IOException
  +  {
  +    CompilingJavaOutputStream joust = getDefaultJoust();
  +    joust.setSourceDir(new File(tylarDestDir,TylarConstants.SRC_ROOT));
  +    joust.setCompilationDir(tylarDestDir);
  +    mJoust = joust;
  +    return ExplodedTylarImpl.create(tylarDestDir,mJoust);
     }
   
     /**
  -   * Computes the binding.
  +   * Computes the binding.  Note that the given TylarWriter MUST provide
  +   * a JavaOutputStream or an IllegalArgumentException will be thrown.  Note
  +   * also that if you call this method, the various parameters on this object
  +   * pertaining to java compilation (e.g. setJavacPath) will be ignored.
      */
     public void bind(TylarWriter writer) {
       if (sts == null) throw new IllegalStateException("SchemaTypeSystem not set");
  -    super.notifyCompilationStarted();
  -    if (writer.getJavaOutputStream() == null) {
  +    if ((mJoust = writer.getJavaOutputStream()) == null) {
         //sanity check
  -      throw new IllegalStateException("joust is null");
  +      throw new IllegalArgumentException("The specified TylarWriter does not " +
  +              "provide a JavaOutputStream, and so it cannot be used with "+
  +              "schema2java.");
       }
  +    super.notifyCompilationStarted();
       bind();
       try {
         writer.writeBindingFile(bindingFile);
  @@ -203,7 +216,17 @@
     // ========================================================================
     // Private methods
   
  +  private CompilingJavaOutputStream getDefaultJoust() {
  +    if (mDefaultJoust == null) {
  +      mDefaultJoust = new CompilingJavaOutputStream();
  +      mDefaultJoust.setLogger(this);
  +    }
  +    return mDefaultJoust;
  +  }
  +
     private void bind() {
  +    //sanity check
  +    if (mJoust == null) throw new IllegalStateException("joust not set");
   
       mLoader = super.getBaseBindingLoader();
   
  
  
  
  1.3       +2 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/CompilingJavaOutputStream.java
  
  Index: CompilingJavaOutputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/joust/CompilingJavaOutputStream.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CompilingJavaOutputStream.java	13 Jan 2004 05:40:11 -0000	1.2
  +++ CompilingJavaOutputStream.java	13 Jan 2004 19:21:56 -0000	1.3
  @@ -120,6 +120,7 @@
     // ========================================================================
     // Public methods
   
  +  //REVIEW the naming this directory 'source' seems a little confusing
     /**
      * Sets the source directory to which files will be written.  This can
      * safely be changed mistream if desired.
  @@ -179,7 +180,7 @@
     public Writer createWriter(String packageName, String className)
             throws IOException {
       if (mWriterFactoryDelegate == null) {
  -      throw new IllegalStateException("setSourceDir never called on the "+
  +      throw new IllegalStateException("delegate never set called on the "+
                                         "CompilingJavaOutputStream");
       }
       File out = mWriterFactoryDelegate.createFile(packageName,className);
  
  
  

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