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/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc JDClassLoaderFactory.java
Date Wed, 22 Oct 2003 02:32:44 GMT
pcal        2003/10/21 19:32:44

  Modified:    v2       build.xml
               v2/src/binding/org/apache/xmlbeans/impl/binding/bts
                        BindingFile.java
               v2/src/configschema/schema binding-config.xsd
               v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc
                        JDClassLoaderFactory.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding/compile
                        ExplodedTylarBuilder.java Java2Schema.java
                        Java2SchemaTask.java TylarBuilder.java
  Log:
  skeleton of java-schema binding compiler
  
  Revision  Changes    Path
  1.9       +1 -0      xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- build.xml	20 Oct 2003 19:07:34 -0000	1.8
  +++ build.xml	22 Oct 2003 02:32:43 -0000	1.9
  @@ -513,6 +513,7 @@
         <fileset dir="build/classes/binding"/>
         <fileset dir="build/classes/marshal"/>
         <fileset dir="build/classes/repackage"/>
  +      <fileset dir="build/classes/jam"/>
         <fileset dir="src/license"/>
       </jar>
     </target>
  
  
  
  1.4       +18 -17    xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingFile.java
  
  Index: BindingFile.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/bts/BindingFile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BindingFile.java	17 Oct 2003 23:00:49 -0000	1.3
  +++ BindingFile.java	22 Oct 2003 02:32:43 -0000	1.4
  @@ -68,38 +68,38 @@
   
   /**
    * Represents a BindingLoader whose contents are loaded from a
  - * single binding-config file. (See binding-config.xsd) 
  + * single binding-config file. (See binding-config.xsd)
    */
   public class BindingFile extends BaseBindingLoader
   {
   
       /**
        * This constructor is used when making a new one out of the blue.
  -     */ 
  +     */
       public BindingFile()
       {
           // nothing to do - all maps are empty
       }
  -    
  +
       /**
        * Loader
  -     */ 
  +     */
       public static BindingFile forDoc(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument
doc)
       {
           return new BindingFile(doc);
       }
  -    
  +
       /**
        * This constructor loads an instance from an XML file
  -     */ 
  +     */
       protected BindingFile(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument
doc)
       {
           List errors = new ArrayList();
           if (!doc.validate(new XmlOptions().setErrorListener(errors)))
               throw new IllegalArgumentException(errors.size() > 0 ? errors.get(0).toString()
: "Invalid binding-config document");
  -        
  +
           // todo: in the loops below, validate that entries are unique, or modify schema
to do so.
  -        
  +
           org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType[] btNodes =
                   doc.getBindingConfig().getBindings().getBindingTypeArray();
           for (int i = 0; i < btNodes.length; i++)
  @@ -115,7 +115,7 @@
               XmlName xName = XmlName.forString(mNodes[i].getXmlcomponent());
               xmlFromJava.put(jName, pair(jName, xName));
           }
  -        
  +
           mNodes = doc.getBindingConfig().getXmlToPojo().getMappingArray();
           for (int i = 0; i < mNodes.length; i++)
           {
  @@ -132,10 +132,10 @@
               javaFromXmlObj.put(xName, pair(jName, xName));
           }
       }
  -    
  +
       /**
        * Writes out to XML
  -     */ 
  +     */
       public org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument write() throws
IOException
       {
           org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument doc =
  @@ -143,22 +143,22 @@
           write(doc);
           return doc;
       }
  -    
  +
       /**
        * This function copies an instance into an empty doc.
  -     */ 
  +     */
       private void write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument
doc)
       {
           if (doc.getBindingConfig() != null)
               throw new IllegalArgumentException("Can only write into empty doc");
           org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument.BindingConfig
bcNode = doc.addNewBindingConfig();
  -        
  +
           // make tables
           org.apache.xmlbeans.x2003.x09.bindingConfig.BindingTable btabNode = bcNode.addNewBindings();
           org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable jtabNode = bcNode.addNewJavaToXml();
           org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable pojotabNode = bcNode.addNewXmlToPojo();
           org.apache.xmlbeans.x2003.x09.bindingConfig.MappingTable xotabNode = bcNode.addNewXmlToXmlobj();
  -        
  +
           // fill em in: binding types (delegate to BindingType.write)
           for (Iterator i = bindingTypes.values().iterator(); i.hasNext(); )
           {
  @@ -177,7 +177,7 @@
               mNode.setJavatype(jName.toString());
               mNode.setXmlcomponent(xName.toString());
           }
  -            
  +
           // to-pojo
           for (Iterator i = javaFromXmlPojo.entrySet().iterator(); i.hasNext(); )
           {
  @@ -213,7 +213,8 @@
           }
           if (fromXmlDefault)
           {
  -            xmlFromJava.put(bType.getJavaName(), bType.getXmlName());
  +            xmlFromJava.put(bType.getJavaName(),
  +                            pair(bType.getJavaName(),bType.getXmlName()));
           }
       }
   
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/ExplodedTylarBuilder.java
  
  Index: ExplodedTylarBuilder.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.w3.x2001.xmlSchema.SchemaDocument;
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.tools.ant.BuildException;
  
  import java.io.IOException;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Iterator;
  
  /**
   * Simple implementation of TylarBuilder that just dumps everything in a
   * directory.
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class ExplodedTylarBuilder implements TylarBuilder {
  
    // =========================================================================
    // Constants
  
    private static final int XML_INDENT = 2;
  
    // =========================================================================
    // Variables
  
    private File mDir;
    private List mSchemas = new ArrayList();
    private List mBindings = new ArrayList();
  
    // =========================================================================
    // Constructors
  
    public ExplodedTylarBuilder(File dir) {
      if (dir == null) throw new IllegalArgumentException("null dir");
      if (!dir.exists()) {
        if (!dir.mkdirs()) {
          throw new IllegalArgumentException("failed to create dir "+dir);
        }
      } else {
        if (!dir.isDirectory())
          throw new IllegalArgumentException("not a directory: "+dir);
      }
      mDir = dir;
    }
  
    // =========================================================================
    // TylarBuilder implementation
  
    public void addSchema(SchemaDocument sd) {
      mSchemas.add(sd);
    }
  
    public void addBindingFile(BindingFile bf) {
      mBindings.add(bf);
    }
  
    public void complete() throws IOException {
      writeBindingFiles();
      writeSchemas();
    }
  
    // =========================================================================
    // Private methods
  
    private void writeBindingFiles() throws IOException {
      int num = 0; // FIXME need real naming rules
      for(Iterator i = mBindings.iterator(); i.hasNext(); num++) {
        BindingFile bf = (BindingFile)i.next();
        BindingConfigDocument doc = bf.write();
        File file = new File(mDir,"binding-file"+(num != 0 ? ""+num : "")+".xml");
        FileOutputStream out;
        out = new FileOutputStream(file);
        try {
          doc.save(out,
                   new XmlOptions().setSavePrettyPrint().
                   setSavePrettyPrintIndent(XML_INDENT));
        } catch(IOException e) {
          throw e;
        } finally {
          try {
            out.close();
          } catch(IOException ioe) {
            ioe.printStackTrace();
          }
        }
      }
    }
  
    private void writeSchemas() throws IOException {
      int num = 0; // FIXME need real naming rules
      for(Iterator i = mSchemas.iterator(); i.hasNext(); num++) {
        SchemaDocument sd = (SchemaDocument)i.next();
        File file = new File(mDir,"schema"+(num != 0 ? ""+num : "")+".xsd");
        FileOutputStream out;
        out = new FileOutputStream(file);
        try {
          sd.save(out,
                  new XmlOptions().setSavePrettyPrint().
                  setSavePrettyPrintIndent(XML_INDENT));
        } catch(IOException e) {
          throw e;
        } finally {
          try {
            out.close();
          } catch(IOException ioe) {
            ioe.printStackTrace();
          }
        }
      }
    }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
  
  Index: Java2Schema.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  package org.apache.xmlbeans.impl.binding.compile;
  
  import org.apache.xmlbeans.impl.binding.bts.*;
  import org.apache.xmlbeans.impl.jam.JAnnotation;
  import org.apache.xmlbeans.impl.jam.JClass;
  import org.apache.xmlbeans.impl.jam.JProperty;
  import org.apache.xmlbeans.impl.jam.JElement;
  import org.apache.xmlbeans.XmlObject;
  import org.apache.xmlbeans.SchemaType;
  import org.apache.xmlbeans.XmlBeans;
  import org.w3.x2001.xmlSchema.*;
  
  import javax.xml.namespace.QName;
  
  /**
   * Transforms a set of JClasses into a BTS and a schema.  This is really just
   * a sketch at this point.
   */
  public class Java2Schema {
  
    // =========================================================================
    // Constants
  
    private static final String JAVA_URI_SCHEME      = "java:";
    private static final String JAVA_NAMESPACE_URI   = "language_builtins";
    private static final String JAVA_PACKAGE_PREFIX  = "java.";
  
    private static final String TAG_CT               = "xsdgen:complexType";
    private static final String TAG_CT_TYPENAME      = TAG_CT+"@typeName";
    private static final String TAG_CT_TARGETNS      = TAG_CT+"@targetNamespace";
    private static final String TAG_CT_ROOT          = TAG_CT+"@rootElement";
  
    private static final String TAG_EL               = "xsdgen:element";
    private static final String TAG_EL_NAME          = TAG_EL+"@name";
  
    // =========================================================================
    // Variables
  
    private BindingFile mBindingFile;
    private BindingLoader mLoader;
    private SchemaDocument mSchemaDocument;
    private SchemaDocument.Schema mSchema;
  
    // =========================================================================
    // Constructors
  
    public Java2Schema() {}
  
    // =========================================================================
    // Public methods
  
    public void bind(JClass[] classes, TylarBuilder tb) {
      tb.addBindingFile(mBindingFile = new BindingFile());
      mLoader = PathBindingLoader.forPath
              (new BindingLoader[] {mBindingFile,
                                    BuiltinBindingLoader.getInstance()});
      tb.addSchema(mSchemaDocument = SchemaDocument.Factory.newInstance());
      mSchema = mSchemaDocument.addNewSchema();
      for(int i=0; i<classes.length; i++) {
        getBindingTypeFor(classes[i]);
      }
    }
  
    // =========================================================================
    // Private methods
  
    private static JavaName getJavaName(JClass jc) {
      return JavaName.forString(jc.getQualifiedName());
    }
  
    private BindingType getBindingTypeFor(JClass clazz) {
      BindingType out = mLoader.getBindingTypeForJava(getJavaName(clazz));
      if (out == null) {
        out = createBindingTypeFor(clazz);
      }
      return out;
    }
  
    private BindingType createBindingTypeFor(JClass clazz) {
      if (clazz.isPrimitive()) {
        throw new IllegalStateException(clazz.getSimpleName());
      }
      // create the schema type
      TopLevelComplexType xsdType = mSchema.addNewComplexType();
      String tns = getTargetNamespace(clazz);
      QName qname = new QName(tns,clazz.getSimpleName());
      // create a binding type
      ByNameBean bindType = new ByNameBean(getJavaName(clazz),
                                           XmlName.forTypeNamed(qname),
                                           isXmlObj(clazz));
      mBindingFile.addBindingType(bindType,true,true);
      // run through the class' properties to populate the binding and xsdtypes
      JProperty props[] = clazz.getProperties();
      Group xsdSequence = null;
      for(int i=0; i<props.length; i++) {
        if (props[i].getGetter() == null || props[i].getSetter() == null) {
          continue; // we can only deal with read-write props
        }
        String propName = getAnnotation(props[i],TAG_EL_NAME,props[i].getSimpleName());
        BindingType propType = getBindingTypeFor(props[i].getType());
        QNameProperty qprop = new QNameProperty();
        qprop.setBindingType(propType);
        qprop.setQName(new QName(propName));
        qprop.setGetterName(props[i].getGetter().getSimpleName());
        qprop.setSetterName(props[i].getSetter().getSimpleName());
        bindType.addProperty(qprop);
        // also populate the schema type
        if (xsdSequence == null) xsdSequence = xsdType.addNewSequence();
        LocalElement xsdElement = xsdSequence.addNewElement();
        xsdElement.setName(propName);
        xsdElement.setType(getBuiltinTypeNameFor(props[i].getType()));
      }
  
      // check to see if they want to create a root elements from this type
      JAnnotation[] anns = clazz.getAnnotations(TAG_CT_ROOT);
      if (anns.length != 0) {
        for(int i=0; i<anns.length; i++) {
  
        }
      }
      return bindType;
    }
  
    //REVIEW seems like having this functionality in jam (getters w/defaults)
    //would be a good thing to add to JAM
    private static String getAnnotation(JElement elem, String annName, String dflt) {
      JAnnotation ann = elem.getAnnotation(annName);
      return (ann == null) ? dflt : ann.getStringValue();
    }
  
    private QName getBuiltinTypeNameFor(JClass clazz) {
      BindingType bt =
              mLoader.getBindingTypeForJava(JavaName.forString(clazz.getQualifiedName()));
      if (bt != null) return bt.getXmlName().getQName();
      System.out.println("no type found for "+clazz.getQualifiedName());
      return null; //FIXME
    }
  
    private String getTargetNamespace(JClass clazz) {
      JAnnotation ann = clazz.getAnnotation(TAG_CT_TARGETNS);
      if (ann != null) return ann.getStringValue();
      // Ok, they didn't specify it in the markup, so we have to
      // synthesize it from the classname.
      String pkg_name;
      if (clazz.isPrimitive()) {
        pkg_name = JAVA_NAMESPACE_URI;
      } else {
        pkg_name = clazz.getContainingPackage().getQualifiedName();
        if (pkg_name.startsWith(JAVA_PACKAGE_PREFIX)) {
          pkg_name = JAVA_NAMESPACE_URI+"."+
                  pkg_name.substring(JAVA_PACKAGE_PREFIX.length());
        }
      }
      return JAVA_URI_SCHEME + pkg_name;
    }
  
    private static boolean isXmlObj(JClass clazz) {
      try {
        JClass xmlObj = clazz.forName("org.apache.xmlbeans.XmlObject");
        return xmlObj.isAssignableFrom(clazz);
      } catch(Exception e) {
        e.printStackTrace(); //FIXME
        return false;
      }
    }
  }
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java
  
  Index: Java2SchemaTask.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.BuildException;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.Path;
  import org.apache.tools.ant.types.Reference;
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.impl.jam.JClass;
  import org.apache.xmlbeans.impl.jam.JFactory;
  import org.apache.xmlbeans.impl.jam.JFileSet;
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  import org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument;
  
  import java.io.File;
  import java.io.IOException;
  
  /**
   * Ant task definition for binding in the start-with-java case.
   * The real work is delegated to another class, Java2Schema.
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public class Java2SchemaTask extends Task {
  
    // =========================================================================
    // Variables
  
    private File mDestDir = null;
    private File mTempDir = null;
    private Path mSourcepath = null;
    private Path mClasspath = null;
    private String mIncludes = null;
    private Path mSrcDir = null;
  
    // =========================================================================
    // Task attributes
  
    public void setDestDir(File dir) { mDestDir = dir; }
  
    public void setTempDir(File dir) { mTempDir = dir; }
  
    /**
     * Set the source directories to find the source Java files.
     */
    public void setSrcdir(Path srcDir) {
      if (mSrcDir == null) {
        mSrcDir = srcDir;
      } else {
        mSrcDir.append(srcDir);
      }
    }
  
    public void setSourcepath(Path path) {
      if (mSourcepath == null) {
        mSourcepath = path;
      } else {
        mSourcepath.append(path);
      }
    }
  
    public void setClasspath(Path path) {
      if (mClasspath == null) {
        mClasspath = path;
      } else {
        mClasspath.append(path);
      }
    }
  
    public void setClasspathRef(Reference r) {
      createClasspath().setRefid(r);
    }
  
    public void setSourcepathRef(Reference r) {
      createSourcepath().setRefid(r);
    }
  
    public Path createClasspath() {
      if (mClasspath == null) {
        mClasspath = new Path(getProject());
      }
      return mClasspath.createPath();
    }
  
    public Path createSourcepath() {
      if (mSourcepath == null) {
        mSourcepath = new Path(getProject());
      }
      return mSourcepath.createPath();
    }
  
    public void setIncludes(String includes) {
      mIncludes = includes;
    }
  
    // =========================================================================
    // Task implementation
  
     /**
     * Execute the task.
     */
    public void execute() throws BuildException {
      JFactory jf = JFactory.getInstance();
      String[] list = mSrcDir.list();
      if (list.length != 1) throw new IllegalStateException("NYI");
      JFileSet fs = jf.createFileSet(new File("."/*list[0]*/));
      fs.include(mIncludes);
      if (mClasspath != null) {
        System.out.println(mClasspath.toString()+"  set classpath");
        fs.setClasspath(mClasspath.toString());
      }
      JClass[] classes;
      try {
        classes = jf.loadSources(fs);
      } catch(IOException ioe) {
        ioe.printStackTrace();
        throw new BuildException(ioe);
      }
      Java2Schema j2b = new Java2Schema();
      TylarBuilder tb = new ExplodedTylarBuilder(mDestDir);
      j2b.bind(classes,tb);
      try {
        tb.complete();
      } catch(IOException ioe) {
        ioe.printStackTrace();
        throw new BuildException(ioe);
      }
      log("Java2Schema complete, output in "+mDestDir);
    }
  
    // =========================================================================
    // Private methods
  
  
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TylarBuilder.java
  
  Index: TylarBuilder.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.w3.x2001.xmlSchema.SchemaDocument;
  import org.apache.xmlbeans.impl.binding.bts.BindingFile;
  
  import java.io.IOException;
  
  /**
   * Isolates binding compilation tasks from details of how their outputs are
   * actually written out to disk.  There will probably be at least two
   * implementations of this interface: one that outputs a jarred 'tylar' and
   * another which outputs a directory.
   *
   * We may want to change the name of this class; I'm still a little uneasy
   * about 'tylar,' but for the moment, at least everyone will understand what
   * this is.
   *
   * @author Patrick Calahan <pcal@bea.com>
   */
  public interface TylarBuilder {
  
  /**
   * Adds the given schema document to the type library.
   */
    public void addSchema(SchemaDocument sd);
  
    /**
     * Adds the given binding config to the type library.
     */
    public void addBindingFile(BindingFile bf);
  
    /**
     * This should be called to inform the builder that work is complete and
     * that it should write all of its output to disk (or whatever it wants
     * to do).  This method can be called at most once for a given instance
     * of TylarBuilder; any subsequent method calls on that instance will result
     * in an IllegalStateException.
     *
     * @throws IOException if an error occurs while performing output. REVIEW
     */
    public void complete() throws IOException;
  
  }
  
  
  1.3       +1 -0      xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd
  
  Index: binding-config.xsd
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- binding-config.xsd	7 Oct 2003 20:29:22 -0000	1.2
  +++ binding-config.xsd	22 Oct 2003 02:32:44 -0000	1.3
  @@ -64,6 +64,7 @@
       </xs:complexContent>
     </xs:complexType>
   
  +
     <xs:complexType name="jaxb-bean">
       <xs:complexContent>
         <xs:extension base="tns:binding-type">
  
  
  
  1.3       +1 -2      xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDClassLoaderFactory.java
  
  Index: JDClassLoaderFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/jam/org/apache/xmlbeans/impl/jam/internal/javadoc/JDClassLoaderFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDClassLoaderFactory.java	20 Oct 2003 19:07:34 -0000	1.2
  +++ JDClassLoaderFactory.java	22 Oct 2003 02:32:44 -0000	1.3
  @@ -86,8 +86,7 @@
     private static final JDClassLoaderFactory INSTANCE =
             new JDClassLoaderFactory();
   
  -  private JDClassLoaderFactory() {
  -  }
  +  private JDClassLoaderFactory() {}
   
     public static final JDClassLoaderFactory getInstance() {
       return INSTANCE;
  
  
  

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