List of usage examples for org.objectweb.asm Opcodes F_SAME1
int F_SAME1
To view the source code for org.objectweb.asm Opcodes F_SAME1.
Click Source Link
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} *///from ww w.j a v a 2 s . c o m @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.spongepowered.test.decompile.SwitchTests.java
License:Open Source License
private static void generateSwitchSyntheticEclipse(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(ACC_STATIC + ACC_SYNTHETIC, "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "()[I", null, null); mv.visitCode();//from w w w .java 2 s . c om Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/lang/NoSuchFieldError"); Label l3 = new Label(); Label l4 = new Label(); Label l5 = new Label(); mv.visitTryCatchBlock(l3, l4, l5, "java/lang/NoSuchFieldError"); Label l6 = new Label(); Label l7 = new Label(); Label l8 = new Label(); mv.visitTryCatchBlock(l6, l7, l8, "java/lang/NoSuchFieldError"); Label l9 = new Label(); Label l10 = new Label(); Label l11 = new Label(); mv.visitTryCatchBlock(l9, l10, l11, "java/lang/NoSuchFieldError"); Label l12 = new Label(); Label l13 = new Label(); Label l14 = new Label(); mv.visitTryCatchBlock(l12, l13, l14, "java/lang/NoSuchFieldError"); Label l15 = new Label(); Label l16 = new Label(); Label l17 = new Label(); mv.visitTryCatchBlock(l15, l16, l17, "java/lang/NoSuchFieldError"); Label l18 = new Label(); Label l19 = new Label(); Label l20 = new Label(); mv.visitTryCatchBlock(l18, l19, l20, "java/lang/NoSuchFieldError"); Label l21 = new Label(); Label l22 = new Label(); Label l23 = new Label(); mv.visitTryCatchBlock(l21, l22, l23, "java/lang/NoSuchFieldError"); Label l24 = new Label(); Label l25 = new Label(); Label l26 = new Label(); mv.visitTryCatchBlock(l24, l25, l26, "java/lang/NoSuchFieldError"); Label l27 = new Label(); Label l28 = new Label(); Label l29 = new Label(); mv.visitTryCatchBlock(l27, l28, l29, "java/lang/NoSuchFieldError"); Label l30 = new Label(); mv.visitLabel(l30); mv.visitLineNumber(28, l30); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests", "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I"); Label l31 = new Label(); mv.visitJumpInsn(IFNULL, l31); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests", "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I"); mv.visitInsn(ARETURN); mv.visitLabel(l31); mv.visitMethodInsn(INVOKESTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "values", "()[Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;", false); mv.visitInsn(ARRAYLENGTH); mv.visitIntInsn(NEWARRAY, T_INT); mv.visitVarInsn(ASTORE, 0); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "EIGHT", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitIntInsn(BIPUSH, 8); mv.visitInsn(IASTORE); mv.visitLabel(l1); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitInsn(POP); mv.visitLabel(l3); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "FIVE", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitInsn(ICONST_5); mv.visitInsn(IASTORE); mv.visitLabel(l4); mv.visitJumpInsn(GOTO, l6); mv.visitLabel(l5); mv.visitInsn(POP); mv.visitLabel(l6); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "FOUR", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitInsn(ICONST_4); mv.visitInsn(IASTORE); mv.visitLabel(l7); mv.visitJumpInsn(GOTO, l9); mv.visitLabel(l8); mv.visitInsn(POP); mv.visitLabel(l9); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "NINE", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitIntInsn(BIPUSH, 9); mv.visitInsn(IASTORE); mv.visitLabel(l10); mv.visitJumpInsn(GOTO, l12); mv.visitLabel(l11); mv.visitInsn(POP); mv.visitLabel(l12); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ONE", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitInsn(ICONST_1); mv.visitInsn(IASTORE); mv.visitLabel(l13); mv.visitJumpInsn(GOTO, l15); mv.visitLabel(l14); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/NoSuchFieldError" }); mv.visitInsn(POP); mv.visitLabel(l15); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "SEVEN", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitIntInsn(BIPUSH, 7); mv.visitInsn(IASTORE); mv.visitLabel(l16); mv.visitJumpInsn(GOTO, l18); mv.visitLabel(l17); mv.visitInsn(POP); mv.visitLabel(l18); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "SIX", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitIntInsn(BIPUSH, 6); mv.visitInsn(IASTORE); mv.visitLabel(l19); mv.visitJumpInsn(GOTO, l21); mv.visitLabel(l20); mv.visitInsn(POP); mv.visitLabel(l21); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "TEN", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitIntInsn(BIPUSH, 10); mv.visitInsn(IASTORE); mv.visitLabel(l22); mv.visitJumpInsn(GOTO, l24); mv.visitLabel(l23); mv.visitInsn(POP); mv.visitLabel(l24); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "THREE", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitInsn(ICONST_3); mv.visitInsn(IASTORE); mv.visitLabel(l25); mv.visitJumpInsn(GOTO, l27); mv.visitLabel(l26); mv.visitInsn(POP); mv.visitLabel(l27); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETSTATIC, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "TWO", "Lorg/spongepowered/test/decompile/SwitchTests$TestEnum;"); mv.visitMethodInsn(INVOKEVIRTUAL, "org/spongepowered/test/decompile/SwitchTests$TestEnum", "ordinal", "()I", false); mv.visitInsn(ICONST_2); mv.visitInsn(IASTORE); mv.visitLabel(l28); Label l32 = new Label(); mv.visitJumpInsn(GOTO, l32); mv.visitLabel(l29); mv.visitInsn(POP); mv.visitLabel(l32); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DUP); mv.visitFieldInsn(PUTSTATIC, "org/spongepowered/test/decompile/SwitchTests", "$SWITCH_TABLE$org$spongepowered$test$decompile$SwitchTests$TestEnum", "[I"); mv.visitInsn(ARETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.teiid.jboss.rest.RestASMBasedWebArchiveBuilder.java
License:Open Source License
private void buildRestService(String vdbName, int vdbVersion, String modelName, Procedure procedure, String method, String uri, ClassWriter cw, String contentType, String charSet, boolean passthroughAuth) { List<ProcedureParameter> params = new ArrayList<ProcedureParameter>(procedure.getParameters().size()); boolean usingReturn = false; boolean hasLobInput = false; for (ProcedureParameter p : procedure.getParameters()) { if (p.getType() == Type.In || p.getType() == Type.InOut) { params.add(p);/*ww w . j a v a 2s . c om*/ } else if (p.getType() == Type.ReturnValue && procedure.getResultSet() == null) { usingReturn = true; } if (!hasLobInput) { String runtimeType = p.getRuntimeType(); hasLobInput = DataTypeManager.isLOB(runtimeType); } } int paramsSize = params.size(); MethodVisitor mv; boolean useMultipart = false; if (method.toUpperCase().equals("POST") && hasLobInput) { useMultipart = true; } AnnotationVisitor av0; { StringBuilder paramSignature = new StringBuilder(); paramSignature.append("("); for (int i = 0; i < paramsSize; i++) { paramSignature.append("Ljava/lang/String;"); } paramSignature.append(")"); if (useMultipart) { mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), "(Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;)Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" }); } else { mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), paramSignature + "Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" }); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, contentType); av1.visitEnd(); } av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/" + method.toUpperCase() + ";", true); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", uri); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/annotation/security/PermitAll;", true); av0.visitEnd(); } if (useMultipart) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, "multipart/form-data"); av1.visitEnd(); } av0.visitEnd(); } if (!useMultipart) { // post only accepts Form inputs, not path params HashSet<String> pathParms = getPathParameters(uri); for (int i = 0; i < paramsSize; i++) { String paramType = "Ljavax/ws/rs/FormParam;"; if (method.toUpperCase().equals("GET")) { paramType = "Ljavax/ws/rs/QueryParam;"; } if (pathParms.contains(params.get(i).getName())) { paramType = "Ljavax/ws/rs/PathParam;"; } av0 = mv.visitParameterAnnotation(i, paramType, true); av0.visit("value", params.get(i).getName()); av0.visitEnd(); } } mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/sql/SQLException"); mv.visitLabel(l0); if (!useMultipart) { mv.visitTypeInsn(NEW, "java/util/LinkedHashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/LinkedHashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, paramsSize + 1); for (int i = 0; i < paramsSize; i++) { mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitLdcInsn(params.get(i).getName()); mv.visitVarInsn(ALOAD, i + 1); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); } mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(vdbName); mv.visitIntInsn(BIPUSH, vdbVersion); mv.visitLdcInsn(procedure.getSQLString()); mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitLdcInsn(charSet == null ? "" : charSet); mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0); mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" }); mv.visitVarInsn(ASTORE, paramsSize + 1); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(7, paramsSize + 2); mv.visitEnd(); } else { mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(vdbName); mv.visitIntInsn(BIPUSH, vdbVersion); mv.visitLdcInsn(procedure.getSQLString()); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn(charSet == null ? "" : charSet); mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0); mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "executePost", "(Ljava/lang/String;ILjava/lang/String;Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" }); mv.visitVarInsn(ASTORE, 2); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(8, 3); mv.visitEnd(); } } }
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;//from w ww.j av a 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(")"))); 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 w w w . j av a2 s . c om*/ } 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(); }
From source file:st.redline.compiler.ClassBytecodeWriter.java
License:Open Source License
public void setupCatchForBlockReturn(SimpleExpression simpleExpression, String blockReturnType) { // System.out.println("setupCatchForBlockReturn: " + simpleExpression); Label l1 = (Label) simpleExpression.label1(); Label l2 = (Label) simpleExpression.label2(); mv.visitLabel(l1);/* w w w .jav a 2s . c om*/ Label l3 = new Label(); mv.visitJumpInsn(GOTO, l3); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { blockReturnType }); mv.visitMethodInsn(INVOKEVIRTUAL, blockReturnType, "answer", "()Lst/redline/lang/ProtoObject;"); mv.visitInsn(ARETURN); mv.visitLabel(l3); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); }