use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class UnmarshallerImpl method unmarshal.
protected Object unmarshal(XMLReader reader, InputSource source) throws JAXBException {
SAXLocator locator = new SAXLocator();
SAXUnmarshallerHandler handler = createUnmarshallerHandler(locator);
reader = InterningXMLReader.adapt(reader);
reader.setContentHandler(handler);
// saxErrorHandler will be set by the createUnmarshallerHandler method.
// configure XMLReader so that the error will be sent to it.
// This is essential for the UnmarshallerHandler to be able to abort
// unmarshalling when an error is found.
//
// Note that when this XMLReader is provided by the client code,
// it might be already configured to call a client error handler.
// This will clobber such handler, if any.
//
// Ryan noted that we might want to report errors to such a client
// error handler as well.
reader.setErrorHandler(new ErrorHandlerAdaptor(handler, locator));
try {
reader.parse(source);
} catch (IOException e) {
throw new JAXBException(e);
} catch (SAXException e) {
throw createUnmarshalException(e);
}
Object result = handler.getResult();
// avoid keeping unnecessary references too long to let the GC
// reclaim more memory.
// setting null upsets some parsers, so use a dummy instance instead.
reader.setContentHandler(dummyHandler);
reader.setErrorHandler(dummyHandler);
return result;
}
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);
}
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 ValidatorImpl method validate.
private boolean validate(Object o, boolean validateId) throws ValidationException {
try {
//ValidatableObject vo = Util.toValidatableObject(o);
ValidatableObject vo = jaxbContext.getGrammarInfo().castToValidatableObject(o);
if (vo == null)
throw new ValidationException(Messages.format(Messages.NOT_VALIDATABLE));
EventInterceptor ei = new EventInterceptor(eventHandler);
ValidationContext context = new ValidationContext(jaxbContext, ei, validateId);
context.validate(vo);
context.reconcileIDs();
return !ei.hadError();
} catch (SAXException e) {
// we need a consistent mechanism to convert SAXException into JAXBException
Exception nested = e.getException();
if (nested != null) {
throw new ValidationException(nested);
} else {
throw new ValidationException(e);
}
//return false;
}
}
use of org.xml.sax.SAXException in project OpenAM by OpenRock.
the class ErrorHandlerAdaptor method propagateEvent.
private void propagateEvent(int severity, SAXParseException saxException) throws SAXException {
// get location info:
// sax locators simply use the location info embedded in the
// sax exception, dom locators keep a reference to their DOMScanner
// and call back to figure out where the error occurred.
ValidationEventLocator vel = locator.getLocation(saxException);
ValidationEventImpl ve = new ValidationEventImpl(severity, saxException.getMessage(), vel);
Exception e = saxException.getException();
if (e != null) {
ve.setLinkedException(e);
} else {
ve.setLinkedException(saxException);
}
// call the client's event handler.
host.handleEvent(ve, severity != ValidationEvent.FATAL_ERROR);
}
Aggregations