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/08/02 01:54:20 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema SchemaSymbols.java TraverseSchema.java

ericye      00/08/01 16:54:20

  Modified:    java/src/org/apache/xerces/validators/common
                        XMLValidator.java
               java/src/org/apache/xerces/validators/schema
                        SchemaSymbols.java TraverseSchema.java
  Log:
  1. Modified the data type registry to be keyed by uri,localpart pair. 2. added xsi:type support for simple types.
  
  Revision  Changes    Path
  1.53      +25 -4     xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
  
  Index: XMLValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- XMLValidator.java	2000/07/26 21:51:52	1.52
  +++ XMLValidator.java	2000/08/01 23:54:16	1.53
  @@ -100,13 +100,14 @@
   import org.apache.xerces.validators.schema.SchemaSymbols;
   import org.apache.xerces.validators.schema.TraverseSchema;
   
  +import org.apache.xerces.validators.datatype.DatatypeValidatorFactoryImpl;
   import org.apache.xerces.validators.datatype.DatatypeValidator;
   import org.apache.xerces.validators.datatype.InvalidDatatypeValueException;
   
   /**
    * This class is the super all-in-one validator used by the parser.
    *
  - * @version $Id: XMLValidator.java,v 1.52 2000/07/26 21:51:52 ericye Exp $
  + * @version $Id: XMLValidator.java,v 1.53 2000/08/01 23:54:16 ericye Exp $
    */
   public final class XMLValidator
       implements DefaultEntityHandler.EventHandler,
  @@ -222,6 +223,7 @@
       private int fXsiPrefix = - 1;
       private int fXsiURI = -2; 
       private int fXsiTypeAttValue = -1;
  +    private DatatypeValidator fXsiTypeValidator = null;
   
       private Grammar fGrammar = null;
       private int fGrammarNameSpaceIndex = -1;
  @@ -1331,6 +1333,7 @@
           fCurrentSchemaURI = -1;
           fEmptyURI = - 1; 
           fXsiPrefix = - 1;
  +        fXsiTypeValidator = null;
   
           fGrammar = null;
           fGrammarNameSpaceIndex = -1;
  @@ -2331,8 +2334,11 @@
   
   
                   Hashtable complexRegistry = ((SchemaGrammar)fGrammar).getComplexTypeRegistry();
  -                if (complexRegistry==null) {
  -                    reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, XMLMessages.SCHEMA_GENERIC_ERROR, fErrorReporter.getLocator().getSystemId()
  +                DatatypeValidatorFactoryImpl dataTypeReg = ((SchemaGrammar)fGrammar).getDatatypeRegistry();
  +                if (complexRegistry==null || dataTypeReg == null) {
  +                    reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, 
  +                                              XMLMessages.SCHEMA_GENERIC_ERROR, 
  +                                              fErrorReporter.getLocator().getSystemId()
                                          +" line"+fErrorReporter.getLocator().getLineNumber()
                                          +", canot resolve xsi:type = " + xsiType+"  ---2");
                   }
  @@ -2345,7 +2351,15 @@
                       //      the SchemaGrammar.
   
                       if (typeInfo==null) {
  -                        reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, XMLMessages.SCHEMA_GENERIC_ERROR, "unsupported case in xsi:type handling");
  +                        if (uri.length() == 0 || uri.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) ) {
  +                            fXsiTypeValidator = dataTypeReg.getDatatypeValidator(localpart);
  +                        }
  +                        else 
  +                            fXsiTypeValidator = dataTypeReg.getDatatypeValidator(uri+","+localpart);
  +                        if( fXsiTypeValidator == null ) 
  +                            reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, 
  +                                                      XMLMessages.SCHEMA_GENERIC_ERROR, 
  +                                                      "unresolved type : "+uri+","+localpart+" found  in xsi:type handling");
                       }
                       else 
                           elementIndex = typeInfo.templateElementIndex;
  @@ -2811,6 +2825,13 @@
                   fGrammar.getElementDecl(elementIndex, fTempElementDecl);
   
                   DatatypeValidator dv = fTempElementDecl.datatypeValidator;
  +
  +                // If there is xsi:type validator, substitute it.
  +                if ( fXsiTypeValidator != null ) {
  +                    dv = fXsiTypeValidator;
  +                    fXsiTypeValidator = null;
  +                }
  +
                   if (dv == null) {
                       System.out.println("Internal Error: this element have a simpletype "+
                                          "but no datatypevalidator was found, element "+fTempElementDecl.name
  
  
  
  1.6       +1 -0      xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaSymbols.java
  
  Index: SchemaSymbols.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaSymbols.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SchemaSymbols.java	2000/07/04 01:28:51	1.5
  +++ SchemaSymbols.java	2000/08/01 23:54:17	1.6
  @@ -108,6 +108,7 @@
       public static final String ELT_SELECTOR =  "selector";
       public static final String ELT_SEQUENCE =  "sequence";
       public static final String ELT_SIMPLETYPE =  "simpleType";
  +    public static final String ELT_UNIQUE = "unique";
       public static final String ATT_ABSTRACT =  "abstract";
       public static final String ATT_ATTRIBUTEFORMDEFAULT =  "attributeFormDefault";
       public static final String ATT_BASE =  "base";
  
  
  
  1.42      +110 -48   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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TraverseSchema.java	2000/07/21 03:42:45	1.41
  +++ TraverseSchema.java	2000/08/01 23:54:17	1.42
  @@ -374,7 +374,7 @@
    *  
    * @see                  org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.41 2000/07/21 03:42:45 ericye Exp $
  + * @version $Id: TraverseSchema.java,v 1.42 2000/08/01 23:54:17 ericye Exp $
    */
   
   public class TraverseSchema implements 
  @@ -1003,7 +1003,8 @@
   
           if ( nameProperty.equals("")) { // anonymous simpleType
               newSimpleTypeName = fStringPool.addSymbol(
  -                               "http://www.apache.org/xml/xerces/internalDatatype"+fSimpleTypeAnonCount++ );   
  +                "#S#"+fSimpleTypeAnonCount++ );   
  +                               //"http://www.apache.org/xml/xerces/internalDatatype"+fSimpleTypeAnonCount++ );   
               } else 
               newSimpleTypeName       = fStringPool.addSymbol( nameProperty );
   
  @@ -1020,13 +1021,17 @@
                   prefix = baseTypeQNameProperty.substring(0,colonptr);
                   localpart = baseTypeQNameProperty.substring(colonptr+1);
               }
  +            String uri = resolvePrefixToURI(prefix);
   
  -            baseValidator = fDatatypeRegistry.getDatatypeValidator( localpart );
  +            baseValidator = getDatatypeValidator(uri, localpart);
  +
               if (baseValidator == null) {
                   Element baseTypeNode = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
                   if (baseTypeNode != null) {
                       traverseSimpleTypeDecl( baseTypeNode );
  -                    baseValidator = fDatatypeRegistry.getDatatypeValidator(localpart);
  +                    
  +                    baseValidator = getDatatypeValidator(uri, localpart);
  +                    
                       if (baseValidator == null) {
                           reportSchemaError(SchemaMessageProvider.UnknownBaseDatatype,
                           new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_BASE ),
  @@ -1105,9 +1110,14 @@
           }
   
           // create & register validator for "generated" type if it doesn't exist
  +        
  +        String nameOfType = fStringPool.toString( newSimpleTypeName);
  +        if (fTargetNSURIString.length () != 0) {
  +            nameOfType = fTargetNSURIString+","+nameOfType;
  +        }
  +                 
  +
           try {
  -           String nameOfType = 
  -                            fStringPool.toString( newSimpleTypeName );
   
              DatatypeValidator newValidator =
                    fDatatypeRegistry.getDatatypeValidator( nameOfType );
  @@ -1125,7 +1135,7 @@
                  //e.printStackTrace(System.err);
                  reportSchemaError(SchemaMessageProvider.DatatypeError,new Object [] { e.getMessage() });
              }
  -        return newSimpleTypeName;
  +        return fStringPool.addSymbol(nameOfType);
       }
   
       /*
  @@ -1199,6 +1209,21 @@
           return anyIndex;
       }
   
  +
  +    public DatatypeValidator getDatatypeValidator(String uri, String localpart) {
  +
  +        DatatypeValidator dv = null;
  +
  +        if (uri.length()==0 || uri.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) {
  +            dv = fDatatypeRegistry.getDatatypeValidator( localpart );
  +        }
  +        else {
  +            dv = fDatatypeRegistry.getDatatypeValidator( uri+","+localpart );
  +        }
  +
  +        return dv;
  +    }
  +
       /*
       * <anyAttribute 
       *   id = ID 
  @@ -1403,7 +1428,7 @@
        */
       
       //REVISIT: TO DO, base and derivation ???
  -    private int traverseComplexTypeDecl( Element complexTypeDecl ) throws Exception{ 
  +    private int traverseComplexTypeDecl( Element complexTypeDecl ) throws Exception { 
           String isAbstract = complexTypeDecl.getAttribute( SchemaSymbols.ATT_ABSTRACT );
           String base = complexTypeDecl.getAttribute(SchemaSymbols.ATT_BASE);
           String blockSet = complexTypeDecl.getAttribute( SchemaSymbols.ATT_BLOCK );
  @@ -1487,8 +1512,7 @@
                   // check if the base type is from the same Schema;
                   if ( ! typeURI.equals(fTargetNSURIString) 
                        && ! typeURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) 
  -                     && ! (typeURI.length() == 0)
  -                     )  /*REVISIT, !!!! a hack: for schema that has no target namespace, e.g. personal-schema.xml*/{
  +                     && typeURI.length() != 0 )  /*REVISIT, !!!! a hack: for schema that has no target namespace, e.g. personal-schema.xml*/{
                       baseTypeInfo = getTypeInfoFromNS(typeURI, localpart);
                       if (baseTypeInfo == null) {
                           baseTypeValidator = getTypeValidatorFromNS(typeURI, localpart);
  @@ -1512,7 +1536,8 @@
                       // if not found, 2 possibilities: 1: ComplexType in question has not been compiled yet;
                       //                                2: base is SimpleTYpe;
                       if (baseTypeInfo == null) {
  -                        baseTypeValidator = fDatatypeRegistry.getDatatypeValidator(localpart);
  +                            baseTypeValidator = getDatatypeValidator(typeURI, localpart);
  +
                           if (baseTypeValidator == null) {
                               baseTypeNode = getTopLevelComponentByName(SchemaSymbols.ELT_COMPLEXTYPE,localpart);
                               if (baseTypeNode != null) {
  @@ -1524,7 +1549,7 @@
                                   baseTypeNode = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
                                   if (baseTypeNode != null) {
                                       baseTypeSymbol = traverseSimpleTypeDecl( baseTypeNode );
  -                                    simpleTypeValidator = baseTypeValidator = fDatatypeRegistry.getDatatypeValidator(localpart);
  +                                    simpleTypeValidator = baseTypeValidator = getDatatypeValidator(typeURI, localpart);
                                       if (simpleTypeValidator == null) {
                                           //TO DO: signal error here.
                                       }
  @@ -1657,10 +1682,10 @@
           if (content.equals(SchemaSymbols.ATTVAL_TEXTONLY)) {
               //TO DO
               if (base.length() == 0) {
  -                simpleTypeValidator = baseTypeValidator = fDatatypeRegistry.getDatatypeValidator(SchemaSymbols.ATTVAL_STRING);
  +                simpleTypeValidator = baseTypeValidator = getDatatypeValidator("", SchemaSymbols.ATTVAL_STRING);
               }
  -            else if (fDatatypeRegistry.getDatatypeValidator(base) == null 
  -                     && baseTypeInfo.datatypeValidator==null ) // must be datatype
  +            else if ( baseTypeValidator == null 
  +                      && baseTypeInfo != null && baseTypeInfo.datatypeValidator==null ) // must be datatype
                           reportSchemaError(SchemaMessageProvider.NotADatatype,
                                             new Object [] { base }); //REVISIT check forward refs
               //handle datatypes
  @@ -1833,7 +1858,7 @@
               if ( ! ( seeOtherParticle || seeAll ) && (elementContent || mixedContent)
                    && base.length() == 0 ) {
                   contentSpecType = XMLElementDecl.TYPE_SIMPLE;
  -                simpleTypeValidator = fDatatypeRegistry.getDatatypeValidator(SchemaSymbols.ATTVAL_STRING);
  +                simpleTypeValidator = getDatatypeValidator("", SchemaSymbols.ATTVAL_STRING);
                   // REVISIT: Localize
                   reportGenericSchemaError ( " complexType '"+typeName+"' with a elementOnly or mixed content "
                                              +"need to have at least one particle child");
  @@ -2285,20 +2310,26 @@
               }
               localpart = fStringPool.toString(dataTypeSymbol);
   
  +            dv = fDatatypeRegistry.getDatatypeValidator(localpart);
  +
           } else {
   
               String prefix = "";
               localpart = datatype;
  +            dataTypeSymbol = fStringPool.addSymbol(localpart);
  +
               int  colonptr = datatype.indexOf(":");
               if ( colonptr > 0) {
                   prefix = datatype.substring(0,colonptr);
                   localpart = datatype.substring(colonptr+1);
               }
               String typeURI = resolvePrefixToURI(prefix);
  -            dataTypeSymbol = fStringPool.addSymbol(localpart);
   
               if ( typeURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) 
                    || typeURI.length()==0) {
  +
  +                dv = getDatatypeValidator("", localpart);
  +
                   if (localpart.equals("ID")) {
                       attType = XMLAttributeDecl.TYPE_ID;
                   } else if (localpart.equals("IDREF")) {
  @@ -2321,23 +2352,32 @@
                   }
                   else {
                       attType = XMLAttributeDecl.TYPE_SIMPLE;
  +                    if (dv == null && typeURI.length() == 0) {
  +                        Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
  +                        if (topleveltype != null) {
  +                            traverseSimpleTypeDecl( topleveltype );
  +                            dv = getDatatypeValidator(typeURI, localpart);
  +                        }else {
  +                            // REVISIT: Localize
  +                            reportGenericSchemaError("simpleType not found : " + localpart);
  +                        }
  +                    }
                   }
  -            } else { // REVISIT: Danger: assuming all other ATTR types are datatypes
  -                //REVISIT check against list of validators to ensure valid type name
  +            } else {
   
                   // check if the type is from the same Schema
   
  -                if (!typeURI.equals(fTargetNSURIString) && typeURI.length() != 0 ) {
  -                    dv = getTypeValidatorFromNS(typeURI, localpart);
  -                    if (dv == null) {
  -                        //TO DO: report error here;
  -                        System.out.println("Counld not find simpleType " +localpart 
  -                                           + " in schema " + typeURI);
  +                dv = getDatatypeValidator(typeURI, localpart);
  +                if (dv == null && typeURI.equals(fTargetNSURIString) ) {
  +                    Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
  +                    if (topleveltype != null) {
  +                        traverseSimpleTypeDecl( topleveltype );
  +                        dv = getDatatypeValidator(typeURI, localpart);
  +                    }else {
  +                        // REVISIT: Localize
  +                        reportGenericSchemaError("simpleType not found : " + localpart);
                       }
                   }
  -                else {
  -                    dv = fDatatypeRegistry.getDatatypeValidator(localpart);
  -                }
   
                   attType = XMLAttributeDecl.TYPE_SIMPLE;
               }
  @@ -2353,25 +2393,9 @@
           boolean required = use.equals(SchemaSymbols.ATTVAL_REQUIRED);
   
   
  -        if(dv==null){
  -            dv = fDatatypeRegistry.getDatatypeValidator(localpart); 
  -            if ( dv == null )  {
  -                 Element topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
  -                 if (topleveltype != null) {
  -                      traverseSimpleTypeDecl( topleveltype );
  -                      dv = fDatatypeRegistry.getDatatypeValidator(localpart);
  -                            //   TO DO:  the Default and fixed attribute handling should be here.
  -                      }else {
  -                          // REVISIT: Localize
  -                      reportGenericSchemaError("simpleType not found : " + localpart);
  -                      }
  -                 }
  -        }
  -
  -
           if (dv == null) {
               // REVISIT: Localize
  -            reportGenericSchemaError("null validator for datatype : " 
  +            reportGenericSchemaError("could not resolve the type or get a null validator for datatype : " 
                                        + fStringPool.toString(dataTypeSymbol));
           }
   
  @@ -2850,7 +2874,11 @@
    
           }
           
  -        //ComplexTypeInfo typeInfo = new ComplexTypeInfo();
  +
  +        //
  +        // resolving the type for this element right here
  +        //
  +
           ComplexTypeInfo typeInfo = null;
   
           // element has a single child element, either a datatype or a type, null if primitive
  @@ -2955,7 +2983,7 @@
               else {
                   typeInfo = (ComplexTypeInfo) fComplexTypeRegistry.get(typeURI+","+localpart);
                   if (typeInfo == null) {
  -                    dv = fDatatypeRegistry.getDatatypeValidator(localpart);
  +                    dv = getDatatypeValidator(typeURI, localpart);
                       if (dv == null )
                       if (typeURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
                           && !fTargetNSURIString.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) 
  @@ -2990,7 +3018,7 @@
                               topleveltype = getTopLevelComponentByName(SchemaSymbols.ELT_SIMPLETYPE, localpart);
                               if (topleveltype != null) {
                                   typeNameIndex = traverseSimpleTypeDecl( topleveltype );
  -                                dv = fDatatypeRegistry.getDatatypeValidator(localpart);
  +                                dv = getDatatypeValidator(typeURI, localpart);
                                   //   TO DO:  the Default and fixed attribute handling should be here.
                               }
                               else {
  @@ -3046,6 +3074,35 @@
               contentSpecType = XMLElementDecl.TYPE_SIMPLE;
           }
   
  +        //
  +        // key/keyref/unique processing\
  +        //
  +
  +        child = XUtil.getFirstChildElement(elementDecl);
  +        Vector idConstraints = null;
  +        
  +        while (child != null){
  +            String childName = child.getNodeName();
  +           /**** 
  +            if ( childName.equals(SchemaSymbols.ELT_KEY) ) { 
  +                traverseKey(child, idCnstrt);
  +            }
  +            else if ( childName.equals(SchemaSymbols.ELT_KEYREF) ) {
  +                traverseKeyRef(child, idCnstrt);
  +            }
  +            else if ( childName.equals(SchemaSymbols.ELT_UNIQUE) ) {
  +                traverseUnique(child, idCnstrt);
  +            }
  +
  +            if (idCnstrt!= null) {
  +                if (idConstraints != null) {
  +                    idConstraints = new Vector();
  +                }
  +                idConstraints.addElement(idCnstrt);
  +            }
  +            /****/
  +            child = XUtil.getNextSiblingElement(child);
  +        }
           
           //
           // Create element decl
  @@ -3204,6 +3261,9 @@
       }
       
       DatatypeValidator getTypeValidatorFromNS(String newSchemaURI, String localpart) throws Exception {
  +        // The following impl is for the case where every Schema Grammar has its own instance of DatatypeRegistry.
  +        // Now that we have only one DataTypeRegistry used by all schemas. this is not needed.
  +        /*****
           Grammar grammar = fGrammarResolver.getGrammar(newSchemaURI);
           if (grammar != null && grammar instanceof SchemaGrammar) {
               SchemaGrammar sGrammar = (SchemaGrammar) grammar;
  @@ -3214,6 +3274,8 @@
               reportGenericSchemaError("could not resolve URI : " + newSchemaURI + " to a SchemaGrammar in getTypeValidatorFromNS");
           }
           return null;
  +        /*****/
  +        return getDatatypeValidator(newSchemaURI, localpart);
       }
   
       ComplexTypeInfo getTypeInfoFromNS(String newSchemaURI, String localpart) throws Exception {