This commit is contained in:
wentch
2016-01-05 10:13:11 +08:00
parent 9c922debf2
commit 0fd1a61e0e

View File

@@ -29,7 +29,7 @@ public final class ResourceFactory {
private static final ResourceFactory instance = new ResourceFactory(null);
private final ConcurrentHashMap<Type, Intercepter> interceptmap = new ConcurrentHashMap();
private final ConcurrentHashMap<Type, ResourceHandler> interceptmap = new ConcurrentHashMap();
private final ConcurrentHashMap<Class<?>, ConcurrentHashMap<String, ?>> store = new ConcurrentHashMap();
@@ -59,7 +59,7 @@ public final class ResourceFactory {
if (rs != null) register("", rs.getClass(), rs);
}
public void add(final Type clazz, final Intercepter rs) {
public void add(final Type clazz, final ResourceHandler rs) {
if (clazz == null || rs == null) return;
interceptmap.put(clazz, rs);
}
@@ -203,8 +203,8 @@ public final class ResourceFactory {
}
}
if (rs == null) {
Intercepter it = findIntercepter(field.getGenericType(), field);
if (it != null) it.invoke(this, src, rcname, field, attachment);
ResourceHandler it = findHandler(field.getGenericType(), field);
if (it != null) it.execute(this, src, rcname, field, attachment);
continue;
}
if (!rs.getClass().isPrimitive() && classtype.isPrimitive()) {
@@ -234,21 +234,21 @@ public final class ResourceFactory {
}
}
private Intercepter findIntercepter(Type ft, Field field) {
Intercepter it = this.interceptmap.get(ft);
private ResourceHandler findHandler(Type ft, Field field) {
ResourceHandler it = this.interceptmap.get(ft);
if (it != null) return it;
Class c = field.getType();
for (Map.Entry<Type, Intercepter> en : this.interceptmap.entrySet()) {
for (Map.Entry<Type, ResourceHandler> en : this.interceptmap.entrySet()) {
Type t = en.getKey();
if (t == ft) return en.getValue();
if (t instanceof Class && (((Class) t)).isAssignableFrom(c)) return en.getValue();
}
return parent == null ? null : parent.findIntercepter(ft, field);
return parent == null ? null : parent.findHandler(ft, field);
}
public static interface Intercepter {
public static interface ResourceHandler {
public void invoke(ResourceFactory factory, Object src, String resourceName, Field field, Object attachment);
public void execute(ResourceFactory factory, Object src, String resourceName, Field field, Object attachment);
}
}