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/08/20 22:25:58 UTC

svn commit: r1881037 [6/7] - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans: ./ impl/common/ impl/config/ impl/regex/ impl/schema/ impl/store/

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=1881037&r1=1881036&r2=1881037&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 Thu Aug 20 22:25:57 2020
@@ -15,35 +15,12 @@
 
 package org.apache.xmlbeans.impl.schema;
 
-import org.apache.xmlbeans.Filer;
-import org.apache.xmlbeans.QNameSet;
-import org.apache.xmlbeans.SchemaAnnotation;
-import org.apache.xmlbeans.SchemaAttributeGroup;
-import org.apache.xmlbeans.SchemaAttributeModel;
-import org.apache.xmlbeans.SchemaComponent;
-import org.apache.xmlbeans.SchemaGlobalAttribute;
-import org.apache.xmlbeans.SchemaGlobalElement;
-import org.apache.xmlbeans.SchemaIdentityConstraint;
-import org.apache.xmlbeans.SchemaLocalAttribute;
-import org.apache.xmlbeans.SchemaLocalElement;
-import org.apache.xmlbeans.SchemaModelGroup;
-import org.apache.xmlbeans.SchemaParticle;
-import org.apache.xmlbeans.SchemaProperty;
-import org.apache.xmlbeans.SchemaStringEnumEntry;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.SchemaTypeLoaderException;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.SimpleValue;
-import org.apache.xmlbeans.SystemProperties;
-import org.apache.xmlbeans.XmlAnySimpleType;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.ResourceLoader;
+import org.apache.xmlbeans.*;
 import org.apache.xmlbeans.impl.common.DefaultClassLoaderResourceLoader;
 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.repackage.Repackager;
 import org.apache.xmlbeans.impl.util.FilerImpl;
 import org.apache.xmlbeans.impl.util.HexBin;
 import org.apache.xmlbeans.impl.values.XmlObjectBase;
@@ -51,36 +28,17 @@ import org.apache.xmlbeans.impl.xb.xsdsc
 import org.apache.xmlbeans.impl.xb.xsdschema.GroupDocument;
 import org.apache.xmlbeans.soap.SOAPArrayType;
 import org.apache.xmlbeans.soap.SchemaWSDLArrayType;
-import org.apache.xmlbeans.impl.repackage.Repackager;
 
 import javax.xml.namespace.QName;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
 import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
-public class SchemaTypeSystemImpl extends SchemaTypeLoaderBase implements SchemaTypeSystem
-{
+public class SchemaTypeSystemImpl extends SchemaTypeLoaderBase implements SchemaTypeSystem {
     public static final int DATA_BABE = 0xDA7ABABE;
     public static final int MAJOR_VERSION = 2;  // must match == to be compatible
     public static final int MINOR_VERSION = 24; // must be <= to be compatible
@@ -116,26 +74,26 @@ public class SchemaTypeSystemImpl extend
     public static final int FIELD_LOCALELT = 3;
 
     // type flags
-    static final int FLAG_SIMPLE_TYPE     = 0x1;
-    static final int FLAG_DOCUMENT_TYPE   = 0x2;
-    static final int FLAG_ORDERED         = 0x4;
-    static final int FLAG_BOUNDED         = 0x8;
-    static final int FLAG_FINITE          = 0x10;
-    static final int FLAG_NUMERIC         = 0x20;
-    static final int FLAG_STRINGENUM      = 0x40;
-    static final int FLAG_UNION_OF_LISTS  = 0x80;
-    static final int FLAG_HAS_PATTERN     = 0x100;
+    static final int FLAG_SIMPLE_TYPE = 0x1;
+    static final int FLAG_DOCUMENT_TYPE = 0x2;
+    static final int FLAG_ORDERED = 0x4;
+    static final int FLAG_BOUNDED = 0x8;
+    static final int FLAG_FINITE = 0x10;
+    static final int FLAG_NUMERIC = 0x20;
+    static final int FLAG_STRINGENUM = 0x40;
+    static final int FLAG_UNION_OF_LISTS = 0x80;
+    static final int FLAG_HAS_PATTERN = 0x100;
     static final int FLAG_ORDER_SENSITIVE = 0x200;
-    static final int FLAG_TOTAL_ORDER     = 0x400;
-    static final int FLAG_COMPILED        = 0x800;
-    static final int FLAG_BLOCK_EXT       = 0x1000;
-    static final int FLAG_BLOCK_REST      = 0x2000;
-    static final int FLAG_FINAL_EXT       = 0x4000;
-    static final int FLAG_FINAL_REST      = 0x8000;
-    static final int FLAG_FINAL_UNION     = 0x10000;
-    static final int FLAG_FINAL_LIST      = 0x20000;
-    static final int FLAG_ABSTRACT        = 0x40000;
-    static final int FLAG_ATTRIBUTE_TYPE  = 0x80000;
+    static final int FLAG_TOTAL_ORDER = 0x400;
+    static final int FLAG_COMPILED = 0x800;
+    static final int FLAG_BLOCK_EXT = 0x1000;
+    static final int FLAG_BLOCK_REST = 0x2000;
+    static final int FLAG_FINAL_EXT = 0x4000;
+    static final int FLAG_FINAL_REST = 0x8000;
+    static final int FLAG_FINAL_UNION = 0x10000;
+    static final int FLAG_FINAL_LIST = 0x20000;
+    static final int FLAG_ABSTRACT = 0x40000;
+    static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
 
     /**
      * regex to identify the type system holder package namespace
@@ -148,10 +106,10 @@ public class SchemaTypeSystemImpl extend
      * xmlbeans one.
      * METADATA_PACKAGE_GEN will be "" for the original and something like
      * com.mycompany.private.xmlbeans for a private distribution of XMLBeans.
-     *
+     * <p>
      * There are two properties:
-     *   METADATA_PACKAGE_GEN - used for generating metadata
-     *   and METADATA_PACKAGE_LOAD - used for loading the metadata.
+     * METADATA_PACKAGE_GEN - used for generating metadata
+     * and METADATA_PACKAGE_LOAD - used for loading the metadata.
      * Most of the time they have the same value, with one exception, during the
      * repackage process scomp needs to load from old package and generate into
      * a new package.
@@ -169,12 +127,12 @@ public class SchemaTypeSystemImpl extend
 //        METADATA_PACKAGE_GEN = stsPackageName.replace('.', '/') + "/metadata";
 //    }
 
-    private static String nameToPathString(String nameForSystem)
-    {
+    private static String nameToPathString(String nameForSystem) {
         nameForSystem = nameForSystem.replace('.', '/');
 
-        if (!nameForSystem.endsWith("/") && nameForSystem.length() > 0)
+        if (!nameForSystem.endsWith("/") && nameForSystem.length() > 0) {
             nameForSystem = nameForSystem + "/";
+        }
 
         return nameForSystem;
     }
@@ -187,17 +145,9 @@ public class SchemaTypeSystemImpl extend
         _classloader = getClass().getClassLoader();
         _linker = this;
         _resourceLoader = new ClassLoaderResourceLoader(_classloader);
-        try
-        {
+        try {
             initFromHeader();
-        }
-        catch (RuntimeException e)
-        {
-            XBeanDebug.logException(e);
-            throw e;
-        }
-        catch (Error e)
-        {
+        } catch (Error | RuntimeException e) {
             XBeanDebug.logException(e);
             throw e;
         }
@@ -212,95 +162,64 @@ public class SchemaTypeSystemImpl extend
         _classloader = indexclass.getClassLoader();
         _linker = SchemaTypeLoaderImpl.build(null, null, _classloader, getMetadataPath());
         _resourceLoader = new ClassLoaderResourceLoader(_classloader);
-        try
-        {
+        try {
             initFromHeader();
-        }
-        catch (RuntimeException e)
-        {
+        } catch (RuntimeException e) {
             XBeanDebug.logException(e);
             throw e;
-        }
-        catch (Error e)
-        {
+        } catch (Error e) {
             XBeanDebug.logException(e);
             throw e;
         }
         XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Finished loading type system " + _name, -1);
     }
 
-    public static boolean fileContainsTypeSystem(File file, String name)
-    {
+    public static boolean fileContainsTypeSystem(File file, String name) {
         String indexname = nameToPathString(name) + "index.xsb";
 
-        if (file.isDirectory())
-        {
+        if (file.isDirectory()) {
             return (new File(file, indexname)).isFile();
-        }
-        else
-        {
-            ZipFile zipfile = null;
-            try
-            {
-                zipfile = new ZipFile(file);
+        } else {
+            try (ZipFile zipfile = new ZipFile(file)) {
                 ZipEntry entry = zipfile.getEntry(indexname);
                 return (entry != null && !entry.isDirectory());
-            }
-            catch (IOException e)
-            {
+            } catch (IOException e) {
                 XBeanDebug.log("Problem loading SchemaTypeSystem, zipfilename " + file);
                 XBeanDebug.logException(e);
-                throw new SchemaTypeLoaderException(e.getMessage(), name, "index", SchemaTypeLoaderException.IO_EXCEPTION);
-            }
-            finally
-            {
-                if (zipfile != null)
-                    try { zipfile.close(); } catch (IOException e) {}
+                throw new SchemaTypeLoaderException(e.getMessage(), name, "index", SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
         }
     }
 
-    public static SchemaTypeSystemImpl forName(String name, ClassLoader loader)
-    {
-        try
-        {
+    public static SchemaTypeSystemImpl forName(String name, ClassLoader loader) {
+        try {
             Class c = Class.forName(name + "." + SchemaTypeCodePrinter.INDEX_CLASSNAME, true, loader);
-            return (SchemaTypeSystemImpl)c.getField("typeSystem").get(null);
-        }
-        catch (Throwable e)
-        {
+            return (SchemaTypeSystemImpl) c.getField("typeSystem").get(null);
+        } catch (Throwable e) {
             return null;
         }
     }
 
-    public SchemaTypeSystemImpl(ResourceLoader resourceLoader, String name, SchemaTypeLoader linker)
-    {
+    public SchemaTypeSystemImpl(ResourceLoader resourceLoader, String name, SchemaTypeLoader linker) {
         _name = name;
         _basePackage = nameToPathString(_name);
         _linker = linker;
         _resourceLoader = resourceLoader;
-        try
-        {
+        try {
             initFromHeader();
-        }
-        catch (RuntimeException e)
-        {
+        } catch (RuntimeException e) {
             XBeanDebug.logException(e);
             throw e;
-        }
-        catch (Error e)
-        {
+        } catch (Error e) {
             XBeanDebug.logException(e);
             throw e;
         }
     }
 
-    private void initFromHeader()
-    {
+    private void initFromHeader() {
         XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Reading unresolved handles for type system " + _name, 0);
         XsbReader reader = null;
-        try
-        {
+        try {
             // Read the index file, which starts with a header.
             reader = new XsbReader("index", FILETYPE_SCHEMAINDEX);
 
@@ -340,28 +259,24 @@ public class SchemaTypeSystemImpl extend
             List typeNames = new ArrayList();
             List modelGroupNames = new ArrayList();
             List attributeGroupNames = new ArrayList();
-            if (reader.atLeast(2, 15, 0))
-            {
+            if (reader.atLeast(2, 15, 0)) {
                 _redefinedGlobalTypes = reader.readQNameRefMapAsList(typeNames);
                 _redefinedModelGroups = reader.readQNameRefMapAsList(modelGroupNames);
                 _redefinedAttributeGroups = reader.readQNameRefMapAsList(attributeGroupNames);
             }
-            if (reader.atLeast(2, 19, 0))
-            {
+            if (reader.atLeast(2, 19, 0)) {
                 _annotations = reader.readAnnotations();
             }
 
             buildContainers(typeNames, modelGroupNames, attributeGroupNames);
-        }
-        finally
-        {
-            if (reader != null)
+        } finally {
+            if (reader != null) {
                 reader.readEnd();
+            }
         }
     }
 
-    void saveIndex()
-    {
+    void saveIndex() {
         String handle = "index";
         XsbReader saver = new XsbReader(handle);
         saver.writeIndexData();
@@ -370,8 +285,7 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    void savePointers()
-    {
+    void savePointers() {
         savePointersForComponents(globalElements(), getMetadataPath() + "/element/");
         savePointersForComponents(globalAttributes(), getMetadataPath() + "/attribute/");
         savePointersForComponents(modelGroups(), getMetadataPath() + "/modelgroup/");
@@ -385,34 +299,27 @@ public class SchemaTypeSystemImpl extend
         savePointersForComponents(redefinedGlobalTypes(), getMetadataPath() + "/redefinedtype/");
     }
 
-    void savePointersForComponents(SchemaComponent[] components, String dir)
-    {
-        for (int i = 0; i < components.length; i++)
-        {
+    void savePointersForComponents(SchemaComponent[] components, String dir) {
+        for (int i = 0; i < components.length; i++) {
             savePointerFile(dir + QNameHelper.hexsafedir(components[i].getName()), _name);
         }
     }
 
-    void savePointersForClassnames(Set classnames, String dir)
-    {
-        for (Iterator i = classnames.iterator(); i.hasNext(); )
-        {
-            String classname = (String)i.next();
+    void savePointersForClassnames(Set classnames, String dir) {
+        for (Iterator i = classnames.iterator(); i.hasNext(); ) {
+            String classname = (String) i.next();
             savePointerFile(dir + classname.replace('.', '/'), _name);
         }
     }
 
-    void savePointersForNamespaces(Set namespaces, String dir)
-    {
-        for (Iterator i = namespaces.iterator(); i.hasNext(); )
-        {
-            String ns = (String)i.next();
+    void savePointersForNamespaces(Set namespaces, String dir) {
+        for (Iterator i = namespaces.iterator(); i.hasNext(); ) {
+            String ns = (String) i.next();
             savePointerFile(dir + QNameHelper.hexsafedir(new QName(ns, "xmlns")), _name);
         }
     }
 
-    void savePointerFile(String filename, String name)
-    {
+    void savePointerFile(String filename, String name) {
         XsbReader saver = new XsbReader(filename);
         saver.writeString(name);
         saver.writeRealHeader(filename, FILETYPE_SCHEMAPOINTER);
@@ -427,39 +334,22 @@ public class SchemaTypeSystemImpl extend
      * 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()
-    {
+    void saveLoader() {
         String indexClassName = SchemaTypeCodePrinter.indexClassForSystem(this);
         String[] replace = makeClassStrings(indexClassName);
         assert replace.length == HOLDER_TEMPLATE_NAMES.length;
 
-        InputStream is = null;
-        OutputStream os = null;
-
-        DataInputStream in = null;
-        DataOutputStream out = null;
-
         Repackager repackager = null;
-        if (_filer instanceof FilerImpl)
-            repackager = ((FilerImpl)_filer).getRepackager();
-
-        try
-        {
-            is = SchemaTypeSystemImpl.class.getResourceAsStream(HOLDER_TEMPLATE_CLASSFILE);
-            if (is == null) {
-                DefaultClassLoaderResourceLoader clLoader = new DefaultClassLoaderResourceLoader();
-                is = clLoader.getResourceAsStream(HOLDER_TEMPLATE_CLASSFILE);
-            }
-            if (is == null) {
-                throw new SchemaTypeLoaderException("couldn't find resource: " + HOLDER_TEMPLATE_CLASSFILE, _name, null, SchemaTypeLoaderException.IO_EXCEPTION);
-            }
-            in = new DataInputStream(is);
+        if (_filer instanceof FilerImpl) {
+            repackager = ((FilerImpl) _filer).getRepackager();
+        }
 
-            os = _filer.createBinaryFile(indexClassName.replace('.', '/') + ".class");
-            out = new DataOutputStream(os);
+        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());
@@ -472,13 +362,11 @@ public class SchemaTypeSystemImpl extend
             out.writeShort(poolsize);
 
             // the constant pool is indexed from 1 to poolsize-1
-            for (int i = 1; i < poolsize; i++)
-            {
+            for (int i = 1; i < poolsize; i++) {
                 int tag = in.readUnsignedByte();
                 out.writeByte(tag);
 
-                switch (tag)
-                {
+                switch (tag) {
                     case CONSTANT_UTF8:
                         String value = in.readUTF();
                         out.writeUTF(repackageConstant(value, replace, repackager));
@@ -515,26 +403,40 @@ public class SchemaTypeSystemImpl extend
 
             // we're done with the class' constant pool,
             // we can just copy the rest of the bytes
-            try
-            {
-                while (true)
-                    out.writeByte(in.readByte());
+            copy(in, out);
+        } catch (IOException e) {
+            // ok
             }
-            catch (java.io.EOFException 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 long copy(InputStream inp, OutputStream out) throws IOException {
+        final byte[] buff = new byte[4096];
+        long totalCount = 0;
+        int readBytes;
+        do {
+            int todoBytes = buff.length;
+            readBytes = inp.read(buff, 0, todoBytes);
+            if (readBytes > 0) {
+                out.write(buff, 0, readBytes);
+                totalCount += readBytes;
             }
+        } while (readBytes >= 0);
 
-        }
-        catch (IOException e)
-        {
-            // ok
-        }
-        finally
-        {
-            if (is != null) try { is.close(); } catch (Exception e) { }
-            if (os != null) try { os.close(); } catch (Exception e) { }
-        }
+        return totalCount;
     }
 
     private static final String HOLDER_TEMPLATE_CLASS = "org.apache.xmlbeans.impl.schema.TypeSystemHolder";
@@ -558,14 +460,16 @@ public class SchemaTypeSystemImpl extend
     // 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))
+    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)
+        if (repackager != null) {
             return repackager.repackage(new StringBuffer(value)).toString();
+        }
 
         return value;
     }
@@ -575,8 +479,7 @@ public class SchemaTypeSystemImpl extend
      * 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)
-    {
+    private static String[] makeClassStrings(String classname) {
         String[] result = new String[4];
 
         result[0] = classname;
@@ -590,8 +493,7 @@ public class SchemaTypeSystemImpl extend
     /**
      * Only used in the nonbootstrapped case.
      */
-    private Map buildTypeRefsByClassname()
-    {
+    private Map buildTypeRefsByClassname() {
         List allSeenTypes = new ArrayList();
         Map result = new LinkedHashMap();
         allSeenTypes.addAll(Arrays.asList(documentTypes()));
@@ -599,12 +501,10 @@ public class SchemaTypeSystemImpl extend
         allSeenTypes.addAll(Arrays.asList(globalTypes()));
 
         // now fully javaize everything deeply.
-        for (int i = 0; i < allSeenTypes.size(); i++)
-        {
-            SchemaType gType = (SchemaType)allSeenTypes.get(i);
+        for (int i = 0; i < allSeenTypes.size(); i++) {
+            SchemaType gType = (SchemaType) allSeenTypes.get(i);
             String className = gType.getFullJavaName();
-            if (className != null)
-            {
+            if (className != null) {
                 result.put(className.replace('$', '.'), gType.getRef());
             }
             allSeenTypes.addAll(Arrays.asList(gType.getAnonymousTypes()));
@@ -612,67 +512,61 @@ public class SchemaTypeSystemImpl extend
         return result;
     }
 
-    private Map buildTypeRefsByClassname(Map typesByClassname)
-    {
+    private Map buildTypeRefsByClassname(Map typesByClassname) {
         Map result = new LinkedHashMap();
-        for (Iterator i = typesByClassname.keySet().iterator(); i.hasNext(); )
-        {
-            String className = (String)i.next();
-            result.put(className, ((SchemaType)typesByClassname.get(className)).getRef());
+        for (Iterator i = typesByClassname.keySet().iterator(); i.hasNext(); ) {
+            String className = (String) i.next();
+            result.put(className, ((SchemaType) typesByClassname.get(className)).getRef());
         }
         return result;
     }
 
-    private static Map buildComponentRefMap(SchemaComponent[] components)
-    {
+    private static Map buildComponentRefMap(SchemaComponent[] components) {
         Map result = new LinkedHashMap();
-        for (int i = 0; i < components.length; i++)
+        for (int i = 0; i < components.length; i++) {
             result.put(components[i].getName(), components[i].getComponentRef());
+        }
         return result;
     }
 
-    private static List buildComponentRefList(SchemaComponent[] components)
-    {
+    private static List buildComponentRefList(SchemaComponent[] components) {
         List result = new ArrayList();
-        for (int i = 0; i < components.length; i++)
+        for (int i = 0; i < components.length; i++) {
             result.add(components[i].getComponentRef());
+        }
         return result;
     }
 
-    private static Map buildDocumentMap(SchemaType[] types)
-    {
+    private static Map buildDocumentMap(SchemaType[] types) {
         Map result = new LinkedHashMap();
-        for (int i = 0; i < types.length; i++)
+        for (int i = 0; i < types.length; i++) {
             result.put(types[i].getDocumentElementName(), types[i].getRef());
+        }
         return result;
     }
 
-    private static Map buildAttributeTypeMap(SchemaType[] types)
-    {
+    private static Map buildAttributeTypeMap(SchemaType[] types) {
         Map result = new LinkedHashMap();
-        for (int i = 0; i < types.length; i++)
+        for (int i = 0; i < types.length; i++) {
             result.put(types[i].getAttributeTypeAttributeName(), types[i].getRef());
+        }
         return result;
     }
 
     // Container operation
-    private SchemaContainer getContainer(String namespace)
-    {
+    private SchemaContainer getContainer(String namespace) {
         return (SchemaContainer) _containers.get(namespace);
     }
 
-    private void addContainer(String namespace)
-    {
+    private void addContainer(String namespace) {
         SchemaContainer c = new SchemaContainer(namespace);
         c.setTypeSystem(this);
         _containers.put(namespace, c);
     }
 
-    private SchemaContainer getContainerNonNull(String namespace)
-    {
+    private SchemaContainer getContainerNonNull(String namespace) {
         SchemaContainer result = getContainer(namespace);
-        if (result == null)
-        {
+        if (result == null) {
             addContainer(namespace);
             result = getContainer(namespace);
         }
@@ -680,91 +574,77 @@ public class SchemaTypeSystemImpl extend
     }
 
     // Only called during init
-    private void buildContainers(List redefTypeNames, List redefModelGroupNames, List redefAttributeGroupNames)
-    {
+    private void buildContainers(List redefTypeNames, List redefModelGroupNames, List redefAttributeGroupNames) {
         // This method walks the reference maps and copies said references
         // into the appropriate container
-        for (Iterator it = _globalElements.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _globalElements.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addGlobalElement((SchemaGlobalElement.Ref) entry.getValue());
         }
-        for (Iterator it = _globalAttributes.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _globalAttributes.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addGlobalAttribute((SchemaGlobalAttribute.Ref) entry.getValue());
         }
-        for (Iterator it = _modelGroups.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _modelGroups.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addModelGroup((SchemaModelGroup.Ref) entry.getValue());
         }
-        for (Iterator it = _attributeGroups.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _attributeGroups.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addAttributeGroup((SchemaAttributeGroup.Ref) entry.getValue());
         }
-        for (Iterator it = _identityConstraints.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _identityConstraints.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addIdentityConstraint((SchemaIdentityConstraint.Ref) entry.getValue());
         }
-        for (Iterator it = _globalTypes.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _globalTypes.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addGlobalType((SchemaType.Ref) entry.getValue());
         }
-        for (Iterator it = _documentTypes.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _documentTypes.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addDocumentType((SchemaType.Ref) entry.getValue());
         }
-        for (Iterator it = _attributeTypes.entrySet().iterator(); it.hasNext(); )
-        {
+        for (Iterator it = _attributeTypes.entrySet().iterator(); it.hasNext(); ) {
             Map.Entry entry = (Map.Entry) it.next();
             String ns = ((QName) entry.getKey()).getNamespaceURI();
             getContainerNonNull(ns).addAttributeType((SchemaType.Ref) entry.getValue());
         }
         // Some earlier .xsb versions don't have records for redefinitions
         if (_redefinedGlobalTypes != null && _redefinedModelGroups != null &&
-            _redefinedAttributeGroups != null)
-        {
+            _redefinedAttributeGroups != null) {
             assert _redefinedGlobalTypes.size() == redefTypeNames.size();
-            for (Iterator it = _redefinedGlobalTypes.iterator(), itname = redefTypeNames.iterator(); it.hasNext(); )
-            {
+            for (Iterator it = _redefinedGlobalTypes.iterator(), itname = redefTypeNames.iterator(); it.hasNext(); ) {
                 String ns = ((QName) itname.next()).getNamespaceURI();
                 getContainerNonNull(ns).addRedefinedType((SchemaType.Ref) it.next());
             }
-            for (Iterator it = _redefinedModelGroups.iterator(), itname = redefModelGroupNames.iterator(); it.hasNext(); )
-            {
+            for (Iterator it = _redefinedModelGroups.iterator(), itname = redefModelGroupNames.iterator(); it.hasNext(); ) {
                 String ns = ((QName) itname.next()).getNamespaceURI();
                 getContainerNonNull(ns).addRedefinedModelGroup((SchemaModelGroup.Ref) it.next());
             }
-            for (Iterator it = _redefinedAttributeGroups.iterator(), itname = redefAttributeGroupNames.iterator(); it.hasNext(); )
-            {
+            for (Iterator it = _redefinedAttributeGroups.iterator(), itname = redefAttributeGroupNames.iterator(); it.hasNext(); ) {
                 String ns = ((QName) itname.next()).getNamespaceURI();
                 getContainerNonNull(ns).addRedefinedAttributeGroup((SchemaAttributeGroup.Ref) it.next());
             }
         }
         // Some earlier .xsb versions don't have records for annotations
-        if (_annotations != null)
-        {
-            for (Iterator it = _annotations.iterator(); it.hasNext(); )
-            {
+        if (_annotations != null) {
+            for (Iterator it = _annotations.iterator(); it.hasNext(); ) {
                 SchemaAnnotation ann = (SchemaAnnotation) it.next();
                 // BUGBUG(radup)
                 getContainerNonNull("").addAnnotation(ann);
             }
         }
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             ((SchemaContainer) it.next()).setImmutable();
+        }
     }
 
     /**
@@ -775,88 +655,99 @@ public class SchemaTypeSystemImpl extend
      * effect all components now indirectly pointing to this typesystem
      * even though they (as well as the typesystem itself) are immutable.
      */
-    private void fixupContainers()
-    {
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
-        {
+    private void fixupContainers() {
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             SchemaContainer container = (SchemaContainer) it.next();
             container.setTypeSystem(this);
             container.setImmutable();
         }
     }
 
-    private void assertContainersSynchronized()
-    {
+    private void assertContainersSynchronized() {
         boolean assertEnabled = false;
         // This code basically checks whether asserts are enabled so we don't do
         // all the work if they arent
         assert assertEnabled = true;
-        if (!assertEnabled)
+        if (!assertEnabled) {
             return;
+        }
         // global elements
         Map temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).globalElements().toArray(new SchemaComponent[0])));
+        }
         assert _globalElements.equals(temp);
         // global attributes
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).globalAttributes().toArray(new SchemaComponent[0])));
+        }
         assert _globalAttributes.equals(temp);
         // model groups
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).modelGroups().toArray(new SchemaComponent[0])));
+        }
         assert _modelGroups.equals(temp);
         // redefined model groups
         Set temp2 = new HashSet();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp2.addAll(buildComponentRefList((SchemaComponent[]) ((SchemaContainer) it.next()).redefinedModelGroups().toArray(new SchemaComponent[0])));
+        }
         assert new HashSet(_redefinedModelGroups).equals(temp2);
         // attribute groups
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).attributeGroups().toArray(new SchemaComponent[0])));
+        }
         assert _attributeGroups.equals(temp);
         // redefined attribute groups
         temp2 = new HashSet();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp2.addAll(buildComponentRefList((SchemaComponent[]) ((SchemaContainer) it.next()).redefinedAttributeGroups().toArray(new SchemaComponent[0])));
+        }
         assert new HashSet(_redefinedAttributeGroups).equals(temp2);
         // global types
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).globalTypes().toArray(new SchemaComponent[0])));
+        }
         assert _globalTypes.equals(temp);
         // redefined global types
         temp2 = new HashSet();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp2.addAll(buildComponentRefList((SchemaComponent[]) ((SchemaContainer) it.next()).redefinedGlobalTypes().toArray(new SchemaComponent[0])));
+        }
         assert new HashSet(_redefinedGlobalTypes).equals(temp2);
         // document types
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildDocumentMap((SchemaType[]) ((SchemaContainer) it.next()).documentTypes().toArray(new SchemaType[0])));
+        }
         assert _documentTypes.equals(temp);
         // attribute types
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildAttributeTypeMap((SchemaType[]) ((SchemaContainer) it.next()).attributeTypes().toArray(new SchemaType[0])));
+        }
         assert _attributeTypes.equals(temp);
         // identity constraints
         temp = new HashMap();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp.putAll(buildComponentRefMap((SchemaComponent[]) ((SchemaContainer) it.next()).identityConstraints().toArray(new SchemaComponent[0])));
+        }
         assert _identityConstraints.equals(temp);
         // annotations
         temp2 = new HashSet();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp2.addAll(((SchemaContainer) it.next()).annotations());
+        }
         assert new HashSet(_annotations).equals(temp2);
         // namespaces
         temp2 = new HashSet();
-        for (Iterator it = _containers.values().iterator(); it.hasNext(); )
+        for (Iterator it = _containers.values().iterator(); it.hasNext(); ) {
             temp2.add(((SchemaContainer) it.next()).getNamespace());
+        }
         assert _namespaces.equals(temp2);
     }
 
@@ -868,11 +759,11 @@ public class SchemaTypeSystemImpl extend
      * We used to use SecureRandom, but now we don't because SecureRandom
      * hits the filesystem and hangs us on a filesystem lock.  It also eats
      * a thread and other expensive resources.. :-).
-     *
+     * <p>
      * We don't really care that non-secure Random() can only do 48 bits of
      * randomness, since we're certainly not going to be called more than 2^48
      * times within our process lifetime.
-     *
+     * <p>
      * Our real concern is that by seeding Random() with the current
      * time, two users will end up with the same bits if they start a
      * schema compilation within the same millisecond.  That makes the
@@ -880,7 +771,7 @@ public class SchemaTypeSystemImpl extend
      * We're going to have millions of users, remember?  With a million
      * users, and one-compilation-per-day each, we'd see a collision every
      * few months.
-     *
+     * <p>
      * So we'll just xor the results of random with our few extra
      * bits of information computed below to help reduce the probability
      * of collision by a few decimal places.  To collide, you will have had
@@ -891,23 +782,18 @@ public class SchemaTypeSystemImpl extend
      * millisecond. Or you can collide if you have a cosmic 128-bit mathematical
      * coincidence. No worries.
      */
-    private static synchronized void nextBytes(byte[] result)
-    {
-        if (_random == null)
-        {
-            try
-            {
+    private static synchronized void nextBytes(byte[] result) {
+        if (_random == null) {
+            try {
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 DataOutputStream daos = new DataOutputStream(baos);
 
                 // at least 10 bits of unqieueness, right?  Maybe even 50 or 60.
                 daos.writeInt(System.identityHashCode(SchemaTypeSystemImpl.class));
-                String[] props = new String[] { "user.name", "user.dir", "user.timezone", "user.country", "java.class.path", "java.home", "java.vendor", "java.version", "os.version" };
-                for (int i = 0; i < props.length; i++)
-                {
+                String[] props = new String[]{"user.name", "user.dir", "user.timezone", "user.country", "java.class.path", "java.home", "java.vendor", "java.version", "os.version"};
+                for (int i = 0; i < props.length; i++) {
                     String prop = SystemProperties.getProperty(props[i]);
-                    if (prop != null)
-                    {
+                    if (prop != null) {
                         daos.writeUTF(prop);
                         daos.writeInt(System.identityHashCode(prop));
                     }
@@ -915,23 +801,19 @@ public class SchemaTypeSystemImpl extend
                 daos.writeLong(Runtime.getRuntime().freeMemory());
                 daos.close();
                 byte[] bytes = baos.toByteArray();
-                for (int i = 0; i < bytes.length; i++)
-                {
+                for (int i = 0; i < bytes.length; i++) {
                     int j = i % _mask.length;
                     _mask[j] *= 21;
                     _mask[j] += i;
                 }
-            }
-            catch (IOException e)
-            {
+            } catch (IOException e) {
                 XBeanDebug.logException(e);
             }
 
             _random = new Random(System.currentTimeMillis());
         }
         _random.nextBytes(result);
-        for (int i = 0; i < result.length; i++)
-        {
+        for (int i = 0; i < result.length; i++) {
             int j = i & _mask.length;
             result[i] ^= _mask[j];
         }
@@ -939,15 +821,14 @@ public class SchemaTypeSystemImpl extend
 
     public SchemaTypeSystemImpl(String nameForSystem) {
         // if we have no name, select a random one
-        if (nameForSystem == null)
-        {
+        if (nameForSystem == null) {
             // get 128 random bits (that'll be 32 hex digits)
-            byte[] bytes = new byte[128/8];
+            byte[] bytes = new byte[128 / 8];
             nextBytes(bytes);
             nameForSystem = "s" + new String(HexBin.encode(bytes));
         }
 
-        _name = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN.replace('/','.') + ".system." + nameForSystem;
+        _name = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN.replace('/', '.') + ".system." + nameForSystem;
         _basePackage = nameToPathString(_name);
         _classloader = null;
     }
@@ -956,9 +837,8 @@ public class SchemaTypeSystemImpl extend
                                 SchemaGlobalAttribute[] globalAttributes,
                                 SchemaType[] globalTypes,
                                 SchemaType[] documentTypes,
-                                SchemaType[] attributeTypes)
-    {
-        assert(_classloader == null);
+                                SchemaType[] attributeTypes) {
+        assert (_classloader == null);
         _localHandles = new HandlePool();
         _globalElements = buildComponentRefMap(globalElements);
         _globalAttributes = buildComponentRefMap(globalAttributes);
@@ -971,9 +851,8 @@ public class SchemaTypeSystemImpl extend
         _namespaces = new HashSet();
     }
 
-    public void loadFromStscState(StscState state)
-    {
-        assert(_classloader == null);
+    public void loadFromStscState(StscState state) {
+        assert (_classloader == null);
         _localHandles = new HandlePool();
         _globalElements = buildComponentRefMap(state.globalElements());
         _globalAttributes = buildComponentRefMap(state.globalAttributes());
@@ -996,25 +875,29 @@ public class SchemaTypeSystemImpl extend
         setDependencies(state.getDependencies());
     }
 
-    final SchemaTypeSystemImpl getTypeSystem()
-    {
+    final SchemaTypeSystemImpl getTypeSystem() {
         return this;
     }
 
-    void setDependencies(SchemaDependencies deps)
-    {   _deps = deps; }
+    void setDependencies(SchemaDependencies deps) {
+        _deps = deps;
+    }
 
-    SchemaDependencies getDependencies()
-    {   return _deps; }
+    SchemaDependencies getDependencies() {
+        return _deps;
+    }
 
     // EXPERIMENTAL
-    public boolean isIncomplete() { return _incomplete; }
+    public boolean isIncomplete() {
+        return _incomplete;
+    }
 
     // EXPERIMENTAL
-    void setIncomplete(boolean incomplete) { _incomplete = incomplete; }
+    void setIncomplete(boolean incomplete) {
+        _incomplete = incomplete;
+    }
 
-    static class StringPool
-    {
+    static class StringPool {
         private List intsToStrings = new ArrayList();
         private Map stringsToInts = new HashMap();
         private String _handle;
@@ -1023,20 +906,18 @@ public class SchemaTypeSystemImpl extend
         /**
          * Constructs an empty StringPool to be filled with strings.
          */
-        StringPool(String handle, String name)
-        {
+        StringPool(String handle, String name) {
             _handle = handle;
             _name = name;
             intsToStrings.add(null);
         }
 
-        int codeForString(String str)
-        {
-            if (str == null)
+        int codeForString(String str) {
+            if (str == null) {
                 return 0;
-            Integer result = (Integer)stringsToInts.get(str);
-            if (result == null)
-            {
+            }
+            Integer result = (Integer) stringsToInts.get(str);
+            if (result == null) {
                 result = new Integer(intsToStrings.size());
                 intsToStrings.add(str);
                 stringsToInts.put(str, result);
@@ -1044,59 +925,51 @@ public class SchemaTypeSystemImpl extend
             return result.intValue();
         }
 
-        String stringForCode(int code)
-        {
-            if (code == 0)
+        String stringForCode(int code) {
+            if (code == 0) {
                 return null;
-            return (String)intsToStrings.get(code);
+            }
+            return (String) intsToStrings.get(code);
         }
 
-        void writeTo(DataOutputStream output)
-        {
-            if (intsToStrings.size() >= MAX_UNSIGNED_SHORT)
+        void writeTo(DataOutputStream output) {
+            if (intsToStrings.size() >= MAX_UNSIGNED_SHORT) {
                 throw new SchemaTypeLoaderException("Too many strings (" + intsToStrings.size() + ")", _name, _handle, SchemaTypeLoaderException.INT_TOO_LARGE);
+            }
 
-            try
-            {
+            try {
                 output.writeShort(intsToStrings.size());
                 Iterator i = intsToStrings.iterator();
-                for (i.next(); i.hasNext(); )
-                {
-                    String str = (String)i.next();
+                for (i.next(); i.hasNext(); ) {
+                    String str = (String) i.next();
                     output.writeUTF(str);
                 }
-            }
-            catch (IOException e)
-            {
-                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+            } catch (IOException e) {
+                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
         }
 
-        void readFrom(DataInputStream input)
-        {
-            if (intsToStrings.size() != 1 || stringsToInts.size() != 0)
+        void readFrom(DataInputStream input) {
+            if (intsToStrings.size() != 1 || stringsToInts.size() != 0) {
                 throw new IllegalStateException();
+            }
 
-            try
-            {
+            try {
                 int size = input.readUnsignedShort();
-                for (int i = 1; i < size; i++)
-                {
+                for (int i = 1; i < size; i++) {
                     String str = input.readUTF().intern();
                     int code = codeForString(str);
-                    if (code != i)
+                    if (code != i) {
                         throw new IllegalStateException();
+                    }
                 }
-            }
-            catch (IOException e)
-            {
+            } catch (IOException e) {
                 throw new SchemaTypeLoaderException(e.getMessage() == null ? e.getMessage() : "IO Exception", _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
         }
     }
 
-    class HandlePool
-    {
+    class HandlePool {
         private Map _handlesToRefs = new LinkedHashMap();
         private Map _componentsToHandles = new LinkedHashMap(); // populated on write
         private boolean _started;
@@ -1104,16 +977,13 @@ public class SchemaTypeSystemImpl extend
         /**
          * Constructs an empty HandlePool to be populated.
          */
-        HandlePool()
-        {
+        HandlePool() {
         }
 
-        private String addUniqueHandle(SchemaComponent obj, String base)
-        {
+        private String addUniqueHandle(SchemaComponent obj, String base) {
             base = base.toLowerCase();  // we lowercase handles because of case-insensitive Windows filenames!!!
             String handle = base;
-            for (int index = 2; _handlesToRefs.containsKey(handle); index++)
-            {
+            for (int index = 2; _handlesToRefs.containsKey(handle); index++) {
                 handle = base + index;
             }
             _handlesToRefs.put(handle, obj.getComponentRef());
@@ -1121,112 +991,123 @@ public class SchemaTypeSystemImpl extend
             return handle;
         }
 
-        String handleForComponent(SchemaComponent comp)
-        {
-            if (comp == null)
+        String handleForComponent(SchemaComponent comp) {
+            if (comp == null) {
                 return null;
-            if (comp.getTypeSystem() != getTypeSystem())
+            }
+            if (comp.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            if (comp instanceof SchemaType)
-                return handleForType((SchemaType)comp);
-            if (comp instanceof SchemaGlobalElement)
-                return handleForElement((SchemaGlobalElement)comp);
-            if (comp instanceof SchemaGlobalAttribute)
-                return handleForAttribute((SchemaGlobalAttribute)comp);
-            if (comp instanceof SchemaModelGroup)
-                return handleForModelGroup((SchemaModelGroup)comp);
-            if (comp instanceof SchemaAttributeGroup)
-                return handleForAttributeGroup((SchemaAttributeGroup)comp);
-            if (comp instanceof SchemaIdentityConstraint)
-                return handleForIdentityConstraint((SchemaIdentityConstraint)comp);
+            }
+            if (comp instanceof SchemaType) {
+                return handleForType((SchemaType) comp);
+            }
+            if (comp instanceof SchemaGlobalElement) {
+                return handleForElement((SchemaGlobalElement) comp);
+            }
+            if (comp instanceof SchemaGlobalAttribute) {
+                return handleForAttribute((SchemaGlobalAttribute) comp);
+            }
+            if (comp instanceof SchemaModelGroup) {
+                return handleForModelGroup((SchemaModelGroup) comp);
+            }
+            if (comp instanceof SchemaAttributeGroup) {
+                return handleForAttributeGroup((SchemaAttributeGroup) comp);
+            }
+            if (comp instanceof SchemaIdentityConstraint) {
+                return handleForIdentityConstraint((SchemaIdentityConstraint) comp);
+            }
             throw new IllegalStateException("Component type cannot have a handle");
         }
 
-        String handleForElement(SchemaGlobalElement element)
-        {
-            if (element == null)
+        String handleForElement(SchemaGlobalElement element) {
+            if (element == null) {
                 return null;
-            if (element.getTypeSystem() != getTypeSystem())
+            }
+            if (element.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(element);
-            if (handle == null)
+            }
+            String handle = (String) _componentsToHandles.get(element);
+            if (handle == null) {
                 handle = addUniqueHandle(element, NameUtil.upperCamelCase(element.getName().getLocalPart()) + "Element");
+            }
             return handle;
         }
 
-        String handleForAttribute(SchemaGlobalAttribute attribute)
-        {
-            if (attribute == null)
+        String handleForAttribute(SchemaGlobalAttribute attribute) {
+            if (attribute == null) {
                 return null;
-            if (attribute.getTypeSystem() != getTypeSystem())
+            }
+            if (attribute.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(attribute);
-            if (handle == null)
+            }
+            String handle = (String) _componentsToHandles.get(attribute);
+            if (handle == null) {
                 handle = addUniqueHandle(attribute, NameUtil.upperCamelCase(attribute.getName().getLocalPart()) + "Attribute");
+            }
             return handle;
         }
 
-        String handleForModelGroup(SchemaModelGroup group)
-        {
-            if (group == null)
+        String handleForModelGroup(SchemaModelGroup group) {
+            if (group == null) {
                 return null;
-            if (group.getTypeSystem() != getTypeSystem())
+            }
+            if (group.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(group);
-            if (handle == null)
+            }
+            String handle = (String) _componentsToHandles.get(group);
+            if (handle == null) {
                 handle = addUniqueHandle(group, NameUtil.upperCamelCase(group.getName().getLocalPart()) + "ModelGroup");
+            }
             return handle;
         }
 
-        String handleForAttributeGroup(SchemaAttributeGroup group)
-        {
-            if (group == null)
+        String handleForAttributeGroup(SchemaAttributeGroup group) {
+            if (group == null) {
                 return null;
-            if (group.getTypeSystem() != getTypeSystem())
+            }
+            if (group.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(group);
-            if (handle == null)
+            }
+            String handle = (String) _componentsToHandles.get(group);
+            if (handle == null) {
                 handle = addUniqueHandle(group, NameUtil.upperCamelCase(group.getName().getLocalPart()) + "AttributeGroup");
+            }
             return handle;
         }
 
-        String handleForIdentityConstraint(SchemaIdentityConstraint idc)
-        {
-            if (idc == null)
+        String handleForIdentityConstraint(SchemaIdentityConstraint idc) {
+            if (idc == null) {
                 return null;
-            if (idc.getTypeSystem() != getTypeSystem())
+            }
+            if (idc.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(idc);
-            if (handle == null)
+            }
+            String handle = (String) _componentsToHandles.get(idc);
+            if (handle == null) {
                 handle = addUniqueHandle(idc, NameUtil.upperCamelCase(idc.getName().getLocalPart()) + "IdentityConstraint");
+            }
             return handle;
         }
 
-        String handleForType(SchemaType type)
-        {
-            if (type == null)
+        String handleForType(SchemaType type) {
+            if (type == null) {
                 return null;
-            if (type.getTypeSystem() != getTypeSystem())
+            }
+            if (type.getTypeSystem() != getTypeSystem()) {
                 throw new IllegalArgumentException("Cannot supply handles for types from another type system");
-            String handle = (String)_componentsToHandles.get(type);
-            if (handle == null)
-            {
+            }
+            String handle = (String) _componentsToHandles.get(type);
+            if (handle == null) {
                 QName name = type.getName();
                 String suffix = "";
-                if (name == null)
-                {
-                    if (type.isDocumentType())
-                    {
+                if (name == null) {
+                    if (type.isDocumentType()) {
                         name = type.getDocumentElementName();
                         suffix = "Doc";
-                    }
-                    else if (type.isAttributeType())
-                    {
+                    } else if (type.isAttributeType()) {
                         name = type.getAttributeTypeAttributeName();
                         suffix = "AttrType";
-                    }
-                    else if (type.getContainerField() != null)
-                    {
+                    } else if (type.getContainerField() != null) {
                         name = type.getContainerField().getName();
                         suffix = type.getContainerField().isAttribute() ? "Attr" : "Elem";
                     }
@@ -1234,10 +1115,11 @@ public class SchemaTypeSystemImpl extend
 
                 String baseName;
                 String uniq = Integer.toHexString(type.toString().hashCode() | 0x80000000).substring(4).toUpperCase();
-                if (name == null)
+                if (name == null) {
                     baseName = "Anon" + uniq + "Type";
-                else
+                } else {
                     baseName = NameUtil.upperCamelCase(name.getLocalPart()) + uniq + suffix + "Type";
+                }
 
                 handle = addUniqueHandle(type, baseName);
             }
@@ -1245,28 +1127,25 @@ public class SchemaTypeSystemImpl extend
             return handle;
         }
 
-        SchemaComponent.Ref refForHandle(String handle)
-        {
-            if (handle == null)
+        SchemaComponent.Ref refForHandle(String handle) {
+            if (handle == null) {
                 return null;
+            }
 
-            return (SchemaComponent.Ref)_handlesToRefs.get(handle);
+            return (SchemaComponent.Ref) _handlesToRefs.get(handle);
         }
 
-        Set getAllHandles()
-        {
+        Set getAllHandles() {
             return _handlesToRefs.keySet();
         }
 
-        void startWriteMode()
-        {
+        void startWriteMode() {
             _started = true;
             _componentsToHandles = new LinkedHashMap();
-            for (Iterator i = _handlesToRefs.keySet().iterator(); i.hasNext(); )
-            {
-                String handle = (String)i.next();
+            for (Iterator i = _handlesToRefs.keySet().iterator(); i.hasNext(); ) {
+                String handle = (String) i.next();
 //                System.err.println("Writing preexisting handle " + handle);
-                SchemaComponent comp = ((SchemaComponent.Ref)_handlesToRefs.get(handle)).getComponent();
+                SchemaComponent comp = ((SchemaComponent.Ref) _handlesToRefs.get(handle)).getComponent();
                 _componentsToHandles.put(comp, handle);
             }
         }
@@ -1323,18 +1202,18 @@ public class SchemaTypeSystemImpl extend
     static private final SchemaIdentityConstraint[] EMPTY_IC_ARRAY = new SchemaIdentityConstraint[0];
     static private final SchemaAnnotation[] EMPTY_ANN_ARRAY = new SchemaAnnotation[0];
 
-    public void saveToDirectory(File classDir)
-    {
+    public void saveToDirectory(File classDir) {
         save(new FilerImpl(classDir, null, null, false, false));
     }
 
-    public void save(Filer filer)
-    {
-        if (_incomplete)
+    public void save(Filer filer) {
+        if (_incomplete) {
             throw new IllegalStateException("Incomplete SchemaTypeSystems cannot be saved.");
+        }
 
-        if (filer == null)
+        if (filer == null) {
             throw new IllegalArgumentException("filer must not be null");
+        }
         _filer = filer;
 
         _localHandles.startWriteMode();
@@ -1357,85 +1236,79 @@ public class SchemaTypeSystemImpl extend
         saveLoader();
     }
 
-    void saveTypesRecursively(SchemaType[] types)
-    {
-        for (int i = 0; i < types.length; i++)
-        {
-            if (types[i].getTypeSystem() != getTypeSystem())
+    void saveTypesRecursively(SchemaType[] types) {
+        for (int i = 0; i < types.length; i++) {
+            if (types[i].getTypeSystem() != getTypeSystem()) {
                 continue;
+            }
             saveType(types[i]);
             saveTypesRecursively(types[i].getAnonymousTypes());
         }
     }
 
-    public void saveGlobalElements(SchemaGlobalElement[] elts)
-    {
-        if (_incomplete)
+    public void saveGlobalElements(SchemaGlobalElement[] elts) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
-        for (int i = 0; i < elts.length; i++)
-        {
+        }
+        for (int i = 0; i < elts.length; i++) {
             saveGlobalElement(elts[i]);
         }
     }
 
-    public void saveGlobalAttributes(SchemaGlobalAttribute[] attrs)
-    {
-        if (_incomplete)
+    public void saveGlobalAttributes(SchemaGlobalAttribute[] attrs) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
-        for (int i = 0; i < attrs.length; i++)
-        {
+        }
+        for (int i = 0; i < attrs.length; i++) {
             saveGlobalAttribute(attrs[i]);
         }
     }
 
-    public void saveModelGroups(SchemaModelGroup[] groups)
-    {
-        if (_incomplete)
+    public void saveModelGroups(SchemaModelGroup[] groups) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
-        for (int i = 0; i < groups.length; i++)
-        {
+        }
+        for (int i = 0; i < groups.length; i++) {
             saveModelGroup(groups[i]);
         }
     }
 
-    public void saveAttributeGroups(SchemaAttributeGroup[] groups)
-    {
-        if (_incomplete)
+    public void saveAttributeGroups(SchemaAttributeGroup[] groups) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
-        for (int i = 0; i < groups.length; i++)
-        {
+        }
+        for (int i = 0; i < groups.length; i++) {
             saveAttributeGroup(groups[i]);
         }
     }
 
-    public void saveIdentityConstraints(SchemaIdentityConstraint[] idcs)
-    {
-        if (_incomplete)
+    public void saveIdentityConstraints(SchemaIdentityConstraint[] idcs) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
-        for (int i = 0; i < idcs.length; i++)
-        {
+        }
+        for (int i = 0; i < idcs.length; i++) {
             saveIdentityConstraint(idcs[i]);
         }
     }
 
-    public void saveGlobalElement(SchemaGlobalElement elt)
-    {
-        if (_incomplete)
+    public void saveGlobalElement(SchemaGlobalElement elt) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
+        }
         String handle = _localHandles.handleForElement(elt);
         XsbReader saver = new XsbReader(handle);
-        saver.writeParticleData((SchemaParticle)elt);
+        saver.writeParticleData((SchemaParticle) elt);
         saver.writeString(elt.getSourceName());
         saver.writeRealHeader(handle, FILETYPE_SCHEMAELEMENT);
-        saver.writeParticleData((SchemaParticle)elt);
+        saver.writeParticleData((SchemaParticle) elt);
         saver.writeString(elt.getSourceName());
         saver.writeEnd();
     }
 
-    public void saveGlobalAttribute(SchemaGlobalAttribute attr)
-    {
-        if (_incomplete)
+    public void saveGlobalAttribute(SchemaGlobalAttribute attr) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
+        }
         String handle = _localHandles.handleForAttribute(attr);
         XsbReader saver = new XsbReader(handle);
         saver.writeAttributeData(attr);
@@ -1446,10 +1319,10 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    public void saveModelGroup(SchemaModelGroup grp)
-    {
-        if (_incomplete)
+    public void saveModelGroup(SchemaModelGroup grp) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
+        }
         String handle = _localHandles.handleForModelGroup(grp);
         XsbReader saver = new XsbReader(handle);
         saver.writeModelGroupData(grp);
@@ -1458,10 +1331,10 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    public void saveAttributeGroup(SchemaAttributeGroup grp)
-    {
-        if (_incomplete)
+    public void saveAttributeGroup(SchemaAttributeGroup grp) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
+        }
         String handle = _localHandles.handleForAttributeGroup(grp);
         XsbReader saver = new XsbReader(handle);
         saver.writeAttributeGroupData(grp);
@@ -1470,10 +1343,10 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    public void saveIdentityConstraint(SchemaIdentityConstraint idc)
-    {
-        if (_incomplete)
+    public void saveIdentityConstraint(SchemaIdentityConstraint idc) {
+        if (_incomplete) {
             throw new IllegalStateException("This SchemaTypeSystem cannot be saved.");
+        }
         String handle = _localHandles.handleForIdentityConstraint(idc);
         XsbReader saver = new XsbReader(handle);
         saver.writeIdConstraintData(idc);
@@ -1482,8 +1355,7 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    void saveType(SchemaType type)
-    {
+    void saveType(SchemaType type) {
         String handle = _localHandles.handleForType(type);
         XsbReader saver = new XsbReader(handle);
         saver.writeTypeData(type);
@@ -1492,51 +1364,53 @@ public class SchemaTypeSystemImpl extend
         saver.writeEnd();
     }
 
-    public static String crackPointer(InputStream stream)
-    {
+    public static String crackPointer(InputStream stream) {
         DataInputStream input = null;
-        try
-        {
+        try {
             input = new DataInputStream(stream);
 
             int magic = input.readInt();
-            if (magic != DATA_BABE)
+            if (magic != DATA_BABE) {
                 return null;
+            }
 
             int majorver = input.readShort();
             int minorver = input.readShort();
 
-            if (majorver != MAJOR_VERSION)
+            if (majorver != MAJOR_VERSION) {
                 return null;
+            }
 
-            if (minorver > MINOR_VERSION)
+            if (minorver > MINOR_VERSION) {
                 return null;
+            }
 
-            if (majorver > 2 || majorver == 2 && minorver >= 18)
+            if (majorver > 2 || majorver == 2 && minorver >= 18) {
                 input.readShort(); // release number present in atLeast(2, 18, 0)
+            }
 
             int actualfiletype = input.readShort();
-            if (actualfiletype != FILETYPE_SCHEMAPOINTER)
+            if (actualfiletype != FILETYPE_SCHEMAPOINTER) {
                 return null;
+            }
 
             StringPool stringPool = new StringPool("pointer", "unk");
             stringPool.readFrom(input);
 
             return stringPool.stringForCode(input.readShort());
-        }
-        catch (IOException e)
-        {
+        } catch (IOException e) {
             return null;
-        }
-        finally
-        {
-            if (input != null)
-                try { input.close(); } catch (IOException e) {}
+        } finally {
+            if (input != null) {
+                try {
+                    input.close();
+                } catch (IOException e) {
+                }
+            }
         }
     }
 
-    private class XsbReader
-    {
+    private class XsbReader {
         DataInputStream _input;
         DataOutputStream _output;
         StringPool _stringPool;
@@ -1546,42 +1420,48 @@ public class SchemaTypeSystemImpl extend
         private int _releaseno;
         int _actualfiletype;
 
-        public XsbReader(String handle, int filetype)
-        {
+        public XsbReader(String handle, int filetype) {
             String resourcename = _basePackage + handle + ".xsb";
             InputStream rawinput = getLoaderStream(resourcename);
-            if (rawinput == null)
+            if (rawinput == null) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Could not locate compiled schema resource " + resourcename, _name, handle, SchemaTypeLoaderException.NO_RESOURCE);
+            }
 
             _input = new DataInputStream(rawinput);
             _handle = handle;
 
             int magic = readInt();
-            if (magic != DATA_BABE)
+            if (magic != DATA_BABE) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Wrong magic cookie", _name, handle, SchemaTypeLoaderException.WRONG_MAGIC_COOKIE);
+            }
 
             _majorver = readShort();
             _minorver = readShort();
 
-            if (_majorver != MAJOR_VERSION)
+            if (_majorver != MAJOR_VERSION) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Wrong major version - expecting " + MAJOR_VERSION + ", got " + _majorver, _name, handle, SchemaTypeLoaderException.WRONG_MAJOR_VERSION);
+            }
 
-            if (_minorver > MINOR_VERSION)
+            if (_minorver > MINOR_VERSION) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Incompatible minor version - expecting up to " + MINOR_VERSION + ", got " + _minorver, _name, handle, SchemaTypeLoaderException.WRONG_MINOR_VERSION);
+            }
 
             // Clip to 14 because we're not backward compatible with earlier
             // minor versions.  Remove this when upgrading to a new major
             // version
 
-            if (_minorver < 14)
+            if (_minorver < 14) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Incompatible minor version - expecting at least 14, got " + _minorver, _name, handle, SchemaTypeLoaderException.WRONG_MINOR_VERSION);
+            }
 
-            if (atLeast(2, 18, 0))
+            if (atLeast(2, 18, 0)) {
                 _releaseno = readShort();
+            }
 
             int actualfiletype = readShort();
-            if (actualfiletype != filetype && filetype != 0xFFFF)
+            if (actualfiletype != filetype && filetype != 0xFFFF) {
                 throw new SchemaTypeLoaderException("XML-BEANS compiled schema: File has the wrong type - expecting type " + filetype + ", got type " + actualfiletype, _name, handle, SchemaTypeLoaderException.WRONG_FILE_TYPE);
+            }
 
             _stringPool = new StringPool(_handle, _name);
             _stringPool.readFrom(_input);
@@ -1589,56 +1469,61 @@ public class SchemaTypeSystemImpl extend
             _actualfiletype = actualfiletype;
         }
 
-        protected boolean atLeast(int majorver, int minorver, int releaseno)
-        {
-            if (_majorver > majorver)
+        protected boolean atLeast(int majorver, int minorver, int releaseno) {
+            if (_majorver > majorver) {
                 return true;
-            if (_majorver < majorver)
+            }
+            if (_majorver < majorver) {
                 return false;
-            if (_minorver > minorver)
+            }
+            if (_minorver > minorver) {
                 return true;
-            if (_minorver < minorver)
+            }
+            if (_minorver < minorver) {
                 return false;
+            }
             return (_releaseno >= releaseno);
         }
 
-        protected boolean atMost(int majorver, int minorver, int releaseno)
-        {
-            if (_majorver > majorver)
+        protected boolean atMost(int majorver, int minorver, int releaseno) {
+            if (_majorver > majorver) {
                 return false;
-            if (_majorver < majorver)
+            }
+            if (_majorver < majorver) {
                 return true;
-            if (_minorver > minorver)
+            }
+            if (_minorver > minorver) {
                 return false;
-            if (_minorver < minorver)
+            }
+            if (_minorver < minorver) {
                 return true;
+            }
             return (_releaseno <= releaseno);
         }
 
-        int getActualFiletype()
-        {
+        int getActualFiletype() {
             return _actualfiletype;
         }
 
-        XsbReader(String handle)
-        {
+        XsbReader(String handle) {
             _handle = handle;
             _stringPool = new StringPool(_handle, _name);
         }
 
-        void writeRealHeader(String handle, int filetype)
-        {
+        void writeRealHeader(String handle, int filetype) {
             // hackeroo: if handle contains a "/" it's not relative.
             String resourcename;
 
-            if (handle.indexOf('/') >= 0)
+            if (handle.indexOf('/') >= 0) {
                 resourcename = handle + ".xsb";
-            else
+            } else {
                 resourcename = _basePackage + handle + ".xsb";
+            }
 
             OutputStream rawoutput = getSaverStream(resourcename);
-            if (rawoutput == null)
+            if (rawoutput == null) {
                 throw new SchemaTypeLoaderException("Could not write compiled schema resource " + resourcename, _name, handle, SchemaTypeLoaderException.NOT_WRITEABLE);
+            }
 
             _output = new DataOutputStream(rawoutput);
             _handle = handle;
@@ -1652,15 +1537,12 @@ public class SchemaTypeSystemImpl extend
             _stringPool.writeTo(_output);
         }
 
-        void readEnd()
-        {
-            try
-            {
-                if (_input != null)
+        void readEnd() {
+            try {
+                if (_input != null) {
                     _input.close();
-            }
-            catch (IOException e)
-            {
+                }
+            } catch (IOException e) {
                 // oh, well.
             }
             _input = null;
@@ -1668,29 +1550,22 @@ public class SchemaTypeSystemImpl extend
             _handle = null;
         }
 
-        void writeEnd()
-        {
-            try
-            {
-                if (_output != null)
-                {
+        void writeEnd() {
+            try {
+                if (_output != null) {
                     _output.flush();
                     _output.close();
                 }
-            }
-            catch (IOException e)
-            {
-                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+            } catch (IOException e) {
+                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
             _output = null;
             _stringPool = null;
             _handle = null;
         }
 
-        int fileTypeFromComponentType(int componentType)
-        {
-            switch (componentType)
-            {
+        int fileTypeFromComponentType(int componentType) {
+            switch (componentType) {
                 case SchemaComponent.TYPE:
                     return SchemaTypeSystemImpl.FILETYPE_SCHEMATYPE;
                 case SchemaComponent.ELEMENT:
@@ -1708,8 +1583,7 @@ public class SchemaTypeSystemImpl extend
             }
         }
 
-        void writeIndexData()
-        {
+        void writeIndexData() {
             // has a handle pool (count, handle/type, handle/type...)
             writeHandlePool(_localHandles);
 
@@ -1750,32 +1624,28 @@ public class SchemaTypeSystemImpl extend
             writeAnnotations(annotations());
         }
 
-        void writeHandlePool(HandlePool pool)
-        {
+        void writeHandlePool(HandlePool pool) {
             writeShort(pool._componentsToHandles.size());
-            for (Iterator i = pool._componentsToHandles.keySet().iterator(); i.hasNext(); )
-            {
-                SchemaComponent comp = (SchemaComponent)i.next();
-                String handle = (String)pool._componentsToHandles.get(comp);
+            for (Iterator i = pool._componentsToHandles.keySet().iterator(); i.hasNext(); ) {
+                SchemaComponent comp = (SchemaComponent) i.next();
+                String handle = (String) pool._componentsToHandles.get(comp);
                 int code = fileTypeFromComponentType(comp.getComponentType());
                 writeString(handle);
                 writeShort(code);
             }
         }
 
-        void readHandlePool(HandlePool pool)
-        {
-            if (pool._handlesToRefs.size() != 0 || pool._started)
+        void readHandlePool(HandlePool pool) {
+            if (pool._handlesToRefs.size() != 0 || pool._started) {
                 throw new IllegalStateException("Nonempty handle set before read");
+            }
 
             int size = readShort();
-            for (int i = 0; i < size; i++)
-            {
+            for (int i = 0; i < size; i++) {
                 String handle = readString();
                 int code = readShort();
                 Object result;
-                switch (code)
-                {
+                switch (code) {
                     case FILETYPE_SCHEMATYPE:
                         result = new SchemaType.Ref(getTypeSystem(), handle);
                         break;
@@ -1801,86 +1671,65 @@ public class SchemaTypeSystemImpl extend
             }
         }
 
-        int readShort()
-        {
-            try
-            {
+        int readShort() {
+            try {
                 return _input.readUnsignedShort();
-            }
-            catch (IOException e)
-            {
-                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+            } catch (IOException e) {
+                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
         }
 
-        void writeShort(int s)
-        {
-            if (s >= MAX_UNSIGNED_SHORT || s < -1)
+        void writeShort(int s) {
+            if (s >= MAX_UNSIGNED_SHORT || s < -1) {
                 throw new SchemaTypeLoaderException("Value " + s + " out of range: must fit in a 16-bit unsigned short.", _name, _handle, SchemaTypeLoaderException.INT_TOO_LARGE);
-            if (_output != null)
-            {
-                try
-                {
+            }
+            if (_output != null) {
+                try {
                     _output.writeShort(s);
-                }
-                catch (IOException e)
-                {
-                    throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+                } catch (IOException e) {
+                    throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
                 }
             }
         }
 
-        int readInt()
-        {
-            try
-            {
+        int readInt() {
+            try {
                 return _input.readInt();
-            }
-            catch (IOException e)
-            {
-                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+            } catch (IOException e) {
+                throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
             }
         }
 
-        void writeInt(int i)
-        {
-            if (_output != null)
-            {
-                try
-                {
+        void writeInt(int i) {
+            if (_output != null) {
+                try {
                     _output.writeInt(i);
-                }
-                catch (IOException e)
-                {
-                    throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION);
+                } catch (IOException e) {
+                    throw new SchemaTypeLoaderException(e.getMessage(), _name, _handle, SchemaTypeLoaderException.IO_EXCEPTION, e);
                 }
             }
         }
 
-        String readString()
-        {
+        String readString() {
             return _stringPool.stringForCode(readShort());
         }
 
-        void writeString(String str)
-        {
+        void writeString(String str) {
             int code = _stringPool.codeForString(str);
             writeShort(code);
         }
 
-        QName readQName()
-        {
+        QName readQName() {
             String namespace = readString();
             String localname = readString();
-            if (localname == null)
+            if (localname == null) {
                 return null;
+            }
             return new QName(namespace, localname);
         }
 
-        void writeQName(QName qname)
-        {
-            if (qname == null)
-            {
+        void writeQName(QName qname) {
+            if (qname == null) {
                 writeString(null);
                 writeString(null);
                 return;
@@ -1889,41 +1738,34 @@ public class SchemaTypeSystemImpl extend
             writeString(qname.getLocalPart());
         }
 
-        SOAPArrayType readSOAPArrayType()
-        {
+        SOAPArrayType readSOAPArrayType() {
             QName qName = readQName();
             String dimensions = readString();
-            if (qName == null)
+            if (qName == null) {
                 return null;
+            }
             return new SOAPArrayType(qName, dimensions);
         }
 
-        void writeSOAPArrayType(SOAPArrayType arrayType)
-        {
-            if (arrayType == null)
-            {
+        void writeSOAPArrayType(SOAPArrayType arrayType) {
+            if (arrayType == null) {
                 writeQName(null);
                 writeString(null);
-            }
-            else
-            {
+            } else {
                 writeQName(arrayType.getQName());
                 writeString(arrayType.soap11DimensionString());
             }
         }
 
-        void writeAnnotation(SchemaAnnotation a)
-        {
+        void writeAnnotation(SchemaAnnotation a) {
             // Write attributes
-            if (a == null)
-            {
+            if (a == null) {
                 writeInt(-1);
                 return;
             }
             SchemaAnnotation.Attribute[] attributes = a.getAttributes();
             writeInt(attributes.length);
-            for (int i = 0; i < attributes.length; i++)
-            {
+            for (int i = 0; i < attributes.length; i++) {
                 QName name = attributes[i].getName();
                 String value = attributes[i].getValue();
                 String valueURI = attributes[i].getValueUri();
@@ -1937,8 +1779,7 @@ public class SchemaTypeSystemImpl extend
             writeInt(documentationItems.length);
             XmlOptions opt = new XmlOptions().setSaveOuter().
                 setSaveAggressiveNamespaces();
-            for (int i = 0; i < documentationItems.length; i++)
-            {
+            for (int i = 0; i < documentationItems.length; i++) {
                 XmlObject doc = documentationItems[i];
                 writeString(doc.xmlText(opt));
             }
@@ -1946,46 +1787,44 @@ public class SchemaTypeSystemImpl extend
             // Write application info items
             XmlObject[] appInfoItems = a.getApplicationInformation();
             writeInt(appInfoItems.length);
-            for (int i = 0; i < appInfoItems.length; i++)
-            {
+            for (int i = 0; i < appInfoItems.length; i++) {
                 XmlObject doc = appInfoItems[i];
                 writeString(doc.xmlText(opt));
             }
         }
 
-        SchemaAnnotation readAnnotation(SchemaContainer c)
-        {
-            if (!atLeast(2, 19, 0))
+        SchemaAnnotation readAnnotation(SchemaContainer c) {
+            if (!atLeast(2, 19, 0)) {
                 return null; // no annotations for this version of the file
+            }
             // Read attributes
             int n = readInt();
-            if (n == -1)
+            if (n == -1) {
                 return null;
+            }
             SchemaAnnotation.Attribute[] attributes =
                 new SchemaAnnotation.Attribute[n];
-            for (int i = 0; i < n; i++)
-            {
+            for (int i = 0; i < n; i++) {
                 QName name = readQName();
                 String value = readString();
                 String valueUri = null;
-                if (atLeast(2, 24, 0))
+                if (atLeast(2, 24, 0)) {
                     valueUri = readString();
+                }
                 attributes[i] = new SchemaAnnotationImpl.AttributeImpl(name, value, valueUri);
             }
 
             // Read documentation items
             n = readInt();
             String[] docStrings = new String[n];
-            for (int i = 0; i <  n; i++)
-            {
+            for (int i = 0; i < n; i++) {
                 docStrings[i] = readString();
             }
 
             // Read application info items
             n = readInt();
             String[] appInfoStrings = new String[n];
-            for (int i = 0; i < n; i++)
-            {
+            for (int i = 0; i < n; i++) {
                 appInfoStrings[i] = readString();
             }
 
@@ -1993,39 +1832,40 @@ public class SchemaTypeSystemImpl extend
                 docStrings, attributes);
         }
 
-        void writeAnnotations(SchemaAnnotation[] anns)
-        {
+        void writeAnnotations(SchemaAnnotation[] anns) {
             writeInt(anns.length);
-            for (int i = 0; i < anns.length; i++)
+            for (int i = 0; i < anns.length; i++) {
                 writeAnnotation(anns[i]);
+            }
         }
 
-        List readAnnotations()
-        {
+        List readAnnotations() {
             int n = readInt();
             List result = new ArrayList(n);
             // BUGBUG(radup)
             SchemaContainer container = getContainerNonNull("");
-            for (int i = 0; i < n; i++)
+            for (int i = 0; i < n; i++) {
                 result.add(readAnnotation(container));
+            }
             return result;
         }
 
-        SchemaComponent.Ref readHandle()
-        {
+        SchemaComponent.Ref readHandle() {
             String handle = readString();
-            if (handle == null)
+            if (handle == null) {
                 return null;
+            }
 
-            if (handle.charAt(0) != '_')
+            if (handle.charAt(0) != '_') {
                 return _localHandles.refForHandle(handle);
+            }
 
-            switch (handle.charAt(2))
-            {
+            switch (handle.charAt(2)) {
                 case 'I': // _BI_ - built-in schema type system
                     SchemaType st = (SchemaType) BuiltinSchemaTypeSystem.get().resolveHandle(handle);
-                    if (st != null)
+                    if (st != null) {
                         return st.getRef();
+                    }
                     st = (SchemaType) XQuerySchemaTypeSystem.get().resolveHandle(handle);
                     return st.getRef();
                 case 'T': // _XT_ - external type
@@ -2043,37 +1883,37 @@ public class SchemaTypeSystemImpl extend
                 case 'R': // _XR_ - external ref to attribute's type
                     // deprecated: replaced by _XY_
                     SchemaGlobalAttribute attr = _linker.findAttribute(QNameHelper.forPretty(handle, 4));
-                    if (attr == null)
+                    if (attr == null) {
                         throw new SchemaTypeLoaderException("Cannot resolve attribute for handle " + handle, _name, _handle, SchemaTypeLoaderException.BAD_HANDLE);
+                    }
                     return attr.getType().getRef();
                 case 'S': // _XS_ - external ref to element's type
                     // deprecated: replaced by _XY_

[... 2110 lines stripped ...]


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