summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl
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/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl
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/sca-java-1.x/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl')
-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
4 files changed, 768 insertions, 23 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(" ");
+ }
+
}