Package org.ow2.util.ee.metadata.ejbjar.impl

Examples of org.ow2.util.ee.metadata.ejbjar.impl.JClassInterceptor


     *        EAR).
     * @return a BeanNamingInfo instance
     */
    public static BeanNamingInfo buildInfo(final EasyBeansEjbJarClassMetadata beanClassMetadata, final String interfaceName,
            final String mode, final String javaEEApplicationName) {
        IJCommonBean commonBean = beanClassMetadata.getJCommonBean();

        BeanNamingInfo beanNamingInfo = new BeanNamingInfo();
        beanNamingInfo.setName(commonBean.getName());
        beanNamingInfo.setBeanClassName(beanClassMetadata.getClassName());
        beanNamingInfo.setInterfaceName(interfaceName);
        beanNamingInfo.setMode(mode);
        beanNamingInfo.setMappedName(commonBean.getMappedName());
        beanNamingInfo.setJavaEEApplicationName(javaEEApplicationName);

        return beanNamingInfo;

    }
View Full Code Here


     * @see <a href="http://www.jcp.org/en/jsr/detail?id=220">EJB 3.0 Spec ?4.6.6</a>
     * @param sessionBean Session bean to analyze
     */
    public static void resolve(final EasyBeansEjbJarClassMetadata sessionBean) {

        IJLocal jLocal = sessionBean.getLocalInterfaces();
        IJRemote jRemote = sessionBean.getRemoteInterfaces();

        // No business interface or empty annotation (@Remote or @Local)
        if ((jLocal == null && jRemote == null) || (jLocal == null && jRemote != null && jRemote.getInterfaces().isEmpty())
                || (jRemote == null && jLocal != null && jLocal.getInterfaces().isEmpty())) {

            // The following interfaces are excluded when determining whether
            // the bean class has
            // more than one interface: java.io.Serializable;
            // java.io.Externalizable;
View Full Code Here

        // As the Bean class may not implement the interface, ads also the local and remote business interfaces
        List<String> businessInterfaces = new ArrayList<String>();
        // Add implemented interfaces
        businessInterfaces.addAll(Arrays.asList(visitingclassAnnotationMetadata.getInterfaces()));
        // Add local interfaces
        IJLocal localInterfaces = beanclassAnnotationMetadata.getLocalInterfaces();
        if (localInterfaces != null) {
            for (String itf : localInterfaces.getInterfaces()) {
                if (!businessInterfaces.contains(itf)) {
                    businessInterfaces.add(itf);
                }
            }
        }
View Full Code Here

     * @param sessionBean Session bean to analyze
     */
    public static void resolve(final EasyBeansEjbJarClassMetadata sessionBean) {

        IJLocal jLocal = sessionBean.getLocalInterfaces();
        IJRemote jRemote = sessionBean.getRemoteInterfaces();

        // No business interface or empty annotation (@Remote or @Local)
        if ((jLocal == null && jRemote == null) || (jLocal == null && jRemote != null && jRemote.getInterfaces().isEmpty())
                || (jRemote == null && jLocal != null && jLocal.getInterfaces().isEmpty())) {

            // The following interfaces are excluded when determining whether
            // the bean class has
            // more than one interface: java.io.Serializable;
            // java.io.Externalizable;
            // any of the interfaces defined by the javax.ejb package.
            String[] interfaces = sessionBean.getInterfaces();
            List<String> inheritedInterfaces = sessionBean.getInheritedInterfaces();

            int numberItfFound = 0;
            String itfFound = null;
            for (String itf : interfaces) {
                if (!itf.equals(java.io.Serializable.class.getName().replace(".", "/"))
                        && !itf.equals(java.io.Externalizable.class.getName().replace(".", "/"))
                        && !itf.startsWith("javax/ejb")
                        // Should not be inherited
                        && !inheritedInterfaces.contains(itf)
                        ) {
                    itfFound = itf;
                    numberItfFound++;
                }
            }

            // No business interface found but there is only one inherited interface, use it.
            if (numberItfFound == 0 && inheritedInterfaces != null && inheritedInterfaces.size() == 1) {
                itfFound = inheritedInterfaces.get(0);
                numberItfFound = 1;
            }


            // No business interface found
            if (numberItfFound == 0) {
                // if this is a 2.1 bean, it could be normal
                if (sessionBean.getRemoteHome() != null || sessionBean.getLocalHome() != null) {
                    return;
                }

                logger.warn("No business interface found on bean class {0}.", sessionBean.getClassName());
            } else {

                if (numberItfFound > 1) {
                    throw new IllegalStateException("More than 1 itf on class '" + sessionBean.getClassName() + "'.");
                }

                // If bean class implements a single interface, that interface is
                // assumed to be the business
                // interface of the bean. This business interface will be a local
                // interface unless the
                // interface is designated as a remote business interface by use of
                // the Remote annotation
                // on the bean class or interface or by means of the deployment
                // descriptor.

                // Build a local interface if no @Remote annotation, else add interface in the existing object
                if (jRemote == null) {
                    JLocal addedJLocal = new JLocal();
                    addedJLocal.addInterface(itfFound);
                    sessionBean.setLocalInterfaces(addedJLocal);
                } else {
                    jRemote.addInterface(itfFound);
                    sessionBean.setRemoteInterfaces(jRemote);
                }
            }
        }
    }
View Full Code Here

                    businessInterfaces.add(itf);
                }
            }
        }
        // Remote interfaces
        IJRemote remoteInterfaces = beanclassAnnotationMetadata.getRemoteInterfaces();
        if (remoteInterfaces != null) {
            for (String itf : remoteInterfaces.getInterfaces()) {
                if (!businessInterfaces.contains(itf)) {
                    businessInterfaces.add(itf);
                }
            }
        }
View Full Code Here

            // Bean managed or container managed ?
            if (beanTxManaged.equals(BEAN)) {
                // BMT
                if (bean.isStateful()) {
                    interceptors.add(new JClassInterceptor(BMT_STATEFUL_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                } else if (bean.isStateless()) {
                    interceptors.add(new JClassInterceptor(BMT_STATELESS_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                } else {
                    interceptors.add(new JClassInterceptor(BMT_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                }
            } else {
                // CMT
                TransactionAttributeType methodTx = method.getTransactionAttributeType();

                // Set method tx attribute to the class tx attribute if none was
                // set.
                if (methodTx == null) {
                    if (!method.isInherited()) {
                        methodTx = beanTxType;
                    } else {
                        // inherited method, take value of the original class
                        methodTx = method.getOriginalClassMetadata().getTransactionAttributeType();
                    }
                }

                // Apply MDB interceptors and performs checks for authorized modes
                if (bean.isMdb()) {
                    switch (methodTx) {
                    case REQUIRED:
                    case NOT_SUPPORTED:
                        break;
                    case MANDATORY:
                    case NEVER:
                    case REQUIRES_NEW:
                    case SUPPORTS:
                    default:
                        logger.error("For MDB, the TX attribute '" + methodTx
                                + "' is not a valid attribute (only Required or Not supported is available). "
                                + "The error is on the method '" + method.getMethodName() + "' of class '"
                                + method.getClassMetadata().getClassName() + "' for the bean '"
                                + method.getClassMetadata().getLinkedBean() + "'. Sets to the default REQUIRED mode.");
                        methodTx = TransactionAttributeType.REQUIRED;
                        break;
                    }

                    if (TransactionAttributeType.NOT_SUPPORTED == methodTx) {
                        interceptors.add(new JClassInterceptor(CMT_NOT_SUPPORTED_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                    } else if (TransactionAttributeType.REQUIRED == methodTx) {
                        method.setTransacted(true);
                        interceptors.add(new JClassInterceptor(MDB_CMT_REQUIRED_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                    } else {
                        // invalid case
                        throw new IllegalStateException(
                                "Shouldn't be in another mode. Expected NOT_Supported/Required and got '" + methodTx
                                        + "' for the method '" + method.getMethodName() + "' of class '"
                                        + method.getClassMetadata().getClassName() + "' for the bean '"
                                        + method.getClassMetadata().getLinkedBean() + "'. Sets to the default REQUIRED mode.");
                    }


                } else {

                switch (methodTx) {
                    case MANDATORY:
                        method.setTransacted(true);
                        interceptors.add(new JClassInterceptor(CMT_MANDATORY_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    case NEVER:
                        interceptors.add(new JClassInterceptor(CMT_NEVER_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    case NOT_SUPPORTED:
                        interceptors.add(new JClassInterceptor(CMT_NOT_SUPPORTED_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    case REQUIRED:
                        method.setTransacted(true);
                        interceptors.add(new JClassInterceptor(CMT_REQUIRED_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    case REQUIRES_NEW:
                        method.setTransacted(true);
                        interceptors.add(new JClassInterceptor(CMT_REQUIRES_NEW_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    case SUPPORTS:
                        method.setTransacted(true);
                        interceptors.add(new JClassInterceptor(CMT_SUPPORTS_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                        break;
                    default:
                        throw new IllegalStateException("Invalid tx attribute on method '" + method.getMethodName()
                                + "', value = '" + methodTx + "'.");
                }

                }

                // Add listener interceptor for stateul bean only if the bean implements SessionSynchronization interface
                if (addSynchro) {
                    interceptors.add(new JClassInterceptor(LISTENER_SESSION_SYNCHRO_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
                }
                // End CMT
            }

View Full Code Here

                }
            }

            // runAs ?
            if (runAs != null) {
                interceptors.add(new JClassInterceptor(RUNAS_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
            }

            if (denyAll) {
                interceptors.add(new JClassInterceptor(DENYALL_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
            } else if (!permitAll && rolesAllowed != null) {
                // only if permitAll is not set as no interceptor is added in this case
                interceptors.add(new JClassInterceptor(ROLEBASED_INTERCEPTOR, EASYBEANS_INTERCEPTOR));
            }
            method.setInterceptors(interceptors);
        }
    }
View Full Code Here

        }

        // Set list of global interceptors (applied on all business methods)
        List<JClassInterceptor> easyBeansGlobalInterceptors = new ArrayList<JClassInterceptor>();
        for (String easyBeansInterceptor : easyBeansInterceptorsClasses) {
            easyBeansGlobalInterceptors.add(new JClassInterceptor(easyBeansInterceptor, EASYBEANS_INTERCEPTOR));
        }
        classAnnotationMetadata.setGlobalEasyBeansInterceptors(easyBeansGlobalInterceptors);


        // Default interceptors (only once as it is stored in the ejb metadata)
        EjbJarArchiveMetadata ejbJarDeployableMetadata = classAnnotationMetadata.getEjbJarDeployableMetadata();

        IJInterceptors defaultInterceptorsClasses = ejbJarDeployableMetadata.getDefaultInterceptorsClasses();
        Map<InterceptorType, List<? extends IJClassInterceptor>> mapDefaultInterceptors =
            ejbJarDeployableMetadata.getDefaultInterceptors();
        if (mapDefaultInterceptors == null && defaultInterceptorsClasses != null && defaultInterceptorsClasses.size() > 0) {
            Map<InterceptorType, List<? extends IJClassInterceptor>> defaultInterceptors =
                new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
            defaultInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
                    defaultInterceptorsClasses.getClasses()));
            ejbJarDeployableMetadata.setDefaultInterceptors(defaultInterceptors);
        }


        // And then, set the user interceptors (found in external class)
        List<String> externalInterceptorsClasses = new ArrayList<String>();

        // Interceptors from other classes (will be analyzed after)
        // See 3.5.3 of simplified EJB 3.0 spec : multiple interceptors
        // Add interceptor classes found on super classes (if any)


        // Invert list of the inheritance on the current class
        LinkedList<EasyBeansEjbJarClassMetadata> invertedInheritanceClassesList =
            getInvertedSuperClassesMetadata(classAnnotationMetadata);
        // Add interceptors found on these classes (order is super super class
        // before super class, ie : top level first)
        for (EasyBeansEjbJarClassMetadata superMetaData : invertedInheritanceClassesList) {
            IJInterceptors classIinterceptors = superMetaData.getAnnotationInterceptors();
            if (classIinterceptors != null) {
                for (String cls : classIinterceptors.getClasses()) {
                    externalInterceptorsClasses.add(cls);
                }
            }
        }

        // Get the interceptors defined by the user on external classes
        Map<InterceptorType, List<? extends IJClassInterceptor>> externalMapClassInterceptors = new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
        externalMapClassInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
                externalInterceptorsClasses));
        classAnnotationMetadata.setExternalUserInterceptors(externalMapClassInterceptors);


        // interceptor in the bean class ? (LifeCycle event interceptors are not in the bean
        // because they don't take an InvocationContext as parameter, this is the intercepted method
        List<String> internalInterceptorsClasses = new ArrayList<String>();

        if (classAnnotationMetadata.isAroundInvokeMethodMetadata()) {
            internalInterceptorsClasses.add(classAnnotationMetadata.getClassName());
        }
        // Get the interceptors defined by the user on the class
        Map<InterceptorType, List<? extends IJClassInterceptor>> internalMapClassInterceptors =
            new HashMap<InterceptorType, List<? extends IJClassInterceptor>>();
        internalMapClassInterceptors.putAll(getInterceptors(classAnnotationMetadata.getClassName(), classAnnotationMetadata,
                internalInterceptorsClasses));
        classAnnotationMetadata.setInternalUserInterceptors(internalMapClassInterceptors);

        // Now, analyze each interceptors found on methods.
        for (EasyBeansEjbJarMethodMetadata methodAnnotationMetaData
                : classAnnotationMetadata.getMethodMetadataCollection()) {

            // Set global interceptors for a given method (ie : Remove)
            Remove remove = methodAnnotationMetaData.getJRemove();
            if (remove != null) {
                List<JClassInterceptor> easyBeansMethodGlobalInterceptors = new ArrayList<JClassInterceptor>();
                String classType = null;
                // choose right interceptor class
                if (remove.retainIfException()) {
                    classType = Type.getInternalName(RemoveOnlyWithoutExceptionInterceptor.class);
                } else {
                    classType = Type.getInternalName(RemoveAlwaysInterceptor.class);
                }
                easyBeansMethodGlobalInterceptors.add(new JClassInterceptor(classType, EASYBEANS_INTERCEPTOR));

                // set list
                methodAnnotationMetaData.setGlobalEasyBeansInterceptors(easyBeansMethodGlobalInterceptors);
            }
View Full Code Here

                for (EasyBeansEjbJarMethodMetadata method : currentMetaData.getMethodMetadataCollection()) {
                    // Don't look inherited methods.
                    if (method.isInherited()) {
                        continue;
                    }
                    JClassInterceptor jInterceptor = new JClassInterceptor(className, method.getJMethod(),
                            interceptorClassAnalyzed);

                    // If the method is overriden, take care of using the
                    // annotation of the lower class in the inheritance classes.
                    // As the method is only add once for a single interceptor
View Full Code Here

                // on the bean class or interface or by means of the deployment
                // descriptor.

                // Build a local interface if no @Remote annotation, else add interface in the existing object
                if (jRemote == null) {
                    JLocal addedJLocal = new JLocal();
                    addedJLocal.addInterface(itfFound);
                    sessionBean.setLocalInterfaces(addedJLocal);
                } else {
                    jRemote.addInterface(itfFound);
                    sessionBean.setRemoteInterfaces(jRemote);
                }
View Full Code Here

TOP

Related Classes of org.ow2.util.ee.metadata.ejbjar.impl.JClassInterceptor

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.