Source Code Cross Referenced for FacesServletImpl.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » jsf » webapp » 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 » EJB Server resin 3.1.5 » resin » com.caucho.jsf.webapp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License version 2
011:         * as published by the Free Software Foundation.
012:         *
013:         * Resin Open Source is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
016:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
017:         * details.
018:         *
019:         * You should have received a copy of the GNU General Public License
020:         * along with Resin Open Source; if not, write to the
021:         *
022:         *   Free Software Foundation, Inc.
023:         *   59 Temple Place, Suite 330
024:         *   Boston, MA 02111-1307  USA
025:         *
026:         * @author Scott Ferguson
027:         */
028:
029:        package com.caucho.jsf.webapp;
030:
031:        import java.io.*;
032:        import java.lang.reflect.*;
033:        import java.net.*;
034:        import java.util.*;
035:        import java.util.logging.*;
036:
037:        import javax.faces.*;
038:        import javax.faces.application.*;
039:        import javax.faces.context.*;
040:        import javax.faces.event.*;
041:        import javax.faces.lifecycle.*;
042:        import javax.faces.webapp.*;
043:
044:        import javax.servlet.*;
045:        import javax.servlet.http.*;
046:
047:        import com.caucho.config.*;
048:        import com.caucho.jsf.application.*;
049:        import com.caucho.jsf.cfg.*;
050:        import com.caucho.vfs.*;
051:
052:        public class FacesServletImpl extends GenericServlet {
053:            private static final Logger log = Logger
054:                    .getLogger(FacesServletImpl.class.getName());
055:
056:            private static final String FACES_SCHEMA = "com/caucho/jsf/cfg/jsf.rnc";
057:
058:            private ConfigException _configException;
059:
060:            private ArrayList<PhaseListener> _phaseListenerList = new ArrayList<PhaseListener>();
061:
062:            public FacesServletImpl() {
063:            }
064:
065:            public void init(ServletConfig config) throws ServletException {
066:                Object factoryObj;
067:                String factory;
068:
069:                initFactory(FactoryFinder.APPLICATION_FACTORY,
070:                        "com.caucho.jsf.application.ApplicationFactoryImpl");
071:
072:                initFactory(FactoryFinder.LIFECYCLE_FACTORY,
073:                        "com.caucho.jsf.lifecycle.LifecycleFactoryImpl");
074:
075:                initFactory(FactoryFinder.RENDER_KIT_FACTORY,
076:                        "com.caucho.jsf.render.RenderKitFactoryImpl");
077:
078:                initFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
079:                        "com.caucho.jsf.context.FacesContextFactoryImpl");
080:
081:                ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
082:                        .getFactory(FactoryFinder.APPLICATION_FACTORY);
083:
084:                Application app = appFactory.getApplication();
085:
086:                if (app == null) {
087:                    app = new ApplicationImpl();
088:                    appFactory.setApplication(app);
089:                }
090:
091:                ClassLoader loader = Thread.currentThread()
092:                        .getContextClassLoader();
093:                try {
094:                    Enumeration e = loader
095:                            .getResources("META-INF/faces-config.xml");
096:                    while (e != null && e.hasMoreElements()) {
097:                        URL url = (URL) e.nextElement();
098:                        initPath(app, Vfs.lookup(url.toString()));
099:                    }
100:                } catch (IOException e) {
101:                    throw ConfigException.create(e);
102:                }
103:
104:                String path = config.getServletContext().getInitParameter(
105:                        FacesServlet.CONFIG_FILES_ATTR);
106:
107:                String[] paths = null;
108:
109:                if (path != null)
110:                    paths = path.split("\\s*,\\s*");
111:
112:                for (int i = 0; paths != null && i < paths.length; i++)
113:                    initPath(app, Vfs.lookup("./" + paths[i]));
114:
115:                initPath(app, Vfs.lookup("WEB-INF/faces-config.xml"));
116:
117:                if (app.getViewHandler() == null)
118:                    app.setViewHandler(new JspViewHandler());
119:
120:                if (app.getStateManager() == null)
121:                    app.setStateManager(new SessionStateManager());
122:
123:                LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
124:                        .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
125:
126:                Iterator iter = lifecycleFactory.getLifecycleIds();
127:                while (iter.hasNext()) {
128:                    Lifecycle lifecycle = lifecycleFactory
129:                            .getLifecycle((String) iter.next());
130:
131:                    for (PhaseListener listener : _phaseListenerList) {
132:                        lifecycle.addPhaseListener(listener);
133:                    }
134:                }
135:            }
136:
137:            private static void initFactory(String factoryName,
138:                    String defaultName) {
139:                Object factoryObj = null;
140:                String factory;
141:
142:                try {
143:                    factoryObj = FactoryFinder.getFactory(factoryName);
144:                } catch (FacesException e) {
145:                }
146:
147:                if (factoryObj == null) {
148:                    factory = getServiceFactory(factoryName);
149:
150:                    if (factory == null || "".equals(factory))
151:                        factory = defaultName;
152:
153:                    FactoryFinder.setFactory(factoryName, factory);
154:                }
155:            }
156:
157:            private static String getServiceFactory(String factoryName) {
158:                try {
159:                    ClassLoader loader = Thread.currentThread()
160:                            .getContextClassLoader();
161:
162:                    InputStream is = loader
163:                            .getResourceAsStream("META-INF/services/"
164:                                    + factoryName);
165:
166:                    try {
167:                        if (is != null) {
168:                            BufferedReader reader = new BufferedReader(
169:                                    new InputStreamReader(is));
170:                            String line = reader.readLine();
171:
172:                            if (line != null) {
173:                                if (line.indexOf('#') >= 0)
174:                                    line = line.substring(0, line.indexOf('#'));
175:
176:                                return line.trim();
177:                            }
178:                        }
179:                    } catch (Exception e) {
180:                        log.log(Level.WARNING, e.toString(), e);
181:                    } finally {
182:                        is.close();
183:                    }
184:                } catch (Exception e) {
185:                }
186:
187:                return null;
188:            }
189:
190:            private void initPath(Application app, Path facesPath)
191:                    throws ServletException {
192:                if (facesPath.canRead() && !facesPath.isDirectory()) {
193:                    try {
194:                        FacesConfig facesConfig = new FacesConfig();
195:
196:                        Config config = new Config();
197:
198:                        config.setEL(false);
199:
200:                        config.configure(facesConfig, facesPath, FACES_SCHEMA);
201:
202:                        if (app instanceof  ApplicationImpl) {
203:                            ApplicationImpl appImpl = (ApplicationImpl) app;
204:
205:                            // jsf/4409
206:                            NavigationHandlerImpl navigationHandler = appImpl
207:                                    .getDefaultNavigationHandler();
208:
209:                            List<NavigationRule> navigationRules = facesConfig
210:                                    .getNavigationRules();
211:
212:                            for (NavigationRule navigationRule : navigationRules) {
213:                                navigationHandler.addRule(navigationRule);
214:                            }
215:
216:                            facesConfig.configure(appImpl);
217:
218:                            facesConfig
219:                                    .configurePhaseListeners(_phaseListenerList);
220:
221:                            for (ManagedBeanConfig bean : facesConfig
222:                                    .getManagedBeans()) {
223:                                appImpl.addManagedBean(bean.getName(), bean);
224:                            }
225:
226:                            ApplicationConfig appConfig = facesConfig
227:                                    .getApplication();
228:
229:                            if (appConfig != null) {
230:                                appConfig.configure(appImpl);
231:
232:                                for (ResourceBundleConfig bundle : appConfig
233:                                        .getResourceBundleList()) {
234:                                    appImpl.addResourceBundle(bundle.getVar(),
235:                                            bundle);
236:                                }
237:                            }
238:                        }
239:                    } catch (ConfigException e) {
240:                        _configException = e;
241:
242:                        throw e;
243:                    } catch (RuntimeException e) {
244:                        throw e;
245:                    } catch (Exception e) {
246:                        throw new ServletException(e);
247:                    }
248:                }
249:            }
250:
251:            public void service(ServletRequest request, ServletResponse response)
252:                    throws IOException, ServletException {
253:                throw new UnsupportedOperationException();
254:            }
255:
256:            public void destroy() {
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.