sandygao    2004/02/03 07:45:23

  Modified:    java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
  Log:
  Fixing bug [26480]: when a child element matches a strict wildcard and there
  is no corresponding global element decl for it, it's an error on the parent
  element, not the sub-element itself.
  
  Another bug is also fixed: when a sub-tree is skipped, for its root, we don't
  need to push context for the xsi error reporter. No error will occur (because
  it's skipped), and because we don't pop context at the end, push/pop won't
  be in sync.
  
  Revision  Changes    Path
  1.150     +35 -15    
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.149
  retrieving revision 1.150
  diff -u -r1.149 -r1.150
  --- XMLSchemaValidator.java   14 Nov 2003 09:25:12 -0000      1.149
  +++ XMLSchemaValidator.java   3 Feb 2004 15:45:23 -0000       1.150
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999-2003 The Apache Software Foundation.
  + * Copyright (c) 1999-2004 The Apache Software Foundation.
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -1764,9 +1764,6 @@
                        }
                }
   
  -             // push error reporter context: record the current position
  -             fXSIErrorReporter.pushContext();
  -
                // if it's not the root element, we push the current states in the 
stacks
                if (fElementDepth != -1) {
                        ensureStackCapacity();
  @@ -1827,11 +1824,6 @@
                        }
                }
   
  -             // Element Locally Valid (Element)
  -             // 2 Its {abstract} must be false.
  -             if (fCurrentElemDecl != null && fCurrentElemDecl.getAbstract())
  -                     reportSchemaError("cvc-elt.2", new Object[] { element.rawname 
});
  -
                if (fCurrentElemDecl != null) {
                        // then get the type
                        fCurrentType = fCurrentElemDecl.fType;
  @@ -1839,11 +1831,9 @@
   
                // get type from xsi:type
                String xsiType = attributes.getValue(SchemaSymbols.URI_XSI, 
SchemaSymbols.XSI_TYPE);
  -             if (xsiType != null)
  -                     fCurrentType = getAndCheckXsiType(element, xsiType, 
attributes);
   
  -             // if the element decl is not found
  -             if (fCurrentType == null) {
  +        // if no decl/type found for the current element
  +        if (fCurrentType == null && xsiType == null) {
                        // 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?
  @@ -1883,7 +1873,9 @@
                                        new Object[] { element.rawname },
                                        XMLErrorReporter.SEVERITY_ERROR);
                        }
  -                     // if wildcard = strict, report error
  +            // if wildcard = strict, report error.
  +            // needs to be called before fXSIErrorReporter.pushContext()
  +            // so that the error belongs to the parent element.
                        else if (wildcard != null && wildcard.fProcessContents == 
XSWildcardDecl.PC_STRICT) {
                                // report error, because wilcard = strict
                                reportSchemaError("cvc-complex-type.2.4.c", new 
Object[] { element.rawname });
  @@ -1896,7 +1888,30 @@
                        fNFullValidationDepth = fElementDepth;
                        // any type has mixed content, so we don't need to append 
buffer
                        fAppendBuffer = false;
  +
  +            // push error reporter context: record the current position
  +            // This has to happen after we process skip contents,
  +            // otherwise push and pop won't be correctly paired.
  +            fXSIErrorReporter.pushContext();
                } else {
  +            // push error reporter context: record the current position
  +            // This has to happen after we process skip contents,
  +            // otherwise push and pop won't be correctly paired.
  +            fXSIErrorReporter.pushContext();
  +
  +            // get xsi:type
  +            if (xsiType != null) {
  +                XSTypeDefinition oldType = fCurrentType;
  +                fCurrentType = getAndCheckXsiType(element, xsiType, attributes);
  +                // If it fails, use the old type. Use anyType if ther is no old 
type.
  +                if (fCurrentType == null) {
  +                    if (oldType == null)
  +                        fCurrentType = SchemaGrammar.fAnyType;
  +                    else
  +                        fCurrentType = oldType;
  +                }
  +            }
  +
                        fNNoneValidationDepth = fElementDepth;
                        // if the element has a fixed value constraint, we need to 
append
                        if (fCurrentElemDecl != null
  @@ -1912,6 +1927,11 @@
                                fAppendBuffer = (ctype.fContentType == 
XSComplexTypeDecl.CONTENTTYPE_SIMPLE);
                        }
                }
  +
  +        // Element Locally Valid (Element)
  +        // 2 Its {abstract} must be false.
  +        if (fCurrentElemDecl != null && fCurrentElemDecl.getAbstract())
  +            reportSchemaError("cvc-elt.2", new Object[] { element.rawname });
   
                // make the current element validation root
                if (fElementDepth == 0) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to