001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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    /**
033     * @author Brian Myunghun Kim
034     */
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    }