001 /** 002 * 003 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.jencks; 019 020 import javax.jms.MessageListener; 021 import javax.resource.spi.LocalTransaction; 022 import javax.resource.spi.UnavailableException; 023 import javax.resource.spi.endpoint.MessageEndpoint; 024 import javax.resource.spi.endpoint.MessageEndpointFactory; 025 import javax.transaction.TransactionManager; 026 import javax.transaction.xa.XAResource; 027 import java.lang.reflect.Method; 028 029 /** 030 * @version $Revision: 1.1.1.1 $ 031 */ 032 public abstract class EndpointFactorySupport implements MessageEndpointFactory { 033 protected TransactionManager transactionManager; 034 035 public MessageEndpoint createEndpoint(XAResource xaResource) throws UnavailableException { 036 MessageListener messageListener = createMessageListener(); 037 if (transactionManager != null) { 038 return new XAEndpoint(messageListener, xaResource, transactionManager); 039 } 040 else if (xaResource instanceof LocalTransaction) { 041 return new LocalTransactionEndpoint(messageListener, (LocalTransaction) xaResource); 042 } 043 return new AcknowledgeEndpoint(messageListener); 044 } 045 046 public String toString() { 047 return super.toString() + "[transactionManager=" + transactionManager + "]"; 048 } 049 050 // Properties 051 //------------------------------------------------------------------------- 052 public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException { 053 return transactionManager != null; 054 } 055 056 public TransactionManager getTransactionManager() { 057 return transactionManager; 058 } 059 060 public void setTransactionManager(TransactionManager transactionManager) { 061 this.transactionManager = transactionManager; 062 } 063 064 // Implementation methods 065 //------------------------------------------------------------------------- 066 protected abstract MessageListener createMessageListener() throws UnavailableException; 067 }