001/* 002 * Copyright 2002-2014 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.support.destination; 018 019import javax.jms.Destination; 020import javax.jms.JMSException; 021import javax.jms.Queue; 022import javax.jms.Session; 023import javax.jms.Topic; 024 025import org.springframework.util.Assert; 026 027/** 028 * Simple {@link DestinationResolver} implementation resolving destination names 029 * as dynamic destinations. 030 * 031 * @author Juergen Hoeller 032 * @since 1.1 033 * @see javax.jms.Session#createQueue 034 * @see javax.jms.Session#createTopic 035 */ 036public class DynamicDestinationResolver implements DestinationResolver { 037 038 /** 039 * Resolve the specified destination name as a dynamic destination. 040 * @param session the current JMS Session 041 * @param destinationName the name of the destination 042 * @param pubSubDomain {@code true} if the domain is pub-sub, {@code false} if P2P 043 * @return the JMS destination (either a topic or a queue) 044 * @throws javax.jms.JMSException if resolution failed 045 * @see #resolveTopic(javax.jms.Session, String) 046 * @see #resolveQueue(javax.jms.Session, String) 047 */ 048 @Override 049 public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) 050 throws JMSException { 051 052 Assert.notNull(session, "Session must not be null"); 053 Assert.notNull(destinationName, "Destination name must not be null"); 054 if (pubSubDomain) { 055 return resolveTopic(session, destinationName); 056 } 057 else { 058 return resolveQueue(session, destinationName); 059 } 060 } 061 062 063 /** 064 * Resolve the given destination name to a {@link Topic}. 065 * @param session the current JMS Session 066 * @param topicName the name of the desired {@link Topic} 067 * @return the JMS {@link Topic} 068 * @throws javax.jms.JMSException if resolution failed 069 * @see Session#createTopic(String) 070 */ 071 protected Topic resolveTopic(Session session, String topicName) throws JMSException { 072 return session.createTopic(topicName); 073 } 074 075 /** 076 * Resolve the given destination name to a {@link Queue}. 077 * @param session the current JMS Session 078 * @param queueName the name of the desired {@link Queue} 079 * @return the JMS {@link Queue} 080 * @throws javax.jms.JMSException if resolution failed 081 * @see Session#createQueue(String) 082 */ 083 protected Queue resolveQueue(Session session, String queueName) throws JMSException { 084 return session.createQueue(queueName); 085 } 086 087}