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/10 04:24:03 UTC

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

pcal        2003/12/09 19:24:03

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Java2Schema.java Java2SchemaResult.java
                        Java2SchemaTask.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/joust
                        FileWriterFactory.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingLogger.java SimpleBindingLogger.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        ExplodedTylar.java ExplodedTylarImpl.java
                        Tylar.java TylarConstants.java TylarWriter.java
  Log:
  new infrastructure for tylars, logging
  
  Revision  Changes    Path
  1.17      +95 -36    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Java2Schema.java	5 Dec 2003 21:48:18 -0000	1.16
  +++ Java2Schema.java	10 Dec 2003 03:24:03 -0000	1.17
  @@ -56,13 +56,20 @@
   package org.apache.xmlbeans.impl.binding.compile;
   
   import org.apache.xmlbeans.impl.binding.bts.*;
  +import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylar;
  +import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
  +import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
  +import org.apache.xmlbeans.impl.binding.tylar.Tylar;
   import org.apache.xmlbeans.impl.jam.*;
  +import org.apache.tools.ant.BuildException;
   import org.w3.x2001.xmlSchema.*;
  -
   import javax.xml.namespace.QName;
   import java.util.ArrayList;
   import java.util.List;
  -import java.util.Collection;
  +import java.util.logging.Level;
  +import java.io.File;
  +import java.io.IOException;
  +
   
   /**
    * Takes a set of Java source inputs and generates a set of XML schemas to
  @@ -95,6 +102,8 @@
     private static final String TAG_AT               = "xsdgen:attribute";
     private static final String TAG_AT_NAME          = TAG_AT+".name";
   
  +  //for debugging only
  +  private static final boolean IGNORE_SEVERE_ERRORS = true;
   
     // =========================================================================
     // Variables
  @@ -103,43 +112,64 @@
     private BindingLoader mLoader;
     private SchemaDocument mSchemaDocument;
     private SchemaDocument.Schema mSchema;
  -  //
     private JavaSourceSet mInput;
  -  private Collection mErrors = null;
  +  private BindingLogger mLogger = null;
  +  private boolean mAnySevereErrors = false;
   
     // =========================================================================
     // Constructors
   
     /**
      * Initializes a Java2Schema instance to perform binding on the given
  -   * inputs, but does not actually do the binding work.
  +   * inputs, but does not actually do any binding work.
      */
  -  public Java2Schema(JavaSourceSet jtsi) {
  -    if (jtsi == null) {
  -      throw new IllegalArgumentException("null JavaSourceSet");
  -    }
  +  public Java2Schema(JavaSourceSet jtsi, BindingLogger logger) {
  +    if (jtsi == null) throw new IllegalArgumentException("null jtsi");
  +    if (logger == null) throw new IllegalArgumentException("null logger");
       mInput = jtsi;
  +    mLogger = logger;
     }
   
     // =========================================================================
     // Public methods
   
     /**
  -   * Does the binding work on the inputs passed to the constructor and returns
  -   * the result.
  +   * Performs the binding and returns an exploded tylar in the specified
  +   * directory.  Returns null if any severe errors were encountered.
      */
  -  public Java2SchemaResult bind() {
  -    return bind(mInput.getJClasses());
  +  public ExplodedTylar bindAsExplodedTylar(File tylarDestDir) {
  +    Java2SchemaResult result = bind();
  +    if (result == null) return null;
  +    ExplodedTylarImpl tylar = new ExplodedTylarImpl(tylarDestDir);
  +    if (!tylarDestDir.exists()) {
  +      if (!tylarDestDir.mkdirs()) {
  +        logError("failed to create "+tylarDestDir);
  +        return null;
  +      }
  +    }
  +    buildTylar(result,(TylarWriter)tylar);
  +    return mAnySevereErrors && !IGNORE_SEVERE_ERRORS ? null : tylar;
     }
   
  -  // ========================================================================
  -  // Private methods
  +  /**
  +   * Performs the binding and returns a tylar in the specified jar file.
  +   * Returns null if any severe errors were encountered.
  +   */
  +  public Tylar bindAsJarredTylar(File tylarJar) {
  +    throw new RuntimeException("NYI");
  +  }
   
     /**
  -   * Runs through all of the given classes and creates both schema types
  -   * and bts bindings for them in the given result object.
  +   * Does the binding work on the inputs passed to the constructor and returns
  +   * the raw result object.  Returns null if any severe errors were
  +   * encountered.
  +   *
  +   * Although this method is public, it should only be used if you know what
  +   * you're doing - you're probably better off using one of the other 'bind'
  +   * methods which return tylars.
      */
  -  private Java2SchemaResult bind(JClass[] classes) {
  +  public Java2SchemaResult bind() {
  +    JClass[] classes = mInput.getJClasses();
       mBindingFile = new BindingFile();
       mLoader = PathBindingLoader.forPath
               (new BindingLoader[] {mBindingFile,
  @@ -152,24 +182,35 @@
         mSchema.setTargetNamespace(getTargetNamespace(classes[0]));
       }
       for(int i=0; i<classes.length; i++) getBindingTypeFor(classes[i]);
  -    //collect the errors
  -    final Throwable[] errors;
  -    if (mErrors == null) {
  -      errors = new Throwable[0];
  -    } else {
  -      errors = new Throwable[mErrors.size()];
  -      mErrors.toArray(errors);
  -    }
  +    if (mAnySevereErrors && !IGNORE_SEVERE_ERRORS) return null;
       //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; }
       };
     }
   
  +
  +  // ========================================================================
  +  // Private methods
  +
  +  /**
  +   * Feeds a tylar builder with the given compilation results.
  +   */
  +  private void buildTylar(Java2SchemaResult result, TylarWriter builder) {
  +    try {
  +      builder.writeBindingFile(result.getBindingFile());
  +      SchemaDocument[] xsds = result.getSchemas();
  +      for(int i=0; i<xsds.length; i++) {
  +        builder.writeSchema(xsds[i],"schema-"+i+".xsd");//FIXME dumb naming
  +      }
  +    } catch(IOException ioe) {
  +      logError(ioe);
  +    }
  +  }
  +
     /**
      * Returns a bts BindingType for the given JClass.  If such a type
      * has not yet been registered with the loader, it will be created.
  @@ -343,7 +384,7 @@
       BindingType bt = mLoader.getBindingType
               (mLoader.lookupTypeFor(JavaTypeName.forString(clazz.getQualifiedName())));
       if (bt != null) return bt.getName().getXmlName().getQName();
  -    logError(clazz,"no type found");
  +    logError(clazz,"no builtin type found");
       return new QName("ERROR",clazz.getQualifiedName());
     }
   
  @@ -374,23 +415,41 @@
      * Logs a message that fatal error that occurred while performing binding
      * 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.  FIXME We need a formal
  -   * build-time logging interface.
  +   * as many errors as possible in a single pass.
      */
     private void logError(JElement context, Throwable error) {
  -    if (mErrors == null) mErrors = new ArrayList();
  -    mErrors.add(error);
  +    mAnySevereErrors = true;
  +    mLogger.log(Level.SEVERE,null,error,context);
     }
   
     /**
      * Logs a message that fatal error that occurred while performing binding
      * 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.  FIXME We need a formal
  -   * build-time logging interface.
  +   * as many errors as possible in a single pass.
      */
     private void logError(JElement context, String msg) {
  -    logError(context, new RuntimeException(msg)); //FIXME
  +    mAnySevereErrors = true;
  +    mLogger.log(Level.SEVERE,msg,null,context);
  +  }
  +
  +  /**
  +   * Logs a message that fatal error that occurred while performing binding
  +   * 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.
  +   */
  +  private void logError(String msg) {
  +    mAnySevereErrors = true;
  +    mLogger.log(Level.SEVERE,msg,null);
  +  }
  +
  +  /**
  +   * Logs a message that fatal error that occurred.
  +   */
  +  private void logError(Throwable t) {
  +    mAnySevereErrors = true;
  +    mLogger.log(Level.SEVERE,null,t);
     }
   
     /**
  @@ -398,7 +457,7 @@
      * mode.
      */
     private void logVerbose(JElement context, String msg) {
  -    //FIXME
  +    mLogger.log(Level.FINEST,msg,null,context);
     }
   
     /*
  
  
  
  1.2       +0 -7      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaResult.java
  
  Index: Java2SchemaResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaResult.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Java2SchemaResult.java	5 Dec 2003 21:48:18 -0000	1.1
  +++ Java2SchemaResult.java	10 Dec 2003 03:24:03 -0000	1.2
  @@ -66,13 +66,6 @@
   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.
      */
  
  
  
  1.10      +43 -15    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Java2SchemaTask.java	5 Dec 2003 21:48:18 -0000	1.9
  +++ Java2SchemaTask.java	10 Dec 2003 03:24:03 -0000	1.10
  @@ -62,6 +62,11 @@
   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.tylar.ExplodedTylar;
  +import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
  +import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
  +import org.apache.xmlbeans.impl.binding.tylar.Tylar;
  +import org.w3.x2001.xmlSchema.SchemaDocument;
   
   import java.io.File;
   import java.io.IOException;
  @@ -78,7 +83,7 @@
     // Variables
   
     private File mDestDir = null;
  -  private File mTempDir = null;
  +  private File mDestJar = null;
     private Path mSourcepath = null;
     private Path mClasspath = null;
     private String mIncludes = null;
  @@ -87,9 +92,19 @@
     // =========================================================================
     // Task attributes
   
  -  public void setDestDir(File dir) { mDestDir = dir; }
  +  public void setDestDir(File dir) {
  +    if (mDestJar != null) {
  +      throw new BuildException("You can set only one of destjar and destdir");
  +    }
  +    mDestDir = dir;
  +  }
   
  -  public void setTempDir(File dir) { mTempDir = dir; }
  +  public void setDestJar(File jar) throws BuildException {
  +    if (mDestDir != null) {
  +      throw new BuildException("You can set only one of destjar and destdir");
  +    }
  +    mDestJar = jar;
  +  }
   
     /**
      * Set the source directories to find the source Java files.
  @@ -144,6 +159,10 @@
       mIncludes = includes;
     }
   
  +  public void setCompileSources(boolean ignoredRightNow) {}
  +
  +  public void setCopySources(boolean ignoredRightNow) {}
  +
     // =========================================================================
     // Task implementation
   
  @@ -154,7 +173,7 @@
       JFactory jf = JFactory.getInstance();
       String[] list = mSrcDir.list();
       if (list.length == 0) throw new BuildException("srcDir attribute required");
  -    if (list.length > 1) throw new BuildException("multipled srcDirs NYI");
  +    if (list.length > 1) throw new BuildException("multiple srcDirs NYI");
       JFileSet fs = jf.createFileSet(new File(list[0]));
       fs.include(mIncludes);
       String classpathString = null;
  @@ -174,20 +193,29 @@
         public TylarLoader getTylarLoader() { return null; }
         public void compileJavaToBinaries(File classesDir) {}
       };
  -    Java2Schema j2b = new Java2Schema(input);
  -    TylarBuilder tb = new ExplodedTylarBuilder(mDestDir);
  -    Java2SchemaResult result = j2b.bind();
  -    try {
  -      tb.buildTylar(result);
  -    } catch(IOException ioe) {
  -      ioe.printStackTrace();
  -      throw new BuildException(ioe);
  +    BindingLogger logger = new SimpleBindingLogger();
  +    Java2Schema j2b = new Java2Schema(input,logger);
  +    Tylar tylar = null;
  +    if (mDestDir != null) {
  +      tylar = j2b.bindAsExplodedTylar(mDestDir);
  +    } else if (mDestJar != null) {
  +      tylar = j2b.bindAsJarredTylar(mDestJar);
  +    }
  +    if (tylar == null) {
  +      throw new BuildException("fatal errors encountered, "+
  +                               "see log for details.");
       }
  -    log("Java2Schema complete, output in "+mDestDir);
  +    log("Java2SchemaTask complete, output at "+tylar.getLocation());
     }
   
     // =========================================================================
     // Private methods
   
  -
  -}
  +  private void printErrors(Throwable[] errs) {
  +    if (errs == null || errs.length == 0) return;
  +    for(int i=0; i<errs.length; i++) {
  +      errs[i].printStackTrace();
  +    }
  +    System.out.flush();
  +  }
  +}
  \ No newline at end of file
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingLogger.java
  
  Index: BindingLogger.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.compile;
  
  import org.apache.xmlbeans.impl.jam.JElement;
  import org.w3.x2001.xmlSchema.Element;
  import java.util.logging.Level;
  
  /**
   * Note that the binding compilers should attempt to continue even after
   * errors are encountered so as to identify as many errors as possible in a
   * single pass.
   */
  public interface BindingLogger {
  
    /**
     * Logs a message that was produced while performing binding.
     *
     * @param level         Severity of the message
     * @param message       Text message or null
     * @param error         Error or null
     */
    public void log(Level level,
                    String message,
                    Throwable error);
  
    /**
     * Logs a message that was produced while performing binding
     * on the given java construct.
     *
     * @param level         Severity of the message
     * @param message       Text message or null
     * @param error         Error or null
     * @param javaContext   JAM context element or null
     */
    public void log(Level level,
                    String message,
                    Throwable error,
                    JElement javaContext);
  
    /**
     * Logs a message that was produced while performing binding
     * on the given schema construct.
     *
     * @param level         Severity of the message
     * @param schemaContext Schema context element or null
     * @param message       Text message or null
     * @param error         Error or null
     */
    public void log(Level level,
                    String message,
                    Throwable error,
                    Element schemaContext);
  
  }
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SimpleBindingLogger.java
  
  Index: SimpleBindingLogger.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.compile;
  
  import java.util.logging.Level;
  import java.io.PrintWriter;
  import org.apache.xmlbeans.impl.jam.JElement;
  import org.w3.x2001.xmlSchema.Element;
  
  /**
   * Implementation of BindingLogger that just spews out to some writer.
   */
  public class SimpleBindingLogger implements BindingLogger {
  
    // ========================================================================
    // Variables
  
    private PrintWriter mOut;
  
    // ========================================================================
    // Constructors
  
    public SimpleBindingLogger() {
      this(new PrintWriter(System.out));
    }
  
    public SimpleBindingLogger(PrintWriter out) {
      if (out == null) throw new IllegalArgumentException();
      mOut = out;
    }
  
    // ========================================================================
    // BindingLogger implementation
  
    public void log(Level level, String message, Throwable error) {
      mOut.print(level.toString());
      if (message != null) {
        mOut.print(' ');
        mOut.print(message);
      }
      mOut.println();
      if (error != null) {
        error.printStackTrace(mOut);
      }
      mOut.flush();
    }
  
    public void log(Level level,
                    String message,
                    Throwable error,
                    JElement javaContext) {
      log(level,"'"+message+"' on "+javaContext.getQualifiedName(),error);
    }
  
    public void log(Level level,
                    String message,
                    Throwable error,
                    Element schemaContext) {
      log(level,message,error);
    }
  
  
  }
  
  
  
  1.2       +4 -6      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileWriterFactory.java	5 Dec 2003 19:59:10 -0000	1.1
  +++ FileWriterFactory.java	10 Dec 2003 03:24:03 -0000	1.2
  @@ -83,10 +83,6 @@
   
     public FileWriterFactory(File sourceRoot) {
       if (sourceRoot == null) throw new IllegalArgumentException();
  -    if (!sourceRoot.mkdirs()) {
  -      throw new IllegalArgumentException("Failed to create directory " +
  -                                         sourceRoot);
  -    }
       mSourceRoot = sourceRoot;
     }
   
  @@ -97,8 +93,10 @@
             throws IOException {
       File dir = new File(mSourceRoot, packageName.replace
                                        (PACKAGE_SEPARATOR, File.separatorChar));
  -    if (!dir.mkdirs()) {
  -      throw new IllegalArgumentException("Failed to create directory " + dir);
  +    if (!dir.exists()) {
  +      if (!dir.mkdirs()) {
  +        throw new IOException("Failed to create directory " + dir);
  +      }
       }
       File outFile = new File(dir, className + EXTENSION);
       return new FileWriter(outFile);
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylar.java
  
  Index: ExplodedTylar.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.tylar;
  
  import java.io.File;
  import java.io.IOException;
  
  /**
   * An extension of Tylar which is known to exist as an open directory
   * structure.  This is useful for consumers who may need additional control
   * over the generated artifacts, e.g. to manually perform compilation of
   * generated java source files.
   */
  public interface ExplodedTylar extends Tylar {
  
    // ========================================================================
    // Public methods - these services are the 'value add' we provide over
    // just a generic Tylar.
  
    /**
     * Returns the directory on disk in which the tylar is stored.  Never
     * returns null.
     */
    public File getRootDir();
  
    /**
     * Returns the directory in which generated source files are stored in
     * the tylar.
     */
    public File getSourceDir();
  
    /**
     * Returns the directory in which generated class files are stored in
     * the tylar.  (Note that this typically is the same as the root dir).
     */
    public File getClassDir();
  
    /**
     * Returns the directory in which generated schema files are stored in
     * the tylar.
     */
    public File getSchemaDir();
  
  
    /**
     * Jars up the exploded tylar directory into the given file and returns
     * a handle to the JarredTylar.  The main advantage of using this method
     * over jarring it yourself is that this may save you the cost or reparsing
     * the binding file and the schemas, in the event that you want to
     * immediately hand the tylar to the runtime.
     *
     * @param jarfile Destination file for the new jar
     * @return A handle to the newly-created tylar
     * @throws java.io.IOException if the specified jarfile already exists or if an
     * error occurs while writing the file.
     */
    public TylarConstants toJar(File jarfile) throws IOException;
  }
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java
  
  Index: ExplodedTylarImpl.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.tylar;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.impl.binding.joust.*;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  import java.io.*;
  import java.util.Collection;
  import java.util.ArrayList;
  import java.net.URI;
  
  /**
   * Concrete implementation of ExplodedTylar - a tylar which exists in an open
   * directory structure on disk.  Note that this class also implements
   * TylarWriter, which allows the compile time to build up the tylar files
   * and then hand them directly to the runtime if desired.
   */
  public class ExplodedTylarImpl
          implements TylarConstants, ExplodedTylar, TylarWriter
   {
  
    // ========================================================================
    // Constants
  
    private static final int XML_INDENT = 2;
  
    // ========================================================================
    // Variables
  
    private File mRootDir;
    private File mSourceRoot;
    private File mSchemaDir;
    private BindingFile mBindingFile = null;
    private JavaOutputStream mJoust;
    private Collection mSchemaDocuments = null;
  
    // ========================================================================
    // Constructors
  
    /**
     * Constructs a new ExplodedTylarImpl in the given directory.  The
     * default JavaOutputStream is used, which simply writes java sources
     * into the 'src' directory of the tylar.
     */
    public ExplodedTylarImpl(File dir) {
      this(dir,null);
      mJoust = new ValidatingJavaOutputStream
              (new SourceJavaOutputStream(new FileWriterFactory(mSourceRoot)));
    }
  
    /**
     * Constructs a new ExplodedTylarImpl in the given directory and using
     * the given JavaOutputStream.
     */
    public ExplodedTylarImpl(File dir, JavaOutputStream joust) {
      if (dir.exists() && dir.isFile()) {
        throw new IllegalArgumentException("already a file at '"+dir+"'");
      }
      dir.mkdirs();
      mRootDir = dir;
      mSourceRoot = new File(mRootDir,SRC_ROOT);
      mSchemaDir = new File(mRootDir,SCHEMA_DIR);
      mJoust = joust;
    }
  
  
    // ========================================================================
    // TylarWriter implementation
  
    public void writeBindingFile(BindingFile bf) throws IOException {
      mBindingFile = bf;
      writeBindingFile(bf,new File(mRootDir,BINDING_FILE));
    }
  
    public void writeSchema(SchemaDocument xsd, String schemaFileName)
            throws IOException
    {
      if (mSchemaDocuments == null) mSchemaDocuments = new ArrayList();
      mSchemaDocuments.add(xsd);
      writeXsd(xsd,new File(mSchemaDir,schemaFileName));
    }
  
    public JavaOutputStream getJavaOutputStream() {
      return mJoust;
    }
  
    // ========================================================================
    // Tylar implementation
  
    public BindingFile getBindingFile() throws IOException, XmlException {
      if (mBindingFile == null) {
        mBindingFile = parseBindingFile(new File(mRootDir, BINDING_FILE));
      }
      return mBindingFile;
    }
  
    public SchemaDocument[] getSchemas() throws IOException, XmlException {
      if (mSchemaDocuments == null) {
        mSchemaDocuments = new ArrayList();
        parseSchemas(mSchemaDir,mSchemaDocuments);
      }
      SchemaDocument[] out = new SchemaDocument[mSchemaDocuments.size()];
      mSchemaDocuments.toArray(out);
      return out;
    }
  
    public URI getLocation() { return mRootDir.toURI(); }
  
    //not sure we ever need this
    public void resetCaches() {
      mSchemaDocuments = null;
      mBindingFile = null;
    }
  
    // ========================================================================
    // ExplodedTylar implementation
  
    /**
     * Returns the directory on disk in which the tylar is stored.  Never
     * returns null.
     */
    public File getRootDir() { return mRootDir; }
  
    public TylarConstants toJar(File jarfile) throws IOException {
      throw new RuntimeException("NYI");
    }
  
    public File getSourceDir() {
      return mSourceRoot;
    }
  
    public File getClassDir() {
      return mRootDir;
    }
  
    public File getSchemaDir() {
      return mSchemaDir;
    }
  
    // ========================================================================
    // Private methods
  
    private static void parseSchemas(File schemaDir, Collection out)
            throws IOException, XmlException
    {
      File[] xsds = schemaDir.listFiles();
      for(int i=0; i<xsds.length; i++) {
        out.add(parseXsd(xsds[i]));
      }
    }
  
    private static SchemaDocument parseXsd(File file)
            throws IOException, XmlException
    {
      FileReader in = null;
      try {
        in = new FileReader(file);
        return SchemaDocument.Factory.parse(in);
      } catch(IOException ioe) {
        throw ioe;
      } catch(XmlException xe) {
        throw xe;
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch(Exception ohwell) {
            ohwell.printStackTrace();
          }
        }
      }
    }
  
    private static void writeXsd(SchemaDocument xsd, File file)
            throws IOException
    {
      FileOutputStream out = null;
      try {
        file.getParentFile().mkdirs();
        out = new FileOutputStream(file);
        xsd.save(out,
                 new XmlOptions().setSavePrettyPrint().
                 setSavePrettyPrintIndent(XML_INDENT));
      } catch (IOException ioe) {
        throw ioe;
      } finally {
        if (out != null) {
          try {
            out.close();
          } catch(Exception ohwell) {
            ohwell.printStackTrace();
          }
        }
      }
    }
  
    private static BindingFile parseBindingFile(File file)
            throws IOException, XmlException
    {
      FileReader in = null;
      try {
        in = new FileReader(file);
        return BindingFile.forDoc(BindingConfigDocument.Factory.parse(in));
      } catch(IOException ioe) {
        throw ioe;
      } catch(XmlException xe) {
        throw xe;
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch(Exception ohwell) {
            ohwell.printStackTrace();
          }
        }
      }
    }
  
    private static void writeBindingFile(BindingFile bf, File file)
            throws IOException
    {
      FileWriter out = null;
      try {
        file.getParentFile().mkdirs();
        out = new FileWriter(file);
        BindingConfigDocument doc = bf.write();
        doc.save(out,
                 new XmlOptions().setSavePrettyPrint().
                 setSavePrettyPrintIndent(XML_INDENT));
        out.flush();
      } catch(IOException ioe) {
        throw ioe;
      } finally {
        if (out != null) {
          try {
            out.close();
          } catch(Exception ohwell) {
            ohwell.printStackTrace();
          }
        }
      }
    }
  }
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java
  
  Index: Tylar.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.tylar;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.XmlException;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  import java.net.URI;
  import java.io.File;
  import java.io.IOException;
  
  /**
   * Abstract representation of a type library archive.  This is the interface
   * which is used by the binding runtime for retrieving information about a
   * tylar.
   */
  public interface Tylar {
  
    // ========================================================================
    // Public methods
  
    /**
     * Returns the binding file for this Tylar.
     */
    public BindingFile getBindingFile() throws IOException, XmlException;
  
    /**
     * Returns the schemas contained in this Tylar.
     */
    public SchemaDocument[] getSchemas() throws IOException, XmlException;
  
    /**
     * Returns a URI describing the location of the physical store from
     * which this Tylar was built.  This is useful for logging purposes.
     */
    public URI getLocation();
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarConstants.java
  
  Index: TylarConstants.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.tylar;
  
  import java.io.File;
  
  /**
   * These constants describe the physical structure of the tylar archive.
   * The values are subject to change at any time and should not be used
   * outside of this package.
   */
  public interface TylarConstants {
  
    // ========================================================================
    // Constants
  
    public static final char SEP = File.separatorChar;
  
    public static final String SRC_ROOT = "src";
  
    public static final String METAINF = "META-INF";
  
    public static final String BINDING_FILE = METAINF +SEP+ "binding-file.xml";
  
    public static final String SCHEMA_DIR = METAINF +SEP+ "schemas";
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarWriter.java
  
  Index: TylarWriter.java
  ===================================================================
  package org.apache.xmlbeans.impl.binding.tylar;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  import java.io.IOException;
  
  /**
   * Interface which is used at compile time for building up a tylar.
   */
  public interface TylarWriter {
  
    /**
     * Writes the given BindingFile into the tylar.
     *
     * @param bf The binding file
     * @throws IOException
     */
    public void writeBindingFile(BindingFile bf) throws IOException;
  
    /**
     * Writes the given schema into the tylar.
     *
     * @param xsd  The schema
     * @param filepath Path relative to the 'schemas' directory of the tylar
     * @throws IOException
     */
    public void writeSchema(SchemaDocument xsd, String filepath) throws IOException;
  
    /**
     * Returns the JavaOutputStream which should be used for creating new java
     * code to be stored in this tylar.
     */
    public JavaOutputStream getJavaOutputStream();
  
  }
  
  
  

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