KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > support > destination > JmsDestinationAccessor


1 /*
2  * Copyright 2002-2007 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 JavaDoc;
20 import javax.jms.JMSException JavaDoc;
21 import javax.jms.Session JavaDoc;
22
23 import org.springframework.jms.support.JmsAccessor;
24 import org.springframework.util.Assert;
25
26 /**
27  * Base class for {@link org.springframework.jms.core.JmsTemplate} and other
28  * JMS-accessing gateway helpers, adding destination-related properties to
29  * {@link JmsAccessor JmsAccessor's} common properties.
30  *
31  * <p>Not intended to be used directly.
32  * See {@link org.springframework.jms.core.JmsTemplate}.
33  *
34  * @author Juergen Hoeller
35  * @since 1.2.5
36  * @see org.springframework.jms.support.JmsAccessor
37  * @see org.springframework.jms.core.JmsTemplate
38  */

39 public abstract class JmsDestinationAccessor extends JmsAccessor {
40
41     private DestinationResolver destinationResolver = new DynamicDestinationResolver();
42
43     private boolean pubSubDomain = false;
44
45
46     /**
47      * Set the {@link DestinationResolver} that is to be used to resolve
48      * {@link javax.jms.Destination} references for this accessor.
49      * <p>The default resolver is a DynamicDestinationResolver. Specify a
50      * JndiDestinationResolver for resolving destination names as JNDI locations.
51      * @see org.springframework.jms.support.destination.DynamicDestinationResolver
52      * @see org.springframework.jms.support.destination.JndiDestinationResolver
53      */

54     public void setDestinationResolver(DestinationResolver destinationResolver) {
55         Assert.notNull(destinationResolver, "'destinationResolver' must not be null");
56         this.destinationResolver = destinationResolver;
57     }
58
59     /**
60      * Return the DestinationResolver for this accessor (never <code>null</code>).
61      */

62     public DestinationResolver getDestinationResolver() {
63         return this.destinationResolver;
64     }
65
66     /**
67      * Configure the destination accessor with knowledge of the JMS domain used.
68      * Default is Point-to-Point (Queues).
69      * <p>For JMS 1.0.2 based accessors, this tells the JMS provider which class hierarchy
70      * to use in the implementation of its operations. For JMS 1.1 based accessors, this
71      * setting does usually not affect operations. However, for both JMS versions, this
72      * setting tells what type of destination to resolve if dynamic destinations are enabled.
73      * @param pubSubDomain "true" for the Publish/Subscribe domain ({@link javax.jms.Topic Topics}),
74      * "false" for the Point-to-Point domain ({@link javax.jms.Queue Queues})
75      * @see #setDestinationResolver
76      */

77     public void setPubSubDomain(boolean pubSubDomain) {
78         this.pubSubDomain = pubSubDomain;
79     }
80
81     /**
82      * Return whether the Publish/Subscribe domain ({@link javax.jms.Topic Topics}) is used.
83      * Otherwise, the Point-to-Point domain ({@link javax.jms.Queue Queues}) is used.
84      */

85     public boolean isPubSubDomain() {
86         return this.pubSubDomain;
87     }
88
89
90     /**
91      * Resolve the given destination name into a JMS {@link Destination},
92      * via this accessor's {@link DestinationResolver}.
93      * @param session the current JMS {@link Session}
94      * @param destinationName the name of the destination
95      * @return the located {@link Destination}
96      * @throws javax.jms.JMSException if resolution failed
97      * @see #setDestinationResolver
98      */

99     protected Destination JavaDoc resolveDestinationName(Session JavaDoc session, String JavaDoc destinationName) throws JMSException JavaDoc {
100         return getDestinationResolver().resolveDestinationName(session, destinationName, isPubSubDomain());
101     }
102
103 }
104
Popular Tags