You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/01/14 08:19:15 UTC

cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases BindingTests.java MarshalTests.java

pcal        2004/01/13 23:19:15

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompiler.java BindingCompilerTask.java
                        Both2Bind.java Both2BindTask.java Java2Schema.java
                        Java2SchemaTask.java Schema2Java.java
                        TypeMatcher.java TypeMatcherContext.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/logger
                        BindingLogger.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        DefaultTylarLoader.java ExplodedTylarImpl.java
                        Tylar.java TylarImpl.java TylarLoader.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        BindingContextFactoryImpl.java
               v2/src/xmlpublic/org/apache/xmlbeans
                        BindingContextFactory.java
               v2/test/src/drt/drtcases BindingTests.java MarshalTests.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        DefaultTypeMatcher.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        BaseTylarImpl.java CompositeTylar.java
  Removed:     v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BothSourceSet.java JavaSourceSet.java
                        SchemaCodeResult.java SchemaSourceSet.java
                        SimpleSourceSet.java SimpleTylarLoader.java
                        SimpleTypeMatcher.java TylarLoader.java
  Log:
  finish refactoring both2bind
  
  Revision  Changes    Path
  1.9       +38 -87    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BindingCompiler.java	13 Jan 2004 19:21:56 -0000	1.8
  +++ BindingCompiler.java	14 Jan 2004 07:19:15 -0000	1.9
  @@ -57,19 +57,14 @@
   
   import org.apache.xmlbeans.impl.binding.tylar.*;
   import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  -import org.apache.xmlbeans.impl.binding.bts.PathBindingLoader;
   import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
   import org.apache.xmlbeans.impl.binding.logger.BindingLogger;
  -import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
   import org.apache.xmlbeans.impl.jam.JClassLoader;
   import org.apache.xmlbeans.impl.jam.JFactory;
   import org.apache.xmlbeans.*;
  -import org.w3.x2001.xmlSchema.SchemaDocument;
   
   import java.io.File;
   import java.io.IOException;
  -import java.util.ArrayList;
  -import java.util.Collection;
   
   /**
    * Abstract base class for classes which produce a tylar based on
  @@ -94,10 +89,7 @@
     // ========================================================================
     // Variables
   
  -  private Tylar[] mBaseLibraries = null;
  -  private BindingLoader mBaseBindingLoader = null;
  -  private SchemaTypeLoader mBaseSchemaTypeLoader = null;
  -  private JClassLoader mBaseJClassLoader = null;
  +  private Tylar mBaseTylar = null;
     private boolean mIsCompilationStarted = false;
   
     // ========================================================================
  @@ -114,7 +106,7 @@
      * to be thrown; the extending class should call logError() with any
      * unexpected exceptions -  BindingCompiler takes care of the rest.
      */
  -  public abstract void bind(TylarWriter writer);
  +  protected abstract void internalBind(TylarWriter writer);
   
     /**
      * Creates the ExplodedTylarImpl/Writer to be used when one of the bindAs...
  @@ -132,6 +124,15 @@
     // Public methods
   
     /**
  +   * Public method for beginning the binding compilation process with
  +   * an arbitrary TylarWriter.  Delegates to the subclass to do the real work.
  +   */
  +  public final void bind(TylarWriter writer) {
  +    mIsCompilationStarted = true;
  +    internalBind(writer);
  +  }
  +
  +  /**
      * Performs the binding and returns an exploded tylar in the specified
      * directory.  Returns null if any severe errors were encountered.
      */
  @@ -181,20 +182,15 @@
     }
   
     /**
  -   * Sets the list type libraries that should be checked for resolving
  -   * bindings before creating bindings in the new tylar being compiled.
  -   * Bindings provided in these tylars will preempt the compilation of
  -   * equivalent bindings in the tylar generated by this compiler, so it is
  -   * the user's responsibility to ensure that these tylars are made available
  -   * at runtime.
  +   * Sets the base type libraries that should be checked for resolving
  +   * bindings before creating bindings in the new lib being compiled.
      *
  -   * This is an optional setting; if the libraries are not provided, only the
  +   * This is an optional setting; if the lib is not provided, only the
      * default (builtin) loader will be used.
      */
  -  public void setBaseLibraries(Tylar[] list) {
  -    assertCompilationStarted(false);
  -    if (list == null) throw new IllegalArgumentException("null list");
  -    mBaseLibraries = list;
  +  public void setBaseLibrary(Tylar lib) {
  +    if (lib == null) throw new IllegalArgumentException("null lib");
  +    mBaseTylar = lib;
     }
   
   
  @@ -221,82 +217,54 @@
     }
   
     // ========================================================================
  -  // TypeMatcherContext impl
  -
  -  public BindingLogger getLogger() { return this; }
  +  // TypeMatcherContext implementation
   
  -  // ========================================================================
  -  // Protected methods
  +    public BindingLogger getLogger() { return this; }
   
     /**
      * Subclasses should call this method to retrieve the BindingLoader
      * to use as a basis for the binding process.  Normally, this will
      * simply be the builtin loader.  However, if the user has
  -   * setExistingBindings, the returned loader will also include those
  +   * setBaseLibrary, the returned loader will also include those
      * bindings as well.  Note that this method must not be called until
      * binding has actually begun.
      *
      * @throws IllegalStateException if this method is called before
      * the abstract bind() method is called.
      */
  -  protected BindingLoader getBaseBindingLoader() {
  +  public BindingLoader getBaseBindingLoader() {
       assertCompilationStarted(true);
  -    if (mBaseBindingLoader == null) {
  -      if (mBaseLibraries == null) {
  -        mBaseBindingLoader = BuiltinBindingLoader.getInstance();
  -      } else {
  -        //new up a loader on the bindings provided in the base libraries
  -        //they gave us
  -        BindingLoader[] loaders = new BindingLoader[mBaseLibraries.length+1];
  -        for(int i=0; i<mBaseLibraries.length; i++) {
  -          loaders[i] = mBaseLibraries[i].getBindingFile();
  -        }
  -        loaders[loaders.length-1] = BuiltinBindingLoader.getInstance();
  -        mBaseBindingLoader = PathBindingLoader.forPath(loaders);
  -      }
  +    if (mBaseTylar == null) {
  +      return BuiltinBindingLoader.getInstance();
  +    } else {
  +      return mBaseTylar.getBindingLoader();
       }
  -    return mBaseBindingLoader;
     }
   
  -
     /**
      * Returns a SchemaTypeLoader to be used as a basis for the binding process.
      * Normally, this will simply be the builtin loader.  However, if the user
  -   * has setBaseLibraries, the returned loader will also include the schema
  +   * has setBaseLibrary, the returned loader will also include the schema
      * types in those libraries.  Note that this method must not be called until
      * binding has actually begun.
      *
      * @throws IllegalStateException if this method is called before
      * the abstract bind() method is called.
      */
  -  protected SchemaTypeLoader getBaseSchemaTypeLoader() throws XmlException
  +  public SchemaTypeSystem getBaseSchemaTypeSystem()
     {
       assertCompilationStarted(true);
  -    if (mBaseSchemaTypeLoader == null) {
  -      if (mBaseLibraries == null) {
  -        mBaseSchemaTypeLoader = XmlBeans.getBuiltinTypeSystem();
  -      } else {
  -        //create a schema type loader based on all of the schemas in all
  -        //of the base tylars
  -        Collection schemas = new ArrayList();
  -        for(int i=0; i<mBaseLibraries.length; i++) {
  -          SchemaDocument[] xsds = mBaseLibraries[i].getSchemas();
  -          for(int j=0; j<xsds.length; j++) schemas.add(xsds[j].getSchema());
  -        }
  -        XmlObject[] xxds = new XmlObject[schemas.size()];
  -        schemas.toArray(xxds);
  -        mBaseSchemaTypeLoader = XmlBeans.
  -                compileXsd(xxds,XmlBeans.getBuiltinTypeSystem(),null);
  -      }
  -
  +    if (mBaseTylar == null) {
  +      return XmlBeans.getBuiltinTypeSystem();
  +    } else {
  +      return mBaseTylar.getSchemaTypeSystem();
       }
  -    return mBaseSchemaTypeLoader;
     }
   
     /**
      * Returns a JClassLoader to be used as a basis for the binding process.
      * Normally, this will simply be the loader backed by the system
  -   * classloader.  However, if the user has setBaseLibraries, the returned
  +   * classloader.  However, if the user has setBaseLibrary, the returned
      * loader will also load java classes that may be stored those libraries.
      * Note that this method must not be called until binding has actually
      * begun.
  @@ -304,23 +272,15 @@
      * @throws IllegalStateException if this method is called before
      * the abstract bind() method is called.
      */
  -  protected JClassLoader getBaseJavaTypeLoader() throws XmlException
  +  public JClassLoader getBaseJavaTypeLoader()
     {
       assertCompilationStarted(true);
  -    if (mBaseJClassLoader == null) {
  -      if (mBaseLibraries == null) {
  -        mBaseJClassLoader = JFactory.getInstance().getSystemClassLoader();
  -      } else {
  -        //create a classloader chain that runs throw all of the base tylars
  -        ClassLoader cl = ClassLoader.getSystemClassLoader();//FIXME this needs a knob
  -        for(int i = mBaseLibraries.length; i >= 0; i--) {
  -          cl = mBaseLibraries[i].createClassLoader(cl);
  -        }
  -        mBaseJClassLoader = JFactory.getInstance().
  -                createClassLoader(cl,null,null);
  -      }
  +    if (mBaseTylar == null) {
  +      return JFactory.getInstance().
  +                createClassLoader(ClassLoader.getSystemClassLoader(),null,null);
  +    } else {
  +      return mBaseTylar.getJClassLoader();
       }
  -    return mBaseJClassLoader;
     }
   
     /**
  @@ -339,15 +299,6 @@
                  "binding compilation has begun");
       }
     }
  -
  -  /**
  -   * Should be the first thing called in every implmentation of
  -   * bind(TylarWriter).  Just tells us that the compiler's state has changed.
  -   */
  -  protected void notifyCompilationStarted() {
  -    mIsCompilationStarted = true;
  -  }
  -
   
     // ========================================================================
     // Private methods
  
  
  
  1.6       +24 -0     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BindingCompilerTask.java	13 Jan 2004 05:40:11 -0000	1.5
  +++ BindingCompilerTask.java	14 Jan 2004 07:19:15 -0000	1.6
  @@ -60,6 +60,9 @@
   import org.apache.xmlbeans.impl.binding.tylar.Tylar;
   import org.apache.xmlbeans.impl.binding.logger.MessageSink;
   import org.apache.xmlbeans.impl.binding.logger.SimpleMessageSink;
  +import org.apache.xmlbeans.impl.jam.JFactory;
  +import org.apache.xmlbeans.impl.jam.JFileSet;
  +import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.SchemaTypeSystem;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
  @@ -183,6 +186,27 @@
       }
       return XmlBeans.compileXsd(xsds, XmlBeans.getBuiltinTypeSystem(), null);
     }
  +
  +  protected JClass[] loadJClasses(final File[] javaFiles, String classpath)
  +          throws IOException
  +  {
  +    JFileSet fs = new JFileSet() {
  +      public void include(String pattern) {}
  +      public void exclude(String pattern) {}
  +      public void setClasspath(String cp) {}
  +      public void setCaseSensitive(boolean b) {}
  +      public File[] getFiles() { return javaFiles; }
  +    };
  +    /*
  +    String classpathString = null;
  +    if (mClasspath != null) {
  +      //this will be removed after jam factory is refactored
  +      fs.setClasspath(classpathString = mClasspath.toString());
  +    }
  +    */
  +    return JFactory.getInstance().loadSources(fs,null,null,null,null,classpath);
  +  }
  +
   
   
     // ========================================================================
  
  
  
  1.6       +31 -15    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java
  
  Index: Both2Bind.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Both2Bind.java	8 Jan 2004 23:48:10 -0000	1.5
  +++ Both2Bind.java	14 Jan 2004 07:19:15 -0000	1.6
  @@ -59,6 +59,7 @@
   import org.apache.xmlbeans.SchemaProperty;
   import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   import org.apache.xmlbeans.impl.binding.bts.*;
   import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
   import org.apache.xmlbeans.impl.jam.JClass;
  @@ -75,12 +76,13 @@
     // Variables
   
     private TypeMatcher mMatcher;
  -  private BothSourceSet mBss;
     private Map scratchFromXmlName = new LinkedHashMap();
     private Map scratchFromJavaName = new LinkedHashMap();
     private Map scratchFromBindingName = new LinkedHashMap();
     private BindingFile bindingFile = new BindingFile();
     private LinkedList resolveQueue = new LinkedList();
  +  private JClass[] mJavaTypes = null;
  +  private SchemaTypeSystem mSchemaTypes = null;
   
     // ========================================================================
     // Constructor
  @@ -91,6 +93,22 @@
     // Compilation attributes
   
     /**
  +   * Sets the java types to be compiled.  This is required.
  +   */
  +  public void setJavaTypesToMatch(JClass[] jclasses) {
  +    if (jclasses == null) throw new IllegalArgumentException("null jclasses");
  +    mJavaTypes = jclasses;
  +  }
  +
  +  /**
  +   * Sets the schema types to be compiled.  This is required.
  +   */
  +  public void setSchemaTypesToMatch(SchemaTypeSystem sts) {
  +    if (sts == null) throw new IllegalArgumentException("null sts");
  +    mSchemaTypes = sts;
  +  }
  +
  +  /**
      * Sets a custom TypeMatcher to use for lining up the java and schema types.
      * This is optional; if omitted, a default TypeMatcher will be used.
      * @param matcher
  @@ -102,7 +120,7 @@
     // ========================================================================
     // BindingCompiler implementation
   
  -  public void bind(TylarWriter tw) {
  +  protected void internalBind(TylarWriter tw) {
       bind();
       try {
         tw.writeBindingFile(bindingFile);
  @@ -115,16 +133,6 @@
     // Deprecated methods
   
     /**
  -   * @deprecated BothSourceSet should be replaced by attributes on
  -   * this class.
  -   *
  -   * @param bss
  -   */
  -  public void setBothSourceSet(BothSourceSet bss) {
  -    mBss = bss;
  -  }
  -
  -  /**
      * @deprecated BindingFile should not be used directly any more - you
      * need to use tylars.  The entry point you should probably use now is
      * BindingCompiler.bindAsJarredTylar().
  @@ -137,7 +145,8 @@
     // Private methods
   
     private void bind() {
  -    if (mMatcher == null) mMatcher = new SimpleTypeMatcher();
  +    if (mMatcher == null) mMatcher = new DefaultTypeMatcher();
  +    mMatcher.init(this);
       // Let the passed mMatcher propose any matches it wishes to
   
       resolveInitiallyMatchedTypes();
  @@ -309,8 +318,15 @@
      * a schema type, and a category.
      */
     private void resolveInitiallyMatchedTypes() {
  -    TypeMatcher.MatchedType[] matchedTypes = mMatcher.matchTypes(mBss);
  +    if (mJavaTypes == null) {
  +      throw new IllegalStateException("javaTypesToMatch was never set");
  +    }
  +    if (mSchemaTypes == null) {
  +      throw new IllegalStateException("schemaTypesToMatch was never set");
  +    }
   
  +    TypeMatcher.MatchedType[] matchedTypes =
  +            mMatcher.matchTypes(mJavaTypes, mSchemaTypes);
       for (int i = 0; i < matchedTypes.length; i++) {
         Scratch scratch = createScratch(matchedTypes[i].getJClass(), matchedTypes[i].getSType());
         scratchFromBindingName.put(scratch.getBindingTypeName(), scratch);
  @@ -432,7 +448,7 @@
         return scratch.getBindingType();
   
       // Then look on path
  -    BindingType result = mBss.getTylarLoader().getBindingLoader().getBindingType(btName);
  +    BindingType result = getBaseBindingLoader().getBindingType(btName);
       if (result != null)
         return result;
   
  
  
  
  1.6       +5 -57     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2BindTask.java
  
  Index: Both2BindTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2BindTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Both2BindTask.java	9 Jan 2004 20:30:39 -0000	1.5
  +++ Both2BindTask.java	14 Jan 2004 07:19:15 -0000	1.6
  @@ -56,20 +56,15 @@
   
   package org.apache.xmlbeans.impl.binding.compile;
   
  -import org.apache.tools.ant.taskdefs.MatchingTask;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
   import org.apache.tools.ant.types.FileSet;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.XmlOptions;
  -import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  -import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
   
   import java.io.File;
   import java.io.IOException;
  -import java.io.FileOutputStream;
   import java.util.List;
   import java.util.ArrayList;
   
  @@ -78,7 +73,6 @@
     // =========================================================================
     // Variables
   
  -  private File mDestFile = null;
     private Both2Bind mCompiler;
     private Path mSrc = null;
     private Path mClasspath = null;
  @@ -133,19 +127,13 @@
       File[] xsdFiles = (File[]) mXsdFiles.toArray(new File[mXsdFiles.size()]);
       File[] javaFiles = (File[]) mJavaFiles.toArray(new File[mJavaFiles.size()]);
   
  -    TylarLoader tylarLoader = null;
  -
  -    /*if (mClasspath != null) {
  -      File[] classpath = namesToFiles(mClasspath.list());
  -      tylarLoader = SimpleTylarLoader.forClassPath(classpath);
  -    } */
  -
       // bind
  -    BothSourceSet input = null;
       try {
         String cp = (mClasspath == null) ? null : mClasspath.toString();
  -      input = SimpleSourceSet.forJavaAndXsdFiles(javaFiles, xsdFiles, tylarLoader,cp);
  -      mCompiler.setBothSourceSet(input);
  +      //FIXME when we allow them to set up a base tylar, we need to take
  +      //those loaders into account here
  +      mCompiler.setSchemaTypesToMatch(createSchemaTypeSystem(xsdFiles));
  +      mCompiler.setJavaTypesToMatch(loadJClasses(javaFiles,cp));
       } catch (IOException e) {
         log(e.getMessage());
         throw new BuildException(e);
  @@ -156,44 +144,6 @@
       return mCompiler;
     }
   
  -  // ========================================================================
  -  // Temporary destFile hack - remove these methods when we no longer need to
  -  // support 'destFile' attribute
  -
  -  public void execute() throws BuildException {
  -    super.execute();
  -    if (mDestFile != null) {
  -      BindingFile bf = mCompiler.getBindingFile();
  -      FileOutputStream out = null;
  -      try {
  -        out = new FileOutputStream(mDestFile);
  -        BindingConfigDocument doc = bf.write();
  -        doc.save(out,
  -                new XmlOptions().setSavePrettyPrint().
  -                setSavePrettyPrintIndent(2));
  -      } catch (IOException ioe) {
  -        throw new BuildException(ioe);
  -      } finally {
  -        try {
  -          if (out != null)
  -            out.close();
  -        } catch (IOException ohwell) {
  -          ohwell.printStackTrace();
  -        }
  -      }
  -    }
  -  }
  -
  -  public void setDestFile(File file) {
  -    log("note: the 'destFile' attribute is deprecated and will soon\n" +
  -            "be removed.  You should instead use destJar, which generates\n" +
  -            "a full tylar jar (which contains, among other things, the\n" +
  -            "binding file).  You should not be directly using the binding " +
  -            "file directly anymore");
  -    mDestFile = file;
  -    super.setDestDir(file.getParentFile());
  -  }
  -
     // =========================================================================
     // Task attributes
   
  @@ -310,6 +260,4 @@
         result[i] = new File(names[i]);
       return result;
     }
  -
  -
  -}
  +}
  \ No newline at end of file
  
  
  
  1.25      +1 -7      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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Java2Schema.java	8 Jan 2004 23:48:10 -0000	1.24
  +++ Java2Schema.java	14 Jan 2004 07:19:15 -0000	1.25
  @@ -56,17 +56,12 @@
   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.w3.x2001.xmlSchema.*;
   import javax.xml.namespace.QName;
   import java.util.ArrayList;
   import java.util.List;
  -import java.util.logging.Level;
  -import java.io.File;
   import java.io.IOException;
   
   
  @@ -127,8 +122,7 @@
      * Does the binding work on the inputs passed to the constructor and writes
      * out the tylar.
      */
  -  public void bind(TylarWriter writer) {
  -    super.notifyCompilationStarted();
  +  protected void internalBind(TylarWriter writer) {
       mBindingFile = new BindingFile();
       mLoader = PathBindingLoader.forPath
               (new BindingLoader[] {mBindingFile, super.getBaseBindingLoader()});
  
  
  
  1.15      +2 -0      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Java2SchemaTask.java	8 Jan 2004 23:48:11 -0000	1.14
  +++ Java2SchemaTask.java	14 Jan 2004 07:19:15 -0000	1.15
  @@ -145,6 +145,8 @@
     // BindingCompilerTask implementation
   
     protected BindingCompiler getCompilerToExecute() throws BuildException {
  +    //FIXME refactor this so the functionality is shared and consistent with
  +    //Both2BindTask
       JFactory jf = JFactory.getInstance();
       String[] list = mSrcDir.list();
       if (list.length == 0) throw new BuildException("srcDir attribute required");
  
  
  
  1.9       +1 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Schema2Java.java	13 Jan 2004 19:21:56 -0000	1.8
  +++ Schema2Java.java	14 Jan 2004 07:19:15 -0000	1.9
  @@ -194,7 +194,7 @@
      * 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) {
  +  protected void internalBind(TylarWriter writer) {
       if (sts == null) throw new IllegalStateException("SchemaTypeSystem not set");
       if ((mJoust = writer.getJavaOutputStream()) == null) {
         //sanity check
  @@ -202,7 +202,6 @@
                 "provide a JavaOutputStream, and so it cannot be used with "+
                 "schema2java.");
       }
  -    super.notifyCompilationStarted();
       bind();
       try {
         writer.writeBindingFile(bindingFile);
  
  
  
  1.4       +9 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java
  
  Index: TypeMatcher.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypeMatcher.java	12 Dec 2003 21:33:13 -0000	1.3
  +++ TypeMatcher.java	14 Jan 2004 07:19:15 -0000	1.4
  @@ -60,9 +60,17 @@
   import org.apache.xmlbeans.impl.jam.JProperty;
   import org.apache.xmlbeans.SchemaType;
   import org.apache.xmlbeans.SchemaProperty;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   
   public interface TypeMatcher
   {
  +
  +    /**
  +     * Called to initializes the TypeMatcher instance.  This is guaranteed
  +     * to be called prior to any of the match... methods.
  +     */
  +    public void init(TypeMatcherContext ctx);
  +
       /**
        * Returns a collection of MatchedTypes, advising which
        * Java classes and which Schema types should be matched
  @@ -71,7 +79,7 @@
        * dealt with automatically if possible, and warnings
        * will be produced for any types that are not covered.
        */ 
  -    MatchedType[] matchTypes(BothSourceSet bss);
  +    MatchedType[] matchTypes(JClass[] classes, SchemaTypeSystem sts);
       
       /**
        * Returns a collection of MatchedProperties, advising which
  
  
  
  1.2       +26 -1     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcherContext.java
  
  Index: TypeMatcherContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcherContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeMatcherContext.java	13 Jan 2004 05:40:11 -0000	1.1
  +++ TypeMatcherContext.java	14 Jan 2004 07:19:15 -0000	1.2
  @@ -56,13 +56,38 @@
   package org.apache.xmlbeans.impl.binding.compile;
   
   import org.apache.xmlbeans.impl.binding.logger.BindingLogger;
  +import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  +import org.apache.xmlbeans.impl.jam.JClassLoader;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   
   /**
  + * Provides context/initialzation information for a TypeMatcher instance.
    *
    * @author Patrick Calahan <pc...@bea.com>
    */
   public interface TypeMatcherContext {
   
  +  /**
  +   * @return The logger to which the type matcher should send log messages.
  +   */
     public BindingLogger getLogger();
   
  -}
  +  /**
  +   * Returns the BindingLoader as a basis for the binding process.  Normally,
  +   * this will simply be the builtin loader.
  +   */
  +  public BindingLoader getBaseBindingLoader();
  +
  +  /**
  +   * Returns a SchemaTypeLoader to be used as a basis for the binding process.
  +   * Normally, this will simply be the builtin loader.
  +   */
  +  public SchemaTypeSystem getBaseSchemaTypeSystem();
  +
  +  /**
  +   * Returns a JClassLoader to be used as a basis for the binding process.
  +   * Normally, this will simply be the loader backed by the system
  +   * classloader.
  +   */
  +  public JClassLoader getBaseJavaTypeLoader();
  +}
  \ No newline at end of file
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/DefaultTypeMatcher.java
  
  Index: DefaultTypeMatcher.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.jam.JClass;
  import org.apache.xmlbeans.impl.jam.JProperty;
  import org.apache.xmlbeans.impl.common.NameUtil;
  import org.apache.xmlbeans.SchemaType;
  import org.apache.xmlbeans.SchemaProperty;
  import org.apache.xmlbeans.SchemaTypeSystem;
  
  import javax.xml.namespace.QName;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * This is a simple implementation of a type matcher
   * that uses the names of the Java classes and Schema
   * types, and Java properties and Schema elements or
   * attributes, to line them up with each other. 
   */
  public class DefaultTypeMatcher implements TypeMatcher
  {
      private TypeMatcherContext mContext;
  
      public void init(TypeMatcherContext ctx) {
        mContext = ctx;
      }
  
      public MatchedType[] matchTypes(JClass[] jClasses, SchemaTypeSystem sts) {
          SchemaType[] types = sts.globalTypes();
          
          List result = new ArrayList();
          
          // start the match
          startMatch();
          
          // add all the jClasses
          // todo: there is a need for some code which does
          // "primary interfaces" rather than "impl classes".  This
          // should be plugin behavior or controlled by annotations
          // rather than hard-coded.
          for (int i = 0; i < jClasses.length; i++) {
              putJavaName(jClasses[i].getSimpleName(), jClasses[i]);
          }
          
          // Then, go through all the Schema types with complex content
          // and try to find a matching Java class by looking for a similar
          // name.
          for (int i = 0; i < types.length; i++) {
              JClass jClass = (JClass)getSchemaName(types[i].getName());
              if (jClass != null)
                  result.add(new MatchedType(jClass, types[i]));
          }
          
          return (MatchedType[])result.toArray(new MatchedType[result.size()]);
      }
  
      public TypeMatcher.MatchedProperties[] matchProperties(JClass jClass, SchemaType sType)
      {
          SchemaProperty[] sProps = sType.getProperties();
          JProperty[] jProps = jClass.getProperties();
          
          List result = new ArrayList();
          
          // start the match
          startMatch();
          
          // add all the jProperties
          for (int i = 0; i < jProps.length; i++) {
              putJavaName(jProps[i].getSimpleName(), jProps[i]);
          }
          
          // Then, go through all the Schema properties and try to find a
          // matching Java property by looking for a similar name.
          for (int i = 0; i < sProps.length; i++) {
              JProperty jProp = (JProperty)getSchemaName(sProps[i].getName());
              if (jProp != null)
                  result.add(new MatchedProperties(jProp, sProps[i]));
          }
          
          return (MatchedProperties[])result.toArray(new MatchedProperties[result.size()]);
      }
  
      public JClass substituteClass(JClass declaredClass) {
          return declaredClass;
      }
  
      public void startMatch()
      {
          mapByShortName.clear();
          mapByLowercasedShortName.clear();
      }
  
      private final Map mapByShortName = new HashMap();
      private final Map mapByLowercasedShortName = new HashMap();
  
      /**
       * Returns false if the name has already been used.
       * Otherwise, indexes the given object by the given Java name.
       * 
       * Note that there is logic to be case-insensitive, yet to
       * remove case-insensitivity for names which differ from
       * each other only by case.
       */ 
      public boolean putJavaName(String key, Object value)
      {
          String shortName = key;
          verbose("JavaNameMatcher.put " + key);
          if (mapByShortName.containsKey(shortName))
              return false;
  
          mapByShortName.put(shortName, value);
  
          String lcShortName = shortName.toLowerCase();
          if (mapByLowercasedShortName.containsKey(lcShortName))
              mapByLowercasedShortName.put(lcShortName, null);
          else
              mapByLowercasedShortName.put(lcShortName, value);
  
          return true;
      }
  
      /**
       * Attempts to find a Java name similar to the given QName.
       * If found, returns the indexed object; otherwise returns
       * null.
       * 
       * Note that this algorithm searches for the localName to
       * match exactly; then in a case-insensitive way; and then
       * with XML punctuation removed and camel-casing applied;
       * and then in a case-insensitive way again.
       */ 
      public Object getSchemaName(QName name)
      {
          Object result = null;
          String localName = name.getLocalPart();
          verbose("JavaNameMatcher.getLocalPart " + localName);
  
          result = mapByShortName.get(localName);
          if (result != null) {
              verbose("javaTypeByShortName.get(localName): "+ localName);
              return result;
          }
  
          String lcLocalName = localName.toLowerCase();
          verbose("JavaNameMatcher.lcLocalName " + lcLocalName);
          result = mapByLowercasedShortName.get(lcLocalName);
          if (result != null) {
              verbose("javaTypeByLowercasedShortName.get(lcLocalName): " + lcLocalName);
              return result;
          }
  
          String niceName = NameUtil.upperCamelCase(localName);
          verbose("JavaNameMatcher.jaxbName " + niceName);
          result = mapByShortName.get(niceName);
          if (result != null) {
              verbose("javaTypeByShortName.get(jaxbName): " + niceName);
              return result;
          }
  
          String lowercaseNiceName = niceName.toLowerCase();
          verbose("JavaNameMatcher.lcJaxbName " + lowercaseNiceName);
          result = mapByLowercasedShortName.get(lowercaseNiceName);
          if (result != null) {
              verbose("javaTypeByShortName.get(lcJaxbName): " + lowercaseNiceName);
              return result;
          }
  
          verbose("javaTypeByShortName.get() no match found: " + localName);
  
          return null;
      }
  
      private void verbose(String w) {
        mContext.getLogger().logVerbose(w);
      }
  }
  
  
  1.2       +8 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/BindingLogger.java
  
  Index: BindingLogger.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/logger/BindingLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingLogger.java	13 Jan 2004 05:40:11 -0000	1.1
  +++ BindingLogger.java	14 Jan 2004 07:19:15 -0000	1.2
  @@ -127,6 +127,14 @@
     // Public logging methods
   
     /**
  +   * Logs a warning message.
  +   */
  +  public void logWarning(String msg) {
  +    mSink.log(new MessageImpl
  +            (Level.WARNING, msg, null, null, null, null));
  +  }
  +
  +  /**
      * Logs a message that some error occurred while performing binding.
      *
      * @return true if processing should attempt to continue.
  
  
  
  1.4       +8 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java
  
  Index: DefaultTylarLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultTylarLoader.java	19 Dec 2003 01:34:46 -0000	1.3
  +++ DefaultTylarLoader.java	14 Jan 2004 07:19:15 -0000	1.4
  @@ -61,7 +61,6 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.net.URI;
  -import java.net.URLConnection;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.jar.JarEntry;
  @@ -161,6 +160,14 @@
                               "' scheme is not supported for loading tylars" +
                               "("+uri+")");
       }
  +  }
  +
  +  public Tylar load(URI[] uris) throws IOException, XmlException {
  +    Tylar[] tylars = new Tylar[uris.length];
  +    for(int i=0; i<tylars.length; i++) {
  +      tylars[i] = load(uris[i]);
  +    }
  +    return new CompositeTylar(tylars);
     }
   
     // ========================================================================
  
  
  
  1.6       +4 -3      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExplodedTylarImpl.java	13 Jan 2004 05:40:11 -0000	1.5
  +++ ExplodedTylarImpl.java	14 Jan 2004 07:19:15 -0000	1.6
  @@ -85,7 +85,7 @@
    *
    * @author Patrick Calahan <pc...@bea.com>
    */
  -public class ExplodedTylarImpl
  +public class ExplodedTylarImpl extends BaseTylarImpl
           implements TylarConstants, ExplodedTylar, TylarWriter {
   
     // ========================================================================
  @@ -203,8 +203,8 @@
     // ========================================================================
     // Tylar implementation
   
  -  public BindingFile getBindingFile() {
  -    return mBindingFile;
  +  public BindingFile[] getBindingFiles() {
  +    return new BindingFile[] {mBindingFile};
     }
   
     public SchemaDocument[] getSchemas() {
  @@ -237,6 +237,7 @@
   
     public Tylar toJar(File jarfile) throws IOException {
       JarHelper j = new JarHelper();
  +    jarfile.getParentFile().mkdirs(); //make sure the path exists
       j.jarDir(mRootDir,jarfile);
       return new TylarImpl(jarfile.toURI(),mBindingFile,mSchemaDocuments);
     }
  
  
  
  1.4       +42 -10    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java
  
  Index: Tylar.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Tylar.java	8 Jan 2004 23:48:11 -0000	1.3
  +++ Tylar.java	14 Jan 2004 07:19:15 -0000	1.4
  @@ -57,6 +57,9 @@
   
   import java.net.URI;
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  +import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  +import org.apache.xmlbeans.impl.jam.JClassLoader;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   
   /**
  @@ -72,27 +75,56 @@
     // Public methods
   
     /**
  -   * Returns the binding file for this Tylar.
  +   * Returns a short textual description of this tylar.  This is primarily
  +   * useful for logging and debugging.
      */
  -  public BindingFile getBindingFile();
  +  public String getDescription();
   
     /**
  -   * Returns the schemas contained in this Tylar.
  +   * Returns a URI describing the location of the physical store from
  +   * which this Tylar was loaded.  This is useful for logging purposes.
  +   */
  +  public URI getLocation();
  +
  +  /**
  +   * Returns the binding files contained in this Tylar.
  +   */
  +  public BindingFile[] getBindingFiles();
  +
  +  /**
  +   * Returns the schema documents contained in this Tylar.
      */
     public SchemaDocument[] getSchemas();
   
     /**
  +   * Returns a BindingLoader for the bindings in this tylar.  This is really
  +   * just a convenience method; it simply returns a composite of the binding
  +   * files returned by getBindingFiles() plus the BuiltinBindingLoader.
  +   */
  +  public BindingLoader getBindingLoader();
  +
  +  /**
  +   * Returns a BindingLoader for the bindings in this tylar.  This is really
  +   * just a convenience method; it simply returns a the schema type system
  +   * that results from compiling all of the schemas returned by getSchemas()
  +   * plus the BuiltinSchemaTypeSystem.
  +   */
  +  public SchemaTypeSystem getSchemaTypeSystem();
  +
  +
  +  /**
  +   * Returns a JClassLoader which can be used to load descriptions of the
  +   * java types contained in this tylar.
  +   */
  +  public JClassLoader getJClassLoader();
  +
  +  /**
      * Returns a new ClassLoader that can load any class files contained in
      * this tylar.  Returns null if this tylar contains no class resources.
      *
  +   * REVIEW are we sure this method is needed?
  +   *
      * @param parent The parent for new classloader.
      */
     public ClassLoader createClassLoader(ClassLoader parent);
  -
  -  /**
  -   * Returns a URI describing the location of the physical store from
  -   * which this Tylar was loaded.  This is useful for logging purposes.
  -   */
  -  public URI getLocation();
  -
   }
  
  
  
  1.3       +3 -4      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarImpl.java
  
  Index: TylarImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TylarImpl.java	8 Jan 2004 23:48:11 -0000	1.2
  +++ TylarImpl.java	14 Jan 2004 07:19:15 -0000	1.3
  @@ -61,7 +61,6 @@
   import java.net.URLClassLoader;
   import java.util.Collection;
   import java.util.ArrayList;
  -import java.io.IOException;
   
   import org.apache.xmlbeans.impl.binding.bts.BindingFile;
   import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
  @@ -72,7 +71,7 @@
    *
    * @author Patrick Calahan <pc...@bea.com>
    */
  -public class TylarImpl implements Tylar, TylarWriter {
  +public class TylarImpl extends BaseTylarImpl implements Tylar, TylarWriter {
   
     // ========================================================================
     // Variables
  @@ -98,8 +97,8 @@
     // ========================================================================
     // Tylar implementation
   
  -  public BindingFile getBindingFile() {
  -    return mBindingFile;
  +  public BindingFile[] getBindingFiles() {
  +    return new BindingFile[] {mBindingFile};
     }
   
     public SchemaDocument[] getSchemas() {
  
  
  
  1.3       +15 -1     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarLoader.java
  
  Index: TylarLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TylarLoader.java	18 Dec 2003 01:58:58 -0000	1.2
  +++ TylarLoader.java	14 Jan 2004 07:19:15 -0000	1.3
  @@ -68,7 +68,7 @@
   public interface TylarLoader {
   
     /**
  -   * Loads the tylar from the given URI.
  +   * Loads a single tylar from the given URI.
      *
      * @param uri pointing to where the tylar is stored.
      * @return
  @@ -76,4 +76,18 @@
      * @throws XmlException if an error occurs parsing the contents of the tylar.
      */
     public Tylar load(URI uri) throws IOException, XmlException;
  +
  +  /**
  +   * Returns a composition of the set of tylars at the given URIs.  Tylars
  +   * will be consulted in the order in which they appear in this array when
  +   * resolving bindings and types; first one wins.
  +   *
  +   * @param uris pointing to where the tylars are stored.
  +   * @return
  +   * @throws IOException if an i/o error occurs while processing
  +   * @throws XmlException if an error occurs parsing the contents of the
  +   * tylars.
  +   */
  +  public Tylar load(URI[] uris) throws IOException, XmlException;
  +
   }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/BaseTylarImpl.java
  
  Index: BaseTylarImpl.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.tylar;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.PathBindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.impl.jam.JClassLoader;
  import org.apache.xmlbeans.impl.jam.JFactory;
  import org.apache.xmlbeans.*;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  import java.net.URI;
  
  /**
   * Base class for simplifying implementation of the Tylar interface.
   *
   * @author Patrick Calahan <pc...@bea.com>
   */
  public abstract class BaseTylarImpl implements Tylar {
  
    // ========================================================================
    // Partial default Tylar implementation
  
    public String getDescription() {
      URI uri = getLocation();
      if (uri != null) return uri.toString();
      return "["+this.getClass().getName()+"]";
    }
  
    public URI getLocation() {
      return null;
    }
  
    public BindingLoader getBindingLoader() {
      //REVIEW should consider caching this result
      BindingFile[] bfs = getBindingFiles();
      BindingLoader[] loaders = new BindingLoader[bfs.length+1];
      System.arraycopy(bfs,0,loaders,0,bfs.length);
      loaders[loaders.length-1] = BuiltinBindingLoader.getInstance();
      return PathBindingLoader.forPath(loaders);
    }
  
    public SchemaTypeSystem getSchemaTypeSystem()
    {
      // REVIEW should consider caching this result
      SchemaDocument[] xsds = getSchemas();
      XmlObject[] xxds = new XmlObject[xsds.length];
      for(int i=0; i<xsds.length; i++) xxds[i] = xsds[i].getSchema();
      try {
        return XmlBeans.compileXsd(xxds,XmlBeans.getBuiltinTypeSystem(),null);
      } catch(XmlException xe) {
        // REVIEW we need to enforce an invariant that a tylar with invalid
        // schemas can never be instantiated.
        xe.printStackTrace();
        throw new IllegalStateException(xe.getMessage());
      }
    }
  
    public JClassLoader getJClassLoader()
    {
      // REVIEW should consider caching this result
      // create a classloader chain that runs throw all of the base tylars
      ClassLoader cl = createClassLoader(ClassLoader.getSystemClassLoader());
      return JFactory.getInstance().createClassLoader(cl,null,null);
    }
  }
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/CompositeTylar.java
  
  Index: CompositeTylar.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.tylar;
  
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  
  import java.util.Collection;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Iterator;
  
  /**
   * Implementation of Tylar which is a composition of other Tylars.
   *
   * @author Patrick Calahan <pc...@bea.com>
   */
  public class CompositeTylar extends BaseTylarImpl {
  
    // ========================================================================
    // Variables
  
    private Tylar[] mTylars; //the tylars we are composing
  
    // ========================================================================
    // Constructors
  
    /**
     * Constructs a composition of the tylars in the given collection.  Bindings
     * and types will be sought in the tylars in the order in which they are
     * presented in this collection (as returned by Collection.iterator()).
     *
     * @throws IllegalArgumentException if any object in the collection is not
     * a Tylar or the collection is null.
     */
    public CompositeTylar(Collection tylars) {
      if (tylars == null) throw new IllegalArgumentException("null tylars");
      mTylars = new Tylar[tylars.size()];
      int n = 0;
      for(Iterator i = tylars.iterator(); i.hasNext(); n++) {
        Object next = i.next();
        if (next instanceof Tylar) {
          mTylars[n] = (Tylar)next;
        } else {
          throw new IllegalArgumentException("Collection contains a "+
                  next.getClass()+" which does not implement Tylar");
        }
      }
    }
  
    /**
     * Constructs a composition of the given Tylars.  Bindings and types
     * will be sought in the tylars in the order in which they are presented in
     * this array.
     */
    public CompositeTylar(Tylar[] tylars) {
      if (tylars == null) throw new IllegalArgumentException("null tylars");
      mTylars = tylars;
    }
  
    // ========================================================================
    // Tylar implementation
  
    public String getDescription() {
      return "CompositeTylar containing "+mTylars.length+" tylars";
    }
  
    public BindingFile[] getBindingFiles() {
      //REVIEW consider caching
      Collection all = new ArrayList();
      for(int i=0; i<mTylars.length; i++) {
        all.addAll(Arrays.asList(mTylars[i].getBindingFiles()));
      }
      BindingFile[] out = new BindingFile[all.size()];
      all.toArray(out);
      return out;
    }
  
    public SchemaDocument[] getSchemas() {
      //REVIEW consider caching
      Collection all = new ArrayList();
      for(int i=0; i<mTylars.length; i++) {
        all.addAll(Arrays.asList(mTylars[i].getSchemas()));
      }
      SchemaDocument[] out = new SchemaDocument[all.size()];
      all.toArray(out);
      return out;
    }
  
    public ClassLoader createClassLoader(ClassLoader cl) {
      //REVIEW consider caching
      for(int i=0; i<mTylars.length; i++) {
        cl = mTylars[i].createClassLoader(cl);
      }
      return cl;
    }
  }
  
  
  
  1.9       +21 -11    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java
  
  Index: BindingContextFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/BindingContextFactoryImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BindingContextFactoryImpl.java	12 Jan 2004 07:26:01 -0000	1.8
  +++ BindingContextFactoryImpl.java	14 Jan 2004 07:19:15 -0000	1.9
  @@ -74,6 +74,7 @@
   import org.apache.xmlbeans.impl.binding.tylar.DefaultTylarLoader;
   import org.apache.xmlbeans.impl.binding.tylar.Tylar;
   import org.apache.xmlbeans.impl.binding.tylar.TylarLoader;
  +import org.apache.xmlbeans.impl.binding.tylar.CompositeTylar;
   import org.apache.xmlbeans.impl.common.XmlWhitespace;
   
   import java.io.File;
  @@ -88,18 +89,26 @@
   public final class BindingContextFactoryImpl
       extends BindingContextFactory
   {
  +    public BindingContext createBindingContext(URI tylarUri)
  +      throws IOException, XmlException
  +    {
  +      return createBindingContext(new URI[] {tylarUri});
  +    }
  +
  +
  +
       public BindingContext createBindingContext(URI[] tylarUris)
           throws IOException, XmlException
       {
           if (tylarUris == null) throw new IllegalArgumentException("null uris");
           //FIXME loader needs to be pluggable
           TylarLoader loader = DefaultTylarLoader.getInstance();
  -        if (loader == null) throw new IllegalArgumentException("null loader");
  +        if (loader == null) throw new IllegalStateException("null loader");
           Tylar[] tylars = new Tylar[tylarUris.length];
           for (int i = 0; i < tylars.length; i++) {
               tylars[i] = loader.load(tylarUris[i]);
           }
  -        return createBindingContext(tylars);
  +        return createBindingContext(loader.load(tylarUris));
       }
   
       // REVIEW It's unfortunate that we can't expose this method to the public
  @@ -107,19 +116,20 @@
       // up the tylar and doesn't want to pay the cost of re-parsing it.
       // Of course, exposing it means we expose Tylar to the public as well,
       // and this should be done with caution.
  +    /**
  +     * @deprecated use createBindingContext(TylarLoader.load(tylars))
  +     */
       public BindingContext createBindingContext(Tylar[] tylars)
       {
  +      return createBindingContext(new CompositeTylar(tylars));
  +    }
  +
  +    public BindingContext createBindingContext(Tylar tylar) {
           // get the binding files
  -        BindingFile[] bfs = new BindingFile[tylars.length];
  -        for (int i = 0; i < tylars.length; i++) {
  -            bfs[i] = tylars[i].getBindingFile();
  -        }
  +        BindingFile[] bfs = tylar.getBindingFiles();
           // also build the loader chain - this is the binding files plus
           // the builtin loader
  -        BindingLoader[] loaders = new BindingLoader[bfs.length + 1];
  -        System.arraycopy(bfs, 0, loaders, 0, bfs.length);
  -        loaders[loaders.length - 1] = BuiltinBindingLoader.getInstance();
  -        BindingLoader loader = PathBindingLoader.forPath(loaders);
  +        BindingLoader loader = tylar.getBindingLoader();
           // finally, glue it all together
           RuntimeBindingTypeTable tbl = buildUnmarshallingTypeTable(bfs, loader);
           return new BindingContextImpl(loader, tbl);
  @@ -140,7 +150,7 @@
           return createBindingContext(doc);
       }
   
  -    public BindingContext createBindingContext(File bindingConfig)
  +    public BindingContext createBindingContextFromConfig(File bindingConfig)
           throws IOException, XmlException
       {
           BindingConfigDocument doc =
  
  
  
  1.5       +22 -3     xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContextFactory.java
  
  Index: BindingContextFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/BindingContextFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BindingContextFactory.java	17 Dec 2003 02:09:19 -0000	1.4
  +++ BindingContextFactory.java	14 Jan 2004 07:19:15 -0000	1.5
  @@ -82,6 +82,19 @@
       public abstract BindingContext createBindingContext(URI[] tylarUris)
           throws IOException, XmlException;
   
  +  /**
  +   * Creates a BindingContext from a tylar located at the given URI.
  +   * The order in which tylars appear in the array determines their precedence
  +   * for loading types.
  +   *
  +   * @param tylarUri A URIs to the tylar to be used in the BindingContext.
  +   * @return The BindingContext
  +   * @throws IOException if a problem occurs while opening or parsing the
  +   * contents of the tylars.
  +   */
  +  public abstract BindingContext createBindingContext(URI tylarUri)
  +      throws IOException, XmlException;
  +
   
       /**
        * Create a BindingContext that only knows about builtin types
  @@ -97,9 +110,12 @@
        * @return
        * @throws IOException
        * @throws XmlException
  +     *
  +     * @deprecated we are not exposing the binding file directly anymore.
  +     * use one of the uri-based methods above.
        */
  -    public abstract BindingContext createBindingContext(InputStream bindingConfig)
  -        throws IOException, XmlException;
  +//    public abstract BindingContext createBindingContext(InputStream bindingConfig)
  +//        throws IOException, XmlException;
   
       /**
        * Create a BindingContext from a binding config xml file
  @@ -108,8 +124,11 @@
        * @return
        * @throws IOException
        * @throws XmlException
  +     *
  +     * @deprecated we are not exposing the binding file directly anymore.
  +     * use one of the tylar-based methods above.
        */
  -    public abstract BindingContext createBindingContext(File bindingConfig)
  +    public abstract BindingContext createBindingContextFromConfig(File bindingConfig)
           throws IOException, XmlException;
   
   
  
  
  
  1.16      +0 -3      xml-xmlbeans/v2/test/src/drt/drtcases/BindingTests.java
  
  Index: BindingTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/BindingTests.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BindingTests.java	18 Dec 2003 01:58:59 -0000	1.15
  +++ BindingTests.java	14 Jan 2004 07:19:15 -0000	1.16
  @@ -11,8 +11,6 @@
   import junit.framework.TestSuite;
   import org.apache.xmlbeans.impl.binding.bts.*;
   import org.apache.xmlbeans.impl.binding.compile.Schema2Java;
  -import org.apache.xmlbeans.impl.binding.compile.SchemaSourceSet;
  -import org.apache.xmlbeans.impl.binding.compile.SimpleSourceSet;
   import org.apache.xmlbeans.impl.binding.compile.BindingCompilerTask;
   import org.apache.xmlbeans.impl.binding.joust.SourceJavaOutputStream;
   import org.apache.xmlbeans.impl.binding.joust.WriterFactory;
  @@ -23,7 +21,6 @@
   
   import javax.xml.namespace.QName;
   import java.io.*;
  -import java.util.Iterator;
   
   public class BindingTests extends TestCase
   {
  
  
  
  1.25      +10 -10    xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java
  
  Index: MarshalTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- MarshalTests.java	7 Jan 2004 07:29:53 -0000	1.24
  +++ MarshalTests.java	14 Jan 2004 07:19:15 -0000	1.25
  @@ -217,7 +217,7 @@
           final File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           final XmlOptions options = new XmlOptions();
           Collection errors = new LinkedList();
  @@ -263,7 +263,7 @@
           final File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           StringWriter sw = new StringWriter();
           XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
  @@ -302,7 +302,7 @@
           final File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           StringWriter sw = new StringWriter();
           XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
  @@ -344,7 +344,7 @@
           final File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
  @@ -404,7 +404,7 @@
           final File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
   
           final String javaType = "com.mytest.MyClass";
  @@ -481,7 +481,7 @@
           File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
   
           //TODO: remove hard coded values
  @@ -544,7 +544,7 @@
           File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           File doc = TestEnv.xbeanCase("marshal/doc2.xml");
   
  @@ -577,7 +577,7 @@
           File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           File doc = TestEnv.xbeanCase("marshal/doc2.xml");
   
  @@ -635,7 +635,7 @@
           File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           final File doc = TestEnv.xbeanCase("marshal/doc.xml");
           final String javaType = "com.mytest.MyClass";
  @@ -675,7 +675,7 @@
           File bcdoc = getBindingConfigDocument();
   
           BindingContext bindingContext =
  -            BindingContextFactory.newInstance().createBindingContext(bcdoc);
  +            BindingContextFactory.newInstance().createBindingContextFromConfig(bcdoc);
   
           //File doc = TestEnv.xbeanCase("marshal/doc2.xml");
           File doc = TestEnv.xbeanCase("marshal/bigdoc.xml");
  
  
  

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