1 16 17 18 package org.apache.commons.beanutils; 19 20 import java.beans.PropertyDescriptor ; 21 import java.lang.reflect.InvocationTargetException ; 22 import java.lang.reflect.Method ; 23 import java.util.Map ; 24 25 import org.apache.commons.collections.FastHashMap; 26 27 28 45 46 public class PropertyUtils { 47 48 49 51 52 56 public static final char INDEXED_DELIM = '['; 57 58 59 63 public static final char INDEXED_DELIM2 = ']'; 64 65 66 69 public static final char MAPPED_DELIM = '('; 70 71 72 75 public static final char MAPPED_DELIM2 = ')'; 76 77 78 81 public static final char NESTED_DELIM = '.'; 82 83 84 86 87 91 private static int debug = 0; 92 93 96 public static int getDebug() { 97 return (debug); 98 } 99 100 103 public static void setDebug(int newDebug) { 104 debug = newDebug; 105 } 106 107 109 110 119 public static void clearDescriptors() { 120 121 PropertyUtilsBean.getInstance().clearDescriptors(); 122 123 } 124 125 126 136 public static void copyProperties(Object dest, Object orig) 137 throws IllegalAccessException , InvocationTargetException , 138 NoSuchMethodException { 139 140 PropertyUtilsBean.getInstance().copyProperties(dest, orig); 141 } 142 143 144 152 public static Map describe(Object bean) 153 throws IllegalAccessException , InvocationTargetException , 154 NoSuchMethodException { 155 156 return (PropertyUtilsBean.getInstance().describe(bean)); 157 158 } 159 160 161 169 public static Object getIndexedProperty(Object bean, String name) 170 throws IllegalAccessException , InvocationTargetException , 171 NoSuchMethodException { 172 173 return (PropertyUtilsBean.getInstance().getIndexedProperty(bean, name)); 174 175 } 176 177 178 186 public static Object getIndexedProperty(Object bean, 187 String name, int index) 188 throws IllegalAccessException , InvocationTargetException , 189 NoSuchMethodException { 190 191 return (PropertyUtilsBean.getInstance().getIndexedProperty(bean, name, index)); 192 } 193 194 195 203 public static Object getMappedProperty(Object bean, String name) 204 throws IllegalAccessException , InvocationTargetException , 205 NoSuchMethodException { 206 207 return (PropertyUtilsBean.getInstance().getMappedProperty(bean, name)); 208 209 } 210 211 212 220 public static Object getMappedProperty(Object bean, 221 String name, String key) 222 throws IllegalAccessException , InvocationTargetException , 223 NoSuchMethodException { 224 225 return PropertyUtilsBean.getInstance().getMappedProperty(bean, name, key); 226 227 } 228 229 230 238 public static FastHashMap getMappedPropertyDescriptors(Class beanClass) { 239 240 return PropertyUtilsBean.getInstance().getMappedPropertyDescriptors(beanClass); 241 242 } 243 244 245 253 public static FastHashMap getMappedPropertyDescriptors(Object bean) { 254 255 return PropertyUtilsBean.getInstance().getMappedPropertyDescriptors(bean); 256 257 } 258 259 260 268 public static Object getNestedProperty(Object bean, String name) 269 throws IllegalAccessException , InvocationTargetException , 270 NoSuchMethodException { 271 272 return PropertyUtilsBean.getInstance().getNestedProperty(bean, name); 273 274 } 275 276 277 286 public static Object getProperty(Object bean, String name) 287 throws IllegalAccessException , InvocationTargetException , 288 NoSuchMethodException { 289 290 return (PropertyUtilsBean.getInstance().getProperty(bean, name)); 291 292 } 293 294 295 304 public static PropertyDescriptor getPropertyDescriptor(Object bean, 305 String name) 306 throws IllegalAccessException , InvocationTargetException , 307 NoSuchMethodException { 308 309 return PropertyUtilsBean.getInstance().getPropertyDescriptor(bean, name); 310 311 } 312 313 314 323 public static PropertyDescriptor [] 324 getPropertyDescriptors(Class beanClass) { 325 326 return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass); 327 328 } 329 330 331 340 public static PropertyDescriptor [] getPropertyDescriptors(Object bean) { 341 342 return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean); 343 344 } 345 346 347 355 public static Class getPropertyEditorClass(Object bean, String name) 356 throws IllegalAccessException , InvocationTargetException , 357 NoSuchMethodException { 358 359 return PropertyUtilsBean.getInstance().getPropertyEditorClass(bean, name); 360 361 } 362 363 364 373 public static Class getPropertyType(Object bean, String name) 374 throws IllegalAccessException , InvocationTargetException , 375 NoSuchMethodException { 376 377 return PropertyUtilsBean.getInstance().getPropertyType(bean, name); 378 } 379 380 381 389 public static Method getReadMethod(PropertyDescriptor descriptor) { 390 391 return (PropertyUtilsBean.getInstance().getReadMethod(descriptor)); 392 393 } 394 395 396 404 public static Object getSimpleProperty(Object bean, String name) 405 throws IllegalAccessException , InvocationTargetException , 406 NoSuchMethodException { 407 408 return PropertyUtilsBean.getInstance().getSimpleProperty(bean, name); 409 410 } 411 412 413 421 public static Method getWriteMethod(PropertyDescriptor descriptor) { 422 423 return PropertyUtilsBean.getInstance().getWriteMethod(descriptor); 424 425 } 426 427 428 438 public static boolean isReadable(Object bean, String name) { 439 440 return PropertyUtilsBean.getInstance().isReadable(bean, name); 441 } 442 443 444 454 public static boolean isWriteable(Object bean, String name) { 455 456 return PropertyUtilsBean.getInstance().isWriteable(bean, name); 457 } 458 459 460 468 public static void setIndexedProperty(Object bean, String name, 469 Object value) 470 throws IllegalAccessException , InvocationTargetException , 471 NoSuchMethodException { 472 473 PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, value); 474 475 } 476 477 478 486 public static void setIndexedProperty(Object bean, String name, 487 int index, Object value) 488 throws IllegalAccessException , InvocationTargetException , 489 NoSuchMethodException { 490 491 PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, index, value); 492 } 493 494 495 503 public static void setMappedProperty(Object bean, String name, 504 Object value) 505 throws IllegalAccessException , InvocationTargetException , 506 NoSuchMethodException { 507 508 PropertyUtilsBean.getInstance().setMappedProperty(bean, name, value); 509 } 510 511 512 520 public static void setMappedProperty(Object bean, String name, 521 String key, Object value) 522 throws IllegalAccessException , InvocationTargetException , 523 NoSuchMethodException { 524 525 PropertyUtilsBean.getInstance().setMappedProperty(bean, name, key, value); 526 } 527 528 529 537 public static void setNestedProperty(Object bean, 538 String name, Object value) 539 throws IllegalAccessException , InvocationTargetException , 540 NoSuchMethodException { 541 542 PropertyUtilsBean.getInstance().setNestedProperty(bean, name, value); 543 } 544 545 546 555 public static void setProperty(Object bean, String name, Object value) 556 throws IllegalAccessException , InvocationTargetException , 557 NoSuchMethodException { 558 559 PropertyUtilsBean.getInstance().setProperty(bean, name, value); 560 561 } 562 563 564 572 public static void setSimpleProperty(Object bean, 573 String name, Object value) 574 throws IllegalAccessException , InvocationTargetException , 575 NoSuchMethodException { 576 577 PropertyUtilsBean.getInstance().setSimpleProperty(bean, name, value); 578 } 579 580 581 } 582 | Popular Tags |