/** * Returns name of field whether public member or method. * * @param fieldOrMethod field or method * @return field or method name */ public static String getFieldName(AccessibleObject fieldOrMethod) { if (fieldOrMethod instanceof Field) { return ((Field) fieldOrMethod).getName(); } Method method = (Method) fieldOrMethod; String name = method.getName(); boolean hasValidParameterCount = method.getParameterCount() == 0 || isRequestScopeableMethod(method); if (name.startsWith("get") && hasValidParameterCount) { return StringUtils.uncapitalize(name.substring("get".length())); } if (name.startsWith("is") && hasValidParameterCount) { return StringUtils.uncapitalize(name.substring("is".length())); } return null; }
/** * Returns name of field whether public member or method. * * @param fieldOrMethod field or method * @return field or method name */ public static String getFieldName(AccessibleObject fieldOrMethod) { if (fieldOrMethod instanceof Field) { return ((Field) fieldOrMethod).getName(); } Method method = (Method) fieldOrMethod; String name = method.getName(); boolean hasValidParameterCount = method.getParameterCount() == 0 || isRequestScopeableMethod(method); if (name.startsWith("get") && hasValidParameterCount) { return StringUtils.uncapitalize(name.substring("get".length())); } if (name.startsWith("is") && hasValidParameterCount) { return StringUtils.uncapitalize(name.substring("is".length())); } return null; }
/** * Bind an attribute or relationship. * * @param fieldOrMethod Field or method to bind */ private void bindAttrOrRelation(AccessibleObject fieldOrMethod) { boolean isRelation = RELATIONSHIP_TYPES.stream().anyMatch(fieldOrMethod::isAnnotationPresent); String fieldName = getFieldName(fieldOrMethod); Class<?> fieldType = getFieldType(fieldOrMethod); if (fieldName == null || "id".equals(fieldName) || "class".equals(fieldName) || OBJ_METHODS.contains(fieldOrMethod)) { return; // Reserved } if (fieldOrMethod instanceof Method) { Method method = (Method) fieldOrMethod; requestScopeableMethods.put(method, isRequestScopeableMethod(method)); } if (isRelation) { bindRelation(fieldOrMethod, fieldName, fieldType); } else { bindAttr(fieldOrMethod, fieldName, fieldType); } }
/** * Bind an attribute or relationship. * * @param fieldOrMethod Field or method to bind */ private void bindAttrOrRelation(AccessibleObject fieldOrMethod) { boolean isRelation = RELATIONSHIP_TYPES.stream().anyMatch(fieldOrMethod::isAnnotationPresent); String fieldName = getFieldName(fieldOrMethod); Class<?> fieldType = getFieldType(fieldOrMethod); if (fieldName == null || "id".equals(fieldName) || "class".equals(fieldName) || OBJ_METHODS.contains(fieldOrMethod)) { return; // Reserved } if (fieldOrMethod instanceof Method) { Method method = (Method) fieldOrMethod; requestScopeableMethods.put(method, isRequestScopeableMethod(method)); } if (isRelation) { bindRelation(fieldOrMethod, fieldName, fieldType); } else { bindAttr(fieldOrMethod, fieldName, fieldType); } }