use of javax.xml.bind.ValidationEvent in project jOOQ by jOOQ.
the class GenerationTool method load.
/**
* Load a jOOQ codegen configuration file from an input stream
*/
public static Configuration load(InputStream in) throws IOException {
// [#1149] If there is no namespace defined, add the default one
ByteArrayOutputStream out = new ByteArrayOutputStream();
copyLarge(in, out);
String xml = out.toString();
// TODO [#1201] Add better error handling here
xml = xml.replaceAll("<(\\w+:)?configuration xmlns(:\\w+)?=\"http://www.jooq.org/xsd/jooq-codegen-\\d+\\.\\d+\\.\\d+.xsd\">", "<$1configuration xmlns$2=\"" + Constants.NS_CODEGEN + "\">");
xml = xml.replace("<configuration>", "<configuration xmlns=\"" + Constants.NS_CODEGEN + "\">");
try {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
javax.xml.validation.Schema schema = sf.newSchema(GenerationTool.class.getResource("/xsd/" + Constants.XSD_CODEGEN));
JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(new ValidationEventHandler() {
@Override
public boolean handleEvent(ValidationEvent event) {
log.warn("Unmarshal warning", event.getMessage());
return true;
}
});
return (Configuration) unmarshaller.unmarshal(new StringReader(xml));
} catch (Exception e) {
throw new GeneratorException("Error while reading XML configuration", e);
}
}
use of javax.xml.bind.ValidationEvent 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 javax.xml.bind.ValidationEvent 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 javax.xml.bind.ValidationEvent in project OpenAM by OpenRock.
the class Util method handleTypeMismatchError.
/**
* Reports that the type of an object in a property is unexpected.
*/
public static void handleTypeMismatchError(XMLSerializer serializer, Object parentObject, String fieldName, Object childObject) throws AbortSerializationException {
ValidationEvent ve = new ValidationEventImpl(// maybe it should be a fatal error.
ValidationEvent.ERROR, Messages.format(Messages.ERR_TYPE_MISMATCH, getUserFriendlyTypeName(parentObject), fieldName, getUserFriendlyTypeName(childObject)), new ValidationEventLocatorExImpl(parentObject, fieldName));
serializer.reportError(ve);
}
use of javax.xml.bind.ValidationEvent in project camel by apache.
the class JaxbDataFormat method createUnmarshaller.
protected Unmarshaller createUnmarshaller() throws JAXBException, SAXException, FileNotFoundException, MalformedURLException {
Unmarshaller unmarshaller = getContext().createUnmarshaller();
if (schema != null) {
unmarshaller.setSchema(cachedSchema);
unmarshaller.setEventHandler(new ValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
// ERROR
return event.getSeverity() == ValidationEvent.WARNING;
}
});
}
return unmarshaller;
}
Aggregations