xml-xmlbeans-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From david...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases BindingTests.java
Date Tue, 09 Dec 2003 17:25:16 GMT
davidbau    2003/12/09 09:25:16

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingFileResult.java ExplodedTylarBuilder.java
                        Schema2Java.java Schema2JavaTask.java
                        SchemaToJavaResult.java TylarBuilder.java
               v2/src/jam/org/apache/xmlbeans/impl/jam JFactory.java
                        JFileSet.java
               v2/test/src/drt/drtcases BindingTests.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        Both2Bind.java Both2BindTask.java
                        SimpleSourceSet.java
  Removed:     v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        SimpleJavaToSchemaResultCompiler.java
                        SimpleSchemaSourceSet.java
                        SimpleSchemaToJavaResultCompiler.java
  Log:
  Some both2bind code.
  
  CR: pcal (pending)
  DRT: passed
  
  Revision  Changes    Path
  1.2       +3 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingFileResult.java
  
  Index: BindingFileResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingFileResult.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingFileResult.java	4 Dec 2003 21:14:55 -0000	1.1
  +++ BindingFileResult.java	9 Dec 2003 17:25:16 -0000	1.2
  @@ -56,10 +56,12 @@
   
   package org.apache.xmlbeans.impl.binding.compile;
   
  +import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  +
   import java.io.IOException;
   import java.io.OutputStream;
   
   public interface BindingFileResult
   {
  -    void printBindingFile(OutputStream output) throws IOException;
  +    BindingFile getBindingFile();
   }
  
  
  
  1.6       +12 -30    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java
  
  Index: ExplodedTylarBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExplodedTylarBuilder.java	5 Dec 2003 21:48:18 -0000	1.5
  +++ ExplodedTylarBuilder.java	9 Dec 2003 17:25:16 -0000	1.6
  @@ -122,7 +122,8 @@
         throw ioe;
       } finally {
         try {
  -        out.close();
  +        if (out != null)
  +          out.close();
         } catch (IOException ohwell) {
           ohwell.printStackTrace();
         }
  @@ -143,7 +144,8 @@
           throw ioe;
         } finally {
           try {
  -          out.close();
  +          if (out != null)
  +            out.close();
           } catch (Exception ohwell) {
             ohwell.printStackTrace();
           }
  @@ -164,7 +166,8 @@
           throw e;
         } finally {
           try {
  -          out.close();
  +          if (out != null)
  +            out.close();
           } catch (Exception ohwell) {
             ohwell.printStackTrace();
           }
  @@ -190,34 +193,13 @@
       writeJavaFiles(result.getJavaCodeResult());
   
       // print the binding file
  -    writeBindingFile(result.getBindingFileResult());
  +    writeBindingFile(result.getBindingFile());
     }
   
  -  /**
  -   * @deprecated I really think it is a bad idea for SchemaToJavaResult
  -   * to have the responsibility for printing out the binding file and java
  -   * code.  It should just return handles to things that get printed out
  -   * by the tylar builder.  I have already made this change on the
  -   * java->schema side.
  -   */
  -  private void writeBindingFile(BindingFileResult bfg) throws IOException
  -  {
  -    File file = new File(mDir, "binding-file.xml"); //FIXME naming
  -    FileOutputStream out = null;
  -    try {
  -      out = new FileOutputStream(file);
  -      bfg.printBindingFile(out);
  -    }
  -    catch (IOException ioe) {
  -      throw ioe;
  -    }
  -    finally {
  -      try {
  -        out.close();
  -      }
  -      catch (IOException ohwell) {
  -        ohwell.printStackTrace();
  -      }
  +    public void buildTylar(BindingFileResult result) throws IOException {
  +      createTargetDir();
  +
  +      // print the binding file
  +      writeBindingFile(result.getBindingFile());
       }
  -  }
   }
  
  
  
  1.2       +2 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Schema2Java.java	4 Dec 2003 21:14:55 -0000	1.1
  +++ Schema2Java.java	9 Dec 2003 17:25:16 -0000	1.2
  @@ -1082,9 +1082,9 @@
       /**
        * Prints the binding file generated by this binding.
        */ 
  -    public void printBindingFile(OutputStream output) throws IOException
  +    public BindingFile getBindingFile()
       {
  -        bindingFile.write().save(output, new XmlOptions().setSavePrettyPrint());
  +        return bindingFile;
       }
   
       /**
  
  
  
  1.2       +3 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2JavaTask.java
  
  Index: Schema2JavaTask.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Schema2JavaTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Schema2JavaTask.java	4 Dec 2003 21:14:55 -0000	1.1
  +++ Schema2JavaTask.java	9 Dec 2003 17:25:16 -0000	1.2
  @@ -147,6 +147,8 @@
           checkParameters();
           
           // scan source directories and dest directory to build up
  +        startScan();
  +        
           String[] list = mSrc.list();
           for (int i = 0; i < list.length; i++) {
               File srcDir = getProject().resolveFile(list[i]);
  @@ -199,7 +201,7 @@
           // bind
           SchemaSourceSet input = null;
           try {
  -            input = SimpleSchemaSourceSet.forFileArray(xsdFiles, tylarLoader);
  +            input = SimpleSourceSet.forXsdFiles(xsdFiles, tylarLoader);
           }
           catch (IOException e) {
               log(e.getMessage());
  
  
  
  1.4       +6 -1      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SchemaToJavaResult.java
  
  Index: SchemaToJavaResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SchemaToJavaResult.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SchemaToJavaResult.java	4 Dec 2003 21:14:55 -0000	1.3
  +++ SchemaToJavaResult.java	9 Dec 2003 17:25:16 -0000	1.4
  @@ -58,6 +58,7 @@
   
   import org.apache.xmlbeans.impl.binding.compile.BindingFileResult;
   import org.apache.xmlbeans.impl.binding.compile.JavaCodeResult;
  +import org.apache.xmlbeans.impl.binding.bts.BindingFile;
   
   /**
    * The result of a Schema->Java binding.
  @@ -67,7 +68,11 @@
    */
   public interface SchemaToJavaResult
   {
  -    BindingFileResult getBindingFileResult();
  +    /**
  +     * Returns the BindingFile object that was produced by Java2Schema.  May
  +     * return null if catastrophic errors were encountered.
  +     */
  +    BindingFile getBindingFile();
       JavaCodeResult getJavaCodeResult();
       SchemaSourceSet getSchemaSourceSet();
   }
  
  
  
  1.5       +2 -0      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TylarBuilder.java
  
  Index: TylarBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TylarBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TylarBuilder.java	5 Dec 2003 21:48:18 -0000	1.4
  +++ TylarBuilder.java	9 Dec 2003 17:25:16 -0000	1.5
  @@ -78,4 +78,6 @@
     public void buildTylar(Java2SchemaResult result) throws IOException;
   
     public void buildTylar(SchemaToJavaResult result) throws IOException;
  +    
  +  public void buildTylar(BindingFileResult result) throws IOException;
   }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2Bind.java
  
  Index: Both2Bind.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.binding.bts.BindingTypeName;
  import org.apache.xmlbeans.impl.binding.bts.BindingType;
  import org.apache.xmlbeans.impl.binding.bts.JavaTypeName;
  import org.apache.xmlbeans.impl.binding.bts.QNameProperty;
  import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.impl.binding.bts.XmlTypeName;
  import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.BindingLoader;
  import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
  import org.apache.xmlbeans.impl.binding.bts.SimpleDocumentBinding;
  import org.apache.xmlbeans.SchemaProperty;
  import org.apache.xmlbeans.SchemaType;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlObject;
  
  import javax.xml.namespace.QName;
  import java.util.Collection;
  import java.util.Map;
  import java.util.LinkedHashMap;
  import java.util.LinkedList;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.HashSet;
  import java.math.BigInteger;
  import java.io.OutputStream;
  import java.io.IOException;
  
  public class Both2Bind implements BindingFileResult
  {
      public static String TYPE_MATCHER = "TYPE_MATCHER";
      
      private TypeMatcher matcher;
      private BothSourceSet bss;
      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 Collection errors = new ArrayList(); // just strings for now
      private static final XmlOptions empty_opts = new XmlOptions();
  
      public static BindingFileResult bind(BothSourceSet bss, XmlOptions opts)
      {
          if (opts == null)
              opts = empty_opts;
          Both2Bind binder = new Both2Bind(bss, opts);
          binder.bind();
          return binder;
      }
  
      private Both2Bind(BothSourceSet bss, XmlOptions opts)
      {
          matcher = buildTypeMatcher((String)opts.get(TYPE_MATCHER));
          this.bss = bss;
      }
      
      private void bind()
      {
          // Let the passed matcher propose any matches it wishes to
          
          resolveInitiallyMatchedTypes();
          
          // consider: when to generate warnings for missing matches?
          
          // Now we recurse through data structures and match up properties,
          // also adding new types to match based on position in props.
          while (moreToResolve()) {
              Scratch scratch = dequeueToResolve();
              resolveBinding(scratch);
          }
          
      }
  
  
      private static TypeMatcher buildTypeMatcher(String className)
      {
          if (className == null) {
              return new SimpleTypeMatcher();
          }
          else {
              try {
                  return (TypeMatcher)Both2Bind.class.getClassLoader().loadClass(className).newInstance();
              }
              catch (ClassNotFoundException cnfe) {
                  throw new AssertionError(cnfe);
              }
              catch (InstantiationException ie) {
                  throw new AssertionError(ie);
              }
              catch (IllegalAccessException iae) {
                  throw new AssertionError(iae);
              }
          }
      }
      
      /**
       * Scratch area corresponding to a schema type, used for the binding
       * computation.
       */ 
      private static class Scratch
      {
          Scratch(JClass jClass, JavaTypeName javaName, SchemaType schemaType, XmlTypeName xmlName, int category)
          {
              this.jClass = jClass;
              this.javaName = javaName;
              this.schemaType = schemaType;
              this.xmlName = xmlName;
              this.category = category;
              this.bindingTypeName = BindingTypeName.forPair(javaName, xmlName);
          }
          
          private BindingType bindingType;
          private SchemaType schemaType; // may be null
          private JavaTypeName javaName;
          private XmlTypeName xmlName;
          private JClass jClass;
          private BindingTypeName bindingTypeName;
          private TypeMatcher.MatchedProperties onBehalfOf;
  
          private int category;
  
          // atomic types get a treatAs
          private XmlTypeName asIf;
          private boolean isStructureResolved;
  
          // categories of Scratch, established at ctor time
          public static final int ATOMIC_TYPE = 1;
          public static final int STRUCT_TYPE = 2;
          public static final int LITERALARRAY_TYPE = 3;
          public static final int SOAPARRAY_REF = 4;
          public static final int SOAPARRAY = 5;
          public static final int ELEMENT = 6;
          public static final int ATTRIBUTE = 7;
  
          public int getCategory()
          {
              return category;
          }
  
          public JClass getJClass()
          {
              return jClass;
          }
  
          public JavaTypeName getJavaName()
          {
              return javaName;
          }
  
          public BindingTypeName getBindingTypeName()
          {
              return bindingTypeName;
          }
  
          public BindingType getBindingType()
          {
              return bindingType;
          }
  
          public void setBindingType(BindingType bindingType)
          {
              this.bindingType = bindingType;
          }
  
          public SchemaType getSchemaType()
          {
              return schemaType;
          }
  
          public XmlTypeName getXmlName()
          {
              return xmlName;
          }
  
          public XmlTypeName getAsIf()
          {
              return asIf;
          }
  
          public void setAsIf(XmlTypeName xmlName)
          {
              this.asIf = xmlName;
          }
          
          public void addQNameProperty(QNameProperty prop)
          {
              if (!(bindingType instanceof ByNameBean))
                  throw new IllegalStateException();
              ((ByNameBean)bindingType).addProperty(prop);
          }
          
          public Collection getQNameProperties()
          {
              if (!(bindingType instanceof ByNameBean))
                  throw new IllegalStateException();
              return ((ByNameBean)bindingType).getProperties();
          }
  
          public boolean isStructureResolved()
          {
              return this.isStructureResolved;
          }
          
          public void setStructureResolved(boolean isStructureResolved)
          {
              this.isStructureResolved = isStructureResolved;
          }
  
          public void setOnBehalfOf(TypeMatcher.MatchedProperties onBehalfOf)
          {
              this.onBehalfOf = onBehalfOf;
          }
  
          public TypeMatcher.MatchedProperties getOnBehalfOf()
          {
              return onBehalfOf;
          }
      }
      
      private static XmlTypeName normalizedXmlTypeName(SchemaType sType)
      {
          if (sType.isDocumentType())
              return XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, sType.getDocumentElementName());
          if (sType.isAttributeType())
              return XmlTypeName.forGlobalName(XmlTypeName.ATTRIBUTE, sType.getDocumentElementName());
          return XmlTypeName.forSchemaType(sType);
      }
      
      /**
       * Returns a schema type which is the closest base type for the given schema
       * type which is builtin and compatible with the given Java class.
       * 
       * Or returns null if no builtin base class is known to be compatible.
       */ 
      private static SchemaType computeCompatibleBuiltin(JavaTypeName javaName, SchemaType sType)
      {
          // only interesting builtins are simple
          if (!sType.isSimpleType() && sType.getContentType() != SchemaType.SIMPLE_CONTENT)
              return null;
          
          // See if the java class is actually a compatible primitive
          BindingLoader builtins = BuiltinBindingLoader.getInstance();
          
          // find the closest simple base type
          while (!sType.isSimpleType())
              sType = sType.getBaseType();
          
          // look for a base type compatible with the given primitive
          while (sType != null)
          {
              if (null != builtins.getBindingType(BindingTypeName.forPair(javaName, XmlTypeName.forSchemaType(sType))))
                  return sType;
              sType = sType.getBaseType();
          }
          
          return null;
      }
      
      /**
       * Arrays currently not automatically handled.
       */ 
      private static boolean isCompatibleArray(JClass jClass, SchemaType sType)
      {
          return false;
      }
      
      /**
       * This function goes through all relevant schema types, plus soap
       * array types, and creates a scratch area for each.  Each
       * scratch area is also marked at this time with an XmlTypeName,
       * a schema type, and a category.
       */ 
      private void resolveInitiallyMatchedTypes()
      {
          TypeMatcher.MatchedType[] matchedTypes = matcher.matchTypes(bss);
          
          for (int i = 0; i < matchedTypes.length; i++)
          {
              Scratch scratch = createScratch(matchedTypes[i].getJClass(), matchedTypes[i].getSType());
              scratchFromBindingName.put(scratch.getBindingTypeName(), scratch);
          }
          
          // Now run through and make sure we're unique in both S+J
          // and add the matches to the "unique" tables.
          for (Iterator i = scratchIterator(); i.hasNext(); )
          {
              Scratch scratch = (Scratch)i.next();
              boolean skip = false;
              
              createBindingType(scratch, true);
              
              if (!scratchFromXmlName.containsKey(scratch.getXmlName()))
                  scratchFromXmlName.put(scratch.getXmlName(), scratch);
              else
              {
                  skip = true;
                  addError(new Object[] { scratch.getJClass(),
                                          ((Scratch)scratchFromXmlName.get(scratch.getXmlName())).getJClass(),
                                          scratch.getSchemaType() },
                                          "Both " + scratch.getJavaName() + " and " + ((Scratch)scratchFromXmlName.get(scratch.getXmlName())).getJavaName() + " match Schema " + scratch.getXmlName());
              }
              
              if (!scratchFromJavaName.containsKey(scratch.getJavaName()))
                  scratchFromJavaName.put(scratch.getJavaName(), scratch);
              else
              {
                  skip = true;
                  addError(new Object[] { scratch.getSchemaType(),
                                          ((Scratch)scratchFromJavaName.get(scratch.getJavaName())).getSchemaType(),
                                          scratch.getJClass() },
                                          "Both " + scratch.getXmlName() + " and " + ((Scratch)scratchFromJavaName.get(scratch.getJavaName())).getXmlName() + " match Java " + scratch.getJavaName());
              }
              
              if (!skip)
                  queueToResolve(scratch);
          }
      }
      
      private static Scratch createScratch(JClass jClass, SchemaType sType)
      {
          XmlTypeName xmlName = normalizedXmlTypeName(sType);
          JavaTypeName javaName = JavaTypeName.forJClass(jClass);
          Scratch scratch;
              
          SchemaType simpleBuiltin = computeCompatibleBuiltin(javaName, sType);
              
          if (simpleBuiltin != null)
          {
              // simple types are atomic
              // todo: what about simple content, custom codecs, etc?
              scratch = new Scratch(jClass, javaName, sType, xmlName, Scratch.ATOMIC_TYPE);
              scratch.setAsIf(XmlTypeName.forSchemaType(simpleBuiltin));
          }
          else if (sType.isDocumentType())
          {
              scratch = new Scratch(jClass, javaName, sType, xmlName, Scratch.ELEMENT);
              scratch.setAsIf(XmlTypeName.forSchemaType(sType.getProperties()[0].getType()));
          }
          else if (sType.isAttributeType())
          {
              scratch = new Scratch(jClass, javaName, sType, xmlName, Scratch.ATTRIBUTE);
              scratch.setAsIf(XmlTypeName.forSchemaType(sType.getProperties()[0].getType()));
          }
          else if (isCompatibleArray(jClass, sType))
          {
              scratch = new Scratch(jClass, javaName, sType, xmlName, Scratch.LITERALARRAY_TYPE);
          }
          else
          {
              scratch = new Scratch(jClass, javaName, sType, xmlName, Scratch.STRUCT_TYPE);
          }
          
          return scratch;
      }
      
      
      /**
       * Computes a BindingType for a scratch.
       */ 
      private void createBindingType(Scratch scratch, boolean shouldDefault)
      {
          assert(scratch.getBindingType() == null);
          
          BindingTypeName btName = BindingTypeName.forPair(scratch.getJavaName(), scratch.getXmlName());
          
          switch (scratch.getCategory())
          {
              case Scratch.ATOMIC_TYPE:
              case Scratch.SOAPARRAY_REF:
              case Scratch.ATTRIBUTE:
                  SimpleBindingType simpleResult = new SimpleBindingType(btName);
                  simpleResult.setAsIfXmlType(scratch.getAsIf());
                  scratch.setBindingType(simpleResult);
                  bindingFile.addBindingType(simpleResult, shouldDefault, shouldDefault);
                  break;
                  
              case Scratch.ELEMENT:
                  SimpleDocumentBinding docResult = new SimpleDocumentBinding(btName);
                  docResult.setTypeOfElement(scratch.getAsIf());
                  scratch.setBindingType(docResult);
                  bindingFile.addBindingType(docResult, shouldDefault, shouldDefault);
                  break;
                  
              case Scratch.STRUCT_TYPE:
                  ByNameBean byNameResult = new ByNameBean(btName);
                  scratch.setBindingType(byNameResult);
                  bindingFile.addBindingType(byNameResult, shouldDefault, shouldDefault);
                  break;
                  
              case Scratch.LITERALARRAY_TYPE:
                  throw new UnsupportedOperationException();
                  
              case Scratch.SOAPARRAY:
                  throw new UnsupportedOperationException();
                  
              default:
                  throw new IllegalStateException("Unrecognized category");
          }
      }
      
      /**
       * Looks on both the path and in the current scratch area for
       * the binding type corresponding to the given pair.  Must
       * be called after all the binding types have been created.
       */ 
      private BindingType bindingTypeForMatchedTypes(JClass jClass, SchemaType sType, TypeMatcher.MatchedProperties onBehalfOf)
      {
          // note that jClass may differ from property type because of arrays
          BindingTypeName btName = BindingTypeName.forTypes(jClass, sType); 
          
          // First look in locally compiled bindings
          Scratch scratch = (Scratch)scratchFromBindingName.get(btName);
          if (scratch != null)
              return scratch.getBindingType();
          
          // Then look on path
          BindingType result = bss.getTylarLoader().getBindingLoader().getBindingType(btName);
          if (result != null)
              return result;
          
          // Not found?  Then allocate and queue for processing
          scratch = createScratch(jClass, sType);
          scratch.setOnBehalfOf(onBehalfOf);
          createBindingType(scratch, false);
          queueToResolve(scratch);
          
          return scratch.getBindingType();
      }
      
      private void queueToResolve(Scratch scratch)
      {
          resolveQueue.add(scratch);
      }
      
      private boolean moreToResolve()
      {
          return !resolveQueue.isEmpty();
      }
      
      private Scratch dequeueToResolve()
      {
          return (Scratch)resolveQueue.removeFirst();
      }
  
  
      /**
       * Returns an iterator for all the Scratch's
       */ 
      private Iterator scratchIterator()
      {
          return scratchFromBindingName.values().iterator();
      }
      
      
      private void resolveBinding(Scratch scratch)
      {
          switch (scratch.getCategory())
          {
              case Scratch.ATOMIC_TYPE:
                  return; // nothing to do that's not already done
                  
              case Scratch.ELEMENT:
                  // must ensure that the element's type is bound to the underlying JClass
                  bindingTypeForMatchedTypes(scratch.getJClass(), scratch.getSchemaType().getProperties()[0].getType(), null);
                  return;
                  
              case Scratch.STRUCT_TYPE:
                  resolveStructure(scratch);
                  return;
                  
              case Scratch.LITERALARRAY_TYPE:
              default:
                  return;
          }                    
      }
      
      private static class SchemaPropertyName
      {
          QName qName;
          boolean isAttribute;
          
          public static SchemaPropertyName forProperty(SchemaProperty sProp)
          {
              return new SchemaPropertyName(sProp.getName(), sProp.isAttribute());
          }
  
          private SchemaPropertyName(QName qName, boolean attribute)
          {
              this.qName = qName;
              isAttribute = attribute;
          }
  
          public QName getQName()
          {
              return qName;
          }
  
          public boolean isAttribute()
          {
              return isAttribute;
          }
  
          public boolean equals(Object o)
          {
              if (this == o) return true;
              if (!(o instanceof SchemaPropertyName)) return false;
  
              final SchemaPropertyName schemaPropertyName = (SchemaPropertyName) o;
  
              if (isAttribute != schemaPropertyName.isAttribute) return false;
              if (!qName.equals(schemaPropertyName.qName)) return false;
  
              return true;
          }
  
          public int hashCode()
          {
              int result;
              result = qName.hashCode();
              result = 29 * result + (isAttribute ? 1 : 0);
              return result;
          }
      }
      
      /**
       * Returns the set of elements and attributes which have a
       * minimum occurance greater than zero.  (In other words,
       * binding to them is not optional if you ever want to
       * serialize your XML out.)  The result Set contains
       * SchemaPropertyNames.
       */ 
      private static Set computeRequiredProperties(SchemaType sType)
      {
          Set result = new HashSet();
          
          SchemaProperty[] sProps = sType.getProperties();
          for (int i = 0; i < sProps.length; i++)
          {
              if (sProps[i].getMinOccurs().signum() > 0)
                  result.add(SchemaPropertyName.forProperty(sProps[i]));
          }
          
          return result;
      }
      
      private void resolveStructure(Scratch scratch)
      {
          Object[] context;
          if (scratch.getOnBehalfOf() == null)
              context = new Object[] { scratch.getJClass(), scratch.getSchemaType() };
          else
              context = new Object[] { scratch.getOnBehalfOf().getJProperty(), scratch.getOnBehalfOf().getSProperty() };
          
          if (scratch.getSchemaType().isSimpleType() || scratch.getSchemaType() == XmlObject.type)
          {
              addError(context, "Java class " + scratch.getJavaName() + " does not match Schema type " + scratch.getXmlName());
              return;
          }
          
          // todo: check inheritance validity (inheritance in java + xml should match up)
  
          // todo: when looking at java + schema properties, be aware of inheritance issues
  
          // now, match up the names
          TypeMatcher.MatchedProperties[] matchedProperties =
                  matcher.matchProperties(scratch.getJClass(), scratch.getSchemaType());
          
          // The only requirements:
          // (1) every required schema attribute or element must be accounted for
          // (2) cardinality must match
          
          Set requiredProperties = computeRequiredProperties(scratch.getSchemaType());
          
          for (int i = 0; i < matchedProperties.length; i++)
          {
              SchemaProperty sProp = matchedProperties[i].getSProperty();
              JProperty jProp = matchedProperties[i].getJProperty();
              
              // first, remove a matched schema property name when seen
              requiredProperties.remove(SchemaPropertyName.forProperty(sProp));
              
              // Extract property types to recurse on
              JClass jPropType = jProp.getType();
              SchemaType sPropType = sProp.getType();
              
              // Check cardinality, skip into type
              boolean multiple = isMultiple(sProp);
              JavaTypeName collection = null;
              if (multiple)
              {
                  if (!jPropType.isArray())
                      addError(new Object[] { jProp, sProp }, "Property " + jProp + " in " + scratch.getJClass() + " is an array, but " + sProp.getName() + " in " + scratch.getSchemaType() + " is a singleton.");
                  else
                  {
                      collection = JavaTypeName.forJClass(jPropType);
                      jPropType = jPropType.getArrayComponentType();
                  }
              }
              
              // Queues the binding type for this property for processing if needed
              BindingType bType = bindingTypeForMatchedTypes(jPropType, sPropType, matchedProperties[i]);
                  
              QNameProperty prop = new QNameProperty();
              prop.setQName(sProp.getName());
              prop.setAttribute(sProp.isAttribute());
              prop.setSetterName(jProp.getSetter().getSimpleName());
              prop.setGetterName(jProp.getGetter().getSimpleName());
              prop.setCollectionClass(collection);
              prop.setBindingType(bType);
              prop.setNillable(sProp.hasNillable() != SchemaProperty.NEVER);
              prop.setOptional(isOptional(sProp));
              prop.setMultiple(multiple);
              
              scratch.addQNameProperty(prop);
          }
          
          if (!requiredProperties.isEmpty())
          {
              int missing = requiredProperties.size();
              String reason;
              if (missing > 1)
                  reason = "No match for " + missing + " schema element or attribute names.";
              else
              {
                  SchemaPropertyName spName = (SchemaPropertyName)requiredProperties.iterator().next();
                  if (spName.isAttribute())
                      reason = "No match for required attribute " + spName.getQName().getLocalPart();
                  else
                      reason = "No match for required element " + spName.getQName().getLocalPart();
              }
              
              addError(context, "Java class " + scratch.getJavaName() + " does not match schema type " + scratch.getXmlName() + " (" + reason + ")");
          }
      }
  
      private static boolean isMultiple(SchemaProperty sProp)
      {
          BigInteger max = sProp.getMaxOccurs();
          if (max == null) return true;
          return (max.compareTo(BigInteger.ONE) > 0);
      }
  
      private static boolean isOptional(SchemaProperty sProp)
      {
          BigInteger min = sProp.getMinOccurs();
          return (min.signum() == 0);
      }
  
      
      private void addError(Object[] context, String message)
      {
          for (int i = 0; i < context.length; i++)
          {
              Object obj = context[i];
              assert(obj instanceof JClass || obj instanceof SchemaType || obj instanceof SchemaProperty || obj instanceof JProperty);
          }
          
          System.out.println(message);
          errors.add(message);
      }
      
      /**
       * Prints the binding file generated by this binding.
       */ 
      public BindingFile getBindingFile()
      {
          return bindingFile;
      }
  
      
  }
  
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Both2BindTask.java
  
  Index: Both2BindTask.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.tools.ant.taskdefs.MatchingTask;
  import org.apache.tools.ant.types.Path;
  import org.apache.tools.ant.types.Reference;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.xmlbeans.XmlException;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.List;
  import java.util.ArrayList;
  
  public class Both2BindTask extends MatchingTask
  {
  
      // =========================================================================
      // Variables
  
      private File mDestDir = null;
      private Path mSrc = null;
      private Path mClasspath = null;
      private List mXsdFiles = null;
      private List mJavaFiles = null;
  
      // =========================================================================
      // Task attributes
  
      public void setDestDir(File dir)
      {
          mDestDir = dir;
      }
  
      /**
       * Set the source directories to find the source XSD files.
       */
      public void setSrcdir(Path srcDir)
      {
          if (mSrc == null) {
              mSrc = srcDir;
          }
          else {
              mSrc.append(srcDir);
          }
      }
  
      /**
       * Adds a path for source compilation.
       *
       * @return a nested src element.
       */
      public Path createSrc() {
          if (mSrc == null) {
              mSrc = new Path(getProject());
          }
          return mSrc.createPath();
      }
  
  
      public void setClasspath(Path path)
      {
          if (mClasspath == null) {
              mClasspath = path;
          }
          else {
              mClasspath.append(path);
          }
      }
  
      public void setClasspathRef(Reference r)
      {
          createClasspath().setRefid(r);
      }
  
      public Path createClasspath()
      {
          if (mClasspath == null) {
              mClasspath = new Path(getProject());
          }
          return mClasspath.createPath();
      }
  
      // =========================================================================
      // Task implementation
  
      /**
       * Execute the task.
       */
      public void execute() throws BuildException
      {
          checkParameters();
          
          // scan source directories and dest directory to build up
          startScan();
          String[] list = mSrc.list();
          for (int i = 0; i < list.length; i++) {
              File srcDir = getProject().resolveFile(list[i]);
              if (!srcDir.exists()) {
                  throw new BuildException("srcdir \""
                                           + srcDir.getPath()
                                           + "\" does not exist!", getLocation());
              }
  
              DirectoryScanner ds = this.getDirectoryScanner(srcDir);
              String[] files = ds.getIncludedFiles();
  
              scanDir(srcDir, files);
          }
  
          compile();
      }
      
      protected void startScan()
      {
          mXsdFiles = new ArrayList();
          mJavaFiles = new ArrayList();
      }
      
      protected void scanDir(File srcDir, String[] files) {
          for (int i = 0; i < files.length; i++)
          {
              if (files[i].endsWith(".xsd"))
                  mXsdFiles.add(new File(srcDir, files[i]));
              if (files[i].endsWith(".java"))
                  mJavaFiles.add(new File(srcDir, files[i]));
          }
      }
      
      protected File[] namesToFiles(String[] names)
      {
          File[] result = new File[names.length];
          for (int i = 0; i < names.length; i++)
              result[i] = new File(names[i]);
          return result;
      }
  
      protected void compile() throws BuildException
      {
          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 {
              input = SimpleSourceSet.forJavaAndXsdFiles(javaFiles, xsdFiles, tylarLoader);
          }
          catch (IOException e) {
              log(e.getMessage());
              throw new BuildException(e);
          }
          catch (XmlException e) {
              log(e.getMessage());
              throw new BuildException(e);
          }
          
          TylarBuilder tb = new ExplodedTylarBuilder(mDestDir);
          BindingFileResult result = Both2Bind.bind(input, null);
  
          try {
              tb.buildTylar(result);
          }
          catch (IOException ioe) {
              ioe.printStackTrace();
              throw new BuildException(ioe);
          }
          log("Both2Bind complete, output in " + mDestDir);
      }
  
      // =========================================================================
      // Private methods
  
      protected void checkParameters() throws BuildException {
          if (mSrc == null) {
              throw new BuildException("srcdir attribute must be set!",
                                       getLocation());
          }
          if (mSrc.size() == 0) {
              throw new BuildException("srcdir attribute must be set!",
                                       getLocation());
          }
  
          if (mDestDir != null && !mDestDir.isDirectory()) {
              throw new BuildException("destination directory \""
                                       + mDestDir
                                       + "\" does not exist "
                                       + "or is not a directory", getLocation());
          }
      }
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SimpleSourceSet.java
  
  Index: SimpleSourceSet.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.JFactory;
  import org.apache.xmlbeans.impl.jam.JFileSet;
  import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
  import org.apache.xmlbeans.SchemaTypeSystem;
  import org.apache.xmlbeans.SchemaTypeLoader;
  import org.apache.xmlbeans.XmlBeans;
  import org.apache.xmlbeans.XmlException;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlObject;
  import org.w3.x2001.xmlSchema.SchemaDocument;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.ByteArrayOutputStream;
  import java.io.ByteArrayInputStream;
  import java.util.Collection;
  import java.util.ArrayList;
  
  public class SimpleSourceSet implements BothSourceSet
  {
      private JClass[] classes;
      private SchemaTypeSystem sts;
      private TylarLoader tylarLoader;
  
      private SimpleSourceSet(JClass[] classes, SchemaTypeSystem sts, TylarLoader tylarLoader)
      {
          this.classes = classes;
          this.sts = sts;
          this.tylarLoader = tylarLoader;
      }
  
      public JClass[] getJClasses()
      {
          return classes;
      }
  
      public TylarLoader getTylarLoader()
      {
          return tylarLoader;
      }
  
      public void compileJavaToBinaries(File classesDir)
      {
          throw new UnsupportedOperationException();
      }
  
      public SchemaTypeSystem getSchemaTypeSystem()
      {
          return sts;
      }
  
      public void compileSchemaToBinaries(File classesDir)
      {
          SchemaTypeSystemImpl impl = (SchemaTypeSystemImpl)sts;
          impl.saveToDirectory(classesDir);
      }
  
      private static class SimpleJFileSet implements JFileSet
      {
          private File[] javaFiles;
  
          SimpleJFileSet(File[] javaFiles)
          {
              this.javaFiles = javaFiles;
          }
  
          public void include(String pattern)
          {
              throw new UnsupportedOperationException();
          }
  
          public void exclude(String pattern)
          {
              throw new UnsupportedOperationException();
          }
  
          public void setClasspath(String cp)
          {
              throw new UnsupportedOperationException();
          }
  
          public void setCaseSensitive(boolean b)
          {
              throw new UnsupportedOperationException();
          }
  
          public File[] getFiles() throws IOException
          {
              return javaFiles;
          }
      }
      
      private static SchemaTypeLoader schemaLoader = XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
      
      private static SchemaDocument parseSchemaFile(File file) throws IOException, XmlException
      {
          XmlOptions options = new XmlOptions();
          options.setLoadLineNumbers();
          options.setLoadMessageDigest();
          return (SchemaDocument)schemaLoader.parse(file, SchemaDocument.type, options);
      }
      
      private static TylarLoader defaultTylarLoader(TylarLoader supplied)
      {
          if (supplied != null)
              return supplied;
          return SimpleTylarLoader.forBuiltins();
      }
      
      public static BothSourceSet forJavaAndXsdFiles(File[] javaFiles, File[] xsdFiles, TylarLoader tylarLoader) throws IOException, XmlException
      {
          tylarLoader = defaultTylarLoader(tylarLoader);
          JClass[] classes = null;
          SchemaTypeSystem sts = null;
          
          if (javaFiles != null)
          {
              JFactory factory = JFactory.getInstance();
              classes = factory.loadSources(new SimpleSourceSet.SimpleJFileSet(javaFiles),
                      tylarLoader.getJClassLoader(), null, null);
          }
          
          if (xsdFiles != null)
          {
              XmlObject[] parsedSchemas = new XmlObject[xsdFiles.length];
              for (int i = 0; i < xsdFiles.length; i++)
                  parsedSchemas[i] = parseSchemaFile(xsdFiles[i]);
              sts = XmlBeans.compileXsd(parsedSchemas, tylarLoader.getSchemaTypeLoader(), null);
          }
          return new SimpleSourceSet(classes, sts, tylarLoader);
      }
      
      public static JavaSourceSet forJavaFiles(File[] javaFiles, TylarLoader tylarLoader) throws IOException 
      {
          try
          {
              return forJavaAndXsdFiles(javaFiles, null, tylarLoader);
          }
          catch (XmlException e)
          {
              throw new IllegalStateException();
          }
      }
      
      public static SchemaSourceSet forXsdFile(File xsdFilename, TylarLoader tylarLoader) throws IOException, XmlException
      {
          return forJavaAndXsdFiles(null, new File[] { xsdFilename }, tylarLoader);
      }
      
      public static SchemaSourceSet forXsdFiles(File[] xsdFiles, TylarLoader tylarLoader) throws IOException, XmlException
      {
          return forJavaAndXsdFiles(null, xsdFiles, tylarLoader);
      }
          
      public static SchemaSourceSet forSchemaGenerator(SchemaCodeResult generator, TylarLoader tylarLoader)
      {
          try
          {
              String[] namespaces = generator.getTargetNamespaces();
              Collection schemas = new ArrayList();
              for (int i = 0; i < namespaces.length; i++)
              {
                  ByteArrayOutputStream inMemoryBuffer = new ByteArrayOutputStream();
                  generator.printSchema(namespaces[i], inMemoryBuffer);
                  inMemoryBuffer.close();
                  ByteArrayInputStream input = new ByteArrayInputStream(inMemoryBuffer.toByteArray());
                  schemas.add(SchemaDocument.Factory.parse(input));
              }
              XmlObject [] sources = (XmlObject[])schemas.toArray(new XmlObject[schemas.size()]);
              SchemaTypeSystem sts = XmlBeans.compileXsd(sources, tylarLoader.getSchemaTypeLoader(), null);
              return new SimpleSourceSet(null, sts, tylarLoader);
          }
          catch (IOException e)
          {
              throw new RuntimeException(e);
          }
          catch (XmlException e)
          {
              throw (IllegalStateException)new IllegalStateException().initCause(e);
          }
      }
      
  }
  
  
  
  1.4       +2 -0      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java
  
  Index: JFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JFactory.java	3 Dec 2003 22:46:15 -0000	1.3
  +++ JFactory.java	9 Dec 2003 17:25:16 -0000	1.4
  @@ -272,6 +272,7 @@
     /**
      * main method is provided for debugging.
      */
  +  /*
     public static void main(String[] args) throws Exception {
       if (args.length == 0) {
         System.out.println("Usage:\n java org.apache.xmlbeans.impl.jam.JFactory "+
  @@ -291,4 +292,5 @@
       }
       System.out.flush();
     }
  +  */
   }
  
  
  
  1.3       +4 -1      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFileSet.java
  
  Index: JFileSet.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/JFileSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JFileSet.java	20 Oct 2003 19:07:34 -0000	1.2
  +++ JFileSet.java	9 Dec 2003 17:25:16 -0000	1.3
  @@ -69,7 +69,8 @@
   
     // ========================================================================
     // Public methods
  -
  +  
  +  
     public void include(String pattern);
   
     public void exclude(String pattern);
  @@ -78,6 +79,8 @@
   
     public void setCaseSensitive(boolean b);
   
  +  // REVIEW: why can't JFileSet just be the following method and none of the
  +  // others? (davidbau)
     public File[] getFiles() throws IOException;
   
     //  public boolean setFollowSymlinks(boolean b);
  
  
  
  1.11      +7 -8      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BindingTests.java	4 Dec 2003 21:14:56 -0000	1.10
  +++ BindingTests.java	9 Dec 2003 17:25:16 -0000	1.11
  @@ -24,8 +24,7 @@
   import org.apache.xmlbeans.impl.binding.compile.SchemaToJavaResult;
   import org.apache.xmlbeans.impl.binding.compile.JavaCodeResult;
   import org.apache.xmlbeans.impl.binding.compile.SchemaSourceSet;
  -import org.apache.xmlbeans.impl.binding.compile.SimpleSchemaSourceSet;
  -import org.apache.xmlbeans.impl.binding.compile.SimpleSchemaToJavaResultCompiler;
  +import org.apache.xmlbeans.impl.binding.compile.SimpleSourceSet;
   import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
   
   import javax.xml.namespace.QName;
  @@ -43,11 +42,11 @@
       {
           // bind
           File typesonlyfile = TestEnv.xbeanCase("schema/typesonly/typesonly.xsd");
  -        SchemaSourceSet input = SimpleSchemaSourceSet.forFile(typesonlyfile, null);
  +        SchemaSourceSet input = SimpleSourceSet.forXsdFile(typesonlyfile, null);
           SchemaToJavaResult result = Schema2Java.bind(input);
           if (verbose)
           {
  -            result.getBindingFileResult().printBindingFile(System.out);
  +            result.getBindingFile().write().save(System.out);
               JavaCodeResult javacode = result.getJavaCodeResult();
               for (Iterator i = javacode.getToplevelClasses().iterator(); i.hasNext(); )
               {
  @@ -59,11 +58,11 @@
                   System.out.flush();
               }
           }
  -        
  +
           // now compile
  -        SimpleSchemaToJavaResultCompiler.Params params = new SimpleSchemaToJavaResultCompiler.Params();
  -        File theJar = TestEnv.xbeanOutput("schema/binding/typesonly.jar");
  -        params.setOutputJar(theJar);
  +        // SimpleSchemaToJavaResultCompiler.Params params = new SimpleSchemaToJavaResultCompiler.Params();
  +        // File theJar = TestEnv.xbeanOutput("schema/binding/typesonly.jar");
  +        // params.setOutputJar(theJar);
           // to test later
           //SimpleSchemaToJavaResultCompiler.compile(result, params);
       }
  
  
  

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


Mime
View raw message