001: /*
002: * Copyright 2002-2007 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: * http://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:
017: package org.springframework.jms.support.destination;
018:
019: import javax.jms.Destination;
020: import javax.jms.JMSException;
021: import javax.jms.Session;
022:
023: import org.springframework.jms.support.JmsAccessor;
024: import org.springframework.util.Assert;
025:
026: /**
027: * Base class for {@link org.springframework.jms.core.JmsTemplate} and other
028: * JMS-accessing gateway helpers, adding destination-related properties to
029: * {@link JmsAccessor JmsAccessor's} common properties.
030: *
031: * <p>Not intended to be used directly.
032: * See {@link org.springframework.jms.core.JmsTemplate}.
033: *
034: * @author Juergen Hoeller
035: * @since 1.2.5
036: * @see org.springframework.jms.support.JmsAccessor
037: * @see org.springframework.jms.core.JmsTemplate
038: */
039: public abstract class JmsDestinationAccessor extends JmsAccessor {
040:
041: private DestinationResolver destinationResolver = new DynamicDestinationResolver();
042:
043: private boolean pubSubDomain = false;
044:
045: /**
046: * Set the {@link DestinationResolver} that is to be used to resolve
047: * {@link javax.jms.Destination} references for this accessor.
048: * <p>The default resolver is a DynamicDestinationResolver. Specify a
049: * JndiDestinationResolver for resolving destination names as JNDI locations.
050: * @see org.springframework.jms.support.destination.DynamicDestinationResolver
051: * @see org.springframework.jms.support.destination.JndiDestinationResolver
052: */
053: public void setDestinationResolver(
054: DestinationResolver destinationResolver) {
055: Assert.notNull(destinationResolver,
056: "'destinationResolver' must not be null");
057: this .destinationResolver = destinationResolver;
058: }
059:
060: /**
061: * Return the DestinationResolver for this accessor (never <code>null</code>).
062: */
063: public DestinationResolver getDestinationResolver() {
064: return this .destinationResolver;
065: }
066:
067: /**
068: * Configure the destination accessor with knowledge of the JMS domain used.
069: * Default is Point-to-Point (Queues).
070: * <p>For JMS 1.0.2 based accessors, this tells the JMS provider which class hierarchy
071: * to use in the implementation of its operations. For JMS 1.1 based accessors, this
072: * setting does usually not affect operations. However, for both JMS versions, this
073: * setting tells what type of destination to resolve if dynamic destinations are enabled.
074: * @param pubSubDomain "true" for the Publish/Subscribe domain ({@link javax.jms.Topic Topics}),
075: * "false" for the Point-to-Point domain ({@link javax.jms.Queue Queues})
076: * @see #setDestinationResolver
077: */
078: public void setPubSubDomain(boolean pubSubDomain) {
079: this .pubSubDomain = pubSubDomain;
080: }
081:
082: /**
083: * Return whether the Publish/Subscribe domain ({@link javax.jms.Topic Topics}) is used.
084: * Otherwise, the Point-to-Point domain ({@link javax.jms.Queue Queues}) is used.
085: */
086: public boolean isPubSubDomain() {
087: return this .pubSubDomain;
088: }
089:
090: /**
091: * Resolve the given destination name into a JMS {@link Destination},
092: * via this accessor's {@link DestinationResolver}.
093: * @param session the current JMS {@link Session}
094: * @param destinationName the name of the destination
095: * @return the located {@link Destination}
096: * @throws javax.jms.JMSException if resolution failed
097: * @see #setDestinationResolver
098: */
099: protected Destination resolveDestinationName(Session session,
100: String destinationName) throws JMSException {
101: return getDestinationResolver().resolveDestinationName(session,
102: destinationName, isPubSubDomain());
103: }
104:
105: }
|