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()); }
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); }
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); } }
/** * 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); } }
@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); } }
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()); }
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()); }
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); }
@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(); } }
@Override public Injector getInjector() { return injector; }
@Override public void setInjector(Injector injector) { this.injector = injector; }
public LazyLoadingTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) { super(resolver, injector, factoryFinder); }
public DefaultTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) { super(resolver, injector, factoryFinder); }
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; }
private <T> T newInstance(String key, Injector injector, Class<T> expectedType) throws IOException, ClassNotFoundException { return newInstance(key, injector, null, expectedType); }
public Injector getInjector() { if (injector == null) { injector = createInjector(); } return injector; }
public void setInjector(Injector injector) { this.injector = injector; }
public void testInjectorIsDefaultByDefault() throws Exception { Injector injector = context.getInjector(); assertIsInstanceOf(DefaultInjector.class, injector); }
public GuiceInjector(com.google.inject.Injector injector) { this.injector = injector; }
@Inject public GuiceCamelContext(com.google.inject.Injector injector) { this.injector = injector; }
@Override @Inject(optional = true) public void setInjector(Injector injector) { super.setInjector(injector); }
@Override protected Injector createInjector() { return new GuiceInjector(injector); }
CdiCamelInjector(Injector injector, BeanManager manager) { this.injector = injector; this.manager = manager; }
public void setInjector(Injector injector) { getDelegate().setInjector(injector); }
public Injector getInjector() { return getDelegate().getInjector(); }
public void setInjector(Injector injector) { // do nothing }
public Injector getInjector() { return null; }
@Override public Injector getInjector() { return context.getInjector(); }
@Inject public GuiceInjector(final com.google.inject.Injector guice) { this.guice = requireNonNull(guice, "An injector is required."); }
/** * Returns the injector used to instantiate objects by type * * @return the injector */ Injector getInjector();