You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2005/02/08 16:29:23 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/xs/traversers XSDHandler.java

ankitp      2005/02/08 07:29:23

  Modified:    java/src/org/apache/xerces/parsers XML11Configuration.java
                        StandardParserConfiguration.java
               java/src/org/apache/xerces/impl/xs XMLSchemaLoader.java
                        XMLSchemaValidator.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDHandler.java
  Log:
  allow imports of multiple schema docs. under the same namespace to be resolved.
  This is under feature control:http://apache.org/xml/features/handle-multiple-imports.
  By default, the value is 'false' so the original Xerces behaviour is preserved.
  
  Revision  Changes    Path
  1.21      +7 -1      xml-xerces/java/src/org/apache/xerces/parsers/XML11Configuration.java
  
  Index: XML11Configuration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/XML11Configuration.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XML11Configuration.java	20 Dec 2004 06:09:36 -0000	1.20
  +++ XML11Configuration.java	8 Feb 2005 15:29:22 -0000	1.21
  @@ -142,6 +142,10 @@
       /** Feature identifier: validate annotations */
       protected static final String VALIDATE_ANNOTATIONS =
           Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
  +    
  +    /** Feature identifier: handle multiple imports. */
  +    protected static final String HANDLE_MULTIPLE_IMPORTS = 
  +        Constants.XERCES_FEATURE_PREFIX + Constants.HANDLE_MULTIPLE_IMPORTS_FEATURE;
           
   	// feature identifiers
   
  @@ -439,6 +443,7 @@
   				NAMESPACES,
                   NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, SCHEMA_AUGMENT_PSVI,
                   GENERATE_SYNTHETIC_ANNOTATIONS, VALIDATE_ANNOTATIONS,
  +                HANDLE_MULTIPLE_IMPORTS,
               	// NOTE: These shouldn't really be here but since the XML Schema
               	//       validator is constructed dynamically, its recognized
               	//       features might not have been set and it would cause a
  @@ -461,6 +466,7 @@
   		fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE);
           fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE);
           fFeatures.put(VALIDATE_ANNOTATIONS, Boolean.FALSE);
  +        fFeatures.put(HANDLE_MULTIPLE_IMPORTS, Boolean.FALSE);
   		fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
   
           // add default recognized properties
  
  
  
  1.37      +7 -1      xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java
  
  Index: StandardParserConfiguration.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- StandardParserConfiguration.java	20 Dec 2004 06:09:35 -0000	1.36
  +++ StandardParserConfiguration.java	8 Feb 2005 15:29:22 -0000	1.37
  @@ -98,6 +98,10 @@
       /** Feature identifier: validate annotations */
       protected static final String VALIDATE_ANNOTATIONS =
           Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
  +    
  +    /** Feature identifier: handle multiple imports. */
  +    protected static final String HANDLE_MULTIPLE_IMPORTS = 
  +        Constants.XERCES_FEATURE_PREFIX + Constants.HANDLE_MULTIPLE_IMPORTS_FEATURE;
   
       // property identifiers
   
  @@ -180,6 +184,7 @@
               SCHEMA_AUGMENT_PSVI,
               GENERATE_SYNTHETIC_ANNOTATIONS,
               VALIDATE_ANNOTATIONS,
  +            HANDLE_MULTIPLE_IMPORTS,
               // NOTE: These shouldn't really be here but since the XML Schema
               //       validator is constructed dynamically, its recognized
               //       features might not have been set and it would cause a
  @@ -195,6 +200,7 @@
           setFeature(SCHEMA_AUGMENT_PSVI, true);
           setFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false);
           setFeature(VALIDATE_ANNOTATIONS, false);
  +        setFeature(HANDLE_MULTIPLE_IMPORTS, false);
   
           // add default recognized properties
       
  
  
  
  1.37      +10 -3     xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java
  
  Index: XMLSchemaLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaLoader.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- XMLSchemaLoader.java	31 Jan 2005 04:10:48 -0000	1.36
  +++ XMLSchemaLoader.java	8 Feb 2005 15:29:23 -0000	1.37
  @@ -122,6 +122,10 @@
       protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = 
           Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE;
       
  +    /** Feature identifier: handle multiple imports. */
  +    protected static final String HANDLE_MULTIPLE_IMPORTS = 
  +        Constants.XERCES_FEATURE_PREFIX + Constants.HANDLE_MULTIPLE_IMPORTS_FEATURE;
  +    
       
       protected static final String AUGMENT_PSVI = 
           Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI;
  @@ -138,7 +142,8 @@
           STANDARD_URI_CONFORMANT_FEATURE, 
           DISALLOW_DOCTYPE,
           GENERATE_SYNTHETIC_ANNOTATIONS,
  -        VALIDATE_ANNOTATIONS
  +        VALIDATE_ANNOTATIONS,
  +        HANDLE_MULTIPLE_IMPORTS
       };
       
       // property identifiers
  @@ -1100,7 +1105,8 @@
                   name.equals(CONTINUE_AFTER_FATAL_ERROR) ||
                   name.equals(ALLOW_JAVA_ENCODINGS) ||
                   name.equals(STANDARD_URI_CONFORMANT_FEATURE) ||
  -                name.equals(GENERATE_SYNTHETIC_ANNOTATIONS)) {
  +                name.equals(GENERATE_SYNTHETIC_ANNOTATIONS) ||
  +                name.equals(HANDLE_MULTIPLE_IMPORTS)) {
                   return true;
                   
               }
  @@ -1175,6 +1181,7 @@
               v.add(STANDARD_URI_CONFORMANT_FEATURE);
               v.add(VALIDATE_ANNOTATIONS);
               v.add(GENERATE_SYNTHETIC_ANNOTATIONS);
  +            v.add(HANDLE_MULTIPLE_IMPORTS);
               fRecognizedParameters = new DOMStringListImpl(v);      	
           }
           return fRecognizedParameters;
  
  
  
  1.164     +10 -4     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.163
  retrieving revision 1.164
  diff -u -r1.163 -r1.164
  --- XMLSchemaValidator.java	20 Dec 2004 06:09:40 -0000	1.163
  +++ XMLSchemaValidator.java	8 Feb 2005 15:29:23 -0000	1.164
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -150,6 +150,10 @@
       /** Feature identifier: validate annotations. */
       protected static final String VALIDATE_ANNOTATIONS =
           Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
  +    
  +    /** Feature identifier: handle multiple imports. */
  +    protected static final String HANDLE_MULTIPLE_IMPORTS = 
  +        Constants.XERCES_FEATURE_PREFIX + Constants.HANDLE_MULTIPLE_IMPORTS_FEATURE;
   
       /** Feature identifier: whether to continue parsing a schema after a fatal error is encountered */
       protected static final String CONTINUE_AFTER_FATAL_ERROR =
  @@ -211,7 +215,8 @@
               CONTINUE_AFTER_FATAL_ERROR,
               STANDARD_URI_CONFORMANT_FEATURE,
               GENERATE_SYNTHETIC_ANNOTATIONS,
  -            VALIDATE_ANNOTATIONS};
  +            VALIDATE_ANNOTATIONS,
  +            HANDLE_MULTIPLE_IMPORTS};
   
       /** Feature defaults. */
       private static final Boolean[] FEATURE_DEFAULTS = { null,
  @@ -228,7 +233,8 @@
           null, //Boolean.FALSE,
           null,
           null,
  -        null };
  +        null,
  +        null};
   
       /** Recognized properties. */
       private static final String[] RECOGNIZED_PROPERTIES =
  
  
  
  1.86      +55 -14    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.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- XSDHandler.java	20 Dec 2004 06:09:37 -0000	1.85
  +++ XSDHandler.java	8 Feb 2005 15:29:23 -0000	1.86
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -43,11 +43,12 @@
   import org.apache.xerces.impl.xs.opti.ElementImpl;
   import org.apache.xerces.impl.xs.opti.SchemaParsingConfig;
   import org.apache.xerces.impl.xs.util.SimpleLocator;
  -import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.parsers.XML11Configuration;
  +import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.util.DefaultErrorHandler;
   import org.apache.xerces.util.SymbolTable;
   import org.apache.xerces.util.XMLSymbols;
  +import org.apache.xerces.util.URI.MalformedURIException;
   import org.apache.xerces.xni.QName;
   import org.apache.xerces.xni.grammars.Grammar;
   import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  @@ -111,6 +112,10 @@
       protected static final String VALIDATE_ANNOTATIONS =
           Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE;
       
  +    /** Feature identifier: handle multiple imports. */
  +    protected static final String HANDLE_MULTIPLE_IMPORTS = 
  +        Constants.XERCES_FEATURE_PREFIX + Constants.HANDLE_MULTIPLE_IMPORTS_FEATURE;
  +    
       /** Property identifier: error handler. */
       protected static final String ERROR_HANDLER =
           Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY;
  @@ -264,6 +269,9 @@
       
       // validate annotations feature
       private boolean fValidateAnnotations = false;
  +    
  +    //handle multiple import feature
  +    private boolean fHandleMultipleImports = false;
   
       // the XMLErrorReporter
       private XMLErrorReporter fErrorReporter;
  @@ -379,7 +387,12 @@
           // no namespace schema.
           if (referType != XSDDescription.CONTEXT_PREPARSE){
               // first try to find it in the bucket/pool, return if one is found
  -            grammar = findGrammar(desc);
  +            if(fHandleMultipleImports && referType == XSDDescription.CONTEXT_IMPORT && isExistingGrammar(desc)) {
  +                grammar = fGrammarBucket.getGrammar(desc.getTargetNamespace());
  +            }
  +            else {
  +                grammar = findGrammar(desc);
  +            }
               if (grammar != null)
                   return grammar;
               schemaNamespace = desc.getTargetNamespace();
  @@ -663,6 +676,13 @@
                   referType == XSDDescription.CONTEXT_REDEFINE) {
               sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace);
           }
  +        else if(fHandleMultipleImports && referType == XSDDescription.CONTEXT_IMPORT) {
  +            sg = findGrammar(desc);
  +            if(sg == null) {
  +                sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable);
  +                fGrammarBucket.putGrammar(sg);
  +            }
  +        }
           else {
               sg = new SchemaGrammar(currSchemaInfo.fTargetNamespace, desc.makeClone(), fSymbolTable);
               fGrammarBucket.putGrammar(sg);
  @@ -727,14 +747,15 @@
                   }
                   fAttributeChecker.returnAttrArray(importAttrs, currSchemaInfo);
                   
  -                // if this namespace has been imported by this document,
  -                // ignore the <import> statement
  -                if (currSchemaInfo.isAllowedNS(schemaNamespace))
  -                    continue;
  -                
  -                // a schema document can access it's imported namespaces
  -                currSchemaInfo.addAllowedNS(schemaNamespace);
  -                
  +                // if this namespace has not been imported by this document,
  +                //  then import if multiple imports support is enabled.
  +                if(currSchemaInfo.isAllowedNS(schemaNamespace)) {
  +                    if(!fHandleMultipleImports)
  +                        continue;
  +                }
  +                else  {
  +                    currSchemaInfo.addAllowedNS(schemaNamespace);
  +                }
                   // also record the fact that one namespace imports another one
                   // convert null to ""
                   String tns = null2EmptyString(currSchemaInfo.fTargetNamespace);
  @@ -758,9 +779,9 @@
                   fSchemaGrammarDescription.setLocationHints(new String[]{schemaHint});
                   fSchemaGrammarDescription.setTargetNamespace(schemaNamespace);
                   
  -                // if a grammar with the same namespace exists (or being
  +                // if a grammar with the same namespace and location exists (or being
                   // built), ignore this one (don't traverse it).
  -                if (findGrammar(fSchemaGrammarDescription) != null)
  +                if ((!fHandleMultipleImports && findGrammar(fSchemaGrammarDescription) != null) || isExistingGrammar(fSchemaGrammarDescription))
                       continue;
                   newSchemaRoot = resolveSchema(fSchemaGrammarDescription, false, child);
               }
  @@ -875,6 +896,20 @@
           return currSchemaInfo;
       } // end constructTrees
       
  +    private boolean isExistingGrammar(XSDDescription desc) {
  +        SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
  +        if(sg == null) {
  +            return findGrammar(desc) != null;
  +        }
  +        else {
  +            try {
  +                return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false));
  +            } catch (MalformedURIException e) {
  +                return false;
  +            }
  +        }
  +    }
  +    
       // This method builds registries for all globally-referenceable
       // names.  A registry will be built for each symbol space defined
       // by the spec.  It is also this method's job to rename redefined
  @@ -1705,6 +1740,12 @@
           } catch (XMLConfigurationException e) {
               fValidateAnnotations = false;
           }
  +        
  +        try {
  +            fHandleMultipleImports = componentManager.getFeature(HANDLE_MULTIPLE_IMPORTS);
  +        } catch (XMLConfigurationException e) {
  +            fHandleMultipleImports = false;
  +        }
   
           try {
               fSchemaParser.setFeature(
  
  
  

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