1 16 package org.apache.cocoon.faces.context; 17 18 import org.apache.cocoon.environment.Context; 19 import org.apache.cocoon.environment.Request; 20 import org.apache.cocoon.environment.Response; 21 22 import javax.faces.FacesException; 23 import javax.faces.context.FacesContext; 24 import javax.faces.context.FacesContextFactory; 25 import javax.faces.lifecycle.Lifecycle; 26 27 33 public class FacesContextFactoryImpl extends FacesContextFactory { 34 private static final String FALLBACK_FACTORY = "net.sourceforge.myfaces.context.FacesContextFactoryImpl"; 36 37 private FacesContextFactory fallback; 38 39 40 public FacesContextFactoryImpl() { 41 try { 42 this.fallback = 43 (FacesContextFactory) Class.forName(FALLBACK_FACTORY).newInstance(); 44 } catch (Exception ignored) { 45 } 46 } 47 48 public FacesContext getFacesContext(Object context, 49 Object request, 50 Object response, 51 Lifecycle lifecycle) 52 throws FacesException { 53 try { 54 if (!(context instanceof Context)) { 55 throw new FacesException("Context must be instance of " + Context.class.getName()); 56 } 57 58 if (!(request instanceof Request)) { 59 throw new FacesException("Request must be instance of " + Request.class.getName()); 60 } 61 62 if (!(response instanceof Response)) { 63 throw new FacesException("Response must be instance of " + Response.class.getName()); 64 } 65 66 return new FacesContextImpl(new ExternalContextImpl((Context) context, 67 (Request) request, 68 (Response) response)); 69 } catch (FacesException e) { 70 try { 71 return this.fallback.getFacesContext(context, request, response, lifecycle); 72 } catch (Exception ignored) { 73 throw e; 74 } 75 } 76 } 77 } 78 | Popular Tags |