1 29 30 package com.caucho.el; 31 32 import com.caucho.loader.EnvironmentClassLoader; 33 import com.caucho.loader.EnvironmentLocal; 34 35 import javax.el.ELContext; 36 import javax.el.ELResolver; 37 import java.beans.FeatureDescriptor ; 38 import java.util.Iterator ; 39 40 43 public class EnvironmentLevelELResolver extends ELResolver { 44 private static final EnvironmentLocal<EnvironmentLevelELResolver> _local 45 = new EnvironmentLocal<EnvironmentLevelELResolver>(); 46 47 private final ClassLoader _loader; 48 49 private EnvironmentLevelELResolver(ClassLoader loader) 50 { 51 _loader = loader; 52 } 53 54 57 public static EnvironmentLevelELResolver create() 58 { 59 return create(Thread.currentThread().getContextClassLoader()); 60 } 61 62 65 public static EnvironmentLevelELResolver create(ClassLoader loader) 66 { 67 EnvironmentLevelELResolver elResolver = _local.getLevel(loader); 68 69 if (elResolver == null) { 70 for (; loader != null; loader = loader.getParent()) { 71 if (loader instanceof EnvironmentClassLoader) { 72 elResolver = new EnvironmentLevelELResolver(loader); 73 _local.set(elResolver, loader); 74 75 return elResolver; 76 } 77 } 78 79 loader = ClassLoader.getSystemClassLoader(); 80 elResolver = new EnvironmentLevelELResolver(loader); 81 _local.set(elResolver, loader); 82 } 83 84 return elResolver; 85 } 86 87 90 @Override 91 public boolean isReadOnly(ELContext context, Object base, Object property) 92 { 93 if (property != null || ! (base instanceof String )) 94 return true; 95 96 context.setPropertyResolved(true); 97 98 return false; 99 } 100 101 104 @Override 105 public Class <?> getType(ELContext context, 106 Object base, 107 Object property) 108 { 109 Object value = getValue(context, base, property); 110 111 if (value != null) 112 return value.getClass(); 113 else 114 return null; 115 } 116 117 public Class <?> getCommonPropertyType(ELContext context, 118 Object base) 119 { 120 return null; 121 } 122 123 public Iterator <FeatureDescriptor > 124 getFeatureDescriptors(ELContext context, Object base) 125 { 126 return null; 127 } 128 129 132 @Override 133 public Object getValue(ELContext env, 134 Object base, 135 Object property) 136 { 137 if (base != null) 138 return null; 139 else if (! (property instanceof String )) 140 return null; 141 142 String var = (String ) property; 143 144 Object value = EL.getLevelVar(var, _loader); 145 146 if (value == null) 147 return null; 148 149 env.setPropertyResolved(true); 150 151 if (value == EL.NULL) 152 return null; 153 else 154 return value; 155 } 156 157 160 @Override 161 public void setValue(ELContext env, 162 Object base, 163 Object property, 164 Object value) 165 { 166 if (base != null || ! (property instanceof String )) 167 return; 168 169 env.setPropertyResolved(true); 170 171 String name = (String ) property; 172 173 EL.putVar(name, value, _loader); 174 } 175 176 public String toString() 177 { 178 return "EnvironmentLevelELResolver[" + _loader + "]"; 179 } 180 } 181 | Popular Tags |