KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > el > ELAdaptor


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.el;
16
17 import java.util.Map JavaDoc;
18
19 import javax.el.ELContext;
20 import javax.el.ExpressionFactory;
21 import javax.el.ValueExpression;
22 import javax.faces.component.UIComponent;
23 import javax.faces.context.FacesContext;
24
25 import com.sun.facelets.util.FacesAPI;
26
27 /**
28  *
29  *
30  * @author Jacob Hookom
31  * @version $Id: ELAdaptor.java,v 1.8 2006/03/29 04:10:10 jhook Exp $
32  */

33 public final class ELAdaptor {
34
35     private static final boolean ELSUPPORT = (FacesAPI.getVersion() >= 12);
36
37     private final static String JavaDoc LEGACY_ELCONTEXT_KEY = "com.sun.facelets.legacy.ELCONTEXT";
38
39     public ELAdaptor() {
40         super();
41     }
42
43     public final static ELContext getELContext(FacesContext faces) {
44         if (ELSUPPORT) {
45             return faces.getELContext();
46         } else {
47             Map JavaDoc request = faces.getExternalContext().getRequestMap();
48             Object JavaDoc ctx = request.get(LEGACY_ELCONTEXT_KEY);
49             if (!(ctx instanceof LegacyELContext)
50                     || (((LegacyELContext) ctx).getFacesContext() != faces)) {
51                 ctx = new LegacyELContext(faces);
52                 request.put(LEGACY_ELCONTEXT_KEY, ctx);
53             }
54             return (ELContext) ctx;
55         }
56     }
57
58     public final static void setExpression(UIComponent c, String JavaDoc name,
59             ValueExpression ve) {
60         if (FacesAPI.getComponentVersion(c) >= 12) {
61             c.setValueExpression(name, ve);
62         } else {
63             c.setValueBinding(name, new LegacyValueBinding(ve));
64         }
65     }
66
67 }
68
Popular Tags