Java 类org.apache.camel.spi.FactoryFinder 实例源码

项目:Camel    文件:BaseTypeConverterRegistry.java   
public BaseTypeConverterRegistry(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) {
    this.resolver = resolver;
    this.injector = injector;
    this.factoryFinder = factoryFinder;
    this.typeConverterLoaders.add(new AnnotationTypeConverterLoader(resolver));

    // add to string first as it will then be last in the last as to string can nearly
    // always convert something to a string so we want it only as the last resort
    // ToStringTypeConverter should NOT allow to be promoted
    addFallbackTypeConverter(new ToStringTypeConverter(), false);
    // enum is okay to be promoted
    addFallbackTypeConverter(new EnumTypeConverter(), true);
    // arrays is okay to be promoted
    addFallbackTypeConverter(new ArrayTypeConverter(), true);
    // and future should also not allowed to be promoted
    addFallbackTypeConverter(new FutureTypeConverter(this), false);
    // add sync processor to async processor converter is to be promoted
    addFallbackTypeConverter(new AsyncProcessorTypeConverter(), true);
}
项目:Camel    文件:DefaultProcessorFactory.java   
@Override
public Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception {
    String name = definition.getClass().getSimpleName();
    FactoryFinder finder = routeContext.getCamelContext().getFactoryFinder(RESOURCE_PATH);
    try {
        if (finder != null) {
            Object object = finder.newInstance(name);
            if (object != null && object instanceof ProcessorFactory) {
                ProcessorFactory pc = (ProcessorFactory) object;
                return pc.createChildProcessor(routeContext, definition, mandatory);
            }
        }
    } catch (NoFactoryAvailableException e) {
        // ignore there is no custom factory
    }

    return null;
}
项目:Camel    文件:DefaultProcessorFactory.java   
@Override
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
    String name = definition.getClass().getSimpleName();
    FactoryFinder finder = routeContext.getCamelContext().getFactoryFinder(RESOURCE_PATH);
    try {
        if (finder != null) {
            Object object = finder.newInstance(name);
            if (object != null && object instanceof ProcessorFactory) {
                ProcessorFactory pc = (ProcessorFactory) object;
                return pc.createProcessor(routeContext, definition);
            }
        }
    } catch (NoFactoryAvailableException e) {
        // ignore there is no custom factory
    }

    return null;
}
项目:syndesis    文件:VerifierEndpoint.java   
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{id}")
public List<VerifierResponse> verify(@PathParam("id") String connectorId, Map<String, Object> parameters) {
    List<VerifierResponse> answer;
    Verifier verifier;

    try {
        // First find try to lookup the verifier from the application context
        verifier = applicationContext.getBean(connectorId, Verifier.class);
    } catch (NoSuchBeanDefinitionException|NoSuchBeanException ignored) {
        LOGGER.debug("No bean of type: {} with id: {} found in application context, switch to factory finder", Verifier.class.getName(), connectorId);

        verifier = null;

        try {
            // Then fallback to camel's factory finder
            final FactoryFinder finder = camelContext.getFactoryFinder(RESOURCE_PATH);
            final Class<?> type = finder.findClass(connectorId);

            verifier = (Verifier) camelContext.getInjector().newInstance(type);
        } catch (Exception e) {
            LOGGER.warn("No factory finder of type: {} for id: {}", Verifier.class.getName(), connectorId, e);
        }
    }


    if (verifier != null) {
        answer = verifier.verify(camelContext, connectorId, parameters);
        answer = filterExceptions(answer);
    } else {
        answer = Collections.singletonList(createUnsupportedResponse(connectorId));
    }


    return answer;
}
项目:Camel    文件:DefaultCamelContext.java   
public String getComponentDocumentation(String componentName) throws IOException {
    // use the component factory finder to find the package name of the component class, which is the location
    // where the documentation exists as well
    FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
    try {
        Class<?> clazz = finder.findClass(componentName);
        if (clazz == null) {
            // fallback and find existing component
            Component existing = hasComponent(componentName);
            if (existing != null) {
                clazz = existing.getClass();
            } else {
                return null;
            }
        }

        String packageName = clazz.getPackage().getName();
        packageName = packageName.replace('.', '/');
        String path = packageName + "/" + componentName + ".html";

        ClassResolver resolver = getClassResolver();
        InputStream inputStream = resolver.loadResourceAsStream(path);
        log.debug("Loading component documentation for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream});
        if (inputStream != null) {
            try {
                return IOHelper.loadText(inputStream);
            } finally {
                IOHelper.close(inputStream);
            }
        }
        // special for ActiveMQ as it is really just JMS
        if ("ActiveMQComponent".equals(clazz.getSimpleName())) {
            return getComponentDocumentation("jms");
        } else {
            return null;
        }
    } catch (ClassNotFoundException e) {
        return null;
    }
}
项目:Camel    文件:DefaultCamelContext.java   
public String getComponentParameterJsonSchema(String componentName) throws IOException {
    // use the component factory finder to find the package name of the component class, which is the location
    // where the documentation exists as well
    FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
    try {
        Class<?> clazz = finder.findClass(componentName);
        if (clazz == null) {
            // fallback and find existing component
            Component existing = hasComponent(componentName);
            if (existing != null) {
                clazz = existing.getClass();
            } else {
                return null;
            }
        }

        String packageName = clazz.getPackage().getName();
        packageName = packageName.replace('.', '/');
        String path = packageName + "/" + componentName + ".json";

        ClassResolver resolver = getClassResolver();
        InputStream inputStream = resolver.loadResourceAsStream(path);
        log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}", new Object[]{componentName, resolver, inputStream});
        if (inputStream != null) {
            try {
                return IOHelper.loadText(inputStream);
            } finally {
                IOHelper.close(inputStream);
            }
        }
        // special for ActiveMQ as it is really just JMS
        if ("ActiveMQComponent".equals(clazz.getSimpleName())) {
            return getComponentParameterJsonSchema("jms");
        } else {
            return null;
        }
    } catch (ClassNotFoundException e) {
        return null;
    }
}
项目:Camel    文件:DefaultCamelContext.java   
public String getDataFormatParameterJsonSchema(String dataFormatName) throws IOException {
    // use the dataformat factory finder to find the package name of the dataformat class, which is the location
    // where the documentation exists as well
    FactoryFinder finder = getFactoryFinder(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH);
    try {
        Class<?> clazz = finder.findClass(dataFormatName);
        if (clazz == null) {
            return null;
        }

        String packageName = clazz.getPackage().getName();
        packageName = packageName.replace('.', '/');
        String path = packageName + "/" + dataFormatName + ".json";

        ClassResolver resolver = getClassResolver();
        InputStream inputStream = resolver.loadResourceAsStream(path);
        log.debug("Loading dataformat JSON Schema for: {} using class resolver: {} -> {}", new Object[]{dataFormatName, resolver, inputStream});
        if (inputStream != null) {
            try {
                return IOHelper.loadText(inputStream);
            } finally {
                IOHelper.close(inputStream);
            }
        }
        return null;

    } catch (ClassNotFoundException e) {
        return null;
    }
}
项目:Camel    文件:DefaultCamelContext.java   
public String getLanguageParameterJsonSchema(String languageName) throws IOException {
    // use the language factory finder to find the package name of the language class, which is the location
    // where the documentation exists as well
    FactoryFinder finder = getFactoryFinder(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH);
    try {
        Class<?> clazz = finder.findClass(languageName);
        if (clazz == null) {
            return null;
        }

        String packageName = clazz.getPackage().getName();
        packageName = packageName.replace('.', '/');
        String path = packageName + "/" + languageName + ".json";

        ClassResolver resolver = getClassResolver();
        InputStream inputStream = resolver.loadResourceAsStream(path);
        log.debug("Loading language JSON Schema for: {} using class resolver: {} -> {}", new Object[]{languageName, resolver, inputStream});
        if (inputStream != null) {
            try {
                return IOHelper.loadText(inputStream);
            } finally {
                IOHelper.close(inputStream);
            }
        }
        return null;

    } catch (ClassNotFoundException e) {
        return null;
    }
}
项目:Camel    文件:DefaultCamelContext.java   
/**
 * Lazily create a default implementation
 */
protected Injector createInjector() {
    FactoryFinder finder = getDefaultFactoryFinder();
    try {
        return (Injector) finder.newInstance("Injector");
    } catch (NoFactoryAvailableException e) {
        // lets use the default injector
        return new DefaultInjector(this);
    }
}
项目:Camel    文件:DefaultCamelContext.java   
public FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException {
    synchronized (factories) {
        FactoryFinder answer = factories.get(path);
        if (answer == null) {
            answer = factoryFinderResolver.resolveFactoryFinder(getClassResolver(), path);
            factories.put(path, answer);
        }
        return answer;
    }
}
项目:Camel    文件:BlueprintCamelContext.java   
@Override
protected TypeConverter createTypeConverter() {
    // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package
    BundleContext ctx = BundleContextUtils.getBundleContext(getClass());
    if (ctx == null) {
        ctx = bundleContext;
    }
    FactoryFinder finder = new OsgiFactoryFinderResolver(bundleContext).resolveDefaultFactoryFinder(getClassResolver());
    return new OsgiTypeConverter(ctx, this, getInjector(), finder);
}
项目:Camel    文件:OsgiTypeConverter.java   
public OsgiTypeConverter(BundleContext bundleContext, CamelContext camelContext, Injector injector, FactoryFinder factoryFinder) {
    this.bundleContext = bundleContext;
    this.camelContext = camelContext;
    this.injector = injector;
    this.factoryFinder = factoryFinder;
    this.tracker = new ServiceTracker<TypeConverterLoader, Object>(bundleContext, TypeConverterLoader.class.getName(), this);
}
项目:Camel    文件:OsgiDefaultCamelContext.java   
@Override
protected TypeConverter createTypeConverter() {
    // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package
    BundleContext ctx = BundleContextUtils.getBundleContext(getClass());
    if (ctx == null) {
        ctx = bundleContext;
    }
    FactoryFinder finder = new OsgiFactoryFinderResolver(bundleContext).resolveDefaultFactoryFinder(getClassResolver());
    return new OsgiTypeConverter(ctx, this, getInjector(), finder);
}
项目:Camel    文件:OsgiSpringCamelContext.java   
@Override
protected TypeConverter createTypeConverter() {
    // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package
    BundleContext ctx = BundleContextUtils.getBundleContext(getClass());
    if (ctx == null) {
        ctx = bundleContext;
    }
    FactoryFinder finder = new OsgiFactoryFinderResolver(bundleContext).resolveDefaultFactoryFinder(getClassResolver());
    return new OsgiTypeConverter(ctx, this, getInjector(), finder);
}
项目:switchyard    文件:OsgiSwitchYardCamelContextImpl.java   
@Override
protected TypeConverter createTypeConverter() {
    // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package
    BundleContext ctx = BundleContextUtils.getBundleContext(getClass());
    if (ctx == null) {
        ctx = _bundleContext;
    }
    FactoryFinder finder = new OsgiFactoryFinderResolver(_bundleContext).resolveDefaultFactoryFinder(getClassResolver());
    return new OsgiTypeConverter(ctx, getInjector(), finder);
}
项目:Camel    文件:LazyLoadingTypeConverter.java   
public LazyLoadingTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) {
    super(resolver, injector, factoryFinder);
}
项目:Camel    文件:DefaultTypeConverter.java   
public DefaultTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) {
    super(resolver, injector, factoryFinder);
}
项目:Camel    文件:DefaultCamelContext.java   
public FactoryFinder getDefaultFactoryFinder() {
    if (defaultFactoryFinder == null) {
        defaultFactoryFinder = factoryFinderResolver.resolveDefaultFactoryFinder(getClassResolver());
    }
    return defaultFactoryFinder;
}
项目:Camel    文件:DefaultFactoryFinderResolver.java   
public FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver) {
    return resolveFactoryFinder(classResolver, "META-INF/services/org/apache/camel/");
}
项目:Camel    文件:DefaultFactoryFinderResolver.java   
public FactoryFinder resolveFactoryFinder(ClassResolver classResolver, String resourcePath) {
    return new DefaultFactoryFinder(classResolver, resourcePath);
}
项目:Camel    文件:RestApiEndpoint.java   
@Override
public Producer createProducer() throws Exception {
    RestApiProcessorFactory factory = null;

    RestConfiguration config = getCamelContext().getRestConfiguration(componentName, true);

    // lookup in registry
    Set<RestApiProcessorFactory> factories = getCamelContext().getRegistry().findByType(RestApiProcessorFactory.class);
    if (factories != null && factories.size() == 1) {
        factory = factories.iterator().next();
    }

    // lookup on classpath using factory finder to automatic find it (just add camel-swagger-java to classpath etc)
    if (factory == null) {
        String name = apiComponentName != null ? apiComponentName : config.getApiComponent();
        if (name == null) {
            name = DEFAULT_API_COMPONENT_NAME;
        }
        try {
            FactoryFinder finder = getCamelContext().getFactoryFinder(RESOURCE_PATH);
            Object instance = finder.newInstance(name);
            if (instance instanceof RestApiProcessorFactory) {
                factory = (RestApiProcessorFactory) instance;
            }
        } catch (NoFactoryAvailableException e) {
            // ignore
        }
    }

    if (factory != null) {

        // if no explicit port/host configured, then use port from rest configuration
        String host = "";
        int port = 80;

        if (config.getHost() != null) {
            host = config.getHost();
        }
        int num = config.getPort();
        if (num > 0) {
            port = num;
        }

        // if no explicit hostname set then resolve the hostname
        if (ObjectHelper.isEmpty(host)) {
            if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
                host = "0.0.0.0";
            } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
                host = HostUtils.getLocalHostName();
            } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
                host = HostUtils.getLocalIp();
            }

            // no host was configured so calculate a host to use
            // there should be no schema in the host (but only port)
            String targetHost = host + (port != 80 ? ":" + port : "");
            getParameters().put("host", targetHost);
        }

        // the base path should start with a leading slash
        String path = getPath();
        if (path != null && !path.startsWith("/")) {
            path = "/" + path;
        }

        // whether listing of the context id's is enabled or not
        boolean contextIdListing = config.isApiContextListing();

        Processor processor = factory.createApiProcessor(getCamelContext(), path, getContextIdPattern(), contextIdListing, config, getParameters());
        return new RestApiProducer(this, processor);
    } else {
        throw new IllegalStateException("Cannot find RestApiProcessorFactory in Registry or classpath (such as the camel-swagger-java component)");
    }
}
项目:Camel    文件:OsgiFactoryFinderResolver.java   
public FactoryFinder resolveDefaultFactoryFinder(ClassResolver classResolver) {
    return resolveFactoryFinder(classResolver, "META-INF/services/org/apache/camel/");
}
项目:Camel    文件:OsgiFactoryFinderResolver.java   
public FactoryFinder resolveFactoryFinder(ClassResolver classResolver, String resourcePath) {
    return new OsgiFactoryFinder(bundleContext, classResolver, resourcePath);
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public FactoryFinder getDefaultFactoryFinder() {
  return context.getDefaultFactoryFinder();
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException {
  return context.getFactoryFinder(path);
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
public FactoryFinder getDefaultFactoryFinder() {
    return context.getDefaultFactoryFinder();
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
public FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException {
    return context.getFactoryFinder(path);
}
项目:Camel    文件:CamelContext.java   
/**
 * Gets the default FactoryFinder which will be used for the loading the factory class from META-INF
 *
 * @return the default factory finder
 */
FactoryFinder getDefaultFactoryFinder();
项目:Camel    文件:CamelContext.java   
/**
 * Gets the FactoryFinder which will be used for the loading the factory class from META-INF in the given path
 *
 * @param path the META-INF path
 * @return the factory finder
 * @throws NoFactoryAvailableException is thrown if a factory could not be found
 */
FactoryFinder getFactoryFinder(String path) throws NoFactoryAvailableException;