use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class UnmarshallerImpl method unmarshal.
public final Object unmarshal(Node node) throws JAXBException {
try {
DOMScanner scanner = new DOMScanner();
UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
if (node instanceof Element)
scanner.parse((Element) node, handler);
else if (node instanceof Document)
scanner.parse(((Document) node).getDocumentElement(), handler);
else
// no other type of input is supported
throw new IllegalArgumentException();
return handler.getResult();
} catch (SAXException e) {
throw createUnmarshalException(e);
}
}
use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class MarshallerImpl method write.
private void write(XMLSerializable obj, ContentHandler writer) throws JAXBException {
try {
if (getSchemaLocation() != null || getNoNSSchemaLocation() != null) {
// if we need to add xsi:schemaLocation or its brother,
// throw in the component to do that.
writer = new SchemaLocationFilter(getSchemaLocation(), getNoNSSchemaLocation(), writer);
}
SAXMarshaller serializer = new SAXMarshaller(writer, prefixMapper, this);
// set a DocumentLocator that doesn't provide any information
writer.setDocumentLocator(new LocatorImpl());
writer.startDocument();
serializer.childAsBody(obj, null);
writer.endDocument();
// extra check
serializer.reconcileID();
} catch (SAXException e) {
throw new MarshalException(e);
}
}
use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class LogMessageProviderBase method getXMLDoc.
private Document getXMLDoc() throws IOException {
Document xmlDoc = null;
try {
DocumentBuilder builder = XMLUtils.getSafeDocumentBuilder(true);
builder.setErrorHandler(new ValidationErrorHandler());
InputStream is = getClass().getClassLoader().getResourceAsStream(xmlDefinitionFilename);
if (is != null) {
xmlDoc = builder.parse(is);
} else {
throw new IOException(xmlDefinitionFilename + " cannot be found.");
}
} catch (SAXParseException e) {
Debug.error("LogMessageProviderBase.getXMLDoc", e);
} catch (SAXException e) {
Debug.error("LogMessageProviderBase.getXMLDoc", e);
} catch (ParserConfigurationException e) {
Debug.error("LogMessageProviderBase.getXMLDoc", e);
}
return xmlDoc;
}
use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class ValidationErrorHandler method getXMLDocument.
public static Document getXMLDocument(InputStream in) throws Exception {
try {
DocumentBuilder builder = getSafeDocumentBuilder(validating);
Document doc = builder.parse(in);
return doc;
} catch (SAXParseException pe) {
String msg = "\n" + pe.getMessage() + "\n";
Object[] params = { new Integer(pe.getLineNumber()) };
throw new Exception(msg + "XMLUtils.parser_error" + params);
} catch (SAXException sax) {
Object[] params = { sax.getMessage() };
throw new Exception("XMLUtils.exception_message" + params);
} catch (ParserConfigurationException pc) {
Object[] params = { pc.getMessage() };
throw new Exception("XMLUtils.invalid_xml_document" + params);
} catch (IOException ioe) {
Object[] params = { ioe.getMessage() };
throw new Exception("XMLUtils.invalid_input_stream" + params);
}
}
use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class Util method handlePrintConversionException.
/**
* Reports a print conversion error while marshalling.
*/
public static void handlePrintConversionException(Object caller, Exception e, XMLSerializer serializer) throws SAXException {
if (e instanceof SAXException)
// will be thrown)
throw (SAXException) e;
String message = e.getMessage();
if (message == null) {
message = e.toString();
}
ValidationEvent ve = new PrintConversionEventImpl(ValidationEvent.ERROR, message, new ValidationEventLocatorImpl(caller), e);
serializer.reportError(ve);
}
Aggregations