if (result == null || result instanceof StAXResult) {
if( identityTransformer1==null ) {
try {
SAXTransformerFactory tf = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
identityTransformer1 = tf.newTransformer();
identityTransformer2 = tf.newTransformerHandler();
} catch (TransformerConfigurationException e) {
// this is impossible, but again better safe than sorry
throw new TransformerFactoryConfigurationError(e);
}
}
if( result!=null ) {
handler = new ValidatorHandlerImpl(fComponentManager);
handler.setContentHandler(identityTransformer2);
identityTransformer2.setResult(result);
}
try {
identityTransformer1.transform( source, new SAXResult(handler) );
} catch (TransformerException e) {
if( e.getException() instanceof SAXException )
throw (SAXException)e.getException();
throw new SAXException(e);
} finally {
handler.setContentHandler(null);
}
return;
}
throw new IllegalArgumentException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"SourceResultMismatch",
new Object [] {source.getClass().getName(), result.getClass().getName()}));