List of usage examples for org.objectweb.asm Opcodes F_FULL
int F_FULL
To view the source code for org.objectweb.asm Opcodes F_FULL.
Click Source Link
From source file:org.simantics.databoard.tests.testASM.java
License:Open Source License
void createImpl(String className, Class<?> interfaze, ClassWriter cw) { FieldVisitor fv;/* ww w .jav a2s. com*/ MethodVisitor mv; AnnotationVisitor av0; java.lang.reflect.Method[] methods = interfaze.getMethods(); Arrays.sort(methods, MethodInterfaceUtil.methodComparator); String classResourceName = className.replaceAll("\\.", "/"); String classTypeDescriptor = "L" + classResourceName + ";"; String interfaceResourceName = classResourceName.substring(0, classResourceName.length() - 5); String interfaceTypeDescriptor = "L" + interfaceResourceName + ";"; cw.visit(V1_6, ACC_SUPER | ACC_PUBLIC, classResourceName, null, "java/lang/Object", new String[] { interfaceResourceName }); // Imports Set<Class<?>> imports = new HashSet<Class<?>>(); imports.add(AsyncResult.class); imports.add(ExecutionError.class); imports.add(Method.class); imports.add(interfaze); for (java.lang.reflect.Method m : methods) { for (Class<?> clazz : m.getExceptionTypes()) { imports.add(clazz); } for (Class<?> clazz : m.getParameterTypes()) { imports.add(clazz); } imports.add(m.getReturnType()); } for (Class<?> clazz : imports) { if (clazz.isPrimitive()) continue; String name = clazz.getName(); if (name.startsWith("java.lang")) continue; String resourceName = name.replaceAll("\\.", "/"); String outerName = resourceName.contains("$") ? resourceName.substring(0, resourceName.indexOf('$')) : null; String className_ = clazz.isArray() ? clazz.getSimpleName().substring(0, clazz.getSimpleName().length() - 2) : clazz.getSimpleName(); int access = ACC_PUBLIC + ACC_STATIC + (clazz.isInterface() ? ACC_INTERFACE + ACC_ABSTRACT : 0); // System.out.printf("name=%s, outerName=%s, innerName=%s\n", resourceName, outerName, className_); cw.visitInnerClass(resourceName, outerName, className_, access); } // Fields { fv = cw.visitField(ACC_FINAL + ACC_STATIC, "interfaze", "Ljava/lang/Class;", "Ljava/lang/Class<*>;", null); fv.visitEnd(); } { fv = cw.visitField(ACC_FINAL + ACC_STATIC, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "mi", "Lorg/simantics/data/session/MethodInterface;", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "methods", "[Lorg/simantics/data/session/MethodInterface$Method;", null, null); fv.visitEnd(); } // Init class - static {} { mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(Type.getType(interfaceTypeDescriptor)); mv.visitFieldInsn(PUTSTATIC, classResourceName, "interfaze", "Ljava/lang/Class;"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitFieldInsn(GETSTATIC, classResourceName, "interfaze", "Ljava/lang/Class;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethods", "()[Ljava/lang/reflect/Method;"); mv.visitVarInsn(ASTORE, 0); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/simantics/data/network/MethodInterfaceUtil", "methodComparator", "Ljava/util/Comparator;"); mv.visitMethodInsn(INVOKESTATIC, "java/util/Arrays", "sort", "([Ljava/lang/Object;Ljava/util/Comparator;)V"); Label l3 = new Label(); mv.visitLabel(l3); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ARRAYLENGTH); mv.visitTypeInsn(ANEWARRAY, "org/simantics/databoard/method/MethodBinding"); mv.visitFieldInsn(PUTSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); Label l4 = new Label(); mv.visitLabel(l4); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 1); Label l5 = new Label(); mv.visitLabel(l5); Label l6 = new Label(); mv.visitJumpInsn(GOTO, l6); Label l7 = new Label(); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "[Ljava/lang/reflect/Method;", Opcodes.INTEGER }, 0, null); mv.visitFieldInsn(GETSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); mv.visitVarInsn(ILOAD, 1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(AALOAD); mv.visitMethodInsn(INVOKESTATIC, "org/simantics/databoard/DataTypes", "getMethodBinding", "(Ljava/lang/reflect/Method;)Lorg/simantics/databoard/method/MethodBinding;"); mv.visitInsn(AASTORE); Label l8 = new Label(); mv.visitLabel(l8); mv.visitIincInsn(1, 1); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 1); mv.visitFieldInsn(GETSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); mv.visitInsn(ARRAYLENGTH); mv.visitJumpInsn(IF_ICMPLT, l7); Label l9 = new Label(); mv.visitLabel(l9); mv.visitInsn(RETURN); Label l10 = new Label(); mv.visitLabel(l10); mv.visitLocalVariable("methods", "[Ljava/lang/reflect/Method;", null, l2, l10, 0); mv.visitLocalVariable("i", "I", null, l5, l9, 1); mv.visitMaxs(4, 2); mv.visitEnd(); } // Constructor { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Lorg/simantics/data/session/MethodInterface;)V", null, new String[] { "org/simantics/data/error/MethodNotSupportedException" }); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, classResourceName, "mi", "Lorg/simantics/data/session/MethodInterface;"); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); mv.visitInsn(ARRAYLENGTH); mv.visitTypeInsn(ANEWARRAY, "org/simantics/data/session/MethodInterface$Method"); mv.visitFieldInsn(PUTFIELD, classResourceName, "methods", "[Lorg/simantics/data/session/MethodInterface$Method;"); Label l3 = new Label(); mv.visitLabel(l3); mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 2); Label l4 = new Label(); mv.visitLabel(l4); Label l5 = new Label(); mv.visitJumpInsn(GOTO, l5); Label l6 = new Label(); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_FULL, 3, new Object[] { classResourceName, "org/simantics/data/session/MethodInterface", Opcodes.INTEGER }, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, classResourceName, "methods", "[Lorg/simantics/data/session/MethodInterface$Method;"); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(GETSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); mv.visitVarInsn(ILOAD, 2); mv.visitInsn(AALOAD); mv.visitMethodInsn(INVOKEINTERFACE, "org/simantics/data/session/MethodInterface", "getMethod", "(Lorg/simantics/databoard/method/MethodBinding;)Lorg/simantics/data/session/MethodInterface$Method;"); mv.visitInsn(AASTORE); Label l7 = new Label(); mv.visitLabel(l7); mv.visitIincInsn(2, 1); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ILOAD, 2); mv.visitFieldInsn(GETSTATIC, classResourceName, "bindings", "[Lorg/simantics/databoard/method/MethodBinding;"); mv.visitInsn(ARRAYLENGTH); mv.visitJumpInsn(IF_ICMPLT, l6); Label l8 = new Label(); mv.visitLabel(l8); mv.visitInsn(RETURN); Label l9 = new Label(); mv.visitLabel(l9); mv.visitLocalVariable("this", classTypeDescriptor, null, l0, l9, 0); mv.visitLocalVariable("mi", "Lorg/simantics/data/session/MethodInterface;", null, l0, l9, 1); mv.visitLocalVariable("i", "I", null, l4, l8, 2); mv.visitMaxs(5, 3); mv.visitEnd(); } // Method int methodNumber = 0; for (java.lang.reflect.Method m : methods) { String typeDescription = ""; Class<?>[] params = m.getParameterTypes(); for (int i = 0; i < params.length; i++) { if (i > 0) typeDescription += ";"; typeDescription += classToTypeDescriptor(params[i]); } typeDescription = "(" + typeDescription + ")" + classToTypeDescriptor(m.getReturnType()); System.out.println(typeDescription + " " + m.getName()); Class<?>[] exceptions = m.getExceptionTypes(); String[] exceptionResourceNames = new String[exceptions.length]; for (int i = 0; i < exceptionResourceNames.length; i++) { exceptionResourceNames[i] = exceptions[i].getName().replaceAll("\\.", "/"); } // Registers // 0 - this // 1..argRegs args // argRegs+1 - method // argRegs+2 - args (the array) // argRegs+3 - AsyncResult // argRegs+4 - e // argRegs+5 - ExecutionError.cause // argRegs+6 - e int argRegs = 0; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; argRegs++; if (clazz == long.class || clazz == float.class || clazz == Double.class) argRegs++; } mv = cw.visitMethod(ACC_PUBLIC, m.getName(), typeDescription, null, exceptionResourceNames); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "org/simantics/data/session/MethodInterface$ExecutionError"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/InterruptedException"); Label l4 = new Label(); mv.visitLabel(l4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, classResourceName, "methods", "[Lorg/simantics/data/session/MethodInterface$Method;"); // Method m and puts into register mv.visitLdcInsn(Integer.valueOf(methodNumber)); mv.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, argRegs + 1); Label l5 = new Label(); mv.visitLabel(l5); mv.visitLdcInsn(Integer.valueOf(params.length)); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); int register = 1; // argument register for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; mv.visitInsn(DUP); mv.visitLdcInsn(Integer.valueOf(i)); if (clazz == byte.class) { mv.visitVarInsn(ILOAD, register++); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); } else if (clazz == char.class) { mv.visitVarInsn(ILOAD, register++); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;"); } else if (clazz == boolean.class) { mv.visitVarInsn(ILOAD, register++); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); } else if (clazz == byte.class) { mv.visitVarInsn(ILOAD, register++); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); } else if (clazz == int.class) { mv.visitVarInsn(ILOAD, register++); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); } else if (clazz == long.class) { mv.visitVarInsn(LLOAD, register); register += 2; mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(F)Ljava/lang/Long;"); } else if (clazz == float.class) { mv.visitVarInsn(FLOAD, register); register += 2; mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); } else if (clazz == Double.class) { mv.visitVarInsn(DLOAD, register); register += 2; mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); } else { // Push argument to stack mv.visitVarInsn(ALOAD, register++); } mv.visitInsn(AASTORE); } // Store args to argRegs+2 mv.visitVarInsn(ASTORE, argRegs + 2); Label l6 = new Label(); mv.visitLabel(l6); mv.visitVarInsn(ALOAD, argRegs + 1 /* m */); mv.visitVarInsn(ALOAD, argRegs + 2 /*args*/); mv.visitMethodInsn(INVOKEINTERFACE, "org/simantics/data/session/MethodInterface$Method", "invoke", "(Ljava/lang/Object;)Lorg/simantics/data/session/MethodInterface$AsyncResult;"); mv.visitVarInsn(ASTORE, argRegs + 3); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, argRegs + 3); mv.visitMethodInsn(INVOKEINTERFACE, "org/simantics/data/session/MethodInterface$AsyncResult", "waitForResponse", "()Ljava/lang/Object;"); // TODO Return typecase result Class<?> returnType = m.getReturnType(); if (returnType == void.class) { mv.visitInsn(POP); mv.visitInsn(RETURN); } else if (returnType == int.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); mv.visitLabel(l1); mv.visitInsn(IRETURN); } else if (returnType == byte.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Byte"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "B()"); mv.visitLabel(l1); mv.visitInsn(IRETURN); } else if (returnType == char.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Character"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C"); mv.visitLabel(l1); mv.visitInsn(IRETURN); } else if (returnType == boolean.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); mv.visitLabel(l1); mv.visitInsn(IRETURN); } else if (returnType == short.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Short"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S"); mv.visitLabel(l1); mv.visitInsn(IRETURN); } else if (returnType == long.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Long"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J"); mv.visitLabel(l1); mv.visitInsn(LRETURN); } else if (returnType == double.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Double"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); mv.visitLabel(l1); mv.visitInsn(DRETURN); } else if (returnType == float.class) { mv.visitTypeInsn(CHECKCAST, "java/lang/Float"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F"); mv.visitLabel(l1); mv.visitInsn(FRETURN); } else { // Object mv.visitTypeInsn(CHECKCAST, returnType.getName().replaceAll("\\.", "/")); mv.visitLabel(l1); mv.visitInsn(ARETURN); } // Handle exceptions mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, argRegs + 4, new Object[] { classResourceName, "java/lang/Integer", "org/simantics/data/session/MethodInterface$Method", "[Ljava/lang/Object;", "org/simantics/data/session/MethodInterface$AsyncResult" }, 1, new Object[] { "org/simantics/data/session/MethodInterface$ExecutionError" }); mv.visitVarInsn(ASTORE, argRegs + 4); Label l7 = new Label(); mv.visitLabel(l7); mv.visitVarInsn(ALOAD, argRegs + 4); mv.visitMethodInsn(INVOKEVIRTUAL, "org/simantics/data/session/MethodInterface$ExecutionError", "getError", "()Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, argRegs + 5); // argRegs+5 <- ExecutionError.cause Class<?>[] exceptionClasses = m.getExceptionTypes(); Label nextException[] = new Label[exceptionClasses.length]; for (int i = 0; i < exceptionClasses.length; i++) { Class<?> exceptionClass = exceptionClasses[i]; String exceptionClassResourceName = exceptionClass.getName().replaceAll("\\.", "/"); nextException[i] = new Label(); // If instanceof MyException Label l8 = new Label(); mv.visitLabel(l8); mv.visitVarInsn(ALOAD, argRegs + 5); // Cause mv.visitTypeInsn(INSTANCEOF, exceptionClassResourceName); mv.visitJumpInsn(IFEQ, nextException[i]); // If not, go to ExecutionError // If so, throw it mv.visitVarInsn(ALOAD, argRegs + 5); // e mv.visitTypeInsn(CHECKCAST, exceptionClassResourceName); mv.visitInsn(ATHROW); mv.visitLabel(nextException[i]); } // ExecutionError mv.visitFrame( Opcodes.F_APPEND, argRegs + 1, new Object[] { "org/simantics/data/session/MethodInterface$ExecutionError", "java/lang/Object" }, 0, null); mv.visitTypeInsn(NEW, "java/lang/RuntimeException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, argRegs + 4); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); // InteruptedException mv.visitLabel(l3); mv.visitFrame(Opcodes.F_FULL, argRegs + 4, new Object[] { classResourceName, "java/lang/Integer", "org/simantics/data/session/MethodInterface$Method", "[Ljava/lang/Object;", "org/simantics/data/session/MethodInterface$AsyncResult" }, 1, new Object[] { "java/lang/InterruptedException" }); mv.visitVarInsn(ASTORE, argRegs + 4); Label l10 = new Label(); mv.visitLabel(l10); mv.visitTypeInsn(NEW, "java/lang/RuntimeException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, argRegs + 4); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); Label l11 = new Label(); mv.visitLabel(l11); mv.visitLocalVariable("this", classTypeDescriptor, null, l4, l11, 0); // mv.visitLocalVariable("arg1", "Ljava/lang/Integer;", null, l4, l11, 1); register = 1; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; mv.visitLocalVariable("arg" + (i + 1), classToTypeDescriptor(clazz), null, l4, l11, register); register++; if (clazz == long.class || clazz == float.class || clazz == Double.class) argRegs++; } mv.visitLocalVariable("m", "Lorg/simantics/data/session/MethodInterface$Method;", null, l5, l11, argRegs + 1); mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l6, l11, argRegs + 2); mv.visitLocalVariable("result", "Lorg/simantics/data/session/MethodInterface$AsyncResult;", null, l0, l11, argRegs + 3); mv.visitLocalVariable("e", "Lorg/simantics/data/session/MethodInterface$ExecutionError;", null, l7, l3, argRegs + 4); mv.visitLocalVariable("cause", "Ljava/lang/Object;", null, l7, l3, argRegs + 5); mv.visitLocalVariable("e", "Ljava/lang/InterruptedException;", null, l10, l11, argRegs + 4); mv.visitMaxs(argRegs + 3, argRegs + 6); mv.visitEnd(); methodNumber++; } cw.visitEnd(); }
From source file:org.sonatype.restsimple.jaxrs.impl.JAXRSServiceDefinitionGenerator.java
License:Open Source License
/** * Generate a JAX RS Resource on the fly, based on the information contained with a {@link ServiceDefinition} * @param serviceDefinition a {@link ServiceDefinition} *///ww w .ja v a 2 s . c om @Override public void generate(final ServiceDefinition serviceDefinition, ServiceHandlerMapper mapper) { for (ServiceHandler sh : serviceDefinition.serviceHandlers()) { mapper.addServiceHandler(serviceDefinition.path(), sh); } ClassWriter cw = new ClassWriter(0); FieldVisitor fv; MethodVisitor mv; AnnotationVisitor av0; String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 4); String className = "org/sonatype/restsimple/model/ServiceDescriptionResource" + uuid; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, className, null, "java/lang/Object", null); { String path = serviceDefinition.path().contains("/:") ? convert(serviceDefinition.path()) : serviceDefinition.path(); logger.info("Generating jaxrs resource for {} with path {}", serviceDefinition, path); if (path == "") { path = "/"; } av0 = cw.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", path); av0.visitEnd(); } if (serviceDefinition.mediaToProduce().size() > 0) { { av0 = cw.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceDefinition.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } if (serviceDefinition.mediaToConsume().size() > 0) { { av0 = cw.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceDefinition.mediaToConsume()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } cw.visitInnerClass("javax/ws/rs/core/Response$ResponseBuilder", "javax/ws/rs/core/Response", "ResponseBuilder", ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT); cw.visitInnerClass("javax/ws/rs/core/Response$Status", "javax/ws/rs/core/Response", "Status", ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM); cw.visitInnerClass("org/sonatype/restsimple/api/ServiceDefinition$HttpMethod", "org/sonatype/restsimple/api/ServiceDefinition", "HttpMethod", ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM); { fv = cw.visitField(ACC_PRIVATE, "logger", "Lorg/slf4j/Logger;", null, null); fv.visitEnd(); } { fv = cw.visitField(0, "request", "Ljavax/servlet/http/HttpServletRequest;", null, null); { av0 = fv.visitAnnotation("Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } fv.visitEnd(); } { fv = cw.visitField(0, "mapper", "Lorg/sonatype/restsimple/spi/ServiceHandlerMapper;", null, null); { av0 = fv.visitAnnotation("Lcom/google/inject/Inject;", true); av0.visitEnd(); } fv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(Type.getType("L" + className + ";")); mv.visitMethodInsn(INVOKESTATIC, "org/slf4j/LoggerFactory", "getLogger", "(Ljava/lang/Class;)Lorg/slf4j/Logger;"); mv.visitFieldInsn(PUTFIELD, className, "logger", "Lorg/slf4j/Logger;"); mv.visitInsn(RETURN); mv.visitMaxs(2, 1); mv.visitEnd(); } int duplicateCounter = -1; for (ServiceHandler serviceHandler : serviceDefinition.serviceHandlers()) { { String methodName = serviceHandler.getHttpMethod().name().toLowerCase(); if (duplicateCounter++ >= 0) { methodName = methodName + duplicateCounter; } if (serviceHandler.getHttpMethod().name().equalsIgnoreCase("get")) { mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;)Ljava/lang/Object;", null, null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/GET;", true); av0.visitEnd(); } if (serviceHandler.consumeMediaType() != null) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, serviceHandler.consumeMediaType().toMediaType()); av1.visitEnd(); } av0.visitEnd(); } } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("get"); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 2); mv.visitInsn(ARETURN); mv.visitMaxs(6, 3); mv.visitEnd(); continue; } } { if (serviceHandler.getHttpMethod().name().equalsIgnoreCase("head")) { { String methodName = serviceHandler.getHttpMethod().name().toLowerCase(); if (duplicateCounter++ >= 0) { methodName = methodName + "_" + duplicateCounter; } mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;)Ljavax/ws/rs/core/Response;", null, null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/HEAD;", true); av0.visitEnd(); } if (serviceHandler.consumeMediaType() != null) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, serviceHandler.consumeMediaType().toMediaType()); av1.visitEnd(); } av0.visitEnd(); } } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("head"); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 2); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "ok", "()Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitMaxs(6, 3); mv.visitEnd(); continue; } } } { if (serviceHandler.getHttpMethod().name().equalsIgnoreCase("put")) { { String methodName = serviceHandler.getHttpMethod().name().toLowerCase(); if (duplicateCounter++ >= 0) { methodName = methodName + "_" + duplicateCounter; } String methodType = serviceHandler.consumeClass() != null ? serviceHandler.consumeClass().getName().replace(".", "/") : "java/lang/String"; mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;L" + methodType + ";)Ljavax/ws/rs/core/Response;", null, null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/PUT;", true); av0.visitEnd(); } if (serviceHandler.consumeMediaType() != null) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, serviceHandler.consumeMediaType().toMediaType()); av1.visitEnd(); } av0.visitEnd(); } } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/UriBuilder", "fromResource", "(Ljava/lang/Class;)Ljavax/ws/rs/core/UriBuilder;"); mv.visitInsn(ICONST_3); mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); mv.visitInsn(DUP); mv.visitInsn(ICONST_0); mv.visitLdcInsn(""); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_1); mv.visitLdcInsn(""); mv.visitInsn(AASTORE); mv.visitInsn(DUP); mv.visitInsn(ICONST_2); mv.visitLdcInsn(""); mv.visitInsn(AASTORE); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/UriBuilder", "build", "([Ljava/lang/Object;)Ljava/net/URI;"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("put"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/UriInfo", "getQueryParameters", "()Ljavax/ws/rs/core/MultivaluedMap;"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "created", "(Ljava/net/URI;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "entity", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitMaxs(6, 5); mv.visitEnd(); continue; } } { if (serviceHandler.getHttpMethod().name().equalsIgnoreCase("post")) { String methodName = serviceHandler.getHttpMethod().name().toLowerCase(); if (duplicateCounter++ >= 0) { methodName = methodName + "_" + duplicateCounter; } List<String> formsParam = PostServiceHandler.class.cast(serviceHandler).formParams(); if (formsParam.size() > 0) { { mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;)Ljavax/ws/rs/core/Response;", "(Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap<Ljava/lang/String;Ljava/lang/String;>;)Ljavax/ws/rs/core/Response;", null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/POST;", true); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, "application/x-www-form-urlencoded"); av1.visitEnd(); } av0.visitEnd(); } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("post"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "NO_CONTENT", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "status", "(Ljavax/ws/rs/core/Response$Status;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/Object" }, 0, null); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "ok", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitMaxs(6, 4); mv.visitEnd(); continue; } } else { String methodType = serviceHandler.consumeClass() != null ? serviceHandler.consumeClass().getName().replace(".", "/") : "java/lang/String"; mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;L" + methodType + ";)Ljavax/ws/rs/core/Response;", null, null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/POST;", true); av0.visitEnd(); } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } if (serviceHandler.consumeMediaType() != null) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, serviceHandler.consumeMediaType().toMediaType()); av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("post"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/UriInfo", "getQueryParameters", "()Ljavax/ws/rs/core/MultivaluedMap;"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "NO_CONTENT", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "status", "(Ljavax/ws/rs/core/Response$Status;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/Object" }, 0, null); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "ok", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitMaxs(6, 4); mv.visitEnd(); continue; } } } { if (serviceHandler.getHttpMethod().name().equalsIgnoreCase("delete")) { { String methodName = serviceHandler.getHttpMethod().name().toLowerCase(); if (duplicateCounter++ >= 0) { methodName = methodName + "_" + duplicateCounter; } String methodType = serviceHandler.consumeClass() != null ? serviceHandler.consumeClass().getName().replace(".", "/") : "java/lang/String"; mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljavax/ws/rs/core/UriInfo;L" + methodType + ";)Ljavax/ws/rs/core/Response;", null, null); { String p = convert(serviceHandler.path()); if (!p.equals("/") && !p.isEmpty()) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", p); av0.visitEnd(); } } { av0 = mv.visitAnnotation("Ljavax/ws/rs/DELETE;", true); av0.visitEnd(); } if (serviceHandler.mediaToProduce().size() > 0) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); for (MediaType m : serviceHandler.mediaToProduce()) { av1.visit(null, m.toMediaType()); } av1.visitEnd(); } av0.visitEnd(); } } if (serviceHandler.consumeMediaType() != null) { { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, serviceHandler.consumeMediaType().toMediaType()); av1.visitEnd(); } av0.visitEnd(); } } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/core/Context;", true); av0.visitEnd(); } mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn("delete"); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;"); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKESPECIAL, className, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "ok", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitInsn(ARETURN); mv.visitMaxs(6, 4); mv.visitEnd(); continue; } } } } } { mv = cw.visitMethod(ACC_PRIVATE, "invokeAction", "(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap;Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;", "<T:Ljava/lang/Object;>(Ljava/lang/String;Ljavax/ws/rs/core/UriInfo;Ljavax/ws/rs/core/MultivaluedMap<Ljava/lang/String;Ljava/lang/String;>;Ljava/util/Map<Ljava/lang/String;Ljava/util/Collection<Ljava/lang/String;>;>;TT;)Ljava/lang/Object;", null); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "org/sonatype/restsimple/api/ActionException"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, "java/lang/Throwable"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "mapper", "Lorg/sonatype/restsimple/spi/ServiceHandlerMapper;"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/UriInfo", "getPath", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/sonatype/restsimple/spi/ServiceHandlerMapper", "map", "(Ljava/lang/String;Ljava/lang/String;)Lorg/sonatype/restsimple/api/ServiceHandler;"); mv.visitVarInsn(ASTORE, 6); mv.visitVarInsn(ALOAD, 6); Label l4 = new Label(); mv.visitJumpInsn(IFNONNULL, l4); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitIntInsn(SIPUSH, 405); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "status", "(I)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitLdcInsn("Method not allowed"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "entity", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljavax/ws/rs/core/Response;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "org/sonatype/restsimple/api/ServiceHandler" }, 0, null); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEVIRTUAL, "org/sonatype/restsimple/api/ServiceHandler", "getHttpMethod", "()Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "name", "()Ljava/lang/String;"); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l5 = new Label(); mv.visitJumpInsn(IFNE, l5); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitIntInsn(SIPUSH, 405); mv.visitMethodInsn(INVOKESTATIC, "javax/ws/rs/core/Response", "status", "(I)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitLdcInsn("Method not allowed"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "entity", "(Ljava/lang/Object;)Ljavax/ws/rs/core/Response$ResponseBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "javax/ws/rs/core/Response$ResponseBuilder", "build", "()Ljavax/ws/rs/core/Response;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljavax/ws/rs/core/Response;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ASTORE, 7); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEVIRTUAL, "org/sonatype/restsimple/api/ServiceHandler", "getAction", "()Lorg/sonatype/restsimple/api/Action;"); mv.visitVarInsn(ASTORE, 8); mv.visitTypeInsn(NEW, "java/util/HashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, 9); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/UriInfo", "getPathParameters", "()Ljavax/ws/rs/core/MultivaluedMap;"); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "entrySet", "()Ljava/util/Set;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;"); mv.visitVarInsn(ASTORE, 10); Label l6 = new Label(); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_FULL, 11, new Object[] { className, "java/lang/String", "javax/ws/rs/core/UriInfo", "javax/ws/rs/core/MultivaluedMap", "java/util/Map", "java/lang/Object", "org/sonatype/restsimple/api/ServiceHandler", "java/lang/Object", "org/sonatype/restsimple/api/Action", "java/util/Map", "java/util/Iterator" }, 0, new Object[] {}); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z"); mv.visitJumpInsn(IFEQ, l0); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/Map$Entry"); mv.visitVarInsn(ASTORE, 11); mv.visitVarInsn(ALOAD, 9); mv.visitVarInsn(ALOAD, 11); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getKey", "()Ljava/lang/Object;"); mv.visitVarInsn(ALOAD, 11); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getValue", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/List"); mv.visitInsn(ICONST_0); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitJumpInsn(GOTO, l6); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitTypeInsn(NEW, "org/sonatype/restsimple/api/ActionContext"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "request", "Ljavax/servlet/http/HttpServletRequest;"); mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getMethod", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, className, "mapMethod", "(Ljava/lang/String;)Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, className, "mapHeaders", "()Ljava/util/Map;"); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKESPECIAL, className, "mapFormParams", "(Ljavax/ws/rs/core/MultivaluedMap;)Ljava/util/Map;"); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "request", "Ljavax/servlet/http/HttpServletRequest;"); mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getInputStream", "()Ljavax/servlet/ServletInputStream;"); mv.visitVarInsn(ALOAD, 9); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKESPECIAL, "org/sonatype/restsimple/api/ActionContext", "<init>", "(Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/io/InputStream;Ljava/util/Map;Ljava/lang/Object;)V"); mv.visitVarInsn(ASTORE, 10); mv.visitVarInsn(ALOAD, 8); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEINTERFACE, "org/sonatype/restsimple/api/Action", "action", "(Lorg/sonatype/restsimple/api/ActionContext;)Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, 7); mv.visitLabel(l1); Label l7 = new Label(); mv.visitJumpInsn(GOTO, l7); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "org/sonatype/restsimple/api/ActionException" }); mv.visitVarInsn(ASTORE, 10); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 10); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEVIRTUAL, "org/sonatype/restsimple/api/ActionException", "getStatusCode", "()I"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;I)V"); mv.visitInsn(ATHROW); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 10); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "logger", "Lorg/slf4j/Logger;"); mv.visitLdcInsn("invokeAction"); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKEINTERFACE, "org/slf4j/Logger", "error", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 10); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l7); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 7); mv.visitInsn(ARETURN); mv.visitMaxs(9, 12); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE, "mapFormParams", "(Ljavax/ws/rs/core/MultivaluedMap;)Ljava/util/Map;", "(Ljavax/ws/rs/core/MultivaluedMap<Ljava/lang/String;Ljava/lang/String;>;)Ljava/util/Map<Ljava/lang/String;Ljava/util/Collection<Ljava/lang/String;>;>;", null); mv.visitCode(); mv.visitTypeInsn(NEW, "java/util/HashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 1); Label l0 = new Label(); mv.visitJumpInsn(IFNULL, l0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "keySet", "()Ljava/util/Set;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;"); mv.visitVarInsn(ASTORE, 3); Label l1 = new Label(); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/util/Map", "java/util/Iterator" }, 0, null); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z"); mv.visitJumpInsn(IFEQ, l0); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); Label l2 = new Label(); mv.visitJumpInsn(IFNULL, l2); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/Collection"); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/Collection"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "addAll", "(Ljava/util/Collection;)Z"); mv.visitInsn(POP); Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null); mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"); mv.visitVarInsn(ASTORE, 5); mv.visitVarInsn(ALOAD, 5); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/Collection"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "addAll", "(Ljava/util/Collection;)Z"); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(ALOAD, 2); mv.visitInsn(ARETURN); mv.visitMaxs(3, 6); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE, "mapMethod", "(Ljava/lang/String;)Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("GET"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l0 = new Label(); mv.visitJumpInsn(IFEQ, l0); mv.visitFieldInsn(GETSTATIC, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "GET", "Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("PUT"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitFieldInsn(GETSTATIC, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "PUT", "Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitInsn(ARETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("POST"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l2 = new Label(); mv.visitJumpInsn(IFEQ, l2); mv.visitFieldInsn(GETSTATIC, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "POST", "Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("DELETE"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l3 = new Label(); mv.visitJumpInsn(IFEQ, l3); mv.visitFieldInsn(GETSTATIC, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "DELETE", "Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitInsn(ARETURN); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn("HEAD"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equalsIgnoreCase", "(Ljava/lang/String;)Z"); Label l4 = new Label(); mv.visitJumpInsn(IFEQ, l4); mv.visitFieldInsn(GETSTATIC, "org/sonatype/restsimple/api/ServiceDefinition$METHOD", "HEAD", "Lorg/sonatype/restsimple/api/ServiceDefinition$METHOD;"); mv.visitInsn(ARETURN); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/IllegalStateException"); mv.visitInsn(DUP); mv.visitLdcInsn("Invalid Method"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(3, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE, "mapHeaders", "()Ljava/util/Map;", "()Ljava/util/Map<Ljava/lang/String;Ljava/util/Collection<Ljava/lang/String;>;>;", null); mv.visitCode(); mv.visitTypeInsn(NEW, "java/util/HashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, 1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "request", "Ljavax/servlet/http/HttpServletRequest;"); mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getHeaderNames", "()Ljava/util/Enumeration;"); mv.visitVarInsn(ASTORE, 2); Label l0 = new Label(); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "java/util/Map", "java/util/Enumeration" }, 0, null); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Enumeration", "hasMoreElements", "()Z"); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Enumeration", "nextElement", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); Label l2 = new Label(); mv.visitJumpInsn(IFNULL, l2); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/util/Collection"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "request", "Ljavax/servlet/http/HttpServletRequest;"); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getHeader", "(Ljava/lang/String;)Ljava/lang/String;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "add", "(Ljava/lang/Object;)Z"); mv.visitInsn(POP); mv.visitJumpInsn(GOTO, l0); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/lang/String" }, 0, null); mv.visitTypeInsn(NEW, "java/util/ArrayList"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"); mv.visitVarInsn(ASTORE, 4); mv.visitVarInsn(ALOAD, 4); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, "request", "Ljavax/servlet/http/HttpServletRequest;"); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "javax/servlet/http/HttpServletRequest", "getHeader", "(Ljava/lang/String;)Ljava/lang/String;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z"); mv.visitInsn(POP); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 3); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitJumpInsn(GOTO, l0); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, "java/util/Collections", "unmodifiableMap", "(Ljava/util/Map;)Ljava/util/Map;"); mv.visitInsn(ARETURN); mv.visitMaxs(3, 5); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PRIVATE, "mapMatrixParam", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map;", "(Ljavax/ws/rs/core/UriInfo;)Ljava/util/Map<Ljava/lang/String;Ljava/util/Collection<Ljava/lang/String;>;>;", null); mv.visitCode(); mv.visitTypeInsn(NEW, "java/util/HashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, 2); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/UriInfo", "getPathSegments", "()Ljava/util/List;"); mv.visitVarInsn(ASTORE, 3); mv.visitVarInsn(ALOAD, 3); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "iterator", "()Ljava/util/Iterator;"); mv.visitVarInsn(ASTORE, 4); Label l0 = new Label(); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] { "java/util/Map", "java/util/List", "java/util/Iterator" }, 0, null); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z"); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "javax/ws/rs/core/PathSegment"); mv.visitVarInsn(ASTORE, 5); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/PathSegment", "getMatrixParameters", "()Ljavax/ws/rs/core/MultivaluedMap;"); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "keySet", "()Ljava/util/Set;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;"); mv.visitVarInsn(ASTORE, 6); Label l2 = new Label(); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] { "javax/ws/rs/core/PathSegment", "java/util/Iterator" }, 0, null); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z"); Label l3 = new Label(); mv.visitJumpInsn(IFEQ, l3); mv.visitVarInsn(ALOAD, 6); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/String"); mv.visitVarInsn(ASTORE, 7); mv.visitVarInsn(ALOAD, 2); mv.visitVarInsn(ALOAD, 7); mv.visitVarInsn(ALOAD, 5); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/PathSegment", "getMatrixParameters", "()Ljavax/ws/rs/core/MultivaluedMap;"); mv.visitVarInsn(ALOAD, 7); mv.visitMethodInsn(INVOKEINTERFACE, "javax/ws/rs/core/MultivaluedMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_CHOP, 2, null, 0, null); mv.visitJumpInsn(GOTO, l0); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_CHOP, 1, null, 0, null); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKESTATIC, "java/util/Collections", "unmodifiableMap", "(Ljava/util/Map;)Ljava/util/Map;"); mv.visitInsn(ARETURN); mv.visitMaxs(4, 8); mv.visitEnd(); } cw.visitEnd(); byte[] bytes = cw.toByteArray(); try { String classToLoad = className.replace("/", "."); ClassLoader cl = new ByteClassloader(bytes, this.getClass().getClassLoader(), classToLoad); Class<?> clazz = cl.loadClass(classToLoad); moduleConfig.bind(clazz); moduleConfig.bind(GenericMessageBodyWriter.class); bindExtension(serviceDefinition); } catch (Throwable e) { logger.error("generate", e); } }
From source file:org.yx.asm.ProxyMethodWritor.java
License:Apache License
public static void writeVoid(MethodVisitor mv, AsmMethod asmMethod) { Box db = asmMethod.method.getAnnotation(Box.class); if (db == null) { return;// w w w . j a v a 2 s .c o m } String superowener = Type.getInternalName(asmMethod.superClz); String currentClz = asmMethod.currentClz.replace('.', '/'); List<Object> argTypes = AsmUtils.getImplicitFrame( asmMethod.desc.substring(asmMethod.desc.indexOf("(") + 1, asmMethod.desc.indexOf(")"))); int localVariableIndex = argLength(argTypes); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); Label l3 = new Label(); Label l4 = new Label(); mv.visitTryCatchBlock(l0, l3, l4, null); mv.visitTypeInsn(NEW, AOPEXCUTOR); mv.visitInsn(DUP); mv.visitInsn(db.embed() ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKESPECIAL, AOPEXCUTOR, "<init>", "(Z)V", false); mv.visitVarInsn(ASTORE, localVariableIndex + 1); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitLdcInsn(db.dbName()); mv.visitFieldInsn(GETSTATIC, "org/yx/db/DBType", db.dbType().toString(), "Lorg/yx/db/DBType;"); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "begin", "(Ljava/lang/String;Lorg/yx/db/DBType;)V", false); mv.visitVarInsn(ALOAD, 0); loadArgs(mv, argTypes, 0); mv.visitMethodInsn(INVOKESPECIAL, superowener, asmMethod.name, asmMethod.desc, false); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "commit", "()V", false); mv.visitLabel(l1); Label l5 = new Label(); mv.visitJumpInsn(GOTO, l5); mv.visitLabel(l2); List<Object> list = new ArrayList<Object>(); list.add(currentClz); list.addAll(argTypes); list.add(AOPEXCUTOR); Object[] frames = list.toArray(new Object[list.size()]); mv.visitFrame(Opcodes.F_FULL, frames.length, frames, 1, new Object[] { "java/lang/Exception" }); mv.visitVarInsn(ASTORE, localVariableIndex + 2); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitVarInsn(ALOAD, localVariableIndex + 2); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "rollback", "(Ljava/lang/Throwable;)V", false); mv.visitLabel(l3); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); Label l6 = new Label(); mv.visitJumpInsn(GOTO, l6); mv.visitLabel(l4); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, localVariableIndex + 3); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); mv.visitVarInsn(ALOAD, localVariableIndex + 3); mv.visitInsn(ATHROW); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(RETURN); mv.visitMaxs(Math.max(3, localVariableIndex + 1), 4 + localVariableIndex); mv.visitEnd(); }
From source file:org.yx.asm.ProxyMethodWritor.java
License:Apache License
public static void writeWithReturn(MethodVisitor mv, AsmMethod asmMethod) { Box db = asmMethod.method.getAnnotation(Box.class); if (db == null) { return;/*from ww w .j a va 2 s. co m*/ } String superowener = Type.getInternalName(asmMethod.superClz); String currentClz = asmMethod.currentClz.replace('.', '/'); List<Object> argTypes = AsmUtils.getImplicitFrame( asmMethod.desc.substring(asmMethod.desc.indexOf("(") + 1, asmMethod.desc.indexOf(")"))); Object returnType = AsmUtils.getImplicitFrame(asmMethod.desc.substring(asmMethod.desc.indexOf(")") + 1)) .get(0); int localVariableIndex = argLength(argTypes); mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); Label l3 = new Label(); mv.visitTryCatchBlock(l0, l1, l3, null); Label l4 = new Label(); mv.visitTryCatchBlock(l2, l4, l3, null); mv.visitTypeInsn(NEW, AOPEXCUTOR); mv.visitInsn(DUP); mv.visitInsn(db.embed() ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKESPECIAL, AOPEXCUTOR, "<init>", "(Z)V", false); mv.visitVarInsn(ASTORE, localVariableIndex + 1); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitLdcInsn(db.dbName()); mv.visitFieldInsn(GETSTATIC, "org/yx/db/DBType", db.dbType().toString(), "Lorg/yx/db/DBType;"); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "begin", "(Ljava/lang/String;Lorg/yx/db/DBType;)V", false); mv.visitVarInsn(ALOAD, 0); loadArgs(mv, argTypes, 0); mv.visitMethodInsn(INVOKESPECIAL, superowener, asmMethod.name, asmMethod.desc, false); int methodReturnFrameIndex = localVariableIndex + 2; store(mv, returnType, methodReturnFrameIndex); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "commit", "()V", false); mv.visitLabel(l1); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); load(mv, returnType, methodReturnFrameIndex); jReturn(mv, returnType); mv.visitLabel(l2); List<Object> list = new ArrayList<Object>(); list.add(currentClz); list.addAll(argTypes); list.add(AOPEXCUTOR); Object[] frames = list.toArray(new Object[list.size()]); mv.visitFrame(Opcodes.F_FULL, frames.length, frames, 1, new Object[] { "java/lang/Exception" }); mv.visitVarInsn(ASTORE, localVariableIndex + 2); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitVarInsn(ALOAD, localVariableIndex + 2); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "rollback", "(Ljava/lang/Throwable;)V", false); mv.visitLabel(l4); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); Label l5 = new Label(); mv.visitJumpInsn(GOTO, l5); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, localVariableIndex + 3); mv.visitVarInsn(ALOAD, localVariableIndex + 1); mv.visitMethodInsn(INVOKEVIRTUAL, AOPEXCUTOR, "close", "()V", false); mv.visitVarInsn(ALOAD, localVariableIndex + 3); mv.visitInsn(ATHROW); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "org/yx/exception/SumkException"); mv.visitInsn(DUP); mv.visitLdcInsn(new Integer(-364533425)); mv.visitLdcInsn("you are locky to see me^_^"); mv.visitMethodInsn(INVOKESPECIAL, "org/yx/exception/SumkException", "<init>", "(ILjava/lang/String;)V", false); mv.visitInsn(ATHROW); mv.visitMaxs(Math.max(4, localVariableIndex + 1), 4 + localVariableIndex); mv.visitEnd(); }