Source Code Cross Referenced for SimplePortletPostProcessor.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.Collections;
020:        import java.util.Enumeration;
021:        import java.util.Locale;
022:        import java.util.ResourceBundle;
023:
024:        import javax.portlet.Portlet;
025:        import javax.portlet.PortletConfig;
026:        import javax.portlet.PortletContext;
027:        import javax.portlet.PortletException;
028:
029:        import org.springframework.beans.BeansException;
030:        import org.springframework.beans.factory.BeanInitializationException;
031:        import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
032:        import org.springframework.web.portlet.context.PortletConfigAware;
033:        import org.springframework.web.portlet.context.PortletContextAware;
034:
035:        /**
036:         * Bean post-processor that applies initialization and destruction callbacks
037:         * to beans that implement the Portlet interface.
038:         *
039:         * <p>After initialization of the bean instance, the Portlet <code>init</code>
040:         * method will be called with a PortletConfig that contains the bean name
041:         * of the Portlet and the PortletContext that it is running in.
042:         *
043:         * <p>Before destruction of the bean instance, the Portlet <code>destroy</code>
044:         * will be called.
045:         *
046:         * <p><b>Note that this post-processor does not support Portlet initialization
047:         * parameters.</b> Bean instances that implement the Portlet interface are
048:         * supposed to be configured like any other Spring bean, that is, through
049:         * constructor arguments or bean properties.
050:         *
051:         * <p>For reuse of a Portlet implementation in a plain Portlet container and as
052:         * a bean in a Spring context, consider deriving from Spring's GenericPortletBean
053:         * base class that applies Portlet initialization parameters as bean properties,
054:         * supporting both initialization styles.
055:         *
056:         * <p><b>Alternatively, consider wrapping a Portlet with Spring's
057:         * PortletWrappingController.</b> This is particularly appropriate for
058:         * existing Portlet classes, allowing to specify Portlet initialization
059:         * parameters etc.
060:         *
061:         * @author Juergen Hoeller
062:         * @author John A. Lewis
063:         * @since 2.0
064:         * @see javax.portlet.Portlet
065:         * @see javax.portlet.PortletConfig
066:         * @see SimplePortletHandlerAdapter
067:         * @see org.springframework.web.portlet.GenericPortletBean
068:         * @see org.springframework.web.portlet.mvc.PortletWrappingController
069:         */
070:        public class SimplePortletPostProcessor implements 
071:                DestructionAwareBeanPostProcessor, PortletContextAware,
072:                PortletConfigAware {
073:
074:            private boolean useSharedPortletConfig = true;
075:
076:            private PortletContext portletContext;
077:
078:            private PortletConfig portletConfig;
079:
080:            /**
081:             * Set whether to use the shared PortletConfig object passed in
082:             * through <code>setPortletConfig</code>, if available.
083:             * <p>Default is "true". Turn this setting to "false" to pass in
084:             * a mock PortletConfig object with the bean name as portlet name,
085:             * holding the current PortletContext.
086:             * @see #setPortletConfig
087:             */
088:            public void setUseSharedPortletConfig(boolean useSharedPortletConfig) {
089:                this .useSharedPortletConfig = useSharedPortletConfig;
090:            }
091:
092:            public void setPortletContext(PortletContext portletContext) {
093:                this .portletContext = portletContext;
094:            }
095:
096:            public void setPortletConfig(PortletConfig portletConfig) {
097:                this .portletConfig = portletConfig;
098:            }
099:
100:            public Object postProcessBeforeInitialization(Object bean,
101:                    String beanName) throws BeansException {
102:                return bean;
103:            }
104:
105:            public Object postProcessAfterInitialization(Object bean,
106:                    String beanName) throws BeansException {
107:                if (bean instanceof  Portlet) {
108:                    PortletConfig config = this .portletConfig;
109:                    if (config == null || !this .useSharedPortletConfig) {
110:                        config = new DelegatingPortletConfig(beanName,
111:                                this .portletContext, this .portletConfig);
112:                    }
113:                    try {
114:                        ((Portlet) bean).init(config);
115:                    } catch (PortletException ex) {
116:                        throw new BeanInitializationException(
117:                                "Portlet.init threw exception", ex);
118:                    }
119:                }
120:                return bean;
121:            }
122:
123:            public void postProcessBeforeDestruction(Object bean,
124:                    String beanName) throws BeansException {
125:                if (bean instanceof  Portlet) {
126:                    ((Portlet) bean).destroy();
127:                }
128:            }
129:
130:            /**
131:             * Internal implementation of the PortletConfig interface, to be passed
132:             * to the wrapped servlet.
133:             */
134:            private static class DelegatingPortletConfig implements 
135:                    PortletConfig {
136:
137:                private final String portletName;
138:
139:                private final PortletContext portletContext;
140:
141:                private final PortletConfig portletConfig;
142:
143:                public DelegatingPortletConfig(String portletName,
144:                        PortletContext portletContext,
145:                        PortletConfig portletConfig) {
146:                    this .portletName = portletName;
147:                    this .portletContext = portletContext;
148:                    this .portletConfig = portletConfig;
149:                }
150:
151:                public String getPortletName() {
152:                    return portletName;
153:                }
154:
155:                public PortletContext getPortletContext() {
156:                    return portletContext;
157:                }
158:
159:                public String getInitParameter(String paramName) {
160:                    return null;
161:                }
162:
163:                public Enumeration getInitParameterNames() {
164:                    return Collections.enumeration(Collections.EMPTY_SET);
165:                }
166:
167:                public ResourceBundle getResourceBundle(Locale locale) {
168:                    return portletConfig == null ? null : portletConfig
169:                            .getResourceBundle(locale);
170:                }
171:            }
172:
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.