use of org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor in project Payara by payara.
the class ASMClassWriter method createCustomResourceMapping.
@Override
public void createCustomResourceMapping(String resourceClassName, String mappingPath) {
// gen in custom package!
String completeName = "org/glassfish/admin/rest/resources/custom/" + resourceClassName;
String baseClassName = generatedPath + className;
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get" + resourceClassName, "()L" + completeName + ";", null, null);
RestLogging.restLogger.log(Level.FINE, "Creating resource with path {0} (2)", mappingPath);
AnnotationVisitor av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true);
av0.visit("value", mappingPath + "/");
av0.visitEnd();
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, baseClassName, INJECTOR_FIELD, FORNAME_INJECTOR_TYPE);
mv.visitLdcInsn(Type.getType("L" + completeName + ";"));
mv.visitMethodInsn(INVOKEINTERFACE, INTERFACE_INJECTOR_TYPE, CREATE_AND_INITIALIZE, CREATE_AND_INITIALIZE_SIG);
mv.visitTypeInsn(CHECKCAST, completeName);
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, baseClassName, "getEntity", "()Lorg/jvnet/hk2/config/Dom;");
mv.visitMethodInsn(INVOKEVIRTUAL, completeName, "setEntity", "(Lorg/jvnet/hk2/config/Dom;)V");
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor in project Payara by payara.
the class ASMClassWriter method createGetCommandResource.
@Override
public void createGetCommandResource(String commandResourceClassName, String resourcePath) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get" + commandResourceClassName, "()L" + generatedPath + commandResourceClassName + ";", null, null);
RestLogging.restLogger.log(Level.FINE, "Creating resource with path {0} (3)", resourcePath);
AnnotationVisitor av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true);
av0.visit("value", resourcePath + "/");
av0.visitEnd();
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, generatedPath + className, INJECTOR_FIELD, FORNAME_INJECTOR_TYPE);
mv.visitLdcInsn(Type.getType("L" + generatedPath + commandResourceClassName + ";"));
mv.visitMethodInsn(INVOKEINTERFACE, INTERFACE_INJECTOR_TYPE, CREATE_AND_INITIALIZE, CREATE_AND_INITIALIZE_SIG);
mv.visitTypeInsn(CHECKCAST, generatedPath + commandResourceClassName);
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
use of org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor in project Payara by payara.
the class ASMClassWriter method createGetChildResource.
@Override
public void createGetChildResource(String path, String childResourceClassName) {
String childClass;
switch(childResourceClassName) {
case "PropertiesBagResource":
childClass = "org/glassfish/admin/rest/resources/PropertiesBagResource";
break;
case "MonitoredAttributeBagResource":
childClass = "fish/payara/admin/rest/resources/MonitoredAttributeBagResource";
break;
default:
childClass = generatedPath + childResourceClassName;
break;
}
String methodName = "get" + childResourceClassName;
if (childClass.equals(generatedMethods.get(methodName))) {
return;
}
generatedMethods.put(methodName, childClass);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "()L" + childClass + ";", null, null);
RestLogging.restLogger.log(Level.FINE, "Creating resource with path {0} (4)", path);
AnnotationVisitor av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true);
av0.visit("value", path + "/");
av0.visitEnd();
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, generatedPath + className, INJECTOR_FIELD, FORNAME_INJECTOR_TYPE);
mv.visitLdcInsn(Type.getType("L" + childClass + ";"));
mv.visitMethodInsn(INVOKEINTERFACE, INTERFACE_INJECTOR_TYPE, CREATE_AND_INITIALIZE, CREATE_AND_INITIALIZE_SIG);
mv.visitTypeInsn(CHECKCAST, childClass);
mv.visitVarInsn(ASTORE, 1);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, generatedPath + className, "getEntity", "()Lorg/jvnet/hk2/config/Dom;");
mv.visitLdcInsn(path);
mv.visitMethodInsn(INVOKEVIRTUAL, childClass, "setParentAndTagName", "(Lorg/jvnet/hk2/config/Dom;Ljava/lang/String;)V");
mv.visitVarInsn(ALOAD, 1);
mv.visitInsn(ARETURN);
mv.visitMaxs(3, 2);
mv.visitEnd();
}
Aggregations