Package org.apache.tuscany.sca.assembly

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


       
        // Create pseudo-component
        epr.setComponent(component);
       
        // Create pseudo-reference
        ComponentReference reference = assemblyFactory.createComponentReference();
        ExtensionPointRegistry registry = compositeContext.getExtensionPointRegistry();
        FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
        JavaInterfaceFactory javaInterfaceFactory = (JavaInterfaceFactory)modelFactories.getFactory(JavaInterfaceFactory.class);
        JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
        try {
      interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(AsyncResponseService.class));
    } catch (InvalidInterfaceException e1) {
      // Nothing to do here - will not happen
    } // end try
    reference.setInterfaceContract(interfaceContract);
        String referenceName = endpoint.getService().getName() + "_asyncCallback";
        reference.setName(referenceName);
        reference.setForCallback(true);
        // Add in "implementation" reference (really a dummy, but with correct interface)
        Reference implReference = assemblyFactory.createReference();
        implReference.setInterfaceContract(interfaceContract);
        implReference.setName(referenceName);
        implReference.setForCallback(true);
       
        reference.setReference(implReference);
        // Set the created ComponentReference into the EPR
        epr.setReference(reference);
       
        // Create a binding
    Binding binding = createMatchingBinding( endpoint.getBinding(), (RuntimeComponent)endpoint.getComponent(), reference, registry );     
View Full Code Here


        assertEquals(calcComponentService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        ComponentReference calcComponentReference = calcComponent.getReferences().get(0);
        assertEquals(calcComponentReference.getName(), "addService");
        assertEquals(calcComponentReference.getAutowire(), Boolean.FALSE);
        assertEquals(calcComponentReference.isWiredByImpl(), false);
        assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Property property = calcComponent.getProperties().get(0);
        assertEquals(property.getName(), "round");
        Document doc = (Document) property.getValue();
View Full Code Here

        // that they promote
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;
            List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences();
            for (int i = 0, n = promotedReferences.size(); i < n; i++) {
                ComponentReference componentReference = promotedReferences.get(i);
                if (componentReference.isUnresolved()) {
                    String componentReferenceName = componentReference.getName();
                    componentReference = componentReferences.get(componentReferenceName);
                    if (componentReference != null) {
   
                        // Point to the resolved component reference
                        promotedReferences.set(i, componentReference);
   
                        // Use the interface contract from the component
                        // reference if none
                        // is specified on the composite reference
                        if (compositeReference.getInterfaceContract() == null) {
                            compositeReference.setInterfaceContract(componentReference.getInterfaceContract());
                        }
   
                    } else {
                        warning("Promoted component reference not found: " + componentReferenceName, composite);
                    }
View Full Code Here

        // add it to the list of targets of the reference
        List<Wire> wires = composite.getWires();
        for (int i = 0, n = wires.size(); i < n; i++) {
            Wire wire = wires.get(i);
   
            ComponentReference resolvedReference;
            ComponentService resolvedService;
   
            // Resolve the source reference
            ComponentReference source = wire.getSource();
            if (source != null && source.isUnresolved()) {
                resolvedReference = componentReferences.get(source.getName());
                if (resolvedReference != null) {
                    wire.setSource(resolvedReference);
                } else {
                    warning("Wire source not found: " + source.getName(), composite);
                }
            } else {
                resolvedReference = wire.getSource();
            }
   
            // Resolve the target service
            ComponentService target = wire.getTarget();
            if (target != null && target.isUnresolved()) {
                resolvedService = componentServices.get(target.getName());
                if (resolvedService != null) {
                    wire.setTarget(target);
                } else {
                    warning("Wire target not found: " + source.getName(), composite);
                }
            } else {
                resolvedService = wire.getTarget();
            }
   
            // Add the target service to the list of targets of the
            // reference
            if (resolvedReference != null && resolvedService != null) {
                // Check that the target component service provides
                // a superset of
                // the component reference interface
                if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper
                    .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) {
   
                    //resolvedReference.getTargets().add(resolvedService);
                    resolvedReference.getTargets().add(wire.getTarget());
                } else {
                    warning("Incompatible interfaces on wire source and target: " + source.getName()
                        + " : "
                        + target.getName(), composite);
                }
            }
        }
View Full Code Here

                instanceFactoryProvider.getImplementation().getReferenceMembers().get(ref.getName());
            if (element != null) {
                if (!(element.getAnchor() instanceof Constructor)) {
                    instanceFactoryProvider.getInjectionSites().add(element);
                }
                ComponentReference componentReference = null;
                List<RuntimeWire> wireList = null;
                for (ComponentReference reference : component.getReferences()) {
                    if (reference.getName().equals(ref.getName())) {
                        wireList = ((RuntimeComponentReference)reference).getRuntimeWires();
                        componentReference = reference;
View Full Code Here

        }
        Object model = extensionProcessor.read(reader, context);
        if (model instanceof Composite) {
            Composite composite = (Composite)model;
            Component component = composite.getComponents().get(0);
            ComponentReference reference = component.getReferences().get(0);
            Binding binding = reference.getBindings().get(0);
            endpointReference.setComponent(component);
            endpointReference.setReference(reference);
            reference.getEndpointReferences().add(endpointReference);
            endpointReference.setBinding(binding);
           
            // set up the EPR so that resolution will happen
            // at wire creation time if needs be
            Endpoint endpoint = assemblyFactory.createEndpoint();
            endpointReference.setTargetEndpoint(endpoint);
           
            if (reference.getTargets().size() > 0){
                // create a dummy endpoint with the URI set so that
                // the endpoint registry will be consulted
                endpoint.setUnresolved(true);
                endpoint.setURI(reference.getTargets().get(0).getName());
                endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND);
                endpointReference.setUnresolved(true);
            } else {
                endpoint.setUnresolved(false);
                endpoint.setBinding(reference.getBindings().get(0));
                endpointReference.setStatus(EndpointReference.Status.RESOLVED_BINDING);
                endpointReference.setUnresolved(false);
            }           
        }
        return endpointReference;
View Full Code Here

            composite.setLocal(false);
            Component component = (Component)endpointReference.getComponent().clone();
            composite.getComponents().add(component);
            component.getReferences().clear();
            component.getServices().clear();
            ComponentReference reference = (ComponentReference)endpointReference.getReference().clone();
            component.getReferences().add(reference);
            reference.getBindings().clear();
            Binding binding = (Binding)endpointReference.getBinding().clone();
            reference.getBindings().add(binding);
            //reference.setInterfaceContract(endpointReference.getInterfaceContract());
            if (endpointReference.getStatus() != EndpointReference.Status.RESOLVED_BINDING){
                ComponentService service = assemblyFactory.createComponentService();
                service.setName(endpointReference.getTargetEndpoint().getURI());
                reference.getTargets().clear();
                reference.getTargets().add(service);
            }
            return composite;
        } catch (CloneNotSupportedException e) {
            return null;
        }
View Full Code Here

            throws ContributionReadException, XMLStreamException {
        Composite include = null;
        Component component = null;
        Property property = null;
        ComponentService componentService = null;
        ComponentReference componentReference = null;
        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        // Read the component scdl

        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
            case START_ELEMENT:
                QName itemName = reader.getName();
                if (!itemName.getNamespaceURI().equals(SCA10_NS))
                    name = new QName(SCA10_NS, itemName.getLocalPart());
                else
                    name = itemName;

                if (SERVICE_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><service>
                        componentService = assemblyFactory
                                .createComponentService();
                        contract = componentService;
                        componentService.setName(getString(reader, NAME));
                        component.getServices().add(componentService);
                        policyProcessor.readPolicies(contract, reader);
                    }

                } else if (REFERENCE_QNAME.equals(name)) {
                    if (component != null) {
                        // Read a <component><reference>
                        componentReference = assemblyFactory
                                .createComponentReference();
                        contract = componentReference;
                        componentReference.setName(getString(reader, NAME));
                        readMultiplicity(componentReference, reader);
                        if (isSet(reader, AUTOWIRE)) {
                            componentReference.setAutowire(getBoolean(reader,
                                    AUTOWIRE));
                        }
                        readTargets(componentReference, reader);
                        componentReference.setWiredByImpl(getBoolean(reader,
                                WIRED_BY_IMPL));
                        component.getReferences().add(componentReference);
                        policyProcessor.readPolicies(contract, reader);
                    }

                } else if (PROPERTY_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><property>
                        componentProperty = assemblyFactory
                                .createComponentProperty();
                        property = componentProperty;
                        componentProperty.setSource(getString(reader, SOURCE));
                        componentProperty.setFile(getString(reader, FILE));
                        policyProcessor.readPolicies(property, reader);
                        readAbstractProperty(componentProperty, reader);

                        // Read the property value
                        Document value = readPropertyValue(property
                                .getXSDElement(), property.getXSDType(), reader);
                        property.setValue(value);

                        component.getProperties().add(componentProperty);
                    }
                } else if (COMPONENT_QNAME.equals(name)) {

                    // Read a <component>
                    component = assemblyFactory.createComponent();
                    component.setName(getString(reader, NAME));
                    if (isSet(reader, AUTOWIRE)) {
                        component.setAutowire(getBoolean(reader, AUTOWIRE));
                    }
                    if (isSet(reader, URI)) {
                        component.setURI(getString(reader, URI));
                    }
                    component.setConstrainingType(readConstrainingType(reader));
                    composite.getComponents().add(component);
                    policyProcessor.readPolicies(component, reader);

                } else if (WIRE_QNAME.equals(name)) {

                    // Read a <wire>
                    wire = assemblyFactory.createWire();
                    ComponentReference source = assemblyFactory
                            .createComponentReference();
                    source.setUnresolved(true);
                    source.setName(getString(reader, SOURCE));
                    wire.setSource(source);

                    ComponentService target = assemblyFactory
                            .createComponentService();
                    target.setUnresolved(true);
View Full Code Here

     */
    private ComponentReference createSelfReference(Component component,
                                                   ComponentService service,
                                                   Class<?> businessInterface) throws CloneNotSupportedException,
        InvalidInterfaceException {
        ComponentReference componentReference = assemblyFactory.createComponentReference();
        componentReference.setName("$self$." + service.getName());
        for (Binding binding : service.getBindings()) {
            if (binding instanceof OptimizableBinding) {
                OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
                optimizableBinding.setTargetBinding(binding);
                optimizableBinding.setTargetComponent(component);
                optimizableBinding.setTargetComponentService(service);
                componentReference.getBindings().add(optimizableBinding);
            } else {
                componentReference.getBindings().add(binding);
            }
        }

        componentReference.setCallback(service.getCallback());
        componentReference.getTargets().add(service);
        componentReference.getPolicySets().addAll(service.getPolicySets());
        componentReference.getRequiredIntents().addAll(service.getRequiredIntents());

        InterfaceContract interfaceContract = service.getInterfaceContract();
        Service componentTypeService = service.getService();
        if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) {
            interfaceContract = componentTypeService.getInterfaceContract();
        }
        interfaceContract = getInterfaceContract(interfaceContract, businessInterface);
        componentReference.setInterfaceContract(interfaceContract);
        componentReference.setMultiplicity(Multiplicity.ONE_ONE);
        // component.getReferences().add(componentReference);
        return componentReference;
    }
View Full Code Here

        List<DeployedArtifact> artifacts = contributionService.getContribution(
                contribURI).getArtifacts();
        RuntimeComponent source = null;
        Composite composite = ArtifactsFinder.findComposite(compositeURI,
                artifacts);
        ComponentReference toRemove = null;

        if (composite != null) {
            source = (RuntimeComponent) ArtifactsFinder.findComponent(
                    composite, this.componentName);
        } else {
View Full Code Here

TOP

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

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.