Hi,
Based on the earlier discussion (few private mail exchanges also :-)),
I modified the code which needs some changes to SchemaValidator (completed
by Neeraj). Neeraj, please do the needful.
Please find the attached diffs.
-Pavani
--
Pavani Mukthipudi
Sun Microsystems, Inc.
Phone: 080 - 2298989 Extn: 87390
Index: XMLGrammarPoolImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/validation/XMLGrammarPoolImpl.java,v
retrieving revision 1.2
diff -u -r1.2 XMLGrammarPoolImpl.java
--- XMLGrammarPoolImpl.java 28 Jan 2002 19:33:35 -0000 1.2
+++ XMLGrammarPoolImpl.java 19 Feb 2002 15:48:19 -0000
@@ -61,6 +61,9 @@
import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
+import org.apache.xerces.impl.dtd.XMLDTDDescription;
+import org.apache.xerces.impl.xs.XSDDescription;
+
import java.util.Hashtable;
import java.util.Enumeration;
@@ -69,13 +72,13 @@
* implementation stores two types of grammars: those keyed by the root element
* name, and those keyed by the grammar's target namespace.
*
- * This is for now, a very simple default implementation of the GrammarPool
- * interface. As we move forward, this will become more function-rich and
- * robust.
+ * This is the default implementation of the GrammarPool interface.
+ * As we move forward, this will become more function-rich and robust.
*
* @author Jeffrey Rodriguez, IBM
* @author Andy Clark, IBM
* @author Neil Graham, IBM
+ * @author Pavani Mukthipudi, Sun Microsystems
*
* @version $Id: XMLGrammarPoolImpl.java,v 1.2 2002/01/28 19:33:35 lehors Exp $
*/
@@ -86,11 +89,14 @@
//
/** Grammars associated with element root name. */
- protected Hashtable fGrammars = new Hashtable();
+ // REVISIT : Do we want to use Internal subset also to identify DTD grammars ?
+ protected Hashtable fDTDGrammars = new Hashtable();
/** Grammars associated with namespaces. */
- protected Hashtable fGrammarsNS = new Hashtable();
- protected Grammar fNoNSGrammar = null;
+ // REVISIT : Do we want to use some other information available with the
+XSDDescription
+ // along with the namespace to identify Schema grammars ?
+ protected Hashtable fSchemaGrammars = new Hashtable();
+ protected Grammar fNoNSSchemaGrammar = null;
//
// Constructors
@@ -100,144 +106,241 @@
public XMLGrammarPoolImpl() {
} // <init>()
+ //
// XMLGrammarPool methods
- // REVISIT: implement these!
+ //
+
+ /* <p> Retrieve the initial known set of grammars. This method is
+ * called by a validator before the validation starts. The application
+ * can provide an initial set of grammars available to the current
+ * validation attempt. </p>
+ *
+ * @param grammarType The type of the grammar, from the
+ *
+<code>org.apache.xerces.xni.grammars.XMLGrammarDescription</code>
+ * interface.
+ * @return The set of grammars the validator may put in its
+"bucket"
+ */
public Grammar [] retrieveInitialGrammarSet (String grammarType) {
+ if (grammarType.equals(XMLGrammarDescription.XML_DTD)) {
+ return getDTDGrammars();
+ }
+ else if (grammarType.equals(XMLGrammarDescription.XML_SCHEMA)) {
+ return getSchemaGrammars();
+ }
return null;
} // retrieveInitialGrammarSet (String): Grammar[]
+ /* <p> Return the final set of grammars that the validator ended up
+ * with. This method is called after the validation finishes. The
+ * application may then choose to cache some of the returned grammars.</p>
+ *
+ * @param grammarType The type of the grammars being returned;
+ * @param grammars An array containing the set of grammars being
+ * returned; order is not significant.
+ */
public void cacheGrammars(String grammarType, Grammar[] grammars) {
+ for (int i = 0; i < grammars.length; i++) {
+ putGrammar(grammars[i]);
+ }
} // cacheGrammars(String, Grammar[]);
-
+
+ /* <p> This method requests that the application retrieve a grammar
+ * corresponding to the given GrammarIdentifier from its cache.
+ * If it cannot do so it must return null; the parser will then
+ * call the EntityResolver. </p>
+ * <strong>An application must not call its EntityResolver itself
+ * from this method; this may result in infinite recursions.</strong>
+ *
+ * This implementation chooses to use the root element name to identify a DTD
+grammar
+ * and the target namespace to identify a Schema grammar.
+ *
+ * @param desc The description of the Grammar being requested.
+ * @return The Grammar corresponding to this description or null if
+ * no such Grammar is known.
+ */
public Grammar retrieveGrammar(XMLGrammarDescription desc) {
- return null;
- } // retrieveGrammar(Grammar): XMLGrammarDescription
+ return getGrammar(desc);
+ } // retrieveGrammar(XMLGrammarDescription): Grammar
//
// Public methods
//
/**
- * Puts the specified grammar into the grammar pool and associate it to
- * a root element name.
- *
- * @param rootElement Root element name.
- * @param grammar The grammar.
- */
- public void putGrammar(String rootElement, Grammar grammar) {
- fGrammars.put(rootElement, grammar);
- } // putGrammar(String,Grammar)
-
- /**
- * Puts the specified grammar into the grammar pool and associate it to
- * a target namespace.
+ * Puts the specified grammar into the grammar pool and associates it to
+ * its root element name or its target namespace.
*
- * @param namespace The grammar namespace.
- * @param grammar The grammar.
+ * @param grammar The Grammar.
*/
- public void putGrammarNS(String namespace, Grammar grammar) {
- if(namespace != null) {
- fGrammarsNS.put(namespace, grammar);
- } else {
- fNoNSGrammar = grammar;
+ public void putGrammar(Grammar grammar) {
+ if
+(grammar.getGrammarDescription().getGrammarType().equals(XMLGrammarDescription.XML_DTD))
+ {
+
+fDTDGrammars.put(((XMLDTDDescription)grammar.getGrammarDescription()).getRootName(),
+grammar);
}
- } // putGrammarNS(String,Grammar)
-
- /**
- * Returns the grammar associated to the specified root element name.
- *
- * @param rootElement Root element name.
- */
- public Grammar getGrammar(String rootElement) {
- return (Grammar)fGrammars.get(rootElement);
- } // getGrammar(String):Grammar
-
- /**
- * Returns the grammar associated to the specified target namespace.
- *
- * @param namespace Target namespace.
- */
- public Grammar getGrammarNS(String namespace) {
- return ((namespace == null)?
- fNoNSGrammar :
- (Grammar)fGrammarsNS.get(namespace));
- } // getGrammarNS(String):Grammar
+ else if
+(grammar.getGrammarDescription().getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA))
+ {
+ String namespace =
+((XSDDescription)grammar.getGrammarDescription()).getTargetNamespace();
+ if (namespace != null) {
+ fSchemaGrammars.put(namespace, grammar);
+ }
+ else {
+ fNoNSSchemaGrammar = grammar;
+ }
+ }
+ } // putGrammar(Grammar)
/**
- * Removes the grammar associated to the specified root elememt name from the
- * grammar pool and returns the removed grammar.
- *
- * @param rootElement Root element name.
+ * Returns the grammar associated to the specified grammar description.
+ * Currently, the root element name is used as the key for DTD grammars
+ * and the target namespace is used as the key for Schema grammars.
+ *
+ * @param desc The Grammar Description.
*/
- public Grammar removeGrammar(String rootElement) {
- if (fGrammars.contains(rootElement)) {
- return (Grammar)fGrammars.remove(rootElement);
+ public Grammar getGrammar(XMLGrammarDescription desc) {
+ if (desc.getGrammarType().equals(XMLGrammarDescription.XML_DTD)) {
+ Grammar grammar =
+(Grammar)fDTDGrammars.get(((XMLDTDDescription)desc).getRootName());
+
+ // REVISIT : As of right now, calling equals(...) doesn't serve much of
+the purpose. It's a double check.
+ // Probably it will be useful if the way two grammars are
+compared in equals(...) is changed.
+ if (grammar != null && equals(grammar.getGrammarDescription(), desc)) {
+ return grammar;
+ }
+ }
+ else if (desc.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
+ String namespace = ((XSDDescription)desc).getTargetNamespace();
+ Grammar grammar = ((namespace == null)? fNoNSSchemaGrammar :
+(Grammar)fSchemaGrammars.get(namespace));
+ if (grammar != null && equals(grammar.getGrammarDescription(), desc)) {
+ return grammar;
+ }
}
return null;
- } // removeGrammar(String):Grammar
+ } // getGrammar(XMLGrammarDescription):Grammar
/**
- * Removes the grammar associated to the specified namespace from the
- * grammar pool and returns the removed grammar.
+ * Removes the grammar associated to the specified grammar description from the
+ * grammar pool and returns the removed grammar. Currently, the root element name
+ * is used as the key for DTD grammars and the target namespace is used
+ * as the key for Schema grammars.
*
- * @param namespace Target namespace.
+ * @param desc The Grammar Description.
+ * @return The removed grammar.
*/
- public Grammar removeGrammarNS(String namespace) {
- if(namespace == null) {
- Grammar tempGrammar = fNoNSGrammar;
- fNoNSGrammar = null;
- return tempGrammar;
- } else if (fGrammarsNS.contains(namespace)) {
- return (Grammar)fGrammarsNS.remove(namespace);
- }
- return null;
- } // removeGrammarNS(String):Grammar
+ public Grammar removeGrammar(XMLGrammarDescription desc) {
+ if (containsGrammar(desc)) {
+ if (desc.getGrammarType().equals(XMLGrammarDescription.XML_DTD)) {
+ return
+(Grammar)fDTDGrammars.remove(((XMLDTDDescription)desc).getRootName());
+ }
+ else if (desc.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
+ String namespace = ((XSDDescription)desc).getTargetNamespace();
+ if (namespace == null) {
+ Grammar tempGrammar = fNoNSSchemaGrammar;
+ fNoNSSchemaGrammar = null;
+ return tempGrammar;
+ }
+ else {
+ return (Grammar)fSchemaGrammars.remove(namespace);
+ }
+ }
+ }
+ return null;
+ } // removeGrammar(XMLGrammarDescription):Grammar
/**
* Returns true if the grammar pool contains a grammar associated
- * to the specified root element name.
+ * to the specified grammar description. Currently, the root element name
+ * is used as the key for DTD grammars and the target namespace is used
+ * as the key for Schema grammars.
*
- * @param rootElement Root element name.
+ * @param desc The Grammar Description.
*/
- public boolean containsGrammar(String rootElement) {
- return fGrammars.containsKey(rootElement);
- } // containsGrammar(String):boolean
+ public boolean containsGrammar(XMLGrammarDescription desc) {
+ if (desc.getGrammarType().equals(XMLGrammarDescription.XML_DTD)) {
+ Grammar grammar =
+(Grammar)fDTDGrammars.get(((XMLDTDDescription)desc).getRootName());
+ if (grammar != null && equals(grammar.getGrammarDescription(), desc)) {
+ return true;
+ }
+ }
+ else if (desc.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
+ String namespace = ((XSDDescription)desc).getTargetNamespace();
+ Grammar grammar = ((namespace == null)? fNoNSSchemaGrammar :
+(Grammar)fSchemaGrammars.get(namespace));
+ if (grammar != null && equals(grammar.getGrammarDescription(), desc)) {
+ return true;
+ }
+ }
+ return false;
+ } // containsGrammar(XMLGrammarDescription):boolean
/**
- * Returns true if the grammar pool contains a grammar associated
- * to the specified target namespace.
- *
- * @param namespace Target namespace.
+ * Returns all the DTD grammars.
+ *
+ * @return The set of DTD grammars in the pool
*/
- public boolean containsGrammarNS(String namespace) {
- return fGrammarsNS.containsKey(namespace);
- } // containsGrammarNS(String):boolean
-
- public Grammar [] getGrammars() {
- int grammarSize = fGrammars.size() ;
+ public Grammar [] getDTDGrammars() {
+ int grammarSize = fDTDGrammars.size() ;
Grammar [] toReturn = new Grammar[grammarSize];
int pos = 0;
- Enumeration grammars = fGrammars.elements();
+ Enumeration grammars = fDTDGrammars.elements();
while (grammars.hasMoreElements()) {
toReturn[pos++] = (Grammar)grammars.nextElement();
}
return toReturn;
- } // getGrammars()
+ } // getDTDGrammars()
/**
- * Returns all grammars associated with namespaces.
+ * Returns all the Schema grammars.
*
+ * @return The set of Schema grammars in the pool
*/
- public Grammar [] getGrammarsNS() {
- int grammarSize = fGrammarsNS.size() + ((fNoNSGrammar == null) ? 0 : 1);
+ public Grammar [] getSchemaGrammars() {
+ int grammarSize = fSchemaGrammars.size() + ((fNoNSSchemaGrammar == null) ? 0
+: 1);
Grammar [] toReturn = new Grammar[grammarSize];
int pos = 0;
- Enumeration grammarsNS = fGrammarsNS.elements();
+ Enumeration grammarsNS = fSchemaGrammars.elements();
while (grammarsNS.hasMoreElements()) {
toReturn[pos++] = (Grammar)grammarsNS.nextElement();
}
if(pos < grammarSize)
- toReturn[pos++] = fNoNSGrammar;
+ toReturn[pos++] = fNoNSSchemaGrammar;
return toReturn;
- } // getGrammarsNS()
-} // class GrammarPool
+ } // getSchemaGrammars()
+
+ /**
+ * This method checks whether two grammars are the same. Currently, we compare
+ * the root element names for DTD grammars and the target namespaces for Schema
+grammars.
+ * The application can override this behaviour and add its own logic.
+ *
+ * @param gDesc1 The grammar description
+ * @param gDesc2 The grammar description of the grammar to be compared to
+ * @return True if the grammars are equal, otherwise false
+ */
+ public boolean equals(XMLGrammarDescription gDesc1, XMLGrammarDescription gDesc2)
+{
+ if (gDesc1.getGrammarType() != gDesc2.getGrammarType()) {
+ return false;
+ }
+ if (gDesc1.getGrammarType().equals(XMLGrammarDescription.XML_DTD)) {
+ if
+(((XMLDTDDescription)gDesc1).getRootName().equals(((XMLDTDDescription)gDesc2).getRootName()))
+ {
+ return true;
+ }
+ }
+ else if (gDesc1.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
+ String namespace1 = ((XSDDescription)gDesc1).getTargetNamespace();
+ String namespace2 = ((XSDDescription)gDesc2).getTargetNamespace();
+ if (namespace1 != null && namespace1.equals(namespace2)) {
+ return true;
+ }
+ else if (namespace1 == null && namespace2 == null) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int hashCode(XMLGrammarDescription desc) {
+ if (desc.getGrammarType().equals(XMLGrammarDescription.XML_DTD)) {
+ return (((XMLDTDDescription)desc).getRootName()).hashCode();
+ }
+ else {
+ String namespace = ((XSDDescription)desc).getTargetNamespace();
+ return (namespace == null) ? namespace.hashCode() : 0;
+ }
+ }
+
+} // class XMLGrammarPoolImpl
Index: XSDHandler.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v
retrieving revision 1.26
diff -u -r1.26 XSDHandler.java
--- XSDHandler.java 18 Feb 2002 22:30:25 -0000 1.26
+++ XSDHandler.java 19 Feb 2002 15:37:35 -0000
@@ -74,9 +74,12 @@
import org.apache.xerces.impl.XMLEntityManager;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLResourceIdentifier;
+import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.parser.XMLConfigurationException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
+import org.apache.xerces.xni.grammars.Grammar;
+import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.util.XMLResourceIdentifierImpl;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.SymbolHash;
@@ -113,6 +116,7 @@
* schema, other grammars may be constructed as a side-effect.
*
* @author Neil Graham, IBM
+ * @author Pavani Mukthipudi, Sun Microsystems
* @version $Id: XSDHandler.java,v 1.26 2002/02/18 22:30:25 sandygao Exp $
*/
public class XSDHandler {
@@ -284,6 +288,12 @@
// the GrammarResolver
private XSGrammarBucket fGrammarBucket;
+
+ // the Grammar description
+ private SchemaGrammarDescription fSchemaGrammarDescription;
+
+ // the Grammar Pool
+ private XMLGrammarPool fGrammarPool;
//************ Traversers **********
XSDAttributeGroupTraverser fAttributeGroupTraverser;
@@ -498,21 +508,32 @@
// a schema document can always access it's own target namespace
currSchemaInfo.addAllowedNS(currSchemaInfo.fTargetNamespace);
- if (fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace) == null) {
- // REVISIT: the grammar bucket should have been called
- // already, when we first tried to do the import (not with
- // preparse of course). So this code should be moved! - NG
- SchemaGrammar sg = new SchemaGrammar(fSymbolTable,
currSchemaInfo.fTargetNamespace, new XSDDescription());
+ SchemaGrammar sg = null;
+ SchemaGrammarDescription grammarDescription = null;
+
+ // In the case of preparse, if the grammar is not available in the bucket we
+ask the pool
+ // If the context is instance, the validator would have already consulted the
+pool
+ if ((sg = fGrammarBucket.getGrammar(currSchemaInfo.fTargetNamespace)) == null
+&& referType == XSDDescription.CONTEXT_PREPARSE) {
+ if (fGrammarPool != null) {
+ grammarDescription = new SchemaGrammarDescription();
+ grammarDescription.setTargetNamespace(currSchemaInfo.fTargetNamespace);
+ grammarDescription.setLocationHints(new String[] {locationHint});
+ sg = (SchemaGrammar)fGrammarPool.retrieveGrammar(grammarDescription);
+ if (sg != null) {
+ fGrammarBucket.putGrammar(sg);
+ }
+ }
+ }
+ if (sg == null) {
+ grammarDescription = new SchemaGrammarDescription();
+ sg = new SchemaGrammar(fSymbolTable, currSchemaInfo.fTargetNamespace,
+grammarDescription);
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) {
+ }
+ // we got a grammar of the same namespace in the bucket, should ignore this
+one
+ else if (referType == XSDDescription.CONTEXT_PREPARSE) {
return null;
- }
-
- // Modified by Pavani Mukthipudi, Sun Microsystems Inc.
+ }
+
fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
Vector dependencies = new Vector();
@@ -543,18 +564,31 @@
reportSchemaError("src-import.1.1", new Object []
{schemaNamespace}, child);
}
fAttributeChecker.returnAttrArray(includeAttrs, currSchemaInfo);
+
// a schema document can access it's imported namespaces
currSchemaInfo.addAllowedNS(schemaNamespace);
- // consciously throw away whether was a duplicate; don't care.
- // pass the systemId of the current document as the base systemId
- // REVISIT: We must consult the gtrammar bucket, then the gramar
- // pool, and only then the entity resolver; this *must* be the
- // order. Therefore, the current sequence is *wrong*, since we
- // consult the EntityResolver, only when we call constructTrees
- // again consulting Grammar bucket. So this code needs to be
- // reworked - NG
- // i.e., we need to create an XSDDescription, ask Grammar
- // bucket, ask GrammarPool, then pass that along...
+
+ // We first ask the GrammarBucket, then the GrammarPool and only then
+the EntityResolver is consulted
+
+ if (fGrammarBucket.getGrammar(schemaNamespace) != null) {
+ continue;
+ }
+ else {
+ if (fGrammarPool != null) {
+ fSchemaGrammarDescription.reset();
+ fSchemaGrammarDescription.setTargetNamespace(schemaNamespace);
+ sg =
+(SchemaGrammar)fGrammarPool.retrieveGrammar(fSchemaGrammarDescription);
+ if (sg != null) {
+ fGrammarBucket.putGrammar(sg);
+ continue;
+ }
+ }
+ }
+ grammarDescription = new SchemaGrammarDescription();
+ grammarDescription.setTargetNamespace(schemaNamespace);
+ grammarDescription.setLocationHints(new String[] {schemaHint});
+ sg = new SchemaGrammar(fSymbolTable, schemaNamespace,
+grammarDescription);
+ fGrammarBucket.putGrammar(sg);
newSchemaRoot = getSchema(schemaNamespace, schemaHint,
(String)fDoc2SystemId.get(schemaRoot), false, XSDDescription.CONTEXT_IMPORT, child);
}
else if ((localName.equals(SchemaSymbols.ELT_INCLUDE)) ||
@@ -1277,10 +1311,11 @@
SymbolTable symbolTable,
String externalSchemaLocation,
String externalNoNSSchemaLocation,
- Object jaxpSchemaSource) {
+ Object jaxpSchemaSource, XMLGrammarPool grammarPool) {
fErrorReporter = errorReporter;
fSymbolTable = symbolTable;
+ fGrammarPool = grammarPool;
EMPTY_STRING = fSymbolTable.addSymbol(SchemaSymbols.EMPTY_STRING);
@@ -1925,4 +1960,52 @@
return true;
}
}
+
+ /**
+ * This inner class extends XSDDescription and provides set methods for setting
+the
+ * protected fields of XSDDescription. It is declared private, so as, not to
+expose set*
+ * methods outside this class. XSDDescription is for providing the read only
+information
+ * to the application about Schema Grammar required by the parser. Application
+uses this info
+ * in making decisions about caching/retrieving appropriate grammar. XSDHanlder
+will make use
+ * of this class to provide information and give a chance to application to
+supply
+ * SchemaGrammar required by parser.
+ *
+ * @author Neeraj Bajaj SUN Microsystems.
+ *
+ */
+ private class SchemaGrammarDescription extends XSDDescription {
+
+
+ public void setContextType(short contextType){
+ fContextType = contextType ;
+ }
+
+ public void setTargetNamespace(String targetNamespace){
+ fTargetNamespace = targetNamespace ;
+ }
+
+ public void setLocationHints(String [] locationHints){
+ int length = locationHints.length ;
+ fLocationHints = new String[length];
+ System.arraycopy(locationHints, 0, fLocationHints, 0, length);
+ //fLocationHints = locationHints ;
+ }
+
+ public void setTriggeringComponent(QName triggeringComponent){
+ fTriggeringComponent = triggeringComponent ;
+ }
+
+ public void setEnclosingElementName(QName enclosedElementName){
+ fEnclosedElementName = enclosedElementName ;
+ }
+
+ public void setAttributes(XMLAttributes attributes){
+ fAttributes = attributes ;
+ }
+
+ public void reset(){
+ super.reset();
+ }
+
+ }//SchemaGrammarDescription
} // XSDHandler
Index: DOMASBuilderImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/parsers/DOMASBuilderImpl.java,v
retrieving revision 1.9
diff -u -r1.9 DOMASBuilderImpl.java
--- DOMASBuilderImpl.java 4 Feb 2002 05:34:19 -0000 1.9
+++ DOMASBuilderImpl.java 19 Feb 2002 15:44:18 -0000
@@ -80,6 +80,7 @@
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.apache.xerces.xni.grammars.XMLGrammarPool;
+import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.impl.validation.XMLGrammarPoolImpl;
import org.apache.xerces.impl.xs.traversers.XSDHandler;
import org.apache.xerces.impl.xs.XSDDescription;
@@ -216,7 +217,9 @@
if (fGrammarPool == null) {
fGrammarPool =
(XMLGrammarPool)fConfiguration.getProperty(StandardParserConfiguration.XMLGRAMMAR_POOL);
}
- initGrammarPool(fAbstractSchema);
+ if (fAbstractSchema != null) {
+ initGrammarPool(fAbstractSchema);
+ }
}
@@ -344,7 +347,7 @@
initGrammarBucket();
fSubGroupHandler.reset();
- fSchemaHandler.reset(fErrorReporter, fEntityResolver, fSymbolTable,
externalSchemas, noNamespaceExternalSchemas, null);
+ fSchemaHandler.reset(fErrorReporter, fEntityResolver, fSymbolTable,
+externalSchemas, noNamespaceExternalSchemas, null, fGrammarPool);
// Should check whether the grammar with this namespace is already in
// the grammar resolver. But since we don't know the target namespace
@@ -388,17 +391,15 @@
private void initGrammarPool(ASModelImpl currModel) {
// put all the grammars in fAbstractSchema into the grammar pool.
- // REVISIT: straighten this out when grammar caching's properly implemented!
- if(!(fGrammarPool instanceof XMLGrammarPoolImpl)) return;
- XMLGrammarPoolImpl poolImpl = (XMLGrammarPoolImpl)fGrammarPool;
- SchemaGrammar grammar = null;
- if((grammar = currModel.getGrammar()) != null) {
- String tns = grammar.getTargetNamespace();
- poolImpl.putGrammarNS(tns, grammar);
- }
- Vector modelStore = currModel.getInternalASModels();
- for (int i = 0; i < modelStore.size(); i++) {
- initGrammarPool((ASModelImpl)modelStore.elementAt(i));
+ if (fGrammarPool != null) {
+ Grammar[] grammars = new Grammar[1];
+ if ((grammars[0] = (Grammar)currModel.getGrammar()) != null) {
+
+fGrammarPool.cacheGrammars(grammars[0].getGrammarDescription().getGrammarType(),
+grammars);
+ }
+ Vector modelStore = currModel.getInternalASModels();
+ for (int i = 0; i < modelStore.size(); i++) {
+ initGrammarPool((ASModelImpl)modelStore.elementAt(i));
+ }
}
}
} // class DOMASBuilderImpl
Index: XMLGrammarCachingConfiguration.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/parsers/XMLGrammarCachingConfiguration.java,v
retrieving revision 1.2
diff -u -r1.2 XMLGrammarCachingConfiguration.java
--- XMLGrammarCachingConfiguration.java 9 Feb 2002 20:55:21 -0000 1.2
+++ XMLGrammarCachingConfiguration.java 19 Feb 2002 15:46:41 -0000
@@ -301,7 +301,7 @@
for(int i=0; i<grammars.length; i++ )
fXSGrammarBucket.putGrammar(grammars[i]);
fSubGroupHandler.reset();
- fSchemaHandler.reset(fErrorReporter, fEntityManager, fSymbolTable,
externalSchemas, noNamespaceExternalSchemas, null);
+ fSchemaHandler.reset(fErrorReporter, fEntityManager, fSymbolTable,
+externalSchemas, noNamespaceExternalSchemas, null, fGrammarPool);
// Should check whether the grammar with this namespace is already in
// the grammar resolver. But since we don't know the target namespace
Index: CachingParserPool.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/parsers/CachingParserPool.java,v
retrieving revision 1.8
diff -u -r1.8 CachingParserPool.java
--- CachingParserPool.java 7 Feb 2002 22:15:09 -0000 1.8
+++ CachingParserPool.java 19 Feb 2002 15:45:39 -0000
@@ -470,32 +470,40 @@
// GrammarPool methods
//
- // retrieve the initial set of grammars for the validator
- // to work with.
- // REVISIT: does this need to be synchronized since it's just reading?
- // @param grammarType type of the grammars to be retrieved.
- // @return the initial grammar set the validator may place in its "bucket"
+ /**
+ * Retrieve the initial set of grammars for the validator to work with.
+ * REVISIT: does this need to be synchronized since it's just reading?
+ *
+ * @param grammarType Type of the grammars to be retrieved.
+ * @return The initial grammar set the validator may place in its
+"bucket"
+ */
public Grammar [] retrieveInitialGrammarSet(String grammarType ) {
Grammar [] grammars = super.retrieveInitialGrammarSet(grammarType);
if (grammars != null) return grammars;
return fGrammarPool.retrieveInitialGrammarSet(grammarType);
} // retrieveInitialGrammarSet(String): Grammar[]
- // retrieve a particular grammar.
- // REVISIT: does this need to be synchronized since it's just reading?
- // @param gDesc description of the grammar to be retrieved
- // @return Grammar corresponding to gDesc, or null if none exists.
+ /**
+ * Retrieve a particular grammar.
+ * REVISIT: does this need to be synchronized since it's just reading?
+ *
+ * @param gDesc Description of the grammar to be retrieved
+ * @return Grammar corresponding to gDesc, or null if none exists.
+ */
public Grammar retrieveGrammar(XMLGrammarDescription gDesc) {
Grammar g = super.retrieveGrammar(gDesc);
if(g != null) return g;
return fGrammarPool.retrieveGrammar(gDesc);
} // retrieveGrammar(XMLGrammarDesc): Grammar
- // give the grammarPool the option of caching these grammars.
- // This certainly must be synchronized.
- // @param grammarType The type of the grammars to be cached.
- // @param grammars the Grammars that may be cached (unordered, Grammars
previously
- // given to the validator may be included).
+ /**
+ * Give the grammarPool the option of caching these grammars.
+ * This certainly must be synchronized.
+ *
+ * @param grammarType The type of the grammars to be cached.
+ * @param grammars The Grammars that may be cached (unordered, Grammars
+previously
+ * given to the validator may be included).
+ */
public void cacheGrammars(String grammarType, Grammar[] grammars) {
// better give both grammars a shot...
super.cacheGrammars(grammarType, grammars);
@@ -503,28 +511,28 @@
} // cacheGrammars(grammarType, Grammar[]);
/**
- * Returns the grammar associated to the specified key.
+ * Returns the grammar associated to the specified description.
*
- * @param key The key of the grammar.
+ * @param desc The description of the grammar.
*/
- public Grammar getGrammar(String key) {
+ public Grammar getGrammar(XMLGrammarDescription desc) {
- if (super.containsGrammar(key)) {
- return super.getGrammar(key);
+ if (super.containsGrammar(desc)) {
+ return super.getGrammar(desc);
}
return null;
- } // getGrammar(String):Grammar
+ } // getGrammar(XMLGrammarDescription):Grammar
/**
* Returns true if the grammar pool contains a grammar associated
- * to the specified key.
+ * to the specified description.
*
- * @param key The key of the grammar.
+ * @param desc The description of the grammar.
*/
- public boolean containsGrammar(String key) {
- return super.containsGrammar(key);
- } // containsGrammar(String):boolean
+ public boolean containsGrammar(XMLGrammarDescription desc) {
+ return super.containsGrammar(desc);
+ } // containsGrammar(XMLGrammarDescription):boolean
} // class ShadowedGrammarPool
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]