Hashtable locationPairs) {
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;
// reset pools
fDOMPool.reset();
if (fSchemaParser != null) {
fSchemaParser.setPool(fDOMPool);
}
short referType = desc.getContextType();
String 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
// parsing schemas
prepareForParse();
// first phase: construct trees.
Document schemaRoot = getSchema(schemaNamespace, is,
referType == XSDDescription.CONTEXT_PREPARSE,
referType, null);
if (schemaRoot == null) {
// something went wrong right off the hop
return null;
}
if ( schemaNamespace == null && 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());
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
// all traversers and clear all registries
prepareForTraverse();
fRoot = constructTrees(schemaRoot, is.getSystemId(), desc);
if (fRoot == null) {
return null;
}
// second phase: fill global registries.
buildGlobalNameRegistries();
// third phase: call traversers
traverseSchemas();
// fourth phase: handle local element decls
traverseLocalElements();
// fifth phase: handle Keyrefs
resolveKeyRefs();
// sixth phase: validate attribute of non-schema namespaces
// REVISIT: skip this for now. we really don't want to do it.
//fAttributeChecker.checkNonSchemaAttributes(fGrammarBucket);
// seventh phase: store imported grammars
// for all grammars with <import>s
for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
// get its target namespace
String tns = (String)fAllTNSs.elementAt(i);
// get all namespaces it imports
Vector ins = (Vector)fImportMap.get(tns);
// get the grammar
SchemaGrammar sg = fGrammarBucket.getGrammar(emptyString2Null(tns));
if (sg == null)
continue;
SchemaGrammar isg;
// for imported namespace
int count = 0;
for (int j = 0; j < ins.size(); j++) {
// get imported grammar
isg = fGrammarBucket.getGrammar((String)ins.elementAt(j));