1 28 29 package com.caucho.el; 30 31 import javax.el.ELContext; 32 import javax.el.ELResolver; 33 import java.beans.FeatureDescriptor ; 34 import java.util.HashMap ; 35 import java.util.Iterator ; 36 import java.util.Map ; 37 38 41 public class MapVariableResolver extends ELResolver { 42 private Map <String ,Object > _map; 43 44 47 public MapVariableResolver(Map <String ,Object > map) 48 { 49 if (map == null) 50 map = new HashMap <String ,Object >(); 51 52 _map = map; 53 } 54 55 58 public MapVariableResolver() 59 { 60 this(new HashMap <String ,Object >()); 61 } 62 63 66 @Override 67 public Object getValue(ELContext context, Object base, Object property) 68 { 69 if (base != null || ! (property instanceof String )) 70 return null; 71 72 String var = (String ) property; 73 74 Object value = _map.get(var); 75 76 if (value != null) { 77 context.setPropertyResolved(true); 78 79 return value; 80 } 81 82 return null; 83 } 84 85 88 @Override 89 public void setValue(ELContext context, 90 Object base, 91 Object property, 92 Object value) 93 { 94 if (base != null || ! (property instanceof String )) 95 return; 96 97 String var = (String ) property; 98 99 context.setPropertyResolved(true); 100 101 _map.put(var, value); 102 } 103 104 107 public Object put(String var, Object value) 108 { 109 return _map.put(var, value); 110 } 111 112 115 @Override 116 public boolean isReadOnly(ELContext context, Object base, Object property) 117 { 118 if (property != null || ! (base instanceof String )) 119 return true; 120 121 context.setPropertyResolved(true); 122 123 return false; 124 } 125 126 129 @Override 130 public Class <?> getType(ELContext context, 131 Object base, 132 Object property) 133 { 134 Object value = getValue(context, base, property); 135 136 if (value != null) 137 return value.getClass(); 138 else 139 return null; 140 } 141 142 public Class <?> getCommonPropertyType(ELContext context, 143 Object base) 144 { 145 return null; 146 } 147 148 public Iterator <FeatureDescriptor > 149 getFeatureDescriptors(ELContext context, Object base) 150 { 151 return null; 152 } 153 154 157 public Map <String ,Object > getMap() 158 { 159 return _map; 160 } 161 162 165 public void setMap(Map <String ,Object > map) 166 { 167 _map = map; 168 } 169 170 public String toString() 171 { 172 return "MapVariableResolver[" + _map + "]"; 173 } 174 } 175 | Popular Tags |