Package org.apache.openejb.jee

Examples of org.apache.openejb.jee.SessionBean


    EnterpriseBean[] enterpriseBeans = ejbJar.getEnterpriseBeans();
    Iterator<EnterpriseBean> iterator = Arrays.asList(enterpriseBeans).iterator();
    while (iterator.hasNext()) {
      EnterpriseBean bean = (EnterpriseBean) iterator.next();
      if (bean instanceof SessionBean) {
        SessionBean sessionBean = (SessionBean) bean;
        processSessionBean(sessionBean);
      } else if (bean instanceof MessageDrivenBean) {
        MessageDrivenBean messageDriven = (MessageDrivenBean) bean;
        processMessageDrivenBean(messageDriven);
      }
View Full Code Here


                    /*
                     * Annotations specific to @Stateless, @Stateful and @Singleton beans
                     */
                    if (remoteBean instanceof SessionBean) {
                        final SessionBean sessionBean = (SessionBean) remoteBean;

                        // add parents
                        sessionBean.getParents().add(clazz.getName());
                        if (!clazz.isInterface()) {
                            for (Class<?> current = clazz.getSuperclass(); !current.equals(Object.class); current = current.getSuperclass()) {
                                sessionBean.getParents().add(current.getName());
                            }
                        }

                        /*
                        * @Remote
                        * @Local
                        * @WebService
                        * @WebServiceProvider
                        */
                        processSessionInterfaces(sessionBean, clazz, ejbModule);

                        /*
                         * @Asynchronous
                         */
                        processAsynchronous(bean, annotationFinder);

                        /*
                         * Allow for all session bean types
                         * @DependsOn
                         */
                        if (sessionBean.getDependsOn() == null) {
                            final DependsOn dependsOn = getInheritableAnnotation(clazz, DependsOn.class);
                            if (dependsOn != null) {
                                sessionBean.setDependsOn(dependsOn.value());
                            } else {
                                sessionBean.setDependsOn(Collections.EMPTY_LIST);
                            }
                        }

                        /**
                         * Annotations for singletons and stateless
                         */
                        if (sessionBean.getSessionType() != SessionType.STATEFUL) {
                            // REST can be fun
                            if (annotationFinder.isAnnotationPresent(Path.class)) {
                                sessionBean.setRestService(true);
                            }
                        }

                        /*
                         * Annotations specific to @Singleton beans
                         */
                        if (sessionBean.getSessionType() == SessionType.SINGLETON) {

                            /*
                             * @ConcurrencyManagement
                             */
                            if (sessionBean.getConcurrencyManagementType() == null) {
                                final ConcurrencyManagement tx = getInheritableAnnotation(clazz, ConcurrencyManagement.class);
                                javax.ejb.ConcurrencyManagementType concurrencyType = javax.ejb.ConcurrencyManagementType.CONTAINER;
                                if (tx != null) {
                                    concurrencyType = tx.value();
                                }
                                switch (concurrencyType) {
                                    case BEAN:
                                        sessionBean.setConcurrencyManagementType(ConcurrencyManagementType.BEAN);
                                        break;
                                    case CONTAINER:
                                        sessionBean.setConcurrencyManagementType(ConcurrencyManagementType.CONTAINER);
                                        break;
                                }
                            }

                            /*
                             * @Lock
                             */
                            final LockHandler lockHandler = new LockHandler(assemblyDescriptor, sessionBean);
                            if (sessionBean.getConcurrencyManagementType() == ConcurrencyManagementType.CONTAINER) {
                                processAttributes(lockHandler, clazz, annotationFinder);
                            } else {
                                checkAttributes(lockHandler, ejbName, ejbModule, annotationFinder, "invalidConcurrencyAttribute");
                            }

                            /*
                             * @AccessTimeout
                             */
                            final AccessTimeoutHandler accessTimeoutHandler =
                                new AccessTimeoutHandler(assemblyDescriptor, sessionBean, lockHandler.getContainerConcurrency());
                            processAttributes(accessTimeoutHandler, clazz, annotationFinder);

                            /*
                             * @Startup
                             */
                            if (!sessionBean.hasInitOnStartup()) {
                                final Startup startup = getInheritableAnnotation(clazz, Startup.class);
                                sessionBean.setInitOnStartup(startup != null);
                            }

                        } else if (sessionBean.getSessionType() == SessionType.STATEFUL) {
                            /*
                             * Annotations specific to @Stateful beans
                             */

                            /*
                             * @StatefulTimeout
                             */
                            if (sessionBean.getStatefulTimeout() == null) {
                                final StatefulTimeout annotation = getInheritableAnnotation(clazz, StatefulTimeout.class);
                                if (annotation != null) {
                                    final Timeout timeout = new Timeout();
                                    timeout.setTimeout(annotation.value());
                                    timeout.setUnit(annotation.unit());
                                    sessionBean.setStatefulTimeout(timeout);
                                }
                            }

                            /*
                             * @AccessTimeout
 
View Full Code Here

        private void processAsynchronous(final EnterpriseBean bean, final AnnotationFinder annotationFinder) {
            if (!(bean instanceof SessionBean)) {
                return;
            }

            final SessionBean sessionBean = (SessionBean) bean;

            for (final Annotated<Method> method : annotationFinder.findMetaAnnotatedMethods(Asynchronous.class)) {
                sessionBean.getAsyncMethod().add(new AsyncMethod(method.get()));
            }

            //Spec 4.5.1 @Asynchronous could be used at the class level of a bean-class ( or superclass ).
            //Seems that it should not be used on the any interface view

            for (final Annotated<Class<?>> clazz : annotationFinder.findMetaAnnotatedClasses(Asynchronous.class)) {
                if (!clazz.get().isInterface()) {
                    sessionBean.getAsynchronousClasses().add(clazz.get().getName());
                }
            }
        }
View Full Code Here

            for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                if (!(bean instanceof SessionBean)) {
                    continue;
                }

                final SessionBean sessionBean = (SessionBean) bean;

                if (sessionBean.getSessionType() != null) {
                    continue;
                }

                try {
                    final Class<?> clazz = ejbModule.getClassLoader().loadClass(bean.getEjbClass());
                    sessionBean.setSessionType(getSessionType(clazz));
                } catch (final Throwable handledInValidation) {
                    // no-op
                }
            }

            // Fill in default ejbName for xml declared EJBs
            for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
                if (bean.getEjbClass() == null) {
                    continue;
                }
                if (bean.getEjbName() == null || bean.getEjbName().startsWith("@NULL@")) {
                    ejbModule.getEjbJar().removeEnterpriseBean(bean.getEjbName());
                    try {
                        final Class<?> clazz = ejbModule.getClassLoader().loadClass(bean.getEjbClass());
                        final String ejbName = getEjbName(bean, clazz);
                        bean.setEjbName(ejbName);
                    } catch (final Throwable handledInValidation) {
                        // no-op
                    }
                    ejbModule.getEjbJar().addEnterpriseBean(bean);
                }
            }
            /* 19.2:  ejb-name: Default is the unqualified name of the bean class */

            final EjbJar ejbJar = ejbModule.getEjbJar();
            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(Singleton.class)) {
                final Singleton singleton = beanClass.getAnnotation(Singleton.class);
                final String ejbName = getEjbName(singleton, beanClass.get());

                if (!isValidEjbAnnotationUsage(Singleton.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new SingletonBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.SINGLETON);

                    if (singleton.mappedName() != null) {
                        sessionBean.setMappedName(singleton.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(Stateless.class)) {
                final Stateless stateless = beanClass.getAnnotation(Stateless.class);
                final String ejbName = getEjbName(stateless, beanClass.get());

                if (!isValidEjbAnnotationUsage(Stateless.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatelessBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.STATELESS);

                    if (stateless.mappedName() != null) {
                        sessionBean.setMappedName(stateless.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            // The Specialization code is good, but it possibly needs to be moved to after the full processing of the bean
            // the plus is that it would get the required interfaces.  The minus is that it would get all the other items

            // Possibly study alternatives.  Alternatives might have different meta data completely while it seems Specializing beans inherit all meta-data

            // Anyway.. the qualifiers aren't getting inherited, so we need to fix that

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(Stateful.class)) {
                final Stateful stateful = beanClass.getAnnotation(Stateful.class);
                final String ejbName = getEjbName(stateful, beanClass.get());

                if (!isValidEjbAnnotationUsage(Stateful.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new StatefulBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    // TODO: We might be stepping on an xml override here
                    sessionBean.setSessionType(SessionType.STATEFUL);
                    if (stateful.mappedName() != null) {
                        sessionBean.setMappedName(stateful.mappedName());
                    }
                }
                LegacyProcessor.process(beanClass.get(), enterpriseBean);
            }

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(ManagedBean.class)) {
                final ManagedBean managed = beanClass.getAnnotation(ManagedBean.class);
                final String ejbName = getEjbName(managed, beanClass.get());

                // TODO: this is actually against the spec, but the requirement is rather silly
                // (allowing @Stateful and @ManagedBean on the same class)
                // If the TCK doesn't complain we should discourage it
                if (!isValidEjbAnnotationUsage(ManagedBean.class, beanClass, ejbName, ejbModule)) {
                    continue;
                }

                EnterpriseBean enterpriseBean = ejbJar.getEnterpriseBean(ejbName);
                if (enterpriseBean == null) {
                    enterpriseBean = new org.apache.openejb.jee.ManagedBean(ejbName, beanClass.get());
                    ejbJar.addEnterpriseBean(enterpriseBean);
                }
                if (enterpriseBean.getEjbClass() == null) {
                    enterpriseBean.setEjbClass(beanClass.get());
                }
                if (enterpriseBean instanceof SessionBean) {
                    final SessionBean sessionBean = (SessionBean) enterpriseBean;
                    sessionBean.setSessionType(SessionType.MANAGED);

                    final TransactionType transactionType = sessionBean.getTransactionType();
                    if (transactionType == null) {
                        sessionBean.setTransactionType(TransactionType.BEAN);
                    }
                }
            }

            for (final Annotated<Class<?>> beanClass : finder.findMetaAnnotatedClasses(MessageDriven.class)) {
View Full Code Here

        }

        private String getEjbName(final EnterpriseBean bean, final Class<?> clazz) {

            if (bean instanceof SessionBean) {
                final SessionBean sessionBean = (SessionBean) bean;
                switch (sessionBean.getSessionType()) {
                    case STATEFUL: {
                        final Stateful annotation = clazz.getAnnotation(Stateful.class);
                        if (annotation != null && specified(annotation.name())) {
                            return annotation.name();
                        }
View Full Code Here

public class CheckPersistenceRefs extends ValidationBase {
    public void validate(final EjbModule ejbModule) {

        for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            if (bean instanceof SessionBean) {
                final SessionBean sessionBean = (SessionBean) bean;
                if (sessionBean.getSessionType() == null) {
                    continue; // skipping since we don't know here what is the type
                }
            }

            final String beanType = getType(bean);
View Full Code Here

        return type != null && type.equals(PersistenceContextType.EXTENDED);
    }

    private String getType(final EnterpriseBean bean) {
        if (bean instanceof SessionBean) {
            final SessionBean sessionBean = (SessionBean) bean;
            switch (sessionBean.getSessionType()) {
                case STATEFUL:
                    return "Stateful";
                case STATELESS:
                    return "Stateless";
                case SINGLETON:
View Full Code Here

            if (!(enterpriseBean instanceof SessionBean)) {
                continue;
            }

            final SessionBean sessionBean = (SessionBean) enterpriseBean;

            if (sessionBean.getSessionType() != SessionType.SINGLETON) {
                continue;
            }

            for (final String ejbName : sessionBean.getDependsOn()) {
                final Bean referee = bean.resolveLink(ejbName);
                if (referee == null) {
                    bean.module.getValidation().fail(enterpriseBean.getEjbName(), "dependsOn.noSuchEjb", ejbName);
                } else {
                    bean.dependsOn.add(referee);
View Full Code Here

                    fail(b, "entity.no.ejb.create", b.getEjbClass(), entity.getPrimKeyClass(), ejbCreateName.toString(), paramString);

                } else {
                    if (b instanceof SessionBean) {
                        final SessionBean sb = (SessionBean) b;
                        // Under EJB 3.1, it is not required that a stateless session bean have an ejbCreate method, even when it has a home interface
                        if (!sb.getSessionType().equals(SessionType.STATELESS)) {
                            fail(b, "session.no.ejb.create", b.getEjbClass(), ejbCreateName.toString(), paramString);
                        }
                    }
                }
            }
View Full Code Here

                            }
                        }
                    }

                    if (remoteBean instanceof SessionBean) {
                        SessionBean sessionBean = (SessionBean) remoteBean;

                        // Anything declared in the xml is also not eligable
                        List<String> declared = new ArrayList<String>();
                        declared.addAll(sessionBean.getBusinessLocal());
                        declared.addAll(sessionBean.getBusinessRemote());
                        declared.add(sessionBean.getHome());
                        declared.add(sessionBean.getRemote());
                        declared.add(sessionBean.getLocalHome());
                        declared.add(sessionBean.getLocal());
                        declared.add(sessionBean.getServiceEndpoint());

                        List<Class<?>> interfaces = new ArrayList<Class<?>>();
                        for (Class<?> interfce : clazz.getInterfaces()) {
                            String name = interfce.getName();
                            if (!name.equals("java.io.Serializable") &&
                                    !name.equals("java.io.Externalizable") &&
                                    !name.startsWith("javax.ejb.") &&
                                    !declared.contains(interfce.getName())) {
                                interfaces.add(interfce);
                            }
                        }

                        List<Class> remotes = new ArrayList<Class>();
                        Remote remote = clazz.getAnnotation(Remote.class);
                        if (remote != null) {
                            if (remote.value().length == 0) {
                                if (interfaces.size() != 1) {
                                    validation.fail(ejbName, "ann.remote.noAttributes", join(", ", interfaces));
                                } else if (clazz.getAnnotation(Local.class) != null) {
                                    validation.fail(ejbName, "ann.remoteLocal.ambiguous", join(", ", interfaces));
                                } else if (interfaces.get(0).getAnnotation(Local.class) != null) {
                                    validation.fail(ejbName, "ann.remoteLocal.conflict", join(", ", interfaces));
                                } else {
                                    validateRemoteInterface(interfaces.get(0), validation, ejbName);
                                    remotes.add(interfaces.get(0));
                                    interfaces.remove(0);
                                }
                            } else for (Class interfce : remote.value()) {
                                validateRemoteInterface(interfce, validation, ejbName);
                                remotes.add(interfce);
                                interfaces.remove(interfce);
                            }
                        }

                        List<Class> locals = new ArrayList<Class>();
                        Local local = clazz.getAnnotation(Local.class);
                        if (local != null) {
                            if (local.value().length == 0) {
                                if (interfaces.size() != 1) {
                                    validation.fail(ejbName, "ann.local.noAttributes", join(", ", interfaces));
                                } else if (clazz.getAnnotation(Remote.class) != null) {
                                    validation.fail(ejbName, "ann.localRemote.ambiguous", join(", ", interfaces));
                                } else if (interfaces.get(0).getAnnotation(Remote.class) != null) {
                                    validation.fail(ejbName, "ann.localRemote.conflict", join(", ", interfaces));
                                } else {
                                    validateLocalInterface(interfaces.get(0), validation, ejbName);
                                    locals.add(interfaces.get(0));
                                    interfaces.remove(0);
                                }
                            } else for (Class interfce : local.value()) {
                                validateLocalInterface(interfce, validation, ejbName);
                                locals.add(interfce);
                                interfaces.remove(interfce);
                            }
                        }

                        if (sessionBean.getServiceEndpoint() == null) {
                            WebService webService = clazz.getAnnotation(WebService.class);
                            if (webService != null) {
                                String endpointInterfaceName = webService.endpointInterface();
                                if (!endpointInterfaceName.equals("")){
                                    try {
                                        sessionBean.setServiceEndpoint(endpointInterfaceName);
                                        Class endpointInterface = Class.forName(endpointInterfaceName, false, ejbModule.getClassLoader());
                                        interfaces.remove(endpointInterface);
                                    } catch (ClassNotFoundException e) {
                                        throw new IllegalStateException("Class not found @WebService.endpointInterface: "+endpointInterfaceName, e);
                                    }
                                } else {
                                    sessionBean.setServiceEndpoint(DeploymentInfo.ServiceEndpoint.class.getName());
                                }
                            } else if (clazz.isAnnotationPresent(WebServiceProvider.class)) {
                                sessionBean.setServiceEndpoint(DeploymentInfo.ServiceEndpoint.class.getName());
                            }
                        }

                        for (Class interfce : copy(interfaces)) {
                            if (interfce.isAnnotationPresent(WebService.class)) {
                                if (sessionBean.getServiceEndpoint().equals(DeploymentInfo.ServiceEndpoint.class.getName())) {
                                    sessionBean.setServiceEndpoint(interfce.getName());
                                }
                                interfaces.remove(interfce);
                            } else if (interfce.isAnnotationPresent(Remote.class)) {
                                remotes.add(interfce);
                                interfaces.remove(interfce);
                            } else {
                                locals.add(interfce);
                                interfaces.remove(interfce);
                            }
                        }

                        for (Class interfce : remotes) {
                            sessionBean.addBusinessRemote(interfce.getName());
                        }

                        for (Class interfce : locals) {
                            sessionBean.addBusinessLocal(interfce.getName());
                        }
                    }
                }

                if (bean instanceof MessageDrivenBean) {
View Full Code Here

TOP

Related Classes of org.apache.openejb.jee.SessionBean

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.