Example #1
0
  protected void setAppropriateCamelContext(ActivityExecution execution) {
    // Check to see if the springConfiguration has been set. If not, set it.
    if (springConfiguration == null) {
      // Get the ProcessEngineConfiguration object.
      ProcessEngineConfiguration engineConfiguration = Context.getProcessEngineConfiguration();

      // Convert it to a SpringProcessEngineConfiguration. If this doesn't work, throw a
      // RuntimeException.
      // (ActivitiException extends RuntimeException.)
      try {
        springConfiguration = (SpringProcessEngineConfiguration) engineConfiguration;
      } catch (Exception e) {
        throw new ActivitiException(
            "Expecting a SpringProcessEngineConfiguration for the Activiti Camel module.", e);
      }
    }

    // Get the appropriate String representation of the CamelContext object from ActivityExecution
    // (if available).
    String camelContextValue = getStringFromField(camelContext, execution);

    // If the String representation of the CamelContext object from ActivityExecution is empty, use
    // the default.
    if (StringUtils.isEmpty(camelContextValue) && camelContextObj != null) {
      // No processing required. No custom CamelContext & the default is already set.
    } else {
      if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
        camelContextValue = springConfiguration.getDefaultCamelContext();
      }

      // Get the CamelContext object and set the super's member variable.
      Object ctx = springConfiguration.getApplicationContext().getBean(camelContextValue);
      if (ctx == null || ctx instanceof CamelContext == false) {
        throw new ActivitiException("Could not find CamelContext named " + camelContextValue + ".");
      }
      camelContextObj = (CamelContext) ctx;
    }
  }