Search in sources :

Example 6 with AnnotationVisitor

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();
}
Also used : AnnotationVisitor(org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor) MethodVisitor(org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor)

Example 7 with AnnotationVisitor

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();
}
Also used : AnnotationVisitor(org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor) MethodVisitor(org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor)

Example 8 with AnnotationVisitor

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();
}
Also used : AnnotationVisitor(org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor) MethodVisitor(org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor)

Aggregations

AnnotationVisitor (org.glassfish.hk2.external.org.objectweb.asm.AnnotationVisitor)8 MethodVisitor (org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor)5 JsonString (javax.json.JsonString)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JsonObject (javax.json.JsonObject)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 PropertiesDesc (org.glassfish.api.admin.config.PropertiesDesc)1 PropertyDesc (org.glassfish.api.admin.config.PropertyDesc)1 FlashlightProbe (org.glassfish.flashlight.provider.FlashlightProbe)1 ProbeRegistry (org.glassfish.flashlight.provider.ProbeRegistry)1 ClassWriter (org.glassfish.hk2.external.org.objectweb.asm.ClassWriter)1 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)1 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)1 Attribute (org.jvnet.hk2.config.Attribute)1