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/01/23 00:37:27 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/xni/grammars XMLGrammarDescription.java

sandygao    02/01/22 15:37:27

  Modified:    java/src/org/apache/xerces/impl/msg
                        XMLSchemaMessages.properties
               java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDHandler.java XSDocumentInfo.java
               java/src/org/apache/xerces/parsers DOMASBuilderImpl.java
                        DOMBuilderImpl.java
               java/src/org/apache/xerces/xni/grammars
                        XMLGrammarDescription.java
  Added:       java/src/org/apache/xerces/impl/xs XSDDescription.java
  Log:
  Solving many problems related to schema document resolution:
  1. Bug[5849]: can't validate schema documents against the schema for
  schemas;
  2. We failed to report an error when the importing and the imported schema
  documents have the same target namespace;
  3. We failed to report an error when the including and the included schema
  documents have different non-absent target namespaces;
  4. We should use different error codes for similar errors related to importing,
  including, redefining, and reference from the instance document;
  5. We failed to deal with the case where the same schema document without
  a target namespace is included by two other schema documents with
  different target namespaces. We only considered one of the inclusions.
  (Similar problem occurred for <redefine>.)
  6. Bug[4421]: We failed to deal with the case where the same schema
  document (with no target namespace) is both included and imported by the
  same schema document. We only considered the first reference. (Similar problem occurred for <redefine>.)
  7. In DOMASBuilderImpl, we should convert a URI input to an InputSource,
  not the other way around;
  8. If the input is a DOMInputSource, we need to create an XMLInputSource
  accordingly;
  9. For grammar-preparsing methods, we shouldn't call EntityResolver for the
  locations.
  
  Revision  Changes    Path
  1.39      +33 -24    xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
  
  Index: XMLSchemaMessages.properties
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- XMLSchemaMessages.properties	15 Jan 2002 22:22:18 -0000	1.38
  +++ XMLSchemaMessages.properties	22 Jan 2002 23:37:26 -0000	1.39
  @@ -76,7 +76,6 @@
   
   #validation (3.X.4)
   
  -        declaration-not-found = component {0} with name {1} was not found.
           cvc-assess-attr = cvc-assess-attr: error.
           cvc-assess-elt = cvc-assess-elt: error.
           cvc-attribute.1 = cvc-attribute.1: error.
  @@ -90,10 +89,10 @@
           cvc-complex-type.2.3 = cvc-complex-type.2.3: Element ''{0}'' must have no character [children], because the type's content type is element-only.
           cvc-complex-type.2.4.a = cvc-complex-type.2.4.a: Invalid content starting with element ''{0}''. The content must match ''{1}''.
           cvc-complex-type.2.4.b = cvc-complex-type.2.4.b: The content of element ''{0}'' is not complete. It must match ''{1}''.
  -        cvc-complex-type.2.4.c = cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaratoin can be found for element ''{0}''.
  +        cvc-complex-type.2.4.c = cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ''{0}''.
           cvc-complex-type.3.1 = cvc-complex-type.3.1: Value ''{2}'' of attribute ''{1}'' of element ''{0}'' is not valid with repect to the corresponding attribute use.
  -        cvc-complex-type.3.2.1 = cvc-complex-type.3.2.1: Elment ''{0}'' does not have an attribute wildcard for attribute ''{1}''.
  -        cvc-complex-type.3.2.2 = cvc-complex-type.3.2.2: Attribute ''{1}'' is not allowed to appear in elment ''{0}''.
  +        cvc-complex-type.3.2.1 = cvc-complex-type.3.2.1: Element ''{0}'' does not have an attribute wildcard for attribute ''{1}''.
  +        cvc-complex-type.3.2.2 = cvc-complex-type.3.2.2: Attribute ''{1}'' is not allowed to appear in element ''{0}''.
           cvc-complex-type.4 = cvc-complex-type.4: Attribute ''{1}'' must appear on element ''{0}''.
           cvc-complex-type.5.1 = cvc-complex-type.5.1: In element ''{0}'', attribute ''{1}'' is a Wild ID. But there is already a Wild ID ''{2}''.
           cvc-complex-type.5.2 = cvc-complex-type.5.2: In element ''{0}'', attribute ''{1}'' is a Wild ID. But there is already a attribute ''{2}'' from the attribute uses.
  @@ -146,19 +145,9 @@
           cvc-wildcard = cvc-wildcard: error.
           cvc-wildcard-namespace = cvc-wildcard-namespace: error.
   
  -#schema for Schemas
  -
  -        s4s-att-not-allowed = s4s-att-not-allowed: Attribute ''{1}'' cannot appear in element ''{0}''.
  -        s4s-att-must-appear = s4s-att-must-appear: Attribute ''{1}'' must appear in element ''{0}''.
  -        s4s-att-invalid-value = s4s-att-invalid-value: Invalid attribute value for ''{1}'' in element ''{0}'': {2}.
  -        s4s-elt-schema-ns = s4s-elt-schema-ns: The namespace of element ''{0}'' must be from the schema namespace.
  -        s4s-elt-invalid = s4s-elt-invalid: Element ''{0}'' is not a valid element in schema document.
  -        s4s-elt-must-match = s4s-elt-must-match: The content of ''{0}'' must match {1}.
  -
   #schema valid (3.X.3)
   
  -        sch-props-correct = Duplicate declaration for an element ''{0}''
  -        schema_reference.4 = schema_reference.4: Failed to read schema document ''{0}''.
  +        schema_reference.4 = schema_reference.4: Failed to read schema document ''{0}'', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
           src-annotation = src-annotation: can only contain <appinfo> and <documentation> elements.
           src-attribute.1 = src-attribute.1: ''default'' and ''fixed'' must not both be present in attribute declaration ''{0}''.
           src-attribute.2 = src-attribute.2: : ''default'' is present in attribute ''{0}'', so ''use'' must be ''optional''.
  @@ -181,8 +170,12 @@
           src-identity-constraint.1 = src-identity-constraint.1: a ''<selector>'' or a ''<field>'' element can contain at most one ''<annotation>'' in its content; identity constraint ''{0}'' violates this constraint.
           src-import.0 = src-import.0: Failed to read imported schema document ''{0}''.
           src-import.1.1 = src-import.1.1: The namespace attribute ''{0}'' of an <import> element information item must not be the same as the targetNamespace of the schema it exists in.
  +        src-import.2 = src-import.2: The root element of document ''{0}'' is not <xsd:schema>.
  +        src-import.3.1 = src-import.3.1: The namespace attribute ''{0}'' of an <import> element information item must be identical to the targetNamespace attribute ''{1}'' of the imported document.
  +        src-import.3.2 = src-import.3.2: There is no namespace attribute on the <import> element information item, so the imported document must have no targetNamespace attribute.
           src-include.0 = src-include.0: Failed to read included schema document ''{0}''.
  -        src-include.2 = src-include.2: the targetNamespace of the schema ''{0}'' must be identical to that of the including or redefining schema (''{1}'').
  +        src-include.1 = src-include.1: The root element of document ''{0}'' is not <xsd:schema>.
  +        src-include.2.1 = src-include.2.1: the targetNamespace of the schema ''{1}'' must be identical to that of the including schema ''{0}''.
           src-list-itemType-or-simpleType = src-list-itemType-or-simpleType: error.
           src-model_group = src-model_group: error.
           src-model_group_defn = src-model_group_defn: error.
  @@ -191,7 +184,9 @@
           src-notation = src-notation: {0}.
           src-qname = src-qname: error.
           src-redefine.0 = src-redefine.0: Failed to read redefined schema document ''{0}''.
  -        src-redefine.1 = src-redefine.1: the component ''{0}'' occurs in a schema different from that which was redefined.
  +        src-redefine.1 = src-redefine.1: The component ''{0}'' occurs in a schema different from that which was redefined.
  +        src-redefine.2 = src-redefine.2: The root element of document ''{0}'' is not <xsd:schema>.
  +        src-redefine.3.1 = src-redefine.3.1: the targetNamespace of the schema ''{1}'' must be identical to that of the redefining schema ''{0}''.
           src-redefine.5 = src-redefine.5: <simpleType> or <complexType> children of <redefine> elements must have <extension> or <restriction> descendants referring to themselves.
           src-redefine = src-redefine: A <redefine> element cannot contain a child of type ''{0}''.
           src-redefine.6.1.1 = src-redefine.6.1.1:  if a group child of a <redefine> element contains a group ref'ing itself, it must have exactly 1; this one has ''{0}''.
  @@ -335,6 +330,7 @@
           rcase-RecurseUnordered = rcase-RecurseUnordered: error.
           rcase-RecurseUnordered.1 = rcase-RecurseUnordered.1: Group''s occurrence range is not a valid restriction of base group''s occurrence range.
           rcase-RecurseUnordered.2 = rcase-RecurseUnordered.2: There is not a complete functional mapping between the particles.
  +        sch-props-correct = sch-props-correct: Duplicate declaration for an element ''{0}''
           sch-props-correct.1 = sch-props-correct.1: schema components of type ''{0}'' cannot occur after declarations or are not permitted as children of a <schema> element.
           sch-props-correct.2 = sch-props-correct.2: a schema cannot contain two global components with the same name; this one contains two occurrences of ''{0}''.
           st-props-correct.1 = st-props-correct.1: error.
  @@ -348,21 +344,34 @@
           whiteSpace-valid-restriction.2 = whiteSpace-valid-restriction.2: It is an error if whiteSpace = ''preserve'' and fBase.whiteSpace = ''replace''.
           w-props-correct = w-props-correct: error.
   
  +#schema for Schemas
  +
  +        s4s-att-not-allowed = s4s-att-not-allowed: Attribute ''{1}'' cannot appear in element ''{0}''.
  +        s4s-att-must-appear = s4s-att-must-appear: Attribute ''{1}'' must appear in element ''{0}''.
  +        s4s-att-invalid-value = s4s-att-invalid-value: Invalid attribute value for ''{1}'' in element ''{0}'': {2}.
  +        s4s-elt-schema-ns = s4s-elt-schema-ns: The namespace of element ''{0}'' must be from the schema namespace.
  +        s4s-elt-invalid = s4s-elt-invalid: Element ''{0}'' is not a valid element in schema document.
  +        s4s-elt-must-match = s4s-elt-must-match: The content of ''{0}'' must match {1}.
  +
   # codes not defined by the spec
   
  -    FacetValueFromBase = Value ''{0}'' of facet ''{1}'' must from the value space of the base type.
  +    declaration-not-found = declaration-not-found: component {0} with name {1} was not found.
  +    EmptyTargetNamespace = EmptyTargetNamespace: In schea document ''{0}'', the value of the targetNamespace attribute cannot be empty string.
  +    FacetValueFromBase = FacetValueFromBase: Value ''{0}'' of facet ''{1}'' must from the value space of the base type.
       FixedFacetValue = FixedFacetValue: ''{0}'' value = ''{1}'' must be equal to that of the base type ''{2}'' when {fixed} = true.
  -    InvalidRegex = Pattern value ''{0}'' is not a valid regular expression: ''{1}''.
  -    SchemaLocation = schemaLocation value = ''{0}'' must have even number of URI''s.
  -    UndeclaredPrefix = Cannot resolve ''{0}'' as a QName: the prefix ''{1}'' is not declared.
  -    UndeclaredEntity = Entity ''{0}'' is not declared.
  -    ValidationRoot = Validation Root Valid (ID/IDREF) (�3.3.4): validation was not successful.
  +    InvalidRegex = InvalidRegex: Pattern value ''{0}'' is not a valid regular expression: ''{1}''.
  +    SchemaLocation = SchemaLocation: schemaLocation value = ''{0}'' must have even number of URI''s.
  +    TargetNamespace.1 = TargetNamespace.1: Expecting namespace ''{0}'', but the target namespace of the schema document is ''{1}''.
  +    TargetNamespace.2 = TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace.
  +    UndeclaredPrefix = UndeclaredPrefix: Cannot resolve ''{0}'' as a QName: the prefix ''{1}'' is not declared.
  +    UndeclaredEntity = UndeclaredEntity: Entity ''{0}'' is not declared.
  +    ValidationRoot = ValidationRoot: Validation Root Valid (ID/IDREF) (�3.3.4): validation was not successful.
   
   # SimpleTypes
      ListUnionRestrictionError = List | Union | Restriction content is invalid for type ''{0}''
      dt-unsupported-derivation =  Derivation of type {0} is unsupported.
      dt-simpleType = The content of ''{0}'' named ''{1}'' must match {2}.
  -   dt-unknown-basetype  = Unknown base type ''{0}'' for a type ''{1}''
  +   dt-unknown-basetype = Unknown base type ''{0}'' for a type ''{1}''
      dt-restiction-final = the base type ''{0}'' does not allow itself to be used as the base for a restriction and/or as a type in a list and/or union
      dt-list-itemType = Datatypes 4.1.3: error in the simpleType ''{0}'' itemType attribute or simpleType child constraint
      dt-restriction-base = Datatypes 4.1.3: error in the simpleType ''{0}'' base attribute or simpleType child constraint
  
  
  
  1.35      +19 -8     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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- XMLSchemaValidator.java	22 Jan 2002 16:42:26 -0000	1.34
  +++ XMLSchemaValidator.java	22 Jan 2002 23:37:26 -0000	1.35
  @@ -128,7 +128,7 @@
    * @author Elena Litani IBM
    * @author Andy Clark IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
  - * @version $Id: XMLSchemaValidator.java,v 1.34 2002/01/22 16:42:26 neilg Exp $
  + * @version $Id: XMLSchemaValidator.java,v 1.35 2002/01/22 23:37:26 sandygao Exp $
    */
   public class XMLSchemaValidator
                implements XMLComponent, XMLDocumentFilter, FieldActivator {
  @@ -1052,7 +1052,6 @@
   
           // clear grammars, and put the one for schema namespace there
           fGrammarBucket.reset();
  -        fGrammarBucket.putGrammar(URI_SCHEMAFORSCHEMA, SchemaGrammar.SG_SchemaNS);
           fGrammarPool = (XMLGrammarPool)componentManager.getProperty(XMLGRAMMAR_POOL);
           if(fGrammarPool instanceof XMLGrammarPoolImpl) {
               XMLGrammarPoolImpl poolImpl = (XMLGrammarPoolImpl)fGrammarPool;
  @@ -1440,6 +1439,7 @@
               }
               // no element decl or type found for this element.
               // if there is a validation root, then skip the whole element
  +            // because we choose not to do lax acssessment
               // otherwise, don't skip sub-elements
               if (fValidationRootDepth >= 0)
                   fSkipValidationDepth = fElementDepth;
  @@ -1721,13 +1721,16 @@
                       break;
                   }
                   location = t.nextToken();
  -                if (fGrammarBucket.getGrammar(namespace) == null)
  -                    fSchemaHandler.parseSchema(namespace, location);
  +                if (fGrammarBucket.getGrammar(namespace) == null) {
  +                    fSchemaHandler.parseSchema(namespace, location,
  +                                               XSDDescription.CONTEXT_INSTANCE);
  +                }
               }
           }
           if (nsLocation != null) {
               if (fGrammarBucket.getGrammar(null) == null)
  -                fSchemaHandler.parseSchema(null, nsLocation);
  +                fSchemaHandler.parseSchema(null, nsLocation,
  +                                           XSDDescription.CONTEXT_INSTANCE);
           }
       }
   
  @@ -1749,9 +1752,17 @@
   
           // 4.2 The local name and namespace name (as defined in QName Interpretation (3.15.3)), of the actual value of that attribute information item must resolve to a type definition, as defined in QName resolution (Instance) (3.15.4)
           XSTypeDecl type = null;
  -        SchemaGrammar grammar = fGrammarBucket.getGrammar(typeName.uri);
  -        if (grammar != null)
  -            type = grammar.getGlobalTypeDecl(typeName.localpart);
  +        // if the namespace is schema namespace, first try built-in types
  +        if (typeName.uri == URI_SCHEMAFORSCHEMA) {
  +            type = SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(typeName.localpart);
  +        }
  +        // if it's not schema built-in types, then try to get a grammar
  +        if (type == null) {
  +            SchemaGrammar grammar = fGrammarBucket.getGrammar(typeName.uri);
  +            if (grammar != null)
  +                type = grammar.getGlobalTypeDecl(typeName.localpart);
  +        }
  +        // still couldn't find the type, report an error
           if (type == null) {
               reportSchemaError("cvc-elt.4.2", new Object[]{element.rawname, xsiType});
               return;
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/xs/XSDDescription.java
  
  Index: XSDDescription.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2002 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.impl.xs;
  
  import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  import org.apache.xerces.xni.QName;
  import org.apache.xerces.xni.XMLAttributes;
  
  /*
   * All information specific to XML Schema grammars.
   *
   * @author Neil Graham, IBM
   * @version $Id: XSDDescription.java,v 1.1 2002/01/22 23:37:26 sandygao Exp $
   */
  public class XSDDescription implements XMLGrammarDescription {
      // used to indicate what triggered the call
      /**
       * Indicate that the current schema document is <include>d by another
       * schema document.
       */
      public final static short CONTEXT_INCLUDE   = 0;
      /**
       * Indicate that the current schema document is <redefine>d by another
       * schema document.
       */
      public final static short CONTEXT_REDEFINE  = 1;
      /**
       * Indicate that the current schema document is <import>ed by another
       * schema document.
       */
      public final static short CONTEXT_IMPORT    = 2;
      /**
       * Indicate that the current schema document is being preparsed.
       */
      public final static short CONTEXT_PREPARSE  = 3;
      /**
       * Indicate that the parse of the current schema document is triggered
       * by xsi:schemaLocation/noNamespaceSchemaLocation attribute(s) in the
       * instance document. This value is only used if we don't defer the loading
       * of schema documents.
       */
      public final static short CONTEXT_INSTANCE  = 4;
      /**
       * Indicate that the parse of the current schema document is triggered by
       * the occurrence of an element whose namespace is the target namespace
       * of this schema document. This value is only used if we do defer the
       * loading of schema documents until a component from that namespace is
       * referenced from the instance.
       */
      public final static short CONTEXT_ELEMENT   = 5;
      /**
       * Indicate that the parse of the current schema document is triggered by
       * the occurrence of an attribute whose namespace is the target namespace
       * of this schema document. This value is only used if we do defer the
       * loading of schema documents until a component from that namespace is
       * referenced from the instance.
       */
      public final static short CONTEXT_ATTRIBUTE = 6;
      /**
       * Indicate that the parse of the current schema document is triggered by
       * the occurrence of an "xsi:type" attribute, whose value (a QName) has
       * the target namespace of this schema document as its namespace.
       * This value is only used if we do defer the loading of schema documents
       * until a component from that namespace is referenced from the instance.
       */
      public final static short CONTEXT_XSITYPE   = 7;
  
      /** Returns the public identifier. */
      public String getPublicId() {
          return null;
      }
  
      /** Returns the expanded system identifier. */
      public String getExpandedSystemId() {
          return null;
      }
  
      /** Returns the literal system identifier. */
      public String getLiteralSystemId() {
          return null;
      }
  
      /** <p> Returns the base URI against which the literal SystemId is to be 
          resolved. </p> */
      public String getBaseSystemId() {
          return null;
      }
  
      /**
       * the type of the grammar (e.g., DTD or XSD);
       *  
       * @see org.apache.xerces.xni.grammars.Grammar
       */
      public String getGrammarType() {
          return null;
      }
  
      /**
       * Get the context. The returned value is one of the pre-defined
       * CONTEXT_xxx constants.
       * 
       * @return  the value indicating the context
       */
      public short getContextType() {
          return 0;
      }
  
      /**
       * If the context is "include" or "redefine", then return the target
       * namespace of the enclosing schema document; otherwise, the expected
       * target namespace of this document.
       * 
       * @return  the expected/enclosing target namespace
       */
      public String getTargetNamespace() {
          return null;
      }
  
      /**
       * For import and references from the instance document, it's possible to
       * have multiple hints for one namespace. So this method returns an array,
       * which contains all location hints.
       * 
       * @return  an array of all location hints associated to the expected
       *          target namespace
       */
      public String[] getLocationHints() {
          return null;
      }
  
      /**
       * If a call is triggered by an element/attribute/xsi:type in the instance,
       * this call returns the name of such triggering component: the name of
       * the element/attribute, or the value of the xsi:type.
       * 
       * @return  the name of the triggering component
       */
      public QName getTriggeringComponent() {
          return null;
      }
  
      /**
       * If a call is triggered by an attribute or xsi:type, then this mehtod
       * returns the enclosing element of such element.
       * 
       * @return  the name of the enclosing element
       */
      public QName getEnclosingElementName() {
          return null;
      }
      
      /**
       * If a call is triggered by an element/attribute/xsi:type in the instance,
       * this call returns all attribute of such element (or enclosing element).
       * 
       * @return  all attributes of the tiggering/enclosing element
       */
      public XMLAttributes getAttributes() {
          return null;
      }
      
  } // XSDDescription
  
  
  
  1.16      +182 -45   xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java
  
  Index: XSDHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XSDHandler.java	17 Jan 2002 23:54:59 -0000	1.15
  +++ XSDHandler.java	22 Jan 2002 23:37:26 -0000	1.16
  @@ -66,6 +66,8 @@
   import org.apache.xerces.impl.xs.SchemaSymbols;
   import org.apache.xerces.impl.xs.XSMessageFormatter;
   import org.apache.xerces.impl.xs.XMLSchemaValidator;
  +import org.apache.xerces.impl.xs.XSDDescription;
  +import org.apache.xerces.impl.xs.XMLSchemaException;
   import org.apache.xerces.parsers.StandardParserConfiguration;
   import org.apache.xerces.impl.XMLErrorReporter;
   import org.apache.xerces.impl.XMLEntityManager;
  @@ -97,7 +99,7 @@
    * schema, other grammars may be constructed as a side-effect.
    *
    * @author Neil Graham, IBM
  - * @version $Id: XSDHandler.java,v 1.15 2002/01/17 23:54:59 neilg Exp $
  + * @version $Id: XSDHandler.java,v 1.16 2002/01/22 23:37:26 sandygao Exp $
    */
   
   public class XSDHandler {
  @@ -162,7 +164,7 @@
       // schema document.  This combination is used so that the user's
       // EntityResolver can provide a consistent way of identifying a
       // schema document that is included in multiple other schemas.
  -    private SymbolHash fTraversed = new SymbolHash();
  +    private Hashtable fTraversed = new Hashtable();
   
       // this hashtable contains a mapping from Document to its systemId
       // this is useful to resolve a uri relative to the referring document
  @@ -341,10 +343,22 @@
       // already have been set; the last thing this method does is reset
       // this object (i.e., clean the registries, etc.).
       public SchemaGrammar parseSchema(String schemaNamespace,
  -                                     String schemaHint) {
  +                                     String schemaHint, short referType) {
  +        XMLInputSource schemaSource=null;
  +        try {
  +            schemaSource = fLocationResolver.resolveEntity(schemaNamespace, schemaHint, null, true);
  +        }
  +        catch (IOException ex) {
  +            reportSchemaError(DOC_ERROR_CODES[referType], new Object[]{schemaHint});
  +        }
  +        return parseSchema(schemaNamespace, schemaSource, XSDDescription.CONTEXT_INSTANCE);
  +    } // end parseSchema
   
  +    public SchemaGrammar parseSchema(String schemaNamespace,
  +                                     XMLInputSource is, short referType) {
  +        
           // first phase:  construct trees.
  -        Document schemaRoot = getSchema(schemaNamespace, schemaHint, null, true, INSTANCE);
  +        Document schemaRoot = getSchema(schemaNamespace, is, true, referType);
           if (schemaRoot == null) {
               // something went wrong right off the hop
               return null;
  @@ -353,7 +367,7 @@
           if (schemaNamespace != null) {
               schemaNamespace = fSymbolTable.addSymbol(schemaNamespace);
           }
  -        fRoot = constructTrees(schemaRoot, schemaNamespace);
  +        fRoot = constructTrees(schemaRoot, is.getSystemId(), schemaNamespace, referType);
           if (fRoot == null) {
               // REVISIT:  something went wrong; print error about no schema found
               return null;
  @@ -382,6 +396,22 @@
       // may wish to have setter methods for ErrorHandler,
       // EntityResolver...
   
  +    private static String[][] NS_ERROR_CODES = {
  +        {"src-include.2.1", "src-include.2.1"},
  +        {"src-redefine.3.1", "src-redefine.3.1"},
  +        {"src-import.3.1", "src-import.3.2"},
  +        null,
  +        {"TargetNamespace.1", "TargetNamespace.2"},
  +        {"TargetNamespace.1", "TargetNamespace.2"},
  +        {"TargetNamespace.1", "TargetNamespace.2"},
  +        {"TargetNamespace.1", "TargetNamespace.2"}
  +    };
  +    
  +    private static String[] ELE_ERROR_CODES = {
  +        "src-include.1", "src-redefine.2", "src-import.2", "schema_reference.4",
  +        "schema_reference.4", "schema_reference.4", "schema_reference.4", "schema_reference.4"
  +    };
  +    
       // This method does several things:
       // It constructs an instance of an XSDocumentInfo object using the
       // schemaRoot node.  Then, for each <include>,
  @@ -392,28 +422,78 @@
       // depends on.
       // It also makes sure the targetNamespace of the schema it was
       // called to parse is correct.
  -    protected XSDocumentInfo constructTrees(Document schemaRoot, String callerTNS) {
  +    protected XSDocumentInfo constructTrees(Document schemaRoot, String locationHint, String callerTNS, short referType) {
           if (schemaRoot == null) return null;
  -        XSDocumentInfo currSchemaInfo = new XSDocumentInfo(schemaRoot, fAttributeChecker, fSymbolTable);
  -
  -        // Modified by Pavani Mukthipudi, Sun Microsystems Inc.
  -        fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
  +        XSDocumentInfo currSchemaInfo = null;
  +        try {
  +            currSchemaInfo = new XSDocumentInfo(schemaRoot, fAttributeChecker, fSymbolTable);
  +        } catch (XMLSchemaException se) {
  +            reportSchemaError(ELE_ERROR_CODES[referType], new Object[]{locationHint});
  +            return null;
  +        }
  +        // targetNamespace="" is not valid, issue a warning, and ignore it
  +        if (currSchemaInfo.fTargetNamespace != null &&
  +            currSchemaInfo.fTargetNamespace.length() == 0) {
  +            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                       "EmptyTargetNamespace",
  +                                       new Object[]{locationHint},
  +                                       XMLErrorReporter.SEVERITY_WARNING);
  +            currSchemaInfo.fTargetNamespace = null;
  +        }
   
           if (callerTNS != null) {
  -            // only set if we were included or redefined in.
  -            if (currSchemaInfo.fTargetNamespace == null) {
  -                currSchemaInfo.fTargetNamespace = callerTNS;
  -                currSchemaInfo.fIsChameleonSchema = true;
  +            // the second index to the NS_ERROR_CODES array
  +            // if the caller/expected NS is not absent, we use the first column
  +            int secondIdx = 0;
  +            // for include and redefine
  +            if (referType == XSDDescription.CONTEXT_INCLUDE ||
  +                referType == XSDDescription.CONTEXT_REDEFINE) {
  +                // if the referred document has no targetNamespace,
  +                // it's a chameleon schema
  +                if (currSchemaInfo.fTargetNamespace == null) {
  +                    currSchemaInfo.fTargetNamespace = callerTNS;
  +                    currSchemaInfo.fIsChameleonSchema = true;
  +                }
  +                // if the referred document has a target namespace differing
  +                // from the caller, it's an error
  +                else if (callerTNS != currSchemaInfo.fTargetNamespace) {
  +                    reportSchemaError(NS_ERROR_CODES[referType][secondIdx],
  +                                      new Object [] {callerTNS, currSchemaInfo.fTargetNamespace});
  +                }
               }
  +            // for preparse, callerTNS is null, so it's not possible
  +            // for instance and import, the two NS's must be the same
               else if (callerTNS != currSchemaInfo.fTargetNamespace) {
  -                reportSchemaError("src-include.2", new Object [] {callerTNS, currSchemaInfo.fTargetNamespace});
  +                reportSchemaError(NS_ERROR_CODES[referType][secondIdx],
  +                                  new Object [] {callerTNS, currSchemaInfo.fTargetNamespace});
               }
           }
  -        SchemaGrammar sg = null;
  -        if ((sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace)) == null) {
  -            sg = new SchemaGrammar(fSymbolTable, currSchemaInfo.fTargetNamespace);
  +        // now there is no caller/expected NS, it's an error for the referred
  +        // document to have a target namespace, unless we are preparsing a schema
  +        else if (currSchemaInfo.fTargetNamespace != null &&
  +                 referType != XSDDescription.CONTEXT_PREPARSE) {
  +            // the second index to the NS_ERROR_CODES array
  +            // if the caller/expected NS is absent, we use the second column
  +            int secondIdx = 1;
  +            reportSchemaError(NS_ERROR_CODES[referType][secondIdx],
  +                              new Object [] {callerTNS, currSchemaInfo.fTargetNamespace});
  +        }
  +        // the other cases (callerTNS == currSchemaInfo.fTargetNamespce == null)
  +        // are valid
  +        
  +        if (fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace) == null) {
  +            SchemaGrammar sg = new SchemaGrammar(fSymbolTable, currSchemaInfo.fTargetNamespace);
               fGrammarBucket.putGrammar(sg);
           }
  +        // we got a grammar of the samenamespace in the bucket, should ignore this one
  +        else if (referType == XSDDescription.CONTEXT_INSTANCE ||
  +                 referType == XSDDescription.CONTEXT_IMPORT ||
  +                 referType == XSDDescription.CONTEXT_PREPARSE) {
  +            return null;
  +        }
  +
  +        // Modified by Pavani Mukthipudi, Sun Microsystems Inc.
  +        fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
   
           Vector dependencies = new Vector();
           Element rootNode = DOMUtil.getRoot(schemaRoot);
  @@ -425,9 +505,13 @@
               String schemaNamespace=null;
               String schemaHint=null;
               String localName = DOMUtil.getLocalName(child);
  +            
  +            short refType = -1;
  +            
               if (localName.equals(SchemaSymbols.ELT_ANNOTATION))
                   continue;
               else if (localName.equals(SchemaSymbols.ELT_IMPORT)) {
  +                refType = XSDDescription.CONTEXT_IMPORT;
                   // have to handle some validation here too!
                   // call XSAttributeChecker to fill in attrs
                   Object[] includeAttrs = fAttributeChecker.checkAttributes(child, true, currSchemaInfo);
  @@ -441,7 +525,7 @@
                   fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo);
                   // consciously throw away whether was a duplicate; don't care.
                   // pass the systemId of the current document as the base systemId
  -                newSchemaRoot = getSchema(schemaNamespace, schemaHint, (String)fDoc2SystemId.get(schemaRoot), false, IMPORT);
  +                newSchemaRoot = getSchema(schemaNamespace, schemaHint, (String)fDoc2SystemId.get(schemaRoot), false, XSDDescription.CONTEXT_IMPORT);
               }
               else if ((localName.equals(SchemaSymbols.ELT_INCLUDE)) ||
                        (localName.equals(SchemaSymbols.ELT_REDEFINE))) {
  @@ -454,15 +538,15 @@
                   // schemaLocation is required on <include> and <redefine>
                   if (schemaHint == null)
                       reportSchemaError("s4s-att-must-appear", new Object [] {
  -                            "<include> or <redefine>", "schemaLocation"});
  +                                      "<include> or <redefine>", "schemaLocation"});
                   // pass the systemId of the current document as the base systemId
                   boolean mustResolve = false;
  -                short referType = INCLUDE;
  +                refType = XSDDescription.CONTEXT_INCLUDE;
                   if(localName.equals(SchemaSymbols.ELT_REDEFINE)) {
                       mustResolve = nonAnnotationContent(child);
  -                    referType = REDEFINE;
  +                    refType = XSDDescription.CONTEXT_REDEFINE;
                   }
  -                newSchemaRoot = getSchema(null, schemaHint, (String)fDoc2SystemId.get(schemaRoot), mustResolve, referType);
  +                newSchemaRoot = getSchema(null, schemaHint, (String)fDoc2SystemId.get(schemaRoot), mustResolve, refType);
                   schemaNamespace = currSchemaInfo.fTargetNamespace;
               }
               else {
  @@ -483,7 +567,7 @@
                   newSchemaInfo = (XSDocumentInfo)fDoc2XSDocumentMap.get(newSchemaRoot);
               }
               else {
  -                newSchemaInfo = constructTrees(newSchemaRoot, schemaNamespace);
  +                newSchemaInfo = constructTrees(newSchemaRoot, schemaHint, schemaNamespace, refType);
               }
               if (localName.equals(SchemaSymbols.ELT_REDEFINE) &&
                   newSchemaInfo != null) {
  @@ -492,7 +576,8 @@
                   fRedefine2XSDMap.put(child, newSchemaInfo);
               }
               if (newSchemaRoot != null) {
  -                dependencies.addElement(newSchemaInfo);
  +                if (newSchemaInfo != null)
  +                    dependencies.addElement(newSchemaInfo);
                   newSchemaRoot = null;
               }
           }
  @@ -1011,13 +1096,10 @@
           fKeyrefNamespaceContext[fKeyrefStackPos++] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext();
       } // storeKeyref (Element, XSDocumentInfo, XSElementDecl): void
   
  -    // all possible ways of referring to a schema document
  -    private static short INSTANCE = 0;
  -    private static short IMPORT   = 1;
  -    private static short INCLUDE  = 2;
  -    private static short REDEFINE = 3;
  -    private static String[] ERROR_CODES = {"schema_reference.4", "src-import.0",
  -                                           "src-include.0", "src-redefine.0"};
  +    private static String[] DOC_ERROR_CODES = {
  +        "src-include.0", "src-redefine.0", "src-import.0", "schema_reference.4",
  +        "schema_reference.4", "schema_reference.4", "schema_reference.4", "schema_reference.4"
  +    };
       
       // This method is responsible for schema resolution.  If it finds
       // a schema document that the XMLEntityResolver resolves to with
  @@ -1027,12 +1109,28 @@
       // was resolved to.
       private Document getSchema(String schemaNamespace, String schemaHint,
                                  String baseSystemId, boolean mustResolve, short referType) {
  -        // contents of this method will depend on the system we adopt for entity resolution--i.e., XMLEntityHandler, EntityHandler, etc.
           XMLInputSource schemaSource=null;
  -        Document schemaDoc = null;
           try {
               schemaSource = fLocationResolver.resolveEntity(schemaNamespace, schemaHint, baseSystemId,
  -                                                           referType == INSTANCE || referType == IMPORT);
  +                                                           referType == XSDDescription.CONTEXT_INSTANCE ||
  +                                                           referType == XSDDescription.CONTEXT_IMPORT);
  +        }
  +        catch (IOException ex) {
  +            fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  +                                       DOC_ERROR_CODES[referType],
  +                                       new Object[]{schemaHint},
  +                                       mustResolve ?
  +                                       XMLErrorReporter.SEVERITY_ERROR: 
  +                                       XMLErrorReporter.SEVERITY_WARNING); 
  +        }
  +        return getSchema(schemaNamespace, schemaSource, mustResolve, referType);
  +    } // getSchema(String, String, String, boolean, short):  Document
  +
  +    private Document getSchema(String schemaNamespace, XMLInputSource schemaSource,
  +                               boolean mustResolve, short referType) {
  +        // contents of this method will depend on the system we adopt for entity resolution--i.e., XMLEntityHandler, EntityHandler, etc.
  +        Document schemaDoc = null;
  +        try {
               // REVISIT: when the system id and byte stream and character stream
               //          of the input source are all null, it's
               //          impossible to find the schema document. so we skip in
  @@ -1049,12 +1147,14 @@
                   // parsed before. If so, return the document corresponding to
                   // that system id.
                   String schemaId = null;
  +                XSDKey key = null;
                   if (schemaSource.getByteStream() == null &&
                       schemaSource.getCharacterStream() == null) {
                       schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId());
  -                    if (fTraversed.get(schemaId) != null) {
  +                    key = new XSDKey(schemaId, referType, schemaNamespace);
  +                    if (fTraversed.get(key) != null) {
                           fLastSchemaWasDuplicate = true;
  -                        return(Document)(fTraversed.get(schemaId));
  +                        return(Document)(fTraversed.get(key));
                       }
                   }
                   fSchemaParser.reset();
  @@ -1063,7 +1163,7 @@
                   // now we need to store the mapping information from system id
                   // to the document. also from the document to the system id.
                   if (schemaId != null) {
  -                    fTraversed.put(schemaId, schemaDoc );
  +                    fTraversed.put(key, schemaDoc );
                       fDoc2SystemId.put(schemaDoc, schemaId );
                   }
                   fLastSchemaWasDuplicate = false;
  @@ -1073,12 +1173,8 @@
           }
           catch (IOException ex) {
               fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
  -                                       ERROR_CODES[referType],
  -                                       new Object[]{schemaHint},
  -                                       // when using namespace, then hint is optional,
  -                                       // and it's not an error if the file is not found
  -                                       // but if not using namespace (include),
  -                                       // it's a warning if the file is not found.
  +                                       DOC_ERROR_CODES[referType],
  +                                       new Object[]{schemaSource.getSystemId()},
                                          mustResolve ?
                                          XMLErrorReporter.SEVERITY_ERROR: 
                                          XMLErrorReporter.SEVERITY_WARNING); 
  @@ -1087,7 +1183,7 @@
           schemaDoc = null;
           fLastSchemaWasDuplicate = false;
           return null;
  -    } // getSchema(String, String, String, boolean, boolean):  Document
  +    } // getSchema(String, XMLInputSource, boolean, boolean): Document
   
       // initialize all the traversers.
       // this should only need to be called once during the construction
  @@ -1564,4 +1660,45 @@
                                      XMLErrorReporter.SEVERITY_ERROR);
       }
   
  +    private class XSDKey {
  +        String systemId;
  +        short  referType;
  +        String referNS;
  +
  +        XSDKey(String systemId, short referType, String referNS) {
  +            this.systemId = systemId;
  +            this.referType = referType;
  +            this.referNS = referNS;
  +        }
  +        
  +        public int hashCode() {
  +            return systemId.hashCode();
  +        }
  +
  +        public boolean equals(Object obj) {
  +            if (!(obj instanceof XSDKey)) {
  +                return false;
  +            }
  +            XSDKey key = (XSDKey)obj;
  +            // if they have different system id, then read the document
  +            if (!systemId.equals(key.systemId)) {
  +                return false;
  +            }
  +            // for include and redefine
  +            if (referType == XSDDescription.CONTEXT_INCLUDE ||
  +                referType == XSDDescription.CONTEXT_REDEFINE ||
  +                key.referType == XSDDescription.CONTEXT_INCLUDE ||
  +                key.referType == XSDDescription.CONTEXT_REDEFINE) {
  +                // the refer type must be the same, and the referer NS must be
  +                // the same
  +                if (referType != key.referType || referNS != key.referNS) {
  +                    return false;
  +                }
  +            }
  +            // for import/instance/preparse, as long as the system id
  +            // are the same, we don't need to parse the document again
  +            
  +            return true;
  +        }
  +    }
   } // XSDHandler
  
  
  
  1.5       +12 -6     xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java
  
  Index: XSDocumentInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDocumentInfo.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XSDocumentInfo.java	12 Dec 2001 22:33:47 -0000	1.4
  +++ XSDocumentInfo.java	22 Jan 2002 23:37:26 -0000	1.5
  @@ -60,6 +60,7 @@
   import org.apache.xerces.impl.xs.SchemaNamespaceSupport;
   import org.apache.xerces.impl.xs.SchemaSymbols;
   import org.apache.xerces.impl.validation.ValidationState;
  +import org.apache.xerces.impl.xs.XMLSchemaException;
   import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.impl.xs.util.XInt;
  @@ -76,7 +77,7 @@
    * affect the contents of that schema document alone.
    *
    * @author Neil Graham, IBM
  - * @version $Id: XSDocumentInfo.java,v 1.4 2001/12/12 22:33:47 elena Exp $
  + * @version $Id: XSDocumentInfo.java,v 1.5 2002/01/22 23:37:26 sandygao Exp $
    */
   class XSDocumentInfo {
   
  @@ -108,13 +109,14 @@
   
       SymbolTable fSymbolTable = null;
   
  -    XSDocumentInfo (Document schemaDoc, XSAttributeChecker attrChecker, SymbolTable symbolTable) {
  +    XSDocumentInfo (Document schemaDoc, XSAttributeChecker attrChecker, SymbolTable symbolTable)
  +                    throws XMLSchemaException {
           fSchemaDoc = schemaDoc;
           fNamespaceSupport = new SchemaNamespaceSupport();
           fIsChameleonSchema = false;
  -        
  +
           fSymbolTable = symbolTable;
  -        // During XML Schema traversal bind "xml" prefix to 
  +        // During XML Schema traversal bind "xml" prefix to
           // "http://www.w3.org/XML/1998/namespace"
           // per Namespace Constraint: Prefix Declared (Namespaces in XML REC)
           fNamespaceSupport.declarePrefix(symbolTable.addSymbol("xml"), symbolTable.addSymbol("http://www.w3.org/XML/1998/namespace"));
  @@ -122,6 +124,12 @@
           if(schemaDoc != null) {
               Element root = DOMUtil.getRoot(schemaDoc);
               Object[] schemaAttrs = attrChecker.checkAttributes(root, true, this);
  +            // schemaAttrs == null means it's not an <xsd:schema> element
  +            // throw an exception, but we don't know the document systemId,
  +            // so we leave that to the caller.
  +            if (schemaAttrs == null) {
  +                throw new XMLSchemaException(null, null);
  +            }
               fAreLocalAttributesQualified =
                   ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_AFORMDEFAULT]).intValue() == SchemaSymbols.FORM_QUALIFIED;
               fAreLocalElementsQualified =
  @@ -132,8 +140,6 @@
                   ((XInt)schemaAttrs[XSAttributeChecker.ATTIDX_FINALDEFAULT]).shortValue();
               fTargetNamespace =
                   (String)schemaAttrs[XSAttributeChecker.ATTIDX_TARGETNAMESPACE];
  -            if(fTargetNamespace != null && fTargetNamespace.length() == 0)
  -                fTargetNamespace = null;
               if (fTargetNamespace != null)
                   fTargetNamespace = symbolTable.addSymbol(fTargetNamespace);
   
  
  
  
  1.5       +17 -45    xml-xerces/java/src/org/apache/xerces/parsers/DOMASBuilderImpl.java
  
  Index: DOMASBuilderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMASBuilderImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DOMASBuilderImpl.java	17 Jan 2002 23:54:58 -0000	1.4
  +++ DOMASBuilderImpl.java	22 Jan 2002 23:37:26 -0000	1.5
  @@ -57,9 +57,6 @@
   
   package org.apache.xerces.parsers;
   
  -import java.io.InputStream;
  -import java.io.IOException;
  -import java.io.Reader;
   import java.util.Vector;
   
   import org.w3c.dom.DOMException;
  @@ -73,6 +70,7 @@
   import org.apache.xerces.dom3.as.DOMASException;
   
   import org.apache.xerces.dom.ASModelImpl;
  +import org.apache.xerces.dom.DOMInputSourceImpl;
   import org.apache.xerces.util.DOMEntityResolverWrapper;
   import org.apache.xerces.util.DOMErrorHandlerWrapper;
   import org.apache.xerces.xni.XNIException;
  @@ -83,6 +81,7 @@
   import org.apache.xerces.xni.grammars.XMLGrammarPool;
   import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
   import org.apache.xerces.impl.xs.traversers.XSDHandler;
  +import org.apache.xerces.impl.xs.XSDDescription;
   import org.apache.xerces.impl.xs.XSGrammarBucket;
   import org.apache.xerces.impl.xs.SubstitutionGroupHandler;
   import org.apache.xerces.impl.xs.models.CMBuilder;
  @@ -105,7 +104,7 @@
    *
    * @author Pavani Mukthipudi, Sun Microsystems Inc.
    * @author Neil Graham, IBM
  - * @version $Id: DOMASBuilderImpl.java,v 1.4 2002/01/17 23:54:58 neilg Exp $
  + * @version $Id: DOMASBuilderImpl.java,v 1.5 2002/01/22 23:37:26 sandygao Exp $
    *
    */
   
  @@ -254,45 +253,8 @@
        */
       public ASModel parseASURI(String uri)
                                 throws DOMASException, Exception {
  -       if (fSchemaHandler == null) {
  -           fGrammarBucket = new XSGrammarBucket();
  -           fSubGroupHandler = new SubstitutionGroupHandler(fGrammarBucket);
  -           fSchemaHandler = new XSDHandler(fGrammarBucket);
  -           fCMBuilder = new CMBuilder(new XSDeclarationPool());
  -       }
  -
  -       fErrorReporter = (XMLErrorReporter)fConfiguration.getProperty(ERROR_REPORTER);
  -       fEntityResolver = (XMLEntityResolver)fConfiguration.getProperty(ENTITY_RESOLVER);
  -       if (fEntityResolver == null)
  -           fEntityResolver = (XMLEntityResolver)fConfiguration.getProperty(ENTITY_MANAGER);
  -
  -       fSymbolTable = (SymbolTable)fConfiguration.getProperty(SYMBOL_TABLE);
  -       String externalSchemas =
  -            (String)(fConfiguration.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SCHEMA_LOCATION));
  -       String noNamespaceExternalSchemas =
  -            (String)(fConfiguration.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SCHEMA_NONS_LOCATION));
  -
  -       XMLNS = fSymbolTable.addSymbol(SchemaSymbols.O_XMLNS);
  -       URI_XSI = fSymbolTable.addSymbol(SchemaSymbols.URI_XSI);
  -       XSI_SCHEMALOCATION = fSymbolTable.addSymbol(SchemaSymbols.OXSI_SCHEMALOCATION);
  -       XSI_NONAMESPACESCHEMALOCATION = fSymbolTable.addSymbol(SchemaSymbols.OXSI_NONAMESPACESCHEMALOCATION);
  -       XSI_TYPE = fSymbolTable.addSymbol(SchemaSymbols.OXSI_TYPE);
  -       XSI_NIL = fSymbolTable.addSymbol(SchemaSymbols.OXSI_NIL);
  -       URI_SCHEMAFORSCHEMA = fSymbolTable.addSymbol(SchemaSymbols.OURI_SCHEMAFORSCHEMA);
  -
  -       initGrammarBucket();
  -       fSubGroupHandler.reset();
  -       fSchemaHandler.reset(fErrorReporter, fEntityResolver, fSymbolTable, externalSchemas, noNamespaceExternalSchemas);
  -
  -       SchemaGrammar grammar = fSchemaHandler.parseSchema(null,uri);
  -
  -       if (getFeature(SCHEMA_FULL_CHECKING)) {
  -           XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
  -       }
  -
  -       ASModelImpl newAsModel = new ASModelImpl();
  -       addGrammars(newAsModel, fGrammarBucket);
  -       return newAsModel;
  +        // need to wrap the uri with an XMLInputSource
  +        return parseASInputSource(new XMLInputSource(null, uri, null));
       }
   
       /**
  @@ -322,6 +284,13 @@
        */
       public ASModel parseASInputSource(DOMInputSource is)
                                         throws DOMASException, Exception {
  +        // need to wrap the DOMInputSource with an XMLInputSource
  +        XMLInputSource xis = this.dom2xmlInputSource(is);
  +        return parseASInputSource(xis);
  +    }
  +
  +    ASModel parseASInputSource(XMLInputSource is) throws Exception {
  +                                      
          if (fSchemaHandler == null) {
              fGrammarBucket = new XSGrammarBucket();
              fSubGroupHandler = new SubstitutionGroupHandler(fGrammarBucket);
  @@ -350,7 +319,11 @@
          fSubGroupHandler.reset();
          fSchemaHandler.reset(fErrorReporter, fEntityResolver, fSymbolTable, externalSchemas, noNamespaceExternalSchemas);
   
  -       SchemaGrammar grammar = fSchemaHandler.parseSchema(is.getBaseURI(),is.getSystemId());
  +       // Should check whether the grammar with this namespace is already in
  +       // the grammar resolver. But since we don't know the target namespace
  +       // of the document here, we leave such check to XSDHandler
  +       SchemaGrammar grammar = fSchemaHandler.parseSchema(null, is,
  +                                                          XSDDescription.CONTEXT_PREPARSE);
   
          if (getFeature(SCHEMA_FULL_CHECKING)) {
              XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
  @@ -364,7 +337,6 @@
       // put all the grammars we have access to in the GrammarBucket
       private void initGrammarBucket() {
           fGrammarBucket.reset();
  -        fGrammarBucket.putGrammar(URI_SCHEMAFORSCHEMA, SchemaGrammar.SG_SchemaNS);
           if (fAbstractSchema != null)
               initGrammarBucketRecurse(fAbstractSchema);
       }
  
  
  
  1.4       +95 -66    xml-xerces/java/src/org/apache/xerces/parsers/DOMBuilderImpl.java
  
  Index: DOMBuilderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/DOMBuilderImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMBuilderImpl.java	17 Jan 2002 23:54:58 -0000	1.3
  +++ DOMBuilderImpl.java	22 Jan 2002 23:37:26 -0000	1.4
  @@ -60,6 +60,7 @@
   import java.io.InputStream;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   import java.util.Hashtable;
   import java.util.Stack;
   import java.util.Vector;
  @@ -294,7 +295,7 @@
        */
       public void reset() {
           super.reset();
  -	try {
  +        try {
               fNamespaceDeclarations = fConfiguration.getFeature(NAMESPACE_DECLARATIONS);
               fValidateIfSchema = fConfiguration.getFeature(VALIDATE_IF_SCHEMA);
               fValidateAgainstDTD = fConfiguration.getFeature(VALIDATE_AGAINST_DTD);
  @@ -327,7 +328,7 @@
        * entity.
        */
       public DOMEntityResolver getEntityResolver() {
  -    	DOMEntityResolver domEntityResolver = null;
  +        DOMEntityResolver domEntityResolver = null;
           try {
               DOMEntityResolver entityResolver = (DOMEntityResolver)fConfiguration.getProperty(ENTITY_RESOLVER);
               if (entityResolver != null && 
  @@ -349,9 +350,9 @@
        * entity.
        */
       public void setEntityResolver(DOMEntityResolver entityResolver) {
  -    	try {
  +        try {
               fConfiguration.setProperty(ENTITY_RESOLVER, 
  -            				new DOMEntityResolverWrapper(entityResolver));
  +                                        new DOMEntityResolverWrapper(entityResolver));
           }
           catch (XMLConfigurationException e) {
               
  @@ -370,7 +371,7 @@
        * result in implementation dependent behavour. 
        */
       public DOMErrorHandler getErrorHandler() {
  -    	DOMErrorHandler errorHandler = null;
  +        DOMErrorHandler errorHandler = null;
           try {
               DOMErrorHandler domErrorHandler = 
                   (DOMErrorHandler)fConfiguration.getProperty(ERROR_HANDLER);
  @@ -397,7 +398,7 @@
        * result in implementation dependent behavour. 
        */
       public void setErrorHandler(DOMErrorHandler errorHandler) {
  -    	try {
  +        try {
               fConfiguration.setProperty(ERROR_HANDLER, 
                                          new DOMErrorHandlerWrapper(errorHandler));
           }
  @@ -416,7 +417,7 @@
        * happens before the filter is called. 
        */
       public DOMBuilderFilter getFilter() {
  -    	throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
  +        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
       }
       
       /**
  @@ -429,7 +430,7 @@
        * happens before the filter is called. 
        */
       public void setFilter(DOMBuilderFilter filter) {
  -    	throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
  +        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
       }
   
       /**
  @@ -450,31 +451,31 @@
        */
       public void setFeature(String name, boolean state) throws DOMException {
           try {
  -    	    if (canSetFeature(name, state)) {
  -            	if (name.equals(VALIDATION)) {
  -            	    fConfiguration.setFeature(VALIDATION_FEATURE, state);
  -            	}
  -            	else if (name.equals(EXTERNAL_PARAMETER_ENTITIES)) {
  -            	    fConfiguration.setFeature(EXTERNAL_PARAMETER_ENTITIES_FEATURE, state);
  -            	}
  -            	else if (name.equals(EXTERNAL_GENERAL_ENTITIES)) {
  -            	    fConfiguration.setFeature(EXTERNAL_GENERAL_ENTITIES_FEATURE, state);
  -            	}
  -            	else if (name.equals(EXTERNAL_DTD_SUBSET)) {
  -            	    fConfiguration.setFeature(LOAD_EXTERNAL_DTD_FEATURE, state);
  -            	}
  -            	else if (name.equals(COMMENTS)) {
  -            	    fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
  -            	}
  -            	else if(name.equals(CREATE_ENTITY_REFERENCE_NODES)) {
  -            	    fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
  -            	}
  -            	else {
  -            	    fConfiguration.setFeature(name, state);
  -            	}
  +            if (canSetFeature(name, state)) {
  +                if (name.equals(VALIDATION)) {
  +                    fConfiguration.setFeature(VALIDATION_FEATURE, state);
  +                }
  +                else if (name.equals(EXTERNAL_PARAMETER_ENTITIES)) {
  +                    fConfiguration.setFeature(EXTERNAL_PARAMETER_ENTITIES_FEATURE, state);
  +                }
  +                else if (name.equals(EXTERNAL_GENERAL_ENTITIES)) {
  +                    fConfiguration.setFeature(EXTERNAL_GENERAL_ENTITIES_FEATURE, state);
  +                }
  +                else if (name.equals(EXTERNAL_DTD_SUBSET)) {
  +                    fConfiguration.setFeature(LOAD_EXTERNAL_DTD_FEATURE, state);
  +                }
  +                else if (name.equals(COMMENTS)) {
  +                    fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
  +                }
  +                else if(name.equals(CREATE_ENTITY_REFERENCE_NODES)) {
  +                    fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
  +                }
  +                else {
  +                    fConfiguration.setFeature(name, state);
  +                }
               }
               else {
  -            	throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Feature \""+name+"\" cannot be set to \""+state+"\"");
  +                throw new DOMException(DOMException.NOT_SUPPORTED_ERR,"Feature \""+name+"\" cannot be set to \""+state+"\"");
               }
           }
           catch (XMLConfigurationException e) {
  @@ -500,29 +501,29 @@
        *   the feature itself is not changed.
        */
       public boolean canSetFeature(String name, boolean state) {
  -    	if (name.equals(NAMESPACE_DECLARATIONS) && !state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(VALIDATE_IF_SCHEMA) && state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(VALIDATE_AGAINST_DTD) && state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(CREATE_ENTITY_NODES) && !state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(WHITESPACE_IN_ELEMENT_CONTENT) && !state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(LOAD_AS_INFOSET) && state) {
  -    	    return false;
  -    	}
  -    	else if(name.equals(SUPPORTED_MEDIATYPES_ONLY) && state) {
  -    	    return false;
  -    	}
  -    	
  -    	return true;
  +        if (name.equals(NAMESPACE_DECLARATIONS) && !state) {
  +            return false;
  +        }
  +        else if(name.equals(VALIDATE_IF_SCHEMA) && state) {
  +            return false;
  +        }
  +        else if(name.equals(VALIDATE_AGAINST_DTD) && state) {
  +            return false;
  +        }
  +        else if(name.equals(CREATE_ENTITY_NODES) && !state) {
  +            return false;
  +        }
  +        else if(name.equals(WHITESPACE_IN_ELEMENT_CONTENT) && !state) {
  +            return false;
  +        }
  +        else if(name.equals(LOAD_AS_INFOSET) && state) {
  +            return false;
  +        }
  +        else if(name.equals(SUPPORTED_MEDIATYPES_ONLY) && state) {
  +            return false;
  +        }
  +        
  +        return true;
       }
   
       /**
  @@ -538,7 +539,7 @@
        *   recognize the feature name.
        */
       public boolean getFeature(String name) throws DOMException {
  -    	try {
  +        try {
               if (name.equals(VALIDATION)) {
                   return fConfiguration.getFeature(VALIDATION_FEATURE);
               }
  @@ -600,7 +601,7 @@
               Exception ex = e.getException();
               throw ex;
           }
  -            	
  +                
           // close stream opened by the parser
           finally {
               try {
  @@ -642,13 +643,10 @@
        *   ErrorHandlers are not required to do so. 
        */
       public Document parse(DOMInputSource is) throws Exception {
  -    	
  -    	try {
  -            XMLInputSource xmlInputSource = 
  -                new XMLInputSource(is.getPublicId(), is.getSystemId(), is.getBaseURI());
  -            xmlInputSource.setByteStream(is.getByteStream());
  -            xmlInputSource.setCharacterStream(is.getCharacterStream());
  -            xmlInputSource.setEncoding(is.getEncoding());
  +        
  +        try {
  +            // need to wrap the DOMInputSource with an XMLInputSource
  +            XMLInputSource xmlInputSource = dom2xmlInputSource(is);
               parse(xmlInputSource);
           }
           catch (XNIException e) {
  @@ -656,7 +654,7 @@
               throw ex;
           }
                   
  -    	return getDocument();
  +        return getDocument();
       }
                             
       /**
  @@ -681,8 +679,39 @@
       public void parseWithContext(DOMInputSource is, Node cnode, 
                                    short action) throws DOMException {
           // REVISIT: need to implement.
  -	throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
  +        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Not supported");
       }
       
  +    XMLInputSource dom2xmlInputSource(DOMInputSource is) {
  +        // need to wrap the DOMInputSource with an XMLInputSource
  +        XMLInputSource xis = null;
  +        // if there is a string data, use a StringReader
  +        // according to DOM, we need to treat such data as "UTF-16".
  +        if (is.getStringData() != null) {
  +            xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
  +                                     is.getBaseURI(), new StringReader(is.getStringData()),
  +                                     "UTF-16");
  +        }
  +        // check whether there is a Reader
  +        // according to DOM, we need to treat such reader as "UTF-16".
  +        else if (is.getCharacterStream() != null) {
  +            xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
  +                                     is.getBaseURI(), is.getCharacterStream(),
  +                                     "UTF-16");
  +        }
  +        // check whether there is an InputStream
  +        else if (is.getByteStream() != null) {
  +            xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
  +                                     is.getBaseURI(), is.getByteStream(),
  +                                     is.getEncoding());
  +        }
  +        // otherwise, just use the public/system/base Ids
  +        else {
  +            xis = new XMLInputSource(is.getPublicId(), is.getSystemId(),
  +                                     is.getBaseURI());
  +        }
           
  -} // class DOMASBuilderImpl
  +        return xis;
  +    }
  +            
  +} // class DOMBuilderImpl
  
  
  
  1.2       +7 -5      xml-xerces/java/src/org/apache/xerces/xni/grammars/XMLGrammarDescription.java
  
  Index: XMLGrammarDescription.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/xni/grammars/XMLGrammarDescription.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLGrammarDescription.java	17 Jan 2002 23:54:59 -0000	1.1
  +++ XMLGrammarDescription.java	22 Jan 2002 23:37:26 -0000	1.2
  @@ -64,14 +64,16 @@
    * physical location and their type. </p>
    *
    * @author Neil Graham, IBM
  - * @version $Id: XMLGrammarDescription.java,v 1.1 2002/01/17 23:54:59 neilg Exp $
  + * @version $Id: XMLGrammarDescription.java,v 1.2 2002/01/22 23:37:26 sandygao Exp $
    */
  -
   public interface XMLGrammarDescription  
           extends XMLResourceIdentifier {
  -    // the type of the grammar (e.g., DTD or XSD); 
  -    // @see org.apache.xerces.xni.grammars.Grammar
  -    
  +
  +    /**
  +     * the type of the grammar (e.g., DTD or XSD);
  +     *  
  +     * @see org.apache.xerces.xni.grammars.Grammar
  +     */
       public String getGrammarType();
   
   } // XMLGrammarDescription
  
  
  

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