summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java27
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java37
2 files changed, 64 insertions, 0 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 a3d383b4c5..6c9ba36162 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
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import org.apache.tuscany.sca.assembly.BindingRRB;
import org.apache.tuscany.sca.assembly.OperationSelector;
@@ -492,6 +493,17 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
properties.put(name, value);
}
+ /**
+ * Provides key set of operation names in this binding.
+ * @return a Set<String> of operation names
+ */
+ public Set<String> getOperationNames() {
+ // Make a defensive copy since key changes affect map, map changes affect keys.
+ Set<String> opNames = operationProperties.keySet();
+ Set<String> opNamesCopy = new TreeSet<String>( opNames );
+ return opNamesCopy;
+ }
+
public Map<String, Object> getOperationProperties(String opName) {
return operationProperties.get(opName);
}
@@ -505,6 +517,21 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
props.put(propName, value);
}
+ /**
+ * Provides the value of a property for a given operation
+ * @param opName is the name of the operation in this binding.
+ * @param propName is the key name for the property
+ * @return Object representing the property value for this property name. Returns
+ * null for non existant operation name or property name.
+ */
+ public Object getOperationProperty(String opName, String propName ) {
+ Map<String, Object> props = operationProperties.get(opName);
+ if (props == null) {
+ return null;
+ }
+ return props.get(propName);
+ }
+
public boolean hasNativeOperationName(String opName) {
return nativeOperationNames.containsKey(opName);
}
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 357e542b91..74524daf19 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
@@ -20,7 +20,9 @@
package org.apache.tuscany.sca.binding.jms.impl;
import java.io.StringReader;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
@@ -579,4 +581,39 @@ public class JMSBindingProcessorTestCase extends TestCase {
assertEquals(null, bp2.getType());
assertEquals("bla", bp2.getValue().toString().trim());
}
+
+ /**
+ * Tests the APIs:
+ * public Set<String> getOperationNames();
+ * public Object getOperationProperty(String opName, String propName );
+ * @throws Exception
+ */
+ public void testOpProperties2() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+
+ Set<String> opNames = binding.getOperationNames();
+ assertEquals( 2, opNames.size() );
+ // Recall that order is not guaranteed iterating over a set.
+ for (Iterator<String> it=opNames.iterator(); it.hasNext(); ) {
+ String opName = it.next();
+ assertTrue( opName.equals( "op1") || opName.equals( "op2"));
+ }
+
+ Object value = binding.getOperationProperty( "op1", "p1" );
+ assertEquals("bla", value);
+ value = binding.getOperationProperty( "op1", "intProp" );
+ assertEquals(42, ((Integer)value).intValue());
+
+ value = binding.getOperationProperty( "op2", "p2" );
+ assertEquals("op2bla", value);
+ value = binding.getOperationProperty( "op2", "intProp" );
+ assertEquals(77, ((Integer)value).intValue());
+ }
+
+
}