diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-29 23:41:25 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-29 23:41:25 +0000 |
commit | b7fb8ba1b979ed77a8d9ad29acd15d9ae9a78d8f (patch) | |
tree | 17c1ac5452f43fb8e090c751232ec62900061b75 /java/sca/modules/builder | |
parent | bd77e0fb2851f7ae6a45a11ea9cda0979c035539 (diff) |
Start to integrate the policy attachment builder
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@820125 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/builder')
8 files changed, 193 insertions, 342 deletions
diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BaseBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BaseBuilderImpl.java index e78c0c46d5..ad2267a635 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BaseBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BaseBuilderImpl.java @@ -691,6 +691,7 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { } */ SCABinding scaBinding = scaBindingFactory.createSCABinding(); + scaBinding.setName(contract.getName()); if (definitions != null) { for (ExtensionType attachPointType : definitions.getBindingTypes()) { diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java index 88b5c126fc..57d0a7f639 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java @@ -21,7 +21,6 @@ package org.apache.tuscany.sca.builder.impl; import java.net.URI; import java.net.URISyntaxException; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,33 +28,25 @@ 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.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.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 class BindingURIBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { public BindingURIBuilderImpl(ExtensionPointRegistry registry) { - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); } /** @@ -63,10 +54,10 @@ public class BindingURIBuilderImpl { * * @param composite the composite to be configured */ - protected void configureBindingURIsAndNames(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { configureBindingURIs(composite, null, definitions, null, monitor); - configureBindingNames(composite, monitor); + return composite; } /** @@ -77,11 +68,12 @@ public class BindingURIBuilderImpl { * @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 { + public Composite build(Composite composite, + Definitions definitions, + Map<QName, List<String>> defaultBindings, + Monitor monitor) throws CompositeBuilderException { configureBindingURIs(composite, null, definitions, defaultBindings, monitor); + return composite; } /** @@ -137,8 +129,6 @@ public class BindingURIBuilderImpl { 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); @@ -154,8 +144,6 @@ public class BindingURIBuilderImpl { for (ComponentService service : component.getServices()) { - constructBindingNames(service, monitor); - // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(component, service, binding, defaultBindings, monitor); @@ -171,114 +159,6 @@ public class BindingURIBuilderImpl { } /** - * 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 @@ -506,4 +386,8 @@ public class BindingURIBuilderImpl { return URI.create(baseURI.toString() + str).normalize(); } + public String getID() { + return "org.apache.tuscany.sca.assembly.builder.BindingURIBuilder"; + } + } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java index eac88b88b5..1603c80eb5 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java @@ -872,6 +872,7 @@ public class ComponentBuilderImpl { protected void createSCABinding(Contract contract, Definitions definitions) { SCABinding scaBinding = scaBindingFactory.createSCABinding(); + scaBinding.setName(contract.getName()); if (definitions != null) { for (ExtensionType attachPointType : definitions.getBindingTypes()) { diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java index 69428285ce..a05a90afa2 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java @@ -386,6 +386,7 @@ public class CompositeComponentTypeBuilderImpl { protected void createSCABinding(Contract contract, Definitions definitions) { SCABinding scaBinding = scaBindingFactory.createSCABinding(); + scaBinding.setName(contract.getName()); if (definitions != null) { for (ExtensionType attachPointType : definitions.getBindingTypes()) { diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java index 43e5d76e9e..45df386aae 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java @@ -37,12 +37,15 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil private CompositeComponentTypeBuilderImpl compositeComponentTypeBuilder; private ComponentBuilderImpl componentBuilder; + private CompositeBuilder structuralURIBuilder; private BindingURIBuilderImpl bindingURIBuilder; private ComponentServiceBindingBuilderImpl componentServiceBindingBuilder; private ComponentReferenceBindingBuilderImpl componentReferenceBindingBuilder; private EndpointBuilderImpl endpointBuilder; private EndpointReferenceBuilderImpl endpointReferenceBuilder; private ComponentReferencePromotionBuilderImpl componentReferencePromotionBuilder; + + private CompositeBuilder policyAttachmentBuilder; private CompositePolicyBuilderImpl compositePolicyBuilder; /** @@ -61,14 +64,16 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil compositeComponentTypeBuilder.setComponentBuilder(componentBuilder); componentBuilder.setComponentTypeBuilder(compositeComponentTypeBuilder); + structuralURIBuilder = new StructuralURIBuilderImpl(registry); 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); + policyAttachmentBuilder = new PolicyAttachmentBuilderImpl(registry); + compositePolicyBuilder = new CompositePolicyBuilderImpl(registry); } public String getID() { @@ -94,8 +99,11 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil // and discards the included composite composite = compositeIncludeBuilder.build(composite, definitions, monitor); + // Set up the structural URIs for components (services/references/bindings?) + composite = structuralURIBuilder.build(composite, definitions, monitor); + // need to apply policy external attachment - + composite = policyAttachmentBuilder.build(composite, definitions, monitor); // Process the implementation hierarchy by calculating the component type // for the top level implementation (composite). This has the effect of @@ -115,7 +123,7 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil // 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 = bindingURIBuilder.build(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); diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java index 19dff30051..df98ec89b7 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java @@ -23,34 +23,43 @@ import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX; import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE; import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; +import java.io.IOException; import java.io.StringWriter; import java.util.Set; import java.util.StringTokenizer; import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; +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.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.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.common.xml.dom.DOMHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; 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.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; /** * A builder that attaches policy sets to the domain composite using the xpath defined by @@ -77,7 +86,8 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.policy.builder.PolicyAttachmentBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { try { Composite patched = applyXPath(composite, definitions, monitor); return patched; @@ -95,6 +105,9 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { * @throws Exception */ private Composite applyXPath(Composite composite, Definitions definitions, Monitor monitor) throws Exception { + if (definitions == null || definitions.getPolicySets().isEmpty()) { + return composite; + } // Recursively apply the xpath against the composites referenced by <implementation.composite> for (Component component : composite.getComponents()) { Implementation impl = component.getImplementation(); @@ -105,16 +118,8 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { } } } - // First write the composite into a DOM document so that we can apply the xpath - StringWriter sw = new StringWriter(); - XMLStreamWriter writer = staxHelper.createXMLStreamWriter(sw); - // Write the composite into a DOM document - processor.write(composite, writer); - writer.close(); - - Document document = domHelper.load(sw.toString()); + Document document = saveAsDOM(composite); - boolean changed = false; for (PolicySet ps : definitions.getPolicySets()) { // First calculate the applicable nodes Set<Node> applicableNodes = null; @@ -135,22 +140,156 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { Node node = nodes.item(i); if (applicableNodes == null || applicableNodes.contains(node)) { // The node can be a component, service, reference or binding - if (attach(node, ps) && !changed) { - changed = true; + String index = getStructuralURI(node); + PolicySubject subject = lookup(composite, index); + if (subject != null) { + subject.getPolicySets().add(ps); } } } } } - if (changed) { - XMLStreamReader reader = staxHelper.createXMLStreamReader(document); - reader.nextTag(); - Composite patchedComposite = (Composite)processor.read(reader); - return patchedComposite; - } else { - return composite; + return composite; + } + + private Document saveAsDOM(Composite composite) throws XMLStreamException, ContributionWriteException, IOException, + SAXException { + // First write the composite into a DOM document so that we can apply the xpath + StringWriter sw = new StringWriter(); + XMLStreamWriter writer = staxHelper.createXMLStreamWriter(sw); + // Write the composite into a DOM document + processor.write(composite, writer); + writer.close(); + + Document document = domHelper.load(sw.toString()); + return document; + } + + private static final QName COMPONENT = new QName(Base.SCA11_NS, "component"); + private static final QName SERVICE = new QName(Base.SCA11_NS, "service"); + private static final QName REFERENCE = new QName(Base.SCA11_NS, "reference"); + + private static String getStructuralURI(Node node) { + if (node != null) { + QName name = new QName(node.getNamespaceURI(), node.getLocalName()); + if (COMPONENT.equals(name)) { + Element element = (Element)node; + return element.getAttributeNS(null, "uri"); + } else if (SERVICE.equals(name)) { + Element component = (Element)node.getParentNode(); + String uri = component.getAttributeNS(null, "uri"); + String service = ((Element)node).getAttributeNS(null, "name"); + return uri + "#service(" + service + ")"; + } else if (REFERENCE.equals(name)) { + Element component = (Element)node.getParentNode(); + String uri = component.getAttributeNS(null, "uri"); + String reference = ((Element)node).getAttributeNS(null, "name"); + return uri + "#reference(" + reference + ")"; + } else { + String localName = node.getLocalName(); + if (localName.startsWith("binding.")) { + String bindingName = ((Element)node).getAttributeNS(null, "name"); + Element contract = (Element)node.getParentNode(); + String contractName = contract.getAttributeNS(null, "name"); + Element component = (Element)node.getParentNode().getParentNode(); + String uri = component.getAttributeNS(null, "uri"); + return uri + "#" + contract.getLocalName() + "(" + contractName + "/" + bindingName + ")"; + } else if (localName.startsWith("implementation.")) { + Element component = (Element)node.getParentNode(); + String uri = component.getAttributeNS(null, "uri"); + return uri + "#implementation()"; + } + } + } + return null; + } + + private Binding getBinding(Contract contract, String name) { + for (Binding binding : contract.getBindings()) { + if (name.equals(binding.getName())) { + return binding; + } + } + return null; + } + + private PolicySubject lookup(Composite composite, String structuralURI) { + if (structuralURI == null) { + return null; + } + int index = structuralURI.indexOf('#'); + String componentURI = structuralURI; + String service = null; + String reference = null; + String binding = null; + boolean impl = false; + + if (index != -1) { + componentURI = structuralURI.substring(0, index); + String fragment = structuralURI.substring(index + 1); + int begin = fragment.indexOf('('); + int end = fragment.indexOf(')'); + if (begin != -1 && end != -1) { + String path = fragment.substring(begin + 1, end).trim(); + String prefix = fragment.substring(0, begin).trim(); + if (prefix.equals("implementation")) { + impl = true; + } else { + int pos = path.indexOf('/'); + if (pos != -1) { + binding = path.substring(pos + 1); + path = path.substring(0, index); + if ("service-binding".equals(prefix)) { + service = path; + } else if ("reference-binding".equals(prefix)) { + reference = path; + } + } + if ("service".equals(prefix)) { + service = path; + } else if ("reference".equals(prefix)) { + reference = path; + } + } + } + } + for (Component component : composite.getComponents()) { + if (component.getURI().equals(componentURI)) { + if (service != null) { + ComponentService componentService = component.getService(service); + if (binding != null) { + Binding b = getBinding(componentService, binding); + if (b instanceof PolicySubject) { + return (PolicySubject)b; + } + } else { + return componentService; + } + } else if (reference != null) { + ComponentReference componentReference = component.getReference(reference); + if (binding != null) { + Binding b = getBinding(componentReference, binding); + if (b instanceof PolicySubject) { + return (PolicySubject)b; + } + } else { + return componentReference; + } + } else if (impl) { + return component.getImplementation(); + } + return component; + } else if (structuralURI.startsWith(component.getURI() + "/")) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + return lookup((Composite)implementation, structuralURI); + } else { + return null; + } + } } + return null; } /** diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java index 04f7759493..d1942a3e4e 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java @@ -54,160 +54,6 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo } /** - * 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 bindingBaseURIs list of default binding configurations - */ - private void configureBindingURIs(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, bindingBaseURIs, 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 parentComponentURI, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - 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 = parentComponentURI + '/' + component.getName(); - } - 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.getURI(), 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 * @@ -272,29 +118,6 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo } /** - * 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); - } - - /** * 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 @@ -494,7 +317,7 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo Definitions definitions, Map<QName, List<String>> bindingBaseURIs, Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, definitions, bindingBaseURIs, monitor); + configureStructuralURIs(composite, null, definitions, bindingBaseURIs, monitor); return composite; } @@ -531,10 +354,12 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo for (ComponentService service : component.getServices()) { constructBindingNames(service, monitor); + /* // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(componentURI, service, binding, defaultBindings, monitor); } + */ } for (ComponentReference service : component.getReferences()) { constructBindingNames(service, monitor); diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java index 075dac51a1..76b6c8b1f1 100644 --- a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java @@ -33,10 +33,6 @@ import org.apache.tuscany.sca.assembly.Base; 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.builder.impl.CompositeCloneBuilderImpl; -import org.apache.tuscany.sca.builder.impl.CompositeIncludeBuilderImpl; -import org.apache.tuscany.sca.builder.impl.PolicyAttachmentBuilderImpl; -import org.apache.tuscany.sca.builder.impl.StructuralURIBuilderImpl; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; @@ -92,7 +88,10 @@ public class PolicyAttachmentTestCase { public void testBuild() throws Exception { Definitions definitions = load("test_definitions.xml"); Composite composite = load("Calculator.composite"); + + CompositeBuilder uriBuilder = new StructuralURIBuilderImpl(extensionPoints); + composite = uriBuilder.build(composite, definitions, monitor); PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints); builder.build(composite, definitions, monitor); } @@ -131,13 +130,6 @@ public class PolicyAttachmentTestCase { CompositeBuilder cloneBuilder = new CompositeCloneBuilderImpl(); CompositeBuilder uriBuilder = new StructuralURIBuilderImpl(extensionPoints); - /* - CompositeBuilder includeBuilder = - builders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeIncludeBuilder"); - CompositeBuilder cloneBuilder = - builders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeCloneBuilder"); - */ - domainComposite = cloneBuilder.build(domainComposite, definitions, monitor); domainComposite = includeBuilder.build(domainComposite, definitions, monitor); domainComposite = uriBuilder.build(domainComposite, definitions, monitor); |