private <I> ScopedComponent createPhysicalComponent(LogicalComponent<?> logicalComponent, I instance) { URI uri = logicalComponent.getUri(); InjectingComponentType type = (InjectingComponentType) logicalComponent.getDefinition().getComponentType(); type.getInjectionSites(); SingletonComponent component = new SingletonComponent(uri, instance, type.getInjectionSites()); component.setClassLoaderId(BOOT_CONTRIBUTION); return component; }
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(); Signature constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<Injectable>(constructor.getParameterTypes().size()); for (int i = 0; i < constructor.getParameterTypes().size(); 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 evaluateFields(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); TypeMapping typeMapping = context.getTypeMapping(implClass); Set<Field> fields = helper.getInjectionFields(implClass); for (Field field : fields) { InjectionSite site = new FieldInjectionSite(field); // skip sites that have already been mapped if (sites.containsKey(site)) { continue; } String name = helper.getSiteName(field, null); Type parameterType = field.getGenericType(); Annotation[] annotations = field.getAnnotations(); processSite(componentType, typeMapping, name, field, parameterType, site, annotations, context); } }
void evaluateSetters(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); TypeMapping typeMapping = context.getTypeMapping(implClass); Set<Method> setters = helper.getInjectionMethods(implClass, componentType.getServices().values()); for (Method setter : setters) { InjectionSite site = new MethodInjectionSite(setter, 0); // skip sites that have already been mapped if (sites.containsKey(site)) { continue; } String name = helper.getSiteName(setter, null); Type parameterType = setter.getGenericParameterTypes()[0]; Annotation[] annotations = setter.getAnnotations(); processSite(componentType, typeMapping, name, setter, parameterType, site, annotations, context); } }
private void evaluateConstructor(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); Constructor<?> constructor; try { if (componentType.getConstructor() == null) { // there was an error with the constructor previously, just return return; } constructor = componentType.getConstructor().getConstructor(implClass); } catch (ClassNotFoundException e) { throw new AssertionError(e); } catch (NoSuchMethodException e) { throw new AssertionError(e); } 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); Annotation[] annotations = constructor.getParameterAnnotations()[i]; processSite(componentType, typeMapping, name, constructor, parameterType, site, annotations, context); } }
/** * Merges the POJO component type into the web component type. * * @param webType the web component type to merge into * @param componentType the component type to merge * @param context the introspection context */ private void mergeComponentTypes(WebComponentType webType, InjectingComponentType componentType, IntrospectionContext context) { for (Map.Entry<String, ReferenceDefinition> entry : componentType.getReferences().entrySet()) { String name = entry.getKey(); AbstractReference reference = webType.getReferences().get(name); if (reference != null) { ServiceContract source = reference.getServiceContract(); ServiceContract target = entry.getValue().getServiceContract(); MatchResult result = matcher.isAssignableFrom(source, target, false); if (!result.isAssignable()) { // TODO display areas where it was not matching IncompatibleReferenceDefinitions failure = new IncompatibleReferenceDefinitions(name); context.addError(failure); } } else { webType.add(entry.getValue()); } } // apply all injection sites for (Map.Entry<InjectionSite, Injectable> entry : componentType.getInjectionSites().entrySet()) { webType.addMapping(componentType.getImplClass(), entry.getKey(), entry.getValue()); } }