You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/10/18 21:03:06 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 XSWildcardDecl.java XSParticleDecl.java XSElementDecl.java

sandygao    01/10/18 12:03:06

  Modified:    java/src/org/apache/xerces/impl/v2 XSWildcardDecl.java
                        XSParticleDecl.java XSElementDecl.java
  Log:
  1. check whether a particle is emptiable;
  2. reuse .toString message for particle, wildcard and element.
  
  Revision  Changes    Path
  1.11      +25 -15    xml-xerces/java/src/org/apache/xerces/impl/v2/XSWildcardDecl.java
  
  Index: XSWildcardDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSWildcardDecl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XSWildcardDecl.java	2001/10/18 16:11:37	1.10
  +++ XSWildcardDecl.java	2001/10/18 19:03:05	1.11
  @@ -67,7 +67,7 @@
    * @author Sandy Gao, IBM
    * @author Rahul Srivastava, Sun Microsystems Inc.
    *
  - * @version $Id: XSWildcardDecl.java,v 1.10 2001/10/18 16:11:37 neilg Exp $
  + * @version $Id: XSWildcardDecl.java,v 1.11 2001/10/18 19:03:05 sandygao Exp $
    */
   public class XSWildcardDecl  {
   
  @@ -380,22 +380,32 @@
   
       // REVISIT: how to prepresent wildcard in string.
       //          "namespace:usr=someuri," is not so descriptive
  +
  +    /**
  +     * get the string description of this wildcard
  +     */
  +    private String fDescription = null;
       public String toString() {
  -        String ret = null;
  -        switch (fType) {
  -        case WILDCARD_ANY:
  -            ret = SchemaSymbols.ATTVAL_TWOPOUNDANY;
  -            break;
  -        case WILDCARD_OTHER:
  -            ret = SchemaSymbols.ATTVAL_TWOPOUNDOTHER + ":uri=" + fNamespaceList[0];
  -            break;
  -        case WILDCARD_LIST:
  -            ret = "namespace:uri=" + fNamespaceList[0];
  -            for (int i = 1; i < fNamespaceList.length; i++)
  -                ret += "," + fNamespaceList[i];
  -            break;
  +        if (fDescription == null) {
  +            String ret = null;
  +            switch (fType) {
  +            case WILDCARD_ANY:
  +                fDescription = SchemaSymbols.ATTVAL_TWOPOUNDANY;
  +                break;
  +            case WILDCARD_OTHER:
  +                fDescription = SchemaSymbols.ATTVAL_TWOPOUNDOTHER + ":uri=" + fNamespaceList[0];
  +                break;
  +            case WILDCARD_LIST: {
  +                StringBuffer buffer = new StringBuffer();
  +                buffer.append("namespace:uri=" + fNamespaceList[0]);
  +                for (int i = 1; i < fNamespaceList.length; i++)
  +                    buffer.append("," + fNamespaceList[i]);
  +                fDescription = buffer.toString();
  +                break;
  +            }
  +            }
           }
   
  -        return ret;
  +        return fDecription;
       }
   } // class XSWildcardDecl
  
  
  
  1.17      +112 -17   xml-xerces/java/src/org/apache/xerces/impl/v2/XSParticleDecl.java
  
  Index: XSParticleDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSParticleDecl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XSParticleDecl.java	2001/10/17 23:07:14	1.16
  +++ XSParticleDecl.java	2001/10/18 19:03:05	1.17
  @@ -62,7 +62,7 @@
    *
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSParticleDecl.java,v 1.16 2001/10/17 23:07:14 sandygao Exp $
  + * @version $Id: XSParticleDecl.java,v 1.17 2001/10/18 19:03:05 sandygao Exp $
    */
   public class XSParticleDecl {
   
  @@ -92,34 +92,129 @@
       // maximum occurrence of this particle
       public int fMaxOccurs = 1;
   
  +    /**
  +     * 3.9.6 Schema Component Constraint: Particle Emptiable
  +     * whether this particle is emptible
  +     */
  +    public boolean emptiable() {
  +        return minEffectiveTotalRange() == 0;
  +    }
   
  -    private StringBuffer fBuffer = null;
  +    /**
  +     * 3.8.6 Effective Total Range (all and sequence) and
  +     *       Effective Total Range (choice)
  +     * The following methods are used to return min/max range for a particle.
  +     * They are not exactly the same as it's described in the spec, but all the
  +     * values from the spec are retrievable by these methods.
  +     */
  +    public int minEffectiveTotalRange() {
  +        switch (fType) {
  +        case PARTICLE_EMPTY:
  +            return 0;
  +        case PARTICLE_ALL:
  +        case PARTICLE_SEQUENCE:
  +            return minEffectiveTotalRangeAllSeq();
  +        case PARTICLE_CHOICE:
  +            return minEffectiveTotalRangeChoice();
  +        default:
  +            return fMinOccurs;
  +        }
  +    }
   
  +    private int minEffectiveTotalRangeAllSeq() {
  +        int fromLeft = ((XSParticleDecl)fValue).minEffectiveTotalRange();
  +        if (fOtherValue != null)
  +            fromLeft += ((XSParticleDecl)fOtherValue).minEffectiveTotalRange();
  +        return fMinOccurs * fromLeft;
  +    }
  +
  +    private int minEffectiveTotalRangeChoice() {
  +        int fromLeft = ((XSParticleDecl)fValue).minEffectiveTotalRange();
  +        if (fOtherValue != null) {
  +            int fromRight = ((XSParticleDecl)fOtherValue).minEffectiveTotalRange();
  +            if (fromRight < fromLeft)
  +                fromLeft = fromRight;
  +        }
  +        return fMinOccurs * fromLeft;
  +    }
  +
  +    public int maxEffectiveTotalRange() {
  +        switch (fType) {
  +        case PARTICLE_EMPTY:
  +            return 0;
  +        case PARTICLE_ALL:
  +        case PARTICLE_SEQUENCE:
  +            return maxEffectiveTotalRangeAllSeq();
  +        case PARTICLE_CHOICE:
  +            return maxEffectiveTotalRangeChoice();
  +        default:
  +            return fMaxOccurs;
  +        }
  +    }
  +
  +    private int maxEffectiveTotalRangeAllSeq() {
  +        int fromLeft = ((XSParticleDecl)fValue).maxEffectiveTotalRange();
  +        if (fromLeft == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +            return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +        if (fOtherValue != null) {
  +            int fromRight = ((XSParticleDecl)fValue).maxEffectiveTotalRange();
  +            if (fromRight == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +                return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +            fromLeft += fromRight;
  +        }
  +
  +        if (fromLeft != 0 && fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +            return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +
  +        return fMaxOccurs * fromLeft;
  +    }
  +
  +    private int maxEffectiveTotalRangeChoice() {
  +        int fromLeft = ((XSParticleDecl)fValue).maxEffectiveTotalRange();
  +        if (fromLeft == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +            return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +        if (fOtherValue != null) {
  +            int fromRight = ((XSParticleDecl)fValue).maxEffectiveTotalRange();
  +            if (fromRight == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +                return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +            if (fromRight < fromLeft)
  +                fromLeft = fromRight;
  +        }
  +
  +        if (fromLeft != 0 && fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  +            return SchemaSymbols.OCCURRENCE_UNBOUNDED;
  +
  +        return fMaxOccurs * fromLeft;
  +    }
  +
  +    /**
  +     * get the string description of this particle
  +     */
  +    private String fDescription = null;
       public String toString() {
  -        if (fBuffer == null) {
  -            fBuffer = new StringBuffer();
  -            appendParticle(fBuffer);
  +        if (fDescription == null) {
  +            StringBuffer buffer = new StringBuffer();
  +            appendParticle(buffer);
               // REVISIT: what would be the best form?
  -            // 1. do we output "element[1-1]" or just "element"?
  -            // 2. do we output "element[3-3]" or "elment[3]"?
  -            // 3. how to output "unbounded"?
  +            // how to output "unbounded"?
               if (!(fMinOccurs == 0 && fMaxOccurs == 0 ||
                     fMinOccurs == 1 && fMaxOccurs == 1)) {
  -                fBuffer.append("[" + fMinOccurs);
  +                buffer.append("[" + fMinOccurs);
                   if (fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)
  -                    fBuffer.append("-UNBOUNDED");
  +                    buffer.append("-UNBOUNDED");
                   else if (fMinOccurs != fMaxOccurs)
  -                    fBuffer.append("-" + fMaxOccurs);
  -                fBuffer.append("]");
  +                    buffer.append("-" + fMaxOccurs);
  +                buffer.append("]");
               }
  +            fDescription = buffer.toString();
           }
  -        return fBuffer.toString();
  -    }
  -
  -    public boolean emptiable() {
  -        return false;
  +        return fDescription;
       }
   
  +    /**
  +     * append the string description of this particle to the string buffer
  +     * this is for error message.
  +     */
       void appendParticle(StringBuffer fBuffer) {
           switch (fType) {
           case PARTICLE_EMPTY:
  
  
  
  1.17      +8 -2      xml-xerces/java/src/org/apache/xerces/impl/v2/XSElementDecl.java
  
  Index: XSElementDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSElementDecl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XSElementDecl.java	2001/10/17 23:07:14	1.16
  +++ XSElementDecl.java	2001/10/18 19:03:05	1.17
  @@ -65,7 +65,7 @@
    *
    * @author Elena Litani, IBM
    * @author Sandy Gao, IBM
  - * @version $Id: XSElementDecl.java,v 1.16 2001/10/17 23:07:14 sandygao Exp $
  + * @version $Id: XSElementDecl.java,v 1.17 2001/10/18 19:03:05 sandygao Exp $
    */
   public class XSElementDecl {
   
  @@ -141,7 +141,13 @@
           return newArray;
       }
   
  +    /**
  +     * get the string description of this element
  +     */
  +    private String fDescription = null;
       public String toString() {
  -        return fTargetNamespace+":"+fName;
  +        if (fDescription == null)
  +            fDescription = fTargetNamespace+":"+fName;
  +        return fDescription;
       }
   } // class XMLElementDecl
  
  
  

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