summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider
diff options
context:
space:
mode:
Diffstat (limited to 'branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider')
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java258
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingListener.java155
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java64
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java145
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java194
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java48
-rw-r--r--branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorImpl.java161
7 files changed, 0 insertions, 1025 deletions
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
deleted file mode 100644
index 444c659eeb..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingInvoker.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * 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.provider;
-
-import java.lang.reflect.InvocationTargetException;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.naming.NamingException;
-
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
-import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.invocation.Invoker;
-
-/**
- * Interceptor for the JMS binding.
- *
- * @version $Rev$ $Date$
- */
-public class JMSBindingInvoker implements Invoker {
-
- protected Operation operation;
- protected String operationName;
-
- protected JMSBinding jmsBinding;
- protected JMSResourceFactory jmsResourceFactory;
- protected JMSMessageProcessor requestMessageProcessor;
- protected JMSMessageProcessor responseMessageProcessor;
- protected Destination requestDest;
- protected Destination replyDest;
-
- public JMSBindingInvoker(JMSBinding jmsBinding, Operation operation, JMSResourceFactory jmsResourceFactory) {
-
- this.operation = operation;
- operationName = operation.getName();
-
- this.jmsBinding = jmsBinding;
- this.jmsResourceFactory = jmsResourceFactory;
- requestMessageProcessor = jmsBinding.getRequestMessageProcessor();
- responseMessageProcessor = jmsBinding.getResponseMessageProcessor();
- try {
- requestDest = lookupDestination();
- replyDest = lookupResponseDestination();
- } catch (NamingException e) {
- throw new JMSBindingException(e);
- }
-
- }
-
- /**
- * Looks up the Destination Queue for the JMS Binding
- *
- * @return The Destination Queue
- * @throws NamingException Failed to lookup Destination Queue
- * @throws JMSBindingException Failed to lookup Destination Queue
- * @see #lookupDestinationQueue(boolean)
- */
- private Destination lookupDestination() throws NamingException, JMSBindingException {
- return lookupDestinationQueue(false);
- }
-
- /**
- * Looks up the Destination Response Queue for the JMS Binding
- *
- * @return The Destination Response Queue
- * @throws NamingException Failed to lookup Destination Response Queue
- * @throws JMSBindingException Failed to lookup Destination Response Queue
- * @see #lookupDestinationQueue(boolean)
- */
- private Destination lookupResponseDestination() throws NamingException, JMSBindingException {
- return lookupDestinationQueue(true);
- }
-
- /**
- * Looks up the Destination Queue for the JMS Binding.
- * <p>
- * What happens in the look up will depend on the create mode specified for the JMS Binding:
- * <ul>
- * <li>always - the JMS queue is always created. It is an error if the queue already exists
- * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists
- * <li>never - the JMS queue is never created. It is an error if the queue does not exist
- * </ul>
- * See the SCA JMS Binding specification for more information.
- * <p>
- *
- * @param isReponseQueue <code>true</code> if we are creating a response queue. <code>false</code> if we are
- * creating a request queue
- * @return The Destination queue.
- * @throws NamingException Failed to lookup JMS queue
- * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that the JMS queue's current
- * existance/non-existance is not compatible with the create mode specified on the binding
- */
- private Destination lookupDestinationQueue(boolean isReponseQueue) throws NamingException, JMSBindingException {
- String queueName;
- String queueType;
- String qCreateMode;
- if (isReponseQueue) {
- queueName = jmsBinding.getResponseDestinationName();
- queueType = "JMS Response Destination ";
- qCreateMode = jmsBinding.getResponseDestinationCreate();
- } else {
- queueName = jmsBinding.getDestinationName();
- queueType = "JMS Destination ";
- qCreateMode = jmsBinding.getDestinationCreate();
- }
-
- Destination dest = jmsResourceFactory.lookupDestination(queueName);
-
- if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
- // In this mode, the queue must not already exist as we are creating it
- if (dest != null) {
- throw new JMSBindingException(queueType + queueName
- + " already exists but has create mode of \""
- + qCreateMode
- + "\" while registering binding "
- + jmsBinding.getName()
- + " invoker");
- }
- // Create the queue
- dest = jmsResourceFactory.createDestination(queueName);
-
- } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
- // In this mode, the queue may nor may not exist. It will be created if it does not exist
- if (dest == null) {
- dest = jmsResourceFactory.createDestination(queueName);
- }
-
- } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
- // In this mode, the queue must have already been created.
- if (dest == null) {
- throw new JMSBindingException(queueType + queueName
- + " not found but create mode of \""
- + qCreateMode
- + "\" while registering binding "
- + jmsBinding.getName()
- + " invoker");
- }
- }
-
- // Make sure we ended up with a queue
- if (dest == null) {
- throw new JMSBindingException(queueType + queueName
- + " not found with create mode of \""
- + qCreateMode
- + "\" while registering binding "
- + jmsBinding.getName()
- + " invoker");
- }
-
- return dest;
- }
-
- public org.apache.tuscany.sca.invocation.Message invoke(org.apache.tuscany.sca.invocation.Message msg) {
- try {
- Object resp = invokeTarget((Object[])msg.getBody(), (short)0);
- msg.setBody(resp);
- } catch (InvocationTargetException e) {
- msg.setFaultBody(e.getCause());
- } catch (Throwable e) {
- msg.setFaultBody(e);
- }
- return msg;
- }
-
- public Object invokeTarget(Object payload, final short sequence) throws InvocationTargetException {
- try {
- Session session = jmsResourceFactory.createSession();
- try {
-
- Destination replyToDest;
- if (operation.isNonBlocking()) {
- replyToDest = null;
- } else {
- replyToDest = (replyDest != null) ? replyDest : session.createTemporaryQueue();
- }
-
- Message requestMsg = sendRequest((Object[])payload, session, replyToDest);
- if (replyToDest == null) {
- return null;
- } else {
- Message replyMsg = receiveReply(session, replyToDest, requestMsg.getJMSMessageID());
- return ((Object[])responseMessageProcessor.extractPayloadFromJMSMessage(replyMsg))[0];
- }
-
- } finally {
- session.close();
- }
- } catch (JMSException e) {
- throw new InvocationTargetException(e);
- } catch (NamingException e) {
- throw new InvocationTargetException(e);
- }
- }
-
- public void stop() throws NamingException, JMSException {
- jmsResourceFactory.closeConnection();
- }
-
- protected Message sendRequest(Object payload, Session session, Destination replyToDest) throws JMSException {
-
- Message requestMsg = requestMessageProcessor.insertPayloadIntoJMSMessage(session, payload);
-
- requestMsg.setJMSDeliveryMode(jmsBinding.getDeliveryMode());
- requestMsg.setJMSPriority(jmsBinding.getPriority());
-
- requestMessageProcessor.setOperationName(operationName, requestMsg);
- requestMsg.setJMSReplyTo(replyToDest);
-
- MessageProducer producer = session.createProducer(requestDest);
- try {
- producer.send(requestMsg);
- } finally {
- producer.close();
- }
- return requestMsg;
- }
-
- protected Message receiveReply(Session session, Destination replyToDest, String requestMsgId) throws JMSException,
- NamingException {
- String msgSelector = "JMSCorrelationID = '" + requestMsgId + "'";
- MessageConsumer consumer = session.createConsumer(replyToDest, msgSelector);
- Message replyMsg;
- try {
- jmsResourceFactory.startConnection();
- replyMsg = consumer.receive(jmsBinding.getTimeToLive());
- } finally {
- consumer.close();
- }
- if (replyMsg == null) {
- throw new JMSBindingException("No reply message received on " + replyToDest + " for message id " + requestMsgId);
- }
- return replyMsg;
- }
-
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingListener.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingListener.java
deleted file mode 100644
index 1c01786c31..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingListener.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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.provider;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.naming.NamingException;
-
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
-import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-
-public class JMSBindingListener implements MessageListener {
-
- private static final String ON_MESSAGE_METHOD_NAME = "onMessage";
- private JMSBinding jmsBinding;
- private JMSResourceFactory jmsResourceFactory;
- private RuntimeComponentService service;
- private JMSMessageProcessor requestMessageProcessor;
- private JMSMessageProcessor responseMessageProcessor;
- private String correlationScheme;
-
- public JMSBindingListener(JMSBinding jmsBinding,
- JMSResourceFactory jmsResourceFactory,
- RuntimeComponentService service) throws NamingException {
- this.jmsBinding = jmsBinding;
- this.jmsResourceFactory = jmsResourceFactory;
- this.service = service;
- requestMessageProcessor = jmsBinding.getRequestMessageProcessor();
- responseMessageProcessor = jmsBinding.getResponseMessageProcessor();
- correlationScheme = jmsBinding.getCorrelationScheme();
- }
-
- public void onMessage(Message requestJMSMsg) {
- try {
- Object responsePayload = invokeService(requestJMSMsg);
- sendReply(requestJMSMsg, responsePayload);
- } catch (Exception e) {
- sendFaultReply(requestJMSMsg, e);
- }
- }
-
- /**
- * Turn the JMS message back into a Tuscany message and invoke the target component
- *
- * @param requestJMSMsg
- * @return
- * @throws JMSException
- * @throws InvocationTargetException
- */
- protected Object invokeService(Message requestJMSMsg) throws JMSException, InvocationTargetException {
-
- String operationName = requestMessageProcessor.getOperationName(requestJMSMsg);
- Object requestPayload = requestMessageProcessor.extractPayloadFromJMSMessage(requestJMSMsg);
-
- List<Operation> opList = service.getInterfaceContract().getInterface().getOperations();
-
- Operation operation = null;
-
- if (opList.size() == 1) {
- // SCA JMS Binding Specification - Rule 1.5.1 line 203
- operation = opList.get(0);
- } else if (operationName != null) {
- // SCA JMS Binding Specification - Rule 1.5.1 line 205
- for (Operation op : opList) {
- if (op.getName().equals(operationName)) {
- operation = op;
- break;
- }
- }
- } else {
- // SCA JMS Binding Specification - Rule 1.5.1 line 207
- for (Operation op : opList) {
- if (op.getName().equals(ON_MESSAGE_METHOD_NAME)) {
- operation = op;
- break;
- }
- }
- }
-
- if (operation != null) {
- return service.getRuntimeWire(jmsBinding).invoke(operation, (Object[])requestPayload);
- } else {
- throw new JMSBindingException("Can't find operation " + (operationName != null ? operationName
- : ON_MESSAGE_METHOD_NAME));
- }
-
- }
-
- protected void sendReply(Message requestJMSMsg, Object responsePayload) {
- try {
-
- if (requestJMSMsg.getJMSReplyTo() == null) {
- // assume no reply is expected
- return;
- }
-
- Session session = jmsResourceFactory.createSession();
- Message replyJMSMsg = responseMessageProcessor.insertPayloadIntoJMSMessage(session, responsePayload);
-
- replyJMSMsg.setJMSDeliveryMode(requestJMSMsg.getJMSDeliveryMode());
- replyJMSMsg.setJMSPriority(requestJMSMsg.getJMSPriority());
-
- if (correlationScheme == null || JMSBindingConstants.CORRELATE_MSG_ID.equalsIgnoreCase(correlationScheme)) {
- replyJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSMessageID());
- } else if (JMSBindingConstants.CORRELATE_CORRELATION_ID.equalsIgnoreCase(correlationScheme)) {
- replyJMSMsg.setJMSCorrelationID(requestJMSMsg.getJMSCorrelationID());
- }
-
- Destination destination = requestJMSMsg.getJMSReplyTo();
- MessageProducer producer = session.createProducer(destination);
-
- producer.send(replyJMSMsg);
-
- producer.close();
- session.close();
-
- } catch (JMSException e) {
- throw new JMSBindingException(e);
- } catch (NamingException e) {
- throw new JMSBindingException(e);
- }
- }
-
- protected void sendFaultReply(Message requestJMSMsg, Exception e) {
- sendReply(requestJMSMsg, new JMSBindingException("exception invoking JMS service", e));
- }
-
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java
deleted file mode 100644
index 06f5388bd1..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingProviderFactory.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.provider;
-
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.host.jms.JMSHost;
-import org.apache.tuscany.sca.provider.BindingProviderFactory;
-import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
-import org.apache.tuscany.sca.provider.ServiceBindingProvider;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-
-/**
- * A factory from creating the JMS binding provider.
- *
- * @version $Rev$ $Date$
- */
-public class JMSBindingProviderFactory implements BindingProviderFactory<JMSBinding> {
-
- private JMSHost jmsHost;
-
- public JMSBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
- jmsHost = extensionPoints.getExtensionPoint(JMSHost.class);
- if (jmsHost == null) {
- throw new JMSBindingException("No JMSHost extension point registered");
- }
- }
-
- public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
- RuntimeComponentReference reference,
- JMSBinding binding) {
- return new JMSBindingReferenceBindingProvider(component, reference, binding, jmsHost);
- }
-
- public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
- RuntimeComponentService service,
- JMSBinding binding) {
- return new JMSBindingServiceBindingProvider(component, service, binding, jmsHost);
- }
-
- public Class<JMSBinding> getModelType() {
- return JMSBinding.class;
- }
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java
deleted file mode 100644
index eb22783813..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingReferenceBindingProvider.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.provider;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-import org.apache.tuscany.sca.host.jms.JMSHost;
-import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.invocation.Invoker;
-import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
-
-/**
- * Implementation of the JMS reference binding provider.
- *
- * @version $Rev$ $Date$
- */
-public class JMSBindingReferenceBindingProvider implements ReferenceBindingProvider {
-
- private RuntimeComponentReference reference;
- private JMSBinding jmsBinding;
- private List<JMSBindingInvoker> jmsBindingInvokers = new ArrayList<JMSBindingInvoker>();
- private JMSResourceFactory jmsResourceFactory;
-
- public JMSBindingReferenceBindingProvider(RuntimeComponent component,
- RuntimeComponentReference reference,
- JMSBinding binding, JMSHost jmsHost) {
- this.reference = reference;
- this.jmsBinding = binding;
- jmsResourceFactory = jmsHost.createJMSResourceFactory(binding.getConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL());
-
- if (jmsBinding.getXMLFormat()) {
- setXMLDataBinding(reference);
- }
-
- }
-
- protected void setXMLDataBinding(RuntimeComponentReference reference) {
- try {
- InterfaceContract ic = (InterfaceContract)reference.getInterfaceContract().clone();
-
- Interface ii = (Interface)ic.getInterface().clone();
- ii.resetDataBinding("org.apache.axiom.om.OMElement");
- ic.setInterface(ii);
- reference.setInterfaceContract(ic);
-
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
-
- public Invoker createInvoker(Operation operation) {
-
- if (jmsBinding.getDestinationName().equals(JMSBindingConstants.DEFAULT_DESTINATION_NAME)) {
- throw new JMSBindingException("No destination specified for reference " + reference.getName());
- }
-
- /* The following doesn't work as I can't get to the
- * target list on the composite reference
- // if the default destination queue name is set
- // set the destination queue name to the wired service name
- // so that any wires can be assured a unique endpoint.
-
- if (jmsBinding.getDestinationName().equals(JMSBindingConstants.DEFAULT_DESTINATION_NAME)){
- // get the name of the target service
- List<ComponentService> targets = reference.getTargets();
-
- if (targets.size() < 1){
- throw new JMSBindingException("No target specified for reference " +
- reference.getName() +
- " so destination queue name can't be determined");
- }
-
- if (targets.size() > 1){
- throw new JMSBindingException("More than one target specified for reference " +
- reference.getName() +
- " so destination queue name can't be determined");
- }
-
- ComponentService service = targets.get(0);
- jmsBinding.setDestinationName(service.getName());
- }
-
-
- // if the default response queue name is set
- // set the response queue to the names of this
- // reference
- if (jmsBinding.getResponseDestinationName().equals(JMSBindingConstants.DEFAULT_RESPONSE_DESTINATION_NAME)){
- jmsBinding.setResponseDestinationName(reference.getName());
- }
- */
- JMSBindingInvoker invoker = new JMSBindingInvoker(jmsBinding, operation, jmsResourceFactory);
- jmsBindingInvokers.add(invoker);
- return invoker;
- }
-
- public boolean supportsOneWayInvocation() {
- return true;
- }
-
- public InterfaceContract getBindingInterfaceContract() {
- return reference.getInterfaceContract();
- }
-
- public void start() {
-
- }
-
- public void stop() {
- try {
- for (JMSBindingInvoker invoker : jmsBindingInvokers) {
- invoker.stop();
-
- }
- } catch (Exception e) {
- throw new JMSBindingException("Error stopping JMSReferenceBinding", e);
- }
- }
-
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
deleted file mode 100644
index 33e2d32663..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * 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.provider;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.Session;
-import javax.naming.NamingException;
-
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-import org.apache.tuscany.sca.host.jms.JMSHost;
-import org.apache.tuscany.sca.host.jms.JMSResourceFactory;
-import org.apache.tuscany.sca.interfacedef.Interface;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
-import org.apache.tuscany.sca.provider.ServiceBindingProvider;
-import org.apache.tuscany.sca.runtime.RuntimeComponent;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-
-/**
- * Implementation of the JMS service binding provider.
- *
- * @version $Rev$ $Date$
- */
-public class JMSBindingServiceBindingProvider implements ServiceBindingProvider {
-
- private RuntimeComponentService service;
- private JMSBinding jmsBinding;
- private JMSResourceFactory jmsResourceFactory;
- private MessageConsumer consumer;
-
- public JMSBindingServiceBindingProvider(RuntimeComponent component,
- RuntimeComponentService service,
- JMSBinding binding, JMSHost jmsHost) {
- this.service = service;
- this.jmsBinding = binding;
-
- jmsResourceFactory = jmsHost.createJMSResourceFactory(binding.getConnectionFactoryName(), binding.getInitialContextFactoryName(), binding.getJndiURL());
- jmsResourceFactory.startBroker();
-
- // if the default destination queue names is set
- // set the destinate queue name to the reference name
- // so that any wires can be assured a unique endpoint.
- if (jmsBinding.getDestinationName().equals(JMSBindingConstants.DEFAULT_DESTINATION_NAME)) {
- // jmsBinding.setDestinationName(service.getName());
- throw new JMSBindingException("No destination specified for service " + service.getName());
- }
-
- if (jmsBinding.getXMLFormat()) {
- setXMLDataBinding(service);
- }
-
- }
-
- protected void setXMLDataBinding(RuntimeComponentService service) {
- if (service.getInterfaceContract() != null) {
- try {
- InterfaceContract ic = (InterfaceContract)service.getInterfaceContract().clone();
-
- Interface ii = (Interface)ic.getInterface().clone();
- ii.resetDataBinding("org.apache.axiom.om.OMElement");
- ic.setInterface(ii);
- service.setInterfaceContract(ic);
-
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- public InterfaceContract getBindingInterfaceContract() {
- return service.getInterfaceContract();
- }
-
- public boolean supportsOneWayInvocation() {
- return true;
- }
-
- public void start() {
-
- try {
- registerListerner();
- } catch (Exception e) {
- throw new JMSBindingException("Error starting JMSServiceBinding", e);
- }
- }
-
- public void stop() {
- try {
- consumer.close();
- jmsResourceFactory.closeConnection();
- } catch (Exception e) {
- throw new JMSBindingException("Error stopping JMSServiceBinding", e);
- }
- }
-
- private void registerListerner() throws NamingException, JMSException {
-
- Session session = jmsResourceFactory.createSession();
- Destination destination = lookupDestinationQueue();
-
- consumer = session.createConsumer(destination);
-
- consumer.setMessageListener(new JMSBindingListener(jmsBinding, jmsResourceFactory, service));
-
- jmsResourceFactory.startConnection();
-
- }
-
- /**
- * Looks up the Destination Queue for the JMS Binding.
- * <p>
- * What happens in the look up will depend on the create mode specified for the JMS Binding:
- * <ul>
- * <li>always - the JMS queue is always created. It is an error if the queue already exists
- * <li>ifnotexist - the JMS queue is created if it does not exist. It is not an error if the queue already exists
- * <li>never - the JMS queue is never created. It is an error if the queue does not exist
- * </ul>
- * See the SCA JMS Binding specification for more information.
- * <p>
- *
- * @return The Destination queue.
- * @throws NamingException Failed to lookup JMS queue
- * @throws JMSBindingException Failed to lookup JMS Queue. Probable cause is that the JMS queue's current
- * existance/non-existance is not compatible with the create mode specified on the binding
- */
- private Destination lookupDestinationQueue() throws NamingException, JMSBindingException {
- Destination destination = jmsResourceFactory.lookupDestination(jmsBinding.getDestinationName());
-
- String qCreateMode = jmsBinding.getDestinationCreate();
- if (qCreateMode.equals(JMSBindingConstants.CREATE_ALWAYS)) {
- // In this mode, the queue must not already exist as we are creating it
- if (destination != null) {
- throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
- + " already exists but has create mode of \""
- + qCreateMode
- + "\" while registering service "
- + service.getName()
- + " listener");
- }
-
- // Create the queue
- destination = jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
-
- } else if (qCreateMode.equals(JMSBindingConstants.CREATE_IF_NOT_EXIST)) {
- // In this mode, the queue may nor may not exist. It will be created if it does not exist
- if (destination == null) {
- destination = jmsResourceFactory.createDestination(jmsBinding.getDestinationName());
- }
-
- } else if (qCreateMode.equals(JMSBindingConstants.CREATE_NEVER)) {
- // In this mode, the queue must have already been created.
- if (destination == null) {
- throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
- + " not found but create mode of \""
- + qCreateMode
- + "\" while registering service "
- + service.getName()
- + " listener");
- }
- }
-
- // Make sure we ended up with a queue
- if (destination == null) {
- throw new JMSBindingException("JMS Destination " + jmsBinding.getDestinationName()
- + " not found with create mode of \""
- + qCreateMode
- + "\" while registering service "
- + service.getName()
- + " listener");
- }
-
- return destination;
- }
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java
deleted file mode 100644
index 29ea78e906..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessor.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.provider;
-
-import javax.jms.Message;
-import javax.jms.Session;
-
-/**
- * Interface for a component that does operation selection and message payload processing
- */
-public interface JMSMessageProcessor {
-
- /**
- * Get the operation name from a JMS Message
- */
- public abstract String getOperationName(Message message);
-
- /**
- * Set the operation name on a JMS Message
- */
- public abstract void setOperationName(String operationName, Message message);
-
- /**
- * Extracts the payload from a JMS Message
- */
- public abstract Object extractPayloadFromJMSMessage(Message msg);
-
- /**
- * Create a JMS Message containing the payload
- */
- public abstract Message insertPayloadIntoJMSMessage(Session session, Object payload);
-}
diff --git a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorImpl.java b/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorImpl.java
deleted file mode 100644
index 57ba81106f..0000000000
--- a/branches/sca-java-1.1/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorImpl.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.provider;
-
-import java.io.Serializable;
-import java.io.StringReader;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
-
-public class JMSMessageProcessorImpl implements JMSMessageProcessor {
-
- protected String operationPropertyName;
- protected boolean xmlFormat;
-
- public JMSMessageProcessorImpl(JMSBinding jmsBinding) {
- this.operationPropertyName = jmsBinding.getOperationSelectorPropertyName();
- this.xmlFormat = jmsBinding.getXMLFormat();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#getOperationName(javax.jms.Message)
- */
- public String getOperationName(Message message) {
- try {
-
- return message.getStringProperty(operationPropertyName);
-
- } catch (JMSException e) {
- throw new JMSBindingException("Exception retreiving operation name from message", e);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#setOperationName(javax.jms.Message, java.lang.String)
- */
- public void setOperationName(String operationName, Message message) {
- try {
-
- message.setStringProperty(operationPropertyName, operationName);
-
- } catch (JMSException e) {
- throw new JMSBindingException("Exception setting the operation name on message", e);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Session, java.lang.Object)
- */
- public Message insertPayloadIntoJMSMessage(Session session, Object o) {
- if (xmlFormat) {
- return createXMLJMSMessage(session, o);
- } else {
- return createObjectJMSMessage(session, o);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.tuscany.binding.jms.OperationAndDataBinding#extractPayload(javax.jms.Message)
- */
- public Object extractPayloadFromJMSMessage(Message msg) {
- if (xmlFormat) {
- return extractXMLPayload(msg);
- } else {
- return extractObjectPayload(msg);
- }
- }
-
- protected Object extractXMLPayload(Message msg) {
- try {
-
- String xml = ((TextMessage)msg).getText();
-
- XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
- StAXOMBuilder builder = new StAXOMBuilder(reader);
- OMElement omElement = builder.getDocumentElement();
-
- return new Object[] {omElement};
-
- } catch (XMLStreamException e) {
- throw new JMSBindingException(e);
- } catch (JMSException e) {
- throw new JMSBindingException(e);
- }
- }
-
- protected Object extractObjectPayload(Message msg) {
- try {
-
- return ((ObjectMessage)msg).getObject();
-
- } catch (JMSException e) {
- throw new JMSBindingException(e);
- }
- }
-
- protected Message createXMLJMSMessage(Session session, Object o) {
- try {
-
- TextMessage message = session.createTextMessage();
-
- if (o instanceof OMElement) {
- message.setText(o.toString());
- } else {
- message.setText(((Object[])o)[0].toString());
- }
-
- return message;
-
- } catch (JMSException e) {
- throw new JMSBindingException(e);
- }
- }
-
- protected Message createObjectJMSMessage(Session session, Object o) {
- try {
-
- ObjectMessage message = session.createObjectMessage(); // default
- message.setObject((Serializable)o);
- return message;
-
- } catch (JMSException e) {
- throw new JMSBindingException(e);
- }
- }
-}