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 @Override
038 public FacesContext getFacesContext(
039 Object context, Object request, Object response,
040 Lifecycle lifecycle)
041 throws FacesException {
042
043 if (context == null) {
044 throw new NullPointerException("context");
045 }
046
047 if (request == null) {
048 throw new NullPointerException("request");
049 }
050
051 if (response == null) {
052 throw new NullPointerException("response");
053 }
054
055 if (lifecycle == null) {
056 throw new NullPointerException("lifecycle");
057 }
058
059 if (context instanceof ServletContext) {
060 return new ServletFacesContextImpl(
061 (ServletContext)context, (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 }