001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jms.config; 018 019import javax.jms.MessageListener; 020 021import org.springframework.jms.listener.MessageListenerContainer; 022import org.springframework.lang.Nullable; 023import org.springframework.util.Assert; 024 025/** 026 * A {@link JmsListenerEndpoint} simply providing the {@link MessageListener} to 027 * invoke to process an incoming message for this endpoint. 028 * 029 * @author Stephane Nicoll 030 * @since 4.1 031 */ 032public class SimpleJmsListenerEndpoint extends AbstractJmsListenerEndpoint { 033 034 @Nullable 035 private MessageListener messageListener; 036 037 038 /** 039 * Set the {@link MessageListener} to invoke when a message matching 040 * the endpoint is received. 041 */ 042 public void setMessageListener(@Nullable MessageListener messageListener) { 043 this.messageListener = messageListener; 044 } 045 046 /** 047 * Return the {@link MessageListener} to invoke when a message matching 048 * the endpoint is received. 049 */ 050 @Nullable 051 public MessageListener getMessageListener() { 052 return this.messageListener; 053 } 054 055 056 @Override 057 protected MessageListener createMessageListener(MessageListenerContainer container) { 058 MessageListener listener = getMessageListener(); 059 Assert.state(listener != null, "No MessageListener set"); 060 return listener; 061 } 062 063 @Override 064 protected StringBuilder getEndpointDescription() { 065 return super.getEndpointDescription() 066 .append(" | messageListener='").append(this.messageListener).append("'"); 067 } 068 069}