From f59fca36e7538cafbd6032003c7b06d64862a2bf Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 19 Jul 2010 02:50:53 +0000 Subject: Branch to experiment with dynamic component interfaces and implementations. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@965346 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/binding/jms/BindingProperty.java | 72 + .../apache/tuscany/sca/binding/jms/JMSBinding.java | 974 +++++++++++++ .../sca/binding/jms/JMSBindingConstants.java | 75 + .../sca/binding/jms/JMSBindingException.java | 45 + .../sca/binding/jms/JMSBindingProcessor.java | 1537 ++++++++++++++++++++ .../OperationSelectorJMSDefault.java | 45 + .../OperationSelectorJMSDefaultProcessor.java | 76 + .../OperationSelectorJMSUserProp.java | 57 + .../OperationSelectorJMSUserPropProcessor.java | 87 ++ .../token/JMSTokenAuthenticationPolicy.java | 55 + .../JMSTokenAuthenticationPolicyProcessor.java | 111 ++ .../binding/jms/policy/header/JMSHeaderPolicy.java | 130 ++ .../policy/header/JMSHeaderPolicyProcessor.java | 206 +++ .../binding/jms/wireformat/WireFormatJMSBytes.java | 45 + .../wireformat/WireFormatJMSBytesProcessor.java | 75 + .../jms/wireformat/WireFormatJMSBytesXML.java | 40 + .../wireformat/WireFormatJMSBytesXMLProcessor.java | 72 + .../jms/wireformat/WireFormatJMSDefault.java | 64 + .../wireformat/WireFormatJMSDefaultProcessor.java | 89 ++ .../jms/wireformat/WireFormatJMSObject.java | 57 + .../wireformat/WireFormatJMSObjectProcessor.java | 88 ++ .../binding/jms/wireformat/WireFormatJMSText.java | 45 + .../jms/wireformat/WireFormatJMSTextProcessor.java | 75 + .../jms/wireformat/WireFormatJMSTextXML.java | 48 + .../wireformat/WireFormatJMSTextXMLProcessor.java | 75 + ...ca.contribution.processor.StAXArtifactProcessor | 30 + ...che.tuscany.sca.provider.SCADefinitionsProvider | 19 + ...nding-jms-policy-validation-messages.properties | 23 + .../binding-jms-validation-messages.properties | 53 + .../tuscany/sca/binding/jms/policy/definitions.xml | 89 ++ .../binding/jms/JMSBindingProcessorTestCase.java | 773 ++++++++++ .../jms/JMSBindingProcessorWriteTestCase.java | 438 ++++++ .../jms/policy/PolicyProcessorTestCase.java | 95 ++ 33 files changed, 5763 insertions(+) create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/BindingProperty.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingConstants.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingException.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefault.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserProp.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytes.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXML.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefault.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObject.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSText.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXML.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java create mode 100644 sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java (limited to 'sandbox/sebastien/java/dynamic/modules/binding-jms/src') diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/BindingProperty.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/BindingProperty.java new file mode 100644 index 0000000000..7aa62215ff --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/BindingProperty.java @@ -0,0 +1,72 @@ +/* + * 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; + +public class BindingProperty { + + private String name; + private String type; + private Object value; + + public BindingProperty(String name, String type, Object value) { + this.name = name; + this.type = type; + this.value = value; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public Object getValue() { + return value; + } + + @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/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java new file mode 100644 index 0000000000..7480d8fe17 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBinding.java @@ -0,0 +1,974 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.policy.ExtensionType; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySubject; + +/** + * Models a binding to a JMS resource. + * + * @version $Rev$ $Date$ + */ + +//public class JMSBinding implements BindingRRB, PolicySubject, OperationsConfigurator, DefinitionElement { +public class JMSBinding implements Binding, PolicySubject, OperationsConfigurator { + QName TYPE = new QName(SCA11_NS, "binding.jms"); + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + // properties required to implement the Tuscany binding extension SPI + private String uri = null; + private String name = null; + private boolean unresolved = false; + private List extensions = new ArrayList(); + + // properties required by PolicySetAttachPoint + private List policySets = new ArrayList(); + private List applicablePolicySets = new ArrayList(); + + // properties required by IntentAttachPoint + private List requiredIntents = new ArrayList(); + + // properties required to describe configured operations + private List configuredOperations = new ArrayList(); + + // properties required by DefinitionElement @575803A + private String targetNamespace; + + // Properties required to describe the JMS binding model + + private String correlationScheme = JMSBindingConstants.CORRELATE_MSG_ID; + private String initialContextFactoryName; + private String jndiURL; + + private String destinationName = null; + private String destinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String destinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map destinationProperties = new HashMap(); + + private String connectionFactoryName = null; + private String connectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map connectionFactoryProperties = new HashMap(); + + private String activationSpecName = null; + private String activationSpecCreate = null; + private Map activationSpecProperties = new HashMap(); + + private String resourceAdapterName;; + private Map resourceAdapterProperties = new HashMap(); + + private String responseActivationSpecName = null; + private String responseActivationSpecCreate = null; + private Map responseActivationSpecProperties = new HashMap(); + + private String responseDestinationName = null; + private String responseDestinationType = JMSBindingConstants.DESTINATION_TYPE_QUEUE; + private String responseDestinationCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map responseDestinationProperties = new HashMap(); + + private String responseConnectionFactoryName = null; + private String responseConnectionFactoryCreate = JMSBindingConstants.CREATE_IF_NOT_EXIST; + private Map responseConnectionFactoryProperties = new HashMap(); + + // Provides the name of the factory that interfaces to the JMS API for us. + private String jmsResourceFactoryName = JMSBindingConstants.DEFAULT_RF_CLASSNAME; + + // 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 + private String operationSelectorPropertyName = JMSBindingConstants.DEFAULT_OPERATION_PROP_NAME; + + // 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; + 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(); + private Map> operationPropertiesProperties = new HashMap>(); + + private String jmsSelector; + private QName requestConnectionName; + private QName responseConnectionName; + private QName operationPropertiesName; + private JMSBinding requestConnectionBinding; + private JMSBinding responseConnectionBinding; + private JMSBinding operationPropertiesBinding; + + private WireFormat requestWireFormat; + private WireFormat responseWireFormat; + private OperationSelector operationSelector; + private ExtensionType extensionType; + + public JMSBinding() { + super(); + } + + // operations required by Binding + public String getURI() { + return this.uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List getExtensions() { + return extensions; + } + + public WireFormat getRequestWireFormat() { + return requestWireFormat; + } + + public void setRequestWireFormat(WireFormat wireFormat) { + this.requestWireFormat = wireFormat; + } + + public WireFormat getResponseWireFormat() { + return responseWireFormat; + } + + public void setResponseWireFormat(WireFormat wireFormat) { + this.responseWireFormat = wireFormat; + } + + public OperationSelector getOperationSelector() { + return operationSelector; + } + + public void setOperationSelector(OperationSelector operationSelector) { + this.operationSelector = operationSelector; + } + + // Methods for getting/setting JMS binding model information + // as derived from the XML of the binding.jms element + + public void setCorrelationScheme(String correlationScheme) { + this.correlationScheme = correlationScheme; + } + + public String getCorrelationScheme() { + return correlationScheme; + } + + public String getInitialContextFactoryName() { + return initialContextFactoryName; + } + + public void setInitialContextFactoryName(String initialContextFactoryName) { + this.initialContextFactoryName = initialContextFactoryName; + } + + public String getJndiURL() { + return this.jndiURL; + } + + public void setJndiURL(String jndiURL) { + this.jndiURL = jndiURL; + } + + public String getDestinationName() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationName() != null) { + return requestConnectionBinding.getDestinationName(); + } else { + return destinationName; + } + } + + public void setDestinationName(String destinationName) { + this.destinationName = destinationName; + } + + public String getDestinationType() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationType() != null) { + return requestConnectionBinding.getDestinationType(); + } else { + return destinationType; + } + } + + public void setDestinationType(String destinationType) { + this.destinationType = destinationType; + } + + public String getDestinationCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getDestinationCreate() != null) { + return requestConnectionBinding.getDestinationCreate(); + } else { + return this.destinationCreate; + } + } + + public void setDestinationCreate(String create) { + this.destinationCreate = create; + } + + public String getConnectionFactoryName() { + if (requestConnectionBinding != null && requestConnectionBinding.getConnectionFactoryName() != null) { + return requestConnectionBinding.getConnectionFactoryName(); + } else { + return connectionFactoryName; + } + } + + public void setConnectionFactoryName(String connectionFactoryName) { + this.connectionFactoryName = connectionFactoryName; + } + + public String getConnectionFactoryCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getConnectionFactoryCreate() != null) { + return requestConnectionBinding.getConnectionFactoryCreate(); + } else { + return this.connectionFactoryCreate; + } + } + + public void setConnectionFactoryCreate(String create) { + this.connectionFactoryCreate = create; + } + + public String getResourceAdapterName() { + return resourceAdapterName; + } + + public void setResourceAdapterName(String name) { + resourceAdapterName = name; + } + + public String getActivationSpecName() { + if (requestConnectionBinding != null && requestConnectionBinding.getActivationSpecName() != null) { + return requestConnectionBinding.getActivationSpecName(); + } else { + return activationSpecName; + } + } + + public void setActivationSpecName(String activationSpecName) { + this.activationSpecName = activationSpecName; + } + + public String getActivationSpecCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getActivationSpecCreate() != null) { + return requestConnectionBinding.getActivationSpecCreate(); + } else { + return this.activationSpecCreate; + } + } + + public void setActivationSpecCreate(String create) { + this.activationSpecCreate = create; + } + + public String getResponseDestinationName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationName() != null) { + return requestConnectionBinding.getResponseDestinationName(); + } else { + return this.responseDestinationName; + } + } + + public void setResponseDestinationName(String name) { + this.responseDestinationName = name; + } + + public String getResponseDestinationType() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationType() != null) { + return requestConnectionBinding.getResponseDestinationType(); + } else { + return this.responseDestinationType; + } + } + + public void setResponseDestinationType(String type) { + this.responseDestinationType = type; + } + + public String getResponseDestinationCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseDestinationCreate() != null) { + return requestConnectionBinding.getResponseDestinationCreate(); + } else { + return this.responseDestinationCreate; + } + } + + public void setResponseDestinationCreate(String create) { + this.responseDestinationCreate = create; + } + + public String getResponseConnectionFactoryName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseConnectionFactoryName() != null) { + return requestConnectionBinding.getResponseConnectionFactoryName(); + } else { + return responseConnectionFactoryName; + } + } + + public void setResponseConnectionFactoryName(String connectionFactoryName) { + this.responseConnectionFactoryName = connectionFactoryName; + } + + public String getResponseConnectionFactoryCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseConnectionFactoryCreate() != null) { + return requestConnectionBinding.getResponseConnectionFactoryCreate(); + } else { + return this.responseConnectionFactoryCreate; + } + } + + public void setResponseConnectionFactoryCreate(String create) { + this.responseConnectionFactoryCreate = create; + } + + public String getResponseActivationSpecName() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseActivationSpecName() != null) { + return requestConnectionBinding.getResponseActivationSpecName(); + } else { + return responseActivationSpecName; + } + } + + public void setResponseActivationSpecName(String activationSpecName) { + this.responseActivationSpecName = activationSpecName; + } + + public String getResponseActivationSpecCreate() { + if (requestConnectionBinding != null && requestConnectionBinding.getResponseActivationSpecCreate() != null) { + return requestConnectionBinding.getResponseActivationSpecCreate(); + } else { + return this.responseActivationSpecCreate; + } + } + + public void setResponseActivationSpecCreate(String create) { + this.responseActivationSpecCreate = create; + } + + public String getJmsResourceFactoryName() { + return jmsResourceFactoryName; + } + + public void setJmsResourceFactoryName(String jmsResourceFactoryName) { + this.jmsResourceFactoryName = jmsResourceFactoryName; + } + + public void setRequestMessageProcessorName(String name) { + this.requestMessageProcessorName = name; + } + + public String getRequestMessageProcessorName() { + return requestMessageProcessorName; + } + + public void setResponseMessageProcessorName(String name) { + this.responseMessageProcessorName = name; + } + + public String getResponseMessageProcessorName() { + return responseMessageProcessorName; + } + + public String getOperationSelectorPropertyName() { + return operationSelectorPropertyName; + } + + public void setOperationSelectorPropertyName(String operationSelectorPropertyName) { + this.operationSelectorPropertyName = operationSelectorPropertyName; + } + + public String getOperationSelectorName() { + return operationSelectorName; + } + + public void setOperationSelectorName(String operationSelectorName) { + this.operationSelectorName = operationSelectorName; + } + + public void setHeaders( boolean containsHeaders ) { + this.containsHeaders = containsHeaders; + } + + public boolean containsHeaders() { + return this.containsHeaders; + } + + public String getReplyTo() { + return replyTo; + } + + public void setReplyTo(String replyTo) { + this.replyTo = replyTo; + } + + public String getJMSType() { + return jmsType; + } + public void setJMSType(String jmsType) { + setHeaders( true ); + this.jmsType = jmsType; + } + + public String getJMSCorrelationId() { + return jmsCorrelationId; + } + + public void setJMSCorrelationId(String jmsCorrelationId) { + setHeaders( true ); + this.jmsCorrelationId = jmsCorrelationId; + } + + public Boolean isdeliveryModePersistent() { + return deliveryModePersistent; + } + public void setJMSDeliveryMode(boolean persistent) { + setHeaders( true ); + this.deliveryModePersistent = Boolean.valueOf(persistent); + } + + public Integer getJMSPriority() { + return jmsPriority; + } + + public void setJMSPriority(int jmsPriority) { + setHeaders( true ); + this.jmsPriority = Integer.valueOf(jmsPriority); + } + + public Long getJMSTimeToLive() { + return timeToLive; + } + + public void setJMSTimeToLive(long timeToLive) { + setHeaders( true ); + 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); + } + + protected Map getProperties() { + return properties; + } + + /** + * Adds an operationName to this binding. + * @param opName + */ + public void addOperationName(String opName) { + Map props = operationProperties.get(opName); + if (props == null) { + props = new HashMap(); + operationProperties.put(opName, props); + } + } + + /** + * Provides set of operation names in this binding. + * @return a Set of operation names + */ + public Set getOperationNames() { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationNames(); + } else { + // Make a defensive copy since key changes affect map, map changes affect keys. + Set opNames = operationProperties.keySet(); + Set opNamesCopy = new TreeSet( opNames ); + return opNamesCopy; + } + } + + public Map getOperationProperties(String opName) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationProperties(opName); + } else { + 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); + } + + /** + * Provides the value of a property for a given operation + * @param opName is the name of the operation in this binding. + * @param propName is the key name for the property + * @return Object representing the property value for this property name. Returns + * null for non existant operation name or property name. + */ + public Object getOperationProperty(String opName, String propName ) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.getOperationProperty(opName, propName); + } else { + Map props = operationProperties.get(opName); + if (props == null) { + return null; + } + return props.get(propName); + } + } + + public boolean hasNativeOperationName(String opName) { + if (operationPropertiesBinding != null) { + return operationPropertiesBinding.hasNativeOperationName(opName); + } else { + return nativeOperationNames.containsKey(opName); + } + } + + public String getNativeOperationName(String opName) { + if (operationPropertiesBinding != null && operationPropertiesBinding.getNativeOperationName(opName) != null) { + return operationPropertiesBinding.getNativeOperationName(opName); + } else { + 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 (operationPropertiesBinding != null && operationPropertiesBinding.getOperationJMSType(opName) != null) { + return operationPropertiesBinding.getOperationJMSType(opName); + } else { + 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 (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSCorrelationId(opName) != null) { + return operationPropertiesBinding.getOperationJMSCorrelationId(opName); + } else { + return jmsCorrelationId; + } + } else { + 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 (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSDeliveryMode(opName) != null) { + return operationPropertiesBinding.getOperationJMSDeliveryMode(opName); + } else { + return deliveryModePersistent; + } + } else { + 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 (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSTimeToLive(opName) != null) { + return operationPropertiesBinding.getOperationJMSTimeToLive(opName); + } else { + return timeToLive; + } + } else { + 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 (operationPropertiesBinding != null) { + if (operationPropertiesBinding.getOperationJMSPriority(opName) != null) { + return operationPropertiesBinding.getOperationJMSPriority(opName); + } else { + return jmsPriority; + } + } else { + if (operationJMSPriorities.containsKey(opName)) { + return operationJMSPriorities.get(opName); + } else { + return jmsPriority; + } + } + } + public void setOperationJMSPriority(String opName, int p) { + operationJMSPriorities.put(opName, p); + } + + public String getJMSSelector() { + return jmsSelector; + } + public void setJMSSelector(String jmsSelector) { + this.jmsSelector = jmsSelector; + } + + public QName getRequestConnectionName() { + return requestConnectionName; + } + + public void setRequestConnectionName(QName requestConnectionName) { + this.requestConnectionName = requestConnectionName; + } + + public void setResponseConnectionName(QName responseConnectionName) { + this.responseConnectionName = responseConnectionName; + } + + public QName getResponseConnectionName() { + return responseConnectionName; + } + + public void setRequestConnectionBinding(JMSBinding binding) { + this.requestConnectionBinding = binding; + } + public JMSBinding getRequestConnectionBinding() { + return requestConnectionBinding; + } + + public void setResponseConnectionBinding(JMSBinding binding) { + this.responseConnectionBinding = binding; + } + public JMSBinding getResponseConnectionBinding() { + return responseConnectionBinding; + } + + public void setOperationPropertiesName(QName nameValue) { + this.operationPropertiesName = nameValue; + } + public QName getOperationPropertiesName() { + return operationPropertiesName; + } + + public void setOperationPropertiesBinding(JMSBinding binding) { + this.operationPropertiesBinding = binding; + } + public JMSBinding getOperationPropertiesBinding() { + return operationPropertiesBinding; + } + + // operations required by PolicySetAttachPoint + public List getPolicySets() { + return policySets; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + // operations required by IntentAttachPoint + public List getRequiredIntents() { + return requiredIntents; + } + + public QName getType() { + return TYPE; + } + + public Map getDestinationProperties() { + return destinationProperties; + } + + public Map getConnectionFactoryProperties() { + return connectionFactoryProperties; + } + + public Map getResourceAdapterProperties() { + return resourceAdapterProperties; + } + + public Map getActivationSpecProperties() { + return activationSpecProperties; + } + + public Map getResponseActivationSpecProperties() { + return responseActivationSpecProperties; + } + + public Map getResponseDestinationProperties() { + return responseDestinationProperties; + } + + public Map getResponseConnectionFactoryProperties() { + return responseConnectionFactoryProperties; + } + + public Map getOperationPropertiesProperties(String opName) { + if (operationPropertiesProperties.get(opName)==null) { + operationPropertiesProperties.put(opName, new HashMap()); + } + return operationPropertiesProperties.get(opName); + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public void setConfiguredOperations(List configuredOperations) { + this.configuredOperations = configuredOperations; + } + + public String getTargetNamespace() { + return targetNamespace; + } + + public void setTargetNamespace(String ns) { + targetNamespace = ns; + } + + // hashCode() is here because binding elements in definitions documents are added + // to the model resolver hashmap. The namespace and name are keys. + @Override + public int hashCode() { + return (String.valueOf(getTargetNamespace()) + String.valueOf(getName())).hashCode(); + } + + @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 ) { + // If the target namespace is set, this binding came from a definitions document. + // The target namespace and name are used as keys for doing model resolver hashmap lookups. + // Only the target namespace and name can be compared. + if (this.targetNamespace != null) { + if ( !optStringEquals( this.targetNamespace, binding.getTargetNamespace() )) return false; + if ( !optStringEquals( this.name, binding.getName() )) return false; + return true; + } + + // 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.targetNamespace, binding.getTargetNamespace() )) 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 operationNamesA = this.getOperationNames(); + Set 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 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; + + // Configured operations + if ( this.configuredOperations.size() != binding.getConfiguredOperations().size() ) return false; + + // wire format + if ( this.getRequestWireFormat().getClass() != binding.getRequestWireFormat().getClass()) return false; + if ( this.getResponseWireFormat().getClass() != binding.getResponseWireFormat().getClass()) return false; + + // operation selector + if ( this.getOperationSelector().getClass() != binding.getOperationSelector().getClass()) 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( Object s1, Object 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 p1, Map 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; + } + + public ExtensionType getExtensionType() { + return extensionType; + } + + public void setExtensionType(ExtensionType intentAttachPointType) { + this.extensionType = intentAttachPointType; + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingConstants.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingConstants.java new file mode 100644 index 0000000000..80bc61baa1 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingConstants.java @@ -0,0 +1,75 @@ +/* + * 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; + +import java.util.Arrays; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Constants for the JMS binding. + * + * @version $Rev$ $Date$ + */ +public interface JMSBindingConstants { + + // Constants used when describing the JMS binding + // model and for setting up defaults + String BINDING_JMS = "binding.jms"; + QName BINDING_JMS_QNAME = new QName(Constants.SCA11_NS, BINDING_JMS); + String CORRELATE_MSG_ID = "requestmsgidtocorrelid"; + String CORRELATE_CORRELATION_ID = "requestcorrelidtocorrelid"; + String CORRELATE_NONE = "none"; + List VALID_CORRELATION_SCHEMES = + Arrays.asList(new String[] {CORRELATE_MSG_ID, CORRELATE_CORRELATION_ID, CORRELATE_NONE}); + String DESTINATION_TYPE_QUEUE = "queue"; // 0 + String DESTINATION_TYPE_TOPIC = "topic"; // 1 + List VALID_DESTINATION_TYPES = + Arrays.asList(new String[] {DESTINATION_TYPE_QUEUE, DESTINATION_TYPE_TOPIC}); + String CREATE_ALWAYS = "always"; + String CREATE_NEVER = "never"; + String CREATE_IF_NOT_EXIST = "ifnotexist"; + String DEFAULT_CONTEXT_FACTORY_NAME = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"; + String DEFAULT_JNDI_URL = "tcp://localhost:61616"; + int DEFAULT_TIME_TO_LIVE = 20000; // in milliseconds + int DEFAULT_PRIORITY = 1; + int NON_PERSISTENT = 1; // Maps to javax.jms.DeliveryMode + String DEFAULT_RF_CLASSNAME = "org.apache.tuscany.sca.host.jms.activemq.JMSResourceFactoryImpl"; + String XML_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.XMLTextMessageProcessor"; + String TEXT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.TextMessageProcessor"; + String OBJECT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.ObjectMessageProcessor"; + String BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.BytesMessageProcessor"; + String XML_BYTES_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.XMLBytesMessageProcessor"; + String DEFAULT_MP_CLASSNAME = "org.apache.tuscany.sca.binding.jms.provider.DefaultMessageProcessor"; + String DEFAULT_OPERATION_PROP_NAME = "scaOperationName"; + + String FAULT_PROPERTY = "org_apache_tuscany_sca_fault"; + + String CALLBACK_ID_PROPERTY = "CallbackID"; + 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/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingException.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingException.java new file mode 100644 index 0000000000..74f030ca21 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms; + +/** + * Base exception for the JMSBinding. + * + * @version $Rev$ $Date$ + */ +public class JMSBindingException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public JMSBindingException() { + super(); + } + + public JMSBindingException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public JMSBindingException(String arg0) { + super(arg0); + } + + public JMSBindingException(Throwable arg0) { + super(arg0); + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java new file mode 100644 index 0000000000..933ef333f7 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java @@ -0,0 +1,1537 @@ +/* + * 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; + +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.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor; +import org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A processor to read the XML that describes the JMS binding... + * + * + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * + * + * * + * ? + * + * + * * + * ? + * + * + * * + * ? + * + * ? + * ? + * + * + * + * + * + * ? + * * + * ? + * + * + * * + * + * * + * ? + * * + * + * ? + * + * + * Parsing error messages are recorded locally and reported as validation exceptions. Parsing + * warnings do not cause validation exceptions. + * + * @version $Rev$ $Date$ + */ + +public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + private PolicyFactory policyFactory; + private PolicySubjectProcessor policyProcessor; + private ConfiguredOperationProcessor configuredOperationProcessor; + protected StAXArtifactProcessor extensionProcessor; + + public JMSBindingProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor extensionProcessor) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.policyProcessor = new PolicySubjectProcessor(policyFactory); + + this.configuredOperationProcessor = + new ConfiguredOperationProcessor(modelFactories); + this.extensionProcessor = extensionProcessor; + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "binding-jms-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report an error. + * One side effect is that error messages are saved for future validation calls. + * + * @param problems + * @param message + * @param model + */ + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), "binding-jms-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return JMSBindingConstants.BINDING_JMS_QNAME; + } + + public Class getModelType() { + return JMSBinding.class; + } + + public JMSBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Monitor monitor = context.getMonitor(); + JMSBinding jmsBinding = new JMSBinding(); + // Reset validation message to keep track of validation issues. + + // Read policies + policyProcessor.readPolicies(jmsBinding, reader); + + // Read binding name + String name = reader.getAttributeValue(null, "name"); + if (name != null) { + jmsBinding.setName(name); + } + + // Read binding URI + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null && uri.length() > 0) { + parseURI(uri, jmsBinding, monitor); + } + + // Read correlation scheme + String correlationScheme = reader.getAttributeValue(null, "correlationScheme"); + if (correlationScheme != null && correlationScheme.length() > 0) { + if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) { + jmsBinding.setCorrelationScheme(correlationScheme); + } else { + error(monitor, "InvalidCorrelationScheme", reader, correlationScheme); + } + } + + // Read initial context factory + String initialContextFactory = getURIString(reader, "initialContextFactory"); + if (initialContextFactory != null && initialContextFactory.length() > 0) { + jmsBinding.setInitialContextFactoryName(initialContextFactory); + } + + // Read JNDI URL + String jndiURL = getURIString(reader, "jndiURL"); + if (jndiURL != null && jndiURL.length() > 0) { + jmsBinding.setJndiURL(jndiURL); + } + + // Read message processor class name + // TODO - maintain this for the time being but move over to + // configuring wire formats instead of message processors + String messageProcessorName = reader.getAttributeValue(null, "messageProcessor"); + if (messageProcessorName != null && messageProcessorName.length() > 0) { + if ("XMLTextMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSTextXML()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else if ("TextMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else if ("ObjectMessage".equalsIgnoreCase(messageProcessorName)) { + // may be overwritten be real wire format later + jmsBinding.setRequestWireFormat(new WireFormatJMSObject()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } else { + jmsBinding.setRequestMessageProcessorName(messageProcessorName); + jmsBinding.setResponseMessageProcessorName(messageProcessorName); + // exploit the text wire format code to drive the user selected + // message processor + jmsBinding.setRequestWireFormat(new WireFormatJMSText()); + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } + } + + String requestConnectionName = reader.getAttributeValue(null, "requestConnection"); + if (requestConnectionName != null && requestConnectionName.length() > 0) { + jmsBinding.setRequestConnectionName(getQNameValue(reader, requestConnectionName)); + } + String responseConnectionName = reader.getAttributeValue(null, "responseConnection"); + if (responseConnectionName != null && responseConnectionName.length() > 0) { + jmsBinding.setResponseConnectionName(getQNameValue(reader, responseConnectionName)); + } + + String operationPropertiesName = reader.getAttributeValue(null, "operationProperties"); + if (operationPropertiesName != null && operationPropertiesName.length() > 0) { + jmsBinding.setOperationPropertiesName(getQNameValue(reader, operationPropertiesName)); + } + + // Read sub-elements of binding.jms + boolean endFound = false; + while (!endFound) { + int fg = reader.next(); + switch (fg) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseDestination(reader, jmsBinding, monitor); + } else if ("connectionFactory".equals(elementName)) { + parseConnectionFactory(reader, jmsBinding, monitor); + } else if ("activationSpec".equals(elementName)) { + parseActivationSpec(reader, jmsBinding, monitor); + } else if ("response".equals(elementName)) { + parseResponse(reader, jmsBinding, context); + } else if ("resourceAdapter".equals(elementName)) { + parseResourceAdapter(reader, jmsBinding, monitor); + } else if ("headers".equals(elementName)) { + parseHeaders(reader, jmsBinding, monitor); + } else if ("operationProperties".equals(elementName)) { + parseOperationProperties(reader, jmsBinding, monitor); + } else if ("messageSelection".equals(elementName)) { + parseSubscriptionHeaders(reader, jmsBinding); + } else if (Constants.OPERATION_QNAME.equals(reader.getName())) { + ConfiguredOperation confOp = configuredOperationProcessor.read(reader, context); + if (confOp != null) { + ((OperationsConfigurator)jmsBinding).getConfiguredOperations().add(confOp); + } + } else { + Object extension = extensionProcessor.read(reader, context); + if (extension != null) { + if (extension instanceof WireFormat) { + if (jmsBinding.getRequestWireFormat() == null) { + jmsBinding.setRequestWireFormat((WireFormat) extension); + } else { + error(monitor, "WireFormatAlreadyDefined", reader, extension.toString()); + } + } else if (extension instanceof OperationSelector) { + if (jmsBinding.getOperationSelector() == null) { + jmsBinding.setOperationSelector((OperationSelector) extension); + } else { + error(monitor, "OpSelectorAlreadyDefined", reader, extension.toString()); + } + + } else { + error(monitor, "UnexpectedElement", reader, extension.toString()); + } + } + } + //reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (Constants.OPERATION.equals(x.getLocalPart())) break; + // This assumption is not captured in schema, which isn't good, but will probably be fine for now. + // A better solution might be to require each processor to advance to its own END_ELEMENT. + if (x.getLocalPart().startsWith("wireFormat.") || x.getLocalPart().startsWith("operationSelector.")) { + break; + } + if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) { + endFound = true; + } else { + error(monitor, "UnexpectedElement: expected " + JMSBindingConstants.BINDING_JMS_QNAME + ", found " + x.toString(), + reader, x.toString()); + } + } + } + + // if no operation selector is specified then assume the default + if (jmsBinding.getOperationSelector() == null){ + jmsBinding.setOperationSelector(new OperationSelectorJMSDefault()); + } + + // if no request wire format specified then assume the default + if (jmsBinding.getRequestWireFormat() == null){ + jmsBinding.setRequestWireFormat(new WireFormatJMSDefault()); + } + + // if no response wire format specific then assume the same as the request + if (jmsBinding.getResponseWireFormat() == null){ + jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); + } + + validate( jmsBinding, monitor ); + + return jmsBinding; + } + + protected void parseURI(String uri, JMSBinding jmsBinding, Monitor monitor) { + if (!uri.startsWith("jms:")) { + error(monitor, "MustStartWithSchema", jmsBinding, uri); + return; + } + int i = uri.indexOf('?'); + if (i >= 0) { + StringTokenizer st = new StringTokenizer(uri.substring(i+1),"&"); + while (st.hasMoreTokens()) { + String s = st.nextToken(); + if (s.startsWith("connectionFactoryName=")) { + jmsBinding.setConnectionFactoryName(s.substring(22)); + } else { + error(monitor, "UnknownTokenInURI", jmsBinding, s, uri); + return; + } + } + jmsBinding.setDestinationName(uri.substring(4, i)); + } else { + jmsBinding.setDestinationName(uri.substring(4)); + } + } + + public void resolve(JMSBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + if (model.getRequestConnectionName() != null) { + model.setRequestConnectionBinding(getConnectionBinding(model, "requestConnection", model.getRequestConnectionName(), resolver, context)); + } + if (model.getResponseConnectionName() != null) { + model.setResponseConnectionBinding(getConnectionBinding(model, "responseConnection", model.getResponseConnectionName(), resolver, context)); + } + if (model.getOperationPropertiesName() != null) { + model.setOperationPropertiesBinding(getConnectionBinding(model, "operationProperties", model.getOperationPropertiesName(), resolver, context)); + } + } + + private JMSBinding getConnectionBinding(JMSBinding model, String attrName, QName bindingName, ModelResolver resolver, ProcessorContext context) { + JMSBinding binding = new JMSBinding(); + binding.setTargetNamespace(bindingName.getNamespaceURI()); + binding.setName(bindingName.getLocalPart()); + binding.setUnresolved(true); + binding = resolver.resolveModel(JMSBinding.class, binding, context); + if (binding.isUnresolved()) + error(context.getMonitor(), "BindingNotFound", model, attrName, bindingName); + return binding; + } + + private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = getURIString(reader, "jndiName"); + if (name != null && name.length() > 0) { + jmsBinding.setDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + error(monitor, "InvalidDestinationType", reader, type); + } + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setDestinationCreate(create); + } + + jmsBinding.getDestinationProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = getURIString(reader, "jndiName"); + if (name != null && name.length() > 0) { + jmsBinding.setConnectionFactoryName(name); + } else { + error(monitor, "MissingConnectionFactoryName", reader); + } + jmsBinding.getConnectionFactoryProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setActivationSpecName(name); + } else { + warning(monitor, "MissingActivationSpecName", reader); + } + jmsBinding.getActivationSpecProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = getURIString(reader, "jndiName"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseDestinationName(name); + } + + String type = reader.getAttributeValue(null, "type"); + if (type != null && type.length() > 0) { + warning(monitor, "DoesntProcessResponseDestinationType", jmsBinding); + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); + } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { + jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); + } else { + error(monitor, "InvalidResponseDestinationType", reader, type); + } + } + + String create = reader.getAttributeValue(null, "create"); + if (create != null && create.length() > 0) { + jmsBinding.setResponseDestinationCreate(create); + } + + jmsBinding.getResponseDestinationProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = getURIString(reader, "jndiName"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseConnectionFactoryName(name); + } else { + warning(monitor, "MissingResponseConnectionFactory", reader); + } + jmsBinding.getResponseConnectionFactoryProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResponseActivationSpecName(name); + } else { + warning(monitor, "MissingResponseActivationSpec", reader); + } + jmsBinding.getResponseActivationSpecProperties().putAll(parseBindingProperties(reader, monitor)); + } + + private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding, ProcessorContext context) throws ContributionReadException, XMLStreamException { + // Read sub-elements of response + Monitor monitor = context.getMonitor(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("destination".equals(elementName)) { + parseResponseDestination(reader, jmsBinding, context.getMonitor()); + } else if ("connectionFactory".equals(elementName)) { + parseResponseConnectionFactory(reader, jmsBinding, monitor); + } else if ("activationSpec".equals(elementName)) { + parseResponseActivationSpec(reader, jmsBinding, monitor); + } else { + Object extension = extensionProcessor.read(reader, context); + if (extension != null) { + if (extension instanceof WireFormat) { + if (jmsBinding.getResponseWireFormat() == null) { + jmsBinding.setResponseWireFormat((WireFormat)extension); + } else { + error(context.getMonitor(), "ResponseWireformatAlreadyDefined", reader, extension.toString()); + } + } else { + error(context.getMonitor(), "UnexpectedElement", reader, extension.toString()); + } + } + reader.next(); + } + //reader.next(); + break; + case END_ELEMENT: + QName x = reader.getName(); + if (x.getLocalPart().equals("response")) { + return; + } else { + error(context.getMonitor(), "UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name != null && name.length() > 0) { + jmsBinding.setResourceAdapterName(name); + } else { + error(monitor, "MissingResourceAdapterName", reader); + } + jmsBinding.getResourceAdapterProperties().putAll(parseBindingProperties(reader, monitor)); + } + + /** + * + * * + * ? + */ + private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { + String jmsType = reader.getAttributeValue(null, "type"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setJMSType(jmsType); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "deliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("persistent".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(true); + } else if ("nonpersistent".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setJMSDeliveryMode(false); + } else { + error(monitor, "InvalidJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "timeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setJMSTimeToLive(Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "priority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setJMSPriority(p); + } else { + warning(monitor, "InvalidJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error(monitor, "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(monitor, "UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + + private void parseProperty(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + jmsBinding.setHeaders( true ); + 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, Monitor monitor) throws XMLStreamException { + + if (jmsBinding.getOperationPropertiesName() != null) { + error(monitor, "DuplicateOperationProperties", jmsBinding); + } + + String opName = reader.getAttributeValue(null, "name"); + if (opName == null || opName.length() < 1) { + warning(monitor, "MissingJMSOperationPropertyName", jmsBinding); + return; + } + // Since nativeOpName, headers, and property elements are optional, must add opName. + jmsBinding.addOperationName(opName); + String nativeOpName = reader.getAttributeValue(null, "nativeOperation"); // optional + if (nativeOpName != null && nativeOpName.length() > 0) { + jmsBinding.setNativeOperationName(opName, nativeOpName); + } + + Map props = new HashMap(); + while (true) { + switch (reader.next()) { + case START_ELEMENT: + if (reader.getName().getLocalPart().equals("headers")) { // optional + parseOperationHeaders(reader, jmsBinding, opName, monitor); + } else if (reader.getName().getLocalPart().equals("property")) { // optional + processProperty(reader, props, monitor); + } + break; + case END_ELEMENT: + if (reader.isEndElement()) { + QName x = reader.getName(); + if (x.getLocalPart().equals("headers")) { + break; + } + if (x.getLocalPart().equals("property")) { + break; + } + if (x.getLocalPart().equals("operationProperties")) { + jmsBinding.getOperationPropertiesProperties(opName).putAll(props); + return; + } else { + error(monitor, "UnexpectedResponseElement", reader, x.toString()); + } + } + } + } + } + + private void parseOperationHeaders(XMLStreamReader reader, JMSBinding jmsBinding, String opName, Monitor monitor) throws XMLStreamException { + String jmsType = reader.getAttributeValue(null, "type"); + if (jmsType != null && jmsType.length() > 0) { + jmsBinding.setOperationJMSType(opName, jmsType); + } + + String jmsDeliveryMode = reader.getAttributeValue(null, "deliveryMode"); + if (jmsDeliveryMode != null && jmsDeliveryMode.length() > 0) { + if ("persistent".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setOperationJMSDeliveryMode(opName, true); + } else if ("nonpersistent".equalsIgnoreCase(jmsDeliveryMode)) { + jmsBinding.setOperationJMSDeliveryMode(opName, false); + } else { + error(monitor, "InvalidOPJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + } + } + + String jmsTimeToLive = reader.getAttributeValue(null, "timeToLive"); + if (jmsTimeToLive != null && jmsTimeToLive.length() > 0) { + jmsBinding.setOperationJMSTimeToLive(opName, Long.parseLong(jmsTimeToLive)); + } + + String jmsPriority = reader.getAttributeValue(null, "priority"); + if (jmsPriority != null && jmsPriority.length() > 0) { + try { + int p = Integer.parseInt(jmsPriority); + if (p >= 0 && p <= 9) { + jmsBinding.setOperationJMSPriority(opName, p); + } else { + warning(monitor, "InvalidOPJMSPriority", jmsBinding, jmsPriority); + } + } catch (NumberFormatException ex) { + error(monitor, "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(monitor, "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); + } + } + + private void parseSubscriptionHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + String jmsSelector = reader.getAttributeValue(null, "selector"); + if (jmsSelector != null && jmsSelector.length() > 0) { + jmsBinding.setJMSSelector(jmsSelector); + } + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && "messageSelection".equals(reader.getName().getLocalPart())) { + break; + } + } // end while + } + + private Map parseBindingProperties(XMLStreamReader reader, Monitor monitor) throws XMLStreamException { + Map props = new HashMap(); + String parentName = reader.getName().getLocalPart(); + // Parse for all the properties within this element, until the end of + // the element is reached. + boolean completed = false; + while (!completed) { + switch (reader.next()) { + case START_ELEMENT: + String elementName = reader.getName().getLocalPart(); + if ("property".equals(elementName)) { + processProperty(reader, props, monitor); + } + break; + case END_ELEMENT: + String endName = reader.getName().getLocalPart(); + if (parentName.equals(endName)) { + completed = true; + break; + } + } + } + return props; + } + + private void processProperty(XMLStreamReader reader, Map props, Monitor monitor) throws XMLStreamException { + String name = reader.getAttributeValue(null, "name"); + if (name == null || name.length() < 1) { + error(monitor, "InvalidPropertyElement", reader); + } + String type = reader.getAttributeValue(null, "type"); + String value = reader.getElementText(); + props.put(name, new BindingProperty(name, type, value)); + } + + /** + * Preserve an existing public method. The method validate() is a legacy method + * that was called from reading am XML stream via the read(XMLStreamReader) method above. + * However read(XMLStreamReader) now calls validate(JMSBinding jmsBinding) and + * passes in the jmsBinding model. + * The older validate() now calls validate(JMSBinding jmsBinding) with a null model. + */ + public void validate() { + validate( null, null ); + } + + /** + * Validates JMS parsing and JMSBinding model. + * Validation rules are taken from the binding schema and the OSOA and OASIS specs: + * http://www.oasis-open.org/committees/documents.php?wg_abbrev=sca-bindings + * (sca-binding-jms-1.1-spec-cd01-rev4.pdf) + * http://www.osoa.org/display/Main/Service+Component+Architecture+Specifications + * (SCA JMS Binding V1.00 ) + * @param jmsBinding an optional JMS binding model to check for validity. + * @since 1.4 + */ + protected void validate( JMSBinding jmsBinding, Monitor monitor ) { + // If no JMSBinding model is provided, that is all the validation we can do. + if ( jmsBinding == null ) { + return; + } + + // Connection factory should not contradict destination type. + String connectionFactoryName = jmsBinding.getConnectionFactoryName(); + if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { + if (JMSBindingConstants.DESTINATION_TYPE_QUEUE == jmsBinding.getDestinationType()) { + if ( connectionFactoryName.contains( "topic" )) { + error(monitor, "DestinationQueueContradiction", jmsBinding, connectionFactoryName ); + } + } + if (JMSBindingConstants.DESTINATION_TYPE_TOPIC == jmsBinding.getDestinationType()) { + if ( connectionFactoryName.contains( "queue" )) { + error(monitor, "DestinationTopicContradiction", jmsBinding, connectionFactoryName ); + } + } + } + + // Connection factory and activation Specification are mutually exclusive. + if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { + String activationSpecName = jmsBinding.getActivationSpecName(); + if ((activationSpecName != null) && (activationSpecName.length() > 0 )) { + error(monitor, "ConnectionFactoryActivationSpecContradiction", jmsBinding, connectionFactoryName, activationSpecName ); + } + } + + // Given a response connection name attribute, there must not be a response element. + // 156 /binding.jms/@responseConnection - identifies a binding.jms element that is present in a + // 157 definition document, whose response child element is used to define the values for this binding. In + // 158 this case this binding.jms element MUST NOT contain a response element. + QName responseConnectionName = jmsBinding.getResponseConnectionName(); + if (( responseConnectionName != null ) && ( responseConnectionName.getLocalPart().length() > 0 )) { + String responseDestinationName = jmsBinding.getResponseDestinationName(); + if (( responseDestinationName != null ) && (responseDestinationName.length() > 0)) { + error(monitor, "ResponseAttrElement", jmsBinding, responseConnectionName, responseDestinationName ); + } + } + + // Other jmsBinding model validation may be added here. + + } + + /** + * 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. + * + * @param writer an XMLStreamWriter that writes XML attributes and elements + * @param jmsBinding JMSBinding model + */ + public void write(JMSBinding jmsBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, + XMLStreamException { + // Write a + writeStart(writer, Constants.SCA11_NS, JMSBindingConstants.BINDING_JMS, + new XAttr("requestConnection", jmsBinding.getRequestConnectionName()), + new XAttr("responseConnection", jmsBinding.getResponseConnectionName()), + new XAttr("operationProperties", jmsBinding.getOperationPropertiesName())); + + 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 != null ) { + // 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.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 || + responseCFName != null || + responseASName != null ) { + + writer.writeStartElement(Constants.SCA11_NS, "response"); + writeResponseDestinationProperties( jmsBinding, writer ); + writeResponseConnectionFactoryProperties( jmsBinding, writer ); + writeResponseActivationSpecProperties( jmsBinding, writer ); + + if ((jmsBinding.getResponseWireFormat() != null) && + !(jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault)){ + writeWireFormat(jmsBinding.getResponseWireFormat(), writer, context); + } + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters( " " ); + } + + writeResourceAdapterProperties( jmsBinding, writer ); + + writeConfiguredOperations( jmsBinding, writer, context ); + + if ((jmsBinding.getRequestWireFormat() != null) && + !(jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault)){ + writeWireFormat(jmsBinding.getRequestWireFormat(), writer, context); + } + + if ((jmsBinding.getOperationSelector() != null) && + !(jmsBinding.getOperationSelector() instanceof OperationSelectorJMSDefault)){ + writeOperationSelector(jmsBinding.getOperationSelector(), writer, context); + } + + writeEnd(writer); + } + + /** + * Writes headers element and its attributes. + * + * * + * ? + */ + private void writeHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + + writer.writeStartElement(Constants.SCA11_NS, JMSBindingConstants.HEADERS); + + String jmsType = jmsBinding.getJMSType(); + if (jmsType != null && jmsType.length() > 0) { + writer.writeAttribute("type", jmsType); + } + + Boolean jmsDeliveryMode = jmsBinding.isdeliveryModePersistent(); + if (jmsDeliveryMode != null) { + if ( jmsDeliveryMode.booleanValue() ) + writer.writeAttribute("deliveryMode", "persistent"); + else + writer.writeAttribute("deliveryMode", "nonpersistent"); + } + + Long jmsTimeToLive = jmsBinding.getJMSTimeToLive(); + if (jmsTimeToLive != null) { + writer.writeAttribute("timeToLive", jmsTimeToLive.toString()); + } + + Integer jmsPriority = jmsBinding.getJMSPriority(); + if (jmsPriority != null) { + writer.writeAttribute("priority", jmsPriority.toString()); + } + + Map 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: + * StringValue + * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be + * 42 + */ + @SuppressWarnings("unchecked") + private void writeProperties(Map 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(Constants.SCA11_NS, "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. + * + * + * * + * + * * + * ? + * * + * + */ + private void writeOperationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + if (jmsBinding.getOperationPropertiesBinding() != null) { + return; + } + Set operationNames = jmsBinding.getOperationNames(); + if (operationNames == null || (operationNames.size() < 1)) { + return; + } + + for(Iterator it=operationNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + + writer.writeStartElement(Constants.SCA11_NS, "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 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 operationProperties = jmsBinding.getOperationProperties(opName); + + if (operationProperties != null){ + if ((jmsType != null && jmsType.length() > 0) || + (jmsCorrelationId != null && jmsCorrelationId.length() > 0) || + jmsDeliveryMode != null || jmsTimeToLive != null || + jmsPriority != null) { + + writer.writeStartElement(Constants.SCA11_NS, JMSBindingConstants.HEADERS); + + if (jmsType != null && jmsType.length() > 0) { + writer.writeAttribute("type", jmsType); + } + + if (jmsDeliveryMode != null) { + if (jmsDeliveryMode.booleanValue()) + writer.writeAttribute("deliveryMode", "persistent"); + else + writer.writeAttribute("deliveryMode", "nonpersistent"); + } + + if (jmsTimeToLive != null) { + writer.writeAttribute("timeToLive", jmsTimeToLive.toString()); + } + + if (jmsPriority != null) { + writer.writeAttribute("priority", 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: + * StringValue + * If the value is of type box (e.g.Integer, Long) or BindingProperty, the output will be + * 42 + */ + @SuppressWarnings("unchecked") + private void writeBindingProperties(Map 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(Constants.SCA11_NS, "property" ); + if (key != null){ + 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. + * + * + * + * + */ + private void writeSubscriptionHeaders( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String jmsSubscriptionHeaders = jmsBinding.getJMSSelector(); + if (jmsSubscriptionHeaders != null && jmsSubscriptionHeaders.length() > 0) { + writer.writeStartElement(Constants.SCA11_NS, "messageSelection"); + writer.writeAttribute("selector", jmsSubscriptionHeaders); + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + // writer.writeCharacters( " " ); + } + } + + /** + * Writes destination properties if there are any. + * + * * + * ? + */ + private void writeDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String destinationName = jmsBinding.getDestinationName(); + if (destinationName == null || (destinationName.length() < 1)) { + return; + } + if (destinationName == null) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "destination"); + + if ( destinationName != null && destinationName.length() > 0) { + writer.writeAttribute("jndiName", 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 && + !destinationCreate.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + writer.writeAttribute("create", destinationCreate); + } + + Map 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. + * + * * + * ? + */ + private void writeConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String cfName = jmsBinding.getConnectionFactoryName(); + if (cfName == null || (cfName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "connectionFactory"); + + if ( cfName != null && cfName.length() > 0) { + writer.writeAttribute("jndiName", cfName); + } + + String destinationCreate = jmsBinding.getConnectionFactoryCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0 && + !destinationCreate.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) { + writer.writeAttribute("create", destinationCreate); + } + + Map 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. + * + * * + * ? + * + */ + private void writeActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getActivationSpecName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "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 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. + * + * * + * ? + */ + private void writeResponseDestinationProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String destinationName = jmsBinding.getResponseDestinationName(); + if (destinationName == null || (destinationName.length() < 1)) { + return; + } + if (destinationName == null) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "destination"); + + if ( destinationName != null && destinationName.length() > 0) { + writer.writeAttribute("jndiName", 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 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. + * + * * + * ? + * + */ + private void writeResponseConnectionFactoryProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String cfName = jmsBinding.getResponseConnectionFactoryName(); + if (cfName == null || (cfName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "connectionFactory"); + + if ( cfName != null && cfName.length() > 0) { + writer.writeAttribute("jndiName", cfName); + } + + String destinationCreate = jmsBinding.getResponseConnectionFactoryCreate(); + if ( destinationCreate != null && destinationCreate.length() > 0) { + writer.writeAttribute("create", destinationCreate); + } + + Map 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. + * + * * + * ? + * + */ + private void writeResponseActivationSpecProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getResponseActivationSpecName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "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 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. + * ? + * * + * ? + */ + private void writeResourceAdapterProperties( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException { + String asName = jmsBinding.getResourceAdapterName(); + if (asName == null || (asName.length() < 1)) { + return; + } + + writer.writeStartElement(Constants.SCA11_NS, "resourceAdapter"); + + if ( asName != null && asName.length() > 0) { + writer.writeAttribute("name", asName); + } + + Map cfProperties = + jmsBinding.getResourceAdapterProperties(); + writeBindingProperties( cfProperties, writer ); + + writer.writeEndElement(); + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Writes configured operations if there are any. + * " + * " + * " + * " + * " + */ + private void writeConfiguredOperations( JMSBinding jmsBinding, XMLStreamWriter writer, ProcessorContext context) throws XMLStreamException, ContributionWriteException { + List configOps = jmsBinding.getConfiguredOperations(); + if (configOps == null || (configOps.size() < 1)) { + return; + } + + for( Iterator it = configOps.iterator(); it.hasNext();) { + configuredOperationProcessor.write(it.next(), writer, context); + } + + // Strange bug. Without white space, headers end tag improperly read. + writer.writeCharacters(" "); + } + + /** + * Wire out a request or response wire format element. Uses extension processors + * to do this as wire format is an extension point + * + * @param wireFormat + * @param writer + */ + private void writeWireFormat(WireFormat wireFormat, XMLStreamWriter writer, ProcessorContext context ) throws XMLStreamException, ContributionWriteException { + extensionProcessor.write(wireFormat, writer, context); + } + + /** + * Wire out an operation selector element. Uses extension processors + * to do this as operation selector is an extension point + * + * @param operationSeletor + * @param writer + */ + private void writeOperationSelector(OperationSelector operationSeletor, XMLStreamWriter writer, ProcessorContext context ) throws XMLStreamException, ContributionWriteException{ + extensionProcessor.write(operationSeletor, writer, context); + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefault.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefault.java new file mode 100644 index 0000000000..a02decd20f --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefault.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.operationselector; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefault implements OperationSelector { + public static final QName OPERATION_SELECTOR_JMS_DEFAULT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "operationSelector.jmsdefault"); + + public QName getSchemaName() { + return OPERATION_SELECTOR_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java new file mode 100644 index 0000000000..4f09eeb9a5 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java @@ -0,0 +1,76 @@ +/* + * 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.operationselector; + + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return OperationSelectorJMSDefault.OPERATION_SELECTOR_JMS_DEFAULT_QNAME; + } + + public OperationSelectorJMSDefaultProcessor(FactoryExtensionPoint modelFactories) { + } + + + public OperationSelectorJMSDefault read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + OperationSelectorJMSDefault wireFormat = new OperationSelectorJMSDefault(); + + return wireFormat; + } + + public void write(OperationSelectorJMSDefault wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return OperationSelectorJMSDefault.class; + } + + public void resolve(OperationSelectorJMSDefault arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserProp.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserProp.java new file mode 100644 index 0000000000..f978adfa58 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserProp.java @@ -0,0 +1,57 @@ +/* + * 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.operationselector; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.OperationSelector; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Model of user property based operation selection + * + * + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSUserProp implements OperationSelector { + public static final QName OPERATION_SELECTOR_JMS_USERPROP_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "operationSelector.jmsUserProp"); + public static final String OPERATION_SELECTOR_JMS_USERPROP_ATTR = "propertyName"; + + private String propertyName; + + public QName getSchemaName() { + return OPERATION_SELECTOR_JMS_USERPROP_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public String getPropertyName() { + return propertyName; + } + + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java new file mode 100644 index 0000000000..9b731ffb1b --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java @@ -0,0 +1,87 @@ +/* + * 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.operationselector; + + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class OperationSelectorJMSUserPropProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_QNAME; + } + + public OperationSelectorJMSUserPropProcessor(FactoryExtensionPoint modelFactories) { + } + + + public OperationSelectorJMSUserProp read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + OperationSelectorJMSUserProp opSelector = new OperationSelectorJMSUserProp(); + String propertyName = reader.getAttributeValue(null, OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR); + if (propertyName != null && propertyName.length() > 0) { + opSelector.setPropertyName(propertyName); + } else { + throw new ContributionReadException(OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_QNAME.toString() + ": " + + OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR + " is a required attribute."); + } + + return opSelector; + } + + public void write(OperationSelectorJMSUserProp opSelector, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + if (opSelector.getPropertyName() != null) { + writer.writeAttribute(OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR, opSelector.getPropertyName()); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return OperationSelectorJMSUserProp.class; + } + + public void resolve(OperationSelectorJMSUserProp arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java new file mode 100644 index 0000000000..24f43d3027 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicy.java @@ -0,0 +1,55 @@ +/* + * 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.policy.authentication.token; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicy { + public static final QName JMS_TOKEN_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "jmsTokenAuthentication"); + public static final String JMS_TOKEN_AUTHENTICATION_TOKEN_NAME = "tokenName"; + + private QName tokenName; + + public QName getTokenName() { + return tokenName; + } + + public void setTokenName(QName tokenName) { + this.tokenName = tokenName; + } + + public QName getSchemaName() { + return JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java new file mode 100644 index 0000000000..4322595515 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java @@ -0,0 +1,111 @@ +/* + * 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.policy.authentication.token; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; + } + + public JMSTokenAuthenticationPolicyProcessor(ExtensionPointRegistry registry) { + } + + + public JMSTokenAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + JMSTokenAuthenticationPolicy policy = new JMSTokenAuthenticationPolicy(); + int event = reader.getEventType(); + QName name = null; + + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + policy.setTokenName(getQName(reader, JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME)); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSTokenAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + if ( policy.getTokenName() != null ) { + writer.writeAttribute(prefix, + getArtifactType().getNamespaceURI(), + JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_TOKEN_NAME, + policy.getTokenName().toString()); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSTokenAuthenticationPolicy.class; + } + + public void resolve(JMSTokenAuthenticationPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java new file mode 100644 index 0000000000..48fef397c7 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicy.java @@ -0,0 +1,130 @@ +/* + * 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.policy.header; + +import java.util.Hashtable; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicy { + public static final QName JMS_HEADER_POLICY_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "jmsHeader"); + public static final String JMS_HEADER_JMS_TYPE = "JMSType"; + public static final String JMS_HEADER_JMS_CORRELATION_ID = "JMSCorrelationID"; + public static final String JMS_HEADER_JMS_DELIVERY_MODE = "JMSDeliveryMode"; + public static final String JMS_HEADER_JMS_TIME_TO_LIVE = "JMSTimeToLive"; + public static final String JMS_HEADER_JMS_PRIORITY = "JMSPriority"; + public static final String JMS_HEADER_JMS_PROPERTY = "property"; + public static final String JMS_HEADER_JMS_PROPERTY_NAME = "name"; + + private String jmsType = null; + private String jmsCorrelationId = null; + private Boolean deliveryModePersistent = null; + private Long timeToLive = null; + private Integer jmsPriority = null; + private Map properties = new Hashtable(); + + 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 getDeliveryModePersistent() { + return deliveryModePersistent; + } + + public void setDeliveryModePersistent(Boolean deliveryModePersistent) { + this.deliveryModePersistent = deliveryModePersistent; + } + + public Long getTimeToLive() { + return timeToLive; + } + + public void setTimeToLive(Long timeToLive) { + this.timeToLive = timeToLive; + } + + public Integer getJmsPriority() { + return jmsPriority; + } + + public void setJmsPriority(Integer jmsPriority) { + this.jmsPriority = jmsPriority; + } + + public Map getProperties() { + return properties; + } + + public QName getSchemaName() { + return JMS_HEADER_POLICY_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public String toString() { + String result = "jmsHeader"; + + result += " JMSType "; + result += getJmsType(); + result += " JMSDeliveryMode "; + result += getJmsCorrelationId(); + result += " JMSDeliveryMode "; + result += getDeliveryModePersistent(); + result += " JMSTimeToLive "; + result += getTimeToLive(); + result += " JMSPriority "; + result += getJmsPriority(); + + for (String propertyName : properties.keySet()){ + result += " property "; + result += propertyName; + result += " "; + result += properties.get(propertyName); + } + + return result; + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java new file mode 100644 index 0000000000..c925c01554 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java @@ -0,0 +1,206 @@ +/* + * 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.policy.header; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.assembly.xml.Messages; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * + * @version $Rev$ $Date$ + */ +public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + + + public QName getArtifactType() { + return JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME; + } + + public JMSHeaderPolicyProcessor(ExtensionPointRegistry modelFactories) { + } + + /** + * Marshals warnings into the monitor + * + * @param message + * @param model + * @param messageParameters + */ + protected void warning(Monitor monitor, String message, Object model, String... messageParameters) { + if (monitor != null){ + Problem problem = monitor.createProblem(this.getClass().getName(), Messages.RESOURCE_BUNDLE, Severity.WARNING, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Marshals errors into the monitor + * + * @param problems + * @param message + * @param model + */ + protected void error(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = monitor.createProblem(this.getClass().getName(), Messages.RESOURCE_BUNDLE, Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + + public JMSHeaderPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + JMSHeaderPolicy policy = new JMSHeaderPolicy(); + int event = reader.getEventType(); + QName name = null; + Monitor monitor = context.getMonitor(); + while (reader.hasNext()) { + event = reader.getEventType(); + switch (event) { + case START_ELEMENT : { + name = reader.getName(); + if ( name.equals(getArtifactType()) ) { + + policy.setJmsType(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TYPE)); + policy.setJmsCorrelationId(getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID)); + + String deliveryMode = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE); + if (deliveryMode != null){ + if (deliveryMode.equals("PERSISTENT")) { + policy.setDeliveryModePersistent(true); + } else if (deliveryMode.equals("NON_PERSISTENT")){ + policy.setDeliveryModePersistent(false); + } else { + error(monitor, "InvalidDeliveryMode", policy, deliveryMode); + } + } + + String timeToLive = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE); + + if ( timeToLive != null){ + try { + policy.setTimeToLive(Long.valueOf(timeToLive)); + } catch (NumberFormatException ex){ + error(monitor, "InvalidTimeToLive", policy, timeToLive); + } + } + + String priority = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY); + + if ( priority != null){ + try { + policy.setJmsPriority(Integer.valueOf(priority)); + } catch (NumberFormatException ex){ + error(monitor, "InvalidPriority", policy, priority); + } + } + } else if (name.getLocalPart().equals(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY)) { + String propertyName = getString(reader, JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME); + String propertyValue = reader.getElementText(); + policy.getProperties().put(propertyName, propertyValue); + } + break; + } + } + + if ( event == END_ELEMENT ) { + if ( getArtifactType().equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return policy; + } + + public void write(JMSHeaderPolicy policy, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + if (policy.getJmsType() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TYPE, policy.getJmsType()); + } + + if (policy.getJmsCorrelationId() != null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_CORRELATION_ID, policy.getJmsCorrelationId()); + } + + if (policy.getDeliveryModePersistent() == true){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "PERSISTENT"); + } else { + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_DELIVERY_MODE, "NON_PERSISTENT"); + } + + if (policy.getTimeToLive()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_TIME_TO_LIVE, policy.getTimeToLive().toString()); + } + + if (policy.getJmsPriority()!= null){ + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PRIORITY, policy.getJmsPriority().toString()); + } + + for (String propertyName : policy.getProperties().keySet()){ + writer.writeStartElement(prefix, + JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY, + getArtifactType().getNamespaceURI()); + writer.writeAttribute(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY_NAME, propertyName); + writer.writeCharacters(policy.getProperties().get(propertyName)); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return JMSHeaderPolicy.class; + } + + public void resolve(JMSHeaderPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytes.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytes.java new file mode 100644 index 0000000000..a16cdc9c4f --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytes.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytes implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsBytes"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java new file mode 100644 index 0000000000..8be904da3e --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java @@ -0,0 +1,75 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSBytesProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSBytes.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSBytesProcessor(FactoryExtensionPoint modelFactories) { + } + + + public WireFormatJMSBytes read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSBytes wireFormat = new WireFormatJMSBytes(); + + return wireFormat; + } + + public void write(WireFormatJMSBytes wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSBytes.class; + } + + public void resolve(WireFormatJMSBytes arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXML.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXML.java new file mode 100644 index 0000000000..4f7a91657f --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXML.java @@ -0,0 +1,40 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + + +public class WireFormatJMSBytesXML implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsBytesXML"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java new file mode 100644 index 0000000000..33533b23eb --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java @@ -0,0 +1,72 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + + +public class WireFormatJMSBytesXMLProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSBytesXML.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSBytesXMLProcessor(FactoryExtensionPoint modelFactories) { + } + + + public WireFormatJMSBytesXML read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSBytesXML wireFormat = new WireFormatJMSBytesXML(); + + return wireFormat; + } + + public void write(WireFormatJMSBytesXML wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSBytesXML.class; + } + + public void resolve(WireFormatJMSBytesXML arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefault.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefault.java new file mode 100644 index 0000000000..5c33a3e2c8 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefault.java @@ -0,0 +1,64 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefault implements WireFormat { + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsdefault"); + + public static final String WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR = "sendFormat"; + + public static final String WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL = "text"; + public static final String WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL = "bytes"; + + //default is to use a javax.jms.BytesMessage + private boolean useBytesMessage = true; + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } + + public void setUseBytesMessage(boolean useBytesMessage) { + this.useBytesMessage = useBytesMessage; + } + + public boolean isUseBytesMessage() { + return useBytesMessage; + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java new file mode 100644 index 0000000000..6b5488a168 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java @@ -0,0 +1,89 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public WireFormatJMSDefaultProcessor(FactoryExtensionPoint modelFactories) { + } + + public WireFormatJMSDefault read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSDefault wireFormat = new WireFormatJMSDefault(); + + String sendFormat = reader.getAttributeValue(null, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); + if (sendFormat != null && sendFormat.length() > 0) { + if (WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL.equalsIgnoreCase(sendFormat)) { + wireFormat.setUseBytesMessage(false); + }else if (WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL.equalsIgnoreCase(sendFormat)) { + wireFormat.setUseBytesMessage(true); + }else{ + throw new ContributionReadException(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME.toString() +" " +sendFormat + " is not a valid attribute value for " + + WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); + } + } + + return wireFormat; + } + + public void write(WireFormatJMSDefault wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + if (wireFormat.isUseBytesMessage()) { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_BYTES_FORMAT_VAL); + } else { + writer.writeAttribute(WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_TEXT_FORMAT_VAL); + } + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSDefault.class; + } + + public void resolve(WireFormatJMSDefault arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObject.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObject.java new file mode 100644 index 0000000000..e043139010 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObject.java @@ -0,0 +1,57 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObject implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsObject"); + + public static final String WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR = "wrapSingle"; + + private boolean wrappedSingleInput = false; + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + public void setWrappedSingleInput(boolean wrappedSingleInput) { + this.wrappedSingleInput = wrappedSingleInput; + } + + public boolean isWrappedSingleInput() { + return wrappedSingleInput; + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java new file mode 100644 index 0000000000..cf0c0db0d7 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java @@ -0,0 +1,88 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSObjectProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSObject.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSObjectProcessor(FactoryExtensionPoint modelFactories) { + } + + + public WireFormatJMSObject read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSObject wireFormat = new WireFormatJMSObject(); + + String wrappedSingleInput = reader.getAttributeValue(null, WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR); + if (wrappedSingleInput != null && wrappedSingleInput.length() > 0) { + if ("true".equalsIgnoreCase(wrappedSingleInput)) { + wireFormat.setWrappedSingleInput(true); + } else if ("false".equalsIgnoreCase(wrappedSingleInput)) { + wireFormat.setWrappedSingleInput(false); + } else { + throw new ContributionReadException(WireFormatJMSObject.WIRE_FORMAT_JMS_BYTES_QNAME.toString() + ": " + wrappedSingleInput + + " is not a valid attribute value for " + WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR); + } + } + return wireFormat; + } + + public void write(WireFormatJMSObject wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeAttribute(WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR, String.valueOf(wireFormat.isWrappedSingleInput())); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSObject.class; + } + + public void resolve(WireFormatJMSObject arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSText.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSText.java new file mode 100644 index 0000000000..4f728cea92 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSText.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jms.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * Implementation for policies that could be injected as parameter + * into the axis2config. + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSText implements WireFormat { + public static final QName WIRE_FORMAT_JMS_BYTES_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsText"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java new file mode 100644 index 0000000000..5c564e044c --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java @@ -0,0 +1,75 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSText.WIRE_FORMAT_JMS_BYTES_QNAME; + } + + public WireFormatJMSTextProcessor(FactoryExtensionPoint modelFactories) { + } + + + public WireFormatJMSText read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSText wireFormat = new WireFormatJMSText(); + + return wireFormat; + } + + public void write(WireFormatJMSText wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSText.class; + } + + public void resolve(WireFormatJMSText arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXML.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXML.java new file mode 100644 index 0000000000..be6187d2c5 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXML.java @@ -0,0 +1,48 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.assembly.xml.Constants; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXML implements WireFormat { + public static final QName WIRE_FORMAT_JMS_DEFAULT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.jmsTextXML"); + + public QName getSchemaName() { + return WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } + + @Override + public boolean equals(Object obj) { + return this.getClass() == obj.getClass(); + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java new file mode 100644 index 0000000000..ae544f3163 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java @@ -0,0 +1,75 @@ +/* + * 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.wireformat; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * + * @version $Rev$ $Date$ + */ +public class WireFormatJMSTextXMLProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + + public QName getArtifactType() { + return WireFormatJMSTextXML.WIRE_FORMAT_JMS_DEFAULT_QNAME; + } + + public WireFormatJMSTextXMLProcessor(FactoryExtensionPoint modelFactories) { + } + + + public WireFormatJMSTextXML read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + WireFormatJMSTextXML wireFormat = new WireFormatJMSTextXML(); + + return wireFormat; + } + + public void write(WireFormatJMSTextXML wireFormat, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + String prefix = "tuscany"; + writer.writeStartElement(prefix, + getArtifactType().getLocalPart(), + getArtifactType().getNamespaceURI()); + writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); + + writer.writeEndElement(); + } + + public Class getModelType() { + return WireFormatJMSTextXML.class; + } + + public void resolve(WireFormatJMSTextXML arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { + + } + +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..3e6b2d887a --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,30 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.binding.jms.JMSBindingProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#binding.jms,model=org.apache.tuscany.sca.binding.jms.JMSBinding +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefaultProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsdefault,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSDefault +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXMLProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsTextXML,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextXML +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsBytes,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXMLProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsBytesXML,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytesXML +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSTextProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsText,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSText +org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObjectProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.jmsObject,model=org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject +org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefaultProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.jmsdefault,model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSDefault +org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserPropProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.jmsUserProp,model=org.apache.tuscany.sca.binding.jms.operationselector.OperationSelectorJMSUserProp +org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#jmsTokenAuthentication,model=org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy +org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#jmsHeader,model=org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy + diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider new file mode 100644 index 0000000000..f30da64ca4 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for SCA Definitions Providers +org.apache.tuscany.sca.binding.jms.policy.JMSBindingDefinitionsProvider diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties new file mode 100644 index 0000000000..fd43b2c4e9 --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-policy-validation-messages.properties @@ -0,0 +1,23 @@ +# +# +# 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. +# +# +InvalidDeliveryMode = JMSDeliveryMode must be either PERSISTENT or NON_PERSISTENT but found {0} +InvalidTimeToLive = JMSTimeToLive must be a long integer but found {0} +InvalidPriority = JMSPriority must be a integer but found {0} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties new file mode 100644 index 0000000000..33d6a9df5c --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/binding-jms-validation-messages.properties @@ -0,0 +1,53 @@ +# +# +# 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. +# +# +DoesntProcessOperationProperties = JMS Binding doesn't process operationProperties yet +DoesntProcessHeaders = JMS Binding doesn't process headers yet +DoesntProcessResourceAdapter = JMS Binding doesn't process resourceAdapter yet +DoesntProcessResponseConnectionFactory = JMS Binding doesn't process response connectionFactory yet +DoesntProcessResponseActivationSpec = JMS Binding doesn't process response activationSpec yet +DoesntProcessResponseDestinationType = JMS Binding doesn't process response destination type yet +DoesntProcessActivationSpec = JMS Binding doesn't process activationSpec yet +DoesntProcessDestinationType = JMS Binding doesn't process destination type yet +MissingConnectionFactoryName = Missing ConnectionFactory Name +MissingResponseConnectionFactory = Missing response connectionFactory name +InvalidResponseDestinationType = Invalid response destination type: {0} +InvalidDestinationType = Invalid destination type: {0} +MissingActivationSpecName = Missing ActivationSpec Name +MissingResponseActivationSpec = Missing response ActivationSpec name +UnknownTokenInURI = Unknown token {0} in uri: {1} +MustStartWithSchema = URI must start with the scheme 'jms:' for uri: {0} +InvalidCorrelationScheme = Invalid correlationScheme: {0} +UnexpectedElement = Incomplete binding.jms definition found unexpected element: {0} +UnexpectedResponseElement = Incomplete binding.jms/response definition found unexpected element: {0} +InvalidJMSDeliveryMode = Invalid JMSDeliveryMode: {0} +InvalidJMSPriority = Invalid JMSPriority: {0} +MissingJMSOperationPropertyName = Missing JMSOperationProperty Name +InvalidOPJMSDeliveryMode = Invalid OPJMSDeliveryMode: {0} +InvalidOPJMSPriority = Invalid OPJMSPriority: {0} +DestinationQueueContradiction = Destination type queue contradicts connection factory name: {0} +DestinationTopicContradiction = Destination type topic contradicts connection factory name: {0} +ConnectionFactoryActivationSpecContradiction = Connection factory \"{0}\" and activation specification \"{0}\" are mutually exclusive +ResponseAttrElement = Response connection \"{0}\" and response element \"{1}\" are mutually exclusive +BindingNotFound = {0} refers to a binding definition {1} which is not found +DuplicateOperationProperties = Must not use both operationProperties attribute and operationProperties element +WireFormatAlreadyDefined = The request wireformat has already been defined. Only one request wire format can be specified. +OpSelectorAlreadyDefined = More than one operation selector has been specified. Only one operation selector can be specified. +ResponseWireformatAlreadyDefined = The response wireformat has already been defined. Only one response wire format can be specified. diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml new file mode 100644 index 0000000000..1b94f139dd --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/main/resources/org/apache/tuscany/sca/binding/jms/policy/definitions.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + Communication through this binding requires JMS + + + + + + + This intent is used to indicate the deliver mode + of the sent message + + + + + + Message are sent persistently + + + + + + Message are sent non-persistently + + + + + + + This intent is used to indicate the priority of the + sent message + + + + + + Messages are high priority + + + + + + Messages are medium priority + + + + + + Messages are low priority + + + \ No newline at end of file diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java new file mode 100644 index 0000000000..67a14068ae --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java @@ -0,0 +1,773 @@ +/* + * 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; + +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 junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.OperationsConfigurator; +import org.apache.tuscany.sca.assembly.WireFormat; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes; +import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; + +/** + * Tests for JMS binding xml + */ +public class JMSBindingProcessorTestCase extends TestCase { + // Note: If you are adding new JMS binding read test cases, + // consider adding a similar test case to JMSBindingProcessorWriteTestCase. + public static final String COMPOSITE = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String HEADERS1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String HEADERS_INVALID_PRIORITY = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String PROPERTIES1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " bla" + + " 42" + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROPERTIES1 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " bla" + + " 42" + + " " + + " " + + " " + + " " + + " op2bla" + + " 77" + + " " + + " " + + " " + + " " + + " " + + ""; + + 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 = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_DEST_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_CF_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RESP_AS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROPS_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String RES_ADPT_PROPS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " some value text" + + " " + + " " + + " bla" + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String CONFIGURED_OPERATIONS = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String WIRE_FORMAT = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + public static final String OP_PROP_NAME = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private XMLInputFactory inputFactory; + private StAXArtifactProcessor staxProcessor; + private ProcessorContext context; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + inputFactory = XMLInputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); + + } + + /** + * 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(COMPOSITE)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("testQueue", binding.getDestinationName()); + } + + public void testHeaders1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS1)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("myType", binding.getJMSType()); + assertTrue(binding.isdeliveryModePersistent()); + assertEquals(54321, binding.getJMSTimeToLive().longValue()); + assertEquals(5, binding.getJMSPriority().intValue()); + } + + public void testProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("bla", binding.getProperty("p1")); + assertEquals(42, ((Integer)binding.getProperty("intProp")).intValue()); + } + + public void testOpProperties1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Map op1Props = binding.getOperationProperties("op1"); + assertEquals("op1Type", binding.getOperationJMSType("op1")); + assertEquals("bla", op1Props.get("p1")); + assertEquals(42, ((Integer)op1Props.get("intProp")).intValue()); + + assertEquals("op2Type", binding.getOperationJMSType("op2")); + Map op2Props = binding.getOperationProperties("op2"); + assertEquals("op2bla", op2Props.get("p2")); + assertEquals(77, ((Integer)op2Props.get("intProp")).intValue()); + } + + public void testSubscriptionHeaders () throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(SELECTOR)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + assertEquals("prop1 = 2", binding.getJMSSelector()); + } + + /** Test various parsing validation requirements. */ + public void testParsingValidationErrors1() throws Exception { + // Composite with malformed URI. + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_URI)); + + try { + Composite composite = (Composite)staxProcessor.read(reader, context); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + } + } + + public void testParsingValidationErrors2() throws Exception { + // Composite with invalid priority + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS_INVALID_PRIORITY)); + + try { + Composite composite = (Composite)staxProcessor.read(reader, context); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + return; + } + } + + /** Test various model validation requirements. */ + public void testValidationErrors1() throws Exception { + // Composite with response connection attr and element. + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT)); + + try { + Composite composite = (Composite)staxProcessor.read(reader, context); + } catch(Exception e) { + // JMSBindingExceptions are expected with invalid composite. + if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) ) + throw e; + // Do assertion to make sure test registers results. + assertTrue( e.getClass().isAssignableFrom( JMSBindingException.class ) ); + } + } + + public void testDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(DEST_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getDestinationProperties()); + assertEquals(2, binding.getDestinationProperties().size()); + BindingProperty bp = binding.getDestinationProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getDestinationProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CF_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getConnectionFactoryProperties()); + assertEquals(2, binding.getConnectionFactoryProperties().size()); + BindingProperty bp = binding.getConnectionFactoryProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getConnectionFactoryProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(AS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getActivationSpecProperties()); + assertEquals(2, binding.getActivationSpecProperties().size()); + BindingProperty bp = binding.getActivationSpecProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getActivationSpecProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseDestinationProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_DEST_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseDestinationProperties()); + assertEquals(2, binding.getResponseDestinationProperties().size()); + BindingProperty bp = binding.getResponseDestinationProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseDestinationProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseConnectionFactoryProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_CF_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseConnectionFactoryProperties()); + assertEquals(2, binding.getResponseConnectionFactoryProperties().size()); + BindingProperty bp = binding.getResponseConnectionFactoryProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseConnectionFactoryProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResponseActivationSpecProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_AS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getResponseActivationSpecProperties()); + assertEquals(2, binding.getResponseActivationSpecProperties().size()); + BindingProperty bp = binding.getResponseActivationSpecProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResponseActivationSpecProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testOperationPropertiesProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPS_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertNotNull(binding.getOperationPropertiesProperties("op1")); + assertEquals(2, binding.getOperationPropertiesProperties("op1").size()); + BindingProperty bp = binding.getOperationPropertiesProperties("op1").get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getOperationPropertiesProperties("op1").get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + public void testResouceAdapterProperties() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RES_ADPT_PROPS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals("r1", binding.getResourceAdapterName()); + assertNotNull(binding.getResourceAdapterProperties()); + assertEquals(2, binding.getResourceAdapterProperties().size()); + BindingProperty bp = binding.getResourceAdapterProperties().get("xxx"); + assertEquals("xxx", bp.getName()); + assertEquals("yyy", bp.getType()); + assertEquals("some value text", bp.getValue().toString().trim()); + BindingProperty bp2 = binding.getResourceAdapterProperties().get("two"); + assertEquals("two", bp2.getName()); + assertEquals(null, bp2.getType()); + assertEquals("bla", bp2.getValue().toString().trim()); + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * public Object getOperationProperty(String opName, String propName ); + * @throws Exception + */ + public void testOpProperties2() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Set opNames = binding.getOperationNames(); + assertEquals( 2, opNames.size() ); + // Recall that order is not guaranteed iterating over a set. + for (Iterator it=opNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + assertTrue( opName.equals( "op1") || opName.equals( "op2")); + } + + Object value = binding.getOperationProperty( "op1", "p1" ); + assertEquals("bla", value); + value = binding.getOperationProperty( "op1", "intProp" ); + assertEquals(42, ((Integer)value).intValue()); + + value = binding.getOperationProperty( "op2", "p2" ); + assertEquals("op2bla", value); + value = binding.getOperationProperty( "op2", "intProp" ); + assertEquals(77, ((Integer)value).intValue()); + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * Provides no optional properties or sub elements + * @throws Exception + */ + public void testOpProperties3() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_NAMES_NO_PROPERTIES1)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + + Set opNames = binding.getOperationNames(); + assertEquals( 2, opNames.size() ); + // Recall that order is not guaranteed iterating over a set. + for (Iterator it=opNames.iterator(); it.hasNext(); ) { + String opName = it.next(); + assertTrue( opName.equals( "op1") || opName.equals( "op2")); + } + } + + /** + * Tests the APIs: + * public Set getOperationNames(); + * Provides no optional properties or sub elements + * @throws Exception + */ + public void testConfiguredOperations1() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CONFIGURED_OPERATIONS)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + OperationsConfigurator opConfig = ((OperationsConfigurator)binding); + assertEquals(opConfig.getConfiguredOperations().get(0).getRequiredIntents().size(), 2); + } + + /** + * Tests the APIs: + * public WireFormat getRequstWireFormat(); + * public WireFormat getResponseWireFormat(); + * + * @throws Exception + */ + public void testWireFormat() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(WIRE_FORMAT)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + WireFormat requestWireFormat = binding.getRequestWireFormat(); + assertEquals(WireFormatJMSObject.class, requestWireFormat.getClass()); + + WireFormat responseWireFormat = binding.getResponseWireFormat(); + assertEquals(WireFormatJMSBytes.class, responseWireFormat.getClass()); + } + + public void testOpPropertiesName() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROP_NAME)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + assertNotNull(binding); + assertEquals( "foo", binding.getOperationPropertiesName().getLocalPart() ); + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java new file mode 100644 index 0000000000..db138aa30d --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java @@ -0,0 +1,438 @@ +/* + * 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; + +import java.io.ByteArrayOutputStream; +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; + +/** + * 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 { + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessor staxProcessor; + + public static final String DEFAULT = + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + private ProcessorContext context; + + @Override + protected void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); + } + + /** + * 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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 { + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.HEADERS1)), context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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 testConfiguredOperations() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CONFIGURED_OPERATIONS)); + Composite composite = (Composite)staxProcessor.read(reader, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + 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 testWireFormat() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.WIRE_FORMAT)); + Composite composite = (Composite)staxProcessor.read(reader, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals(binding, binding2); + } + + // TUSCANY-3120 + // Checking we don't write out values unless the use has specified them on input + public void testDefault() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(DEFAULT)); + Composite composite = (Composite)staxProcessor.read(reader, context); + JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); + + System.out.println(bos.toString()); + assertEquals(bos.toString(), + "" + + "" + + "" + + "" + + " " + + "" + + "" + + " " + + " "+ + " " + + "" + + "" + + "" + + ""); + } + + public void testOperationPropertiesName() throws Exception { + XMLStreamReader reader = + inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROP_NAME)); + Composite composite = (Composite)staxProcessor.read(reader, context); + 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), context); + + // Read written JMSBinding to a different JMSBinding model. + XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); + JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); + assertNotNull(binding2); + + // Compare initial binding to written binding. + assertEquals("foo", binding2.getOperationPropertiesName().getLocalPart()); + } +} diff --git a/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..326bb54cca --- /dev/null +++ b/sandbox/sebastien/java/dynamic/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java @@ -0,0 +1,95 @@ +/* + * 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.policy; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicy; +import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; +import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.junit.Ignore; +import org.junit.Test; + +/** + * @version $Rev$ $Date$ + */ +@Ignore("TODO: 2.x migration") +public class PolicyProcessorTestCase { + private final static List SEQ = + Arrays.asList("property value", + ""); + + @Test + public void testRead() throws Exception { + List results = new ArrayList(); + Map processors = new HashMap(); + processors.put(JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME, new JMSHeaderPolicyProcessor(null)); + processors.put(JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME, new JMSTokenAuthenticationPolicyProcessor(null)); + + InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + + XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + ProcessorContext context =new ProcessorContext(); + while (true) { + int event = reader.getEventType(); + if (event == XMLStreamConstants.START_ELEMENT) { + if ("policySet".equals(reader.getName().getLocalPart())) { + reader.nextTag(); + StAXArtifactProcessor processor = processors.get(reader.getName()); + Object xxx = processor.read(reader, context); +// Policy policy = (Policy)processor.read(reader); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream); + processor.write(xxx, writer, context); +// processor.write(policy, writer); + writer.flush(); + results.add(outputStream.toString()); + } + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + Assert.assertEquals(SEQ, results); + } +} -- cgit v1.2.3