java: rollback MessagePack.java

This commit is contained in:
Muga Nishizawa 2010-11-19 02:57:42 +09:00
parent b5617f7df9
commit dd452b05e3

View File

@ -161,21 +161,11 @@ public class MessagePack {
} else {
if (MessagePackTemplateProvider.class.isAssignableFrom(target)) {
try {
Method m = target.getMethod("getTemplate", new Class[0]);
tmpl = (Template)m.invoke(null, new Object[0]);
tmpl = ((MessagePackTemplateProvider) target.newInstance()).getTemplate();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException 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 {
tmpl = DynamicTemplate.create(target);
@ -187,6 +177,22 @@ public class MessagePack {
CustomUnpacker.register(target, tmpl);
}
public static class Foo implements MessagePackTemplateProvider {
public int f1;
public int f2;
public Foo() {}
public Template getTemplate() {
return DynamicTemplate.create(Foo.class);
}
}
public static void main(String[] args) throws Exception {
MessagePack.register(Foo.class);
}
public static void register(Class<?> target, FieldList opts) {
Template tmpl = DynamicTemplate.create(target, opts);
CustomPacker.register(target, tmpl);