Apache Commons BeanUtils
Apache Commons BeanUtils — это утилита на основе Java , обеспечивающая компонентную архитектуру . [ 1 ] [ 2 ] [ 3 ]
Модули
[ редактировать ]Библиотека распространяется в трёх jar-файлах:
- commons-beanutils.jar — содержит всё
- commons-beanutils-core.jar — исключает классы коллекций компонентов.
- commons-beanutils-bean-collections.jar — только классы Bean Collections. [ 1 ]
Пример
[ редактировать ]Пример кода может выглядеть следующим образом:
/**
* Example displaying the new default behaviour such that
* it is not possible to access class level properties utilizing the
* BeanUtilsBean, which in turn utilizes the PropertyUtilsBean.
*/
public void testSuppressClassPropertyByDefault() throws Exception {
final BeanUtilsBean bub = new BeanUtilsBean();
final AlphaBean bean = new AlphaBean();
try {
bub.getProperty(bean, "class");
fail("Could access class property!");
} catch (final NoSuchMethodException ex) {
// Ok
}
}
/**
* Example showing how by which one would use to revert to the
* behaviour prior to the 1.9.4 release where class level properties were accessible by
* the BeanUtilsBean and the PropertyUtilsBean.
*/
public void testAllowAccessToClassProperty() throws Exception {
final BeanUtilsBean bub = new BeanUtilsBean();
bub.getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
final AlphaBean bean = new AlphaBean();
String result = bub.getProperty(bean, "class");
assertEquals("Class property should have been accessed", "class org.apache.commons.beanutils2.AlphaBean", result);
}
См. также
[ редактировать ]Ссылки
[ редактировать ]- ^ Перейти обратно: а б с «BeanUtils – Commons» . commons.apache.org . Проверено 20 августа 2019 г.
- ^ Берглунд, Тим; Маккалоу, Мэтью (13 июля 2011 г.). Сборка и тестирование с помощью Gradle . «О'Рейли Медиа, Инк.». п. 57. ИСБН 9781449304638 .
- ^ Компания Sonatype (24 сентября 2008 г.). Maven: Полное руководство: Полное руководство . «О'Рейли Медиа, Инк.». п. 136. ИСБН 9780596551780 .
{{cite book}}
:|last=
имеет общее имя ( справка )