/** * Create a new ConfigGetter instance. * * @param configInterface The configuration interface. * @param method The method. */ public ConfigGetter(Class<?> configInterface, Method method) { super(configInterface, method); // not needed for defaulted method, but no harm. defaultValue = ConfigUtil.getDefaultValue(configInterface, method); sourceType = ConfigUtil.getSourceType(configInterface, method); // if (!String.class.equals(method.getReturnType())) factory = TypeFactory.getInstance(configInterface, method); }
/** * Create a new ConfigSetter instance. * * @param configInterface The configuration interface. * @param method The method. */ public ConfigSetter(Class<?> configInterface, Method method) { super(configInterface, method); Method getMethod = ConfigUtil.getGetMethod(configInterface, method); Preconditions.checkNotNullArgument(getMethod, String.format("Cannot find getter for config \"%s\" property \"%s\"", configInterface.getSimpleName(), getPropertyName())); sourceType = ConfigUtil.getSourceType(configInterface, method); if (!String.class.equals(ConfigUtil.getMethodType(method))) stringifier = TypeStringify.getInstance(configInterface, method); }
/** * Create a new ConfigAccessorMethod instance. * * @param configInterface The configuration interface. * @param method The method. */ protected ConfigAccessorMethod(Class<?> configInterface, Method method) { property = ConfigUtil.getPropertyName(configInterface, method); }
/** * Search for an annotation on a configuration interface method. In * addition to searching the method itself, the {@link #getGetMethod * plain get method} is also searched, as can the {@link * #getMethodType method type} be. * * @param configInterface The configuration interface. * @param method The method. * @param annotationType The annotation type of interest. * @param searchMethodType Whether to search the method type. * @return The annotation, or null. */ public static <T extends Annotation> T getAnnotation(Class<?> configInterface, Method method, Class<T> annotationType, boolean searchMethodType) { T annotation = method.getAnnotation(annotationType); if (annotation == null) { Method getMethod = getGetMethod(configInterface, method); if (getMethod != null) { annotation = getMethod.getAnnotation(annotationType); } if ((annotation == null) && searchMethodType) { String methodName = method.getName(); if (ACCESS_RE.matcher(methodName).matches()) { // Is the annotation present on the method type? Class<?> methodType = getMethodType(method); annotation = methodType.getAnnotation(annotationType); } } } return annotation; }
/** * Get the property name associated with a configuration interface method. * If a {@link Property} annotation is present, that value is returned. * Otherwise the {@link #getPropertyPrefix interface prefix} is concatenated * with the {@link #extendedUncapitalize uncapitalized} property name. * * @param configInterface The configuration interface. * @param method The method. * @return The property name. */ public static String getPropertyName(Class<?> configInterface, Method method) { Property property = getAnnotation(configInterface, method, Property.class, false); if (property != null) { return property.value(); } else { String prefix = getPropertyPrefix(configInterface); String methodName = method.getName(); Matcher matcher; if (((matcher = ACCESS_RE.matcher(methodName)).matches() || (matcher = LISTENER_RE.matcher(methodName)).matches()) && !"".equals(matcher.group(2))) { String prop = matcher.group(2); return prefix + extendedUncapitalize(prop); } else { throw new IllegalArgumentException("Unsupported method name: " + method); } } }
Class<?> methodType = ConfigUtil.getMethodType(method); try { Stringify stringify = ConfigUtil.getAnnotation(configInterface, method, Stringify.class, true); if (stringify != null) { if ("".equals(stringify.method())) { EnumStore mode = ConfigUtil.getAnnotation(configInterface, method, EnumStore.class, true); if (mode != null && EnumStoreMode.ID == mode.value()) { @SuppressWarnings("unchecked") Class<EnumClass> enumeration = (Class<EnumClass>) methodType; TypeStringify idStringify = getInferred(ConfigUtil.getEnumIdType(enumeration)); return new EnumClassStringify(idStringify);
@SuppressWarnings("unchecked") Class<EnumClass> enumeration = (Class<EnumClass>) type; EnumStore mode = getAnnotation(configInterface, method, EnumStore.class, true); if (mode != null && EnumStoreMode.ID == mode.value()) { Class<?> idType = getEnumIdType(enumeration); String name = "Default" + StringUtils.capitalize(ClassUtils.getShortClassName(idType)); Object value = getAnnotationValue(method, name); if (value != null) { Method fromId = enumeration.getDeclaredMethod("fromId", idType); Object value = getAnnotationValue(method, name); if (value != null) { TypeStringify stringConverter = TypeStringify.getInstance(configInterface, method);
returnType = ClassUtils.primitiveToWrapper(returnType); Factory factory = ConfigUtil.getAnnotation(configInterface, method, Factory.class, true); if (factory != null) { try { } else { if (EnumClass.class.isAssignableFrom(returnType)) { EnumStore mode = ConfigUtil.getAnnotation(configInterface, method, EnumStore.class, true); if (mode != null && EnumStoreMode.ID == mode.value()) { @SuppressWarnings("unchecked") Class<EnumClass> enumeration = (Class<EnumClass>) returnType; Class<?> idType = ConfigUtil.getEnumIdType(enumeration); TypeFactory idFactory = getInferred(idType); try {
public static SourceType getSourceType(Class<?> configInterface, Method method) { Source source = method.getAnnotation(Source.class); if (source == null) { Method getMethod = getGetMethod(configInterface, method); if (getMethod != null && !method.equals(getMethod)) { source = getMethod.getAnnotation(Source.class); } if (source == null) { source = configInterface.getAnnotation(Source.class); if (source == null) return SourceType.DATABASE; } } return source.type(); }
getMethod = configInterface.getMethod("get" + prop); } catch (NoSuchMethodException ex) { Class<?> methodType = getMethodType(method); try { getMethod = configInterface.getMethod("get" + prop, methodType);
@SuppressWarnings("unchecked") Class<EnumClass> enumeration = (Class<EnumClass>) method.getReturnType(); TypeStringify idStringify = TypeStringify.getInferred(ConfigUtil.getEnumIdType(enumeration)); return new EnumClassStringify(idStringify);