Package org.apache.tuscany.sca.assembly

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


        // Add a wire for each service Endpoint
        for ( Endpoint2 endpoint : runtimeService.getEndpoints()){
           
            // fluff up a fake endpoint reference as we are on the service side
            // so we need to represent the reference that will call us
            EndpointReference2 endpointReference = assemblyFactory.createEndpointReference();
            endpointReference.setBinding(endpoint.getBinding());
            endpointReference.setTargetEndpoint(endpoint);
           
            // create the interface contract for the binding and service ends of the wire
            // that are created as forward only contracts
            // FIXME: [rfeng] We might need a better way to get the impl interface contract
            Service targetService = service.getService();
            if (targetService == null) {
                targetService = service;
            }
            endpoint.setInterfaceContract(targetService.getInterfaceContract().makeUnidirectional(false));
            endpointReference.setInterfaceContract(getServiceBindingInterfaceContract(service, endpoint.getBinding()));
           
            // create the wire
            RuntimeWire wire = new RuntimeWireImpl2(false,
                                                    endpointReference,
                                                    endpoint,
View Full Code Here


                    for (ComponentService targetComponentService : targetComponent.getServices()) {
                        if (reference.getInterfaceContract() == null ||
                            interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
                                                                 targetComponentService.getInterfaceContract())) {
                            // create endpoint reference
                            EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                            endpointRef.setComponent(component);
                            endpointRef.setReference(reference);
                            endpointRef.setUnresolved(false);
                           
                            // create dummy endpoint. This will be replaced when policies
                            // are matched and bindings are configured later
                            Endpoint2 endpoint = assemblyFactory.createEndpoint();
                            endpoint.setComponent(targetComponent);
                            endpoint.setService(targetComponentService);
                            endpoint.setUnresolved(true);
                            endpointRef.setTargetEndpoint(endpoint);
                           
                            reference.getEndpointReferences().add(endpointRef);

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

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

        } else if (!reference.getTargets().isEmpty()) {

            // Check that the component reference does not mix the use of
            // endpoint references specified via the target attribute with
            // the presence of binding elements
            if (reference.getBindings().size() > 0) {
                warning(monitor, "ReferenceEndPointMixWithTarget",
                        composite, reference.getName());
            }

            // Resolve targets specified on the component reference
            for (ComponentService target : reference.getTargets()) {              
               
                String targetName = target.getName();
                ComponentService targetComponentService = componentServices.get(targetName);
               
                Component targetComponent;
                int s = targetName.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(targetName);
                } else {
                    targetComponent = components.get(targetName.substring(0, s));
                }

                if (targetComponentService != null) {

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

                        // create endpoint reference
                        EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                        endpointRef.setComponent(component);
                        endpointRef.setReference(reference);
                        endpointRef.setUnresolved(false);

                        // create dummy endpoint. This will be replaced when policies
                        // are matched and bindings are configured later
                        Endpoint2 endpoint = assemblyFactory.createEndpoint();
                        endpoint.setComponent(targetComponent);
                        endpoint.setService(targetComponentService);
                        endpoint.setUnresolved(true);
                        endpointRef.setTargetEndpoint(endpoint);
                       
                        reference.getEndpointReferences().add(endpointRef);
                    } else {
                        warning(monitor,
                                "ReferenceIncompatibleInterface",
                                composite,
                                composite.getName().toString(),
                                reference.getName(),
                                targetName);
                    }
                } else {
                    // add an unresolved endpoint reference
                    EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                    endpointRef.setComponent(component);
                    endpointRef.setReference(reference);
                    endpointRef.setUnresolved(true);
                               
                    // create an unresolved endpoint to go with it
                    Endpoint2 endpoint = assemblyFactory.createEndpoint();
                    endpoint.setUnresolved(true);
                    endpointRef.setTargetEndpoint(endpoint);
                   
                    warning(monitor,
                            "ComponentReferenceTargetNotFound",
                            composite,
                            composite.getName().toString(),
                            targetName);
                }
            }
        } else if ((reference.getReference() != null)
                && (!reference.getReference().getTargets().isEmpty())) {

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

                String targetName = target.getName();
                ComponentService targetComponentService = componentServices.get(targetName);
               
                Component targetComponent;
                int s = targetName.indexOf('/');
                if (s == -1) {
                    targetComponent = components.get(targetName);
                } else {
                    targetComponent = components.get(targetName.substring(0, s));
                }

                if (targetComponentService != null) {

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

                        // create endpoint reference
                        EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                        endpointRef.setComponent(component);
                        endpointRef.setReference(reference);
                        endpointRef.setUnresolved(false);
                       
                        // create dummy endpoint. This will be replaced when policies
                        // are matched and bindings are configured later
                        Endpoint2 endpoint = assemblyFactory.createEndpoint();
                        endpoint.setComponent(targetComponent);
                        endpoint.setService(targetComponentService);
                        endpoint.setUnresolved(true);
                        endpointRef.setTargetEndpoint(endpoint);
                       
                        reference.getEndpointReferences().add(endpointRef);
                    } else {
                        warning(monitor,
                                "ReferenceIncompatibleInterface",
                                composite,
                                composite.getName().toString(),
                                reference.getName(),
                                targetName);
                    }
                } else {
                    // add an unresolved endpoint reference
                    EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                    endpointRef.setComponent(component);
                    endpointRef.setReference(reference);
                    endpointRef.setUnresolved(true);
                   
                    // create an unresolved endpoint to go with it
                    Endpoint2 endpoint = assemblyFactory.createEndpoint();
                    endpoint.setUnresolved(true);
                    endpointRef.setTargetEndpoint(endpoint);                   
                   
                    warning(monitor,
                            "ComponentReferenceTargetNotFound",
                            composite,
                            composite.getName().toString(),
                            targetName);
                }
            }
        }


        // if no endpoints have found so far the bindings become targets.
        if (reference.getEndpointReferences().isEmpty()) {
            for (Binding binding : reference.getBindings()) {

                String uri = binding.getURI();

                // user hasn't put a uri on the binding so it's not a target
                // name
                if (uri == null) {
                    // create endpoint reference for manually configured bindings
                    EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                    endpointRef.setComponent(component);
                    endpointRef.setReference(reference);
                    endpointRef.setBinding(binding);
                    endpointRef.setTargetEndpoint(null);
                    endpointRef.setUnresolved(false);
                   
                    // create a resolved endpoint to signify that this
                    // reference is pointing at some unwired endpoint
                    Endpoint2 endpoint = assemblyFactory.createEndpoint();
                    endpoint.setUnresolved(false);
                    endpointRef.setTargetEndpoint(endpoint);
                   
                    reference.getEndpointReferences().add(endpointRef);
                   
                    continue;
                }

                // user might have put a local target name in the uri
                // 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;


                if (uri.startsWith("/")) {
                    uri = uri.substring(1);
                }

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

                // if the binding URI matches a component in the
                // composite then configure an endpoint reference 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 (reference.getInterfaceContract() == null ||
                        interfaceContractMapper.isCompatible(reference.getInterfaceContract(),
                                                             targetComponentService.getInterfaceContract())) {
                        // create enpoint reference
                        EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                        endpointRef.setComponent(component);
                        endpointRef.setReference(reference);
                        endpointRef.setBinding(binding);
                        endpointRef.setUnresolved(false);

                        // create dummy endpoint. This will be replaced when policies
                        // are matched and bindings are configured later
                        Endpoint2 endpoint = assemblyFactory.createEndpoint();
                        endpoint.setComponent(targetComponent);
                        endpoint.setService(targetComponentService);
                        endpoint.setUnresolved(true);
                        endpointRef.setTargetEndpoint(endpoint);
                       
                        reference.getEndpointReferences().add(endpointRef);
                    } else {
                        warning(monitor,
                                "ReferenceIncompatibleInterface",
                                composite,
                                composite.getName().toString(),
                                reference.getName(),
                                uri);
                    }
                } else {
                    // create endpoint reference for manually configured bindings
                    EndpointReference2 endpointRef = assemblyFactory.createEndpointReference();
                    endpointRef.setComponent(component);
                    endpointRef.setReference(reference);
                    endpointRef.setBinding(binding);
                    endpointRef.setTargetEndpoint(null);
                    endpointRef.setUnresolved(false);
                   
                    // create a resolved endpoint to signify that this
                    // reference is pointing at some unwired endpoint
                    Endpoint2 endpoint = assemblyFactory.createEndpoint();
                    endpoint.setUnresolved(false);
                    endpointRef.setTargetEndpoint(endpoint);
                   
                    reference.getEndpointReferences().add(endpointRef);
                }
            }
        }
View Full Code Here

        componentReference.setInterfaceContract(interfaceContract);
        componentReference.setMultiplicity(Multiplicity.ONE_ONE);
        // component.getReferences().add(componentReference);
       
        // create endpoint reference
        EndpointReference2 endpointReference = assemblyFactory
                .createEndpointReference();
        endpointReference.setComponent(component);
        endpointReference.setReference(componentReference);
         endpointReference.setUnresolved(false);

        // create endpoint.
        Endpoint2 endpoint = assemblyFactory.createEndpoint();
        endpoint.setComponent(component);
        endpoint.setService(service);
        endpoint.setUnresolved(true);
        endpointReference.setTargetEndpoint(endpoint);
       
        componentReference.getEndpointReferences().add(endpointReference);
       
        // do binding matching
        endpointReferenceBuilder.build(endpointReference, monitor);
View Full Code Here

        }
       
        ref.getEndpointReferences().clear();
       
        for(EndpointReference2 endpointReference : reference.getEndpointReferences()){
            EndpointReference2 clone = (EndpointReference2)endpointReference.clone();
           
            clone.setReference(ref);
            clone.getBinding().setURI(resolvedEndpoint.getURI());
           
            clone.getTargetEndpoint().setComponent(resolvedEndpoint.getComponent());
            clone.getTargetEndpoint().setService((ComponentService)resolvedEndpoint.getContract())
            clone.getTargetEndpoint().setBinding(resolvedEndpoint.getBinding());
           
            ref.getEndpointReferences().add(clone);
        }
      
        return ref;
View Full Code Here

    protected EndpointReference2Impl() {
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        EndpointReference2 cloned = (EndpointReference2)super.clone();
       
        if (targetEndpoint != null){
            cloned.setTargetEndpoint((Endpoint2)targetEndpoint.clone());
        }
       
        return cloned;
    }
View Full Code Here

        assertEquals(policiedComposite.getRequiredIntents().get(0).getName(),
                     new QName(namespaceUri, "tuscanyIntent_1"));

        Component component = composite.getComponents().get(0);
        Endpoint2 ep = component.getServices().get(0).getEndpoints().get(0);
        EndpointReference2 epr = component.getReferences().get(0).getEndpointReferences().get(0);

        System.out.println(ep.getRequiredIntents());
        System.out.println(epr.getRequiredIntents());
    }
View Full Code Here

TOP

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

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.