java: edit MessagePack.java for TemplateProvider

This commit is contained in:
Muga Nishizawa 2010-11-19 01:46:31 +09:00
parent 39ad071c4f
commit b73ca1ba3a
2 changed files with 34 additions and 1 deletions

View File

@ -156,7 +156,17 @@ public class MessagePack {
//} else if(Collection.isAssignableFrom(target)) {
//} else if(BigInteger.isAssignableFrom(target)) {
} else {
tmpl = DynamicTemplate.create(target);
if (MessagePackTemplateProvider.class.isAssignableFrom(target)) {
try {
tmpl = ((MessagePackTemplateProvider) target.newInstance()).getTemplate();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} else {
tmpl = DynamicTemplate.create(target);
}
}
CustomPacker.register(target, tmpl);

View File

@ -0,0 +1,23 @@
//
// MessagePack for Java
//
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack;
public interface MessagePackTemplateProvider {
Template getTemplate();
}