You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2005/03/01 19:49:18 UTC

svn commit: r155813 [2/3] - in xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store: Locale.java Xobj.java

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java?view=diff&r1=155812&r2=155813
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Locale.java Tue Mar  1 10:49:16 2005
@@ -106,36 +106,39 @@
 import org.apache.xmlbeans.impl.piccolo.xml.Piccolo;
 import org.apache.xmlbeans.impl.piccolo.io.FileFormatException;
 
-public final class Locale implements DOMImplementation, SaajCallback, XmlLocale
+public final class Locale
+    implements DOMImplementation, SaajCallback, XmlLocale
 {
-    static final int ROOT     = Cur.ROOT;
-    static final int ELEM     = Cur.ELEM;
-    static final int ATTR     = Cur.ATTR;
-    static final int COMMENT  = Cur.COMMENT;
+    static final int ROOT = Cur.ROOT;
+    static final int ELEM = Cur.ELEM;
+    static final int ATTR = Cur.ATTR;
+    static final int COMMENT = Cur.COMMENT;
     static final int PROCINST = Cur.PROCINST;
-    static final int TEXT     = Cur.TEXT;
+    static final int TEXT = Cur.TEXT;
 
     static final int WS_UNSPECIFIED = TypeStore.WS_UNSPECIFIED;
-    static final int WS_PRESERVE    = TypeStore.WS_PRESERVE;
-    static final int WS_REPLACE     = TypeStore.WS_REPLACE;
-    static final int WS_COLLAPSE    = TypeStore.WS_COLLAPSE;
-                                        
-    static final String _xsi         = "http://www.w3.org/2001/XMLSchema-instance";
-    static final String _schema      = "http://www.w3.org/2001/XMLSchema";
+    static final int WS_PRESERVE = TypeStore.WS_PRESERVE;
+    static final int WS_REPLACE = TypeStore.WS_REPLACE;
+    static final int WS_COLLAPSE = TypeStore.WS_COLLAPSE;
+
+    static final String _xsi = "http://www.w3.org/2001/XMLSchema-instance";
+    static final String _schema = "http://www.w3.org/2001/XMLSchema";
     static final String _openFragUri = "http://www.openuri.org/fragment";
-    static final String _xml1998Uri  = "http://www.w3.org/XML/1998/namespace";
-    static final String _xmlnsUri    = "http://www.w3.org/2000/xmlns/";
-    
-    static final QName _xsiNil          = new QName( _xsi, "nil", "xsi" );
-    static final QName _xsiType         = new QName( _xsi, "type", "xsi" );
-    static final QName _xsiLoc          = new QName( _xsi, "schemaLocation", "xsi" );
-    static final QName _xsiNoLoc        = new QName( _xsi, "noNamespaceSchemaLocation", "xsi" );
-    static final QName _openuriFragment = new QName( _openFragUri, "fragment", "frag" );
-    static final QName _xmlFragment     = new QName( "xml-fragment" );
+    static final String _xml1998Uri = "http://www.w3.org/XML/1998/namespace";
+    static final String _xmlnsUri = "http://www.w3.org/2000/xmlns/";
+
+    static final QName _xsiNil = new QName(_xsi, "nil", "xsi");
+    static final QName _xsiType = new QName(_xsi, "type", "xsi");
+    static final QName _xsiLoc = new QName(_xsi, "schemaLocation", "xsi");
+    static final QName _xsiNoLoc = new QName(_xsi, "noNamespaceSchemaLocation",
+        "xsi");
+    static final QName _openuriFragment = new QName(_openFragUri, "fragment",
+        "frag");
+    static final QName _xmlFragment = new QName("xml-fragment");
 
-    private Locale ( SchemaTypeLoader stl, XmlOptions options )
+    private Locale(SchemaTypeLoader stl, XmlOptions options)
     {
-        options = XmlOptions.maskNull( options );
+        options = XmlOptions.maskNull(options);
 
         //
         //
@@ -146,9 +149,9 @@
         // Also - have a thread local setting for thread safety?  .. Perhaps something
         // in the type loader which defines whether ot not sync is on????
         
-        _noSync = options.hasOption( XmlOptions.UNSYNCHRONIZED );
-        
-        _tempFrames = new Cur [ _numTempFramesLeft = 8 ];
+        _noSync = options.hasOption(XmlOptions.UNSYNCHRONIZED);
+
+        _tempFrames = new Cur[_numTempFramesLeft = 8];
 
         // BUGBUG - this cannot be thread local ....
         // BUGBUG - this cannot be thread local ....
@@ -159,26 +162,27 @@
         
         _qnameFactory = new DefaultQNameFactory();
 
-        _locations = new Locations( this );
+        _locations = new Locations(this);
 
         _schemaTypeLoader = stl;
 
-        _validateOnSet = options.hasOption( XmlOptions.VALIDATE_ON_SET );
+        _validateOnSet = options.hasOption(XmlOptions.VALIDATE_ON_SET);
         
         //
         // Check for Saaj implementation request
         //
         
-        Object saajObj = options.get( Saaj.SAAJ_IMPL );
+        Object saajObj = options.get(Saaj.SAAJ_IMPL);
 
         if (saajObj != null)
         {
             if (!(saajObj instanceof Saaj))
-                throw new IllegalStateException( "Saaj impl not correct type: " + saajObj );
+                throw new IllegalStateException(
+                    "Saaj impl not correct type: " + saajObj);
 
             _saaj = (Saaj) saajObj;
-            
-            _saaj.setCallback( this );
+
+            _saaj.setCallback(this);
         }
     }
 
@@ -187,40 +191,45 @@
     //
 
     public static final String USE_SAME_LOCALE = "USE_SAME_LOCALE";
-    
-    static Locale getLocale ( SchemaTypeLoader stl, XmlOptions options )
+
+    static Locale getLocale(SchemaTypeLoader stl, XmlOptions options)
     {
         if (stl == null)
             stl = XmlBeans.getContextTypeLoader();
-        
-        options = XmlOptions.maskNull( options );
+
+        options = XmlOptions.maskNull(options);
 
         Locale l = null;
-        
-        if (options.hasOption( USE_SAME_LOCALE ))
+
+        if (options.hasOption(USE_SAME_LOCALE))
         {
-            Object source = options.get( USE_SAME_LOCALE );
+            Object source = options.get(USE_SAME_LOCALE);
 
             if (source instanceof Locale)
                 l = (Locale) source;
             else if (source instanceof XmlTokenSource)
                 l = (Locale) ((XmlTokenSource) source).monitor();
             else
-                throw new IllegalArgumentException( "Source locale not understood: " + source );
+                throw new IllegalArgumentException(
+                    "Source locale not understood: " + source);
 
             if (l._schemaTypeLoader != stl)
-                throw new IllegalArgumentException( "Source locale does not support same schema type loader" );
-            
-            if (l._saaj != null && l._saaj != options.get( Saaj.SAAJ_IMPL ))
-                throw new IllegalArgumentException( "Source locale does not support same saaj" );
+                throw new IllegalArgumentException(
+                    "Source locale does not support same schema type loader");
 
-            if (l._validateOnSet && !options.hasOption( XmlOptions.VALIDATE_ON_SET ))
-                throw new IllegalArgumentException( "Source locale does not support same validate on set" );
+            if (l._saaj != null && l._saaj != options.get(Saaj.SAAJ_IMPL))
+                throw new IllegalArgumentException(
+                    "Source locale does not support same saaj");
+
+            if (l._validateOnSet &&
+                !options.hasOption(XmlOptions.VALIDATE_ON_SET))
+                throw new IllegalArgumentException(
+                    "Source locale does not support same validate on set");
 
             // TODO - other things to check?
         }
         else
-            l = new Locale( stl, options );
+            l = new Locale(stl, options);
 
         return l;
     }
@@ -229,32 +238,35 @@
     //
     //
     
-    static void associateSourceName ( Cur c, XmlOptions options )
+    static void associateSourceName(Cur c, XmlOptions options)
     {
-        String sourceName = (String) XmlOptions.safeGet( options, XmlOptions.DOCUMENT_SOURCE_NAME );
+        String sourceName = (String) XmlOptions.safeGet(options,
+            XmlOptions.DOCUMENT_SOURCE_NAME);
 
         if (sourceName != null)
-            getDocProps( c, true ).setSourceName( sourceName );
+            getDocProps(c, true).setSourceName(sourceName);
     }
 
     //
     //
     //
     
-    static void autoTypeDocument ( Cur c, SchemaType requestedType, XmlOptions options )
+    static void autoTypeDocument(Cur c, SchemaType requestedType,
+        XmlOptions options)
         throws XmlException
     {
         assert c.isRoot();
 
         // The type in the options overrides all sniffing
 
-        options = XmlOptions.maskNull( options );
-        
-        SchemaType optionType = (SchemaType) options.get( XmlOptions.DOCUMENT_TYPE );
+        options = XmlOptions.maskNull(options);
+
+        SchemaType optionType = (SchemaType) options.get(
+            XmlOptions.DOCUMENT_TYPE);
 
         if (optionType != null)
         {
-            c.setType( optionType );
+            c.setType(optionType);
             return;
         }
 
@@ -268,55 +280,62 @@
             QName xsiTypeName = c.getXsiTypeName();
 
             SchemaType xsiSchemaType =
-                xsiTypeName == null ? null : c._locale._schemaTypeLoader.findType( xsiTypeName );
+                xsiTypeName == null ?
+                null : c._locale._schemaTypeLoader.findType(xsiTypeName);
 
-            if (requestedType == null || requestedType.isAssignableFrom( xsiSchemaType ))
+            if (requestedType == null ||
+                requestedType.isAssignableFrom(xsiSchemaType))
                 type = xsiSchemaType;
         }
 
         // Look for a document element to establish type
         
-        if (type == null && (requestedType == null || requestedType.isDocumentType()))
+        if (type == null &&
+            (requestedType == null || requestedType.isDocumentType()))
         {
             assert c.isRoot();
-            
+
             c.push();
 
             QName docElemName =
-                !c.hasAttrs() && Locale.toFirstChildElement( c ) &&
-                    !Locale.toNextSiblingElement( c )
-                        ? c.getName() : null;
+                !c.hasAttrs() && Locale.toFirstChildElement(c) &&
+                !Locale.toNextSiblingElement(c)
+                ? c.getName() : null;
 
             c.pop();
 
             if (docElemName != null)
             {
-                type = c._locale._schemaTypeLoader.findDocumentType( docElemName );
+                type =
+                    c._locale._schemaTypeLoader.findDocumentType(docElemName);
 
                 if (type != null && requestedType != null)
                 {
                     QName requesteddocElemNameName = requestedType.getDocumentElementName();
-                    
-                    if (!requesteddocElemNameName.equals( docElemName ) &&
-                            !requestedType.isValidSubstitution( docElemName ))
+
+                    if (!requesteddocElemNameName.equals(docElemName) &&
+                        !requestedType.isValidSubstitution(docElemName))
                     {
                         throw
-                            new XmlException(
-                                "Element " + QNameHelper.pretty( docElemName ) +
-                                " is not a valid " + QNameHelper.pretty( requesteddocElemNameName ) +
-                                " document or a valid substitution.");
+                            new XmlException("Element " +
+                            QNameHelper.pretty(docElemName) +
+                            " is not a valid " +
+                            QNameHelper.pretty(requesteddocElemNameName) +
+                            " document or a valid substitution.");
                     }
                 }
             }
         }
-        
+
         if (type == null && requestedType == null)
         {
             c.push();
 
             type =
-                Locale.toFirstNormalAttr( c ) && !Locale.toNextNormalAttr( c )
-                  ? c._locale._schemaTypeLoader.findAttributeType( c.getName() ) : null;
+                Locale.toFirstNormalAttr(c) && !Locale.toNextNormalAttr(c)
+                ?
+                c._locale._schemaTypeLoader.findAttributeType(c.getName()) :
+                null;
 
             c.pop();
         }
@@ -327,18 +346,18 @@
         if (type == null)
             type = XmlBeans.NO_TYPE;
 
-        c.setType( type );
+        c.setType(type);
 
         if (requestedType != null)
         {
             if (type.isDocumentType())
-                verifyDocumentType( c, type.getDocumentElementName() );
+                verifyDocumentType(c, type.getDocumentElementName());
             else if (type.isAttributeType())
-                verifyAttributeType( c, type.getAttributeTypeAttributeName() );
+                verifyAttributeType(c, type.getAttributeTypeAttributeName());
         }
     }
-    
-    private static boolean namespacesSame ( QName n1, QName n2 )
+
+    private static boolean namespacesSame(QName n1, QName n2)
     {
         if (n1 == n2)
             return true;
@@ -352,77 +371,82 @@
         if (n1.getNamespaceURI() == null || n2.getNamespaceURI() == null)
             return false;
 
-        return n1.getNamespaceURI().equals( n2.getNamespaceURI() );
+        return n1.getNamespaceURI().equals(n2.getNamespaceURI());
     }
 
-    private static void addNamespace ( StringBuffer sb, QName name )
+    private static void addNamespace(StringBuffer sb, QName name)
     {
         if (name.getNamespaceURI() == null)
-            sb.append( "<no namespace>" );
+            sb.append("<no namespace>");
         else
         {
-            sb.append( "\"" );
-            sb.append( name.getNamespaceURI() );
-            sb.append( "\"" );
+            sb.append("\"");
+            sb.append(name.getNamespaceURI());
+            sb.append("\"");
         }
     }
 
-    private static void verifyDocumentType ( Cur c, QName docElemName ) throws XmlException
+    private static void verifyDocumentType(Cur c, QName docElemName)
+        throws XmlException
     {
         assert c.isRoot();
-        
+
         c.push();
 
         try
         {
             StringBuffer sb = null;
 
-            if (!Locale.toFirstChildElement( c ) || Locale.toNextSiblingElement( c ))
+            if (!Locale.toFirstChildElement(c) ||
+                Locale.toNextSiblingElement(c))
             {
                 sb = new StringBuffer();
 
-                sb.append( "The document is not a " );
-                sb.append( QNameHelper.pretty( docElemName ) );
-                sb.append( c.isRoot() ? ": no document element" : ": multiple document elements" );
+                sb.append("The document is not a ");
+                sb.append(QNameHelper.pretty(docElemName));
+                sb.append(
+                    c.isRoot() ?
+                    ": no document element" : ": multiple document elements");
             }
             else
             {
                 QName name = c.getName();
 
-                if (!name.equals( docElemName ))
+                if (!name.equals(docElemName))
                 {
                     sb = new StringBuffer();
 
-                    sb.append( "The document is not a " );
-                    sb.append( QNameHelper.pretty( docElemName ) );
+                    sb.append("The document is not a ");
+                    sb.append(QNameHelper.pretty(docElemName));
 
-                    if (docElemName.getLocalPart().equals( name.getLocalPart() ))
+                    if (docElemName.getLocalPart().equals(name.getLocalPart()))
                     {
-                        sb.append( ": document element namespace mismatch " );
-                        sb.append( "expected " );
-                        addNamespace( sb, docElemName );
-                        sb.append( " got " );
-                        addNamespace(sb,  name );
+                        sb.append(": document element namespace mismatch ");
+                        sb.append("expected ");
+                        addNamespace(sb, docElemName);
+                        sb.append(" got ");
+                        addNamespace(sb, name);
                     }
-                    else if (namespacesSame( docElemName, name ))
+                    else if (namespacesSame(docElemName, name))
                     {
-                        sb.append( ": document element local name mismatch " );
-                        sb.append( "expected " + docElemName.getLocalPart() );
-                        sb.append( " got " + name.getLocalPart() );
+                        sb.append(": document element local name mismatch ");
+                        sb.append("expected " + docElemName.getLocalPart());
+                        sb.append(" got " + name.getLocalPart());
                     }
                     else
                     {
-                        sb.append( ": document element mismatch " );
-                        sb.append( "got " );
-                        sb.append( QNameHelper.pretty( name ) );
+                        sb.append(": document element mismatch ");
+                        sb.append("got ");
+                        sb.append(QNameHelper.pretty(name));
                     }
                 }
             }
 
             if (sb != null)
             {
-                XmlError err = XmlError.forCursor( sb.toString(), new Cursor( c ) );
-                throw new XmlException( err.toString(), null, err );
+                XmlError err = XmlError.forCursor(sb.toString(),
+                    new Cursor(c));
+                throw new XmlException(err.toString(), null, err);
             }
         }
         finally
@@ -431,7 +455,8 @@
         }
     }
 
-    private static void verifyAttributeType ( Cur c, QName attrName ) throws XmlException
+    private static void verifyAttributeType(Cur c, QName attrName)
+        throws XmlException
     {
         assert c.isRoot();
 
@@ -441,52 +466,54 @@
         {
             StringBuffer sb = null;
 
-            if (!Locale.toFirstNormalAttr( c ) || Locale.toNextNormalAttr( c ))
+            if (!Locale.toFirstNormalAttr(c) || Locale.toNextNormalAttr(c))
             {
                 sb = new StringBuffer();
 
-                sb.append( "The document is not a " );
-                sb.append( QNameHelper.pretty( attrName ) );
-                sb.append( c.isRoot() ? ": no attributes" : ": multiple attributes" );
+                sb.append("The document is not a ");
+                sb.append(QNameHelper.pretty(attrName));
+                sb.append(
+                    c.isRoot() ? ": no attributes" : ": multiple attributes");
             }
             else
             {
                 QName name = c.getName();
 
-                if (!name.equals( attrName ))
+                if (!name.equals(attrName))
                 {
                     sb = new StringBuffer();
 
-                    sb.append( "The document is not a " );
-                    sb.append( QNameHelper.pretty( attrName ) );
+                    sb.append("The document is not a ");
+                    sb.append(QNameHelper.pretty(attrName));
 
-                    if (attrName.getLocalPart().equals( name.getLocalPart() ))
+                    if (attrName.getLocalPart().equals(name.getLocalPart()))
                     {
-                        sb.append( ": attribute namespace mismatch " );
-                        sb.append( "expected " );
-                        addNamespace( sb, attrName );
-                        sb.append( " got " );
-                        addNamespace(sb,  name );
+                        sb.append(": attribute namespace mismatch ");
+                        sb.append("expected ");
+                        addNamespace(sb, attrName);
+                        sb.append(" got ");
+                        addNamespace(sb, name);
                     }
-                    else if (namespacesSame( attrName, name ))
+                    else if (namespacesSame(attrName, name))
                     {
-                        sb.append( ": attribute local name mismatch " );
-                        sb.append( "expected " + attrName.getLocalPart() );
-                        sb.append( " got " + name.getLocalPart() );
+                        sb.append(": attribute local name mismatch ");
+                        sb.append("expected " + attrName.getLocalPart());
+                        sb.append(" got " + name.getLocalPart());
                     }
                     else
                     {
-                        sb.append( ": attribute element mismatch " );
-                        sb.append( "got " );
-                        sb.append( QNameHelper.pretty( name ) );
+                        sb.append(": attribute element mismatch ");
+                        sb.append("got ");
+                        sb.append(QNameHelper.pretty(name));
                     }
                 }
             }
 
             if (sb != null)
             {
-                XmlError err = XmlError.forCursor( sb.toString(), new Cursor( c ) );
-                throw new XmlException( err.toString(), null, err );
+                XmlError err = XmlError.forCursor(sb.toString(),
+                    new Cursor(c));
+                throw new XmlException(err.toString(), null, err);
             }
         }
         finally
@@ -495,12 +522,13 @@
         }
     }
 
-    static boolean isFragmentQName ( QName name )
+    static boolean isFragmentQName(QName name)
     {
-        return name.equals( Locale._openuriFragment ) || name.equals( Locale._xmlFragment );
+        return name.equals(Locale._openuriFragment) ||
+            name.equals(Locale._xmlFragment);
     }
 
-    static boolean isFragment ( Cur start, Cur end )
+    static boolean isFragment(Cur start, Cur end)
     {
         assert !end.isAttr();
 
@@ -509,15 +537,15 @@
 
         int numDocElems = 0;
         boolean isFrag = false;
-        
-        while ( ! start.isSamePos( end ) )
+
+        while (!start.isSamePos(end))
         {
             int k = start.kind();
 
             if (k == ATTR)
                 break;
-            
-            if (k == TEXT && !isWhiteSpace( start.getCharsAsString( -1 )))
+
+            if (k == TEXT && !isWhiteSpace(start.getCharsAsString(-1)))
             {
                 isFrag = true;
                 break;
@@ -532,10 +560,10 @@
             // Move to next token
 
             assert k != ATTR;
-            
+
             if (k != TEXT)
                 start.toEnd();
-            
+
             start.next();
         }
 
@@ -549,30 +577,55 @@
     //
     //
     
-    public static XmlObject newInstance (
-        SchemaTypeLoader stl, SchemaType type, XmlOptions options )
+    public static XmlObject newInstance(SchemaTypeLoader stl, SchemaType type,
+        XmlOptions options)
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.newInstance( type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.newInstance( type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.newInstance(type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.newInstance(type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    private XmlObject newInstance ( SchemaType type, XmlOptions options )
+    private XmlObject newInstance(SchemaType type, XmlOptions options)
     {
-        options = XmlOptions.maskNull( options );
-        
+        options = XmlOptions.maskNull(options);
+
         Cur c = tempCur();
 
-        c.createRoot();
 
-        SchemaType sType = (SchemaType) options.get( XmlOptions.DOCUMENT_TYPE );
+        SchemaType sType = (SchemaType) options.get(XmlOptions.DOCUMENT_TYPE);
 
         if (sType == null)
             sType = type == null ? XmlObject.type : type;
-
-        c.setType( sType );
-
+        if (sType.isDocumentType())
+            c.createDomDocumentRoot();
+        else
+             c.createRoot();
+        c.setType(sType);
+        
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
@@ -583,31 +636,55 @@
     //
     //
     //
-    
-    public static DOMImplementation newDomImplementation (
-        SchemaTypeLoader stl, XmlOptions options )
+
+    public static DOMImplementation newDomImplementation(SchemaTypeLoader stl,
+        XmlOptions options)
     {
-        return (DOMImplementation) getLocale( stl, options );
+        return (DOMImplementation) getLocale(stl, options);
     }
-            
+
     //
     //
     //
-    
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, String xmlText, SchemaType type, XmlOptions options )
-            throws XmlException
+
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl,
+        String xmlText, SchemaType type, XmlOptions options)
+        throws XmlException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( xmlText, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( xmlText, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(xmlText, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(xmlText, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    private XmlObject parseToXmlObject ( String xmlText, SchemaType type, XmlOptions options )
+    private XmlObject parseToXmlObject(String xmlText, SchemaType type,
+        XmlOptions options)
         throws XmlException
     {
-        Cur c = parse( xmlText, type, options );
+        Cur c = parse(xmlText, type, options);
 
         XmlObject x = (XmlObject) c.getUser();
 
@@ -615,66 +692,97 @@
 
         return x;
     }
-    
-    Cur parse ( String s, SchemaType type, XmlOptions options ) throws XmlException
+
+    Cur parse(String s, SchemaType type, XmlOptions options)
+        throws XmlException
     {
-        Reader r = new StringReader( s );
-        
+        Reader r = new StringReader(s);
+
         try
         {
-            Cur c = getSaxLoader( options ).load( this, new InputSource( r ), options );
+            Cur c = getSaxLoader(options).load(this, new InputSource(r),
+                options);
 
-            autoTypeDocument( c, type, options );
+            autoTypeDocument(c, type, options);
 
             return c;
         }
-        catch ( IOException e )
+        catch (IOException e)
         {
             assert false: "StringReader should not throw IOException";
-            
-            throw new XmlException( e.getMessage(), e );
+
+            throw new XmlException(e.getMessage(), e);
         }
         finally
         {
-            try { r.close(); } catch ( IOException e ) { }
+            try
+            {
+                r.close();
+            }
+            catch (IOException e)
+            {
+            }
         }
     }
-    
+
     //
     //
     //
-            
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, XMLInputStream xis, SchemaType type, XmlOptions options )
-            throws XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException
+
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl,
+        XMLInputStream xis, SchemaType type, XmlOptions options)
+        throws XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( xis, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( xis, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(xis, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(xis, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
-    
-    public XmlObject parseToXmlObject (
-        XMLInputStream xis, SchemaType type, XmlOptions options )
-            throws XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException
+
+    public XmlObject parseToXmlObject(XMLInputStream xis, SchemaType type,
+        XmlOptions options)
+        throws XmlException, org.apache.xmlbeans.xml.stream.XMLStreamException
     {
         Cur c;
-        
+
         try
         {
-            c = loadXMLInputStream( xis, options );
+            c = loadXMLInputStream(xis, options);
         }
-        catch ( org.apache.xmlbeans.xml.stream.XMLStreamException e )
+        catch (org.apache.xmlbeans.xml.stream.XMLStreamException e)
         {
-            throw new XmlException( e.getMessage(), e );
+            throw new XmlException(e.getMessage(), e);
         }
-            
-        autoTypeDocument( c, type, options );
+
+        autoTypeDocument(c, type, options);
 
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
-        
+
         return x;
     }
 
@@ -682,97 +790,122 @@
     //
     //
 
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, XMLStreamReader xsr, SchemaType type, XmlOptions options )
-            throws XmlException
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl,
+        XMLStreamReader xsr, SchemaType type, XmlOptions options)
+        throws XmlException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( xsr, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( xsr, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(xsr, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(xsr, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
-    
-    public XmlObject parseToXmlObject ( XMLStreamReader xsr, SchemaType type, XmlOptions options )
+
+    public XmlObject parseToXmlObject(XMLStreamReader xsr, SchemaType type,
+        XmlOptions options)
         throws XmlException
     {
         Cur c;
-        
+
         try
         {
-            c = loadXMLStreamReader( xsr, options );
+            c = loadXMLStreamReader(xsr, options);
         }
-        catch ( XMLStreamException e )
+        catch (XMLStreamException e)
         {
-            throw new XmlException( e.getMessage(), e );
+            throw new XmlException(e.getMessage(), e);
         }
-            
-        autoTypeDocument( c, type, options );
+
+        autoTypeDocument(c, type, options);
 
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
-        
+
         return x;
     }
 
-    private static void lineNumber ( XMLEvent xe, LoadContext context )
+    private static void lineNumber(XMLEvent xe, LoadContext context)
     {
         org.apache.xmlbeans.xml.stream.Location loc = xe.getLocation();
-        
+
         if (loc != null)
-            context.lineNumber( loc.getLineNumber(), loc.getColumnNumber(), -1 );
+            context.lineNumber(loc.getLineNumber(), loc.getColumnNumber(), -1);
     }
 
-    private static void lineNumber ( XMLStreamReader xsr, LoadContext context )
+    private static void lineNumber(XMLStreamReader xsr, LoadContext context)
     {
         javax.xml.stream.Location loc = xsr.getLocation();
 
         if (loc != null)
         {
-            context.lineNumber(
-                loc.getLineNumber(), loc.getColumnNumber(), loc.getCharacterOffset() );
+            context.lineNumber(loc.getLineNumber(), loc.getColumnNumber(),
+                loc.getCharacterOffset());
         }
     }
 
-    private void doAttributes ( XMLStreamReader xsr, LoadContext context )
+    private void doAttributes(XMLStreamReader xsr, LoadContext context)
     {
         int n = xsr.getAttributeCount();
 
-        for ( int a = 0 ; a < n ; a++ )
+        for (int a = 0; a < n; a++)
         {
-            context.attr(
-                xsr.getAttributeLocalName( a ),
-                xsr.getAttributeNamespace( a ),
-                xsr.getAttributePrefix( a ),
-                xsr.getAttributeValue( a ) );
+            context.attr(xsr.getAttributeLocalName(a),
+                xsr.getAttributeNamespace(a),
+                xsr.getAttributePrefix(a),
+                xsr.getAttributeValue(a));
         }
     }
-    
-    private void doNamespaces ( XMLStreamReader xsr, LoadContext context )
+
+    private void doNamespaces(XMLStreamReader xsr, LoadContext context)
     {
         int n = xsr.getNamespaceCount();
 
-        for ( int a = 0 ; a < n ; a++ )
+        for (int a = 0; a < n; a++)
         {
-            String prefix = xsr.getNamespacePrefix( a );
+            String prefix = xsr.getNamespacePrefix(a);
 
             if (prefix == null || prefix.length() == 0)
-                context.attr( "xmlns", _xmlnsUri, null, xsr.getNamespaceURI( a ) );
+                context.attr("xmlns", _xmlnsUri, null,
+                    xsr.getNamespaceURI(a));
             else
-                context.attr( prefix, _xmlnsUri, "xmlns", xsr.getNamespaceURI( a ) );
+                context.attr(prefix, _xmlnsUri, "xmlns",
+                    xsr.getNamespaceURI(a));
         }
 
     }
 
-    private Cur loadXMLInputStream ( XMLInputStream xis, XmlOptions options )
+    private Cur loadXMLInputStream(XMLInputStream xis, XmlOptions options)
         throws org.apache.xmlbeans.xml.stream.XMLStreamException
     {
-        options = XmlOptions.maskNull( options );
+        options = XmlOptions.maskNull(options);
 
-        boolean lineNums = options.hasOption( XmlOptions.LOAD_LINE_NUMBERS );
+        boolean lineNums = options.hasOption(XmlOptions.LOAD_LINE_NUMBERS);
 
         XMLEvent x = xis.peek();
-        
+
         if (x != null && x.getType() == XMLEvent.START_ELEMENT)
         {
             Map nsMap = ((StartElement) x).getNamespaceMap();
@@ -780,12 +913,12 @@
             if (nsMap != null && nsMap.size() > 0)
             {
                 Map namespaces = new HashMap();
-                
-                namespaces.putAll( nsMap );
 
-                options = new XmlOptions( options );
+                namespaces.putAll(nsMap);
+
+                options = new XmlOptions(options);
 
-                options.put( XmlOptions.LOAD_ADDITIONAL_NAMESPACES, namespaces );
+                options.put(XmlOptions.LOAD_ADDITIONAL_NAMESPACES, namespaces);
             }
         }
 
@@ -794,14 +927,14 @@
         String version = null;
         boolean standAlone = true;
 
-        LoadContext context = new Cur.CurLoadContext( this, options );
+        LoadContext context = new Cur.CurLoadContext(this, options);
 
         events:
-        for ( XMLEvent xe = xis.next() ; xe != null ; xe = xis.next() )
+        for (XMLEvent xe = xis.next(); xe != null; xe = xis.next())
         {
-            switch ( xe.getType() )
+            switch (xe.getType())
             {
-            case XMLEvent.START_DOCUMENT :
+            case XMLEvent.START_DOCUMENT:
                 StartDocument doc = (StartDocument) xe;
 
                 systemId = doc.getSystemId();
@@ -811,437 +944,514 @@
                 standAlone = doc.isStandalone();
 
                 if (lineNums)
-                    lineNumber( xe, context );
+                    lineNumber(xe, context);
 
                 break;
 
-            case XMLEvent.END_DOCUMENT :
+            case XMLEvent.END_DOCUMENT:
                 if (lineNums)
-                    lineNumber( xe, context );
+                    lineNumber(xe, context);
 
                 break events;
 
-            case XMLEvent.NULL_ELEMENT :
+            case XMLEvent.NULL_ELEMENT:
                 if (!xis.hasNext())
                     break events;
                 break;
 
-            case XMLEvent.START_ELEMENT :
-                context.startElement(XMLNameHelper.getQName( xe.getName() ) );
+            case XMLEvent.START_ELEMENT:
+                context.startElement(XMLNameHelper.getQName(xe.getName()));
 
                 if (lineNums)
-                    lineNumber( xe, context );
+                    lineNumber(xe, context);
 
-                for ( AttributeIterator ai = ((StartElement) xe).getAttributes() ; ai.hasNext() ; )
+                for (AttributeIterator ai = ((StartElement) xe).getAttributes();
+                     ai.hasNext();)
                 {
                     Attribute attr = ai.next();
 
-                    context.attr(
-                        XMLNameHelper.getQName( attr.getName() ),
-                        attr.getValue() );
+                    context.attr(XMLNameHelper.getQName(attr.getName()),
+                        attr.getValue());
                 }
 
-                for ( AttributeIterator ai = ((StartElement) xe).getNamespaces()
-                      ; ai.hasNext() ; )
+                for (AttributeIterator ai = ((StartElement) xe).getNamespaces()
+                    ; ai.hasNext();)
                 {
                     Attribute attr = ai.next();
 
                     XMLName name = attr.getName();
                     String local = name.getLocalName();
 
-                    if (name.getPrefix() == null && local.equals( "xmlns" ))
+                    if (name.getPrefix() == null && local.equals("xmlns"))
                         local = "";
 
-                    context.xmlns( local, attr.getValue() );
+                    context.xmlns(local, attr.getValue());
                 }
 
                 break;
 
-            case XMLEvent.END_ELEMENT :
+            case XMLEvent.END_ELEMENT:
                 context.endElement();
 
                 if (lineNums)
-                    lineNumber( xe, context );
+                    lineNumber(xe, context);
 
                 break;
 
-            case XMLEvent.SPACE :
+            case XMLEvent.SPACE:
                 if (((Space) xe).ignorable())
                     break;
 
                 // Fall through
 
-            case XMLEvent.CHARACTER_DATA :
+            case XMLEvent.CHARACTER_DATA:
                 CharacterData cd = (CharacterData) xe;
 
                 if (cd.hasContent())
                 {
-                    context.text( cd.getContent() );
+                    context.text(cd.getContent());
 
                     if (lineNums)
-                        lineNumber( xe, context );
+                        lineNumber(xe, context);
                 }
 
                 break;
 
-            case XMLEvent.COMMENT :
+            case XMLEvent.COMMENT:
                 org.apache.xmlbeans.xml.stream.Comment comment =
                     (org.apache.xmlbeans.xml.stream.Comment) xe;
 
                 if (comment.hasContent())
                 {
-                    context.comment( comment.getContent() );
+                    context.comment(comment.getContent());
 
                     if (lineNums)
-                        lineNumber( xe, context );
+                        lineNumber(xe, context);
                 }
 
                 break;
 
-            case XMLEvent.PROCESSING_INSTRUCTION :
+            case XMLEvent.PROCESSING_INSTRUCTION:
                 ProcessingInstruction procInstr = (ProcessingInstruction) xe;
 
-                context.procInst( procInstr.getTarget(), procInstr.getData() );
+                context.procInst(procInstr.getTarget(), procInstr.getData());
 
                 if (lineNums)
-                    lineNumber( xe, context );
+                    lineNumber(xe, context);
 
                 break;
 
-            // These are ignored
-            case XMLEvent.ENTITY_REFERENCE :
-            case XMLEvent.START_PREFIX_MAPPING :
-            case XMLEvent.END_PREFIX_MAPPING :
-            case XMLEvent.CHANGE_PREFIX_MAPPING :
-            case XMLEvent.XML_EVENT :
+                // These are ignored
+            case XMLEvent.ENTITY_REFERENCE:
+            case XMLEvent.START_PREFIX_MAPPING:
+            case XMLEvent.END_PREFIX_MAPPING:
+            case XMLEvent.CHANGE_PREFIX_MAPPING:
+            case XMLEvent.XML_EVENT:
                 break;
 
             default :
                 throw new RuntimeException(
-                    "Unhandled xml event type: " + xe.getTypeAsString() );
+                    "Unhandled xml event type: " + xe.getTypeAsString());
             }
         }
 
         Cur c = context.finish();
-        
-        associateSourceName( c, options );
-        
-        XmlDocumentProperties props = getDocProps( c, true );
 
-        props.setDoctypeSystemId( systemId );
-        props.setEncoding( encoding );
-        props.setVersion( version );
-        props.setStandalone( standAlone );
+        associateSourceName(c, options);
+
+        XmlDocumentProperties props = getDocProps(c, true);
+
+        props.setDoctypeSystemId(systemId);
+        props.setEncoding(encoding);
+        props.setVersion(version);
+        props.setStandalone(standAlone);
 
         return c;
     }
-    
-    private Cur loadXMLStreamReader ( XMLStreamReader xsr, XmlOptions options )
+
+    private Cur loadXMLStreamReader(XMLStreamReader xsr, XmlOptions options)
         throws XMLStreamException
     {
-        options = XmlOptions.maskNull( options );
-        
-        boolean lineNums = options.hasOption( XmlOptions.LOAD_LINE_NUMBERS );
+        options = XmlOptions.maskNull(options);
+
+        boolean lineNums = options.hasOption(XmlOptions.LOAD_LINE_NUMBERS);
 
         String encoding = null, version = null;
         boolean standAlone = false;
-        
-        LoadContext context = new Cur.CurLoadContext( this, options );
+
+        LoadContext context = new Cur.CurLoadContext(this, options);
         int depth = 0;
 
         events:
-        for ( int eventType = xsr.getEventType() ; ; eventType = xsr.next() )
+        for (int eventType = xsr.getEventType(); ; eventType = xsr.next())
         {
-            switch ( eventType )
-            {
-            case XMLStreamReader.START_DOCUMENT :
+            switch (eventType)
             {
-                depth++;
+            case XMLStreamReader.START_DOCUMENT:
+                {
+                    depth++;
 
-                encoding   = xsr.getCharacterEncodingScheme();
-                version    = xsr.getVersion();
-                standAlone = xsr.isStandalone();
+                    encoding = xsr.getCharacterEncodingScheme();
+                    version = xsr.getVersion();
+                    standAlone = xsr.isStandalone();
 
-                if (lineNums)
-                    lineNumber( xsr, context );
+                    if (lineNums)
+                        lineNumber(xsr, context);
 
-                break;
-            }
-            
-            case XMLStreamReader.END_DOCUMENT :
-            {
-                depth--;
+                    break;
+                }
 
-                if (lineNums)
-                    lineNumber( xsr, context );
+            case XMLStreamReader.END_DOCUMENT:
+                {
+                    depth--;
 
-                break events;
-            }
-            
-            case XMLStreamReader.START_ELEMENT :
-            {
-                depth++;
-                context.startElement( xsr.getName() );
-                
-                if (lineNums)
-                    lineNumber( xsr, context );
+                    if (lineNums)
+                        lineNumber(xsr, context);
 
-                doAttributes( xsr, context );
-                doNamespaces( xsr, context );
-                
-                break;
-            }
-            
-            case XMLStreamReader.END_ELEMENT :
-            {
-                depth--;
-                context.endElement();
-                
-                if (lineNums)
-                    lineNumber( xsr, context );
-                
-                break;
-            }
-            
-            case XMLStreamReader.CHARACTERS :
-            case XMLStreamReader.CDATA :
-            {
-                context.text( xsr.getTextCharacters(), xsr.getTextStart(), xsr.getTextLength() );
-                
-                if (lineNums)
-                    lineNumber( xsr, context );
-                
-                break;
-            }
-            
-            case XMLStreamReader.COMMENT :
-            {
-                String comment = xsr.getText();
-                
-                context.comment( comment );
-                
-                if (lineNums)
-                    lineNumber( xsr, context );
-                
-                break;
-            }
-            
-            case XMLStreamReader.PROCESSING_INSTRUCTION :
-            {
-                context.procInst( xsr.getPITarget(), xsr.getPIData() );
-                
-                if (lineNums)
-                    lineNumber( xsr, context );
-                
-                break;
-            }
-            
-            case XMLStreamReader.ATTRIBUTE :
-            {
-                doAttributes( xsr, context );
-                break;
-            }
-            
-            case XMLStreamReader.NAMESPACE :
-            {
-                doNamespaces( xsr, context );
-                break;
-            }
-            
-            case XMLStreamReader.ENTITY_REFERENCE :
-            {
-                context.text( xsr.getText() );
-                break;
-            }
-            
-            case XMLStreamReader.SPACE :
-            case XMLStreamReader.DTD :
+                    break events;
+                }
+
+            case XMLStreamReader.START_ELEMENT:
+                {
+                    depth++;
+                    context.startElement(xsr.getName());
+
+                    if (lineNums)
+                        lineNumber(xsr, context);
+
+                    doAttributes(xsr, context);
+                    doNamespaces(xsr, context);
+
+                    break;
+                }
+
+            case XMLStreamReader.END_ELEMENT:
+                {
+                    depth--;
+                    context.endElement();
+
+                    if (lineNums)
+                        lineNumber(xsr, context);
+
+                    break;
+                }
+
+            case XMLStreamReader.CHARACTERS:
+            case XMLStreamReader.CDATA:
+                {
+                    context.text(xsr.getTextCharacters(), xsr.getTextStart(),
+                        xsr.getTextLength());
+
+                    if (lineNums)
+                        lineNumber(xsr, context);
+
+                    break;
+                }
+
+            case XMLStreamReader.COMMENT:
+                {
+                    String comment = xsr.getText();
+
+                    context.comment(comment);
+
+                    if (lineNums)
+                        lineNumber(xsr, context);
+
+                    break;
+                }
+
+            case XMLStreamReader.PROCESSING_INSTRUCTION:
+                {
+                    context.procInst(xsr.getPITarget(), xsr.getPIData());
+
+                    if (lineNums)
+                        lineNumber(xsr, context);
+
+                    break;
+                }
+
+            case XMLStreamReader.ATTRIBUTE:
+                {
+                    doAttributes(xsr, context);
+                    break;
+                }
+
+            case XMLStreamReader.NAMESPACE:
+                {
+                    doNamespaces(xsr, context);
+                    break;
+                }
+
+            case XMLStreamReader.ENTITY_REFERENCE:
+                {
+                    context.text(xsr.getText());
+                    break;
+                }
+
+            case XMLStreamReader.SPACE:
+            case XMLStreamReader.DTD:
                 break;
 
             default :
-                throw new RuntimeException( "Unhandled xml event type: " + eventType );
+                throw new RuntimeException(
+                    "Unhandled xml event type: " + eventType);
             }
 
-            if (!xsr.hasNext() || depth<=0)
+            if (!xsr.hasNext() || depth <= 0)
                 break;
         }
-        
+
         Cur c = context.finish();
 
-        associateSourceName( c, options );
+        associateSourceName(c, options);
 
-        XmlDocumentProperties props = getDocProps( c, true );
+        XmlDocumentProperties props = getDocProps(c, true);
 
-        props.setEncoding( encoding );
-        props.setVersion ( version );
-        props.setStandalone ( standAlone );
+        props.setEncoding(encoding);
+        props.setVersion(version);
+        props.setStandalone(standAlone);
 
         return c;
     }
-    
+
     //
     //
     //
 
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, InputStream is, SchemaType type, XmlOptions options )
-            throws XmlException, IOException
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl,
+        InputStream is, SchemaType type, XmlOptions options)
+        throws XmlException, IOException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( is, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( is, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(is, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(is, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    private XmlObject parseToXmlObject (
-        InputStream is, SchemaType type, XmlOptions options )
-            throws XmlException, IOException
+    private XmlObject parseToXmlObject(InputStream is, SchemaType type,
+        XmlOptions options)
+        throws XmlException, IOException
     {
-        Cur c = getSaxLoader( options ).load( this, new InputSource( is ), options );
-        
-        autoTypeDocument( c, type, options );
+        Cur c = getSaxLoader(options).load(this, new InputSource(is),
+            options);
+
+        autoTypeDocument(c, type, options);
 
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
-        
+
         return x;
     }
 
     //
     //
     //
-            
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, Reader reader, SchemaType type, XmlOptions options )
-            throws XmlException, IOException
+
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl,
+        Reader reader, SchemaType type, XmlOptions options)
+        throws XmlException, IOException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( reader, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( reader, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(reader, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(reader, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    private XmlObject parseToXmlObject (
-        Reader reader, SchemaType type, XmlOptions options )
-            throws XmlException, IOException
+    private XmlObject parseToXmlObject(Reader reader, SchemaType type,
+        XmlOptions options)
+        throws XmlException, IOException
     {
-        Cur c = getSaxLoader( options ).load( this, new InputSource( reader ), options );
-        
-        autoTypeDocument( c, type, options );
-        
+        Cur c = getSaxLoader(options).load(this, new InputSource(reader),
+            options);
+
+        autoTypeDocument(c, type, options);
+
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
-        
+
         return x;
     }
-    
+
     //
     //
     //
 
-    public static XmlObject parseToXmlObject (
-        SchemaTypeLoader stl, Node node, SchemaType type, XmlOptions options )
-            throws XmlException
+    public static XmlObject parseToXmlObject(SchemaTypeLoader stl, Node node,
+        SchemaType type, XmlOptions options)
+        throws XmlException
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.parseToXmlObject( node, type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.parseToXmlObject( node, type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.parseToXmlObject(node, type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.parseToXmlObject(node, type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    public XmlObject parseToXmlObject ( Node node, SchemaType type, XmlOptions options )
+    public XmlObject parseToXmlObject(Node node, SchemaType type,
+        XmlOptions options)
         throws XmlException
     {
-        LoadContext context = new Cur.CurLoadContext( this, options );
-        
-        loadNode( node, context );
+        LoadContext context = new Cur.CurLoadContext(this, options);
+
+        loadNode(node, context);
 
         Cur c = context.finish();
-            
-        associateSourceName( c, options );
-        
-        autoTypeDocument( c, type, options );
+
+        associateSourceName(c, options);
+
+        autoTypeDocument(c, type, options);
 
         XmlObject x = (XmlObject) c.getUser();
 
         c.release();
-        
+
         return x;
     }
-    
-    private void loadNodeChildren ( Node n, LoadContext context )
+
+    private void loadNodeChildren(Node n, LoadContext context)
     {
-        for ( Node c = n.getFirstChild() ; c != null ; c = c.getNextSibling() )
-            loadNode( c, context );
+        for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling())
+            loadNode(c, context);
     }
 
-     void loadNode ( Node n, LoadContext context )
+    void loadNode(Node n, LoadContext context)
     {
-        switch ( n.getNodeType() )
-        {
-        case Node.DOCUMENT_NODE :
-        case Node.DOCUMENT_FRAGMENT_NODE :
-        case Node.ENTITY_REFERENCE_NODE :
+        switch (n.getNodeType())
         {
-            loadNodeChildren( n, context );
-
-            break;
-        }
-        case Node.ELEMENT_NODE :
-        {
-            context.startElement( makeQualifiedQName( n.getNamespaceURI(), n.getNodeName() ) );
-
-            NamedNodeMap attrs = n.getAttributes();
+        case Node.DOCUMENT_NODE:
+        case Node.DOCUMENT_FRAGMENT_NODE:
+        case Node.ENTITY_REFERENCE_NODE:
+            {
+                loadNodeChildren(n, context);
 
-            for ( int i = 0 ; i < attrs.getLength() ; i++ )
+                break;
+            }
+        case Node.ELEMENT_NODE:
             {
-                Node a = attrs.item( i );
+                context.startElement(
+                    makeQualifiedQName(n.getNamespaceURI(), n.getNodeName()));
 
-                String attrName  = a.getNodeName();
-                String attrValue = a.getNodeValue();
+                NamedNodeMap attrs = n.getAttributes();
 
-                if (attrName.toLowerCase().startsWith( "xmlns" ))
+                for (int i = 0; i < attrs.getLength(); i++)
                 {
-                    if (attrName.length() == 5)
-                        context.xmlns( null, attrValue );
+                    Node a = attrs.item(i);
+
+                    String attrName = a.getNodeName();
+                    String attrValue = a.getNodeValue();
+
+                    if (attrName.toLowerCase().startsWith("xmlns"))
+                    {
+                        if (attrName.length() == 5)
+                            context.xmlns(null, attrValue);
+                        else
+                            context.xmlns(attrName.substring(6), attrValue);
+                    }
                     else
-                        context.xmlns( attrName.substring( 6 ), attrValue );
+                        context.attr(
+                            makeQualifiedQName(a.getNamespaceURI(), attrName),
+                            attrValue);
                 }
-                else
-                    context.attr( makeQualifiedQName( a.getNamespaceURI(), attrName ), attrValue );
+
+                loadNodeChildren(n, context);
+
+                context.endElement();
+
+                break;
+            }
+        case Node.TEXT_NODE:
+        case Node.CDATA_SECTION_NODE:
+            {
+                context.text(n.getNodeValue());
+                break;
+            }
+        case Node.COMMENT_NODE:
+            {
+                context.comment(n.getNodeValue());
+                break;
+            }
+        case Node.PROCESSING_INSTRUCTION_NODE:
+            {
+                context.procInst(n.getNodeName(), n.getNodeValue());
+                break;
+            }
+        case Node.DOCUMENT_TYPE_NODE:
+        case Node.ENTITY_NODE:
+        case Node.NOTATION_NODE:
+        case Node.ATTRIBUTE_NODE:
+            {
+                throw new RuntimeException("Unexpected node");
             }
-
-            loadNodeChildren( n, context );
-
-            context.endElement();
-
-            break;
-        }
-        case Node.TEXT_NODE :
-        case Node.CDATA_SECTION_NODE :
-        {
-            context.text( n.getNodeValue() );
-            break;
-        }
-        case Node.COMMENT_NODE :
-        {
-            context.comment( n.getNodeValue() );
-            break;
-        }
-        case Node.PROCESSING_INSTRUCTION_NODE :
-        {
-            context.procInst( n.getNodeName(), n.getNodeValue() );
-            break;
-        }
-        case Node.DOCUMENT_TYPE_NODE :
-        case Node.ENTITY_NODE :
-        case Node.NOTATION_NODE :
-        case Node.ATTRIBUTE_NODE :
-        {
-            throw new RuntimeException( "Unexpected node" );
-        }
         }
     }
 
@@ -1249,12 +1459,14 @@
     //
     //
 
-    private class XmlSaxHandlerImpl extends SaxHandler implements XmlSaxHandler
+    private class XmlSaxHandlerImpl
+        extends SaxHandler
+        implements XmlSaxHandler
     {
-        XmlSaxHandlerImpl ( Locale l, SchemaType type, XmlOptions options )
+        XmlSaxHandlerImpl(Locale l, SchemaType type, XmlOptions options)
         {
-            super( null );
-            
+            super(null);
+
             _options = options;
             _type = type;
 
@@ -1262,33 +1474,34 @@
             // thread local CharUtil.  Instruct the SaxHandler (and the LoadContext, eventually)
             // to use the Locale specific CharUtil.
 
-            XmlOptions saxHandlerOptions = new XmlOptions( options );
-            saxHandlerOptions.put( Cur.LOAD_USE_LOCALE_CHAR_UTIL );
+            XmlOptions saxHandlerOptions = new XmlOptions(options);
+            saxHandlerOptions.put(Cur.LOAD_USE_LOCALE_CHAR_UTIL);
 
-            initSaxHandler( l, saxHandlerOptions );
+            initSaxHandler(l, saxHandlerOptions);
         }
 
-        public ContentHandler getContentHandler ( )
+        public ContentHandler getContentHandler()
         {
             return _context == null ? null : this;
         }
 
-        public LexicalHandler getLexicalHandler ( )
+        public LexicalHandler getLexicalHandler()
         {
             return _context == null ? null : this;
         }
 
-        public void bookmarkLastEvent ( XmlBookmark mark )
+        public void bookmarkLastEvent(XmlBookmark mark)
         {
-            _context.bookmarkLastNonAttr( mark );
+            _context.bookmarkLastNonAttr(mark);
         }
 
-        public void bookmarkLastAttr ( QName attrName, XmlBookmark mark )
+        public void bookmarkLastAttr(QName attrName, XmlBookmark mark)
         {
-            _context.bookmarkLastAttr( attrName, mark );
+            _context.bookmarkLastAttr(attrName, mark);
         }
-        
-        public XmlObject getObject ( ) throws XmlException
+
+        public XmlObject getObject()
+            throws XmlException
         {
             if (_context == null)
                 return null;
@@ -1299,7 +1512,7 @@
             {
                 Cur c = _context.finish();
 
-                autoTypeDocument( c, _type, _options );
+                autoTypeDocument(c, _type, _options);
 
                 XmlObject x = (XmlObject) c.getUser();
 
@@ -1318,75 +1531,113 @@
         private SchemaType _type;
         private XmlOptions _options;
     }
-    
-    public static XmlSaxHandler newSaxHandler (
-        SchemaTypeLoader stl, SchemaType type, XmlOptions options )
+
+    public static XmlSaxHandler newSaxHandler(SchemaTypeLoader stl,
+        SchemaType type, XmlOptions options)
     {
-        Locale l = getLocale( stl, options );
+        Locale l = getLocale(stl, options);
 
-        if (l.noSync())         { l.enter(); try { return l.newSaxHandler( type, options ); } finally { l.exit(); } }
-        else synchronized ( l ) { l.enter(); try { return l.newSaxHandler( type, options ); } finally { l.exit(); } }
+        if (l.noSync())
+        {
+            l.enter();
+            try
+            {
+                return l.newSaxHandler(type, options);
+            }
+            finally
+            {
+                l.exit();
+            }
+        }
+        else
+            synchronized (l)
+            {
+                l.enter();
+                try
+                {
+                    return l.newSaxHandler(type, options);
+                }
+                finally
+                {
+                    l.exit();
+                }
+            }
     }
 
-    public XmlSaxHandler newSaxHandler ( SchemaType type, XmlOptions options )
-    {    
-        return new XmlSaxHandlerImpl( this, type, options );
+    public XmlSaxHandler newSaxHandler(SchemaType type, XmlOptions options)
+    {
+        return new XmlSaxHandlerImpl(this, type, options);
     }
 
     // TODO (ericvas ) - have a qname factory here so that the same factory may be
     // used by the parser.  This factory would probably come from my
     // high speed parser.  Otherwise, use a thread local on
-    
-    QName makeQName ( String uri, String localPart )
+
+    QName makeQName(String uri, String localPart)
     {
         assert localPart != null && localPart.length() > 0;
         // TODO - make sure name is a well formed name?
 
-        return _qnameFactory.getQName( uri, localPart );
+        return _qnameFactory.getQName(uri, localPart);
     }
 
-    QName makeQNameNoCheck ( String uri, String localPart )
+    QName makeQNameNoCheck(String uri, String localPart)
     {
-        return _qnameFactory.getQName( uri, localPart );
+        return _qnameFactory.getQName(uri, localPart);
     }
 
-    QName makeQName ( String uri, String local, String prefix )
+    QName makeQName(String uri, String local, String prefix)
     {
-        return _qnameFactory.getQName( uri, local, prefix == null ? "" : prefix );
+        return _qnameFactory.getQName(uri, local, prefix == null ? "" : prefix);
     }
 
-    QName makeQualifiedQName ( String uri, String qname )
+    QName makeQualifiedQName(String uri, String qname)
     {
         if (qname == null)
             qname = "";
 
-        int i = qname.indexOf( ':' );
+        int i = qname.indexOf(':');
 
         return i < 0
-            ? _qnameFactory.getQName( uri, qname )
-            : _qnameFactory.getQName( uri, qname.substring( i + 1 ), qname.substring( 0, i ) );
+            ?
+            _qnameFactory.getQName(uri, qname)
+            :
+            _qnameFactory.getQName(uri, qname.substring(i + 1),
+                qname.substring(0, i));
     }
 
-    static private class DocProps extends XmlDocumentProperties
+    static private class DocProps
+        extends XmlDocumentProperties
     {
         private HashMap _map = new HashMap();
 
-        public Object put    ( Object key, Object value ) { return _map.put( key, value ); }
-        public Object get    ( Object key )               { return _map.get( key ); }
-        public Object remove ( Object key )               { return _map.remove( key ); }
+        public Object put(Object key, Object value)
+        {
+            return _map.put(key, value);
+        }
+
+        public Object get(Object key)
+        {
+            return _map.get(key);
+        }
+
+        public Object remove(Object key)
+        {
+            return _map.remove(key);
+        }
     }
 
-    static XmlDocumentProperties getDocProps ( Cur c, boolean ensure )
+    static XmlDocumentProperties getDocProps(Cur c, boolean ensure)
     {
         c.push();
 
-        while ( c.toParent() )
+        while (c.toParent())
             ;
 
-        DocProps props = (DocProps) c.getBookmark( DocProps.class );
+        DocProps props = (DocProps) c.getBookmark(DocProps.class);
 
         if (props == null && ensure)
-            c.setBookmark( DocProps.class, props = new DocProps() );
+            c.setBookmark(DocProps.class, props = new DocProps());
 
         c.pop();
 
@@ -1395,40 +1646,40 @@
 
     interface ChangeListener
     {
-        void notifyChange ( );
+        void notifyChange();
 
-        void setNextChangeListener ( ChangeListener listener );
-        
-        ChangeListener getNextChangeListener ( );
+        void setNextChangeListener(ChangeListener listener);
+
+        ChangeListener getNextChangeListener();
     }
 
-    void registerForChange ( ChangeListener listener )
+    void registerForChange(ChangeListener listener)
     {
         if (listener.getNextChangeListener() == null)
         {
             if (_changeListeners == null)
-                listener.setNextChangeListener( listener );
+                listener.setNextChangeListener(listener);
             else
-                listener.setNextChangeListener( _changeListeners );
-        
+                listener.setNextChangeListener(_changeListeners);
+
             _changeListeners = listener;
         }
     }
 
-    void notifyChange ( )
+    void notifyChange()
     {
         // First, notify the registered listeners ...
-        
-        while ( _changeListeners != null )
+
+        while (_changeListeners != null)
         {
             _changeListeners.notifyChange();
 
             if (_changeListeners.getNextChangeListener() == _changeListeners)
-                _changeListeners.setNextChangeListener( null );
+                _changeListeners.setNextChangeListener(null);
 
             ChangeListener next = _changeListeners.getNextChangeListener();
 
-            _changeListeners.setNextChangeListener( null );
+            _changeListeners.setNextChangeListener(null);
 
             _changeListeners = next;
         }
@@ -1438,12 +1689,12 @@
 
         _locations.notifyChange();
     }
-    
+
     //
     // Cursor helpers
     //
 
-    static String getTextValue ( Cur c )
+    static String getTextValue(Cur c)
     {
         assert c.isNode();
 
@@ -1454,22 +1705,22 @@
 
         c.push();
 
-        for ( c.next() ; !c.isAtEndOfLastPush() ; c.next() )
+        for (c.next(); !c.isAtEndOfLastPush(); c.next())
             if (c.isText())
-                CharUtil.getString( sb, c.getChars( -1 ), c._offSrc, c._cchSrc );
+                CharUtil.getString(sb, c.getChars(-1), c._offSrc, c._cchSrc);
 
         c.pop();
-                
+
         return sb.toString();
     }
-    
-    static int getTextValue ( Cur c, int wsr, char[] chars, int off, int maxCch )
+
+    static int getTextValue(Cur c, int wsr, char[] chars, int off, int maxCch)
     {
         // TODO - hack impl for now ... improve
 
         assert c.isNode();
 
-        String s = c._xobj.getValueAsString( wsr );
+        String s = c._xobj.getValueAsString(wsr);
 
         int n = s.length();
 
@@ -1479,39 +1730,40 @@
         if (n <= 0)
             return 0;
 
-        s.getChars( 0, n, chars, off );
+        s.getChars(0, n, chars, off);
 
         return n;
     }
 
-    static String applyWhiteSpaceRule ( String s, int wsr )
+    static String applyWhiteSpaceRule(String s, int wsr)
     {
         int l = s == null ? 0 : s.length();
-        
+
         if (l == 0 || wsr == WS_PRESERVE)
             return s;
 
         char ch;
-        
+
         if (wsr == WS_REPLACE)
         {
-            for ( int i = 0 ; i < l ; i++ )
-                if ((ch = s.charAt( i )) == '\n' || ch == '\r' || ch == '\t')
-                    return processWhiteSpaceRule( s, wsr );
+            for (int i = 0; i < l; i++)
+                if ((ch = s.charAt(i)) == '\n' || ch == '\r' || ch == '\t')
+                    return processWhiteSpaceRule(s, wsr);
         }
         else if (wsr == Locale.WS_COLLAPSE)
         {
-            if (CharUtil.isWhiteSpace( s.charAt( 0 ) ) || CharUtil.isWhiteSpace( s.charAt( l - 1 )))
-                return processWhiteSpaceRule( s, wsr );
-            
+            if (CharUtil.isWhiteSpace(s.charAt(0)) ||
+                CharUtil.isWhiteSpace(s.charAt(l - 1)))
+                return processWhiteSpaceRule(s, wsr);
+
             boolean lastWasWhite = false;
-            
-            for ( int i = 1 ; i < l ; i++ )
+
+            for (int i = 1; i < l; i++)
             {
-                boolean isWhite = CharUtil.isWhiteSpace( s.charAt( i ) );
-                
+                boolean isWhite = CharUtil.isWhiteSpace(s.charAt(i));
+
                 if (isWhite && lastWasWhite)
-                    return processWhiteSpaceRule( s, wsr );
+                    return processWhiteSpaceRule(s, wsr);
 
                 lastWasWhite = isWhite;
             }
@@ -1519,39 +1771,39 @@
 
         return s;
     }
-        
-    static String processWhiteSpaceRule ( String s, int wsr )
+
+    static String processWhiteSpaceRule(String s, int wsr)
     {
-        ScrubBuffer sb = getScrubBuffer( wsr );
-        
-        sb.scrub( s, 0, s.length() );
+        ScrubBuffer sb = getScrubBuffer(wsr);
+
+        sb.scrub(s, 0, s.length());
 
         return sb.getResultAsString();
     }
 
     static final class ScrubBuffer
     {
-        ScrubBuffer ( )
+        ScrubBuffer()
         {
             _sb = new StringBuffer();
         }
-        
-        void init ( int wsr )
+
+        void init(int wsr)
         {
-            _sb.delete( 0, _sb.length() );
-            
+            _sb.delete(0, _sb.length());
+
             _wsr = wsr;
             _state = START_STATE;
         }
 
-        void scrub ( Object src, int off, int cch )
+        void scrub(Object src, int off, int cch)
         {
             if (cch == 0)
                 return;
 
             if (_wsr == Locale.WS_PRESERVE)
             {
-                CharUtil.getString( _sb, src, off, cch );
+                CharUtil.getString(_sb, src, off, cch);
                 return;
             }
 
@@ -1564,24 +1816,24 @@
                 if (cch <= _srcBuf.length)
                     chars = _srcBuf;
                 else if (cch <= 16384)
-                    chars = _srcBuf = new char [ 16384 ];
+                    chars = _srcBuf = new char[16384];
                 else
-                    chars = new char [ cch ];
+                    chars = new char[cch];
 
-                CharUtil.getChars( chars, 0, src, off, cch );
+                CharUtil.getChars(chars, 0, src, off, cch);
                 off = 0;
             }
 
             int start = 0;
-            
-            for ( int i = 0 ; i < cch ; i++ )
+
+            for (int i = 0; i < cch; i++)
             {
-                char ch = chars[ off + i ];
-                
+                char ch = chars[off + i];
+
                 if (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t')
                 {
-                    _sb.append( chars, off + start, i - start );
-                    
+                    _sb.append(chars, off + start, i - start);
+
                     start = i + 1;
 
                     if (_wsr == Locale.WS_REPLACE)
@@ -1592,20 +1844,20 @@
                 else
                 {
                     if (_state == SPACE_SEEN_STATE)
-                        _sb.append( ' ' );
+                        _sb.append(' ');
 
                     _state = NOSPACE_STATE;
                 }
             }
 
-            _sb.append( chars, off + start, cch - start );
+            _sb.append(chars, off + start, cch - start);
         }
 
-        String getResultAsString ( )
+        String getResultAsString()
         {
             return _sb.toString();
         }
-        
+
         private static final int START_STATE = 0;
         private static final int SPACE_SEEN_STATE = 1;
         private static final int NOSPACE_STATE = 2;
@@ -1614,44 +1866,60 @@
 
         private int _wsr;
 
-        private char[] _srcBuf = new char [ 1024 ];
+        private char[] _srcBuf = new char[1024];
         private StringBuffer _sb;
     }
 
     private static ThreadLocal tl_scrubBuffer =
-        new ThreadLocal ( ) { protected Object initialValue ( ) { return new SoftReference(new ScrubBuffer()); } };
+        new ThreadLocal()
+        {
+            protected Object initialValue()
+            {
+                return new SoftReference(new ScrubBuffer());
+            }
+        };
 
-    static ScrubBuffer getScrubBuffer ( int wsr )
+    static ScrubBuffer getScrubBuffer(int wsr)
     {
-        SoftReference softRef = (SoftReference)tl_scrubBuffer.get();
+        SoftReference softRef = (SoftReference) tl_scrubBuffer.get();
         ScrubBuffer scrubBuffer = (ScrubBuffer) (softRef).get();
-        if (scrubBuffer==null)
+        if (scrubBuffer == null)
         {
             scrubBuffer = new ScrubBuffer();
             tl_scrubBuffer.set(new SoftReference(scrubBuffer));
         }
 
-        scrubBuffer.init( wsr );
+        scrubBuffer.init(wsr);
         return scrubBuffer;
     }
 
-    static boolean pushToContainer ( Cur c )
+    static boolean pushToContainer(Cur c)
     {
         c.push();
-        
-        for ( ; ; )
+
+        for (; ;)
         {
-            switch ( c.kind() )
+            switch (c.kind())
             {
-            case    ROOT : case     ELEM : return true;
-            case  - ROOT : case   - ELEM : c.pop(); return false;
-            case COMMENT : case PROCINST : c.skip(); break;
-            default                      : c.nextWithAttrs();   break;
+            case ROOT:
+            case ELEM:
+                return true;
+            case -ROOT:
+            case -ELEM:
+                c.pop();
+                return false;
+            case COMMENT:
+            case PROCINST:
+                c.skip();
+                break;
+            default                      :
+                c.nextWithAttrs();
+                break;
             }
         }
     }
 
-    static boolean toFirstNormalAttr ( Cur c )
+    static boolean toFirstNormalAttr(Cur c)
     {
         c.push();
 
@@ -1665,7 +1933,7 @@
                     return true;
                 }
             }
-            while ( c.toNextAttr() );
+            while (c.toNextAttr());
         }
 
         c.pop();
@@ -1673,22 +1941,22 @@
         return false;
     }
 
-    static boolean toPrevNormalAttr ( Cur c )
+    static boolean toPrevNormalAttr(Cur c)
     {
         if (c.isAttr())
         {
             c.push();
 
-            for ( ; ; )
+            for (; ;)
             {
                 assert c.isAttr();
-                
+
                 // See if I can move backward.  If I'm at the first attr, prev must return
                 // false and not move.
 
                 if (!c.prev())
                     break;
-                
+
                 // Skip past the text value or attr begin
 
                 c.prev();
@@ -1711,11 +1979,11 @@
         return false;
     }
 
-    static boolean toNextNormalAttr ( Cur c )
+    static boolean toNextNormalAttr(Cur c)
     {
         c.push();
 
-        while ( c.toNextAttr() )
+        while (c.toNextAttr())
         {
             if (!c.isXmlns())
             {
@@ -1723,29 +1991,29 @@
                 return true;
             }
         }
-        
+
         c.pop();
 
         return false;
     }
 
-    Xobj findNthChildElem ( Xobj parent, QName name, QNameSet set, int n )
+    Xobj findNthChildElem(Xobj parent, QName name, QNameSet set, int n)
     {
         // only one of (set or name) is not null
         // or both are null for a wildcard
-        assert ( name == null || set == null );
+        assert (name == null || set == null);
         assert n >= 0;
 
         if (parent == null)
             return null;
 
-        int da = _nthCache_A.distance( parent, name, set, n );
-        int db = _nthCache_B.distance( parent, name, set, n );
+        int da = _nthCache_A.distance(parent, name, set, n);
+        int db = _nthCache_B.distance(parent, name, set, n);
 
         Xobj x =
             da <= db
-                ? _nthCache_A.fetch( parent, name, set, n )
-                : _nthCache_B.fetch( parent, name, set, n );
+            ? _nthCache_A.fetch(parent, name, set, n)
+            : _nthCache_B.fetch(parent, name, set, n);
 
         if (da == db)
         {
@@ -1757,20 +2025,21 @@
         return x;
     }
 
-    int count ( Xobj parent, QName name, QNameSet set )
+    int count(Xobj parent, QName name, QNameSet set)
     {
         int n = 0;
-        
-        for ( Xobj x = findNthChildElem( parent, name, set, 0 ) ; x != null ; x = x._nextSibling )
+
+        for (Xobj x = findNthChildElem(parent, name, set, 0);
+             x != null; x = x._nextSibling)
         {
             if (x.isElem())
             {
                 if (set == null)
                 {
-                    if (x._name.equals( name ))
+                    if (x._name.equals(name))
                         n++;
                 }
-                else if (set.contains( x._name ))
+                else if (set.contains(x._name))
                     n++;
             }
         }
@@ -1778,17 +2047,17 @@
         return n;
     }
 
-    static boolean toChild ( Cur c, QName name, int n )
+    static boolean toChild(Cur c, QName name, int n)
     {
-        if (n >= 0 && pushToContainer( c ))
+        if (n >= 0 && pushToContainer(c))
         {
-            Xobj x = c._locale.findNthChildElem( c._xobj, name, null, n );
+            Xobj x = c._locale.findNthChildElem(c._xobj, name, null, n);
 
             c.pop();
 
             if (x != null)
             {
-                c.moveTo( x );
+                c.moveTo(x);
                 return true;
             }
         }
@@ -1796,12 +2065,12 @@
         return false;
     }
 
-    static boolean toFirstChildElement ( Cur c )
+    static boolean toFirstChildElement(Cur c)
     {
-        if (!pushToContainer( c ))
+        if (!pushToContainer(c))
             return false;
 
-        if (!c.toFirstChild() || (!c.isElem() && !toNextSiblingElement( c )))
+        if (!c.toFirstChild() || (!c.isElem() && !toNextSiblingElement(c)))
         {
             c.pop();
             return false;
@@ -1811,13 +2080,13 @@
 
         return true;
     }
-    
-    static boolean toLastChildElement ( Cur c )
+
+    static boolean toLastChildElement(Cur c)
     {
-        if (!pushToContainer( c ))
+        if (!pushToContainer(c))
             return false;
 
-        if (!c.toLastChild() || (!c.isElem() && !toPrevSiblingElement( c )))
+        if (!c.toLastChild() || (!c.isElem() && !toPrevSiblingElement(c)))
         {
             c.pop();
             return false;
@@ -1827,8 +2096,8 @@
 
         return true;
     }
-    
-    static boolean toPrevSiblingElement ( Cur cur )
+
+    static boolean toPrevSiblingElement(Cur cur)
     {
         if (!cur.hasParent())
             return false;
@@ -1836,12 +2105,12 @@
         Cur c = cur.tempCur();
 
         boolean moved = false;
-        
+
         int k = c.kind();
 
         if (k != ATTR)
         {
-            for ( ; ; )
+            for (; ;)
             {
                 if (!c.prev())
                     break;
@@ -1855,7 +2124,7 @@
                 {
                     c.toParent();
 
-                    cur.moveToCur( c );
+                    cur.moveToCur(c);
                     moved = true;
 
                     break;
@@ -1867,8 +2136,8 @@
 
         return moved;
     }
-    
-    static boolean toNextSiblingElement ( Cur c )
+
+    static boolean toNextSiblingElement(Cur c)
     {
         if (!c.hasParent())
             return false;
@@ -1885,7 +2154,7 @@
         else if (k == ELEM)
             c.skip();
 
-        while ( (k = c.kind()) >= 0 )
+        while ((k = c.kind()) >= 0)
         {
             if (k == ELEM)
             {
@@ -1904,28 +2173,28 @@
         return false;
     }
 
-    static void applyNamespaces ( Cur c, Map namespaces )
+    static void applyNamespaces(Cur c, Map namespaces)
     {
         assert c.isContainer();
 
         java.util.Iterator i = namespaces.keySet().iterator();
 
-        while ( i.hasNext() )
+        while (i.hasNext())
         {
             String prefix = (String) i.next();
 
             // Usually, this is the predefined xml namespace
-            if (!prefix.toLowerCase().startsWith( "xml" ))
+            if (!prefix.toLowerCase().startsWith("xml"))
             {
-                if (c.namespaceForPrefix( prefix, false ) == null)
+                if (c.namespaceForPrefix(prefix, false) == null)
                 {
                     c.push();
 
                     c.next();
-                    c.createAttr( c._locale.createXmlns( prefix ) );
+                    c.createAttr(c._locale.createXmlns(prefix));
                     c.next();
 
-                    c.insertString( (String) namespaces.get( prefix ) );
+                    c.insertString((String) namespaces.get(prefix));
 
                     c.pop();
                 }
@@ -1933,28 +2202,28 @@
         }
     }
 
-    static Map getAllNamespaces ( Cur c, Map filleMe )
+    static Map getAllNamespaces(Cur c, Map filleMe)
     {
         assert c.isNode();
-        
+
         c.push();
 
         if (!c.isContainer())
             c.toParent();
-        
+
         assert c.isContainer();
 
         do
         {
             QName cName = c.getName();
 
-            while ( c.toNextAttr() )
+            while (c.toNextAttr())
             {
                 if (c.isXmlns())
                 {
                     String prefix = c.getXmlnsPrefix();
-                    String uri    = c.getXmlnsUri();
-                    
+                    String uri = c.getXmlnsUri();
+
                     // Here I check to see if there is a default namespace
                     // mapping which is not empty on a non root container which
                     // is in a namespace.  This this case, I do not want to add
@@ -1962,7 +2231,8 @@
                     // way.
 
                     if (prefix.length() == 0 && uri.length() > 0 &&
-                            cName != null && cName.getNamespaceURI().length() > 0)
+                        cName != null &&
+                        cName.getNamespaceURI().length() > 0)
                     {
                         continue;
                     }
@@ -1970,15 +2240,15 @@
                     if (filleMe == null)
                         filleMe = new HashMap();
 
-                    if (!filleMe.containsKey( prefix ))
-                        filleMe.put( prefix, uri );
+                    if (!filleMe.containsKey(prefix))
+                        filleMe.put(prefix, uri);
                 }
             }
 
             if (!c.isContainer())
                 c.toParentRaw();
         }
-        while ( c.toParentRaw() );
+        while (c.toParentRaw());
 
         c.pop();
 
@@ -1987,37 +2257,38 @@
 
     class nthCache
     {
-        private boolean namesSame ( QName pattern, QName name )
+        private boolean namesSame(QName pattern, QName name)
         {
-            return pattern == null || pattern.equals( name );
+            return pattern == null || pattern.equals(name);
         }
 
-        private boolean setsSame ( QNameSet patternSet, QNameSet set)
+        private boolean setsSame(QNameSet patternSet, QNameSet set)
         {
             // value equality is probably too expensive. Since the use case
             // involves QNameSets that are generated by the compiler, we
             // can use identity comparison.
-            
+
             return patternSet != null && patternSet == set;
         }
 
-        private boolean nameHit ( QName namePattern, QNameSet setPattern, QName name )
+        private boolean nameHit(QName namePattern, QNameSet setPattern,
+            QName name)
         {
             return
                 setPattern == null
-                    ? namesSame( namePattern, name )
-                    : setPattern.contains( name );
+                ? namesSame(namePattern, name)
+                : setPattern.contains(name);
         }
 
-        private boolean cacheSame ( QName namePattern,  QNameSet setPattern )
+        private boolean cacheSame(QName namePattern, QNameSet setPattern)
         {
             return
                 setPattern == null
-                    ? namesSame( namePattern, _name )
-                    : setsSame( setPattern, _set );
+                ? namesSame(namePattern, _name)
+                : setsSame(setPattern, _set);
         }
 
-        int distance ( Xobj parent, QName name, QNameSet set, int n )
+        int distance(Xobj parent, QName name, QNameSet set, int n)
         {
             assert n >= 0;
 
@@ -2030,12 +2301,12 @@
             return n > _n ? n - _n : _n - n;
         }
 
-        Xobj fetch ( Xobj parent, QName name, QNameSet set, int n )
+        Xobj fetch(Xobj parent, QName name, QNameSet set, int n)
         {
             assert n >= 0;
 
             if (_version != Locale.this.version() || _parent != parent ||
-                  !cacheSame( name, set ) || n == 0)
+                !cacheSame(name, set) || n == 0)
             {
                 _version = Locale.this.version();
                 _parent = parent;
@@ -2044,13 +2315,14 @@
                 _n = -1;
 
                 loop:
-                for ( Xobj x = parent._firstChild ; x != null ; x = x._nextSibling )

[... 1429 lines stripped ...]


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