1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.jencks;
19
20 import javax.jms.MessageListener;
21 import javax.resource.spi.LocalTransaction;
22 import javax.resource.spi.UnavailableException;
23 import javax.resource.spi.endpoint.MessageEndpoint;
24 import javax.resource.spi.endpoint.MessageEndpointFactory;
25 import javax.transaction.TransactionManager;
26 import javax.transaction.xa.XAResource;
27 import java.lang.reflect.Method;
28
29 /***
30 * @version $Revision: 1.1.1.1 $
31 */
32 public abstract class EndpointFactorySupport implements MessageEndpointFactory {
33 protected TransactionManager transactionManager;
34
35 public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException {
36 MessageListener messageListener = createMessageListener();
37 if (transactionManager != null) {
38 return new XAEndpoint(messageListener, xaResource, transactionManager);
39 }
40 else if (xaResource instanceof LocalTransaction) {
41 return new LocalTransactionEndpoint(messageListener, (LocalTransaction) xaResource);
42 }
43 return new AcknowledgeEndpoint(messageListener);
44 }
45
46 public String toString() {
47 return super.toString() + "[transactionManager=" + transactionManager + "]";
48 }
49
50
51
52 public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException {
53 return transactionManager != null;
54 }
55
56 public TransactionManager getTransactionManager() {
57 return transactionManager;
58 }
59
60 public void setTransactionManager(TransactionManager transactionManager) {
61 this.transactionManager = transactionManager;
62 }
63
64
65
66 protected abstract MessageListener createMessageListener() throws UnavailableException;
67 }