Package org.apache.tuscany.sca.assembly

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


                        }
                    } else {
                        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


        Composite composite = null;
        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;

        try {
            // Read the composite document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
   
                        if (COMPOSITE_QNAME.equals(name)) {
   
                            // Read a <composite>
                            composite = assemblyFactory.createComposite();
                            composite.setSpecVersion(Constants.SCA11_NS);
                           
                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
   
                            if(!isSet(reader, TARGET_NAMESPACE)){
                                // spec says that a composite must have a namespace
                                warning("NoCompositeNamespace", composite, composite.getName().toString());  
                            }
                           
                            if(isSet(reader, AUTOWIRE)) {
                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                           
                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
   
                            composite.setLocal(getBoolean(reader, LOCAL));
                            composite.setConstrainingType(readConstrainingType(reader));
                            policyProcessor.readPolicies(composite, reader);
   
                        } else if (INCLUDE_QNAME.equals(name)) {
   
                            // Read an <include>
                            include = assemblyFactory.createComposite();
                            include.setName(getQName(reader, NAME));
                            include.setURI(getString(reader, URI));
                            include.setUnresolved(true);
                            composite.getIncludes().add(include);
   
                        } else if (SERVICE_QNAME.equals(name)) {
                            if (component != null) {
   
                                // Read a <component><service>
                                componentService = assemblyFactory.createComponentService();
                                contract = componentService;
                                componentService.setName(getString(reader, NAME));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
   
                                component.getServices().add(componentService);
                                policyProcessor.readPolicies(contract, reader);
                            } else {
   
                                // Read a <composite><service>
                                compositeService = assemblyFactory.createCompositeService();
                                contract = compositeService;
                                compositeService.setName(getString(reader, NAME));
   
                                String promoted = getString(reader, PROMOTE);
                                if (promoted != null) {
                                    String promotedComponentName;
                                    String promotedServiceName;
                                    int s = promoted.indexOf('/');
                                    if (s == -1) {
                                        promotedComponentName = promoted;
                                        promotedServiceName = null;
                                    } else {
                                        promotedComponentName = promoted.substring(0, s);
                                        promotedServiceName = promoted.substring(s + 1);
                                    }
       
                                    Component promotedComponent = assemblyFactory.createComponent();
                                    promotedComponent.setUnresolved(true);
                                    promotedComponent.setName(promotedComponentName);
                                    compositeService.setPromotedComponent(promotedComponent);
       
                                    ComponentService promotedService = assemblyFactory.createComponentService();
                                    promotedService.setUnresolved(true);
                                    promotedService.setName(promotedServiceName);
                                    compositeService.setPromotedService(promotedService);
                                }
   
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
   
                                composite.getServices().add(compositeService);
                                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));
                                }
                                // Read @nonOverridable
                                String nonOverridable = reader.getAttributeValue(null, NONOVERRIDABLE);
                                if (nonOverridable != null) {
                                    componentReference.setNonOverridable(Boolean.parseBoolean(nonOverridable));
                                }
                                readTargets(componentReference, reader);
                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
   
                                component.getReferences().add(componentReference);
                                policyProcessor.readPolicies(contract, reader);
                            } else {
                                // Read a <composite><reference>
                                compositeReference = assemblyFactory.createCompositeReference();
                                contract = compositeReference;
                                compositeReference.setName(getString(reader, NAME));
                                readMultiplicity(compositeReference, reader);
                                readTargets(compositeReference, reader);
                                String promote = reader.getAttributeValue(null, Constants.PROMOTE);
                                if (promote != null) {
                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
                                        String refName = tokens.nextToken();
                                        Component promotedComponent = assemblyFactory.createComponent();
                                        int index = refName.indexOf('/');
                                        if (index == -1) {
                                            error("Invalid reference name", compositeReference, refName);
                                        }
                                        String promotedComponentName = refName.substring(0, index);
                                        promotedComponent.setName(promotedComponentName);
                                        promotedComponent.setUnresolved(true);
                                        compositeReference.getPromotedComponents().add(promotedComponent);
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(refName);
                                        compositeReference.getPromotedReferences().add(promotedReference);
                                    }
                                }
                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
   
                                composite.getReferences().add(compositeReference);                           
                                policyProcessor.readPolicies(contract, reader);
                            }
   
                        } else if (PROPERTY_QNAME.equals(name)) {
                            if (component != null) {
   
                                // Read a <component><property>
                                componentProperty = assemblyFactory.createComponentProperty();
                                property = componentProperty;
                                String source = getString(reader, SOURCE);
                                if(source!=null) {
                                    source = source.trim();
                                }
                                componentProperty.setSource(source);
                                if (source != null) {
                                    // $<name>/...
                                    if (source.charAt(0) == '$') {
                                        int index = source.indexOf('/');
                                        if (index == -1) {
                                            // Tolerating $prop
                                            source = source + "/";
                                            index = source.length() - 1;
                                        }
                                        source = source.substring(index + 1);
                                        if ("".equals(source)) {
                                            source = ".";
                                        }
                                    }
                                    XPath xpath = xPathFactory.newXPath();
                                    xpath.setNamespaceContext(reader.getNamespaceContext());
                                    try {
                                        componentProperty.setSourceXPathExpression(xpath.compile(source));
                                    } catch (XPathExpressionException e) {
                                      ContributionReadException ce = new ContributionReadException(e);
                                      error("ContributionReadException", xpath, ce);
                                        //throw ce;
                                    }
                                }
                                componentProperty.setFile(getString(reader, FILE));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
   
                                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 {
   
                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(property, reader);
                               
                                // Read the property value
                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                                property.setValue(value);
                               
                                composite.getProperties().add(property);
                            }
                           
                            // TUSCANY-1949
                            // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
                            if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
                                property = null;
                                componentProperty = null;
                            }
   
                        } 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));
                            }
                           
                            //handle extension attributes
                           this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
                           
                            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);
                            target.setName(getString(reader, TARGET));
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) {
                        // Set the promoted component
                        Component promotedComponent = compositeReference.getPromotedComponents().get(i);
                        promotedComponent = components.get(promotedComponent.getName());
                        compositeReference.getPromotedComponents().set(i, promotedComponent);
                       
                        // 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
                       
                        InterfaceContract compositeReferenceInterfaceContract = compositeReference.getInterfaceContract();
                        InterfaceContract componentReferenceInterfaceContract = componentReference.getInterfaceContract();
                        if (compositeReferenceInterfaceContract == null) {
                            compositeReference.setInterfaceContract(componentReferenceInterfaceContract);
                        } else if (componentReferenceInterfaceContract != null) {
                            // Check the compositeInterfaceContract and componentInterfaceContract
                            boolean isCompatible = interfaceContractMapper.isCompatible(compositeReferenceInterfaceContract, componentReferenceInterfaceContract);
View Full Code Here

        // Create a component reference for each reference
        if (component.getImplementation() != null) {
            for (Reference reference : component.getImplementation().getReferences()) {
                if (!componentReferences.containsKey(reference.getName())) {
                    ComponentReference componentReference =
                        assemblyFactory.createComponentReference();
                    componentReference.setIsCallback(reference.isCallback());
                    componentReference.setName(reference.getName());
                    componentReference.setReference(reference);
                    component.getReferences().add(componentReference);
                }
            }
        }

        // Reconcile each component reference with its reference
        for (ComponentReference componentReference : component.getReferences()) {
            Reference reference = componentReference.getReference();
            if (reference != null) {
                // Reconcile multiplicity
                if (componentReference.getMultiplicity() != null) {
                    if (!ReferenceConfigurationUtil.isValidMultiplicityOverride(reference.getMultiplicity(),
                                                                   componentReference
                                                                       .getMultiplicity())) {
                        warning(monitor, "ReferenceIncompatibleMultiplicity", component, component.getName(), componentReference.getName());
                    }
                } else {
                    componentReference.setMultiplicity(reference.getMultiplicity());
                }

                // Reconcile interface
                InterfaceContract interfaceContract = reference.getInterfaceContract();
                if (componentReference.getInterfaceContract() != null) {
                    if (interfaceContract != null && !componentReference.getInterfaceContract().equals(reference
                        .getInterfaceContract())) {
                        if (!interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(),
                                                                  interfaceContract)) {
                            warning(monitor, "ReferenceIncompatibleComponentInterface", component, component.getName(), componentReference.getName());
                        }
                    }
                } else {
                    componentReference.setInterfaceContract(interfaceContract);
                }

                // Reconcile bindings
                if (componentReference.getBindings().isEmpty()) {
                    componentReference.getBindings().addAll(reference.getBindings());
                }
               
                // Reconcile callback bindings
                if (componentReference.getCallback() == null) {
                    componentReference.setCallback(reference.getCallback());
                    if (componentReference.getCallback() == null) {
                        // Create an empty callback to avoid null check
                        componentReference.setCallback(assemblyFactory.createCallback());
                    }

                } else if (componentReference.getCallback().getBindings().isEmpty() && reference
                    .getCallback() != null) {
                    componentReference.getCallback().getBindings().addAll(reference.getCallback()
                        .getBindings());
                }
               
                // Propagate autowire setting from the component
                if (componentReference.getAutowire() == null) {
                    componentReference.setAutowire(component.getAutowire());
                }

                // Reconcile targets
                if (componentReference.getTargets().isEmpty()) {
                    componentReference.getTargets().addAll(reference.getTargets());
                }
            }
        }
    }
View Full Code Here

     */
    public 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

                                             Map<String, ComponentReference> componentReferences) {
        for (ComponentService service : component.getServices()) {
            if (service.getInterfaceContract() != null && // can be null in
                                                            // unit tests
            service.getInterfaceContract().getCallbackInterface() != null) {
                ComponentReference reference =
                    componentReferences.get(service.getName());
                if (reference == null) {
                    reference = createCallbackReference(component, service);
                }
                if (service.getCallback() != null) {
                    if (reference.getBindings().isEmpty()) {
                        reference.getBindings().addAll(service.getCallback().getBindings());
                    }
                }
                service.setCallbackReference(reference);
            }
        }
View Full Code Here

     *
     * @param component
     * @param service
     */
    private ComponentReference createCallbackReference(Component component, ComponentService service) {
        ComponentReference componentReference = assemblyFactory.createComponentReference();
        componentReference.setIsCallback(true);
        componentReference.setName(service.getName());
        try {
            InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone();
            contract.setInterface(contract.getCallbackInterface());
            contract.setCallbackInterface(null);
            componentReference.setInterfaceContract(contract);
        } catch (CloneNotSupportedException e) {
            // will not happen
        }
        Service implService = service.getService();
        if (implService != null) {
            Reference implReference = assemblyFactory.createReference();
            implReference.setName(implService.getName());
            try {
                InterfaceContract implContract =
                    (InterfaceContract)implService.getInterfaceContract().clone();
                implContract.setInterface(implContract.getCallbackInterface());
                implContract.setCallbackInterface(null);
                implReference.setInterfaceContract(implContract);
            } catch (CloneNotSupportedException e) {
                // will not happen
            }
            componentReference.setReference(implReference);
        }
        component.getReferences().add(componentReference);
        return componentReference;
    }
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);
       
        // 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);
       
        return componentReference;
View Full Code Here

           
            Composite composite = contribution.getDeployables().get(0);
           
            compositeBuilder.build(composite, null, monitor);
           
            ComponentReference ref = (composite.getComponents().get(0).getReferences().get(0));
/* TODO - EPR - convert to new endpoint reference          
            Assert.assertEquals(1, ref.getEndpoints().size());
           
            Endpoint endpoint = ref.getEndpoints().get(0);
           
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

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.