Source Code Cross Referenced for WebApplicationContextFacesELResolver.java in  » J2EE » spring-framework-2.5 » org » springframework » web » jsf » el » 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.web.jsf.el 
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.web.jsf.el;
018:
019:        import java.beans.FeatureDescriptor;
020:        import java.util.Iterator;
021:
022:        import javax.el.ELContext;
023:        import javax.el.ELException;
024:        import javax.el.ELResolver;
025:        import javax.faces.context.FacesContext;
026:
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:
030:        import org.springframework.beans.BeansException;
031:        import org.springframework.web.context.WebApplicationContext;
032:        import org.springframework.web.jsf.FacesContextUtils;
033:
034:        /**
035:         * Special JSF 1.2 <code>ELResolver</code> that exposes the Spring
036:         * <code>WebApplicationContext</code> instance under a variable named
037:         * "webApplicationContext".
038:         *
039:         * <p>In contrast to {@link SpringBeanFacesELResolver}, this ELResolver variant
040:         * does <i>not</i> resolve JSF variable names as Spring bean names. It rather
041:         * exposes Spring's root WebApplicationContext <i>itself</i> under a special name,
042:         * and is able to resolve "webApplicationContext.mySpringManagedBusinessObject"
043:         * dereferences to Spring-defined beans in that application context.
044:         *
045:         * <p>Configure this resolver in your <code>faces-config.xml</code> file as follows:
046:         *
047:         * <pre>
048:         * &lt;application>
049:         *   ...
050:         *   &lt;el-resolver>org.springframework.web.jsf.el.WebApplicationContextFacesELResolver&lt;/el-resolver>
051:         * &lt;/application></pre>
052:         *
053:         * @author Juergen Hoeller
054:         * @since 2.5
055:         * @see SpringBeanFacesELResolver
056:         * @see org.springframework.web.jsf.FacesContextUtils#getWebApplicationContext
057:         */
058:        public class WebApplicationContextFacesELResolver extends ELResolver {
059:
060:            /**
061:             * Name of the exposed WebApplicationContext variable: "webApplicationContext".
062:             */
063:            public static final String WEB_APPLICATION_CONTEXT_VARIABLE_NAME = "webApplicationContext";
064:
065:            /** Logger available to subclasses */
066:            protected final Log logger = LogFactory.getLog(getClass());
067:
068:            public Object getValue(ELContext elContext, Object base,
069:                    Object property) throws ELException {
070:                if (base != null) {
071:                    if (base instanceof  WebApplicationContext) {
072:                        WebApplicationContext wac = (WebApplicationContext) base;
073:                        String beanName = property.toString();
074:                        if (logger.isTraceEnabled()) {
075:                            logger.trace("Attempting to resolve property '"
076:                                    + beanName
077:                                    + "' in root WebApplicationContext");
078:                        }
079:                        if (wac.containsBean(beanName)) {
080:                            if (logger.isDebugEnabled()) {
081:                                logger.debug("Successfully resolved property '"
082:                                        + beanName
083:                                        + "' in root WebApplicationContext");
084:                            }
085:                            elContext.setPropertyResolved(true);
086:                            try {
087:                                return wac.getBean(beanName);
088:                            } catch (BeansException ex) {
089:                                throw new ELException(ex);
090:                            }
091:                        } else {
092:                            // Mimic standard JSF/JSP behavior when base is a Map by returning null.
093:                            return null;
094:                        }
095:                    }
096:                } else {
097:                    if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
098:                        elContext.setPropertyResolved(true);
099:                        return getWebApplicationContext(elContext);
100:                    }
101:                }
102:
103:                return null;
104:            }
105:
106:            public Class<?> getType(ELContext elContext, Object base,
107:                    Object property) throws ELException {
108:                if (base != null) {
109:                    if (base instanceof  WebApplicationContext) {
110:                        WebApplicationContext wac = (WebApplicationContext) base;
111:                        String beanName = property.toString();
112:                        if (logger.isDebugEnabled()) {
113:                            logger.debug("Attempting to resolve property '"
114:                                    + beanName
115:                                    + "' in root WebApplicationContext");
116:                        }
117:                        if (wac.containsBean(beanName)) {
118:                            if (logger.isDebugEnabled()) {
119:                                logger.debug("Successfully resolved property '"
120:                                        + beanName
121:                                        + "' in root WebApplicationContext");
122:                            }
123:                            elContext.setPropertyResolved(true);
124:                            try {
125:                                return wac.getType(beanName);
126:                            } catch (BeansException ex) {
127:                                throw new ELException(ex);
128:                            }
129:                        } else {
130:                            // Mimic standard JSF/JSP behavior when base is a Map by returning null.
131:                            return null;
132:                        }
133:                    }
134:                } else {
135:                    if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
136:                        elContext.setPropertyResolved(true);
137:                        return WebApplicationContext.class;
138:                    }
139:                }
140:
141:                return null;
142:            }
143:
144:            public void setValue(ELContext elContext, Object base,
145:                    Object property, Object value) throws ELException {
146:            }
147:
148:            public boolean isReadOnly(ELContext elContext, Object base,
149:                    Object property) throws ELException {
150:                if (base instanceof  WebApplicationContext) {
151:                    elContext.setPropertyResolved(true);
152:                    return false;
153:                }
154:                return false;
155:            }
156:
157:            public Iterator<FeatureDescriptor> getFeatureDescriptors(
158:                    ELContext elContext, Object base) {
159:                return null;
160:            }
161:
162:            public Class<?> getCommonPropertyType(ELContext elContext,
163:                    Object base) {
164:                return Object.class;
165:            }
166:
167:            /**
168:             * Retrieve the WebApplicationContext reference to expose.
169:             * <p>The default implementation delegates to FacesContextUtils,
170:             * returning <code>null</code> if no WebApplicationContext found.
171:             * @param elContext the current JSF ELContext
172:             * @return the Spring web application context
173:             * @see org.springframework.web.jsf.FacesContextUtils#getWebApplicationContext
174:             */
175:            protected WebApplicationContext getWebApplicationContext(
176:                    ELContext elContext) {
177:                FacesContext facesContext = FacesContext.getCurrentInstance();
178:                return FacesContextUtils
179:                        .getRequiredWebApplicationContext(facesContext);
180:            }
181:
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.