001
014
015 package com.liferay.util.bridges.jsf.myfaces;
016
017 import javax.faces.FacesException;
018 import javax.faces.context.FacesContext;
019 import javax.faces.context.FacesContextFactory;
020 import javax.faces.lifecycle.Lifecycle;
021
022 import javax.portlet.PortletContext;
023 import javax.portlet.PortletRequest;
024 import javax.portlet.PortletResponse;
025
026 import javax.servlet.ServletContext;
027 import javax.servlet.ServletRequest;
028 import javax.servlet.ServletResponse;
029
030 import org.apache.myfaces.context.servlet.ServletFacesContextImpl;
031
032
035 public class MyFacesContextFactoryImpl extends FacesContextFactory {
036
037 public FacesContext getFacesContext(
038 Object context, Object request, Object response,
039 Lifecycle lifecycle)
040 throws FacesException {
041
042 if (context == null) {
043 throw new NullPointerException("context");
044 }
045
046 if (request == null) {
047 throw new NullPointerException("request");
048 }
049
050 if (response == null) {
051 throw new NullPointerException("response");
052 }
053
054 if (lifecycle == null) {
055 throw new NullPointerException("lifecycle");
056 }
057
058 if (context instanceof ServletContext) {
059 return new ServletFacesContextImpl(
060 (ServletContext)context,
061 (ServletRequest)request,
062 (ServletResponse)response);
063 }
064
065 if (context instanceof PortletContext) {
066 return new MyFacesContextImpl(
067 (PortletContext)context, (PortletRequest)request,
068 (PortletResponse)response);
069 }
070
071 throw new FacesException(
072 "Unsupported context type " + getClass().getName());
073 }
074
075 }