diff options
Diffstat (limited to 'java')
73 files changed, 83 insertions, 10858 deletions
diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java index 1b607a1170..1fba771a7e 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java @@ -22,18 +22,19 @@ package org.apache.tuscany.sca.assembly.xml; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URL; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; @@ -43,12 +44,7 @@ import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.BeforeClass; import org.junit.Test; @@ -63,8 +59,6 @@ public class WireTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static ModelResolver resolver; private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; - private static CompositeBuilder compositeBuilder; - private static Monitor monitor; @BeforeClass public static void setUp() throws Exception { @@ -73,17 +67,10 @@ public class WireTestCase { StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); resolver = new DefaultModelResolver(); - - MonitorFactory monitorFactory = new DefaultMonitorFactory(); - monitor = monitorFactory.createMonitor(); - + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); modelFactories.addFactory(scaBindingFactory); - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); @@ -112,7 +99,6 @@ public class WireTestCase { policyDefinitionsProcessor.resolve(scaDefns, resolver); staxProcessor.resolve(composite, resolver); - compositeBuilder.build(composite, null, monitor); assertEquals(composite.getConstrainingType(), constrainingType); assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); @@ -120,17 +106,11 @@ public class WireTestCase { @Test public void testResolveComposite() throws Exception { - InputStream is = getClass().getResourceAsStream("Calculator.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite nestedComposite = (Composite)staxProcessor.read(reader); - is.close(); + Composite nestedComposite = readComposite("Calculator.composite"); assertNotNull(nestedComposite); resolver.addModel(nestedComposite); - is = getClass().getResourceAsStream("TestAllCalculator.composite"); - reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); - is.close(); + Composite composite = readComposite("TestAllCalculator.composite"); URL url = getClass().getResource("test_definitions.xml"); URI uri = URI.create("test_definitions.xml"); @@ -140,9 +120,16 @@ public class WireTestCase { policyDefinitionsProcessor.resolve(scaDefns, resolver); staxProcessor.resolve(composite, resolver); - compositeBuilder.build(composite, null, monitor); assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); } + private Composite readComposite(String resource) throws XMLStreamException, ContributionReadException, IOException { + InputStream is = getClass().getResourceAsStream(resource); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = (Composite)staxProcessor.read(reader); + is.close(); + return composite; + } + } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java index 2b70520076..6a2c9278fc 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java @@ -36,8 +36,6 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; @@ -46,12 +44,7 @@ import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.BeforeClass; import org.junit.Test; @@ -65,9 +58,7 @@ public class WriteAllTestCase { private static XMLOutputFactory outputFactory; private static ExtensibleStAXArtifactProcessor staxProcessor; private static ModelResolver resolver; - private static CompositeBuilder compositeBuilder; private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; - private static Monitor monitor; @BeforeClass public static void setUp() throws Exception { @@ -81,14 +72,7 @@ public class WriteAllTestCase { FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); modelFactories.addFactory(scaBindingFactory); - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); - - MonitorFactory monitorFactory = new DefaultMonitorFactory(); - monitor = monitorFactory.createMonitor(); - URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); } @@ -123,7 +107,7 @@ public class WriteAllTestCase { policyDefinitionsProcessor.resolve(scaDefns, resolver); staxProcessor.resolve(composite, resolver); - compositeBuilder.build(composite, null, monitor); + // compositeBuilder.build(composite, null, monitor); ByteArrayOutputStream bos = new ByteArrayOutputStream(); staxProcessor.write(composite, bos); } diff --git a/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite index 998a49226b..0336002ded 100644 --- a/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite +++ b/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite @@ -29,8 +29,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://docs.oasis-open.org/ns/opencsa/sca/200903 http://docs.oasis-open.org/ns/opencsa/sca/200903 "> + <!-- <include name="tns:CompleteDivide"/> - + --> <service name="DivideService" policySets="" promote="CalculatorDivideComponent/DivideService" requires=""> <interface.java interface="calculator.DivideService" callbackInterface="calculator.DivideCallback"/> <operation name="divide" policySets="" requires=""/> diff --git a/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml b/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml index 9de5be3212..4325309463 100644 --- a/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml +++ b/java/sca/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml @@ -64,7 +64,7 @@ <policySet name="SecureMessagingPolicies" provides="test:confidentiality" appliesTo="binding.ws" xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> - <intentMap provides="test:confidentiality" default="transport"> + <intentMap provides="test:confidentiality"> <qualifier name="transport"> <wsp:PolicyAttachment> <!-- policy expression and policy subject for "transport" alternative --> @@ -81,7 +81,7 @@ <policySet name="SecurityPolicy" provides="test:confidentiality" appliesTo="binding.ws" xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> - <intentMap provides="test:confidentiality" default="message"> + <intentMap provides="test:confidentiality"> <qualifier name="message"> <wsp:PolicyAttachment> <!-- policy attachment for body encryption --> @@ -114,7 +114,7 @@ <policySet name="ConfidentialityPolicies" provides="test:confidentiality" appliesTo="binding.ws" xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> - <intentMap provides="test:confidentiality" default="transport"> + <intentMap provides="test:confidentiality"> <qualifier name="transport"> <wsp:PolicyAttachment> <!-- policy expression and policy subject for "transport" diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java deleted file mode 100644 index cb74572fa9..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java +++ /dev/null @@ -1,705 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.Map; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.TransformerFactory; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.w3c.dom.Document; - -/** - * Base class for Builder implementations - * - * @version $Rev$ $Date$ - */ -public abstract class BaseBuilderImpl implements CompositeBuilder { - protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - protected static final String BINDING_SCA = "binding.sca"; - protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); - - protected AssemblyFactory assemblyFactory; - protected SCABindingFactory scaBindingFactory; - protected InterfaceContractMapper interfaceContractMapper; - protected DocumentBuilderFactory documentBuilderFactory; - protected TransformerFactory transformerFactory; - protected BuilderExtensionPoint builders; - - protected BaseBuilderImpl(BuilderExtensionPoint builders, - AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory, - InterfaceContractMapper interfaceContractMapper) { - this.builders = builders; - this.assemblyFactory = assemblyFactory; - this.scaBindingFactory = scaBindingFactory; - this.documentBuilderFactory = documentBuilderFactory; - this.transformerFactory = transformerFactory; - this.interfaceContractMapper = interfaceContractMapper; - } - - /** - * Construct a builder from the extension point registry - * @param registry - */ - protected BaseBuilderImpl(ExtensionPointRegistry registry) { - this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = factoryExtensionPoint.getFactory(AssemblyFactory.class); - this.scaBindingFactory = factoryExtensionPoint.getFactory(SCABindingFactory.class); - this.documentBuilderFactory = factoryExtensionPoint.getFactory(DocumentBuilderFactory.class); - this.transformerFactory = factoryExtensionPoint.getFactory(TransformerFactory.class); - this.interfaceContractMapper = - registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(InterfaceContractMapper.class); - } - - /** - * Report a warning. - * - * @param monitor - * @param problems - * @param message - * @param model - */ - protected void warning(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "assembly-validation-messages", - Severity.WARNING, - model, - message, - messageParameters); - monitor.problem(problem); - } - } - - /** - * Report a error. - * - * @param monitor - * @param problems - * @param message - * @param model - */ - protected void error(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "assembly-validation-messages", - Severity.ERROR, - model, - message, - messageParameters); - monitor.problem(problem); - } - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - protected void error(Monitor monitor, String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = null; - problem = - monitor.createProblem(this.getClass().getName(), - "assembly-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - - /** - * Index components inside a composite - * - * @param composite - * @param componentServices - - */ - protected void indexComponents(Composite composite, Map<String, Component> components) { - for (Component component : composite.getComponents()) { - // Index components by name - components.put(component.getName(), component); - } - } - - /** - * Index services inside a composite - * - * @param composite - * @param componentServices - */ - protected void indexServices(Composite composite, Map<String, ComponentService> componentServices) { - - for (Component component : composite.getComponents()) { - - ComponentService nonCallbackService = null; - int nonCallbackServiceCount = 0; - - for (ComponentService componentService : component.getServices()) { - // Index component services by component name / service name - String uri = component.getName() + '/' + componentService.getName(); - componentServices.put(uri, componentService); - - // count how many non-callback there are - if (!componentService.isForCallback()) { - - if (nonCallbackServiceCount == 0) { - nonCallbackService = componentService; - } - nonCallbackServiceCount++; - } - } - if (nonCallbackServiceCount == 1) { - // If we have a single non callback service, index it by - // component name as well - componentServices.put(component.getName(), nonCallbackService); - } - } - } - - /** - * Index components, services and references inside a composite. - * @param composite - * @param components - * @param componentServices - * @param componentReferences - */ - protected void indexComponentsServicesAndReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences) { - - for (Component component : composite.getComponents()) { - - // Index components by name - components.put(component.getName(), component); - - ComponentService nonCallbackService = null; - int nonCallbackServices = 0; - for (ComponentService componentService : component.getServices()) { - - // Index component services by component name / service name - String uri = component.getName() + '/' + componentService.getName(); - componentServices.put(uri, componentService); - - // TODO - EPR - $promoted$ no longer used but it doesn't do any harm here - boolean promotedService = false; - if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) { - promotedService = true; - } - - // count how many non-callback, non-promoted services there are - // if there is only one the component name also acts as the service name - if ((!componentService.isForCallback()) && (!promotedService)) { - - // Check how many non callback non-promoted services we have - if (nonCallbackServices == 0) { - nonCallbackService = componentService; - } - nonCallbackServices++; - } - - } - - if (nonCallbackServices == 1) { - // If we have a single non callback service, index it by - // component name as well - componentServices.put(component.getName(), nonCallbackService); - } - - // Index references by component name / reference name - for (ComponentReference componentReference : component.getReferences()) { - String uri = component.getName() + '/' + componentReference.getName(); - componentReferences.put(uri, componentReference); - } - } - } - - protected void indexComponentPropertiesServicesAndReferences(Component component, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences, - Map<String, ComponentProperty> componentProperties, - Monitor monitor) { - for (ComponentService componentService : component.getServices()) { - if (componentServices.containsKey(componentService.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateComponentServiceName", component, component.getName(), componentService - .getName()); - } else { - componentServices.put(componentService.getName(), componentService); - } - } - for (ComponentReference componentReference : component.getReferences()) { - if (componentReferences.containsKey(componentReference.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateComponentReferenceName", component, component.getName(), componentReference - .getName()); - } else { - componentReferences.put(componentReference.getName(), componentReference); - } - } - for (ComponentProperty componentProperty : component.getProperties()) { - if (componentProperties.containsKey(componentProperty.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateComponentPropertyName", component, component.getName(), componentProperty - .getName()); - } else { - componentProperties.put(componentProperty.getName(), componentProperty); - } - } - - } - - protected void indexImplementationPropertiesServicesAndReferences(Component component, - Map<String, Service> services, - Map<String, Reference> references, - Map<String, Property> properties, - Monitor monitor) { - // First check that the component has a resolved implementation - Implementation implementation = component.getImplementation(); - if (implementation == null) { - // A component must have an implementation - error(monitor, "NoComponentImplementation", component, component.getName()); - - } else if (implementation.isUnresolved()) { - - // The implementation must be fully resolved - error(monitor, "UnresolvedComponentImplementation", component, component.getName(), implementation.getURI()); - - } else { - - // Index properties, services and references, also check for - // duplicates - for (Property property : implementation.getProperties()) { - if (properties.containsKey(property.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateImplementationPropertyName", component, component.getName(), property - .getName()); - } else { - properties.put(property.getName(), property); - } - } - for (Service service : implementation.getServices()) { - if (services.containsKey(service.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateImplementationServiceName", component, component.getName(), service - .getName()); - } else { - services.put(service.getName(), service); - } - } - for (Reference reference : implementation.getReferences()) { - if (references.containsKey(reference.getName())) { - // [MJE 13/05/2009] Changed to "error" since allowing these violates the OASIS spec - error(monitor, "DuplicateImplementationReferenceName", component, component.getName(), reference - .getName()); - } else { - references.put(reference.getName(), reference); - } - } - } - - } - - /** - * Reconcile component properties and the properties defined by the - * component type. - * - * @param component - * @param properties - * @param componentProperties - * @param problems - */ - protected void reconcileProperties(Component component, - Map<String, Property> properties, - Map<String, ComponentProperty> componentProperties, - Monitor monitor) { - - // Connect component properties to their properties - for (ComponentProperty componentProperty : component.getProperties()) { - Property property = properties.get(componentProperty.getName()); - if (property != null) { - componentProperty.setProperty(property); - } else { - error(monitor, "PropertyNotFound", component, component.getName(), componentProperty.getName()); - } - } - - // Create component properties for all properties - if (component.getImplementation() != null) { - for (Property property : component.getImplementation().getProperties()) { - if (!componentProperties.containsKey(property.getName())) { - ComponentProperty componentProperty = assemblyFactory.createComponentProperty(); - componentProperty.setName(property.getName()); - componentProperty.setValue(property.getValue()); - componentProperty.setMany(property.isMany()); - componentProperty.setMustSupply(property.isMustSupply()); - componentProperty.setXSDElement(property.getXSDElement()); - componentProperty.setXSDType(property.getXSDType()); - componentProperty.setProperty(property); - component.getProperties().add(componentProperty); - } - } - } - - // Reconcile component properties and their properties - for (ComponentProperty componentProperty : component.getProperties()) { - Property property = componentProperty.getProperty(); - if (property != null) { - - // Check that a component property does not override the - // mustSupply attribute - if (!property.isMustSupply() && componentProperty.isMustSupply()) { - warning(monitor, - "PropertyMustSupplyIncompatible", - component, - component.getName(), - componentProperty.getName()); - } - - // Default to the mustSupply attribute specified on the property - if (!componentProperty.isMustSupply()) - componentProperty.setMustSupply(property.isMustSupply()); - - // Default to the value specified on the component type property - if (!isPropertyValueSet(componentProperty)) { - componentProperty.setValue(property.getValue()); - } - - // Override the property value for the composite - if (component.getImplementation() instanceof Composite) { - property.setValue(componentProperty.getValue()); - } - - // Check that a value is supplied - if (!isPropertyValueSet(componentProperty) && property.isMustSupply()) { - error(monitor, "PropertyMustSupplyNull", component, component.getName(), componentProperty - .getName()); - } - - // Check that a component property does not override the - // many attribute - if (!property.isMany() && componentProperty.isMany()) { - - warning(monitor, "PropertyOverrideManyAttribute", component, component.getName(), componentProperty - .getName()); - } - - // Default to the many attribute defined on the property - componentProperty.setMany(property.isMany()); - - // Default to the type and element defined on the property - if (componentProperty.getXSDType() == null) { - componentProperty.setXSDType(property.getXSDType()); - } - if (componentProperty.getXSDElement() == null) { - componentProperty.setXSDElement(property.getXSDElement()); - } - - // Check that a type or element are specified - if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { - warning(monitor, "NoTypeForComponentProperty", component, component.getName(), componentProperty - .getName()); - } - } - } - } - - /** - * Look to see if any value elements have been set into the property - * A bit involved as the value is stored as a DOM Document - * - * @param property the property to be tested - * @return true is values are present - */ - private boolean isPropertyValueSet(Property property) { - Document value = (Document)property.getValue(); - - if (value == null) { - return false; - } - - if (value.getFirstChild() == null) { - return false; - } - - if (value.getFirstChild().getChildNodes().getLength() == 0) { - return false; - } - - return true; - } - - /** - * Reconcile component references with the references defined on the - * component type. - * - * @param component - * @param references - * @param componentReferences - * @param monitor - */ - protected void reconcileReferences(Component component, - Map<String, Reference> references, - Map<String, ComponentReference> componentReferences, - Monitor monitor) { - - // Connect each component reference to the corresponding reference - for (ComponentReference componentReference : component.getReferences()) { - if (componentReference.getReference() != null || componentReference.isForCallback()) { - continue; - } - Reference reference = references.get(componentReference.getName()); - if (reference != null) { - componentReference.setReference(reference); - } else { - if (!componentReference.getName().startsWith("$self$.")) { - error(monitor, "ReferenceNotFound", component, component.getName(), componentReference.getName()); - } - } - } - - // Create a Component reference for each reference for which there is no declared Component reference - if (component.getImplementation() != null) { - for (Reference reference : component.getImplementation().getReferences()) { - if (!componentReferences.containsKey(reference.getName())) { - ComponentReference componentReference = assemblyFactory.createComponentReference(); - componentReference.setForCallback(reference.isForCallback()); - 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())) { - error(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(interfaceContract, componentReference - .getInterfaceContract())) { - error(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()); - } - } - } - } - - /** - * Reconcile component services and services defined on the component type. - * - * @param component - * @param services - * @param componentServices - * @param monitor - */ - protected void reconcileServices(Component component, - Map<String, Service> services, - Map<String, ComponentService> componentServices, - Monitor monitor) { - - // Connect each component service to the corresponding service - for (ComponentService componentService : component.getServices()) { - if (componentService.getService() != null || componentService.isForCallback()) { - continue; - } - Service service = services.get(componentService.getName()); - if (service != null) { - componentService.setService(service); - } else { - warning(monitor, "ServiceNotFoundForComponentService", component, component.getName(), componentService - .getName()); - } - } - - // Create a component service for each service - if (component.getImplementation() != null) { - for (Service service : component.getImplementation().getServices()) { - if (!componentServices.containsKey(service.getName())) { - ComponentService componentService = assemblyFactory.createComponentService(); - componentService.setForCallback(service.isForCallback()); - String name = service.getName(); - componentService.setName(name); - componentService.setService(service); - component.getServices().add(componentService); - componentServices.put(name, componentService); - } - } - } - - //Reconcile each component service with its service - for (ComponentService componentService : component.getServices()) { - Service service = componentService.getService(); - if (service != null) { - // Reconcile interface - InterfaceContract interfaceContract = service.getInterfaceContract(); - if (componentService.getInterfaceContract() != null) { - if (interfaceContract != null && !componentService.getInterfaceContract().equals(interfaceContract)) { - if (!interfaceContractMapper.isCompatible(componentService.getInterfaceContract(), - interfaceContract)) { - // MJE, 16/05/2009 - Upgraded from "warning" to "error" since this is a fatal problem - TUSCANY-3036 - error(monitor, - "ServiceIncompatibleComponentInterface", - component, - component.getName(), - componentService.getName()); - } - } - } else { - componentService.setInterfaceContract(interfaceContract); - } - - // Reconcile bindings - if (componentService.getBindings().isEmpty()) { - componentService.getBindings().addAll(service.getBindings()); - } - - // Reconcile callback bindings - if (componentService.getCallback() == null) { - componentService.setCallback(service.getCallback()); - if (componentService.getCallback() == null) { - // Create an empty callback to avoid null check - componentService.setCallback(assemblyFactory.createCallback()); - } - } else if (componentService.getCallback().getBindings().isEmpty() && service.getCallback() != null) { - componentService.getCallback().getBindings().addAll(service.getCallback().getBindings()); - } - } - } - } - - protected void attachSCABinding(Contract contract, Definitions definitions) { - if (!contract.getBindings().isEmpty()) { - contract.setOverridingBindings(true); - // No need to set binding.sca - return; - } - contract.setOverridingBindings(false); - - // Only add binding.sca for services - // FIXME: The latest OASIS spec only adds binding.sca to services - /* - if (!(contract instanceof Service)) { - return; - } - */ - SCABinding scaBinding = scaBindingFactory.createSCABinding(); - - if (definitions != null) { - for (ExtensionType attachPointType : definitions.getBindingTypes()) { - if (attachPointType.getType().equals(BINDING_SCA_QNAME)) { - ((PolicySubject)scaBinding).setExtensionType(attachPointType); - } - } - } - - contract.getBindings().add(scaBinding); - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java deleted file mode 100644 index d0cee1f6fb..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; - -/** - * Configuration of binding URIs. - * - * @version $Rev$ $Date$ - */ -public class BindingURIBuilderImpl { - - private Monitor monitor; - - public BindingURIBuilderImpl(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - } - - /** - * Called by CompositeBindingURIBuilderImpl - * - * @param composite the composite to be configured - */ - protected void configureBindingURIsAndNames(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, null, monitor); - configureBindingNames(composite, monitor); - } - - /** - * Fully resolve the binding URIs based on available information. This includes information - * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, - * from any associated policies and from the default information for each binding type. - * - * @param composite the composite to be configured - * @param defaultBindings list of default binding configurations - */ - protected void configureBindingURIs(Composite composite, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, defaultBindings, monitor); - } - - /** - * Fully resolve the binding URIs based on available information. This includes information - * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, - * from any associated policies and from the default information for each binding type. - * - * NOTE: This method repeats some of the processing performed by the configureComponents() - * method above. The duplication is needed because NodeConfigurationServiceImpl - * calls this method without previously calling configureComponents(). In the - * normal builder sequence used by CompositeBuilderImpl, both of these methods - * are called. - * - * TODO: Share the URL calculation algorithm with the configureComponents() method above - * although keeping the configureComponents() methods signature as is because when - * a composite is actually build in a node the node default information is currently - * available - * - * @param composite the composite to be configured - * @param uri the path to the composite provided through any nested composite component implementations - * @param defaultBindings list of default binding configurations - */ - private void configureBindingURIs(Composite composite, - String uri, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - String parentComponentURI = uri; - - monitor.pushContext("Composite: " + composite.getName().toString()); - try { - // Process nested composites recursively - for (Component component : composite.getComponents()) { - - // Initialize component URI - String componentURI; - if (parentComponentURI == null) { - componentURI = component.getName(); - } else { - componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString(); - } - component.setURI(componentURI); - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - // Process nested composite - configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); - } - } - - // Initialize composite service binding URIs - List<Service> compositeServices = composite.getServices(); - for (Service service : compositeServices) { - - constructBindingNames(service, monitor); - - // Initialize binding names and URIs - for (Binding binding : service.getBindings()) { - constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings, monitor); - } - } - - // Initialize component service binding URIs - for (Component component : composite.getComponents()) { - - monitor.pushContext("Component: " + component.getName()); - - try { - - for (ComponentService service : component.getServices()) { - - constructBindingNames(service, monitor); - - // Initialize binding names and URIs - for (Binding binding : service.getBindings()) { - constructBindingURI(component, service, binding, defaultBindings, monitor); - } - } - } finally { - monitor.popContext(); - } - } - } finally { - monitor.popContext(); - } - } - - /** - * Add default names for callback bindings and reference bindings. Needs to be - * separate from configureBindingURIs() because configureBindingURIs() is called - * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl. - */ - private void configureBindingNames(Composite composite, Monitor monitor) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // Process nested composite - configureBindingNames((Composite)implementation, monitor); - } - } - - // Initialize composite service callback binding names - for (Service service : composite.getServices()) { - constructBindingNames(service, monitor); - } - - // Initialize composite reference binding names - for (Reference reference : composite.getReferences()) { - constructBindingNames(reference, monitor); - } - - // Initialize component service and reference binding names - for (Component component : composite.getComponents()) { - - // Initialize component service callback binding names - for (ComponentService service : component.getServices()) { - constructBindingNames(service, monitor); - } - - // Initialize component reference binding names - for (ComponentReference reference : component.getReferences()) { - // Initialize binding names - constructBindingNames(reference, monitor); - } - } - } - - /** - * If a binding name is not provided by the user, construct it based on the service - * or reference name - * - * @param contract the service or reference - */ - private void constructBindingNames(Contract contract, Monitor monitor) { - List<Binding> bindings = contract.getBindings(); - Map<String, Binding> bindingMap = new HashMap<String, Binding>(); - for (Binding binding : bindings) { - // set the default binding name if one is required - // if there is no name on the binding then set it to the service or reference name - if (binding.getName() == null) { - binding.setName(contract.getName()); - } - Binding existed = bindingMap.put(binding.getName(), binding); - // Check that multiple bindings do not have the same name - if (existed != null && existed != binding) { - if (contract instanceof Service) { - Monitor.error(monitor, this, "assembly-validation-messages", "MultipleBindingsForService", contract - .getName(), binding.getName()); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForReference", - contract.getName(), - binding.getName()); - } - } - } - - if (contract.getCallback() != null) { - bindings = contract.getCallback().getBindings(); - bindingMap.clear(); - for (Binding binding : bindings) { - // set the default binding name if one is required - // if there is no name on the binding then set it to the service or reference name - if (binding.getName() == null) { - binding.setName(contract.getName()); - } - Binding existed = bindingMap.put(binding.getName(), binding); - // Check that multiple bindings do not have the same name - if (existed != null && existed != binding) { - if (contract instanceof Service) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForServiceCallback", - contract.getName(), - binding.getName()); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForReferenceCallback", - contract.getName(), - binding.getName()); - } - } - } - } - } - - /** - * URI construction for composite bindings based on Assembly Specification section 1.7.2, This method - * assumes that the component URI part of the binding URI is formed from the part to the - * composite in question and just calls the generic constructBindingURI method with this - * information - * - * @param parentComponentURI - * @param composite - * @param service - * @param binding - * @param defaultBindings - */ - private void constructBindingURI(String parentComponentURI, - Composite composite, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - // This is a composite service so there is no component to provide a component URI - // The path to this composite (through nested composites) is used. - constructBindingURI(parentComponentURI, service, binding, defaultBindings, monitor); - } - - /** - * URI construction for component bindings based on Assembly Specification section 1.7.2. This method - * calculates the component URI part based on component information before calling the generic - * constructBindingURI method - * - * @param component the component that holds the service - * @param service the service that holds the binding - * @param binding the binding for which the URI is being constructed - * @param defaultBindings the list of default binding configurations - */ - private void constructBindingURI(Component component, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - constructBindingURI(component.getURI(), service, binding, defaultBindings, monitor); - } - - /** - * Generic URI construction for bindings based on Assembly Specification section 1.7.2 - * - * @param componentURIString the string version of the URI part that comes from the component name - * @param service the service in question - * @param binding the binding for which the URI is being constructed - * @param includeBindingName when set true the serviceBindingURI part should be used - * @param defaultBindings the list of default binding configurations - * @throws CompositeBuilderException - */ - private void constructBindingURI(String componentURIString, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - try { - - boolean includeBindingName = !service.getName().equals(binding.getName()); - - // calculate the service binding URI - URI bindingURI; - if (binding.getURI() != null) { - bindingURI = new URI(binding.getURI()); - - // if the user has provided an absolute binding URI then use it - if (bindingURI.isAbsolute()) { - binding.setURI(bindingURI.toString()); - return; - } - } else { - bindingURI = null; - } - - String serviceName = service.getName(); - // Get the service binding name - String bindingName; - if (binding.getName() != null) { - bindingName = binding.getName(); - } else { - bindingName = serviceName; - } - - // calculate the component URI - URI componentURI; - if (componentURIString != null) { - componentURI = new URI(addSlashToPath(componentURIString)); - } else { - componentURI = null; - } - - // if the user has provided an absolute component URI then use it - if (componentURI != null && componentURI.isAbsolute()) { - binding.setURI(constructBindingURI(null, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - return; - } - - // calculate the base URI - URI baseURI = null; - if (defaultBindings != null) { - List<String> uris = defaultBindings.get(binding.getType()); - if (uris != null && uris.size() > 0) { - baseURI = new URI(addSlashToPath(uris.get(0))); - } - } - - binding.setURI(constructBindingURI(baseURI, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - } catch (URISyntaxException ex) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "URLSyntaxException", - componentURIString, - service.getName(), - binding.getName()); - } - } - - /** - * Use to ensure that URI paths end in "/" as here we want to maintain the - * last path element of an base URI when other URI are resolved against it. This is - * not the default behaviour of URI resolution as defined in RFC 2369 - * - * @param path the path string to which the "/" is to be added - * @return the resulting path with a "/" added if it not already there - */ - private static String addSlashToPath(String path) { - if (path.endsWith("/") || path.endsWith("#")) { - return path; - } else { - return path + "/"; - } - } - - /** - * Concatenate binding URI parts together based on Assembly Specification section 1.7.2 - * - * @param baseURI the base of the binding URI - * @param componentURI the middle part of the binding URI derived from the component name - * @param bindingURI the end part of the binding URI - * @param includeBindingName when set true the binding name part should be used - * @param bindingName the binding name - * @return the resulting URI as a string - */ - private static String constructBindingURI(URI baseURI, - URI componentURI, - URI bindingURI, - String serviceName, - boolean includeBindingName, - String bindingName) { - String name = includeBindingName ? serviceName + "/" + bindingName : serviceName; - String uriString; - - if (baseURI == null) { - if (componentURI == null) { - if (bindingURI != null) { - uriString = name + "/" + bindingURI.toString(); - } else { - uriString = name; - } - } else { - if (bindingURI != null) { - if (bindingURI.toString().startsWith("/")) { - uriString = componentURI.resolve(bindingURI).toString(); - } else { - uriString = componentURI.resolve(name + "/" + bindingURI).toString(); - } - } else { - uriString = componentURI.resolve(name).toString(); - } - } - } else { - if (componentURI == null) { - if (bindingURI != null) { - uriString = basedURI(baseURI, bindingURI).toString(); - } else { - uriString = basedURI(baseURI, URI.create(name)).toString(); - } - } else { - if (bindingURI != null) { - uriString = basedURI(baseURI, componentURI.resolve(bindingURI)).toString(); - } else { - uriString = basedURI(baseURI, componentURI.resolve(name)).toString(); - } - } - } - - // tidy up by removing any trailing "/" - if (uriString.endsWith("/")) { - uriString = uriString.substring(0, uriString.length() - 1); - } - - URI uri = URI.create(uriString); - if (!uri.isAbsolute()) { - uri = URI.create("/").resolve(uri); - } - return uri.toString(); - } - - /** - * Combine a URI with a base URI. - * - * @param baseURI - * @param uri - * @return - */ - private static URI basedURI(URI baseURI, URI uri) { - if (uri.getScheme() != null) { - return uri; - } - String str = uri.toString(); - if (str.startsWith("/")) { - str = str.substring(1); - } - return URI.create(baseURI.toString() + str).normalize(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java deleted file mode 100644 index 6197764f4c..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java +++ /dev/null @@ -1,1004 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.io.InputStream; -import java.net.URI; -import java.net.URL; -import java.net.URLConnection; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.sax.SAXSource; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentBuilderImpl { - private static final Logger logger = Logger.getLogger(ComponentBuilderImpl.class.getName()); - - protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - protected static final String BINDING_SCA = "binding.sca"; - protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); - - private CompositeComponentTypeBuilderImpl componentTypeBuilder; - private Monitor monitor; - private AssemblyFactory assemblyFactory; - private SCABindingFactory scaBindingFactory; - private DocumentBuilderFactory documentBuilderFactory; - protected TransformerFactory transformerFactory; - private InterfaceContractMapper interfaceContractMapper; - private BuilderExtensionPoint builders; - - public ComponentBuilderImpl(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); - documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); - transformerFactory = modelFactories.getFactory(TransformerFactory.class); - - interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - - builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public void setComponentTypeBuilder(CompositeComponentTypeBuilderImpl componentTypeBuilder) { - this.componentTypeBuilder = componentTypeBuilder; - } - - /** - * Configure the component based on its component type using OASIS rules - * - * @Param parentComposite the composite that contains the component being configured. Required for property processing - * @param component the component to be configured - */ - public void configureComponentFromComponentType(Composite parentComposite, Component component) { - - // do any work we need to do before we calculate the component type - // for this component. Anything that needs to be pushed down the promotion - // hierarchy must be done before we calculate the component type - - // first carry out any implementation specific builder processing - Implementation impl = component.getImplementation(); - if (impl != null) { - ImplementationBuilder builder = builders.getImplementationBuilder(impl.getClass()); - if (builder != null) { - builder.build(component, impl, monitor); - } - } - - // Properties on the composite component type are not affected by the components - // that the composite contains. Instead the child components might source - // composite level property values. Hence we have to calculate whether the component - // type property value should be overridden by this component's property value - // before we go ahead and calculate the component type - configureProperties(parentComposite, component); - - // create the component type for this component - // taking any nested composites into account - createComponentType(component); - - // configure services based on the calculated component type - configureServices(component); - - // configure services based on the calculated component type - configureReferences(component); - } - - /** - * Use the component type builder to build the component type for - * this component. - * - * @param component - */ - private void createComponentType(Component component) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - componentTypeBuilder.createComponentType((Composite)implementation); - } - } - - /** - * Configure this component's services based on the services in its - * component type and the configuration from the composite file - * - * @param component - */ - private void configureServices(Component component) { - - // If the component type has services that are not described in this - // component then create services for this component - addServicesFromComponentType(component); - - // Connect this component's services to the - // services from its component type - connectServicesToComponentType(component); - - // look at each component service in turn and calculate its - // configuration based on OASIS rules - for (ComponentService componentService : component.getServices()) { - Service componentTypeService = componentService.getService(); - - if (componentTypeService == null) { - // raise error? - // can be null in some of the assembly-xml unit tests - continue; - } - - // interface contracts - calculateInterfaceContract(componentService, componentTypeService); - - // bindings - calculateBindings(componentService, componentTypeService); - - // add callback reference model objects - createCallbackReference(component, componentService); - - // intents - done later in CompositePolicyBuilder - discuss with RF - //calculateIntents(componentService, - // componentTypeService); - - // policy sets - done later in CompositePolicyBuilder - discuss with RF - // calculatePolicySets(componentService, - // componentTypeService); - - } - } - - /** - * Configure this component's references based on the references in its - * component type and the configuration from the composite file - * - * @param component - */ - private void configureReferences(Component component) { - - // If the component type has references that are not described in this - // component then create references for this component - addReferencesFromComponentType(component); - - // Connect this component's references to the - // references from its component type - connectReferencesToComponentType(component); - - // look at each component reference in turn and calculate its - // configuration based on OASIS rules - for (ComponentReference componentReference : component.getReferences()) { - Reference componentTypeReference = componentReference.getReference(); - - if (componentTypeReference == null) { - // raise error? - // can be null in some of the assembly-xml unit tests - continue; - } - - // reference multiplicity - reconcileReferenceMultiplicity(component, componentReference, componentTypeReference); - - // interface contracts - calculateInterfaceContract(componentReference, componentTypeReference); - - // bindings - // We don't have to do anything with reference bindings. You've either - // specified one or you haven't - //calculateBindings(componentService, - // componentTypeService); - - // add callback service model objects - createCallbackService(component, componentReference); - - // intents - done later in CompositePolicyBuilder - discuss with RF - //calculateIntents(componentService, - // componentTypeService); - - // policy sets - done later in CompositePolicyBuilder - discuss with RF - // calculatePolicySets(componentService, - // componentTypeService); - - // Propagate autowire setting from the component down the structural - // hierarchy - if (componentReference.getAutowire() == null) { - componentReference.setAutowire(component.getAutowire()); - } - - // Reconcile targets copying then up the promotion hierarchy - if (componentReference.getTargets().isEmpty()) { - componentReference.getTargets().addAll(componentTypeReference.getTargets()); - } - - } - } - - /** - * Configure this component's properties based on the properties in its - * component type and the configuration from the composite file - * - * @param component - */ - private void configureProperties(Composite parentComposite, Component component) { - // If the component type has properties that are not described in this - // component then create properties for this component - addPropertiesFromComponentType(component); - - // Connect this component's properties to the - // properties from its component type - connectReferencesToComponentType(component); - - // Reconcile component properties and their component type properties - for (ComponentProperty componentProperty : component.getProperties()) { - reconcileComponentPropertyWithComponentType(component, componentProperty); - - // configure the property value based on the @source attribute - // At the moment this is done in the parent composite component - // type calculation a - processPropertySourceAttribute(parentComposite, component, componentProperty); - - // configure the property value based on the @file attribute - processPropertyFileAttribute(component, componentProperty); - } - } - - private void addServicesFromComponentType(Component component) { - - // Create a component service for each service - if (component.getImplementation() != null) { - for (Service service : component.getImplementation().getServices()) { - ComponentService componentService = (ComponentService)component.getService(service.getName()); - - // if the component doesn't have a service with the same name as the - // component type service then create one - if (componentService == null) { - componentService = assemblyFactory.createComponentService(); - componentService.setForCallback(service.isForCallback()); - String name = service.getName(); - componentService.setName(name); - component.getServices().add(componentService); - } - } - } - } - - private void addReferencesFromComponentType(Component component) { - - // Create a component reference for each reference - if (component.getImplementation() != null) { - for (Reference reference : component.getImplementation().getReferences()) { - ComponentReference componentReference = (ComponentReference)component.getReference(reference.getName()); - - // if the component doesn't have a reference with the same name as the - // component type reference then create one - if (componentReference == null) { - componentReference = assemblyFactory.createComponentReference(); - componentReference.setForCallback(reference.isForCallback()); - componentReference.setName(reference.getName()); - componentReference.setReference(reference); - component.getReferences().add(componentReference); - } - } - } - } - - private void addPropertiesFromComponentType(Component component) { - - // Create component property for each property - if (component.getImplementation() != null) { - for (Property property : component.getImplementation().getProperties()) { - ComponentProperty componentProperty = (ComponentProperty)component.getProperty(property.getName()); - - // if the component doesn't have a property with the same name as - // the component type property then create one - if (componentProperty == null) { - componentProperty = assemblyFactory.createComponentProperty(); - componentProperty.setName(property.getName()); - componentProperty.setValue(property.getValue()); - componentProperty.setMany(property.isMany()); - componentProperty.setMustSupply(property.isMustSupply()); - componentProperty.setXSDElement(property.getXSDElement()); - componentProperty.setXSDType(property.getXSDType()); - componentProperty.setProperty(property); - component.getProperties().add(componentProperty); - } - } - } - } - - private void connectServicesToComponentType(Component component) { - - // Connect each component service to the corresponding component type service - for (ComponentService componentService : component.getServices()) { - if (componentService.getService() != null || componentService.isForCallback()) { - continue; - } - - if (component.getImplementation() == null) { - // is null in some of our basic unit tests - continue; - } - - Service service = component.getImplementation().getService(componentService.getName()); - - if (service != null) { - componentService.setService(service); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ServiceNotFoundForComponentService", - component.getName(), - componentService.getName()); - } - } - } - - private void connectReferencesToComponentType(Component component) { - - // Connect each component reference to the corresponding component type reference - for (ComponentReference componentReference : component.getReferences()) { - if (componentReference.getReference() != null || componentReference.isForCallback()) { - continue; - } - - if (component.getImplementation() == null) { - // is null in some of our basic unit tests - continue; - } - - Reference reference = component.getImplementation().getReference(componentReference.getName()); - - if (reference != null) { - componentReference.setReference(reference); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceNotFoundForComponentReference", - component.getName(), - componentReference.getName()); - } - } - } - - private void connectPropertiesToComponentType(Component component) { - // Connect each component property to the corresponding component type property - for (ComponentProperty componentProperty : component.getProperties()) { - Property property = component.getImplementation().getProperty(componentProperty.getName()); - if (property != null) { - componentProperty.setProperty(property); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyNotFound", - component.getName(), - componentProperty.getName()); - } - } - } - - private void reconcileReferenceMultiplicity(Component component, - Reference componentReference, - Reference componentTypeReference) { - if (componentReference.getMultiplicity() != null) { - if (!isValidMultiplicityOverride(componentTypeReference.getMultiplicity(), componentReference - .getMultiplicity())) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleMultiplicity", - component.getName(), - componentReference.getName()); - } - } else { - componentReference.setMultiplicity(componentTypeReference.getMultiplicity()); - } - } - - private void reconcileComponentPropertyWithComponentType(Component component, ComponentProperty componentProperty) { - Property componentTypeProperty = componentProperty.getProperty(); - if (componentTypeProperty != null) { - - // Check that a component property does not override the - // mustSupply attribute - if (!componentTypeProperty.isMustSupply() && componentProperty.isMustSupply()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyMustSupplyIncompatible", - component.getName(), - componentProperty.getName()); - } - - // Default to the mustSupply attribute specified on the property - if (!componentProperty.isMustSupply()) - componentProperty.setMustSupply(componentTypeProperty.isMustSupply()); - - // Default to the value specified on the component type property - if (!isPropertyValueSet(componentProperty)) { - componentProperty.setValue(componentTypeProperty.getValue()); - } - - // Override the property value for the composite - if (component.getImplementation() instanceof Composite) { - componentTypeProperty.setValue(componentProperty.getValue()); - } - - // Check that a value is supplied - if (!isPropertyValueSet(componentProperty) && componentTypeProperty.isMustSupply()) { - Monitor.error(monitor, this, "assembly-validation-messages", "PropertyMustSupplyNull", component - .getName(), componentProperty.getName()); - } - - // Check that a component property does not override the - // many attribute - if (!componentTypeProperty.isMany() && componentProperty.isMany()) { - Monitor.error(monitor, this, "assembly-validation-messages", "PropertyOverrideManyAttribute", component - .getName(), componentProperty.getName()); - } - - // Default to the many attribute defined on the property - componentProperty.setMany(componentTypeProperty.isMany()); - - // Default to the type and element defined on the property - if (componentProperty.getXSDType() == null) { - componentProperty.setXSDType(componentTypeProperty.getXSDType()); - } - if (componentProperty.getXSDElement() == null) { - componentProperty.setXSDElement(componentTypeProperty.getXSDElement()); - } - - // Check that a type or element are specified - if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { - Monitor.error(monitor, this, "assembly-validation-messages", "NoTypeForComponentProperty", component - .getName(), componentProperty.getName()); - } - } - } - - /** - * If the property has a source attribute use this to retrieve the value from a - * property in the parent composite - - * - * @param parentCompoent the composite that contains the component - * @param component - * @param componentProperty - */ - private void processPropertySourceAttribute(Composite parentComposite, - Component component, - ComponentProperty componentProperty) { - String source = componentProperty.getSource(); - - if (source != null) { - // $<name>/... - int index = source.indexOf('/'); - if (index == -1) { - // Tolerating $prop - source = source + "/"; - index = source.length() - 1; - } - if (source.charAt(0) == '$') { - String name = source.substring(1, index); - Property compositeProp = parentComposite.getProperty(name); - if (compositeProp == null) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceNotFound", - source, - componentProperty.getName(), - component.getName()); - } - - Document compositePropDefValues = (Document)compositeProp.getValue(); - - try { - // FIXME: How to deal with namespaces? - Document node = - evaluateXPath(compositePropDefValues, - componentProperty.getSourceXPathExpression(), - documentBuilderFactory); - - if (node != null) { - componentProperty.setValue(node); - } - } catch (Exception ex) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceXpathInvalid", - source, - componentProperty.getName(), - component.getName(), - ex.toString()); - } - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceValueInvalid", - source, - componentProperty.getName(), - component.getName()); - } - } - } - - /** - * If the property has a file attribute use this to retrieve the value from a - * local file - - * - * @param parentCompoent the composite that contains the component - * @param component - */ - private void processPropertyFileAttribute(Component component, ComponentProperty componentProperty) { - String file = componentProperty.getFile(); - if (file != null) { - try { - URI uri = URI.create(file); - // URI resolution for relative URIs is done when the composite is resolved. - URL url = uri.toURL(); - URLConnection connection = url.openConnection(); - connection.setUseCaches(false); - InputStream is = null; - try { - is = connection.getInputStream(); - - Source streamSource = new SAXSource(new InputSource(is)); - DOMResult result = new DOMResult(); - javax.xml.transform.Transformer transformer = transformerFactory.newTransformer(); - transformer.transform(streamSource, result); - - Document document = (Document)result.getNode(); - - // TUSCANY-2377, Add a fake value element so it's consistent with - // the DOM tree loaded from inside SCDL - Element root = document.createElementNS(null, "value"); - root.appendChild(document.getDocumentElement()); - document.appendChild(root); - componentProperty.setValue(document); - } finally { - if (is != null) { - is.close(); - } - } - } catch (Exception ex) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyFileValueInvalid", - file, - componentProperty.getName(), - component.getName(), - ex.toString()); - } - } - - } - - /** - * Evaluate an XPath expression against a Property value, returning the result as a Property value - * @param node - the document root element of a Property value - * @param expression - the XPath expression - * @param documentBuilderFactory - a DOM document builder factory - * @return - a DOM Document representing the result of the evaluation as a Property value - * @throws XPathExpressionException - * @throws ParserConfigurationException - */ - private Document evaluateXPath(Document node, - XPathExpression expression, - DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException, - ParserConfigurationException { - - // The document element is a <sca:property/> element - Node property = node.getDocumentElement(); - // The first child of the <property/> element is a <value/> element - Node value = property.getFirstChild(); - - Node result = (Node)expression.evaluate(value, XPathConstants.NODE); - if (result == null) { - return null; - } - - if (result instanceof Document) { - return (Document)result; - } else { - Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); - Element newProperty = document.createElementNS(SCA11_NS, "property"); - - if (result.getNodeType() == Node.ELEMENT_NODE) { - // If the result is a <value/> element, use it directly in the result - newProperty.appendChild(document.importNode(result, true)); - } else { - // If the result is not a <value/> element, create a <value/> element to contain the result - Element newValue = document.createElementNS(SCA11_NS, "value"); - newValue.appendChild(document.importNode(result, true)); - newProperty.appendChild(newValue); - } // end if - document.appendChild(newProperty); - - return document; - } - } - - /** - * Create a callback reference for a component service - * - * @param component - * @param service - */ - private void createCallbackReference(Component component, ComponentService service) { - - // if the service has a callback interface create a reference - // to represent the callback - if (service.getInterfaceContract() != null && // can be null in unit tests - service.getInterfaceContract().getCallbackInterface() != null) { - - ComponentReference callbackReference = assemblyFactory.createComponentReference(); - callbackReference.setForCallback(true); - callbackReference.setName(service.getName()); - try { - InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone(); - contract.setInterface(contract.getCallbackInterface()); - contract.setCallbackInterface(null); - callbackReference.setInterfaceContract(contract); - } catch (CloneNotSupportedException e) { - // will not happen - } - Service implService = service.getService(); - if (implService != null) { - - // If the implementation service is a CompositeService, ensure that the Reference that is - // created is a CompositeReference, otherwise create a Reference - Reference implReference; - if (implService instanceof CompositeService) { - CompositeReference implCompReference = assemblyFactory.createCompositeReference(); - // Set the promoted component from the promoted component of the composite service - implCompReference.getPromotedComponents().add(((CompositeService)implService) - .getPromotedComponent()); - // Set the promoted service - ComponentReference promotedReference = assemblyFactory.createComponentReference(); - String promotedRefName = - ((CompositeService)implService).getPromotedComponent().getName() + "/" - + ((CompositeService)implService).getPromotedService().getName(); - promotedReference.setName(promotedRefName); - promotedReference.setUnresolved(true); - implCompReference.getPromotedReferences().add(promotedReference); - implReference = implCompReference; - // Add the composite reference to the composite implementation artifact - Implementation implementation = component.getImplementation(); - if (implementation != null && implementation instanceof Composite) { - ((Composite)implementation).getReferences().add(implCompReference); - } - } else { - 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 - } - callbackReference.setReference(implReference); - } - component.getReferences().add(callbackReference); - - // Set the bindings of the callback reference - if (callbackReference.getBindings().isEmpty()) { - // If there are specific callback bindings set in the SCDL service - // callback element then use them - if (service.getCallback() != null && service.getCallback().getBindings().size() > 0) { - callbackReference.getBindings().addAll(service.getCallback().getBindings()); - } else { - // otherwise create a default binding which - // will cause the EPR for this reference to be - // marked as EndpointReference.NOT_CONFIGURED - createSCABinding(callbackReference, null); - - // TODO - should really use the forward binding here but - // awaiting OASIS decision on what's going to - // happen with callbacks - } - } - service.setCallbackReference(callbackReference); - } - } - - /** - * Create a callback service for a component reference - * - * @param component - * @param service - */ - private void createCallbackService(Component component, ComponentReference reference) { - if (reference.getInterfaceContract() != null && // can be null in unit tests - reference.getInterfaceContract().getCallbackInterface() != null) { - ComponentService componentService = assemblyFactory.createComponentService(); - componentService.setForCallback(true); - componentService.setName(reference.getName()); - try { - InterfaceContract contract = (InterfaceContract)reference.getInterfaceContract().clone(); - contract.setInterface(contract.getCallbackInterface()); - contract.setCallbackInterface(null); - componentService.setInterfaceContract(contract); - } catch (CloneNotSupportedException e) { - // will not happen - } - Reference implReference = reference.getReference(); - if (implReference != null) { - // If the implementation reference is a CompositeReference, ensure that the Service that is - // created is a CompositeService, otherwise create a Service - Service implService; - if (implReference instanceof CompositeReference) { - CompositeService implCompService = assemblyFactory.createCompositeService(); - // TODO The reality here is that the composite reference which has the callback COULD promote more than - // one component reference - and there must be a separate composite callback service for each of these component - // references - // Set the promoted component from the promoted component of the composite reference - implCompService.setPromotedComponent(((CompositeReference)implReference).getPromotedComponents() - .get(0)); - implCompService.setForCallback(true); - // Set the promoted service - ComponentService promotedService = assemblyFactory.createComponentService(); - promotedService.setName(((CompositeReference)implReference).getPromotedReferences().get(0) - .getName()); - promotedService.setUnresolved(true); - promotedService.setForCallback(true); - implCompService.setPromotedService(promotedService); - implService = implCompService; - // Add the composite service to the composite implementation artifact - Implementation implementation = component.getImplementation(); - if (implementation != null && implementation instanceof Composite) { - ((Composite)implementation).getServices().add(implCompService); - } // end if - // - } else { - implService = assemblyFactory.createService(); - } // end if - // - implService.setName(implReference.getName()); - try { - InterfaceContract implContract = (InterfaceContract)implReference.getInterfaceContract().clone(); - implContract.setInterface(implContract.getCallbackInterface()); - implContract.setCallbackInterface(null); - implService.setInterfaceContract(implContract); - } catch (CloneNotSupportedException e) { - // will not happen - } - componentService.setService(implService); - } - component.getServices().add(componentService); - - // configure bindings for the callback service - if (componentService.getBindings().isEmpty()) { - if (reference.getCallback() != null && reference.getCallback().getBindings().size() > 0) { - // set bindings of the callback service based on the information provided in - // SCDL reference callback element - componentService.getBindings().addAll(reference.getCallback().getBindings()); - } else if (reference.getBindings().size() > 0) { - // use any bindings explicitly declared on the forward reference - for (Binding binding : reference.getBindings()) { - try { - Binding clonedBinding = (Binding)binding.clone(); - // binding uri will be calculated during runtime build - clonedBinding.setURI(null); - componentService.getBindings().add(clonedBinding); - } catch (CloneNotSupportedException ex) { - - } - } - } else { - // TODO - should use the binding resolved from the service but - // waiting for OASIS to decide what to do about callbacks - // create a default binding - createSCABinding(componentService, null); - } - } - - reference.setCallbackService(componentService); - } - } - - /** - * Create a default SCA binding in the case that no binding - * is specified by the user - * - * @param contract - * @param definitions - */ - protected void createSCABinding(Contract contract, Definitions definitions) { - - SCABinding scaBinding = scaBindingFactory.createSCABinding(); - - if (definitions != null) { - for (ExtensionType attachPointType : definitions.getBindingTypes()) { - if (attachPointType.getType().equals(BINDING_SCA_QNAME)) { - ((PolicySubject)scaBinding).setExtensionType(attachPointType); - } - } - } - - contract.getBindings().add(scaBinding); - contract.setOverridingBindings(false); - } - - /** - * Look to see if any value elements have been set into the property - * A bit involved as the value is stored as a DOM Document - * - * @param property the property to be tested - * @return true is values are present - */ - private boolean isPropertyValueSet(Property property) { - Document value = (Document)property.getValue(); - - if (value == null) { - return false; - } - - if (value.getFirstChild() == null) { - return false; - } - - if (value.getFirstChild().getChildNodes().getLength() == 0) { - return false; - } - - return true; - } - - private boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { - if (definedMul != overridenMul) { - switch (definedMul) { - case ZERO_N: - return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE - || overridenMul == Multiplicity.ONE_N; - case ONE_N: - return overridenMul == Multiplicity.ONE_ONE; - case ZERO_ONE: - return overridenMul == Multiplicity.ONE_ONE; - default: - return false; - } - } else { - return true; - } - } - - /** - * The following methods implement rules that the OASIS specification defined explicitly - * to control how configuration from a component type is inherited by a component - */ - - /** - * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence - * - * @param topContract the top contract - * @param bottomContract the bottom contract - */ - private void calculateInterfaceContract(Contract topContract, Contract bottomContract) { - - // Use the interface contract from the bottom level contract if - // none is specified on the top level contract - InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); - InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract(); - - if (topInterfaceContract == null) { - topContract.setInterfaceContract(bottomInterfaceContract); - } else if (bottomInterfaceContract != null) { - // Check that the top and bottom interface contracts are compatible - boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, bottomInterfaceContract); - if (!isCompatible) { - if (topContract instanceof Reference) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceInterfaceNotSubSet", - topContract.getName()); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ServiceInterfaceNotSubSet", - topContract.getName()); - } - } - } - } - - /** - * OASIS RULE: Bindings from higher in the hierarchy take precedence - * - * @param componentService the top service - * @param componentTypeService the bottom service - */ - private void calculateBindings(Service componentService, Service componentTypeService) { - // forward bindings - if (componentService.getBindings().isEmpty()) { - componentService.getBindings().addAll(componentTypeService.getBindings()); - } - - if (componentService.getBindings().isEmpty()) { - createSCABinding(componentService, null); - } - - // callback bindings - if (componentService.getCallback() == null) { - componentService.setCallback(componentTypeService.getCallback()); - if (componentService.getCallback() == null) { - // Create an empty callback to avoid null check - componentService.setCallback(assemblyFactory.createCallback()); - } - } else if (componentService.getCallback().getBindings().isEmpty() && componentTypeService.getCallback() != null) { - componentService.getCallback().getBindings().addAll(componentTypeService.getCallback().getBindings()); - } - - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java deleted file mode 100644 index 02a6fb8037..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.net.URI; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the configuration of components. - * - * @version $Rev$ $Date$ - */ -public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - - public ComponentConfigurationBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentConfigurationBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureComponents(composite, definitions, monitor); - return composite; - } - - /** - * Configure components in the composite. - * - * @param composite - * @param monitor - */ - protected void configureComponents(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureComponents(composite, null, definitions, monitor); - configureSourcedProperties(composite, null); - } - - /** - * Configure components in the composite. - * - * @param composite - * @param uri - * @param problems - */ - private void configureComponents(Composite composite, String uri, Definitions definitions, Monitor monitor) { - String parentURI = uri; - - monitor.pushContext("Composite: " + composite.getName().toString()); - - try { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - - // Initialize component URI - String componentURI; - if (parentURI == null) { - componentURI = component.getName(); - } else { - componentURI = URI.create(parentURI + '/').resolve(component.getName()).toString(); - } - component.setURI(componentURI); - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - // Process nested composite - configureComponents((Composite)implementation, componentURI, definitions, monitor); - } - } // end for - - // Initialize service bindings - List<Service> compositeServices = composite.getServices(); - for (Service service : compositeServices) { - // Set default binding names - - // Create default SCA binding - attachSCABinding(service, definitions); - } - - // Initialize reference bindings - for (Reference reference : composite.getReferences()) { - // Create default SCA binding - attachSCABinding(reference, definitions); - } - - // Initialize all component services and references - Map<String, Component> components = new HashMap<String, Component>(); - for (Component component : composite.getComponents()) { - - monitor.pushContext("Component: " + component.getName()); - - try { - // Index all components and check for duplicates - if (components.containsKey(component.getName())) { - error(monitor, "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()); - } - - Implementation impl = component.getImplementation(); - if (impl != null) { - ImplementationBuilder builder = builders.getImplementationBuilder(impl.getClass()); - if (builder != null) { - builder.build(component, impl, monitor); - } - } - - // Index implementation 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, - monitor); - - // 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, - monitor); - - // 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, monitor); - reconcileReferences(component, references, componentReferences, monitor); - reconcileProperties(component, properties, componentProperties, monitor); - - // 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); - - // Initialize service bindings - for (ComponentService componentService : component.getServices()) { - - // Create default SCA binding - attachSCABinding(componentService, definitions); - } - - // Initialize reference bindings - for (ComponentReference componentReference : component.getReferences()) { - - // Create default SCA binding - attachSCABinding(componentReference, definitions); - } - } finally { - monitor.popContext(); - } - } - - } finally { - monitor.popContext(); - } // end try - } // end method - - /** - * For all the references with callbacks, create a corresponding callback - * service. - * - * @param component - */ - private void configureCallbackServices(Component component, Map<String, ComponentService> componentServices) { - for (ComponentReference reference : component.getReferences()) { - if (reference.getInterfaceContract() != null && // can be null in - // unit tests - reference.getInterfaceContract().getCallbackInterface() != null) { - ComponentService service = componentServices.get(reference.getName()); - if (service == null) { - service = createCallbackService(component, reference); - } - if (reference.getCallback() != null) { - if (service.getBindings().isEmpty()) { - service.getBindings().addAll(reference.getCallback().getBindings()); - } - } - reference.setCallbackService(service); - } - } - } - - /** - * Create a callback service for a component reference - * - * @param component - * @param reference - */ - private ComponentService createCallbackService(Component component, ComponentReference reference) { - ComponentService componentService = assemblyFactory.createComponentService(); - componentService.setForCallback(true); - componentService.setName(reference.getName()); - try { - InterfaceContract contract = (InterfaceContract)reference.getInterfaceContract().clone(); - contract.setInterface(contract.getCallbackInterface()); - contract.setCallbackInterface(null); - componentService.setInterfaceContract(contract); - } catch (CloneNotSupportedException e) { - // will not happen - } - Reference implReference = reference.getReference(); - if (implReference != null) { - // If the implementation reference is a CompositeReference, ensure that the Service that is - // created is a CompositeService, otherwise create a Service - Service implService; - if (implReference instanceof CompositeReference) { - CompositeService implCompService = assemblyFactory.createCompositeService(); - // TODO The reality here is that the composite reference which has the callback COULD promote more than - // one component reference - and there must be a separate composite callback service for each of these component - // references - // Set the promoted component from the promoted component of the composite reference - implCompService - .setPromotedComponent(((CompositeReference)implReference).getPromotedComponents().get(0)); - implCompService.setForCallback(true); - // Set the promoted service - ComponentService promotedService = assemblyFactory.createComponentService(); - promotedService.setName(((CompositeReference)implReference).getPromotedReferences().get(0).getName()); - promotedService.setUnresolved(true); - promotedService.setForCallback(true); - implCompService.setPromotedService(promotedService); - implService = implCompService; - // Add the composite service to the composite implementation artifact - Implementation implementation = component.getImplementation(); - if (implementation != null && implementation instanceof Composite) { - ((Composite)implementation).getServices().add(implCompService); - } // end if - // - } else { - implService = assemblyFactory.createService(); - } // end if - // - implService.setName(implReference.getName()); - try { - InterfaceContract implContract = (InterfaceContract)implReference.getInterfaceContract().clone(); - implContract.setInterface(implContract.getCallbackInterface()); - implContract.setCallbackInterface(null); - implService.setInterfaceContract(implContract); - } catch (CloneNotSupportedException e) { - // will not happen - } - componentService.setService(implService); - } - component.getServices().add(componentService); - return componentService; - } - - /** - * For all the services with callbacks, create a corresponding callback reference. - * - * @param component - * @param componentReferences - */ - private void configureCallbackReferences(Component component, 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); - } // end if - // Set the bindings of the callback reference - if (reference.getBindings().isEmpty()) { - // If there are specific callback bindings set, use them - if (service.getCallback() != null) { - reference.getBindings().addAll(service.getCallback().getBindings()); - } else { - // otherwise use the bindings on the forward service - reference.getBindings().addAll(service.getBindings()); - } // end if - } // end if - service.setCallbackReference(reference); - } // end if - } // end for - } // end method configureCallbackReferences - - /** - * Create a callback reference for a component service - * - * @param component - * @param service - */ - private ComponentReference createCallbackReference(Component component, ComponentService service) { - ComponentReference componentReference = assemblyFactory.createComponentReference(); - componentReference.setForCallback(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) { - - // If the implementation service is a CompositeService, ensure that the Reference that is - // created is a CompositeReference, otherwise create a Reference - Reference implReference; - if (implService instanceof CompositeService) { - CompositeReference implCompReference = assemblyFactory.createCompositeReference(); - // Set the promoted component from the promoted component of the composite service - implCompReference.getPromotedComponents().add(((CompositeService)implService).getPromotedComponent()); - // Set the promoted service - ComponentReference promotedReference = assemblyFactory.createComponentReference(); - String promotedRefName = - ((CompositeService)implService).getPromotedComponent().getName() + "/" - + ((CompositeService)implService).getPromotedService().getName(); - promotedReference.setName(promotedRefName); - promotedReference.setUnresolved(true); - implCompReference.getPromotedReferences().add(promotedReference); - implReference = implCompReference; - // Add the composite reference to the composite implementation artifact - Implementation implementation = component.getImplementation(); - if (implementation != null && implementation instanceof Composite) { - ((Composite)implementation).getReferences().add(implCompReference); - } // end if - } else { - implReference = assemblyFactory.createReference(); - } // end if - // - - 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; - } - - /** - * @param composite - */ - private void configureSourcedProperties(Composite composite, List<ComponentProperty> propertySettings) { - // Resolve properties - Map<String, Property> compositeProperties = new HashMap<String, Property>(); - ComponentProperty componentProperty = null; - for (Property p : composite.getProperties()) { - componentProperty = getComponentPropertyByName(p.getName(), propertySettings); - if (componentProperty != null) { - compositeProperties.put(p.getName(), componentProperty); - } else { - compositeProperties.put(p.getName(), p); - } - } - - for (Component component : composite.getComponents()) { - try { - PropertyConfigurationUtil.sourceComponentProperties(compositeProperties, - component, - documentBuilderFactory, - transformerFactory); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Implementation impl = component.getImplementation(); - if (impl instanceof Composite) { - configureSourcedProperties((Composite)impl, component.getProperties()); - } - } - } - - private ComponentProperty getComponentPropertyByName(String propertyName, List<ComponentProperty> properties) { - if (properties != null) { - for (ComponentProperty aProperty : properties) { - if (aProperty.getName().equals(propertyName)) { - return aProperty; - } - } - } - return null; - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java deleted file mode 100644 index ae0bcaac69..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.builder.BindingBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that performs any additional building steps that - * component reference bindings may need. Used for WSDL generation. - * - * @version $Rev$ $Date$ - */ -public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { - - private BuilderExtensionPoint builders; - - public ComponentReferenceBindingBuilderImpl(ExtensionPointRegistry registry) { - this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - buildReferenceBindings(composite, monitor); - return composite; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceBindingBuilder"; - } - - private void buildReferenceBindings(Composite composite, Monitor monitor) { - - // find all the component reference bindings (starting at top level) - for (Component component : composite.getComponents()) { - for (ComponentReference componentReference : component.getReferences()) { - for (Binding binding : componentReference.getBindings()) { - BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); - if (builder != null) { - builder.build(component, componentReference, binding, monitor); - } - } - } - } - - // build bindings recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - buildReferenceBindings((Composite)implementation, monitor); - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java deleted file mode 100644 index 544e8ca8c6..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java +++ /dev/null @@ -1,1209 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicySet; - -/** - * A composite builder that creates endpoint reference models. - * - * @version $Rev$ $Date$ - */ -public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - - Monitor monitor; - // Testing - //boolean useNew = true; - boolean useNew = false; - - public ComponentReferenceEndpointReferenceBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceEndpointReferenceBuilder"; - } - - /** - * Create endpoint references for all component references. - * - * @param composite - */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - this.monitor = monitor; - - // process component services - processComponentReferences(composite); - return composite; - } - - private void processComponentReferences(Composite composite) { - - monitor.pushContext("Composite: " + composite.getName().toString()); - try { - // index all of the components in the composite - Map<String, Component> components = new HashMap<String, Component>(); - indexComponents(composite, components); - - // index all of the services in the composite - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - indexServices(composite, componentServices); - - // create endpoint references for each component's references - for (Component component : composite.getComponents()) { - monitor.pushContext("Component: " + component.getName()); - - try { - if (useNew) { - for (ComponentReference reference : component.getReferences()) { - createReferenceEndpointReferences2(composite, - component, - reference, - components, - componentServices); - } // end for - } - - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processComponentReferences((Composite)implementation); - } - - // create endpoint references to represent the component reference - for (ComponentReference reference : component.getReferences()) { - - if (!useNew) { - createReferenceEndpointReferences(composite, - component, - reference, - components, - componentServices); - } // end if - - // fix up links between endpoints and endpoint references that represent callbacks - for (ComponentService service : component.getServices()) { - if ((service.getInterfaceContract() != null) && (service.getInterfaceContract() - .getCallbackInterface() != null)) { - if (reference.getName().equals(service.getName())) { - for (Endpoint endpoint : service.getEndpoints()) { - endpoint.getCallbackEndpointReferences().addAll(reference - .getEndpointReferences()); - } - break; - } // end if - } // end if - } // end for - } // end for - - // Validate that references are wired or promoted, according - // to their multiplicity - validateReferenceMultiplicity(composite, component); - - } finally { - monitor.popContext(); - } - } // end for - - } finally { - monitor.popContext(); - } - - } // end method processCompoenntReferences - - private void createReferenceEndpointReferences(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - - monitor.pushContext("Reference: " + reference.getName()); - - // Get reference targets - List<ComponentService> refTargets = getReferenceTargets(reference); - if (reference.getAutowire() == Boolean.TRUE && reference.getTargets().isEmpty()) { - - // Find suitable targets in the current composite for an - // autowired reference - Multiplicity multiplicity = reference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - - // Tuscany specific selection of the first autowire reference - // when there are more than one (ASM_60025) - if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && (reference - .getEndpointReferences().size() != 0)) { - break; - } - - // Prevent autowire connecting to self - if (targetComponent == component) - continue; - - for (ComponentService targetComponentService : targetComponent.getServices()) { - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - - // Stop with the first match for 0..1 and 1..1 references - if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { - break; - } // end if - } // end if - } // end for - } // end for - - if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { - if (reference.getEndpointReferences().size() == 0) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "NoComponentReferenceTarget", - reference.getName()); - } - } - - setSingleAutoWireTarget(reference); - - } else if (!refTargets.isEmpty()) { - // Check that the component reference does not mix the use of endpoint references - // specified via the target attribute with the presence of binding elements - if (bindingsIdentifyTargets(reference)) { - error(monitor, "ReferenceEndPointMixWithTarget", composite, composite.getName().toString(), component - .getName(), reference.getName()); - } - - // Resolve targets specified on the component reference - for (ComponentService target : refTargets) { - - String targetName = getComponentServiceName(target.getName()); - String bindingName = getBindingName(target.getName()); - ComponentService targetComponentService = componentServices.get(targetName); - - Component targetComponent = getComponentFromTargetName(components, targetName); - - if (targetComponentService != null) { - // Check that target component service provides a superset of the component reference interface - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - - if (bindingName != null) { - // the user has selected a binding as part of the target name - Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()) { - if (tmp.getName().equals(bindingName)) { - targetBinding = tmp; - continue; - } - } - - if (targetBinding != null) { - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, - targetComponentService, - targetBinding, - true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - // relying on the registry here to resolve the real endpoint - reference.getEndpointReferences().add(endpointRef); - - } else { - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - warning(monitor, "ComponentReferenceTargetNotFound", composite, composite.getName() - .toString(), targetName); - } - - } else { - // the user hasn't selected a binding as part of the target name - - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef - .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - } - } else { - error(monitor, - "ReferenceIncompatibleInterface", - composite, - composite.getName().toString(), - component.getName() + "." + reference.getName(), - targetName); - } - } else { - // add an unresolved endpoint reference with an unresolved endpoint to go with it - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - warning(monitor, - "ComponentReferenceTargetNotFound", - composite, - composite.getName().toString(), - targetName); - } // end if - } // end for - } // end if - - // if no endpoints have found so far the bindings hold the targets. - if (reference.getEndpointReferences().isEmpty()) { - for (Binding binding : reference.getBindings()) { - - String uri = binding.getURI(); - - // user hasn't put a uri on the binding so it's not a target name and the assumption is that - // the target is established via configuration of the binding element itself - if (uri == null) { - // Regular forward references are UNWIRED with no endpoint if they have an SCABinding with NO targets - // and NO URI set - but Callbacks with an SCABinding are wired and need an endpoint - if (!reference.isForCallback() && (binding instanceof SCABinding)) - continue; - - // create endpoint reference for manually configured bindings with a resolved endpoint to - // signify that this reference is pointing at some unwired endpoint - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - if (binding instanceof SCABinding) { - // Assume that the system needs to resolve this binding later as - // it's the SCA binding - endpointRef.setTargetEndpoint(createEndpoint(true)); - endpointRef.setStatus(EndpointReference.NOT_CONFIGURED); - } else { - // The user has configured a binding so assume they know what - // they are doing and mark in as already resolved. - endpointRef.setTargetEndpoint(createEndpoint(false)); - endpointRef.setStatus(EndpointReference.RESOLVED_BINDING); - } - endpointRef.setRemote(true); - reference.getEndpointReferences().add(endpointRef); - continue; - } // end if - - // user might have put a local target name in the uri - see if it refers to a target we know about - // - if it does the reference binding will be matched with a service binding - // - if it doesn't it is assumed to be an external reference - if (uri.startsWith("/")) { - uri = uri.substring(1); - } - - String targetName = getComponentServiceName(uri); - String bindingName = getBindingName(uri); - - // Resolve the target component and service - ComponentService targetComponentService = componentServices.get(targetName); - Component targetComponent = getComponentFromTargetName(components, targetName); - - // If the binding URI matches a component in the composite, configure an endpoint reference with - // this component as the target. - // If not, the binding URI is assumed to reference an external service - if (targetComponentService != null) { - - // Check that the target component service provides - // a superset of the component reference interface - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null) { - // the user has selected a binding as part of the target name - Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()) { - if (tmp.getName().equals(bindingName)) { - targetBinding = tmp; - continue; - } - } - - if (targetBinding != null) { - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, - targetComponentService, - targetBinding, - true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - // relying on the registry here to resolve the real endpoint - reference.getEndpointReferences().add(endpointRef); - - } else { - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - warning(monitor, "ComponentReferenceTargetNotFound", composite, composite.getName() - .toString(), targetName); - } - - } else { - // create endpoint reference with dummy endpoint which will be replaced when policies - // are matched and bindings are configured later - EndpointReference endpointRef = - createEndpointRef(component, reference, binding, null, false); - endpointRef - .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - } - } else { - warning(monitor, - "ReferenceIncompatibleInterface", - composite, - composite.getName().toString(), - reference.getName(), - uri); - } - } else { - // create endpoint reference for manually configured bindings with resolved endpoint - // to signify that this reference is pointing at some unwired endpoint. The endpoint - // is given the configured binding as a representation of the endpoint configuration. - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - Endpoint endpoint = createEndpoint(false); - endpoint.setBinding(binding); - endpointRef.setTargetEndpoint(endpoint); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.RESOLVED_BINDING); - reference.getEndpointReferences().add(endpointRef); - } // end if - } - } - - monitor.popContext(); - - } // end method - - private void validateReferenceMultiplicity(Composite composite, Component component) { - for (ComponentReference componentReference : component.getReferences()) { - if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), - componentReference.getEndpointReferences())) { - if (componentReference.getEndpointReferences().isEmpty()) { - - // No error if the reference is promoted out of the current composite - boolean promoted = false; - for (Reference reference : composite.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - if (compositeReference.getPromotedReferences().contains(componentReference)) { - promoted = true; - break; - } - } - if (!promoted && !componentReference.isForCallback() && !componentReference.isWiredByImpl()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceWithoutTargets", - composite.getName().toString(), - componentReference.getName()); - } - } else { - // no error if reference is autowire and more targets - // than multiplicity have been found - if (componentReference.getAutowire() == Boolean.TRUE) { - break; - } - - // TUSCANY-3132 first example of updated error handling - Monitor.error(monitor, - this, - "assembly-validation-messages", - "TooManyReferenceTargets", - componentReference.getName()); - } - } - } - - } - - /** - * Create Endpoint References for a component reference inside a given composite - * @param composite - the composite - * @param component - the component - * @param reference - the component reference - * @param components - a map of the components in the composite - * @param componentServices - a map of the component services in the composite - */ - private void createReferenceEndpointReferences2(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - // Find all the leafmost component references related to this component reference - EndpointrefInfo refInfo = gatherEndpointrefInfo(component, reference, null); - - List<Endpoint> endpoints = - getReferenceEndpoints(composite, component, reference, components, componentServices); - - Multiplicity multiplicity = reference.getMultiplicity(); - if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { - // If there are no endpoints defined and also no endpoint references already present - // then this reference is unwired, which is an error - the existing endpoint references - // will have been attached to a nested reference when a promoting reference has its endpoint - // references computed - if (endpoints.size() == 0 && !reference.isPromoted() && !reference.isWiredByImpl()) { - warning(monitor, "ReferenceWithoutTargets", reference, composite.getName().toString(), reference - .getName()); - } // end if - } // end if - - // An endpoint reference is created for the combination of each leafmost component reference and - // each discovered endpoint - for (int i = 0; i < refInfo.getRefs().size(); i++) { - Component leafComponent = refInfo.getComponents().get(i); - ComponentReference leafReference = refInfo.getRefs().get(i); - boolean unresolved = false; - - for (Endpoint endpoint : endpoints) { - if (endpoint.isUnresolved() && endpoint.getComponent() == null && endpoint.getService() == null) { - unresolved = true; - } else { - unresolved = false; - } // end if - // Create an EndpointReference pointing at the endpoint - EndpointReference endRef = - createEndpointRef(leafComponent, leafReference, endpoint.getBinding(), endpoint, unresolved); - // Add the EndpointReference to the top level AND the leaf level reference, if not the same!! - if (useNew) { - leafReference.getEndpointReferences().add(endRef); - if (leafReference != reference) { - reference.getEndpointReferences().add(endRef); - } // end if - } // end if - // (Debug) For the moment, print out the results - // disable for the time being - SL - //System.out.println( "Created endpointRef. Component = " + component.getName() + " Reference = " + - // reference.getName() + " LeafComponent = " + endRef.getComponent().getName() + " LeafReference = " + - // endRef.getReference().getName() + " Binding = " + endRef.getBinding() + " target Component = " + - // endpoint.getComponent() + " target Service = " + endpoint.getService() ); - } // end for - } // end for - - } // end method createReferenceEndpointReferences2 - - private List<Endpoint> getReferenceEndpoints(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - // Target services for a component reference are specified in one of a number of ways, in order: - // 1. Component services declared by the @target attribute of the reference - // 2. Service endpoints inside or outside the domain through bindings with configured endpoints - // 3. If @autowire=true is declared, component services within the composite containing the component which - // are compatible with the reference - // 1. takes precedence over 2. - 3. is only used if neither of the other applies - - List<Endpoint> endpoints = new ArrayList<Endpoint>(); - - // Get targets for references that are callbacks... - if (getReferenceCallbackEndpoints(composite, component, reference, components, componentServices, endpoints)) { - - // Get reference targets declared by @target attribute - } else if (getReferenceTargetEndpoints(composite, - component, - reference, - components, - componentServices, - endpoints)) { - - // TODO - need to ensure that <wire/> elements are handled correctly - // Get reference targets identified by configured <binding/> subelements - } else if (getReferenceBindingEndpoints(composite, - component, - reference, - components, - componentServices, - endpoints)) { - - // Get reference targets identified by @autowire - } else { - getReferenceAutowireEndpoints(composite, component, reference, components, componentServices, endpoints); - } // end if - return endpoints; - } // end method getReferenceEndpoints - - /** - * Gets the callback endpoints of a reference that is a callback reference - * @param composite - the composite - * @param component - the component - * @param reference - the reference - * @param components - a mapped list of the components in the composite - * @param componentServices - a mapped list of the componentServices in the composite - * @param endpoints - a list of the endpoints (in/out parameter) - * @return - true if the reference is a callback reference, false otherwise - */ - private boolean getReferenceCallbackEndpoints(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - List<Endpoint> endpoints) { - // Only if this reference is a callback are there any endpoints of this kind - if (reference.isForCallback()) { - // add an unresolved endpoint reference with an unresolved endpoint to go with it - // there will be one of these for each binding on the reference - for (Binding binding : reference.getBindings()) { - Endpoint endpoint = createEndpoint(true); - endpoint.setBinding(binding); - endpoints.add(endpoint); - } // end for - return true; - } else { - return false; - } // end if - - } // end method getReferenceCallbackEndpoints - - /** - * Gets the endpoints for the services identified by the @target attribute of a reference - * @param composite - the composite - * @param component - the component - * @param reference - the component reference - * @param components - a mapped list of the components in the composite - * @param componentServices - a mapped list of the componentServices in the composite - * @param endpoints - a list of the endpoints (in/out parameter) - * @return true if the @target attribute was set, false otherwise - */ - private boolean getReferenceTargetEndpoints(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - List<Endpoint> endpoints) { - - List<ComponentService> refTargets = getReferenceTargets(reference); - if (!refTargets.isEmpty()) { - // Resolve targets specified on the component reference - for (ComponentService target : refTargets) { - - String targetName = target.getName(); - Component targetComponent = getComponentFromTargetName(components, targetName); - ComponentService targetComponentService = componentServices.get(targetName); - - if (targetComponentService != null) { - // Check that target component service provides a superset of the component reference interface - if (InterfaceContractIsCompatible(reference, targetComponentService)) { - // create endpoint reference - with dummy endpoint which will be replaced when policies - // are matched and bindings are configured later - // TODO - Endpoint endpoint = selectTargetEndpoint(reference, targetComponentService); - // SL - Turn off for now - //System.out.println("Selected Endpoint: component=" + endpoint.getComponent().getName() + - // " service=" + endpoint.getService().getName() + - // " binding=" + endpoint.getBinding().toString()); - Endpoint endpoint2 = createEndpoint(targetComponent, targetComponentService, true); - endpoint2.setBinding(endpoint.getBinding()); - endpoints.add(endpoint2); - } else { - warning(monitor, - "ReferenceIncompatibleInterface", - composite, - composite.getName().toString(), - reference.getName(), - targetName); - } - } else { - // add an unresolved endpoint reference with an unresolved endpoint to go with it - endpoints.add(createEndpoint(true)); - warning(monitor, - "ComponentReferenceTargetNotFound", - composite, - composite.getName().toString(), - targetName); - } // end if - } // end for - return true; - } else { - return false; - } // end if - - } // end method getReferenceTargetEndpoints - - /** - * Selects one endpoint of a target service which is compatible with the policy requirements of a reference - * @param reference - the reference (carries policy data with it) - * @param service - the target service - * @return - an endpoint belonging to the service which is compatible with the reference. - * This will in practice select a particular binding on the service if there is more than one endpoint on the - * service. If there are no matches, this method returns null - */ - private Endpoint selectTargetEndpoint(ComponentReference reference, ComponentService service) { - - // Return the first endpoint with a Binding which is compatible with the policy requirements on - // the reference - for (Endpoint endpoint : service.getEndpoints()) { - return endpoint; - } //end for - - return null; - } // end method selectTargetEndpoint - - /** - * Gets the endpoints for the services identified by the <binding/> subelements of a reference - * @param composite - the composite - * @param component - the component - * @param reference - the component reference - * @param components - a mapped list of the components in the composite - * @param componentServices - a mapped list of the componentServices in the composite - * @param endpoints - a list of the endpoints (in/out parameter) - * @return true if the <binding/> subelements identify target services, false otherwise - */ - private boolean getReferenceBindingEndpoints(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - List<Endpoint> endpoints) { - // Get service endpoints declared by <binding/> subelements - if (bindingsIdentifyTargets(reference)) { - for (Binding binding : reference.getBindings()) { - - String uri = binding.getURI(); - - // user hasn't put a uri on the binding so it's not a target name and the assumption is that - // the target is established via configuration of the binding element itself - if (uri == null) { - // Regular forward references are UNWIRED with no endpoint if they have an SCABinding with NO targets - // and NO URI set - but Callbacks with an SCABinding are wired and need an endpoint - if (!reference.isForCallback() && (binding instanceof SCABinding)) - continue; - - // create an unwired endpoint containing the binding - Endpoint endpoint = createEndpoint(false); - endpoint.setBinding(binding); - endpoints.add(endpoint); - continue; - } // end if - - // user might have put a local target name in the uri - see if it refers to a target we know about - // - if it does the reference binding will be matched with a service binding - // - if it doesn't it is assumed to be an external reference - if (uri.startsWith("/")) - uri = uri.substring(1); - - // Resolve the target component and service - ComponentService targetComponentService = componentServices.get(uri); - Component targetComponent = getComponentFromTargetName(components, uri); - - // If the binding URI matches a component in the composite, configure an endpoint reference with - // this component as the target. - // If not, the binding URI is assumed to reference an external service - if (targetComponentService != null) { - // Check that the target component service provides - // a superset of the component reference interface - if (InterfaceContractIsCompatible(reference, targetComponentService)) { - // create dummy endpoint which will be replaced when policies - // are matched and bindings are configured later - endpoints.add(createEndpoint(targetComponent, targetComponentService, true)); - } else { - warning(monitor, - "ReferenceIncompatibleInterface", - composite, - composite.getName().toString(), - reference.getName(), - uri); - } // end if - } else { - // create resolved endpoint to signify that this reference is pointing at some unwired endpoint - endpoints.add(createEndpoint(false)); - } // end if - } // end for - return true; - } else { - return false; - } // end if - - } // end method getReferenceBindingEndpoints - - /** - * Gets the endpoints for the services identified by the @autowire attribute of a reference - * @param composite - the composite - * @param component - the component - * @param reference - the component reference - * @param components - a mapped list of the components in the composite - * @param componentServices - a mapped list of the componentServices in the composite - * @param endpoints - a list of the endpoints (in/out parameter) - * @return true if the @autowire attribute was set, false otherwise - */ - private boolean getReferenceAutowireEndpoints(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - List<Endpoint> endpoints) { - // Get compatible target services if @autowire=true is specified - if (reference.getAutowire() == Boolean.TRUE) { - - Multiplicity multiplicity = reference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - - // Prevent autowire connecting to self - if (targetComponent == component) - continue; - - for (ComponentService targetComponentService : targetComponent.getServices()) { - if (InterfaceContractIsCompatible(reference, targetComponentService)) { - // create endpoint reference - with a dummy endpoint which will be replaced when policies - // are matched and bindings are configured later - endpoints.add(createEndpoint(targetComponent, targetComponentService, true)); - - // Stop with the first match for 0..1 and 1..1 references - if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { - break; - } // end if - } // end if - } // end for - } // end for - return true; - } else { - return false; - } // end if - - } // end method getReferenceAutowireEndpoints - - /** - * Evaluates if the interface contract of a component service is a compatible superset of the interface contract - * of a component reference - * @param reference - the component reference - * @param service - the component service - * @return - true if the interface of the service is a compatible superset of the interface of the reference, false otherwise - */ - private boolean InterfaceContractIsCompatible(ComponentReference reference, ComponentService service) { - if (reference.getInterfaceContract() == null) - return true; - return interfaceContractMapper.isCompatible(reference.getInterfaceContract(), service.getInterfaceContract()); - } // end method InterfaceContractIsCompatible - - /** - * Gather the Endpoint reference information for a component reference - * - gathers information from deeper in the hierarchy for a component which is implemented by a composite - * @param component - the component - * @param reference - the component reference - * @param refInfo - a reference info datastructure where the endpoint reference information is gathered. Can be null, in - * which case this method will allocate and return an instance of refInfo. - * @return - an EndpointrefInfo - the same object as the refInfo parameter, unless that parameter is null in which case - * it is a new object - */ - private EndpointrefInfo gatherEndpointrefInfo(Component component, - ComponentReference reference, - EndpointrefInfo refInfo) { - if (refInfo == null) - refInfo = new EndpointrefInfo(); - // Deal with the cases where there is an error in the configuration - if (reference.isUnresolved()) - return refInfo; - - refInfo.setContract(reference.getInterfaceContract()); - // RULE: If the interface contract is not already set at this level, then it must be - // identical across all the next level elements - otherwise they can be subsets - boolean equalInterfaces = false; - if (refInfo.getContract() == null) - equalInterfaces = true; - - refInfo.addIntents(reference.getRequiredIntents()); - if (reference.getReference() instanceof CompositeReference) { - // It's a composite reference - get hold of the set of promoted references - CompositeReference compRef = (CompositeReference)reference.getReference(); - List<Component> components = compRef.getPromotedComponents(); - List<ComponentReference> componentRefs = compRef.getPromotedReferences(); - // Scan over all promoted references - for (int i = 0; i < componentRefs.size(); i++) { - refInfo.setContractEqual(equalInterfaces); - gatherEndpointrefInfo(components.get(i), componentRefs.get(i), refInfo); - } // end for - } else { - // Otherwise it's a leaf node reference which must be recorded as an endpoint reference - refInfo.addRef(reference); - refInfo.addComponent(component); - } // end if - // RULE: Any PolicySets at this level override PolicySets from lower levels - refInfo.setPolicySets(reference.getPolicySets()); - - return refInfo; - } // end method gatherEndpointrefInfo - - /** - * A class used to gather endpoint reference information for a component reference - * - handles the information in a promotion hierarchy where the component reference is implemented - * by a composite reference. - * @author MikeEdwards - */ - private class EndpointrefInfo { - private List<Component> components = new ArrayList<Component>(); - private List<ComponentReference> refs = new ArrayList<ComponentReference>(); - private InterfaceContract contract = null; - private List<Intent> intents = new ArrayList<Intent>(); - private List<PolicySet> policySets = null; - private boolean contractEqual = false; - - /** - * Sets whether new contracts must be equal to the current contract or not - * @param isEqual - true means that Contracts must be equal to the current contract - false means that Contracts - * can be subsets of the current contract - */ - void setContractEqual(boolean isEqual) { - contractEqual = isEqual; - } - - boolean getContractEqual() { - return contractEqual; - } - - List<PolicySet> getPolicySets() { - return policySets; - } - - void setPolicySets(List<PolicySet> policySets) { - this.policySets = policySets; - } - - List<Component> getComponents() { - return components; - } - - void addComponent(Component component) { - this.components.add(component); - } - - List<ComponentReference> getRefs() { - return refs; - } - - void addRef(ComponentReference ref) { - this.refs.add(ref); - } - - InterfaceContract getContract() { - return contract; - } - - /** - * Set the contract - with checking of the contract if a contract is already set - * @param contract - the contract to set - */ - void setContract(InterfaceContract contract) { - // Add the contract if there is no existing contract set - if (this.contract == null) { - this.contract = contract; - } else { - // RULE: Raise an error if the new contract is not a subset of the existing contract - if (contractEqual) { - // Contracts must be equal - if (!interfaceContractMapper.isEqual(this.contract, contract)) { - warning(monitor, "ReferencePromotionInterfacesNotEqual", this.contract.toString(), contract - .toString()); - } // end if - } else { - // Contract must be subset - if (!interfaceContractMapper.isCompatible(contract, this.contract)) { - warning(monitor, "ReferencePromotionIncompatibleInterface", this.contract.toString(), contract - .toString()); - } // end if - } // end if - } // end if - } - - List<Intent> getIntents() { - return intents; - } - - /** - * Accumulate intents - * @param intents - */ - void addIntents(List<Intent> intents) { - this.intents.addAll(intents); - } - - } // end class EndpointrefInfo - - /** - * Evaluates whether the bindings attached to a reference identify one or more target services. - * @param reference - the reference - * @return true if the bindings identify a target, false otherwise - */ - private boolean bindingsIdentifyTargets(ComponentReference reference) { - for (Binding binding : reference.getBindings()) { - // <binding.sca without a URI does not identify a target - if ((binding instanceof SCABinding) && (binding.getURI() == null)) - continue; - // any other binding implies a target - // TODO Processing for other binding types - return true; - } // end for - return false; - } // end bindingsIdentifyTargets - - /** - * Helper method which obtains a list of targets for a reference - * @param reference - Component reference - * @return - the list of targets, which will be empty if there are no targets - */ - private List<ComponentService> getReferenceTargets(ComponentReference reference) { - List<ComponentService> theTargets = reference.getTargets(); - if (theTargets.isEmpty()) { - // Component reference list of targets is empty, try the implementation reference - if (reference.getReference() != null) { - theTargets = reference.getReference().getTargets(); - } // end if - } // end if - return theTargets; - } // end method getReferenceTargets - - /** - * Target names can take the form - * component/service/binding - * This extracts the component/service part - * - * @param targetName - * @return String the component/service name - */ - private String getComponentServiceName(String targetName) { - String[] parts = targetName.split("/"); - - if (parts.length > 1) { - return parts[0] + "/" + parts[1]; - } else { - return parts[0]; - } - } - - /** - * Target names can take the form - * component/service/binding - * This extracts the binding part and returns - * it. If there is no binding part it returns null - * - * @param targetName - * @return String the binding name or null if there is no binding name - */ - private String getBindingName(String targetName) { - String[] parts = targetName.split("/"); - - if (parts.length == 3) { - return parts[2]; - } else { - return null; - } - } - - /** - * Helper method that finds the Component given a target name - * @param components - * @param targetName - * @return the component - */ - private Component getComponentFromTargetName(Map<String, Component> components, String targetName) { - Component theComponent; - int s = targetName.indexOf('/'); - if (s == -1) { - theComponent = components.get(targetName); - } else { - theComponent = components.get(targetName.substring(0, s)); - } - return theComponent; - } // end method getComponentFromTargetName - - /** - * Helper method to create an Endpoint Reference - * @param component - * @param reference - * @param binding - * @param endpoint - * @param unresolved - * @return the endpoint reference - */ - private EndpointReference createEndpointRef(Component component, - ComponentReference reference, - Binding binding, - Endpoint endpoint, - boolean unresolved) { - EndpointReference endpointRef = createEndpointRef(component, reference, unresolved); - endpointRef.setBinding(binding); - endpointRef.setTargetEndpoint(endpoint); - return endpointRef; - } // end method - - /** - * Helper method to create an Endpoint Reference - * @param component - * @param reference - * @param unresolved - * @return the endpoint reference - */ - private EndpointReference createEndpointRef(Component component, ComponentReference reference, boolean unresolved) { - EndpointReference endpointRef = assemblyFactory.createEndpointReference(); - endpointRef.setComponent(component); - endpointRef.setReference(reference); - endpointRef.setUnresolved(unresolved); - return endpointRef; - } // end method createEndpointRef - - /** - * Helper method to create an endpoint - * @param component - * @param service - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, ComponentService service, boolean unresolved) { - Endpoint endpoint = createEndpoint(unresolved); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an endpoint - * @param component - * @param service - * @param binding - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, ComponentService service, Binding binding, boolean unresolved) { - Endpoint endpoint = createEndpoint(unresolved); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setBinding(binding); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an Endpoint - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(boolean unresolved) { - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an Endpoint - * - * @param component The component that owns the reference - * @param targetName It can be one of the following formats - * <ul> - * <li>componentName - * <li>componentName/serviceName - * <li>componentName/serviceName/bindingName - * </ul> - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, String targetName) { - String[] parts = targetName.split("/"); - if (parts.length < 1 || parts.length > 3) { - throw new IllegalArgumentException("Invalid target URI: " + targetName); - } - - // Find the parent uri - String uri = component.getURI(); - int index = uri.lastIndexOf('/'); - if (index == -1) { - uri = ""; - } else { - uri = uri.substring(0, index); - } - - if (parts.length >= 1) { - // Append the target component name - if (uri.length() == 0) { - uri = parts[0]; - } else { - uri = uri + "/" + parts[0]; - } - } - if (parts.length == 3) { - // <componentURI>#service-binding(serviceName/bindingName) - uri = uri + "#service-binding(" + parts[1] + "/" + parts[2] + ")"; - } else if (parts.length == 2) { - // <componentURI>#service(serviceName) - uri = uri + "#service(" + parts[1] + ")"; - } - - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setUnresolved(true); - endpoint.setURI(uri); - return endpoint; - } // end method createEndpoint - - /** - * ASM_5021: where a <reference/> of a <component/> has @autowire=true - * and where the <reference/> has a <binding/> child element which - * declares a single target service, the reference is wired only to - * the single service identified by the <wire/> element - */ - private void setSingleAutoWireTarget(ComponentReference reference) { - if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null - && reference.getBindings().size() == 1) { - String uri = reference.getBindings().get(0).getURI(); - if (uri != null) { - if (uri.indexOf('/') > -1) { - // TODO: must be a way to avoid this fiddling - int i = uri.indexOf('/'); - String c = uri.substring(0, i); - String s = uri.substring(i + 1); - uri = c + "#service(" + s + ")"; - } - for (EndpointReference er : reference.getEndpointReferences()) { - if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { - reference.getEndpointReferences().clear(); - reference.getEndpointReferences().add(er); - return; - } - } - } - } - } - -} // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java deleted file mode 100644 index 41d90a9d31..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the creation of promoted composite services. - * - * @version $Rev$ $Date$ - */ -public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public ComponentReferencePromotionBuilderImpl(ExtensionPointRegistry registry) { - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = factories.getFactory(AssemblyFactory.class); - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureNestedCompositeReferences(composite, monitor); - return composite; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferencePromotionBuilder"; - } - - /** - * Push down reference configuration into nested composites. - * - * @param composite - * @param problems - */ - private void configureNestedCompositeReferences(Composite composite, Monitor monitor) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - configureNestedCompositeReferences((Composite)implementation, monitor); - } - } - - // Process component references declared on components in this composite - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - for (ComponentReference componentReference : component.getReferences()) { - Reference implReference = componentReference.getReference(); - if (implReference != null && implReference instanceof CompositeReference) { - - // If the component reference is wired, it is a promotion override - if (!componentReference.getEndpointReferences().isEmpty()) { - componentReference.setPromotionOverride(true); - } - - // 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); - if (componentReference.getInterfaceContract() != null && // can be null in unit tests - componentReference.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 (componentReference.getCallback() != null) { - promotedReference.getCallback().getBindings().addAll(componentReference - .getCallback().getBindings()); - } - } - /* TODO - let endpoint references worry about target service - // Wire the promoted reference to the actual non-composite component services - if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) { - // promotedReference.getTargets().clear(); - } - for (ComponentService target : componentReference.getTargets()) { - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - // Find the promoted component service - ComponentService componentService = - ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (componentService != null) { - promotedReference.getTargets().add(componentService); - } - } else { - - // Wire to a non-composite target service - promotedReference.getTargets().add(target); - } - } - */ - } - } - } - } - } else { - /* TODO - let endpoint references worry about target servicep - for (ComponentReference componentReference : component.getReferences()) { - - // Wire the component reference to the actual - // non-composite component services - List<ComponentService> targets = componentReference.getTargets(); - for (int i = 0, n = targets.size(); i < n; i++) { - ComponentService target = targets.get(i); - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - targets.set(i, componentService); - } - } - } - } - */ - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java deleted file mode 100644 index b775e23143..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the creation of promoted composite services. - * - * @version $Rev$ $Date$ - */ -public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - wireCompositeReferences(composite, monitor); - return composite; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferencePromotionWireBuilder"; - } - - /** - * Wire composite references in nested composites. - * - * @param composite - * @param problems - */ - private void wireCompositeReferences(Composite composite, Monitor monitor) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - wireCompositeReferences((Composite)implementation, monitor); - } - } - - // Process component references declared on components in this composite - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - for (ComponentReference componentReference : component.getReferences()) { - Reference implReference = componentReference.getReference(); - if (implReference != null && implReference instanceof CompositeReference) { - - // If the component reference is wired, it is a promotion override - if (!componentReference.getEndpointReferences().isEmpty()) { - componentReference.setPromotionOverride(true); - } - - // 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); - if (componentReference.getInterfaceContract() != null && // can be null in unit tests - componentReference.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 (componentReference.getCallback() != null) { - promotedReference.getCallback().getBindings().addAll(componentReference - .getCallback().getBindings()); - } - } - /* TODO - let endpoint references worry about target service - // Wire the promoted reference to the actual non-composite component services - if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) { - // promotedReference.getTargets().clear(); - } - for (ComponentService target : componentReference.getTargets()) { - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - // Find the promoted component service - ComponentService componentService = - ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (componentService != null) { - promotedReference.getTargets().add(componentService); - } - } else { - - // Wire to a non-composite target service - promotedReference.getTargets().add(target); - } - } - */ - } - } - } - } - } else { - /* TODO - let endpoint references worry about target servicep - for (ComponentReference componentReference : component.getReferences()) { - - // Wire the component reference to the actual - // non-composite component services - List<ComponentService> targets = componentReference.getTargets(); - for (int i = 0, n = targets.size(); i < n; i++) { - ComponentService target = targets.get(i); - if (target.getService() instanceof CompositeService) { - - // Wire to the actual component service - // promoted by a composite service - CompositeService compositeService = (CompositeService)target.getService(); - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - targets.set(i, componentService); - } - } - } - } - */ - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java deleted file mode 100644 index 724240a35a..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Wire; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that wires component references. - * - * @version $Rev$ $Date$ - */ -public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - - public ComponentReferenceWireBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceWireBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - wireComponentReferences(composite, monitor); - return composite; - } - - /** - * Wire component references to component services and connect promoted - * services/references to component services/references inside a composite. - * - * @param composite - */ - protected void wireComponentReferences(Composite composite, Monitor monitor) { - - monitor.pushContext(composite.getName().toString()); - - try { - // Wire nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - wireComponentReferences((Composite)implementation, monitor); - - } - } - - // Index components, services and references - Map<String, Component> components = new HashMap<String, Component>(); - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); - indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - - // Connect component references as described in wires - connectWires(composite, componentServices, componentReferences, monitor); - - // Finally clear the original reference target lists as we now have - // bindings to represent the targets - // for (ComponentReference componentReference : componentReferences.values()) { - // componentReference.getTargets().clear(); - // } - - } finally { - monitor.popContext(); - } - - } - - /** - * Resolve wires and connect the sources to their targets - * - * @param composite - * @param componentServices - * @param componentReferences - * @param problems - */ - private void connectWires(Composite composite, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences, - Monitor monitor) { - - // For each wire, resolve the source reference, the target service, and - // add it to the list of targets of the reference - List<Wire> wires = composite.getWires(); - for (int i = 0, n = wires.size(); i < n; i++) { - Wire wire = wires.get(i); - - ComponentReference resolvedReference; - ComponentService resolvedService; - - // Resolve the source reference - ComponentReference source = wire.getSource(); - if (source != null && source.isUnresolved()) { - resolvedReference = componentReferences.get(source.getName()); - if (resolvedReference != null) { - wire.setSource(resolvedReference); - } else { - warning(monitor, "WireSourceNotFound", composite, source.getName()); - } - } else { - resolvedReference = wire.getSource(); - } - - // Resolve the target service - ComponentService target = wire.getTarget(); - if (target != null && target.isUnresolved()) { - resolvedService = componentServices.get(target.getName()); - if (resolvedService != null) { - wire.setTarget(target); - } else { - warning(monitor, "WireTargetNotFound", composite, source.getName()); - } - } else { - resolvedService = wire.getTarget(); - } - - // Add the target service to the list of targets of the - // reference - if (resolvedReference != null && resolvedService != null) { - // Check that the target component service provides - // a superset of - // the component reference interface - if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper - .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) { - - //resolvedReference.getTargets().add(resolvedService); - if (wire.isReplace()) { - resolvedReference.getTargets().clear(); - } - resolvedReference.getTargets().add(wire.getTarget()); - } else { - warning(monitor, "WireIncompatibleInterface", composite, source.getName(), target.getName()); - } - } - } - - // Clear the list of wires - composite.getWires().clear(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java deleted file mode 100644 index 9616eb024e..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.builder.BindingBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that performs any additional building steps that - * component service bindings may need. Used for WSDL generation. - * - * @version $Rev$ $Date$ - */ -public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { - private BuilderExtensionPoint builders; - - public ComponentServiceBindingBuilderImpl(ExtensionPointRegistry registry) { - this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentServiceBindingBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - buildServiceBindings(composite, monitor); - return composite; - } - - private void buildServiceBindings(Composite composite, Monitor monitor) { - - // build bindings recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - buildServiceBindings((Composite)implementation, monitor); - } - } - - // find all the component service bindings - for (Component component : composite.getComponents()) { - for (ComponentService componentService : component.getServices()) { - for (Binding binding : componentService.getBindings()) { - BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); - if (builder != null) { - builder.build(component, componentService, binding, monitor); - } - } - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java deleted file mode 100644 index 86c60b713d..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; -import java.util.Vector; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicySet; - -/** - * A composite builder that creates endpoint models for component services. - * - * @version $Rev$ $Date$ - */ -public class ComponentServiceEndpointBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - // Testing - //boolean useNew = true; - boolean useNew = false; - - public ComponentServiceEndpointBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceEndpointReferenceBuilder"; - } - - /** - * Create endpoint models for all component services. - * - * @param composite - the top-level composite to build the models for - * @param definitions - * @param monitor - a Monitor for logging errors - */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - // process component services - if (!useNew) { - processComponentServices(composite); - } // end if - processComponentServices2(composite); - return composite; - - } // end method build - - private void processComponentServices(Composite composite) { - - for (Component component : composite.getComponents()) { - - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processComponentServices((Composite)implementation); - } - - // create an endpoint for each component service binding - for (ComponentService service : component.getServices()) { - - /* change to finding the promoted component and service - * when the wire is created as storing them here leads to - * the wrong URI being calculated - Component endpointComponent = component; - ComponentService endpointService = service; - - // TODO - EPR - We maintain all endpoints at the right level now - // but endpoints for promoting services must point down - // to the services they promote. - if (service.getService() instanceof CompositeService) { - CompositeService compositeService = (CompositeService)service.getService(); - endpointService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - endpointComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); - } // end if - */ - - for (Binding binding : service.getBindings()) { - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setBinding(binding); - endpoint.setUnresolved(false); - service.getEndpoints().add(endpoint); - } // end for - } - } - } // end method processComponentServices - - /** - * @param composite - the composite which contains the component services - */ - private void processComponentServices2(Composite composite) { - for (Component component : composite.getComponents()) { - for (ComponentService service : component.getServices()) { - EndpointInfo theInfo = scanComponentService(component, service, null); - - List<Binding> theBindings = theInfo.getBindings(); - // Create an endpoint for each binding which applies to this service - // and copy across the information relating to the endpoint. - for (Binding binding : theBindings) { - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setComponent(theInfo.getComponent()); - endpoint.setService(theInfo.getComponentService()); - endpoint.setBinding(binding); - endpoint.setInterfaceContract(theInfo.getInterfaceContract()); - endpoint.getRequiredIntents().addAll(theInfo.getIntents()); - endpoint.getPolicySets().addAll(theInfo.getPolicySets()); - endpoint.setUnresolved(false); - // Add the endpoint to the component service - if (useNew) { - // Add to top level and leaf level services, if different - service.getEndpoints().add(endpoint); - ComponentService leafService = theInfo.getComponentService(); - if (service != leafService) { - leafService.getEndpoints().add(endpoint); - } // end if - } // end if - // debug - // disabled for the time being - SL - //System.out.println( "Endpoint created for Component = " + component.getName() + " Leaf component = " + - // endpoint.getComponent().getName() + " service = " + - // endpoint.getService().getName() + " binding = " + endpoint.getBinding() ); - } // end for - } // end for - // Handle composites as implementations - if (component.getImplementation() instanceof Composite) { - processComponentServices2((Composite)component.getImplementation()); - } // end if - } // end for - } // end method processComponentServices2 - - /** - * Scan a component service for endpoint information, recursing down to the leafmost promoted service if the component service is - * implemented by a Composite service - * @param component - the component - * @param service - the component service - * @param theInfo - an EndpointInfo object in which the endpoint information is accumulated. If null on entry, a new EndpointInfo object is created - * @return - the EndpointInfo object containing the information about the component service - */ - private EndpointInfo scanComponentService(Component component, ComponentService service, EndpointInfo theInfo) { - if (theInfo == null) { - theInfo = new EndpointInfo(); - } // end if - - theInfo.setBindings(service.getBindings()); - theInfo.setInterfaceContract(service.getInterfaceContract()); - theInfo.setIntents(service.getRequiredIntents()); - theInfo.setPolicySets(service.getPolicySets()); - - Service implService = service.getService(); - if (implService instanceof CompositeService) { - // If it is implemented by a Composite, scan through the promoted service - ComponentService promotedService = ((CompositeService)implService).getPromotedService(); - Component promotedComponent = ((CompositeService)implService).getPromotedComponent(); - if (promotedService != null) { - scanComponentService(promotedComponent, promotedService, theInfo); - } else { - // If its a composite service with no promoted component service, it's an error - } // end if - } else { - // Otherwise the component and service are the ones at this level - theInfo.setComponent(component); - theInfo.setComponentService(service); - } //end if - - return theInfo; - } // end method scanPromotedComponentService - - private class EndpointInfo { - private Component leafComponent = null; - private ComponentService leafComponentService = null; - private List<Binding> bindings = null; - private InterfaceContract contract; - private List<Intent> intents = new Vector<Intent>(); - private List<PolicySet> policySets = null; - - void setComponent(Component component) { - leafComponent = component; - } // end method - - Component getComponent() { - return leafComponent; - } // end method - - void setComponentService(ComponentService service) { - leafComponentService = service; - } // end method - - ComponentService getComponentService() { - return leafComponentService; - } // end method - - void setBindings(List<Binding> theBindings) { - // RULE: Bindings from higher in the hierarchy take precedence - if (bindings == null) { - bindings = theBindings; - } // end if - } // end method - - List<Binding> getBindings() { - return bindings; - } // end method - - void setInterfaceContract(InterfaceContract theInterface) { - // RULE: Interface contract from higher in the hierarchy takes precedence - if (contract == null) { - contract = theInterface; - } // end if - } // end method - - InterfaceContract getInterfaceContract() { - return contract; - } // end method - - List<Intent> getIntents() { - return intents; - } // end method - - void setIntents(List<Intent> intents) { - // RULE: Intents accumulate from all levels in the hierarchy - this.intents.addAll(intents); - } // end method - - List<PolicySet> getPolicySets() { - return policySets; - } // end method - - void setPolicySets(List<PolicySet> policySets) { - // RULE: Policy Sets from higher in the hierarchy override those lower - if (this.policySets == null) { - this.policySets = policySets; - } // end if - } // end method - - } // end class EndpointInfo - -} // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java deleted file mode 100644 index 89e7046c85..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the creation of promoted services. - * - * @version $Rev$ $Date$ - */ -public class ComponentServicePromotionBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public ComponentServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentServicePromotionBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - // Process nested composites recursively - configureNestedCompositeServices(composite); - return composite; - } - - private void configureNestedCompositeServices(Composite composite) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // First process nested composites - configureNestedCompositeServices((Composite)implementation); - - // 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 innermost promoted service - ComponentService promotedService = - ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (promotedService != null) { - Component promotedComponent = - ServiceConfigurationUtil.getPromotedComponent(compositeService); - - // Create a new component service to represent this - // component service on the promoted component - ComponentService newComponentService = assemblyFactory.createComponentService(); - newComponentService.setName("$promoted$" + component.getName() - + "$slash$" - + componentService.getName()); - promotedComponent.getServices().add(newComponentService); - newComponentService.setService(promotedService.getService()); - newComponentService.getBindings().addAll(componentService.getBindings()); - newComponentService.setInterfaceContract(componentService.getInterfaceContract()); - - if (componentService.getInterfaceContract() != null && componentService - .getInterfaceContract().getCallbackInterface() != null) { - newComponentService.setCallback(assemblyFactory.createCallback()); - newComponentService.getCallback().getBindings().addAll(componentService.getCallback() - .getBindings()); - } - - // Change the composite service to now promote the - // newly created component service directly - compositeService.setPromotedComponent(promotedComponent); - compositeService.setPromotedService(newComponentService); - } - } - } - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java deleted file mode 100644 index ccf96835db..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that performs any additional building steps that - * composite service bindings may need. Used for WSDL generation. - * - * TODO - What is this actually used for? I can't find any references in the - * code base - * - * @version $Rev$ $Date$ - */ -public class CompositeBindingConfigurationBuilderImpl extends CompositeBindingURIBuilderImpl implements - CompositeBuilder { - - public CompositeBindingConfigurationBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeServiceBindingBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - List<Binding> defaultBindings = null; - for (Object x : composite.getExtensions()) { - if (x instanceof List) { - defaultBindings = (List<Binding>)x; - } - } - // TODO - EPR - is this ever used? - //configureBindingURIs(composite, definitions, defaultBindings, monitor); - return composite; - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java deleted file mode 100644 index 3ae96e6f75..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java +++ /dev/null @@ -1,534 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the configuration of binding URIs. - * - * @version $Rev$ $Date$ - */ -public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements CompositeBuilder, - DeployedCompositeBuilder { - - public CompositeBindingURIBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeBindingURIBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureBindingURIsAndNames(composite, definitions, monitor); - return composite; - } - - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, bindingBaseURIs, monitor); - configureBindingNames(composite, monitor); - return composite; - } - - /** - * Called by CompositeBindingURIBuilderImpl - * - * @param composite the composite to be configured - */ - protected void configureBindingURIsAndNames(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, null, monitor); - configureBindingNames(composite, monitor); - } - - /** - * Fully resolve the binding URIs based on available information. This includes information - * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, - * from any associated policies and from the default information for each binding type. - * - * @param composite the composite to be configured - * @param defaultBindings list of default binding configurations - */ - protected void configureBindingURIs(Composite composite, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, defaultBindings, monitor); - } - - /** - * Fully resolve the binding URIs based on available information. This includes information - * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, - * from any associated policies and from the default information for each binding type. - * - * NOTE: This method repeats some of the processing performed by the configureComponents() - * method above. The duplication is needed because NodeConfigurationServiceImpl - * calls this method without previously calling configureComponents(). In the - * normal builder sequence used by CompositeBuilderImpl, both of these methods - * are called. - * - * TODO: Share the URL calculation algorithm with the configureComponents() method above - * although keeping the configureComponents() methods signature as is because when - * a composite is actually build in a node the node default information is currently - * available - * - * @param composite the composite to be configured - * @param uri the path to the composite provided through any nested composite component implementations - * @param defaultBindings list of default binding configurations - */ - private void configureBindingURIs(Composite composite, - String uri, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - String parentComponentURI = uri; - - monitor.pushContext("Composite: " + composite.getName().toString()); - try { - // Process nested composites recursively - for (Component component : composite.getComponents()) { - - // Initialize component URI - String componentURI; - if (parentComponentURI == null) { - componentURI = component.getName(); - } else { - componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString(); - } - component.setURI(componentURI); - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - // Process nested composite - configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); - } - } - - // Initialize composite service binding URIs - List<Service> compositeServices = composite.getServices(); - for (Service service : compositeServices) { - // Set default binding names - - // Create default SCA binding - attachSCABinding(service, definitions); - - constructBindingNames(service, monitor); - - // Initialize binding names and URIs - for (Binding binding : service.getBindings()) { - constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings, monitor); - } - } - - // Initialize component service binding URIs - for (Component component : composite.getComponents()) { - - monitor.pushContext("Component: " + component.getName()); - - try { - // 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, - monitor); - - // 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, - monitor); - - // 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, monitor); - reconcileReferences(component, references, componentReferences, monitor); - reconcileProperties(component, properties, componentProperties, monitor); - - for (ComponentService service : component.getServices()) { - - // Create default SCA binding - attachSCABinding(service, definitions); - - constructBindingNames(service, monitor); - - // Initialize binding names and URIs - for (Binding binding : service.getBindings()) { - constructBindingURI(component, service, binding, defaultBindings, monitor); - } - } - } finally { - monitor.popContext(); - } - } - } finally { - monitor.popContext(); - } - } - - /** - * Add default names for callback bindings and reference bindings. Needs to be - * separate from configureBindingURIs() because configureBindingURIs() is called - * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl. - */ - private void configureBindingNames(Composite composite, Monitor monitor) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // Process nested composite - configureBindingNames((Composite)implementation, monitor); - } - } - - // Initialize composite service callback binding names - for (Service service : composite.getServices()) { - constructBindingNames(service, monitor); - } - - // Initialize composite reference binding names - for (Reference reference : composite.getReferences()) { - constructBindingNames(reference, monitor); - } - - // Initialize component service and reference binding names - for (Component component : composite.getComponents()) { - - // Initialize component service callback binding names - for (ComponentService service : component.getServices()) { - constructBindingNames(service, monitor); - } - - // Initialize component reference binding names - for (ComponentReference reference : component.getReferences()) { - // Initialize binding names - constructBindingNames(reference, monitor); - } - } - } - - /** - * If a binding name is not provided by the user, construct it based on the service - * or reference name - * - * @param contract the service or reference - */ - private void constructBindingNames(Contract contract, Monitor monitor) { - List<Binding> bindings = contract.getBindings(); - Map<String, Binding> bindingMap = new HashMap<String, Binding>(); - for (Binding binding : bindings) { - // set the default binding name if one is required - // if there is no name on the binding then set it to the service or reference name - if (binding.getName() == null) { - binding.setName(contract.getName()); - } - Binding existed = bindingMap.put(binding.getName(), binding); - // Check that multiple bindings do not have the same name - if (existed != null && existed != binding) { - error(monitor, contract instanceof Service ? "MultipleBindingsForService" - : "MultipleBindingsForReference", binding, contract.getName(), binding.getName()); - } - } - - if (contract.getCallback() != null) { - bindings = contract.getCallback().getBindings(); - bindingMap.clear(); - for (Binding binding : bindings) { - // set the default binding name if one is required - // if there is no name on the binding then set it to the service or reference name - if (binding.getName() == null) { - binding.setName(contract.getName()); - } - Binding existed = bindingMap.put(binding.getName(), binding); - // Check that multiple bindings do not have the same name - if (existed != null && existed != binding) { - error(monitor, contract instanceof Service ? "MultipleBindingsForServiceCallback" - : "MultipleBindingsForReferenceCallback", binding, contract.getName(), binding.getName()); - } - } - } - } - - /** - * URI construction for composite bindings based on Assembly Specification section 1.7.2, This method - * assumes that the component URI part of the binding URI is formed from the part to the - * composite in question and just calls the generic constructBindingURI method with this - * information - * - * @param parentComponentURI - * @param composite - * @param service - * @param binding - * @param defaultBindings - */ - private void constructBindingURI(String parentComponentURI, - Composite composite, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - // This is a composite service so there is no component to provide a component URI - // The path to this composite (through nested composites) is used. - constructBindingURI(parentComponentURI, service, binding, defaultBindings, monitor); - } - - /** - * URI construction for component bindings based on Assembly Specification section 1.7.2. This method - * calculates the component URI part based on component information before calling the generic - * constructBindingURI method - * - * @param component the component that holds the service - * @param service the service that holds the binding - * @param binding the binding for which the URI is being constructed - * @param defaultBindings the list of default binding configurations - */ - private void constructBindingURI(Component component, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - constructBindingURI(component.getURI(), service, binding, defaultBindings, monitor); - } - - /** - * Generic URI construction for bindings based on Assembly Specification section 1.7.2 - * - * @param componentURIString the string version of the URI part that comes from the component name - * @param service the service in question - * @param binding the binding for which the URI is being constructed - * @param includeBindingName when set true the serviceBindingURI part should be used - * @param defaultBindings the list of default binding configurations - * @throws CompositeBuilderException - */ - private void constructBindingURI(String componentURIString, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - try { - - boolean includeBindingName = !service.getName().equals(binding.getName()); - - // calculate the service binding URI - URI bindingURI; - if (binding.getURI() != null) { - bindingURI = new URI(binding.getURI()); - - // if the user has provided an absolute binding URI then use it - if (bindingURI.isAbsolute()) { - binding.setURI(bindingURI.toString()); - return; - } - } else { - bindingURI = null; - } - - String serviceName = service.getName(); - // Get the service binding name - String bindingName; - if (binding.getName() != null) { - bindingName = binding.getName(); - } else { - bindingName = serviceName; - } - - // calculate the component URI - URI componentURI; - if (componentURIString != null) { - componentURI = new URI(addSlashToPath(componentURIString)); - } else { - componentURI = null; - } - - // if the user has provided an absolute component URI then use it - if (componentURI != null && componentURI.isAbsolute()) { - binding.setURI(constructBindingURI(null, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - return; - } - - // calculate the base URI - URI baseURI = null; - if (defaultBindings != null) { - List<String> uris = defaultBindings.get(binding.getType()); - if (uris != null && uris.size() > 0) { - baseURI = new URI(addSlashToPath(uris.get(0))); - } - } - - binding.setURI(constructBindingURI(baseURI, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - } catch (URISyntaxException ex) { - error(monitor, "URLSyntaxException", binding, componentURIString, service.getName(), binding.getName()); - } - } - - /** - * Use to ensure that URI paths end in "/" as here we want to maintain the - * last path element of an base URI when other URI are resolved against it. This is - * not the default behaviour of URI resolution as defined in RFC 2369 - * - * @param path the path string to which the "/" is to be added - * @return the resulting path with a "/" added if it not already there - */ - private static String addSlashToPath(String path) { - if (path.endsWith("/") || path.endsWith("#")) { - return path; - } else { - return path + "/"; - } - } - - /** - * Concatenate binding URI parts together based on Assembly Specification section 1.7.2 - * - * @param baseURI the base of the binding URI - * @param componentURI the middle part of the binding URI derived from the component name - * @param bindingURI the end part of the binding URI - * @param includeBindingName when set true the binding name part should be used - * @param bindingName the binding name - * @return the resulting URI as a string - */ - private static String constructBindingURI(URI baseURI, - URI componentURI, - URI bindingURI, - String serviceName, - boolean includeBindingName, - String bindingName) { - String name = includeBindingName ? serviceName + "/" + bindingName : serviceName; - String uriString; - - if (baseURI == null) { - if (componentURI == null) { - if (bindingURI != null) { - uriString = name + "/" + bindingURI.toString(); - } else { - uriString = name; - } - } else { - if (bindingURI != null) { - if (bindingURI.toString().startsWith("/")) { - uriString = componentURI.resolve(bindingURI).toString(); - } else { - uriString = componentURI.resolve(name + "/" + bindingURI).toString(); - } - } else { - uriString = componentURI.resolve(name).toString(); - } - } - } else { - if (componentURI == null) { - if (bindingURI != null) { - uriString = basedURI(baseURI, bindingURI).toString(); - } else { - uriString = basedURI(baseURI, URI.create(name)).toString(); - } - } else { - if (bindingURI != null) { - uriString = basedURI(baseURI, componentURI.resolve(bindingURI)).toString(); - } else { - uriString = basedURI(baseURI, componentURI.resolve(name)).toString(); - } - } - } - - // tidy up by removing any trailing "/" - if (uriString.endsWith("/")) { - uriString = uriString.substring(0, uriString.length() - 1); - } - - URI uri = URI.create(uriString); - if (!uri.isAbsolute()) { - uri = URI.create("/").resolve(uri); - } - return uri.toString(); - } - - /** - * Combine a URI with a base URI. - * - * @param baseURI - * @param uri - * @return - */ - private static URI basedURI(URI baseURI, URI uri) { - if (uri.getScheme() != null) { - return uri; - } - String str = uri.toString(); - if (str.startsWith("/")) { - str = str.substring(1); - } - return URI.create(baseURI.toString() + str).normalize(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java deleted file mode 100644 index 5fa9c9db17..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A builder that handles the configuration of the components inside a composite - * and the wiring of component references to component services. - * - * @version $Rev$ $Date$ - */ -public class CompositeBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { - private static final Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName()); - private CompositeBuilder compositeIncludeBuilder; - private CompositeBuilder componentReferenceWireBuilder; - //private CompositeBuilder componentReferencePromotionWireBuilder; - private CompositeBuilder componentReferencePromotionBuilder; - //private CompositeBuilder compositeReferenceWireBuilder; - private CompositeBuilder compositeCloneBuilder; - private CompositeBuilder componentConfigurationBuilder; - private CompositeBuilder compositeServiceConfigurationBuilder; - private CompositeBuilder compositeReferenceConfigurationBuilder; - private CompositeBuilder compositeBindingURIBuilder; - //private CompositeBuilder componentServicePromotionBuilder; - //private CompositeBuilder compositeServicePromotionBuilder; - private CompositeBuilder compositePromotionBuilder; - private CompositeBuilder compositePolicyBuilder; - private CompositeBuilder componentServiceBindingBuilder; - private CompositeBuilder componentReferenceBindingBuilder; - - private CompositeBuilder componentReferenceEndpointReferenceBuilder; - private CompositeBuilder componentServiceEndpointBuilder; - - private BuilderExtensionPoint builders; - - /** - * Constructs a new composite builder. - * - * @param registry - */ - public CompositeBuilderImpl(ExtensionPointRegistry registry) { - - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); - - compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); - componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(registry); - //componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory); - componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(registry); - //compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory); - compositeCloneBuilder = new CompositeCloneBuilderImpl(); - componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(registry); - compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(registry); - compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(registry); - compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(registry); - //componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); - //compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); - compositePromotionBuilder = new CompositePromotionBuilderImpl(registry); - compositePolicyBuilder = new CompositePolicyBuilderImpl(registry); - componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(registry); - componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(registry); - - componentReferenceEndpointReferenceBuilder = new ComponentReferenceEndpointReferenceBuilderImpl(registry); - componentServiceEndpointBuilder = new ComponentServiceEndpointBuilderImpl(assemblyFactory); - //endpointReferenceBuilder = new EndpointReference2BuilderImpl(assemblyFactory, interfaceContractMapper); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - build(composite, definitions, null, monitor); - return composite; - } - - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - - try { - - // Clone nested and included composites - composite = compositeCloneBuilder.build(composite, definitions, monitor); - - // Collect and fuse includes - composite = compositeIncludeBuilder.build(composite, definitions, monitor); - - // Configure all components - composite = componentConfigurationBuilder.build(composite, definitions, monitor); - - // Connect composite services/references to promoted services/references - composite = compositePromotionBuilder.build(composite, definitions, monitor); - - // Configure composite services by copying bindings up the promotion - // hierarchy overwriting automatic bindings with those added manually - composite = compositeServiceConfigurationBuilder.build(composite, definitions, monitor); - - // Configure composite references by copying bindings down promotion - // hierarchy overwriting automatic bindings with those added manually - composite = compositeReferenceConfigurationBuilder.build(composite, definitions, monitor); - - // Configure service binding URIs and names. Creates an SCA defined URI based - // on the scheme base URI, the component name and the binding name - composite = - ((DeployedCompositeBuilder)compositeBindingURIBuilder).build(composite, - definitions, - bindingBaseURIs, - monitor); - - // Create $promoted$ component services on bottom level components - // to represent promoted services - // TODO - EPR replaced by endpoints on the promoted services - //componentServicePromotionBuilder.build(composite, definitions, monitor); - - // Create $promoted$ component services on bottom level components - // to represent promoted composite services - // TODO - EPR OASIS doesn't deploy top level composite services - // if it did it would be replaced by endpoints - //compositeServicePromotionBuilder.build(composite, definitions, monitor); - - // Perform and service binding related build activities. The binding - // will provide the builder. - composite = componentServiceBindingBuilder.build(composite, definitions, monitor); - - // create endpoints on component services. - composite = componentServiceEndpointBuilder.build(composite, definitions, monitor); - - // Apply any wires in the composite to create new component reference targets - composite = componentReferenceWireBuilder.build(composite, definitions, monitor); - - // create reference endpoint reference models - composite = componentReferenceEndpointReferenceBuilder.build(composite, definitions, monitor); - - // Push down configuration from promoted references to the - // references they promote - composite = componentReferencePromotionBuilder.build(composite, definitions, monitor); - - // Push down configuration from promoted references to the - // references they promote - // TODO - EPR Seems to be a repeat of compositeReferenceConfigurationBuilder - // componentReferencePromotionWireBuilder.build(composite, definitions, monitor); - - // Wire the composite references - // TODO - EPR OASIS doesn't deploy top level composite references - // compositeReferenceWireBuilder.build(composite, definitions, monitor); - - // Perform and reference binding related build activities. The binding - // will provide the builder. - composite = componentReferenceBindingBuilder.build(composite, definitions, monitor); - - // Compute the policies across the model hierarchy - composite = compositePolicyBuilder.build(composite, definitions, monitor); - - return composite; - } catch (Exception e) { - throw new CompositeBuilderException("Exception while building composite " + composite.getName(), e); - } // end try - - } // end method build - -} //end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java deleted file mode 100644 index 57a87a7a0f..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that clones nested composites. - * - * @version $Rev$ $Date$ - */ -public class CompositeCloneBuilderImpl implements CompositeBuilder { - - public CompositeCloneBuilderImpl() { - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - if (Composite.DOMAIN_COMPOSITE.equals(composite.getName())) { - // Try to avoid clone for top-level composites that are added to the domain composite - for (Composite included : composite.getIncludes()) { - cloneIncludes(included); - } - } else { - // Clone the includes - cloneIncludes(composite); - } - - cloneCompositeImplementations(composite); - return composite; - } - - private void cloneIncludes(Composite composite) { - List<Composite> includes = new ArrayList<Composite>(); - for (Composite included : composite.getIncludes()) { - try { - includes.add((Composite)included.clone()); - } catch (CloneNotSupportedException e) { - throw new UnsupportedOperationException(e); - } - } - composite.getIncludes().clear(); - composite.getIncludes().addAll(includes); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeCloneBuilder"; - } - - /** - * Clone composite component implementations - * - * @param composite - * @param problems - */ - private void cloneCompositeImplementations(Composite composite) { - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - Composite compositeImplementation = (Composite)implementation; - try { - // Please note the clone method is recursive - Composite clone = (Composite)compositeImplementation.clone(); - component.setImplementation(clone); - } catch (CloneNotSupportedException e) { - throw new UnsupportedOperationException(e); - } - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java deleted file mode 100644 index d696496a19..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java +++ /dev/null @@ -1,482 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * @version $Rev$ $Date$ - */ - -// TODO - really implementation.composite component type builder - CompositeComponentTypeBuilder? - -public class CompositeComponentTypeBuilderImpl { - private static final Logger logger = Logger.getLogger(CompositeComponentTypeBuilderImpl.class.getName()); - - protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; - protected static final String BINDING_SCA = "binding.sca"; - protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); - - private ComponentBuilderImpl componentBuilder; - private Monitor monitor; - private AssemblyFactory assemblyFactory; - private SCABindingFactory scaBindingFactory; - private InterfaceContractMapper interfaceContractMapper; - private BuilderExtensionPoint builders; - - public CompositeComponentTypeBuilderImpl(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); - - interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public void setComponentBuilder(ComponentBuilderImpl componentBuilder) { - this.componentBuilder = componentBuilder; - } - - /** - * Calculate the component type for the provided implementation - * - * @param implementation - * @return component type - */ - public void createComponentType(Implementation implementation) { - if (!(implementation instanceof Composite)) { - // component type will have been calculated at resolve time - return; - } - - // create the composite component type as this was not - // calculated at resolve time - Composite composite = (Composite)implementation; - - // first make sure that each child component has been properly configured based - // on its own component type - for (Component component : composite.getComponents()) { - - // Check for duplicate component names - if (composite.getComponent(component.getName()) == null) { - Monitor.error(monitor, this, "assembly-validation-messages", "DuplicateComponentName", composite - .getName().toString(), component.getName()); - } - - // do any work we need to do before we configure the component - // Anything that needs to be pushed down the promotion - // hierarchy must be done before we configure the component - - // Push down the autowire flag from the composite to components - if (component.getAutowire() == null) { - component.setAutowire(composite.getAutowire()); - } - - // configure the component from its component type - componentBuilder.configureComponentFromComponentType(composite, component); - } - - // create the composite component type based on the promoted artifacts - // from the components that it contains - - // index all the components, services and references in the - // component type so that they are easy to find - Map<String, Component> components = new HashMap<String, Component>(); - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); - indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - - // services - calculateServices(composite, components, componentServices); - - // references - calculateReferences(composite, components, componentReferences); - - // properties - // Properties on the composite component are unaffected by properties - // on child components. Instead child component properties might take their - // values from component properties. Hence there is nothing to do here. - //calculateProperties(composite, components); - - } - - /** - * Index components, services and references inside a composite. - * - * @param composite - * @param components - * @param componentServices - * @param componentReferences - */ - private void indexComponentsServicesAndReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences) { - - for (Component component : composite.getComponents()) { - - // Index components by name - components.put(component.getName(), component); - - ComponentService nonCallbackService = null; - int nonCallbackServices = 0; - for (ComponentService componentService : component.getServices()) { - - // Index component services by component name / service name - String uri = component.getName() + '/' + componentService.getName(); - componentServices.put(uri, componentService); - - // count how many non-callback services there are - // if there is only one the component name also acts as the service name - if (!componentService.isForCallback()) { - - // Check how many non callback non-promoted services we have - if (nonCallbackServices == 0) { - nonCallbackService = componentService; - } - nonCallbackServices++; - } - } - - if (nonCallbackServices == 1) { - // If we have a single non callback service, index it by - // component name as well - componentServices.put(component.getName(), nonCallbackService); - } - - // Index references by component name / reference name - for (ComponentReference componentReference : component.getReferences()) { - String uri = component.getName() + '/' + componentReference.getName(); - componentReferences.put(uri, componentReference); - } - } - } - - /** - * Connect the services in the component type to the component services that - * they promote - * - * @param componentType - * @param component - */ - private void calculateServices(ComponentType componentType, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - - // Connect this component type's services to the - // services from child components which it promotes - connectPromotedServices(componentType, components, componentServices); - - // look at each component type service in turn and - // calculate its configuration based on OASIS rules - for (Service service : componentType.getServices()) { - CompositeService compositeService = (CompositeService)service; - ComponentService promotedComponentService = compositeService.getPromotedService(); - - // promote interface contracts - calculatePromotedInterfaceContract(compositeService, promotedComponentService); - - // promote bindings - calculatePromotedBindings(compositeService, promotedComponentService); - - // promote intents - done later in CompositePolicyBuilder - discuss with RF - // calculatePromotedIntents(compositeService, promotedComponentService); - - // promote policy sets - done later in CompositePolicyBuilder - discuss with RF - // calculatePromotedPolicySets(compositeService, promotedComponentService); - } - } - - /** - * Connect the references in the component type to the component references that - * they promote - * - * @param componentType - * @param component - */ - private void calculateReferences(ComponentType componentType, - Map<String, Component> components, - Map<String, ComponentReference> componentReferences) { - - // Connect this component type's references to the - // references from child components which it promotes - connectPromotedReferences(componentType, components, componentReferences); - - // look at each component type reference in turn and - // calculate its configuration based on OASIS rules - for (Reference reference : componentType.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences(); - - for (ComponentReference promotedComponentReference : promotedReferences) { - - // promote interface contracts - calculatePromotedInterfaceContract(compositeReference, promotedComponentReference); - - // promote bindings - // Don't need to promote reference bindings as any lower level binding will - // already be targeting the correct service without need for promotion - //calculatePromotedBindings(compositeReference, promotedComponentReference); - - // promote intents - done later in CompositePolicyBuilder - discuss with RF - // calculatePromotedIntents(compositeService, promotedComponentService); - - // promote policy sets - done later in CompositePolicyBuilder - discuss with RF - // calculatePromotedPolicySets(compositeService, promotedComponentService); - } - } - } - - /** - * Connect the services in the component type to the component services that - * they promote - * - * @param componentType - * @param component - */ - private void connectPromotedServices(ComponentType componentType, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - - for (Service service : componentType.getServices()) { - // Connect composite (component type) services to the component services - // that they promote - CompositeService compositeService = (CompositeService)service; - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null && componentService.isUnresolved()) { - // get the name of the promoted component/service - String promotedComponentName = compositeService.getPromotedComponent().getName(); - String promotedServiceName; - if (componentService.getName() != null) { - if (compositeService.isForCallback()) { - // For callbacks the name already has the form "componentName/servicename" - promotedServiceName = componentService.getName(); - } else { - promotedServiceName = promotedComponentName + '/' + componentService.getName(); - } - } else { - promotedServiceName = promotedComponentName; - } - - // find the promoted service - 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); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PromotedServiceNotFound", - ((Composite)componentType).getName().toString(), - promotedServiceName); - } - } - } - } - - /** - * Connect the references in the component type to the component references that - * they promote - * - * @param componentType - * @param component - */ - private void connectPromotedReferences(ComponentType componentType, - Map<String, Component> components, - Map<String, ComponentReference> componentReferences) { - - // Connect composite (component type) references to the component references that they promote - for (Reference reference : componentType.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); - - componentReference.setPromoted(true); - - // Point to the resolved component reference - promotedReferences.set(i, componentReference); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PromotedReferenceNotFound", - ((Composite)componentType).getName().toString(), - componentReferenceName); - } - } - } - } - } - - /** - * Create a default SCA binding in the case that no binding - * is specified by the user - * - * @param contract - * @param definitions - */ - protected void createSCABinding(Contract contract, Definitions definitions) { - - SCABinding scaBinding = scaBindingFactory.createSCABinding(); - - if (definitions != null) { - for (ExtensionType attachPointType : definitions.getBindingTypes()) { - if (attachPointType.getType().equals(BINDING_SCA_QNAME)) { - ((PolicySubject)scaBinding).setExtensionType(attachPointType); - } - } - } - - contract.getBindings().add(scaBinding); - contract.setOverridingBindings(false); - } - - /** - * The following methods implement rules that the OASIS specification defined explicitly - * to control how configuration from a component type is inherited by a component - */ - - /** - * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence - * - * @param topContract the top contract - * @param bottomContract the bottom contract - */ - private void calculatePromotedInterfaceContract(Contract topContract, Contract bottomContract) { - // Use the interface contract from the bottom level contract if - // none is specified on the top level contract - InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); - InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract(); - - if (topInterfaceContract == null) { - topContract.setInterfaceContract(bottomInterfaceContract); - } else if (bottomInterfaceContract != null) { - // Check that the top and bottom interface contracts are compatible - boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, bottomInterfaceContract); - if (!isCompatible) { - if (topContract instanceof Reference) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceInterfaceNotSubSet", - topContract.getName()); - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ServiceInterfaceNotSubSet", - topContract.getName()); - } - } - } - } - - /** - * OASIS RULE: Bindings from higher in the implementation hierarchy take precedence - * - * @param compositeService - * @param promotedComponentService - */ - private void calculatePromotedBindings(CompositeService compositeService, ComponentService promotedComponentService) { - // forward bindings - if (compositeService.getBindings().isEmpty()) { - for (Binding binding : promotedComponentService.getBindings()) { - try { - compositeService.getBindings().add((Binding)binding.clone()); - } catch (CloneNotSupportedException ex) { - // this binding can't be used in the promoted service - } - } - } - - if (compositeService.getBindings().isEmpty()) { - createSCABinding(compositeService, null); - } - - // callback bindings - if (promotedComponentService.getCallback() != null) { - if (compositeService.getCallback() != null) { - compositeService.getCallback().getBindings().clear(); - } else { - compositeService.setCallback(assemblyFactory.createCallback()); - } - - for (Binding binding : promotedComponentService.getCallback().getBindings()) { - try { - compositeService.getCallback().getBindings().add((Binding)binding.clone()); - } catch (CloneNotSupportedException ex) { - // this binding can't be used in the promoted service - } - } - } - } - -} //end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java deleted file mode 100644 index 2a28c48905..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * Implementation of a CompositeBuilder. - * - * @version $Rev$ $Date$ - */ -public class CompositeIncludeBuilderImpl implements CompositeBuilder { - - public CompositeIncludeBuilderImpl() { - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeIncludeBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - return processIncludes(composite, monitor); - } - - /** - * Merge the elements from the included composites into the including composite - * @param composite - * @param monitor - * @return - */ - private Composite processIncludes(Composite composite, Monitor monitor) { - monitor.pushContext("Composite: " + composite.getName().toString()); - - try { - // process any composites referenced through implementation.composite - for (Component component : composite.getComponents()) { - - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processIncludes((Composite)implementation, monitor); - } - } - - // get the components etc. from any included composites - for (Composite included : composite.getIncludes()) { - if (included.isLocal() && !composite.isLocal()) { - // ASM60041 - Monitor.error(monitor, this, "assembly-validation-messages", "IllegalCompositeIncusion", composite - .getName().toString(), included.getName().toString()); - return null; - } - - // The included has been cloned during composite.clone() - Composite merged = processIncludes(included, monitor); - if (merged != null) { - for (Component component : merged.getComponents()) { - // apply the autowire flag on this composite to any inline - // components - Assembly 5.6 point 4 - if (component.getAutowire() == null && merged.getAutowire() == Boolean.TRUE) { - component.setAutowire(Boolean.TRUE); - } - // Merge the intents and policySets from the included composite into - // component/service/reference elements under the composite - component.getRequiredIntents().addAll(merged.getRequiredIntents()); - component.getPolicySets().addAll(merged.getPolicySets()); - } - - for (Service service : merged.getServices()) { - service.getRequiredIntents().addAll(merged.getRequiredIntents()); - service.getPolicySets().addAll(merged.getPolicySets()); - } - - for (Reference reference : merged.getReferences()) { - reference.getRequiredIntents().addAll(merged.getRequiredIntents()); - reference.getPolicySets().addAll(merged.getPolicySets()); - } - composite.getComponents().addAll(merged.getComponents()); - composite.getServices().addAll(merged.getServices()); - composite.getReferences().addAll(merged.getReferences()); - composite.getProperties().addAll(merged.getProperties()); - composite.getWires().addAll(merged.getWires()); - // FIXME: What should we do for the extensions - /* - clone.getExtensions().addAll(fusedComposite.getExtensions()); - clone.getAttributeExtensions().addAll(fusedComposite.getAttributeExtensions()); - */ - } - } - - composite.getIncludes().clear(); - - // return the fused composite we have built up so far - return composite; - } finally { - monitor.popContext(); - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java deleted file mode 100644 index b79a9a9ad5..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.IntentMap; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.apache.tuscany.sca.policy.Qualifier; - -/** - * A composite builder that computes policy sets based on attached intents and policy sets. - * Useful if you want to build the model without making any runtime decisions such as - * reference/services matching - * - * @version $Rev$ $Date$ - */ -public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - public CompositePolicyBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositePolicyBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - computePolicies(composite, definitions, monitor); - return composite; - } - - /** - * Inherit the intents and policySets from the list of models - * @param intents - * @param policySets - * @param models - */ - private void inherit(PolicySubject policySubject, Object... models) { - for (Object model : models) { - if (model instanceof PolicySubject) { - PolicySubject subject = (PolicySubject)model; - policySubject.getRequiredIntents().addAll(subject.getRequiredIntents()); - policySubject.getPolicySets().addAll(subject.getPolicySets()); - } - } - } - - /** - * Check if two policy subjects requires multually exclusive intents - * @param subject1 - * @param subject2 - * @param monitor - * @return - */ - private boolean checkMutualExclusion(PolicySubject subject1, PolicySubject subject2, Monitor monitor) { - if (subject1 == subject2 || subject1 == null || subject2 == null) { - return false; - } - for (Intent i1 : subject1.getRequiredIntents()) { - for (Intent i2 : subject1.getRequiredIntents()) { - if (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) { - error(monitor, "MutuallyExclusiveIntents", new Object[] {subject1, subject2}, i1, i2); - return true; - } - } - } - return false; - } - - /** - * Inherit the policySets and intents from the implementation hierarchy - * @param subject - * @param composite - * @param component - * @param service - */ - private void inheritFromService(PolicySubject subject, Composite composite, Component component, Service service) { - if (service == null) { - return; - } - if (service instanceof ComponentService) { - // component!=null - if (component.getImplementation() instanceof Composite) { - composite = (Composite)component.getImplementation(); - } - inheritFromService(subject, composite, component, ((ComponentService)service).getService()); - // Component service also inherits the intents/policySets from composite/component - inherit(subject, composite, component); - } else if (service instanceof CompositeService) { - // composite!=null, component is not used - CompositeService compositeService = (CompositeService)service; - // Handle the promoted component service - inheritFromService(subject, composite, compositeService.getPromotedComponent(), compositeService - .getPromotedService()); - } - // For atomic service, the composite is not used - inherit(subject, component.getImplementation(), service); - } - - /** - * Inherit the policySets and intents from the implementation hierarchy - * @param subject - * @param composite - * @param component - * @param reference - */ - private void inheritFromReference(PolicySubject subject, - Composite composite, - Component component, - Reference reference) { - if (reference == null) { - return; - } - if (reference instanceof ComponentReference) { - // component!=null - if (component.getImplementation() instanceof Composite) { - composite = (Composite)component.getImplementation(); - } - inheritFromReference(subject, composite, component, ((ComponentReference)reference).getReference()); - } else if (reference instanceof CompositeReference) { - CompositeReference compositeReference = (CompositeReference)reference; - for (int i = 0, n = compositeReference.getPromotedReferences().size(); i < n; i++) { - inheritFromReference(subject, - composite, - compositeReference.getPromotedComponents().get(i), - compositeReference.getPromotedReferences().get(i)); - } - } - // Inherit from the componentType/reference - inherit(subject, component.getImplementation(), reference); - } - - /** - * Check if two names are equal - * @param name1 - * @param name2 - * @return - */ - private boolean isEqual(String name1, String name2) { - if (name1 == name2) { - return true; - } - if (name1 != null) { - return name1.equals(name2); - } else { - return name2.equals(name1); - } - } - - private Intent resolve(Definitions definitions, Intent proxy) { - for (Intent i : definitions.getIntents()) { - if (i.equals(proxy)) { - return i; - } - for (Intent qi : i.getQualifiedIntents()) { - if (qi.equals(proxy)) { - return qi; - } - } - } - return null; - } - - private void resolveAndNormalize(PolicySubject subject, Definitions definitions, Monitor monitor) { - - Set<Intent> intents = new HashSet<Intent>(); - if (definitions != null) { - for (Intent i : subject.getRequiredIntents()) { - Intent resolved = resolve(definitions, i); - if (resolved != null) { - intents.add(resolved); - } else { - warning(monitor, "IntentNotFound", subject, i); - // Intent cannot be resolved - } - } - } - - // Replace profile intents with their required intents - while (!intents.isEmpty()) { - boolean profileIntentsFound = false; - Set<Intent> copy = new HashSet<Intent>(intents); - for (Intent i : copy) { - if (!i.getRequiredIntents().isEmpty()) { - intents.remove(i); - intents.addAll(i.getRequiredIntents()); - profileIntentsFound = true; - } - } - if (!profileIntentsFound) { - // No more profileIntents - break; - } - } - - // Remove the intents whose @contraints do not include the current element - // Replace unqualified intents if there is a qualified intent in the list - Set<Intent> copy = new HashSet<Intent>(intents); - for (Intent i : copy) { - if (i.getQualifiableIntent() != null) { - intents.remove(i.getQualifiableIntent()); - } - } - - // Replace qualifiable intents with the default qualified intent - copy = new HashSet<Intent>(intents); - for (Intent i : copy) { - if (i.getDefaultQualifiedIntent() != null) { - intents.remove(i); - intents.add(i.getDefaultQualifiedIntent()); - } - } - - subject.getRequiredIntents().clear(); - subject.getRequiredIntents().addAll(intents); - - Set<PolicySet> policySets = new HashSet<PolicySet>(); - if (definitions != null) { - for (PolicySet policySet : subject.getPolicySets()) { - int index = definitions.getPolicySets().indexOf(policySet); - if (index != -1) { - policySets.add(definitions.getPolicySets().get(index)); - } else { - // PolicySet cannot be resolved - } - } - } - - for (Intent intent : subject.getRequiredIntents()) { - loop: for (PolicySet ps : definitions.getPolicySets()) { - // FIXME: We will have to check the policy references and intentMap too - // as well as the appliesTo - if (ps.getProvidedIntents().contains(intent)) { - policySets.add(ps); - break; - } - for (IntentMap map : ps.getIntentMaps()) { - for (Qualifier q : map.getQualifiers()) { - if (intent.equals(q.getIntent())) { - policySets.add(ps); - break loop; - } - } - } - } - } - - subject.getPolicySets().clear(); - subject.getPolicySets().addAll(policySets); - - } - - protected void computePolicies(Composite composite, Definitions definitions, Monitor monitor) { - - // compute policies recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - computePolicies((Composite)implementation, definitions, monitor); - } - } - - for (Component component : composite.getComponents()) { - checkMutualExclusion(component, component.getImplementation(), monitor); - - for (ComponentService componentService : component.getServices()) { - checkMutualExclusion(componentService, componentService.getService(), monitor); - - if (componentService.getInterfaceContract() != null && componentService.getService() != null) { - checkMutualExclusion(componentService.getInterfaceContract().getInterface(), componentService - .getService().getInterfaceContract().getInterface(), monitor); - checkMutualExclusion(componentService.getInterfaceContract().getCallbackInterface(), - componentService.getService().getInterfaceContract().getCallbackInterface(), - monitor); - } - - for (Endpoint ep : componentService.getEndpoints()) { - // Inherit from the componentType.service.interface - if (componentService.getService() != null && componentService.getService().getInterfaceContract() != null) { - inherit(ep, componentService.getService().getInterfaceContract().getInterface()); - } - if (componentService.getInterfaceContract() != null) { - // Inherit from the component.service.interface - inherit(ep, componentService.getInterfaceContract().getInterface()); - } - // Inherit from the componentType/service - inheritFromService(ep, composite, component, componentService.getService()); - // Find the corresponding binding in the componentType and inherit the intents/policySets - if (componentService.getService() != null) { - for (Binding binding : componentService.getService().getBindings()) { - if (isEqual(ep.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) { - checkMutualExclusion((PolicySubject)ep.getBinding(), (PolicySubject)binding, monitor); - // Inherit from componentType.service.binding - inherit(ep, binding); - break; - } - } - } - // Inherit from composite/component/service - inheritFromService(ep, composite, ep.getComponent(), ep.getService()); - // Inherit from binding - inherit(ep, ep.getBinding()); - - // Replace profile intents with their required intents - // Remove the intents whose @contraints do not include the current element - // Replace unqualified intents if there is a qualified intent in the list - // Replace qualifiable intents with the default qualied intent - resolveAndNormalize(ep, definitions, monitor); - } - } - - for (ComponentReference componentReference : component.getReferences()) { - checkMutualExclusion(componentReference, componentReference.getReference(), monitor); - - if (componentReference.getInterfaceContract() != null && componentReference.getReference() != null) { - checkMutualExclusion(componentReference.getInterfaceContract().getInterface(), componentReference - .getReference().getInterfaceContract().getInterface(), monitor); - checkMutualExclusion(componentReference.getInterfaceContract().getCallbackInterface(), - componentReference.getReference().getInterfaceContract() - .getCallbackInterface(), - monitor); - } - - for (EndpointReference epr : componentReference.getEndpointReferences()) { - // Inherit from the componentType.reference.interface - if (componentReference.getReference() != null && componentReference.getReference() - .getInterfaceContract() != null) { - inherit(epr, componentReference.getReference().getInterfaceContract().getInterface()); - } - // Inherit from the component.reference.interface - if (componentReference.getInterfaceContract() != null) { - inherit(epr, componentReference.getInterfaceContract().getInterface()); - } - // Inherit from the componentType/reference - inheritFromReference(epr, composite, component, componentReference.getReference()); - // Find the corresponding binding in the componentType and inherit the intents/policySets - if (componentReference.getReference() != null) { - for (Binding binding : componentReference.getReference().getBindings()) { - if (epr.getBinding() != null && isEqual(epr.getBinding().getName(), binding.getName()) - && (binding instanceof PolicySubject)) { - checkMutualExclusion((PolicySubject)epr.getBinding(), (PolicySubject)binding, monitor); - // Inherit from componentType.reference.binding - inherit(epr, binding); - break; - } - } - } - // Inherit from composite/component/reference/binding - inheritFromReference(epr, composite, epr.getComponent(), epr.getReference()); - inherit(epr, epr.getBinding()); - - // Replace profile intents with their required intents - // Remove the intents whose @contraints do not include the current element - // Replace unqualified intents if there is a qualified intent in the list - // Replace qualifiable intents with the default qualied intent - resolveAndNormalize(epr, definitions, monitor); - } - } - - Implementation implementation = component.getImplementation(); - // How to deal with implementation level policySets/intents - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java deleted file mode 100644 index 274d6db83e..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that makes the connections between composite services and references - * and the services and references that they promote - * - * @version $Rev$ $Date$ - */ -public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - - public CompositePromotionBuilderImpl(ExtensionPointRegistry registry) { - super(registry); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositePromotionBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - connectCompositeReferencesAndServices(composite, monitor); - return composite; - } - - /** - * Connect composite references and services to the reference and services that they promote. - * - * @param composite - * @param componentServices - * @param problems - */ - protected void connectCompositeReferencesAndServices(Composite composite, Monitor monitor) { - - monitor.pushContext("Composite: " + composite.getName().toString()); - - try { - // Wire nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - connectCompositeReferencesAndServices((Composite)implementation, monitor); - } - } - - // Index components, services and references - Map<String, Component> components = new HashMap<String, Component>(); - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); - indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - - // Connect composite services and references to the component - // services and references that they promote - connectCompositeServices(composite, components, componentServices, monitor); - connectCompositeReferences(composite, components, componentReferences, monitor); - } finally { - monitor.popContext(); - } // end try - } - - /** - * Connect composite services to the component services that they promote. - * - * @param composite - * @param componentServices - * @param problems - */ - private void connectCompositeServices(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Monitor monitor) { - - // Propagate interfaces from inner composite components' services to - // their component services - for (Component component : composite.getComponents()) { - if (component.getImplementation() instanceof Composite) { - for (ComponentService componentService : component.getServices()) { - Service service = componentService.getService(); - if (service != null) { - if (componentService.getInterfaceContract() == null) { - componentService.setInterfaceContract(service.getInterfaceContract()); - } - } - } - } - } - - // 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) { - if (compositeService.isForCallback()) { - // For callbacks the name already has the form "componentName"/"servicename" - promotedServiceName = componentService.getName(); - } else { - 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) { - error(monitor, "ServiceInterfaceNotSubSet", compositeService, promotedServiceName); - } - } - - } else { - // MJE 15/05/2005 - Priority raised from "warning" to "error" to fix TUSCANY-3034 - error(monitor, - "PromotedServiceNotFound", - composite, - composite.getName().toString(), - promotedServiceName); - } - } - } - - } - - /** - * Resolves promoted references. - * - * @param composite - * @param componentReferences - * @param problems - */ - private void connectCompositeReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentReference> componentReferences, - Monitor monitor) { - - // Propagate interfaces from inner composite components' references to - // their component references - for (Component component : composite.getComponents()) { - if (component.getImplementation() instanceof Composite) { - for (ComponentReference componentReference : component.getReferences()) { - Reference reference = componentReference.getReference(); - if (reference != null) { - if (componentReference.getInterfaceContract() == null) { - componentReference.setInterfaceContract(reference.getInterfaceContract()); - } - } - } - } - } - - // 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); - - componentReference.setPromoted(true); - - // 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 that the componentInterfaceContract is a subset of the compositeInterfaceContract - boolean isCompatible = - interfaceContractMapper.isCompatible(componentReferenceInterfaceContract, - compositeReferenceInterfaceContract); - if (!isCompatible) { - error(monitor, - "ReferenceInterfaceNotSubSet", - compositeReference, - componentReferenceName); - } - } - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PromotedReferenceNotFound", - composite.getName().toString(), - componentReferenceName); - } - } - } - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java deleted file mode 100644 index 51cea9100e..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Callback; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the configuration of composite references. - * - * @version $Rev$ $Date$ - */ -public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public CompositeReferenceConfigurationBuilderImpl(ExtensionPointRegistry registry) { - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = factories.getFactory(AssemblyFactory.class); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeReferenceConfigurationBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - // Process nested composites recursively - configureNestedCompositeReferences(composite); - - // Process top level composite references - // TODO - In OASIS the treament of top level composite references is different so need to review - for (Reference reference : composite.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - - // 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 (compositeReference.isOverridingBindings()) { - compositeReference.setPromotionOverride(true); - } else if (promotedReference.isOverridingBindings()) { - 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 (compositeReference.getInterfaceContract() != null && compositeReference.getInterfaceContract() - .getCallbackInterface() != null) { - if (isCallbackOverridingBindings(compositeReference)) { - compositeReference.setPromotionOverride(true); - } else if (isCallbackOverridingBindings(promotedReference)) { - if (compositeReference.getCallback() != null) { - compositeReference.getCallback().getBindings().clear(); - } else { - compositeReference.setCallback(assemblyFactory.createCallback()); - } - for (Binding binding : promotedReference.getCallback().getBindings()) { - try { - compositeReference.getCallback().getBindings().add((Binding)binding.clone()); - } catch (CloneNotSupportedException ex) { - // this binding can't be used in the promoted reference - } - } - } - } - } else { - // This composite reference promotes multiple component references. - // Because the component reference bindings can all be different, we don't - // copy any of them up to this composite reference, which will therefore always - // have its own binding, even if it's only the default SCA binding. - if (compositeReference.isOverridingBindings() || (compositeReference.getCallback() != null && !compositeReference - .getCallback().getBindings().isEmpty())) { - compositeReference.setPromotionOverride(true); - } - } - } - } - return composite; - } - - private void configureNestedCompositeReferences(Composite composite) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // First process nested composites - configureNestedCompositeReferences((Composite)implementation); - - // 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 (!compositeReference.isOverridingBindings() && promotedReference - .isOverridingBindings()) { - 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 (componentReference.isOverridingBindings()) { - componentReference.setPromotionOverride(true); - } else if (compositeReference.isOverridingBindings()) { - componentReference.getBindings().clear(); - componentReference.getBindings().addAll(compositeReference.getBindings()); - } - if (componentReference.getInterfaceContract() != null && componentReference - .getInterfaceContract().getCallbackInterface() != null) { - if (!isCallbackOverridingBindings(compositeReference) && isCallbackOverridingBindings(promotedReference)) { - if (compositeReference.getCallback() != null) { - compositeReference.getCallback().getBindings().clear(); - } else { - compositeReference.setCallback(assemblyFactory.createCallback()); - } - compositeReference.getCallback().getBindings().addAll(promotedReference - .getCallback().getBindings()); - } - if (componentReference.getCallback() != null && !componentReference.getCallback() - .getBindings().isEmpty()) { - componentReference.setPromotionOverride(true); - } else if (isCallbackOverridingBindings(compositeReference)) { - 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 - } - } - } - } - } else { - // This component reference promotes multiple lower-level component references. - // Because the lower-level component reference bindings can all be different, - // we don't copy any of them up to this component reference, which will therefore - // always have its own binding, even if it's only the default SCA binding. - if (componentReference.isOverridingBindings() || isCallbackOverridingBindings(componentReference)) { - componentReference.setPromotionOverride(true); - } - } - } - } - } - } - } - } - - private boolean isCallbackOverridingBindings(Contract contract) { - Callback callback = contract.getCallback(); - return callback != null && !callback.getBindings().isEmpty(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java deleted file mode 100644 index 9daf1b67b2..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that wires composite references. - * - * @version $Rev$ $Date$ - */ -public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceWireBuilder"; - } - - /** - * Wire composite references in a deployment composite. - * - * @param composite - */ - public Composite 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()); - } - } - } - } - } - return composite; - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java deleted file mode 100644 index d06b686b48..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.BindingBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that performs any additional building steps that - * composite service bindings may need. Used for WSDL generation. - * - * @version $Rev$ $Date$ - */ -public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { - private BuilderExtensionPoint builders; - - public CompositeServiceBindingBuilderImpl(ExtensionPointRegistry registry) { - this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeServiceBindingBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - buildServiceBindings(composite, monitor); - return composite; - } - - private void buildServiceBindings(Composite composite, Monitor monitor) { - - // build bindings recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - buildServiceBindings((Composite)implementation, monitor); - } - } - - // find all the composite service bindings - for (Service service : composite.getServices()) { - for (Binding binding : service.getBindings()) { - BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); - if (builder != null) { - Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service); - builder.build(component, service, binding, monitor); - } - } - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java deleted file mode 100644 index e690e26170..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Callback; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the configuration of composite services. - * - * @version $Rev$ $Date$ - */ -public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public CompositeServiceConfigurationBuilderImpl(ExtensionPointRegistry registry) { - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = factories.getFactory(AssemblyFactory.class); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeServiceConfigurationBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - // Process nested composites recursively - configureNestedCompositeServices(composite); - - // TODO - In OASIS the treatment of top level composite services it different - // 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 (!compositeService.isOverridingBindings() && promotedService.isOverridingBindings()) { - 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 (!isCallbackOverridingBindings(compositeService) && isCallbackOverridingBindings(promotedService)) { - 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 - } - } - } - } - } - } - return composite; - } - - private void configureNestedCompositeServices(Composite composite) { - - // Process nested composites recursively - for (Component component : composite.getComponents()) { - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - - // First process nested composites - configureNestedCompositeServices((Composite)implementation); - - // 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 (!compositeService.isOverridingBindings() && promotedService.isOverridingBindings()) { - 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 (!componentService.isOverridingBindings() && compositeService.isOverridingBindings()) { - componentService.getBindings().clear(); - componentService.getBindings().addAll(compositeService.getBindings()); - } - if (componentService.getInterfaceContract() != null && componentService - .getInterfaceContract().getCallbackInterface() != null) { - if (!isCallbackOverridingBindings(compositeService) && isCallbackOverridingBindings(promotedService)) { - 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 (!(isCallbackOverridingBindings(componentService)) && isCallbackOverridingBindings(compositeService)) { - if (componentService.getCallback() != null) { - componentService.getCallback().getBindings().clear(); - } else { - componentService.setCallback(assemblyFactory.createCallback()); - } - componentService.getCallback().getBindings().addAll(compositeService.getCallback() - .getBindings()); - } - } - } - } - } - } - } - } - - private boolean isCallbackOverridingBindings(Contract contract) { - Callback callback = contract.getCallback(); - return callback != null && !callback.getBindings().isEmpty(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java deleted file mode 100644 index 2b2634bcd3..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A composite builder that handles the creation of promoted composite services. - * - * @version $Rev$ $Date$ - */ -public class CompositeServicePromotionBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public CompositeServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeServicePromotionBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - // Process top level composite services - for (Service service : composite.getServices()) { - CompositeService compositeService = (CompositeService)service; - - // Get the innermost promoted service - ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (promotedService != null) { - Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); - - // Create a new component service to represent this composite - // service on the promoted component - ComponentService newComponentService = assemblyFactory.createComponentService(); - newComponentService.setName("$promoted$" + compositeService.getName()); - promotedComponent.getServices().add(newComponentService); - newComponentService.setService(promotedService.getService()); - newComponentService.getBindings().addAll(compositeService.getBindings()); - newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); - if (compositeService.getInterfaceContract() != null && compositeService.getInterfaceContract() - .getCallbackInterface() != null) { - newComponentService.setCallback(assemblyFactory.createCallback()); - newComponentService.getCallback().getBindings() - .addAll(compositeService.getCallback().getBindings()); - } - - // Change the composite service to now promote the newly - // created component service directly - compositeService.setPromotedComponent(promotedComponent); - compositeService.setPromotedService(newComponentService); - } - } - return composite; - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java deleted file mode 100644 index 54f6d0e850..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * creates endpoint models for component services. - */ -public class EndpointBuilderImpl { - private AssemblyFactory assemblyFactory; - - public EndpointBuilderImpl(ExtensionPointRegistry registry) { - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - } - - /** - * Create endpoint models for all component services. - * - * @param composite - the top-level composite to build the models for - * @param definitions - * @param monitor - a Monitor for logging errors - */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - - processComponentServices(composite); - return composite; - - } // end method build - - private void processComponentServices(Composite composite) { - - for (Component component : composite.getComponents()) { - - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processComponentServices((Composite)implementation); - } - - // create an endpoint for each component service binding - for (ComponentService service : component.getServices()) { - - /* change to finding the promoted component and service - * when the wire is created as storing them here leads to - * the wrong URI being calculated - Component endpointComponent = component; - ComponentService endpointService = service; - - // TODO - EPR - We maintain all endpoints at the right level now - // but endpoints for promoting services must point down - // to the services they promote. - if (service.getService() instanceof CompositeService) { - CompositeService compositeService = (CompositeService)service.getService(); - endpointService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - endpointComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService); - } // end if - */ - - for (Binding binding : service.getBindings()) { - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setBinding(binding); - endpoint.setUnresolved(false); - service.getEndpoints().add(endpoint); - } // end for - } - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java deleted file mode 100644 index 0e810e8ce5..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java +++ /dev/null @@ -1,840 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.Wire; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; - -/** - * Creates endpoint reference models. - */ -public class EndpointReferenceBuilderImpl { - - private Monitor monitor; - private AssemblyFactory assemblyFactory; - private InterfaceContractMapper interfaceContractMapper; - - public EndpointReferenceBuilderImpl(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - } - - /** - * Create endpoint references for all component references. - * - * @param composite - */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - this.monitor = monitor; - - // process component services - processComponentReferences(composite); - return composite; - } - - private void processComponentReferences(Composite composite) { - - monitor.pushContext("Composite: " + composite.getName().toString()); - try { - // Index components, services and references - Map<String, Component> components = new HashMap<String, Component>(); - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); - indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - - // Connect component references as described in wires - connectWires(composite, componentServices, componentReferences, monitor); - - // create endpoint references for each component's references - for (Component component : composite.getComponents()) { - monitor.pushContext("Component: " + component.getName()); - - try { - - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processComponentReferences((Composite)implementation); - } - - // create endpoint references to represent the component reference - for (ComponentReference reference : component.getReferences()) { - createReferenceEndpointReferences(composite, - component, - reference, - components, - componentServices); - - // fix up links between endpoints and endpoint references that represent callbacks - for (ComponentService service : component.getServices()) { - if ((service.getInterfaceContract() != null) && (service.getInterfaceContract() - .getCallbackInterface() != null)) { - if (reference.getName().equals(service.getName())) { - for (Endpoint endpoint : service.getEndpoints()) { - endpoint.getCallbackEndpointReferences().addAll(reference - .getEndpointReferences()); - } - break; - } // end if - } // end if - } // end for - } // end for - - // Validate that references are wired or promoted, according - // to their multiplicity - validateReferenceMultiplicity(composite, component); - - } finally { - monitor.popContext(); - } - } // end for - - } finally { - monitor.popContext(); - } - - } // end method processCompoenntReferences - - protected void indexComponentsServicesAndReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences) { - - for (Component component : composite.getComponents()) { - - // Index components by name - components.put(component.getName(), component); - - ComponentService nonCallbackService = null; - int nonCallbackServices = 0; - for (ComponentService componentService : component.getServices()) { - - // Index component services by component name / service name - String uri = component.getName() + '/' + componentService.getName(); - componentServices.put(uri, componentService); - - // TODO - EPR - $promoted$ no longer used but it doesn't do any - // harm here - boolean promotedService = false; - if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) { - promotedService = true; - } - - // count how many non-callback, non-promoted services there are - // if there is only one the component name also acts as the - // service name - if ((!componentService.isForCallback()) && (!promotedService)) { - - // Check how many non callback non-promoted services we have - if (nonCallbackServices == 0) { - nonCallbackService = componentService; - } - nonCallbackServices++; - } - - } - - if (nonCallbackServices == 1) { - // If we have a single non callback service, index it by - // component name as well - componentServices.put(component.getName(), nonCallbackService); - } - - // Index references by component name / reference name - for (ComponentReference componentReference : component.getReferences()) { - String uri = component.getName() + '/' + componentReference.getName(); - componentReferences.put(uri, componentReference); - } - } - } - - /** - * Resolve wires and connect the sources to their targets - * - * @param composite - * @param componentServices - * @param componentReferences - * @param problems - */ - private void connectWires(Composite composite, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences, - Monitor monitor) { - - // For each wire, resolve the source reference, the target service, and - // add it to the list of targets of the reference - List<Wire> wires = composite.getWires(); - for (int i = 0, n = wires.size(); i < n; i++) { - Wire wire = wires.get(i); - - ComponentReference resolvedReference; - ComponentService resolvedService; - - // Resolve the source reference - ComponentReference source = wire.getSource(); - if (source != null && source.isUnresolved()) { - resolvedReference = componentReferences.get(source.getName()); - if (resolvedReference != null) { - wire.setSource(resolvedReference); - } else { - Monitor.warning(monitor, this, "assembly-validation-messages", "WireSourceNotFound", source - .getName()); - } - } else { - resolvedReference = wire.getSource(); - } - - // Resolve the target service - ComponentService target = wire.getTarget(); - if (target != null && target.isUnresolved()) { - resolvedService = componentServices.get(target.getName()); - if (resolvedService != null) { - wire.setTarget(target); - } else { - Monitor.warning(monitor, this, "assembly-validation-messages", "WireTargetNotFound", target - .getName()); - } - } else { - resolvedService = wire.getTarget(); - } - - // Add the target service to the list of targets of the - // reference - if (resolvedReference != null && resolvedService != null) { - // Check that the target component service provides - // a superset of - // the component reference interface - if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper - .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) { - - //resolvedReference.getTargets().add(resolvedService); - if (wire.isReplace()) { - resolvedReference.getTargets().clear(); - } - resolvedReference.getTargets().add(wire.getTarget()); - } else { - Monitor.warning(monitor, this, "assembly-validation-messages", "WireIncompatibleInterface", source - .getName(), target.getName()); - } - } - } - - // Clear the list of wires - composite.getWires().clear(); - } - - private void createReferenceEndpointReferences(Composite composite, - Component component, - ComponentReference reference, - Map<String, Component> components, - Map<String, ComponentService> componentServices) { - - monitor.pushContext("Reference: " + reference.getName()); - - // Get reference targets - List<ComponentService> refTargets = getReferenceTargets(reference); - if (reference.getAutowire() == Boolean.TRUE && reference.getTargets().isEmpty()) { - - // Find suitable targets in the current composite for an - // autowired reference - Multiplicity multiplicity = reference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - - // Tuscany specific selection of the first autowire reference - // when there are more than one (ASM_60025) - if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && (reference - .getEndpointReferences().size() != 0)) { - break; - } - - // Prevent autowire connecting to self - if (targetComponent == component) - continue; - - for (ComponentService targetComponentService : targetComponent.getServices()) { - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - - // Stop with the first match for 0..1 and 1..1 references - if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { - break; - } // end if - } // end if - } // end for - } // end for - - if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { - if (reference.getEndpointReferences().size() == 0) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "NoComponentReferenceTarget", - reference.getName()); - } - } - - setSingleAutoWireTarget(reference); - - } else if (!refTargets.isEmpty()) { - // Check that the component reference does not mix the use of endpoint references - // specified via the target attribute with the presence of binding elements - if (bindingsIdentifyTargets(reference)) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceEndPointMixWithTarget", - composite.getName().toString(), - component.getName(), - reference.getName()); - } - - // Resolve targets specified on the component reference - for (ComponentService target : refTargets) { - - String targetName = getComponentServiceName(target.getName()); - String bindingName = getBindingName(target.getName()); - ComponentService targetComponentService = componentServices.get(targetName); - - Component targetComponent = getComponentFromTargetName(components, targetName); - - if (targetComponentService != null) { - // Check that target component service provides a superset of the component reference interface - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - - if (bindingName != null) { - // the user has selected a binding as part of the target name - Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()) { - if (tmp.getName().equals(bindingName)) { - targetBinding = tmp; - continue; - } - } - - if (targetBinding != null) { - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, - targetComponentService, - targetBinding, - true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - // relying on the registry here to resolve the real endpoint - reference.getEndpointReferences().add(endpointRef); - - } else { - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", - composite.getName().toString(), - targetName); - } - - } else { - // the user hasn't selected a binding as part of the target name - - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef - .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - } - } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleInterface", - composite.getName().toString(), - component.getName() + "." + reference.getName(), - targetName); - } - } else { - // add an unresolved endpoint reference with an unresolved endpoint to go with it - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", - composite.getName().toString(), - targetName); - } // end if - } // end for - } // end if - - // if no endpoints have found so far the bindings hold the targets. - if (reference.getEndpointReferences().isEmpty()) { - for (Binding binding : reference.getBindings()) { - - String uri = binding.getURI(); - - // user hasn't put a uri on the binding so it's not a target name and the assumption is that - // the target is established via configuration of the binding element itself - if (uri == null) { - // Regular forward references are UNWIRED with no endpoint if they have an SCABinding with NO targets - // and NO URI set - but Callbacks with an SCABinding are wired and need an endpoint - if (!reference.isForCallback() && (binding instanceof SCABinding)) - continue; - - // create endpoint reference for manually configured bindings with a resolved endpoint to - // signify that this reference is pointing at some unwired endpoint - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - if (binding instanceof SCABinding) { - // Assume that the system needs to resolve this binding later as - // it's the SCA binding - endpointRef.setTargetEndpoint(createEndpoint(true)); - endpointRef.setStatus(EndpointReference.NOT_CONFIGURED); - } else { - // The user has configured a binding so assume they know what - // they are doing and mark in as already resolved. - endpointRef.setTargetEndpoint(createEndpoint(false)); - endpointRef.setStatus(EndpointReference.RESOLVED_BINDING); - } - endpointRef.setRemote(true); - reference.getEndpointReferences().add(endpointRef); - continue; - } // end if - - // user might have put a local target name in the uri - see if it refers to a target we know about - // - if it does the reference binding will be matched with a service binding - // - if it doesn't it is assumed to be an external reference - if (uri.startsWith("/")) { - uri = uri.substring(1); - } - - String targetName = getComponentServiceName(uri); - String bindingName = getBindingName(uri); - - // Resolve the target component and service - ComponentService targetComponentService = componentServices.get(targetName); - Component targetComponent = getComponentFromTargetName(components, targetName); - - // If the binding URI matches a component in the composite, configure an endpoint reference with - // this component as the target. - // If not, the binding URI is assumed to reference an external service - if (targetComponentService != null) { - - // Check that the target component service provides - // a superset of the component reference interface - if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null) { - // the user has selected a binding as part of the target name - Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()) { - if (tmp.getName().equals(bindingName)) { - targetBinding = tmp; - continue; - } - } - - if (targetBinding != null) { - EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, - targetComponentService, - targetBinding, - true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - // relying on the registry here to resolve the real endpoint - reference.getEndpointReferences().add(endpointRef); - - } else { - EndpointReference endpointRef = createEndpointRef(component, reference, true); - endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); - reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", - composite.getName().toString(), - targetName); - } - - } else { - // create endpoint reference with dummy endpoint which will be replaced when policies - // are matched and bindings are configured later - EndpointReference endpointRef = - createEndpointRef(component, reference, binding, null, false); - endpointRef - .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); - endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); - reference.getEndpointReferences().add(endpointRef); - } - } else { - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleInterface", - composite.getName().toString(), - reference.getName(), - uri); - } - } else { - // create endpoint reference for manually configured bindings with resolved endpoint - // to signify that this reference is pointing at some unwired endpoint. The endpoint - // is given the configured binding as a representation of the endpoint configuration. - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - Endpoint endpoint = createEndpoint(false); - endpoint.setBinding(binding); - endpointRef.setTargetEndpoint(endpoint); - endpointRef.setRemote(true); - endpointRef.setStatus(EndpointReference.RESOLVED_BINDING); - reference.getEndpointReferences().add(endpointRef); - } // end if - } - } - - monitor.popContext(); - - } // end method - - private void validateReferenceMultiplicity(Composite composite, Component component) { - for (ComponentReference componentReference : component.getReferences()) { - if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), - componentReference.getEndpointReferences())) { - if (componentReference.getEndpointReferences().isEmpty()) { - - // No error if the reference is promoted out of the current composite - boolean promoted = false; - for (Reference reference : composite.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - if (compositeReference.getPromotedReferences().contains(componentReference)) { - promoted = true; - break; - } - } - if (!promoted && !componentReference.isForCallback() && !componentReference.isWiredByImpl()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceWithoutTargets", - composite.getName().toString(), - componentReference.getName()); - } - } else { - // no error if reference is autowire and more targets - // than multiplicity have been found - if (componentReference.getAutowire() == Boolean.TRUE) { - break; - } - - Monitor.error(monitor, - this, - "assembly-validation-messages", - "TooManyReferenceTargets", - componentReference.getName()); - } - } - } - - } - - /** - * Evaluates whether the bindings attached to a reference identify one or more target services. - * @param reference - the reference - * @return true if the bindings identify a target, false otherwise - */ - private boolean bindingsIdentifyTargets(ComponentReference reference) { - for (Binding binding : reference.getBindings()) { - // <binding.sca without a URI does not identify a target - if ((binding instanceof SCABinding) && (binding.getURI() == null)) - continue; - // any other binding implies a target - // TODO Processing for other binding types - return true; - } // end for - return false; - } // end bindingsIdentifyTargets - - /** - * Helper method which obtains a list of targets for a reference - * @param reference - Component reference - * @return - the list of targets, which will be empty if there are no targets - */ - private List<ComponentService> getReferenceTargets(ComponentReference reference) { - List<ComponentService> theTargets = reference.getTargets(); - if (theTargets.isEmpty()) { - // Component reference list of targets is empty, try the implementation reference - if (reference.getReference() != null) { - theTargets = reference.getReference().getTargets(); - } // end if - } // end if - return theTargets; - } // end method getReferenceTargets - - /** - * Target names can take the form - * component/service/binding - * This extracts the component/service part - * - * @param targetName - * @return String the component/service name - */ - private String getComponentServiceName(String targetName) { - String[] parts = targetName.split("/"); - - if (parts.length > 1) { - return parts[0] + "/" + parts[1]; - } else { - return parts[0]; - } - } - - /** - * Target names can take the form - * component/service/binding - * This extracts the binding part and returns - * it. If there is no binding part it returns null - * - * @param targetName - * @return String the binding name or null if there is no binding name - */ - private String getBindingName(String targetName) { - String[] parts = targetName.split("/"); - - if (parts.length == 3) { - return parts[2]; - } else { - return null; - } - } - - /** - * Helper method that finds the Component given a target name - * @param components - * @param targetName - * @return the component - */ - private Component getComponentFromTargetName(Map<String, Component> components, String targetName) { - Component theComponent; - int s = targetName.indexOf('/'); - if (s == -1) { - theComponent = components.get(targetName); - } else { - theComponent = components.get(targetName.substring(0, s)); - } - return theComponent; - } // end method getComponentFromTargetName - - /** - * Helper method to create an Endpoint Reference - * @param component - * @param reference - * @param binding - * @param endpoint - * @param unresolved - * @return the endpoint reference - */ - private EndpointReference createEndpointRef(Component component, - ComponentReference reference, - Binding binding, - Endpoint endpoint, - boolean unresolved) { - EndpointReference endpointRef = createEndpointRef(component, reference, unresolved); - endpointRef.setBinding(binding); - endpointRef.setTargetEndpoint(endpoint); - return endpointRef; - } // end method - - /** - * Helper method to create an Endpoint Reference - * @param component - * @param reference - * @param unresolved - * @return the endpoint reference - */ - private EndpointReference createEndpointRef(Component component, ComponentReference reference, boolean unresolved) { - EndpointReference endpointRef = assemblyFactory.createEndpointReference(); - endpointRef.setComponent(component); - endpointRef.setReference(reference); - endpointRef.setUnresolved(unresolved); - return endpointRef; - } // end method createEndpointRef - - /** - * Helper method to create an endpoint - * @param component - * @param service - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, ComponentService service, boolean unresolved) { - Endpoint endpoint = createEndpoint(unresolved); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an endpoint - * @param component - * @param service - * @param binding - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, ComponentService service, Binding binding, boolean unresolved) { - Endpoint endpoint = createEndpoint(unresolved); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setBinding(binding); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an Endpoint - * @param unresolved - * @return the endpoint - */ - private Endpoint createEndpoint(boolean unresolved) { - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setUnresolved(unresolved); - return endpoint; - } // end method createEndpoint - - /** - * Helper method to create an Endpoint - * - * @param component The component that owns the reference - * @param targetName It can be one of the following formats - * <ul> - * <li>componentName - * <li>componentName/serviceName - * <li>componentName/serviceName/bindingName - * </ul> - * @return the endpoint - */ - private Endpoint createEndpoint(Component component, String targetName) { - String[] parts = targetName.split("/"); - if (parts.length < 1 || parts.length > 3) { - throw new IllegalArgumentException("Invalid target URI: " + targetName); - } - - // Find the parent uri - String uri = component.getURI(); - int index = uri.lastIndexOf('/'); - if (index == -1) { - uri = ""; - } else { - uri = uri.substring(0, index); - } - - if (parts.length >= 1) { - // Append the target component name - if (uri.length() == 0) { - uri = parts[0]; - } else { - uri = uri + "/" + parts[0]; - } - } - if (parts.length == 3) { - // <componentURI>#service-binding(serviceName/bindingName) - uri = uri + "#service-binding(" + parts[1] + "/" + parts[2] + ")"; - } else if (parts.length == 2) { - // <componentURI>#service(serviceName) - uri = uri + "#service(" + parts[1] + ")"; - } - - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setUnresolved(true); - endpoint.setURI(uri); - return endpoint; - } // end method createEndpoint - - /** - * ASM_5021: where a <reference/> of a <component/> has @autowire=true - * and where the <reference/> has a <binding/> child element which - * declares a single target service, the reference is wired only to - * the single service identified by the <wire/> element - */ - private void setSingleAutoWireTarget(ComponentReference reference) { - if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null - && reference.getBindings().size() == 1) { - String uri = reference.getBindings().get(0).getURI(); - if (uri != null) { - if (uri.indexOf('/') > -1) { - // TODO: must be a way to avoid this fiddling - int i = uri.indexOf('/'); - String c = uri.substring(0, i); - String s = uri.substring(i + 1); - uri = c + "#service(" + s + ")"; - } - for (EndpointReference er : reference.getEndpointReferences()) { - if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { - reference.getEndpointReferences().clear(); - reference.getEndpointReferences().add(er); - return; - } - } - } - } - } - -} // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java deleted file mode 100644 index 99c5947ab3..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { - private static final Logger logger = Logger.getLogger(ModelBuilderImpl.class.getName()); - private CompositeBuilder compositeIncludeBuilder; - private CompositeBuilder compositeCloneBuilder; - private CompositeComponentTypeBuilderImpl compositeComponentTypeBuilder; - private ComponentBuilderImpl componentBuilder; - - private BindingURIBuilderImpl bindingURIBuilder; - private ComponentServiceBindingBuilderImpl componentServiceBindingBuilder; - private ComponentReferenceBindingBuilderImpl componentReferenceBindingBuilder; - private EndpointBuilderImpl endpointBuilder; - private EndpointReferenceBuilderImpl endpointReferenceBuilder; - private ComponentReferencePromotionBuilderImpl componentReferencePromotionBuilder; - private CompositePolicyBuilderImpl compositePolicyBuilder; - - /** - * Constructs a new composite builder. - * - * @param registry the extension point registry - */ - public ModelBuilderImpl(ExtensionPointRegistry registry) { - - compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); - compositeCloneBuilder = new CompositeCloneBuilderImpl(); - - compositeComponentTypeBuilder = new CompositeComponentTypeBuilderImpl(registry); - componentBuilder = new ComponentBuilderImpl(registry); - - compositeComponentTypeBuilder.setComponentBuilder(componentBuilder); - componentBuilder.setComponentTypeBuilder(compositeComponentTypeBuilder); - - bindingURIBuilder = new BindingURIBuilderImpl(registry); - componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(registry); - componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(registry); - endpointBuilder = new EndpointBuilderImpl(registry); - endpointReferenceBuilder = new EndpointReferenceBuilderImpl(registry); - componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(registry); - compositePolicyBuilder = new CompositePolicyBuilderImpl(registry); - - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.CompositeBuilder"; - } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) - throws CompositeBuilderException { - return build(composite, definitions, null, monitor); - } - - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - - try { - // Clone the composites that are included or referenced in implementation.composite - composite = compositeCloneBuilder.build(composite, definitions, monitor); - - // Collect and fuse includes. Copy all of the components - // out of the included composite into the including composite - // and discards the included composite - composite = compositeIncludeBuilder.build(composite, definitions, monitor); - - // need to apply policy external attachment - - - // Process the implementation hierarchy by calculating the component type - // for the top level implementation (composite). This has the effect of - // recursively calculating component types and configuring the - // components that depend on them - compositeComponentTypeBuilder.createComponentType(composite); - - // create the runtime model by updating the static model we have just - // created. This involves things like creating - // component URIs - // binding URIs - // binding specific build processing - // callback references - currently done in static pass - // callback services - currently done in static pass - // Endpoints - // Endoint References - // Policies - // TODO - called here at the moment but we could have a separate build phase - // to call these. Also we need to re-org these builders - bindingURIBuilder.configureBindingURIsAndNames(composite, definitions, monitor); - composite = componentServiceBindingBuilder.build(composite, definitions, monitor); // binding specific build - composite = componentReferenceBindingBuilder.build(composite, definitions, monitor); // binding specific build - endpointBuilder.build(composite, definitions, monitor); - endpointReferenceBuilder.build(composite, definitions, monitor); - composite = componentReferencePromotionBuilder.build(composite, definitions, monitor); // move into the static build? - composite = compositePolicyBuilder.build(composite, definitions, monitor); // the rest of the policy processing? - return composite; - } catch (Exception e) { - throw new CompositeBuilderException("Exception while building model " + composite.getName(), e); - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java deleted file mode 100644 index 27f768fc53..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -/** - * Exception to be throw for invalid policy intents / policysets - * - * @version $Rev$ $Date$ - */ -public class PolicyConfigurationException extends Exception { - private static final long serialVersionUID = 506979037642587755L; - - public PolicyConfigurationException(String message) { - super(message); - } - - public PolicyConfigurationException(Throwable e) { - super(e); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java deleted file mode 100644 index 12450a889d..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Base; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.IntentMap; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.apache.tuscany.sca.policy.util.PolicyComputationUtils; -import org.apache.tuscany.sca.policy.util.PolicyValidationException; -import org.apache.tuscany.sca.policy.util.PolicyValidationUtils; - -/** - * This class contains policy computation methods common to computing implementation and binding policies - * - * @version $Rev$ $Date$ - */ -abstract class PolicyConfigurationUtil { - - private static List<Intent> computeInheritableIntents(ExtensionType attachPointType, List<Intent> inheritableIntents) - throws PolicyValidationException { - List<Intent> validInheritableIntents = new ArrayList<Intent>(); - - //expand profile intents in inherited intents - PolicyComputationUtils.expandProfileIntents(inheritableIntents); - - //validate if inherited intent applies to the attachpoint (binding / implementation) and - //only add such intents to the attachpoint (binding / implementation) - for (Intent intent : inheritableIntents) { - if (!intent.isUnresolved()) { - for (ExtensionType constrained : intent.getConstrainedTypes()) { - if (PolicyValidationUtils.isConstrained(constrained, attachPointType)) { - validInheritableIntents.add(intent); - break; - } - } - } else { - throw new PolicyValidationException("Policy Intent '" + intent.getName() - + "' is not defined in this domain"); - } - } - - return validInheritableIntents; - } - - private static void normalizeIntents(PolicySubject intentAttachPoint) { - //expand profile intents specified in the attachpoint (binding / implementation) - PolicyComputationUtils.expandProfileIntents(intentAttachPoint.getRequiredIntents()); - - //remove duplicates and ... - //where qualified form of intent exists retain it and remove the qualifiable intent - filterDuplicatesAndQualifiableIntents(intentAttachPoint); - } - - private static void trimInherentlyProvidedIntents(ExtensionType attachPointType, List<Intent> intents) { - //exclude intents that are inherently supported by the - //attachpoint-type (binding-type / implementation-type) - List<Intent> requiredIntents = new ArrayList<Intent>(intents); - for (Intent intent : requiredIntents) { - if (isProvidedInherently(attachPointType, intent)) { - intents.remove(intent); - } - } - } - - private static List<PolicySet> computeInheritablePolicySets(List<PolicySet> inheritablePolicySets) - throws PolicyValidationException { - // FIXME: - return inheritablePolicySets; - } - - private static void normalizePolicySets(PolicySubject subject) { - //get rid of duplicate entries - Set<PolicySet> policySetTable = new HashSet<PolicySet>(subject.getPolicySets()); - - subject.getPolicySets().clear(); - subject.getPolicySets().addAll(policySetTable); - - //expand profile intents - for (PolicySet policySet : subject.getPolicySets()) { - PolicyComputationUtils.expandProfileIntents(policySet.getProvidedIntents()); - } - } - - private static void trimProvidedIntents(List<Intent> requiredIntents, List<PolicySet> policySets) { - for (PolicySet policySet : policySets) { - trimProvidedIntents(requiredIntents, policySet); - } - } - - private static void determineApplicableDomainPolicySets(List<PolicySet> applicablePolicySets, - PolicySubject policySetAttachPoint, - ExtensionType intentAttachPointType) { - - if (policySetAttachPoint.getRequiredIntents().size() > 0) { - - // form a list of all intents required by the attach point - List<Intent> combinedTargetIntents = new ArrayList<Intent>(); - combinedTargetIntents.addAll(policySetAttachPoint.getRequiredIntents()); - for (PolicySet targetPolicySet : policySetAttachPoint.getPolicySets()) { - combinedTargetIntents.addAll(PolicyComputationUtils.findAndExpandProfileIntents(targetPolicySet - .getProvidedIntents())); - } - - //since the set of applicable policysets for this attachpoint is known - //we only need to check in that list if there is a policyset that matches - for (PolicySet policySet : applicablePolicySets) { - // do not use the policy set if it provides intents that conflict with required intents - boolean conflict = false; - List<Intent> providedIntents = - PolicyComputationUtils.findAndExpandProfileIntents(policySet.getProvidedIntents()); - checkConflict: for (Intent intent : providedIntents) { - for (Intent excluded : intent.getExcludedIntents()) { - if (combinedTargetIntents.contains(excluded)) { - conflict = true; - break checkConflict; - } - } - } - if (conflict) - continue; - int prevSize = policySetAttachPoint.getRequiredIntents().size(); - trimProvidedIntents(policySetAttachPoint.getRequiredIntents(), policySet); - // if any intent was trimmed off, then this policyset must - // be attached to the intent attachpoint's policyset - if (prevSize != policySetAttachPoint.getRequiredIntents().size()) { - policySetAttachPoint.getPolicySets().add(policySet); - } - } - } - } - - private static boolean isProvidedInherently(ExtensionType attachPointType, Intent intent) { - return (attachPointType != null && ((attachPointType.getAlwaysProvidedIntents() != null && attachPointType - .getAlwaysProvidedIntents().contains(intent)) || (attachPointType.getMayProvidedIntents() != null && attachPointType - .getMayProvidedIntents().contains(intent)))); - } - - private static void trimProvidedIntents(List<Intent> requiredIntents, PolicySet policySet) { - for (Intent providedIntent : policySet.getProvidedIntents()) { - if (requiredIntents.contains(providedIntent)) { - requiredIntents.remove(providedIntent); - } - } - - for (IntentMap intentMap : policySet.getIntentMaps()) { - if (requiredIntents.contains(intentMap.getProvidedIntent())) { - requiredIntents.remove(intentMap.getProvidedIntent()); - } - } - } - - private static void filterDuplicatesAndQualifiableIntents(PolicySubject intentAttachPoint) { - //remove duplicates - Map<QName, Intent> intentsTable = new HashMap<QName, Intent>(); - for (Intent intent : intentAttachPoint.getRequiredIntents()) { - intentsTable.put(intent.getName(), intent); - } - - //where qualified form of intent exists retain it and remove the qualifiable intent - Map<QName, Intent> intentsTableCopy = new HashMap<QName, Intent>(intentsTable); - //if qualified form of intent exists remove the unqualified form - for (Intent intent : intentsTableCopy.values()) { - if (intent.getQualifiableIntent() != null) { - if (intentsTable.get(intent.getQualifiableIntent().getName()) != null) { - intentsTable.remove(intent.getQualifiableIntent().getName()); - } - } - } - intentAttachPoint.getRequiredIntents().clear(); - intentAttachPoint.getRequiredIntents().addAll(intentsTable.values()); - } - - static void computeBindingIntentsAndPolicySets(Contract contract) throws PolicyValidationException { - for (Binding binding : contract.getBindings()) { - if (binding instanceof PolicySubject) { - PolicySubject policiedBinding = (PolicySubject)binding; - computeIntents((PolicySubject)binding, contract.getRequiredIntents()); - - computePolicySets(policiedBinding, contract.getPolicySets()); - - PolicyComputationUtils.checkForMutuallyExclusiveIntents(policiedBinding.getRequiredIntents(), - policiedBinding.getPolicySets(), - policiedBinding.getExtensionType(), - contract.getName()); - } - } - - if (contract.getCallback() != null) { - for (Binding binding : contract.getCallback().getBindings()) { - if (binding instanceof PolicySubject) { - PolicySubject policiedBinding = (PolicySubject)binding; - computeIntents((PolicySubject)binding, contract.getCallback().getRequiredIntents()); - - computePolicySets(policiedBinding, contract.getCallback().getPolicySets()); - - PolicyComputationUtils.checkForMutuallyExclusiveIntents(policiedBinding.getRequiredIntents(), - policiedBinding.getPolicySets(), - policiedBinding.getExtensionType(), - contract.getName() + " callback"); - - } - } - } - } - - private static void computeIntents(PolicySubject policiedBinding, List<Intent> inheritedIntents) - throws PolicyValidationException { - //since the parent component could also contain intents that apply to implementation - //and binding elements within, we filter out only those that apply to this binding type - List<Intent> prunedIntents = computeInheritableIntents(policiedBinding.getExtensionType(), inheritedIntents); - policiedBinding.getRequiredIntents().addAll(prunedIntents); - - normalizeIntents(policiedBinding); - } - - private static void computePolicySets(PolicySubject policiedBinding, List<PolicySet> inheritedPolicySets) - throws PolicyValidationException { - - List<PolicySet> prunedPolicySets = computeInheritablePolicySets(inheritedPolicySets); - policiedBinding.getPolicySets().addAll(prunedPolicySets); - normalizePolicySets(policiedBinding); - } - - static void determineApplicableBindingPolicySets(Contract source, Contract target) - throws PolicyConfigurationException { - List<Intent> intentsCopy = null; - for (Binding aBinding : source.getBindings()) { - if (aBinding instanceof PolicySubject) { - PolicySubject policiedBinding = (PolicySubject)aBinding; - ExtensionType bindingType = policiedBinding.getExtensionType(); - - intentsCopy = new ArrayList<Intent>(policiedBinding.getRequiredIntents()); - // add the target component's intents to the reference binding - if (target != null) { - for (Intent intent : target.getRequiredIntents()) { - if (!policiedBinding.getRequiredIntents().contains(intent)) { - for (ExtensionType constrained : intent.getConstrainedTypes()) { - if (bindingType != null && bindingType.getType().getNamespaceURI().equals(constrained - .getType().getNamespaceURI()) - && bindingType.getType().getLocalPart().startsWith(constrained.getType() - .getLocalPart())) { - policiedBinding.getRequiredIntents().add(intent); - break; - } - } - } - } - } - - trimInherentlyProvidedIntents(policiedBinding.getExtensionType(), policiedBinding.getRequiredIntents()); - trimProvidedIntents(policiedBinding.getRequiredIntents(), policiedBinding.getPolicySets()); - - // determine additional policysets that match remaining intents - // TODO: resolved to domain policy registry and attach suitable - // policy sets to the binding - // for now using the SCA Definitions instead of registry - // if there are intents that are not provided by any policy set - // throw a warning - determineApplicableDomainPolicySets(source, policiedBinding); - - //the intents list could have been trimmed when matching for policysets - //since the bindings may need the original set of intents we copy that back - policiedBinding.getRequiredIntents().clear(); - policiedBinding.getRequiredIntents().addAll(intentsCopy); - - } - } - } - - private static void determineApplicableDomainPolicySets(Contract contract, PolicySubject policiedBinding) - throws PolicyConfigurationException { - // FIXME: - /* - //if ( domainPolicySets != null) { - determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(), - policiedBinding, - policiedBinding.getExtensionType()); - - if ( policiedBinding.getRequiredIntents().size() > 0 ) { - if ( contract instanceof Service ) { - throw new PolicyConfigurationException("The following are unfulfilled intents for " + - "binding in service - " + contract.getName() + "\nUnfulfilled Intents = " + - policiedBinding.getRequiredIntents()); - } else { - throw new PolicyConfigurationException("The are unfulfilled intents for " + - "binding in reference - " + contract.getName() + "\nUnfulfilled Intents = " + - policiedBinding.getRequiredIntents()); - } - } - //} - */ - } - - private static void aggregateAndPruneApplicablePolicySets(List<PolicySet> source, List<PolicySet> target) { - target.addAll(source); - //strip duplicates - Hashtable<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>(); - for (PolicySet policySet : target) { - policySetTable.put(policySet.getName(), policySet); - } - - target.clear(); - target.addAll(policySetTable.values()); - } - - static <C extends Contract> void inheritDefaultPolicies(Base parent, List<C> contracts) { - - for (Contract contract : contracts) { - - // The contract inherits default policies from the parent composite/component. - if (parent instanceof PolicySubject) { - PolicyComputationUtils.addDefaultPolicies(((PolicySubject)parent).getRequiredIntents(), - ((PolicySubject)parent).getPolicySets(), - contract.getRequiredIntents(), - contract.getPolicySets()); - } - - // The contract's callback inherits default policies from the contract. - if (contract.getCallback() != null) { - PolicyComputationUtils.addDefaultPolicies(contract.getRequiredIntents(), - contract.getPolicySets(), - contract.getCallback().getRequiredIntents(), - contract.getCallback().getPolicySets()); - } - - } - } - - static void computeImplementationIntentsAndPolicySets(Implementation implementation, Component parent) - throws PolicyValidationException, PolicyConfigurationException { - PolicySubject policiedImplementation = (PolicySubject)implementation; - //since for an implementation the component has its policy intents and policysets its possible - //that there are some intents there that does not constrain the implementation.. so prune - List<Intent> prunedIntents = - computeInheritableIntents(policiedImplementation.getExtensionType(), parent.getRequiredIntents()); - parent.getRequiredIntents().clear(); - parent.getRequiredIntents().addAll(prunedIntents); - normalizeIntents(parent); - - List<PolicySet> prunedPolicySets = computeInheritablePolicySets(parent.getPolicySets()); - parent.getPolicySets().clear(); - parent.getPolicySets().addAll(prunedPolicySets); - normalizePolicySets(parent); - - PolicyComputationUtils.checkForMutuallyExclusiveIntents(parent.getRequiredIntents(), - parent.getPolicySets(), - policiedImplementation.getExtensionType(), - parent.getName()); - - determineApplicableImplementationPolicySets(parent); - - } - - private static void determineApplicableImplementationPolicySets(Component component) - throws PolicyConfigurationException { - List<Intent> intentsCopy = null; - if (component.getImplementation() instanceof PolicySubject) { - PolicySubject policiedImplementation = (PolicySubject)component.getImplementation(); - - intentsCopy = new ArrayList<Intent>(component.getRequiredIntents()); - trimInherentlyProvidedIntents(policiedImplementation.getExtensionType(), component.getRequiredIntents()); - trimProvidedIntents(component.getRequiredIntents(), component.getPolicySets()); - - //determine additional policysets that match remaining intents - //if there are intents that are not provided by any policy set throw a warning - //TODO: resolved to domain policy registry and attach suitable policy sets to the implementation - //...for now using the SCA Definitions instead of registry - //if ( domainPolicySets != null) { - - if (component.getRequiredIntents().size() > 0) { - throw new PolicyConfigurationException( - "The following are unfulfilled intents for component implementation - " + component - .getName() - + "\nUnfulfilled Intents = " - + component.getRequiredIntents()); - } - //} - - //the intents list could have been trimmed when matching for policysets - //since the bindings may need the original set of intents we copy that back - component.getRequiredIntents().clear(); - component.getRequiredIntents().addAll(intentsCopy); - } - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java deleted file mode 100644 index 3762cc6e77..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.w3c.dom.Node; - -/** - * A simple print utility class to help print model instances. - * - * @version $Rev$ $Date$ - */ -class PrintUtil { - private boolean useGetters = false; - private PrintWriter out; - private int indent; - - public PrintUtil(PrintWriter out, boolean useGetters) { - this.out = out; - this.useGetters = useGetters; - } - - public PrintUtil(OutputStream out) { - this.out = new PrintWriter(new OutputStreamWriter(out), true); - } - - void indent() { - for (int i = 0; i < indent; i++) { - out.print(" "); - } - } - - /** - * Print an object. - * - * @param object - */ - public void print(Object object) { - Set<Integer> objects = new HashSet<Integer>(); - print(object, objects); - } - - /** - * Print an object. - * - * @param object - */ - private void print(Object object, Set<Integer> printed) { - if (object == null) { - return; - } - int id = System.identityHashCode(object); - if (printed.contains(id)) { - - // If we've already printed an object, print just it's HashCode - indent(); - out.println(object.getClass().getName() + "@" + id); - } else { - printed.add(id); - try { - - // Print the object class name - indent(); - out.println(object.getClass().getSimpleName() + " {"); - - // Get the object's properties - ValueAccessor accessor = useGetters ? new PropertyAccessor(object) : new FieldAccessor(object); - for (int i = 0; i < accessor.size(); i++) { - try { - - // Get the value of each property - Object value = accessor.getValue(i); - if (value != null) { - - // Convert array value into a list - if (value.getClass().isArray()) { - value = Arrays.asList((Object[])value); - } - - // Print elements in a list - if (value instanceof List) { - if (!((List<?>)value).isEmpty()) { - indent++; - indent(); - out.println(accessor.getName(i) + "= ["); - - // Print each element, recursively - for (Object element : (List<?>)value) { - indent++; - print(element, printed); - indent--; - } - indent(); - out.println(" ]"); - indent--; - } - } else { - Class<?> valueClass = value.getClass(); - - // Print a primitive, java built in type or - // enum, using toString() - if (valueClass.isPrimitive() || valueClass.getName().startsWith("java.") - || valueClass.getName().startsWith("javax.") - || valueClass.isEnum()) { - if (!accessor.getName(i).equals("class")) { - if (!(Boolean.FALSE.equals(value))) { - indent++; - indent(); - out.println(accessor.getName(i) + "=" + value.toString()); - indent--; - } - } - } else if (value instanceof Node) { - indent++; - indent(); - out.println(accessor.getName(i) + "=" + value.toString()); - indent--; - } else { - - // Print an object, recursively - indent++; - indent(); - out.println(accessor.getName(i) + "= {"); - indent++; - print(value, printed); - indent--; - indent(); - out.println("}"); - indent--; - } - } - } - } catch (Exception e) { - } - } - indent(); - out.println("}"); - } catch (Exception e) { - indent(); - out.println(e); - } - } - } - - public static interface ValueAccessor { - int size(); - - String getName(int i); - - Object getValue(int i) throws Exception; - } - - /** - * Java field reflection based value accessor - */ - private static class FieldAccessor implements ValueAccessor { - - private Object object; - private List<Field> fields; - - public FieldAccessor(Object object) { - this.fields = getAllFields(object.getClass()); - this.object = object; - } - - public String getName(int i) { - return fields.get(i).getName(); - } - - public Object getValue(int i) throws Exception { - return fields.get(i).get(object); - } - - public int size() { - return fields.size(); - } - - } - - /** - * JavaBean-based value accessor - */ - private static class PropertyAccessor implements ValueAccessor { - - private Object object; - private PropertyDescriptor[] fields; - - public PropertyAccessor(Object object) throws IntrospectionException { - BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); - this.fields = beanInfo.getPropertyDescriptors(); - this.object = object; - } - - public String getName(int i) { - return fields[i].getName(); - } - - public Object getValue(int i) throws Exception { - Method getter = fields[i].getReadMethod(); - if (getter != null) { - return getter.invoke(object); - } - return null; - } - - public int size() { - return fields.length; - } - - } - - /** - * Returns a collection of fields declared by a class - * or one of its supertypes - */ - private static List<Field> getAllFields(Class<?> clazz) { - return getAllFields(clazz, new ArrayList<Field>()); - } - - /** - * Recursively evaluates the type hierarchy to return all fields - */ - private static List<Field> getAllFields(Class<?> clazz, List<Field> fields) { - if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) { - return fields; - } - fields = getAllFields(clazz.getSuperclass(), fields); - Field[] declaredFields = clazz.getDeclaredFields(); - for (final Field field : declaredFields) { - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - field.setAccessible(true); // ignore Java accessibility - return null; - } - }); - fields.add(field); - } - return fields; - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java deleted file mode 100644 index 7a91e4da18..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import static org.apache.tuscany.sca.assembly.Base.SCA11_NS; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.net.URLConnection; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Source; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.sax.SAXSource; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.InputSource; - -/** - * Utility class to deal with processing of component properties that are taking values from the parent - * composite's properties or an external file. - * - * @version $Rev$ $Date$ - */ -abstract class PropertyConfigurationUtil { - - /** - * Evaluate an XPath expression against a Property value, returning the result as a Property value - * @param node - the document root element of a Property value - * @param expression - the XPath expression - * @param documentBuilderFactory - a DOM document builder factory - * @return - a DOM Document representing the result of the evaluation as a Property value - * @throws XPathExpressionException - * @throws ParserConfigurationException - */ - private static Document evaluate(Document node, - XPathExpression expression, - DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException, - ParserConfigurationException { - - // The document element is a <sca:property/> element - Node property = node.getDocumentElement(); - // The first child of the <property/> element is a <value/> element - Node value = property.getFirstChild(); - - Node result = (Node)expression.evaluate(value, XPathConstants.NODE); - if (result == null) { - return null; - } - - if (result instanceof Document) { - return (Document)result; - } else { - Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); - Element newProperty = document.createElementNS(SCA11_NS, "property"); - - if (result.getNodeType() == Node.ELEMENT_NODE) { - // If the result is a <value/> element, use it directly in the result - newProperty.appendChild(document.importNode(result, true)); - } else { - // If the result is not a <value/> element, create a <value/> element to contain the result - Element newValue = document.createElementNS(SCA11_NS, "value"); - newValue.appendChild(document.importNode(result, true)); - newProperty.appendChild(newValue); - } // end if - document.appendChild(newProperty); - - return document; - } - } // end method evaluate - - private static Document loadFromFile(String file, TransformerFactory transformerFactory) - throws MalformedURLException, IOException, TransformerException, ParserConfigurationException { - URI uri = URI.create(file); - // URI resolution for relative URIs is done when the composite is resolved. - URL url = uri.toURL(); - URLConnection connection = url.openConnection(); - connection.setUseCaches(false); - InputStream is = null; - try { - is = connection.getInputStream(); - - Source streamSource = new SAXSource(new InputSource(is)); - DOMResult result = new DOMResult(); - javax.xml.transform.Transformer transformer = transformerFactory.newTransformer(); - transformer.transform(streamSource, result); - - Document document = (Document)result.getNode(); - - // TUSCANY-2377, Add a fake value element so it's consistent with - // the DOM tree loaded from inside SCDL - Element root = document.createElementNS(null, "value"); - root.appendChild(document.getDocumentElement()); - document.appendChild(root); - return document; - } finally { - if (is != null) { - is.close(); - } - } - } - - static void sourceComponentProperties(Map<String, Property> compositeProperties, - Component componentDefinition, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory) throws CompositeBuilderException, - ParserConfigurationException, XPathExpressionException, TransformerException, IOException { - - List<ComponentProperty> componentProperties = componentDefinition.getProperties(); - for (ComponentProperty aProperty : componentProperties) { - String source = aProperty.getSource(); - String file = aProperty.getFile(); - if (source != null) { - // $<name>/... - int index = source.indexOf('/'); - if (index == -1) { - // Tolerating $prop - source = source + "/"; - index = source.length() - 1; - } - if (source.charAt(0) == '$') { - String name = source.substring(1, index); - Property compositeProp = compositeProperties.get(name); - if (compositeProp == null) { - throw new CompositeBuilderException( - "The 'source' cannot be resolved to a composite property: " + source); - } - - Document compositePropDefValues = (Document)compositeProp.getValue(); - - // FIXME: How to deal with namespaces? - Document node = - evaluate(compositePropDefValues, aProperty.getSourceXPathExpression(), documentBuilderFactory); - - if (node != null) { - aProperty.setValue(node); - } - } else { - throw new CompositeBuilderException("The 'source' has an invalid value: " + source); - } - } else if (file != null) { - aProperty.setValue(loadFromFile(aProperty.getFile(), transformerFactory)); - - } - } - } - - private static class DOMNamespaceContext implements NamespaceContext { - private Node node; - - /** - * @param node - */ - public DOMNamespaceContext(Node node) { - super(); - this.node = node; - } - - public String getNamespaceURI(String prefix) { - if (prefix == null) { - throw new IllegalArgumentException("Prefix is null"); - } else if (XMLConstants.XML_NS_PREFIX.equals(prefix)) { - return XMLConstants.XML_NS_URI; - } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) { - return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; - } - String ns = node.lookupNamespaceURI(prefix); - return ns == null ? XMLConstants.NULL_NS_URI : ns; - } - - public String getPrefix(String namespaceURI) { - if (namespaceURI == null) { - throw new IllegalArgumentException("Namespace URI is null"); - } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { - return XMLConstants.XML_NS_PREFIX; - } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { - return XMLConstants.XMLNS_ATTRIBUTE; - } - return node.lookupPrefix(namespaceURI); - } - - public Iterator<?> getPrefixes(String namespaceURI) { - // Not implemented - if (namespaceURI == null) { - throw new IllegalArgumentException("Namespace URI is null"); - } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) { - return Arrays.asList(XMLConstants.XML_NS_PREFIX).iterator(); - } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) { - return Arrays.asList(XMLConstants.XMLNS_ATTRIBUTE).iterator(); - } - String prefix = getPrefix(namespaceURI); - if (prefix == null) { - return Collections.emptyList().iterator(); - } - return Arrays.asList(prefix).iterator(); - } - - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java deleted file mode 100644 index 3ea0bd289b..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.OptimizableBinding; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * This class encapsulates utility methods to deal with reference definitions - * - * @version $Rev$ $Date$ - */ -abstract class ReferenceConfigurationUtil { - - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private static void warning(Monitor monitor, String message, Object model, String... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(ReferenceConfigurationUtil.class.getName(), - "assembly-validation-messages", - Severity.WARNING, - model, - message, - (Object[])messageParameters); - monitor.problem(problem); - } - } - - static boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { - if (definedMul != overridenMul) { - switch (definedMul) { - case ZERO_N: - return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE - || overridenMul == Multiplicity.ONE_N; - case ONE_N: - return overridenMul == Multiplicity.ONE_ONE; - case ZERO_ONE: - return overridenMul == Multiplicity.ONE_ONE; - default: - return false; - } - } else { - return true; - } - } - - static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, List<EndpointReference> endpointReferences) { - - // In some tests multiplicity is not set - if (multiplicity == null) { - return true; - } - - // Count targets - int count = endpointReferences.size(); - - switch (multiplicity) { - case ZERO_N: - break; - case ZERO_ONE: - if (count > 1) { - return false; - } - break; - case ONE_ONE: - if (count != 1) { - return false; - } - break; - case ONE_N: - if (count < 1) { - return false; - } - break; - } - return true; - } - - /** - * Follow a reference promotion chain down to the innermost (non composite) - * component references. - * - * @param compositeReference - * @return - */ - static List<ComponentReference> getPromotedComponentReferences(CompositeReference compositeReference) { - List<ComponentReference> componentReferences = new ArrayList<ComponentReference>(); - collectPromotedComponentReferences(compositeReference, componentReferences); - return componentReferences; - } - - /** - * Follow a reference promotion chain down to the innermost (non composite) - * component references. - * - * @param compositeReference - * @param componentReferences - * @return - */ - private static void collectPromotedComponentReferences(CompositeReference compositeReference, - List<ComponentReference> componentReferences) { - for (ComponentReference componentReference : compositeReference.getPromotedReferences()) { - Reference reference = componentReference.getReference(); - if (reference instanceof CompositeReference) { - - // Continue to follow the reference promotion chain - collectPromotedComponentReferences((CompositeReference)reference, componentReferences); - - } else if (reference != null) { - - // Found a non-composite reference - componentReferences.add(componentReference); - } - } - } - - /** - * Override the bindings for a promoted reference from an outer component reference - * - * @param reference - the outer level reference - * @param promotedReference - the inner level promoted reference - */ - static void reconcileReferenceBindings(Reference reference, - ComponentReference promotedReference, - AssemblyFactory assemblyFactory, - Monitor monitor) { - - if (reference.getEndpointReferences().size() > 0) { - if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) { - // Override any existing wires for 0..1 and 1..1 multiplicity - promotedReference.getEndpointReferences().clear(); - // For 0..1 and 1..1, there should not be more than 1 endpoint reference - if (reference.getEndpointReferences().size() > 1) { - warning(monitor, "ComponentReferenceMoreWire", promotedReference, promotedReference.getName()); - } // end if - } // end if - // Clone the EndpointReferences from the outer level and add to the promoted reference - for (EndpointReference epRef : reference.getEndpointReferences()) { - EndpointReference epRefClone = copyHigherReference(epRef, promotedReference); - promotedReference.getEndpointReferences().add(epRefClone); - } // end for - } // end if - - Set<Binding> callbackBindings = new HashSet<Binding>(); - if (promotedReference.getCallback() != null) { - callbackBindings.addAll(promotedReference.getCallback().getBindings()); - } - if (reference.getCallback() != null) { - callbackBindings.addAll(reference.getCallback().getBindings()); - } - promotedReference.setCallback(assemblyFactory.createCallback()); - for (Binding binding : callbackBindings) { - if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { - promotedReference.getCallback().getBindings().add(binding); - } // end if - } // end for - } // end method reconcileReferenceBindings - - /** - * Copy a higher level EndpointReference down to a lower level reference which it promotes - * @param epRef - the endpoint reference - * @param promotedReference - the promoted reference - * @return - a copy of the EndpointReference with data merged from the promoted reference - */ - private static EndpointReference copyHigherReference(EndpointReference epRef, ComponentReference promotedReference) { - EndpointReference epRefClone = null; - try { - epRefClone = (EndpointReference)epRef.clone(); - } catch (Exception e) { - // Ignore (we know that EndpointReference2 can be cloned) - } // end try - // Copy across details of the inner reference - ComponentReference ref = epRefClone.getReference(); - //FIXME - epRefClone.setReference(promotedReference); - return epRefClone; - } // end copyHigherReference - -} // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java deleted file mode 100644 index 312be1b40e..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.assembly.builder.impl; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Service; - -/** - * This class encapsulates utility methods to deal with service definitions. - * - * @version $Rev$ $Date$ - */ -abstract class ServiceConfigurationUtil { - - /** - * Follow a service promotion chain down to the inner most (non composite) - * component service. - * - * @param topCompositeService - * @return - */ - static ComponentService getPromotedComponentService(CompositeService compositeService) { - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - Service service = componentService.getService(); - if (componentService.getName() != null && service instanceof CompositeService) { - - // Continue to follow the service promotion chain - return getPromotedComponentService((CompositeService)service); - - } else { - - // Found a non-composite service - return componentService; - } - } else { - - // No promoted service - return null; - } - } - - /** - * Follow a service promotion chain down to the innermost (non-composite) component. - * - * @param compositeService - * @return - */ - static Component getPromotedComponent(CompositeService compositeService) { - ComponentService componentService = compositeService.getPromotedService(); - if (componentService != null) { - Service service = componentService.getService(); - if (componentService.getName() != null && service instanceof CompositeService) { - - // Continue to follow the service promotion chain - return getPromotedComponent((CompositeService)service); - - } else { - - // Found a non-composite service - return compositeService.getPromotedComponent(); - } - } else { - - // No promoted service - return null; - } - } - -} diff --git a/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder b/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder deleted file mode 100644 index 30af6bf7e6..0000000000 --- a/java/sca/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.builder.CompositeBuilder +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-org.apache.tuscany.sca.assembly.builder.impl.ModelBuilderImpl;id=org.apache.tuscany.sca.assembly.builder.CompositeBuilder
-#org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;id=org.apache.tuscany.sca.assembly.builder.CompositeBuilder
diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java deleted file mode 100644 index 62141844cb..0000000000 --- a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder.impl; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.AbstractProperty; -import org.apache.tuscany.sca.assembly.AbstractReference; -import org.apache.tuscany.sca.assembly.AbstractService; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.ConstrainingType; -import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.TestBinding; -import org.apache.tuscany.sca.assembly.TestImplementation; -import org.apache.tuscany.sca.assembly.TestInterfaceContract; -import org.apache.tuscany.sca.assembly.Wire; -import org.junit.Test; - -/** - * @version $Rev$ $Date$ - */ -public class PrintUtilTestCase { - - private AssemblyFactory factory = new DefaultAssemblyFactory(); - - /** - * Create a composite - */ - Composite createComposite() { - Composite c = factory.createComposite(); - - Component c1 = createComponent("AccountServiceComponent1"); - c.getComponents().add(c1); - Component c2 = createComponent("AccountServiceComponent2"); - c.getComponents().add(c2); - - Wire w = factory.createWire(); - w.setSource(c1.getReferences().get(0)); - w.setTarget(c2.getServices().get(0)); - c.getWires().add(w); - - CompositeService cs = factory.createCompositeService(); - cs.setName("AccountService"); - cs.setPromotedService(c1.getServices().get(0)); - cs.setInterfaceContract(new TestInterfaceContract(factory)); - c.getServices().add(cs); - cs.getBindings().add(new TestBinding(factory)); - - CompositeReference cr = factory.createCompositeReference(); - cr.setName("StockQuoteService"); - cr.getPromotedReferences().add(c2.getReferences().get(1)); - cr.setInterfaceContract(new TestInterfaceContract(factory)); - c.getReferences().add(cr); - cr.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component - */ - Component createComponent(String name) { - Component c = factory.createComponent(); - c.setName(name); - - ConstrainingType constraint = createConstrainingType(); - c.setConstrainingType(constraint); - - Implementation i = new TestImplementation(factory); - c.setImplementation(i); - - ComponentProperty p = factory.createComponentProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - p.setProperty(i.getProperties().get(0)); - c.getProperties().add(p); - - ComponentReference ref1 = factory.createComponentReference(); - ref1.setName("accountDataService"); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setReference(i.getReferences().get(0)); - c.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - ComponentReference ref2 = factory.createComponentReference(); - ref2.setName("stockQuoteService"); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setReference(i.getReferences().get(1)); - c.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - ComponentService s = factory.createComponentService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - s.setService(i.getServices().get(0)); - c.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return c; - } - - /** - * Create a new component type - * - * @return - */ - ComponentType createComponentType() { - ComponentType ctype = factory.createComponentType(); - - Property p = factory.createProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - Reference ref1 = factory.createReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - ref1.getBindings().add(new TestBinding(factory)); - - Reference ref2 = factory.createReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - ref2.getBindings().add(new TestBinding(factory)); - - Service s = factory.createService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - s.getBindings().add(new TestBinding(factory)); - - return ctype; - } - - /** - * Create a new constraining type - * - * @return - */ - ConstrainingType createConstrainingType() { - ConstrainingType ctype = factory.createConstrainingType(); - - AbstractProperty p = factory.createAbstractProperty(); - p.setName("currency"); - p.setValue("USD"); - p.setMustSupply(true); - p.setXSDType(new QName("", "")); - ctype.getProperties().add(p); - - AbstractReference ref1 = factory.createAbstractReference(); - ref1.setName("accountDataService"); - ref1.setInterfaceContract(new TestInterfaceContract(factory)); - ref1.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref1); - - AbstractReference ref2 = factory.createAbstractReference(); - ref2.setName("stockQuoteService"); - ref2.setInterfaceContract(new TestInterfaceContract(factory)); - ref2.setMultiplicity(Multiplicity.ONE_ONE); - ctype.getReferences().add(ref2); - - AbstractService s = factory.createAbstractService(); - s.setName("AccountService"); - s.setInterfaceContract(new TestInterfaceContract(factory)); - ctype.getServices().add(s); - - return ctype; - } - - @Test - public void testPrint1() { - Composite composite = createComposite(); - StringWriter sw = new StringWriter(); - PrintUtil p = new PrintUtil(new PrintWriter(sw), true); - p.print(composite); - // System.out.println(sw.toString()); - } - - @Test - public void testPrint2() { - Composite composite = createComposite(); - StringWriter sw = new StringWriter(); - PrintUtil p = new PrintUtil(new PrintWriter(sw), false); - p.print(composite); - // System.out.println(sw.toString()); - } -} diff --git a/java/sca/modules/binding-http-runtime/META-INF/MANIFEST.MF b/java/sca/modules/binding-http-runtime/META-INF/MANIFEST.MF index 89a065ce74..64df1fd696 100644 --- a/java/sca/modules/binding-http-runtime/META-INF/MANIFEST.MF +++ b/java/sca/modules/binding-http-runtime/META-INF/MANIFEST.MF @@ -13,20 +13,20 @@ Bundle-Description: Apache Tuscany SCA HTTP Binding Runtime Import-Package: javax.servlet, javax.servlet.http, javax.xml.namespace, - javax.xml.stream;version="1.0", - org.apache.tuscany.sca.assembly;version="2.0", + javax.xml.stream, + org.apache.tuscany.sca.assembly;version="2.0.0", org.apache.tuscany.sca.assembly.xml;version="2.0.0", - org.apache.tuscany.sca.binding.http;version="2.0", - org.apache.tuscany.sca.contribution.processor;version="2.0", - org.apache.tuscany.sca.contribution.resolver;version="2.0", - org.apache.tuscany.sca.core;version="2.0", - org.apache.tuscany.sca.host.http, - org.apache.tuscany.sca.interfacedef, - org.apache.tuscany.sca.invocation, - org.apache.tuscany.sca.monitor;version="2.0", - org.apache.tuscany.sca.provider, - org.apache.tuscany.sca.runtime, - org.oasisopen.sca.annotation + org.apache.tuscany.sca.binding.http;version="2.0.0", + org.apache.tuscany.sca.contribution.processor;version="2.0.0", + org.apache.tuscany.sca.contribution.resolver;version="2.0.0", + org.apache.tuscany.sca.core;version="2.0.0", + org.apache.tuscany.sca.host.http;version="2.0.0", + org.apache.tuscany.sca.interfacedef;version="2.0.0", + org.apache.tuscany.sca.invocation;version="2.0.0", + org.apache.tuscany.sca.monitor;version="2.0.0", + org.apache.tuscany.sca.provider;version="2.0.0", + org.apache.tuscany.sca.runtime;version="2.0.0", + org.oasisopen.sca.annotation;version="2.0.0" Bundle-SymbolicName: org.apache.tuscany.sca.binding.http.runtime Bundle-DocURL: http://www.apache.org/ Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/java/sca/modules/binding-http/META-INF/MANIFEST.MF b/java/sca/modules/binding-http/META-INF/MANIFEST.MF index faa12e60e9..d50454f842 100644 --- a/java/sca/modules/binding-http/META-INF/MANIFEST.MF +++ b/java/sca/modules/binding-http/META-INF/MANIFEST.MF @@ -14,13 +14,16 @@ Bnd-LastModified: 1253494834368 Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA HTTP Binding Model
-Import-Package: javax.servlet.http,javax.xml.namespace,javax.xml.strea
- m;version="1.0",org.apache.tuscany.sca.assembly;version="2.0",org.apa
- che.tuscany.sca.assembly.xml;version="2.0.0",org.apache.tuscany.sca.b
- inding.http;version="2.0",org.apache.tuscany.sca.contribution.process
- or;version="2.0",org.apache.tuscany.sca.contribution.resolver;version
- ="2.0",org.apache.tuscany.sca.core;version="2.0",org.apache.tuscany.s
- ca.monitor;version="2.0"
+Import-Package: javax.servlet.http,
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.xml;version="2.0.0",
+ org.apache.tuscany.sca.binding.http;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.monitor;version="2.0.0"
Bundle-SymbolicName: org.apache.tuscany.sca.binding.http
Bundle-DocURL: http://www.apache.org/
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java index 33131c6bf2..c6d6f98de6 100644 --- a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java +++ b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java @@ -23,12 +23,9 @@ import java.io.InputStream; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -36,10 +33,6 @@ import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtens import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.policy.PolicyFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; @@ -55,9 +48,7 @@ public class SCABindingTestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; private CompositeModelResolver resolver; - private CompositeBuilder compositeBuilder; private ExtensionPointRegistry extensionPoints; - private Monitor monitor; @Before public void init() throws Exception { @@ -68,18 +59,6 @@ public class SCABindingTestCase { staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); resolver = new CompositeModelResolver(null, null, null); - - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); - PolicyFactory attachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class); - - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - } @Test @@ -106,8 +85,6 @@ public class SCABindingTestCase { staxProcessor.resolve(composite, resolver); - compositeBuilder.build(composite, null, monitor); - 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); diff --git a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java index b6ce565479..6e0e0bbab7 100644 --- a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java +++ b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java @@ -29,16 +29,11 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -52,8 +47,6 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - private static CompositeBuilder compositeBuilder; - private static Monitor monitor; @BeforeClass public static void setUp() throws Exception { @@ -62,12 +55,6 @@ public class ReadTestCase { inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); - - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } @Test @@ -93,8 +80,6 @@ public class ReadTestCase { Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - compositeBuilder.build(composite, null, monitor); - 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); diff --git a/java/sca/modules/binding-ws-xml/pom.xml b/java/sca/modules/binding-ws-xml/pom.xml index b2b55abd23..a5ff4c3d75 100644 --- a/java/sca/modules/binding-ws-xml/pom.xml +++ b/java/sca/modules/binding-ws-xml/pom.xml @@ -58,6 +58,13 @@ <artifactId>tuscany-interface-wsdl</artifactId> <version>2.0-SNAPSHOT</version> </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-builder</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.apache.tuscany.sca</groupId> diff --git a/java/sca/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/java/sca/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java index 652789fb14..bba7ff28ab 100644 --- a/java/sca/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java +++ b/java/sca/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java @@ -30,17 +30,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.BeforeClass; import org.junit.Test; @@ -53,8 +48,6 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - private static CompositeBuilder compositeBuilder; - private static Monitor monitor; @BeforeClass public static void setUp() throws Exception { @@ -62,11 +55,6 @@ public class ReadTestCase { inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } @Test @@ -83,8 +71,6 @@ public class ReadTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - - compositeBuilder.build(composite, null, monitor); } @Test @@ -93,9 +79,6 @@ public class ReadTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - - compositeBuilder.build(composite, null, monitor); - } /** diff --git a/java/sca/modules/builder/pom.xml b/java/sca/modules/builder/pom.xml index 520e89f35d..33db479180 100644 --- a/java/sca/modules/builder/pom.xml +++ b/java/sca/modules/builder/pom.xml @@ -52,14 +52,6 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-implementation-java</artifactId> - <version>2.0-SNAPSHOT</version> - <scope>test</scope> - </dependency> - - - <dependency> - <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-contribution</artifactId> <version>2.0-SNAPSHOT</version> </dependency> diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java index 8c3601591b..e8d065cdcd 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.assembly.xml; +package org.apache.tuscany.sca.builder.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -31,12 +31,10 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; @@ -48,7 +46,6 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.PolicySubject; @@ -73,8 +70,7 @@ public class BuildPolicyTestCase { public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl(); - modelFactories.addFactory(scaBindingFactory); + compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class) .getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); @@ -86,8 +82,6 @@ public class BuildPolicyTestCase { MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); monitor = monitorFactory.createMonitor(); - InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); - URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints); documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); @@ -97,19 +91,13 @@ public class BuildPolicyTestCase { extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); - URL url = BuildPolicyTestCase.class.getResource("CalculatorComponent.constrainingType"); - URI uri = URI.create("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); - assertNotNull(constrainingType); - resolver.addModel(constrainingType); - - url = BuildPolicyTestCase.class.getResource("TestAllPolicyCalculator.composite"); - uri = URI.create("TestAllCalculator.composite"); + URL url = BuildPolicyTestCase.class.getResource("Calculator.composite"); + URI uri = URI.create("TestAllCalculator.composite"); composite = (Composite)documentProcessor.read(null, uri, url); assertNotNull(composite); - url = BuildPolicyTestCase.class.getResource("another_test_definitions.xml"); - uri = URI.create("another_test_definitions.xml"); + url = BuildPolicyTestCase.class.getResource("test_definitions.xml"); + uri = URI.create("test_definitions.xml"); Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url); assertNotNull(definitions); policyDefinitions.add(definitions); diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java index 57c6081859..f309331fff 100644 --- a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.tuscany.sca.assembly.builder.impl; +package org.apache.tuscany.sca.builder.impl; import static org.junit.Assert.assertTrue; diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Calculator.composite index d6082a936d..d6082a936d 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Calculator.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Calculator.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite1.composite index 105a478842..105a478842 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite1.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite2.composite index d3d5bafdfc..d3d5bafdfc 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite2.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite3.composite index 12aa35b694..12aa35b694 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite3.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite4.composite index 141ff2a4ea..141ff2a4ea 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/Composite4.composite diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/definitions.xml index fe76d0038a..fe76d0038a 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/definitions.xml diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.odg Binary files differindex a010bb1bf1..a010bb1bf1 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.odg diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.png Binary files differindex e1f78f6423..e1f78f6423 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/scenario.png diff --git a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/test_definitions.xml index dac8e384e3..dac8e384e3 100644 --- a/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/test_definitions.xml +++ b/java/sca/modules/builder/src/test/resources/org/apache/tuscany/sca/builder/impl/test_definitions.xml diff --git a/java/sca/modules/endpoint-wrapper/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/java/sca/modules/endpoint-wrapper/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java deleted file mode 100644 index 51c02d544f..0000000000 --- a/java/sca/modules/endpoint-wrapper/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java +++ /dev/null @@ -1,156 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apace.tuscany.sca.binding.sca;
-
-
-import java.io.File;
-import java.net.URI;
-import java.net.URL;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-
-import org.apache.tuscany.sca.assembly.AssemblyFactory;
-import org.apache.tuscany.sca.assembly.ComponentReference;
-import org.apache.tuscany.sca.assembly.Composite;
-import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
-import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint;
-import org.apache.tuscany.sca.contribution.Contribution;
-import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
-import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
-import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
-import org.apache.tuscany.sca.runtime.CompositeActivator;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * EndpointTestCase
- *
- * @version $Rev: 803502 $ $Date: 2009-08-12 14:34:45 +0100 (Wed, 12 Aug 2009) $
- */
-public class EndpointTestCase {
-
- private static URLArtifactProcessor<Contribution> contributionProcessor;
- private static ModelResolverExtensionPoint modelResolvers;
- private static FactoryExtensionPoint modelFactories;
- private static AssemblyFactory assemblyFactory;
- private static XMLOutputFactory outputFactory;
- private static StAXArtifactProcessor<Object> xmlProcessor;
- private static CompositeBuilder compositeBuilder;
- private static ModelResolver modelResolver;
- private static CompositeActivator compositeActivator;
- private static ExtensionPointRegistry extensionPoints;
- private static Monitor monitor;
-
- @BeforeClass
- public static void init() {
-
- // Create extension point registry
- extensionPoints = new DefaultExtensionPointRegistry();
-
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- monitor = monitorFactory.createMonitor();
-
- modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
-
- // Initialize the Tuscany module activators
- extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
-
- // Get XML input/output factories
-
- XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
- outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
-
- // Get contribution workspace and assembly model factories
- assemblyFactory = new RuntimeAssemblyFactory(extensionPoints);
- modelFactories.addFactory(assemblyFactory);
-
- // Create XML artifact processors
- StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
- xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor);
-
- // Create contribution content processor
- URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class);
-
- // Get the model resolvers
- modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
- modelResolver = new ExtensibleModelResolver(null, modelResolvers, modelFactories, monitor);
-
- // Create a composite builder
- compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
-
-
-
- }
-
- @Ignore
- @Test
- public void testProvider(){
- try {
- URI calculatorURI = URI.create("calcualtor");
- URL calculatorURL = new File("./target/test-classes").toURI().toURL();
- Contribution contribution = contributionProcessor.read(null, calculatorURI, calculatorURL);
-
- contributionProcessor.resolve(contribution, modelResolver);
-
- 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);
-
- EndpointResolverFactory<Endpoint> factory = new EndpointResolverFactoryImpl(extensionPoints);
-
- EndpointResolver endpointResolver = factory.createEndpointResolver(endpoint, null);
-
- Assert.assertNotNull(endpointResolver);
-*/
-
-
- } catch(Exception ex) {
- ex.printStackTrace();
- System.out.println(ex.toString());
- Assert.fail();
- }
- }
-
-
-}
diff --git a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java deleted file mode 100644 index 12a915c5db..0000000000 --- a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apace.tuscany.sca.binding.sca; - - -import java.io.File; -import java.net.URI; -import java.net.URL; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.runtime.CompositeActivator; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -/** - * EndpointTestCase - * - * @version $Rev$ $Date$ - */ -public class EndpointTestCase { - - private static URLArtifactProcessor<Contribution> contributionProcessor; - private static ModelResolverExtensionPoint modelResolvers; - private static FactoryExtensionPoint modelFactories; - private static AssemblyFactory assemblyFactory; - private static XMLOutputFactory outputFactory; - private static StAXArtifactProcessor<Object> xmlProcessor; - private static CompositeBuilder compositeBuilder; - private static ModelResolver modelResolver; - private static CompositeActivator compositeActivator; - private static ExtensionPointRegistry extensionPoints; - private static Monitor monitor; - - @BeforeClass - public static void init() { - - // Create extension point registry - extensionPoints = new DefaultExtensionPointRegistry(); - - // Create a monitor - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); - - modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - - // Initialize the Tuscany module activators - extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class); - - // Get XML input/output factories - - XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); - outputFactory = modelFactories.getFactory(XMLOutputFactory.class); - - // Get contribution workspace and assembly model factories - assemblyFactory = new RuntimeAssemblyFactory(extensionPoints); - modelFactories.addFactory(assemblyFactory); - - // Create XML artifact processors - StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor); - - // Create contribution content processor - URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class); - - // Get the model resolvers - modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - modelResolver = new ExtensibleModelResolver(null, modelResolvers, modelFactories, monitor); - - // Create a composite builder - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - - - } - - @Ignore - @Test - public void testProvider(){ - try { - URI calculatorURI = URI.create("calcualtor"); - URL calculatorURL = new File("./target/test-classes").toURI().toURL(); - Contribution contribution = contributionProcessor.read(null, calculatorURI, calculatorURL); - - contributionProcessor.resolve(contribution, modelResolver); - - 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); - - EndpointResolverFactory<Endpoint> factory = new EndpointResolverFactoryImpl(extensionPoints); - - EndpointResolver endpointResolver = factory.createEndpointResolver(endpoint, null); - - Assert.assertNotNull(endpointResolver); -*/ - - - } catch(Exception ex) { - ex.printStackTrace(); - System.out.println(ex.toString()); - Assert.fail(); - } - } - - -} diff --git a/java/sca/modules/implementation-java/pom.xml b/java/sca/modules/implementation-java/pom.xml index 94d5c67e05..7b246debf7 100644 --- a/java/sca/modules/implementation-java/pom.xml +++ b/java/sca/modules/implementation-java/pom.xml @@ -73,6 +73,13 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-builder</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-policy-xml</artifactId> <version>2.0-SNAPSHOT</version> <scope>test</scope> diff --git a/java/sca/modules/implementation-osgi/pom.xml b/java/sca/modules/implementation-osgi/pom.xml index a648421425..b03f730977 100644 --- a/java/sca/modules/implementation-osgi/pom.xml +++ b/java/sca/modules/implementation-osgi/pom.xml @@ -58,6 +58,7 @@ <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-assembly-xml</artifactId> <version>2.0-SNAPSHOT</version> + <scope>test</scope> </dependency> <dependency> diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java index 43cca15341..8c85b9136d 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java @@ -34,7 +34,6 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -57,7 +56,6 @@ public class OSGiReadImplTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - private static CompositeBuilder compositeBuilder; @BeforeClass public static void setUp() throws Exception { diff --git a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java index 82477d086c..32622dec39 100644 --- a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java +++ b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java @@ -27,17 +27,12 @@ import javax.xml.stream.XMLStreamReader; import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.implementation.web.WebImplementation; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; /** * Test reading Web implementations. @@ -46,8 +41,6 @@ public class ReadTestCase extends TestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; - private CompositeBuilder compositeBuilder; - private static Monitor monitor; @Override public void setUp() throws Exception { @@ -55,11 +48,6 @@ public class ReadTestCase extends TestCase { inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } public void testReadComposite() throws Exception { @@ -67,9 +55,6 @@ public class ReadTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite) staxProcessor.read(reader); assertNotNull(composite); - - compositeBuilder.build(composite, null, monitor); - assertTrue(((WebImplementation) composite.getComponents().get(0).getImplementation()).getWebURI().equals("MyWebapp")); } diff --git a/java/sca/modules/interface-java/META-INF/MANIFEST.MF b/java/sca/modules/interface-java/META-INF/MANIFEST.MF index 333ed8a54d..65e69260bd 100644 --- a/java/sca/modules/interface-java/META-INF/MANIFEST.MF +++ b/java/sca/modules/interface-java/META-INF/MANIFEST.MF @@ -24,7 +24,6 @@ Bundle-Description: Apache Tuscany SCA Java Interface Model Import-Package: javax.xml.namespace,
javax.xml.stream,
org.apache.tuscany.sca.assembly;version="2.0.0",
- org.apache.tuscany.sca.assembly.builder;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.contribution.processor;version="2.0.0",
org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
diff --git a/java/sca/modules/interface-java/pom.xml b/java/sca/modules/interface-java/pom.xml index 913b22ae94..8211b7ebf5 100644 --- a/java/sca/modules/interface-java/pom.xml +++ b/java/sca/modules/interface-java/pom.xml @@ -39,6 +39,7 @@ <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-assembly-xml</artifactId> <version>2.0-SNAPSHOT</version> + <scope>test</scope> </dependency> <dependency> @@ -53,12 +54,6 @@ <version>2.0-SNAPSHOT</version> </dependency> - <!-- dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-sca</artifactId> - <version>2.0-SNAPSHOT</version> - <scope>test</scope> - </dependency --> </dependencies> </project> diff --git a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java index bc32b556bf..d63b3e0549 100644 --- a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java +++ b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java @@ -30,16 +30,11 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -54,8 +49,6 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - private static CompositeBuilder compositeBuilder; - private static Monitor monitor; @BeforeClass public static void setUp() throws Exception { @@ -64,12 +57,6 @@ public class ReadTestCase { outputFactory = XMLOutputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); - - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } @Test @@ -95,8 +82,6 @@ public class ReadTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - - compositeBuilder.build(composite, null, monitor); } } diff --git a/java/sca/modules/interface-wsdl/META-INF/MANIFEST.MF b/java/sca/modules/interface-wsdl/META-INF/MANIFEST.MF index 05f351494f..b88aa2a141 100644 --- a/java/sca/modules/interface-wsdl/META-INF/MANIFEST.MF +++ b/java/sca/modules/interface-wsdl/META-INF/MANIFEST.MF @@ -23,7 +23,6 @@ Import-Package: javax.wsdl, javax.xml.namespace,
javax.xml.stream,
org.apache.tuscany.sca.assembly;version="2.0.0",
- org.apache.tuscany.sca.assembly.builder;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.common.java.io;version="2.0.0",
org.apache.tuscany.sca.common.xml;version="2.0.0",
org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
diff --git a/java/sca/modules/interface-wsdl/pom.xml b/java/sca/modules/interface-wsdl/pom.xml index a0f0894ef6..aefbca7dd6 100644 --- a/java/sca/modules/interface-wsdl/pom.xml +++ b/java/sca/modules/interface-wsdl/pom.xml @@ -57,8 +57,9 @@ <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-assembly-xml</artifactId> <version>2.0-SNAPSHOT</version> + <scope>test</scope> </dependency> - + <dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-binding-sca-runtime</artifactId> diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java index 27213a521c..ef30b0453f 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java @@ -29,17 +29,11 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.Before; import org.junit.Test; @@ -52,8 +46,6 @@ public class ReadTestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; - private CompositeBuilder compositeBuilder; - private static Monitor monitor; @Before public void setUp() throws Exception { @@ -61,13 +53,6 @@ public class ReadTestCase { inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); - - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } @Test @@ -92,8 +77,6 @@ public class ReadTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); Composite composite = (Composite)staxProcessor.read(reader); assertNotNull(composite); - - compositeBuilder.build(composite, null, monitor); } } diff --git a/java/sca/modules/node-impl-osgi/pom.xml b/java/sca/modules/node-impl-osgi/pom.xml index 75bc2991ef..2b06e06208 100644 --- a/java/sca/modules/node-impl-osgi/pom.xml +++ b/java/sca/modules/node-impl-osgi/pom.xml @@ -110,6 +110,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-rmi-runtime</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/java/sca/modules/node-impl/pom.xml b/java/sca/modules/node-impl/pom.xml index dc63d829b0..185499eaec 100644 --- a/java/sca/modules/node-impl/pom.xml +++ b/java/sca/modules/node-impl/pom.xml @@ -71,6 +71,13 @@ <dependency> <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-builder</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-binding-sca-runtime</artifactId> <version>2.0-SNAPSHOT</version> <scope>runtime</scope> diff --git a/java/sca/modules/pom.xml b/java/sca/modules/pom.xml index 0fd5addb7e..33a8a9ec5a 100644 --- a/java/sca/modules/pom.xml +++ b/java/sca/modules/pom.xml @@ -46,6 +46,7 @@ <module>binding-ws-axis2-policy</module> <module>binding-ws-wsdlgen</module> <module>binding-ws-xml</module> + <module>builder</module> <module>common-java</module> <module>common-xml</module> <module>contribution</module> |