Package org.apache.tuscany.sca.assembly

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


                // Process the component references declared on components in this composite
                for (ComponentReference componentReference : component.getReferences()) {
                    Reference implReference = componentReference.getReference();
                    if (implReference != null && implReference instanceof CompositeReference) {
                        CompositeReference compositeReference = (CompositeReference)implReference;

                        // Get the next lower level promoted reference
                        List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
                        if (!promotedRefs.isEmpty()) {
                            if (promotedRefs.size() == 1) {
                                ComponentReference promotedReference = promotedRefs.get(0);

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


        }
   
        // Connect composite references to the component references
        // 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
                       
                        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);
                            if (!isCompatible) {
                                warning(monitor, "ReferenceInterfaceNotSubSet", compositeReference, componentReferenceName);
View Full Code Here

        String value = element.getTextContent();
        assertEquals(value, "true");
        assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean"));
        assertEquals(property.isMany(), false);

        CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0);
        assertEquals(calcCompositeReference.getName(), "MultiplyService");
        assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved());
        assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(),
                     "CalculatorServiceComponent/multiplyService");
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcCallback = calcCompositeReference.getCallback();
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        assertNotNull(calcCallback);
        // TODO test operations

    }
View Full Code Here

        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.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));
                                }
                                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();) {
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(tokens.nextToken());
                                        compositeReference.getPromotedReferences().add(promotedReference);
                                    }
                                }
                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
   
                                composite.getReferences().add(compositeReference);                           
View Full Code Here

            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
                promote.add(promoted.getName());
            }
           
            // Write <reference> element
            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
View Full Code Here

        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);                           
View Full Code Here

            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
                promote.add(promoted.getName());
            }
           
            // Write <reference> element
            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
View Full Code Here

        }
   
        // Connect composite references to the component references
        // 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);
                            if (!isCompatible) {
                                warning(monitor, "ReferenceInterfaceNotSubSet", compositeReference, componentReferenceName);
View Full Code Here

                        }
    
                        // If the component reference is a promotion override, override the
                        // configuration of the promoted reference 
                        if (componentReference.isPromotionOverride()) {
                            CompositeReference compositeReference = (CompositeReference)implReference;
                            List<ComponentReference> promotedReferences =
                                ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
                            for (ComponentReference promotedReference : promotedReferences) {
                                ReferenceConfigurationUtil.reconcileReferenceBindings(
                                        componentReference, promotedReference, assemblyFactory, monitor);
View Full Code Here

     */
    public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException {
   
        // Process composite references declared in this composite
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // If the composite reference is a promotion override, override the
            // configuration of the promoted reference. 
            //FIXME: Policy configuration or wiring of domain-level composite references
            // doesn't cause a promotion override, unless the composite reference has
            // additional bindings.  Do we need to detect this and force an override?
            if (compositeReference.isPromotionOverride()) {
                List<ComponentReference> promotedReferences =
                    ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
                for (ComponentReference promotedReference : promotedReferences) {
                    ReferenceConfigurationUtil.reconcileReferenceBindings(
                            compositeReference, promotedReference, assemblyFactory, monitor);
                    if (compositeReference.getInterfaceContract() != null && // can be null in unit tests
                        compositeReference.getInterfaceContract().getCallbackInterface() != null) {
                        SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
                        if (promotedReference.getCallback() != null) {
                            promotedReference.getCallback().getBindings().clear();
                        } else {
                            promotedReference.setCallback(assemblyFactory.createCallback());
                        }
                        if (scaCallbackBinding != null) {
                            promotedReference.getCallback().getBindings().add(scaCallbackBinding);
                        }
                        if (compositeReference.getCallback() != null) {
                            promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback()
                                .getBindings());
                        }
                    }
                }
            }
View Full Code Here

TOP

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

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.