|
|
|
@ -24,6 +24,8 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -45,6 +47,7 @@ public final class PropertyElf
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Method> methods = Arrays.asList(target.getClass().getMethods());
|
|
|
|
|
Enumeration<?> propertyNames = properties.propertyNames();
|
|
|
|
|
while (propertyNames.hasMoreElements()) {
|
|
|
|
|
Object key = propertyNames.nextElement();
|
|
|
|
@ -59,7 +62,7 @@ public final class PropertyElf
|
|
|
|
|
config.addDataSourceProperty(propName.substring("dataSource.".length()), propValue);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setProperty(target, propName, propValue);
|
|
|
|
|
setProperty(target, propName, propValue, methods);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -73,9 +76,11 @@ public final class PropertyElf
|
|
|
|
|
public static Set<String> getPropertyNames(Class<?> targetClass)
|
|
|
|
|
{
|
|
|
|
|
HashSet<String> set = new HashSet<>();
|
|
|
|
|
Pattern pattern = Pattern.compile("(get|is)[A-Z].+");
|
|
|
|
|
Matcher matcher = pattern.matcher("");
|
|
|
|
|
for (Method method : targetClass.getMethods()) {
|
|
|
|
|
String name = method.getName();
|
|
|
|
|
if (name.matches("(get|is)[A-Z].+") && method.getParameterTypes().length == 0) {
|
|
|
|
|
if (method.getParameterTypes().length == 0 && matcher.reset(name).matches()) {
|
|
|
|
|
name = name.replaceFirst("(get|is)", "");
|
|
|
|
|
try {
|
|
|
|
|
if (targetClass.getMethod("set" + name, method.getReturnType()) != null) {
|
|
|
|
@ -120,12 +125,11 @@ public final class PropertyElf
|
|
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void setProperty(Object target, String propName, Object propValue)
|
|
|
|
|
private static void setProperty(Object target, String propName, Object propValue, List<Method> methods)
|
|
|
|
|
{
|
|
|
|
|
Method writeMethod = null;
|
|
|
|
|
String methodName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
|
|
|
|
|
|
|
|
|
|
List<Method> methods = Arrays.asList(target.getClass().getMethods());
|
|
|
|
|
for (Method method : methods) {
|
|
|
|
|
if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) {
|
|
|
|
|
writeMethod = method;
|
|
|
|
@ -140,7 +144,7 @@ public final class PropertyElf
|
|
|
|
|
writeMethod = method;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (writeMethod == null) {
|
|
|
|
|