}// parseSchemaLocaltion(String, Hashtable)
private void resolveSchemaGrammar( String loc, String uri) throws Exception {
SchemaGrammar grammar = (SchemaGrammar) fGrammarResolver.getGrammar(uri);
if (grammar == null) {
if (fSchemaGrammarParser == null) {
//
// creating a parser for schema only once per parser instance
// leads to less objects, but increases time we spend in reset()
//
fSchemaGrammarParser = new DOMParser();
fSchemaGrammarParser.setEntityResolver( new Resolver(fEntityHandler) );
fSchemaGrammarParser.setErrorHandler( new ErrorHandler() );
try {
fSchemaGrammarParser.setFeature("http://xml.org/sax/features/validation", false);
fSchemaGrammarParser.setFeature("http://xml.org/sax/features/namespaces", true);
fSchemaGrammarParser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
} catch ( org.xml.sax.SAXNotRecognizedException e ) {
e.printStackTrace();
} catch ( org.xml.sax.SAXNotSupportedException e ) {
e.printStackTrace();
}
}
// expand it before passing it to the parser
InputSource source = null;
EntityResolver currentER = fSchemaGrammarParser.getEntityResolver();
if (currentER != null) {
source = currentER.resolveEntity("", loc);
}
if (source == null) {
loc = fEntityHandler.expandSystemId(loc);
source = new InputSource(loc);
}
try {
fSchemaGrammarParser.parse( source );
} catch ( IOException e ) {
e.printStackTrace();
} catch ( SAXException e ) {
reportRecoverableXMLError( XMLMessages.MSG_GENERIC_SCHEMA_ERROR,
XMLMessages.SCHEMA_GENERIC_ERROR, e.getMessage() );
}
Document document = fSchemaGrammarParser.getDocument(); //Our Grammar
TraverseSchema tst = null;
try {
if (DEBUG_SCHEMA_VALIDATION) {
System.out.println("I am geting the Schema Document");
}
Element root = null;
if (document != null) {
root = document.getDocumentElement();// This is what we pass to TraverserSchema
}
if (root == null) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, XMLMessages.SCHEMA_GENERIC_ERROR, "Can't get back Schema document's root element :" + loc);
} else {
if (uri == null || !uri.equals(root.getAttribute(SchemaSymbols.ATT_TARGETNAMESPACE)) ) {
reportRecoverableXMLError(XMLMessages.MSG_GENERIC_SCHEMA_ERROR, XMLMessages.SCHEMA_GENERIC_ERROR, "Schema in " + loc + " has a different target namespace " +
"from the one specified in the instance document :" + uri);
}
grammar = new SchemaGrammar();
grammar.setGrammarDocument(document);
// Since we've just constructed a schema grammar, we should make sure we know what we've done.
fGrammarIsSchemaGrammar = true;
fGrammarIsDTDGrammar = false;