KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > context > FacesContextFactoryImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
28  * JSF Context Factory Implementation
29  *
30  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
31  * @version CVS $Id: FacesContextFactoryImpl.java 46253 2004-09-17 14:36:29Z vgritsenko $
32  */

33 public class FacesContextFactoryImpl extends FacesContextFactory {
34     // private static final String FALLBACK_FACTORY = "com.sun.faces.context.FacesContextFactoryImpl";
35
private static final String JavaDoc 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 JavaDoc ignored) {
45         }
46     }
47
48     public FacesContext getFacesContext(Object JavaDoc context,
49                                         Object JavaDoc request,
50                                         Object JavaDoc 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 JavaDoc ignored) {
73                 throw e;
74             }
75         }
76     }
77 }
78
Popular Tags