mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-02 01:41:02 +02:00
java: refactor register method in MessagePack.java for TemplateProvider
This commit is contained in:
parent
b73ca1ba3a
commit
b5617f7df9
@ -21,6 +21,9 @@ import java.io.OutputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.msgpack.util.codegen.DynamicTemplate;
|
import org.msgpack.util.codegen.DynamicTemplate;
|
||||||
import org.msgpack.util.codegen.DynamicOrdinalEnumTemplate;
|
import org.msgpack.util.codegen.DynamicOrdinalEnumTemplate;
|
||||||
import org.msgpack.util.codegen.FieldList;
|
import org.msgpack.util.codegen.FieldList;
|
||||||
@ -158,11 +161,21 @@ public class MessagePack {
|
|||||||
} else {
|
} else {
|
||||||
if (MessagePackTemplateProvider.class.isAssignableFrom(target)) {
|
if (MessagePackTemplateProvider.class.isAssignableFrom(target)) {
|
||||||
try {
|
try {
|
||||||
|
Method m = target.getMethod("getTemplate", new Class[0]);
|
||||||
|
tmpl = (Template)m.invoke(null, new Object[0]);
|
||||||
tmpl = ((MessagePackTemplateProvider) target.newInstance()).getTemplate();
|
tmpl = ((MessagePackTemplateProvider) target.newInstance()).getTemplate();
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmpl = DynamicTemplate.create(target);
|
tmpl = DynamicTemplate.create(target);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user