// Catch the exception and ignore if we can't set this feature.
}
// cs : toggle the comments on these 2 lines to easily disable caching
// grammarPreparser.setGrammarPool(new XMLGrammarPoolImpl());
grammarPreparser.setGrammarPool(grammarPool != null ? grammarPool : new XMLGrammarPoolImpl());
grammarPreparser.setErrorHandler(errorHandler);
if (entityResolver != null)
{
grammarPreparser.setEntityResolver(entityResolver);
}
try
{
XMLInputSource is = null;
List oldGrammars = null;
XMLGrammarPoolImpl pool = null;
// This allows support for the inline schema in WSDL documents.
if (inlineXSD)
{
Reader reader = new StringReader(schema);
is = new XMLInputSource(null,filelocation,filelocation,reader,null);
((InlineXSDResolver)inlineSchemaEntityResolver).addReferringSchema(is,targetNamespace);
// In the case that 'shared' grammar pool is used we need to consider
// that we might have already added a schema to the pool with the same target namespace
// as the inline schema we're hoping to construct. In this case we need to remove
// the schema from the pool before constructing our inline schema. We can add it
// back when we're all done.
pool = (XMLGrammarPoolImpl)grammarPreparser.getGrammarPool();
oldGrammars = new ArrayList();
// Remove the inline schema namespace if it is listed directly
// in the pool. If it is indirectly listed as an import of a grammar listed
// directly in the pool hide the grammar to continue to get caching benefits
// from the cached grammar.
Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
int numGrammars = grammars.length;
for(int i = 0; i < numGrammars; i++)
{
XMLGrammarDescription desc = grammars[i].getGrammarDescription();
if(targetNamespace.equals(desc.getNamespace()))
{
oldGrammars.add(pool.removeGrammar(desc));
}
else
{
if(grammars[i] instanceof XSGrammar)
{
XSGrammar grammar = (XSGrammar)grammars[i];
StringList namespaces = grammar.toXSModel().getNamespaces();
if(namespaces.contains(targetNamespace))
{
oldGrammars.add(pool.removeGrammar(desc));
//pool.putGrammar(new XSGrammarHider(grammar, targetNamespace));
}
}
}
}
Set inlineNSs = ((InlineXSDResolver)inlineSchemaEntityResolver).getInlineSchemaNSs();
Iterator nsiter = inlineNSs.iterator();
while(nsiter.hasNext())
{
XSDDescription desc = new XSDDescription();
desc.setNamespace((String)nsiter.next());
Grammar oldGrammar = pool.removeGrammar(desc);
if(oldGrammar != null)
oldGrammars.add(oldGrammar);
}
}
// get the input source for an external schema file
else
{
is = new XMLInputSource(null,schema,schema);
}
XSGrammar grammar = (XSGrammar)grammarPreparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,is);
xsModel = grammar.toXSModel();
// Here we add the temporiliy removed schema back.
if (inlineXSD && oldGrammars != null)
{
XSDDescription description = new XSDDescription();
description.setNamespace(targetNamespace);
pool.removeGrammar(description);
Set inlineNSs = ((InlineXSDResolver)inlineSchemaEntityResolver).getInlineSchemaNSs();
Iterator nsiter = inlineNSs.iterator();
while(nsiter.hasNext())
{
XSDDescription desc = new XSDDescription();
desc.setNamespace((String)nsiter.next());
pool.removeGrammar(desc);
}
Iterator oldGIter = oldGrammars.iterator();
while(oldGIter.hasNext())
{
Grammar oldGrammar = (Grammar)oldGIter.next();
if(oldGrammar != null)
pool.putGrammar(oldGrammar);
}
}
}
catch (Exception e)
{