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 2002/09/18 23:58:29 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs AttributePSVImpl.java ElementPSVImpl.java XMLSchemaValidator.java

sandygao    2002/09/18 14:58:29

  Modified:    java/src/org/apache/xerces/impl/xs AttributePSVImpl.java
                        ElementPSVImpl.java XMLSchemaValidator.java
  Log:
  1. A new feature to indicate whether PSVI augmentation is necessary.
  It turned out PSVI augmentation is costly. For applications that care about
  performance but don't need PSVI, this feature can be turned off.
  2. Fixing a PSVI bug: when an attribute is invalid, it's parent should also be
  marked invalid.
  
  Revision  Changes    Path
  1.14      +10 -13    xml-xerces/java/src/org/apache/xerces/impl/xs/AttributePSVImpl.java
  
  Index: AttributePSVImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/AttributePSVImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AttributePSVImpl.java	16 Sep 2002 21:50:58 -0000	1.13
  +++ AttributePSVImpl.java	18 Sep 2002 21:58:29 -0000	1.14
  @@ -82,8 +82,8 @@
       protected XSTypeDefinition fTypeDecl = null;
   
       /** If this attribute was explicitly given a 
  -     * value in the original document, this is true; otherwise, it is false  */
  -    protected boolean fSpecified = true;
  +     * value in the original document, this is false; otherwise, it is true */
  +    protected boolean fSpecified = false;
   
       /** schema normalized value property */
       protected String fNormalizedValue = null;
  @@ -98,7 +98,7 @@
       protected short fValidity = AttributePSVI.VALIDITY_UNKNOWN;
   
       /** error codes */
  -    protected Vector fErrorCodes = new Vector(10);
  +    protected String[] fErrorCodes = null;
   
       /** validation context: could be QName or XPath expression*/
       protected String fValidationContext = null;
  @@ -134,7 +134,7 @@
       /**
        * [schema specified] 
        * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  -     * @return false value was specified in schema, true value comes from the infoset
  +     * @return true - value was specified in schema, false - value comes from the infoset
        */
       public boolean getIsSchemaSpecified() {
           return fSpecified;
  @@ -169,8 +169,9 @@
        * @return list of error codes
        */
       public StringList getErrorCodes() {
  -        // REVISIT: fErrorCodes should be of type StringList
  -        return new StringListImpl(fErrorCodes);
  +        if (fErrorCodes == null)
  +            return null;
  +        return new StringListImpl(fErrorCodes, fErrorCodes.length);
       }
   
       // This is the only information we can provide in a pipeline.
  @@ -218,15 +219,11 @@
           fDeclaration = null;
           fSchemaDefault = null;
           fTypeDecl = null;
  -        fSpecified = true;
  +        fSpecified = false;
           fMemberType = null;
           fValidationAttempted = AttributePSVI.VALIDATION_NONE;
           fValidity = AttributePSVI.VALIDITY_UNKNOWN;
  -        fErrorCodes.setSize(0);
  +        fErrorCodes = null;
           fValidationContext = null;
  -    }
  -
  -    public void addErrorCode(String key){
  -        fErrorCodes.addElement(key);
       }
   }
  
  
  
  1.19      +5 -5      xml-xerces/java/src/org/apache/xerces/impl/xs/ElementPSVImpl.java
  
  Index: ElementPSVImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/ElementPSVImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ElementPSVImpl.java	9 Aug 2002 15:18:18 -0000	1.18
  +++ ElementPSVImpl.java	18 Sep 2002 21:58:29 -0000	1.19
  @@ -89,9 +89,9 @@
         */
       protected boolean fNil = false;
   
  -    /** false if the element value was provided by the schema; true otherwise. 
  +    /** true if the element value was provided by the schema; false otherwise. 
        */
  -    protected boolean fSpecified = true;
  +    protected boolean fSpecified = false;
   
       /** schema normalized value property */
       protected String fNormalizedValue = null;
  @@ -145,7 +145,7 @@
       /**
        * [schema specified] 
        * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
  -     * @return false value was specified in schema, true value comes from the infoset
  +     * @return true - value was specified in schema, false - value comes from the infoset
        */
       public boolean getIsSchemaSpecified() {
           return fSpecified;
  @@ -257,7 +257,7 @@
           fDeclaration = null;
           fTypeDecl = null;
           fNil = false;
  -        fSpecified = true;
  +        fSpecified = false;
           fNotation = null;
           fMemberType = null;
           fValidationAttempted = ElementPSVI.VALIDATION_NONE;
  
  
  
  1.101     +238 -249  xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
  
  Index: XMLSchemaValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v
  retrieving revision 1.100
  retrieving revision 1.101
  diff -u -r1.100 -r1.101
  --- XMLSchemaValidator.java	18 Sep 2002 21:49:46 -0000	1.100
  +++ XMLSchemaValidator.java	18 Sep 2002 21:58:29 -0000	1.101
  @@ -174,6 +174,10 @@
       protected static final String SCHEMA_ELEMENT_DEFAULT =
       Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT;
   
  +    /** Feature identifier: augment PSVI */
  +    protected static final String SCHEMA_AUGMENT_PSVI =
  +    Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
  +
       /** Feature identifier: whether to recognize java encoding names */
       protected static final String ALLOW_JAVA_ENCODING =
       Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE;
  @@ -226,6 +230,7 @@
           SCHEMA_VALIDATION,
           DYNAMIC_VALIDATION,
           SCHEMA_FULL_CHECKING,
  +        SCHEMA_AUGMENT_PSVI
       };
   
       /** Recognized properties. */
  @@ -249,12 +254,8 @@
       // Data
       //
   
  -    /** PSV infoset information for element */
  -    protected final  ElementPSVImpl fElemPSVI = new ElementPSVImpl();
  -
       /** current PSVI element info */
  -    protected ElementPSVImpl fCurrentPSVI = null;
  -
  +    protected ElementPSVImpl fCurrentPSVI = new ElementPSVImpl();
   
       // since it is the responsibility of each component to an
       // Augmentations parameter if one is null, to save ourselves from
  @@ -272,6 +273,9 @@
       protected boolean fFullChecking = false;
       protected boolean fNormalizeData = true;
       protected boolean fSchemaElementDefault = true;
  +    protected boolean fAugPSVI = true;
  +    
  +    // to indicate whether we are in the scope of entity reference or CData
       protected boolean fEntityRef = false;
       protected boolean fInCDATA = false;
   
  @@ -285,7 +289,7 @@
        * in this wrapper object, so that we can get all errors (error codes) of
        * a specific element. This is useful for PSVI.
        */
  -    protected static final class XSIErrorReporter {
  +    protected final class XSIErrorReporter {
   
           // the error reporter property
           XMLErrorReporter fErrorReporter;
  @@ -303,9 +307,11 @@
               fContextCount = 0;
           }
   
  -        // should be called on startElement: store the starting position
  -        // for the current element
  +        // should be called when starting process an element or an attribute.
  +        // store the starting position for the current context
           public void pushContext() {
  +            if (!fAugPSVI)
  +                return;
               // resize array if necessary
               if (fContextCount == fContext.length) {
                   int newSize = fContextCount + INC_STACK_SIZE;
  @@ -319,6 +325,8 @@
   
           // should be called on endElement: get all errors of the current element
           public String[] popContext() {
  +            if (!fAugPSVI)
  +                return null;
               // get starting position of the current element
               int contextPos = fContext[--fContextCount];
               // number of errors of the current element
  @@ -336,6 +344,28 @@
               return errors;
           }
   
  +        // should be called when an attribute is done: get all errors of 
  +        // this attribute, but leave the errors to the containing element
  +        public String[] mergeContext() {
  +            if (!fAugPSVI)
  +                return null;
  +            // get starting position of the current element
  +            int contextPos = fContext[--fContextCount];
  +            // number of errors of the current element
  +            int size = fErrors.size() - contextPos;
  +            // if no errors, return null
  +            if (size == 0)
  +                return null;
  +            // copy errors from the list to an string array
  +            String[] errors = new String[size];
  +            for (int i = 0; i < size; i++) {
  +                errors[i] = (String)fErrors.elementAt(contextPos + i);
  +            }
  +            // don't resize the vector: leave the errors for this attribute
  +            // to the containing element
  +            return errors;
  +        }
  +
           public void reportError(String domain, String key, Object[] arguments,
                                   short severity) throws XNIException {
               fErrorReporter.reportError(domain, key, arguments, severity);
  @@ -1173,7 +1203,6 @@
               fSymbolTable = symbolTable;
           }
   
  -
           // internal xerces property: namespace-context 
           fNamespaceSupport = (NamespaceSupport)componentManager.getProperty(NAMESPACE_CONTEXT_PROPERTY);
           fValidationState.setNamespaceSupport(fNamespaceSupport);
  @@ -1231,6 +1260,13 @@
               fSchemaElementDefault = false;
           }
   
  +        try {
  +            fAugPSVI = componentManager.getFeature(SCHEMA_AUGMENT_PSVI);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fAugPSVI = true;
  +        }
  +        
           fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_MANAGER);
           fSchemaLoader.setEntityResolver(fEntityResolver);
   
  @@ -1254,7 +1290,7 @@
           // effectively ignored. becuase we choose to take first location hint
           // available for a particular namespace.
           storeLocations(fExternalSchemas, fExternalNoNamespaceSchema) ;
  -        
  +
           try {
               fJaxpSchemaSource = componentManager.getProperty(JAXP_SCHEMA_SOURCE);
           }
  @@ -1638,18 +1674,6 @@
               System.out.println("==>handleStartElement: " +element);
           }
   
  -        if(augs == null) {
  -            augs = fAugmentations;
  -            augs.clear();
  -        }
  -
  -        fCurrentPSVI = (ElementPSVImpl)augs.getItem(Constants.ELEMENT_PSVI);
  -        if (fCurrentPSVI == null) {
  -            fCurrentPSVI = fElemPSVI;
  -            augs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI);
  -        }
  -        fCurrentPSVI.reset();
  -
           // root element
           if (fElementDepth == -1 && fValidationManager.isGrammarFound()) {
               // if a DTD grammar is found, we do the same thing as Dynamic:
  @@ -1668,19 +1692,12 @@
           //application for a namespace
           storeLocations(sLocation, nsLocation) ;
   
  -        // update normalization flags
  -        if (fNormalizeData) {
  -            // reset values
  -            fFirstChunk = true;
  -            fTrailing = false;
  -            fUnionType = false;
  -            fWhiteSpace = -1;
  -        }
  -
           // if we are in the content of "skip", then just skip this element
           // REVISIT:  is this the correct behaviour for ID constraints?  -NG
           if (fSkipValidationDepth >= 0) {
               fElementDepth++;
  +            if (fAugPSVI)
  +                augs = getEmptyAugs(augs);
               return augs;
           }
   
  @@ -1756,6 +1773,8 @@
           // if the wildcard is skip, then return
           if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_SKIP) {
               fSkipValidationDepth = fElementDepth;
  +            if (fAugPSVI)
  +                augs = getEmptyAugs(augs);
               return augs;
           }
   
  @@ -1766,7 +1785,6 @@
               if (sGrammar != null){
                   fCurrentElemDecl = sGrammar.getGlobalElementDecl(element.localpart);
               }
  -
           }
   
           // Element Locally Valid (Element)
  @@ -1789,13 +1807,15 @@
               // if this is the validation root, report an error, because
               // we can't find eith decl or type for this element
               // REVISIT: should we report error, or warning?
  -            // for dynamic validation, skip the whole content,
  -            // because no grammar was found.
  -            if (fDynamicValidation) {
  -                fSkipValidationDepth = fElementDepth;
  -                return augs;
  -            }
               if (fElementDepth == 0) {
  +                // for dynamic validation, skip the whole content,
  +                // because no grammar was found.
  +                if (fDynamicValidation) {
  +                    fSkipValidationDepth = fElementDepth;
  +                    if (fAugPSVI)
  +                        augs = getEmptyAugs(augs);
  +                    return augs;
  +                }
                   // report error, because it's root element
                   reportSchemaError("cvc-elt.1", new Object[]{element.rawname});
               }
  @@ -1808,8 +1828,6 @@
               // no element decl or type found for this element.
               // Allowed by the spec, we can choose to either laxly assess this
               // element, or to skip it. Now we choose lax assessment.
  -            // REVISIT: IMO, we should perform lax assessment when validation
  -            // feature is on, and skip when dynamic validation feature is on.
               fCurrentType = SchemaGrammar.fAnyType;
           }
   
  @@ -1818,12 +1836,14 @@
               fValidationRoot = element.rawname;
           }
   
  -        // PSVI: add validation context
  -        fCurrentPSVI.fValidationContext = fValidationRoot;
  -        // PSVI: add element declaration
  -        fCurrentPSVI.fDeclaration = fCurrentElemDecl;
  -        // PSVI: add element type
  -        fCurrentPSVI.fTypeDecl = fCurrentType;
  +        // update normalization flags
  +        if (fNormalizeData) {
  +            // reset values
  +            fFirstChunk = true;
  +            fTrailing = false;
  +            fUnionType = false;
  +            fWhiteSpace = -1;
  +        }
   
           // Element Locally Valid (Type)
           // 2 Its {abstract} must be false.
  @@ -1863,7 +1883,6 @@
                }
           }
   
  -
           // then try to get the content model
           fCurrentCM = null;
           if (fCurrentType.getTypeCategory() == XSTypeDecl.COMPLEX_TYPE) {
  @@ -1920,6 +1939,20 @@
               XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
               matcher.startElement(element, attributes, fCurrentElemDecl);
           }
  +
  +        if (fAugPSVI) {
  +            augs = getEmptyAugs(augs);
  +
  +            // PSVI: add validation context
  +            fCurrentPSVI.fValidationContext = fValidationRoot;
  +            // PSVI: add element declaration
  +            fCurrentPSVI.fDeclaration = fCurrentElemDecl;
  +            // PSVI: add element type
  +            fCurrentPSVI.fTypeDecl = fCurrentType;
  +            // PSVI: add notation attribute
  +            fCurrentPSVI.fNotation = fNotation;
  +        }
  +
           return augs;
   
       } // handleStartElement(QName,XMLAttributes,boolean)
  @@ -1936,18 +1969,6 @@
               System.out.println("==>handleEndElement:" +element);
           }
   
  -        if(augs == null) { // again, always assume adding augmentations...
  -            augs = fAugmentations;
  -            augs.clear();
  -        }
  -
  -        fCurrentPSVI = (ElementPSVImpl)augs.getItem(Constants.ELEMENT_PSVI);
  -        if (fCurrentPSVI == null) {
  -            fCurrentPSVI = fElemPSVI;
  -            augs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI);
  -        }
  -        fCurrentPSVI.reset();
  -
           // if we are skipping, return
           if (fSkipValidationDepth >= 0) {
               // but if this is the top element that we are skipping,
  @@ -1972,25 +1993,23 @@
                   fElementDepth--;
               }
   
  -            // pop error reporter context: get all errors for the current
  -            // element, and remove them from the error list
  -            // String[] errors = fXSIErrorReporter.popContext();
  -
               // PSVI: validation attempted:
               // use default values in psvi item for
               // validation attempted, validity, and error codes
   
               // check extra schema constraints on root element
  -            if (fElementDepth == -1 && fDoValidation && fFullChecking) {
  +            if (fElementDepth == -1 && fFullChecking) {
                   XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fXSIErrorReporter.fErrorReporter);
               }
   
               fDefaultValue = null;
  +            if (fAugPSVI)
  +                augs = getEmptyAugs(augs);
               return augs;
           }
   
           // now validate the content of the element
  -        XMLString defaultValue = processElementContent(element);
  +        processElementContent(element);
   
           // Element Locally Valid (Element)
           // 6 The element information item must be valid with respect to each of the {identity-constraint definitions} as per Identity-constraint Satisfied (3.11.4).
  @@ -2000,7 +2019,7 @@
           for (int i = oldCount - 1; i >= 0; i--) {
               XPathMatcher matcher = fMatcherStack.getMatcherAt(i);
               matcher.endElement(element, fCurrentElemDecl,
  -                               defaultValue == null ?
  +                               fDefaultValue == null ?
                                  fValidatedInfo.normalizedValue :
                                  fCurrentElemDecl.fDefault.normalizedValue);
           }
  @@ -2036,6 +2055,8 @@
   
           // decrease element depth and restore states
           fElementDepth--;
  +        
  +        SchemaGrammar[] grammars = null;
           // have we reached the end tag of the validation root?
           if (fElementDepth == -1) {
               // 7 If the element information item is the validation root, it must be valid per Validation Root Valid (ID/IDREF) (3.3.4).
  @@ -2049,13 +2070,11 @@
               }
               fValidationState.resetIDTables();
   
  -            SchemaGrammar[] grammars = fGrammarBucket.getGrammars();
  +            grammars = fGrammarBucket.getGrammars();
               // return the final set of grammars validator ended up with
               if (fGrammarPool != null) {
                   fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, grammars);
               }
  -            // store [schema information] in the PSVI
  -            fCurrentPSVI.fSchemaInformation = new XSModelImpl(grammars);
           }
           else {
               // get the states for the parent element.
  @@ -2070,39 +2089,59 @@
               fSawChildren = fSawChildrenStack[fElementDepth];
           }
   
  -        fCurrentPSVI.fDeclaration = this.fCurrentElemDecl;
  -        fCurrentPSVI.fTypeDecl = this.fCurrentType;
  -        fCurrentPSVI.fNotation = this.fNotation;
  -        fCurrentPSVI.fValidationContext = this.fValidationRoot;
  -
  -        // PSVI: validation attempted
  -        if (fElementDepth <= fPartialValidationDepth) {
  -            // the element had child with a content skip.
  -            fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_PARTIAL;
  -            if (fElementDepth == fPartialValidationDepth) {
  -                // set depth to the depth of the parent
  -                fPartialValidationDepth--;
  +        if (fAugPSVI) {
  +            augs = getEmptyAugs(augs);
  +
  +            // the 4 properties sent on startElement calls
  +            fCurrentPSVI.fDeclaration = this.fCurrentElemDecl;
  +            fCurrentPSVI.fTypeDecl = this.fCurrentType;
  +            fCurrentPSVI.fNotation = this.fNotation;
  +            fCurrentPSVI.fValidationContext = this.fValidationRoot;
  +    
  +            // PSVI: validation attempted
  +            if (fElementDepth <= fPartialValidationDepth) {
  +                // the element had child with a content skip.
  +                fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_PARTIAL;
  +                if (fElementDepth == fPartialValidationDepth) {
  +                    // set depth to the depth of the parent
  +                    fPartialValidationDepth--;
  +                }
  +            }
  +            else {
  +                fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_FULL;
  +            }
  +    
  +            // pop error reporter context: get all errors for the current
  +            // element, and remove them from the error list
  +            String[] errors = fXSIErrorReporter.popContext();
  +    
  +            // PSVI: error codes
  +            fCurrentPSVI.fErrorCodes = errors;
  +            // PSVI: validity
  +            fCurrentPSVI.fValidity = (errors == null) ?
  +                                     ElementPSVI.VALIDITY_VALID :
  +                                     ElementPSVI.VALIDITY_INVALID;
  +    
  +            if (fElementDepth == -1) {
  +                // store [schema information] in the PSVI
  +                fCurrentPSVI.fSchemaInformation = new XSModelImpl(grammars);
               }
           }
  -        else {
  -            fCurrentPSVI.fValidationAttempted = ElementPSVI.VALIDATION_FULL;
  -        }
  -
  -        // pop error reporter context: get all errors for the current
  -        // element, and remove them from the error list
  -        String[] errors = fXSIErrorReporter.popContext();
  -
  -        // PSVI: error codes
  -        fCurrentPSVI.fErrorCodes = errors;
  -        // PSVI: validity
  -        fCurrentPSVI.fValidity = (errors == null) ? ElementPSVI.VALIDITY_VALID
  -        : ElementPSVI.VALIDITY_INVALID;
  -
  -        fDefaultValue = defaultValue;
   
           return augs;
       } // handleEndElement(QName,boolean)*/
   
  +    Augmentations getEmptyAugs(Augmentations augs) {
  +        if (augs == null) {
  +            augs = fAugmentations;
  +            augs.clear();
  +        }
  +        augs.putItem(Constants.ELEMENT_PSVI, fCurrentPSVI);
  +        fCurrentPSVI.reset();
  +        
  +        return augs;
  +    }
  +    
       void storeLocations(String sLocation, String nsLocation){
           if (sLocation != null) {
               if(!XMLSchemaLoader.tokenizeSchemaLocationStr(sLocation, fLocationPairs)) { // error!
  @@ -2265,95 +2304,56 @@
               System.out.println("==>processAttributes: " +attributes.getLength());
           }
   
  -        // REVISIT: should we assume that XMLAttributeImpl removes
  -        //          all augmentations from Augmentations? if yes.. we loose objects
  -        //         if no - we always produce attribute psvi objects which may not be filled in
  -        //         in this case we need to create/reset here all objects
  -        Augmentations augs = null;
  -        AttributePSVImpl attrPSVI = null;
  -
  -        for (int k=0;k<attributes.getLength();k++) {
  -            augs = attributes.getAugmentations(k);
  -            attrPSVI = (AttributePSVImpl) augs.getItem(Constants.ATTRIBUTE_PSVI);
  -            if (attrPSVI != null) {
  -                attrPSVI.reset();
  -            } else {
  -                attrPSVI= new AttributePSVImpl();
  -                augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  -            }
  -            // PSVI attribute: validation context
  -            attrPSVI.fValidationContext = fValidationRoot;
  -        }
  -
  -        if (attributes.getLength() == 0){
  -            // PSVI: validity is unknown, and validation attempted is none
  -            // this is a default value thus we should not set anything else here.
  -            return;
  -        }
  -
  -        // Element Locally Valid (Type)
  -        // 3.1.1 The element information item's [attributes] must be empty, excepting those
  -        // whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and
  -        // whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation.
  -        if (fCurrentType == null || fCurrentType.getTypeCategory() == XSTypeDecl.SIMPLE_TYPE) {
  -            int attCount = attributes.getLength();
  -
  -            for (int index = 0; index < attCount; index++) {
  -
  -                if (DEBUG) {
  -                    System.out.println("==>process attribute: "+fTempQName);
  -                }
  -                attributes.getName(index, fTempQName);
  -                // get attribute PSVI
  -                attrPSVI = (AttributePSVImpl)attributes.getAugmentations(index).getItem(Constants.ATTRIBUTE_PSVI);
  -
  -                // for the 4 xsi attributes, get appropriate decl, and validate
  -                if (fTempQName.uri == SchemaSymbols.URI_XSI) {
  -                    XSAttributeDecl attrDecl = null;
  -                    if (fTempQName.localpart == SchemaSymbols.XSI_SCHEMALOCATION)
  -                        attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_SCHEMALOCATION);
  -                    else if (fTempQName.localpart == SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION)
  -                        attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION);
  -                    else if (fTempQName.localpart == SchemaSymbols.XSI_NIL)
  -                        attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_NIL);
  -                    else if (fTempQName.localpart == SchemaSymbols.XSI_TYPE)
  -                        attrDecl = SchemaGrammar.SG_XSI.getGlobalAttributeDecl(SchemaSymbols.XSI_TYPE);
  -                    if (attrDecl != null) {
  -                        processOneAttribute(element, attributes, index,
  -                                            attrDecl, null, attrPSVI);
  -                        continue;
  -                    }
  -                }
  -
  -                // for all other attributes, no_validation/unknow_validity
  -                if (fTempQName.rawname != XMLSymbols.PREFIX_XMLNS && !fTempQName.rawname.startsWith("xmlns:")) {
  -                    reportSchemaError("cvc-type.3.1.1", new Object[]{element.rawname});
  -                }
  -            }
  -            return;
  -        }
  -
  -        XSObjectList attrUses = attrGrp.getAttributeUses();
  -        int useCount = attrUses.getLength();
  -        XSWildcardDecl attrWildcard = attrGrp.fAttributeWC;
  -
           // whether we have seen a Wildcard ID.
           String wildcardIDName = null;
   
           // for each present attribute
           int attCount = attributes.getLength();
   
  +        Augmentations augs = null;
  +        AttributePSVImpl attrPSVI = null;
  +
  +        boolean isSimple = fCurrentType == null ||
  +                           fCurrentType.getTypeCategory() == XSTypeDecl.SIMPLE_TYPE;
  +        
  +        XSObjectList attrUses = null;
  +        int useCount = 0;
  +        XSWildcardDecl attrWildcard = null;
  +        if (!isSimple) {
  +            attrUses = attrGrp.getAttributeUses();
  +            useCount = attrUses.getLength();
  +            attrWildcard = attrGrp.fAttributeWC;
  +        }
  +
           // Element Locally Valid (Complex Type)
           // 3 For each attribute information item in the element information item's [attributes] excepting those whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation, the appropriate case among the following must be true:
           // get the corresponding attribute decl
           for (int index = 0; index < attCount; index++) {
  +
               attributes.getName(index, fTempQName);
  +
               if (DEBUG) {
                   System.out.println("==>process attribute: "+fTempQName);
               }
  -            // get attribute PSVI
  -            attrPSVI = (AttributePSVImpl)attributes.getAugmentations(index).getItem(Constants.ATTRIBUTE_PSVI);
   
  +            if (fAugPSVI) {
  +                augs = attributes.getAugmentations(index);
  +                attrPSVI = (AttributePSVImpl) augs.getItem(Constants.ATTRIBUTE_PSVI);
  +                if (attrPSVI != null) {
  +                    attrPSVI.reset();
  +                } else {
  +                    attrPSVI= new AttributePSVImpl();
  +                    augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  +                }
  +                // PSVI attribute: validation context
  +                attrPSVI.fValidationContext = fValidationRoot;
  +            }
  +
  +            // Element Locally Valid (Type)
  +            // 3.1.1 The element information item's [attributes] must be empty, excepting those
  +            // whose [namespace name] is identical to http://www.w3.org/2001/XMLSchema-instance and
  +            // whose [local name] is one of type, nil, schemaLocation or noNamespaceSchemaLocation.
  +    
               // for the 4 xsi attributes, get appropriate decl, and validate
               if (fTempQName.uri == SchemaSymbols.URI_XSI) {
                   XSAttributeDecl attrDecl = null;
  @@ -2377,6 +2377,12 @@
                   continue;
               }
   
  +            // simple type doesn't allow any other attributes
  +            if (isSimple) {
  +                reportSchemaError("cvc-type.3.1.1", new Object[]{element.rawname});
  +                continue;
  +            }
  +
               // it's not xmlns, and not xsi, then we need to find a decl for it
               XSAttributeUseImpl currUse = null, oneUse;
               for (int i = 0; i < useCount; i++) {
  @@ -2438,10 +2444,6 @@
                           ((XSSimpleType)currDecl.fType).isIDType()) {
                           if (wildcardIDName != null){
                               reportSchemaError("cvc-complex-type.5.1", new Object[]{element.rawname, currDecl.fName, wildcardIDName});
  -
  -                            // PSVI: attribute is invalid, record errors
  -                            attrPSVI.fValidity = AttributePSVI.VALIDITY_INVALID;
  -                            attrPSVI.addErrorCode("cvc-complex-type.5.1");
                           }
                           else
                               wildcardIDName = currDecl.fName;
  @@ -2454,8 +2456,7 @@
           } // end of for (all attributes)
   
           // 5.2 If wild IDs is non-empty, there must not be any attribute uses among the {attribute uses} whose {attribute declaration}'s {type definition} is or is derived from ID.
  -        if (attrGrp.fIDAttrName != null && wildcardIDName != null){
  -            // PSVI: attribute is invalid, record errors
  +        if (!isSimple && attrGrp.fIDAttrName != null && wildcardIDName != null){
               reportSchemaError("cvc-complex-type.5.2", new Object[]{element.rawname, wildcardIDName, attrGrp.fIDAttrName});
           }
   
  @@ -2466,6 +2467,7 @@
                                AttributePSVImpl attrPSVI) {
   
           String attrValue = attributes.getValue(index);
  +        fXSIErrorReporter.pushContext();
           
           // Attribute Locally Valid
           // For an attribute information item to be locally valid with respect to an attribute declaration all of the following must be true:
  @@ -2475,25 +2477,12 @@
           // get simple type
           XSSimpleType attDV = currDecl.fType;
           
  -        // PSVI: attribute declaration
  -        attrPSVI.fDeclaration = currDecl;
  -        if (currDecl != null && currDecl.fDefault != null)
  -            attrPSVI.fSchemaDefault = currDecl.fDefault.normalizedValue;
  -        // PSVI: attribute type
  -        attrPSVI.fTypeDecl = attDV;
  -
  -        // PSVI: validation attempted:
  -        attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  -        attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID;
  -
           Object actualValue = null;
           try {
               actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo);
               // store the normalized value
               if (fNormalizeData)
                   attributes.setValue(index, fValidatedInfo.normalizedValue);
  -            // PSVI: attribute memberType
  -            attrPSVI.fMemberType = fValidatedInfo.memberType;
               if (attributes instanceof XMLAttributesImpl) {
                   XMLAttributesImpl attrs = (XMLAttributesImpl)attributes;
                   boolean schemaId = fValidatedInfo.memberType != null ?
  @@ -2516,33 +2505,19 @@
   
                   if (grammar != null) {
                       fNotation = grammar.getGlobalNotationDecl(qName.localpart);
  -                    fCurrentPSVI.fNotation = fNotation;
                   }
               }
           }
           catch (InvalidDatatypeValueException idve) {
  -
  -            // PSVI: attribute is invalid, record errors
  -            attrPSVI.fValidity = AttributePSVI.VALIDITY_INVALID;
  -            attrPSVI.addErrorCode("cvc-attribute.3");
               reportSchemaError(idve.getKey(), idve.getArgs());
               reportSchemaError("cvc-attribute.3", new Object[]{element.rawname, fTempQName.rawname, attrValue});
           }
  -        // PSVI: attribute normalized value
  -        // NOTE: we always store the normalized value, even if it's invlid,
  -        // because it might still be useful to the user. But when the it's
  -        // not valid, the normalized value is not trustable.
  -        attrPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
   
           // get the value constraint from use or decl
           // 4 The item's actual value must match the value of the {value constraint}, if it is present and fixed.                 // now check the value against the simpleType
           if (actualValue != null &&
               currDecl.getConstraintType() == XSConstants.VC_FIXED) {
               if (!attDV.isEqual(actualValue, currDecl.fDefault.actualValue)){
  -
  -                // PSVI: attribute is invalid, record errors
  -                attrPSVI.fValidity = AttributePSVI.VALIDITY_INVALID;
  -                attrPSVI.addErrorCode("cvc-attribute.4");
                   reportSchemaError("cvc-attribute.4", new Object[]{element.rawname, fTempQName.rawname, attrValue});
               }
           }
  @@ -2551,12 +2526,37 @@
           if (actualValue != null &&
               currUse != null && currUse.fConstraintType == XSConstants.VC_FIXED) {
               if (!attDV.isEqual(actualValue, currUse.fDefault.actualValue)){
  -                // PSVI: attribute is invalid, record errors
  -                attrPSVI.fValidity = AttributePSVI.VALIDITY_INVALID;
  -                attrPSVI.addErrorCode("cvc-complex-type.3.1");
                   reportSchemaError("cvc-complex-type.3.1", new Object[]{element.rawname, fTempQName.rawname, attrValue});
               }
           }
  +
  +        if (fAugPSVI) {
  +            // PSVI: attribute declaration
  +            attrPSVI.fDeclaration = currDecl;
  +            if (currDecl != null && currDecl.fDefault != null)
  +                attrPSVI.fSchemaDefault = currDecl.fDefault.normalizedValue;
  +            // PSVI: attribute type
  +            attrPSVI.fTypeDecl = attDV;
  +
  +            // PSVI: attribute memberType
  +            attrPSVI.fMemberType = fValidatedInfo.memberType;
  +            // PSVI: attribute normalized value
  +            // NOTE: we always store the normalized value, even if it's invlid,
  +            // because it might still be useful to the user. But when the it's
  +            // not valid, the normalized value is not trustable.
  +            attrPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
  +
  +            // PSVI: validation attempted:
  +            attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  +
  +            String[] errors = fXSIErrorReporter.mergeContext();
  +            // PSVI: error codes
  +            attrPSVI.fErrorCodes = errors;
  +            // PSVI: validity
  +            attrPSVI.fValidity = (errors == null) ?
  +                                 AttributePSVI.VALIDITY_VALID :
  +                                 AttributePSVI.VALIDITY_INVALID;
  +        }
       }
   
       void addDefaultAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) {
  @@ -2614,18 +2614,20 @@
                       attrs.setSchemaId(attrIndex, schemaId);
                   }
   
  -                // PSVI: attribute is "schema" specified
  -                Augmentations augs = attributes.getAugmentations(attrIndex);
  -
  -                AttributePSVImpl attrPSVI = new AttributePSVImpl();
  -                augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  -
  -                attrPSVI.fNormalizedValue = normalized;
  -                attrPSVI.fSchemaDefault = normalized;
  -                attrPSVI.fValidationContext = fValidationRoot;
  -                attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID;
  -                attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  -                attrPSVI.fSpecified = false;
  +                if (fAugPSVI) {
  +                    // PSVI: attribute is "schema" specified
  +                    Augmentations augs = attributes.getAugmentations(attrIndex);
  +
  +                    AttributePSVImpl attrPSVI = new AttributePSVImpl();
  +                    augs.putItem(Constants.ATTRIBUTE_PSVI, attrPSVI);
  +
  +                    attrPSVI.fNormalizedValue = normalized;
  +                    attrPSVI.fSchemaDefault = normalized;
  +                    attrPSVI.fValidationContext = fValidationRoot;
  +                    attrPSVI.fValidity = AttributePSVI.VALIDITY_VALID;
  +                    attrPSVI.fValidationAttempted = AttributePSVI.VALIDATION_FULL;
  +                    attrPSVI.fSpecified = true;
  +                }
               }
   
           } // for
  @@ -2636,16 +2638,11 @@
        *  {value constraint} on the corresponding element decl, then return
        *  an XMLString representing the default value.
        */
  -    XMLString processElementContent(QName element) {
  -        // fCurrentElemDecl: default value; ...
  -        XMLString defaultValue = null;
  +    void processElementContent(QName element) {
           // 1 If the item is ?valid? with respect to an element declaration as per Element Locally Valid (Element) (?3.3.4) and the {value constraint} is present, but clause 3.2 of Element Locally Valid (Element) (?3.3.4) above is not satisfied and the item has no element or character information item [children], then schema. Furthermore, the post-schema-validation infoset has the canonical lexical representation of the {value constraint} value as the item's [schema normalized value] property.
           if (fCurrentElemDecl != null && fCurrentElemDecl.fDefault != null &&
               fBuffer.length() == 0 && fChildCount == 0 && !fNil) {
   
  -            // PSVI: specified
  -            fCurrentPSVI.fSpecified = false;
  -
               int bufLen = fCurrentElemDecl.fDefault.normalizedValue.length();
               if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) {
                   fNormalizedStr.ch = new char[bufLen];
  @@ -2653,25 +2650,23 @@
               fCurrentElemDecl.fDefault.normalizedValue.getChars(0, bufLen, fNormalizedStr.ch, 0);
               fNormalizedStr.offset = 0;
               fNormalizedStr.length = bufLen;
  -            defaultValue = fNormalizedStr;
  +            fDefaultValue = fNormalizedStr;
           }
           // fixed values are handled later, after xsi:type determined.
   
           String content = fBuffer.toString();
           fValidatedInfo.normalizedValue = null;
  -        
  +
           // Element Locally Valid (Element)
           // 3.2.1 The element information item must have no character or element information item [children].
           if (fNil) {
               if (fChildCount != 0 || content.length() != 0){
                   reportSchemaError("cvc-elt.3.2.1", new Object[]{element.rawname, SchemaSymbols.URI_XSI+","+SchemaSymbols.XSI_NIL});
  -                // PSVI: nil
  -                fCurrentPSVI.fNil = false;
  -            } else {
  -                fCurrentPSVI.fNil = true;
               }
           }
   
  +        this.fValidatedInfo.reset();
  +        
           // 5 The appropriate case among the following must be true:
           // 5.1 If the declaration has a {value constraint}, the item has neither element nor character [children] and clause 3.2 has not applied, then all of the following must be true:
           if (fCurrentElemDecl != null &&
  @@ -2729,12 +2724,12 @@
               }
           }
   
  -        if (defaultValue == null && fNormalizeData &&
  +        if (fDefaultValue == null && fNormalizeData &&
               fDocumentHandler != null && fUnionType) {
               // for union types we need to send data because we delayed sending
               // this data when we received it in the characters() call.
               if (fValidatedInfo.normalizedValue != null)
  -               content = fValidatedInfo.normalizedValue;
  +                content = fValidatedInfo.normalizedValue;
               int bufLen = content.length();
               if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < bufLen) {
                   fNormalizedStr.ch = new char[bufLen];
  @@ -2744,8 +2739,14 @@
               fNormalizedStr.length = bufLen;
               fDocumentHandler.characters(fNormalizedStr, null);
           }
  -
  -        return defaultValue;
  +        
  +        if (fAugPSVI) {
  +            if (this.fDefaultValue != null)
  +                fCurrentPSVI.fSpecified = true;
  +            fCurrentPSVI.fNil = fNil;
  +            fCurrentPSVI.fMemberType = fValidatedInfo.memberType;
  +            fCurrentPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
  +        }
       } // processElementContent
   
       Object elementLocallyValidType(QName element, String textContent) {
  @@ -2768,11 +2769,6 @@
                           fValidationState.setNormalizationRequired(true);
                       }
                       retValue = dv.validate(textContent, fValidationState, fValidatedInfo);
  -                    // PSVI: schema normalized value
  -                    //
  -                    fCurrentPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
  -                    // PSVI: memberType
  -                    fCurrentPSVI.fMemberType = fValidatedInfo.memberType;
                   }
                   catch (InvalidDatatypeValueException e) {
                       reportSchemaError(e.getKey(), e.getArgs());
  @@ -2812,9 +2808,6 @@
                           fValidationState.setNormalizationRequired(true);
                       }
                       actualValue = dv.validate(textContent, fValidationState, fValidatedInfo);
  -
  -                    // PSVI: memberType
  -                    fCurrentPSVI.fMemberType = fValidatedInfo.memberType;
                   }
                   catch (InvalidDatatypeValueException e) {
                       reportSchemaError(e.getKey(), e.getArgs());
  @@ -2822,10 +2815,6 @@
                   }
                   // REVISIT: eventually, this method should return the same actualValue as elementLocallyValidType...
                   // obviously it'll return null when the content is complex.
  -
  -                // PSVI: schema normalized value
  -                //
  -                fCurrentPSVI.fNormalizedValue = fValidatedInfo.normalizedValue;
               }
               // 2.3 If the {content type} is element-only, then the element information item has no character information item [children] other than those whose [character code] is defined as a white space in [XML 1.0 (Second Edition)].
               else if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
  @@ -2853,8 +2842,8 @@
       void reportSchemaError(String key, Object[] arguments) {
           if (fDoValidation)
               fXSIErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  -                                          key, arguments,
  -                                          XMLErrorReporter.SEVERITY_ERROR);
  +                    key, arguments,
  +                    XMLErrorReporter.SEVERITY_ERROR);
       }
   
       /**********************************/
  
  
  

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