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 2020/09/12 23:25:46 UTC

svn commit: r1881669 [1/2] - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans: ./ impl/tool/ impl/util/ impl/values/

Author: kiwiwings
Date: Sat Sep 12 23:25:46 2020
New Revision: 1881669

URL: http://svn.apache.org/viewvc?rev=1881669&view=rev
Log:
spotbugs fixes and cleanups

Modified:
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlBeans.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Diff.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Extension.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/RunXQuery.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XMLBeanXSTCHarness.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XSTCTester.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/util/FilerImpl.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/JavaBase64Holder.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlBeans.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlBeans.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlBeans.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlBeans.java Sat Sep 12 23:25:46 2020
@@ -33,8 +33,7 @@ import java.lang.reflect.Field;
  * for managing XML Bean types, type systems, QNames, paths,
  * and queries.
  */
-public final class XmlBeans
-{
+public final class XmlBeans {
     private static final String HOLDER_CLASS_NAME = "TypeSystemHolder";
     private static final String TYPE_SYSTEM_FIELD = "typeSystem";
 
@@ -42,8 +41,7 @@ public final class XmlBeans
     private static String XMLBEANS_VERSION = "4.0.0";
     private static String XMLBEANS_VENDOR = "Apache Software Foundation";
 
-    static
-    {
+    static {
         Package pkg = XmlBeans.class.getPackage();
         if (pkg != null && pkg.getImplementationVersion() != null) {
             XMLBEANS_TITLE = pkg.getImplementationTitle();
@@ -57,8 +55,7 @@ public final class XmlBeans
      * the value of
      * {@link Package#getImplementationTitle() XmlBeans.class.getPackage().getImplementationTitle()}.
      */
-    public static final String getTitle()
-    {
+    public static final String getTitle() {
         return XMLBEANS_TITLE;
     }
 
@@ -67,8 +64,7 @@ public final class XmlBeans
      * the value of
      * {@link Package#getImplementationVendor() XmlBeans.class.getPackage().getImplementationVendor()}.
      */
-    public static final String getVendor()
-    {
+    public static final String getVendor() {
         return XMLBEANS_VENDOR;
     }
 
@@ -77,8 +73,7 @@ public final class XmlBeans
      * the value of
      * {@link Package#getImplementationVersion() XmlBeans.class.getPackage().getImplementationVersion()}.
      */
-    public static final String getVersion()
-    {
+    public static final String getVersion() {
         return XMLBEANS_VERSION;
     }
 
@@ -86,11 +81,9 @@ public final class XmlBeans
      * Thread local QName cache for general use
      */
     private static final ThreadLocal _threadLocalLoaderQNameCache =
-        new ThreadLocal()
-        {
-            protected Object initialValue()
-            {
-                return new SoftReference(new QNameCache( 32 ));
+        new ThreadLocal() {
+            protected Object initialValue() {
+                return new SoftReference(new QNameCache(32));
             }
         };
 
@@ -102,13 +95,11 @@ public final class XmlBeans
     /**
      * Returns a thread local QNameCache
      */
-    public static QNameCache getQNameCache ( )
-    {
-        SoftReference softRef = (SoftReference)_threadLocalLoaderQNameCache.get();
+    public static QNameCache getQNameCache() {
+        SoftReference softRef = (SoftReference) _threadLocalLoaderQNameCache.get();
         QNameCache qnameCache = (QNameCache) (softRef).get();
-        if (qnameCache==null)
-        {
-            qnameCache = new QNameCache( 32 );
+        if (qnameCache == null) {
+            qnameCache = new QNameCache(32);
             _threadLocalLoaderQNameCache.set(new SoftReference(qnameCache));
         }
         return qnameCache;
@@ -117,23 +108,20 @@ public final class XmlBeans
     /**
      * Obtains a name from the thread local QNameCache
      */
-    public static QName getQName ( String localPart )
-    {
-        return getQNameCache().getName( "",  localPart );
+    public static QName getQName(String localPart) {
+        return getQNameCache().getName("", localPart);
     }
 
     /**
      * Obtains a name from the thread local QNameCache
      */
 
-    public static QName getQName ( String namespaceUri, String localPart )
-    {
-        return getQNameCache().getName( namespaceUri,  localPart );
+    public static QName getQName(String namespaceUri, String localPart) {
+        return getQNameCache().getName(namespaceUri, localPart);
     }
 
-    private static RuntimeException causedException ( RuntimeException e, Throwable cause )
-    {
-        e.initCause( cause );
+    private static RuntimeException causedException(RuntimeException e, Throwable cause) {
+        e.initCause(cause);
 
         return e;
     }
@@ -142,9 +130,8 @@ public final class XmlBeans
      * Compiles an XPath, returning a String equal to that which was passed,
      * but whose identity is that of one which has been precompiled and cached.
      */
-    public static String compilePath ( String pathExpr ) throws XmlException
-    {
-        return compilePath( pathExpr, null );
+    public static String compilePath(String pathExpr) throws XmlException {
+        return compilePath(pathExpr, null);
     }
 
     /**
@@ -153,24 +140,22 @@ public final class XmlBeans
      * takes an option for specifying text that indicates the name of context node.
      * The default is "this", as in "$this".
      *
-     * @param  options  Options for the path. For example, you can call
-     * the {@link XmlOptions#setXqueryCurrentNodeVar(String) XmlOptions.setXqueryCurrentNodeVar(String)}
-     * method to specify a particular name for the expression
-     * variable that indicates the context node.
-     */
-    public static String compilePath ( String pathExpr, XmlOptions options )
-        throws XmlException
-    {
-        return getContextTypeLoader().compilePath( pathExpr, options );
+     * @param options Options for the path. For example, you can call
+     *                the {@link XmlOptions#setXqueryCurrentNodeVar(String) XmlOptions.setXqueryCurrentNodeVar(String)}
+     *                method to specify a particular name for the expression
+     *                variable that indicates the context node.
+     */
+    public static String compilePath(String pathExpr, XmlOptions options)
+        throws XmlException {
+        return getContextTypeLoader().compilePath(pathExpr, options);
     }
 
     /**
      * Compiles an XQuery, returning a String equal to that which was passed,
      * but whose identity is that of one which has been precompiled and cached.
      */
-    public static String compileQuery ( String queryExpr ) throws XmlException
-    {
-        return compileQuery( queryExpr, null );
+    public static String compileQuery(String queryExpr) throws XmlException {
+        return compileQuery(queryExpr, null);
     }
 
     /**
@@ -178,17 +163,16 @@ public final class XmlBeans
      * but whose identity is that of one which has been precompiled and cached;
      * takes an option for specifying text that indicates the context node.
      *
-     * @param  options  Options for the query. For example, you can call
-     * the {@link XmlOptions#setXqueryCurrentNodeVar(String) XmlOptions.setXqueryCurrentNodeVar(String)}
-     * method to specify a particular name for the expression
-     * variable that indicates the context node and the
-     * {@link XmlOptions#setXqueryVariables(java.util.Map) XmlOptions.setXqueryVariables(Map)}
-     * method to map external variable names to values.
-     */
-    public static String compileQuery ( String queryExpr, XmlOptions options )
-        throws XmlException
-    {
-        return getContextTypeLoader().compileQuery( queryExpr, options );
+     * @param options Options for the query. For example, you can call
+     *                the {@link XmlOptions#setXqueryCurrentNodeVar(String) XmlOptions.setXqueryCurrentNodeVar(String)}
+     *                method to specify a particular name for the expression
+     *                variable that indicates the context node and the
+     *                {@link XmlOptions#setXqueryVariables(java.util.Map) XmlOptions.setXqueryVariables(Map)}
+     *                method to map external variable names to values.
+     */
+    public static String compileQuery(String queryExpr, XmlOptions options)
+        throws XmlException {
+        return getContextTypeLoader().compileQuery(queryExpr, options);
     }
 
     /**
@@ -215,28 +199,28 @@ public final class XmlBeans
     /**
      * Creates an XmlCursor for a DOM node which is implemented by XmlBwans
      */
-    public static XmlCursor nodeToCursor ( Node n ) {
+    public static XmlCursor nodeToCursor(Node n) {
         return Locale.nodeToCursor(n);
     }
 
     /**
      * Creates an XmlObject for a DOM node which is implemented by XmlBwans
      */
-    public static XmlObject nodeToXmlObject ( Node n ) {
+    public static XmlObject nodeToXmlObject(Node n) {
         return Locale.nodeToXmlObject(n);
     }
 
     /**
      * Creates an XmlObject for a DOM node which is implemented by XmlBwans
      */
-    public static XMLStreamReader nodeToXmlStreamReader ( Node n ) {
+    public static XMLStreamReader nodeToXmlStreamReader(Node n) {
         return Locale.nodeToXmlStream(n);
     }
 
     /**
      * Returns the XmlObject for a DOM node which is implemented by XmlBwans
      */
-    public static Node streamToNode ( XMLStreamReader xs ) {
+    public static Node streamToNode(XMLStreamReader xs) {
         return Locale.streamToNode(xs);
     }
 
@@ -248,8 +232,7 @@ public final class XmlBeans
      * linking, and returns a unioned typeloader that is suitable for
      * creating instances.
      */
-    public static SchemaTypeLoader loadXsd(XmlObject[] schemas) throws XmlException
-    {
+    public static SchemaTypeLoader loadXsd(XmlObject[] schemas) throws XmlException {
         return loadXsd(schemas, null);
     }
 
@@ -306,12 +289,11 @@ public final class XmlBeans
      * as described in {@link XmlOptions#setCompileNoValidation}.</li>
      * </ul>
      *
-     * @param schemas The schema definitions from which to build the schema type system.
+     * @param schemas  The schema definitions from which to build the schema type system.
      * @param typepath The path to already-compiled schema types for linking while processing.
-     * @param options Options specifying an error listener and/or validation behavior.
+     * @param options  Options specifying an error listener and/or validation behavior.
      */
-    public static SchemaTypeSystem compileXsd(XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException
-    {
+    public static SchemaTypeSystem compileXsd(XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException {
         return compileXmlBeans(null, null, schemas, null, typepath, null, options);
     }
 
@@ -354,12 +336,11 @@ public final class XmlBeans
      * as described in {@link XmlOptions#setCompileNoValidation}.</li>
      * </ul>
      *
-     * @param schemas The schema definitions from which to build the schema type system.
+     * @param schemas  The schema definitions from which to build the schema type system.
      * @param typepath The path to already-compiled schema types for linking while processing.
-     * @param options Options specifying an error listener and/or validation behavior.
+     * @param options  Options specifying an error listener and/or validation behavior.
      */
-    public static SchemaTypeSystem compileXsd(SchemaTypeSystem system, XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException
-    {
+    public static SchemaTypeSystem compileXsd(SchemaTypeSystem system, XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException {
         return compileXmlBeans(null, system, schemas, null, typepath, null, options);
     }
 
@@ -414,13 +395,13 @@ public final class XmlBeans
      * as described in {@link XmlOptions#setCompileNoValidation}.</li>
      * </ul>
      *
-     * @param name The type system name or null to use a randomly generated name.
-     * @param system A pre-existing SchemaTypeSystem used in incremental compilation.
-     * @param schemas The schema definitions from which to build the schema type system.
-     * @param config The configuration controls the code generation shape.
+     * @param name     The type system name or null to use a randomly generated name.
+     * @param system   A pre-existing SchemaTypeSystem used in incremental compilation.
+     * @param schemas  The schema definitions from which to build the schema type system.
+     * @param config   The configuration controls the code generation shape.
      * @param typepath The path to already-compiled schema types for linking while processing.
-     * @param filer The Filer instance used to create binary binding files and source text files.
-     * @param options Options specifying an error listener and/or validation behavior.
+     * @param filer    The Filer instance used to create binary binding files and source text files.
+     * @param options  Options specifying an error listener and/or validation behavior.
      */
     public static SchemaTypeSystem compileXmlBeans(String name, SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config, SchemaTypeLoader typepath, Filer filer, XmlOptions options) throws XmlException {
         return SchemaTypeSystemCompiler.compile(name, system, schemas, config, typepath != null ? typepath : getContextTypeLoader(), filer, options);
@@ -461,40 +442,31 @@ public final class XmlBeans
      * Note: you will almost always need typeLoaderForClassLoader()
      * instead (see {@link XmlBeans#typeLoaderForClassLoader}).
      */
-    public static SchemaTypeSystem typeSystemForClassLoader(ClassLoader loader, String stsName)
-    {
-        try
-        {
+    public static SchemaTypeSystem typeSystemForClassLoader(ClassLoader loader, String stsName) {
+        try {
             ClassLoader cl = loader == null ? Thread.currentThread().getContextClassLoader() : loader;
             Class clazz = cl.loadClass(stsName + "." + HOLDER_CLASS_NAME);
             SchemaTypeSystem sts = (SchemaTypeSystem)
                 (clazz.getDeclaredField(TYPE_SYSTEM_FIELD).get(null));
-            if (sts == null)
-            {
+            if (sts == null) {
                 throw new RuntimeException("SchemaTypeSystem is null for field " +
-                    TYPE_SYSTEM_FIELD + " on class with name " + stsName +
-                    "." + HOLDER_CLASS_NAME +
-                    ". Please verify the version of xmlbeans.jar is correct.");
+                                           TYPE_SYSTEM_FIELD + " on class with name " + stsName +
+                                           "." + HOLDER_CLASS_NAME +
+                                           ". Please verify the version of xmlbeans.jar is correct.");
             }
             return sts;
-        }
-        catch (ClassNotFoundException e)
-        {
+        } catch (ClassNotFoundException e) {
             throw causedException(new RuntimeException("Cannot load SchemaTypeSystem. " +
-                "Unable to load class with name " + stsName + "." + HOLDER_CLASS_NAME +
-                ". Make sure the generated binary files are on the classpath."), e);
-        }
-        catch (NoSuchFieldException e)
-        {
+                                                       "Unable to load class with name " + stsName + "." + HOLDER_CLASS_NAME +
+                                                       ". Make sure the generated binary files are on the classpath."), e);
+        } catch (NoSuchFieldException e) {
             throw causedException(new RuntimeException("Cannot find field " +
-                TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
-                ". Please verify the version of xmlbeans.jar is correct."), e);
-        }
-        catch (IllegalAccessException e)
-        {
+                                                       TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
+                                                       ". Please verify the version of xmlbeans.jar is correct."), e);
+        } catch (IllegalAccessException e) {
             throw causedException(new RuntimeException("Field " +
-                TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
-                "is not accessible. Please verify the version of xmlbeans.jar is correct."), e);
+                                                       TYPE_SYSTEM_FIELD + " on class " + stsName + "." + HOLDER_CLASS_NAME +
+                                                       "is not accessible. Please verify the version of xmlbeans.jar is correct."), e);
         }
     }
 
@@ -510,22 +482,20 @@ public final class XmlBeans
      * Returns the SchemaType from a corresponding XmlObject subclass,
      * or null if none.
      */
-    public static SchemaType typeForClass(Class c)
-    {
-        if (c == null || !XmlObject.class.isAssignableFrom(c))
+    public static SchemaType typeForClass(Class c) {
+        if (c == null || !XmlObject.class.isAssignableFrom(c)) {
             return null;
+        }
 
-        try
-        {
+        try {
             Field typeField = c.getField("type");
 
-            if (typeField == null)
+            if (typeField == null) {
                 return null;
+            }
 
-            return (SchemaType)typeField.get(null);
-        }
-        catch (Exception e)
-        {
+            return (SchemaType) typeField.get(null);
+        } catch (Exception e) {
             return null;
         }
     }
@@ -544,7 +514,8 @@ public final class XmlBeans
      * which is the universal base type from which all other types
      * can be derived, and of which all instances are valid.)
      */
-    public static SchemaType NO_TYPE = getNoType();
+    public static final SchemaType NO_TYPE = getNoType();
 
-    private XmlBeans ( ) { }
+    private XmlBeans() {
+    }
 }

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Diff.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Diff.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Diff.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Diff.java Sat Sep 12 23:25:46 2020
@@ -19,69 +19,56 @@ import org.apache.xmlbeans.SystemPropert
 import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
 
 import java.io.*;
-import java.util.List;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.ArrayList;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
-import java.util.Enumeration;
 import java.util.zip.ZipEntry;
 
-public class Diff
-{
-    public static void main(String[] args)
-    {
-        if (args.length != 2)
-        {
+public class Diff {
+    public static void main(String[] args) {
+        if (args.length != 2) {
             System.out.println("Usage: diff <jarname1> <jarname2> to compare two jars");
             System.out.println("  or   diff <dirname1> <dirname2> to compare two dirs");
             return;
         }
         File file1 = new File(args[0]);
-        if (!file1.exists())
-        {
+        if (!file1.exists()) {
             System.out.println("File \"" + args[0] + "\" not found.");
             return;
         }
         File file2 = new File(args[1]);
-        if (!file2.exists())
-        {
+        if (!file2.exists()) {
             System.out.println("File \"" + args[1] + "\" not found.");
             return;
         }
-        List result = new ArrayList();
-        if (file1.isDirectory())
-        {
-            if (!file2.isDirectory())
-            {
+        List<String> result = new ArrayList<>();
+        if (file1.isDirectory()) {
+            if (!file2.isDirectory()) {
                 System.out.println("Both parameters have to be directories if the first parameter is a directory.");
                 return;
             }
             dirsAsTypeSystems(file1, file2, result);
-        }
-        else
-        {
-            if (file2.isDirectory())
-            {
+        } else {
+            if (file2.isDirectory()) {
                 System.out.println("Both parameters have to be jar files if the first parameter is a jar file.");
                 return;
             }
-            try
-            {
-            JarFile jar1 = new JarFile(file1);
-            JarFile jar2 = new JarFile(file2);
-            jarsAsTypeSystems(jar1, jar2, result);
+            try {
+                JarFile jar1 = new JarFile(file1);
+                JarFile jar2 = new JarFile(file2);
+                jarsAsTypeSystems(jar1, jar2, result);
+            } catch (IOException ioe) {
+                ioe.printStackTrace();
             }
-            catch (IOException ioe)
-            { ioe.printStackTrace(); }
         }
-        if (result.size() < 1)
+        if (result.size() < 1) {
             System.out.println("No differences encountered.");
-        else
-        {
+        } else {
             System.out.println("Differences:");
-            for (int i = 0; i < result.size(); i++)
-                System.out.println(result.get(i).toString());
+            for (String s : result) {
+                System.out.println(s);
+            }
         }
     }
 
@@ -89,69 +76,61 @@ public class Diff
      * Diffs the contents of two jars, looking only at the schema typesystems
      * saved inside those jars
      */
-    public static void jarsAsTypeSystems(JarFile jar1, JarFile jar2, List diffs)
-    {
-        Enumeration entries1 = jar1.entries();
-        Enumeration entries2 = jar2.entries();
-        List list1 = new ArrayList();
-        List list2 = new ArrayList();
-        for (; entries1.hasMoreElements(); )
-        {
-            ZipEntry ze = (ZipEntry) entries1.nextElement();
+    public static void jarsAsTypeSystems(JarFile jar1, JarFile jar2, List<String> diffs) {
+        Enumeration<JarEntry> entries1 = jar1.entries();
+        Enumeration<JarEntry> entries2 = jar2.entries();
+        List<ZipEntry> list1 = new ArrayList<>();
+        List<ZipEntry> list2 = new ArrayList<>();
+        while (entries1.hasMoreElements()) {
+            ZipEntry ze = entries1.nextElement();
             String name = ze.getName();
-            if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
+            if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb")) {
                 list1.add(ze);
+            }
         }
-        for (; entries2.hasMoreElements(); )
-        {
-            ZipEntry ze = (ZipEntry) entries2.nextElement();
+        while (entries2.hasMoreElements()) {
+            ZipEntry ze = entries2.nextElement();
             String name = ze.getName();
-            if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb"))
+            if (name.startsWith(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system/s") && name.endsWith(".xsb")) {
                 list2.add(ze);
+            }
         }
-        ZipEntry[] files1 = (ZipEntry[]) list1.toArray(new ZipEntry[list1.size()]);
-        ZipEntry[] files2 = (ZipEntry[]) list2.toArray(new ZipEntry[list2.size()]);
-        ZipEntryNameComparator comparator = new ZipEntryNameComparator();
+        ZipEntry[] files1 = list1.toArray(new ZipEntry[0]);
+        ZipEntry[] files2 = list2.toArray(new ZipEntry[0]);
+        Comparator<ZipEntry> comparator = Comparator.comparing(ZipEntry::getName);
         Arrays.sort(files1, comparator);
         Arrays.sort(files2, comparator);
         int i1 = 0;
         int i2 = 0;
-        while (i1 < files1.length && i2 < files2.length)
-        {
+        while (i1 < files1.length && i2 < files2.length) {
             String name1 = files1[i1].getName();
             String name2 = files2[i2].getName();
             int dif = name1.compareTo(name2);
-            if (dif == 0)
-            {
+            if (dif == 0) {
                 // Compare the files
                 zipEntriesAsXsb(files1[i1], jar1, files2[i2], jar2, diffs);
-                i1++; i2++; // Move to next pair
-            }
-            else if (dif < 0)
-            {
+                i1++;
+                i2++; // Move to next pair
+            } else if (dif < 0) {
                 // dir1 contains a file that dir2 doesn't
                 diffs.add("Jar \"" + jar1.getName() + "\" contains an extra file: \"" +
-                    name1 + "\"");
+                          name1 + "\"");
                 i1++;
-            }
-            else if (dif > 0)
-            {
+            } else {
                 // dir2 contains a file that dir1 doesn't
                 diffs.add("Jar \"" + jar2.getName() + "\" contains an extra file: \"" +
-                    name2 + "\"");
+                          name2 + "\"");
                 i2++;
             }
         }
-        while (i1 < files1.length)
-        {
+        while (i1 < files1.length) {
             diffs.add("Jar \"" + jar1.getName() + "\" contains an extra file: \"" +
-                files1[i1].getName() + "\"");
+                      files1[i1].getName() + "\"");
             i1++;
         }
-        while (i2 < files2.length)
-        {
+        while (i2 < files2.length) {
             diffs.add("Jar \"" + jar2.getName() + "\" contains an extra file: \"" +
-                files2[i2].getName() + "\"");
+                      files2[i2].getName() + "\"");
             i2++;
         }
     }
@@ -162,223 +141,155 @@ public class Diff
      * Updated diffs with a list of differences (for the time being, strings
      * describing the difference)
      */
-    public static void dirsAsTypeSystems(File dir1, File dir2, List diffs)
-    {
+    public static void dirsAsTypeSystems(File dir1, File dir2, List<String> diffs) {
         assert dir1.isDirectory() : "Parameters must be directories";
         assert dir2.isDirectory() : "Parameters must be directories";
 
-        /**
-         * Navigate three directories deep to get to the type system.
-         * Assume the schema[METADATA_PACKAGE_LOAD]/system/* structure
+        /*
+          Navigate three directories deep to get to the type system.
+          Assume the schema[METADATA_PACKAGE_LOAD]/system/* structure
          */
         File temp1 = new File(dir1, SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
         File temp2 = new File(dir2, SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/system");
-        if (temp1.exists() && temp2.exists())
-        {
+        if (temp1.exists() && temp2.exists()) {
             File[] files1 = temp1.listFiles();
             File[] files2 = temp2.listFiles();
-            if (files1.length == 1 && files2.length == 1)
-            {
+
+            assert (files1 != null && files2 != null);
+
+            if (files1.length == 1 && files2.length == 1) {
                 temp1 = files1[0];
                 temp2 = files2[0];
-            }
-            else
-            {
-                if (files1.length == 0)
+            } else {
+                if (files1.length == 0) {
                     temp1 = null;
-                if (files2.length == 0)
+                }
+                if (files2.length == 0) {
                     temp2 = null;
-                if (files1.length > 1)
-                {
+                }
+                if (files1.length > 1) {
                     diffs.add("More than one typesystem found in dir \"" +
-                        dir1.getName() + "\"");
+                              dir1.getName() + "\"");
                     return;
                 }
-                if (files2.length > 1)
-                {
+                if (files2.length > 1) {
                     diffs.add("More than one typesystem found in dir \"" +
-                        dir2.getName() + "\"");
+                              dir2.getName() + "\"");
                     return;
-                }                    
+                }
             }
-        }
-        else
-        {
-            if (!temp1.exists())
+        } else {
+            if (!temp1.exists()) {
                 temp1 = null;
-            if (!temp2.exists())
+            }
+            if (!temp2.exists()) {
                 temp2 = null;
+            }
         }
-        if (temp1 == null && temp2 == null)
+        if (temp1 == null && temp2 == null) {
             return;
-        else if (temp1 == null || temp2 == null)
-        {
-            if (temp1 == null)
+        } else if (temp1 == null || temp2 == null) {
+            if (temp1 == null) {
                 diffs.add("No typesystems found in dir \"" + dir1 + "\"");
-            if (temp2 == null)
+            }
+            if (temp2 == null) {
                 diffs.add("No typesystems found in dir \"" + dir2 + "\"");
+            }
             return;
-        }
-        else
-        {
+        } else {
             dir1 = temp1;
             dir2 = temp2;
         }
 
         boolean diffIndex = isDiffIndex();
-        XsbFilenameFilter xsbName = new XsbFilenameFilter();
+        FilenameFilter xsbName = (dir, name) -> name.endsWith(".xsb");
         File[] files1 = dir1.listFiles(xsbName);
         File[] files2 = dir2.listFiles(xsbName);
-        FileNameComparator comparator = new FileNameComparator();
+
+        assert (files1 != null && files2 != null);
+
+        Comparator<File> comparator = Comparator.comparing(File::getName);
         Arrays.sort(files1, comparator);
         Arrays.sort(files2, comparator);
         int i1 = 0;
         int i2 = 0;
-        while (i1 < files1.length && i2 < files2.length)
-        {
+        while (i1 < files1.length && i2 < files2.length) {
             String name1 = files1[i1].getName();
             String name2 = files2[i2].getName();
             int dif = name1.compareTo(name2);
-            if (dif == 0)
-            {
-                if (diffIndex || !files1[i1].getName().equals("index.xsb"))
+            if (dif == 0) {
+                if (diffIndex || !files1[i1].getName().equals("index.xsb")) {
                     filesAsXsb(files1[i1], files2[i2], diffs); // Compare the files
-                i1++; i2++; // Move to next pair
-            }
-            else if (dif < 0)
-            {
+                }
+                i1++;
+                i2++; // Move to next pair
+            } else if (dif < 0) {
                 // dir1 contains a file that dir2 doesn't
                 diffs.add("Dir \"" + dir1.getName() + "\" contains an extra file: \"" +
-                    name1 + "\"");
+                          name1 + "\"");
                 i1++;
-            }
-            else if (dif > 0)
-            {
+            } else {
                 // dir2 contains a file that dir1 doesn't
                 diffs.add("Dir \"" + dir2.getName() + "\" contains an extra file: \"" +
-                    name2 + "\"");
+                          name2 + "\"");
                 i2++;
             }
         }
-        while (i1 < files1.length)
-        {
+        while (i1 < files1.length) {
             diffs.add("Dir \"" + dir1.getName() + "\" contains an extra file: \"" +
-                files1[i1].getName() + "\"");
+                      files1[i1].getName() + "\"");
             i1++;
         }
-        while (i2 < files2.length)
-        {
+        while (i2 < files2.length) {
             diffs.add("Dir \"" + dir2.getName() + "\" contains an extra file: \"" +
-                files2[i2].getName() + "\"");
+                      files2[i2].getName() + "\"");
             i2++;
         }
     }
 
-    private static boolean isDiffIndex()
-    {
+    private static boolean isDiffIndex() {
         String prop = SystemProperties.getProperty("xmlbeans.diff.diffIndex");
-        if (prop == null)
-            return true;
-        if ("0".equals(prop) || "false".equalsIgnoreCase(prop))
-            return false;
-        return true;
+        return prop == null || !"0".equals(prop) && !"false".equalsIgnoreCase(prop);
     }
 
     /**
      * Diffs the two given files assuming they are in xsb format
      * Updates diffs with differences in string format
      */
-    public static void filesAsXsb(File file1, File file2, List diffs)
-    {
+    public static void filesAsXsb(File file1, File file2, List<String> diffs) {
         assert file1.exists() : "File \"" + file1.getAbsolutePath() + "\" does not exist.";
         assert file2.exists() : "File \"" + file2.getAbsolutePath() + "\" does not exist.";
-        try
-        {
-        FileInputStream stream1 = new FileInputStream(file1);
-        FileInputStream stream2 = new FileInputStream(file2);
-        streamsAsXsb(stream1, file1.getName(), stream2, file2.getName(), diffs);
-        }
-        catch (FileNotFoundException fnfe)
-        { }
-        catch (IOException ioe)
-        { }
+        try (FileInputStream stream1 = new FileInputStream(file1);
+             FileInputStream stream2 = new FileInputStream(file2)) {
+            streamsAsXsb(stream1, file1.getName(), stream2, file2.getName(), diffs);
+        } catch (IOException ignored) {
+        }
     }
 
     public static void zipEntriesAsXsb(ZipEntry file1, JarFile jar1,
-        ZipEntry file2, JarFile jar2, List diffs)
-    {
-        try
-        {
-        InputStream stream1 = jar1.getInputStream(file1);
-        InputStream stream2 = jar2.getInputStream(file2);
-        streamsAsXsb(stream1, file1.getName(), stream2, file2.getName(), diffs);
+                                       ZipEntry file2, JarFile jar2, List<String> diffs) {
+        try (InputStream stream1 = jar1.getInputStream(file1);
+             InputStream stream2 = jar2.getInputStream(file2)) {
+            streamsAsXsb(stream1, file1.getName(), stream2, file2.getName(), diffs);
+        } catch (IOException ignored) {
         }
-        catch (IOException ioe)
-        { }
     }
 
     public static void streamsAsXsb(InputStream stream1, String name1,
-        InputStream stream2, String name2, List diffs)
-        throws IOException
-    {
+                                    InputStream stream2, String name2, List<String> diffs)
+        throws IOException {
+        String charset = StandardCharsets.UTF_8.name();
         ByteArrayOutputStream buf1 = new ByteArrayOutputStream();
         ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
-        XsbDumper.dump(stream1, "", new PrintStream(buf1));
-        XsbDumper.dump(stream2, "", new PrintStream(buf2));
-        stream1.close();
-        stream2.close();
-        readersAsText(new StringReader(buf1.toString()), name1,
-            new StringReader(buf2.toString()), name2, diffs);
+        XsbDumper.dump(stream1, "", new PrintStream(buf1, true, charset));
+        XsbDumper.dump(stream2, "", new PrintStream(buf2, true, charset));
+        readersAsText(new StringReader(buf1.toString(charset)), name1,
+            new StringReader(buf2.toString(charset)), name2, diffs);
     }
 
     public static void readersAsText(Reader r1, String name1, Reader r2, String name2,
-        List diffs)
-        throws IOException
-    {
+                                     List<String> diffs)
+        throws IOException {
         org.apache.xmlbeans.impl.util.Diff.readersAsText(r1, name1, r2, name2, diffs);
     }
-
-    private static class XsbFilenameFilter implements FilenameFilter
-    {
-        public boolean accept(File dir, String name)
-        {
-            return name.endsWith(".xsb");
-        }
-    }
-
-    private static class ZipEntryNameComparator implements Comparator
-    {
-        public boolean equals(Object object)
-        {
-            return this == object;
-        }
-
-        public int compare(Object object1, Object object2)
-        {
-            assert (object1 instanceof ZipEntry) : "Must pass in a java.util.zip.ZipEntry as argument";
-            assert (object2 instanceof ZipEntry) : "Must pass in a java.util.zip.ZipEntry as argument";
-
-            String name1 = ((ZipEntry) object1).getName();
-            String name2 = ((ZipEntry) object2).getName();
-            return name1.compareTo(name2);
-        }
-    }
-
-    private static class FileNameComparator implements Comparator
-    {
-        public boolean equals(Object object)
-        {
-            return this == object;
-        }
-
-        public int compare(Object object1, Object object2)
-        {
-            assert (object1 instanceof File) : "Must pass in a java.io.File as argument";
-            assert (object2 instanceof File) : "Must pass in a java.io.File as argument";
-
-            String name1 = ((File) object1).getName();
-            String name2 = ((File) object2).getName();
-            return name1.compareTo(name2);
-        }
-    }
 }

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Extension.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Extension.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Extension.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/Extension.java Sat Sep 12 23:25:46 2020
@@ -15,56 +15,57 @@
 
 package org.apache.xmlbeans.impl.tool;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 
- /**
-  * An extension is a javabean that represents a SchemaCompilerExtension to be passed for callback into the
-  *  XmlBeans Schema Compiler.
-  */
+/**
+ * An extension is a javabean that represents a SchemaCompilerExtension to be passed for callback into the
+ * XmlBeans Schema Compiler.
+ */
 public class Extension {
-        private Class className;
-        private List params = new ArrayList();
+    private Class className;
+    private List<Param> params = new ArrayList<>();
 
-        public Class getClassName() {
-            return className;
-        }
+    public Class getClassName() {
+        return className;
+    }
+
+    public void setClassName(Class className) {
+        this.className = className;
+    }
+
+    public List<Param> getParams() {
+        return params;
+    }
+
+    public Param createParam() {
+        Param p = new Param();
+        params.add(p);
+        return p;
+    }
+
+    /**
+     * A Param is just a name value pair applicable to the extension.
+     */
+    public class Param {
+        private String name;
+        private String value;
 
-        public void setClassName(Class className) {
-            this.className = className;
+        public String getName() {
+            return name;
         }
-        public List getParams() {
-            return params;
+
+        public void setName(String name) {
+            this.name = name;
         }
 
-        public Param createParam() {
-            Param p = new Param();
-            params.add(p);
-            return p;
+        public String getValue() {
+            return value;
         }
 
-        /**
-         * A Param is just a name value pair applicable to the extension.
-         */
-        public class Param {
-            private String name;
-            private String value;
-
-            public String getName() {
-                return name;
-            }
-
-            public void setName(String name) {
-                this.name = name;
-            }
-
-            public String getValue() {
-                return value;
-            }
-
-            public void setValue(String value) {
-                this.value = value;
-            }
+        public void setValue(String value) {
+            this.value = value;
         }
-    }
\ No newline at end of file
+    }
+}
\ No newline at end of file

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/RunXQuery.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/RunXQuery.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/RunXQuery.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/RunXQuery.java Sat Sep 12 23:25:46 2020
@@ -15,14 +15,21 @@
 
 package org.apache.xmlbeans.impl.tool;
 
-import java.io.*;
-import java.util.*;
-import org.apache.xmlbeans.*;
-
-public class RunXQuery
-{
-    public static void printUsage()
-    {
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class RunXQuery {
+    public static void printUsage() {
         System.out.println("Run an XQuery against an XML instance");
         System.out.println("Usage:");
         System.out.println("xquery [-verbose] [-pretty] [-q <query> | -qf query.xq] [file.xml]*");
@@ -31,12 +38,11 @@ public class RunXQuery
         System.out.println(" -pretty pretty-prints the results");
         System.out.println(" -license prints license information");
         System.out.println(" the query is run on each XML file specified");
-        System.out.println("");
+        System.out.println();
     }
 
-    public static void main ( String[] args ) throws Exception
-    {
-        Set flags = new HashSet();
+    public static void main(String[] args) throws Exception {
+        Set<String> flags = new HashSet<>();
         flags.add("h");
         flags.add("help");
         flags.add("usage");
@@ -48,90 +54,82 @@ public class RunXQuery
         CommandLine cl =
             new CommandLine(
                 args, flags,
-                Arrays.asList( new String[] { "q", "qf" } ) );
-        
-        if (cl.getOpt("h") != null || cl.getOpt("help") != null || cl.getOpt("usage") != null)
-        {
+                Arrays.asList("q", "qf"));
+
+        if (cl.getOpt("h") != null || cl.getOpt("help") != null || cl.getOpt("usage") != null) {
             printUsage();
             System.exit(0);
             return;
         }
 
         String[] badopts = cl.getBadOpts();
-        if (badopts.length > 0)
-        {
-            for (int i = 0; i < badopts.length; i++)
-                System.out.println("Unrecognized option: " + badopts[i]);
+        if (badopts.length > 0) {
+            for (String badopt : badopts) {
+                System.out.println("Unrecognized option: " + badopt);
+            }
             printUsage();
             System.exit(0);
             return;
         }
 
-        if (cl.getOpt("license") != null)
-        {
+        if (cl.getOpt("license") != null) {
             CommandLine.printLicense();
             System.exit(0);
             return;
         }
 
-        if (cl.getOpt("version") != null)
-        {
+        if (cl.getOpt("version") != null) {
             CommandLine.printVersion();
             System.exit(0);
             return;
         }
 
         args = cl.args();
-        
-        if (args.length == 0)
-        {
+
+        if (args.length == 0) {
             printUsage();
             System.exit(0);
             return;
         }
 
-        boolean verbose = cl.getOpt( "verbose" ) != null;
-        boolean pretty = cl.getOpt( "pretty" ) != null;
+        boolean verbose = cl.getOpt("verbose") != null;
+        boolean pretty = cl.getOpt("pretty") != null;
 
         //
         // Get and compile the query
         //
-        
-        String query = cl.getOpt( "q" );
-        String queryfile = cl.getOpt( "qf" );
 
-        if (query == null && queryfile == null)
-        {
-            System.err.println( "No query specified" );
+        String query = cl.getOpt("q");
+        String queryfile = cl.getOpt("qf");
+
+        if (query == null && queryfile == null) {
+            System.err.println("No query specified");
             System.exit(0);
             return;
         }
-        
-        if (query != null && queryfile != null)
-        {
-            System.err.println( "Specify -qf or -q, not both." );
+
+        if (query != null && queryfile != null) {
+            System.err.println("Specify -qf or -q, not both.");
             System.exit(0);
             return;
         }
-        
-        try
-        {
-            if (queryfile != null)
-            {
-                File queryFile = new File( queryfile );
-                FileInputStream is = new FileInputStream( queryFile );
-                InputStreamReader r = new InputStreamReader( is );
-                
+
+        try {
+            if (queryfile != null) {
+                File queryFile = new File(queryfile);
+                FileInputStream is = new FileInputStream(queryFile);
+                InputStreamReader r = new InputStreamReader(is, StandardCharsets.ISO_8859_1);
+
                 StringBuilder sb = new StringBuilder();
 
-                for ( ; ; )
-                {
+                for (; ; ) {
                     int ch = r.read();
 
-                    if (ch < 0)
+                    if (ch < 0) {
                         break;
+                    }
 
-                    sb.append( (char) ch );
+                    sb.append((char) ch);
                 }
 
                 r.close();
@@ -139,28 +137,22 @@ public class RunXQuery
 
                 query = sb.toString();
             }
-        }
-        catch ( Throwable e )
-        {
-            System.err.println( "Cannot read query file: " + e.getMessage() );
+        } catch (Throwable e) {
+            System.err.println("Cannot read query file: " + e.getMessage());
             System.exit(1);
             return;
         }
 
-        if (verbose)
-        {
-            System.out.println( "Compile Query:" );
-            System.out.println( query );
+        if (verbose) {
+            System.out.println("Compile Query:");
+            System.out.println(query);
             System.out.println();
         }
-            
-        try
-        {
-            query= XmlBeans.compileQuery( query );
-        }
-        catch ( Exception e )
-        {
-            System.err.println( "Error compiling query: " + e.getMessage() );
+
+        try {
+            query = XmlBeans.compileQuery(query);
+        } catch (Exception e) {
+            System.err.println("Error compiling query: " + e.getMessage());
             System.exit(1);
             return;
         }
@@ -168,75 +160,65 @@ public class RunXQuery
         //
         // Get the instance
         //
-        
+
         File[] files = cl.getFiles();
-        
-        for (int i = 0; i < files.length; i++)
-        {
+
+        for (File file : files) {
             XmlObject x;
-                
-            try
-            {
-                if (verbose)
-                {
-                    InputStream is = new FileInputStream( files[i] );
 
-                    for ( ; ; )
-                    {
+            try {
+                if (verbose) {
+                    InputStream is = new FileInputStream(file);
+
+                    for (; ; ) {
                         int ch = is.read();
 
-                        if (ch < 0)
+                        if (ch < 0) {
                             break;
+                        }
 
-                        System.out.write( ch );
+                        System.out.write(ch);
                     }
-                    
+
                     is.close();
 
                     System.out.println();
                 }
-                
-                x = XmlObject.Factory.parse( files[i] );
-            }
-            catch ( Throwable e )
-            {
-                System.err.println( "Error parsing instance: " + e.getMessage() );
+
+                x = XmlObject.Factory.parse(file);
+            } catch (Throwable e) {
+                System.err.println("Error parsing instance: " + e.getMessage());
                 System.exit(1);
                 return;
             }
-            
-            if (verbose)
-            {
-                System.out.println( "Executing Query..." );
+
+            if (verbose) {
+                System.out.println("Executing Query...");
                 System.err.println();
             }
-    
-            XmlObject[] result = null;
-    
-            try
-            {
-                result = x.execQuery( query );
-            }
-            catch ( Throwable e )
-            {
-                System.err.println( "Error executing query: " + e.getMessage() );
+
+            XmlObject[] result;
+
+            try {
+                result = x.execQuery(query);
+            } catch (Throwable e) {
+                System.err.println("Error executing query: " + e.getMessage());
                 System.exit(1);
                 return;
             }
-    
-            if (verbose)
-            {
-                System.out.println( "Query Result:" );
+
+            if (verbose) {
+                System.out.println("Query Result:");
             }
-            
+
             XmlOptions opts = new XmlOptions();
             opts.setSaveOuter();
-            if (pretty)
+            if (pretty) {
                 opts.setSavePrettyPrint();
-            
-            for (int j = 0; j < result.length; j++)
-            {
-                result[j].save( System.out, opts );
+            }
+
+            for (XmlObject xmlObject : result) {
+                xmlObject.save(System.out, opts);
                 System.out.println();
             }
         }

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/SchemaCompiler.java Sat Sep 12 23:25:46 2020
@@ -25,6 +25,7 @@ import org.apache.xmlbeans.impl.values.X
 import org.apache.xmlbeans.impl.xb.xmlconfig.ConfigDocument;
 import org.apache.xmlbeans.impl.xb.xmlconfig.Extensionconfig;
 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument.Schema;
 import org.xml.sax.EntityResolver;
 
 import java.io.File;
@@ -141,7 +142,6 @@ public class SchemaCompiler {
             return;
         }
 
-        args = cl.args();
         boolean verbose = (cl.getOpt("verbose") != null);
         boolean quiet = (cl.getOpt("quiet") != null);
         if (verbose) {
@@ -589,20 +589,6 @@ public class SchemaCompiler {
             this.javasource = javasource;
         }
 
-        /**
-         * @deprecated
-         */
-        public String getJar() {
-            return null;
-        }
-
-        /**
-         * @deprecated
-         */
-        public void setJar(String jar) {
-            // no op
-        }
-
         public Collection<XmlError> getErrorListener() {
             return errorListener;
         }
@@ -663,7 +649,7 @@ public class SchemaCompiler {
     private static SchemaTypeSystem loadTypeSystem(String name, File[] xsdFiles, File[] wsdlFiles, URL[] urlFiles, File[] configFiles,
                                                    File[] javaFiles, ResourceLoader cpResourceLoader,
                                                    boolean download, boolean noUpa, boolean noPvr, boolean noAnn, boolean noVDoc, boolean noExt,
-                                                   Set<String> mdefNamespaces, File baseDir, Map sourcesToCopyMap,
+                                                   Set<String> mdefNamespaces, File baseDir, Map<String, String> sourcesToCopyMap,
                                                    Collection<XmlError> outerErrorListener, File schemasDir, EntityResolver entResolver, File[] classpath, String javasource) {
         XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
 
@@ -681,7 +667,7 @@ public class SchemaCompiler {
             SchemaTypeLoader loader = XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
 
             // step 1, parse all the XSD files.
-            ArrayList<SchemaDocument.Schema> scontentlist = new ArrayList<>();
+            ArrayList<Schema> scontentlist = new ArrayList<>();
             if (xsdFiles != null) {
                 for (File xsdFile : xsdFiles) {
                     try {
@@ -766,7 +752,7 @@ public class SchemaCompiler {
                 }
             }
 
-            SchemaDocument.Schema[] sdocs = (SchemaDocument.Schema[]) scontentlist.toArray(new SchemaDocument.Schema[0]);
+            Schema[] sdocs = scontentlist.toArray(new Schema[0]);
 
             // now the config files.
             ArrayList<ConfigDocument.Config> cdoclist = new ArrayList<>();
@@ -855,7 +841,7 @@ public class SchemaCompiler {
     }
 
     private static void addSchema(String name, SchemaDocument schemadoc,
-                                  XmlErrorWatcher errorListener, boolean noVDoc, List<SchemaDocument.Schema> scontentlist) {
+                                  XmlErrorWatcher errorListener, boolean noVDoc, List<Schema> scontentlist) {
         StscState.addInfo(errorListener, "Loading schema file " + name);
         XmlOptions opts = new XmlOptions().setErrorListener(errorListener);
         if (noVDoc) {
@@ -868,7 +854,7 @@ public class SchemaCompiler {
 
     private static void addWsdlSchemas(String name,
                                        org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument wsdldoc,
-                                       XmlErrorWatcher errorListener, boolean noVDoc, List scontentlist) {
+                                       XmlErrorWatcher errorListener, boolean noVDoc, List<Schema> scontentlist) {
         if (wsdlContainsEncoded(wsdldoc)) {
             StscState.addWarning(errorListener, "The WSDL " + name + " uses SOAP encoding. SOAP encoding is not compatible with literal XML Schema.", XmlErrorCodes.GENERIC_ERROR, wsdldoc);
         }
@@ -879,18 +865,17 @@ public class SchemaCompiler {
         }
         XmlObject[] types = wsdldoc.getDefinitions().getTypesArray();
         int count = 0;
-        for (int j = 0; j < types.length; j++) {
-            XmlObject[] schemas = types[j].selectPath("declare namespace xs=\"http://www.w3.org/2001/XMLSchema\" xs:schema");
+        for (XmlObject type : types) {
+            Schema[] schemas = (Schema[]) type.selectPath("declare namespace xs=\"http://www.w3.org/2001/XMLSchema\" xs:schema");
             if (schemas.length == 0) {
                 StscState.addWarning(errorListener, "The WSDL " + name + " did not have any schema documents in namespace 'http://www.w3.org/2001/XMLSchema'", XmlErrorCodes.GENERIC_ERROR, wsdldoc);
                 continue;
             }
 
-            for (int k = 0; k < schemas.length; k++) {
-                if (schemas[k] instanceof SchemaDocument.Schema &&
-                    schemas[k].validate(opts)) {
+            for (Schema schema : schemas) {
+                if (schema.validate(opts)) {
                     count++;
-                    scontentlist.add(schemas[k]);
+                    scontentlist.add(schema);
                 }
             }
         }
@@ -924,7 +909,7 @@ public class SchemaCompiler {
         boolean noVDoc = params.isNoVDoc();
         boolean noExt = params.isNoExt();
         boolean incrSrcGen = params.isIncrementalSrcGen();
-        Collection outerErrorListener = params.getErrorListener();
+        Collection<XmlError> outerErrorListener = params.getErrorListener();
 
         String repackage = params.getRepackage();
 
@@ -941,8 +926,8 @@ public class SchemaCompiler {
         }
 
         SchemaCodePrinter codePrinter = params.getSchemaCodePrinter();
-        List extensions = params.getExtensions();
-        Set mdefNamespaces = params.getMdefNamespaces();
+        List<Extension> extensions = params.getExtensions();
+        Set<String> mdefNamespaces = params.getMdefNamespaces();
 
         EntityResolver cmdLineEntRes = params.getEntityResolver() == null ?
             ResolverUtil.resolverForCatalog(params.getCatalogFile()) : params.getEntityResolver();
@@ -955,12 +940,14 @@ public class SchemaCompiler {
 
         // Calculate the usenames based on the relativized filenames on the filesystem
         if (baseDir == null) {
-            baseDir = new File(SystemProperties.getProperty("user.dir"));
+            String userDir = SystemProperties.getProperty("user.dir");
+            assert (userDir != null);
+            baseDir = new File(userDir);
         }
 
         ResourceLoader cpResourceLoader = null;
 
-        Map sourcesToCopyMap = new HashMap();
+        Map<String, String> sourcesToCopyMap = new HashMap<>();
 
         if (classpath != null) {
             cpResourceLoader = new PathResourceLoader(classpath);
@@ -1005,12 +992,12 @@ public class SchemaCompiler {
             system.save(filer);
 
             // gen source files
-            result &= SchemaTypeSystemCompiler.generateTypes(system, filer, options);
+            result = SchemaTypeSystemCompiler.generateTypes(system, filer, options);
 
             if (incrSrcGen) {
                 // We have to delete extra source files that may be out of date
                 SchemaCodeGenerator.deleteObsoleteFiles(srcDir, srcDir,
-                    new HashSet(filer.getSourceFiles()));
+                    new HashSet<>(filer.getSourceFiles()));
             }
 
             if (result) {
@@ -1024,7 +1011,7 @@ public class SchemaCompiler {
             if (result && !nojavac) {
                 start = System.currentTimeMillis();
 
-                List sourcefiles = filer.getSourceFiles();
+                List<File> sourcefiles = filer.getSourceFiles();
 
                 if (javaFiles != null) {
                     sourcefiles.addAll(java.util.Arrays.asList(javaFiles));
@@ -1067,12 +1054,12 @@ public class SchemaCompiler {
         return result;
     }
 
-    private static void runExtensions(List extensions, SchemaTypeSystem system, File classesDir) {
+    private static void runExtensions(List<Extension> extensions, SchemaTypeSystem system, File classesDir) {
         if (extensions != null && extensions.size() > 0) {
-            SchemaCompilerExtension sce = null;
-            Iterator i = extensions.iterator();
-            Map extensionParms = null;
-            String classesDirName = null;
+            SchemaCompilerExtension sce;
+            Iterator<Extension> i = extensions.iterator();
+            Map<String, String> extensionParms;
+            String classesDirName;
             try {
                 classesDirName = classesDir.getCanonicalPath();
             } catch (java.io.IOException e) {
@@ -1081,7 +1068,7 @@ public class SchemaCompiler {
             }
 
             while (i.hasNext()) {
-                Extension extension = (Extension) i.next();
+                Extension extension = i.next();
                 try {
                     sce = (SchemaCompilerExtension) extension.getClassName().newInstance();
                 } catch (InstantiationException e) {
@@ -1095,10 +1082,8 @@ public class SchemaCompiler {
                 }
 
                 System.out.println("Running Extension: " + sce.getExtensionName());
-                extensionParms = new HashMap();
-                Iterator parmsi = extension.getParams().iterator();
-                while (parmsi.hasNext()) {
-                    Extension.Param p = (Extension.Param) parmsi.next();
+                extensionParms = new HashMap<>();
+                for (Extension.Param p : extension.getParams()) {
                     extensionParms.put(p.getName(), p.getValue());
                 }
                 extensionParms.put("classesDir", classesDirName);
@@ -1113,8 +1098,8 @@ public class SchemaCompiler {
         XmlObject[] useAttrs = wsdldoc.selectPath(
             "declare namespace soap='http://schemas.xmlsoap.org/wsdl/soap/' " +
             ".//soap:body/@use|.//soap:header/@use|.//soap:fault/@use");
-        for (int i = 0; i < useAttrs.length; i++) {
-            if ("encoded".equals(((SimpleValue) useAttrs[i]).getStringValue())) {
+        for (XmlObject useAttr : useAttrs) {
+            if ("encoded".equals(((SimpleValue) useAttr).getStringValue())) {
                 return true;
             }
         }
@@ -1123,10 +1108,6 @@ public class SchemaCompiler {
 
     private static final String CONFIG_URI = "http://xml.apache.org/xmlbeans/2004/02/xbean/config";
     private static final String COMPATIBILITY_CONFIG_URI = "http://www.bea.com/2002/09/xbean/config";
-    private static final Map MAP_COMPATIBILITY_CONFIG_URIS;
-
-    static {
-        MAP_COMPATIBILITY_CONFIG_URIS = new HashMap();
-        MAP_COMPATIBILITY_CONFIG_URIS.put(COMPATIBILITY_CONFIG_URI, CONFIG_URI);
-    }
+    private static final Map<String, String> MAP_COMPATIBILITY_CONFIG_URIS
+        = Collections.singletonMap(COMPATIBILITY_CONFIG_URI, CONFIG_URI);
 }

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XMLBeanXSTCHarness.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XMLBeanXSTCHarness.java?rev=1881669&r1=1881668&r2=1881669&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XMLBeanXSTCHarness.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/XMLBeanXSTCHarness.java Sat Sep 12 23:25:46 2020
@@ -15,95 +15,76 @@
 
 package org.apache.xmlbeans.impl.tool;
 
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.*;
 
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 
-public class XMLBeanXSTCHarness implements XSTCTester.Harness
-{
-    public void runTestCase(XSTCTester.TestCaseResult result)
-    {
+public class XMLBeanXSTCHarness implements XSTCTester.Harness {
+    public void runTestCase(XSTCTester.TestCaseResult result) {
         XSTCTester.TestCase testCase = result.getTestCase();
-        
-        // System.out.println("Running case " + testCase.getDescription());
-        
-        try
-        {
-            Collection errors = new ArrayList();
-            boolean schemaValid = true;
-            boolean instanceValid = true;
-            
-            if (testCase.getSchemaFile() == null)
-                return;
-            
-            // step 1, load schema file etc.
-            SchemaTypeLoader loader = null;
-            try
-            {
-                XmlObject schema = XmlObject.Factory.parse(testCase.getSchemaFile(), new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
-                XmlObject schema2 = null;
-                if (testCase.getResourceFile() != null)
-                    schema2 = XmlObject.Factory.parse(testCase.getResourceFile(), new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
-                XmlObject[] schemas = schema2 == null ? new XmlObject[] { schema } : new XmlObject[] { schema, schema2 };
-                SchemaTypeSystem system = XmlBeans.compileXsd(schemas, XmlBeans.getBuiltinTypeSystem(), new XmlOptions().setErrorListener(errors));
-                loader = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[] { system, XmlBeans.getBuiltinTypeSystem() });
-            }
-            catch (Exception e)
-            {
-                schemaValid = false;
-                if (!(e instanceof XmlException) || errors.isEmpty())
-                {
-                    result.setCrash(true);
-                    StringWriter sw = new StringWriter();
-                    e.printStackTrace(new PrintWriter(sw));
-                    result.addSvMessages(Collections.singleton(sw.toString()));
-                }
+
+        Collection<XmlError> errors = new ArrayList<>();
+        boolean schemaValid = true;
+        boolean instanceValid = true;
+
+        if (testCase.getSchemaFile() == null) {
+            return;
+        }
+
+        // step 1, load schema file etc.
+        SchemaTypeLoader loader = null;
+        try {
+            XmlObject schema = XmlObject.Factory.parse(testCase.getSchemaFile(), new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
+            XmlObject schema2 = null;
+            if (testCase.getResourceFile() != null) {
+                schema2 = XmlObject.Factory.parse(testCase.getResourceFile(), new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
             }
-            
-            result.addSvMessages(errors);
-            result.setSvActual(schemaValid);
-            errors.clear();
-            
-            if (loader == null)
-                return;
-            
-            if (testCase.getInstanceFile() == null)
-                return;
-            
-            // step 2, load instance file and validate
-            try
-            {
-                XmlObject instance = loader.parse(testCase.getInstanceFile(), null, new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
-                if (!instance.validate(new XmlOptions().setErrorListener(errors)))
-                    instanceValid = false;
+            XmlObject[] schemas = schema2 == null ? new XmlObject[]{schema} : new XmlObject[]{schema, schema2};
+            SchemaTypeSystem system = XmlBeans.compileXsd(schemas, XmlBeans.getBuiltinTypeSystem(), new XmlOptions().setErrorListener(errors));
+            loader = XmlBeans.typeLoaderUnion(system, XmlBeans.getBuiltinTypeSystem());
+        } catch (Exception e) {
+            schemaValid = false;
+            if (!(e instanceof XmlException) || errors.isEmpty()) {
+                result.setCrash(true);
+                StringWriter sw = new StringWriter();
+                e.printStackTrace(new PrintWriter(sw));
+                result.addSvMessages(Collections.singleton(XmlError.forMessage(sw.toString())));
             }
-            catch (Exception e)
-            {
+        }
+
+        result.addSvMessages(errors);
+        result.setSvActual(schemaValid);
+        errors.clear();
+
+        if (loader == null) {
+            return;
+        }
+
+        if (testCase.getInstanceFile() == null) {
+            return;
+        }
+
+        // step 2, load instance file and validate
+        try {
+            XmlObject instance = loader.parse(testCase.getInstanceFile(), null, new XmlOptions().setErrorListener(errors).setLoadLineNumbers());
+            if (!instance.validate(new XmlOptions().setErrorListener(errors))) {
                 instanceValid = false;
-                if (!(e instanceof XmlException) || errors.isEmpty())
-                {
-                    result.setCrash(true);
-                    StringWriter sw = new StringWriter();
-                    e.printStackTrace(new PrintWriter(sw));
-                    result.addIvMessages(Collections.singleton(sw.toString()));
-                }
             }
-            result.addIvMessages(errors);
-            result.setIvActual(instanceValid);
-                    
-        }
-        finally
-        {
-            // System.out.println(result.succeeded() ? "Success.": "Failure.");
+        } catch (Exception e) {
+            instanceValid = false;
+            if (!(e instanceof XmlException) || errors.isEmpty()) {
+                result.setCrash(true);
+                StringWriter sw = new StringWriter();
+                e.printStackTrace(new PrintWriter(sw));
+                result.addIvMessages(Collections.singleton(XmlError.forMessage(sw.toString())));
+            }
         }
+        result.addIvMessages(errors);
+        result.setIvActual(instanceValid);
+
     }
 }



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