@SuppressWarnings({"unchecked"}) public ImplementationManager createManager() { ObjectFactory<?> factory = reflectionFactory.createInstantiator(constructor, getConstructorParameterFactories(cdiSources)); Map<Injectable, Injector<?>> mappings = createInjectorMappings(); Injectable[] attributes = mappings.keySet().toArray(new Injectable[mappings.size()]); Injector<Object>[] injectors = mappings.values().toArray(new Injector[mappings.size()]); return new ImplementationManagerImpl(componentUri, factory, attributes, injectors, initInvoker, destroyInvoker, reinjectable, cl); }
private LifecycleInvoker getInitInvoker(ImplementationManagerDefinition definition) { LifecycleInvoker initInvoker = null; Method initMethod = definition.getInitMethod(); if (initMethod != null) { initInvoker = reflectionFactory.createLifecycleInvoker(initMethod); } return initInvoker; }
injector = createInjector(siteName, supplier, (WebContextInjectionSite) site); } else if (site instanceof FieldInjectionSite) { injector = reflectionFactory.createInjector(((FieldInjectionSite) site).getField(), supplier); } else if (site instanceof MethodInjectionSite) { injector = reflectionFactory.createInjector(((MethodInjectionSite) site).getMethod(), supplier); } else { throw new UnsupportedOperationException("Unsupported injection site type: " + site.getClass());
public void attach(PhysicalConnectionSource source, SystemConnectionTarget target, ChannelConnection connection) { URI targetUri = target.getUri(); URI targetName = UriHelper.getDefragmentedName(targetUri); SystemComponent component = (SystemComponent) manager.getComponent(targetName); if (component == null) { throw new Fabric3Exception("Target component not found: " + targetName); } ClassLoader loader = target.getClassLoader(); Method method = (Method) target.getConsumerObject(); // if the object is not a method, it is a programming error ConsumerInvoker invoker = reflectionFactory.createConsumerInvoker(method); EventStream stream = connection.getEventStream(); Class<?> type = connection.getEventStream().getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } InvokerEventStreamHandler handler = new InvokerEventStreamHandler(invoker, component, loader); stream.addHandler(handler); }
PhysicalOperationDefinition operation = chain.getPhysicalOperation(); Method method = MethodUtils.findMethod(sourceDefinition, targetDefinition, operation, implementationClass, loader, classLoaderRegistry); ServiceInvoker invoker = reflectionFactory.createServiceInvoker(method); InvokerInterceptor interceptor; if (sourceDefinition instanceof PojoSourceDefinition && targetDefinition.getClassLoaderId().equals(sourceDefinition.getClassLoaderId())) {
FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); Injector<?> injector = reflectionFactory.createInjector(field, supplier); injectors.put(attribute, injector); } catch (NoSuchFieldException e) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); Injector<?> injector = reflectionFactory.createInjector(method, supplier); injectors.put(attribute, injector);
public void attach(PhysicalConnectionSource source, JavaConnectionTarget target, ChannelConnection connection) { URI targetUri = target.getUri(); URI targetName = UriHelper.getDefragmentedName(targetUri); JavaComponent component = (JavaComponent) manager.getComponent(targetName); if (component == null) { throw new Fabric3Exception("Target component not found: " + targetName); } if (target.isDirectConnection()) { // A direct connection; create a setter that will inject the field, method or ctor param annotated with @Consumer component.setSupplier(target.getInjectable(), connection.getDirectConnection().get()); } else { // Not a direct connection; a consumer method that is invoked and passed an event from the channel via an event stream // Note that a null supplier must be injected in this case as the @Consumer annotation creates an injector for the case where the // method takes a direct connection to the channel. The null supplier forces the injector not to activate since the @Consumer method is used to // receive events and not serve as a setter for the direct connection component.setSupplier(target.getInjectable(), () -> null); ClassLoader loader = target.getClassLoader(); Method method = (Method) target.getConsumerObject(); // if the object is not a method, it is a programming error ConsumerInvoker invoker = reflectionFactory.createConsumerInvoker(method); EventStream stream = connection.getEventStream(); Class<?> type = connection.getEventStream().getEventType(); if (!Object.class.equals(type)) { // add a filter if the event type is not Object stream.addHandler(new FilterHandler(type)); } InvokerEventStreamHandler handler = new InvokerEventStreamHandler(invoker, component, loader); stream.addHandler(handler); } }
public void attach(PhysicalWireSource source, JavaWireTarget target, Wire wire) { URI targetName = UriHelper.getDefragmentedName(target.getUri()); Component component = manager.getComponent(targetName); if (component == null) { throw new Fabric3Exception("Target not found: " + targetName); } JavaComponent javaComponent = (JavaComponent) component; Class<?> implementationClass = javaComponent.getImplementationClass(); ClassLoader loader = target.getClassLoader(); // attach the invoker interceptor to forward invocation chains for (InvocationChain chain : wire.getInvocationChains()) { PhysicalOperation operation = chain.getPhysicalOperation(); Method method = MethodUtils.findMethod(source, target, operation, implementationClass, loader); ServiceInvoker invoker = reflectionFactory.createServiceInvoker(method); InvokerInterceptor interceptor; if (source instanceof PojoWireSource && target.getClassLoader().equals(source.getClassLoader())) { // if the source is Java and target classloaders are equal, do not set the TCCL interceptor = new InvokerInterceptor(invoker, javaComponent); } else { // If the source and target classloaders are not equal, configure the interceptor to set the TCCL to the target classloader // when dispatching to a target instance. This guarantees when application code executes, it does so with the TCCL set to the // target component's classloader. interceptor = new InvokerInterceptor(invoker, javaComponent, loader); } chain.addInterceptor(interceptor); } }
FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); Injector<?> injector = reflectionFactory.createInjector(field, supplier); injectors.put(attribute, injector); } catch (NoSuchFieldException e) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); Injector<?> injector = reflectionFactory.createInjector(method, supplier); injectors.put(attribute, injector);
private LifecycleInvoker getDestroyInvoker(ImplementationManagerDefinition definition) { LifecycleInvoker destroyInvoker = null; Method destroyMethod = definition.getDestroyMethod(); if (destroyMethod != null) { destroyInvoker = reflectionFactory.createLifecycleInvoker(destroyMethod); } return destroyInvoker; }
@SuppressWarnings({"unchecked"}) public ImplementationManager createManager() { Supplier<?> factory = reflectionFactory.createInstantiator(constructor, getConstructorParameterSuppliers(cdiSources)); Map<Injectable, Injector<?>> mappings = createInjectorMappings(); Injectable[] attributes = mappings.keySet().toArray(new Injectable[mappings.size()]); Injector<Object>[] injectors = mappings.values().toArray(new Injector[mappings.size()]); return new ImplementationManagerImpl(factory, attributes, injectors, initInvoker, destroyInvoker, reinjectable, cl); }
private Injector<?> createInjector(ObjectFactory<?> factory, String artifactName, MethodInjectionSite site, ClassLoader classLoader) throws InjectionCreationException { try { Method method = getMethod(site, artifactName, classLoader); return reflectionFactory.createInjector(method, factory); } catch (ClassNotFoundException e) { throw new InjectionCreationException(e); } catch (NoSuchMethodException e) { throw new InjectionCreationException(e); } }
private LifecycleInvoker getInitInvoker(ImplementationManagerDefinition definition) { LifecycleInvoker initInvoker = null; Method initMethod = definition.getInitMethod(); if (initMethod != null) { initInvoker = reflectionFactory.createLifecycleInvoker(initMethod); } return initInvoker; }
@SuppressWarnings({"unchecked"}) public ImplementationManager createManager() { Supplier<?> factory = reflectionFactory.createInstantiator(constructor, getConstructorParameterSuppliers(cdiSources)); Map<Injectable, Injector<?>> mappings = createInjectorMappings(); Injectable[] attributes = mappings.keySet().toArray(new Injectable[mappings.size()]); Injector<Object>[] injectors = mappings.values().toArray(new Injector[mappings.size()]); return new ImplementationManagerImpl(factory, attributes, injectors, initInvoker, destroyInvoker, reinjectable, cl); }
private Injector<?> createInjector(ObjectFactory<?> factory, String artifactName, FieldInjectionSite site, ClassLoader classLoader) throws InjectionCreationException { try { Field field = getField(site, artifactName, classLoader); return reflectionFactory.createInjector(field, factory); } catch (NoSuchFieldException e) { throw new InjectionCreationException(e); } catch (ClassNotFoundException e) { throw new InjectionCreationException(e); } }
private LifecycleInvoker getDestroyInvoker(ImplementationManagerDefinition definition) { LifecycleInvoker destroyInvoker = null; Method destroyMethod = definition.getDestroyMethod(); if (destroyMethod != null) { destroyInvoker = reflectionFactory.createLifecycleInvoker(destroyMethod); } return destroyInvoker; }
FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); Injector<?> injector = reflectionFactory.createInjector(field, factory); injectors.put(attribute, injector); } catch (NoSuchFieldException e) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getSignature().getMethod(implementationClass); Injector<?> injector = reflectionFactory.createInjector(method, factory); injectors.put(attribute, injector); } catch (ClassNotFoundException e) {
private LifecycleInvoker getInitInvoker(ImplementationManagerDefinition definition, Class<?> implClass) throws NoSuchMethodException, ClassNotFoundException { LifecycleInvoker initInvoker = null; Method initMethod = getMethod(implClass, definition.getInitMethod()); if (initMethod != null) { initInvoker = reflectionFactory.createLifecycleInvoker(initMethod); } return initInvoker; }
private LifecycleInvoker getDestroyInvoker(ImplementationManagerDefinition definition, Class<?> implClass) throws NoSuchMethodException, ClassNotFoundException { LifecycleInvoker destroyInvoker = null; Method destroyMethod = getMethod(implClass, definition.getDestroyMethod()); if (destroyMethod != null) { destroyInvoker = reflectionFactory.createLifecycleInvoker(destroyMethod); } return destroyInvoker; }