1 25 package jsp2_1.examples.elresolver; 26 27 import java.util.Arrays ; 28 import java.util.Iterator ; 29 import javax.el.ELContext; 30 import javax.el.ELException; 31 import javax.el.ELResolver; 32 import javax.el.PropertyNotWritableException; 33 34 54 public class ColorELResolver 55 extends ELResolver 56 { 57 public Object getValue(ELContext context, Object base, Object property) 58 throws ELException 59 { 60 if(context == null) throw new NullPointerException (); 61 62 Object result = null; 63 64 if(base == null) { 65 String propertyName = (String )property; 68 if(propertyName.equals("Color")) { 69 result = new ColorImplicitObject(); 70 context.setPropertyResolved(true); 71 } 72 } 73 else if(base instanceof ColorImplicitObject) { 74 ColorImplicitObject color = (ColorImplicitObject)base; 76 77 if(property instanceof Long ) { 78 int red = ((Long )property).intValue(); 80 result = new ColorImplicitObject.ColorR(red); 81 context.setPropertyResolved(true); 82 } 83 else { 84 String colorName = property.toString(); 85 86 if(colorName.startsWith("#")) { 87 result = ColorImplicitObject.fromHex(colorName); 89 context.setPropertyResolved(true); 90 } 91 else { 92 result = ColorImplicitObject.fromName(colorName); 94 context.setPropertyResolved(true); 95 } 96 } 97 } 98 else if(base instanceof ColorImplicitObject.ColorRGB) { 99 ColorImplicitObject.ColorRGB rgb = 100 (ColorImplicitObject.ColorRGB)base; 101 } 103 else if(base instanceof ColorImplicitObject.ColorRG) { 104 ColorImplicitObject.ColorRG rg = (ColorImplicitObject.ColorRG)base; 105 if(property instanceof Long ) { 106 int blue = ((Long )property).intValue(); 108 result = new ColorImplicitObject.ColorRGB(rg.getRed(), 109 rg.getGreen(), blue); 110 context.setPropertyResolved(true); 111 } 112 } 113 else if(base instanceof ColorImplicitObject.ColorR) { 114 ColorImplicitObject.ColorR r = (ColorImplicitObject.ColorR)base; 115 if(property instanceof Long ) { 116 int green = ((Long )property).intValue(); 118 result = new ColorImplicitObject.ColorRG(r.getRed(), green); 119 context.setPropertyResolved(true); 120 } 121 } 122 123 return result; 124 } 125 126 public Class getType(ELContext context, Object base, Object property) 127 throws ELException 128 { 129 Class result = null; 130 131 if(context == null) throw new NullPointerException (); 132 133 if(base == null) { 134 } 136 else if(base instanceof ColorImplicitObject) { 137 context.setPropertyResolved(true); 140 } 141 else if( 142 (base instanceof ColorImplicitObject.ColorR) 143 || (base instanceof ColorImplicitObject.ColorRG)) 144 { 145 if(property instanceof Long ) { 148 context.setPropertyResolved(true); 149 } 150 } 151 153 return result; 154 } 155 156 public void setValue(ELContext context, Object base, Object property, 157 Object value) 158 throws ELException 159 { 160 if(context == null) throw new NullPointerException (); 161 162 if(base == null) { 163 } 165 else if(base instanceof ColorImplicitObject) { 166 throw new PropertyNotWritableException(); 169 } 170 else if( 171 (base instanceof ColorImplicitObject.ColorR) 172 || (base instanceof ColorImplicitObject.ColorRG)) 173 { 174 if(property instanceof Long ) { 177 throw new PropertyNotWritableException(); 178 } 179 } 180 } 181 182 public boolean isReadOnly(ELContext context, Object base, 183 Object property) 184 throws ELException 185 { 186 boolean result = false; 187 188 if(context == null) throw new NullPointerException (); 189 190 if(base == null) { 191 } 193 else if(base instanceof ColorImplicitObject) { 194 result = false; 197 context.setPropertyResolved(true); 198 } 199 else if( 200 (base instanceof ColorImplicitObject.ColorR) 201 || (base instanceof ColorImplicitObject.ColorRG)) 202 { 203 if(property instanceof Long ) { 206 result = false; 207 context.setPropertyResolved(true); 208 } 209 } 210 211 return result; 212 } 213 214 public Iterator getFeatureDescriptors(ELContext context, Object base) { 215 Iterator result = null; 216 217 if(context == null) throw new NullPointerException (); 218 219 if(base == null) { 220 result = Arrays.asList(new String [] {"Color"}).iterator(); 221 } 222 else if(base instanceof ColorImplicitObject) { 223 result = ColorImplicitObject.colorNameIterator(); 225 226 } 228 else if( 229 (base instanceof ColorImplicitObject.ColorR) 230 || (base instanceof ColorImplicitObject.ColorRG) 231 || (base instanceof ColorImplicitObject.ColorRGB)) 232 { 233 result = null; 236 } 237 238 240 return result; 241 } 242 243 public Class getCommonPropertyType(ELContext context, 244 Object base) 245 { 246 Class result = null; 247 248 if(base == null) { 249 result = String .class; 252 } 253 else if(base instanceof ColorImplicitObject) { 254 result = Object .class; 256 } 257 else if(base instanceof ColorImplicitObject.ColorR) { 258 result = Long .class; 260 } 261 else if(base instanceof ColorImplicitObject.ColorRG) { 262 result = Long .class; 264 } 265 else if(base instanceof ColorImplicitObject.ColorRGB) { 266 } 269 270 return result; 271 } 272 } 273 | Popular Tags |