1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.bridges.jsf.myfaces;
16  
17  import javax.faces.FacesException;
18  import javax.faces.context.FacesContext;
19  import javax.faces.context.FacesContextFactory;
20  import javax.faces.lifecycle.Lifecycle;
21  
22  import javax.portlet.PortletContext;
23  import javax.portlet.PortletRequest;
24  import javax.portlet.PortletResponse;
25  
26  import javax.servlet.ServletContext;
27  import javax.servlet.ServletRequest;
28  import javax.servlet.ServletResponse;
29  
30  import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
31  
32  /**
33   * <a href="MyFacesContextFactoryImpl.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Brian Myunghun Kim
36   */
37  public class MyFacesContextFactoryImpl extends FacesContextFactory {
38  
39      public FacesContext getFacesContext(
40              Object context, Object request, Object response,
41              Lifecycle lifecycle)
42          throws FacesException {
43  
44          if (context == null) {
45              throw new NullPointerException("context");
46          }
47  
48          if (request == null) {
49              throw new NullPointerException("request");
50          }
51  
52          if (response == null) {
53              throw new NullPointerException("response");
54          }
55  
56          if (lifecycle == null) {
57              throw new NullPointerException("lifecycle");
58          }
59  
60          if (context instanceof ServletContext) {
61              return new ServletFacesContextImpl(
62                  (ServletContext)context,
63                  (ServletRequest)request,
64                  (ServletResponse)response);
65          }
66  
67          if (context instanceof PortletContext) {
68              return new MyFacesContextImpl(
69                  (PortletContext)context, (PortletRequest)request,
70                  (PortletResponse)response);
71          }
72  
73          throw new FacesException(
74              "Unsupported context type " + getClass().getName());
75      }
76  
77  }