コード例 #1
0
 protected void addDependsOn(CamelContextFactoryBean factoryBean, BeanDefinitionBuilder builder) {
   String dependsOn = factoryBean.getDependsOn();
   if (ObjectHelper.isNotEmpty(dependsOn)) {
     // comma, whitespace and semi colon is valid separators in Spring depends-on
     String[] depends = dependsOn.split(",|;|\\s");
     if (depends == null) {
       throw new IllegalArgumentException("Cannot separate depends-on, was: " + dependsOn);
     } else {
       for (String depend : depends) {
         depend = depend.trim();
         LOG.debug("Adding dependsOn {} to CamelContext({})", depend, factoryBean.getId());
         builder.addDependsOn(depend);
       }
     }
   }
 }
コード例 #2
0
    @Override
    protected void doParse(
        Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
      renameNamespaceRecursive(element);
      super.doParse(element, parserContext, builder);

      String contextId = element.getAttribute("id");
      boolean implicitId = false;

      // lets avoid folks having to explicitly give an ID to a camel context
      if (ObjectHelper.isEmpty(contextId)) {
        // if no explicit id was set then use a default auto generated name
        CamelContextNameStrategy strategy = new DefaultCamelContextNameStrategy();
        contextId = strategy.getName();
        element.setAttributeNS(null, "id", contextId);
        implicitId = true;
      }

      // now lets parse the routes with JAXB
      Binder<Node> binder;
      try {
        binder = getJaxbContext().createBinder();
      } catch (JAXBException e) {
        throw new BeanDefinitionStoreException("Failed to create the JAXB binder", e);
      }
      Object value = parseUsingJaxb(element, parserContext, binder);

      if (value instanceof CamelContextFactoryBean) {
        // set the property value with the JAXB parsed value
        CamelContextFactoryBean factoryBean = (CamelContextFactoryBean) value;
        builder.addPropertyValue("id", contextId);
        builder.addPropertyValue("implicitId", implicitId);
        builder.addPropertyValue("routes", factoryBean.getRoutes());
        builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
        builder.addPropertyValue("interceptFroms", factoryBean.getInterceptFroms());
        builder.addPropertyValue(
            "interceptSendToEndpoints", factoryBean.getInterceptSendToEndpoints());
        builder.addPropertyValue("dataFormats", factoryBean.getDataFormats());
        builder.addPropertyValue("onCompletions", factoryBean.getOnCompletions());
        builder.addPropertyValue("onExceptions", factoryBean.getOnExceptions());
        builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs());
        builder.addPropertyValue("routeRefs", factoryBean.getRouteRefs());
        builder.addPropertyValue("properties", factoryBean.getProperties());
        builder.addPropertyValue("packageScan", factoryBean.getPackageScan());
        builder.addPropertyValue("contextScan", factoryBean.getContextScan());
        if (factoryBean.getPackages().length > 0) {
          builder.addPropertyValue("packages", factoryBean.getPackages());
        }
        builder.addPropertyValue(
            "camelPropertyPlaceholder", factoryBean.getCamelPropertyPlaceholder());
        builder.addPropertyValue("camelJMXAgent", factoryBean.getCamelJMXAgent());
        builder.addPropertyValue(
            "camelStreamCachingStrategy", factoryBean.getCamelStreamCachingStrategy());
        builder.addPropertyValue("threadPoolProfiles", factoryBean.getThreadPoolProfiles());
        // add any depends-on
        addDependsOn(factoryBean, builder);
      }

      NodeList list = element.getChildNodes();
      int size = list.getLength();
      for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
          Element childElement = (Element) child;
          String localName = child.getLocalName();
          if (localName.equals("endpoint")) {
            registerEndpoint(childElement, parserContext, contextId);
          } else if (localName.equals("routeBuilder")) {
            addDependsOnToRouteBuilder(childElement, parserContext, contextId);
          } else {
            BeanDefinitionParser parser = parserMap.get(localName);
            if (parser != null) {
              BeanDefinition definition = parser.parse(childElement, parserContext);
              String id = childElement.getAttribute("id");
              if (ObjectHelper.isNotEmpty(id)) {
                parserContext.registerComponent(new BeanComponentDefinition(definition, id));
                // set the templates with the camel context
                if (localName.equals("template")
                    || localName.equals("consumerTemplate")
                    || localName.equals("proxy")
                    || localName.equals("export")) {
                  // set the camel context
                  definition
                      .getPropertyValues()
                      .addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
                }
              }
            }
          }
        }
      }

      // register as endpoint defined indirectly in the routes by from/to types having id explicit
      // set
      registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder);

      // register templates if not already defined
      registerTemplates(element, parserContext, contextId);

      // lets inject the namespaces into any namespace aware POJOs
      injectNamespaces(element, binder);

      // inject bean post processor so we can support @Produce etc.
      // no bean processor element so lets create it by our self
      injectBeanPostProcessor(element, parserContext, contextId, builder);
    }