You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by zi...@apache.org on 2004/01/09 03:18:57 UTC

cvs commit: xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections ObjectAccumulator.java

zieg        2004/01/08 18:18:57

  Modified:    v2/src/common/org/apache/xmlbeans/impl/common
                        XmlWhitespace.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        MarshalResult.java ScopedNamespaceContext.java
               v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections
                        ObjectAccumulator.java
  Log:
  implement more JSR 173 methods in marshal
  
  Revision  Changes    Path
  1.2       +11 -1     xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/XmlWhitespace.java
  
  Index: XmlWhitespace.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/common/org/apache/xmlbeans/impl/common/XmlWhitespace.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XmlWhitespace.java	26 Sep 2003 21:23:27 -0000	1.1
  +++ XmlWhitespace.java	9 Jan 2004 02:18:57 -0000	1.2
  @@ -81,7 +81,17 @@
   
       public static boolean isAllSpace(String v)
       {
  -        for (int i = 0; i < v.length(); i++)
  +        for (int i = 0, len = v.length(); i < len; i++)
  +        {
  +            if (!isSpace(v.charAt(i)))
  +                return false;
  +        }
  +        return true;
  +    }
  +
  +    public static boolean isAllSpace(CharSequence v)
  +    {
  +        for (int i = 0, len = v.length(); i < len; i++)
           {
               if (!isSpace(v.charAt(i)))
                   return false;
  
  
  
  1.10      +83 -17    xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java
  
  Index: MarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalResult.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MarshalResult.java	7 Jan 2004 07:29:52 -0000	1.9
  +++ MarshalResult.java	9 Jan 2004 02:18:57 -0000	1.10
  @@ -61,6 +61,7 @@
   import org.apache.xmlbeans.impl.binding.bts.ByNameBean;
   import org.apache.xmlbeans.impl.binding.bts.SimpleBindingType;
   import org.apache.xmlbeans.impl.common.XmlStreamUtils;
  +import org.apache.xmlbeans.impl.common.XmlWhitespace;
   import org.apache.xmlbeans.impl.marshal.util.collections.ArrayIterator;
   import org.apache.xmlbeans.impl.marshal.util.collections.EmptyIterator;
   import org.apache.xmlbeans.impl.marshal.util.collections.ReflectiveArrayIterator;
  @@ -201,7 +202,10 @@
   
       public String getNamespaceURI(String s)
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        if (s == null)
  +            throw new IllegalArgumentException("prefix cannot be null");
  +
  +        return getNamespaceContext().getNamespaceURI(s);
       }
   
       public boolean isStartElement()
  @@ -216,18 +220,30 @@
   
       public boolean isCharacters()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return currentEventType == CHARACTERS;
       }
   
       public boolean isWhiteSpace()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        if (!isCharacters()) return false;
  +        CharSequence seq = currVisitor.getCharData();
  +        return XmlWhitespace.isAllSpace(seq);
       }
   
  -    public String getAttributeValue(String s, String s1)
  +    public String getAttributeValue(String uri, String lname)
       {
           initAttributes();
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +
  +        //TODO: do better than this basic and slow implementation
  +        for (int i = 0, len = getAttributeCount(); i < len; i++) {
  +            final QName aname = getAttributeName(i);
  +
  +            if (lname.equals(aname.getLocalPart())) {
  +                if (uri == null || uri.equals(aname.getNamespaceURI()))
  +                    return getAttributeValue(i);
  +            }
  +        }
  +        return null;
       }
   
       public int getAttributeCount()
  @@ -316,15 +332,56 @@
   
       public char[] getTextCharacters()
       {
  -        return getText().toCharArray();
  -    }
  +        CharSequence seq = currVisitor.getCharData();
  +        if (seq instanceof String) {
  +            return seq.toString().toCharArray();
  +        }
   
  -    public int getTextCharacters(int i, char[] chars, int i1, int i2)
  -        throws XMLStreamException
  -    {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        final int len = seq.length();
  +        char[] val = new char[len];
  +        for(int i = 0 ; i < len ; i++) {
  +            val[i] = seq.charAt(i);
  +        }
  +        return val;
       }
   
  +
  +      public int getTextCharacters(int sourceStart,
  +                                   char[] target,
  +                                   int targetStart,
  +                                   int length)
  +          throws XMLStreamException
  +      {
  +          if (length < 0)
  +              throw new IndexOutOfBoundsException("negative length: " + length);
  +
  +          if (targetStart < 0)
  +              throw new IndexOutOfBoundsException("negative targetStart: " + targetStart);
  +
  +          final int target_length = target.length;
  +          if (targetStart >= target_length)
  +              throw new IndexOutOfBoundsException("targetStart(" + targetStart + ") past end of target(" + target_length + ")");
  +
  +          if ((targetStart + length) > target_length) {
  +              throw new IndexOutOfBoundsException("insufficient data in target(length is " + target_length + ")");
  +          }
  +
  +          CharSequence seq = currVisitor.getCharData();
  +          if (seq instanceof String) {
  +              final String s = seq.toString();
  +              s.getChars(sourceStart, sourceStart + length, target, targetStart);
  +              return length;
  +          }
  +
  +          final int len = seq.length();
  +          char[] val = new char[len];
  +          int cnt = 0;
  +          for (int src_idx = sourceStart, dest_idx = targetStart; cnt < length; cnt++) {
  +              target[dest_idx++] = seq.charAt(src_idx++);
  +          }
  +          return cnt;
  +      }
  +
       public int getTextStart()
       {
           return 0;
  @@ -337,12 +394,21 @@
   
       public String getEncoding()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return null;
       }
   
       public boolean hasText()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        //we'll likely never return some of these but just in case...
  +        switch (currentEventType) {
  +            case COMMENT:
  +            case DTD:
  +            case ENTITY_REFERENCE:
  +            case CHARACTERS:
  +                return true;
  +            default:
  +                return false;
  +        }
       }
   
       public Location getLocation()
  @@ -378,22 +444,22 @@
   
       public String getVersion()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return null;
       }
   
       public boolean isStandalone()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return false;
       }
   
       public boolean standaloneSet()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return false;
       }
   
       public String getCharacterEncodingScheme()
       {
  -        throw new UnsupportedOperationException("UNIMPLEMENTED");
  +        return null;
       }
   
       public String getPITarget()
  
  
  
  1.2       +22 -1     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ScopedNamespaceContext.java
  
  Index: ScopedNamespaceContext.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/ScopedNamespaceContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScopedNamespaceContext.java	31 Oct 2003 22:23:26 -0000	1.1
  +++ ScopedNamespaceContext.java	9 Jan 2004 02:18:57 -0000	1.2
  @@ -73,6 +73,11 @@
       private final Stack scopeStack;
       private LLNamespaceContext current = null;
   
  +    private static final String XML_NS = "http://www.w3.org/XML/1998/namespace";
  +    private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
  +    private static final String XML_PREFIX = "xml";
  +    private static final String XMLNS_PREFIX = "xmlns";
  +
       public ScopedNamespaceContext()
       {
           this(null, new Stack());
  @@ -86,7 +91,7 @@
   
       public ScopedNamespaceContext(NamespaceContext root_nsctx)
       {
  -        //TODO: copy initial context!
  +        //TODO: copy or use initial context!
           this(null, new Stack());
       }
   
  @@ -98,6 +103,13 @@
   
       public String getNamespaceURI(String prefix)
       {
  +        //two special cases from JSR 173
  +        if (XML_PREFIX.equals(prefix))
  +            return XML_NS;
  +
  +        if (XMLNS_PREFIX.equals(prefix))
  +            return XMLNS_URI;
  +
           if (current == null) return null;
   
           return current.getNamespaceURI(prefix);
  @@ -105,6 +117,15 @@
   
       public String getPrefix(String namespaceURI)
       {
  +        //two special cases from JSR 173
  +
  +        if (XML_NS.equals(namespaceURI))
  +            return XML_PREFIX;
  +
  +        if (XMLNS_URI.equals(namespaceURI))
  +            return XMLNS_PREFIX;
  +
  +
           if (current == null)
               return null;
           else
  
  
  
  1.3       +1 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/ObjectAccumulator.java
  
  Index: ObjectAccumulator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/util/collections/ObjectAccumulator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectAccumulator.java	19 Nov 2003 20:40:25 -0000	1.2
  +++ ObjectAccumulator.java	9 Jan 2004 02:18:57 -0000	1.3
  @@ -83,6 +83,7 @@
           returnCollectionForArray = return_collection;
   
           store = createNewStore(initial_capacity);
  +        assert store != null;
       }
   
       public ObjectAccumulator(Class component_type,
  
  
  

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