mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-03 01:54:45 +02:00
java: prototyped TemplateClassWriter, which is program for writing class file of generated tmplate class
This commit is contained in:
parent
a03418ab12
commit
27b89b237b
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for Java
|
// MessagePack for Java
|
||||||
//
|
//
|
||||||
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.msgpack.template.TemplateRegistry;
|
import org.msgpack.template.TemplateRegistry;
|
||||||
import org.msgpack.template.TemplateBuilder;
|
import org.msgpack.template.TemplateBuilder;
|
||||||
|
import org.msgpack.template.TemplateClassWriter;
|
||||||
import org.msgpack.template.FieldList;
|
import org.msgpack.template.FieldList;
|
||||||
|
|
||||||
public class MessagePack {
|
public class MessagePack {
|
||||||
@ -146,6 +147,10 @@ public class MessagePack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void write(Class<?> target, String directoryName) {
|
||||||
|
TemplateClassWriter.write(target, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public static void register(Class<?> target) {
|
public static void register(Class<?> target) {
|
||||||
TemplateRegistry.register(target);
|
TemplateRegistry.register(target);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for Java
|
// MessagePack for Java
|
||||||
//
|
//
|
||||||
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -122,9 +122,33 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
this.director = director;
|
this.director = director;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void write(final String className, final String directoryName) {
|
||||||
|
try {
|
||||||
|
reset(className, false);
|
||||||
|
buildClass();
|
||||||
|
buildConstructor();
|
||||||
|
buildMethodInit();
|
||||||
|
buildPackMethod();
|
||||||
|
buildUnpackMethod();
|
||||||
|
buildConvertMethod();
|
||||||
|
writeClassFile(directoryName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String code = getBuiltString();
|
||||||
|
if(code != null) {
|
||||||
|
LOG.error("builder: " + code, e);
|
||||||
|
throw new TemplateBuildException("cannot compile: " + code, e);
|
||||||
|
} else {
|
||||||
|
throw new TemplateBuildException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void writeClassFile(final String directoryName) throws CannotCompileException, IOException {
|
||||||
|
tmplCtClass.writeFile(directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
protected Template build(final String className) {
|
protected Template build(final String className) {
|
||||||
try {
|
try {
|
||||||
reset(className);
|
reset(className, true);
|
||||||
buildClass();
|
buildClass();
|
||||||
buildConstructor();
|
buildConstructor();
|
||||||
buildMethodInit();
|
buildMethodInit();
|
||||||
@ -143,8 +167,12 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reset(String className) {
|
protected void reset(String className, boolean isBuilt) {
|
||||||
|
if (isBuilt) {
|
||||||
tmplName = className + "_$$_Template" + director.nextSeqId();
|
tmplName = className + "_$$_Template" + director.nextSeqId();
|
||||||
|
} else {
|
||||||
|
tmplName = className + "_$$_Template";
|
||||||
|
}
|
||||||
tmplCtClass = director.makeCtClass(tmplName);
|
tmplCtClass = director.makeCtClass(tmplName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +282,15 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
super(director);
|
super(director);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, FieldEntry[] entries,
|
||||||
|
Template[] templates, final String directoryName) {
|
||||||
|
this.entries = entries;
|
||||||
|
this.templates = templates;
|
||||||
|
this.origClass = targetClass;
|
||||||
|
this.origName = this.origClass.getName();
|
||||||
|
write(this.origName, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries, Template[] templates) {
|
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries, Template[] templates) {
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
this.templates = templates;
|
this.templates = templates;
|
||||||
@ -279,6 +316,22 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
this.tmplCtClass.addConstructor(newCtCons);
|
this.tmplCtClass.addConstructor(newCtCons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Template buildInstance(Class<?> targetClass, Class<?> tmplClass, Template[] tmpls) {
|
||||||
|
try {
|
||||||
|
Constructor<?> cons = tmplClass.getConstructor(new Class[] {
|
||||||
|
Class.class,
|
||||||
|
Template[].class
|
||||||
|
});
|
||||||
|
Object tmpl = cons.newInstance(new Object[] {
|
||||||
|
targetClass,
|
||||||
|
tmpls
|
||||||
|
});
|
||||||
|
return (Template)tmpl;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new TemplateBuildException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Template buildInstance(Class<?> c) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
protected Template buildInstance(Class<?> c) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||||
Constructor<?> cons = c.getConstructor(new Class[] {
|
Constructor<?> cons = c.getConstructor(new Class[] {
|
||||||
Class.class,
|
Class.class,
|
||||||
@ -544,7 +597,39 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> loadTemplateClass(Class<?> targetClass) {
|
||||||
|
String tmplClassName = targetClass.getName() + "_$$_Template";
|
||||||
|
ClassLoader cl = this.getClass().getClassLoader();// TODO
|
||||||
|
try {
|
||||||
|
return cl.loadClass(tmplClassName);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
LOG.debug("Tmplate class not found: " + tmplClassName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Template initializeTemplate(Class<?> targetClass, Class<?> tmplClass, FieldEntry[] entries) {
|
||||||
|
Template[] tmpls = toTemplates(entries);
|
||||||
|
BuildContext bc = new BuildContext(this);
|
||||||
|
return bc.buildInstance(targetClass, tmplClass, tmpls);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, FieldEntry[] entries, String directoryName) {
|
||||||
|
Template[] tmpls = toTemplates(entries);
|
||||||
|
BuildContext bc = new BuildContext(this);
|
||||||
|
bc.writeTemplateClass(targetClass, entries, tmpls, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries) {
|
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries) {
|
||||||
|
Template[] tmpls = toTemplates(entries);
|
||||||
|
BuildContext bc = new BuildContext(this);
|
||||||
|
return bc.buildTemplate(targetClass, entries, tmpls);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Template[] toTemplates(FieldEntry[] from) {
|
||||||
// FIXME private / packagefields
|
// FIXME private / packagefields
|
||||||
//for(FieldEntry e : entries) {
|
//for(FieldEntry e : entries) {
|
||||||
// Field f = e.getField();
|
// Field f = e.getField();
|
||||||
@ -554,9 +639,9 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Template[] tmpls = new Template[entries.length];
|
Template[] tmpls = new Template[from.length];
|
||||||
for(int i=0; i < entries.length; i++) {
|
for(int i=0; i < from.length; i++) {
|
||||||
FieldEntry e = entries[i];
|
FieldEntry e = from[i];
|
||||||
if(!e.isAvailable()) {
|
if(!e.isAvailable()) {
|
||||||
tmpls[i] = null;
|
tmpls[i] = null;
|
||||||
} else {
|
} else {
|
||||||
@ -564,9 +649,7 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
tmpls[i] = tmpl;
|
tmpls[i] = tmpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tmpls;
|
||||||
BuildContext bc = new BuildContext(this);
|
|
||||||
return bc.buildTemplate(targetClass, entries, tmpls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class JavassistOrdinalEnumTemplate extends ReflectionTemplateBuilder.ReflectionOrdinalEnumTemplate {
|
static class JavassistOrdinalEnumTemplate extends ReflectionTemplateBuilder.ReflectionOrdinalEnumTemplate {
|
||||||
@ -575,10 +658,21 @@ public class JavassistTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeOrdinalEnumTemplateClass(Class<?> targetClass, Enum<?>[] entires, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("not supported yet.");// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries) {
|
public Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries) {
|
||||||
return new JavassistOrdinalEnumTemplate(entries);
|
return new JavassistOrdinalEnumTemplate(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeArrayTemplateClass(Type arrayType, Type genericBaseType,
|
||||||
|
Class<?> baseClass, int dim, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("not supported yet.");//TODO
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim) {
|
public Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim) {
|
||||||
if(dim == 1) {
|
if(dim == 1) {
|
||||||
if(baseClass == boolean.class) {
|
if(baseClass == boolean.class) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for Java
|
// MessagePack for Java
|
||||||
//
|
//
|
||||||
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -373,6 +373,22 @@ public class ReflectionTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> loadTemplateClass(Class<?> targetClass) {
|
||||||
|
throw new UnsupportedOperationException("Not supported by reflection-based template builder");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Template initializeTemplate(Class<?> targetClass, Class<?> tmplClass, FieldEntry[] entries) {
|
||||||
|
throw new UnsupportedOperationException("Not supported by reflection-based template builder");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, FieldEntry[] entries,
|
||||||
|
String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("Not supported by reflection-based template builder");
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries) {
|
public Template buildTemplate(Class<?> targetClass, FieldEntry[] entries) {
|
||||||
for(FieldEntry e : entries) {
|
for(FieldEntry e : entries) {
|
||||||
Field f = e.getField();
|
Field f = e.getField();
|
||||||
@ -448,11 +464,16 @@ public class ReflectionTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeOrdinalEnumTemplateClass(Class<?> targetClass,
|
||||||
|
Enum<?>[] entires, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("Not supported by reflection-based template builder");
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries) {
|
public Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries) {
|
||||||
return new ReflectionOrdinalEnumTemplate(entries);
|
return new ReflectionOrdinalEnumTemplate(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ReflectionObjectArrayTemplate extends AbstractTemplate {
|
static class ReflectionObjectArrayTemplate extends AbstractTemplate {
|
||||||
private Class<?> componentClass;
|
private Class<?> componentClass;
|
||||||
private Template elementTemplate;
|
private Template elementTemplate;
|
||||||
@ -536,6 +557,12 @@ public class ReflectionTemplateBuilder extends TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeArrayTemplateClass(Type arrayType, Type genericBaseType,
|
||||||
|
Class<?> baseClass, int dim, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("Not supported by reflection-based template builder");
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim) {
|
public Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim) {
|
||||||
if(dim == 1) {
|
if(dim == 1) {
|
||||||
if(baseClass == boolean.class) {
|
if(baseClass == boolean.class) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for Java
|
// MessagePack for Java
|
||||||
//
|
//
|
||||||
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -107,37 +107,81 @@ public abstract class TemplateBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override this method
|
||||||
|
public abstract Class<?> loadTemplateClass(Class<?> targetClass);
|
||||||
|
|
||||||
|
// Override this method
|
||||||
|
public abstract Template initializeTemplate(Class<?> targetClass, Class<?> tmplClass, FieldEntry[] entries);
|
||||||
|
|
||||||
|
// Override this method
|
||||||
|
public abstract void writeTemplateClass(Class<?> targetClass, FieldEntry[] entries, String directoryName);
|
||||||
|
|
||||||
// Override this method
|
// Override this method
|
||||||
public abstract Template buildTemplate(Class<?> targetClass, FieldEntry[] entries);
|
public abstract Template buildTemplate(Class<?> targetClass, FieldEntry[] entries);
|
||||||
|
|
||||||
|
// Override this method
|
||||||
|
public abstract void writeOrdinalEnumTemplateClass(Class<?> targetClass, Enum<?>[] entires, String directoryName);
|
||||||
|
|
||||||
// Override this method
|
// Override this method
|
||||||
public abstract Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries);
|
public abstract Template buildOrdinalEnumTemplate(Class<?> targetClass, Enum<?>[] entries);
|
||||||
|
|
||||||
|
// Override this method
|
||||||
|
public abstract void writeArrayTemplateClass(Type arrayType, Type genericBaseType,
|
||||||
|
Class<?> baseClass, int dim, String directoryName);
|
||||||
|
|
||||||
// Override this method
|
// Override this method
|
||||||
public abstract Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim);
|
public abstract Template buildArrayTemplate(Type arrayType, Type genericBaseType, Class<?> baseClass, int dim);
|
||||||
|
|
||||||
|
public Template initializeTemplate(Class<?> targetClass, Class<?> tmplClass) {
|
||||||
|
return initializeTemplate(targetClass, tmplClass, readFieldEntries(targetClass, readImplicitFieldOption(targetClass)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, FieldList fList, String directoryName) throws NoSuchFieldException {
|
||||||
|
checkValidation(targetClass);
|
||||||
|
writeTemplateClass(targetClass, convertFieldEntries(targetClass, fList), directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass, FieldList flist) throws NoSuchFieldException {
|
public Template buildTemplate(Class<?> targetClass, FieldList flist) throws NoSuchFieldException {
|
||||||
checkValidation(targetClass);
|
checkValidation(targetClass);
|
||||||
return buildTemplate(targetClass, convertFieldEntries(targetClass, flist));
|
return buildTemplate(targetClass, convertFieldEntries(targetClass, flist));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, FieldOption implicitOption, String directoryName) {
|
||||||
|
checkValidation(targetClass);
|
||||||
|
writeTemplateClass(targetClass, readFieldEntries(targetClass, implicitOption), directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass, FieldOption implicitOption) {
|
public Template buildTemplate(Class<?> targetClass, FieldOption implicitOption) {
|
||||||
checkValidation(targetClass);
|
checkValidation(targetClass);
|
||||||
return buildTemplate(targetClass, readFieldEntries(targetClass, implicitOption));
|
return buildTemplate(targetClass, readFieldEntries(targetClass, implicitOption));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeTemplateClass(Class<?> targetClass, final String directoryName) {
|
||||||
|
FieldOption implicitOption = readImplicitFieldOption(targetClass);
|
||||||
|
writeTemplateClass(targetClass, implicitOption, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildTemplate(Class<?> targetClass) {
|
public Template buildTemplate(Class<?> targetClass) {
|
||||||
FieldOption implicitOption = readImplicitFieldOption(targetClass);
|
FieldOption implicitOption = readImplicitFieldOption(targetClass);
|
||||||
return buildTemplate(targetClass, implicitOption);
|
return buildTemplate(targetClass, implicitOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeOrdinalEnumTemplateClass(Class<?> targetClass, String directoryName) {
|
||||||
|
checkOrdinalEnumValidation(targetClass);
|
||||||
|
Enum<?>[] entries = (Enum<?>[])targetClass.getEnumConstants();
|
||||||
|
writeOrdinalEnumTemplateClass(targetClass, entries, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildOrdinalEnumTemplate(Class<?> targetClass) {
|
public Template buildOrdinalEnumTemplate(Class<?> targetClass) {
|
||||||
checkOrdinalEnumValidation(targetClass);
|
checkOrdinalEnumValidation(targetClass);
|
||||||
Enum<?>[] entries = (Enum<?>[])targetClass.getEnumConstants();
|
Enum<?>[] entries = (Enum<?>[])targetClass.getEnumConstants();
|
||||||
return buildOrdinalEnumTemplate(targetClass, entries);
|
return buildOrdinalEnumTemplate(targetClass, entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeArrayTemplateClass(Type arrayType, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("not supported yet.");// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public Template buildArrayTemplate(Type arrayType) {
|
public Template buildArrayTemplate(Type arrayType) {
|
||||||
Type baseType;
|
Type baseType;
|
||||||
Class<?> baseClass;
|
Class<?> baseClass;
|
||||||
@ -195,22 +239,51 @@ public abstract class TemplateBuilder {
|
|||||||
instance = builder;
|
instance = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class<?> load(Class<?> targetClass) {
|
||||||
|
return instance.loadTemplateClass(targetClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Template initialize(Class<?> targetClass, Class<?> tmplClass) {
|
||||||
|
return instance.initializeTemplate(targetClass, tmplClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeClass(Class<?> targetClass, String directoryName) {
|
||||||
|
instance.writeTemplateClass(targetClass, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public static Template build(Class<?> targetClass) {
|
public static Template build(Class<?> targetClass) {
|
||||||
return instance.buildTemplate(targetClass);
|
return instance.buildTemplate(targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void writeClass(Class<?> targetClass, FieldOption implicitOption, String directoryName) {
|
||||||
|
instance.writeTemplateClass(targetClass, implicitOption, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
public static Template build(Class<?> targetClass, FieldOption implicitOption) {
|
public static Template build(Class<?> targetClass, FieldOption implicitOption) {
|
||||||
return instance.buildTemplate(targetClass, implicitOption);
|
return instance.buildTemplate(targetClass, implicitOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Template build(Class<?> targetClass, FieldList flist) throws NoSuchFieldException {
|
public static void writeClass(Class<?> targetClass, FieldList fList, String directoryName)
|
||||||
return instance.buildTemplate(targetClass, flist);
|
throws NoSuchFieldException {
|
||||||
|
instance.writeTemplateClass(targetClass, fList, directoryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Template build(Class<?> targetClass, FieldList fList) throws NoSuchFieldException {
|
||||||
|
return instance.buildTemplate(targetClass, fList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeOrdinalEnumClass(Class<?> targetClass, String directoryName) {
|
||||||
|
instance.writeOrdinalEnumTemplateClass(targetClass, directoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Template buildOrdinalEnum(Class<?> targetClass) {
|
public static Template buildOrdinalEnum(Class<?> targetClass) {
|
||||||
return instance.buildOrdinalEnumTemplate(targetClass);
|
return instance.buildOrdinalEnumTemplate(targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void writeArrayClass(Type arrayType, String directoryName) {
|
||||||
|
throw new UnsupportedOperationException("not supported yet.");// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public static Template buildArray(Type arrayType) {
|
public static Template buildArray(Type arrayType) {
|
||||||
return instance.buildArrayTemplate(arrayType);
|
return instance.buildArrayTemplate(arrayType);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// MessagePack for Java
|
||||||
|
//
|
||||||
|
// Copyright (C) 2009-2011 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.template;
|
||||||
|
|
||||||
|
public class TemplateClassWriter {
|
||||||
|
public static void write(Class<?> target, String directoryName) {
|
||||||
|
if(target.isEnum()) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
} else {
|
||||||
|
TemplateBuilder.writeClass(target, directoryName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// MessagePack for Java
|
// MessagePack for Java
|
||||||
//
|
//
|
||||||
// Copyright (C) 2009-2010 FURUHASHI Sadayuki
|
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -27,7 +27,6 @@ import org.msgpack.annotation.MessagePackMessage;
|
|||||||
import org.msgpack.annotation.MessagePackDelegate;
|
import org.msgpack.annotation.MessagePackDelegate;
|
||||||
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
import org.msgpack.annotation.MessagePackOrdinalEnum;
|
||||||
import org.msgpack.Template;
|
import org.msgpack.Template;
|
||||||
import org.msgpack.Templates;
|
|
||||||
|
|
||||||
public class TemplateRegistry {
|
public class TemplateRegistry {
|
||||||
private static Map<Type, Template> map;
|
private static Map<Type, Template> map;
|
||||||
@ -111,6 +110,11 @@ public class TemplateRegistry {
|
|||||||
|
|
||||||
Class<?> target = (Class<?>)targetType;
|
Class<?> target = (Class<?>)targetType;
|
||||||
|
|
||||||
|
Class<?> tmplClass = TemplateBuilder.load(target);
|
||||||
|
if (tmplClass != null) {
|
||||||
|
return TemplateBuilder.initialize(target, tmplClass);
|
||||||
|
}
|
||||||
|
|
||||||
if(target.isArray()) {
|
if(target.isArray()) {
|
||||||
// FIXME can't distinguish type-erased T<>[]?
|
// FIXME can't distinguish type-erased T<>[]?
|
||||||
tmpl = TemplateBuilder.buildArray(target);
|
tmpl = TemplateBuilder.buildArray(target);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user