Search in sources :

Example 1 with ErrorHandlerDefinition

use of org.apache.camel.cdi.xml.ErrorHandlerDefinition in project camel by apache.

the class XmlCdiBeanFactory method beansFrom.

Set<SyntheticBean<?>> beansFrom(URL url) throws JAXBException, IOException {
    try (InputStream xml = url.openStream()) {
        Object node = XmlCdiJaxbContexts.CAMEL_CDI.instance().createUnmarshaller().unmarshal(xml);
        if (node instanceof RoutesDefinition) {
            RoutesDefinition routes = (RoutesDefinition) node;
            return singleton(routesDefinitionBean(routes, url));
        } else if (node instanceof ApplicationContextFactoryBean) {
            ApplicationContextFactoryBean app = (ApplicationContextFactoryBean) node;
            Set<SyntheticBean<?>> beans = new HashSet<>();
            for (CamelContextFactoryBean factory : app.getContexts()) {
                SyntheticBean<?> bean = camelContextBean(factory, url);
                beans.add(bean);
                beans.addAll(camelContextBeans(factory, bean, url));
            }
            for (ErrorHandlerDefinition definition : app.getErrorHandlers()) {
                beans.add(errorHandlerBean(definition, url));
            }
            for (ImportDefinition definition : app.getImports()) {
                // Get the base URL as imports are relative to this
                String path = url.getFile().substring(0, url.getFile().lastIndexOf('/'));
                String base = url.getProtocol() + "://" + url.getHost() + path;
                beans.addAll(beansFrom(base + "/" + definition.getResource()));
            }
            for (RestContextDefinition factory : app.getRestContexts()) {
                beans.add(restContextBean(factory, url));
            }
            for (RouteContextDefinition factory : app.getRouteContexts()) {
                beans.add(routeContextBean(factory, url));
            }
            for (AbstractCamelFactoryBean<?> factory : app.getBeans()) {
                if (hasId(factory)) {
                    beans.add(camelContextBean(null, factory, url));
                }
            }
            return beans;
        } else if (node instanceof CamelContextFactoryBean) {
            CamelContextFactoryBean factory = (CamelContextFactoryBean) node;
            Set<SyntheticBean<?>> beans = new HashSet<>();
            SyntheticBean<?> bean = camelContextBean(factory, url);
            beans.add(bean);
            beans.addAll(camelContextBeans(factory, bean, url));
            return beans;
        } else if (node instanceof RestContextDefinition) {
            RestContextDefinition factory = (RestContextDefinition) node;
            return singleton(restContextBean(factory, url));
        } else if (node instanceof RouteContextDefinition) {
            RouteContextDefinition factory = (RouteContextDefinition) node;
            return singleton(routeContextBean(factory, url));
        }
    }
    return emptySet();
}
Also used : HashSet(java.util.HashSet) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ErrorHandlerDefinition(org.apache.camel.cdi.xml.ErrorHandlerDefinition) RestContextDefinition(org.apache.camel.cdi.xml.RestContextDefinition) InputStream(java.io.InputStream) RouteContextDefinition(org.apache.camel.cdi.xml.RouteContextDefinition) ImportDefinition(org.apache.camel.cdi.xml.ImportDefinition) AbstractCamelFactoryBean(org.apache.camel.core.xml.AbstractCamelFactoryBean) ApplicationContextFactoryBean(org.apache.camel.cdi.xml.ApplicationContextFactoryBean) RoutesDefinition(org.apache.camel.model.RoutesDefinition) CamelContextFactoryBean(org.apache.camel.cdi.xml.CamelContextFactoryBean) HashSet(java.util.HashSet)

Aggregations

InputStream (java.io.InputStream)1 Collections.emptySet (java.util.Collections.emptySet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 ApplicationContextFactoryBean (org.apache.camel.cdi.xml.ApplicationContextFactoryBean)1 CamelContextFactoryBean (org.apache.camel.cdi.xml.CamelContextFactoryBean)1 ErrorHandlerDefinition (org.apache.camel.cdi.xml.ErrorHandlerDefinition)1 ImportDefinition (org.apache.camel.cdi.xml.ImportDefinition)1 RestContextDefinition (org.apache.camel.cdi.xml.RestContextDefinition)1 RouteContextDefinition (org.apache.camel.cdi.xml.RouteContextDefinition)1 AbstractCamelFactoryBean (org.apache.camel.core.xml.AbstractCamelFactoryBean)1 RoutesDefinition (org.apache.camel.model.RoutesDefinition)1