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

项目:syndesis    文件:ConnectorHandler.java   
private ComponentProxyComponent resolveComponent(CamelContext context, Connector step) {
    ComponentProxyFactory factory = ComponentProxyComponent::new;

    if (step.getFactory() != null ) {
        final ClassResolver resolver = context.getClassResolver();
        final Injector injector = context.getInjector();

        Class<? extends ComponentProxyFactory> type = resolver.resolveClass(step.getFactory(), ComponentProxyFactory.class);
        if (type == null) {
            throw new IllegalArgumentException("Unable to resolve a ComponentProxyFactory of type: " + step.getFactory());
        }

        factory = injector.newInstance(type);
        if (factory == null) {
            throw new IllegalArgumentException("Unable to instantiate a ComponentProxyFactory of type: " + step.getFactory());
        }
    }

    return factory.newInstance(step.getComponentId(), step.getComponentScheme());
}
项目: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    文件:DefaultFactoryFinder.java   
private <T> T newInstance(String key, Injector injector, String propertyPrefix, Class<T> expectedType)
    throws IOException, ClassNotFoundException {
    Class<?> type = findClass(key, propertyPrefix);
    Object value = injector.newInstance(type);
    if (expectedType.isInstance(value)) {
        return expectedType.cast(value);
    } else {
        throw new ClassCastException("Not instanceof " + expectedType.getName() + " value: " + value);
    }
}
项目: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    文件:Activator.java   
@SuppressWarnings("unchecked")
protected T createInstance(String name, URL url, Injector injector) {
    try {
        Properties properties = loadProperties(url);
        String classname = (String) properties.get("class");
        Class<?> type = bundle.loadClass(classname);
        if (!this.type.isAssignableFrom(type)) {
            throw new IllegalArgumentException("Type is not a " + this.type.getName() + " implementation. Found: " + type.getName());
        }
        return injector.newInstance((Class<T>) type);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("Invalid URI, no " + this.type.getName() + " registered for scheme : " + name, e);
    }
}
项目:Camel    文件:InjectorDefaultsTest.java   
public void testNewInstance() throws Exception {
    Injector injector = context.getInjector();

    MyFoo foo = injector.newInstance(MyFoo.class);
    foo.setName("Claus");

    MyFoo foo2 = injector.newInstance(MyFoo.class);
    assertNotSame(foo, foo2);

    assertEquals("Claus", foo.getName());
    assertNull(foo2.getName());
}
项目:Camel    文件:InjectorDefaultsTest.java   
public void testSharedInstance() throws Exception {
    Injector injector = context.getInjector();

    MyBarSingleton bar = injector.newInstance(MyBarSingleton.class, new MyBarSingleton());
    bar.setName("Claus");

    MyBarSingleton bar2 = injector.newInstance(MyBarSingleton.class, bar);
    assertSame(bar, bar2);

    assertEquals("Claus", bar.getName());
    assertEquals("Claus", bar2.getName());
}
项目: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    文件:SpringCamelContext.java   
@Override
protected Injector createInjector() {
    if (applicationContext instanceof ConfigurableApplicationContext) {
        return new SpringInjector((ConfigurableApplicationContext)applicationContext);
    } else {
        LOG.warn("Cannot use SpringInjector as applicationContext is not a ConfigurableApplicationContext as its: "
                  + applicationContext);
        return super.createInjector();
    }
}
项目:Camel    文件:BaseTypeConverterRegistry.java   
@Override
public Injector getInjector() {
    return injector;
}
项目:Camel    文件:BaseTypeConverterRegistry.java   
@Override
public void setInjector(Injector injector) {
    this.injector = injector;
}
项目: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    文件:DefaultFactoryFinder.java   
public <T> List<T> newInstances(String key, Injector injector, Class<T> type) throws ClassNotFoundException, IOException {
    List<Class<T>> list = CastUtils.cast(findClasses(key));
    List<T> answer = new ArrayList<T>(list.size());
    answer.add(newInstance(key, injector, type));
    return answer;
}
项目:Camel    文件:DefaultFactoryFinder.java   
private <T> T newInstance(String key, Injector injector, Class<T> expectedType) throws IOException,
    ClassNotFoundException {
    return newInstance(key, injector, null, expectedType);
}
项目:Camel    文件:DefaultCamelContext.java   
public Injector getInjector() {
    if (injector == null) {
        injector = createInjector();
    }
    return injector;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setInjector(Injector injector) {
    this.injector = injector;
}
项目:Camel    文件:InjectorDefaultsTest.java   
public void testInjectorIsDefaultByDefault() throws Exception {
    Injector injector = context.getInjector();
    assertIsInstanceOf(DefaultInjector.class, injector);
}
项目:Camel    文件:GuiceInjector.java   
public GuiceInjector(com.google.inject.Injector injector) {
    this.injector = injector;
}
项目:Camel    文件:GuiceCamelContext.java   
@Inject
public GuiceCamelContext(com.google.inject.Injector injector) {
    this.injector = injector;
}
项目:Camel    文件:GuiceCamelContext.java   
@Override
@Inject(optional = true)
public void setInjector(Injector injector) {
    super.setInjector(injector);
}
项目:Camel    文件:GuiceCamelContext.java   
@Override
protected Injector createInjector() {
    return new GuiceInjector(injector);
}
项目:Camel    文件:CdiCamelInjector.java   
CdiCamelInjector(Injector injector, BeanManager manager) {
    this.injector = injector;
    this.manager = manager;
}
项目:Camel    文件:OsgiTypeConverter.java   
public void setInjector(Injector injector) {
    getDelegate().setInjector(injector);
}
项目:Camel    文件:OsgiTypeConverter.java   
public Injector getInjector() {
    return getDelegate().getInjector();
}
项目:Camel    文件:MockTypeConverterRegistry.java   
public void setInjector(Injector injector) {
   // do nothing
}
项目:Camel    文件:MockTypeConverterRegistry.java   
public Injector getInjector() {
    return null;
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
public Injector getInjector() {
  return context.getInjector();
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
public Injector getInjector() {
    return context.getInjector();
}
项目:camel-cdi    文件:CdiCamelInjector.java   
CdiCamelInjector(Injector injector, BeanManager manager) {
    this.injector = injector;
    this.manager = manager;
}
项目:jooby    文件:GuiceInjector.java   
@Inject
public GuiceInjector(final com.google.inject.Injector guice) {
  this.guice = requireNonNull(guice, "An injector is required.");
}
项目:Camel    文件:CamelContext.java   
/**
 * Returns the injector used to instantiate objects by type
 *
 * @return the injector
 */
Injector getInjector();