You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/06/16 20:14:00 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/common DFAContentModel.java Grammar.java MixedContentModel.java

andyc       00/06/16 11:13:56

  Modified:    java/src/org/apache/xerces/framework XMLContentSpec.java
               java/src/org/apache/xerces/validators/common
                        DFAContentModel.java Grammar.java
                        MixedContentModel.java
  Log:
  1) Fixed minor bug in DFAContentModel for ANY.
  2) Added support for ANY in mixed content models for Schema.
  3) Updated XMLContentSpec#toString to produce "meaningful" output
     when a content model validation error occurs.
  
  Revision  Changes    Path
  1.6       +41 -6     xml-xerces/java/src/org/apache/xerces/framework/XMLContentSpec.java
  
  Index: XMLContentSpec.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/framework/XMLContentSpec.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLContentSpec.java	2000/06/15 22:04:13	1.5
  +++ XMLContentSpec.java	2000/06/16 18:13:04	1.6
  @@ -109,7 +109,7 @@
    * string pool index, as the "#PCDATA" leaf is not used in the declarations
    * for element content models.
    *
  - * @version $Id: XMLContentSpec.java,v 1.5 2000/06/15 22:04:13 andyc Exp $
  + * @version $Id: XMLContentSpec.java,v 1.6 2000/06/16 18:13:04 andyc Exp $
    */
   public class XMLContentSpec {
   
  @@ -286,6 +286,9 @@
                       else if (contentSpec.otherValue != -1) {
                           str.append("##any:uri="+stringPool.toString(contentSpec.otherValue));
                       }
  +                    else if (contentSpec.value == -1) {
  +                        str.append("##any");
  +                    }
                       else {
                           str.append(stringPool.toString(contentSpec.value));
                       }
  @@ -315,6 +318,9 @@
                           else if (contentSpec.otherValue != -1) {
                               str.append("##any:uri="+stringPool.toString(contentSpec.otherValue));
                           }
  +                        else if (contentSpec.value == -1) {
  +                            str.append("##any");
  +                        }
                           else {
                               str.append(stringPool.toString(contentSpec.value));
                           }
  @@ -336,6 +342,9 @@
                           else if (contentSpec.otherValue != -1) {
                               str.append("##any:uri="+stringPool.toString(contentSpec.otherValue));
                           }
  +                        else if (contentSpec.value == -1) {
  +                            str.append("##any");
  +                        }
                           else {
                               str.append(stringPool.toString(contentSpec.value));
                           }
  @@ -353,10 +362,12 @@
                                         contentSpec, str, true);
                       break;
                   }
  -                // REVISIT
                   case XMLContentSpec.CONTENTSPECNODE_ANY: {
  -                    str.append("##any:uri=");
  -                    str.append(stringPool.toString(contentSpec.otherValue));
  +                    str.append("##any");
  +                    if (contentSpec.otherValue != -1) {
  +                        str.append(":uri=");
  +                        str.append(stringPool.toString(contentSpec.otherValue));
  +                    }
                       break;
                   }
                   case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: {
  @@ -369,7 +380,7 @@
                       break;
                   }
                   default: {
  -                    return null;
  +                    str.append("???");
                   }
   
               } // switch type
  @@ -426,9 +437,12 @@
                   if (contentSpec.value == -1 && contentSpec.otherValue == -1) {
                       str.append("#PCDATA");
                   }
  -                else if (contentSpec.otherValue != -1) {
  +                else if (contentSpec.value == -1 && contentSpec.otherValue != -1) {
                       str.append("##any:uri="+stringPool.toString(contentSpec.otherValue));
                   }
  +                else if (contentSpec.value == -1) {
  +                    str.append("##any");
  +                }
                   else {
                       str.append(stringPool.toString(contentSpec.value));
                   }
  @@ -484,6 +498,27 @@
                   if (parens) {
                       str.append(')');
                   }
  +                break;
  +            }
  +            case XMLContentSpec.CONTENTSPECNODE_ANY: {
  +                str.append("##any");
  +                if (contentSpec.otherValue != -1) {
  +                    str.append(":uri=");
  +                    str.append(stringPool.toString(contentSpec.otherValue));
  +                }
  +                break;
  +            }
  +            case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: {
  +                str.append("##other:uri=");
  +                str.append(stringPool.toString(contentSpec.otherValue));
  +                break;
  +            }
  +            case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: {
  +                str.append("##local");
  +                break;
  +            }
  +            default: {
  +                str.append("???");
                   break;
               }
   
  
  
  
  1.7       +2 -2      xml-xerces/java/src/org/apache/xerces/validators/common/DFAContentModel.java
  
  Index: DFAContentModel.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/DFAContentModel.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DFAContentModel.java	2000/06/16 16:54:44	1.6
  +++ DFAContentModel.java	2000/06/16 18:13:31	1.7
  @@ -74,7 +74,7 @@
    * are very constrained in form and easily handled via a special case. 
    * This also makes implementation of this class much easier.
    *
  - * @version $Id: DFAContentModel.java,v 1.6 2000/06/16 16:54:44 andyc Exp $
  + * @version $Id: DFAContentModel.java,v 1.7 2000/06/16 18:13:31 andyc Exp $
    */
   public class DFAContentModel 
       implements XMLContentModel {
  @@ -366,7 +366,7 @@
                       }
                   }
                   else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
  -                    if (fElemMap[elemIndex].uri == -1) {
  +                    if (curElem.uri == -1) {
                           break;
                       }
                   }
  
  
  
  1.6       +55 -25    xml-xerces/java/src/org/apache/xerces/validators/common/Grammar.java
  
  Index: Grammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/Grammar.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Grammar.java	2000/06/15 23:45:16	1.5
  +++ Grammar.java	2000/06/16 18:13:34	1.6
  @@ -69,7 +69,7 @@
   
   
   /**
  - * @version $Id: Grammar.java,v 1.5 2000/06/15 23:45:16 andyc Exp $
  + * @version $Id: Grammar.java,v 1.6 2000/06/16 18:13:34 andyc Exp $
    */
   public class Grammar
   implements XMLContentSpec.Provider {
  @@ -245,12 +245,11 @@
   
               Vector vQName = new Vector(); 
               try {
  -                contentSpecTree( contentSpecIndex, vQName, contentSpec ); //traverse content spec and build QName vector
  -
  -                QName[] childList            = new QName[ vQName.size()];
  -                vQName.copyInto( childList );
  -                vQName = null;
  -                contentModel = new MixedContentModel(childList.length, childList);
  +                ChildrenList children = new ChildrenList();
  +                contentSpecTree(contentSpecIndex, contentSpec, children);
  +                contentModel = new MixedContentModel(children.qname,
  +                                                     children.type,
  +                                                     0, children.length);
               }catch(  CMException ex ){
                   ex.printStackTrace();
               }
  @@ -707,9 +706,6 @@
           return nodeRet;
       }
   
  -
  -
  -
       /**
        * Build a vector of valid QNames from Content Spec
        * table.
  @@ -720,14 +716,31 @@
        *               Array of QName
        * @exception CMException
        */
  -
  -    private void contentSpecTree( int contentSpecIndex, Vector vectorQName,
  -                                  XMLContentSpec contentSpec ) throws CMException {
  +    private void contentSpecTree(int contentSpecIndex, 
  +                                XMLContentSpec contentSpec,
  +                                ChildrenList children) throws CMException {
   
  +        // Handle any and leaf nodes
           getContentSpec( contentSpecIndex, contentSpec);
  +        if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ANY ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
  +
  +            // resize arrays, if needed
  +            if (children.length == children.qname.length) {
  +                QName[] newQName = new QName[children.length * 2];
  +                System.arraycopy(children.qname, 0, newQName, 0, children.length);
  +                children.qname = newQName;
  +                int[] newType = new int[children.length * 2];
  +                System.arraycopy(children.type, 0, newType, 0, children.length);
  +                children.type = newType;
  +            }
   
  -        if ( contentSpec.type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
  -            vectorQName.addElement( new QName( -1, contentSpec.value, -1, contentSpec.otherValue ) );
  +            // save values and return length
  +            children.qname[children.length] = new QName(-1, contentSpec.value, -1, contentSpec.otherValue);
  +            children.type[children.length] = contentSpec.type;
  +            children.length++;
               return;
           }
   
  @@ -738,17 +751,22 @@
           final int leftNode  = contentSpec.value;
           final int rightNode = contentSpec.otherValue;
   
  -        if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE) ||
  -            (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ)) {
  -            contentSpecTree(leftNode, vectorQName, contentSpec); // recurse to left
  -            contentSpecTree(rightNode, vectorQName, contentSpec);// recurse to right
  -        } else if ((contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE)
  -                   ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE)
  -                   ||  (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE)) {
  -            contentSpecTree(leftNode, vectorQName, contentSpec);//only recurse to left on this node 
  -        } else {
  -            throw new CMException(ImplementationMessages.VAL_CST);
  +        if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_CHOICE ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_SEQ) {
  +            contentSpecTree(leftNode, contentSpec, children);
  +            contentSpecTree(rightNode, contentSpec, children);
  +            return;
  +        } 
  +
  +        if (contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE ||
  +            contentSpec.type == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE) {
  +            contentSpecTree(leftNode, contentSpec, children);
  +            return;
           }
  +
  +        // error
  +        throw new CMException(ImplementationMessages.VAL_CST);
       }
   
   
  @@ -851,5 +869,17 @@
           return newarray;
       }
   
  +    //
  +    // Classes
  +    //
  +
  +    /**
  +     * Children list for <code>contentSpecTree</code> method.
  +     */
  +    static class ChildrenList {
  +        public int length = 0;
  +        public QName[] qname = new QName[2];
  +        public int[] type = new int[2];
  +    }
   
   } // class Grammar
  
  
  
  1.4       +65 -12    xml-xerces/java/src/org/apache/xerces/validators/common/MixedContentModel.java
  
  Index: MixedContentModel.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/MixedContentModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MixedContentModel.java	2000/05/19 02:27:20	1.3
  +++ MixedContentModel.java	2000/06/16 18:13:34	1.4
  @@ -57,6 +57,7 @@
   
   package org.apache.xerces.validators.common;
   
  +import org.apache.xerces.framework.XMLContentSpec;
   import org.apache.xerces.utils.QName;
   
   /**
  @@ -72,7 +73,7 @@
    * validate by just looking up each child being validated by looking it up
    * in the list.
    *
  - * @version $Id: MixedContentModel.java,v 1.3 2000/05/19 02:27:20 andyc Exp $
  + * @version $Id: MixedContentModel.java,v 1.4 2000/06/16 18:13:34 andyc Exp $
    */
   public class MixedContentModel 
       implements XMLContentModel {
  @@ -88,6 +89,9 @@
       /** The list of possible children that we have to accept. */
       private QName fChildren[];
   
  +    /** The type of the children to support ANY. */
  +    private int fChildrenType[];
  +
       /** 
        * True if mixed content model is ordered. DTD mixed content models
        * are <em>always</em> unordered.
  @@ -106,8 +110,10 @@
        *
        * @exception CMException Thrown if content model can't be built.
        */
  -    public MixedContentModel(int count, QName childList[]) throws CMException {
  -        this(count, childList, false);
  +    public MixedContentModel(QName childList[],
  +                             int childListType[],
  +                             int offset, int length) throws CMException {
  +        this(childList, childListType, offset, length, false);
       }
   
       /**
  @@ -119,15 +125,20 @@
        *
        * @exception CMException Thrown if content model can't be built.
        */
  -    public MixedContentModel(int count, QName childList[],
  +    public MixedContentModel(QName childList[],
  +                             int childListType[],
  +                             int offset, int length,
                                boolean ordered) throws CMException {
   
           // Make our own copy now, which is exactly the right size
  -        fCount = count;
  +        fCount = length;
           fChildren = new QName[fCount];
  +        fChildrenType = new int[fCount];
           for (int i = 0; i < fCount; i++) {
  -            fChildren[i] = new QName(childList[i]);
  +            fChildren[i] = new QName(childList[offset + i]);
  +            fChildrenType[i] = childListType[offset + i];
           }
  +        fOrdered = ordered;
   
       } // <init>(int,QName[],boolean)
   
  @@ -174,9 +185,28 @@
                   }
   
                   // element must match
  -                if (fChildren[inIndex].uri != children[offset + outIndex].uri &&
  -                    fChildren[inIndex].localpart != children[offset + outIndex].localpart) {
  -                    return outIndex;
  +                int type = fChildrenType[inIndex];
  +                if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
  +                    if (fChildren[inIndex].uri != children[offset + outIndex].uri &&
  +                        fChildren[inIndex].localpart != children[offset + outIndex].localpart) {
  +                        return outIndex;
  +                    }
  +                }
  +                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
  +                    int uri = fChildren[inIndex].uri;
  +                    if (uri != -1 && uri != children[outIndex].uri) {
  +                        return outIndex;
  +                    }
  +                }
  +                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
  +                    if (children[outIndex].uri != -1) {
  +                        return outIndex;
  +                    }
  +                }
  +                else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
  +                    if (fChildren[inIndex].uri == children[outIndex].uri) {
  +                        return outIndex;
  +                    }
                   }
                   
                   // advance index
  @@ -199,9 +229,32 @@
                   int inIndex = 0;
                   for (; inIndex < fCount; inIndex++)
                   {
  -                    if (curChild.uri == fChildren[inIndex].uri &&
  -                        curChild.localpart == fChildren[inIndex].localpart)
  -                        break;
  +                    int type = fChildrenType[inIndex];
  +                    if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
  +                        if (curChild.uri == fChildren[inIndex].uri &&
  +                            curChild.localpart == fChildren[inIndex].localpart)
  +                            break;
  +                    }
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY) {
  +                        int uri = fChildren[inIndex].uri;
  +                        if (uri == -1 || uri == children[outIndex].uri) {
  +                            break;
  +                        }
  +                    }
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL) {
  +                        if (children[outIndex].uri == -1) {
  +                            break;
  +                        }
  +                    }
  +                    else if (type == XMLContentSpec.CONTENTSPECNODE_ANY_OTHER) {
  +                        if (fChildren[inIndex].uri != children[outIndex].uri) {
  +                            break;
  +                        }
  +                    }
  +                    // REVISIT: What about checking for multiple ANY matches?
  +                    //          The content model ambiguity *could* be checked
  +                    //          by the caller before constructing the mixed
  +                    //          content model.
                   }
   
                   // We did not find this one, so the validation failed