You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2021/04/26 21:55:28 UTC

svn commit: r1889220 - in /xmlbeans: site/src/documentation/content/xdocs/ trunk/ trunk/src/main/java/org/apache/xmlbeans/ trunk/src/main/java/org/apache/xmlbeans/impl/schema/ trunk/src/test/java/compile/scomp/checkin/ trunk/src/test/java/compile/scomp...

Author: kiwiwings
Date: Mon Apr 26 21:55:27 2021
New Revision: 1889220

URL: http://svn.apache.org/viewvc?rev=1889220&view=rev
Log:
XMLBEANS-565 - Generate TypeSystemHolder as .java (in sources) instead of .class (in resources)

Modified:
    xmlbeans/site/src/documentation/content/xdocs/status.xml
    xmlbeans/trunk/build.xml
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/SchemaCodePrinter.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
    xmlbeans/trunk/src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java
    xmlbeans/trunk/src/test/java/compile/scomp/common/CompileCommon.java
    xmlbeans/trunk/src/test/java/compile/scomp/common/mockobj/TestFiler.java

Modified: xmlbeans/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/xmlbeans/site/src/documentation/content/xdocs/status.xml?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/site/src/documentation/content/xdocs/status.xml (original)
+++ xmlbeans/site/src/documentation/content/xdocs/status.xml Mon Apr 26 21:55:27 2021
@@ -49,6 +49,7 @@
     <release version="5.0.1" date="2021-06-??">
         <actions>
             <action dev="PD" type="update" context="code" fixes-bug="XMLBEANS-564">SAXHelper creates noisy logging with stacktraces</action>
+            <action dev="PD" type="update" context="code" fixes-bug="XMLBEANS-565">Generate TypeSystemHolder as .java (in sources) instead of .class (in resources)</action>
         </actions>
     </release>
 

Modified: xmlbeans/trunk/build.xml
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/build.xml?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/build.xml (original)
+++ xmlbeans/trunk/build.xml Mon Apr 26 21:55:27 2021
@@ -389,13 +389,6 @@
         </javac>
         <mkdir dir="build/generated-resources/org/apache/xmlbeans/impl/schema"/>
 
-        <!-- need to provide the template also in classes - generated-resources will be ignored on bootstrapping -->
-        <move file="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.class"
-              tofile="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template"/>
-
-        <copy file="build/classes/org/apache/xmlbeans/impl/schema/TypeSystemHolder.template"
-              todir="build/generated-resources/org/apache/xmlbeans/impl/schema"/>
-
         <!-- now generate new xmlbeans re-/sources and remove the traces of the oldxbean generated re-/sources -->
         <path id="oldschemas">
             <pathelement location="${log4j-api.jar}"/>

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/SchemaCodePrinter.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/SchemaCodePrinter.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/SchemaCodePrinter.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/SchemaCodePrinter.java Mon Apr 26 21:55:27 2021
@@ -15,6 +15,8 @@
 
 package org.apache.xmlbeans;
 
+import org.apache.xmlbeans.impl.repackage.Repackager;
+
 import java.io.IOException;
 import java.io.Writer;
 
@@ -42,5 +44,7 @@ public interface SchemaCodePrinter {
     default void printType(Writer writer, SchemaType sType, XmlOptions opt) throws IOException {
         printType(writer, sType);
     }
+
+    void printHolder(Writer writer, SchemaTypeSystem system, XmlOptions opt, Repackager repackager) throws IOException;
 }
 

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeCodePrinter.java Mon Apr 26 21:55:27 2021
@@ -18,6 +18,7 @@ package org.apache.xmlbeans.impl.schema;
 import org.apache.xmlbeans.*;
 import org.apache.xmlbeans.XmlOptions.BeanMethod;
 import org.apache.xmlbeans.impl.common.NameUtil;
+import org.apache.xmlbeans.impl.repackage.Repackager;
 
 import javax.xml.namespace.QName;
 import java.io.IOException;
@@ -2376,4 +2377,28 @@ public final class SchemaTypeCodePrinter
             sType = sType.getBaseType();
         }
     }
+
+    public void printHolder(Writer writer, SchemaTypeSystem system, XmlOptions opt, Repackager repackager) throws IOException {
+        _writer = writer;
+
+        String sysPack = system.getName();
+        if (repackager != null) {
+            sysPack = repackager.repackage(new StringBuffer(sysPack)).toString();
+        }
+        emit("package "+sysPack+";");
+        emit("");
+        emit("import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;");
+        emit("");
+        emit("public final class TypeSystemHolder extends SchemaTypeSystemImpl {");
+        indent();
+        emit("public static final TypeSystemHolder typeSystem = new TypeSystemHolder();");
+        emit("");
+        emit("private TypeSystemHolder() {");
+        indent();
+        emit("super(TypeSystemHolder.class);");
+        outdent();
+        emit("}");
+        outdent();
+        emit("}");
+    }
 }

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java Mon Apr 26 21:55:27 2021
@@ -17,6 +17,8 @@ package org.apache.xmlbeans.impl.schema;
 
 import org.apache.xmlbeans.*;
 import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
+import org.apache.xmlbeans.impl.repackage.Repackager;
+import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument.Schema;
 
@@ -370,6 +372,22 @@ public class SchemaTypeSystemCompiler {
         types.addAll(Arrays.asList(system.documentTypes()));
         types.addAll(Arrays.asList(system.attributeTypes()));
 
+
+        SchemaCodePrinter printer = (options == null) ? null : options.getSchemaCodePrinter();
+        if (printer == null) {
+            printer = new SchemaTypeCodePrinter();
+        }
+
+        String indexClassName = SchemaTypeCodePrinter.indexClassForSystem(system);
+
+        try (Writer out = filer.createSourceFile(indexClassName)) {
+            Repackager repackager = (filer instanceof FilerImpl) ? ((FilerImpl) filer).getRepackager() : null;
+            printer.printHolder(out, system, options, repackager);
+        } catch (IOException e) {
+            System.err.println("IO Error " + e);
+            success = false;
+        }
+
         for (SchemaType type : types) {
             if (type.isBuiltinType()) {
                 continue;
@@ -380,11 +398,6 @@ public class SchemaTypeSystemCompiler {
 
             String fjn = type.getFullJavaName();
 
-            SchemaCodePrinter printer = (options == null) ? null : options.getSchemaCodePrinter();
-            if (printer == null) {
-                printer = new SchemaTypeCodePrinter();
-            }
-
             try (Writer writer = filer.createSourceFile(fjn)) {
                 // Generate interface class
                 printer.printType(writer, type, options);

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java Mon Apr 26 21:55:27 2021
@@ -16,8 +16,9 @@
 package org.apache.xmlbeans.impl.schema;
 
 import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.common.*;
-import org.apache.xmlbeans.impl.repackage.Repackager;
+import org.apache.xmlbeans.impl.common.NameUtil;
+import org.apache.xmlbeans.impl.common.QNameHelper;
+import org.apache.xmlbeans.impl.common.XBeanDebug;
 import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.impl.util.HexBin;
 import org.apache.xmlbeans.impl.values.XmlObjectBase;
@@ -291,153 +292,9 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    /**
-     * 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.
-     * <p>
-     * 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);
-        assert replace.length == HOLDER_TEMPLATE_NAMES.length;
-
-        Repackager repackager = null;
-        if (_filer instanceof FilerImpl) {
-            repackager = ((FilerImpl) _filer).getRepackager();
-        }
-
-        final String outName = indexClassName.replace('.', '/') + ".class";
-        try (DataInputStream in = new DataInputStream(getHolder());
-             DataOutputStream out = new DataOutputStream(_filer.createBinaryFile(outName))) {
-
-            // 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();
-                        out.writeUTF(repackageConstant(value, replace, repackager));
-                        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
-            IOUtil.copyCompletely(in, out);
-        } catch (IOException e) {
-            // ok
-        }
-    }
-
-    private InputStream getHolder() {
-        InputStream is = SchemaTypeSystemImpl.class.getResourceAsStream(HOLDER_TEMPLATE_CLASSFILE);
-        if (is != null) {
-            return is;
-        }
-        DefaultClassLoaderResourceLoader clLoader = new DefaultClassLoaderResourceLoader();
-        is = clLoader.getResourceAsStream(HOLDER_TEMPLATE_CLASSFILE);
-        if (is != null) {
-            return is;
-        }
-        throw new SchemaTypeLoaderException("couldn't find resource: " + HOLDER_TEMPLATE_CLASSFILE,
-            _name, null, SchemaTypeLoaderException.IO_EXCEPTION);
-    }
-
-    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;
-
     // MAX_UNSIGNED_SHORT
     private static final int MAX_UNSIGNED_SHORT = Short.MAX_VALUE * 2 + 1;
 
-    private static String repackageConstant(String value, String[] replace, Repackager repackager) {
-        for (int i = 0; i < HOLDER_TEMPLATE_NAMES.length; i++) {
-            if (HOLDER_TEMPLATE_NAMES[i].equals(value)) {
-                return replace[i];
-            }
-        }
-
-        if (repackager != null) {
-            return repackager.repackage(new StringBuffer(value)).toString();
-        }
-
-        return value;
-    }
-
-    /**
-     * 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;
-    }
-
     private Map<String, SchemaComponent.Ref> buildTypeRefsByClassname(Map<String, SchemaType> typesByClassname) {
         Map<String, SchemaComponent.Ref> result = new LinkedHashMap<>();
         for (String className : typesByClassname.keySet()) {
@@ -1081,8 +938,6 @@ public class SchemaTypeSystemImpl extend
 
         saveIndex();
         savePointers();
-
-        saveLoader();
     }
 
     void saveTypesRecursively(SchemaType[] types) {
@@ -1926,7 +1781,6 @@ public class SchemaTypeSystemImpl extend
          * Finishes loading an element after the header has already been loaded.
          */
         public SchemaGlobalElement finishLoadingElement() {
-            String handle = null;
             try {
                 int particleType = readShort();
                 if (particleType != SchemaParticle.ELEMENT) {
@@ -1981,7 +1835,7 @@ public class SchemaTypeSystemImpl extend
             } catch (SchemaTypeLoaderException e) {
                 throw e;
             } catch (Exception e) {
-                throw new SchemaTypeLoaderException("Cannot load type from typesystem", _name, handle, SchemaTypeLoaderException.NESTED_EXCEPTION, e);
+                throw new SchemaTypeLoaderException("Cannot load type from typesystem", _name, null, SchemaTypeLoaderException.NESTED_EXCEPTION, e);
             } finally {
                 readEnd();
             }
@@ -3287,7 +3141,7 @@ public class SchemaTypeSystemImpl extend
      */
     public String getMetadataPath() {
         Matcher m = packPat.matcher(_name);
-        m.find();
-        return m.group(1).replace('.', '/');
+        String n = m.find() ? m.group(1) : _name;
+        return n.replace('.', '/');
     }
 }

Modified: xmlbeans/trunk/src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java (original)
+++ xmlbeans/trunk/src/test/java/compile/scomp/checkin/XmlBeansCompCheckinTests.java Mon Apr 26 21:55:27 2021
@@ -14,7 +14,6 @@
  */
 package compile.scomp.checkin;
 
-import compile.scomp.common.CompileCommon;
 import compile.scomp.common.CompileTestBase;
 import compile.scomp.common.mockobj.TestFiler;
 import org.apache.xmlbeans.*;
@@ -24,34 +23,37 @@ import org.junit.Test;
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Arrays;
 import java.util.List;
-import java.util.Vector;
 
 import static org.junit.Assert.*;
 
 public class XmlBeansCompCheckinTests extends CompileTestBase
 {   public final List xm_errors = new ArrayList();
     public final XmlOptions xm_opts = new XmlOptions();
-    final Vector expBinType = new Vector();
-    final Vector expSrcType = new Vector();
+    final List<String> expBinType;
+    final List<String> expSrcType;
 
     public XmlBeansCompCheckinTests() {
-        expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/atypedb57type.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/elname429edoctype.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/elnameelement.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/index.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/element/http_3A_2F_2Fbaz/elName.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/type/http_3A_2F_2Fbaz/aType.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/namespace/http_3A_2F_2Fbaz/xmlns.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/javaname/baz/ElNameDocument.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/javaname/baz/AType.xsb");
-        expBinType.add("org/apache/xmlbeans/metadata/system/apiCompile/TypeSystemHolder.class");
-
-        expSrcType.add("baz.AType");
-        expSrcType.add("baz.impl.ATypeImpl");
-        expSrcType.add("baz.ElNameDocument");
-        expSrcType.add("baz.impl.ElNameDocumentImpl");
+        expBinType = Arrays.asList(
+            "org/apache/xmlbeans/metadata/system/apiCompile/atypedb57type.xsb",
+            "org/apache/xmlbeans/metadata/system/apiCompile/elname429edoctype.xsb",
+            "org/apache/xmlbeans/metadata/system/apiCompile/elnameelement.xsb",
+            "org/apache/xmlbeans/metadata/system/apiCompile/index.xsb",
+            "org/apache/xmlbeans/metadata/element/http_3A_2F_2Fbaz/elName.xsb",
+            "org/apache/xmlbeans/metadata/type/http_3A_2F_2Fbaz/aType.xsb",
+            "org/apache/xmlbeans/metadata/namespace/http_3A_2F_2Fbaz/xmlns.xsb",
+            "org/apache/xmlbeans/metadata/javaname/baz/ElNameDocument.xsb",
+            "org/apache/xmlbeans/metadata/javaname/baz/AType.xsb"
+        );
+
+        expSrcType = Arrays.asList(
+            "org.apache.xmlbeans.metadata.system.apiCompile.TypeSystemHolder",
+            "baz.AType",
+            "baz.impl.ATypeImpl",
+            "baz.ElNameDocument",
+            "baz.impl.ElNameDocumentImpl"
+        );
 
         xm_opts.setErrorListener(xm_errors);
         xm_opts.setSavePrettyPrint();
@@ -89,11 +91,8 @@ public class XmlBeansCompCheckinTests ex
         if (!f.isCreateSourceFile())
             throw new Exception("Source File method not invoked");
 
-        System.out.println("BIN");
-        CompileCommon.comparefNameVectors(f.getBinFileVec(), expBinType);
-        System.out.println("SRC");
-        CompileCommon.comparefNameVectors(f.getSrcFileVec(), expSrcType);
-
+        comparefNameVectors(f.getBinFileVec(), expBinType);
+        comparefNameVectors(f.getSrcFileVec(), expSrcType);
     }
 
     /**
@@ -102,16 +101,11 @@ public class XmlBeansCompCheckinTests ex
     @Test
     public void test_sts_noSave() throws Exception
     {
-        XmlObject obj1 = XmlObject.Factory.parse(forXsd);
-        XmlObject[] schemas = new XmlObject[]{obj1};
-        XmlObject obj2 = XmlObject.Factory.parse(incrXsd);
-        XmlObject[] schemas2 = new XmlObject[]{obj2};
         XmlObject obj3 = XmlObject.Factory.parse(errXsd);
         XmlObject[] schemas3 = new XmlObject[]{obj3};
 
         SchemaTypeSystem sts;
-        TestFiler f = new TestFiler();
-        ArrayList err = new ArrayList();
+        ArrayList<XmlError> err = new ArrayList<>();
         XmlOptions opt = new XmlOptions().setErrorListener(err);
         opt.setCompilePartialTypesystem();
 
@@ -124,13 +118,11 @@ public class XmlBeansCompCheckinTests ex
             // print out the recovered xm_errors
             if (!err.isEmpty()) {
                 System.out.println("Schema invalid: partial schema type system recovered");
-                for (Iterator i = err.iterator(); i.hasNext();) {
-                    XmlError xErr = (XmlError) i.next();
+                for (XmlError xErr : err) {
                     System.out.println(xErr);
 
                     if ((xErr.getErrorCode().compareTo("src-resolve") == 0) &&
-                            (xErr.getMessage().compareTo("type 'bType@http://baz' not found.") ==
-                            0))
+                        (xErr.getMessage().compareTo("type 'bType@http://baz' not found.") == 0))
                         psom_expError = true;
                 }
             }
@@ -144,8 +136,7 @@ public class XmlBeansCompCheckinTests ex
             if (err.isEmpty())
                 System.err.println(e.getMessage());
             else
-                for (Iterator i = err.iterator(); i.hasNext();)
-                    System.err.println(i.next());
+                for (Object o : err) System.err.println(o);
             throw e;
         }
 
@@ -191,12 +182,8 @@ public class XmlBeansCompCheckinTests ex
         }
 
         //make sure nothing was written
-        assertTrue("Filer -Bin- Partial SOM " +
-            "output dir needed to be empty",
-            tf.getBinFileVec().size() == 0);
-        assertTrue("Filer -SRC- Partial SOM " +
-            "output dir needed to be empty",
-            tf.getSrcFileVec().size() == 0);
+        assertEquals("Filer -Bin- Partial SOM output dir needed to be empty", 0, tf.getBinFileVec().size());
+        assertEquals("Filer -SRC- Partial SOM output dir needed to be empty", 0, tf.getSrcFileVec().size());
 
         assertFalse("Filer Create Source File " +
             "method should not have been invoked",
@@ -207,41 +194,27 @@ public class XmlBeansCompCheckinTests ex
             tf.isCreateBinaryFile());
 
         // Check using filer in partial SOM compilation
-        try {
-            tf = new TestFiler();
+        tf = new TestFiler();
 
-            assertTrue("Filer Source should have been size 0",
-                    tf.getBinFileVec().size() == 0);
+        assertEquals("Filer Source should have been size 0", 0, tf.getBinFileVec().size());
 
-            //reset data
-            sts = null;
-            err.clear();
+        //reset data
+        sts = null;
+        err.clear();
 
-            //filer methods on partial SOM should not be returned
-            sts = XmlBeans.compileXmlBeans(null,
-                    null, schemas3, null,
-                    XmlBeans.getBuiltinTypeSystem(), tf, opt);
+        //filer methods on partial SOM should not be returned
+        sts = XmlBeans.compileXmlBeans(null,
+                null, schemas3, null,
+                XmlBeans.getBuiltinTypeSystem(), tf, opt);
 
-            assertTrue("Errors was not empty", !err.isEmpty());
-            //make sure nothing was written
-            assertTrue("Filer -Bin- Partial SOM " +
-                    "output dir needed to be empty",
-                    tf.getBinFileVec().size() == 0);
-            assertTrue("Filer -SRC- Partial SOM " +
-                    "output dir needed to be empty",
-                    tf.getSrcFileVec().size() == 0);
-
-            assertFalse("Filer Create Source File " +
-                    "method should not have been invoked",
-                    tf.isCreateSourceFile());
-
-            assertFalse("Filer Create Binary File " +
-                    "method should not have been invoked",
-                    tf.isCreateBinaryFile());
-        } catch (Exception e) {
-            throw e;
-        }
+        assertFalse("Errors was not empty", err.isEmpty());
+        //make sure nothing was written
+        assertEquals("Filer -Bin- Partial SOM output dir needed to be empty", 0, tf.getBinFileVec().size());
+        assertEquals("Filer -SRC- Partial SOM output dir needed to be empty", 0, tf.getSrcFileVec().size());
+
+        assertFalse("Filer Create Source File method should not have been invoked", tf.isCreateSourceFile());
 
+        assertFalse("Filer Create Binary File method should not have been invoked", tf.isCreateBinaryFile());
 
         System.out.println("Save Verification passed");
 
@@ -257,8 +230,6 @@ public class XmlBeansCompCheckinTests ex
         XmlObject obj1 = XmlObject.Factory.parse(forXsd);
         XmlObject[] schemas = new XmlObject[]{obj1};
 
-        TestFiler f = new TestFiler();
-
         SchemaTypeSystem apiSts = XmlBeans.compileXmlBeans(null, null,
                 schemas, null, XmlBeans.getBuiltinTypeSystem(), null, null);
         System.out.println("Name: " + apiSts.getName());
@@ -297,4 +268,31 @@ public class XmlBeansCompCheckinTests ex
 
     }
 
+
+    /** compare contents of two vectors */
+    private static void comparefNameVectors(List<String> act, List<String> exp) throws Exception {
+        if (exp == null) {
+            throw new Exception("Exp was null");
+        }
+        if (act == null) {
+            throw new Exception("Act was null");
+        }
+
+        if (exp.size() != act.size()) {
+            throw new Exception("Size was not the same exp.size:" + exp.size() + " act.size:" + act.size());
+        }
+
+        //use Vector.equals to compare
+        if (!act.equals(exp)) {
+            throw new Exception("Expected FNames did Not Match");
+        }
+
+        //check sequence is as expected (not sure if vector.equals does this
+        for (int i = 0; i < exp.size(); i++) {
+            if (!exp.get(i).equals(act.get(i))) {
+                throw new Exception("Item[" + i + "]-was not as expected" +
+                                    "ACT[" + i + "]-" + act.get(i) + " != EXP[" + i + "]-" + exp.get(i));
+            }
+        }
+    }
 }

Modified: xmlbeans/trunk/src/test/java/compile/scomp/common/CompileCommon.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/compile/scomp/common/CompileCommon.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/compile/scomp/common/CompileCommon.java (original)
+++ xmlbeans/trunk/src/test/java/compile/scomp/common/CompileCommon.java Mon Apr 26 21:55:27 2021
@@ -16,33 +16,8 @@ package compile.scomp.common;
 
 import common.Common;
 
-import java.util.Vector;
-
 public class CompileCommon extends Common{
 
     public static String fileLocation = XBEAN_CASE_ROOT +P + "compile" + P + "scomp" + P;
 
-    /** compare contents of two vectors */
-    public static void comparefNameVectors(Vector act, Vector exp) throws Exception
-    {
-        if (exp == null)
-            throw new Exception("Exp was null");
-        if (act == null)
-            throw new Exception("Act was null");
-
-        if (exp.size() != act.size())
-            throw new Exception("Size was not the same exp.size:" + exp.size() + " act.size:" + act.size());
-
-        //use Vector.equals to compare
-        if (!act.equals(exp))
-            throw new Exception("Expected FNames did Not Match");
-
-        //check sequence is as expected (not sure if vector.equals does this
-        for (int i = 0; i < exp.size(); i++) {
-            if (!exp.get(i).equals(act.get(i)))
-                throw new Exception("Item[" + i + "]-was not as expected" +
-                        "ACT[" + i + "]-" + act.get(i) + " != EXP[" + i + "]-" + exp.get(i));
-        }
-    }
-
 }

Modified: xmlbeans/trunk/src/test/java/compile/scomp/common/mockobj/TestFiler.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/test/java/compile/scomp/common/mockobj/TestFiler.java?rev=1889220&r1=1889219&r2=1889220&view=diff
==============================================================================
--- xmlbeans/trunk/src/test/java/compile/scomp/common/mockobj/TestFiler.java (original)
+++ xmlbeans/trunk/src/test/java/compile/scomp/common/mockobj/TestFiler.java Mon Apr 26 21:55:27 2021
@@ -14,75 +14,62 @@
  */
 package compile.scomp.common.mockobj;
 
+import common.Common;
 import org.apache.xmlbeans.Filer;
 import org.apache.xmlbeans.impl.util.FilerImpl;
 
 import java.io.File;
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.Writer;
-import java.util.Vector;
-import common.Common;
+import java.util.ArrayList;
+import java.util.List;
 
-/**
- *
- *
- */
-public class TestFiler implements Filer
-{
-    private String P = File.separator;
-    private FilerImpl impl;
+public class TestFiler implements Filer {
+    private final FilerImpl impl;
     private boolean isCreateBinaryFile;
     private boolean isCreateSourceFile;
-    private Vector binFileVec;
-    private Vector srcFileVec;
+    private final List<String> binFileVec = new ArrayList<>();
+    private final List<String> srcFileVec = new ArrayList<>();
 
-    public TestFiler()
-    {
+    public TestFiler() {
+        String p = File.separator;
         String base = new File(Common.OUTPUTROOT).getAbsolutePath() +
-                P + "filer" + P;
+                      p + "filer" + p;
         String sClass = base + "classes";
         String sSrc = base + "src";
         File fClass = new File(sClass);
         File fSrc = new File(sSrc);
         impl = new FilerImpl(fClass, fSrc, null, true, false);
-        binFileVec = new Vector();
-        srcFileVec = new Vector();
     }
 
-    public OutputStream createBinaryFile(String typename) throws IOException
-    {
+    public OutputStream createBinaryFile(String typename) throws IOException {
         System.out.println("BFS: TypeName: " + typename);
         isCreateBinaryFile = true;
         binFileVec.add(typename);
         return impl.createBinaryFile(typename);
     }
 
-    public Writer createSourceFile(String typename) throws IOException
-    {
+    public Writer createSourceFile(String typename) throws IOException {
         System.out.println("SF: TypeName: " + typename);
         srcFileVec.add(typename);
         isCreateSourceFile = true;
         return impl.createSourceFile(typename);
     }
 
-    public boolean isCreateBinaryFile()
-    {
+    public boolean isCreateBinaryFile() {
         return isCreateBinaryFile;
     }
 
-    public boolean isCreateSourceFile()
-    {
+    public boolean isCreateSourceFile() {
         return isCreateSourceFile;
     }
 
-    public Vector getBinFileVec()
-    {
+    public List<String> getBinFileVec() {
         return binFileVec;
     }
 
-    public Vector getSrcFileVec()
-    {
+    public List<String> getSrcFileVec() {
         return srcFileVec;
     }
 }
\ No newline at end of file



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