1 /* 2 * Copyright 2002-2014 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jms.support.destination; 18 19 import javax.jms.Destination; 20 import javax.jms.JMSException; 21 import javax.jms.Queue; 22 import javax.jms.Session; 23 import javax.jms.Topic; 24 25 import org.springframework.util.Assert; 26 27 /** 28 * Simple {@link DestinationResolver} implementation resolving destination names 29 * as dynamic destinations. 30 * 31 * @author Juergen Hoeller 32 * @since 1.1 33 * @see javax.jms.Session#createQueue 34 * @see javax.jms.Session#createTopic 35 */ 36 public class DynamicDestinationResolver implements DestinationResolver { 37 38 /** 39 * Resolve the specified destination name as a dynamic destination. 40 * @param session the current JMS Session 41 * @param destinationName the name of the destination 42 * @param pubSubDomain {@code true} if the domain is pub-sub, {@code false} if P2P 43 * @return the JMS destination (either a topic or a queue) 44 * @throws javax.jms.JMSException if resolution failed 45 * @see #resolveTopic(javax.jms.Session, String) 46 * @see #resolveQueue(javax.jms.Session, String) 47 */ 48 @Override 49 public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) 50 throws JMSException { 51 52 Assert.notNull(session, "Session must not be null"); 53 Assert.notNull(destinationName, "Destination name must not be null"); 54 if (pubSubDomain) { 55 return resolveTopic(session, destinationName); 56 } 57 else { 58 return resolveQueue(session, destinationName); 59 } 60 } 61 62 63 /** 64 * Resolve the given destination name to a {@link Topic}. 65 * @param session the current JMS Session 66 * @param topicName the name of the desired {@link Topic} 67 * @return the JMS {@link Topic} 68 * @throws javax.jms.JMSException if resolution failed 69 * @see Session#createTopic(String) 70 */ 71 protected Topic resolveTopic(Session session, String topicName) throws JMSException { 72 return session.createTopic(topicName); 73 } 74 75 /** 76 * Resolve the given destination name to a {@link Queue}. 77 * @param session the current JMS Session 78 * @param queueName the name of the desired {@link Queue} 79 * @return the JMS {@link Queue} 80 * @throws javax.jms.JMSException if resolution failed 81 * @see Session#createQueue(String) 82 */ 83 protected Queue resolveQueue(Session session, String queueName) throws JMSException { 84 return session.createQueue(queueName); 85 } 86 87 }