xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eri...@locus.apache.org
Subject cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema SchemaGrammar.java TraverseSchema.java
Date Thu, 13 Jul 2000 23:20:35 GMT
ericye      00/07/13 16:20:35

  Modified:    java/src/org/apache/xerces/validators/schema
                        SchemaGrammar.java TraverseSchema.java
  Log:
  1. clean up EquivClass processing.
  2. add equivClass dimension to SchemaGrammar element decl pool
  --ericye
  
  Revision  Changes    Path
  1.11      +28 -1     xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java
  
  Index: SchemaGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SchemaGrammar.java	2000/07/07 21:22:00	1.10
  +++ SchemaGrammar.java	2000/07/13 23:20:34	1.11
  @@ -55,8 +55,12 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  + 
    /*
  - * @version $Id: SchemaGrammar.java,v 1.10 2000/07/07 21:22:00 ericye Exp $
  + * @author Eric Ye
  + *         
  + * @see    
  + * @version $Id: SchemaGrammar.java,v 1.11 2000/07/13 23:20:34 ericye Exp $
    */
   package org.apache.xerces.validators.schema;
   
  @@ -109,6 +113,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 int fElementDeclBlockSet[][] = new int[INITIAL_CHUNK_COUNT][];
       private int fElementDeclFinalSet[][] = new int[INITIAL_CHUNK_COUNT][];
       private int fElementDeclMiscFlags[][] = new int[INITIAL_CHUNK_COUNT][];
  @@ -222,6 +227,17 @@
           return fElementDeclDefaultValue[chunk][index];
   
       }
  +    public String getElementDeclEquivClassElementFullName( int elementDeclIndex){
  +        
  +        if (elementDeclIndex < 0 ) {
  +            return null;
  +        }
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        return fElementDeclEquivClassFullName[chunk][index];
  +
  +    }
  +
       public TraverseSchema.ComplexTypeInfo getElementComplexTypeInfo(int elementDeclIndex){
   
           if (elementDeclIndex <- 1) {
  @@ -351,6 +367,15 @@
           }
       }
   
  +    protected void setElementDeclEquivClassElementFullName( int elementDeclIndex, String
equivClassFullName){
  +        int chunk = elementDeclIndex >> CHUNK_SHIFT;
  +        int index = elementDeclIndex & CHUNK_MASK;
  +        ensureElementDeclCapacity(chunk);
  +        if (elementDeclIndex > -1 ) {
  +            fElementDeclEquivClassFullName[chunk][index] = equivClassFullName;
  +        }
  +    }
  +
       //add methods for TraverseSchema
       /**
        *@return elementDecl Index, 
  @@ -460,6 +485,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);
           }
           catch (NullPointerException ex) {
               // ignore
  @@ -472,6 +498,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];
           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
  
  
  
  1.38      +139 -27   xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
  
  Index: TraverseSchema.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- TraverseSchema.java	2000/07/12 19:14:50	1.37
  +++ TraverseSchema.java	2000/07/13 23:20:34	1.38
  @@ -370,11 +370,11 @@
        * </period>
        * 
    * 
  - * @author Jeffrey Rodriguez
  - *         Eric Ye
  + * @author Eric Ye, Jeffrey Rodriguez, Andy Clark
  + *  
    * @see                  org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.37 2000/07/12 19:14:50 ericye Exp $
  + * @version $Id: TraverseSchema.java,v 1.38 2000/07/13 23:20:34 ericye Exp $
    */
   
   public class TraverseSchema implements 
  @@ -474,6 +474,7 @@
           if (uriStr == null) {
               // REVISIT: Localize
               reportGenericSchemaError("prefix : [" + prefix +"] can not be resolved to a
URI");
  +            return "";
           }
   
           //REVISIT, !!!! a hack: needs to be updated later, cause now we only use localpart
to key build-in datatype.
  @@ -2518,30 +2519,68 @@
               return eltName;
           }
                   
  +        // Handle the equivClass
           Element equivClassElementDecl = null;
           int equivClassElementDeclIndex = -1;
           boolean noErrorSoFar = true;
  +        String equivClassUri = null;
  +        String equivClassLocalpart = null;
  +        String equivClassFullName = null;
  +        ComplexTypeInfo equivClassEltTypeInfo = null;
  +        DatatypeValidator equivClassEltDV = null;
   
           if ( equivClass.length() > 0 ) {
  -            equivClassElementDecl = getTopLevelComponentByName(SchemaSymbols.ELT_ELEMENT,
getLocalPart(equivClass));
  -            if (equivClassElementDecl == null) {
  -                noErrorSoFar = false;
  -                // REVISIT: Localize
  -                reportGenericSchemaError("Equivclass affiliation element "
  -                                          +equivClass
  -                                          +" in element declaration " 
  -                                          +name);  
  +            equivClassUri =  resolvePrefixToURI(getPrefix(equivClass));
  +            equivClassLocalpart = getLocalPart(equivClass);
  +            equivClassFullName = equivClassUri+","+equivClassLocalpart;
  +           
  +            if ( !equivClassUri.equals(fTargetNSURIString) ) {  
  +                equivClassEltTypeInfo = getElementDeclTypeInfoFromNS(equivClassUri, equivClassLocalpart);
  +                if (equivClassEltTypeInfo == null) {
  +                    equivClassEltDV = getElementDeclTypeValidatorFromNS(equivClassUri,
equivClassLocalpart);
  +                    if (equivClassEltDV == null) {
  +                        //TO DO: report error here;
  +                        noErrorSoFar = false;
  +                        reportGenericSchemaError("Could not find type for element '" +equivClassLocalpart

  +                                                 + "' in schema '" + equivClassUri+"'");
  +                    }
  +                }
               }
               else {
  -                equivClassElementDeclIndex = 
  -                    fSchemaGrammar.getElementDeclIndex(fTargetNSURI, getLocalPartIndex(equivClass),TOP_LEVEL_SCOPE);
  -
  -                if ( equivClassElementDeclIndex == -1) {
  -                    traverseElementDecl(equivClassElementDecl);
  +                equivClassElementDecl = getTopLevelComponentByName(SchemaSymbols.ELT_ELEMENT,
equivClassLocalpart);
  +                if (equivClassElementDecl == null) {
  +                    noErrorSoFar = false;
  +                    // REVISIT: Localize
  +                    reportGenericSchemaError("Equivclass affiliation element "
  +                                              +equivClass
  +                                              +" in element declaration " 
  +                                              +name);  
  +                }
  +                else {
                       equivClassElementDeclIndex = 
                           fSchemaGrammar.getElementDeclIndex(fTargetNSURI, getLocalPartIndex(equivClass),TOP_LEVEL_SCOPE);
  +
  +                    if ( equivClassElementDeclIndex == -1) {
  +                        traverseElementDecl(equivClassElementDecl);
  +                        equivClassElementDeclIndex = 
  +                            fSchemaGrammar.getElementDeclIndex(fTargetNSURI, getLocalPartIndex(equivClass),TOP_LEVEL_SCOPE);
  +                    }
                   }
  +                if (equivClassElementDeclIndex != -1) {
  +                    equivClassEltTypeInfo = fSchemaGrammar.getElementComplexTypeInfo( equivClassElementDeclIndex
);
  +                    if (equivClassEltTypeInfo == null) {
  +                        fSchemaGrammar.getElementDecl(equivClassElementDeclIndex, fTempElementDecl);
  +                        equivClassEltDV = fTempElementDecl.datatypeValidator;
  +                        if (equivClassEltDV == null) {
  +                            //TO DO: report error here;
  +                            noErrorSoFar = false;
  +                            reportGenericSchemaError("Could not find type for element '"
+equivClassLocalpart 
  +                                                     + "' in schema '" + equivClassUri+"'");
  +                        }
  +                    }
  +                }
               }
  + 
           }
           
           //ComplexTypeInfo typeInfo = new ComplexTypeInfo();
  @@ -2555,6 +2594,7 @@
           
           boolean haveAnonType = false;
   
  +        // Handle Anonymous type if there is one
           if (child != null) {
               
               String childName = child.getNodeName();
  @@ -2608,6 +2648,7 @@
               }
           } 
   
  +        // handle type="" here
           if (haveAnonType && (type.length()>0)) {
               noErrorSoFar = false;
               // REVISIT: Localize
  @@ -2695,12 +2736,12 @@
               }
   
           }
  -        // this element is ur-type
  +        // this element is ur-type, check its equivClass afficliation.
           else {
  -            // if there is equivClass affiliation, then grab its type and stick it to this
element
  -            if (equivClassElementDeclIndex != -1) {
  -                ComplexTypeInfo equivClassEltType = fSchemaGrammar.getElementComplexTypeInfo(
equivClassElementDeclIndex );
  -            }
  +            // if there is equivClass affiliation and not type defintion found for this
element, 
  +            // then grab equivClass affiliation's type and give it to this element
  +            if ( typeInfo == null && dv == null ) typeInfo = equivClassEltTypeInfo;
  +            if ( typeInfo == null && dv == null ) dv = equivClassEltDV;
           }
   
           if (typeInfo == null && dv==null) {
  @@ -2806,6 +2847,9 @@
           fSchemaGrammar.setElementDeclFinalSet(elementIndex, finalSet);
           fSchemaGrammar.setElementDeclMiscFlags(elementIndex, elementMiscFlags);
   
  +        // setEquivClassElementFullName
  +        fSchemaGrammar.setElementDeclEquivClassElementFullName(elementIndex, equivClassFullName);
  +
           return eltQName;
   
       }// end of method traverseElementDecl(Element)
  @@ -2829,6 +2873,24 @@
           return localpart;
       }
       
  +    int getPrefixIndex(String fullName){
  +        int colonAt = fullName.indexOf(":"); 
  +        String prefix = "";
  +        if (  colonAt > -1 ) {
  +            prefix = fullName.substring(0,colonAt);
  +        }
  +        return fStringPool.addSymbol(prefix);
  +    }
  +
  +    String getPrefix(String fullName){
  +        int colonAt = fullName.indexOf(":"); 
  +        String prefix = "";
  +        if (  colonAt > -1 ) {
  +            prefix = fullName.substring(0,colonAt);
  +        }
  +        return prefix;
  +    }
  +    
       private void checkEquivClassOK(Element elementDecl, Element equivClassElementDecl){
           //TO DO!!
       }
  @@ -2865,7 +2927,7 @@
           return false;
       }
       
  -    DatatypeValidator getTypeValidatorFromNS(String newSchemaURI, String localpart){
  +    DatatypeValidator getTypeValidatorFromNS(String newSchemaURI, String localpart) throws
Exception {
           Grammar grammar = fGrammarResolver.getGrammar(newSchemaURI);
           if (grammar != null && grammar instanceof SchemaGrammar) {
               SchemaGrammar sGrammar = (SchemaGrammar) grammar;
  @@ -2873,13 +2935,12 @@
               return dv;
           }
           else {
  -            //TO DO: report internal erro here
  -            System.out.println("could not resolver URI : " + newSchemaURI + " to a SchemaGrammar
in getTypeValidatorFromNS");
  +            reportGenericSchemaError("could not resolve URI : " + newSchemaURI + " to a
SchemaGrammar in getTypeValidatorFromNS");
           }
           return null;
       }
   
  -    ComplexTypeInfo getTypeInfoFromNS(String newSchemaURI, String localpart){
  +    ComplexTypeInfo getTypeInfoFromNS(String newSchemaURI, String localpart) throws Exception
{
           Grammar grammar = fGrammarResolver.getGrammar(newSchemaURI);
           if (grammar != null && grammar instanceof SchemaGrammar) {
               SchemaGrammar sGrammar = (SchemaGrammar) grammar;
  @@ -2887,11 +2948,62 @@
               return typeInfo;
           }
           else {
  -            //TO DO: report internal erro here
  -            System.out.println("could not resolver URI : " + newSchemaURI + " to a SchemaGrammar
in getTypeInfoFromNS");
  +            reportGenericSchemaError("could not resolve URI : " + newSchemaURI + " to a
SchemaGrammar in getTypeInfoFromNS");
           }
           return null;
       }
  +    
  +    DatatypeValidator getElementDeclTypeValidatorFromNS(String newSchemaURI, String localpart)
throws Exception {
  +        Grammar grammar = fGrammarResolver.getGrammar(newSchemaURI);
  +        if (grammar != null && grammar instanceof SchemaGrammar) {
  +            SchemaGrammar sGrammar = (SchemaGrammar) grammar;
  +            int eltIndex = sGrammar.getElementDeclIndex(fStringPool.addSymbol(newSchemaURI),

  +                                                        fStringPool.addSymbol(localpart),

  +                                                        TOP_LEVEL_SCOPE);
  +
  +            DatatypeValidator dv = null;
  +            if (eltIndex>-1) {
  +                sGrammar.getElementDecl(eltIndex, fTempElementDecl);
  +                dv = fTempElementDecl.datatypeValidator;
  +            }
  +            else {
  +                reportGenericSchemaError("could not find global element : '" + localpart

  +                                         + " in the SchemaGrammar "+newSchemaURI);
  +            }
  +            return dv;
  +        }
  +        else {
  +            reportGenericSchemaError("could not resolve URI : " + newSchemaURI
  +                                      + " to a SchemaGrammar in getELementDeclTypeValidatorFromNS");
  +        }
  +        return null;
  +    }
  +
  +    ComplexTypeInfo getElementDeclTypeInfoFromNS(String newSchemaURI, String localpart)
throws Exception {
  +        Grammar grammar = fGrammarResolver.getGrammar(newSchemaURI);
  +        if (grammar != null && grammar instanceof SchemaGrammar) {
  +            SchemaGrammar sGrammar = (SchemaGrammar) grammar;
  +            int eltIndex = sGrammar.getElementDeclIndex(fStringPool.addSymbol(newSchemaURI),

  +                                                              fStringPool.addSymbol(localpart),

  +                                                              TOP_LEVEL_SCOPE);
  +            ComplexTypeInfo typeInfo = null;
  +            if (eltIndex>-1) {
  +                 typeInfo = sGrammar.getElementComplexTypeInfo(eltIndex);
  +            }
  +            else {
  +                reportGenericSchemaError("could not find global element : '" + localpart

  +                                         + " in the SchemaGrammar "+newSchemaURI);
  +
  +            }
  +            return typeInfo;
  +        }
  +        else {
  +            reportGenericSchemaError("could not resolve URI : " + newSchemaURI 
  +                                     + " to a SchemaGrammar in getElementDeclTypeInfoFromNS");
  +        }
  +        return null;
  +    }
  +
       /**
        * Traverse attributeGroup Declaration
        * 
  
  
  

Mime
View raw message