You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2003/09/17 03:04:23 UTC

cvs commit: xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values XmlObjectBase.java

davidbau    2003/09/16 18:04:23

  Modified:    v1/src/typeimpl/org/apache/xmlbeans/impl/schema
                        SchemaTypeImpl.java SchemaTypeSystemImpl.java
               v1/src/typeimpl/org/apache/xmlbeans/impl/values
                        XmlObjectBase.java
  Log:
  Patch from: lawrence jones
  Code review: david bau
  Regression tests: passed
  
  This checkin fixes a few bugs:
  (1) When linking to binary schemas via attribute or element references,
      things weren't working because of inability to deal with
      anonymous types.
  (2) Some NPEs in the SchemaType API fixed
  (3) Added a version numbering scheme to the java.io.Serializable format
      for instances, backward compatible.
  
  Revision  Changes    Path
  1.2       +41 -20    xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
  
  Index: SchemaTypeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchemaTypeImpl.java	15 Sep 2003 18:20:29 -0000	1.1
  +++ SchemaTypeImpl.java	17 Sep 2003 01:04:23 -0000	1.2
  @@ -2,7 +2,7 @@
   * The Apache Software License, Version 1.1
   *
   *
  -* Copyright (c) 2000-2003 The Apache Software Foundation.  All rights 
  +* Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
  -*    notice, this list of conditions and the following disclaimer. 
  +*    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
  @@ -18,19 +18,19 @@
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
  -*    if any, must include the following acknowledgment:  
  +*    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
  -* 4. The names "Apache" and "Apache Software Foundation" must 
  +* 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
  -*    software without prior written permission. For written 
  +*    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
  -* 5. Products derived from this software may not be called "Apache 
  -*    XMLBeans", nor may "Apache" appear in their name, without prior 
  +* 5. Products derived from this software may not be called "Apache
  +*    XMLBeans", nor may "Apache" appear in their name, without prior
   *    written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  @@ -49,7 +49,7 @@
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
  -* originally based on software copyright (c) 2000-2003 BEA Systems 
  +* originally based on software copyright (c) 2000-2003 BEA Systems
   * Inc., <http://www.bea.com/>. For more information on the Apache Software
   * Foundation, please see <http://www.apache.org/>.
   */
  @@ -144,7 +144,7 @@
       private boolean _hasWildcardElements;
       private boolean _hasWildcardAttributes;
       // set of valid QNames that can be substituted for a property
  -    private Set _validSubstitutions = Collections.EMPTY_SET; 
  +    private Set _validSubstitutions = Collections.EMPTY_SET;
   
       // simple content support
       private int _complexTypeVariety;
  @@ -216,7 +216,7 @@
   
       // for document types only - only valid during compilation
       private QName _sg;
  -    private List _sgMembers = new ArrayList(); 
  +    private List _sgMembers = new ArrayList();
   
       public boolean isUnloaded()
       {
  @@ -386,12 +386,33 @@
   
       public QName getDocumentElementName()
       {
  -        return _isDocumentType ? getContentModel().getName() : null;
  +        if (_isDocumentType)
  +        {
  +            SchemaParticle sp = getContentModel();
  +            if (sp != null)
  +                return sp.getName();
  +        }
  +
  +        return null;
       }
   
       public QName getAttributeTypeAttributeName()
       {
  -        return _isAttributeType ? getAttributeModel().getAttributes()[0].getName() : null;
  +        if (_isAttributeType)
  +        {
  +            SchemaAttributeModel sam = getAttributeModel();
  +            if (sam != null)
  +            {
  +                SchemaLocalAttribute[] slaArray = sam.getAttributes();
  +                if (slaArray != null && slaArray.length > 0)
  +                {
  +                    SchemaLocalAttribute sla = slaArray[0];
  +                    return sla.getName();
  +                }
  +            }
  +        }
  +
  +        return null;
       }
   
       public void setDocumentType(boolean isDocument)
  @@ -663,7 +684,7 @@
           for (Iterator it = results.iterator() ; it.hasNext() ; )
           {
               SchemaProperty prop = (SchemaProperty)it.next();
  -            SchemaProperty baseProp = prop.isAttribute() ? 
  +            SchemaProperty baseProp = prop.isAttribute() ?
                   baseType.getAttributeProperty(prop.getName()) :
                   baseType.getElementProperty(prop.getName());
   
  @@ -676,7 +697,7 @@
               {
                   if ( eq(prop.getMinOccurs(), baseProp.getMinOccurs()) &&
                        eq(prop.getMaxOccurs(), baseProp.getMaxOccurs()) &&
  -                     prop.hasNillable() == baseProp.hasNillable()) 
  +                     prop.hasNillable() == baseProp.hasNillable())
                   {
                       it.remove();
                   }
  @@ -856,7 +877,7 @@
               {
                   type = prop.getType();
               }
  -            else if (!_typedWildcardElements.contains(eltName) && 
  +            else if (!_typedWildcardElements.contains(eltName) &&
                        !_validSubstitutions.contains(eltName))
               {
                   type = BuiltinSchemaTypeSystem.ST_NO_TYPE;
  @@ -1124,7 +1145,7 @@
       public void addSubstitutionGroupMember(QName member)
           { assertSGResolved(); _sgMembers.add(member); }
   
  -    public QName[] getSubstitutionGroupMembers() 
  +    public QName[] getSubstitutionGroupMembers()
       {
           QName[] result = new QName[_sgMembers.size()];
           return (QName[])_sgMembers.toArray(result);
  @@ -1233,7 +1254,7 @@
               patterns[i] = _patterns[i].getPattern();
           return patterns;
       }
  -    
  +
       public org.apache.xmlbeans.impl.regex.RegularExpression[] getPatternExpressions()
       {
           if (_patterns == null)
  @@ -1561,7 +1582,7 @@
               result.set_newValue((XmlObject)obj);
           else
               result.objectSet(obj);
  -        
  +
           result.check_dated();
           result.setImmutable();
   
  @@ -1917,7 +1938,7 @@
   
           if (getContainerField() != null)
           {
  -            prefix = (getContainerField().getName().getNamespaceURI().length() > 0 ? 
  +            prefix = (getContainerField().getName().getNamespaceURI().length() > 0 ?
                               (getContainerField().isAttribute() ? "Q=" : "E=") :
                               (getContainerField().isAttribute() ? "A=" : "U="))
                       + getContainerField().getName().getLocalPart();
  @@ -1964,7 +1985,7 @@
   
       public String getChameleonNamespace()
           { return _chameleon ? _parseTNS : null; }
  -    
  +
       public boolean isRedefinition()
           { return _redefinition; }
   
  
  
  
  1.2       +60 -31    xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
  
  Index: SchemaTypeSystemImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchemaTypeSystemImpl.java	15 Sep 2003 18:20:29 -0000	1.1
  +++ SchemaTypeSystemImpl.java	17 Sep 2003 01:04:23 -0000	1.2
  @@ -2,7 +2,7 @@
   * The Apache Software License, Version 1.1
   *
   *
  -* Copyright (c) 2000-2003 The Apache Software Foundation.  All rights 
  +* Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
  -*    notice, this list of conditions and the following disclaimer. 
  +*    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
  @@ -18,19 +18,19 @@
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
  -*    if any, must include the following acknowledgment:  
  +*    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
  -* 4. The names "Apache" and "Apache Software Foundation" must 
  +* 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
  -*    software without prior written permission. For written 
  +*    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
  -* 5. Products derived from this software may not be called "Apache 
  -*    XMLBeans", nor may "Apache" appear in their name, without prior 
  +* 5. Products derived from this software may not be called "Apache
  +*    XMLBeans", nor may "Apache" appear in their name, without prior
   *    written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  @@ -49,7 +49,7 @@
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
  -* originally based on software copyright (c) 2000-2003 BEA Systems 
  +* originally based on software copyright (c) 2000-2003 BEA Systems
   * Inc., <http://www.bea.com/>. For more information on the Apache Software
   * Foundation, please see <http://www.apache.org/>.
   */
  @@ -101,6 +101,7 @@
   import org.apache.xmlbeans.SchemaIdentityConstraint;
   import org.apache.xmlbeans.SimpleValue;
   import org.apache.xmlbeans.SchemaTypeLoaderException;
  +import org.apache.xmlbeans.SchemaField;
   import org.apache.xmlbeans.soap.SOAPArrayType;
   import org.apache.xmlbeans.soap.SchemaWSDLArrayType;
   import com.bea.x2002.x09.xbean.config.ConfigDocument.Config;
  @@ -333,7 +334,7 @@
   
               // qname map of document types, by the qname of the contained element
               _documentTypes = reader.readQNameRefMap();
  -            
  +
               // qname mape of attribute types, by the qname of the contained attribute
               _attributeTypes = reader.readQNameRefMap();
   
  @@ -341,7 +342,7 @@
               _typeRefsByClassname = reader.readClassnameRefMap();
   
               _namespaces = reader.readNamespaces();
  -            
  +
               // support for redefine, at the end of the file
               if (reader.atLeast(2, 15, 0))
               {
  @@ -476,10 +477,10 @@
               result.put(types[i].getAttributeTypeAttributeName(), types[i].getRef());
           return result;
       }
  -    
  +
       private static Random _random;
       private static byte[] _mask = new byte[128 / 8];
  -    
  +
       /**
        * Fun, fun.  Produce 128 bits of uniqueness randomly.
        * We used to use SecureRandom, but now we don't because SecureRandom
  @@ -516,7 +517,7 @@
               {
                   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" };
  @@ -543,7 +544,7 @@
               {
                   XBeanDebug.logException(e);
               }
  -            
  +
               _random = new Random(System.currentTimeMillis());
           }
           _random.nextBytes(result);
  @@ -891,7 +892,7 @@
       private Map _redefinedModelGroups;
       private Map _redefinedAttributeGroups;
       private Map _redefinedGlobalTypes;
  -    
  +
       private Map _globalElements;
       private Map _globalAttributes;
       private Map _modelGroups;
  @@ -923,7 +924,7 @@
           saveModelGroups(modelGroups());
           saveAttributeGroups(attributeGroups());
           saveIdentityConstraints(identityConstraints());
  -        
  +
           saveTypesRecursively(redefinedGlobalTypes());
           saveModelGroups(redefinedModelGroups());
           saveAttributeGroups(redefinedAttributeGroups());
  @@ -1069,7 +1070,7 @@
   
               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)
                   return null;
  @@ -1123,11 +1124,11 @@
   
               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)
                   throw new SchemaTypeLoaderException("XML-BEANS compiled schema: Incompatible minor version - expecting at least 14, got " + _minorver, _name, handle, SchemaTypeLoaderException.WRONG_MINOR_VERSION);
   
  @@ -1297,7 +1298,7 @@
   
               // all the namespaces
               writeNamespaces(_namespaces);
  -            
  +
               // VERSION 2.15 and newer below
               writeQNameMap(redefinedGlobalTypes());
               writeQNameMap(redefinedModelGroups());
  @@ -1477,20 +1478,24 @@
   
               switch (handle.charAt(2))
               {
  -                case 'I': // _BI_
  +                case 'I': // _BI_ - built-in schema type system
                       return ((SchemaType)BuiltinSchemaTypeSystem.get().resolveHandle(handle)).getRef();
  -                case 'T': // _XT_
  +                case 'T': // _XT_ - external type
                       return _linker.findTypeRef(QNameHelper.forPretty(handle, 4));
  -                case 'E': // _XE_
  +                case 'E': // _XE_ - external element
                       return _linker.findElementRef(QNameHelper.forPretty(handle, 4));
  -                case 'A': // _XA_
  +                case 'A': // _XA_ - external attribute
                       return _linker.findAttributeRef(QNameHelper.forPretty(handle, 4));
  -                case 'M': // _XM_
  +                case 'M': // _XM_ - external model group
                       return _linker.findModelGroupRef(QNameHelper.forPretty(handle, 4));
  -                case 'N': // _XN_
  +                case 'N': // _XN_ - external attribute group
                       return _linker.findAttributeGroupRef(QNameHelper.forPretty(handle, 4));
  -                case 'D': // _XD_
  +                case 'D': // _XD_ - external identity constraint
                       return _linker.findIdentityConstraintRef(QNameHelper.forPretty(handle, 4));
  +                case 'R': // _XR_ - external ref to attribute's type
  +                    return _linker.findAttribute(QNameHelper.forPretty(handle, 4)).getType().getRef();
  +                case 'S': // _XS_ - external ref to element's type
  +                    return _linker.findElement(QNameHelper.forPretty(handle, 4)).getType().getRef();
                   default:
                       throw new SchemaTypeLoaderException("Cannot resolve handle " + handle, _name, _handle, SchemaTypeLoaderException.BAD_HANDLE);
               }
  @@ -1528,8 +1533,32 @@
                           writeString("_BI_" + type.getName().getLocalPart());
                           return;
                       }
  -                    writeString("_XT_" + QNameHelper.pretty(type.getName()));
  +
  +                    // fix for CR120759 - added output of types _XR_ & _XS_
  +                    // when an attribute (_XR_) or element (_XS_) declaration
  +                    // uses ref to refer to an attribute or element in another
  +                    // schema and the type of that attribute or element
  +                    // is an anonymous (local) type
  +                    if (type.getName() != null)
  +                    {
  +                        writeString("_XT_" + QNameHelper.pretty(type.getName()));
  +                    }
  +                    else
  +                    {
  +                        SchemaField sf = type.getContainerField();
  +                        assert (sf != null);
  +                        if (sf.isAttribute())
  +                        {
  +                            writeString("_XR_" + QNameHelper.pretty(sf.getName()));
  +                        }
  +                        else
  +                        {
  +                            writeString("_XS_" + QNameHelper.pretty(sf.getName()));
  +                        }
  +                    }
  +
                       return;
  +
                   default:
                       assert(false);
                       throw new SchemaTypeLoaderException("Cannot write handle for component " + comp, _name, _handle, SchemaTypeLoaderException.BAD_HANDLE);
  @@ -1758,7 +1787,7 @@
                   impl.setName(readQName());
                   impl.setConstraintCategory(readShort());
                   impl.setSelector(readString());
  -                
  +
                   String[] fields = new String[readShort()];
                   for (int i = 0 ; i < fields.length ; i++)
                       fields[i] = readString();
  @@ -2626,7 +2655,7 @@
               writeType(type);
               if (type == null)
                   return;
  -            
  +
               SchemaType iType = ((SimpleValue)value).instanceType();
               if (iType == null)
               {
  @@ -2911,7 +2940,7 @@
               SchemaComponent.Ref ref = (SchemaComponent.Ref)i.next();
               ref.getComponent(); // Forces ref to be resolved
           }
  -        
  +
           XBeanDebug.trace(XBeanDebug.TRACE_SCHEMA_LOADING, "Finished resolving type system " + _name, -1);
           _allNonGroupHandlesResolved = true;
       }
  
  
  
  1.2       +131 -3    xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java
  
  Index: XmlObjectBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/values/XmlObjectBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlObjectBase.java	15 Sep 2003 18:20:30 -0000	1.1
  +++ XmlObjectBase.java	17 Sep 2003 01:04:23 -0000	1.2
  @@ -73,6 +73,8 @@
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.io.ObjectStreamException;
  +import java.io.ByteArrayInputStream;
  +import java.io.DataInputStream;
   import java.lang.reflect.Array;
   import java.util.Date;
   import java.util.List;
  @@ -121,6 +123,9 @@
   
   public abstract class XmlObjectBase implements TypeStoreUser, Serializable, XmlObject, SimpleValue
   {
  +    public static final short MAJOR_VERSION_NUMBER = (short) 1; // for serialization
  +    public static final short MINOR_VERSION_NUMBER = (short) 1; // for serialization
  +
       public final Object monitor()
       {
           if (has_store())
  @@ -2351,8 +2356,18 @@
           private void writeObject(ObjectOutputStream out) throws IOException
           {
               out.writeObject(_xbeanClass);
  +            // the first short is written out for backwards compatibility
  +            // it will always be zero for objects written with
  +            // this code, but it used to be the first 2 bytes of the
  +            // writeUTF() method
  +            out.writeShort((short)0);
  +            out.writeShort(MAJOR_VERSION_NUMBER);
  +            out.writeShort(MINOR_VERSION_NUMBER);
  +            // CR122401 - need to use writeObject instead of writeUTF
  +            // for xmlText as writeUTF has a length limitation of
  +            // 65535 bytes
               String xmlText = _impl.xmlText();
  -            out.writeUTF(xmlText);
  +            out.writeObject(xmlText);
               out.writeBoolean(false);
           }
   
  @@ -2360,9 +2375,56 @@
           {
               try
               {
  +                // read class object first - this is
  +                // first just for historical reasons - really
  +                // it would be better to have the version numbers
  +                // first
                   _xbeanClass = (Class)in.readObject();
  -                String xmlText = in.readUTF();
  -                in.readBoolean();
  +
  +                int utfBytes = in.readUnsignedShort();
  +
  +                // determine version numbers
  +                // if utfBytes is non-zero then we default to 0.0
  +                // otherwise expect major and minor version numbers
  +                // to be next entries in stream
  +                int majorVersionNum = 0;
  +                int minorVersionNum = 0;
  +                if (utfBytes == 0)
  +                {
  +                    majorVersionNum = in.readUnsignedShort();
  +                    minorVersionNum = in.readUnsignedShort();
  +                }
  +
  +                String xmlText = null;
  +                switch (majorVersionNum)
  +                {
  +                    case 0: // original, unnumbered version
  +                            // minorVersionNum is always zero
  +                        xmlText = readObjectV0(in, utfBytes);
  +                        in.readBoolean(); // ignored
  +                        break;
  +
  +                    case 1:
  +                        switch (minorVersionNum)
  +                        {
  +                            case 1:
  +                                xmlText = (String)in.readObject();
  +                                in.readBoolean(); // ignored
  +                                break;
  +
  +                            default:
  +                                throw new IOException("Deserialization error: " +
  +                                        "version number " + majorVersionNum + "." +
  +                                        minorVersionNum + " not supported.");
  +                        }
  +                        break;
  +
  +                    default:
  +                        throw new IOException("Deserialization error: " +
  +                                "version number " + majorVersionNum + "." +
  +                                minorVersionNum + " not supported.");
  +                }
  +
                   XmlOptions opts = new XmlOptions().setDocumentType(XmlBeans.typeForClass(_xbeanClass));
                   _impl = XmlBeans.getContextTypeLoader().parse(xmlText, null, opts);
               }
  @@ -2370,6 +2432,72 @@
               {
                   throw (IOException)(new IOException(e.getMessage()).initCause(e));
               }
  +        }
  +
  +        // this method is for reading the UTF-8 String that used to be
  +        // written out for a serialized XmlObject according to the
  +        // original format before this fix, i.e. it expects it
  +        // to have been written using the following algorithm:
  +        //
  +        // writeObject(Class object)
  +        // writeUTF(xmlText of object as String)
  +        // writeBoolean()
  +        //
  +        // this method is passed the original input stream positioned as though
  +        // it had just read the class object plus the next 2 bytes. Those 2
  +        // bytes are interpreted as an unsigned short saying how many more
  +        // bytes there are representing the bytes of the UTF-8-formatted String;
  +        // this value is passed in as the argument utfBytes
  +        private String readObjectV0(ObjectInputStream in, int utfBytes)
  +                throws IOException
  +        {
  +            // allow an extra 2 bytes up front for the unsigned short
  +            byte[] bArray = new byte[utfBytes+2];
  +
  +            // for format of these first 2 bytes see
  +            // Java API docs - DataOutputStream.writeShort()
  +            bArray[0] = (byte)( 0xff & (utfBytes >> 8) );
  +            bArray[1] = (byte)( 0xff & utfBytes );
  +
  +            // read the next numBytes bytes from the input stream
  +            // into the byte array starting at offset 2; this may
  +            // take multiple calls to read()
  +            int totalBytesRead = 0;
  +            int numRead;
  +            while (totalBytesRead < utfBytes)
  +            {
  +                numRead =
  +                    in.read(bArray, 2+totalBytesRead, utfBytes-totalBytesRead);
  +                if (numRead == -1) // reached end of stream
  +                    break;
  +
  +                totalBytesRead += numRead;
  +            }
  +
  +            if (totalBytesRead != utfBytes)
  +            {
  +                throw new IOException("Error reading backwards compatible " +
  +                        "XmlObject: number of bytes read (" + totalBytesRead +
  +                        ") != number expected (" + utfBytes + ")" );
  +            }
  +
  +            // now set up a DataInputStream to read those
  +            // bytes as a UTF-8 String i.e. as though we'd never
  +            // read the first 2 bytes from the original stream
  +            DataInputStream dis = null;
  +            String str = null;
  +            try
  +            {
  +                dis = new DataInputStream(new ByteArrayInputStream(bArray));
  +                str = dis.readUTF();
  +            }
  +            finally
  +            {
  +                if (dis != null)
  +                    dis.close();
  +            }
  +
  +            return str;
           }
   
           private Object readResolve() throws ObjectStreamException
  
  
  

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