/** * Adds a property value. * * @param name the property name * @param value the value * @return the builder */ public T property(String name, Object value) { checkState(); PropertyValue propertyValue = new PropertyValue(name, value); getComponent().add(propertyValue); return builder(); }
@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); } }
/** * Adds a binding configuration to a service provided by the component. * * @param serviceName the service name * @param bindingDefinition the binding definition * @return the builder */ public T binding(String serviceName, Binding bindingDefinition) { checkState(); Component<?> definition = getComponent(); Service<Component> service = definition.getServices().get(serviceName); if (service == null) { service = new Service<>(serviceName); definition.add(service); } service.addBinding(bindingDefinition); return builder(); }
/** * Adds a property value sourced from the XPath expression. * * @param name the property name * @param xpath the XPath expression * @return the builder */ public T propertyExpression(String name, String xpath) { checkState(); PropertyValue propertyValue = new PropertyValue(name, xpath); propertyValue.setNamespaceContext(new F3NamespaceContext()); getComponent().add(propertyValue); return builder(); }
/** * Adds a reference with the given name and target. * * @param name the reference name * @param target the target */ public T reference(String name, String target, boolean required) { checkState(); Component<?> definition = getComponent(); Multiplicity multiplicity = required ? Multiplicity.ONE_ONE : Multiplicity.ZERO_ONE; Reference<Component> reference = new Reference<>(name, multiplicity); reference.addTarget(new Target(target)); definition.add(reference); return builder(); }
/** * Adds a reference with the given name and target. * * @param name the reference name * @param target the target */ public T reference(String name, String target) { checkState(); Component<?> definition = getComponent(); Reference<Component> reference = new Reference<>(name, Multiplicity.ONE_ONE); reference.addTarget(new Target(target)); definition.add(reference); return builder(); }
/** * Adds a reference with the given name and target. * * @param name the reference name * @param target the target * @param multiplicity the multiplicity */ public T reference(String name, String target, Multiplicity multiplicity) { checkState(); Component<?> definition = getComponent(); Reference<Component> reference = new Reference<>(name, multiplicity); reference.addTarget(new Target(target)); definition.add(reference); return builder(); }