From 1602367641827b9c87ce52ba17acaaff7ca2f11b Mon Sep 17 00:00:00 2001 From: antelder Date: Fri, 6 Feb 2009 11:36:10 +0000 Subject: 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 --- .../sca/binding/jms/impl/BindingProperty.java | 45 ++++ .../tuscany/sca/binding/jms/impl/JMSBinding.java | 30 +++ .../sca/binding/jms/impl/JMSBindingProcessor.java | 44 +++- .../jms/impl/JMSBindingProcessorTestCase.java | 235 +++++++++++++++++++++ 4 files changed, 347 insertions(+), 7 deletions(-) create mode 100644 branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java (limited to 'branches/sca-java-1.x/modules/binding-jms') 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 destinationProperties = new HashMap(); private String connectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map connectionFactoryProperties = new HashMap(); private String activationSpecName = null; private String activationSpecCreate = null; + private Map activationSpecProperties = new HashMap(); private String responseActivationSpecName = null; private String responseActivationSpecCreate = null; + private Map responseActivationSpecProperties = new HashMap(); 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 responseDestinationProperties = new HashMap(); private String responseConnectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map responseConnectionFactoryProperties = new HashMap(); // 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 getDestinationProperties() { + return destinationProperties; + } + + public Map getConnectionFactoryProperties() { + return connectionFactoryProperties; + } + + public Map getActivationSpecProperties() { + return activationSpecProperties; + } + + public Map getResponseActivationSpecProperties() { + return responseActivationSpecProperties; + } + + public Map getResponseDestinationProperties() { + return responseDestinationProperties; + } + + public Map 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 { 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 { 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 { } 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 { } } + private Map parseBindingProperties(XMLStreamReader reader) throws XMLStreamException { + Map props = new HashMap(); + 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 { } // 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 { + " " + ""; + private static final String DEST_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String RESP_DEST_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String RESP_CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private static final String RESP_AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + private XMLInputFactory inputFactory; private StAXArtifactProcessor 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()); + } } -- cgit v1.2.3