use of org.apache.xerces.util.SAXInputSource in project iaf by ibissource.
the class XMLSchemaFactory method newSchema.
public Schema newSchema(Source[] schemas) throws SAXException {
// this will let the loader store parsed Grammars into the pool.
XMLGrammarPoolImplExtension pool = new XMLGrammarPoolImplExtension();
fXMLGrammarPoolWrapper.setGrammarPool(pool);
XMLInputSource[] xmlInputSources = new XMLInputSource[schemas.length];
InputStream inputStream;
Reader reader;
for (int i = 0; i < schemas.length; ++i) {
Source source = schemas[i];
if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
String publicId = streamSource.getPublicId();
String systemId = streamSource.getSystemId();
inputStream = streamSource.getInputStream();
reader = streamSource.getReader();
XMLInputSource xmlInputSource = new XMLInputSource(publicId, systemId, null);
xmlInputSource.setByteStream(inputStream);
xmlInputSource.setCharacterStream(reader);
xmlInputSources[i] = xmlInputSource;
} else if (source instanceof SAXSource) {
SAXSource saxSource = (SAXSource) source;
InputSource inputSource = saxSource.getInputSource();
if (inputSource == null) {
throw new SAXException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SAXSourceNullInputSource", null));
}
xmlInputSources[i] = new SAXInputSource(saxSource.getXMLReader(), inputSource);
} else if (source instanceof DOMSource) {
DOMSource domSource = (DOMSource) source;
Node node = domSource.getNode();
String systemID = domSource.getSystemId();
xmlInputSources[i] = new DOMInputSource(node, systemID);
} else // }
if (source == null) {
throw new NullPointerException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SchemaSourceArrayMemberNull", null));
} else {
throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(fXMLSchemaLoader.getLocale(), "SchemaFactorySourceUnrecognized", new Object[] { source.getClass().getName() }));
}
}
try {
fXMLSchemaLoader.loadGrammar(xmlInputSources);
} catch (XNIException e) {
// this should have been reported to users already.
throw Util.toSAXException(e);
} catch (IOException e) {
// this hasn't been reported, so do so now.
SAXParseException se = new SAXParseException(e.getMessage(), null, e);
if (fErrorHandler != null) {
fErrorHandler.error(se);
}
// and we must throw it.
throw se;
}
// Clear reference to grammar pool.
fXMLGrammarPoolWrapper.setGrammarPool(null);
// Select Schema implementation based on grammar count.
final int grammarCount = pool.getGrammarCount();
AbstractXMLSchema schema = null;
if (fUseGrammarPoolOnly) {
throw new NotImplementedException("fUseGrammarPoolOnly");
// if (grammarCount > 1) {
// schema = new XMLSchemaHack(new ReadOnlyGrammarPool(pool));
// }
// else if (grammarCount == 1) {
// Grammar[] grammars = pool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
// schema = new XMLSchemaHack(grammars[0]);
// }
// else {
// schema = new XMLSchemaHack();
// }
} else {
schema = new XMLSchema(new ReadOnlyGrammarPool(pool), false);
}
propagateFeatures(schema);
return schema;
}
Aggregations