summaryrefslogtreecommitdiffstats
path: root/branches
diff options
context:
space:
mode:
authorbeckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68>2009-02-12 16:27:20 +0000
committerbeckerdo <beckerdo@13f79535-47bb-0310-9956-ffa450edef68>2009-02-12 16:27:20 +0000
commit06e86a2c10c32cd86a7a6961f0d73b57ebd98fdc (patch)
tree49c2314a634760c66037fa5f56144ddb6c3b4216 /branches
parent11d9d3ab051dbd1cb7afe8fded7505aaa19200da (diff)
TUSCANY-2825 JMSBindingProcessor missing 'write' method implementation
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@743796 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches')
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/BindingProperty.java26
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java132
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java3
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java630
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorTestCase.java38
-rw-r--r--branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java361
6 files changed, 1148 insertions, 42 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
index d345130d4f..277cba43ca 100644
--- 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
@@ -42,4 +42,30 @@ public class BindingProperty {
public Object getValue() {
return value;
}
+
+ @Override
+ public boolean equals( Object object ) {
+ return ( object instanceof BindingProperty ) && equals( (BindingProperty) object );
+ }
+
+ /**
+ * Test whether this and another Binding Property are equal.
+ * @param property
+ * @return true if all fields of property match.
+ */
+ public boolean equals( BindingProperty property ) {
+ if ( name == null && property.getName() != null )
+ return false;
+ else if ( !name.equals( property.getName() ))
+ return false;
+ else if ( type == null && property.getType() != null )
+ return false;
+ else if ( !type.equals( property.getType() ))
+ return false;
+ else if ( value == null && property.getValue() != null )
+ return false;
+ else if ( !value.equals( property.getValue() ))
+ return false;
+ return true;
+ }
}
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 1b96547335..296ad1aa44 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
@@ -20,6 +20,7 @@ package org.apache.tuscany.sca.binding.jms.impl;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -108,6 +109,7 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
// If the operation selector is derived automatically from the service interface it's stored here
private String operationSelectorName = null;
+ private boolean containsHeaders = false;
private String replyTo;
private String jmsType;
private String jmsCorrelationId;
@@ -435,6 +437,14 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
this.operationSelectorName = operationSelectorName;
}
+ public void setHeaders( boolean containsHeaders ) {
+ this.containsHeaders = containsHeaders;
+ }
+
+ public boolean containsHeaders() {
+ return this.containsHeaders;
+ }
+
public String getReplyTo() {
return replyTo;
}
@@ -447,6 +457,7 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
return jmsType;
}
public void setJMSType(String jmsType) {
+ setHeaders( true );
this.jmsType = jmsType;
}
@@ -455,6 +466,7 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
}
public void setJMSCorrelationId(String jmsCorrelationId) {
+ setHeaders( true );
this.jmsCorrelationId = jmsCorrelationId;
}
@@ -462,6 +474,7 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
return deliveryModePersistent;
}
public void setJMSDeliveryMode(boolean persistent) {
+ setHeaders( true );
this.deliveryModePersistent = Boolean.valueOf(persistent);
}
@@ -470,14 +483,16 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
}
public void setJMSPriority(int jmsPriority) {
+ setHeaders( true );
this.jmsPriority = Integer.valueOf(jmsPriority);
}
public Long getJMSTimeToLive() {
- return timeToLive.longValue();
+ return timeToLive;
}
public void setJMSTimeToLive(long timeToLive) {
+ setHeaders( true );
this.timeToLive = Long.valueOf(timeToLive);
}
@@ -493,6 +508,10 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
properties.put(name, value);
}
+ protected Map<String, Object> getProperties() {
+ return properties;
+ }
+
/**
* Adds an operationName to this binding.
* @param opName
@@ -708,4 +727,115 @@ public class JMSBinding implements BindingRRB, PolicySetAttachPoint {
return operationPropertiesProperties.get(opName);
}
+ @Override
+ public boolean equals( Object object ) {
+ return ( object instanceof JMSBinding ) && equals( (JMSBinding) object );
+ }
+
+ /**
+ * Compares two JMS bindings for equality.
+ * Because of the many fields, this comparison is rather large O(n).
+ * @param binding test binding for equality comparison
+ * @return boolean stating whether objects are equal
+ */
+ public boolean equals( JMSBinding binding ) {
+ // Test all fields for equality.
+ // First test simple fields to quickly weed out mismatches.
+ if ( !optStringEquals( this.uri, binding.getURI() )) return false;
+ if ( !optStringEquals( this.name, binding.getName() )) return false;
+ if ( !optStringEquals( this.destinationName, binding.getDestinationName() )) return false;
+ if ( !optStringEquals( this.correlationScheme, binding.getCorrelationScheme() )) return false;
+ if ( !optStringEquals( this.initialContextFactoryName, binding.getInitialContextFactoryName() )) return false;
+ if ( !optStringEquals( this.jndiURL, binding.getJndiURL() )) return false;
+ if ( !optStringEquals( this.requestConnectionName, binding.getRequestConnectionName() )) return false;
+ if ( !optStringEquals( this.responseConnectionName, binding.getResponseConnectionName() )) return false;
+ if ( !optStringEquals( this.jmsSelector, binding.getJMSSelector() )) return false;
+ if ( !equals( properties, binding.getProperties()) )
+ return false;
+
+ // Test operation properties
+ Set<String> operationNamesA = this.getOperationNames();
+ Set<String> operationNamesB = binding.getOperationNames();
+ if ( operationNamesA != null && operationNamesB != null ) {
+ if ( operationNamesA == null && operationNamesB != null ) return false;
+ if ( operationNamesA != null && operationNamesB == null ) return false;
+ if ( operationNamesA.size() != operationNamesB.size() ) return false;
+ for(Iterator<String> it=operationNamesA.iterator(); it.hasNext(); ) {
+ String opName = it.next();
+ if ( !operationNamesB.contains( opName )) {
+ return false;
+ }
+ }
+ }
+
+ // Destination properties
+ if ( !optStringEquals( this.getDestinationName(), binding.getDestinationName() )) return false;
+ if ( !optStringEquals( this.getDestinationType(), binding.getDestinationType() )) return false;
+
+ // Connection factory properties
+ if ( !optStringEquals( this.getConnectionFactoryName(), binding.getConnectionFactoryName() )) return false;
+
+ // Activation spec properties
+ if ( !optStringEquals( this.getActivationSpecName(), binding.getActivationSpecName() )) return false;
+
+ // Response properties
+ if ( !optStringEquals( this.getResponseDestinationName(), binding.getResponseDestinationName() )) return false;
+ if ( !optStringEquals( this.getResponseActivationSpecName(), binding.getResponseActivationSpecName() )) return false;
+ if ( !optStringEquals( this.getResponseConnectionFactoryName(), binding.getResponseConnectionFactoryName() )) return false;
+
+ // Resource adapter
+ if ( !optStringEquals( this.getResourceAdapterName(), binding.getResourceAdapterName() )) return false;
+
+ // Other fields could also be checked for equality. See class fields for details.
+ return true;
+ }
+
+ /**
+ * Tests if Strings are equal.
+ * Either one may be null. This will match true if both
+ * are null or both are non-null and equal.
+ * @param p1 property list 1
+ * @param p2 property list 2
+ * @return whether or not properties are equal
+ */
+ public static boolean optStringEquals( String s1, String s2 ) {
+ if ( s1 == null && s2 == null ) return true;
+ if ( s1 != null && s2 == null ) return false;
+ if ( s1 == null && s2 != null ) return false;
+ return s1.equals( s2 );
+ }
+
+ /**
+ * Tests if two property lists are equal.
+ * Either one may be null. This will match true if both
+ * are null or both are non-null and equal.
+ * @param p1 property list 1
+ * @param p2 property list 2
+ * @return whether or not properties are equal
+ */
+ public static boolean equals( Map<String, Object> p1, Map<String, Object> p2 ) {
+ if ( p1 == null && p2 == null)
+ return true;
+ if ( p1 == null || p2 == null)
+ return false;
+ if ( p1.size() != p2.size())
+ return false;
+
+ // For both the keys and values of a map
+ for (Iterator it=p1.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry)it.next();
+ Object k1 = entry.getKey();
+ Object v1 = entry.getValue();
+ Object v2 = p2.get( k1 );
+
+ if ( v1 == null && v2 != null )
+ return false;
+ if ( v1 != null && v2 == null )
+ return false;
+ if ( !v1.equals( v2 ))
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
index de10f9ca60..a3dfa8f618 100644
--- a/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
+++ b/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingConstants.java
@@ -70,5 +70,8 @@ public interface JMSBindingConstants {
String CALLBACK_Q_PROPERTY = "scaCallbackQueue";
String CONVERSATION_ID_PROPERTY = "scaConversationId";
+ // XML element and attribute names
+ String HEADERS = "headers";
+
int MSG_CTXT_POSITION = 0;
}
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 a330ef631e..ef942bdab0 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
@@ -23,7 +23,9 @@ import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
@@ -31,6 +33,7 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.tuscany.sca.assembly.Extension;
import org.apache.tuscany.sca.assembly.OperationSelector;
import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
@@ -64,6 +67,14 @@ import org.apache.tuscany.sca.policy.PolicyFactory;
* operationProperties="QName"?
* ...>
*
+ * <headers JMSType="string"?
+ * JMSCorrelationId="string"?
+ * JMSDeliveryMode="string"?
+ * JMSTimeToLive="int"?
+ * JMSPriority="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </headers>?
+ *
* <destination name="xs:anyURI" type="string"? create="string"?>
* <property name="NMTOKEN" type="NMTOKEN">*
* </destination>?
@@ -98,14 +109,6 @@ import org.apache.tuscany.sca.policy.PolicyFactory;
* <property name="NMTOKEN" type="NMTOKEN">*
* </resourceAdapter>?
*
- * <headers JMSType="string"?
- * JMSCorrelationId="string"?
- * JMSDeliveryMode="string"?
- * JMSTimeToLive="int"?
- * JMSPriority="string"?>
- * <property name="NMTOKEN" type="NMTOKEN">*
- * </headers>?
- *
* <operationProperties name="string" nativeOperation="string"?>
* <property name="NMTOKEN" type="NMTOKEN">*
* <headers JMSType="string"?
@@ -125,7 +128,6 @@ import org.apache.tuscany.sca.policy.PolicyFactory;
*/
public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
-
private PolicyFactory policyFactory;
private PolicyAttachPointProcessor policyProcessor;
protected StAXArtifactProcessor<Object> extensionProcessor;
@@ -294,7 +296,8 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) {
endFound = true;
} else {
- error("UnexpectedElement", reader, x.toString());
+ error("UnexpectedElement: expected " + JMSBindingConstants.BINDING_JMS_QNAME + ", found " + x.toString(),
+ reader, x.toString());
}
}
}
@@ -368,16 +371,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
return null;
}
- public void write(JMSBinding rmiBinding, XMLStreamWriter writer) throws ContributionWriteException,
- XMLStreamException {
- // Write a <binding.jms>
- writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS);
-
- // FIXME Implement
-
- writer.writeEndElement();
- }
-
private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
String name = reader.getAttributeValue(null, "name");
if (name != null && name.length() > 0) {
@@ -516,7 +509,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
* </headers>?
*/
private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
-
String jmsType = reader.getAttributeValue(null, "JMSType");
if (jmsType != null && jmsType.length() > 0) {
jmsBinding.setJMSType(jmsType);
@@ -572,8 +564,9 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
}
private void parseProperty(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException {
+ jmsBinding.setHeaders( true );
String name = reader.getAttributeValue(null, "name");
- String type = reader.getAttributeValue(null, "type");
+ String type = reader.getAttributeValue(null, "type");
if (name != null && name.length() > 0) {
Object value = reader.getElementText();
if ("boolean".equalsIgnoreCase(type)) {
@@ -842,4 +835,597 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> {
}
}
+
+ /**
+ * Given a valid JMSBinding, write it as XML using the given XML writer.
+ *
+ * This high-level method handles binding.jms element and its attributes.
+ * Sub elements have their own writer methods and are called from here.
+ * <binding.jms
+ * correlationScheme="string"?
+ * initialContextFactory="xs:anyURI"?
+ * jndiURL="xs:anyURI"?
+ * requestConnection="QName"?
+ * responseConnection="QName"?
+ * operationProperties="QName"?
+ * ...>
+ *
+ * @param jmsBinding JMSBinding model
+ * @param writer an XMLStreamWriter that writes XML attributes and elements
+ */
+ public void write(JMSBinding jmsBinding, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ // Write a <binding.jms>
+ writer.writeStartElement(Constants.SCA10_NS, JMSBindingConstants.BINDING_JMS);
+
+ if (jmsBinding.getName() != null) {
+ writer.writeAttribute("name", jmsBinding.getName());
+ }
+
+ if (jmsBinding.getURI() != null) {
+ writer.writeAttribute("uri", jmsBinding.getURI());
+ }
+
+ String dest = jmsBinding.getDestinationName();
+ if (dest != null) {
+ if ( !dest.equals( JMSBindingConstants.DEFAULT_DESTINATION_NAME ) ) {
+ writer.writeAttribute("uri", "jms:" + jmsBinding.getDestinationName());
+ }
+ }
+
+ String correlationScheme = jmsBinding.getCorrelationScheme();
+ if ( correlationScheme != null ) {
+ if ( !correlationScheme.equals(JMSBindingConstants.CORRELATE_MSG_ID) ) {
+ writer.writeAttribute("correlationScheme", jmsBinding.getCorrelationScheme());
+ }
+ }
+
+ if ( jmsBinding.getInitialContextFactoryName() != null ) {
+ writer.writeAttribute("initialContextFactory", jmsBinding.getInitialContextFactoryName());
+ }
+
+ if ( jmsBinding.getJndiURL() != null ) {
+ writer.writeAttribute("jndiURL", jmsBinding.getJndiURL());
+ }
+
+ if ( jmsBinding.getRequestConnectionName() != null ) {
+ writer.writeAttribute("requestConnection", jmsBinding.getRequestConnectionName());
+ }
+
+ if ( jmsBinding.getResponseConnectionName() != null ) {
+ writer.writeAttribute("responseConnection", jmsBinding.getResponseConnectionName());
+ }
+
+ if ( jmsBinding.containsHeaders() ) {
+ writeHeaders( jmsBinding, writer);
+ }
+
+ writeOperationProperties( jmsBinding, writer );
+
+ writeSubscriptionHeaders( jmsBinding, writer );
+
+ writeDestinationProperties( jmsBinding, writer );
+
+ writeConnectionFactoryProperties( jmsBinding, writer );
+
+ writeActivationSpecProperties( jmsBinding, writer );
+
+ // Write response info, if names are not defaults.
+ String responseDestName = jmsBinding.getResponseDestinationName();
+ String responseCFName = jmsBinding.getResponseConnectionFactoryName();
+ String responseASName = jmsBinding.getResponseActivationSpecName();
+ if (( responseDestName != null && !responseDestName.equals(JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME)) ||
+ (responseCFName != null && !responseCFName.equals(JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME)) ||
+ responseASName != null ) {
+
+ writer.writeStartElement("response");
+ writeResponseDestinationProperties( jmsBinding, writer );
+ writeResponseConnectionFactoryProperties( jmsBinding, writer );
+ writeResponseActivationSpecProperties( jmsBinding, writer );
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters( " " );
+ }
+
+ writeResourceAdapterProperties( jmsBinding, writer );
+
+ writer.writeEndElement();
+ }
+
+ /**
+ * Writes headers element and its attributes.
+ * <headers JMSType=”string”?
+ * JMSCorrelationID=”string”?
+ * JMSDeliveryMode=”PERSISTENT or NON_PERSISTENT”?
+ * JMSTimeToLive=”long”?
+ * JMSPriority=”0 .. 9”?>
+ * <property name=”NMTOKEN” type=”NMTOKEN”?>*
+ * </headers>?
+ */
+ private void writeHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+
+ writer.writeStartElement(JMSBindingConstants.HEADERS);
+
+ String jmsType = jmsBinding.getJMSType();
+ if (jmsType != null && jmsType.length() > 0) {
+ writer.writeAttribute("JMSType", jmsType);
+ }
+
+ String jmsCorrelationId = jmsBinding.getJMSCorrelationId();
+ if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) {
+ writer.writeAttribute("JMSCorrelationId", jmsCorrelationId);
+ }
+
+ Boolean jmsDeliveryMode = jmsBinding.isdeliveryModePersistent();
+ if (jmsDeliveryMode != null) {
+ if ( jmsDeliveryMode.booleanValue() )
+ writer.writeAttribute("JMSDeliveryMode", "PERSISTENT");
+ else
+ writer.writeAttribute("JMSDeliveryMode", "NON_PERSISTENT");
+ }
+
+ Long jmsTimeToLive = jmsBinding.getJMSTimeToLive();
+ if (jmsTimeToLive != null) {
+ writer.writeAttribute("JMSTimeToLive", jmsTimeToLive.toString());
+ }
+
+ Integer jmsPriority = jmsBinding.getJMSPriority();
+ if (jmsPriority != null) {
+ writer.writeAttribute("JMSPriority", jmsPriority.toString());
+ }
+
+ Map<String, Object> properties = jmsBinding.getProperties();
+ writeProperties( properties, writer );
+ //writer.writeCharacters( " " );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters( " " );
+ }
+
+ /**
+ * Writes a complete set of properties to the given XML stream writer.
+ * If the value is of type string, the property will be output:
+ * <property name="key">StringValue</property>
+ * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be
+ * <property name="key" type="int">42</property>
+ */
+ private void writeProperties(Map<String, Object> properties, XMLStreamWriter writer) throws XMLStreamException {
+ if (( properties == null ) || ( properties.size() == 0 )) {
+ return;
+ }
+
+ // For both the keys and values of a map
+ for (Iterator it=properties.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry)it.next();
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+
+ writer.writeStartElement( "property" );
+ writer.writeAttribute("name", key.toString());
+
+ if ( value instanceof String) {
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof BindingProperty ) {
+ BindingProperty property = (BindingProperty) value;
+ String type = property.getType();
+ if ( type != null ) {
+ writer.writeAttribute("type", type);
+ }
+ writer.writeCharacters( property.getValue().toString() );
+ } else if ( value instanceof Boolean ) {
+ writer.writeAttribute("type", "boolean");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Byte ) {
+ writer.writeAttribute("type", "byte");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Short ) {
+ writer.writeAttribute("type", "short");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Integer ) {
+ writer.writeAttribute("type", "int");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Long ) {
+ writer.writeAttribute("type", "long");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Float ) {
+ writer.writeAttribute("type", "float");
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof Double ) {
+ writer.writeAttribute("type", "double");
+ writer.writeCharacters( value.toString() );
+ } else {
+ writer.writeCharacters( value.toString() );
+ }
+ writer.writeEndElement();
+ }
+ }
+
+ /**
+ * Writes operation properties if there are any.
+ *
+ * <operationProperties name="string" nativeOperation="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * <headers JMSType="string"?
+ * JMSCorrelationId="string"?
+ * JMSDeliveryMode="string"?
+ * JMSTimeToLive="int"?
+ * JMSPriority="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </headers>?
+ * </operationProperties>*
+ * </binding.jms>
+ */
+ private void writeOperationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ Set<String> operationNames = jmsBinding.getOperationNames();
+ if (operationNames == null || (operationNames.size() < 1)) {
+ return;
+ }
+
+ for(Iterator<String> it=operationNames.iterator(); it.hasNext(); ) {
+ String opName = it.next();
+
+ writer.writeStartElement("operationProperties");
+ writer.writeAttribute("name", opName);
+
+ String nativeOperation = jmsBinding.getNativeOperationName(opName);
+ if (nativeOperation != null && nativeOperation.length() > 0) {
+ if ( !nativeOperation.equals( opName )) {
+ writer.writeAttribute("nativeOperation", nativeOperation);
+ }
+ }
+
+ Map<String, BindingProperty> operationPropertiesProperties =
+ jmsBinding.getOperationPropertiesProperties(opName);
+ writeBindingProperties( operationPropertiesProperties, writer );
+
+ String jmsType = jmsBinding.getOperationJMSType(opName);
+ String jmsCorrelationId = jmsBinding.getOperationJMSCorrelationId(opName);
+ Boolean jmsDeliveryMode = jmsBinding.getOperationJMSDeliveryMode(opName);
+ Long jmsTimeToLive = jmsBinding.getOperationJMSTimeToLive(opName);
+ Integer jmsPriority = jmsBinding.getOperationJMSPriority(opName);
+ Map<String, Object> operationProperties = jmsBinding.getOperationProperties(opName);
+
+ if (jmsType != null || jmsCorrelationId != null || jmsDeliveryMode != null ||
+ jmsTimeToLive != null || jmsPriority != null || operationProperties != null) {
+
+ writer.writeStartElement(JMSBindingConstants.HEADERS);
+
+ if (jmsType != null && jmsType.length() > 0) {
+ writer.writeAttribute("JMSType", jmsType);
+ }
+
+ if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) {
+ writer.writeAttribute("JMSCorrelationId", jmsCorrelationId);
+ }
+
+ if (jmsDeliveryMode != null) {
+ if (jmsDeliveryMode.booleanValue())
+ writer.writeAttribute("JMSDeliveryMode", "PERSISTENT");
+ else
+ writer.writeAttribute("JMSDeliveryMode", "NON_PERSISTENT");
+ }
+
+ if (jmsTimeToLive != null) {
+ writer.writeAttribute("JMSTimeToLive", jmsTimeToLive.toString());
+ }
+
+ if (jmsPriority != null) {
+ writer.writeAttribute("JMSPriority", jmsPriority.toString());
+ }
+
+ writeProperties( operationProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ // writer.writeCharacters( " " );
+ }
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+ }
+
+ /**
+ * Writes a complete set of properties to the given XML stream writer.
+ * If the value is of type string, the property will be output:
+ * <property name="key">StringValue</property>
+ * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be
+ * <property name="key" type="int">42</property>
+ */
+ private void writeBindingProperties(Map<String, BindingProperty> properties, XMLStreamWriter writer) throws XMLStreamException {
+ if (( properties == null ) || ( properties.size() == 0 )) {
+ return;
+ }
+
+ // For both the keys and values of a map
+ for (Iterator it=properties.entrySet().iterator(); it.hasNext(); ) {
+ Map.Entry entry = (Map.Entry)it.next();
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+
+ writer.writeStartElement( "property" );
+ writer.writeAttribute("name", key.toString());
+
+ if ( value instanceof String) {
+ writer.writeCharacters( value.toString() );
+ } else if ( value instanceof BindingProperty ) {
+ BindingProperty property = (BindingProperty) value;
+ String type = property.getType();
+ if ( type != null ) {
+ writer.writeAttribute("type", type);
+ }
+ writer.writeCharacters( property.getValue().toString() );
+ } else {
+ writer.writeCharacters( value.toString() );
+ }
+ writer.writeEndElement();
+ }
+ }
+
+ /**
+ * Writes subscription headers if there are any.
+ * <complexType name="SubscriptionHeaders">
+ * <attribute name="JMSSelector" type="string"/>
+ * </complexType>
+ *
+ */
+ private void writeSubscriptionHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String jmsSubscriptionHeaders = jmsBinding.getJMSSelector();
+ if (jmsSubscriptionHeaders != null && jmsSubscriptionHeaders.length() > 0) {
+ writer.writeStartElement("SubscriptionHeaders");
+ writer.writeAttribute("JMSSelector", jmsSubscriptionHeaders);
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ // writer.writeCharacters( " " );
+ }
+ }
+
+ /**
+ * Writes destination properties if there are any.
+ * <destination name="xs:anyURI" type="string"? create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </destination>?
+ */
+ private void writeDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String destinationName = jmsBinding.getDestinationName();
+ if (destinationName == null || (destinationName.length() < 1)) {
+ return;
+ }
+ if (destinationName.equals(JMSBindingConstants.DEFAULT_DESTINATION_NAME)) {
+ return;
+ }
+
+ writer.writeStartElement("destination");
+
+ if ( destinationName != null && destinationName.length() > 0) {
+ writer.writeAttribute("name", destinationName);
+ }
+
+ // Type not handled yet
+ // String destinationType = jmsBinding.getDestinationType();
+ // if ( destinationType != null && destinationType.length() > 0) {
+ // writer.writeAttribute("type", destinationType);
+ // }
+
+ String destinationCreate = jmsBinding.getDestinationCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> destinationProperties =
+ jmsBinding.getDestinationProperties();
+ writeBindingProperties( destinationProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes connection factory properties if there are any.
+ * <connectionFactory name="xs:anyURI" create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </connectionFactory>?
+ */
+ private void writeConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String cfName = jmsBinding.getConnectionFactoryName();
+ if (cfName == null || (cfName.length() < 1)) {
+ return;
+ }
+ if ( cfName.equals(JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME) ) {
+ return;
+ }
+
+ writer.writeStartElement("connectionFactory");
+
+ if ( cfName != null && cfName.length() > 0) {
+ writer.writeAttribute("name", cfName);
+ }
+
+ String destinationCreate = jmsBinding.getConnectionFactoryCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> cfProperties =
+ jmsBinding.getConnectionFactoryProperties();
+ writeBindingProperties( cfProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes activation Spec properties if there are any.
+ * <activationSpec name="xs:anyURI" create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </activationSpec>?
+ *
+ */
+ private void writeActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String asName = jmsBinding.getActivationSpecName();
+ if (asName == null || (asName.length() < 1)) {
+ return;
+ }
+
+ writer.writeStartElement("activationSpec");
+
+ if ( asName != null && asName.length() > 0) {
+ writer.writeAttribute("name", asName);
+ }
+
+ String destinationCreate = jmsBinding.getActivationSpecCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> cfProperties =
+ jmsBinding.getActivationSpecProperties();
+ writeBindingProperties( cfProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes response destination properties if there are any.
+ * <destination name="xs:anyURI" type="string"? create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </destination>?
+ */
+ private void writeResponseDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String destinationName = jmsBinding.getResponseDestinationName();
+ if (destinationName == null || (destinationName.length() < 1)) {
+ return;
+ }
+ if (destinationName.equals(JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME)) {
+ return;
+ }
+
+ writer.writeStartElement("destination");
+
+ if ( destinationName != null && destinationName.length() > 0) {
+ writer.writeAttribute("name", destinationName);
+ }
+
+ // Type not handled yet
+ // String destinationType = jmsBinding.getDestinationType();
+ // if ( destinationType != null && destinationType.length() > 0) {
+ // writer.writeAttribute("type", destinationType);
+ // }
+
+ String destinationCreate = jmsBinding.getResponseDestinationCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> destinationProperties =
+ jmsBinding.getResponseDestinationProperties();
+ writeBindingProperties( destinationProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes response connection factory properties if there are any.
+ * <connectionFactory name="xs:anyURI" create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </connectionFactory>?
+ *
+ */
+ private void writeResponseConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String cfName = jmsBinding.getResponseConnectionFactoryName();
+ if (cfName == null || (cfName.length() < 1)) {
+ return;
+ }
+ if (cfName.equals(JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME)) {
+ return;
+ }
+
+ writer.writeStartElement("connectionFactory");
+
+ if ( cfName != null && cfName.length() > 0) {
+ writer.writeAttribute("name", cfName);
+ }
+
+ String destinationCreate = jmsBinding.getResponseConnectionFactoryCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> cfProperties =
+ jmsBinding.getResponseConnectionFactoryProperties();
+ writeBindingProperties( cfProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes response activation Spec properties if there are any.
+ * <activationSpec name="xs:anyURI" create="string"?>
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </activationSpec>?
+ *
+ */
+ private void writeResponseActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String asName = jmsBinding.getResponseActivationSpecName();
+ if (asName == null || (asName.length() < 1)) {
+ return;
+ }
+
+ writer.writeStartElement("activationSpec");
+
+ if ( asName != null && asName.length() > 0) {
+ writer.writeAttribute("name", asName);
+ }
+
+ String destinationCreate = jmsBinding.getResponseActivationSpecCreate();
+ if ( destinationCreate != null && destinationCreate.length() > 0) {
+ writer.writeAttribute("create", destinationCreate);
+ }
+
+ Map<String, BindingProperty> cfProperties =
+ jmsBinding.getResponseActivationSpecProperties();
+ writeBindingProperties( cfProperties, writer );
+
+ writer.writeEndElement();
+ // Strange bug. Without white space, headers end tag improperly read.
+ writer.writeCharacters(" ");
+ }
+
+ /**
+ * Writes resource adapter properties if there are any.
+ * <resourceAdapter name="NMTOKEN">?
+ * <property name="NMTOKEN" type="NMTOKEN">*
+ * </resourceAdapter>?
+ */
+ private void writeResourceAdapterProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException {
+ String asName = jmsBinding.getResourceAdapterName();
+ if (asName == null || (asName.length() < 1)) {
+ return;
+ }
+
+ writer.writeStartElement("resourceAdapter");
+
+ if ( asName != null && asName.length() > 0) {
+ writer.writeAttribute("name", asName);
+ }
+
+ Map<String, BindingProperty> cfProperties =
+ jmsBinding.getResourceAdapterProperties();
+ writeBindingProperties( cfProperties, writer );
+
+ writer.writeEndElement();
+ // 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 facdffffe9..29ab264c7c 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
@@ -44,8 +44,9 @@ import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
* Tests for JMS binding xml
*/
public class JMSBindingProcessorTestCase extends TestCase {
-
- private static final String COMPOSITE =
+ // Note: If you are adding new JMS binding read test cases,
+ // consider adding a similar test case to JMSBindingProcessorWriteTestCase.
+ public static final String COMPOSITE =
"<?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\">"
@@ -56,21 +57,21 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String HEADERS1 =
+ public static final String HEADERS1 =
"<?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\" >"
- + " <headers JMSType=\"myType\" JMSCorrelationID=\"myCorrelId\" JMSDeliveryMode=\"PERSISTENT\" JMSTimeToLive=\"54321\" JMSPriority=\"5\" >"
+ + " <headers JMSType=\"myType\" JMSCorrelationID=\"myCorrelId\" JMSDeliveryMode=\"PERSISTENT\" JMSTimeToLive=\"54321\" JMSPriority=\"5\">"
+ " </headers>"
+ " </binding.jms>"
+ " </service>"
+ " </component>"
+ "</composite>";
- private static final String PROPERTIES1 =
+ public static final String PROPERTIES1 =
"<?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\">"
@@ -86,7 +87,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String OP_PROPERTIES1 =
+ public static final String OP_PROPERTIES1 =
"<?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\">"
@@ -110,7 +111,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String OP_NAMES_NO_PROPERTIES1 =
+ public static final String OP_NAMES_NO_PROPERTIES1 =
"<?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\">"
@@ -126,7 +127,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String SELECTOR =
+ public static final String SELECTOR =
"<?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\">"
@@ -139,7 +140,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String COMPOSITE_INVALID_URI =
+ public static final String COMPOSITE_INVALID_URI =
"<?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\">"
@@ -151,7 +152,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ "</composite>";
// Invalid: contains both a response attribute and a response element.
- private static final String COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT =
+ public static final String COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT =
"<?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\">"
@@ -166,7 +167,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String DEST_PROPS =
+ public 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\">"
@@ -186,7 +187,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String CF_PROPS =
+ public 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\">"
@@ -206,7 +207,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String AS_PROPS =
+ public 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\">"
@@ -226,7 +227,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String RESP_DEST_PROPS =
+ public 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\">"
@@ -248,7 +249,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String RESP_CF_PROPS =
+ public 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\">"
@@ -270,7 +271,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String RESP_AS_PROPS =
+ public 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\">"
@@ -292,7 +293,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String OP_PROPS_PROPS =
+ public static final String OP_PROPS_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\">"
@@ -312,7 +313,7 @@ public class JMSBindingProcessorTestCase extends TestCase {
+ " </component>"
+ "</composite>";
- private static final String RES_ADPT_PROPS =
+ public static final String RES_ADPT_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\">"
@@ -654,5 +655,4 @@ public class JMSBindingProcessorTestCase extends TestCase {
}
}
-
}
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
new file mode 100644
index 0000000000..b7d3088c42
--- /dev/null
+++ b/branches/sca-java-1.x/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessorWriteTestCase.java
@@ -0,0 +1,361 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+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;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+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.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+
+/**
+ * Tests for JMS binding XML writes.
+ * In general, for each JMS binding XML read test case, there
+ * is a write test case.
+ */
+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;
+ private Monitor monitor;
+
+ @Override
+ protected void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ }
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ }
+
+ /**
+ * Test parsing valid composite definition. Valid composite populated with correct values expected.
+ * @throws Exception
+ */
+ public void testLoadValidComposite() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.COMPOSITE));
+ 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);
+ }
+
+ public void testHeaders1() throws Exception {
+ XMLStreamReader reader =
+ inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.HEADERS1));
+ 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 );
+ }
+
+ public void testProperties1() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.PROPERTIES1));
+ 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 );
+ }
+
+ public void testOpProperties1() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPERTIES1));
+ 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);
+ }
+
+ public void testSubscriptionHeaders() throws Exception {
+ XMLStreamReader reader =
+ inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.SELECTOR));
+ 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);
+ }
+
+ public void testDestinationProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.DEST_PROPS));
+ Composite composite = (Composite)staxProcessor.read(reader);
+ JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ // 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);
+ }
+
+ public void testConnectionFactoryProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CF_PROPS));
+ 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);
+ }
+
+ public void testActivationSpecProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.AS_PROPS));
+ 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);
+ }
+
+ public void testResponseDestinationProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_DEST_PROPS));
+ 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);
+ }
+
+ public void testResponseConnectionFactoryProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_CF_PROPS));
+ 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);
+ }
+
+ public void testResponseActivationSpecProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_AS_PROPS));
+ 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);
+ }
+
+ public void testOperationPropertiesProperties() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPS_PROPS));
+ 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);
+ }
+
+ public void testResouceAdapterProperties() throws Exception {
+ XMLStreamReader reader =
+ inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RES_ADPT_PROPS));
+ 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);
+ }
+}