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.ArrayList ; 39 import java.util.Iterator ; 40 41 44 public class EnvironmentELResolver extends ELResolver { 45 private static final EnvironmentLocal<EnvironmentELResolver> _local 46 = new EnvironmentLocal<EnvironmentELResolver>(); 47 48 private ArrayList <ELResolver> _resolvers 49 = new ArrayList <ELResolver>(); 50 51 private EnvironmentELResolver(ClassLoader loader) 52 { 53 for (; loader != null; loader = loader.getParent()) { 54 if (loader instanceof EnvironmentClassLoader) { 55 EnvironmentLevelELResolver resolver 56 = EnvironmentLevelELResolver.create(loader); 57 58 if (! _resolvers.contains(resolver)) 59 _resolvers.add(resolver); 60 } 61 } 62 63 EnvironmentLevelELResolver resolver 64 = EnvironmentLevelELResolver.create(ClassLoader.getSystemClassLoader()); 65 66 if (! _resolvers.contains(resolver)) 67 _resolvers.add(resolver); 68 } 69 70 73 public static EnvironmentELResolver create() 74 { 75 return create(Thread.currentThread().getContextClassLoader()); 76 } 77 78 81 public static EnvironmentELResolver create(ClassLoader loader) 82 { 83 EnvironmentELResolver elResolver = _local.getLevel(loader); 84 85 if (elResolver == null) { 86 elResolver = new EnvironmentELResolver(loader); 87 88 _local.set(elResolver, loader); 89 } 90 91 return elResolver; 92 } 93 94 97 @Override 98 public boolean isReadOnly(ELContext context, Object base, Object property) 99 { 100 if (property != null || ! (base instanceof String )) 101 return true; 102 103 context.setPropertyResolved(true); 104 105 return false; 106 } 107 108 111 @Override 112 public Class <?> getType(ELContext context, 113 Object base, 114 Object property) 115 { 116 Object value = getValue(context, base, property); 117 118 if (value != null) 119 return value.getClass(); 120 else 121 return null; 122 } 123 124 public Class <?> getCommonPropertyType(ELContext context, 125 Object base) 126 { 127 return null; 128 } 129 130 public Iterator <FeatureDescriptor > 131 getFeatureDescriptors(ELContext context, Object base) 132 { 133 return null; 134 } 135 136 139 @Override 140 public Object getValue(ELContext context, 141 Object base, 142 Object property) 143 { 144 if (base != null) 145 return null; 146 else if (! (property instanceof String )) 147 return null; 148 149 context.setPropertyResolved(false); 150 for (int i = 0; i < _resolvers.size(); i++) { 151 Object value = _resolvers.get(i).getValue(context, base, property); 152 153 if (context.isPropertyResolved()) 154 return value; 155 } 156 157 return null; 158 } 159 160 163 @Override 164 public void setValue(ELContext context, 165 Object base, 166 Object property, 167 Object value) 168 { 169 if (base != null || ! (property instanceof String )) 170 return; 171 172 context.setPropertyResolved(false); 173 for (int i = 0; i < _resolvers.size(); i++) { 174 _resolvers.get(i).setValue(context, base, property, value); 175 176 if (context.isPropertyResolved()) { 177 return; 178 } 179 } 180 } 181 182 public String toString() 183 { 184 return "EnvironmentELResolver[]"; 185 } 186 } 187 | Popular Tags |