in core/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/DescriptorFactory.java [96:144]
public static Descriptor buildDescriptor(final URL url) {
try {
// Read descriptor
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileUtil.copyInputStream(url.openStream(), baos);
// 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 {
LOGGER.debug("Validation warning on {}", url, exception);
}
public void error(SAXParseException exception) throws SAXException {
LOGGER.info("Validation error on {}", url, exception);
}
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
});
validator.validate(new StreamSource(new ByteArrayInputStream(baos.toByteArray())));
// Parse descriptor
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
Document doc = docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
Element jbi = doc.getDocumentElement();
Descriptor desc = new Descriptor();
desc.setVersion(Double.parseDouble(getAttribute(jbi, "version")));
Element child = DOMUtil.getFirstChildElement(jbi);
if ("component".equals(child.getLocalName())) {
Component component = parseComponent(child);
desc.setComponent(component);
} else if ("shared-library".equals(child.getLocalName())) {
SharedLibrary sharedLibrary = parseSharedLibrary(child);
desc.setSharedLibrary(sharedLibrary);
} else if ("service-assembly".equals(child.getLocalName())) {
ServiceAssembly serviceAssembly = parseServiceAssembly(child);
desc.setServiceAssembly(serviceAssembly);
} else if ("services".equals(child.getLocalName())) {
Services services = parseServiceUnit(child);
desc.setServices(services);
}
checkDescriptor(desc);
return desc;
} catch (Exception e) {
throw new RuntimeException(e);
}
}