public void applyHeuristics(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { // if there is already a defined constructor then do nothing if (componentType.getConstructor() != null) { return; } Constructor<?> ctor = findConstructor(implClass, componentType, context); componentType.setConstructor(ctor); }
public void processInjectionSites(InjectingComponentType componentType, ImplementationManagerDefinition managerDefinition) { Map<InjectionSite, Injectable> mappings = componentType.getInjectionSites(); // add injections for all the active constructor args Map<InjectionSite, Injectable> construction = managerDefinition.getConstruction(); Constructor<?> constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<>(); if (constructor != null) { for (int i = 0; i < constructor.getParameterTypes().length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); Injectable attribute = mappings.get(site); construction.put(site, attribute); byConstruction.add(attribute); } } // add field/method injections Map<InjectionSite, Injectable> postConstruction = managerDefinition.getPostConstruction(); Map<InjectionSite, Injectable> reinjection = managerDefinition.getReinjectables(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof ConstructorInjectionSite) { continue; } Injectable attribute = entry.getValue(); if (!byConstruction.contains(attribute)) { postConstruction.put(site, attribute); } reinjection.put(site, attribute); } }
public void processInjectionSites(InjectingComponentType componentType, ImplementationManagerDefinition managerDefinition) { Map<InjectionSite, Injectable> mappings = componentType.getInjectionSites(); // add injections for all the active constructor args Map<InjectionSite, Injectable> construction = managerDefinition.getConstruction(); Constructor<?> constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<>(); if (constructor != null) { for (int i = 0; i < constructor.getParameterTypes().length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); Injectable attribute = mappings.get(site); construction.put(site, attribute); byConstruction.add(attribute); } } // add field/method injections Map<InjectionSite, Injectable> postConstruction = managerDefinition.getPostConstruction(); Map<InjectionSite, Injectable> reinjection = managerDefinition.getReinjectables(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof ConstructorInjectionSite) { continue; } Injectable attribute = entry.getValue(); if (!byConstruction.contains(attribute)) { postConstruction.put(site, attribute); } reinjection.put(site, attribute); } }
void evaluateConstructor(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); Constructor<?> constructor = componentType.getConstructor(); TypeMapping typeMapping = context.getTypeMapping(implClass); Type[] parameterTypes = constructor.getGenericParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); // skip sites that have already been mapped if (sites.containsKey(site)) { continue; } Type parameterType = parameterTypes[i]; String name = helper.getSiteName(constructor, i, null); processSite(componentType, typeMapping, name, constructor, parameterType, site, context); } }
private void evaluateConstructor(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Constructor<?> constructor = componentType.getConstructor(); if (constructor == null) { return; } Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); Type[] parameterTypes = constructor.getGenericParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); // skip sites that have already been mapped if (sites.containsKey(site)) { continue; } TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> parameterType = helper.getBaseType(parameterTypes[i], typeMapping); String name = helper.getSiteName(constructor, i, null); processSite(componentType, name, constructor, parameterType, implClass, site, context); } }
public void applyHeuristics(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { // apply service heuristic serviceHeuristic.applyHeuristics(componentType, implClass, context); if (componentType.getConstructor() == null) { Constructor<?> ctor = findConstructor(implClass, componentType, context); componentType.setConstructor(ctor); } if (componentType.getProperties().isEmpty() && componentType.getReferences().isEmpty() && componentType.getResourceReferences().isEmpty()) { evaluateConstructor(componentType, implClass, context); evaluateSetters(componentType, implClass, context); evaluateFields(componentType, implClass, context); } Scope scope = componentType.getScope(); if (componentType.isManaged() && !scope.isSingleton()) { IllegalManagementAttribute warning = new IllegalManagementAttribute(implClass, componentType); context.addWarning(warning); } }
public PhysicalComponent generate(LogicalComponent<SystemImplementation> component) throws Fabric3Exception { Component<SystemImplementation> definition = component.getDefinition(); SystemImplementation implementation = definition.getImplementation(); InjectingComponentType type = implementation.getComponentType(); ImplementationManagerDefinition managerDefinition = new ImplementationManagerDefinition(); managerDefinition.setReinjectable(true); managerDefinition.setConstructor(type.getConstructor()); managerDefinition.setInitMethod(type.getInitMethod()); managerDefinition.setDestroyMethod(type.getDestroyMethod()); managerDefinition.setImplementationClass(implementation.getImplementationClass()); managerDefinition.setClassLoaderUri(definition.getContributionUri()); helper.processInjectionSites(type, managerDefinition); // create the physical component definition PhysicalSystemComponent physical = new PhysicalSystemComponent(); physical.setEagerInit(type.isEagerInit()); physical.setManaged(type.isManaged()); physical.setManagementInfo(type.getManagementInfo()); physical.setManagerDefinition(managerDefinition); helper.processPropertyValues(component, physical); return physical; }
public void generate(PhysicalJavaComponent physicalComponent, LogicalComponent<? extends JavaImplementation> component) { Component<? extends JavaImplementation> logical = component.getDefinition(); JavaImplementation implementation = logical.getImplementation(); InjectingComponentType type = implementation.getComponentType(); Scope scope = type.getScope(); // create the instance factory definition ImplementationManagerDefinition managerDefinition = new ImplementationManagerDefinition(); managerDefinition.setReinjectable(Scope.COMPOSITE == scope); managerDefinition.setConstructor(type.getConstructor()); managerDefinition.setInitMethod(type.getInitMethod()); managerDefinition.setDestroyMethod(type.getDestroyMethod()); managerDefinition.setImplementationClass(implementation.getImplementationClass()); managerDefinition.setClassLoaderUri(component.getDefinition().getContributionUri()); helper.processInjectionSites(type, managerDefinition); // create the physical component definition physicalComponent.setScope(scope); physicalComponent.setEagerInit(type.isEagerInit()); physicalComponent.setManagerDefinition(managerDefinition); physicalComponent.setManaged(type.isManaged()); physicalComponent.setManagementInfo(type.getManagementInfo()); helper.processPropertyValues(component, physicalComponent); }