diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-06 11:36:10 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2009-02-06 11:36:10 +0000 |
commit | 1602367641827b9c87ce52ba17acaaff7ca2f11b (patch) | |
tree | 39b2f41bbb26b45b83ea0844608cf06fffd41824 | |
parent | 2a8ad11a7d2ff811302e721103f666efd8ad14e8 (diff) |
TUSCANY-2820: start adding support for the varrious property elements on the jms binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@741542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
4 files changed, 347 insertions, 7 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java new file mode 100644 index 0000000000..d345130d4f --- /dev/null +++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java @@ -0,0 +1,45 @@ +/*
+ * 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.binding.jms.impl;
+
+public class BindingProperty {
+
+ private String name;
+ private String type;
+ private Object value;
+
+ public BindingProperty(String name, String type, Object value) {
+ this.name = name;
+ this.type = type;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+}
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 90b4d2488b..fcb640398d 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 @@ -68,22 +68,28 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { private String destinationName = JMSBindingConstants.DEFAULT_DESTINATION_NAME; private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map<String, BindingProperty> destinationProperties = new HashMap<String, BindingProperty>(); private String connectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map<String, BindingProperty> connectionFactoryProperties = new HashMap<String, BindingProperty>(); private String activationSpecName = null; private String activationSpecCreate = null; + private Map<String, BindingProperty> activationSpecProperties = new HashMap<String, BindingProperty>(); private String responseActivationSpecName = null; private String responseActivationSpecCreate = null; + private Map<String, BindingProperty> responseActivationSpecProperties = new HashMap<String, BindingProperty>(); private String responseDestinationName = JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME; private String responseDestinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; private String responseDestinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map<String, BindingProperty> responseDestinationProperties = new HashMap<String, BindingProperty>(); private String responseConnectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map<String, BindingProperty> responseConnectionFactoryProperties = new HashMap<String, BindingProperty>(); // Provides the name of the factory that interfaces to the JMS API for us. private String jmsResourceFactoryName = JMSBindingConstants.DEFAULT_RF_CLASSNAME; @@ -615,4 +621,28 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint { this.intentAttachPointType = intentAttachPointType; } + public Map<String, BindingProperty> getDestinationProperties() { + return destinationProperties; + } + + public Map<String, BindingProperty> getConnectionFactoryProperties() { + return connectionFactoryProperties; + } + + public Map<String, BindingProperty> getActivationSpecProperties() { + return activationSpecProperties; + } + + public Map<String, BindingProperty> getResponseActivationSpecProperties() { + return responseActivationSpecProperties; + } + + public Map<String, BindingProperty> getResponseDestinationProperties() { + return responseDestinationProperties; + } + + public Map<String, BindingProperty> getResponseConnectionFactoryProperties() { + return responseConnectionFactoryProperties; + } + } 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 c586a9ee26..eb50c11843 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 @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.binding.jms.impl; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; +import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; @@ -399,25 +400,28 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { if (create != null && create.length() > 0) { jmsBinding.setDestinationCreate(create); } + + jmsBinding.getDestinationProperties().putAll(parseBindingProperties(reader)); } - private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) { + private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { jmsBinding.setConnectionFactoryName(name); } else { error("MissingConnectionFactoryName", reader); } + jmsBinding.getConnectionFactoryProperties().putAll(parseBindingProperties(reader)); } - private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) { + private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { - warning("DoesntProcessActivationSpec", jmsBinding); jmsBinding.setActivationSpecName(name); } else { warning("MissingActivationSpecName", reader); } + jmsBinding.getActivationSpecProperties().putAll(parseBindingProperties(reader)); } private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { @@ -442,9 +446,11 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { if (create != null && create.length() > 0) { jmsBinding.setResponseDestinationCreate(create); } + + jmsBinding.getResponseDestinationProperties().putAll(parseBindingProperties(reader)); } - private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) { + private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { warning("DoesntProcessResponseConnectionFactory", jmsBinding); @@ -452,16 +458,17 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { } else { warning("MissingResponseConnectionFactory", reader); } + jmsBinding.getResponseConnectionFactoryProperties().putAll(parseBindingProperties(reader)); } - private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) { + private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { - warning("DoesntProcessResponseActivationSpec", jmsBinding); jmsBinding.setResponseActivationSpecName(name); } else { warning("MissingResponseActivationSpec", reader); } + jmsBinding.getResponseActivationSpecProperties().putAll(parseBindingProperties(reader)); } private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { @@ -714,6 +721,28 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { } } + private Map<String, BindingProperty> parseBindingProperties(XMLStreamReader reader) throws XMLStreamException { + Map<String, BindingProperty> props = new HashMap<String, BindingProperty>(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("property".equals(elementName)) { + String name = reader.getAttributeValue(null, "name"); + if (name == null || name.length() < 1) { + error("InvalidPropertyElement", reader, elementName); + } + String type = reader.getAttributeValue(null, "type"); + String value = reader.getElementText(); + props.put(name, new BindingProperty(name, type, value)); + } + break; + case END_ELEMENT: + return props; + } + } + } + /** * Preserve an existing public method. The method validate() is a legacy method * that was called from reading am XML stream via the read(XMLStreamReader) method above. @@ -762,7 +791,8 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { } // Connection factory and activation Specification are mutually exclusive. - if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { + if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 ) + && !JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME.equals(connectionFactoryName) ) { String activationSpecName = jmsBinding.getActivationSpecName(); if ((activationSpecName != null) && (activationSpecName.length() > 0 )) { error("ConnectionFactoryActivationSpecContradiction", jmsBinding, connectionFactoryName, activationSpecName ); 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 ff41751d7d..b715d4997c 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 @@ -148,6 +148,132 @@ public class JMSBindingProcessorTestCase extends TestCase { + " </component>"
+ "</composite>";
+ private static final String DEST_PROPS =
+ "<?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>"
+ + " <destination name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </destination>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
+ private static final String CF_PROPS =
+ "<?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>"
+ + " <connectionFactory name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </connectionFactory>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
+ private static final String AS_PROPS =
+ "<?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>"
+ + " <activationSpec name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </activationSpec>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
+ private static final String RESP_DEST_PROPS =
+ "<?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>"
+ + " <response>"
+ + " <destination name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </destination>"
+ + " </response>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
+ private static final String RESP_CF_PROPS =
+ "<?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>"
+ + " <response>"
+ + " <connectionFactory name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </connectionFactory>"
+ + " </response>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
+ private static final String RESP_AS_PROPS =
+ "<?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>"
+ + " <response>"
+ + " <activationSpec name=\"foo\">"
+ + " <property name=\"xxx\" type=\"yyy\">"
+ + " some value text"
+ + " </property>"
+ + " <property name=\"two\">"
+ + " bla"
+ + " </property>"
+ + " </activationSpec>"
+ + " </response>"
+ + " </binding.jms>"
+ + " </service>"
+ + " </component>"
+ + "</composite>";
+
private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
private Monitor monitor;
@@ -267,4 +393,113 @@ public class JMSBindingProcessorTestCase extends TestCase { assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) );
}
}
+
+ public void testDestinationProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(DEST_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getDestinationProperties());
+ assertEquals(2, binding.getDestinationProperties().size());
+ BindingProperty bp = binding.getDestinationProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getDestinationProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
+ public void testConnectionFactoryProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CF_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getConnectionFactoryProperties());
+ assertEquals(2, binding.getConnectionFactoryProperties().size());
+ BindingProperty bp = binding.getConnectionFactoryProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getConnectionFactoryProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
+ public void testActivationSpecProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(AS_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getActivationSpecProperties());
+ assertEquals(2, binding.getActivationSpecProperties().size());
+ BindingProperty bp = binding.getActivationSpecProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getActivationSpecProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
+ public void testResponseDestinationProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_DEST_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getResponseDestinationProperties());
+ assertEquals(2, binding.getResponseDestinationProperties().size());
+ BindingProperty bp = binding.getResponseDestinationProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getResponseDestinationProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
+ public void testResponseConnectionFactoryProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_CF_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getResponseConnectionFactoryProperties());
+ assertEquals(2, binding.getResponseConnectionFactoryProperties().size());
+ BindingProperty bp = binding.getResponseConnectionFactoryProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getResponseConnectionFactoryProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
+ public void testResponseActivationSpecProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_AS_PROPS));
+
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ assertNotNull(binding);
+ assertNotNull(binding.getResponseActivationSpecProperties());
+ assertEquals(2, binding.getResponseActivationSpecProperties().size());
+ BindingProperty bp = binding.getResponseActivationSpecProperties().get("xxx");
+ assertEquals("xxx", bp.getName());
+ assertEquals("yyy", bp.getType());
+ assertEquals("some value text", bp.getValue().toString().trim());
+ BindingProperty bp2 = binding.getResponseActivationSpecProperties().get("two");
+ assertEquals("two", bp2.getName());
+ assertEquals(null, bp2.getType());
+ assertEquals("bla", bp2.getValue().toString().trim());
+ }
}
|