private Target parseTarget(String target) { String[] tokens = target.split("/"); if (tokens.length == 1) { return new Target(tokens[0]); } else if (tokens.length == 2) { return new Target(tokens[0], tokens[1]); } else if (tokens.length == 3) { return new Target(tokens[0], tokens[1], tokens[2]); } else { throw new IllegalArgumentException("Invalid target format: " + target); } } }
private void raiseServiceNotFound(LogicalReference reference, Target target, InstantiationContext context) { URI referenceUri = reference.getUri(); String componentName = target.getComponent(); String serviceName = target.getBindable(); String msg = "The service " + serviceName + " wired from the reference " + referenceUri + " is not found on component " + componentName; ServiceNotFound error = new ServiceNotFound(msg, reference); context.addError(error); }
private void raiseNoService(LogicalReference reference, Target target, LogicalCompositeComponent parent, InstantiationContext context) { String componentName = target.getComponent(); URI referenceUri = reference.getUri(); String msg = "The reference " + referenceUri + " is wired to component " + componentName + " but the component has no services"; NoServiceOnComponent error = new NoServiceOnComponent(msg, parent); context.addError(error); }
public void instantiateCompositeWires(Composite composite, LogicalCompositeComponent parent, InstantiationContext context) { // instantiate wires held directly in the composite and in included composites for (Wire definition : composite.getWires()) { // resolve the source reference Target referenceTarget = definition.getReferenceTarget(); LogicalReference reference = resolveReference(referenceTarget, parent, context); if (reference == null) { // error resolving, continue processing other targets so all errors are collated continue; } // resolve the target service Target serviceTarget = definition.getServiceTarget(); LogicalService service = resolveService(reference, serviceTarget, parent, context); if (service == null) { // error resolving, continue processing other targets so all errors are collated continue; } // create the wire URI contributionUri = parent.getDefinition().getContributionUri(); LogicalWire wire = new LogicalWire(parent, reference, service, contributionUri); String referenceBindingName = referenceTarget.getBinding(); String serviceBindingName = serviceTarget.getBinding(); resolveBindings(reference, referenceBindingName, service, wire, serviceBindingName, context); parent.addWire(reference, wire); } }
private void raiseAmbiguousService(LogicalReference reference, Target target, InstantiationContext context) { String componentName = target.getComponent(); URI referenceUri = reference.getUri(); String msg = "More than one service available on component: " + componentName + ". The wire from the reference " + referenceUri + " must explicitly specify a target service."; AmbiguousService error = new AmbiguousService(msg, reference); context.addError(error); }
public void instantiateCompositeWires(Composite composite, LogicalCompositeComponent parent, InstantiationContext context) { // instantiate wires held directly in the composite and in included composites for (Wire definition : composite.getWires()) { // resolve the source reference Target referenceTarget = definition.getReferenceTarget(); LogicalReference reference = resolveReference(referenceTarget, parent, context); if (reference == null) { // error resolving, continue processing other targets so all errors are collated continue; } // resolve the target service Target serviceTarget = definition.getServiceTarget(); LogicalService service = resolveService(reference, serviceTarget, parent, context); if (service == null) { // error resolving, continue processing other targets so all errors are collated continue; } // create the wire URI contributionUri = parent.getDefinition().getContributionUri(); LogicalWire wire = new LogicalWire(parent, reference, service, contributionUri); String referenceBindingName = referenceTarget.getBinding(); String serviceBindingName = serviceTarget.getBinding(); resolveBindings(reference, referenceBindingName, service, wire, serviceBindingName, context); parent.addWire(reference, wire); } }
private void raiseServiceNotFound(LogicalReference reference, Target target, InstantiationContext context) { URI referenceUri = reference.getUri(); String componentName = target.getComponent(); String serviceName = target.getBindable(); String msg = "The service " + serviceName + " wired from the reference " + referenceUri + " is not found on component " + componentName; ServiceNotFound error = new ServiceNotFound(msg, reference); context.addError(error); }
private org.fabric3.api.model.type.component.Target parseTarget(String target, Annotation annotation, AccessibleObject accessibleObject, Member member, IntrospectionContext context) { String[] tokens = target.split("/"); if (tokens.length == 1) { return new org.fabric3.api.model.type.component.Target(tokens[0]); } else if (tokens.length == 2) { return new org.fabric3.api.model.type.component.Target(tokens[0], tokens[1]); } else if (tokens.length == 3) { return new org.fabric3.api.model.type.component.Target(tokens[0], tokens[1], tokens[2]); } else { Class<?> clazz = member.getDeclaringClass(); String name = member.getName(); InvalidAnnotation error = new InvalidAnnotation("Invalid target format: " + target + " on " + name, accessibleObject, annotation, clazz); context.addError(error); return null; } } }
private void raiseNoService(LogicalReference reference, Target target, LogicalCompositeComponent parent, InstantiationContext context) { String componentName = target.getComponent(); URI referenceUri = reference.getUri(); String msg = "The reference " + referenceUri + " is wired to component " + componentName + " but the component has no services"; NoServiceOnComponent error = new NoServiceOnComponent(msg, parent); context.addError(error); }
/** * Creates a wire by resolving a Target. * * @param target the target * @param reference the source reference * @param bindingName the binding name or null * @param parent the parent component * @param context the instantiation context * @return the wire or null if it could not be created */ private LogicalWire createWire(Target target, LogicalReference reference, String bindingName, LogicalCompositeComponent parent, InstantiationContext context) { LogicalService service = resolveService(reference, target, parent, context); if (service == null) { return null; } URI contributionUri = service.getParent().getDefinition().getContributionUri(); LogicalWire wire = new LogicalWire(parent, reference, service, contributionUri); String serviceBindingName = target.getBinding(); resolveBindings(reference, bindingName, service, wire, serviceBindingName, context); return wire; }
String base = parent.getUri().toString(); URI componentUri = URI.create(base + "/" + target.getComponent()); String referenceName = target.getBindable();
/** * 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(); }
private void raiseAmbiguousService(LogicalReference reference, Target target, InstantiationContext context) { String componentName = target.getComponent(); URI referenceUri = reference.getUri(); String msg = "More than one service available on component: " + componentName + ". The wire from the reference " + referenceUri + " must explicitly specify a target service."; AmbiguousService error = new AmbiguousService(msg, reference); context.addError(error); }
/** * Creates a wire by resolving a Target. * * @param target the target * @param reference the source reference * @param bindingName the binding name or null * @param parent the parent component * @param context the instantiation context * @return the wire or null if it could not be created */ private LogicalWire createWire(Target target, LogicalReference reference, String bindingName, LogicalCompositeComponent parent, InstantiationContext context) { LogicalService service = resolveService(reference, target, parent, context); if (service == null) { return null; } URI contributionUri = service.getParent().getDefinition().getContributionUri(); LogicalWire wire = new LogicalWire(parent, reference, service, contributionUri); String serviceBindingName = target.getBinding(); resolveBindings(reference, bindingName, service, wire, serviceBindingName, context); return wire; }
String base = parent.getUri().toString(); URI componentUri = URI.create(base + "/" + target.getComponent()); String referenceName = target.getBindable();
/** * 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(); }
URI targetComponentUri = URI.create(parent.getUri().toString() + "/" + target.getComponent()); LogicalComponent<?> targetComponent = parent.getComponent(targetComponentUri); if (targetComponent == null) { return null; String serviceName = target.getBindable(); LogicalService targetService = null; if (serviceName != null) {
/** * 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(); }
URI targetComponentUri = URI.create(parent.getUri().toString() + "/" + target.getComponent()); LogicalComponent<?> targetComponent = parent.getComponent(targetComponentUri); if (targetComponent == null) { return null; String serviceName = target.getBindable(); LogicalService targetService = null; if (serviceName != null) {