public Map<AccessibleObject, Supplier<Object>> getInjectors(Class<?> clazz) { Map<AccessibleObject, Supplier<Object>> injectors = new HashMap<>(); // introspect class InjectingComponentType componentType = new InjectingComponentType(clazz); DefaultIntrospectionContext context = new DefaultIntrospectionContext(); TypeMapping typeMapping = new TypeMapping(); context.addTypeMapping(clazz, typeMapping); introspectionHelper.resolveTypeParameters(clazz, typeMapping); classVisitor.visit(componentType, clazz, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, clazz, context); } // process injection sites for (Map.Entry<ModelObject, InjectionSite> entry : componentType.getInjectionSiteMappings().entrySet()) { ModelObject key = entry.getKey(); InjectionSite value = entry.getValue(); if (key instanceof Reference) { Reference<?> reference = (Reference) key; handleReference(reference, value, clazz, injectors); } else if (key instanceof Producer) { Producer producer = (Producer) key; throw new UnsupportedOperationException("Not yet implemented"); } else if (key instanceof Consumer) { throw new UnsupportedOperationException("Not yet implemented"); } } return injectors; }
public Map<AccessibleObject, Supplier<Object>> getInjectors(Class<?> clazz) { Map<AccessibleObject, Supplier<Object>> injectors = new HashMap<>(); // introspect class InjectingComponentType componentType = new InjectingComponentType(clazz); DefaultIntrospectionContext context = new DefaultIntrospectionContext(); TypeMapping typeMapping = new TypeMapping(); context.addTypeMapping(clazz, typeMapping); introspectionHelper.resolveTypeParameters(clazz, typeMapping); classVisitor.visit(componentType, clazz, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, clazz, context); } // process injection sites for (Map.Entry<ModelObject, InjectionSite> entry : componentType.getInjectionSiteMappings().entrySet()) { ModelObject key = entry.getKey(); InjectionSite value = entry.getValue(); if (key instanceof Reference) { Reference<?> reference = (Reference) key; handleReference(reference, value, clazz, injectors); } else if (key instanceof Producer) { Producer producer = (Producer) key; throw new UnsupportedOperationException("Not yet implemented"); } else if (key instanceof Consumer) { throw new UnsupportedOperationException("Not yet implemented"); } } return injectors; }
public void process(Component<JavaImplementation> component, IntrospectionContext context) { JavaImplementation implementation = component.getImplementation(); Object instance = implementation.getInstance(); InjectingComponentType componentType = implementation.getComponentType(); if (instance == null) { introspector.introspect(componentType, context); } else { componentType.setScope(Scope.COMPOSITE); if (componentType.getServices().isEmpty()) { // introspect services if not defined addServiceDefinitions(instance, componentType, context); } processAnnotations(instance, component, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, instance.getClass(), context); } } }
public void introspect(InjectingComponentType componentType, IntrospectionContext context) { componentType.setScope(Scope.STATELESS); Class<?> implClass = componentType.getImplClass(); if (implClass.isInterface()) { InvalidImplementation failure = new InvalidImplementation("Implementation class is an interface", implClass, componentType); context.addError(failure); return; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); helper.resolveTypeParameters(implClass, mapping); } try { classVisitor.visit(componentType, implClass, context); heuristic.applyHeuristics(componentType, implClass, context); } catch (NoClassDefFoundError e) { // May be thrown as a result of a referenced class not being on the classpath context.addError(new ImplementationArtifactNotFound(implClass.getName(), e.getMessage(), componentType)); } validateScope(componentType, implClass, context); for (PostProcessor postProcessor : postProcessors) { postProcessor.process(componentType, implClass, context); } }