diff options
2 files changed, 374 insertions, 150 deletions
diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java index d1edbf9643..da85607ccb 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBinding.java @@ -19,7 +19,10 @@ package org.apache.tuscany.sca.binding.jms.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; import org.apache.tuscany.sca.assembly.Binding; @@ -31,9 +34,6 @@ import org.apache.tuscany.sca.assembly.Binding; public class JMSBinding implements Binding { - /** - * Clone the binding - */ public Object clone() throws CloneNotSupportedException { return super.clone(); } @@ -45,140 +45,62 @@ public class JMSBinding implements Binding { private boolean unresolved = false; private List<Object> extensions = new ArrayList<Object>(); - // Properties required to describe the JMS - // binding model + // Properties required to describe the JMS binding model - // <binding.jms correlationScheme="string"? Not yet implemented in binding - // initialContextFactory="xs:anyURI"? - // jndiURL="xs:anyURI"? - // requestConnection="QName"? Not yet implemented in binding - // responseConnection="QName"? Not yet implemented in binding - // operationProperties="QName"? Not yet implemented in binding - // ...> private String correlationScheme = JMSBindingConstants.CORRELATE_MSG_ID; private String initialContextFactoryName; private String jndiURL; - // private String requestConnection = null; - // private String responseConnection = null; - // private String operationProperties = null; - // - // <destination name="xs:anyURI" - // type="string"? Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </destination>? + private String destinationName = JMSBindingConstants.DEFAULT_DESTINATION_NAME; private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // <connectionFactory name="xs:anyURI" Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </connectionFactory>? + private String connectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // <activationSpec name="xs:anyURI" Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </activationSpec>? + private String activationSpecName = null; private String activationSpecCreate = null; - // - // <response> - // <destination name="xs:anyURI" - // type="string"? Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </destination>? + + private String responseActivationSpecName = null; + private String responseActivationSpecCreate = null; + private String responseDestinationName = JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME; private String responseDestinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; private String responseDestinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // <connectionFactory name="xs:anyURI" Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </connectionFactory>? + private String responseConnectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // <activationSpec name="xs:anyURI" Not yet implemented in binding - // create="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </activationSpec>? - private String responseActivationSpecName = null; - private String responseActivationSpecCreate = null; - // </response>? - // - // <resourceAdapter name="NMTOKEN">? Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </resourceAdapter>? - // private String resourceAdapterName = null; - // - // <headers JMSType="string"? Not yet implemented in binding - // JMSCorrelationId="string"? Not yet implemented in binding - // JMSDeliveryMode="string"? Not yet implemented in binding - // JMSTimeToLive="int"? Not yet implemented in binding - // JMSPriority="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </headers>? - // private String jmsType = null; - // private String jmsCorrelationId = null; - private int jmsDeliveryMode = JMSBindingConstants.NON_PERSISTENT; // Maps to javax.jms.DeliveryMode - private int jmsTimeToLive = JMSBindingConstants.DEFAULT_TIME_TO_LIVE; - private int jmsPriority = JMSBindingConstants.DEFAULT_PRIORITY; - // - // <operationProperties name="string" Not yet implemented in binding - // nativeOperation="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // <headers JMSType="string"? Not yet implemented in binding - // JMSCorrelationId="string"? Not yet implemented in binding - // JMSDeliveryMode="string"? Not yet implemented in binding - // JMSTimeToLive="int"? Not yet implemented in binding - // JMSPriority="string"?> Not yet implemented in binding - // <property name="NMTOKEN" Not yet implemented in binding - // type="NMTOKEN">* Not yet implemented in binding - // </headers>? - // </operationProperties>* - // </binding.jms> - - // Other properties not directly related to the - // XML definition of the JMS binding // Provides the name of the factory that interfaces to the // JMS API for us. private String jmsResourceFactoryName = JMSBindingConstants.DEFAULT_RF_CLASSNAME; - // Message processors used to deal with the request - // and response messages + // Message processors used to deal with the request and response messages public String requestMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; public String responseMessageProcessorName = JMSBindingConstants.DEFAULT_MP_CLASSNAME; - // The JMS message property used to hold the name of the - // operation being called + // The JMS message property used to hold the name of the operation being called private String operationSelectorPropertyName = JMSBindingConstants.DEFAULT_OPERATION_PROP_NAME; - // If the operation selector is derived automatically from the service - // interface it's stored here + // If the operation selector is derived automatically from the service interface it's stored here private String operationSelectorName = null; - // TODO ..... private String replyTo; - - // Methods required by the Tuscany SPI - - /** - * No arg constructor used by the JSMBindingFactoryImpl to create JMS binding model objects - */ + private String jmsType; + private String jmsCorrelationId; + private Boolean deliveryModePersistent; + private Long timeToLive; + private Integer jmsPriority; + + private Map<String, Object> properties = new HashMap<String, Object>(); + private Map<String, Map<String, Object>> operationProperties = new HashMap<String, Map<String,Object>>(); + private Map<String, String> nativeOperationNames = new HashMap<String, String>(); + private Map<String, String> operationJMSTypes = new HashMap<String, String>(); + private Map<String, String> operationJMSCorrelationIds = new HashMap<String, String>(); + private Map<String, Boolean> operationJMSDeliveryModes = new HashMap<String, Boolean>(); + private Map<String, Long> operationJMSTimeToLives = new HashMap<String, Long>(); + private Map<String, Integer> operationJMSPriorities = new HashMap<String, Integer>(); + public JMSBinding() { super(); } @@ -370,33 +292,6 @@ public class JMSBinding implements Binding { this.responseActivationSpecCreate = create; } - public int getDeliveryMode() { - return jmsDeliveryMode; - } - - public void setDeliveryMode(int deliveryMode) { - this.jmsDeliveryMode = deliveryMode; - } - - public int getTimeToLive() { - return jmsTimeToLive; - } - - public void setTimeToLive(int timeToLive) { - this.jmsTimeToLive = timeToLive; - } - - public int getPriority() { - return jmsPriority; - } - - public void setPriority(int priority) { - this.jmsPriority = priority; - } - - // operations to manage the other information required by the - // JMS binding - public String getJmsResourceFactoryName() { return jmsResourceFactoryName; } @@ -405,10 +300,6 @@ public class JMSBinding implements Binding { this.jmsResourceFactoryName = jmsResourceFactoryName; } -// public JMSResourceFactory getJmsResourceFactory() { -// return (JMSResourceFactory)instantiate(null, jmsResourceFactoryName); -// } - public void setRequestMessageProcessorName(String name) { this.requestMessageProcessorName = name; } @@ -441,8 +332,6 @@ public class JMSBinding implements Binding { this.operationSelectorName = operationSelectorName; } - // TODO... - public String getReplyTo() { return replyTo; } @@ -451,4 +340,138 @@ public class JMSBinding implements Binding { this.replyTo = replyTo; } + public String getJMSType() { + return jmsType; + } + public void setJMSType(String jmsType) { + this.jmsType = jmsType; + } + + public String getJMSCorrelationId() { + return jmsCorrelationId; + } + + public void setJMSCorrelationId(String jmsCorrelationId) { + this.jmsCorrelationId = jmsCorrelationId; + } + + public Boolean isdeliveryModePersistent() { + return deliveryModePersistent; + } + public void setJMSDeliveryMode(boolean persistent) { + this.deliveryModePersistent = Boolean.valueOf(persistent); + } + + public Integer getJMSPriority() { + return jmsPriority; + } + + public void setJMSPriority(int jmsPriority) { + this.jmsPriority = Integer.valueOf(jmsPriority); + } + + public Long getJMSTimeToLive() { + return timeToLive.longValue(); + } + + public void setJMSTimeToLive(long timeToLive) { + this.timeToLive = Long.valueOf(timeToLive); + } + + public Set<String> getPropertyNames() { + return properties.keySet(); + } + + public Object getProperty(String name) { + return properties.get(name); + } + + public void setProperty(String name, Object value) { + properties.put(name, value); + } + + public Map<String, Object> getOperationProperties(String opName) { + return operationProperties.get(opName); + } + + public void setOperationProperty(String opName, String propName, Object value) { + Map<String, Object> props = operationProperties.get(opName); + if (props == null) { + props = new HashMap<String, Object>(); + operationProperties.put(opName, props); + } + props.put(propName, value); + } + + public boolean hasNativeOperationName(String opName) { + return nativeOperationNames.containsKey(opName); + } + + public String getNativeOperationName(String opName) { + if (nativeOperationNames.containsKey(opName)) { + return nativeOperationNames.get(opName); + } else { + return opName; + } + } + + public void setNativeOperationName(String opName, String nativeOpName) { + this.nativeOperationNames .put(opName, nativeOpName); + } + + public String getOperationJMSType(String opName) { + if (operationJMSTypes.containsKey(opName)) { + return operationJMSTypes.get(opName); + } else { + return jmsType; + } + } + public void setOperationJMSType(String opName, String jmsType) { + this.operationJMSTypes.put(opName, jmsType); + } + + public String getOperationJMSCorrelationId(String opName) { + if (operationJMSCorrelationIds.containsKey(opName)) { + return operationJMSCorrelationIds.get(opName); + } else { + return jmsCorrelationId; + } + } + public void setOperationJMSCorrelationId(String opName, String jmsCorrelationId) { + operationJMSCorrelationIds.put(opName, jmsCorrelationId); + } + + public Boolean getOperationJMSDeliveryMode(String opName) { + if (operationJMSDeliveryModes.containsKey(opName)) { + return operationJMSDeliveryModes.get(opName); + } else { + return deliveryModePersistent; + } + } + public void setOperationJMSDeliveryMode(String opName, boolean b) { + operationJMSDeliveryModes.put(opName, b); + } + + public Long getOperationJMSTimeToLive(String opName) { + if (operationJMSTimeToLives.containsKey(opName)) { + return operationJMSTimeToLives.get(opName); + } else { + return timeToLive; + } + } + public void setOperationJMSTimeToLive(String opName, Long ttl) { + operationJMSTimeToLives.put(opName, ttl); + } + + public Integer getOperationJMSPriority(String opName) { + if (operationJMSPriorities.containsKey(opName)) { + return operationJMSPriorities.get(opName); + } else { + return jmsPriority; + } + } + public void setOperationJMSPriority(String opName, int p) { + operationJMSPriorities.put(opName, p); + } + } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java index 61315cbf3a..25c236d425 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/impl/JMSBindingProcessor.java @@ -215,13 +215,12 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { // TODO // Read reponseConnection // TODO - // Read operationProperties - // TODO // Read sub-elements of binding.jms boolean endFound = false; while (!endFound) { - switch (reader.next()) { + int fg = reader.next(); + switch (fg) { case START_ELEMENT: String elementName = reader.getName().getLocalPart(); if ("destination".equals(elementName)) { @@ -247,8 +246,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { endFound = true; } else { error("UnexpectedElement", reader, x.toString()); - //throw new RuntimeException("Incomplete binding.jms definition found unexpected element " - //+ x.toString()); } } } @@ -261,7 +258,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { protected void parseURI(String uri, JMSBinding jmsBinding) { if (!uri.startsWith("jms:")) { error("MustStartWithSchema", jmsBinding, uri); - //throw new JMSBindingException("uri must start with the scheme 'jms:' for uri: " + uri); return; } int i = uri.indexOf('?'); @@ -326,7 +322,6 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { jmsBinding.setConnectionFactoryName(name); } else { error("MissingConnectionFactoryName", reader); - //throw new RuntimeException("missing connectionFactory name"); } } @@ -402,6 +397,7 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { case END_ELEMENT: QName x = reader.getName(); if (x.getLocalPart().equals("response")) { +// reader.next(); return; } else { error("UnexpectedResponseElement", reader, x.toString()); @@ -416,12 +412,217 @@ public class JMSBindingProcessor implements StAXArtifactProcessor<JMSBinding> { warning("DoesntProcessResourceAdapter", jmsBinding); } + /** + * <headers JMSType=”string”? + * JMSCorrelationId=”string”? + * JMSDeliveryMode=”PERSISTENT or NON_PERSISTENT”? + * JMSTimeToLive=”long”? + * JMSPriority=”0 .. 9”?> + * <property name=”NMTOKEN” type=”NMTOKEN”?>* + * </headers>? + */ private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { - warning("DoesntProcessHeaders", jmsBinding); + + String jmsType = reader.getAttributeValue(null, "JMSType"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setJMSType(jmsType); + } + + String jmsCorrelationId = reader.getAttributeValue(null, "JMSCorrelationId"); + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + jmsBinding.setJMSCorrelationId(jmsCorrelationId); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "JMSDeliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(true); + } else if ("NON_PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(false); + } else { + warning("InvalidJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "JMSTimeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setJMSTimeToLive(Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setJMSPriority(p); + } else { + warning("InvalidJMSPriority", jmsBinding, jmsPriority); + } + } + + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("property")) { + parseProperty(reader, jmsBinding); + } + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseProperty(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + String type = reader.getAttributeValue(null, "type"); + if (name != null && name.length() > 0) { + Object value = reader.getElementText(); + if ("boolean".equalsIgnoreCase(type)) { + value = Boolean.parseBoolean((String)value); + } else if ("byte".equalsIgnoreCase(type)) { + value = Byte.parseByte(((String)value)); + } else if ("short".equalsIgnoreCase(type)) { + value = Short.parseShort((String)value); + } else if ("int".equalsIgnoreCase(type)) { + value = Integer.parseInt((String)value); + } else if ("long".equalsIgnoreCase(type)) { + value = Long.parseLong((String)value); + } else if ("float".equalsIgnoreCase(type)) { + value = Float.parseFloat((String)value); + } else if ("double".equalsIgnoreCase(type)) { + value = Double.parseDouble((String)value); + } else if ("String".equalsIgnoreCase(type)) { + // its already a string + } + jmsBinding.setProperty(name, value); + } } + /** + * <operationProperties name=”string” nativeOperation=”string”?> + * <property name=”NMTOKEN” type=”NMTOKEN”?>* + * <headers JMSType=”string”? + * JMSCorrelationId=”string”? + * JMSDeliveryMode=”PERSISTENT or NON_PERSISTENT”? + * JMSTimeToLive=”long”? + * JMSPriority=”0 .. 9”?> + * <property name=”NMTOKEN” type=”NMTOKEN”?>* + * </headers>? + * </operationProperties>* + */ private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { - warning("DoesntProcessOperationProperties", jmsBinding); + String opName = reader.getAttributeValue(null, "name"); + if (opName == null || opName.length() < 1) { + warning("InvalidJMSOperationProperty", jmsBinding); + return; + } + String nativeOpName = reader.getAttributeValue(null, "nativeOperation"); + if (nativeOpName != null && nativeOpName.length() > 0) { + jmsBinding.setNativeOperationName(opName, nativeOpName); + } + + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("headers")) { + parseOperationHeaders(reader, jmsBinding, opName); + } + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("operationProperties")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseOperationHeaders(XMLStreamReader reader, JMSBinding jmsBinding, String opName) throws XMLStreamException { + String jmsType = reader.getAttributeValue(null, "JMSType"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setOperationJMSType(opName, jmsType); + } + + String jmsCorrelationId = reader.getAttributeValue(null, "JMSCorrelationId"); + if (jmsCorrelationId != null && jmsCorrelationId.length() > 0) { + jmsBinding.setOperationJMSCorrelationId(opName, jmsCorrelationId); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "JMSDeliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(true); + } else if ("NON_PERSISTENT".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setOperationJMSDeliveryMode(opName, false); + } else { + warning("InvalidOPJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "JMSTimeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setOperationJMSTimeToLive(opName, Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "JMSPriority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setOperationJMSPriority(opName, p); + } else { + warning("InvalidOPJMSPriority", jmsBinding, jmsPriority); + } + } + + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("property")) { + parseOperationPropertyProperties(reader, jmsBinding, opName); + } + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + return; + } else { + error("UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseOperationPropertyProperties(XMLStreamReader reader, JMSBinding jmsBinding, String opName) throws XMLStreamException { + String propName = reader.getAttributeValue(null, "name"); + String type = reader.getAttributeValue(null, "type"); + if (propName != null && propName.length() > 0) { + Object value = reader.getElementText(); + if ("boolean".equalsIgnoreCase(type)) { + value = Boolean.parseBoolean((String)value); + } else if ("byte".equalsIgnoreCase(type)) { + value = Byte.parseByte(((String)value)); + } else if ("short".equalsIgnoreCase(type)) { + value = Short.parseShort((String)value); + } else if ("int".equalsIgnoreCase(type)) { + value = Integer.parseInt((String)value); + } else if ("long".equalsIgnoreCase(type)) { + value = Long.parseLong((String)value); + } else if ("float".equalsIgnoreCase(type)) { + value = Float.parseFloat((String)value); + } else if ("double".equalsIgnoreCase(type)) { + value = Double.parseDouble((String)value); + } else if ("String".equalsIgnoreCase(type)) { + // its already a string + } + jmsBinding.setOperationProperty(opName, propName, value); + } } /** |