Package org.apache.tuscany.sca.assembly

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


        // Process nested composites recursively
        configureNestedCompositeServices(composite);

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

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

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


                // Process the component services declared on components in this composite
                for (ComponentService componentService : component.getServices()) {
                    Service implService = componentService.getService();
                    if (implService != null && implService instanceof CompositeService) {
                        CompositeService compositeService = (CompositeService)implService;

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

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

        }
   
        // Connect composite services to the component services that they
        // promote
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;
            ComponentService componentService = compositeService.getPromotedService();
            if (componentService != null && componentService.isUnresolved()) {
               
                String promotedComponentName = compositeService.getPromotedComponent().getName();
                String promotedServiceName;
                if (componentService.getName() != null) {
                    promotedServiceName = promotedComponentName + '/' + componentService.getName();
                } else {
                    promotedServiceName = promotedComponentName;
                }
                ComponentService promotedService = componentServices.get(promotedServiceName);
                if (promotedService != null) {
   
                    // Point to the resolved component
                    Component promotedComponent = components.get(promotedComponentName);
                    compositeService.setPromotedComponent(promotedComponent);
                   
                    // Point to the resolved component service
                    compositeService.setPromotedService(promotedService);
   
                    // Use the interface contract from the component service if
                    // none is specified on the composite service
                    InterfaceContract compositeServiceInterfaceContract = compositeService.getInterfaceContract();
                    InterfaceContract promotedServiceInterfaceContract = promotedService.getInterfaceContract();
                    if (compositeServiceInterfaceContract == null) {
                        compositeService.setInterfaceContract(promotedServiceInterfaceContract);
                    } else if (promotedServiceInterfaceContract != null) {
                        // Check the compositeServiceInterfaceContract and promotedServiceInterfaceContract
                        boolean isCompatible = interfaceContractMapper.isCompatible(compositeServiceInterfaceContract, promotedServiceInterfaceContract);
                        if(!isCompatible){
                            warning(monitor, "ServiceInterfaceNotSubSet", compositeService, promotedServiceName);
View Full Code Here

        assertEquals(((PolicySetAttachPoint)composite).getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));

        Composite include = composite.getIncludes().get(0);
        assertEquals(include.getName(), new QName("http://calc", "TestAllDivide"));

        CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0);
        assertEquals(calcCompositeService.getName(), "CalculatorService");
        assertTrue(calcCompositeService.getPromotedService().isUnresolved());
        assertEquals(calcCompositeService.getPromotedService().getName(),
                     "CalculatorService");
        assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcServiceCallback = calcCompositeService.getCallback();
        assertNotNull(calcServiceCallback);
        assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
View Full Code Here

    private Composite createTopLevelCompositeServiceBinding() {
        Composite composite1 = assemblyFactory.createComposite();
        composite1.setName(new QName("http://foo", "C1"));

        CompositeService s1 = assemblyFactory.createCompositeService();
        s1.setName("s1");
        composite1.getServices().add(s1);

        Binding b1 = new TestBindingImpl();
        s1.getBindings().add(b1);

        CompositeService s2 = assemblyFactory.createCompositeService();
        s2.setName("s2");
        composite1.getServices().add(s2);

        Binding b2 = new TestBindingImpl();
        s2.getBindings().add(b2);

        return composite1;
    }
View Full Code Here

        // If the component is a composite, then we need to find the
        // non-composite component that provides the requested service
        if (component.getImplementation() instanceof Composite) {
            for (ComponentService componentService : component.getServices()) {
                if (serviceName == null || serviceName.equals(componentService.getName())) {
                    CompositeService compositeService = (CompositeService)componentService.getService();
                    if (compositeService != null) {
                        if (serviceName != null) {
                            serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
                        }
                        componentContext =
                            ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
                        return componentContext.createSelfReference(businessInterface, compositeService
                            .getPromotedService());
                    }
                    break;
                }
            }
View Full Code Here

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

            writeEnd(writer);
        }

        // Write <service> elements
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;
            Component promotedComponent = compositeService.getPromotedComponent();
            ComponentService promotedService = compositeService.getPromotedService();
            String promote;
            if (promotedService != null) {
                if (promotedService.getName() != null) {
                    promote = promotedComponent.getName() + '/' + promotedService.getName();
                } else {
View Full Code Here

            }
        }

        // Add model resolver to promoted components
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService)service;
            Component promotedComponent = compositeService.getPromotedComponent();
            if (promotedComponent instanceof ResolverExtension) {
                ((ResolverExtension)promotedComponent).setModelResolver(resolver);
            }
        }
    }
View Full Code Here

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

TOP

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

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.