Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.ComponentService


            for (ComponentService componentService : componentReference
                    .getTargets()) {

                // Resolve the target component and service
                String name = componentService.getName();
                ComponentService targetComponentService = componentServices
                        .get(name);
                Component targetComponent;
                int s = name.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(name);
                } else {
                    targetComponent = components.get(name.substring(0, s));
                }

                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
                                                           // start
                        endpoint
                                .setSourceComponentReference(componentReference);
                        endpoint.setInterfaceContract(componentReference
                                .getInterfaceContract());
                        endpoint.setTargetComponent(targetComponent);
                        endpoint
                                .setTargetComponentService(targetComponentService);
                        endpoint.getCandidateBindings().addAll(
                                componentReference.getBindings());
                        endpoints.add(endpoint);

                        // mark the reference target as resolved. Used later
                        // when we are looking to
                        // see if an sca binding is associated with a resolved
                        // target or not
                        componentService.setUnresolved(false);
                    } else {
                        warning(monitor, "ReferenceIncompatibleInterface",
                                composite, composite.getName().toString(),
                                componentReference.getName(), componentService
                                        .getName());
                    }
                } else {
                    // add all the reference bindings into the target so that
                    // they
                    // can be used for comparison when the target is resolved at
                    // runtime
                    componentService.getBindings().addAll(
                            componentReference.getBindings());

                    Endpoint endpoint = endpointFactory.createEndpoint();
                    endpoint.setTargetName(name);
                    endpoint.setSourceComponent(null); // TODO - fixed up at
                                                       // start
                    endpoint.setSourceComponentReference(componentReference);
                    endpoint.setInterfaceContract(componentReference
                            .getInterfaceContract());
                    endpoint.getCandidateBindings().addAll(
                            componentReference.getBindings());
                    endpoints.add(endpoint);

                    // The bindings will be cloned back into the reference when
                    // the
                    // target is finally resolved.
                    warning(monitor, "ComponentReferenceTargetNotFound",
                            composite, composite.getName().toString(),
                            componentService.getName());
                }
            }
        } else if ((componentReference.getReference() != null)
                && (!componentReference.getReference().getTargets().isEmpty())) {

            // Resolve targets from the corresponding reference in the
            // componentType
            for (ComponentService componentService : componentReference
                    .getReference().getTargets()) {

                // Resolve the target component and service
                String name = componentService.getName();
                ComponentService targetComponentService = componentServices
                        .get(name);
                Component targetComponent;
                int s = name.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(name);
                } else {
                    targetComponent = components.get(name.substring(0, s));
                }

                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of
                    // the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
                                                           // start
                        endpoint
                                .setSourceComponentReference(componentReference);
                        endpoint.setInterfaceContract(componentReference
                                .getInterfaceContract());
                        endpoint.setTargetComponent(targetComponent);
                        endpoint
                                .setTargetComponentService(targetComponentService);
                        endpoint.getCandidateBindings().addAll(
                                componentReference.getBindings());
                        endpoints.add(endpoint);

                        // mark the reference target as resolved. Used later
                        // when we are looking to
                        // see if an sca binding is associated with a resolved
                        // target or not
                        componentService.setUnresolved(false);
                    } else {
                        warning(monitor, "ComponentIncompatibleInterface",
                                composite, componentReference.getName(),
                                componentService.getName());
                    }
                } else {
                    // add all the reference bindings into the target so that
                    // they
                    // can be used for comparison when the target is resolved at
                    // runtime
                    componentService.getBindings().addAll(
                            componentReference.getBindings());

                    // The bindings will be cloned back into the reference when
                    // the
                    // target is finally resolved.

                    Endpoint endpoint = endpointFactory.createEndpoint();
                    endpoint.setTargetName(name);
                    endpoint.setSourceComponent(null); // TODO - fixed up at
                                                       // start
                    endpoint.setSourceComponentReference(componentReference);
                    endpoint.setInterfaceContract(componentReference
                            .getInterfaceContract());
                    endpoint.getCandidateBindings().addAll(
                            componentReference.getBindings());
                    endpoints.add(endpoint);

                    warning(monitor, "ComponentReferenceTargetNotFound",
                            composite, composite.getName().toString(),
                            componentService.getName());
                }
            }
        } else if (componentReference.getAutowire() == Boolean.TRUE) {

            // Find suitable targets in the current composite for an
            // autowired reference
            Multiplicity multiplicity = componentReference.getMultiplicity();
            for (Component targetComponent : composite.getComponents()) {
                // prevent autowire connecting to self
                boolean skipSelf = false;
                for (ComponentReference targetComponentReference : targetComponent
                        .getReferences()) {
                    if (componentReference == targetComponentReference) {
                        skipSelf = true;
                    }
                }

                if (!skipSelf) {
                    for (ComponentService targetComponentService : targetComponent
                            .getServices()) {
                        if (componentReference.getInterfaceContract() == null
                                || interfaceContractMapper.isCompatible(
                                        componentReference
                                                .getInterfaceContract(),
                                        targetComponentService
                                                .getInterfaceContract())) {

                            Endpoint endpoint = endpointFactory
                                    .createEndpoint();
                            endpoint.setTargetName(targetComponent.getName());
                            endpoint.setSourceComponent(null); // TODO - fixed
                                                               // up at start
                            endpoint
                                    .setSourceComponentReference(componentReference);
                            endpoint.setInterfaceContract(componentReference
                                    .getInterfaceContract());
                            endpoint.setTargetComponent(targetComponent);
                            endpoint
                                    .setTargetComponentService(targetComponentService);
                            endpoint.getCandidateBindings().addAll(
                                    componentReference.getBindings());
                            endpoints.add(endpoint);

                            if (multiplicity == Multiplicity.ZERO_ONE
                                    || multiplicity == Multiplicity.ONE_ONE) {
                                break;
                            }
                        }
                    }
                }
            }

            if (multiplicity == Multiplicity.ONE_N
                    || multiplicity == Multiplicity.ONE_ONE) {
                if (endpoints.size() == 0) {
                    warning(monitor, "NoComponentReferenceTarget",
                            componentReference, componentReference.getName());
                }
            }
        }

        // if no endpoints have found so far retrieve any target names that are
        // in binding URIs
        if (endpoints.isEmpty()) {
            for (Binding binding : componentReference.getBindings()) {

                String uri = binding.getURI();

                // user hasn't put a uri on the binding so it's not a target
                // name
                if (uri == null) {
                    continue;
                }

                // user might have put a local target name in the uri so get
                // the path part and see if it refers to a target we know about
                // - if it does the reference binding will be matched with a
                // service binding
                // - if it doesn't it is assumed to be an external reference
                Component targetComponent = null;
                ComponentService targetComponentService = null;
                String path = null;

                try {
                    path = URI.create(uri).getPath();
                } catch (Exception ex) {
                    // just assume that no target is identified if
                    // a URI related exception is thrown
                }

                if (path != null) {
                    if (path.startsWith("/")) {
                        path = path.substring(1);
                    }

                    // Resolve the target component and service
                    targetComponentService = componentServices.get(path);
                    int s = path.indexOf('/');
                    if (s == -1) {
                        targetComponent = components.get(path);
                    } else {
                        targetComponent = components.get(path.substring(0, s));
                    }
                }

                // if the path of the binding URI matches a component in the
                // composite then configure an endpoint with this component as
                // the target
                // if not then the binding URI will be assumed to reference an
                // external service
                if (targetComponentService != null) {

                    // Check that the target component service provides
                    // a superset of the component reference interface
                    if (componentReference.getInterfaceContract() == null
                            || interfaceContractMapper.isCompatible(
                                    componentReference.getInterfaceContract(),
                                    targetComponentService
                                            .getInterfaceContract())) {

                        Endpoint endpoint = endpointFactory.createEndpoint();
                        endpoint.setTargetName(targetComponent.getName());
                        endpoint.setSourceComponent(null); // TODO - fixed up at
View Full Code Here


    /**
     * @param component
     */
    public static ComponentService getSingleService(Component component) {
        ComponentService targetService;
        List<ComponentService> services = component.getServices();
        List<ComponentService> regularServices = new ArrayList<ComponentService>();
        for (ComponentService service : services) {
            if (service.isCallback()) {
                continue;
View Full Code Here

        }
        throw new ServiceRuntimeException("Property not found: " + propertyName);
    }

    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
        ComponentService service = CompositeContext.getSingleService(component);
        try {
            return createSelfReference(businessInterface, service);
        } catch (Exception e) {
            throw new ServiceRuntimeException(e.getMessage(), e);
        }
View Full Code Here

            return;
        }
       
        // create wire if binding has an endpoint
        Component targetComponent = null;
        ComponentService targetComponentService = null;
        Binding targetBinding = null;
   
        if (binding instanceof OptimizableBinding) {
            OptimizableBinding endpoint = (OptimizableBinding)binding;
            targetComponent = endpoint.getTargetComponent();
View Full Code Here

        sourceContract = sourceContract.makeUnidirectional(false);

        EndpointReference wireSource =
            new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
        ComponentService callbackService = reference.getCallbackService();
        if (callbackService != null) {
            // select a reference callback binding to pass with invocations on this wire
            Binding callbackBinding = null;
            for (Binding binding : callbackService.getBindings()) {
                // first look for a callback binding whose name matches the reference binding name
              if (refBinding.getName().startsWith(binding.getName())) {
                    callbackBinding = binding;
                    break;
                }
            }
            // if no callback binding found, try again based on reference binding type
            if (callbackBinding == null) {
                callbackBinding = callbackService.getBinding(refBinding.getClass());
            }
            InterfaceContract callbackContract = callbackService.getInterfaceContract();
            EndpointReference callbackEndpoint =
                new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
                                          callbackContract);
            wireSource.setCallbackEndpoint(callbackEndpoint);
        }
View Full Code Here

                        // Resolve the Component
                        final String bindingURI = binding.getURI();
                        final Component targetComponent = resolveComponentURI(bindingURI);

                        // Find the Service
                        ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);

                        // if the target service is a promoted service then find the
                        // service it promotes
                        if ((targetService != null) && (targetService.getService() instanceof CompositeService)) {
                            CompositeService compositeService = (CompositeService)targetService.getService();
                            // Find the promoted component service
                            ComponentService promotedComponentService = getPromotedComponentService(compositeService);
                            if (promotedComponentService != null && !promotedComponentService.isUnresolved()) {
                                targetService = promotedComponentService;
                            }
                        }

                        OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
View Full Code Here

     *
     * @param topCompositeService
     * @return
     */
    private ComponentService getPromotedComponentService(CompositeService compositeService) {
        ComponentService componentService = compositeService.getPromotedService();
        if (componentService != null) {
            Service service = componentService.getService();
            if (componentService.getName() != null && service instanceof CompositeService) {

                // Continue to follow the service promotion chain
                return getPromotedComponentService((CompositeService)service);

            } else {
View Full Code Here

     * @param targetComponent The Component containing the Services
     * @return The Service with the specified serviceName or null if no such Service found.
     */
    protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) {

        ComponentService targetService = null;

        if (targetComponent != null) {
            if (bindingURI.startsWith("/")) {
                bindingURI = bindingURI.substring(1);
            }
View Full Code Here

    /**
     * @param component
     */
    public static ComponentService getSingleService(Component component) {
        ComponentService targetService;
        List<ComponentService> services = component.getServices();
        List<ComponentService> regularServices = new ArrayList<ComponentService>();
        for (ComponentService service : services) {
            if (service.isCallback()) {
                continue;
View Full Code Here

        // Process top level composite services
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;

            // Get the next lower level promoted service
            ComponentService promotedService = compositeService.getPromotedService();
            if (promotedService != null) {

                // Set the bindings using the top level bindings to override the lower level bindings
                if (!bindingsSpecifiedManually(compositeService.getBindings()) &&
                    bindingsSpecifiedManually(promotedService.getBindings())) {
                    compositeService.getBindings().clear();
                    for (Binding binding : promotedService.getBindings()) {
                        try {
                            compositeService.getBindings().add((Binding)binding.clone());
                        } catch (CloneNotSupportedException ex) {
                            // this binding can't be used in the promoted service
                        }
                    }                   
                }
                if (compositeService.getInterfaceContract() != null &&
                    compositeService.getInterfaceContract().getCallbackInterface() != null) {
                    if (!(compositeService.getCallback() != null &&
                          bindingsSpecifiedManually(compositeService.getCallback().getBindings())) &&
                        promotedService.getCallback() != null &&
                        bindingsSpecifiedManually(promotedService.getCallback().getBindings())) {
                        if (compositeService.getCallback() != null) {
                            compositeService.getCallback().getBindings().clear();
                        } else {
                            compositeService.setCallback(assemblyFactory.createCallback());
                        }
                        for (Binding binding : promotedService.getCallback().getBindings()) {
                            try {
                                compositeService.getCallback().getBindings().add((Binding)binding.clone());
                            } catch (CloneNotSupportedException ex) {
                                // this binding can't be used in the promoted service
                            }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.ComponentService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.