private ToDefinition getDroolsNode(ProcessorDefinition nav) {
   if (!nav.getOutputs().isEmpty()) {
     List<ProcessorDefinition> children = nav.getOutputs();
     for (ProcessorDefinition child : children) {
       if (child instanceof ToDefinition) {
         ToDefinition to = (ToDefinition) child;
         if (to.getUri().trim().startsWith("drools:")) {
           return to;
         }
       }
       getDroolsNode(child);
     }
   }
   return null;
 }
  private void registerPerformanceCounters(
      RouteContext routeContext,
      ProcessorDefinition<?> processor,
      Map<ProcessorDefinition<?>, PerformanceCounter> registeredCounters) {

    // traverse children if any exists
    List<ProcessorDefinition<?>> children = processor.getOutputs();
    for (ProcessorDefinition<?> child : children) {
      registerPerformanceCounters(routeContext, child, registeredCounters);
    }

    // skip processors that should not be registered
    if (!registerProcessor(processor)) {
      return;
    }

    // okay this is a processor we would like to manage so create the
    // a delegate performance counter that acts as the placeholder in the interceptor
    // that then delegates to the real mbean which we register later in the onServiceAdd method
    DelegatePerformanceCounter pc = new DelegatePerformanceCounter();
    // set statistics enabled depending on the option
    boolean enabled =
        camelContext
            .getManagementStrategy()
            .getManagementAgent()
            .getStatisticsLevel()
            .isDefaultOrExtended();
    pc.setStatisticsEnabled(enabled);

    // and add it as a a registered counter that will be used lazy when Camel
    // does the instrumentation of the route and adds the InstrumentationProcessor
    // that does the actual performance metrics gatherings at runtime
    registeredCounters.put(processor, pc);
  }
  public static void augmentNodes(
      RouteContext routeContext, ProcessorDefinition<?> nav, Set visited) {
    if (!nav.getOutputs().isEmpty()) {

      List<ProcessorDefinition> outputs = nav.getOutputs();
      for (int i = 0; i < outputs.size(); i++) {
        ProcessorDefinition child = outputs.get(i); // it.next();
        if (child instanceof ToDefinition) {
          ToDefinition to = (ToDefinition) child;
          if (to.getUri().startsWith("cxfrs") && !visited.contains(to)) {
            BeanDefinition beanDef = new BeanDefinition();
            beanDef.setBeanType(PreCxfrs.class.getName());
            outputs.add(i, beanDef); // insert before cxfrs
            beanDef = new BeanDefinition();
            beanDef.setBeanType(PostCxfrs.class.getName());
            outputs.add(i + 2, beanDef); // insert after cxfrs
            i = i + 2; // adjust for the two inserts
          } else if (to.getUri().startsWith("cxf") && !visited.contains(to)) {
            BeanDefinition beanDef = new BeanDefinition();
            beanDef.setBeanType(PreCxfSoapProcessor.class.getName());
            outputs.add(i, beanDef); // insert before cxf
            beanDef = new BeanDefinition();
            beanDef.setBeanType(PostCxfSoapProcessor.class.getName());
            outputs.add(i + 2, beanDef); // insert after cxf
            i = i + 2; // adjust for the two inserts
            augmented = true;
          }
        } else if (child instanceof MarshalDefinition) {
          MarshalDefinition m = (MarshalDefinition) child;
          DataFormatDefinition dformatDefinition = m.getDataFormatType();
          dformatDefinition = processDataFormatType(routeContext, m.getRef(), dformatDefinition);
          m.setDataFormatType(dformatDefinition); // repoint the marshaller, if it was cloned
        } else if (child instanceof UnmarshalDefinition) {
          UnmarshalDefinition m = (UnmarshalDefinition) child;
          DataFormatDefinition dformatDefinition = m.getDataFormatType();
          dformatDefinition = processDataFormatType(routeContext, m.getRef(), dformatDefinition);
          m.setDataFormatType(dformatDefinition); // repoint the marshaller, if it was cloned
        }
      }

      for (Iterator<ProcessorDefinition> it = nav.getOutputs().iterator(); it.hasNext(); ) {
        ProcessorDefinition child = it.next();
        augmentNodes(routeContext, child, visited);
      }
    }
  }
 private static final void addNamespaceParameterTo(
     ProcessorDefinition<?> procDef, String namespace) {
   if (procDef instanceof ToDefinition) {
     ToDefinition toDef = (ToDefinition) procDef;
     String old_uri = toDef.getUri();
     String new_uri = addNamespaceParameter(old_uri, namespace);
     toDef.setUri(new_uri);
     setEndpointUri(toDef.getEndpoint(), namespace);
   }
   for (ProcessorDefinition<?> procDefChild : procDef.getOutputs()) {
     addNamespaceParameterTo(procDefChild, namespace);
   }
 }
 @SuppressWarnings("unchecked")
 private void findOutputComponents(
     List<ProcessorDefinition> defs,
     Set<String> components,
     Set<String> languages,
     Set<String> dataformats) {
   if (defs != null) {
     for (ProcessorDefinition def : defs) {
       if (def instanceof SendDefinition) {
         findUriComponent(((SendDefinition) def).getUri(), components);
       }
       if (def instanceof MarshalDefinition) {
         findDataFormat(((MarshalDefinition) def).getDataFormatType(), dataformats);
       }
       if (def instanceof UnmarshalDefinition) {
         findDataFormat(((UnmarshalDefinition) def).getDataFormatType(), dataformats);
       }
       if (def instanceof ExpressionNode) {
         findLanguage(((ExpressionNode) def).getExpression(), languages);
       }
       if (def instanceof ResequenceDefinition) {
         findLanguage(((ResequenceDefinition) def).getExpression(), languages);
       }
       if (def instanceof AggregateDefinition) {
         findLanguage(((AggregateDefinition) def).getExpression(), languages);
         findLanguage(((AggregateDefinition) def).getCorrelationExpression(), languages);
         findLanguage(((AggregateDefinition) def).getCompletionPredicate(), languages);
         findLanguage(((AggregateDefinition) def).getCompletionTimeoutExpression(), languages);
         findLanguage(((AggregateDefinition) def).getCompletionSizeExpression(), languages);
       }
       if (def instanceof CatchDefinition) {
         findLanguage(((CatchDefinition) def).getHandled(), languages);
       }
       if (def instanceof OnExceptionDefinition) {
         findLanguage(((OnExceptionDefinition) def).getRetryWhile(), languages);
         findLanguage(((OnExceptionDefinition) def).getHandled(), languages);
         findLanguage(((OnExceptionDefinition) def).getContinued(), languages);
       }
       if (def instanceof SortDefinition) {
         findLanguage(((SortDefinition) def).getExpression(), languages);
       }
       if (def instanceof WireTapDefinition) {
         findLanguage(((WireTapDefinition) def).getNewExchangeExpression(), languages);
       }
       findOutputComponents(def.getOutputs(), components, languages, dataformats);
     }
   }
 }