/** * Determine whether the given {@link Method method} should be validated depending on the given {@code executableTypes}. * * @param method method to be examined. * @param allowImplicit allows check for {@link ExecutableType#IMPLICIT} type. * @param executableTypes executable types assigned to the method. * @return {@code true} if the method should be validated, {@code false otherwise}. */ private boolean validateMethod(final Method method, final boolean allowImplicit, final Set<ExecutableType> executableTypes) { if (executableTypes.contains(ExecutableType.ALL) || (allowImplicit && executableTypes.contains(ExecutableType.IMPLICIT))) { return true; } return ReflectionHelper.isGetter(method) ? executableTypes.contains(ExecutableType.GETTER_METHODS) : executableTypes.contains(ExecutableType.NON_GETTER_METHODS); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
&& ReflectionHelper.isGetter(method) && (propertyType == null || propertyType.isAssignableFrom(method.getReturnType()))) { return AccessController.doPrivileged(ReflectionHelper.findMethodOnClassPA(clazz, method));
/** * Get accessor method mappings (field -> getter/setter) for given class. * * @param clazz entity class to obtain property methods for. * @param isGetter flag determining whether to look for getters or setters. * @return non-null map of field-accessor mappings. */ public static Map<String, Method> getPropertyMethods(final Class<?> clazz, final boolean isGetter) { final Map<String, Method> methods = new HashMap<>(); for (final Method method : AccessController.doPrivileged(ReflectionHelper.getDeclaredMethodsPA(clazz))) { if ((isGetter && ReflectionHelper.isGetter(method)) || (!isGetter && ReflectionHelper.isSetter(method))) { methods.put(ReflectionHelper.getPropertyName(method), method); } } final Class<?> parent = clazz.getSuperclass(); // We're interested in fields/accessors in superclasses but not those from i.e. Object/Enum. if (parent != null && !parent.getPackage().getName().startsWith("java.lang")) { methods.putAll(getPropertyMethods(parent, isGetter)); } return methods; }
/** * Process the given {@code method} and {@code validationMethod} on given {@code clazz} and determine whether this method * should be validated or not. * * @param clazz class on which the method will be invoked. * @param method method to be examined. * @param validationMethod method used for cache. * @param forceValidation forces validation of a getter if no {@link ValidateOnExecution} annotation is present. */ private void processMethod(final Class<?> clazz, final Method method, final Method validationMethod, final boolean forceValidation) { final Deque<Class<?>> hierarchy = getValidationClassHierarchy(clazz); Boolean validateMethod = processAnnotation(method, hierarchy, checkOverrides); if (validateMethod != null) { validateMethodCache.putIfAbsent(validationMethod, validateMethod); validateGetterCache.putIfAbsent(validationMethod, validateMethod); } // Return value from validation.xml. if (!validateMethodCache.containsKey(validationMethod)) { final Set<ExecutableType> defaultValidatedExecutableTypes = config.getBootstrapConfiguration() .getDefaultValidatedExecutableTypes(); validateMethod = validateMethod(method, false, defaultValidatedExecutableTypes); validateGetterCache.putIfAbsent(validationMethod, validateMethod || forceValidation); // When validateMethod is called and no ValidateOnExecution annotation is present we want to validate getter resource // methods by default (see SPEC). validateMethodCache.putIfAbsent(validationMethod, ReflectionHelper.isGetter(validationMethod) || validateMethod); } }
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
} else { fieldName = ReflectionHelper.getPropertyName(method); fieldType = ReflectionHelper.isGetter(method) ? method.getGenericReturnType() : method .getGenericParameterTypes()[0];
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
/** * Determine whether the given {@link Method method} should be validated depending on the given {@code executableTypes}. * * @param method method to be examined. * @param allowImplicit allows check for {@link ExecutableType#IMPLICIT} type. * @param executableTypes executable types assigned to the method. * @return {@code true} if the method should be validated, {@code false otherwise}. */ private boolean validateMethod(final Method method, final boolean allowImplicit, final Set<ExecutableType> executableTypes) { if (executableTypes.contains(ExecutableType.ALL) || (allowImplicit && executableTypes.contains(ExecutableType.IMPLICIT))) { return true; } return ReflectionHelper.isGetter(method) ? executableTypes.contains(ExecutableType.GETTER_METHODS) : executableTypes.contains(ExecutableType.NON_GETTER_METHODS); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Determine property (field) name from given getter/setter method. * * @param method method to be examined. * @return property (field) name. */ public static String getPropertyName(final Method method) { if (!isGetter(method) && !isSetter(method)) { throw new IllegalArgumentException(LocalizationMessages.METHOD_NOT_GETTER_NOR_SETTER()); } final String methodName = method.getName(); final int offset = methodName.startsWith("is") ? 2 : 3; final char[] chars = methodName.toCharArray(); chars[offset] = Character.toLowerCase(chars[offset]); return new String(chars, offset, chars.length - offset); }
/** * Get accessor method mappings (field -> getter/setter) for given class. * * @param clazz entity class to obtain property methods for. * @param isGetter flag determining whether to look for getters or setters. * @return non-null map of field-accessor mappings. */ public static Map<String, Method> getPropertyMethods(final Class<?> clazz, final boolean isGetter) { final Map<String, Method> methods = new HashMap<>(); for (final Method method : AccessController.doPrivileged(ReflectionHelper.getDeclaredMethodsPA(clazz))) { if ((isGetter && ReflectionHelper.isGetter(method)) || (!isGetter && ReflectionHelper.isSetter(method))) { methods.put(ReflectionHelper.getPropertyName(method), method); } } final Class<?> parent = clazz.getSuperclass(); // We're interested in fields/accessors in superclasses but not those from i.e. Object/Enum. if (parent != null && !parent.getPackage().getName().startsWith("java.lang")) { methods.putAll(getPropertyMethods(parent, isGetter)); } return methods; }
/** * Get accessor method mappings (field -> getter/setter) for given class. * * @param clazz entity class to obtain property methods for. * @param isGetter flag determining whether to look for getters or setters. * @return non-null map of field-accessor mappings. */ public static Map<String, Method> getPropertyMethods(final Class<?> clazz, final boolean isGetter) { final Map<String, Method> methods = Maps.newHashMap(); for (final Method method : AccessController.doPrivileged(ReflectionHelper.getDeclaredMethodsPA(clazz))) { if ((isGetter && ReflectionHelper.isGetter(method)) || (!isGetter && ReflectionHelper.isSetter(method))) { methods.put(ReflectionHelper.getPropertyName(method), method); } } final Class<?> parent = clazz.getSuperclass(); // We're interested in fields/accessors in superclasses but not those from i.e. Object/Enum. if (parent != null && !parent.getPackage().getName().startsWith("java.lang")) { methods.putAll(getPropertyMethods(parent, isGetter)); } return methods; }
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));