Package org.ow2.easybeans.asm

Examples of org.ow2.easybeans.asm.Type


            }

            IJAnnotationResource jAnnotationResource = methodMetaData.getJAnnotationResource();
            // @Resource annotation
            if (jAnnotationResource != null) {
                Type typeInterface = validateSetterMethod(methodMetaData);
                String itfName = typeInterface.getClassName();

                // Set default name if not present.
                jAnnotationResource.setName(getJndiName(jAnnotationResource.getName(), methodMetaData));

                // Update annotation value with data set on the class
                updateAnnotationResource(jAnnotationResource);

                // Get lookup / Mapped Name
                String lookupName = jAnnotationResource.getLookup();
                String mappedName = jAnnotationResource.getMappedName();

                // Use MessageDestinationLink if present !
                String messageDestinationLink = jAnnotationResource.getMessageDestinationLink();
                if (messageDestinationLink != null) {
                    try {
                        mappedName = this.containerJNDIResolver.getMessageDestinationJNDIUniqueName(messageDestinationLink);
                    } catch (EZBJNDIResolverException e) {
                        throw new IllegalStateException("No JNDI name found when analyzing @Resource annotation '"
                                + jAnnotationResource + "' for the class '" + this.classAnnotationMetadata.getClassName()
                                + "'.", e);
                    }
                }

                // Env-Entry
                if (isEnvEntry(typeInterface)) {

                    JndiType type = JAVA_COMP_ENV;
                    // Lookup name exists ?
                    if (lookupName == null) {
                        lookupName = jAnnotationResource.getName();
                    }
                    if (lookupName.startsWith("java:")) {
                        type = JAVA;
                    }


                    callMethodJndiEnv(lookupName, typeInterface, mv, methodMetaData,
                            this.classAnnotationMetadata.getClassName(), type);
                } else if (USERTRANSACTION_ITF.equals(itfName)) {
                    callMethodJndiEnv("UserTransaction", typeInterface, mv, methodMetaData,
                            this.classAnnotationMetadata.getClassName(), JAVA_COMP);
                    callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/UserTransaction", mv);
                } else if (TIMERSERVICE_ITF.equals(itfName)) {
                    // add call to : setterMethod(getEasyBeansContext().getInternalTimerService());
                    mv.visitVarInsn(ALOAD, 0);
                    addCallGetEasyBeansContext(mv, null);
                    mv.visitMethodInsn(INVOKEINTERFACE, "org/ow2/easybeans/api/container/EZBEJBContext",
                            "getInternalTimerService", "()Ljavax/ejb/TimerService;");
                    mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
                            "(Ljavax/ejb/TimerService;)V");
                    callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/TimerService", mv);
                } else if (SESSION_CONTEXT.equals(itfName)) {
                    // add call to : setterMethod(getEasyBeansContext());
                    mv.visitVarInsn(ALOAD, 0);
                    addCallGetEasyBeansContext(mv, "javax/ejb/SessionContext");
                    mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
                            "(Ljavax/ejb/SessionContext;)V");

                    // Define the type (if missing)
                    jAnnotationResource.setType(SESSION_CONTEXT);
                    bindResource(jAnnotationResource, mv);
                } else if (MESSAGEDRIVEN_CONTEXT.equals(itfName)) {
                    // add call to : setterMethod(getEasyBeansContext());
                    mv.visitVarInsn(ALOAD, 0);
                    addCallGetEasyBeansContext(mv, "javax/ejb/MessageDrivenContext");
                    mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
                            "(Ljavax/ejb/MessageDrivenContext;)V");

                    // Define the type (if missing)
                    jAnnotationResource.setType(MESSAGEDRIVEN_CONTEXT);
                    bindResource(jAnnotationResource, mv);
                } else if (EJBCONTEXT.equals(itfName)) {
                    // add call to : setterMethod(getEasyBeansContext());
                    mv.visitVarInsn(ALOAD, 0);
                    addCallGetEasyBeansContext(mv, "javax/ejb/EJBContext");
                    mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData.getMethodName(),
                            "(Ljavax/ejb/EJBContext;)V");

                    // Define the type (if missing)
                    jAnnotationResource.setType(EJBCONTEXT);
                    bindResource(jAnnotationResource, mv);
                } else if (ORB_ITF.equals(itfName)) {
                    callMethodJndiEnv("ORB", typeInterface, mv, methodMetaData,
                            this.classAnnotationMetadata.getClassName(), JAVA_COMP);
                    callBindLookupJndiRef(jAnnotationResource.getName(), "java:comp/ORB", mv);
                } else if (URL_ITF.equals(itfName)) {
                    // Bind object in java:comp/env
                    callBindLookupURLRef(jAnnotationResource.getName(), mappedName, mv);

                    // Get JNDI value from registry and call setter method
                    callMethodJndiEnv(jAnnotationResource.getName(), typeInterface, mv, methodMetaData,
                        this.classAnnotationMetadata.getClassName(), JAVA_COMP_ENV);
                } else if (lookupName != null && !lookupName.equals("")) {
                    JndiType type = REGISTRY;
                    // Lookup name ?
                    if (lookupName.startsWith("java:")) {
                        type = JAVA;
                    }
                    callMethodJndiEnv(lookupName, typeInterface, mv, methodMetaData,
                            this.classAnnotationMetadata.getClassName(), type);
                } else if (mappedName != null && !mappedName.equals("")) {
                    // Get JNDI value from registry and call setter method
                    callMethodJndiEnv(mappedName, typeInterface, mv, methodMetaData,
                            this.classAnnotationMetadata.getClassName(), REGISTRY);
                    // Then bind attribute in ENC
                    callBindLookupJndiRef(jAnnotationResource.getName(), mappedName, mv);
                }
            }

            // @EJB annotation
            IJEjbEJB jEjb = methodMetaData.getJEjbEJB();
            if (jEjb != null) {
                logger.debug("Add injection for EJB on method {0} of class {1}", methodMetaData.getMethodName(),
                        this.classAnnotationMetadata.getClassName());

                Type typeInterface = validateSetterMethod(methodMetaData);
                String itfName = typeInterface.getClassName();

                // ejbName ?
                String beanName = jEjb.getBeanName();

                // JNDI name
                String jndiName = null;

                // Mapped Name ? if not null, use it as JNDI name
                String mappedName = jEjb.getMappedName();
                if (mappedName != null && !mappedName.equals("")) {
                    jndiName = mappedName;
                }

                // JNDI name still null, ask the JNDI resolver
                if (jndiName == null) {
                    try {
                        jndiName = this.containerJNDIResolver.getEJBJNDIUniqueName(itfName, beanName);
                    } catch (EZBJNDIResolverException e) {
                        logger.error("Cannot find JNDI Name on class {0} for interface {1} and beanName {2}. Result = {3}",
                            this.classAnnotationMetadata.getClassName(), itfName, beanName);
                    }
                }

                // Not null, bind it
                if (jndiName != null) {
                    logger.debug("Asking jndi name on class {0} for interface {1} and beanName {2}. Result = {3}",
                            this.classAnnotationMetadata.getClassName(), itfName, beanName, jndiName);

                    callMethodJndiEnv(jndiName, typeInterface, mv, methodMetaData, this.classAnnotationMetadata
                            .getClassName(), REGISTRY);

                    // get enc name (or the default name) and bind result
                    String encName = getJndiName(jEjb.getName(), methodMetaData);
                    callBindLookupJndiRef(encName, jndiName, mv);
                }
            }

            // @PersistenceContext annotation
            if (methodMetaData.isPersistenceContext()) {
                Type typeInterface = validateSetterMethod(methodMetaData);
                String itfName = typeInterface.getClassName();

                // Check that arg of the method is EntityManager
                if (!ENTITYMANAGER_ITF.equals(itfName)) {
                    throw new IllegalStateException(
                            "Trying to applied @PersistenceContext on an invalid method in the class '"
                                    + this.classAnnotationMetadata.getClassName() + "', method = " + methodMetaData);
                }
                logger.debug("Add injection for PersistenceContext on method {0} of class {1}", methodMetaData
                        .getMethodName(), this.classAnnotationMetadata.getClassName());

                IJavaxPersistenceContext javaxPersistenceContext = methodMetaData.getJavaxPersistenceContext();
                // add
                // setterName(EntityManagerHelper.getEntityManager(getEasyBeansContext(),
                // "myUnitName", PersistenceContextType.EXTENDED);

                mv.visitVarInsn(ALOAD, 0);

                // call em helper
                addCallEntityManagerHelper(javaxPersistenceContext, mv);

                // call setter method
                mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData
                        .getMethodName(), "(Ljavax/persistence/EntityManager;)V");


                // bind value in ENC environment
                javaxPersistenceContext.setName(getJndiName(javaxPersistenceContext.getName(), methodMetaData));
                bindClassPersistenceContext(javaxPersistenceContext, mv);


            }

            // @PersistenceUnit annotation
            if (methodMetaData.isPersistenceUnit()) {
                Type typeInterface = validateSetterMethod(methodMetaData);
                String itfName = typeInterface.getClassName();
                // Check that attribute is EntityManager
                if (!ENTITYMANAGERFACTORY_ITF.equals(itfName)) {
                    throw new IllegalStateException(
                            "Trying to applied @PersistenceUnit on an invalid method in the class '"
                                    + this.classAnnotationMetadata.getClassName() + "', method = " + methodMetaData);
                }
                logger.debug("Add injection for PersistenceUnit on on method {0} of class {1}", methodMetaData
                        .getMethodName(), this.classAnnotationMetadata.getClassName());

                IJavaxPersistenceUnit javaxPersistenceUnit = methodMetaData.getJavaxPersistenceUnit();

                // add
                // setterName(EntityManagerHelper.getEntityManagerFactory(getEasyBeansContext(),
                // "myUnitName"));

                mv.visitVarInsn(ALOAD, 0);
                // get EMF
                addCallEntityManagerFactoryHelper(javaxPersistenceUnit, mv);
                // call setter method
                mv.visitMethodInsn(INVOKEVIRTUAL, this.classAnnotationMetadata.getClassName(), methodMetaData
                        .getMethodName(), "(Ljavax/persistence/EntityManagerFactory;)V");

                // Bind value in JNDI
                javaxPersistenceUnit.setName(getJndiName(javaxPersistenceUnit.getName(), methodMetaData));
                bindClassPersistenceUnit(javaxPersistenceUnit, mv);
            }

            // @WebServiceRef annotation
            IJaxwsWebServiceRef jWebServiceRef = methodMetaData.getJaxwsWebServiceRef();
            if (jWebServiceRef != null) {

                Type typeInterface = validateSetterMethod(methodMetaData);

                // Validate
                validateAccessMethodAnnotation(methodMetaData);

                // Perform a java:comp/env lookup
View Full Code Here


     * Get the classname from a descriptor.
     * @param descriptor class descriptor
     * @return the classname from a descriptor
     */
    public static String getClassname(final String descriptor) {
        Type type = Type.getType(descriptor);
        return type.getClassName();
    }
View Full Code Here

        int index = 0;
        int interceptorIndex = 0;
        for (IJClassInterceptor interceptor : this.allInterceptors) {
            mv.visitLabel(switchLabels[index]);

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

            // interceptor on the bean
            if (interceptor.getClassName().equals(this.beanClassName)) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, this.generatedClassName, "bean", this.beanClassDesc);
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKEVIRTUAL, this.beanClassName,
                        interceptor.getJMethod().getName(), interceptor.getJMethod().getDescriptor());

                // return object or null if the return type is void
                returnsObject(returnType, mv);
            } else { // interceptor in another class
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, this.generatedClassName, INTERCEPTOR + interceptorIndex ,
                        encodeClassDesc(interceptor.getClassName()));
                mv.visitVarInsn(ALOAD, 0);
                mv.visitMethodInsn(INVOKEVIRTUAL, interceptor.getClassName(),
                interceptor.getJMethod().getName(), interceptor.getJMethod().getDescriptor());
                // return object or null if the return type is void
                returnsObject(returnType, mv);
                interceptorIndex++;
            }
            index++;
        }

        // then, add call to original method, ie bean.businessMethod(i,j,...);
        mv.visitLabel(switchLabels[index++]);
        // get bean object
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, this.generatedClassName, "bean", this.beanClassDesc);

        // arguments of the method
        int indexArg = 0;
        for (Type argType : this.methodArgsType) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, this.generatedClassName, ARG + (indexArg++), argType.getDescriptor());
        }

        // Call to the renamed method only for AroundInvoke
        // LifeCycle interceptors call the original method
        String interceptedMethod = null;
        if (this.interceptorType.equals(AROUND_INVOKE)) {
            interceptedMethod = MethodRenamer.encode(this.jMethod.getName());
        } else {
            interceptedMethod = this.jMethod.getName();
        }

        mv.visitMethodInsn(INVOKEVIRTUAL, this.beanClassName, interceptedMethod, this.jMethod.getDescriptor());
        Type returnType = Type.getReturnType(this.jMethod.getDescriptor());
        // return object or null if the return type is void
        returnsObject(returnType, mv);


        // default case
View Full Code Here

    public static void addFieldGettersSetters(final ClassVisitor cv, final String beanClassName,
            final String fieldName, final String className) {


        // Get type of the class
        Type type = Type.getType(className);

        // Add the fieldName attribute
        // private CLASSNAME fieldName = null;
        FieldVisitor fv = cv.visitField(ACC_PRIVATE, fieldName, className, null, null);
        fv.visitEnd();

        // build getterName
        String appendName = fieldName.toUpperCase().charAt(0) + fieldName.substring(1);
        String getterName = "get" + appendName;

        // Add its getter :
        // public CLASSNAME getterName() {
        //    return this.fieldName;
        // }
        MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, getterName, "()" + className, null, null);
        // Add some flags on the generated method
        addAnnotationsOnGeneratedMethod(mv);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, beanClassName, fieldName, className);
        // return type is depending of the type
        addReturnType(type, mv);
        mv.visitMaxs(0, 0);
        mv.visitEnd();

        // Add the setter
        // public void setterName(final CLASSNAME setterName) {
        //    this.fieldName = fieldName;
        // }
        String setterName = "set" + appendName;
        mv = cv.visitMethod(ACC_PUBLIC, setterName, "(" + className + ")V", null, null);
        // Add some flags on the generated method
        addAnnotationsOnGeneratedMethod(mv);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        // Depends of the type
        int opCode = putFieldLoadOpCode(type.getSort());
        mv.visitVarInsn(opCode, 1);
        mv.visitFieldInsn(PUTFIELD, beanClassName, fieldName, className);
        mv.visitInsn(RETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();
View Full Code Here

        for (EasyBeansEjbJarMethodMetadata method : homeMetadata.getMethodMetadataCollection()) {
            // if method name begins with "create", it's matching
            if (method.getMethodName().startsWith("create")) {
                // Get return type
                JMethod jMethod = method.getJMethod();
                Type returnType = Type.getReturnType(jMethod.getDescriptor());
                String returnTypeClassname = returnType.getClassName();
                // Not yet present in the list ? add it
                if (!interfacesList.contains(returnTypeClassname)) {
                    interfacesList.add(returnTypeClassname.replace(".", "/"));
                }
            }
View Full Code Here

            // 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;");
View Full Code Here

        // call super class method()
        mv.visitMethodInsn(INVOKESPECIAL, method.getClassMetadata().getSuperName(),
                jMethod.getName(), jMethod.getDescriptor());

        Type returnType = Type.getReturnType(jMethod.getDescriptor());
        CommonClassGenerator.addReturnType(returnType, mv);


        mv.visitMaxs(0, 0);
        mv.visitEnd();
View Full Code Here

            // Enable bindings into the cluster
            try {
                ConfigurationRepository.getServerConfiguration().enableCMI(this.cmiProperties);
            } 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());
                            }
                        }
                    }
                }
                try {
                    this.clusterViewManager.start();
                } catch (Exception e) {
                    this.logger.error("Cannot start the CMI Server", e);
                    throw new EZBComponentException("Cannot start the CMI Server", e);
                }
            }
        }
        // register the listener.
        EZBEventListener eventListener = new CmiEventListener();
View Full Code Here

            if (this.clusterViewManager != null) {
                try {
                    this.clusterViewManager.stop();
                } catch (Exception e) {
                    this.logger.error("Cannot stop the server-side manager", e);
                    throw new EZBComponentException("Cannot stop the server-side manager", e);
                }
            }
        }
        this.logger.info("CMI extension stopped.");
View Full Code Here

        } else {
            throw new EZBContainerException("unknown session type for: " + sessionBean);
        }

        // Build runtime information
        SessionBeanInfo sessionBeanInfo = new SessionBeanInfo();
        sessionBeanInfo.setTransactionManagementType(sessionBean.getTransactionManagementType());
        sessionBeanInfo.setApplicationExceptions(sessionBean.getEjbJarDeployableMetadata().getApplicationExceptions());
        // Only for singleton
        if (sessionBean.isSingleton()) {
            sessionBeanInfo.setStartup(sessionBean.isStartup());
        }

        sessionFactory.setSessionBeanInfo(sessionBeanInfo);

        // Build WS deploy/time info
        if (sessionBean.getWebServiceMarker() != null) {
            // Bean is annotated with @WebService or @WebServiceprovider
            IWebServiceInfo info = createWebServiceInfo(sessionBean, factoryName);
            sessionBeanInfo.setWebServiceInfo(info);
        } // else this bean is not webservices annotated

        // get interfaces of bean
        IJLocal localItfs = sessionBean.getLocalInterfaces();
        IJRemote remoteItfs = sessionBean.getRemoteInterfaces();

        if (localItfs != null) {
            sessionBeanInfo.setLocalInterfaces(localItfs.getInterfaces());
            for (String itf : localItfs.getInterfaces()) {
                this.bindingReferences.add(createLocalItfRef(itf,
                                                             getEmbedded().getID(),
                                                             getId(),
                                                             factoryName,
                                                             sessionBean,
                                                             sessionFactory));
            }
        }
        if (remoteItfs != null) {
            sessionBeanInfo.setRemoteInterfaces(remoteItfs.getInterfaces());
            for (String itf : remoteItfs.getInterfaces()) {
                this.bindingReferences.add(createRemoteItfRef(itf,
                                                              getId(),
                                                              factoryName,
                                                              sessionBean,
View Full Code Here

TOP

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

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.