elena 2003/05/28 08:01:15 Modified: java/src/org/apache/xerces/impl/xs XMLSchemaLoader.java java/src/org/apache/xerces/impl/xs/traversers XSDHandler.java Log: Fix code for handling JAXP schema-source property. Given that target namespaces are not specified, when we load schemas XSDDescriptions do not have a target namespace set. Therefore, we should not attempt to find a schema in the local cache first, because if a schema with no namespace was loaded first, findSchema method will always find no namespace schema for any attemp to load more schemas. This is realated to the following bug: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=19106 Revision Changes Path 1.18 +15 -2 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.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- XMLSchemaLoader.java 3 Mar 2003 19:15:31 -0000 1.17 +++ XMLSchemaLoader.java 28 May 2003 15:01:15 -0000 1.18 @@ -488,6 +488,11 @@ */ public Grammar loadGrammar(XMLInputSource source) throws IOException, XNIException { + + // REVISIT: this method should have a namespace parameter specified by + // user. In this case we can easily detect if a schema asked to be loaded + // is already in the local cache. + reset(); XSDDescription desc = new XSDDescription(); desc.fContextType = XSDDescription.CONTEXT_PREPARSE; @@ -667,6 +672,7 @@ sid = xis.getSystemId(); fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; if (sid != null) { + fXSDDescription.setBaseSystemId(xis.getBaseSystemId()); fXSDDescription.setLiteralSystemId(sid); fXSDDescription.setExpandedSystemId(sid); fXSDDescription.fLocationHints = new String[]{sid}; @@ -711,12 +717,19 @@ sid = xis.getSystemId(); fXSDDescription.fContextType = XSDDescription.CONTEXT_PREPARSE; if (sid != null) { + fXSDDescription.setBaseSystemId(xis.getBaseSystemId()); fXSDDescription.setLiteralSystemId(sid); fXSDDescription.setExpandedSystemId(sid); fXSDDescription.fLocationHints = new String[]{sid}; } String targetNamespace = null ; - SchemaGrammar grammar = loadSchema(fXSDDescription, xis, locationPairs); + // load schema + SchemaGrammar grammar = fSchemaHandler.parseSchema(xis,fXSDDescription, locationPairs); + // is full-checking enabled? If so, if we're preparsing we'll + // need to let XSConstraints have a go at the new grammar. + if(fIsCheckedFully) { + XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter); + } if(grammar != null){ targetNamespace = grammar.getTargetNamespace() ; if(jaxpSchemaSourceNamespaces.contains(targetNamespace)){ 1.66 +58 -37 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.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- XSDHandler.java 29 Apr 2003 13:58:00 -0000 1.65 +++ XSDHandler.java 28 May 2003 15:01:15 -0000 1.66 @@ -334,23 +334,31 @@ public SchemaGrammar parseSchema(XMLInputSource is, XSDDescription desc, Hashtable locationPairs) throws IOException { - fLocationPairs = locationPairs; - - // first try to find it in the bucket/pool, return if one is found - SchemaGrammar grammar = findGrammar(desc); - if (grammar != null) - return grammar; - - if (fSchemaParser != null) { - fSchemaParser.resetNodePool(); - } - - short referType = desc.getContextType(); - String schemaNamespace = desc.getTargetNamespace(); - // handle empty string URI as null - if (schemaNamespace != null) { - schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); + + if (fSchemaParser != null) { + fSchemaParser.resetNodePool(); + } + + SchemaGrammar grammar = null; + String schemaNamespace = null; + short referType = desc.getContextType(); + // if loading using JAXP schemaSource property, or using grammar caching loadGrammar + // the desc.targetNamespace is always null. + // Therefore we should not attempt to find out if + // the schema is already in the bucket, since in the case we have + // no namespace schema in the bucket, findGrammar will always return the + // 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 (grammar != null) + return grammar; + schemaNamespace = desc.getTargetNamespace(); + // handle empty string URI as null + if (schemaNamespace != null) { + schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); + } } // before parsing a schema, need to clear registries associated with @@ -365,19 +373,27 @@ // something went wrong right off the hop return null; } - if ( schemaNamespace == null && referType == XSDDescription.CONTEXT_PREPARSE) { + if ( referType == XSDDescription.CONTEXT_PREPARSE) { Element schemaElem = DOMUtil.getRoot(schemaRoot); schemaNamespace = DOMUtil.getAttrValue(schemaElem, SchemaSymbols.ATT_TARGETNAMESPACE); - if(schemaNamespace != null && schemaNamespace.length() > 0) { - schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); - desc.setTargetNamespace(schemaNamespace); - String schemaId = XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false); - XSDKey key = new XSDKey(schemaId, referType, schemaNamespace); - fTraversed.put(key, schemaRoot ); - if (schemaId != null) { - fDoc2SystemId.put(schemaRoot, schemaId ); - } - } + if(schemaNamespace != null && schemaNamespace.length() > 0) { + // Since now we've discovered a namespace, we need to update xsd key + // and store this schema in traversed schemas bucket + schemaNamespace = fSymbolTable.addSymbol(schemaNamespace); + desc.setTargetNamespace(schemaNamespace); + } + else { + schemaNamespace = null; + } + grammar = findGrammar(desc); + if (grammar != null) + return grammar; + String schemaId = XMLEntityManager.expandSystemId(is.getSystemId(), is.getBaseSystemId(), false); + XSDKey key = new XSDKey(schemaId, referType, schemaNamespace); + fTraversed.put(key, schemaRoot ); + if (schemaId != null) { + fDoc2SystemId.put(schemaRoot, schemaId ); + } } // before constructing trees and traversing a schema, need to reset @@ -1355,13 +1371,16 @@ // expand it, and check whether the same document has been // parsed before. If so, return the document corresponding to // that system id. - String schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); - XSDKey key = new XSDKey(schemaId, referType, schemaNamespace); - if ((schemaDoc = (Document)fTraversed.get(key)) != null) { - fLastSchemaWasDuplicate = true; - return schemaDoc; - } - + XSDKey key = null; + String schemaId = null; + if (referType != XSDDescription.CONTEXT_PREPARSE){ + schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); + key = new XSDKey(schemaId, referType, schemaNamespace); + if ((schemaDoc = (Document)fTraversed.get(key)) != null) { + fLastSchemaWasDuplicate = true; + return schemaDoc; + } + } // If this is the first schema this Handler has // parsed, it has to construct a DOMParser if (fSchemaParser == null) { @@ -1371,10 +1390,12 @@ } fSchemaParser.parse(schemaSource); schemaDoc = fSchemaParser.getDocument(); + // now we need to store the mapping information from system id // to the document. also from the document to the system id. - fTraversed.put(key, schemaDoc ); - if (schemaId != null) + if (key != null) + fTraversed.put(key, schemaDoc ); + if (schemaId != null) fDoc2SystemId.put(schemaDoc, schemaId ); fLastSchemaWasDuplicate = false; return schemaDoc;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]