public void applyHeuristics(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { // if any services have been defined, just introspect policy if (!componentType.getServices().isEmpty()) { for (Service<ComponentType> definition : componentType.getServices().values()) { JavaServiceContract contract = (JavaServiceContract) definition.getServiceContract(); policyIntrospector.introspectPolicyOnOperations(contract, implClass, context); } return; } Set<Class<?>> interfaces = helper.getImplementedInterfaces(implClass); if (interfaces.isEmpty()) { // no interfaces, use implementation Service<ComponentType> service = createServiceDefinition(implClass, implClass, componentType, context); componentType.add(service); } else { // class implements all interfaces that are not management interfaces or in the Java package for (Class<?> interfaze : interfaces) { Package pkg = interfaze.getPackage(); if (interfaze.isAnnotationPresent(Management.class) || pkg == null || pkg.getName().startsWith("java")) { continue; } Service<ComponentType> service = createServiceDefinition(interfaze, implClass, componentType, context); componentType.add(service); } } }
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]; processSite(componentType, typeMapping, name, setter, parameterType, site, context); } }
public void applyHeuristics(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { // if the service contracts have not already been defined then introspect them if (componentType.getServices().isEmpty()) { // get the most specific interfaces implemented by the class Set<Class<?>> interfaces = helper.getImplementedInterfaces(implClass); // if the class does not implement any interfaces, then the class itself is the service contract // we don't have to worry about proxies because all wires to system components are optimized if (interfaces.isEmpty()) { Service<ComponentType> service = createServiceDefinition(implClass, componentType, context); componentType.add(service); } else { // otherwise, expose all of the implemented interfaces for (Class<?> serviceInterface : interfaces) { Service<ComponentType> service = createServiceDefinition(serviceInterface, componentType, context); componentType.add(service); } } } }
private void evaluateSetters(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); 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); TypeMapping typeMapping = context.getTypeMapping(implClass); Type genericType = setter.getGenericParameterTypes()[0]; Class<?> parameterType = helper.getBaseType(genericType, typeMapping); processSite(componentType, name, setter, parameterType, implClass, site, context); } }
if (componentType.getServices().size() != 1) { InvalidAnnotation error = new InvalidAnnotation("Binding annotation must specify a service interface", implClass, annotation, implClass); context.addError(error); return; boundService = componentType.getServices().values().iterator().next(); } else { String name = serviceInterface.getName(); for (Service<ComponentType> service : componentType.getServices().values()) { String interfaceName = service.getServiceContract().getQualifiedInterfaceName(); if (interfaceName.equals(name)) {
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); } } }