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 org.springframework.beans.factory.InitializingBean; 021 022 import javax.jms.MessageListener; 023 import javax.resource.spi.UnavailableException; 024 import javax.transaction.TransactionManager; 025 026 /** 027 * An implementation of {@link javax.resource.spi.endpoint.MessageEndpointFactory} which always 028 * uses a single shared instance of a {@link javax.jms.MessageListener} for every endpoint, irrespective 029 * of how many physical endpoints are used. 030 * 031 * @version $Revision: 1.2 $ 032 */ 033 public class SingletonEndpointFactory extends EndpointFactorySupport implements InitializingBean { 034 private MessageListener messageListener; 035 036 public SingletonEndpointFactory() { 037 } 038 039 public SingletonEndpointFactory(MessageListener messageListener) { 040 this.messageListener = messageListener; 041 } 042 043 public SingletonEndpointFactory(MessageListener messageListener, TransactionManager tm) { 044 this.messageListener = messageListener; 045 this.transactionManager = tm; 046 } 047 048 public void afterPropertiesSet() throws Exception { 049 if (messageListener == null) { 050 throw new IllegalArgumentException("messageListener property must be set"); 051 } 052 } 053 054 public MessageListener getMessageListener() { 055 return messageListener; 056 } 057 058 public void setMessageListener(MessageListener messageListener) { 059 this.messageListener = messageListener; 060 } 061 062 // Implementation methods 063 //------------------------------------------------------------------------- 064 protected MessageListener createMessageListener() throws UnavailableException { 065 return messageListener; 066 } 067 }