This commit is contained in:
@@ -129,7 +129,6 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final T result = this.creator.create();
|
final T result = this.creator.create();
|
||||||
final AtomicInteger index = new AtomicInteger();
|
final AtomicInteger index = new AtomicInteger();
|
||||||
while (in.hasNext()) {
|
while (in.hasNext()) {
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
|||||||
|
|
||||||
protected Factory factory;
|
protected Factory factory;
|
||||||
|
|
||||||
|
private boolean inited = false;
|
||||||
|
|
||||||
|
private final Object lock = new Object();
|
||||||
|
|
||||||
protected ObjectEncoder(Type type) {
|
protected ObjectEncoder(Type type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
if (type instanceof ParameterizedType) {
|
if (type instanceof ParameterizedType) {
|
||||||
@@ -131,52 +135,59 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
|||||||
|
|
||||||
public void init(final Factory factory) {
|
public void init(final Factory factory) {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
if (type == Object.class) return;
|
|
||||||
//if (!(type instanceof Class)) throw new ConvertException("[" + type + "] is no a class");
|
|
||||||
final Class clazz = this.typeClass;
|
|
||||||
final Set<EnMember> list = new HashSet<>();
|
|
||||||
final Type[] virGenericTypes = this.typeClass.getTypeParameters();
|
|
||||||
final Type[] realGenericTypes = (type instanceof ParameterizedType) ? ((ParameterizedType) type).getActualTypeArguments() : null;
|
|
||||||
if (realGenericTypes != null) {
|
|
||||||
// println(type + "," + Arrays.toString(virGenericTypes) + ", " + Arrays.toString(realGenericTypes));
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
ConvertColumnEntry ref;
|
if (type == Object.class) return;
|
||||||
for (final Field field : clazz.getFields()) {
|
//if (!(type instanceof Class)) throw new ConvertException("[" + type + "] is no a class");
|
||||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
final Class clazz = this.typeClass;
|
||||||
ref = factory.findRef(field);
|
final Set<EnMember> list = new HashSet<>();
|
||||||
if (ref != null && ref.ignore()) continue;
|
final Type[] virGenericTypes = this.typeClass.getTypeParameters();
|
||||||
Type t = makeGenericType(field.getGenericType(), virGenericTypes, realGenericTypes);
|
final Type[] realGenericTypes = (type instanceof ParameterizedType) ? ((ParameterizedType) type).getActualTypeArguments() : null;
|
||||||
list.add(new EnMember(createAttribute(factory, clazz, field, null, null), factory.loadEncoder(t)));
|
if (realGenericTypes != null) {
|
||||||
|
// println(type + "," + Arrays.toString(virGenericTypes) + ", " + Arrays.toString(realGenericTypes));
|
||||||
}
|
}
|
||||||
final boolean reversible = factory.isReversible();
|
try {
|
||||||
for (final Method method : clazz.getMethods()) {
|
ConvertColumnEntry ref;
|
||||||
if (Modifier.isStatic(method.getModifiers())) continue;
|
for (final Field field : clazz.getFields()) {
|
||||||
if (Modifier.isAbstract(method.getModifiers())) continue;
|
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||||
if (method.isSynthetic()) continue;
|
ref = factory.findRef(field);
|
||||||
if (method.getName().length() < 3) continue;
|
if (ref != null && ref.ignore()) continue;
|
||||||
if (method.getName().equals("getClass")) continue;
|
Type t = makeGenericType(field.getGenericType(), virGenericTypes, realGenericTypes);
|
||||||
if (!method.getName().startsWith("is") && !method.getName().startsWith("get")) continue;
|
list.add(new EnMember(createAttribute(factory, clazz, field, null, null), factory.loadEncoder(t)));
|
||||||
if (method.getParameterTypes().length != 0) continue;
|
|
||||||
if (method.getReturnType() == void.class) continue;
|
|
||||||
if (reversible) {
|
|
||||||
boolean is = method.getName().startsWith("is");
|
|
||||||
try {
|
|
||||||
clazz.getMethod(method.getName().replaceFirst(is ? "is" : "get", "set"), method.getReturnType());
|
|
||||||
} catch (Exception e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ref = factory.findRef(method);
|
final boolean reversible = factory.isReversible();
|
||||||
if (ref != null && ref.ignore()) continue;
|
for (final Method method : clazz.getMethods()) {
|
||||||
Type t = makeGenericType(method.getGenericReturnType(), virGenericTypes, realGenericTypes);
|
if (Modifier.isStatic(method.getModifiers())) continue;
|
||||||
list.add(new EnMember(createAttribute(factory, clazz, null, method, null), factory.loadEncoder(t)));
|
if (Modifier.isAbstract(method.getModifiers())) continue;
|
||||||
}
|
if (method.isSynthetic()) continue;
|
||||||
this.members = list.toArray(new EnMember[list.size()]);
|
if (method.getName().length() < 3) continue;
|
||||||
Arrays.sort(this.members);
|
if (method.getName().equals("getClass")) continue;
|
||||||
|
if (!method.getName().startsWith("is") && !method.getName().startsWith("get")) continue;
|
||||||
|
if (method.getParameterTypes().length != 0) continue;
|
||||||
|
if (method.getReturnType() == void.class) continue;
|
||||||
|
if (reversible) {
|
||||||
|
boolean is = method.getName().startsWith("is");
|
||||||
|
try {
|
||||||
|
clazz.getMethod(method.getName().replaceFirst(is ? "is" : "get", "set"), method.getReturnType());
|
||||||
|
} catch (Exception e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ref = factory.findRef(method);
|
||||||
|
if (ref != null && ref.ignore()) continue;
|
||||||
|
Type t = makeGenericType(method.getGenericReturnType(), virGenericTypes, realGenericTypes);
|
||||||
|
list.add(new EnMember(createAttribute(factory, clazz, null, method, null), factory.loadEncoder(t)));
|
||||||
|
}
|
||||||
|
this.members = list.toArray(new EnMember[list.size()]);
|
||||||
|
Arrays.sort(this.members);
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new ConvertException(ex);
|
throw new ConvertException(ex);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
inited = true;
|
||||||
|
synchronized (lock) {
|
||||||
|
lock.notifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +198,15 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
|||||||
out.writeNull();
|
out.writeNull();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.inited) {
|
||||||
|
synchronized (lock) {
|
||||||
|
try {
|
||||||
|
lock.wait();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (value != null && value.getClass() != this.typeClass) {
|
if (value != null && value.getClass() != this.typeClass) {
|
||||||
final Class clz = value.getClass();
|
final Class clz = value.getClass();
|
||||||
out.wirteClassName(factory.getEntity(clz));
|
out.wirteClassName(factory.getEntity(clz));
|
||||||
|
|||||||
Reference in New Issue
Block a user