Source Code Cross Referenced for JndiDestinationResolver.java in  » J2EE » spring-framework-2.5 » org » springframework » jms » support » destination » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.jms.support.destination 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 java.util.Map;
020:
021:        import javax.jms.Destination;
022:        import javax.jms.JMSException;
023:        import javax.jms.Queue;
024:        import javax.jms.Session;
025:        import javax.jms.Topic;
026:        import javax.naming.NamingException;
027:
028:        import org.springframework.core.CollectionFactory;
029:        import org.springframework.jndi.JndiLocatorSupport;
030:        import org.springframework.util.Assert;
031:
032:        /**
033:         * {@link DestinationResolver} implementation which interprets destination names
034:         * as JNDI locations (with a configurable fallback strategy).
035:         *
036:         * <p>Allows for customizing the JNDI environment if necessary, for example
037:         * specifying appropriate JNDI environment properties.
038:         *
039:         * <p>Dynamic queues and topics get cached by destination name. As a consequence,
040:         * you need to use unique destination names across both queues and topics.
041:         * Caching can be turned off through the {@link #setCache "cache"} flag.
042:         *
043:         * <p>Note that the fallback to resolution of dynamic destinations
044:         * is turned <i>off</i> by default. Switch the
045:         * {@link #setFallbackToDynamicDestination "fallbackToDynamicDestination"}
046:         * flag on to enable this functionality.
047:         *
048:         * @author Mark Pollack
049:         * @author Juergen Hoeller
050:         * @since 1.1
051:         * @see #setJndiTemplate
052:         * @see #setJndiEnvironment
053:         * @see #setCache
054:         * @see #setFallbackToDynamicDestination
055:         */
056:        public class JndiDestinationResolver extends JndiLocatorSupport
057:                implements  CachingDestinationResolver {
058:
059:            private boolean cache = true;
060:
061:            private boolean fallbackToDynamicDestination = false;
062:
063:            private DestinationResolver dynamicDestinationResolver = new DynamicDestinationResolver();
064:
065:            private final Map destinationCache = CollectionFactory
066:                    .createConcurrentMapIfPossible(16);
067:
068:            /**
069:             * Set whether to cache resolved destinations. Default is "true".
070:             * <p>This flag can be turned off to re-lookup a destination for each operation,
071:             * which allows for hot restarting of destinations. This is mainly useful
072:             * during development.
073:             * <p>Note that dynamic queues and topics get cached by destination name.
074:             * As a consequence, you need to use unique destination names across both
075:             * queues and topics.
076:             */
077:            public void setCache(boolean cache) {
078:                this .cache = cache;
079:            }
080:
081:            /**
082:             * Set whether this resolver is supposed to create dynamic destinations
083:             * if the destination name is not found in JNDI. Default is "false".
084:             * <p>Turn this flag on to enable transparent fallback to dynamic destinations.
085:             * @see #setDynamicDestinationResolver
086:             */
087:            public void setFallbackToDynamicDestination(
088:                    boolean fallbackToDynamicDestination) {
089:                this .fallbackToDynamicDestination = fallbackToDynamicDestination;
090:            }
091:
092:            /**
093:             * Set the {@link DestinationResolver} to use when falling back to dynamic
094:             * destinations.
095:             * <p>The default is Spring's standard {@link DynamicDestinationResolver}.
096:             * @see #setFallbackToDynamicDestination
097:             * @see DynamicDestinationResolver
098:             */
099:            public void setDynamicDestinationResolver(
100:                    DestinationResolver dynamicDestinationResolver) {
101:                this .dynamicDestinationResolver = dynamicDestinationResolver;
102:            }
103:
104:            public Destination resolveDestinationName(Session session,
105:                    String destinationName, boolean pubSubDomain)
106:                    throws JMSException {
107:
108:                Assert.notNull(destinationName,
109:                        "Destination name must not be null");
110:                Destination dest = (Destination) this .destinationCache
111:                        .get(destinationName);
112:                if (dest != null) {
113:                    validateDestination(dest, destinationName, pubSubDomain);
114:                } else {
115:                    try {
116:                        dest = (Destination) lookup(destinationName,
117:                                Destination.class);
118:                        validateDestination(dest, destinationName, pubSubDomain);
119:                    } catch (NamingException ex) {
120:                        if (logger.isDebugEnabled()) {
121:                            logger.debug("Destination [" + destinationName
122:                                    + "] not found in JNDI", ex);
123:                        }
124:                        if (this .fallbackToDynamicDestination) {
125:                            dest = this .dynamicDestinationResolver
126:                                    .resolveDestinationName(session,
127:                                            destinationName, pubSubDomain);
128:                        } else {
129:                            throw new DestinationResolutionException(
130:                                    "Destination [" + destinationName
131:                                            + "] not found in JNDI", ex);
132:                        }
133:                    }
134:                    if (this .cache) {
135:                        this .destinationCache.put(destinationName, dest);
136:                    }
137:                }
138:                return dest;
139:            }
140:
141:            /**
142:             * Validate the given Destination object, checking whether it matches
143:             * the expected type.
144:             * @param destination the Destination object to validate
145:             * @param destinationName the name of the destination
146:             * @param pubSubDomain <code>true</code> if a Topic is expected,
147:             * <code>false</code> in case of a Queue
148:             */
149:            protected void validateDestination(Destination destination,
150:                    String destinationName, boolean pubSubDomain) {
151:                Class targetClass = Queue.class;
152:                if (pubSubDomain) {
153:                    targetClass = Topic.class;
154:                }
155:                if (!targetClass.isInstance(destination)) {
156:                    throw new DestinationResolutionException("Destination ["
157:                            + destinationName + "] is not of expected type ["
158:                            + targetClass.getName() + "]");
159:                }
160:            }
161:
162:            public void removeFromCache(String destinationName) {
163:                this .destinationCache.remove(destinationName);
164:            }
165:
166:            public void clearCache() {
167:                this.destinationCache.clear();
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.