private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
@SuppressWarnings("unchecked") private void processAnnotations(Object instance, Component<?> definition, IntrospectionContext context) { InjectingComponentType componentType = (InjectingComponentType) definition.getComponentType(); Class<?> implClass = instance.getClass(); // handle consumer annotations AnnotationProcessor consumerProcessor = annotationProcessors.get(org.fabric3.api.annotation.Consumer.class); for (Method method : implClass.getDeclaredMethods()) { org.fabric3.api.annotation.Consumer consumer = method.getAnnotation(org.fabric3.api.annotation.Consumer.class); if (consumer == null) { continue; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); } helper.resolveTypeParameters(implClass, mapping); consumerProcessor.visitMethod(consumer, method, implClass, componentType, context); } // add automatic configuration for consumer annotations for (Consumer<ComponentType> consumer : componentType.getConsumers().values()) { String name = consumer.getName(); Consumer<Component> componentConsumer = new Consumer<>(name); componentConsumer.setSources(Collections.singletonList(URI.create(name))); definition.add(componentConsumer); } }
public void visitConstructorParameter(org.fabric3.api.annotation.Consumer annotation, java.lang.reflect.Constructor<?> constructor, int index, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { String name = helper.getSiteName(constructor, index, annotation.value()); TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> genericType = constructor.getParameterTypes()[index]; Type logicalParamType = typeMapping.getActualType(genericType); DataType dataType = createDataType(genericType, logicalParamType, typeMapping); ServiceContract contract = null; if (contractProcessor != null) { Class<?> baseType = helper.getBaseType(genericType, typeMapping); contract = contractProcessor.introspect(baseType, implClass, context, componentType); } ConstructorInjectionSite injectionSite = new ConstructorInjectionSite(constructor, index); Consumer<ComponentType> consumer = new Consumer<>(name, dataType, contract); if (annotation.group().length() > 0){ consumer.setGroup(annotation.group()); } processSources(annotation, consumer, constructor, constructor.getDeclaringClass(), context); componentType.add(consumer, injectionSite, constructor); }
public void visitField(org.fabric3.api.annotation.Consumer annotation, Field field, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> genericType = field.getType(); Type logicalParamType = typeMapping.getActualType(genericType); DataType dataType = createDataType(genericType, logicalParamType, typeMapping); String name = helper.getSiteName(field, annotation.value()); ServiceContract contract = null; if (contractProcessor != null) { Class<?> baseType = helper.getBaseType(genericType, typeMapping); contract = contractProcessor.introspect(baseType, implClass, context, componentType); } Consumer<ComponentType> consumer = new Consumer<>(name, dataType, contract); if (annotation.group().length() > 0){ consumer.setGroup(annotation.group()); } Class<?> clazz = field.getDeclaringClass(); processSources(annotation, consumer, field, clazz, context); FieldInjectionSite injectionSite = new FieldInjectionSite(field); componentType.add(consumer, injectionSite, field); }
Consumer<ComponentType> consumer = new Consumer<>(name, type, contract);