xml-xmlbeans-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Java2SchemaResult.java ExplodedTylarBuilder.java Java2Schema.java Java2SchemaTask.java TylarBuilder.java JavaToSchemaResult.java JavaToSchemaResultImpl.java
Date Fri, 05 Dec 2003 21:48:18 GMT
pcal        2003/12/05 13:48:18

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        ExplodedTylarBuilder.java Java2Schema.java
                        Java2SchemaTask.java TylarBuilder.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Java2SchemaResult.java
  Removed:     v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        JavaToSchemaResult.java JavaToSchemaResultImpl.java
  Log:
  java2schema: refactor result interface
  
  Revision  Changes    Path
  1.5       +140 -130  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java
  
  Index: ExplodedTylarBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ExplodedTylarBuilder.java	4 Dec 2003 21:14:55 -0000	1.4
  +++ ExplodedTylarBuilder.java	5 Dec 2003 21:48:18 -0000	1.5
  @@ -64,6 +64,7 @@
   import java.io.IOException;
   import java.io.File;
   import java.io.FileOutputStream;
  +import java.io.OutputStream;
   import java.util.ArrayList;
   import java.util.List;
   import java.util.Iterator;
  @@ -75,139 +76,148 @@
    *
    * @author Patrick Calahan <pcal@bea.com>
    */
  -public class ExplodedTylarBuilder implements TylarBuilder
  -{
  +public class ExplodedTylarBuilder implements TylarBuilder {
   
  -    // =========================================================================
  -    // Constants
  +  // =========================================================================
  +  // Constants
   
  -    private static final int XML_INDENT = 2;
  +  private static final int XML_INDENT = 2;
   
  -    // =========================================================================
  -    // Variables
  -
  -    private File mDir;
  -    private List mSchemas = new ArrayList();
  -    private List mBindings = new ArrayList();
  -
  -    // =========================================================================
  -    // Constructors
  -
  -    public ExplodedTylarBuilder(File dir)
  -    {
  -        if (dir == null) throw new IllegalArgumentException("null dir");
  -        mDir = dir;
  -    }
  -
  -    // =========================================================================
  -    // TylarBuilder implementation
  -
  -    public void buildTylar(JavaToSchemaResult result) throws IOException
  -    {
  -        createTargetDir();
  -        
  -        // write schemas
  -        writeXsdFiles(result.getSchemaCodeResult());
  -        
  -        // print the binding file
  -        writeBindingFile(result.getBindingFileResult());
  -    }
  -    
  -    protected void writeBindingFile(BindingFileResult bfg) throws IOException
  -    {
  -        File file = new File(mDir, "binding-file.xml"); //FIXME naming
  -        FileOutputStream out = null;
  +  // =========================================================================
  +  // Variables
  +
  +  private File mDir;
  +  private List mSchemas = new ArrayList();
  +  private List mBindings = new ArrayList();
  +
  +  // =========================================================================
  +  // Constructors
  +
  +  public ExplodedTylarBuilder(File dir) {
  +    if (dir == null) throw new IllegalArgumentException("null dir");
  +    mDir = dir;
  +  }
  +
  +  // =========================================================================
  +  // TylarBuilder implementation
  +
  +  public void buildTylar(Java2SchemaResult result) throws IOException {
  +    createTargetDir();
  +    // write schemas
  +    writeXsdFiles(result.getSchemas());
  +    // print the binding file
  +    writeBindingFile(result.getBindingFile());
  +  }
  +
  +  protected void writeBindingFile(BindingFile bf) throws IOException {
  +    File file = new File(mDir, "binding-file.xml"); //FIXME naming
  +    FileOutputStream out = null;
  +    try {
  +      out = new FileOutputStream(file);
  +      BindingConfigDocument doc = bf.write();
  +      doc.save(out,
  +               new XmlOptions().setSavePrettyPrint().
  +               setSavePrettyPrintIndent(XML_INDENT));
  +    } catch (IOException ioe) {
  +      throw ioe;
  +    } finally {
  +      try {
  +        out.close();
  +      } catch (IOException ohwell) {
  +        ohwell.printStackTrace();
  +      }
  +    }
  +  }
  +
  +  protected void writeXsdFiles(SchemaDocument[] xsds) throws IOException {
  +    // print the schemas
  +    for (int i = 0; i < xsds.length; i++) {
  +      File file = new File(mDir, "schema-" + i + ".xsd");//FIXME naming
  +      FileOutputStream out = null;
  +      try {
  +        out = new FileOutputStream(file);
  +        xsds[i].save(out,
  +                     new XmlOptions().setSavePrettyPrint().
  +                     setSavePrettyPrintIndent(XML_INDENT));
  +      } catch (IOException ioe) {
  +        throw ioe;
  +      } finally {
           try {
  -            out = new FileOutputStream(file);
  -            bfg.printBindingFile(out);
  -        }
  -        catch (IOException ioe) {
  -            throw ioe;
  -        }
  -        finally {
  -            try {
  -                out.close();
  -            }
  -            catch (IOException ohwell) {
  -                ohwell.printStackTrace();
  -            }
  -        }
  -    }
  -    
  -    
  -    protected void writeXsdFiles(SchemaCodeResult scg) throws IOException
  -    {
  -        // print the schemas
  -        String[] tns = scg.getTargetNamespaces();
  -        for (int i = 0; i < tns.length; i++) {
  -            File file = new File(mDir, "schema-" + i + ".xsd");//FIXME naming
  -            FileOutputStream out = null;
  -            try {
  -                out = new FileOutputStream(file);
  -                scg.printSchema(tns[i], out);
  -            }
  -            catch (IOException ioe) {
  -                throw ioe;
  -            }
  -            finally {
  -                try {
  -                    out.close();
  -                }
  -                catch (Exception ohwell) {
  -                    ohwell.printStackTrace();
  -                }
  -            }
  -        }
  -    }
  -    
  -    protected void writeJavaFiles(JavaCodeResult jcg) throws IOException
  -    {
  -        Collection classnames = jcg.getToplevelClasses();
  -        for (Iterator i = classnames.iterator(); i.hasNext(); )
  -        {
  -            String className = (String)i.next();
  -            File javaFile = new File(mDir, className.replace('.','/') + ".java");
  -            FileOutputStream out = null;
  -            try {
  -                out = new FileOutputStream(javaFile);
  -                jcg.printSourceCode(className, out);
  -            }
  -            catch (IOException e) {
  -                throw e;
  -            }
  -            finally
  -            {
  -                try {
  -                    out.close();
  -                }
  -                catch (Exception ohwell) {
  -                    ohwell.printStackTrace();
  -                }
  -            }
  -        }
  -    }
  -
  -    protected void createTargetDir()
  -    {
  -        if (!mDir.exists()) {
  -            if (!mDir.mkdirs()) {
  -                throw new IllegalArgumentException("failed to create dir " + mDir);
  -            }
  -        }
  -        else {
  -            if (!mDir.isDirectory())
  -                throw new IllegalArgumentException("not a directory: " + mDir);
  -        }
  -    }
  -    
  -    public void buildTylar(SchemaToJavaResult result) throws IOException
  -    {
  -        createTargetDir();
  -        
  -        // print the java files
  -        writeJavaFiles(result.getJavaCodeResult());
  -        
  -        // print the binding file
  -        writeBindingFile(result.getBindingFileResult());
  +          out.close();
  +        } catch (Exception ohwell) {
  +          ohwell.printStackTrace();
  +        }
  +      }
  +    }
  +  }
  +
  +  protected void writeJavaFiles(JavaCodeResult jcg) throws IOException {
  +    Collection classnames = jcg.getToplevelClasses();
  +    for (Iterator i = classnames.iterator(); i.hasNext();) {
  +      String className = (String) i.next();
  +      File javaFile = new File(mDir, className.replace('.', '/') + ".java");
  +      FileOutputStream out = null;
  +      try {
  +        out = new FileOutputStream(javaFile);
  +        jcg.printSourceCode(className, out);
  +      } catch (IOException e) {
  +        throw e;
  +      } finally {
  +        try {
  +          out.close();
  +        } catch (Exception ohwell) {
  +          ohwell.printStackTrace();
  +        }
  +      }
  +    }
  +  }
  +
  +  protected void createTargetDir() {
  +    if (!mDir.exists()) {
  +      if (!mDir.mkdirs()) {
  +        throw new IllegalArgumentException("failed to create dir " + mDir);
  +      }
  +    } else {
  +      if (!mDir.isDirectory())
  +        throw new IllegalArgumentException("not a directory: " + mDir);
  +    }
  +  }
  +
  +  public void buildTylar(SchemaToJavaResult result) throws IOException {
  +    createTargetDir();
  +
  +    // print the java files
  +    writeJavaFiles(result.getJavaCodeResult());
  +
  +    // print the binding file
  +    writeBindingFile(result.getBindingFileResult());
  +  }
  +
  +  /**
  +   * @deprecated I really think it is a bad idea for SchemaToJavaResult
  +   * to have the responsibility for printing out the binding file and java
  +   * code.  It should just return handles to things that get printed out
  +   * by the tylar builder.  I have already made this change on the
  +   * java->schema side.
  +   */
  +  private void writeBindingFile(BindingFileResult bfg) throws IOException
  +  {
  +    File file = new File(mDir, "binding-file.xml"); //FIXME naming
  +    FileOutputStream out = null;
  +    try {
  +      out = new FileOutputStream(file);
  +      bfg.printBindingFile(out);
  +    }
  +    catch (IOException ioe) {
  +      throw ioe;
  +    }
  +    finally {
  +      try {
  +        out.close();
  +      }
  +      catch (IOException ohwell) {
  +        ohwell.printStackTrace();
  +      }
       }
  +  }
   }
  
  
  
  1.16      +20 -19    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Java2Schema.java	4 Dec 2003 21:14:55 -0000	1.15
  +++ Java2Schema.java	5 Dec 2003 21:48:18 -0000	1.16
  @@ -128,22 +128,8 @@
      * Does the binding work on the inputs passed to the constructor and returns
      * the result.
      */
  -  public JavaToSchemaResult bind() {
  -    final JavaToSchemaResultImpl out = new JavaToSchemaResultImpl(mInput);
  -    bind(mInput.getJClasses(),out);
  -    final Throwable[] errors;
  -    if (mErrors == null) {
  -      errors = new Throwable[0];
  -    } else {
  -      errors = new Throwable[mErrors.size()];
  -      mErrors.toArray(errors);
  -    }
  -    return new JavaToSchemaResult() {
  -      public Throwable[] getErrors() { return errors; }
  -      public BindingFileResult getBindingFileResult() { return out; }
  -      public SchemaCodeResult getSchemaCodeResult() { return out; }
  -      public JavaSourceSet getJavaSourceSet() { return out.getJavaSourceSet(); }
  -    };
  +  public Java2SchemaResult bind() {
  +    return bind(mInput.getJClasses());
     }
   
     // ========================================================================
  @@ -153,8 +139,8 @@
      * Runs through all of the given classes and creates both schema types
      * and bts bindings for them in the given result object.
      */
  -  private void bind(JClass[] classes, JavaToSchemaResultImpl jtsr) {
  -    jtsr.addBindingFile(mBindingFile = new BindingFile());
  +  private Java2SchemaResult bind(JClass[] classes) {
  +    mBindingFile = new BindingFile();
       mLoader = PathBindingLoader.forPath
               (new BindingLoader[] {mBindingFile,
                                     BuiltinBindingLoader.getInstance()});
  @@ -166,7 +152,22 @@
         mSchema.setTargetNamespace(getTargetNamespace(classes[0]));
       }
       for(int i=0; i<classes.length; i++) getBindingTypeFor(classes[i]);
  -    jtsr.addSchema(mSchemaDocument);
  +    //collect the errors
  +    final Throwable[] errors;
  +    if (mErrors == null) {
  +      errors = new Throwable[0];
  +    } else {
  +      errors = new Throwable[mErrors.size()];
  +      mErrors.toArray(errors);
  +    }
  +    //build the result object
  +    final BindingFile bf = mBindingFile;
  +    final SchemaDocument[] schemas = {mSchemaDocument};
  +    return new Java2SchemaResult() {
  +      public Throwable[] getErrors() { return errors; }
  +      public BindingFile getBindingFile() { return bf; }
  +      public SchemaDocument[] getSchemas() { return schemas; }
  +    };
     }
   
     /**
  
  
  
  1.9       +1 -4      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java
  
  Index: Java2SchemaTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Java2SchemaTask.java	4 Dec 2003 21:14:55 -0000	1.8
  +++ Java2SchemaTask.java	5 Dec 2003 21:48:18 -0000	1.9
  @@ -59,12 +59,9 @@
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
  -import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.impl.jam.JFactory;
   import org.apache.xmlbeans.impl.jam.JFileSet;
  -import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  -import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
   
   import java.io.File;
   import java.io.IOException;
  @@ -179,7 +176,7 @@
       };
       Java2Schema j2b = new Java2Schema(input);
       TylarBuilder tb = new ExplodedTylarBuilder(mDestDir);
  -    JavaToSchemaResult result = j2b.bind();
  +    Java2SchemaResult result = j2b.bind();
       try {
         tb.buildTylar(result);
       } catch(IOException ioe) {
  
  
  
  1.4       +1 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TylarBuilder.java
  
  Index: TylarBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TylarBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TylarBuilder.java	4 Dec 2003 21:14:55 -0000	1.3
  +++ TylarBuilder.java	5 Dec 2003 21:48:18 -0000	1.4
  @@ -75,7 +75,7 @@
    */
   public interface TylarBuilder {
   
  -  public void buildTylar(JavaToSchemaResult result) throws IOException;
  +  public void buildTylar(Java2SchemaResult result) throws IOException;
   
     public void buildTylar(SchemaToJavaResult result) throws IOException;
   }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaResult.java
  
  Index: Java2SchemaResult.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.compile;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  
  /**
   * Encapsulates results returned by Java2Schema.
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public interface Java2SchemaResult
  {
    /**
     * Returns an array containing the set of fatal errors that were encountered
     * during the binding process.  Returns an empty array if no fatal errors
     * were encounted.
     */
    public Throwable[] getErrors();
  
    /**
     * Returns the BindingFile object that was produced by Java2Schema.  May
     * return null if catastrophic errors were encountered.
     */
    public BindingFile getBindingFile();
  
    /**
     * Returns an array containing the schema documents which were produced
     * by Java2Schema.
     */
    public SchemaDocument[] getSchemas();
  
  }
  
  
  

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


Mime
View raw message