From a23f2e761eed657de1320bb920e64a13a3fa5cad Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 4 Aug 2008 09:48:29 +0000 Subject: Updates for properties tests and tidy up old comments git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@682307 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/binding/jms/impl/JMSBinding.java | 305 +++++++++++---------- .../sca/binding/jms/impl/JMSBindingProcessor.java | 219 ++++++++++++++- 2 files changed, 374 insertions(+), 150 deletions(-) (limited to 'java/sca') 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 extensions = new ArrayList(); - // Properties required to describe the JMS - // binding model + // Properties required to describe the JMS binding model - // 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; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? + private String destinationName = JMSBindingConstants.DEFAULT_DESTINATION_NAME; private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? + private String connectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? + private String activationSpecName = null; private String activationSpecCreate = null; - // - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? + + 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; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? + private String responseConnectionFactoryName = JMSBindingConstants.DEFAULT_CONNECTION_FACTORY_NAME; private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? - private String responseActivationSpecName = null; - private String responseActivationSpecCreate = null; - // ? - // - // ? Not yet implemented in binding - // * Not yet implemented in binding - // ? - // private String resourceAdapterName = null; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // ? - // 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; - // - // Not yet implemented in binding - // * Not yet implemented in binding - // Not yet implemented in binding - // * Not yet implemented in binding - // ? - // * - // - - // 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 properties = new HashMap(); + private Map> operationProperties = new HashMap>(); + private Map nativeOperationNames = new HashMap(); + private Map operationJMSTypes = new HashMap(); + private Map operationJMSCorrelationIds = new HashMap(); + private Map operationJMSDeliveryModes = new HashMap(); + private Map operationJMSTimeToLives = new HashMap(); + private Map operationJMSPriorities = new HashMap(); + 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 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 getOperationProperties(String opName) { + return operationProperties.get(opName); + } + + public void setOperationProperty(String opName, String propName, Object value) { + Map props = operationProperties.get(opName); + if (props == null) { + props = new HashMap(); + 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 { // 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 { 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 { 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.setConnectionFactoryName(name); } else { error("MissingConnectionFactoryName", reader); - //throw new RuntimeException("missing connectionFactory name"); } } @@ -402,6 +397,7 @@ public class JMSBindingProcessor implements StAXArtifactProcessor { 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 { warning("DoesntProcessResourceAdapter", jmsBinding); } + /** + * + * * + * ? + */ 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); + } } + /** + * + * * + * + * * + * ? + * * + */ 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); + } } /** -- cgit v1.2.3