Source Code Cross Referenced for AbstractMapBasedHandlerMapping.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » portlet » handler » 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.0.6 » org.springframework.web.portlet.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 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.web.portlet.handler;
018:
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.Map;
022:
023:        import javax.portlet.PortletRequest;
024:
025:        import org.springframework.beans.BeansException;
026:        import org.springframework.util.Assert;
027:
028:        /**
029:         * Abstract base class for HandlerMapping implementations that rely on a map
030:         * which caches handler objects per lookup key. Supports arbitrary lookup keys,
031:         * and automatically resolves handler bean names into handler bean instances.
032:         *
033:         * @author Juergen Hoeller
034:         * @since 2.0
035:         * @see #getLookupKey(javax.portlet.PortletRequest)
036:         * @see #registerHandler(Object, Object)
037:         */
038:        public abstract class AbstractMapBasedHandlerMapping extends
039:                AbstractHandlerMapping {
040:
041:            private boolean lazyInitHandlers = false;
042:
043:            private final Map handlerMap = new HashMap();
044:
045:            /**
046:             * Set whether to lazily initialize handlers. Only applicable to
047:             * singleton handlers, as prototypes are always lazily initialized.
048:             * Default is false, as eager initialization allows for more efficiency
049:             * through referencing the handler objects directly.
050:             * <p>If you want to allow your handlers to be lazily initialized,
051:             * make them "lazy-init" and set this flag to true. Just making them
052:             * "lazy-init" will not work, as they are initialized through the
053:             * references from the handler mapping in this case.
054:             */
055:            public void setLazyInitHandlers(boolean lazyInitHandlers) {
056:                this .lazyInitHandlers = lazyInitHandlers;
057:            }
058:
059:            /**
060:             * Determines a handler for the computed lookup key for the given request.
061:             * @see #getLookupKey
062:             */
063:            protected Object getHandlerInternal(PortletRequest request)
064:                    throws Exception {
065:                Object lookupKey = getLookupKey(request);
066:                Object handler = this .handlerMap.get(lookupKey);
067:                if (handler != null && logger.isDebugEnabled()) {
068:                    logger.debug("Key [" + lookupKey + "] -> handler ["
069:                            + handler + "]");
070:                }
071:                return handler;
072:            }
073:
074:            /**
075:             * Build a lookup key for the given request.
076:             * @param request current portlet request
077:             * @return the lookup key (never <code>null</code>)
078:             * @throws Exception if key computation failed
079:             */
080:            protected abstract Object getLookupKey(PortletRequest request)
081:                    throws Exception;
082:
083:            /**
084:             * Register all handlers specified in the Portlet mode map for the corresponding modes.
085:             * @param handlerMap Map with lookup keys as keys and handler beans or bean names as values
086:             * @throws BeansException if the handler couldn't be registered
087:             */
088:            protected void registerHandlers(Map handlerMap)
089:                    throws BeansException {
090:                Assert.notNull(handlerMap, "Handler Map must not be null");
091:                for (Iterator it = handlerMap.entrySet().iterator(); it
092:                        .hasNext();) {
093:                    Map.Entry entry = (Map.Entry) it.next();
094:                    registerHandler(entry.getKey(), entry.getValue());
095:                }
096:            }
097:
098:            /**
099:             * Register the given handler instance for the given parameter value.
100:             * @param lookupKey the key to map the handler onto
101:             * @param handler the handler instance or handler bean name String
102:             * (a bean name will automatically be resolved into the corrresponding handler bean)
103:             * @throws BeansException if the handler couldn't be registered
104:             * @throws IllegalStateException if there is a conflicting handler registered
105:             */
106:            protected void registerHandler(Object lookupKey, Object handler)
107:                    throws BeansException, IllegalStateException {
108:                Assert.notNull(lookupKey, "Lookup key must not be null");
109:                Assert.notNull(handler, "Handler object must not be null");
110:
111:                // Check for duplicate mapping.
112:                Object mappedHandler = this .handlerMap.get(lookupKey);
113:                if (mappedHandler != null) {
114:                    throw new IllegalStateException("Cannot map handler ["
115:                            + handler + "] to key [" + lookupKey
116:                            + "]: There's already handler [" + mappedHandler
117:                            + "] mapped.");
118:                }
119:
120:                // Eagerly resolve handler if referencing singleton via name.
121:                if (!this .lazyInitHandlers && handler instanceof  String) {
122:                    String handlerName = (String) handler;
123:                    if (getApplicationContext().isSingleton(handlerName)) {
124:                        handler = getApplicationContext().getBean(handlerName);
125:                    }
126:                }
127:
128:                // Add the handler to the map.
129:                this .handlerMap.put(lookupKey, handler);
130:                if (logger.isDebugEnabled()) {
131:                    logger.debug("Mapped key [" + lookupKey
132:                            + "] onto handler [" + handler + "]");
133:                }
134:            }
135:
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.