/** * This method returns true if the given annotation is present on the given field. * * @param fieldClass * @param fieldName * @param annotation * @return true if the given annotation is present */ public static boolean isAnnotationPresent(Class<?> fieldClass, String fieldName, Class<? extends Annotation> annotation) { ClassFields<?> classFields = ClassDataCacher.getInstance().getClassFields(fieldClass); try { return classFields.getFieldAnnotation(annotation, fieldName) != null; } catch (FieldnameNotFoundException e) { return false; } }
/** * Get the types for fields in a class * @return the map of fieldName -> field type */ public Map<String, Class<?>> getFieldTypes() { return getFieldTypes(null); }
/** * Capitalize a string * @param input any string * @return the string capitalized (e.g. myString -> MyString) */ public static String capitalize(String input) { return ClassFields.capitalize(input); }
/** * Checks if a field is valid for the given filter * * @param name the fieldName * @param filter (optional) indicates the fields to include in the check, can be null for defaults * @return true if this fieldName is valid, false otherwise */ public boolean isFieldNameValid(String name, FieldsFilter filter) { boolean valid = namesToProperties.containsKey(name); if (valid) { // the field is real so check to see if it is in this filter ClassProperty cp = getAnyPropertyOrFail(name); if ( isFieldInFilter(cp, filter) ) { valid = true; } else { valid = false; } } return valid; }
Map<String, Class<?>> readTypes = cf.getFieldTypes(FieldsFilter.SERIALIZABLE); Map<String, Class<?>> writeTypes = cf.getFieldTypes(FieldsFilter.WRITEABLE); HashSet<String> requiredFieldNames = new HashSet<String>(cf.getFieldNamesWithAnnotation(EntityFieldRequired.class));
PropertyDescriptor[] descriptors = bi.getPropertyDescriptors(); if (descriptors != null) { populateProperties(descriptors); populateFields(false); } else { useIntrospector = false; List<ClassProperty> properties = findProperties(true); for (ClassProperty property : properties) { String fieldName = property.getFieldName(); populateFields(true); } else { populateFields(false); populateAnnotationsFields();
try { ClassProperty cp = cf.getClassProperty(name); value = findFieldValue(obj, cp); } catch (FieldnameNotFoundException fnfe) { ClassData<?> cd = cf.getClassData(); Field field = getFieldIfPossible(cd, name); if (field == null) {
for (int i = 0; i < getterMethods.length; i++) { if (getterMethods[i] != null && setterMethods[i] != null) { String fieldName = checkPropertyMethods(getterMethods[i], setterMethods[i]); if (!namesToProperties.containsKey(fieldName)) { ClassProperty p = new ClassProperty(fieldName, getterMethods[i], populateFields(publicFields); populateAnnotationsFields();
String name = makeFieldNameFromMethod(method.getName()); ClassProperty cp = getAnyPropertyOrFail(name); Annotation[] annotations = method.getAnnotations(); for (Annotation annotation : annotations) { try { String fieldName = field.getName(); if (! includeStaticFields && isStatic(field)) { ClassProperty cp = getAnyPropertyOrFail(fieldName); if (cp.getField() == null) { ClassProperty cp = getAnyPropertyOrFail(fieldName); cp.transientField = true; } catch (FieldnameNotFoundException e) {
if (classFields.getClassAnnotations().contains(PersistentColumnMappingPolicy.class)) { for (Annotation classAnnote : classFields.getClassAnnotations()) { if (PersistentColumnMappingPolicy.class.equals(classAnnote.annotationType())) { MappingPolicy mp = ((PersistentColumnMappingPolicy)classAnnote).policy(); Annotation annotation = classFields.getFieldAnnotation(PersistentTransient.class, property); if (annotation != null) { PersistentColumnName annotation = (PersistentColumnName) classFields.getFieldAnnotation(PersistentColumnName.class, property); if (annotation != null) { column = annotation.value();
/** * SPECIAL METHOD: accesses the internal data<br/> * Returns a field property object for any field (not limited to only complete fields) * * @param name the fieldName * @return the Property object which holds information about a field * @throws FieldnameNotFoundException if this fieldName is invalid */ public ClassProperty getClassProperty(String name) { ClassProperty cp = getAnyPropertyOrFail(name); return cp; }
if (cf != null && !mode.equals(cf.getFieldFindMode())) { cf = null; cf = new ClassFields<T>(cls, mode, false, this.includeClassField); getReflectionCache().put(cls, cf); cacheMisses++;
nestedClass = cf.getFieldType(name); fieldType = cf.getFieldType(targetName); } catch (FieldnameNotFoundException fnfe) { ClassData<?> cd = cf.getClassData(); Field field = getFieldIfPossible(cd, name); if (field == null) {
ClassProperty cp = cf.getClassProperty(name); if (! cp.isIndexed()) { throw new IllegalArgumentException("This field ("+name+") is not an indexed field");
/** * Convenience Method: <br/> * Gets the class data object which contains information about this class, * will retrieve this from the class data cache if available or generate it if not<br/> * This is also available from the {@link ClassFields} object * * @param <T> * @param cls any {@link Class} * @return the class data cache object (contains reflected data from this class) */ public <T> ClassData<T> getClassData(Class<T> cls) { ClassFields<T> cf = getClassFields(cls); return cf.getClassData(); }
/** * Create a tablename from a given class */ public static String makeTableNameFromClass(Class<?> pClass) { String tableName = null; // try to get from class annotations first ClassFields<?> classFields = ReflectUtils.getInstance().analyzeClass(pClass); if (classFields.getClassAnnotations().contains(PersistentTableName.class)) { for (Annotation classAnnote : classFields.getClassAnnotations()) { if (PersistentTableName.class.equals(classAnnote.annotationType())) { tableName = ((PersistentTableName)classAnnote).value(); break; } } } if (tableName == null) { String name = pClass.getSimpleName(); tableName = makeDBNameFromCamelCase(name); if (tableName.startsWith("_") && tableName.length() > 1) { tableName = tableName.substring(1); } } return tableName; }
Map<String, Class<?>> readTypes = cf.getFieldTypes(FieldsFilter.SERIALIZABLE); Map<String, Class<?>> writeTypes = cf.getFieldTypes(FieldsFilter.WRITEABLE); HashSet<String> requiredFieldNames = new HashSet<String>(cf.getFieldNamesWithAnnotation(EntityFieldRequired.class));
PropertyDescriptor[] descriptors = bi.getPropertyDescriptors(); if (descriptors != null) { populateProperties(descriptors); populateFields(false); } else { useIntrospector = false; List<ClassProperty> properties = findProperties(true); for (ClassProperty property : properties) { String fieldName = property.getFieldName(); populateFields(true); } else { populateFields(false); populateAnnotationsFields();
try { ClassProperty cp = cf.getClassProperty(name); value = findFieldValue(obj, cp); } catch (FieldnameNotFoundException fnfe) { ClassData<?> cd = cf.getClassData(); Field field = getFieldIfPossible(cd, name); if (field == null) {
for (int i = 0; i < getterMethods.length; i++) { if (getterMethods[i] != null && setterMethods[i] != null) { String fieldName = checkPropertyMethods(getterMethods[i], setterMethods[i]); if (!namesToProperties.containsKey(fieldName)) { ClassProperty p = new ClassProperty(fieldName, getterMethods[i], populateFields(publicFields); populateAnnotationsFields();