List of usage examples for org.apache.commons.lang3.reflect FieldUtils getFieldsListWithAnnotation
public static List<Field> getFieldsListWithAnnotation(final Class<?> cls, final Class<? extends Annotation> annotationCls)
From source file:jdao.JDAO.java
public static <T> String extractIdNameFromBean(Class<T> _beanClazz) { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(_beanClazz, IBeanID.class); if (fields.size() != 1) { throw new IllegalArgumentException("improper IBeanID annotation"); }// w ww.j a v a 2 s . c om return fields.iterator().next().getAnnotation(IBeanField.class).value(); }
From source file:jdao.JDAO.java
public static <T> Map<String, Object> extractIdKvFromBean(Object _bean, Class<T> _beanClazz) { Map<String, Object> _ret = new HashMap(); List<Field> fields = FieldUtils.getFieldsListWithAnnotation(_beanClazz, IBeanID.class); if (fields.size() > 0) { throw new IllegalArgumentException("improper IBeanID annotation"); }/*from ww w . j av a 2s. c o m*/ try { Iterator<Field> it = fields.iterator(); while (it.hasNext()) { Field field = it.next(); String _key = field.getAnnotation(IBeanField.class).value(); Object _val = FieldUtils.readField(field, _bean, true); _ret.put(_key, _val); } return _ret; } catch (IllegalAccessException e) { // IGNORE } return null; }
From source file:jdao.JDAO.java
public static <T> Map<String, Object> extractColsFromBean(Object _bean, Class<T> _beanClazz, boolean _inclIdField) { Map<String, Object> _ret = new HashMap(); List<Field> fields = FieldUtils.getFieldsListWithAnnotation(_beanClazz, IBeanField.class); for (Field field : fields) { try {//w w w .j a va 2 s . c o m if (_inclIdField || (!field.isAnnotationPresent(IBeanID.class))) { String _key = field.getAnnotation(IBeanField.class).value(); Object _val = FieldUtils.readField(field, _bean, true); _ret.put(_key, _val); } } catch (IllegalAccessException e) { // IGNORE } } return _ret; }
From source file:org.codice.ddf.test.common.rules.ServiceRegistrationRule.java
@Override public Statement apply(Statement statement, FrameworkMethod method, Object target) { LOGGER.trace("apply"); List<Field> fieldsWithAnnotation = FieldUtils.getFieldsListWithAnnotation(target.getClass(), MockOsgiService.class); List<MockOsgiServiceField> mockOsgiServiceFields = fieldsWithAnnotation.stream() .map(field -> new MockOsgiServiceField(target, field)).collect(Collectors.toList()); return new Statement() { @Override/* ww w .j a v a 2 s .com*/ public void evaluate() throws Throwable { try { LOGGER.debug("Setting up mock services for test {}", method.getName()); mockOsgiServiceFields.forEach(MockOsgiServiceField::setup); statement.evaluate(); } finally { mockOsgiServiceFields.forEach(MockOsgiServiceField::cleanup); } } }; }