1 29 30 package com.caucho.el; 31 32 import com.caucho.loader.EnvironmentLocal; 33 import com.caucho.util.L10N; 34 35 import javax.el.ELContext; 36 import javax.el.ELException; 37 import java.util.HashMap ; 38 import java.util.logging.Logger ; 39 40 43 public class EL { 44 private static final Logger log = Logger.getLogger(EL.class.getName()); 45 private static final L10N L = new L10N(EL.class); 46 47 private static EnvironmentLocal<ELContext> _elEnvironment 48 = new EnvironmentLocal<ELContext>(); 49 50 private static EnvironmentLocal<HashMap <String ,Object >> _envVar 51 = new EnvironmentLocal<HashMap <String ,Object >>(); 52 53 public final static Object NULL = new Object (); 54 55 public static ELContext getEnvironment() 56 { 57 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 58 59 return getEnvironment(loader); 60 } 61 62 public static ELContext getEnvironment(ClassLoader loader) 63 { 64 ELContext context = _elEnvironment.getLevel(loader); 65 66 if (context == null) { 67 context = new EnvironmentContext(loader); 68 69 _elEnvironment.set(context, loader); 70 } 71 72 return context; 73 } 74 75 public static void setEnvironment(ELContext env) 76 { 77 _elEnvironment.set(env); 78 } 79 80 public static void setEnvironment(ELContext env, 81 ClassLoader loader) 82 { 83 _elEnvironment.set(env, loader); 84 } 85 86 89 public static void setVariableMap(HashMap <String ,Object > map, 90 ClassLoader loader) 91 { 92 _envVar.set(map, loader); 93 } 94 95 98 public static Object getLevelVar(String name, ClassLoader loader) 99 { 100 HashMap <String ,Object > varMap = _envVar.getLevel(loader); 101 102 if (varMap == null) 103 return null; 104 else 105 return varMap.get(name); 106 } 107 108 111 public static Object putVar(String name, Object value) 112 { 113 return putVar(name, value, Thread.currentThread().getContextClassLoader()); 114 } 115 116 119 public static Object putVar(String name, Object value, ClassLoader loader) 120 { 121 HashMap <String ,Object > varMap = _envVar.getLevel(loader); 122 123 if (varMap == null) { 124 varMap = new HashMap <String ,Object >(); 125 _envVar.set(varMap, loader); 126 } 127 128 return varMap.put(name, value); 129 } 130 131 public static Object evalObject(String value) 132 throws ELParseException, ELException 133 { 134 ELParser parser = new ELParser(getEnvironment(), value); 135 136 Expr expr = parser.parse(); 137 138 return expr.getValue(getEnvironment()); 139 } 140 141 public static Object evalObject(String value, ELContext env) 142 throws ELParseException, ELException 143 { 144 ELParser parser = new ELParser(getEnvironment(), value); 145 146 Expr expr = parser.parse(); 147 148 return expr.getValue(env); 149 } 150 151 public static String evalString(String value, ELContext env) 152 throws ELParseException, ELException 153 { 154 ELParser parser = new ELParser(getEnvironment(), value); 155 156 Expr expr = parser.parse(); 157 158 return expr.evalString(env); 159 } 160 } 161 | Popular Tags |