01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.faces.context;
18:
19: import org.apache.cocoon.environment.Context;
20: import org.apache.cocoon.environment.Request;
21: import org.apache.cocoon.environment.Response;
22:
23: import javax.faces.FacesException;
24: import javax.faces.context.FacesContext;
25: import javax.faces.context.FacesContextFactory;
26: import javax.faces.lifecycle.Lifecycle;
27:
28: /**
29: * JSF Context Factory Implementation
30: *
31: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
32: * @version CVS $Id: FacesContextFactoryImpl.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34: public class FacesContextFactoryImpl extends FacesContextFactory {
35: // private static final String FALLBACK_FACTORY = "com.sun.faces.context.FacesContextFactoryImpl";
36: private static final String FALLBACK_FACTORY = "net.sourceforge.myfaces.context.FacesContextFactoryImpl";
37:
38: private FacesContextFactory fallback;
39:
40: public FacesContextFactoryImpl() {
41: try {
42: this .fallback = (FacesContextFactory) Class.forName(
43: FALLBACK_FACTORY).newInstance();
44: } catch (Exception ignored) {
45: }
46: }
47:
48: public FacesContext getFacesContext(Object context, Object request,
49: Object response, Lifecycle lifecycle) throws FacesException {
50: try {
51: if (!(context instanceof Context)) {
52: throw new FacesException("Context must be instance of "
53: + Context.class.getName());
54: }
55:
56: if (!(request instanceof Request)) {
57: throw new FacesException("Request must be instance of "
58: + Request.class.getName());
59: }
60:
61: if (!(response instanceof Response)) {
62: throw new FacesException(
63: "Response must be instance of "
64: + Response.class.getName());
65: }
66:
67: return new FacesContextImpl(new ExternalContextImpl(
68: (Context) context, (Request) request,
69: (Response) response));
70: } catch (FacesException e) {
71: try {
72: return this .fallback.getFacesContext(context, request,
73: response, lifecycle);
74: } catch (Exception ignored) {
75: throw e;
76: }
77: }
78: }
79: }
|