xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkro...@apache.org
Subject cvs commit: xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans SchemaCodePrinter.java
Date Fri, 03 Dec 2004 00:15:23 GMT
kkrouse     2004/12/02 16:15:23

  Modified:    v2       build.xml
               v2/external/lib oldxbean.jar
               v2/src/typeimpl/org/apache/xmlbeans/impl/schema
                        SchemaTypeCodePrinter.java
                        SchemaTypeSystemCompiler.java
                        SchemaTypeSystemImpl.java
               v2/src/xmlcomp/org/apache/xmlbeans/impl/tool
                        SchemaCodeGenerator.java SchemaCompiler.java
               v2/src/xmlpublic/org/apache/xmlbeans SchemaCodePrinter.java
  Added:       v2/src/typeholder/org/apache/xmlbeans/impl/schema
                        TypeSystemHolder.java
  Log:
  - deprecate SchemaCodePrinter.printLoader()
  - use a compiled TypeSystemHolder class as a template to gen other
    TypeSystemHodler classes.  no need for javac when saving a type system!
  - update the boostrap jar
  
  Revision  Changes    Path
  1.92      +31 -2     xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- build.xml	4 Nov 2004 05:24:40 -0000	1.91
  +++ build.xml	3 Dec 2004 00:15:19 -0000	1.92
  @@ -302,7 +302,7 @@
     <!-- previously in xbean.xml -->
   
     <target name="xbean.jar"
  -        depends="dirs, xmlpublic.classes, typestore.classes, common.classes,
  +        depends="dirs, xmlpublic.classes, typeholder.template, typestore.classes, common.classes,
                    typeimpl.classes, xmlcomp.classes,
                    newstore2.classes, saaj_api.classes,
                    marshal.classes, xpath.classes, oldxbean.jar, xsdschema.classes,
  @@ -310,6 +310,7 @@
                    piccolo.classes, tools.classes">
       <jar jarfile="build/lib/xbean.jar" index="true">
         <fileset dir="build/classes/xmlpublic"/>
  +      <fileset dir="build/classes/typeholder"/>
         <fileset dir="build/classes/typestore"/>
         <fileset dir="build/classes/common"/>
         <fileset dir="build/classes/typeimpl"/>
  @@ -415,10 +416,36 @@
   
     </target>
   
  +  <!-- typeholder target ================================================ -->
  +
  +  <property name="typeholder.name" value="org/apache/xmlbeans/impl/schema/TypeSystemHolder"/>
  +
  +  <target name="typeholder.check">
  +    <condition property="typeholder.notRequired">
  +        <uptodate property="typeholder.notRequired"
  +          targetfile="build/classes/typeholder/${typeholder.name}.template">
  +          <srcfiles dir="src/typeholder" includes="${typeholder.name}.java"/>
  +        </uptodate>
  +    </condition>
  +  </target>
  +
  +  <target name="typeholder.template" depends="typeholder.check, xmlpublic.classes" unless="typeholder.notRequired">
  +    <mkdir dir="build/classes/typeholder"/>
  +    <javac destdir="build/classes/typeholder" source="${javac.source}" target="${javac.target}"
debug="off">
  +      <classpath>
  +        <pathelement location="build/classes/xmlpublic"/>
  +      </classpath>
  +      <src location="src/typeholder"/>
  +    </javac>
  +    <move
  +      file="build/classes/typeholder/${typeholder.name}.class"
  +      tofile="build/classes/typeholder/${typeholder.name}.template"/>
  +  </target>
  +
     <!-- typeimpl target ============================================== -->
   
     <target name="typeimpl.classes" depends="dirs, newstore2.classes,
  -      repackage.classes, xmlpublic.classes, typestore.classes, xsdschema.classes,
  +      repackage.classes, xmlpublic.classes, typeholder.template, typestore.classes, xsdschema.classes,
         configschema.classes, toolschema.classes, jsr173_api.jar, jam">
       <mkdir dir="build/classes/typeimpl"/>
       <javac destdir="build/classes/typeimpl" source="${javac.source}" target="${javac.target}"
debug="on">
  @@ -432,6 +459,8 @@
           <pathelement location="build/classes/xmlconfig"/>
           <pathelement location="build/classes/configschema"/>
           <pathelement location="build/classes/xsdschema"/>
  +        <pathelement location="build/classes/xmlschema"/>
  +        <pathelement location="build/classes/toolschema"/>
           <pathelement location="${jam_classes_dir}"/>
           <pathelement location="build/lib/jsr173_api.jar"/>
         </classpath>
  
  
  
  1.15      +5879 -5623xml-xmlbeans/v2/external/lib/oldxbean.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-xmlbeans/v2/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
  
  Index: TypeSystemHolder.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.xmlbeans.impl.schema;
  
  import org.apache.xmlbeans.SchemaTypeSystem;
  
  /**
   * This class is the hook which causes the SchemaTypeSystem to be loaded when
   * a generated class is used.  It isn't used by the runtime directly, instead
   * this class is used by the schema compiler as a template class.  By using a
   * template class, the SchemaTypeSystemImpl can create all the binary files
   * required without needing to rely on javac.  The generated source still
   * requires a java compiler.
   *
   * @see SchemaTypeSystemImpl.save()
   */
  //
  // !!! It's important that there never NEVER be any references to this class because
  // !!! the static initializer will fail.  This class must only be used as a class file.
  // !!! If this scares you, turn back now !!!
  //
  // !!! If you modify this class, you will have to run bootstrap.
  // !!! If this scares you, turn back now !!!
  //
  public class TypeSystemHolder
  {
      private TypeSystemHolder() { }
  
      public static final SchemaTypeSystem typeSystem = loadTypeSystem();
  
      // Commenting out this line has the effect of not loading all components in a
      // typesystem upfront, but just as they are needed, which may improve
      // performance significantly
      //static { typeSystem.resolve(); }
  
      private static final SchemaTypeSystem loadTypeSystem()
      {
          try
          {
              return (SchemaTypeSystem)
                  Class.forName(
                      "org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl",
                      true, TypeSystemHolder.class.getClassLoader())
                  .getConstructor(new Class[] { Class.class })
                  .newInstance(new java.lang.Object[] { TypeSystemHolder.class });
          }
          catch (ClassNotFoundException e)
          {
              throw new RuntimeException("Cannot load org.apache.xmlbeans.impl.SchemaTypeSystemImpl:
make sure xbean.jar is on the classpath.", e);
          }
          catch (Exception e)
          {
              throw new RuntimeException("Could not instantiate SchemaTypeSystemImpl (" +
e.toString() + "): is the version of xbean.jar correct?", e);
          }
      }
  }
  
  
  
  1.16      +2 -23     xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
  
  Index: SchemaTypeCodePrinter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SchemaTypeCodePrinter.java	22 Nov 2004 20:30:11 -0000	1.15
  +++ SchemaTypeCodePrinter.java	3 Dec 2004 00:15:22 -0000	1.16
  @@ -266,32 +266,11 @@
                   ((SchemaTypeSystemImpl)system).handleForType(sType) + "\");");
       }
   
  +    /** @deprecated */
       public void printLoader(Writer writer, SchemaTypeSystem system)
           throws IOException
       {
  -        _writer = writer;
  -        String shortName = shortIndexClassForSystem(system);
  -        emit("package " + system.getName() + ";");
  -        emit("");
  -        emit("public final class " + shortName);
  -        emit("{");
  -        indent();
  -        emit("private " + shortName + "() { }");
  -        emit("public static final org.apache.xmlbeans.SchemaTypeSystem typeSystem = loadTypeSystem();");
  -        // Commenting out this line has the effect of not loading all components in a
  -        // typesystem upfront, but just as they are needed, which may improve
  -        // performance significantly
  -//         emit("static { typeSystem.resolve(); }");
  -        emit("private static final org.apache.xmlbeans.SchemaTypeSystem loadTypeSystem()");
  -        emit("{");
  -        indent();
  -        emit("try { return (org.apache.xmlbeans.SchemaTypeSystem)Class.forName(\"org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl\",
true, " + shortName + ".class.getClassLoader()).getConstructor(new Class[] { Class.class }).newInstance(new
java.lang.Object[] { " + shortName + ".class }); }");
  -        emit("catch (ClassNotFoundException e) { throw new RuntimeException(\"Cannot load
org.apache.xmlbeans.impl.SchemaTypeSystemImpl: make sure xbean.jar is on the classpath.\",
e); }");
  -        emit("catch (Exception e) { throw new RuntimeException(\"Could not instantiate
SchemaTypeSystemImpl (\" + e.toString() + \"): is the version of xbean.jar correct?\", e);
}");
  -        outdent();
  -        emit("}");
  -        outdent();
  -        emit("}");
  +        // deprecated
       }
   
       void printInnerType(SchemaType sType, SchemaTypeSystem system) throws IOException
  
  
  
  1.11      +1 -36     xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
  
  Index: SchemaTypeSystemCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SchemaTypeSystemCompiler.java	19 Nov 2004 23:52:33 -0000	1.10
  +++ SchemaTypeSystemCompiler.java	3 Dec 2004 00:15:22 -0000	1.11
  @@ -222,7 +222,7 @@
   
           if (stsi != null && filer != null)
           {
  -            saveTypeSystem(stsi, filer, options);
  +            stsi.save(filer);
               generateTypes(stsi, filer, options);
           }
   
  @@ -394,41 +394,6 @@
           return (Schema[]) result.toArray(new Schema[result.size()]);
       }
   
  -
  -    /**
  -     * Saves a SchemaTypeSystem as .xsb files using Filer.
  -     * Please do not invoke this method directly as the signature could change unexpectedly.
  -     * Use {@link org.apache.xmlbeans.XmlBeans#compileXmlBeans(String, org.apache.xmlbeans.SchemaTypeSystem,
org.apache.xmlbeans.XmlObject[], org.apache.xmlbeans.BindingConfig, org.apache.xmlbeans.SchemaTypeLoader,
org.apache.xmlbeans.Filer, org.apache.xmlbeans.XmlOptions)} instead.
  -     *
  -     * @param system the SchemaTypeSystem to save
  -     * @param filer to create the binary .xsb files
  -     * @param options See {@link XmlOptions#setSchemaCodePrinter(org.apache.xmlbeans.SchemaCodePrinter)}
  -     */
  -    // KHK: generate TypeSystemHolder bytecode directly in SchemaTypeSystemImpl.save()
  -    // KHK: then remove this method and remove SchemaCodeGenerator.saveTypeSystem()
  -    public static boolean saveTypeSystem(SchemaTypeSystem system, Filer filer, XmlOptions
options)
  -    {
  -        system.save(filer);
  -        options = XmlOptions.maskNull(options);
  -
  -        // Now generate the holder class
  -        String index = SchemaTypeCodePrinter.indexClassForSystem(system);
  -        try
  -        {
  -            Writer writer = filer.createSourceFile(index);
  -
  -            SchemaTypeCodePrinter.printLoader(writer, system, options);
  -
  -            writer.close();
  -        }
  -        catch (IOException e)
  -        {
  -            System.err.println("IO Error " + e);
  -            return false;
  -        }
  -
  -        return true;
  -    }
   
       /**
        * Generate java source files for a SchemaTypeSystem.
  
  
  
  1.17      +156 -0    xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
  
  Index: SchemaTypeSystemImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SchemaTypeSystemImpl.java	19 Nov 2004 23:52:33 -0000	1.16
  +++ SchemaTypeSystemImpl.java	3 Dec 2004 00:15:22 -0000	1.17
  @@ -364,6 +364,158 @@
       }
   
       /**
  +     * The strategy here is to copy the compiled TypeSystemHolder.template class
  +     * to a new TypeSystemHolder.class needed by the schema type system.  When
  +     * saving a loader, we read the TypeSystemHolder.template class file and
  +     * swap out the utf8 string constants with new ones to create a new
  +     * TypeSystemHolder class file.  This saves us the need to rely on javac
  +     * to compile a generated .java file into the class file.
  +     *
  +     * See the JVM spec on how to interpret the bytes of a class file.
  +     */
  +    void saveLoader()
  +    {
  +        String indexClassName = SchemaTypeCodePrinter.indexClassForSystem(this);
  +        String[] replace = makeClassStrings(indexClassName);
  +
  +        InputStream is = null;
  +        OutputStream os = null;
  +
  +        DataInputStream in = null;
  +        DataOutputStream out = null;
  +        try
  +        {
  +            is = SchemaTypeSystemImpl.class.getResourceAsStream(HOLDER_TEMPLATE_CLASSFILE);
  +            if (is == null)
  +                throw new SchemaTypeLoaderException("couldn't find resource: " + HOLDER_TEMPLATE_CLASSFILE,
_name, null, SchemaTypeLoaderException.IO_EXCEPTION);
  +            in = new DataInputStream(is);
  +
  +            os = _filer.createBinaryFile(indexClassName.replace('.', '/') + ".class");
  +            out = new DataOutputStream(os);
  +
  +            // java magic
  +            out.writeInt(in.readInt());
  +
  +            // java minor and major version
  +            out.writeShort(in.readUnsignedShort());
  +            out.writeShort(in.readUnsignedShort());
  +
  +            int poolsize = in.readUnsignedShort();
  +            out.writeShort(poolsize);
  +
  +            // the constant pool is indexed from 1 to poolsize-1
  +            for (int i = 1; i < poolsize; i++)
  +            {
  +                int tag = in.readUnsignedByte();
  +                out.writeByte(tag);
  +
  +                switch (tag)
  +                {
  +                    case CONSTANT_UTF8:
  +                        String value = in.readUTF();
  +                        int j = 0;
  +                        inner: for (; j < HOLDER_TEMPLATE_NAMES.length; j++)
  +                        {
  +                            if (HOLDER_TEMPLATE_NAMES[j].equals(value))
  +                            {
  +                                out.writeUTF(replace[j]);
  +                                break inner;
  +                            }
  +                        }
  +                        if (j == HOLDER_TEMPLATE_NAMES.length)
  +                            out.writeUTF(value);
  +                        break;
  +
  +                    case CONSTANT_CLASS:
  +                    case CONSTANT_STRING:
  +                        out.writeShort(in.readUnsignedShort());
  +                        break;
  +
  +                    case CONSTANT_NAMEANDTYPE:
  +                    case CONSTANT_METHOD:
  +                    case CONSTANT_FIELD:
  +                    case CONSTANT_INTERFACEMETHOD:
  +                        out.writeShort(in.readUnsignedShort());
  +                        out.writeShort(in.readUnsignedShort());
  +                        break;
  +
  +                    case CONSTANT_INTEGER:
  +                    case CONSTANT_FLOAT:
  +                        out.writeInt(in.readInt());
  +                        break;
  +
  +                    case CONSTANT_LONG:
  +                    case CONSTANT_DOUBLE:
  +                        out.writeInt(in.readInt());
  +                        out.writeInt(in.readInt());
  +                        break;
  +
  +                    default:
  +                        throw new RuntimeException("Unexpected constant type: " + tag);
  +                }
  +            }
  +
  +            // we're done with the class' constant pool,
  +            // we can just copy the rest of the bytes
  +            try
  +            {
  +                while (true)
  +                    out.writeByte(in.readByte());
  +            }
  +            catch (java.io.EOFException e)
  +            {
  +                // ok
  +            }
  +
  +        }
  +        catch (IOException e)
  +        {
  +            // ok
  +        }
  +        finally
  +        {
  +            if (is != null) try { is.close(); } catch (Exception e) { }
  +            if (os != null) try { os.close(); } catch (Exception e) { }
  +        }
  +    }
  +
  +    private static final String HOLDER_TEMPLATE_CLASS = "org.apache.xmlbeans.impl.schema.TypeSystemHolder";
  +    private static final String HOLDER_TEMPLATE_CLASSFILE = "TypeSystemHolder.template";
  +    private static final String[] HOLDER_TEMPLATE_NAMES = makeClassStrings(HOLDER_TEMPLATE_CLASS);
  +
  +    // constant pool entry types
  +    private static final int CONSTANT_UTF8 = 1;
  +    private static final int CONSTANT_UNICODE = 2;
  +    private static final int CONSTANT_INTEGER = 3;
  +    private static final int CONSTANT_FLOAT = 4;
  +    private static final int CONSTANT_LONG = 5;
  +    private static final int CONSTANT_DOUBLE = 6;
  +    private static final int CONSTANT_CLASS = 7;
  +    private static final int CONSTANT_STRING = 8;
  +    private static final int CONSTANT_FIELD = 9;
  +    private static final int CONSTANT_METHOD = 10;
  +    private static final int CONSTANT_INTERFACEMETHOD = 11;
  +    private static final int CONSTANT_NAMEANDTYPE = 12;
  +
  +
  +    /**
  +     * Construct an array of Strings found in a class file for a classname.
  +     * For the class name 'a.b.C' it will generate an array of:
  +     * 'a.b.C', 'a/b/C', 'La/b/C;', and 'class$a$b$C'.
  +     */
  +    private static String[] makeClassStrings(String classname)
  +    {
  +        String[] result = new String[4];
  +
  +        result[0] = classname;
  +        result[1] = classname.replace('.', '/');
  +        result[2] = "L" + result[1] + ";";
  +        result[3] = "class$" + classname.replace('.', '$');
  +
  +        return result;
  +    }
  +
  +    /**
        * Only used in the nonbootstrapped case.
        */
       private Map buildTypeRefsByClassname()
  @@ -1099,6 +1251,8 @@
   
       public void save(Filer filer)
       {
  +        if (filer == null)
  +            throw new IllegalArgumentException("filer must not be null");
           _filer = filer;
   
           _localHandles.startWriteMode();
  @@ -1117,6 +1271,8 @@
   
           saveIndex();
           savePointers();
  +
  +        saveLoader();
       }
   
       void saveTypesRecursively(SchemaType[] types)
  
  
  
  1.12      +3 -209    xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java
  
  Index: SchemaCodeGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCodeGenerator.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SchemaCodeGenerator.java	19 Nov 2004 23:52:33 -0000	1.11
  +++ SchemaCodeGenerator.java	3 Dec 2004 00:15:23 -0000	1.12
  @@ -54,202 +54,16 @@
        *                   directory and then compiled to the destination dir
        * @param repackager the repackager to use when generating the holder class
        * @param options options. Can be null
  +     * @deprecated Use {@link SchemaTypeSystem.save()} instead.
        */
       public static void saveTypeSystem(SchemaTypeSystem system, File classesDir,
           File sourceFile, Repackager repackager, XmlOptions options)
           throws IOException
       {
  -        if (sourceFile == null)
  -        {
  -            // KHK: remove this branch once we can generate bytecode directly
  -
  -            system.saveToDirectory(classesDir);
  -            options = XmlOptions.maskNull(options);
  -
  -            // Now generate the holder class
  -            File source = sourceFile;
  -            File tempDir = null;
  -
  -            String filename = SchemaTypeCodePrinter.indexClassForSystem(system).replace('.',
  -                File.separatorChar) + ".java";
  -            tempDir = createTempDir();
  -            File sourcedir = IOUtil.createDir(tempDir, "src");
  -            source = new File(sourcedir, filename);
  -            source.getParentFile().mkdirs();
  -
  -            Writer writer =
  -                repackager == null
  -                ? (Writer) new FileWriter( source )
  -                : (Writer) new RepackagingWriter( source, repackager );
  -
  -            SchemaTypeCodePrinter.printLoader(writer, system, options);
  -
  -            writer.close();
  -
  -            // now compile the generated file to classesDir
  -            List srcFiles = new ArrayList(1);
  -            srcFiles.add(source);
  -            CodeGenUtil.externalCompile(srcFiles, classesDir, null, false);
  -            tryHardToDelete(tempDir);
  -        }
  -        else
  -        {
  -            Filer filer = new FilerImpl(classesDir, null, repackager, false, false);
  -            SchemaTypeSystemCompiler.saveTypeSystem(system, filer, options);
  -        }
  +        Filer filer = new FilerImpl(classesDir, null, repackager, false, false);
  +        system.save(filer);
       }
   
  -//    private static boolean genTypes(SchemaTypeSystem saver, List sourcefiles, File sourcedir,
Repackager repackager, boolean verbose, XmlOptions opts, boolean incrSrcGen)
  -//    {
  -//        boolean failure = false;
  -//
  -//        List types = new ArrayList();
  -//        types.addAll(Arrays.asList(saver.globalTypes()));
  -//        types.addAll(Arrays.asList(saver.documentTypes()));
  -//        types.addAll(Arrays.asList(saver.attributeTypes()));
  -//
  -//        Set seenFiles = null;
  -//        if (incrSrcGen)
  -//        {
  -//            seenFiles = new HashSet();
  -//            if (sourcefiles != null)
  -//                for (int i = 0; i < sourcefiles.size(); i++)
  -//                    seenFiles.add(sourcefiles.get(i));
  -//        }
  -//
  -//        for (Iterator i = types.iterator(); i.hasNext(); )
  -//        {
  -//            SchemaType type = (SchemaType)i.next();
  -//            if (verbose)
  -//                System.err.println("Compiling type " + type);
  -//            if (type.isBuiltinType())
  -//                continue;
  -//            if (type.getFullJavaName() == null)
  -//                continue;
  -//
  -//            String fjn = type.getFullJavaName();
  -//
  -//            if (fjn.indexOf('$') > 0)
  -//            {
  -//                fjn =
  -//                    fjn.substring( 0, fjn.lastIndexOf( '.' ) ) + "." +
  -//                        fjn.substring( fjn.indexOf( '$' ) + 1 );
  -//            }
  -//
  -//            String filename = fjn.replace('.', File.separatorChar) + ".java";
  -//
  -//            Writer writer = null;
  -//            Reader reader = null;
  -//            boolean changed = true;
  -//
  -//            try
  -//            {
  -//                File sourcefile = new File(sourcedir, filename);
  -//                sourcefile.getParentFile().mkdirs();
  -//                if (verbose)
  -//                    System.err.println("created " + sourcefile.getAbsolutePath());
  -//                if (incrSrcGen)
  -//                    seenFiles.add(sourcefile);
  -//                if (incrSrcGen && sourcefile.exists())
  -//                {
  -//                    // Generate the file in a buffer and then compare it to the
  -//                    // file already on disk
  -//                    // Generation
  -//                    StringWriter sw = new StringWriter();
  -//                    SchemaTypeCodePrinter.printType(sw, type, opts);
  -//                    StringBuffer buffer = sw.getBuffer();
  -//                    if (repackager != null)
  -//                        buffer = repackager.repackage(buffer);
  -//                    // Comparison
  -//                    List diffs = new ArrayList();
  -//                    reader = new java.io.FileReader(sourcefile);
  -//                    String str = buffer.toString();
  -//                    Diff.readersAsText(new java.io.StringReader(str), "<generated>",
  -//                            reader, sourcefile.getName(), diffs);
  -//                    reader.close();
  -//                    // Check the list of differences
  -//                    changed = (diffs.size() > 0);
  -//                    if (changed)
  -//                    {
  -//                        // Diffs encountered, replace the file with the text from
  -//                        // the buffer
  -//                        writer = new FileWriter( sourcefile );
  -//                        writer.write(str);
  -//                        writer.close();
  -//                        sourcefiles.add(sourcefile);
  -//                    }
  -//                    else
  -//                        ; // No diffs, don't do anything
  -//                }
  -//                else
  -//                {
  -//                    writer =
  -//                        repackager == null
  -//                            ? (Writer) new FileWriter( sourcefile )
  -//                            : (Writer) new RepackagingWriter( sourcefile, repackager
);
  -//
  -//
  -//                    SchemaTypeCodePrinter.printType(writer, type, opts);
  -//
  -//                    writer.close();
  -//
  -//                    sourcefiles.add(sourcefile);
  -//                }
  -//            }
  -//            catch (IOException e)
  -//            {
  -//                System.err.println("IO Error " + e);
  -//                failure = true;
  -//            }
  -//            finally {
  -//                try {
  -//                    if (writer != null) writer.close();
  -//                    if (reader != null) reader.close();
  -//                } catch (IOException e) {}
  -//            }
  -//
  -//            try
  -//            {
  -//                // Generate Implementation class
  -//                filename = type.getFullJavaImplName().replace('.', File.separatorChar)
+ ".java";
  -//                File implFile = new File(sourcedir,  filename);
  -//                if (verbose)
  -//                    System.err.println("created " + implFile.getAbsolutePath());
  -//                implFile.getParentFile().mkdirs();
  -//
  -//                if (incrSrcGen)
  -//                    seenFiles.add(implFile);
  -//                // If the interface did not change, the implementation shouldn't either
  -//                if (changed)
  -//                {
  -//                writer =
  -//                    repackager == null
  -//                        ? (Writer) new FileWriter( implFile )
  -//                        : (Writer) new RepackagingWriter( implFile, repackager );
  -//
  -//                SchemaTypeCodePrinter.printTypeImpl(writer, type, opts);
  -//
  -//                writer.close();
  -//
  -//                sourcefiles.add(implFile);
  -//                }
  -//            }
  -//            catch (IOException e)
  -//            {
  -//                System.err.println("IO Error " + e);
  -//                failure = true;
  -//            }
  -//            finally {
  -//                try { if (writer != null) writer.close(); } catch (IOException e) {}
  -//            }
  -//        }
  -//
  -//        if (incrSrcGen)
  -//            deleteObsoleteFiles(sourcedir, sourcedir, seenFiles);
  -//
  -//        return failure;
  -//    }
  -
       private static void deleteObsoleteFiles(File rootDir, File srcDir, Set seenFiles)
       {
           if (!(rootDir.isDirectory() && srcDir.isDirectory()))
  @@ -417,24 +231,4 @@
           }
       }
   
  -    static class RepackagingWriter extends StringWriter
  -    {
  -        public RepackagingWriter ( File file, Repackager repackager )
  -        {
  -            _file = file;
  -            _repackager = repackager;
  -        }
  -
  -        public void close ( ) throws IOException
  -        {
  -            super.close();
  -
  -            FileWriter fw = new FileWriter( _file );
  -            fw.write( _repackager.repackage( getBuffer() ).toString() );
  -            fw.close();
  -        }
  -
  -        private File _file;
  -        private Repackager _repackager;
  -    }
   }
  
  
  
  1.20      +1 -1      xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
  
  Index: SchemaCompiler.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SchemaCompiler.java	19 Nov 2004 23:52:33 -0000	1.19
  +++ SchemaCompiler.java	3 Dec 2004 00:15:23 -0000	1.20
  @@ -1030,7 +1030,7 @@
                   options.setSchemaCodePrinter(codePrinter);
   
               // save .xsb files
  -            result &= SchemaTypeSystemCompiler.saveTypeSystem(system, filer, options);
  +            system.save(filer);
   
               // gen source files
               result &= SchemaTypeSystemCompiler.generateTypes(system, filer, options);
  
  
  
  1.2       +3 -0      xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/SchemaCodePrinter.java
  
  Index: SchemaCodePrinter.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlpublic/org/apache/xmlbeans/SchemaCodePrinter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchemaCodePrinter.java	18 Mar 2004 23:28:00 -0000	1.1
  +++ SchemaCodePrinter.java	3 Dec 2004 00:15:23 -0000	1.2
  @@ -31,6 +31,9 @@
       public void printType(Writer writer, SchemaType sType)
           throws IOException;
       
  +    /**
  +     * @deprecated Obsoleted by functionality in {@link SchemaTypeSystem.save()}
  +     */
       public void printLoader(Writer writer, SchemaTypeSystem system)
           throws IOException;
   }
  
  
  

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


Mime
View raw message