diff options
author | beckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-19 16:02:03 +0000 |
---|---|---|
committer | beckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-19 16:02:03 +0000 |
commit | 614a2e5ec9d9f1ddebf2e100d3ec82032d72af02 (patch) | |
tree | 1f1ce675a18fe0f5a690852d722dfad31d26eb3e /branches/sca-java-1.x/modules | |
parent | 2123aa9a26dce236c3b531f74b628a867a57e3e8 (diff) |
TUSCANY-2849 Unable to define operation-level intents on binding.jms
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@745909 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
4 files changed, 113 insertions, 19 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java index d4542c6d5f..2236c7fee7 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -27,7 +27,9 @@ import java.util.Set; import java.util.TreeSet; import org.apache.tuscany.sca.assembly.BindingRRB; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; @@ -40,7 +42,7 @@ import org.apache.tuscany.sca.policy.PolicySetAttachPoint; * @version $Rev$ $Date$ */ -public class JMSBinding implements BindingRRB, PolicySetAttachPoint { +public class JMSBinding implements BindingRRB, PolicySetAttachPoint, OperationsConfigurator { @Override public Object clone() throws CloneNotSupportedException { @@ -60,6 +62,9 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { // properties required by IntentAttachPoint private List<Intent> requiredIntents = new ArrayList<Intent>(); private IntentAttachPointType intentAttachPointType; + + // properties required to describe configured operations + private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>(); // Properties required to describe the JMS binding model @@ -727,6 +732,14 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { return operationPropertiesProperties.get(opName); } + public List<ConfiguredOperation> getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List<ConfiguredOperation> configuredOperations) { + this.configuredOperations = configuredOperations; + } + @Override public boolean equals( Object object ) { return ( object instanceof JMSBinding ) && equals( (JMSBinding) object ); @@ -786,6 +799,9 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { // Resource adapter if ( !optStringEquals( this.getResourceAdapterName(), binding.getResourceAdapterName() )) return false; + // Configured operations + if ( this.configuredOperations.size() != binding.getConfiguredOperations().size() ) return false; + // Other fields could also be checked for equality. See class fields for details. return true; } diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java index 820d652895..6d6a14e191 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -24,6 +24,7 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -33,10 +34,13 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.assembly.Extension; import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor; import org.apache.tuscany.sca.binding.jms.operationselector.jmsdefault.OperationSelectorJMSDefault; @@ -130,16 +134,21 @@ import org.apache.tuscany.sca.policy.PolicyFactory; public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { private PolicyFactory policyFactory; private PolicyAttachPointProcessor policyProcessor; + private ConfiguredOperationProcessor configuredOperationProcessor; protected StAXArtifactProcessor<Object> extensionProcessor; private Monitor monitor; protected String validationMessage; + private ModelFactoryExtensionPoint modelFactories; // DOB public JMSBindingProcessor(ModelFactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.configuredOperationProcessor = + new ConfiguredOperationProcessor(modelFactories, this.monitor); this.extensionProcessor = extensionProcessor; this.monitor = monitor; this.validationMessage = null; + this.modelFactories = modelFactories; } /** @@ -277,6 +286,11 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { parseOperationProperties(reader, jmsBinding); } else if ("SubscriptionHeaders".equals(elementName)) { parseSubscriptionHeaders(reader, jmsBinding); + } else if (Constants.OPERATION_QNAME.equals(reader.getName())) { + ConfiguredOperation confOp = configuredOperationProcessor.read(reader); + if (confOp != null) { + ((OperationsConfigurator)jmsBinding).getConfiguredOperations().add(confOp); + } } else { Object extension = extensionProcessor.read(reader); if (extension != null) { @@ -929,6 +943,8 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { writeResourceAdapterProperties( jmsBinding, writer ); + writeConfiguredOperations( jmsBinding, writer ); + writer.writeEndElement(); } @@ -1428,4 +1444,26 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { writer.writeCharacters(" "); } + /** + * Writes configured operations if there are any. + * <binding.jms uri=\"jms:testQueue\" >" + * <operationProperties name=\"op1\">" + * </operationProperties >" + * <operation name=\"op1\" requires=\"IntentOne IntentTwo\"/>" + * </binding.jms>" + */ + private void writeConfiguredOperations( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException, ContributionWriteException { + List<ConfiguredOperation> configOps = jmsBinding.getConfiguredOperations(); + if (configOps == null || (configOps.size() < 1)) { + return; + } + + for( Iterator<ConfiguredOperation> it = configOps.iterator(); it.hasNext();) { + configuredOperationProcessor.write(it.next(), writer); + } + + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + } diff --git a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java index 29ab264c7c..eabe4f7590 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java @@ -19,8 +19,10 @@ package org.apache.tuscany.sca.binding.jms.impl;
+import java.io.InputStream;
import java.io.StringReader;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -30,6 +32,8 @@ import javax.xml.stream.XMLStreamReader; import junit.framework.TestCase;
import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
@@ -333,6 +337,21 @@ public class JMSBindingProcessorTestCase extends TestCase { + " </component>"
+ "</composite>";
+ public static final String CONFIGURED_OPERATIONS =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://binding-jms\" name=\"binding-jms\">"
+ + " <component name=\"HelloWorldComponent\">"
+ + " <implementation.java class=\"services.HelloWorld\"/>"
+ + " <service name=\"HelloWorldService\">"
+ + " <binding.jms uri=\"jms:testQueue\" >"
+ + " <operationProperties name=\"op1\">"
+ + " </operationProperties >"
+ + " <operation name=\"op1\" requires=\"IntentOne IntentTwo\"/>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
private Monitor monitor;
@@ -350,6 +369,7 @@ public class JMSBindingProcessorTestCase extends TestCase { }
StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+
}
/**
@@ -655,4 +675,21 @@ public class JMSBindingProcessorTestCase extends TestCase { }
}
+ /**
+ * Tests the APIs:
+ * public Set<String> getOperationNames();
+ * Provides no optional properties or sub elements
+ * @throws Exception
+ */
+ public void testConfiguredOperations1() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CONFIGURED_OPERATIONS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ assertNotNull(binding);
+
+ OperationsConfigurator opConfig = ((OperationsConfigurator)binding);
+ assertEquals(opConfig.getConfiguredOperations().get(0).getRequiredIntents().size(), 2);
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java index b7d3088c42..d40d69d4c6 100644 --- a/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java +++ b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java @@ -54,24 +54,6 @@ import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl; */ public class JMSBindingProcessorWriteTestCase extends TestCase { -// public static final String COMPOSITE = -// public static final String HEADERS1 = -// public static final String PROPERTIES1 = -// public static final String OP_PROPERTIES1 = -// public static final String OP_NAMES_NO_PROPERTIES1 = -// public static final String SELECTOR = -// public static final String COMPOSITE_INVALID_URI = -// // Invalid: contains both a response attribute and a response element. -// public static final String COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT = -// public static final String DEST_PROPS = -// public static final String CF_PROPS = -// public static final String AS_PROPS = -// public static final String RESP_DEST_PROPS = -// public static final String RESP_CF_PROPS = -// public static final String RESP_AS_PROPS = -// public static final String OP_PROPS_PROPS = -// public static final String RES_ADPT_PROPS = - private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessor<Object> staxProcessor; @@ -358,4 +340,25 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { // Compare initial binding to written binding. assertEquals(binding, binding2); } + + public void testConfiguredOperations() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CONFIGURED_OPERATIONS)); + Composite composite = (Composite)staxProcessor.read(reader); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + // Write out JMSBinding model to stream. + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } } |