/usr/share/doc/libcommons-beanutils-java/api/org/apache/commons/beanutils/package-summary.html is in libcommons-beanutils-java-doc 1.9.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html>
<head>
<!-- Generated by javadoc -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>org.apache.commons.beanutils (Apache Commons BeanUtils 1.9.3 API)</title>
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="org.apache.commons.beanutils (Apache Commons BeanUtils 1.9.3 API)";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">Package</li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev Package</li>
<li><a href="../../../../org/apache/commons/beanutils/converters/package-summary.html">Next Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/commons/beanutils/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h1 title="Package" class="title">Package org.apache.commons.beanutils</h1>
<div class="docSummary">
<div class="block">The <em>Bean Introspection Utilities</em> component of the Apache Commons
subproject offers low-level utility classes that assist in getting and setting
property values on Java classes that follow the naming design patterns outlined
in the JavaBeans Specification, as well as mechanisms for dynamically defining
and accessing bean properties.</div>
</div>
<p>See: <a href="#package.description">Description</a></p>
</div>
<div class="contentContainer">
<ul class="blockList">
<li class="blockList">
<table class="typeSummary" border="0" cellpadding="3" cellspacing="0" summary="Interface Summary table, listing interfaces, and an explanation">
<caption><span>Interface Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Interface</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanIntrospector.html" title="interface in org.apache.commons.beanutils">BeanIntrospector</a></td>
<td class="colLast">
<div class="block">
Definition of an interface for components that can perform introspection on
bean classes.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/Converter.html" title="interface in org.apache.commons.beanutils">Converter</a></td>
<td class="colLast">
<div class="block">General purpose data type converter that can be registered and used
within the BeanUtils package to manage the conversion of objects from
one type to another.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils">DynaBean</a></td>
<td class="colLast">
<div class="block">A <strong>DynaBean</strong> is a Java object that supports properties
whose names and data types, as well as values, may be dynamically modified.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DynaClass.html" title="interface in org.apache.commons.beanutils">DynaClass</a></td>
<td class="colLast">
<div class="block">A <strong>DynaClass</strong> is a simulation of the functionality of
<code>java.lang.Class</code> for classes implementing the
<code>DynaBean</code> interface.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/IntrospectionContext.html" title="interface in org.apache.commons.beanutils">IntrospectionContext</a></td>
<td class="colLast">
<div class="block">
A context interface used during introspection for querying and setting
property descriptors.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/MutableDynaClass.html" title="interface in org.apache.commons.beanutils">MutableDynaClass</a></td>
<td class="colLast">
<div class="block">A specialized extension to <code>DynaClass</code> that allows properties
to be added or removed dynamically.</div>
</td>
</tr>
</tbody>
</table>
</li>
<li class="blockList">
<table class="typeSummary" border="0" cellpadding="3" cellspacing="0" summary="Class Summary table, listing classes, and an explanation">
<caption><span>Class Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Class</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BaseDynaBeanMapDecorator.html" title="class in org.apache.commons.beanutils">BaseDynaBeanMapDecorator</a><K></td>
<td class="colLast">
<div class="block">A base class for decorators providing <code>Map</code> behavior on
<a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a>s.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BasicDynaBean.html" title="class in org.apache.commons.beanutils">BasicDynaBean</a></td>
<td class="colLast">
<div class="block">Minimal implementation of the <code>DynaBean</code> interface.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BasicDynaClass.html" title="class in org.apache.commons.beanutils">BasicDynaClass</a></td>
<td class="colLast">
<div class="block">Minimal implementation of the <code>DynaClass</code> interface.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanComparator.html" title="class in org.apache.commons.beanutils">BeanComparator</a><T></td>
<td class="colLast">
<div class="block">
This comparator compares two beans by the specified bean property.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanMap.html" title="class in org.apache.commons.beanutils">BeanMap</a></td>
<td class="colLast">
<div class="block">An implementation of Map for JavaBeans which uses introspection to
get and put properties in the bean.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanMap.Entry.html" title="class in org.apache.commons.beanutils">BeanMap.Entry</a></td>
<td class="colLast">
<div class="block">Map entry used by <a href="../../../../org/apache/commons/beanutils/BeanMap.html" title="class in org.apache.commons.beanutils"><code>BeanMap</code></a>.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanPredicate.html" title="class in org.apache.commons.beanutils">BeanPredicate</a></td>
<td class="colLast">
<div class="block">Predicate implementation that applies the given <code>Predicate</code>
to the result of calling the given property getter.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanPropertyValueChangeClosure.html" title="class in org.apache.commons.beanutils">BeanPropertyValueChangeClosure</a></td>
<td class="colLast">
<div class="block"><code>Closure</code> that sets a property.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanPropertyValueEqualsPredicate.html" title="class in org.apache.commons.beanutils">BeanPropertyValueEqualsPredicate</a></td>
<td class="colLast">
<div class="block"><code>Predicate</code> that evaluates a property value against a specified value.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanToPropertyValueTransformer.html" title="class in org.apache.commons.beanutils">BeanToPropertyValueTransformer</a></td>
<td class="colLast">
<div class="block"><code>Transformer</code> that outputs a property value.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanUtils.html" title="class in org.apache.commons.beanutils">BeanUtils</a></td>
<td class="colLast">
<div class="block">Utility methods for populating JavaBeans properties via reflection.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanUtilsBean.html" title="class in org.apache.commons.beanutils">BeanUtilsBean</a></td>
<td class="colLast">
<div class="block">JavaBean property population methods.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanUtilsBean2.html" title="class in org.apache.commons.beanutils">BeanUtilsBean2</a></td>
<td class="colLast">
<div class="block"><a href="../../../../org/apache/commons/beanutils/BeanUtilsBean.html" title="class in org.apache.commons.beanutils"><code>BeanUtilsBean</code></a> implementation that creates a
<a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean2.html" title="class in org.apache.commons.beanutils"><code>ConvertUtilsBean2</code></a> and delegates conversion to
<a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean.html#convert-java.lang.Object-java.lang.Class-"><code>ConvertUtilsBean.convert(Object, Class)</code></a>.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConstructorUtils.html" title="class in org.apache.commons.beanutils">ConstructorUtils</a></td>
<td class="colLast">
<div class="block"> Utility reflection methods focussed on constructors, modelled after <a href="../../../../org/apache/commons/beanutils/MethodUtils.html" title="class in org.apache.commons.beanutils"><code>MethodUtils</code></a>.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ContextClassLoaderLocal.html" title="class in org.apache.commons.beanutils">ContextClassLoaderLocal</a><T></td>
<td class="colLast">
<div class="block">An instance of this class represents a value that is provided per (thread)
context classloader.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConvertingWrapDynaBean.html" title="class in org.apache.commons.beanutils">ConvertingWrapDynaBean</a></td>
<td class="colLast">
<div class="block">Implementation of <code>DynaBean</code> that wraps a standard JavaBean
instance, so that DynaBean APIs can be used to access its properties,
though this implementation allows type conversion to occur when properties are set.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConvertUtils.html" title="class in org.apache.commons.beanutils">ConvertUtils</a></td>
<td class="colLast">
<div class="block">Utility methods for converting String scalar values to objects of the
specified Class, String arrays to arrays of the specified Class.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean.html" title="class in org.apache.commons.beanutils">ConvertUtilsBean</a></td>
<td class="colLast">
<div class="block">Utility methods for converting String scalar values to objects of the
specified Class, String arrays to arrays of the specified Class.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean2.html" title="class in org.apache.commons.beanutils">ConvertUtilsBean2</a></td>
<td class="colLast">
<div class="block"><a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean.html" title="class in org.apache.commons.beanutils"><code>ConvertUtilsBean</code></a> implementation that delegates <code>convert()</code>
methods to the new <a href="../../../../org/apache/commons/beanutils/ConvertUtilsBean.html#convert-java.lang.Object-java.lang.Class-"><code>ConvertUtilsBean.convert(Object, Class)</code></a> method.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DefaultBeanIntrospector.html" title="class in org.apache.commons.beanutils">DefaultBeanIntrospector</a></td>
<td class="colLast">
<div class="block">
The default <a href="../../../../org/apache/commons/beanutils/BeanIntrospector.html" title="interface in org.apache.commons.beanutils"><code>BeanIntrospector</code></a> implementation.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DynaBeanMapDecorator.html" title="class in org.apache.commons.beanutils">DynaBeanMapDecorator</a></td>
<td class="colLast">Deprecated
<div class="block"><span class="deprecationComment">Use <a href="../../../../org/apache/commons/beanutils/DynaBeanPropertyMapDecorator.html" title="class in org.apache.commons.beanutils"><code>DynaBeanPropertyMapDecorator</code></a> instead.</span></div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DynaBeanPropertyMapDecorator.html" title="class in org.apache.commons.beanutils">DynaBeanPropertyMapDecorator</a></td>
<td class="colLast">
<div class="block">Decorates a <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a> to provide <code>Map</code> behavior.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/DynaProperty.html" title="class in org.apache.commons.beanutils">DynaProperty</a></td>
<td class="colLast">
<div class="block">The metadata describing an individual property of a DynaBean.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/FluentPropertyBeanIntrospector.html" title="class in org.apache.commons.beanutils">FluentPropertyBeanIntrospector</a></td>
<td class="colLast">
<div class="block">
An implementation of the <code>BeanIntrospector</code> interface which can
detect write methods for properties used in fluent API scenario.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/LazyDynaBean.html" title="class in org.apache.commons.beanutils">LazyDynaBean</a></td>
<td class="colLast">
<div class="block">DynaBean which automatically adds properties to the <code>DynaClass</code>
and provides <i>Lazy List</i> and <i>Lazy Map</i> features.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/LazyDynaClass.html" title="class in org.apache.commons.beanutils">LazyDynaClass</a></td>
<td class="colLast">
<div class="block">DynaClass which implements the <code>MutableDynaClass</code> interface.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/LazyDynaList.html" title="class in org.apache.commons.beanutils">LazyDynaList</a></td>
<td class="colLast">
<div class="block"><i>Lazy</i> DynaBean List.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/LazyDynaMap.html" title="class in org.apache.commons.beanutils">LazyDynaMap</a></td>
<td class="colLast">
<div class="block">Provides a <i>light weight</i> <code>DynaBean</code> facade to a <code>Map</code>
with <i>lazy</i> map/list processing.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/MappedPropertyDescriptor.html" title="class in org.apache.commons.beanutils">MappedPropertyDescriptor</a></td>
<td class="colLast">
<div class="block">A MappedPropertyDescriptor describes one mapped property.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/MethodUtils.html" title="class in org.apache.commons.beanutils">MethodUtils</a></td>
<td class="colLast">
<div class="block"> Utility reflection methods focused on methods in general rather than properties in particular.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/PropertyUtils.html" title="class in org.apache.commons.beanutils">PropertyUtils</a></td>
<td class="colLast">
<div class="block">Utility methods for using Java Reflection APIs to facilitate generic
property getter and setter operations on Java objects.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/PropertyUtilsBean.html" title="class in org.apache.commons.beanutils">PropertyUtilsBean</a></td>
<td class="colLast">
<div class="block">Utility methods for using Java Reflection APIs to facilitate generic
property getter and setter operations on Java objects.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ResultSetDynaClass.html" title="class in org.apache.commons.beanutils">ResultSetDynaClass</a></td>
<td class="colLast">
<div class="block">Implementation of <code>DynaClass</code> for DynaBeans that wrap the
<code>java.sql.Row</code> objects of a <code>java.sql.ResultSet</code>.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ResultSetIterator.html" title="class in org.apache.commons.beanutils">ResultSetIterator</a></td>
<td class="colLast">
<div class="block">Implementation of <code>java.util.Iterator</code> returned by the
<code>iterator()</code> method of <a href="../../../../org/apache/commons/beanutils/ResultSetDynaClass.html" title="class in org.apache.commons.beanutils"><code>ResultSetDynaClass</code></a>.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/RowSetDynaClass.html" title="class in org.apache.commons.beanutils">RowSetDynaClass</a></td>
<td class="colLast">
<div class="block">Implementation of <a href="../../../../org/apache/commons/beanutils/DynaClass.html" title="interface in org.apache.commons.beanutils"><code>DynaClass</code></a> that creates an in-memory collection
of <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a>s representing the results of an SQL query.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/SuppressPropertiesBeanIntrospector.html" title="class in org.apache.commons.beanutils">SuppressPropertiesBeanIntrospector</a></td>
<td class="colLast">
<div class="block">
A specialized <code>BeanIntrospector</code> implementation which suppresses some properties.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/WrapDynaBean.html" title="class in org.apache.commons.beanutils">WrapDynaBean</a></td>
<td class="colLast">
<div class="block">Implementation of <code>DynaBean</code> that wraps a standard JavaBean
instance, so that DynaBean APIs can be used to access its properties.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/WrapDynaClass.html" title="class in org.apache.commons.beanutils">WrapDynaClass</a></td>
<td class="colLast">
<div class="block">Implementation of <code>DynaClass</code> for DynaBeans that wrap
standard JavaBean instances.</div>
</td>
</tr>
</tbody>
</table>
</li>
<li class="blockList">
<table class="typeSummary" border="0" cellpadding="3" cellspacing="0" summary="Exception Summary table, listing exceptions, and an explanation">
<caption><span>Exception Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Exception</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/BeanAccessLanguageException.html" title="class in org.apache.commons.beanutils">BeanAccessLanguageException</a></td>
<td class="colLast">
<div class="block">Thrown to indicate that the <em>Bean Access Language</em> cannot execute query
against given bean.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/ConversionException.html" title="class in org.apache.commons.beanutils">ConversionException</a></td>
<td class="colLast">
<div class="block">A <strong>ConversionException</strong> indicates that a call to
<code>Converter.convert()</code> has failed to complete successfully.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/apache/commons/beanutils/NestedNullException.html" title="class in org.apache.commons.beanutils">NestedNullException</a></td>
<td class="colLast">
<div class="block">Thrown to indicate that the <em>Bean Access Language</em> cannot execute query
against given bean since a nested bean referenced is null.</div>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<a name="package.description">
<!-- -->
</a>
<h2 title="Package org.apache.commons.beanutils Description">Package org.apache.commons.beanutils Description</h2>
<div class="block"><p>The <em>Bean Introspection Utilities</em> component of the Apache Commons
subproject offers low-level utility classes that assist in getting and setting
property values on Java classes that follow the naming design patterns outlined
in the JavaBeans Specification, as well as mechanisms for dynamically defining
and accessing bean properties.</p>
<h1>Table of Contents</h1>
<ul>
<li>1. <a href="#overview">Overview</a>
<ul>
<li>1.1 <a href="#overview.background">Background</a></li>
<li>1.2 <a href="#overview.dependencies">External Dependencies</a></li>
</ul>
</li>
<li>2. <a href="#standard">Standard JavaBeans</a>
<ul>
<li>2.1 <a href="#standard.background">Background</a></li>
<li>2.2 <a href="#standard.basic">Basic Property Access</a></li>
<li>2.3 <a href="#standard.nested">Nested Property Access</a></li>
<li>2.4 <a href="#standard.customize">Customizing Introspection</a></li>
<li>2.5 <a href="#standard.suppress">Suppressing Properties</a></li>
</ul>
</li>
<li>3. <a href="#dynamic">Dynamic Beans (DynaBeans)</a>
<ul>
<li>3.1 <a href="#dynamic.background">Background</a></li>
<li>3.2 <a href="#dynamic.basic">BasicDynaBean and BasicDynaClass</a></li>
<li>3.3 <a href="#dynamic.resultSet">ResultSetDynaClass (Wraps ResultSet in DynaBeans)</a></li>
<li>3.4 <a href="#dynamic.rowSet">RowSetDynaClass (Disconnected ResultSet as DynaBeans)</a></li>
<li>3.5 <a href="#dynamic.wrap">WrapDynaBean and WrapDynaClass</a></li>
<li>3.6 <a href="#dynamic.lazy"><i>Lazy</i> DynaBeans</a></li>
</ul>
</li>
<li>4. <a href="#conversion">Data Type Conversions</a>
<ul>
<li>4.1 <a href="#conversion.background">Background</a></li>
<li>4.2 <a href="#conversion.beanutils">BeanUtils and ConvertUtils
Conversions</a></li>
<li>4.3 <a href="#conversion.defining">Defining Your Own Converters</a></li>
<li>4.4 <a href="#conversion.i18n">Locale Aware Conversions</a></li>
</ul>
</li>
<li>5. <a href="#instances">Utility Objects And Static Utility Classes</a></li>
<li>6. <a href="#collections">Collections</a>
<ul>
<li>6.1 <a href="#bean-comparator">Comparing Beans</a></li>
<li>6.2 <a href="#bean-property-closure">Operating On Collections Of Beans</a></li>
<li>6.3 <a href="#bean-property-predicate">Querying Or Filtering Collections Of Beans</a></li>
<li>6.4 <a href="#bean-property-transformer">Transforming Collections Of Beans</a></li>
</ul></li>
<li>7. <a href="#FAQ">Frequently Asked Questions</a>
<ul>
<li><a href="#FAQ.property">Why Can't BeanUtils Find My Method?</a></li>
<li><a href="#FAQ.bc.order">How Do I Set The BeanComparator Order To Be Ascending/Descending?</a></li>
</ul></li>
</ul>
<a name="overview"></a>
<h1>1. Overview</h1>
<a name="overview.background"></a>
<h2>1.1 Background</h2>
<p>The <em>JavaBeans</em> name comes from a
<a href="http://java.sun.com/products/javabeans/">Java API</a>
for a component architecture for the Java language. Writing Java classes that
conform to the JavaBeans design patterns makes it easier for Java developers
to understand the functionality provided by your class, as well as allowing
JavaBeans-aware tools to use Java's <em>introspection</em> capabilities to
learn about the properties and operations provided by your class, and present
them in a visually appealing manner in development tools.</p>
<p>The <a href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBeans
Specification</a> describes the complete set of characteristics that makes
an arbitrary Java class a JavaBean or not -- and you should consider reading
this document to be an important part of developing your Java programming
skills. However, the required characteristics of JavaBeans that are
important for most development scenarios are listed here:</p>
<ul>
<li>The class must be <strong>public</strong>, and provide a
<strong>public</strong> constructor that accepts no arguments. This allows
tools and applications to dynamically create new instances of your bean,
without necessarily knowing what Java class name will be used ahead of
time, like this:
<pre>
String className = ...;
Class beanClass = Class.forName(className);
Object beanInstance = beanClass.newInstance();
</pre></li>
<li>As a necessary consequence of having a no-arguments constructor,
configuration of your bean's behavior must be accomplished separately
from its instantiation. This is typically done by defining a set of
<em>properties</em> of your bean, which can be used to modify its behavior
or the data that the bean represents. The normal convention for
property names is that they start with a lower case letter, and be
comprised only of characters that are legal in a Java identifier.</li>
<li>Typically, each bean property will have a public <em>getter</em> and
<em>setter</em> method that are used to retrieve or define the property's
value, respectively. The JavaBeans Specification defines a design
pattern for these names, using <code>get</code> or <code>set</code> as the
prefix for the property name with it's first character capitalized. Thus,
you a JavaBean representing an employee might have
(among others) properties named <code>firstName</code>,
<code>lastName</code>, and <code>hireDate</code>, with method signatures
like this:
<pre>
public class Employee {
public Employee(); // Zero-arguments constructor
public String getFirstName();
public void setFirstName(String firstName);
public String getLastName();
public void setLastName(String lastName);
public Date getHireDate();
public void setHireDate(Date hireDate);
public boolean isManager();
public void setManager(boolean manager);
public String getFullName();
}
</pre></li>
<li>As you can see from the above example, there is a special variant allowed
for boolean properties -- you can name the <em>getter</em> method with a
<code>is</code> prefix instead of a <code>get</code> prefix if that makes
for a more understandable method name.</li>
<li>If you have both a <em>getter</em> and a <em>setter</em> method for a
property, the data type returned by the <em>getter</em> must match the
data type accepted by the <em>setter</em>. In addition, it is contrary
to the JavaBeans specification to have more than one <em>setter</em>
with the same name, but different property types.</li>
<li>It is not required that you provide a <em>getter</em> and a
<em>setter</em> for every property. In the example above, the
<code>fullName</code> property is read-only, because there is no
<em>setter</em> method. It is also possible, but less common, to provide
write-only properties.</li>
<li>It is also possible to create a JavaBean where the <em>getter</em> and
<em>setter</em> methods do not match the naming pattern described above.
The standard JavaBeans support classes in the Java language, as well as
all classes in the BeanUtils package, allow you to describe the actual
property method names in a <code>BeanInfo</code> class associated with
your bean class. See the JavaBeans Specification for full details.</li>
<li>The JavaBeans Specification also describes many additional design patterns
for event listeners, wiring JavaBeans together into component hierarchies,
and other useful features that are beyond the scope of the BeanUtils
package.</li>
</ul>
<p>Using standard Java coding techniques, it is very easy to deal with
JavaBeans if you know ahead of time which bean classes you will be using, and
which properties you are interested in:</p>
<pre>
Employee employee = ...;
System.out.println("Hello " + employee.getFirstName() + "!");
</pre>
<a name="overview.dependencies"></a>
<h2>1.2 External Dependencies</h2>
<p>The <em>commons-beanutils</em> package requires that the following
additional packages be available in the application's class path at runtime:
</p>
<ul>
<li><a href="http://commons.apache.org/downloads/download_logging.cgi">
Logging Package (Apache Commons)</a>, version 1.0 or later</li>
<li><a href="http://commons.apache.org/downloads/download_collections.cgi">
Collections Package (Apache Commons)</a>, version 1.0 or later</li>
</ul>
<a name="standard"></a>
<h1>2. Standard JavaBeans</h1>
<a name="standard.background"></a>
<h2>2.1 Background</h2>
<p>As described above, the standard facilities of the Java programming language
make it easy and natural to access the property values of your beans using
calls to the appropriate getter methods.
But what happens in more sophisticated environments where you do not
necessarily know ahead of time which bean class you are going to be using,
or which property you want to retrieve or modify? The Java language provides
classes like <code>java.beans.Introspector</code>, which can examine a Java
class at runtime and identify for you the names of the property getter and
setter methods, plus the <em>Reflection</em> capabilities to dynamically call
such a method. However, these APIs can be difficult to use, and expose the
application developer to many unnecessary details of the underlying structure
of Java classes. The APIs in the BeanUtils package are intended to simplify
getting and setting bean properties dynamically, where the objects you are
accessing -- and the names of the properties you care about -- are determined
at runtime in your application, rather than as you are writing and compiling
your application's classes.</p>
<p>This is the set of needs that are satisfied by the static methods of the
<a href="../../../../org/apache/commons/beanutils/PropertyUtils.html" title="class in org.apache.commons.beanutils"><code>PropertyUtils</code></a>
class, which are described further in this section. First, however, some
further definitions will prove to be useful:</p>
<p>The general set of possible property types supported by a JavaBean can be
broken into three categories -- some of which are supported by the standard
JavaBeans specification, and some of which are uniquely supported by the
<em>BeanUtils</em> package:</p>
<ul>
<li><strong>Simple</strong> - Simple, or scalar, properties have a single
value that may be retrieved or modified. The underlying property type
might be a Java language primitive (such as <code>int</code>, a simple
object (such as a <code>java.lang.String</code>), or a more complex
object whose class is defined either by the Java language, by the
application, or by a class library included with the application.</li>
<li><strong>Indexed</strong> - An indexed property stores an ordered collection
of objects (all of the same type) that can be individually accessed by an
integer-valued, non-negative index (or subscript). Alternatively, the
entire set of values may be set or retrieved using an array.
As an extension to the JavaBeans specification, the
<em>BeanUtils</em> package considers any property whose underlying data
type is <code>java.util.List</code> (or an implementation of List) to be
indexed as well.</li>
<li><strong>Mapped</strong> - As an extension to standard JavaBeans APIs,
the <em>BeanUtils</em> package considers any property whose underlying
value is a <code>java.util.Map</code> to be "mapped". You can set and
retrieve individual values via a String-valued key.</li>
</ul>
<p>A variety of API methods are provided in the
<a href="../../../../org/apache/commons/beanutils/PropertyUtils.html" title="class in org.apache.commons.beanutils"><code>PropertyUtils</code></a> class to get and set
property values of all of these types.
In the code fragments below, assume that there are two bean classes defined
with the following method signatures:</p>
<pre>
public class Employee {
public Address getAddress(String type);
public void setAddress(String type, Address address);
public Employee getSubordinate(int index);
public void setSubordinate(int index, Employee subordinate);
public String getFirstName();
public void setFirstName(String firstName);
public String getLastName();
public void setLastName(String lastName);
}
</pre>
<a name="standard.basic"></a>
<h2>2.2 Basic Property Access</h2>
<p>Getting and setting <strong>simple</strong> property values is, well,
simple :-). Check out the following API signatures in the Javadocs:</p>
<ul>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getSimpleProperty-java.lang.Object-java.lang.String-"><code>PropertyUtils.getSimpleProperty(Object, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setSimpleProperty-java.lang.Object-java.lang.String-java.lang.Object-"><code>PropertyUtils.setSimpleProperty(Object, String, Object)</code></a></li>
</ul>
<p>Using these methods, you might dynamically manipulate the employee's name
in an application:</p>
<pre>
Employee employee = ...;
String firstName = (String)
PropertyUtils.getSimpleProperty(employee, "firstName");
String lastName = (String)
PropertyUtils.getSimpleProperty(employee, "lastName");
... manipulate the values ...
PropertyUtils.setSimpleProperty(employee, "firstName", firstName);
PropertyUtils.setSimpleProperty(employee, "lastName", lastName);
</pre>
<p>For <strong>indexed</strong> properties, you have two choices - you can
either build a subscript into the "property name" string, using square
brackets, or you can specify the subscript in a separate argument to the
method call:</p>
<ul>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getIndexedProperty-java.lang.Object-java.lang.String-"><code>PropertyUtils.getIndexedProperty(Object, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getIndexedProperty-java.lang.Object-java.lang.String-int-"><code>PropertyUtils.getIndexedProperty(Object, String, int)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setIndexedProperty-java.lang.Object-java.lang.String-java.lang.Object-"><code>PropertyUtils.setIndexedProperty(Object, String, Object)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setIndexedProperty-java.lang.Object-java.lang.String-int-java.lang.Object-"><code>PropertyUtils.setIndexedProperty(Object, String, int, Object)</code></a></li>
</ul>
<p>Only integer constants are allowed when you add a subscript to the property
name. If you need to calculate the index of the entry you wish to retrieve,
you can use String concatenation to assemble the property name expression.
For example, you might do either of the following:</p>
<pre>
Employee employee = ...;
int index = ...;
String name = "subordinate[" + index + "]";
Employee subordinate = (Employee)
PropertyUtils.getIndexedProperty(employee, name);
Employee employee = ...;
int index = ...;
Employee subordinate = (Employee)
PropertyUtils.getIndexedProperty(employee, "subordinate", index);
</pre>
<p>In a similar manner, there are two possible method signatures for getting
and setting <strong>mapped</strong> properties. The difference is that the
extra argument is surrounded by parentheses ("(" and ")") instead of square
brackets, and it is considered to be a String-value key used to get or set
the appropriate value from an underlying map.</p>
<ul>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getMappedProperty-java.lang.Object-java.lang.String-"><code>PropertyUtils.getMappedProperty(Object, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getMappedProperty-java.lang.Object-java.lang.String-java.lang.String-"><code>PropertyUtils.getMappedProperty(Object, String, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setMappedProperty-java.lang.Object-java.lang.String-java.lang.Object-"><code>PropertyUtils.setMappedProperty(Object, String, Object)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setMappedProperty-java.lang.Object-java.lang.String-java.lang.String-java.lang.Object-"><code>PropertyUtils.setMappedProperty(Object, String, String, Object)</code></a></li>
</ul>
<p>You can, for example, set the employee's home address in either of these
two manners:</p>
<pre>
Employee employee = ...;
Address address = ...;
PropertyUtils.setMappedProperty(employee, "address(home)", address);
Employee employee = ...;
Address address = ...;
PropertyUtils.setMappedProperty(employee, "address", "home", address);
</pre>
<a name="standard.nested"></a>
<h2>2.3 Nested Property Access</h2>
<p>In all of the examples above, we have assumed that you wished to retrieve
the value of a property of the bean being passed as the first argument to a
PropertyUtils method. However, what if the property value you retrieve is
really a Java object, and you wish to retrieve a property of <em>that</em>
object instead?</p>
<p>For example, assume we really wanted the <code>city</code> property of the
employee's home address. Using standard Java programming techniques for direct
access to the bean properties, we might write:</p>
<pre>
String city = employee.getAddress("home").getCity();
</pre>
<p>The equivalent mechanism using the PropertyUtils class is called
<strong>nested</strong> property access. To use this approach, you concatenate
together the property names of the access path, using "." separators -- very
similar to the way you can perform nested property access in JavaScript.</p>
<ul>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getNestedProperty-java.lang.Object-java.lang.String-"><code>PropertyUtils.getNestedProperty(Object, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setNestedProperty-java.lang.Object-java.lang.String-java.lang.Object-"><code>PropertyUtils.setNestedProperty(Object, String, Object)</code></a></li>
</ul>
<p>The PropertyUtils equivalent to the above Java expression would be:</p>
<pre>
String city = (String)
PropertyUtils.getNestedProperty(employee, "address(home).city");
</pre>
<p>Finally, for convenience, PropertyUtils provides method signatures that
accept any arbitrary combination of simple, indexed, and mapped property
access, using any arbitrary level of nesting:</p>
<ul>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#getProperty-java.lang.Object-java.lang.String-"><code>PropertyUtils.getProperty(Object, String)</code></a></li>
<li> <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#setProperty-java.lang.Object-java.lang.String-java.lang.Object-"><code>PropertyUtils.setProperty(Object, String, Object)</code></a></li>
</ul>
<p>which you might use like this:</p>
<pre>
Employee employee = ...;
String city = (String) PropertyUtils.getProperty(employee,
"subordinate[3].address(home).city");
</pre>
<a name="standard.customize"></a>
<h2>2.4 Customizing Introspection</h2>
<p>As was pointed out, BeanUtils relies on conventions defined by the
<em>JavaBeans</em> specification to determine the properties available for
a specific bean class. Thus all classes conforming to these conventions can
be used out of the box.</p>
<p>Sometimes an application has to deal with classes using different
conventions. For instance, fluent APIs allowing method chaining are not
compliant to the <em>JavaBeans</em> specification because here set methods
have non-void return values. From version 1.9.0 onwards, BeanUtils supports
customization of its introspection mechanism. This allows an application
to extend or modify the default discovery of bean properties.</p>
<p>The key to this extension mechanism is the <a href="../../../../org/apache/commons/beanutils/BeanIntrospector.html" title="interface in org.apache.commons.beanutils"><code>BeanIntrospector</code></a>
interface. The purpose of an object implementing this interface is to
process a specific target class and create corresponding
<code>PropertyDescriptor</code> objects for the properties it detects.
Per default, BeanUtils uses a <a href="../../../../org/apache/commons/beanutils/DefaultBeanIntrospector.html" title="class in org.apache.commons.beanutils"><code>DefaultBeanIntrospector</code></a>
object which detects properties compatible with the <em>JavaBeans</em>
specification.</p>
<p>In order to extend the property discovery mechanism, <code>PropertyUtils</code>
offers the <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html#addBeanIntrospector-org.apache.commons.beanutils.BeanIntrospector-"><code>PropertyUtils.addBeanIntrospector(BeanIntrospector)</code></a>
method. Here a custom <code>BeanIntrospector</code> implementation can be
passed in. During introspection of a class, this custom introspector is
then called, and it can add the properties it has detected to the total
result. As an example of such a custom <code>BeanIntrospector</code>
implementation, BeanUtils ships with the <a href="../../../../org/apache/commons/beanutils/FluentPropertyBeanIntrospector.html" title="class in org.apache.commons.beanutils"><code>FluentPropertyBeanIntrospector</code></a>
class. This implementation can detect properties whose set methods have a
non-void return type - thus enabling support for typical properties in a
fluent API.</p>
<a name="standard.suppress"></a>
<h2>2.5 Suppressing Properties</h2>
<p>The mechanism of customizing bean introspection described in the previous
section can also be used to suppress specific properties. There is a
specialized <code>BeanIntrospector</code> implementation that does exactly
this: <a href="../../../../org/apache/commons/beanutils/SuppressPropertiesBeanIntrospector.html" title="class in org.apache.commons.beanutils"><code>SuppressPropertiesBeanIntrospector</code></a>.
When creating an instance, a collection with the names of properties that
should not be accessible on beans has to be provided. These properties will
then be removed if they have been detected by other <code>BeanIntrospector</code>
instances during processing of a bean class.</p>
<p>A good use case for suppressing properties is the special <code>class</code>
property which is per default available for all beans; it is generated from the
<code>getClass()</code> method inherited from <code>Object</code> which follows the
naming conventions for property get methods. Exposing this property in an
uncontrolled way can lead to a security vulnerability as it allows access to
the class loader. More information can be found at
<a href="https://issues.apache.org/jira/browse/BEANUTILS-463">
https://issues.apache.org/jira/browse/BEANUTILS-463</a>.</p>
<p>Because the <code>class</code> property is undesired in many use cases
there is already an instance of <code>SuppressPropertiesBeanIntrospector</code>
which is configured to suppress this property. It can be obtained via the
<code>SUPPRESS_CLASS</code> constant of
<code>SuppressPropertiesBeanIntrospector</code>.</p>
<a name="dynamic"></a>
<h1>3. Dynamic Beans (DynaBeans)</h1>
<a name="dynamic.background"></a>
<h2>3.1 Background</h2>
<p>The <a href="../../../../org/apache/commons/beanutils/PropertyUtils.html" title="class in org.apache.commons.beanutils"><code>PropertyUtils</code></a> class described in the
preceding section is designed to provide dynamic property access on existing
JavaBean classes, without modifying them in any way. A different use case for
dynamic property access is when you wish to represent a dynamically calculated
set of property values as a JavaBean, but <em>without</em> having to actually
write a Java class to represent these properties. Besides the effort savings
in not having to create and maintain a separate Java class, this ability also
means you can deal with situations where the set of properties you care about
is determined dynamically (think of representing the result set of an SQL
select as a set of JavaBeans ...).</p>
<p>To support this use case, the <em>BeanUtils</em> package provides the
<a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a> interface, which must be implemented by a
bean class actually implementing the interface's methods, and the associated
<a href="../../../../org/apache/commons/beanutils/DynaClass.html" title="interface in org.apache.commons.beanutils"><code>DynaClass</code></a> interface that defines the set of
properties supported by a particular group of DynaBeans, in much the same way
that <code>java.lang.Class</code> defines the set of properties supported by
all instances of a particular JavaBean class.</p>
<p>For example, the <code>Employee</code> class used in the examples above
might be implemented as a DynaBean, rather than as a standard JavaBean. You
can access its properties like this:</p>
<pre>
DynaBean employee = ...; // Details depend on which
// DynaBean implementation you use
String firstName = (String) employee.get("firstName");
Address homeAddress = (Address) employee.get("address", "home");
Object subordinate = employee.get("subordinate", 2);
</pre>
<p>One very important convenience feature should be noted: <em>the
PropertyUtils property getter and setter methods understand how to access
properties in DynaBeans</em>. Therefore, if the bean you pass as the first
argument to, say, <code>PropertyUtils.getSimpleProperty()</code> is really a
DynaBean implementation, the call will get converted to the appropriate
DynaBean getter method transparently. Thus, you can base your application's
dynamic property access totally on the PropertyUtils APIs, if you wish, and
use them to access either standard JavaBeans or DynaBeans without having to
care ahead of time how a particular bean is implemented.</p>
<p>Because DynaBean and DynaClass are interfaces, they may be implemented
multiple times, in different ways, to address different usage scenarios. The
following subsections describe the implementations that are provided as a part
of the standard <em>BeanUtils</em> package, although you are encouraged to
provide your own custom implementations for cases where the standard
implementations are not sufficient.</p>
<a name="dynamic.basic"></a>
<h2>3.2 <code>BasicDynaBean</code> and <code>BasicDynaClass</code></h2>
<p>The <a href="../../../../org/apache/commons/beanutils/BasicDynaBean.html" title="class in org.apache.commons.beanutils"><code>BasicDynaBean</code></a> and
<a href="../../../../org/apache/commons/beanutils/BasicDynaClass.html" title="class in org.apache.commons.beanutils"><code>BasicDynaClass</code></a> implementation provides a
basic set of
dynamic property capabilities where you want to dynamically define the
set of properties (described by instances of <a href="../../../../org/apache/commons/beanutils/DynaProperty.html" title="class in org.apache.commons.beanutils"><code>DynaProperty</code></a>).
You start by defining the DynaClass that establishes
the set of properties you care about:</p>
<pre>
DynaProperty[] props = new DynaProperty[]{
new DynaProperty("address", java.util.Map.class),
new DynaProperty("subordinate", mypackage.Employee[].class),
new DynaProperty("firstName", String.class),
new DynaProperty("lastName", String.class)
};
BasicDynaClass dynaClass = new BasicDynaClass("employee", null, props);
</pre>
<p>Note that the 'dynaBeanClass' argument (in the constructor of
<code>BasicDynaClass</code>) can have the value of <code>null</code>. In this
case, the value of <code>dynaClass.getDynaBeanClass</code> will just be the
<code>Class</code> for BasicDynaBean.</p>
<p>Next, you use the <code>newInstance()</code> method of this DynaClass to
create new DynaBean instances that conform to this DynaClass, and populate
its initial property values (much as you would instantiate a new standard
JavaBean and then call its property setters):</p>
<pre>
DynaBean employee = dynaClass.newInstance();
employee.set("address", new HashMap());
employee.set("subordinate", new mypackage.Employee[0]);
employee.set("firstName", "Fred");
employee.set("lastName", "Flintstone");
</pre>
<p>Note that the DynaBean class was declared to be
<code>DynaBean</code> instead of <code>BasicDynaBean</code>. In
general, if you are using DynaBeans, you will not want to care about the
actual implementation class that is being used -- you only care about
declaring that it is a <code>DynaBean</code> so that you can use the
DynaBean APIs.</p>
<p>As stated above, you can pass a DynaBean instance as the first argument
to a <code>PropertyUtils</code> method that gets and sets properties, and it
will be interpreted as you expect -- the dynamic properties of the DynaBean
will be retrieved or modified, instead of underlying properties on the
actual BasicDynaBean implementation class.</p>
<a name="dynamic.resultSet"></a>
<h2>3.3 <code>ResultSetDynaClass</code> (Wraps ResultSet in DynaBeans)</h2>
<p>A very common use case for DynaBean APIs is to wrap other collections of
"stuff" that do not normally present themselves as JavaBeans. One of the most
common collections that would be nice to wrap is the
<code>java.sql.ResultSet</code> that is returned when you ask a JDBC driver
to perform a SQL SELECT statement. Commons BeanUtils offers a standard
mechanism for making each row of the result set visible as a DynaBean,
which you can utilize as shown in this example:</p>
<pre>
Connection conn = ...;
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery
("select account_id, name from customers");
Iterator rows = (new ResultSetDynaClass(rs)).iterator();
while (rows.hasNext()) {
DynaBean row = (DynaBean) rows.next();
System.out.println("Account number is " +
row.get("account_id") +
" and name is " + row.get("name"));
}
rs.close();
stmt.close();
</pre>
<a name="dynamic.rowSet"></a>
<h2>3.4 <code>RowSetDynaClass</code> (Disconnected ResultSet as DynaBeans)</h2>
<p>Although <a href="#dynamic.resultSet"><code>ResultSetDynaClass</code></a> is
a very useful technique for representing the results of an SQL query as a
series of DynaBeans, an important problem is that the underlying
<code>ResultSet</code> must remain open throughout the period of time that the
rows are being processed by your application. This hinders the ability to use
<code>ResultSetDynaClass</code> as a means of communicating information from
the model layer to the view layer in a model-view-controller architecture
such as that provided by the <a href="http://struts.apache.org/">Struts
Framework</a>, because there is no easy mechanism to assure that the result set
is finally closed (and the underlying <code>Connection</code> returned to its
connection pool, if you are using one).</p>
<p>The <code>RowSetDynaClass</code> class represents a different approach to
this problem. When you construct such an instance, the underlying data is
<em>copied</em> into a set of in-memory DynaBeans that represent the result.
The advantage of this technique, of course, is that you can immediately close
the ResultSet (and the corresponding Statement), normally before you even
process the actual data that was returned. The disadvantage, of course, is
that you must pay the performance and memory costs of copying the result data,
and the result data must fit entirely into available heap memory. For many
environments (particularly in web applications), this tradeoff is usually
quite beneficial.</p>
<p>As an additional benefit, the <code>RowSetDynaClass</code> class is defined
to implement <code>java.io.Serializable</code>, so that it (and the
DynaBeans that correspond to each row of the result) can be conveniently
serialized and deserialized (as long as the underlying column values are
also Serializable). Thus, <code>RowSetDynaClass</code> represents a very
convenient way to transmit the results of an SQL query to a remote Java-based
client application (such as an applet).</p>
<p>The normal usage pattern for a <code>RowSetDynaClass</code> will look
something like this:</p>
<pre>
Connection conn = ...; // Acquire connection from pool
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ...");
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
rs.close();
stmt.close();
...; // Return connection to pool
List rows = rsdc.getRows();
...; // Process the rows as desired
</pre>
<a name="dynamic.wrap"></a>
<h2>3.5 <code>WrapDynaBean</code> and <code>WrapDynaClass</code></h2>
<p>OK, you've tried the DynaBeans APIs and they are cool -- very simple
<code>get()</code> and <code>set()</code> methods provide easy access to all
of the dynamically defined simple, indexed, and mapped properties of your
DynaBeans. You'd like to use the DynaBean APIs to access <strong>all</strong>
of your beans, but you've got a bunch of existing standard JavaBeans classes
to deal with as well. This is where the
<a href="../../../../org/apache/commons/beanutils/WrapDynaBean.html" title="class in org.apache.commons.beanutils"><code>WrapDynaBean</code></a> (and its associated
<a href="../../../../org/apache/commons/beanutils/WrapDynaClass.html" title="class in org.apache.commons.beanutils"><code>WrapDynaClass</code></a>) come into play. As the name
implies, a WrapDynaBean is used to "wrap" the DynaBean APIs around an
existing standard JavaBean class. To use it, simply create the wrapper
like this:</p>
<pre>
MyBean bean = ...;
DynaBean wrapper = new WrapDynaBean(bean);
String firstName = wrapper.get("firstName");
</pre>
<p>Note that, although appropriate <code>WrapDynaClass</code> instances are
created internally, you never need to deal with them.</p>
<a name="dynamic.lazy"></a>
<h2>3.6 <i>Lazy</i> DynaBeans</h2>
<ul>
<li>1. <a href="#LazyDynaBean">LazyDynaBean</a> - A <i>Lazy</i>
<a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a></li>
<li>2. <a href="#LazyDynaMap">LazyDynaMap</a> - A <i>light weight</i>
<a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean</code></a> facade to a Map
with <i>lazy</i> map/list processing</li>
<li>3. <a href="#LazyDynaList">LazyDynaList</a> - A <i>lazy list</i>
for <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean's</code></a>,
<code>java.util.Map</code>'s or POJO beans.</li>
<li>4. <a href="#LazyDynaClass">LazyDynaClass</a> - A
<a href="../../../../org/apache/commons/beanutils/MutableDynaClass.html" title="interface in org.apache.commons.beanutils"><code>MutableDynaClass</code></a> implementation.</li>
</ul>
<p>You bought into the DynaBeans because it saves coding all those POJO JavaBeans but
you're here because <i>lazy</i> caught your eye and wondered whats that about?
What makes these flavors of DynaBean <i>lazy</i> are the following features:</p>
<ul>
<li><strong><i>Lazy</i> property addition</strong> - lazy beans use a
<a href="../../../../org/apache/commons/beanutils/DynaClass.html" title="interface in org.apache.commons.beanutils"><code>DynaClass</code></a> which implements
the <a href="../../../../org/apache/commons/beanutils/MutableDynaClass.html" title="interface in org.apache.commons.beanutils"><code>MutableDynaClass</code></a>
interface. This provides the ability to add and remove a DynaClass's
properties. <i>Lazy</i> beans use this feature to automatically add
a property which doesn't exist to the DynaClass when
the <code>set(name, value)</code> method is called.</li>
<li><strong><i>Lazy</i> List/Array growth</strong> - If an <i>indexed</i> property is not large
enough to accomodate the <code>index</code> being set then the <code>List</code> or
<code>Array</code> is automatically <i>grown</i> so that it is.</li>
<li><strong><i>Lazy</i> List/Array instantiation</strong> - if an <i>indexed</i>
property doesn't exist then calling the <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean's</code></a>
<i>indexed</i> property getter/setter methods (i.e. <code>get(name, index)</code> or
<code>set(name, index, value)</code>) results in either a new <code>List</code>
or <code>Array</code> being instantiated. If the indexed property has not been
defined in the DynaClass then it is automatically added and a default <code>List</code>
implementation instantiated.</li>
<li><strong><i>Lazy</i> Map instantiation</strong> - if a <i>mapped</i>
property doesn't exist then calling the <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBean's</code></a>
<i>mapped</i> property getter/setter methods (i.e. <code>get(name, key)</code> or
<code>set(name, key, value)</code>) results in a new <code>Map</code>
being instantiated. If the mapped property has not been defined in the DynaClass
then it is automatically added and a default <code>Map</code> implementation
instantiated.</li>
<li><strong><i>Lazy</i> Bean instantiation</strong> - if a property is defined in
the <code>DynaClass</code> as a <code>DynaBean</code> or regular bean and
doesn't exist in the <code>DynaBean</code> then <code>LazyDynaBean</code> wiill
try to instantiate the bean using a default empty constructor.</li>
</ul>
<p><strong>1. <a href="../../../../org/apache/commons/beanutils/LazyDynaBean.html" title="class in org.apache.commons.beanutils"><code>LazyDynaBean</code></a></strong> is the standard <i>lazy</i> bean
implementation. By default it is associated with a <a href="../../../../org/apache/commons/beanutils/LazyDynaClass.html" title="class in org.apache.commons.beanutils"><code>LazyDynaClass</code></a>
which implements the <a href="../../../../org/apache/commons/beanutils/MutableDynaClass.html" title="interface in org.apache.commons.beanutils"><code>MutableDynaClass</code></a> interface - however
it can be used with any <code>MutableDynaClass</code> implementation. The question is <i>how do
I use it?</i> - well it can be as simple as creating a new bean and then calling the getters/setters...</p>
<pre>
DynaBean dynaBean = new LazyDynaBean();
dynaBean.set("foo", "bar"); // simple
dynaBean.set("customer", "title", "Mr"); // mapped
dynaBean.set("customer", "surname", "Smith"); // mapped
dynaBean.set("address", 0, addressLine1); // indexed
dynaBean.set("address", 1, addressLine2); // indexed
dynaBean.set("address", 2, addressLine3); // indexed
</pre>
<p><strong>2. <a href="../../../../org/apache/commons/beanutils/LazyDynaMap.html" title="class in org.apache.commons.beanutils"><code>LazyDynaMap</code></a></strong> is a <i>light weight</i>
<code>DynaBean</code> facade to a <code>Map</code> with all the usual <i>lazy</i> features. Its
<i>light weight</i> because it doesn't have an associated <code>DynaClass</code> containing all the properties.
In fact it actually implements the <code>DynaClass</code> interface itself (and <code>MutableDynaClass</code>)
and derives all the <i>DynaClass</i> information from the actual contents of the <code>Map</code>. A
<code>LazyDynaMap</code> can be created around an existing <code>Map</code> or can instantiate its own
<code>Map</code>. After any <code>DynaBean</code> processing has finished the <code>Map</code> can be retrieved
and the DynaBean <i>facade</i> discarded.</p>
<p>If you need a new <code>Map</code> then to use....</p>
<pre>
DynaBean dynaBean = new LazyDynaMap(); // create DynaBean
dynaBean.set("foo", "bar"); // simple
dynaBean.set("customer", "title", "Mr"); // mapped
dynaBean.set("address", 0, addressLine1); // indexed
Map myMap = dynaBean.getMap() // retrieve the Map
</pre>
<p><i>or</i> to use with an existing <code>Map</code> ....</p>
<pre>
Map myMap = .... // exisitng Map
DynaBean dynaBean = new LazyDynaMap(myMap); // wrap Map in DynaBean
dynaBean.set("foo", "bar"); // set properties
</pre>
<p><strong>3. <a href="../../../../org/apache/commons/beanutils/LazyDynaList.html" title="class in org.apache.commons.beanutils"><code>LazyDynaList</code></a></strong>
is <i>lazy list</i> for <a href="../../../../org/apache/commons/beanutils/DynaBean.html" title="interface in org.apache.commons.beanutils"><code>DynaBeans</code></a>
<code>java.util.Map</code>'s or POJO beans. See the <a href="LazyDynaList.html">Javadoc</a>
for more details and example usage.</p>
<p><strong>4. <a href="../../../../org/apache/commons/beanutils/LazyDynaClass.html" title="class in org.apache.commons.beanutils"><code>LazyDynaClass</code></a></strong>
extends <a href="../../../../org/apache/commons/beanutils/BasicDynaClass.html" title="class in org.apache.commons.beanutils"><code>BasicDynaClass</code></a> and implements
the <a href="MutableDynaClass.html">MutableDynaClass</a> interface.
It can be used with other <code>DynaBean</code> implementations, but it
is the default <code>DynaClass</code> used by <code>LazyDynaBean</code>.
When using the <code>LazyDynaBean</code> there may be no need to have
anything to do with the <code>DynaClass</code>. However sometimes there
is a requirement to set up the <code>DynaClass</code> first - perhaps to
define the type of array for an indexed property, or if using the DynaBean
in <i>restricted</i> mode (see note below) is required. Doing so is
straight forward...</p>
<p><i>Either</i> create a <code>LazyDynaClass</code> first...
<pre>
MutableDynaClass dynaClass = new LazyDynaClass(); // create DynaClass
dynaClass.add("amount", java.lang.Integer.class); // add property
dynaClass.add("orders", OrderBean[].class); // add indexed property
dynaClass.add("orders", java.util.TreeMapp.class); // add mapped property
DynaBean dynaBean = new LazyDynaBean(dynaClass); // Create DynaBean with associated DynaClass
</pre>
<p><i>or</i> create a <code>LazyDynaBean</code> and get the <code>DynaClass</code>...
<pre>
DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean
MutableDynaClass dynaClass =
(MutableDynaClass)dynaBean.getDynaClass(); // get DynaClass
dynaClass.add("amount", java.lang.Integer.class); // add property
dynaClass.add("myBeans", myPackage.MyBean[].class); // add 'array' indexed property
dynaClass.add("myMap", java.util.TreeMapp.class); // add mapped property
</pre>
<p><strong>NOTE:</strong> One feature of <a href="../../../../org/apache/commons/beanutils/MutableDynaClass.html" title="interface in org.apache.commons.beanutils"><code>MutableDynaClass</code></a> is that it
has a <i>Restricted</i> property. When the DynaClass is <i>restricted</i> no properties can be added
or removed from the <code>DynaClass</code>. Neither the <code>LazyDynaBean</code> or <code>LazyDynaMap</code>
will add properties automatically if the <code>DynaClass</code> is <i>restricted</i>.</p>
<a name="conversion"></a>
<h1>4. Data Type Conversions</h1>
<a name="conversion.background"></a>
<h3>4.1 Background</h3>
<p>So far, we've only considered the cases where the data types of the
dynamically accessed properties are known, and where we can use Java casts
to perform type conversions. What happens if you want to automatically
perform type conversions when casting is not possible? The
<em>BeanUtils</em> package provides a variety of APIs and design patterns
for performing this task as well.</p>
<a name="conversion.beanutils"></a>
<h3>4.2 <code>BeanUtils</code> and <code>ConvertUtils</code> Conversions</h3>
<p>A very common use case (and the situation that caused the initial creation
of the <em>BeanUtils</em> package) was the desire to convert the set of request
parameters that were included in a
<code>javax.servlet.HttpServletRequest</code> received by a web application
into a set of corresponding property setter calls on an arbitrary JavaBean.
(This is one of the fundamental services provided by the
<a href="http://struts.apache.org/">Struts Framework</a>, which uses
<em>BeanUtils</em> internally to implement this functionality.)</p>
<p>In an HTTP request, the set of included parameters is made available as a
series of String (or String array, if there is more than one value for the
same parameter name) instances, which need to be converted to the underlying
data type. The <a href="../../../../org/apache/commons/beanutils/BeanUtils.html" title="class in org.apache.commons.beanutils"><code>BeanUtils</code></a> class provides
property setter methods that accept String values, and automatically convert
them to appropriate property types for Java primitives (such as
<code>int</code> or <code>boolean</code>), and property getter methods that
perform the reverse conversion. Finally, a <code>populate()</code> method
is provided that accepts a <code>java.util.Map</code> containing a set of
property values (keyed by property name), and calls all of the appropriate
setters whenever the underlying bean has a property with the same name as
one of the request parameters. So, you can perform the all-in-one property
setting operation like this:</p>
<pre>
HttpServletRequest request = ...;
MyBean bean = ...;
HashMap map = new HashMap();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
map.put(name, request.getParameterValues(name));
}
BeanUtils.populate(bean, map);
</pre>
<p>The <code>BeanUtils</code> class relies on conversion methods defined in
the <a href="../../../../org/apache/commons/beanutils/ConvertUtils.html" title="class in org.apache.commons.beanutils"><code>ConvertUtils</code></a> class to perform the actual
conversions, and these methods are availablve for direct use as well.
<strong>WARNING</strong> - It is likely that the hard coded use of
<code>ConvertUtils</code> methods will be deprecated in the future, and
replaced with a mechanism that allows you to plug in your own implementations
of the <a href="../../../../org/apache/commons/beanutils/Converter.html" title="interface in org.apache.commons.beanutils"><code>Converter</code></a> interface instead. Therefore,
new code should not be written with reliance on ConvertUtils.</p>
<a name="conversion.defining"></a>
<h3>4.3 Defining Your Own Converters</h3>
<p>The <code>ConvertUtils</code> class supports the ability to define and
register your own String --> Object conversions for any given Java class.
Once registered, such converters will be used transparently by all of the
<code>BeanUtils</code> methods (including <code>populate()</code>). To
create and register your own converter, follow these steps:</p>
<ul>
<li>Write a class that implements the <a href="../../../../org/apache/commons/beanutils/Converter.html" title="interface in org.apache.commons.beanutils"><code>Converter</code></a>
interface. The <code>convert()</code> method should accept the
<code>java.lang.Class</code> object of your application class (i.e.
the class that you want to convert to, and a String representing the
incoming value to be converted.</li>
<li>At application startup time, register an instance of your converter class
by calling the <code>ConvertUtils.register()</code> method.</li>
</ul>
<a name="conversion.i18n"></a>
<h3>4.4 Locale Aware Conversions</h3>
<p>The standard classes in <code>org.apache.commons.beanutils</code> are not
locale aware. This gives them a cleaner interface and makes then easier to use
in situations where the locale is not important.</p>
<p>Extended, locale-aware analogues can be found in
<code><a href='locale/package-summary.html'>org.apache.commons.beanutils.locale
</a></code>. These are built along the same
lines as the basic classes but support localization.</p>
<a name="instances"></a>
<h1>5. Utility Objects And Static Utility Classes</h1>
<a name="instances.background"></a>
<h3>Background</h3>
<p>
So far, the examples have covered the static utility classes (<code>BeanUtils</code>,
<code>ConvertUtils</code> and <code>PropertyUtils</code>). These are easy to use but are
somewhat inflexible. These all share the same registered converters and the same caches.
</p>
<p>
This functionality can also be accessed through utility objects (in fact, the static utility
class use worker instances of these classes). For each static utility class, there is a corresponding
class with the same functionality that can be instantiated:
</p>
<p>
<table cols='2' width='60%'>
<tr><th>Static Utility Class</th><th>Utility Object</th></tr>
<tr><td>BeanUtils</td><td>BeanUtilsBean</td></tr>
<tr><td>ConvertUtils</td><td>ConvertUtilsBean</td></tr>
<tr><td>PropertyUtils</td><td>PropertyUtilsBean</td></tr>
</table>
</p>
<p>
Creating an instances allow gives guarenteed control of the caching and registration
to the code that creates it.
</p>
<a name="collections"></a>
<h1>6. Collections</h1>
<a name="bean-comparator"></a>
<h3>6.1 Comparing Beans</h3>
<p>
<code>org.apache.commons.beanutils.BeanComparator</code> is a <code>Comparator</code> implementation
that compares beans based on a shared property value.
</p>
<a name="bean-property-closure"></a>
<h3>6.2 Operating On Collections Of Beans</h3>
<p>
The <code>Closure</code> interface in <code>commons-collections</code> encapsulates a block of code that
executes on an arbitrary input Object. <code>Commons-collections</code> contains code that allows
<code>Closures</code> to be applied to the contents of a Collection. For more details, see the
<a href='http://commons.apache.org/collections/'>commons-collections</a>
documentation.
</p>
<p>
<code>BeanPropertyValueChangeClosure</code> is a <code>Closure</code> that sets a specified property
to a particular value. A typical usage is to combine this with <code>commons-collections</code>
so that all the beans in a collection can have a particular property set to a particular value.
</p>
<p>
For example, set the activeEmployee property to TRUE for an entire collection:
<code><pre>
// create the closure
BeanPropertyValueChangeClosure closure =
new BeanPropertyValueChangeClosure( "activeEmployee", Boolean.TRUE );
// update the Collection
CollectionUtils.forAllDo( peopleCollection, closure );
</pre></code>
</p>
<a name="bean-property-predicate"></a>
<h3>6.3 Querying Or Filtering Collections Of Beans</h3>
<p>
The <code>Predicate</code> interface in <code>commons-collections</code> encapsulates an evaluation
of an input Object that returns either true or false. <code>Commons-collections</code> contains code
that allows
<code>Predicates</code> to be applied to be used to filter collections. For more details, see the
<a href='http://commons.apache.org/collections/'>commons-collections</a>
documentation.
</p>
<p>
<code>BeanPropertyValueEqualsPredicate</code> is a <code>Predicate</code> that evaluates a
set property value against a given value. A typical usage is
(in combination with <code>commons-collections</code>)
to filter collections on the basis of a property value.
</p>
<p>
For example, to filter a collection to find all beans where active employee is false use:
<code><pre>
BeanPropertyValueEqualsPredicate predicate =
new BeanPropertyValueEqualsPredicate( "activeEmployee", Boolean.FALSE );
// filter the Collection
CollectionUtils.filter( peopleCollection, predicate );
</pre></code>
</p>
<a href="bean-property-transformer"></a>
<h3>6.4 Transforming Collections Of Beans</h3>
<p>
The <code>Transformer</code> interface in <code>commons-collections</code> encapsulates the transformation
of an input Object into an output object. <code>Commons-collections</code> contains code
that allows
<code>Transformers</code> to be applied produce a collection of outputs from a collection of inputs.
For more details, see the
<a href='http://commons.apache.org/collections/'>commons-collections</a>
documentation.
</p>
<p>
<code>BeanToPropertyTransformer</code> is a <code>Transformer</code> implementation
that transforms a bean into it's property value.
</p>
<p>
For example, to find all cities that are contained in the address of each person property of each bean in
a collection:
<code><pre>
// create the transformer
BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer( "person.address.city" );
// transform the Collection
Collection peoplesCities = CollectionUtils.collect( peopleCollection, transformer );
</pre></code>
</p>
<a name="FAQ"></a>
<h1>7. Frequently Asked Questions</h1>
<a name="FAQ.property"></a>
<h3>Why Can't BeanUtils Find My Method?</h3>
<p>The <em>BeanUtils</em> package relies on <em>introspection</em> rather than
<em>reflection</em>. This means that it will find only
<a href='http://java.sun.com/products/javabeans'><em>JavaBean</em>
compliant</a> properties.</p>
<p>There are some subtleties of this specification that can catch out the unwary:
<ul>
<li>A property can have only one set and one get method. Overloading is not allowed.</li>
<li>The <code>java.beans.Introspector</code> searches widely for a custom <em>BeanInfo</em>
class. If your class has the same name as another with a custom <em>BeanInfo</em>
(typically a java API class) then the <code>Introspector</code> may use that instead of
creating via reflection based on your class. If this happens, the only solution is to
create your own <em>BeanInfo</em>.</li>
</ul>
</p>
<a name="FAQ.bc.order"></a>
<h3>How Do I Set The BeanComparator Order To Be Ascending/Descending?</h3>
<p>
BeanComparator relies on an internal Comparator to perform the actual
comparisions. By default,
<code>org.apache.commons.collections.comparators.ComparableComparator</code>
is used which imposes a natural order. If you want to change the order,
then a custom Comparator should be created and passed into the
appropriate constructor.
</p>
<p>
For example:
</p>
<code><pre>
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;
import org.apache.commons.beanutils.BeanComparator;
...
BeanComparator reversedNaturalOrderBeanComparator
= new BeanComparator("propertyName", new ReverseComparator(new ComparableComparator()));
Collections.sort(myList, reversedNaturalOrderBeanComparator);
...
</pre></code></div>
</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.html">Overview</a></li>
<li class="navBarCell1Rev">Package</li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev Package</li>
<li><a href="../../../../org/apache/commons/beanutils/converters/package-summary.html">Next Package</a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/commons/beanutils/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small>Copyright © 2000–2016 <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</body>
</html>
|