Package org.ow2.easybeans.asm

Examples of org.ow2.easybeans.asm.Label


            } catch (Exception e) {
                this.logger.error("Cannot configure Carol to use CMI", e);
                throw new EZBComponentException("Cannot configure Carol to use CMI", e);
            }

            ClusterViewManagerFactory clusterViewManagerFactory = ClusterViewManagerFactory.getFactory();

            // Start the manager
            try {
                this.clusterViewManager = (ServerClusterViewManager) clusterViewManagerFactory.create();
            } catch (Exception e) {
                this.logger.error("Cannot retrieve the CMI Server", e);
                throw new EZBComponentException("Cannot retrieve the CMI Server", e);
            }
            if (this.clusterViewManager != null
                    && this.clusterViewManager.getState().equals(ClusterViewManager.State.STOPPED)) {
                if (this.eventComponent != null) {
                    List<Component> components =
                        clusterViewManagerFactory.getConfig().getComponents().getComponents();
                    if (components != null) {
                        for (Component cmiEventComponent : components) {
                            if (org.ow2.cmi.component.event.EventComponent.class.isAssignableFrom(cmiEventComponent.getClass())) {
                                ((org.ow2.cmi.component.event.EventComponent) cmiEventComponent).setEventService(
                                        this.eventComponent.getEventService());
View Full Code Here


            return EASYBEANS_ROOT;
        } else if (EZBContainer.class.isAssignableFrom(clazz)) {
            // The object is an EJB container.

            EZBContainer container = (EZBContainer) instance;

            // Get the archive name (remove all character before the last slash/antislash).
            String archiveName = container.getName().replaceAll("(.*[/\\\\])", "");

            // Compute the application id.
            return EASYBEANS_ROOT + "/" + container.getApplicationName() + "/" + archiveName;
        } else if (Factory.class.isAssignableFrom(clazz)) {
            // The object is a bean factory.

            Factory<?, ?> factory = (Factory<?, ?>) instance;
            EZBContainer container = factory.getContainer();

            // Get the archive name (remove all character before the last slash/antislash).
            String archiveName = container.getName().replaceAll("(.*[/\\\\])", "");

            // Get the bean class name (remove all character before the last point).
            String factoryName = factory.getClassName().replaceAll("(.*\\.)", "");

            // Compute the bean id.
            return EASYBEANS_ROOT + "/" + container.getApplicationName() + "/" + archiveName + "/" + factoryName;
        } else {
            throw new java.lang.IllegalArgumentException("Name is not define for argument of type " + instance.getClass());
        }
    }
View Full Code Here

                    throw new EZBComponentException("Cannot start the CMI Server", e);
                }
            }
        }
        // register the listener.
        EZBEventListener eventListener = new CmiEventListener();
        this.eventComponent.registerEventListener(eventListener);

        this.logger.debug("The CMI configuration extension has been added.");
    }
View Full Code Here

            public synchronized void handle(final IEvent event) {
                if (EZBEventBeanInvocationBegin.class.isAssignableFrom(event.getClass())) {
                    EZBEventBeanInvocationBegin e = (EZBEventBeanInvocationBegin) event;
                    MeanCallTimeStatistic.this.pendingCall.put(Long.valueOf(e.getInvocationNumber()), e);
                } else {
                    EZBEventBeanInvocation eventEnd = (EZBEventBeanInvocation) event;
                    EZBEventBeanInvocation eventBegin =
                        MeanCallTimeStatistic.this.pendingCall.remove(Long.valueOf(eventEnd.getInvocationNumber()));

                    MeanCallTimeStatistic.this.count++;
                    MeanCallTimeStatistic.this.total += eventEnd.getTime() - eventBegin.getTime();
                    setLastSampleTime(System.currentTimeMillis());
                }
            }
View Full Code Here

             * Handle the event.
             * @param event The event to handle.
             */
            public synchronized void handle(final IEvent event) {
                if (EZBEventBeanInvocationBegin.class.isAssignableFrom(event.getClass())) {
                    EZBEventBeanInvocationBegin e = (EZBEventBeanInvocationBegin) event;
                    MeanCallTimeStatistic.this.pendingCall.put(Long.valueOf(e.getInvocationNumber()), e);
                } else {
                    EZBEventBeanInvocation eventEnd = (EZBEventBeanInvocation) event;
                    EZBEventBeanInvocation eventBegin =
                        MeanCallTimeStatistic.this.pendingCall.remove(Long.valueOf(eventEnd.getInvocationNumber()));

View Full Code Here

     * @param methodVisitor the given visitor on which annotation are replayed.
     */
    @Override
    public void replay(final MethodVisitor methodVisitor) {
        // Build a new annotation visitor for the given method
        AnnotationVisitor annotationVisitor = methodVisitor.visitParameterAnnotation(this.index, getName(), getVisible());
        getLogger().debug("AnnotationVisitor annotationVisitor = methodVisitor.visitParameterAnnotation({0}, {1}, {2});",
                Integer.valueOf(this.index), getName(), Boolean.valueOf(getVisible()));

        // Replay
        replayInner(annotationVisitor);

        // End of visit
        annotationVisitor.visitEnd();
        getLogger().debug("annotationVisitor.visitEnd();");
    }
View Full Code Here

        //        }
        if (this.classAnnotationMetadata.isBean()) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansInvocationContextFactory",
            "()Lorg/ow2/easybeans/api/interceptor/EZBInvocationContextFactory;");
            Label l1 = new Label();
            mv.visitJumpInsn(IFNULL, l1);

            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansInvocationContextFactory", "()Lorg/ow2/easybeans/api/interceptor/EZBInvocationContextFactory;");
View Full Code Here


        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "isIdentical", "(Ljavax/ejb/EJBLocalObject;)Z", null,
                new String[] {"javax/ejb/EJBException"});
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, ONE);
        Label l1 = new Label();
        mv.visitJumpInsn(IFNONNULL, l1);
        Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l1);
        mv.visitVarInsn(ALOAD, ONE);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/reflect/Proxy", "getInvocationHandler",
                "(Ljava/lang/Object;)Ljava/lang/reflect/InvocationHandler;");
        mv.visitVarInsn(ASTORE, TWO);
        Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ASTORE, THREE);
        Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitVarInsn(ALOAD, TWO);
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/rpc/LocalCallInvocationHandler");
        Label l5 = new Label();
        mv.visitJumpInsn(IFEQ, l5);
        Label l6 = new Label();
        mv.visitLabel(l6);
        mv.visitVarInsn(ALOAD, TWO);
        mv.visitTypeInsn(CHECKCAST, "org/ow2/easybeans/rpc/LocalCallInvocationHandler");
        mv.visitVarInsn(ASTORE, THREE);
        Label l7 = new Label();
        mv.visitJumpInsn(GOTO, l7);
        mv.visitLabel(l5);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l7);
        mv.visitVarInsn(ALOAD, THREE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/ow2/easybeans/rpc/LocalCallInvocationHandler", "getFactoryName",
                "()Ljava/lang/String;");
        mv.visitVarInsn(ASTORE, FOUR);
        Label l8 = new Label();
        mv.visitLabel(l8);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/container/session/stateless/StatelessSessionFactory");
        Label l9 = new Label();
        mv.visitJumpInsn(IFEQ, l9);
        Label l10 = new Label();
        mv.visitLabel(l10);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/Factory", "getClassName", "()Ljava/lang/String;");
        Label l11 = new Label();
        mv.visitLabel(l11);
        mv.visitVarInsn(ALOAD, FOUR);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
        Label l12 = new Label();
        mv.visitLabel(l12);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l9);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/container/session/stateful/StatefulSessionFactory");
        Label l13 = new Label();
        mv.visitJumpInsn(IFEQ, l13);
        Label l14 = new Label();
        mv.visitLabel(l14);
        mv.visitVarInsn(ALOAD, THREE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/ow2/easybeans/rpc/LocalCallInvocationHandler", "getBeanId",
                "()Ljava/lang/Long;");
        mv.visitVarInsn(ASTORE, FIVE);
        Label l15 = new Label();
        mv.visitLabel(l15);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/Factory", "getClassName", "()Ljava/lang/String;");
        Label l16 = new Label();
        mv.visitLabel(l16);
        mv.visitVarInsn(ALOAD, FOUR);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
        Label l17 = new Label();
        mv.visitJumpInsn(IFEQ, l17);
        Label l18 = new Label();
        mv.visitLabel(l18);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansStatefulID", "()Ljava/lang/Long;");
        mv.visitVarInsn(ALOAD, FIVE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "equals", "(Ljava/lang/Object;)Z");
        mv.visitJumpInsn(IFEQ, l17);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l17);
        mv.visitInsn(ICONST_0);
        Label l19 = new Label();
        mv.visitLabel(l19);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l13);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
View Full Code Here

        // }

        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "isIdentical", "(Ljavax/ejb/EJBObject;)Z", null,
                new String[] {"java/rmi/RemoteException"});
        mv.visitCode();
        Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitVarInsn(ALOAD, 1);
        Label l1 = new Label();
        mv.visitJumpInsn(IFNONNULL, l1);
        Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l1);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/reflect/Proxy", "getInvocationHandler",
                "(Ljava/lang/Object;)Ljava/lang/reflect/InvocationHandler;");
        mv.visitVarInsn(ASTORE, 2);
        Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitInsn(ACONST_NULL);
        mv.visitVarInsn(ASTORE, THREE);
        Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitVarInsn(ALOAD, TWO);
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/rpc/ClientRPCInvocationHandler");
        Label l5 = new Label();
        mv.visitJumpInsn(IFEQ, l5);
        Label l6 = new Label();
        mv.visitLabel(l6);
        mv.visitVarInsn(ALOAD, 2);
        mv.visitTypeInsn(CHECKCAST, "org/ow2/easybeans/rpc/ClientRPCInvocationHandler");
        mv.visitVarInsn(ASTORE, THREE);
        Label l7 = new Label();
        mv.visitJumpInsn(GOTO, l7);
        mv.visitLabel(l5);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l7);
        mv.visitVarInsn(ALOAD, THREE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/ow2/easybeans/rpc/ClientRPCInvocationHandler", "getFactoryName",
                "()Ljava/lang/String;");
        mv.visitVarInsn(ASTORE, FOUR);
        Label l8 = new Label();
        mv.visitLabel(l8);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/container/session/stateless/StatelessSessionFactory");
        Label l9 = new Label();
        mv.visitJumpInsn(IFEQ, l9);
        Label l10 = new Label();
        mv.visitLabel(l10);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/Factory", "getClassName", "()Ljava/lang/String;");
        Label l11 = new Label();
        mv.visitLabel(l11);
        mv.visitVarInsn(ALOAD, FOUR);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
        Label l12 = new Label();
        mv.visitLabel(l12);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l9);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitTypeInsn(INSTANCEOF, "org/ow2/easybeans/container/session/stateful/StatefulSessionFactory");
        Label l13 = new Label();
        mv.visitJumpInsn(IFEQ, l13);
        Label l14 = new Label();
        mv.visitLabel(l14);
        mv.visitVarInsn(ALOAD, THREE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "org/ow2/easybeans/rpc/ClientRPCInvocationHandler", "getBeanId",
                "()Ljava/lang/Long;");
        mv.visitVarInsn(ASTORE, FIVE);
        Label l15 = new Label();
        mv.visitLabel(l15);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansFactory",
                "()Lorg/ow2/easybeans/api/Factory;");
        mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/Factory", "getClassName", "()Ljava/lang/String;");
        Label l16 = new Label();
        mv.visitLabel(l16);
        mv.visitVarInsn(ALOAD, FOUR);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z");
        Label l17 = new Label();
        mv.visitJumpInsn(IFEQ, l17);
        Label l18 = new Label();
        mv.visitLabel(l18);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, classAnnotationMetadata.getClassName(), "getEasyBeansStatefulID", "()Ljava/lang/Long;");
        mv.visitVarInsn(ALOAD, FIVE);
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "equals", "(Ljava/lang/Object;)Z");
        mv.visitJumpInsn(IFEQ, l17);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l17);
        mv.visitInsn(ICONST_0);
        Label l19 = new Label();
        mv.visitLabel(l19);
        mv.visitInsn(IRETURN);
        mv.visitLabel(l13);
        mv.visitInsn(ICONST_0);
        mv.visitInsn(IRETURN);
View Full Code Here

            //     original$MethodHelloWorld();
            // }


            // if the factory is not null, skip the code and go the easyBeansFactoryNotNullLabel label
            Label easyBeansFactoryNotNullLabel = new Label();
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansFactory", "()Lorg/ow2/easybeans/api/Factory;");
            mv.visitJumpInsn(IFNONNULL, easyBeansFactoryNotNullLabel);

            // factory is null, needs to call the original/renamed method
            Type[] args = Type.getArgumentTypes(method.getJMethod().getDescriptor());
            mv.visitVarInsn(ALOAD, 0);

            // for each argument of the methods :
            int methodArg = 1;
            for (Type type : args) {
                int opCode = CommonClassGenerator.putFieldLoadOpCode(type.getSort());
                mv.visitVarInsn(opCode, methodArg);
                // Double and Long are special parameters
                if (opCode == LLOAD || opCode == DLOAD) {
                    methodArg++;
                }
                methodArg++;
            }

            // Call the original method
            mv.visitMethodInsn(INVOKEVIRTUAL,  this.classAnnotationMetadata.getClassName(), MethodRenamer.encode(method.getMethodName()), method.getJMethod().getDescriptor());

            // Cast and return value
            Type returnType = Type.getReturnType(method.getJMethod().getDescriptor());
            CommonClassGenerator.addReturnType(returnType, mv);
            // if the factory is not null, skip the previous code
            mv.visitLabel(easyBeansFactoryNotNullLabel);
        }




        if (interceptorType == AROUND_INVOKE || interceptorType  == POST_CONSTRUCT || interceptorType == PRE_DESTROY) {
            //        if (getEasyBeansInvocationContextFactory() != null) {
            //            try {
            //                return ((Integer) getEasyBeansInvocationContextFactory().getContext(this, getEasyBeansDynamicInterceptorManager(), interceptorType.toString(), "addMethodSignature" , a, b)
            //                        .proceed()).intValue();
            //            } catch (Exception e) {
            //                throw new RuntimeException(e);
            //            }
            //        }
            Label tryLabelStart = new Label();
            Label l1 = new Label();
            Label l2 = new Label();
            mv.visitTryCatchBlock(tryLabelStart, l1, l2, "java/lang/Exception");
            // Add bean (as first argument)
            mv.visitVarInsn(ALOAD, 0);
            // Test if invocation context factory is null
            // If there is no invocation context factory, jump to the end
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansInvocationContextFactory", "()Lorg/ow2/easybeans/api/interceptor/EZBInvocationContextFactory;");
            Label labelNoInvocationContextFactory = new Label();
            mv.visitJumpInsn(IFNULL, labelNoInvocationContextFactory);

            // Begin of the try block
            mv.visitLabel(tryLabelStart);
            mv.visitVarInsn(ALOAD, 0);

            // There is an invocation context factory, get it
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansInvocationContextFactory", "()Lorg/ow2/easybeans/api/interceptor/EZBInvocationContextFactory;");
            mv.visitVarInsn(ALOAD, 0);
            mv.visitVarInsn(ALOAD, 0);
            // Get the interceptor manager
            mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), "getEasyBeansDynamicInterceptorManager", "()Lorg/ow2/easybeans/api/interceptor/EZBInterceptorManager;");

            // Add the interceptor type
            mv.visitFieldInsn(GETSTATIC, Type.getInternalName(InterceptorType.class), interceptorType.toString(), "Lorg/ow2/util/ee/metadata/ejbjar/api/InterceptorType;");
            mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(InterceptorType.class), "toString", "()Ljava/lang/String;");

            // Signature of the method
            mv.visitLdcInsn(MethodHelper.getSignature(method));

            // Arguments of the method
            // parameters = new Object[] {arg0, arg1, arg...};
            // put size of the array
            Type[] args = Type.getArgumentTypes(method.getJMethod().getDescriptor());
            int methodArg = 1;

            mv.visitIntInsn(BIPUSH, args.length);
            mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");

            // for each argument of the methods :
            int argCount = 0;
            for (Type type : args) {
                mv.visitInsn(DUP);
                mv.visitIntInsn(BIPUSH, argCount);

                int opCode = CommonClassGenerator.putFieldLoadOpCode(type.getSort());
                mv.visitVarInsn(opCode, methodArg);
                // Double and Long are special parameters
                if (opCode == LLOAD || opCode == DLOAD) {
                    methodArg++;
                }
                methodArg++;

                // if type is not object type, need to convert it
                // for example : Integer.valueOf(i);
                CommonClassGenerator.transformPrimitiveIntoObject(type, mv);
                mv.visitInsn(AASTORE);
                argCount++;
            }

            Type returnType = Type.getReturnType(method.getJMethod().getDescriptor());

            // Call getContext method
            mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/interceptor/EZBInvocationContextFactory", "getContext", "(Lorg/ow2/easybeans/api/bean/EasyBeansBean;Lorg/ow2/easybeans/api/interceptor/EZBInterceptorManager;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Lorg/ow2/easybeans/api/EasyBeansInvocationContext;");
            // Call of proceed method
            mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/EasyBeansInvocationContext", "proceed", "()Ljava/lang/Object;");

            // Cast and return value
            CommonClassGenerator.transformObjectIntoPrimitive(returnType, mv);
            mv.visitLabel(l1);
            CommonClassGenerator.addReturnType(returnType, mv);
            mv.visitLabel(l2);




            boolean methodAlreadyThrowJavaLangException = false;

            // Catch blocks
            String[] methodExceptions = method.getJMethod().getExceptions();
            // catch label = exceptions thrown by method + 1
            Label[] catchsLabel = null;
            if (methodExceptions != null) {
                // if the java.lang.Exception is present, don't need two catchs
                // blocks
                // for java/lang/Exception
                if (Arrays.asList(methodExceptions).contains("java/lang/Exception")) {
                    methodAlreadyThrowJavaLangException = true;
                    catchsLabel = new Label[methodExceptions.length];
                } else {
                    // else, add a catch for java.lang.Exception
                    catchsLabel = new Label[methodExceptions.length + 1];
                }
            } else {
                catchsLabel = new Label[1];
            }

            // init labels
            for (int i = 0; i < catchsLabel.length; i++) {
                catchsLabel[i] = new Label();
            }

            // First, do method exceptions (just rethrow the given exception)
            int lastCatchBlockLabel = 0;
            if (methodAlreadyThrowJavaLangException) {
                lastCatchBlockLabel = catchsLabel.length;
            } else {
                lastCatchBlockLabel = catchsLabel.length - 1;
            }

            for (int block = 0; block < lastCatchBlockLabel; block++) {
                mv.visitLabel(catchsLabel[block]);
                mv.visitVarInsn(ASTORE, methodArg);
                mv.visitVarInsn(ALOAD, methodArg);
                mv.visitInsn(ATHROW);
            }
            // Now, do the wrapped of Exception into a RuntimeException
            if (!methodAlreadyThrowJavaLangException) {
                // start label
                mv.visitLabel(catchsLabel[lastCatchBlockLabel]);
                mv.visitVarInsn(ASTORE, methodArg);

                // instanceof RuntimeException
                mv.visitVarInsn(ALOAD, methodArg);
                mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException");
                Label notInstanceOfRuntimeExceptionLabel = new Label();
                mv.visitJumpInsn(IFEQ, notInstanceOfRuntimeExceptionLabel);

                // throw existing runtime exception (by casting it)
                mv.visitVarInsn(ALOAD, methodArg);
                mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException");
                mv.visitInsn(ATHROW);

                // build Runtime exception with given exception
                mv.visitLabel(notInstanceOfRuntimeExceptionLabel);
                mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
                mv.visitInsn(DUP);
                mv.visitVarInsn(ALOAD, methodArg);
                mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/Throwable;)V");
                mv.visitInsn(ATHROW);

            }

            // Perform try/catch blocks with ASM
            int block = 0;
            // method exception
            if (methodExceptions != null) {
                for (String exception : methodExceptions) {
                    mv.visitTryCatchBlock(tryLabelStart, catchsLabel[0], catchsLabel[block], exception);
                    block++;
                }
            }
            // Exception thrown by proceed() call
            if (!methodAlreadyThrowJavaLangException) {
                mv.visitTryCatchBlock(tryLabelStart, catchsLabel[0], catchsLabel[lastCatchBlockLabel], "java/lang/Exception");
            }

            // No invocation context factory end
            mv.visitLabel(labelNoInvocationContextFactory);
        }


        // Start of the Try label of Try/Catch
        Label tryLabel = new Label();
        mv.visitLabel(tryLabel);

        // build new object by calling the constructor
        mv.visitTypeInsn(NEW, genInvCtx.getGeneratedClassName());
        mv.visitInsn(DUP);

        // Add bean (as first argument)
        mv.visitVarInsn(ALOAD, 0);

        // for each argument
        Type[] args = Type.getArgumentTypes(method.getJMethod().getDescriptor());
        int methodArg = 1;
        for (Type type : args) {
            int opCode = CommonClassGenerator.putFieldLoadOpCode(type.getSort());
            mv.visitVarInsn(opCode, methodArg);
            // Double and Long are special parameters
            if (opCode == LLOAD || opCode == DLOAD) {
                methodArg++;
            }
            methodArg++;
        }
        Type returnType = Type.getReturnType(method.getJMethod().getDescriptor());

        String constructorDesc = genInvCtx.getConstructorDesc();
        mv.visitMethodInsn(INVOKESPECIAL, genInvCtx.getGeneratedClassName(), "<init>", constructorDesc);
        mv.visitMethodInsn(INVOKEVIRTUAL, genInvCtx.getGeneratedClassName(), "proceed", "()Ljava/lang/Object;");

        CommonClassGenerator.transformObjectIntoPrimitive(returnType, mv);
        CommonClassGenerator.addReturnType(returnType, mv);

        boolean methodAlreadyThrowJavaLangException = false;

        // Catch blocks
        String[] methodExceptions = method.getJMethod().getExceptions();
        // catch label = exceptions thrown by method + 1
        Label[] catchsLabel = null;
        if (methodExceptions != null) {
            // if the java.lang.Exception is present, don't need two catchs
            // blocks
            // for java/lang/Exception
            if (Arrays.asList(methodExceptions).contains("java/lang/Exception")) {
                methodAlreadyThrowJavaLangException = true;
                catchsLabel = new Label[methodExceptions.length];
            } else {
                // else, add a catch for java.lang.Exception
                catchsLabel = new Label[methodExceptions.length + 1];
            }
        } else {
            catchsLabel = new Label[1];
        }

        // init labels
        for (int i = 0; i < catchsLabel.length; i++) {
            catchsLabel[i] = new Label();
        }

        // First, do method exceptions (just rethrow the given exception)
        int lastCatchBlockLabel = 0;
        if (methodAlreadyThrowJavaLangException) {
            lastCatchBlockLabel = catchsLabel.length;
        } else {
            lastCatchBlockLabel = catchsLabel.length - 1;
        }

        for (int block = 0; block < lastCatchBlockLabel; block++) {
            mv.visitLabel(catchsLabel[block]);
            mv.visitVarInsn(ASTORE, methodArg);
            mv.visitVarInsn(ALOAD, methodArg);
            mv.visitInsn(ATHROW);
        }
        // Now, do the wrapped of Exception into a RuntimeException
        if (!methodAlreadyThrowJavaLangException) {
            // start label
            mv.visitLabel(catchsLabel[lastCatchBlockLabel]);
            mv.visitVarInsn(ASTORE, methodArg);

            // instanceof RuntimeException
            mv.visitVarInsn(ALOAD, methodArg);
            mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException");
            Label notInstanceOfRuntimeExceptionLabel = new Label();
            mv.visitJumpInsn(IFEQ, notInstanceOfRuntimeExceptionLabel);

            // throw existing runtime exception (by casting it)
            mv.visitVarInsn(ALOAD, methodArg);
            mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException");
View Full Code Here

TOP

Related Classes of org.ow2.easybeans.asm.Label

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.