public static Descriptor buildDescriptor(final byte[] bytes) {
try {
// Validate descriptor
SchemaFactory schemaFactory = SchemaFactory.newInstance(XSD_SCHEMA_LANGUAGE);
Schema schema = schemaFactory.newSchema(DescriptorFactory.class.getResource(JBI_DESCRIPTOR_XSD));
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
//log.debug("Validation warning on " + url + ": " + exception);
}
public void error(SAXParseException exception) throws SAXException {
//log.info("Validation error on " + url + ": " + exception);
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
validator.validate(new StreamSource(new ByteArrayInputStream(bytes)));
// Parse descriptor
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.parse(new ByteArrayInputStream(bytes));