Package org.apache.tuscany.sca.assembly

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


        List<Service> compositeServices = composite.getServices();
        for (Service service : compositeServices) {

            // Create default SCA binding
            if (service.getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                service.getBindings().add(scaBinding);
            }

            // Create default SCA callback binding
            if (service.getInterfaceContract() != null
                && service.getInterfaceContract().getCallbackInterface() != null
                && service.getCallback() != null
                && service.getCallback().getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                scaBinding.setName(service.getName() + "Callback");
                service.getCallback().getBindings().add(scaBinding);
            }

            // Initialize binding names and URIs
            for (Binding binding : service.getBindings()) { 
                constructBindingName(service, binding);
                constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings);
            }
        }

        // Initialize composite reference callback binding URIs
        for (Reference reference : composite.getReferences()) {

            // Create default SCA callback binding
            if (reference.getInterfaceContract() != null
                && reference.getInterfaceContract().getCallbackInterface() != null
                && reference.getCallback() != null
                && reference.getCallback().getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                scaBinding.setName(reference.getName() + "Callback");
                reference.getCallback().getBindings().add(scaBinding);
            }

            // Initialize binding names and URIs
            if (reference.getCallback() != null) {
                for (Binding binding : reference.getCallback().getBindings()) {
                    constructBindingName(reference, binding);
                    constructBindingURI(parentComponentURI, composite, reference, binding, defaultBindings);
                }
            }
        }
       
        // Initialize component service binding URIs
        for (Component component : composite.getComponents()) {
           
            // Index properties, services and references
            Map<String, Service> services = new HashMap<String, Service>();
            Map<String, Reference> references = new HashMap<String, Reference>();
            Map<String, Property> properties = new HashMap<String, Property>();
            indexImplementationPropertiesServicesAndReferences(component,
                                                               services,
                                                               references,
                                                               properties);

            // Index component services, references and properties
            // Also check for duplicates
            Map<String, ComponentService> componentServices =
                new HashMap<String, ComponentService>();
            Map<String, ComponentReference> componentReferences =
                new HashMap<String, ComponentReference>();
            Map<String, ComponentProperty> componentProperties =
                new HashMap<String, ComponentProperty>();
            indexComponentPropertiesServicesAndReferences(component,
                                                          componentServices,
                                                          componentReferences,
                                                          componentProperties);

            // Reconcile component services/references/properties and
            // implementation services/references and create component
            // services/references/properties for the services/references
            // declared by the implementation
            reconcileServices(component, services, componentServices);
            reconcileReferences(component, references, componentReferences);
            reconcileProperties(component, properties, componentProperties);

            for (ComponentService service : component.getServices()) {

                // Create default SCA binding
                if (service.getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    service.getBindings().add(scaBinding);
                }

                // Create default SCA callback binding
                if (service.getInterfaceContract() != null
                    && service.getInterfaceContract().getCallbackInterface() != null
                    && service.getCallback() != null
                    && service.getCallback().getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    scaBinding.setName(service.getName() + "Callback");
                    service.getCallback().getBindings().add(scaBinding);
                }

                // Add all SCA bindings for the service callback to the bindingMap
                // so that BindingConfigurationUtil.matchBinding() can identify the node
                // for the target component.
                if (service.getInterfaceContract() != null
                    && service.getInterfaceContract().getCallbackInterface() != null
                    && service.getCallback() != null
                    && bindingMap != null
                    && defaultBindings != null) {
                    for (Binding binding : service.getCallback().getBindings()) {
                        if (binding instanceof SCABinding) {
                            for (Binding nodeBinding : defaultBindings) {
                                if (nodeBinding instanceof SCABinding) {
                                    bindingMap.put(binding, nodeBinding);
                                    break;
                                }
                            }
                        }
                    }
                }
   
                // Initialize binding names and URIs
                for (Binding binding : service.getBindings()) {
                    constructBindingName(service, binding);
                    constructBindingURI(component, service, binding, defaultBindings);
                }
            }
           
            for (ComponentReference reference : component.getReferences()) {
   
                // Create default SCA binding
                if (reference.getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    reference.getBindings().add(scaBinding);
                }

                // Add all SCA bindings for the reference to the bindingMap so that
                // BindingConfigurationUtil.matchBinding() can identify the node for
                // the source component.
                if (bindingMap != null && defaultBindings != null) {
                    for (Binding binding : reference.getBindings()) {
                        if (binding instanceof SCABinding) {
                            for (Binding nodeBinding : defaultBindings) {
                                if (nodeBinding instanceof SCABinding) {
                                    bindingMap.put(binding, nodeBinding);
                                    break;
                                }
                            }
                        }
                    }
                }
   
                // Create default SCA callback binding
                if (reference.getInterfaceContract() != null
                    && reference.getInterfaceContract().getCallbackInterface() != null
                    && reference.getCallback() != null
                    && reference.getCallback().getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    scaBinding.setName(reference.getName() + "Callback");
                    reference.getCallback().getBindings().add(scaBinding);
                }

                // Add all SCA bindings for the reference callback to the bindingMap
                // so that BindingConfigurationUtil.matchBinding() can identify the node
View Full Code Here


            interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
            reference.setInterfaceContract(interfaceContract);
            component.getReferences().add(reference);
            reference.setComponent(component);
            SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
            SCABinding binding = scaBindingFactory.createSCABinding();
            binding.setURI(targetURI);
            reference.getBindings().add(binding);
            return new ServiceReferenceImpl<B>(businessInterface, component, reference, binding, runtime
                .getProxyFactory(), runtime.getCompositeActivator());
        } catch (Exception e) {
            throw new ServiceRuntimeException(e);
View Full Code Here

        for (Service service : compositeServices) {
            // Set default binding names
           
            // Create default SCA binding
            if (service.getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                service.getBindings().add(scaBinding);
            }
/*
            // Initialize binding names and URIs
            for (Binding binding : service.getBindings()) {
               
                // Binding name defaults to the service name
                if (binding.getName() == null) {
                    binding.setName(service.getName());
                }
            }
           
            if (service.getCallback() != null) {
                for (Binding binding : service.getCallback().getBindings()) {
                    if (binding.getName() == null) {
                        binding.setName(service.getName());
                    }
                }
            }
*/
        }

        // Initialize reference bindings
        for (Reference reference : composite.getReferences()) {
            // Create default SCA binding
            if (reference.getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                reference.getBindings().add(scaBinding);
            }
/*
            // Set binding names
            for (Binding binding : reference.getBindings()) {
                if (binding.getName() == null) {
                    binding.setName(reference.getName());
                }
            }

            if (reference.getCallback() != null) {
                for (Binding binding : reference.getCallback().getBindings()) {
                    if (binding.getName() == null) {
                        binding.setName(reference.getName());
                    }
                }
            }
*/
        }

        // Initialize all component services and references
        Map<String, Component> components = new HashMap<String, Component>();
        for (Component component : composite.getComponents()) {

            // Index all components and check for duplicates
            if (components.containsKey(component.getName())) {
                error("DuplicateComponentName", component, composite.getName().toString(), component.getName());
            } else {
                components.put(component.getName(), component);
            }

            // Propagate the autowire flag from the composite to components
            if (component.getAutowire() == null) {
                component.setAutowire(composite.getAutowire());
            }

            if (component.getImplementation() instanceof ComponentPreProcessor) {
                ((ComponentPreProcessor)component.getImplementation()).preProcess(component);
            }

            // Index properties, services and references
            Map<String, Service> services = new HashMap<String, Service>();
            Map<String, Reference> references = new HashMap<String, Reference>();
            Map<String, Property> properties = new HashMap<String, Property>();
            indexImplementationPropertiesServicesAndReferences(component,
                                                               services,
                                                               references,
                                                               properties);

            // Index component services, references and properties
            // Also check for duplicates
            Map<String, ComponentService> componentServices =
                new HashMap<String, ComponentService>();
            Map<String, ComponentReference> componentReferences =
                new HashMap<String, ComponentReference>();
            Map<String, ComponentProperty> componentProperties =
                new HashMap<String, ComponentProperty>();
            indexComponentPropertiesServicesAndReferences(component,
                                                          componentServices,
                                                          componentReferences,
                                                          componentProperties);

            // Reconcile component services/references/properties and
            // implementation services/references and create component
            // services/references/properties for the services/references
            // declared by the implementation
            reconcileServices(component, services, componentServices);
            reconcileReferences(component, references, componentReferences);
            reconcileProperties(component, properties, componentProperties);

            // Configure or create callback services for component's references
            // with callbacks
            configureCallbackServices(component, componentServices);

            // Configure or create callback references for component's services
            // with callbacks
            configureCallbackReferences(component, componentReferences);

            // Create self references to the component's services
//            if (!(component.getImplementation() instanceof Composite)) {
//                createSelfReferences(component);
//            }

            // Initialize service bindings
            for (ComponentService componentService : component.getServices()) {

                // Create default SCA binding
                if (componentService.getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    componentService.getBindings().add(scaBinding);
                }
/*
                // Set binding names
                for (Binding binding : componentService.getBindings()) {
                   
                    // Binding name defaults to the service name
                    if (binding.getName() == null) {
                        binding.setName(componentService.getName());
                    }
                }
                if (componentService.getCallback() != null) {
                    for (Binding binding : componentService.getCallback().getBindings()) {
                        if (binding.getName() == null) {
                            binding.setName(componentService.getName());
                        }
                    }
                }
*/
            }

            // Initialize reference bindings
            for (ComponentReference componentReference : component.getReferences()) {

                // Create default SCA binding
                if (componentReference.getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    componentReference.getBindings().add(scaBinding);
                }
/*
                // Set binding names
                for (Binding binding : componentReference.getBindings()) {
View Full Code Here

        }
        return null;
    }
   
    private SCABinding createSCABinding() {
        SCABinding scaBinding = scaBindingFactory.createSCABinding();
       
        // mark the bindings that are added automatically so that they can
        // be disregarded for overriding purposes
        if (scaBinding instanceof AutomaticBinding){
            ((AutomaticBinding)scaBinding).setIsAutomatic(true);
View Full Code Here

        for (Service service : compositeServices) {
            // Set default binding names
           
            // Create default SCA binding
            if (service.getBindings().isEmpty()) {
                SCABinding scaBinding = createSCABinding();
                service.getBindings().add(scaBinding);
            }
   
            // Initialize binding names and URIs
            for (Binding binding : service.getBindings()) { 
                constructBindingName(service, binding);
                constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings);
            }
        }
       
        // Initialize component service binding URIs
        for (Component component : composite.getComponents()) {
           
            // Index properties, services and references
            Map<String, Service> services = new HashMap<String, Service>();
            Map<String, Reference> references = new HashMap<String, Reference>();
            Map<String, Property> properties = new HashMap<String, Property>();
            indexImplementationPropertiesServicesAndReferences(component,
                                                               services,
                                                               references,
                                                               properties);

            // Index component services, references and properties
            // Also check for duplicates
            Map<String, ComponentService> componentServices =
                new HashMap<String, ComponentService>();
            Map<String, ComponentReference> componentReferences =
                new HashMap<String, ComponentReference>();
            Map<String, ComponentProperty> componentProperties =
                new HashMap<String, ComponentProperty>();
            indexComponentPropertiesServicesAndReferences(component,
                                                          componentServices,
                                                          componentReferences,
                                                          componentProperties);

            // Reconcile component services/references/properties and
            // implementation services/references and create component
            // services/references/properties for the services/references
            // declared by the implementation
            reconcileServices(component, services, componentServices);
            reconcileReferences(component, references, componentReferences);
            reconcileProperties(component, properties, componentProperties);
           
            for (ComponentService service : component.getServices()) {
   
                // Create default SCA binding
                if (service.getBindings().isEmpty()) {
                    SCABinding scaBinding = createSCABinding();
                    service.getBindings().add(scaBinding);
                }
   
                // Initialize binding names and URIs
                for (Binding binding : service.getBindings()) {
View Full Code Here

    public Class<SCABinding> getModelType() {
        return SCABinding.class;
    }

    public SCABinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
        SCABinding scaBinding = scaBindingFactory.createSCABinding();
        IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
        bindingType.setName(getArtifactType());
        bindingType.setUnresolved(true);
        ((PolicySetAttachPoint)scaBinding).setType(bindingType);
       
        // Read policies
        policyProcessor.readPolicies(scaBinding, reader);
       
        // Read binding name
        String name = reader.getAttributeValue(null, NAME);
        if (name != null) {
            scaBinding.setName(name);
        }

        // Read binding URI
        String uri = reader.getAttributeValue(null, URI);
        if (uri != null) {
            scaBinding.setURI(uri);
        }
       
        // Handle extended attributes
        for (int a = 0; a < reader.getAttributeCount(); a++) {
            QName attributeName = reader.getAttributeName(a);
            if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) {
                if( (! Constants.SCA10_NS.equals(attributeName.getNamespaceURI()) &&
                    (! Constants.SCA10_TUSCANY_NS.equals(attributeName.getNamespaceURI()) ))) {
                    Object attributeValue = extensionAttributeProcessor.read(attributeName, reader);
                    Extension attributeExtension;
                    if (attributeValue instanceof Extension) {
                        attributeExtension = (Extension) attributeValue;
                    } else {
                        attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true);
                    }
                    scaBinding.getAttributeExtensions().add(attributeExtension);
                }
            }
        }       

        // Skip to end element
View Full Code Here

        InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType");
        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
        ComponentType componentType = (ComponentType)staxProcessor.read(reader, context);
        assertNotNull(componentType);
       
        SCABinding referenceSCABinding = (SCABinding) componentType.getReferences().get(0).getBindings().get(0);
        assertNotNull(referenceSCABinding);
       
        SCABinding serviceSCABinding   = (SCABinding) componentType.getServices().get(0).getBindings().get(0);
        assertNotNull(serviceSCABinding);
       
        //new PrintUtil(System.out).print(componentType);
    }
View Full Code Here

        InputStream is = getClass().getResourceAsStream("/Calculator.composite");
        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
        Composite composite = (Composite)staxProcessor.read(reader, context);
        assertNotNull(composite);

        SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0);
        SCABinding serviceSCABinding   = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
       
        Assert.assertNotNull(referenceSCABinding);
        Assert.assertNotNull(serviceSCABinding)
       
        assertNotNull(serviceSCABinding.getRequestWireFormat());       
    }
View Full Code Here

    public Class<SCABinding> getModelType() {
        return SCABinding.class;
    }

    public SCABinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
        SCABinding scaBinding = scaBindingFactory.createSCABinding();
        ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType();
        bindingType.setType(getArtifactType());
        bindingType.setUnresolved(true);
        ((PolicySubject)scaBinding).setExtensionType(bindingType);

        // Read policies
        policyProcessor.readPolicies(scaBinding, reader);

        // Read binding name
        String name = reader.getAttributeValue(null, NAME);
        if (name != null) {
            scaBinding.setName(name);
        }

        // Read binding URI
        String uri = getURIString(reader, URI);
        if (uri != null) {
            scaBinding.setURI(uri);
        }
       
        // Read delegate binding type
        String delegateBindingType = getString(reader, DELEGATE_BINDING_TYPE);
        if (delegateBindingType != null) {
            scaBinding.setDelegateBindingType(delegateBindingType);
        }
       
        // Read delegate binding URI
        String delegateBindingURI = getURIString(reader, DELEGATE_BINDING_URI);
        if (delegateBindingURI != null) {
            scaBinding.setDelegateBindingURI(delegateBindingURI);
        }

        // Read any sub-elements
        boolean endFound = false;
        while (reader.hasNext() && endFound == false) {
            int nextElementType = reader.next();
            switch (nextElementType) {
                case START_ELEMENT:
                    Object extension = extensionProcessor.read(reader, context);
                    if (extension != null) {
                        if (extension instanceof WireFormat) {
                            scaBinding.setRequestWireFormat((WireFormat)extension);
                        }
                    }
                    break;
                case END_ELEMENT:
                  QName endElementName = reader.getName();
View Full Code Here

    @Override
    public Binding handleUnknownEndpoint(EndpointReference endpointReference) {
       
        if (endpointReference.getTargetEndpoint().getURI().endsWith("Service1")) {
            SCABinding b = new SCABindingFactoryImpl().createSCABinding();
            b.setURI("http://localhost:8085/Service1/Helloworld");
            return b;
           
        } else if (endpointReference.getTargetEndpoint().getURI().endsWith("Service2")) {
            SCABinding b = new SCABindingFactoryImpl().createSCABinding();
            b.setURI("http://localhost:8085/Service2/Helloworld");
            return b;
        }

        return null;
    }
View Full Code Here

TOP

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

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.