mrglavas    2004/05/15 16:29:20

  Modified:    java/src/org/apache/xerces/impl/dv/xs XSSimpleTypeDecl.java
               java/src/org/apache/xerces/impl/xs/util StringListImpl.java
                        XSObjectListImpl.java
  Log:
  XSSimpleTypeDefinition [1] specifies that empty lists (XSObjectList & StringList)

  are returned when no list for a requested item exists. Our implementation got

  out of synch with the spec. We were returning null instead. This is now fixed.

  

  [1] 
http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSSimpleType
  
  Revision  Changes    Path
  1.51      +93 -11    
xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
  
  Index: XSSimpleTypeDecl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- XSSimpleTypeDecl.java     26 Feb 2004 19:50:09 -0000      1.50
  +++ XSSimpleTypeDecl.java     15 May 2004 23:29:20 -0000      1.51
  @@ -569,10 +569,20 @@
           }
       }
   
  +    /**
  +     * Returns the closest built-in type category this type represents or 
  +     * derived from. For example, if this simple type is a built-in derived 
  +     * type integer the <code>INTEGER_DV</code> is returned.
  +     */
       public short getBuiltInKind() {
           return this.fBuiltInKind;
       }
   
  +    /**
  +     * If variety is <code>atomic</code> the primitive type definition (a 
  +     * built-in primitive datatype definition or the simple ur-type 
  +     * definition) is available, otherwise <code>null</code>. 
  +     */
       public XSSimpleTypeDefinition getPrimitiveType() {
           if (fVariety == VARIETY_ATOMIC && fValidationDV != DV_ANYSIMPLETYPE) {
               XSSimpleTypeDecl pri = this;
  @@ -587,6 +597,11 @@
           }
       }
   
  +    /**
  +     * If variety is <code>list</code> the item type definition (an atomic or 
  +     * union simple type definition) is available, otherwise 
  +     * <code>null</code>. 
  +     */
       public XSSimpleTypeDefinition getItemType() {
           if (fVariety == VARIETY_LIST) {
               return fItemType;
  @@ -597,13 +612,17 @@
           }
       }
   
  +    /**
  +     * If variety is <code>union</code> the list of member type definitions (a 
  +     * non-empty sequence of simple type definitions) is available, 
  +     * otherwise an empty <code>XSObjectList</code>. 
  +     */
       public XSObjectList getMemberTypes() {
           if (fVariety == VARIETY_UNION) {
               return new XSObjectListImpl(fMemberTypes, fMemberTypes.length);
           }
           else {
  -            // REVISIT: error situation. runtime exception?
  -            return null;
  +            return XSObjectListImpl.EMPTY_LIST;
           }
       }
   
  @@ -1856,22 +1875,40 @@
           return WS_FACET_STRING[ws];
       }
   
  +    /**
  +     *  Fundamental Facet: ordered. 
  +     */
       public short getOrdered() {
           return fOrdered;
       }
   
  +    /**
  +     * Fundamental Facet: bounded. 
  +     */
       public boolean getBounded(){
           return fBounded;
       }
   
  +    /**
  +     * Fundamental Facet: cardinality. 
  +     */
       public boolean getFinite(){
           return fFinite;
       }
   
  +    /**
  +     * Fundamental Facet: numeric. 
  +     */
       public boolean getNumeric(){
           return fNumeric;
       }
   
  +    /**
  +     * Convenience method. [Facets]: check whether a facet is defined on this 
  +     * type.
  +     * @param facetName  The name of the facet. 
  +     * @return  True if the facet is defined, false otherwise.
  +     */
       public boolean isDefinedFacet(short facetName) {
           if ((fFacetsDefined & facetName) != 0)
               return true;
  @@ -1882,6 +1919,10 @@
           return false;
       }
   
  +    /**
  +     * [facets]: all facets defined on this type. The value is a bit 
  +     * combination of FACET_XXX constants of all defined facets. 
  +     */
       public short getDefinedFacets() {
           if (fPatternType != SPECIAL_PATTERN_NONE)
               return (short)(fFacetsDefined | FACET_PATTERN);
  @@ -1890,6 +1931,12 @@
           return fFacetsDefined;
       }
   
  +    /**
  +     * Convenience method. [Facets]: check whether a facet is defined and 
  +     * fixed on this type. 
  +     * @param facetName  The name of the facet. 
  +     * @return  True if the facet is fixed, false otherwise.
  +     */
       public boolean isFixedFacet(short facetName) {
           if ((fFixedFacet & facetName) != 0)
               return true;
  @@ -1898,12 +1945,27 @@
           return false;
       }
   
  +    /**
  +     * [facets]: all defined facets for this type which are fixed.
  +     */
       public short getFixedFacets() {
           if (fValidationDV == DV_INTEGER)
               return (short)(fFixedFacet | FACET_FRACTIONDIGITS);
           return fFixedFacet;
       }
   
  +    /**
  +     * Convenience method. Returns a value of a single constraining facet for 
  +     * this simple type definition. This method must not be used to retrieve 
  +     * values for <code>enumeration</code> and <code>pattern</code> facets. 
  +     * @param facetName The name of the facet, i.e. 
  +     *   <code>FACET_LENGTH, FACET_TOTALDIGITS </code> (see 
  +     *   <code>XSConstants</code>). To retrieve the value for a pattern or 
  +     *   an enumeration, see <code>enumeration</code> and 
  +     *   <code>pattern</code>.
  +     * @return A value of the facet specified in <code>facetName</code> for 
  +     *   this simple type definition or <code>null</code>. 
  +     */
       public String getLexicalFacetValue(short facetName) {
           switch (facetName) {
           case FACET_LENGTH:
  @@ -1932,10 +1994,14 @@
           return null;
       }
   
  +    /**
  +     * A list of enumeration values if it exists, otherwise an empty 
  +     * <code>StringList</code>. 
  +     */
       public StringList getLexicalEnumeration() {
           if (fLexicalEnumeration == null){
               if (fEnumeration == null)
  -                return null;
  +                return StringListImpl.EMPTY_LIST;
               int size = fEnumeration.size();
               String[] strs = new String[size];
               for (int i = 0; i < size; i++)
  @@ -1945,9 +2011,13 @@
           return fLexicalEnumeration;
       }
   
  +    /**
  +     * A list of pattern values if it exists, otherwise an empty 
  +     * <code>StringList</code>. 
  +     */
       public StringList getLexicalPattern() {
           if (fPatternType == SPECIAL_PATTERN_NONE && fValidationDV != DV_INTEGER && 
fPatternStr == null)
  -            return null;
  +            return StringListImpl.EMPTY_LIST;
           if (fLexicalPattern == null){
               int size = fPatternStr == null ? 0 : fPatternStr.size();
               String[] strs;
  @@ -1978,8 +2048,12 @@
           return fLexicalPattern;
       }
   
  +    /**
  +     * [annotations]: a set of annotations for this simple type component if 
  +     * it exists, otherwise an empty <code>XSObjectList</code>. 
  +     */
       public XSObjectList getAnnotations() {
  -        return fAnnotations;
  +        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
       }
   
       private void caclFundamentalFacets() {
  @@ -2387,8 +2461,11 @@
           return this.fTargetNamespace+"," +this.fTypeName;
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.xerces.xs.XSSimpleTypeDefinition#getFacets()
  +    /**
  +     *  A list of constraining facets if it exists, otherwise an empty 
  +     * <code>XSObjectList</code>. Note: This method must not be used to 
  +     * retrieve values for <code>enumeration</code> and <code>pattern</code> 
  +     * facets. 
        */
       public XSObjectList getFacets() {
           if (fFacets == null &&
  @@ -2497,10 +2574,14 @@
               }
               fFacets = new XSObjectListImpl(facets, count);
           }
  -        return fFacets;
  +        return (fFacets != null) ? fFacets : XSObjectListImpl.EMPTY_LIST;
       }
       
  -    public XSObjectList getMultiValueFacets(){
  +    /**
  +     *  A list of enumeration and pattern constraining facets if it exists, 
  +     * otherwise an empty <code>XSObjectList</code>. 
  +     */
  +    public XSObjectList getMultiValueFacets() {
           if (fMultiValueFacets == null &&
               ((fFacetsDefined & FACET_ENUMERATION) != 0 ||
                (fFacetsDefined & FACET_PATTERN) != 0 ||
  @@ -2529,7 +2610,8 @@
               }
               fMultiValueFacets = new XSObjectListImpl(facets, count);
           }
  -        return fMultiValueFacets;
  +        return (fMultiValueFacets != null) ? 
  +            fMultiValueFacets : XSObjectListImpl.EMPTY_LIST;
       }
       
       private static final class XSFacetImpl implements XSFacet {
  
  
  
  1.7       +16 -1     
xml-xerces/java/src/org/apache/xerces/impl/xs/util/StringListImpl.java
  
  Index: StringListImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/util/StringListImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StringListImpl.java       24 Feb 2004 22:59:13 -0000      1.6
  +++ StringListImpl.java       15 May 2004 23:29:20 -0000      1.7
  @@ -27,6 +27,21 @@
    */
   public class StringListImpl 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;
  +        }
  +    };
  +    
       // The array to hold all data
       private String[] fArray = null;
       // Number of elements in this list
  
  
  
  1.9       +13 -1     
xml-xerces/java/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java
  
  Index: XSObjectListImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/util/XSObjectListImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XSObjectListImpl.java     24 Feb 2004 22:59:13 -0000      1.8
  +++ XSObjectListImpl.java     15 May 2004 23:29:20 -0000      1.9
  @@ -28,6 +28,18 @@
    */
   public class XSObjectListImpl implements XSObjectList {
   
  +    /**
  +     * An immutable empty list.
  +     */
  +    public static final XSObjectList EMPTY_LIST = new XSObjectList () {
  +        public int getLength() {
  +            return 0;
  +        }
  +        public XSObject item(int index) {
  +            return null;
  +        }
  +    };
  +    
       private final int DEFAULT_SIZE = 4;
   
       // The array to hold all data
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to