コード例 #1
0
 @Test
 public void testFileProducer() throws Exception {
   FactoryFinder finder =
       context.getFactoryFinder("META-INF/services/org/apache/camel/component/");
   Class<?> factory = finder.findClass("file", "strategy.factory.");
   assertNotNull("We should find the factory here.", factory);
 }
コード例 #2
0
  /** A strategy method to lazily create the file strategy */
  @SuppressWarnings("unchecked")
  protected GenericFileProcessStrategy<T> createGenericFileStrategy() {
    Class<?> factory = null;
    try {
      FactoryFinder finder =
          getCamelContext().getFactoryFinder("META-INF/services/org/apache/camel/component/");
      factory = finder.findClass(getScheme(), "strategy.factory.");
    } catch (ClassNotFoundException e) {
      if (log.isTraceEnabled()) {
        log.trace("'strategy.factory.class' not found", e);
      }
    } catch (IOException e) {
      if (log.isTraceEnabled()) {
        log.trace(
            "No strategy factory defined in 'META-INF/services/org/apache/camel/component/'", e);
      }
    }

    if (factory == null) {
      // use default
      factory =
          this.getCamelContext().getClassResolver().resolveClass(DEFAULT_STRATEGYFACTORY_CLASS);
      if (factory == null) {
        throw new TypeNotPresentException(DEFAULT_STRATEGYFACTORY_CLASS + " class not found", null);
      }
    }

    try {
      Method factoryMethod =
          factory.getMethod("createGenericFileProcessStrategy", CamelContext.class, Map.class);
      return (GenericFileProcessStrategy<T>)
          ObjectHelper.invokeMethod(factoryMethod, null, getCamelContext(), getParamsAsMap());
    } catch (NoSuchMethodException e) {
      throw new TypeNotPresentException(
          factory.getSimpleName() + ".createGenericFileProcessStrategy method not found", e);
    }
  }
コード例 #3
0
 protected Class<?> findLanguageResolver(String name, CamelContext context) throws Exception {
   if (languageResolver == null) {
     languageResolver = context.getFactoryFinder(LANGUAGE_RESOLVER_RESOURCE_PATH);
   }
   return languageResolver.findClass(name);
 }