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); } }
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; }
protected String getPackages() { return Constants.JAXB_CONTEXT_PACKAGES; }