use of org.eclipse.persistence.dynamic.DynamicClassLoader.EnumInfo in project eclipselink by eclipse-ee4j.
the class DynamicClassWriter method writeClass.
@Override
public byte[] writeClass(DynamicClassLoader loader, String className) throws ClassNotFoundException {
EnumInfo enumInfo = loader.enumInfoRegistry.get(className);
if (enumInfo != null) {
return createEnum(enumInfo);
}
Class<?> parent = getParentClass(loader);
parentClassName = parent.getName();
if (parent.isPrimitive() || parent.isArray() || parent.isEnum() || parent.isInterface() || Modifier.isFinal(parent.getModifiers())) {
throw new IllegalArgumentException("Invalid parent class: " + parent);
}
String classNameAsSlashes = className.replace('.', '/');
String parentClassNameAsSlashes = parentClassName.replace('.', '/');
EclipseLinkASMClassWriter cw = new EclipseLinkASMClassWriter();
// public class Foo extends DynamicEntityImpl {
cw.visit(ACC_PUBLIC + ACC_SUPER, classNameAsSlashes, null, parentClassNameAsSlashes, interfaces != null ? interfaces.toArray(new String[interfaces.size()]) : null);
// public static DynamicPropertiesManager DPM = new
// DynamicPropertiesManager();
cw.visitField(ACC_PUBLIC + ACC_STATIC, PROPERTIES_MANAGER_FIELD, "L" + DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);
MethodVisitor mv = cw.visitMethod(ACC_STATIC, CLINIT, "()V", null, null);
mv.visitTypeInsn(NEW, DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES);
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES, INIT, "()V", false);
mv.visitFieldInsn(PUTSTATIC, classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
// public Foo() {
// super();
// }
mv = cw.visitMethod(ACC_PUBLIC, INIT, "()V", null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, parentClassNameAsSlashes, INIT, "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv = cw.visitMethod(ACC_PUBLIC, "fetchPropertiesManager", "()L" + DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";", null, null);
mv.visitFieldInsn(GETSTATIC, classNameAsSlashes, PROPERTIES_MANAGER_FIELD, "L" + DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES + ";");
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
addFields(cw, parentClassNameAsSlashes);
addMethods(cw, parentClassNameAsSlashes);
cw.visitEnd();
return cw.toByteArray();
}
Aggregations