1 16 17 package org.apache.struts.faces.application; 18 19 20 import java.util.Map ; 21 22 import javax.faces.el.PropertyNotFoundException; 23 import javax.faces.el.PropertyResolver; 24 25 import org.apache.commons.beanutils.DynaBean; 26 import org.apache.commons.beanutils.DynaProperty; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.apache.struts.action.DynaActionForm; 30 31 32 33 77 78 public class PropertyResolverImpl extends PropertyResolver { 79 80 81 83 84 95 public PropertyResolverImpl(PropertyResolver resolver) { 96 97 if (resolver == null) { 98 throw new NullPointerException (); 99 } 100 if (log.isDebugEnabled()) { 101 log.debug("Creating new instance, wrapping resolver " + 102 resolver); 103 } 104 this.resolver = resolver; 105 106 } 107 108 109 111 112 115 private static final Log log = 116 LogFactory.getLog(PropertyResolverImpl.class); 117 118 119 124 private PropertyResolver resolver = null; 125 126 127 129 130 142 public Object getValue(Object base, Object name) 143 throws PropertyNotFoundException { 144 145 if ((base == null) || (name == null)) { 146 throw new NullPointerException (); 147 } else if ((base instanceof DynaActionForm) && 148 ("map".equals(name))) { 149 if (log.isTraceEnabled()) { 150 log.trace("Returning property map for DynaActionForm " + base 151 + "'"); 152 } 153 return (((DynaActionForm) base).getMap()); 154 } else if (base instanceof DynaBean) { 155 if (getDynaProperty((DynaBean) base, name.toString()) == null) { 156 throw new PropertyNotFoundException(name.toString()); 157 } 158 Object value = ((DynaBean) base).get(name.toString()); 159 if (log.isTraceEnabled()) { 160 log.trace("Returning dynamic property '" + name + 161 "' for DynaBean '" + base + "' value '" + 162 value + "'"); 163 } 164 return (value); 165 } else { 166 Object value = resolver.getValue(base, name); 167 if (log.isTraceEnabled()) { 168 log.trace("Delegating get of property '" + name + 169 "' for bean '" + base + "' value '" + 170 value + "'"); 171 } 172 return (value); 173 } 174 175 } 176 177 178 191 public Object getValue(Object base, int index) 192 throws PropertyNotFoundException { 193 194 return (resolver.getValue(base, index)); 195 196 } 197 198 199 212 public void setValue(Object base, Object name, Object value) 213 throws PropertyNotFoundException { 214 215 if ((base == null) || (name == null)) { 216 throw new NullPointerException (); 217 } else if ((base instanceof DynaActionForm) && 218 ("map".equals(name))) { 219 throw new PropertyNotFoundException(name.toString()); 220 } else if (base instanceof DynaBean) { 221 if (log.isTraceEnabled()) { 222 log.trace("setting dynamic property '" + name + 223 "' for DynaBean '" + base + 224 "' to '" + value + "'"); 225 } 226 if (getDynaProperty((DynaBean) base, name.toString()) == null) { 227 throw new PropertyNotFoundException(name.toString()); 228 } 229 ((DynaBean) base).set(name.toString(), value); 230 } else { 231 if (log.isTraceEnabled()) { 232 log.trace("Delegating set of property '" + name + 233 "' for bean '" + base + "' to value '" + 234 value + "'"); 235 } 236 resolver.setValue(base, name, value); 237 } 238 239 } 240 241 242 256 public void setValue(Object base, int index, Object value) 257 throws PropertyNotFoundException { 258 259 resolver.setValue(base, index, value); 260 261 } 262 263 264 277 public boolean isReadOnly(Object base, Object name) 278 throws PropertyNotFoundException { 279 280 if ((base == null) || (name == null)) { 281 throw new NullPointerException (); 282 } else if ((base instanceof DynaActionForm) && 283 ("map".equals(name))) { 284 return (true); 285 } else if (base instanceof DynaBean) { 286 if (getDynaProperty((DynaBean) base, name.toString()) == null) { 287 throw new PropertyNotFoundException(name.toString()); 288 } 289 return (false); 290 } else { 291 return (resolver.isReadOnly(base, name.toString())); 292 } 293 294 } 295 296 297 311 public boolean isReadOnly(Object base, int index) 312 throws PropertyNotFoundException { 313 314 return (resolver.isReadOnly(base, index)); 315 316 } 317 318 319 332 public Class getType(Object base, Object name) 333 throws PropertyNotFoundException { 334 335 if ((base == null) || (name == null)) { 336 throw new NullPointerException (); 337 } else if ((base instanceof DynaActionForm) && 338 ("map".equals(name))) { 339 return (Map .class); 340 } else if (base instanceof DynaBean) { 341 DynaProperty dynaProperty = 342 getDynaProperty((DynaBean) base, name.toString()); 343 if (dynaProperty != null) { 344 return (dynaProperty.getType()); 345 } else { 346 throw new PropertyNotFoundException(name.toString()); 347 } 348 } else { 349 return (resolver.getType(base, name)); 350 } 351 } 352 353 354 368 public Class getType(Object base, int index) 369 throws PropertyNotFoundException { 370 371 return (resolver.getType(base, index)); 372 373 } 374 375 376 378 379 388 private DynaProperty getDynaProperty(DynaBean bean, String name) 389 throws PropertyNotFoundException { 390 391 DynaProperty dynaProperty = null; 392 try { 393 dynaProperty = bean.getDynaClass().getDynaProperty(name); 394 } catch (IllegalArgumentException e) { 395 ; 396 } 397 return (dynaProperty); 398 399 } 400 401 402 403 404 } 405 | Popular Tags |