diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-22 16:11:11 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-22 16:11:11 +0000 |
commit | 86163b4ee4d80014e063e01add2f69b77cdf63a0 (patch) | |
tree | b259eebfedf80fbb453d88fe354c27b922940caa /java/sca/modules | |
parent | 399df0e96559b977ef2a880f5f81b0f0eaac189c (diff) |
Add logic to apply the xpath against the implementation composites
Add a more complicated test case
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@817714 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
4 files changed, 89 insertions, 17 deletions
diff --git a/java/sca/modules/policy-builder/META-INF/MANIFEST.MF b/java/sca/modules/policy-builder/META-INF/MANIFEST.MF index 5651b19418..346659a341 100644 --- a/java/sca/modules/policy-builder/META-INF/MANIFEST.MF +++ b/java/sca/modules/policy-builder/META-INF/MANIFEST.MF @@ -11,6 +11,7 @@ Import-Package: javax.xml.namespace, javax.xml.xpath,
org.apache.tuscany.sca.assembly;version="2.0.0",
org.apache.tuscany.sca.assembly.builder;version="2.0.0",
+ org.apache.tuscany.sca.assembly.builder.impl;version="2.0.0";resolution:=optional,
org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
org.apache.tuscany.sca.common.xml.stax;version="2.0.0",
org.apache.tuscany.sca.common.xml.xpath;version="2.0.0",
diff --git a/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java b/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java index ecd8bfc10b..335e677329 100644 --- a/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java +++ b/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java @@ -33,7 +33,9 @@ import javax.xml.stream.XMLStreamWriter; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; +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.common.xml.dom.DOMHelper; @@ -93,6 +95,16 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { * @throws Exception */ private Composite applyXPath(Composite composite, Definitions definitions, Monitor monitor) throws Exception { + // Recursively apply the xpath against the composites referenced by <implementation.composite> + for (Component component : composite.getComponents()) { + Implementation impl = component.getImplementation(); + if (impl instanceof Composite) { + Composite patched = applyXPath((Composite)impl, definitions, monitor); + if (patched != impl) { + component.setImplementation(patched); + } + } + } // First write the composite into a DOM document so that we can apply the xpath StringWriter sw = new StringWriter(); XMLStreamWriter writer = staxHelper.createXMLStreamWriter(sw); diff --git a/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java b/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java index d8c39ae65e..1c2a0dcb0f 100644 --- a/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java +++ b/java/sca/modules/policy-builder/src/test/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentTestCase.java @@ -19,22 +19,35 @@ package org.apache.tuscany.sca.policy.builder.impl; +import java.io.IOException; import java.io.InputStream; import java.net.URL; +import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +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.assembly.builder.impl.CompositeCloneBuilderImpl; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeIncludeBuilderImpl; +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; 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.definitions.Definitions; 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; /** @@ -44,13 +57,20 @@ import org.junit.Test; */ public class PolicyAttachmentTestCase { - private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; + private static StAXArtifactProcessor<Object> staxProcessor; + private static Monitor monitor; - @Test - public void testBuild() throws Exception { - DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + private static ExtensionPointRegistry extensionPoints; + private static XMLInputFactory inputFactory; + private static AssemblyFactory assemblyFactory; + private static BuilderExtensionPoint builders; + + @BeforeClass + public static void init() throws Exception { + extensionPoints = new DefaultExtensionPointRegistry(); + FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + assemblyFactory = factories.getFactory(AssemblyFactory.class); + inputFactory = factories.getFactory(XMLInputFactory.class); // Create a monitor UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = new DefaultMonitorFactory(); @@ -63,24 +83,63 @@ public class PolicyAttachmentTestCase { staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); - URL url = getClass().getResource("test_definitions.xml"); + builders = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class); + } + + @Test + public void testBuild() throws Exception { + Definitions definitions = load("test_definitions.xml"); + Composite composite = load("Calculator.composite"); + + PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints); + builder.build(composite, definitions, monitor); + } + + private <T> T load(String file) throws IOException, XMLStreamException, ContributionReadException { + URL url = getClass().getResource(file); InputStream urlStream = url.openStream(); XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); reader.nextTag(); - Definitions definitions = (Definitions)staxProcessor.read(reader); + T model = (T)staxProcessor.read(reader); reader.close(); + return model; + } - url = getClass().getResource("Calculator.composite"); - urlStream = url.openStream(); - reader = inputFactory.createXMLStreamReader(urlStream); - reader.nextTag(); + @Test + public void testComplexBuild() throws Exception { + Definitions definitions = load("definitions.xml"); + Composite composite1 = load("Composite1.composite"); + Composite composite2 = load("Composite2.composite"); + Composite composite3 = load("Composite3.composite"); + Composite composite4 = load("Composite4.composite"); + composite1.getIncludes().clear(); + composite1.getIncludes().add(composite3); - Composite composite = (Composite)staxProcessor.read(reader); - reader.close(); + composite1.getComponent("Component1B").setImplementation(composite4); + composite2.getComponent("Component2B").setImplementation(composite4); + + Composite domainComposite = assemblyFactory.createComposite(); + domainComposite.setName(new QName(Base.SCA11_NS, "")); + domainComposite.getIncludes().add(composite1); + domainComposite.getIncludes().add(composite2); + + CompositeBuilder includeBuilder = new CompositeIncludeBuilderImpl(); + CompositeBuilder cloneBuilder = new CompositeCloneBuilderImpl(); + + /* + CompositeBuilder includeBuilder = + builders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeIncludeBuilder"); + CompositeBuilder cloneBuilder = + builders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeCloneBuilder"); + */ + + includeBuilder.build(domainComposite, definitions, monitor); + cloneBuilder.build(domainComposite, definitions, monitor); PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints); - builder.build(composite, definitions, monitor); + builder.build(domainComposite, definitions, monitor); + } } diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml index a168cbcd38..fe76d0038a 100644 --- a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml +++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml @@ -24,7 +24,7 @@ xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903"> <policySet name="PolicySet1" appliesTo="sca:implementation.java" - attachTo = "//composite[@name='Composite1' or @name='Composite2']"> + attachTo = "//composite[@name='']"> </policySet> <policySet name="PolicySet2" appliesTo="sca:implementation.java" @@ -32,7 +32,7 @@ </policySet> <policySet name="PolicySet3" appliesTo="sca:binding.ws" - attachTo = "//sca:component[URIRef('Component2B/Component4A)]"> + attachTo = "//sca:component[sca:URIRef('Component2B/Component4A')]"> </policySet> </definitions>
\ No newline at end of file |