private void loadContext(final Collection<String> routes) {
try {
DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
DOMImplementationLS domImpl = (DOMImplementationLS) reg.getDOMImplementation("LS");
LSParser parser = domImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,null);
JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
List<RouteDeFinition> routeDefs = new ArrayList<>();
for (String route : routes) {
try (InputStream input = IoUtils.toInputStream(route,StandardCharsets.UTF_8)) {
LSInput lsinput = domImpl.createLSinput();
lsinput.setByteStream(input);
Node routeElement = parser.parse(lsinput).getDocumentElement();
routeDefs.add(unmarshaller.unmarshal(routeElement,RouteDeFinition.class).getValue());
}
}
camelContext.addRouteDeFinitions(routeDefs);
} catch (Exception e) {
LOG.error("While loading Camel context {}",e);
throw new CamelException(e);
}
}
项目:fabric8-forge
文件:RouteXml.java
public JAXBContext jaxbContext() throws JAXBException {
if (_jaxbContext == null) {
String packageName = Constants.JAXB_CONTEXT_PACKAGES + ":org.apache.camel.spring";
_jaxbContext = JAXBContext.newInstance(packageName,classLoader);
}
return _jaxbContext;
}
项目:Camel
文件:DefaultModelJAXBContextFactory.java
protected String getPackages() {
return Constants.JAXB_CONTEXT_PACKAGES;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。