You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by er...@locus.apache.org on 2000/11/03 23:59:55 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/validation/grammars DTDGrammar.java SchemaGrammar.java

ericye      00/11/03 14:59:55

  Modified:    java/src/org/apache/xerces/impl/validation Tag: xerces_j_2
                        Grammar.java
               java/src/org/apache/xerces/impl/validation/grammars Tag:
                        xerces_j_2 DTDGrammar.java SchemaGrammar.java
  Log:
  1. fix bugs in setting the default value for attributes
  
  2. more implementation for SchemaGrammar
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.22  +4 -14     xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/Grammar.java
  
  Index: Grammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/Grammar.java,v
  retrieving revision 1.1.2.21
  retrieving revision 1.1.2.22
  diff -u -r1.1.2.21 -r1.1.2.22
  --- Grammar.java	2000/11/01 02:25:10	1.1.2.21
  +++ Grammar.java	2000/11/03 22:59:51	1.1.2.22
  @@ -80,7 +80,7 @@
    * @author Jeffrey Rodriguez, ibm
    * @author Eric Ye, ibm
    *
  - * @version $Id: Grammar.java,v 1.1.2.21 2000/11/01 02:25:10 ericye Exp $
  + * @version $Id: Grammar.java,v 1.1.2.22 2000/11/03 22:59:51 ericye Exp $
    */
   public class Grammar {
   
  @@ -911,19 +911,9 @@
         fElementDeclType[chunk][index]                  = elementDecl.type; 
         fElementDeclDatatypeValidator[chunk][index]     =
                           elementDecl.simpleType.datatypeValidator;
  -     /*
  +      fElementDeclDefaultType[chunk][index] = elementDecl.simpleType.defaultType;
  +      fElementDeclDefaultValue[chunk][index] = elementDecl.simpleType.defaultValue;
   
  -      if( elementDecl.type == XMLElementDecl.TYPE_ANY ){
  -         elementDecl.contentModelValidator = 
  -
  -      } else if( elementDecl.type == XMLElementDecl.TYPE_CHILDREN ){
  -
  -      } else if( elementDecl.type == XMLElementDecl.TYPE_EMPTY ){
  -      } else if( elementDecl.type == XMLElementDecl.TYPE_MIXED ){
  -      } else if( elementDecl.type == XMLElementDecl.TYPE_SIMPLE ){
  -      }
  -      */
  -
         fElementDeclContentModelValidator[chunk][index] = elementDecl.contentModelValidator;
            
   
  @@ -1002,7 +992,7 @@
         fAttributeDeclDefaultType[attrChunk][attrIndex]  =  attributeDecl.simpleType.defaultType;
         fAttributeDeclDatatypeValidator[attrChunk][attrIndex] =  attributeDecl.simpleType.datatypeValidator;
   
  -      fAttributeDeclDefaultValue[attrChunk][attrIndex] = new String( attributeDecl.simpleType.defaultValue );
  +      fAttributeDeclDefaultValue[attrChunk][attrIndex] = attributeDecl.simpleType.defaultValue;
   
         int elemChunk     = elementDeclIndex >> CHUNK_SHIFT;
         int elemIndex     = elementDeclIndex &  CHUNK_MASK;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.27  +3 -4      xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/DTDGrammar.java
  
  Index: DTDGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/DTDGrammar.java,v
  retrieving revision 1.1.2.26
  retrieving revision 1.1.2.27
  diff -u -r1.1.2.26 -r1.1.2.27
  --- DTDGrammar.java	2000/11/02 02:38:21	1.1.2.26
  +++ DTDGrammar.java	2000/11/03 22:59:53	1.1.2.27
  @@ -82,7 +82,7 @@
    * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
    * @author Jeffrey Rodriguez, IBM
    *
  - * @version $Id: DTDGrammar.java,v 1.1.2.26 2000/11/02 02:38:21 ericye Exp $
  + * @version $Id: DTDGrammar.java,v 1.1.2.27 2000/11/03 22:59:53 ericye Exp $
    */
   public class DTDGrammar
   extends Grammar
  @@ -444,8 +444,7 @@
       *
       * @throws SAXException Thrown by handler to signal an error.
       */
  -   public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue)
  -   throws SAXException {
  +   public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue) throws SAXException {
   
         if ( this.fElementDeclTab.containsKey( (String) elementName) ) {
            //if ElementDecl has already being created in the Grammar then remove from table, 
  @@ -485,7 +484,7 @@
         if ( DEBUG == true ) {
             System.out.println("defaultvalue = " + defaultValue.toString() );
         }
  -      fSimpleType.defaultValue      = defaultValue.toString();
  +      fSimpleType.defaultValue      = defaultValue.length > 0 ?  defaultValue.toString() : null;
         fSimpleType.enumeration       = enumeration;
         fSimpleType.datatypeValidator = DatatypeValidatorFactoryImpl.getDatatypeRegistry().getDatatypeValidator(type);
   
  
  
  
  1.1.2.4   +330 -5    xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/SchemaGrammar.java
  
  Index: SchemaGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/grammars/Attic/SchemaGrammar.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- SchemaGrammar.java	2000/11/03 02:17:28	1.1.2.3
  +++ SchemaGrammar.java	2000/11/03 22:59:54	1.1.2.4
  @@ -76,9 +76,13 @@
   import java.util.Hashtable;
   
   /**
  + *  SchemaGrammar holds all the extra information needed for schema validation
  + *  on top of the basic information in the Grammar. 
  + *
    * @author ericye, IBM
    * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
  - * @version $Id: SchemaGrammar.java,v 1.1.2.3 2000/11/03 02:17:28 ericye Exp $
  + * @version $Id: SchemaGrammar.java,v 1.1.2.4 2000/11/03 22:59:54 ericye Exp $
  + *
    */
   public class SchemaGrammar
       extends Grammar {
  @@ -113,7 +117,7 @@
           //new TraverseSchema.ComplexTypeInfo[INITIAL_CHUNK_COUNT][];
       private int fElementDeclDefaultType[][] = new int[INITIAL_CHUNK_COUNT][];
       private String fElementDeclDefaultValue[][] = new String[INITIAL_CHUNK_COUNT][];
  -    private String fElementDeclEquivClassFullName[][] = new String[INITIAL_CHUNK_COUNT][];
  +    private String fElementDeclSubstituteGrpFullName[][] = new String[INITIAL_CHUNK_COUNT][];
       private int fElementDeclBlockSet[][] = new int[INITIAL_CHUNK_COUNT][];
       private int fElementDeclFinalSet[][] = new int[INITIAL_CHUNK_COUNT][];
       private int fElementDeclMiscFlags[][] = new int[INITIAL_CHUNK_COUNT][];
  @@ -128,7 +132,7 @@
       Hashtable topLevelAttrDecls  = new Hashtable();
       Hashtable topLevelAttrGrpDecls = new Hashtable();
   
  -    private NamespaceSupport fNamespacesMaps = null;
  +    private NamespaceSupport fNamespacesMap = null;
       private String fTargetNamespaceURI = "";
   
       //
  @@ -159,6 +163,327 @@
       }
   
       //
  +    // Public methods
  +    //
  +
  +    public NamespaceSupport getNamespacesScope(){
  +        return fNamespacesMap;
  +    }
  +
  +    public String getTargetNamespaceURI(){
  +        return fTargetNamespaceURI;
  +    }
  +
  +    public Hashtable getAttirubteDeclRegistry() {
  +        return fAttributeDeclRegistry;
  +    }
  +
  +    public Hashtable getComplexTypeRegistry(){
  +        return fComplexTypeRegistry;
  +    }
  +
  +    public DatatypeValidatorFactoryImpl getDatatypeRegistry(){
  +        return fDatatypeRegistry;
  +    }
  +
  +    public int getElementDefinedScope(int elementDeclIndex) {
  +        
  +        if (elementDeclIndex < -1) {
  +            return -1;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fScopeDefinedByElement[chunk][index];
  +
  +    }
  +    
  +    public int getAttributeDeclIndex(int elementIndex, QName attribute) {
  +        if (elementIndex == -1) {
  +            return -1;
  +        }
  +        int attDefIndex = getFirstAttributeDeclIndex(elementIndex);
  +        while (attDefIndex != -1) {
  +            getAttributeDecl(attDefIndex, fTempAttributeDecl);
  +
  +            if (fTempAttributeDecl.name.localpart == attribute.localpart &&
  +                fTempAttributeDecl.name.uri == attribute.uri ) {
  +                return attDefIndex;
  +            }
  +            attDefIndex = getNextAttributeDeclIndex(attDefIndex);
  +        }
  +        return -1;
  +    } // getAttributeDeclIndex (int,QName)
  +    
  +    public int getElementDefaultTYpe(int elementDeclIndex) {
  +        
  +        if (elementDeclIndex < -1) {
  +            return -1;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclDefaultType[chunk][index];
  +
  +    }
  +
  +    public int getElementDeclBlockSet(int elementDeclIndex) {
  +
  +        if (elementDeclIndex < -1) {
  +            return -1;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclBlockSet[chunk][index];
  +    }
  +
  +    public int getElementDeclFinalSet(int elementDeclIndex) {
  +
  +        if (elementDeclIndex < -1) {
  +            return -1;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclFinalSet[chunk][index];
  +    }
  +
  +    public int getElementDeclMiscFlags(int elementDeclIndex) {
  +
  +        if (elementDeclIndex < -1) {
  +            return -1;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclMiscFlags[chunk][index];
  +    }
  +
  +    public String getElementFromAnotherSchemaURI(int elementDeclIndex) {
  +        
  +        if (elementDeclIndex < 0 ) {
  +            return null;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fFromAnotherSchemaURI[chunk][index];
  +
  +    }
  +
  +    public String getElementDefaultValue(int elementDeclIndex) {
  +        
  +        if (elementDeclIndex < 0 ) {
  +            return null;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclDefaultValue[chunk][index];
  +
  +    }
  +    public String getElementDeclSubstituteGrpElementFullName( int elementDeclIndex){
  +        
  +        if (elementDeclIndex < 0 ) {
  +            return null;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclSubstituteGrpFullName[chunk][index];
  +
  +    }
  +
  +    /****
  +
  +    public TraverseSchema.ComplexTypeInfo getElementComplexTypeInfo(int elementDeclIndex){
  +
  +        if (elementDeclIndex <- 1) {
  +            return null;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fComplexTypeInfo[chunk][index];
  +    }
  +    /****/
  +
  +
  +    public boolean isDTD() {
  +        return false;
  +    }
  +
  +    //
  +    // Protected methods
  +    //
  +    protected void  setAttributeDeclRegistry(Hashtable attrReg){
  +        fAttributeDeclRegistry = attrReg;
  +    }
  +
  +    protected void  setComplexTypeRegistry(Hashtable cTypeReg){
  +        fComplexTypeRegistry = cTypeReg;
  +    }
  +
  +    protected void setDatatypeRegistry(DatatypeValidatorFactoryImpl dTypeReg){
  +        fDatatypeRegistry = dTypeReg;
  +    }
  +
  +    protected void setNamespacesScope(NamespaceSupport nsSupport) {
  +        fNamespacesMap = nsSupport;
  +    }
  +
  +    protected void setTargetNamespaceURI(String targetNSUri) {
  +        fTargetNamespaceURI = targetNSUri;
  +    }
  +
  +    protected void setElementDefinedScope(int elementDeclIndex, int scopeDefined) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fScopeDefinedByElement[chunk][index] = scopeDefined;
  +        }
  +    }
  +
  +    protected  void setElementFromAnotherSchemaURI(int elementDeclIndex, String anotherSchemaURI) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fFromAnotherSchemaURI[chunk][index] = anotherSchemaURI;
  +        }
  +    }
  +
  +    /****
  +    protected void setElementComplexTypeInfo(int elementDeclIndex, TraverseSchema.ComplexTypeInfo typeInfo){
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fComplexTypeInfo[chunk][index] = typeInfo;
  +        }
  +    }
  +    /****/
  +
  +    protected void setElementDefault(int elementDeclIndex, int defaultType, String defaultValue) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclDefaultType[chunk][index] = defaultType;
  +            fElementDeclDefaultValue[chunk][index] = defaultValue;
  +        }
  +    }
  +    
  +    protected void setElementDeclBlockSet(int elementDeclIndex, int blockSet) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclBlockSet[chunk][index] = blockSet;
  +        }
  +    }
  +
  +    protected void setElementDeclFinalSet(int elementDeclIndex, int finalSet) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclFinalSet[chunk][index] = finalSet;
  +        }
  +    }
  +
  +    protected void setElementDeclMiscFlags(int elementDeclIndex, int miscFlags) {
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclMiscFlags[chunk][index] = miscFlags;
  +        }
  +    }
  +
  +    protected void setElementDeclSubstituteGrpElementFullName( int elementDeclIndex, String SubstituteGrpFullName){
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclSubstituteGrpFullName[chunk][index] = SubstituteGrpFullName;
  +        }
  +    }
  +
  +    //add methods for TraverseSchema
  +    /**
  +     *@return elementDecl Index, 
  +     */
  +
  +    protected int addElementDecl(QName eltQName, int enclosingScope, int scopeDefined, 
  +                                 int contentSpecType, int contentSpecIndex, 
  +                                 int attrListHead, DatatypeValidator dv, short defaultType, String defaultValue){
  +        int elementDeclIndex = getElementDeclIndex(eltQName, enclosingScope);
  +        if (elementDeclIndex == -1) {
  +            if (enclosingScope<-1 || scopeDefined < -1 ) {
  +                //TO DO: report error here;
  +            }
  +            fTempElementDecl.name.setValues(eltQName);
  +            fTempElementDecl.scope = enclosingScope;
  +            fTempElementDecl.type = (short)contentSpecType;
  +            fTempElementDecl.simpleType.datatypeValidator = dv;
  +            fTempElementDecl.simpleType.defaultType = defaultType;
  +            fTempElementDecl.simpleType.defaultValue = defaultValue;
  +            elementDeclIndex = createElementDecl();
  +            setElementDecl(elementDeclIndex,fTempElementDecl);
  +            setContentSpecIndex(elementDeclIndex, contentSpecIndex);
  +            setFirstAttributeDeclIndex(elementDeclIndex, attrListHead);
  +            //note, this is the scope defined by the element, not its enclosing scope
  +            setElementDefinedScope(elementDeclIndex, scopeDefined);
  +        }
  +
  +        return elementDeclIndex;
  +
  +    }
  +
  +    /**
  +     *@return the new attribute List Head
  +     */
  +    protected void addAttDef(  int templateElementIndex, 
  +                      QName attQName, int attType, 
  +                      String[] enumeration, int attDefaultType, 
  +                      String attDefaultValue, DatatypeValidator dv, boolean isList){
  +        int attrDeclIndex = createAttributeDecl();
  +        fTempAttributeDecl.name.setValues(attQName);
  +        fTempAttributeDecl.simpleType.datatypeValidator = dv;
  +        fTempAttributeDecl.simpleType.type = (short)attType;
  +        fTempAttributeDecl.simpleType.defaultType = (short)attDefaultType;
  +        fTempAttributeDecl.simpleType.defaultValue = attDefaultValue;
  +        fTempAttributeDecl.simpleType.list = isList;
  +        fTempAttributeDecl.simpleType.enumeration = enumeration;
  +
  +        super.setAttributeDecl(templateElementIndex, attrDeclIndex, fTempAttributeDecl);
  +    }
  +
  +
  +    /**
  +     * use this method for none Leaf type node
  +     *@return the new contentSpec Index
  +     */
  +    protected int addContentSpecNode(short contentSpecType, int value, int otherValue) {
  +        fTempContentSpecNode.type = contentSpecType;
  +        fTempContentSpecNode.value = new int[]{value};
  +        fTempContentSpecNode.otherValue = new int[]{otherValue};
  +        
  +        int contentSpecIndex = createContentSpec();
  +        setContentSpec(contentSpecIndex, fTempContentSpecNode);
  +        return contentSpecIndex;
  +    }
  +    
  +
  +    /**
  +     * use this method for Leaf type node
  +     *@return the new contentSpec Index
  +     */
  +    protected int addContentSpecLeafNode(short contentSpecType, String value, String otherValue) {
  +        fTempContentSpecNode.type = contentSpecType;
  +        fTempContentSpecNode.value = value;
  +        fTempContentSpecNode.otherValue = otherValue;
  +        
  +        int contentSpecIndex = createContentSpec();
  +        setContentSpec(contentSpecIndex, fTempContentSpecNode);
  +        return contentSpecIndex;
  +    }
  +
  +    //
       // Private methods
       //
   
  @@ -177,7 +502,7 @@
                fElementDeclBlockSet = resize(fElementDeclBlockSet,fElementDeclBlockSet.length*2);
                fElementDeclFinalSet = resize(fElementDeclFinalSet,fElementDeclFinalSet.length*2);
                fElementDeclMiscFlags = resize(fElementDeclMiscFlags,fElementDeclMiscFlags.length*2);
  -             fElementDeclEquivClassFullName = resize(fElementDeclEquivClassFullName,fElementDeclEquivClassFullName.length*2);
  +             fElementDeclSubstituteGrpFullName = resize(fElementDeclSubstituteGrpFullName,fElementDeclSubstituteGrpFullName.length*2);
           }
           catch (NullPointerException ex) {
               // ignore
  @@ -190,7 +515,7 @@
           //fComplexTypeInfo[chunk] = new TraverseSchema.ComplexTypeInfo[CHUNK_SIZE];
           fElementDeclDefaultType[chunk] = new int[CHUNK_SIZE];
           fElementDeclDefaultValue[chunk] = new String[CHUNK_SIZE];
  -        fElementDeclEquivClassFullName[chunk] = new String[CHUNK_SIZE];
  +        fElementDeclSubstituteGrpFullName[chunk] = new String[CHUNK_SIZE];
           fElementDeclBlockSet[chunk] = new int[CHUNK_SIZE]; // initialized to 0
           fElementDeclFinalSet[chunk] = new int[CHUNK_SIZE]; // initialized to 0
           fElementDeclMiscFlags[chunk] = new int[CHUNK_SIZE]; // initialized to 0