This commit is contained in:
RedKale
2016-02-16 10:16:09 +08:00
parent ce2293fe24
commit afefc16f5e
16 changed files with 35 additions and 35 deletions

View File

@@ -16,9 +16,9 @@ import java.lang.reflect.Type;
*/ */
public final class AnyEncoder<T> implements Encodeable<Writer, T> { public final class AnyEncoder<T> implements Encodeable<Writer, T> {
final Factory factory; final ConvertFactory factory;
AnyEncoder(Factory factory) { AnyEncoder(ConvertFactory factory) {
this.factory = factory; this.factory = factory;
} }

View File

@@ -30,7 +30,7 @@ public final class ArrayDecoder<T> implements Decodeable<Reader, T[]> {
private final Decodeable<Reader, T> decoder; private final Decodeable<Reader, T> decoder;
public ArrayDecoder(final Factory factory, final Type type) { public ArrayDecoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof GenericArrayType) { if (type instanceof GenericArrayType) {
Type t = ((GenericArrayType) type).getGenericComponentType(); Type t = ((GenericArrayType) type).getGenericComponentType();

View File

@@ -29,7 +29,7 @@ public final class ArrayEncoder<T> implements Encodeable<Writer, T[]> {
private final Encodeable<Writer, Object> encoder; private final Encodeable<Writer, Object> encoder;
public ArrayEncoder(final Factory factory, final Type type) { public ArrayEncoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof GenericArrayType) { if (type instanceof GenericArrayType) {
Type t = ((GenericArrayType) type).getGenericComponentType(); Type t = ((GenericArrayType) type).getGenericComponentType();

View File

@@ -32,7 +32,7 @@ public final class CollectionDecoder<T> implements Decodeable<Reader, Collection
private final Decodeable<Reader, T> decoder; private final Decodeable<Reader, T> decoder;
public CollectionDecoder(final Factory factory, final Type type) { public CollectionDecoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) type; final ParameterizedType pt = (ParameterizedType) type;

View File

@@ -24,7 +24,7 @@ public final class CollectionEncoder<T> implements Encodeable<Writer, Collection
private final Encodeable<Writer, Object> encoder; private final Encodeable<Writer, Object> encoder;
public CollectionEncoder(final Factory factory, final Type type) { public CollectionEncoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
Type t = ((ParameterizedType) type).getActualTypeArguments()[0]; Type t = ((ParameterizedType) type).getActualTypeArguments()[0];

View File

@@ -17,13 +17,13 @@ package org.redkale.convert;
*/ */
public abstract class Convert<R extends Reader, W extends Writer> { public abstract class Convert<R extends Reader, W extends Writer> {
protected final Factory<R, W> factory; protected final ConvertFactory<R, W> factory;
protected Convert(Factory<R, W> factory) { protected Convert(ConvertFactory<R, W> factory) {
this.factory = factory; this.factory = factory;
} }
public Factory<R, W> getFactory() { public ConvertFactory<R, W> getFactory() {
return this.factory; return this.factory;
} }
} }

View File

@@ -29,9 +29,9 @@ import org.redkale.util.*;
* @param <W> Writer输出的子类 * @param <W> Writer输出的子类
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public abstract class Factory<R extends Reader, W extends Writer> { public abstract class ConvertFactory<R extends Reader, W extends Writer> {
private final Factory parent; private final ConvertFactory parent;
protected Convert<R, W> convert; protected Convert<R, W> convert;
@@ -54,7 +54,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
private boolean skipAllIgnore = false; private boolean skipAllIgnore = false;
protected Factory(Factory<R, W> parent, boolean tiny) { protected ConvertFactory(ConvertFactory<R, W> parent, boolean tiny) {
this.tiny = tiny; this.tiny = tiny;
this.parent = parent; this.parent = parent;
if (parent == null) { if (parent == null) {
@@ -108,7 +108,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
} }
} }
public Factory parent() { public ConvertFactory parent() {
return this.parent; return this.parent;
} }
@@ -116,15 +116,15 @@ public abstract class Factory<R extends Reader, W extends Writer> {
public abstract boolean isReversible(); public abstract boolean isReversible();
public abstract Factory createChild(); public abstract ConvertFactory createChild();
public abstract Factory createChild(boolean tiny); public abstract ConvertFactory createChild(boolean tiny);
public Convert getConvert() { public Convert getConvert() {
return convert; return convert;
} }
public Factory tiny(boolean tiny) { public ConvertFactory tiny(boolean tiny) {
this.tiny = tiny; this.tiny = tiny;
return this; return this;
} }
@@ -378,7 +378,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
if (!Modifier.isStatic(method.getModifiers())) continue; if (!Modifier.isStatic(method.getModifiers())) continue;
Class[] paramTypes = method.getParameterTypes(); Class[] paramTypes = method.getParameterTypes();
if (paramTypes.length != 1) continue; if (paramTypes.length != 1) continue;
if (paramTypes[0] != Factory.class && paramTypes[0] != this.getClass()) continue; if (paramTypes[0] != ConvertFactory.class && paramTypes[0] != this.getClass()) continue;
if (!Decodeable.class.isAssignableFrom(method.getReturnType())) continue; if (!Decodeable.class.isAssignableFrom(method.getReturnType())) continue;
try { try {
method.setAccessible(true); method.setAccessible(true);
@@ -458,7 +458,7 @@ public abstract class Factory<R extends Reader, W extends Writer> {
if (!Modifier.isStatic(method.getModifiers())) continue; if (!Modifier.isStatic(method.getModifiers())) continue;
Class[] paramTypes = method.getParameterTypes(); Class[] paramTypes = method.getParameterTypes();
if (paramTypes.length != 1) continue; if (paramTypes.length != 1) continue;
if (paramTypes[0] != Factory.class && paramTypes[0] != this.getClass()) continue; if (paramTypes[0] != ConvertFactory.class && paramTypes[0] != this.getClass()) continue;
if (!Encodeable.class.isAssignableFrom(method.getReturnType())) continue; if (!Encodeable.class.isAssignableFrom(method.getReturnType())) continue;
try { try {
method.setAccessible(true); method.setAccessible(true);

View File

@@ -34,7 +34,7 @@ public final class DeMember<R extends Reader, T, F> implements Comparable<DeMemb
this.decoder = decoder; this.decoder = decoder;
} }
public static <R extends Reader, T, F> DeMember<R, T, F> create(final Factory factory, final Class<T> clazz, final String fieldname) { public static <R extends Reader, T, F> DeMember<R, T, F> create(final ConvertFactory factory, final Class<T> clazz, final String fieldname) {
try { try {
Field field = clazz.getDeclaredField(fieldname); Field field = clazz.getDeclaredField(fieldname);
return new DeMember<>(Attribute.create(field), factory.loadDecoder(field.getGenericType())); return new DeMember<>(Attribute.create(field), factory.loadDecoder(field.getGenericType()));

View File

@@ -39,7 +39,7 @@ public final class EnMember<W extends Writer, T, F> implements Comparable<EnMemb
//this.isnumber = Number.class.isAssignableFrom(t) || (!this.isbool && t.isPrimitive()); //this.isnumber = Number.class.isAssignableFrom(t) || (!this.isbool && t.isPrimitive());
} }
public static <W extends Writer, T, F> EnMember<W, T, F> create(final Factory factory, final Class<T> clazz, final String fieldname) { public static <W extends Writer, T, F> EnMember<W, T, F> create(final ConvertFactory factory, final Class<T> clazz, final String fieldname) {
try { try {
Field field = clazz.getDeclaredField(fieldname); Field field = clazz.getDeclaredField(fieldname);
return new EnMember<>(Attribute.create(field), factory.loadEncoder(field.getGenericType())); return new EnMember<>(Attribute.create(field), factory.loadEncoder(field.getGenericType()));

View File

@@ -32,7 +32,7 @@ public final class MapDecoder<K, V> implements Decodeable<Reader, Map<K, V>> {
private final Decodeable<Reader, V> valueDecoder; private final Decodeable<Reader, V> valueDecoder;
public MapDecoder(final Factory factory, final Type type) { public MapDecoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) type; final ParameterizedType pt = (ParameterizedType) type;

View File

@@ -27,7 +27,7 @@ public final class MapEncoder<K, V> implements Encodeable<Writer, Map<K, V>> {
private final Encodeable<Writer, V> valencoder; private final Encodeable<Writer, V> valencoder;
public MapEncoder(final Factory factory, final Type type) { public MapEncoder(final ConvertFactory factory, final Type type) {
this.type = type; this.type = type;
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
final Type[] pt = ((ParameterizedType) type).getActualTypeArguments(); final Type[] pt = ((ParameterizedType) type).getActualTypeArguments();

View File

@@ -34,7 +34,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
protected DeMember<R, T, ?>[] members; protected DeMember<R, T, ?>[] members;
protected Factory factory; protected ConvertFactory factory;
private boolean inited = false; private boolean inited = false;
@@ -51,7 +51,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
this.members = new DeMember[0]; this.members = new DeMember[0];
} }
public void init(final Factory factory) { public void init(final ConvertFactory factory) {
this.factory = factory; this.factory = factory;
try { try {
if (type == Object.class) return; if (type == Object.class) return;
@@ -87,7 +87,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
if (!method.getName().startsWith("set")) continue; if (!method.getName().startsWith("set")) continue;
if (method.getParameterTypes().length != 1) continue; if (method.getParameterTypes().length != 1) continue;
if (method.getReturnType() != void.class) continue; if (method.getReturnType() != void.class) continue;
if (reversible && (cps == null || !ObjectEncoder.contains(cps, Factory.readGetSetFieldName(method)))) { if (reversible && (cps == null || !ObjectEncoder.contains(cps, ConvertFactory.readGetSetFieldName(method)))) {
boolean is = method.getParameterTypes()[0] == boolean.class || method.getParameterTypes()[0] == Boolean.class; boolean is = method.getParameterTypes()[0] == boolean.class || method.getParameterTypes()[0] == Boolean.class;
try { try {
clazz.getMethod(method.getName().replaceFirst("set", is ? "is" : "get")); clazz.getMethod(method.getName().replaceFirst("set", is ? "is" : "get"));

View File

@@ -30,7 +30,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
protected EnMember[] members; protected EnMember[] members;
protected Factory factory; protected ConvertFactory factory;
private boolean inited = false; private boolean inited = false;
@@ -47,7 +47,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
this.members = new EnMember[0]; this.members = new EnMember[0];
} }
public void init(final Factory factory) { public void init(final ConvertFactory factory) {
this.factory = factory; this.factory = factory;
try { try {
if (type == Object.class) return; if (type == Object.class) return;
@@ -80,7 +80,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
if (!method.getName().startsWith("is") && !method.getName().startsWith("get")) continue; if (!method.getName().startsWith("is") && !method.getName().startsWith("get")) continue;
if (method.getParameterTypes().length != 0) continue; if (method.getParameterTypes().length != 0) continue;
if (method.getReturnType() == void.class) continue; if (method.getReturnType() == void.class) continue;
if (reversible && (cps == null || !contains(cps, Factory.readGetSetFieldName(method)))) { if (reversible && (cps == null || !contains(cps, ConvertFactory.readGetSetFieldName(method)))) {
boolean is = method.getName().startsWith("is"); boolean is = method.getName().startsWith("is");
try { try {
clazz.getMethod(method.getName().replaceFirst(is ? "is" : "get", "set"), method.getReturnType()); clazz.getMethod(method.getName().replaceFirst(is ? "is" : "get", "set"), method.getReturnType());
@@ -246,14 +246,14 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
} }
} }
static Attribute createAttribute(final Factory factory, Class clazz, final Field field, final Method getter, final Method setter) { static Attribute createAttribute(final ConvertFactory factory, Class clazz, final Field field, final Method getter, final Method setter) {
String fieldalias; String fieldalias;
if (field != null) { // public field if (field != null) { // public field
ConvertColumnEntry ref = factory.findRef(field); ConvertColumnEntry ref = factory.findRef(field);
fieldalias = ref == null || ref.name().isEmpty() ? field.getName() : ref.name(); fieldalias = ref == null || ref.name().isEmpty() ? field.getName() : ref.name();
} else if (getter != null) { } else if (getter != null) {
ConvertColumnEntry ref = factory.findRef(getter); ConvertColumnEntry ref = factory.findRef(getter);
String mfieldname = Factory.readGetSetFieldName(getter); String mfieldname = ConvertFactory.readGetSetFieldName(getter);
if (ref == null) { if (ref == null) {
try { try {
ref = factory.findRef(clazz.getDeclaredField(mfieldname)); ref = factory.findRef(clazz.getDeclaredField(mfieldname));
@@ -263,7 +263,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name(); fieldalias = ref == null || ref.name().isEmpty() ? mfieldname : ref.name();
} else { // setter != null } else { // setter != null
ConvertColumnEntry ref = factory.findRef(setter); ConvertColumnEntry ref = factory.findRef(setter);
String mfieldname = Factory.readGetSetFieldName(setter); String mfieldname = ConvertFactory.readGetSetFieldName(setter);
if (ref == null) { if (ref == null) {
try { try {
ref = factory.findRef(clazz.getDeclaredField(mfieldname)); ref = factory.findRef(clazz.getDeclaredField(mfieldname));

View File

@@ -45,7 +45,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
private final boolean tiny; private final boolean tiny;
protected BsonConvert(Factory<BsonReader, BsonWriter> factory, boolean tiny) { protected BsonConvert(ConvertFactory<BsonReader, BsonWriter> factory, boolean tiny) {
super(factory); super(factory);
this.tiny = tiny; this.tiny = tiny;
} }

View File

@@ -15,7 +15,7 @@ import org.redkale.convert.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class BsonFactory extends Factory<BsonReader, BsonWriter> { public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
private static final BsonFactory instance = new BsonFactory(null, Boolean.getBoolean("convert.bson.tiny")); private static final BsonFactory instance = new BsonFactory(null, Boolean.getBoolean("convert.bson.tiny"));

View File

@@ -6,7 +6,7 @@
package org.redkale.convert.json; package org.redkale.convert.json;
import org.redkale.convert.ConvertType; import org.redkale.convert.ConvertType;
import org.redkale.convert.Factory; import org.redkale.convert.ConvertFactory;
import java.io.Serializable; import java.io.Serializable;
import java.math.*; import java.math.*;
import java.net.*; import java.net.*;
@@ -20,7 +20,7 @@ import org.redkale.util.*;
* *
* @author zhangjx * @author zhangjx
*/ */
public final class JsonFactory extends Factory<JsonReader, JsonWriter> { public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
private static final JsonFactory instance = new JsonFactory(null, Boolean.getBoolean("convert.json.tiny")); private static final JsonFactory instance = new JsonFactory(null, Boolean.getBoolean("convert.json.tiny"));