You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2008/12/11 23:19:32 UTC

svn commit: r725841 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl: dv/util/ dv/xs/ xs/traversers/ xs/util/

Author: mrglavas
Date: Thu Dec 11 14:19:31 2008
New Revision: 725841

URL: http://svn.apache.org/viewvc?rev=725841&view=rev
Log:
As a consequence of our choice to design XSModel in IDL instead of Java we ended
up creating many list type interfaces. If we had started this work in Java we
would have used java.util.List instead, an interface which is built into the Java
class library that has first class support in the Collections API and is used by
countless applications. When we revisit the XSModel for XML Schema 1.1 we should
retrofit java.util.List everywhere in the API where we are returning the XSModel
specific list types. In anticipation of this change I've updated each of the
list implementations so that they now implement java.util.List. This will make it
easier to update the API when the time comes.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/util/ByteListImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/ListDV.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/ShortListImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/StringListImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/util/ByteListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/util/ByteListImpl.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/util/ByteListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/util/ByteListImpl.java Thu Dec 11 14:19:31 2008
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.dv.util;
 
+import java.util.AbstractList;
+
 import org.apache.xerces.xs.XSException;
 import org.apache.xerces.xs.datatypes.ByteList;
 
@@ -29,7 +31,7 @@
  * 
  * @version $Id$
  */
-public class ByteListImpl implements ByteList {
+public class ByteListImpl extends AbstractList implements ByteList {
 
     // actually data stored in a byte array
     protected final byte[] data;
@@ -85,5 +87,19 @@
         return data[index];
     }
     
+    /*
+     * List methods
+     */
+
+    public Object get(int index) {
+        if (index >= 0 && index < data.length) {
+            return new Byte(data[index]);
+        }
+        throw new IndexOutOfBoundsException("Index: " + index);
+    }
+
+    public int size() {
+        return getLength();
+    }
 }
 

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/ListDV.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/ListDV.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/ListDV.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/ListDV.java Thu Dec 11 14:19:31 2008
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.dv.xs;
 
+import java.util.AbstractList;
+
 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
 import org.apache.xerces.impl.dv.ValidationContext;
 import org.apache.xerces.xs.datatypes.ObjectList;
@@ -48,7 +50,7 @@
         return ((ListData)value).getLength();
     }
 
-    final static class ListData implements ObjectList {
+    final static class ListData extends AbstractList implements ObjectList {
         final Object[] data;
         private String canonical;
         public ListData(Object[] data) {
@@ -113,6 +115,21 @@
             }
             return data[index];
         }
+        
+        /*
+         * List methods
+         */
+        
+        public Object get(int index) {
+            if (index >= 0 && index < data.length) {
+                return data[index];
+            }
+            throw new IndexOutOfBoundsException("Index: " + index);
+        }
+        
+        public int size() {
+            return getLength();
+        }
     }
 } // class ListDV
 

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java Thu Dec 11 14:19:31 2008
@@ -1442,7 +1442,7 @@
                 if (fBase.patternAnnotations != null) {
                     if (patternAnnotations != null) {
                         for (int i = fBase.patternAnnotations.getLength()-1; i >= 0; --i) {
-                            patternAnnotations.add(fBase.patternAnnotations.item(i));
+                            patternAnnotations.addXSObject(fBase.patternAnnotations.item(i));
                         }
                     }
                     else {
@@ -3165,7 +3165,7 @@
 
             if (annotation != null) {
                 this.annotations = new XSObjectListImpl();
-                ((XSObjectListImpl)this.annotations).add(annotation);
+                ((XSObjectListImpl)this.annotations).addXSObject(annotation);
             } 
             else {
                 this.annotations =  XSObjectListImpl.EMPTY_LIST;

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractParticleTraverser.java Thu Dec 11 14:19:31 2008
@@ -119,7 +119,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add (annotation);
+            ((XSObjectListImpl)annotations).addXSObject (annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }
@@ -283,7 +283,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add (annotation);
+            ((XSObjectListImpl)annotations).addXSObject (annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java Thu Dec 11 14:19:31 2008
@@ -323,7 +323,7 @@
                     enumAnnotations = new XSObjectListImpl();
                 }
                 enumData.addElement(enumVal);
-                enumAnnotations.add(null);
+                enumAnnotations.addXSObject(null);
                 if (hasQName)
                     enumNSDecls.addElement(nsDecls);
                 Element child = DOMUtil.getFirstChildElement( content );
@@ -331,13 +331,13 @@
                 if (child != null &&
                     DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
                     // traverse annotation if any
-                    enumAnnotations.add(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc));
+                    enumAnnotations.addXSObject(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc));
                     child = DOMUtil.getNextSiblingElement(child);
                 }
                 else {
                     String text = DOMUtil.getSyntheticAnnotation(content);
                     if (text != null) {
-                        enumAnnotations.add(enumAnnotations.getLength()-1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
+                        enumAnnotations.addXSObject(enumAnnotations.getLength()-1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
                     }
                 }
                 if (child !=null) {
@@ -362,7 +362,7 @@
                     if (patternAnnotations == null){
                         patternAnnotations = new XSObjectListImpl();
                     }
-                    patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc));
+                    patternAnnotations.addXSObject(traverseAnnotationDecl(child, attrs, false, schemaDoc));
                     child = DOMUtil.getNextSiblingElement(child);
                 }
                 else {
@@ -371,7 +371,7 @@
                         if (patternAnnotations == null){
                             patternAnnotations = new XSObjectListImpl();
                         }
-                        patternAnnotations.add(traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
+                        patternAnnotations.addXSObject(traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
                     }
                 }
                 if (child !=null) {
@@ -414,7 +414,7 @@
                     XSObjectList annotations = null;
                     if (annotation != null) {
                         annotations = new XSObjectListImpl();
-                        ((XSObjectListImpl)annotations).add(annotation);
+                        ((XSObjectListImpl)annotations).addXSObject(annotation);
                     }
                     else {
                         //if no annotations are present add an empty list to the assertion

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeGroupTraverser.java Thu Dec 11 14:19:31 2008
@@ -166,7 +166,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add (annotation);
+            ((XSObjectListImpl)annotations).addXSObject (annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAttributeTraverser.java Thu Dec 11 14:19:31 2008
@@ -142,7 +142,7 @@
                 XSObjectList annotations;
                 if (annotation != null) {
                     annotations = new XSObjectListImpl();
-                    ((XSObjectListImpl) annotations).add(annotation);
+                    ((XSObjectListImpl) annotations).addXSObject(annotation);
                 } else {
                     annotations = XSObjectListImpl.EMPTY_LIST;
                 }
@@ -327,7 +327,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add(annotation);
+            ((XSObjectListImpl)annotations).addXSObject(annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java Thu Dec 11 14:19:31 2008
@@ -1438,7 +1438,7 @@
             XSObjectList annotations = null;
             if (annotation != null) {
                 annotations = new XSObjectListImpl();
-                ((XSObjectListImpl) annotations).add(annotation);
+                ((XSObjectListImpl) annotations).addXSObject(annotation);
             } else {
                 // if no annotations are present add an empty list to
                 // the assertion

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java Thu Dec 11 14:19:31 2008
@@ -206,7 +206,7 @@
             XSObjectList annotations;
             if (annotation != null) {
                 annotations = new XSObjectListImpl();
-                ((XSObjectListImpl) annotations).add(annotation);
+                ((XSObjectListImpl) annotations).addXSObject(annotation);
             } else {
                 annotations = XSObjectListImpl.EMPTY_LIST;
             }
@@ -366,7 +366,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add (annotation);
+            ((XSObjectListImpl)annotations).addXSObject (annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDGroupTraverser.java Thu Dec 11 14:19:31 2008
@@ -122,7 +122,7 @@
                 XSObjectList annotations;
                 if (annotation != null) {
                     annotations = new XSObjectListImpl();
-                    ((XSObjectListImpl) annotations).add(annotation);
+                    ((XSObjectListImpl) annotations).addXSObject(annotation);
                 } else {
                     annotations = XSObjectListImpl.EMPTY_LIST;
                 }
@@ -214,7 +214,7 @@
                 XSObjectList annotations;
                 if (annotation != null) {
                     annotations = new XSObjectListImpl();
-                    ((XSObjectListImpl) annotations).add(annotation);
+                    ((XSObjectListImpl) annotations).addXSObject(annotation);
                 } else {
                     annotations = XSObjectListImpl.EMPTY_LIST;
                 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDNotationTraverser.java Thu Dec 11 14:19:31 2008
@@ -94,7 +94,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl) annotations).add(annotation);
+            ((XSObjectListImpl) annotations).addXSObject(annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDTypeAlternativeTraverser.java Thu Dec 11 14:19:31 2008
@@ -87,7 +87,7 @@
         XSObjectList annotations = null;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl)annotations).add(annotation);
+            ((XSObjectListImpl)annotations).addXSObject(annotation);
         }
         else {
             //if no annotations are present add an empty list to the type alternative

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDWildcardTraverser.java Thu Dec 11 14:19:31 2008
@@ -195,7 +195,7 @@
         XSObjectList annotations;
         if (annotation != null) {
             annotations = new XSObjectListImpl();
-            ((XSObjectListImpl) annotations).add(annotation);
+            ((XSObjectListImpl) annotations).addXSObject(annotation);
         } else {
             annotations = XSObjectListImpl.EMPTY_LIST;
         }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/ShortListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/ShortListImpl.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/ShortListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/ShortListImpl.java Thu Dec 11 14:19:31 2008
@@ -17,11 +17,13 @@
 
 package org.apache.xerces.impl.xs.util;
 
+import java.util.AbstractList;
+
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.XSException;
 
 /**
- * Containts a list of Object's.
+ * Contains a list of shorts.
  *
  * @xerces.internal 
  *
@@ -29,22 +31,12 @@
  *
  * @version $Id$
  */
-public final class ShortListImpl implements ShortList {
+public final class ShortListImpl extends AbstractList implements ShortList {
 
     /**
      * An immutable empty list.
      */
-    public static final ShortList EMPTY_LIST = new ShortList() {
-        public int getLength() {
-            return 0;
-        }
-        public boolean contains(short item) {
-            return false;
-        }
-        public short item(int index) throws XSException {
-            throw new XSException(XSException.INDEX_SIZE_ERR, null);
-        }
-    };
+    public static final ShortListImpl EMPTY_LIST = new ShortListImpl(new short[0], 0);
     
     // The array to hold all data
     private final short[] fArray;
@@ -110,5 +102,20 @@
         }
         return true;
     }
+    
+    /*
+     * List methods
+     */
+
+    public Object get(int index) {
+        if (index >= 0 && index < fLength) {
+            return new Short(fArray[index]);
+        }
+        throw new IndexOutOfBoundsException("Index: " + index);
+    }
+
+    public int size() {
+        return getLength();
+    }
 
 } // class ShortListImpl

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/StringListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/StringListImpl.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/StringListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/StringListImpl.java Thu Dec 11 14:19:31 2008
@@ -17,12 +17,13 @@
 
 package org.apache.xerces.impl.xs.util;
 
+import java.util.AbstractList;
 import java.util.Vector;
 
 import org.apache.xerces.xs.StringList;
 
 /**
- * Containts a list of Object's.
+ * Contains a list of Strings.
  *
  * @xerces.internal 
  *
@@ -30,22 +31,12 @@
  *
  * @version $Id$
  */
-public final class StringListImpl implements StringList {
+public final class StringListImpl extends AbstractList implements StringList {
 
     /**
      * An immutable empty list.
      */
-    public static final StringList EMPTY_LIST = new StringList () {
-        public int getLength() {
-            return 0;
-        }
-        public boolean contains(String item) {
-            return false;
-        }
-        public String item(int index) {
-            return null;
-        }
-    };
+    public static final StringListImpl EMPTY_LIST = new StringListImpl(new String[0], 0);
     
     // The array to hold all data
     private final String[] fArray;
@@ -118,5 +109,23 @@
         }
         return fArray[index];
     }
+    
+    /*
+     * List methods
+     */
+
+    public Object get(int index) {
+        if (index >= 0 && index < fLength) {
+            if (fVector != null) {
+                return fVector.elementAt(index);
+            }
+            return fArray[index];
+        }
+        throw new IndexOutOfBoundsException("Index: " + index);
+    }
+
+    public int size() {
+        return getLength();
+    }
 
-} // class XSParticle
+} // class StringListImpl

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java?rev=725841&r1=725840&r2=725841&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java Thu Dec 11 14:19:31 2008
@@ -17,11 +17,16 @@
 
 package org.apache.xerces.impl.xs.util;
 
+import java.util.AbstractList;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
 import org.apache.xerces.xs.XSObject;
 import org.apache.xerces.xs.XSObjectList;
 
 /**
- * Containts a list of XSObject's.
+ * Contains a list of XSObjects.
  *
  * @xerces.internal 
  *
@@ -29,17 +34,39 @@
  *
  * @version $Id$
  */
-public class XSObjectListImpl implements XSObjectList {
+public class XSObjectListImpl extends AbstractList implements XSObjectList {
 
     /**
      * An immutable empty list.
      */
-    public static final XSObjectList EMPTY_LIST = new XSObjectList () {
-        public int getLength() {
+    public static final XSObjectListImpl EMPTY_LIST = new XSObjectListImpl(new XSObject[0], 0);
+    private static final ListIterator EMPTY_ITERATOR = new ListIterator() {
+        public boolean hasNext() {
+            return false;
+        }
+        public Object next() {
+            throw new NoSuchElementException();
+        }
+        public boolean hasPrevious() {
+            return false;
+        }
+        public Object previous() {
+            throw new NoSuchElementException();
+        }
+        public int nextIndex() {
             return 0;
         }
-        public XSObject item(int index) {
-            return null;
+        public int previousIndex() {
+            return -1;
+        }
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+        public void set(Object object) {
+            throw new UnsupportedOperationException();
+        }
+        public void add(Object object) {
+            throw new UnsupportedOperationException();
         }
     };
     
@@ -50,8 +77,6 @@
     // Number of elements in this list
     private int fLength = 0;
     
-
-
     public XSObjectListImpl() {
         fArray = new XSObject[DEFAULT_SIZE];
         fLength = 0;
@@ -86,8 +111,9 @@
      *   valid index.
      */
     public XSObject item(int index) {
-        if (index < 0 || index >= fLength)
+        if (index < 0 || index >= fLength) {
             return null;
+        }
         return fArray[index];
     }
 
@@ -100,16 +126,113 @@
         fLength = 0;
     }
     
-    public void add (XSObject object){
-       if (fLength == fArray.length){  
+    public void addXSObject(XSObject object) {
+       if (fLength == fArray.length) {  
            XSObject[] temp = new XSObject[fLength + 4];
            System.arraycopy(fArray, 0, temp, 0, fLength);
            fArray = temp;
        }
-       fArray[fLength++]=object;
+       fArray[fLength++] = object;
+    }
+    
+    public void addXSObject(int index, XSObject object) {
+        fArray[index] = object;
+    }
+    
+    /*
+     * List methods
+     */
+    
+    public boolean contains(Object value) {
+        return (value == null) ? containsNull() : containsObject(value);
+    }
+
+    public Object get(int index) {
+        if (index >= 0 && index < fLength) {
+            return fArray[index];
+        }
+        throw new IndexOutOfBoundsException("Index: " + index);
+    }
+
+    public int size() {
+        return getLength();
+    }
+    
+    public Iterator iterator() {
+        return listIterator0(0);
     }
-    public void add (int index, XSObject object){
-        fArray [index] = object;
+    
+    public ListIterator listIterator() {
+        return listIterator0(0);
+    }
+    
+    public ListIterator listIterator(int index) {
+        if (index >= 0 && index < fLength) {
+            return listIterator0(index);
+        }
+        throw new IndexOutOfBoundsException("Index: " + index);
+    }
+    
+    private ListIterator listIterator0(int index) {
+        return fLength == 0 ? EMPTY_ITERATOR : new XSObjectListIterator(index);
+    }
+    
+    private boolean containsObject(Object value) {
+        for (int i = fLength - 1; i >= 0; --i) {
+            if (value.equals(fArray[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private boolean containsNull() {
+        for (int i = fLength - 1; i >= 0; --i) {
+            if (fArray[i] == null) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private final class XSObjectListIterator implements ListIterator {
+        private int index;
+        public XSObjectListIterator(int index) {
+            this.index = index;
+        }
+        public boolean hasNext() {
+            return (index < fLength);
+        }
+        public Object next() {
+            if (index < fLength) {
+                return fArray[index++];
+            }
+            throw new NoSuchElementException();
+        }
+        public boolean hasPrevious() {
+            return (index > 0);
+        }
+        public Object previous() {
+            if (index > 0) {
+                return fArray[--index];
+            }
+            throw new NoSuchElementException();
+        }
+        public int nextIndex() {
+            return index;
+        }
+        public int previousIndex() {
+            return index - 1;
+        }
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+        public void set(Object o) {
+            throw new UnsupportedOperationException();
+        }
+        public void add(Object o) {
+            throw new UnsupportedOperationException();
+        }
     }
 
-} // class XSObjectList
+} // class XSObjectListImpl



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