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:com.jedi.oracle.OracleTypeUtils.java
public static Map<String, Class<?>> findCustomTypes(Class clazz) { Map<String, Class<?>> map = new HashMap<String, Class<?>>(); List<Field> fields = FieldUtils.getFieldsListWithAnnotation(clazz, OracleParameterMapping.class); findCustomTypesRecursive(fields, map); return map;/*ww w . j a v a2 s. co m*/ }
From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java
public static void deserializeFormFields(Object target, ValueMap input) throws DeserializeException { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(target.getClass(), FormField.class); deserializeFields(target, fields, input); }
From source file:com.jedi.oracle.OracleCustomType.java
@Override public void readSQL(SQLInput stream, String typeName) throws SQLException { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(this.getClass(), OracleObjectMapping.class); List<Field> ordering = Ordering.natural().nullsFirst().onResultOf(new Function<Field, Integer>() { public Integer apply(Field field) { OracleObjectMapping mapping = field.getAnnotation(OracleObjectMapping.class); return mapping.index(); }/* www . j av a 2 s.com*/ }).sortedCopy(fields); for (Field field : ordering) { int oracleType = field.getAnnotation(OracleObjectMapping.class).oracleType(); Object value = OracleTypeUtils.getValue(stream, oracleType); if (value != null) { if (!field.getType().isInstance(value)) { try { value = SqlTypeConverter.convert(value, field.getType()); } catch (IOException e) { e.printStackTrace(); } } try { field.setAccessible(true); field.set(this, value); } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
From source file:com.jedi.oracle.OracleTypeUtils.java
private static void findCustomTypesRecursive(List<Field> fields, Map<String, Class<?>> map) { for (Field field : fields) { Class fieldType = field.getType(); if (List.class.isAssignableFrom(fieldType)) { ParameterizedType listType = (ParameterizedType) field.getGenericType(); fieldType = (Class<?>) listType.getActualTypeArguments()[0]; }//w w w . ja v a 2s . co m if (fieldType.isAnnotationPresent(CustomTypeMapping.class)) { CustomTypeMapping mapping = (CustomTypeMapping) fieldType.getAnnotation(CustomTypeMapping.class); map.put(mapping.name(), fieldType); List<Field> oracleObjectFields = FieldUtils.getFieldsListWithAnnotation(fieldType, OracleObjectMapping.class); if (oracleObjectFields != null && !oracleObjectFields.isEmpty()) { findCustomTypesRecursive(oracleObjectFields, map); } } } }
From source file:com.robertsmieja.test.utils.junit.GettersAndSettersUtils.java
static List<Field> getFields(Class<?> aClass, Predicate<Field> fieldPredicate) { List<Field> allFields = FieldUtils.getAllFieldsList(aClass); List<Field> excludedFields = FieldUtils.getFieldsListWithAnnotation(aClass, IgnoreForTests.class); return allFields.stream().filter(field -> !field.isSynthetic()) .filter(field -> !excludedFields.contains(field)).filter(field -> !isFinal(field.getModifiers())) .filter(fieldPredicate).collect(Collectors.toList()); }
From source file:io.apiman.test.integration.runner.handlers.AbstractAnnotationHandler.java
/** * Get all fields of target instance annotated by given annotation type * * @param annotationClass type of annotation * @return annotated fields//from www .j a v a 2 s .c o m */ public List<Field> annotatedFields(Class<? extends Annotation> annotationClass) { return FieldUtils.getFieldsListWithAnnotation(clazz, annotationClass); }
From source file:com.jedi.oracle.OracleCall.java
private void fillParametersFromFields() throws IllegalAccessException { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(getClass(), OracleParameterMapping.class); if (fields == null || fields.isEmpty()) { return;//from ww w. ja v a 2 s .c om } for (Field field : fields) { OracleParameterMapping mapping = field.getAnnotation(OracleParameterMapping.class); OracleParameter parameter = new OracleParameter(); parameter.setDbType(mapping.dbType()); parameter.setDirection(mapping.direction()); parameter.setIndex(mapping.index()); parameter.setName(mapping.name()); parameter.setOracleDbType(mapping.oracleType()); parameter.setCustomTypeName(mapping.customTypeName()); switch (parameter.getDirection()) { case Input: case InputOutput: field.setAccessible(true); parameter.setValue(field.get(this)); break; } this.parameters.add(parameter); } }
From source file:com.thinkbiganalytics.annotations.AnnotationFieldNameResolver.java
/** * Walk a class and obtain {@link AnnotatedFieldProperty} objects matching any fields with the {@link #annotation} supplied * * @param clazz the class to inspect and parse annotations * @return a list of objects describing the annotated fields *//*ww w . ja v a2s. c o m*/ public List<AnnotatedFieldProperty> getProperties(Class clazz) { processedClasses.add(clazz); classPropertyFields.put(clazz, new HashSet<AnnotatedFieldProperty>()); List<AnnotatedFieldProperty> names = new ArrayList<>(); List<Field> fields = FieldUtils.getFieldsListWithAnnotation(clazz, annotation); List<Field> allFields = FieldUtils.getAllFieldsList(clazz); for (Field field : fields) { AnnotatedFieldProperty p = addFieldProperty(clazz, names, field); classPropertyFields.get(clazz).add(p); Class fieldType = field.getType(); if (!processedClasses.contains(fieldType)) { names.addAll(getProperties(fieldType)); } } for (Field field : allFields) { Class fieldType = field.getType(); if (!processedClasses.contains(fieldType)) { stack.push(field.getName()); names.addAll(getProperties(fieldType)); //check to see if field is annotated with deserialize JsonDeserialize deserialize = field.getAnnotation(JsonDeserialize.class); if (deserialize != null) { Class<?> deserializeClass = deserialize.as(); if (!processedClasses.contains(deserializeClass)) { names.addAll(getProperties(deserializeClass)); } } stack.pop(); } else if (classPropertyFields.containsKey(fieldType)) { stack.push(field.getName()); for (AnnotatedFieldProperty prop : classPropertyFields.get(fieldType)) { addFieldProperty(clazz, names, prop.getField()); } //check to see if field is annotated with deserialize JsonDeserialize deserialize = field.getAnnotation(JsonDeserialize.class); if (deserialize != null) { Class<?> deserializeClass = deserialize.as(); if (classPropertyFields.containsKey(deserializeClass)) { for (AnnotatedFieldProperty prop : classPropertyFields.get(deserializeClass)) { addFieldProperty(clazz, names, prop.getField()); } } } stack.pop(); } } return names; }
From source file:com.jedi.oracle.OracleCall.java
private void fillFieldValuesFromParameters() throws IllegalAccessException { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(getClass(), OracleParameterMapping.class); if (fields == null || fields.isEmpty()) { return;//from www . j a v a2s . c o m } for (final OracleParameter parameter : this.parameters) { switch (parameter.getDirection()) { case ReturnValue: case InputOutput: case Output: Field field = Iterables.find(fields, new Predicate<Field>() { public boolean apply(Field item) { OracleParameterMapping mapping = item.getAnnotation(OracleParameterMapping.class); return mapping.name().equals(parameter.getName()); } }); field.setAccessible(true); field.set(this, parameter.getValue()); } } }
From source file:com.sunchenbin.store.feilong.core.tools.jsonlib.JsonUtil.java
/** * ??filed ??./*from ww w . j a v a 2s .c om*/ * * <h3>??:</h3> * * <blockquote> * <ol> * <li>field {@link SensitiveWords}, {@link SensitiveWordsJsonValueProcessor}??</li> * </ol> * </blockquote> * * @param obj * the obj * @return the string * @see com.sunchenbin.store.feilong.core.lang.reflect.FieldUtil#getAllFieldNameAndValueMap(Object) * @see org.apache.commons.lang3.reflect.FieldUtils#getFieldsListWithAnnotation(Class, Class) * @since 1.4.0 */ public static String formatObjectFiledsNameAndValueMap(Object obj) { Map<String, Object> map = FieldUtil.getAllFieldNameAndValueMap(obj); //***************************************************************************** List<Field> fieldsListWithAnnotation = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), SensitiveWords.class); JsonFormatConfig jsonFormatConfig = null; if (Validator.isNotNullOrEmpty(fieldsListWithAnnotation)) { SensitiveWordsJsonValueProcessor sensitiveWordsJsonValueProcessor = new SensitiveWordsJsonValueProcessor(); Map<String, JsonValueProcessor> propertyNameAndJsonValueProcessorMap = new HashMap<String, JsonValueProcessor>(); for (Field field : fieldsListWithAnnotation) { propertyNameAndJsonValueProcessorMap.put(field.getName(), sensitiveWordsJsonValueProcessor); } jsonFormatConfig = new JsonFormatConfig(); jsonFormatConfig.setPropertyNameAndJsonValueProcessorMap(propertyNameAndJsonValueProcessorMap); } return format(map, jsonFormatConfig); }