xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases BindingTests.java
Date Thu, 08 Apr 2004 20:01:01 GMT
pcal        2004/04/08 13:01:01

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        BindingCompiler.java BindingCompilerTask.java
                        Both2Bind.java Both2BindTask.java Java2Schema.java
                        Java2SchemaTask.java Schema2Java.java
                        Schema2JavaTask.java
               v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
                        ExplodedTylarImpl.java
               v2/test/src/drt/drtcases BindingTests.java
  Log:
  J2S/S2J/B2B: ensure schema inclusion in tylars
  
  Revision  Changes    Path
  1.18      +43 -1     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BindingCompiler.java	7 Apr 2004 04:18:09 -0000	1.17
  +++ BindingCompiler.java	8 Apr 2004 20:01:00 -0000	1.18
  @@ -23,9 +23,12 @@
   import org.apache.xmlbeans.impl.jam.JamClassLoader;
   import org.apache.xmlbeans.impl.jam.JamServiceFactory;
   import org.apache.xmlbeans.*;
  +import org.w3.x2001.xmlSchema.SchemaDocument;
   
   import java.io.File;
   import java.io.IOException;
  +import java.util.List;
  +import java.util.ArrayList;
   
   /**
    * Abstract base class for classes which produce a tylar based on
  @@ -53,6 +56,7 @@
     private Tylar mBaseTylar = null;
     private boolean mIsCompilationStarted = false;
     private BindingLoader mBuiltinBindingLoader = null;
  +  private List mSchemasToInclude = null;
   
     // ========================================================================
     // Constructors
  @@ -86,14 +90,27 @@
     // Public methods
   
     /**
  -   * Public method for beginning the binding compilation process with
  +   * <p>Public method for beginning the binding compilation process with
      * an arbitrary TylarWriter.  Delegates to the subclass to do the real work.
  +   * After delegating to internalBind(), this method will finish by writing
  +   * out any schemas which were specified for inclusion.</p>
  +   *
      * Note: the caller of this method is responsible for calling close() on
      * the TylarWriter!
      */
     public final void bind(TylarWriter writer) {
       mIsCompilationStarted = true;
       internalBind(writer);
  +    if (mSchemasToInclude != null) {
  +      for(int i=0; i<mSchemasToInclude.size(); i++) {
  +        SchemaToInclude sti = (SchemaToInclude)mSchemasToInclude.get(i);
  +        try {
  +          writer.writeSchema(sti.schema,sti.filepath);
  +        } catch(IOException ioe) {
  +          logError(ioe);
  +        }
  +      }
  +    }
     }
   
     /**
  @@ -162,6 +179,20 @@
       mBaseTylar = lib;
     }
   
  +  /**
  +   * Specifies a schema to be included in the output tylar.  This will
  +   * have no effect on the binding process.
  +   *
  +   * @param xsd
  +   * @param filepath
  +   */
  +  public void includeSchema(SchemaDocument xsd, String filepath) {
  +    if (xsd == null) throw new IllegalArgumentException("null xsd");
  +    if (filepath == null) throw new IllegalArgumentException("null filepath");
  +    if (mSchemasToInclude == null) mSchemasToInclude = new ArrayList();
  +    mSchemasToInclude.add(new SchemaToInclude(xsd,filepath));
  +  }
  +
   
     // ========================================================================
     // BindingLogger overrides
  @@ -297,5 +328,16 @@
       File out = new File(directory, prefix);
       if (!out.mkdirs()) throw new IOException("Uknown problem creating temp file");
       return out;
  +  }
  +
  +
  +  private class SchemaToInclude {
  +    SchemaToInclude(SchemaDocument sd, String fp) {
  +      schema = sd;
  +      filepath = fp;
  +
  +    }
  +    SchemaDocument schema;
  +    String filepath;
     }
   }
  
  
  
  1.11      +28 -26    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BindingCompilerTask.java	7 Apr 2004 23:20:02 -0000	1.10
  +++ BindingCompilerTask.java	8 Apr 2004 20:01:00 -0000	1.11
  @@ -16,20 +16,15 @@
   package org.apache.xmlbeans.impl.binding.compile;
   
   import org.apache.tools.ant.BuildException;
  -import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.taskdefs.MatchingTask;
   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.JClass;
  -import org.apache.xmlbeans.impl.jam.JamServiceFactory;
  -import org.apache.xmlbeans.impl.jam.JamServiceParams;
  -import org.apache.xmlbeans.SchemaTypeSystem;
  +import org.apache.xmlbeans.impl.binding.logger.MessageSink;
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.SchemaTypeLoader;
  +import org.apache.xmlbeans.SchemaTypeSystem;
   import org.w3.x2001.xmlSchema.SchemaDocument;
   import java.io.File;
   import java.io.IOException;
  @@ -134,20 +129,25 @@
     // ========================================================================
     // Protected methods
   
  -  /**
  -   * Utility method for creating a SchemaTypeSystem from a set of
  -   * xsd files.
  -   */
  -  public static SchemaTypeSystem createSchemaTypeSystem(File[] xsdFiles)
  -          throws IOException, XmlException
  +  protected static SchemaDocument parseSchemaFile(File file)
  +    throws IOException, XmlException
  +  {
  +    XmlOptions options = new XmlOptions();
  +    options.setLoadLineNumbers();
  +    options.setLoadMessageDigest();
  +    return (SchemaDocument)SCHEMA_LOADER.parse
  +      (file, SchemaDocument.type, options);
  +  }
  +
  +  protected static SchemaTypeSystem createSchemaTypeSystem(SchemaDocument[] xsds)
  +    throws IOException, XmlException
     {
  -    XmlObject[] xsds = new XmlObject[xsdFiles.length];
  -    for (int i = 0; i < xsdFiles.length; i++) {
  -        xsds[i] = parseSchemaFile(xsdFiles[i]);
  -    }
       SchemaTypeLoader soapencLoader = org.apache.xmlbeans.impl.schema.SoapEncSchemaTypeSystem.get();
       SchemaTypeLoader xsdLoader = XmlBeans.getBuiltinTypeSystem();
  -    return XmlBeans.compileXsd(xsds, XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] {xsdLoader,
soapencLoader}), null);
  +    return XmlBeans.compileXsd(xsds,
  +                               XmlBeans.typeLoaderUnion
  +                               (new SchemaTypeLoader[] {xsdLoader, soapencLoader}),
  +                               null);
     }
   
   
  @@ -155,17 +155,19 @@
     // ========================================================================
     // Private methods
   
  -  private static SchemaDocument parseSchemaFile(File file)
  -          throws IOException, XmlException
  +  //this is here only because BindingTest uses it-that is stupid, tests
  +  //should not rely on our internals.  need to refactor it
  +  public static SchemaTypeSystem createSchemaTypeSystem(File[] xsds)
  +    throws IOException, XmlException
     {
  -      XmlOptions options = new XmlOptions();
  -      options.setLoadLineNumbers();
  -      options.setLoadMessageDigest();
  -      return (SchemaDocument)SCHEMA_LOADER.parse
  -              (file, SchemaDocument.type, options);
  +    SchemaDocument[] sd = new SchemaDocument[xsds.length];
  +    for(int i=0; i<xsds.length; i++) {
  +      sd[i] = parseSchemaFile(xsds[i]);
  +    }
  +    return createSchemaTypeSystem(sd);
     }
   
  -  private  MessageSink createMessageSink() {
  +  private MessageSink createMessageSink() {
       //FIXME this should be an AntBindingLogger
       return new SimpleMessageSink();
     }
  
  
  
  1.12      +2 -0      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Both2Bind.java	7 Apr 2004 23:20:02 -0000	1.11
  +++ Both2Bind.java	8 Apr 2004 20:01:01 -0000	1.12
  @@ -67,6 +67,7 @@
       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.
  @@ -83,6 +84,7 @@
       bind();
       try {
         tw.writeBindingFile(bindingFile);
  +      tw.writeSchemaTypeSystem(mSchemaTypes);
       } catch (IOException ioe) {
         logError(ioe);
       }
  
  
  
  1.9       +7 -1      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Both2BindTask.java	7 Apr 2004 23:20:02 -0000	1.8
  +++ Both2BindTask.java	8 Apr 2004 20:01:01 -0000	1.9
  @@ -24,6 +24,7 @@
   import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.impl.jam.JamServiceFactory;
   import org.apache.xmlbeans.impl.jam.JamServiceParams;
  +import org.w3.x2001.xmlSchema.SchemaDocument;
   
   import java.io.File;
   import java.io.IOException;
  @@ -93,7 +94,12 @@
       try {
         //FIXME when we allow them to set up a base tylar, we need to take
         //those loaders into account here
  -      mCompiler.setSchemaTypesToMatch(createSchemaTypeSystem(xsdFiles));
  +      SchemaDocument[] xsds = new SchemaDocument[xsdFiles.length];
  +      for(int i=0; i<xsds.length; i++) {
  +        xsds[i] = parseSchemaFile(xsdFiles[i]);
  +        mCompiler.includeSchema(xsds[i],xsdFiles[i].getName());//REVIEW is just the name
ok?  what about conflicts?
  +      }
  +      mCompiler.setSchemaTypesToMatch(createSchemaTypeSystem(xsds));
         mCompiler.setJavaTypesToMatch(loadJClasses(javaFiles));
       } catch (IOException e) {
         log(e.getMessage());
  
  
  
  1.48      +5 -10     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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- Java2Schema.java	7 Apr 2004 06:01:53 -0000	1.47
  +++ Java2Schema.java	8 Apr 2004 20:01:01 -0000	1.48
  @@ -18,7 +18,6 @@
   import org.apache.xmlbeans.impl.binding.bts.*;
   import org.apache.xmlbeans.impl.binding.tylar.TylarWriter;
   import org.apache.xmlbeans.impl.jam.*;
  -import org.apache.xmlbeans.impl.jam.visitor.MVisitor;
   import org.apache.xmlbeans.impl.common.XMLChar;
   import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.SchemaTypeSystem;
  @@ -121,8 +120,8 @@
       //
       try {
         writer.writeBindingFile(mBindingFile);
  +      //REVIEW maybe we should just include the schema and let super class write it out?
         writer.writeSchema(mSchemaDocument,"schema-0.xsd");
  -
       } catch(IOException ioe) {
         logError(ioe);
       }
  @@ -130,16 +129,12 @@
         SchemaTypeSystem sts = XmlBeans.compileXsd
           (new XmlObject[] {mSchemaDocument},XmlBeans.getBuiltinTypeSystem(),null);
         writer.writeSchemaTypeSystem(sts);
  -    } catch(Exception e) {
  -      System.out.println("[XBEANS] Java2Schema encoutnered a problem trying to write out
xsbs.  Ignoring for now: ");
  -      e.printStackTrace(System.out);
  -    }
  -/*    } catch(XmlException xe) {
  -      logError(xe);
       } catch(IOException ioe) {
  -      logError(ioe);
  +      //logError(ioe); ignore for now
  +    } catch(XmlException xe) {
  +      //logError(xe);  ignore for now
       }
  -*/
  +
     }
   
     // ========================================================================
  
  
  
  1.22      +0 -1      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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Java2SchemaTask.java	26 Mar 2004 19:40:25 -0000	1.21
  +++ Java2SchemaTask.java	8 Apr 2004 20:01:01 -0000	1.22
  @@ -21,7 +21,6 @@
   import org.apache.xmlbeans.impl.jam.JamServiceFactory;
   import org.apache.xmlbeans.impl.jam.JamServiceParams;
   import org.apache.xmlbeans.impl.jam.JamService;
  -import org.apache.xmlbeans.impl.jam.internal.DirectoryScanner;
   
   import java.io.File;
   import java.io.IOException;
  
  
  
  1.23      +1 -0      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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Schema2Java.java	7 Apr 2004 06:01:53 -0000	1.22
  +++ Schema2Java.java	8 Apr 2004 20:01:01 -0000	1.23
  @@ -192,6 +192,7 @@
       bind();
       try {
         writer.writeBindingFile(bindingFile);
  +      writer.writeSchemaTypeSystem(sts);
       } catch (IOException ioe) {
         if (!logError(ioe)) return;
       }
  
  
  
  1.10      +7 -3      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Schema2JavaTask.java	13 Mar 2004 00:33:22 -0000	1.9
  +++ Schema2JavaTask.java	8 Apr 2004 20:01:01 -0000	1.10
  @@ -22,6 +22,7 @@
   import org.apache.tools.ant.types.Reference;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.SchemaTypeSystem;
  +import org.w3.x2001.xmlSchema.SchemaDocument;
   
   import java.io.File;
   import java.io.IOException;
  @@ -163,15 +164,18 @@
       //build up a schema type system from the input schemas and give it to
       //the compiler
       File[] xsdFiles = (File[]) mXsdFiles.toArray(new File[mXsdFiles.size()]);
  -    SchemaTypeSystem sts;
  +    SchemaDocument[] xsds = new SchemaDocument[xsdFiles.length];
       try {
  -      sts = createSchemaTypeSystem(xsdFiles);
  +      for(int i=0; i<xsds.length; i++) {
  +        xsds[i] = parseSchemaFile(xsdFiles[i]);
  +        mCompiler.includeSchema(xsds[i],xsdFiles[i].getName());//REVIEW is just the name
ok?  what about conflicts?
  +      }
  +      mCompiler.setSchemaTypeSystem(createSchemaTypeSystem(xsds));
       } catch(IOException ioe) {
         throw new BuildException(ioe);
       } catch(XmlException xe) {
         throw new BuildException(xe);
       }
  -    mCompiler.setSchemaTypeSystem(sts);
       return mCompiler;
     }
   
  
  
  
  1.12      +7 -1      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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ExplodedTylarImpl.java	7 Apr 2004 04:18:10 -0000	1.11
  +++ ExplodedTylarImpl.java	8 Apr 2004 20:01:01 -0000	1.12
  @@ -173,7 +173,13 @@
     public void writeSchemaTypeSystem(SchemaTypeSystem sts) throws IOException {
       if (sts == null) throw new IllegalArgumentException("null sts");
       mSchemaTypeSystem = sts;
  -    sts.saveToDirectory(new File(mRootDir, STS_DIR));
  +    try {
  +      sts.saveToDirectory(new File(mRootDir, STS_DIR));
  +    } catch(Exception e) {
  +      System.out.println("[XBEANS] HAS A PROBLEM WRITING XSBs, IGNORING FOR NOW: "+
  +                         e.getMessage()+"\n YOUR BINDINGS ARE STILL OK");
  +      //e.printStackTrace(System.out);
  +    }
     }
   
     public JavaOutputStream getJavaOutputStream() {
  
  
  
  1.21      +2 -0      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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- BindingTests.java	7 Apr 2004 04:18:10 -0000	1.20
  +++ BindingTests.java	8 Apr 2004 20:01:01 -0000	1.21
  @@ -46,7 +46,9 @@
           File typesonlyfile = TestEnv.xbeanCase("schema/typesonly/typesonly.xsd");
           File[] xsds = new File[] {typesonlyfile};
           Schema2Java compiler = new Schema2Java(
  +          //FIXME please dont use product internals in a test
                   BindingCompilerTask.createSchemaTypeSystem(xsds));
  +
           final JavaOutputStream joust = createJoust();
           BindingFile bindingFile = null;
           TylarWriter twriter = new TylarWriter() {
  
  
  

---------------------------------------------------------------------
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