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