Search in sources :

Example 6 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckClasses method validate.

public void validate(final EjbModule ejbModule) {
    final ClassLoader loader = ejbModule.getClassLoader();
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        try {
            final Class<?> beanClass = check_hasEjbClass(loader, bean);
            // All the subsequent checks require the bean class
            if (beanClass == null) {
                continue;
            }
            if (!(bean instanceof RemoteBean)) {
                continue;
            }
            if (bean instanceof SessionBean && ((SessionBean) bean).getProxy() != null) {
                continue;
            }
            final RemoteBean b = (RemoteBean) bean;
            check_isEjbClass(b);
            check_hasDependentClasses(b, b.getEjbClass(), "ejb-class");
            check_hasInterface(b);
            if (b.getRemote() != null) {
                checkInterface(loader, b, beanClass, "remote", b.getRemote());
            }
            if (b.getHome() != null) {
                checkInterface(loader, b, beanClass, "home", b.getHome());
            }
            if (b.getLocal() != null) {
                checkInterface(loader, b, beanClass, "local", b.getLocal());
            }
            if (b.getLocalHome() != null) {
                checkInterface(loader, b, beanClass, "local-home", b.getLocalHome());
            }
            if (b instanceof SessionBean) {
                final SessionBean sessionBean = (SessionBean) b;
                for (final String interfce : sessionBean.getBusinessLocal()) {
                    checkInterface(loader, b, beanClass, "business-local", interfce);
                }
                for (final String interfce : sessionBean.getBusinessRemote()) {
                    checkInterface(loader, b, beanClass, "business-remote", interfce);
                }
            }
        } catch (final RuntimeException e) {
            throw new OpenEJBRuntimeException(bean.getEjbName(), e);
        }
    }
    for (final Interceptor interceptor : ejbModule.getEjbJar().getInterceptors()) {
        check_hasInterceptorClass(loader, interceptor);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) RemoteBean(org.apache.openejb.jee.RemoteBean) SessionBean(org.apache.openejb.jee.SessionBean) Interceptor(org.apache.openejb.jee.Interceptor)

Example 7 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckDependsOn method validate.

public void validate(final AppModule appModule) {
    module = appModule;
    final LinkResolver<Bean> app = new LinkResolver<Bean>();
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        final Resolver<Bean> resolver = new Resolver(app, new LinkResolver<Bean>());
        for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
            final Bean b = new Bean(bean, ejbModule, ejbModule.getModuleUri(), resolver);
            resolver.module.add(ejbModule.getModuleUri(), bean.getEjbName(), b);
            resolver.app.add(ejbModule.getModuleUri(), bean.getEjbName(), b);
        }
    }
    for (final Bean bean : app.values()) {
        final EnterpriseBean enterpriseBean = bean.bean;
        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);
            }
        }
    }
    try {
        References.sort(new ArrayList<Bean>(app.values()), new References.Visitor<Bean>() {

            public String getName(final Bean t) {
                return t.getId();
            }

            public Set<String> getReferences(final Bean t) {
                final LinkedHashSet<String> refs = new LinkedHashSet<String>();
                for (final Bean bean : t.dependsOn) {
                    refs.add(bean.getId());
                }
                return refs;
            }
        });
    } catch (final CircularReferencesException e) {
        for (final List<Bean> circuit : e.getCircuits()) {
            final List<String> ejbNames = new ArrayList<String>(circuit.size());
            for (final Bean bean : circuit) {
                ejbNames.add(bean.bean.getEjbName());
            }
            fail("EAR", "dependsOn.circuit", Join.join(" -> ", ejbNames), ejbNames.get(0));
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) LinkResolver(org.apache.openejb.util.LinkResolver) EjbModule(org.apache.openejb.config.EjbModule) SessionBean(org.apache.openejb.jee.SessionBean) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) SessionBean(org.apache.openejb.jee.SessionBean) LinkResolver(org.apache.openejb.util.LinkResolver) References(org.apache.openejb.util.References) CircularReferencesException(org.apache.openejb.util.CircularReferencesException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckMethods method check_createMethodsAreImplemented.

public boolean check_createMethodsAreImplemented(final RemoteBean b, final Class bean, final Class home) {
    boolean result = true;
    final Method[] homeMethods = home.getMethods();
    for (int i = 0; i < homeMethods.length; i++) {
        if (!homeMethods[i].getName().startsWith("create")) {
            continue;
        }
        final Method create = homeMethods[i];
        final StringBuilder ejbCreateName = new StringBuilder(create.getName());
        ejbCreateName.replace(0, 1, "ejbC");
        try {
            if (javax.ejb.EnterpriseBean.class.isAssignableFrom(bean)) {
                bean.getMethod(ejbCreateName.toString(), create.getParameterTypes());
            }
        // TODO: else { /* Check for Init method in pojo session bean class */ }
        } catch (final NoSuchMethodException e) {
            result = false;
            final String paramString = getParameters(create);
            if (b instanceof EntityBean) {
                final EntityBean entity = (EntityBean) b;
                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);
                    }
                }
            }
        }
    }
    return result;
}
Also used : EntityBean(org.apache.openejb.jee.EntityBean) Method(java.lang.reflect.Method) SessionBean(org.apache.openejb.jee.SessionBean)

Example 9 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckMethods method check_postCreateMethodsAreImplemented.

public boolean check_postCreateMethodsAreImplemented(final RemoteBean b, final Class bean, final Class home) {
    boolean result = true;
    if (b instanceof SessionBean) {
        return true;
    }
    final Method[] homeMethods = home.getMethods();
    final Method[] beanMethods = bean.getMethods();
    for (int i = 0; i < homeMethods.length; i++) {
        if (!homeMethods[i].getName().startsWith("create")) {
            continue;
        }
        final Method create = homeMethods[i];
        final StringBuilder ejbPostCreateName = new StringBuilder(create.getName());
        ejbPostCreateName.replace(0, 1, "ejbPostC");
        try {
            bean.getMethod(ejbPostCreateName.toString(), create.getParameterTypes());
        } catch (final NoSuchMethodException e) {
            result = false;
            final String paramString = getParameters(create);
            fail(b, "no.ejb.post.create", b.getEjbClass(), ejbPostCreateName.toString(), paramString);
        }
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) SessionBean(org.apache.openejb.jee.SessionBean)

Example 10 with SessionBean$JAXB.readSessionBean

use of org.apache.openejb.jee.SessionBean$JAXB.readSessionBean in project tomee by apache.

the class CheckPersistenceRefs method validate.

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) {
                // skipping since we don't know here what is the type
                continue;
            }
        }
        final String beanType = getType(bean);
        if (beanType.equals("Stateful")) {
            // skip statefuls and Comp ManagedBean
            continue;
        }
        for (final PersistenceContextRef ref : bean.getPersistenceContextRef()) {
            if (isExtented(ref)) {
                String refName = ref.getName();
                final String prefix = bean.getEjbClass() + "/";
                if (refName.startsWith(prefix)) {
                    refName = refName.substring(prefix.length());
                }
                fail(bean, "persistenceContextExtented.nonStateful", refName, beanType);
            }
        }
    }
}
Also used : EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PersistenceContextRef(org.apache.openejb.jee.PersistenceContextRef) SessionBean(org.apache.openejb.jee.SessionBean)

Aggregations

SessionBean (org.apache.openejb.jee.SessionBean)22 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)12 EjbJar (org.apache.openejb.jee.EjbJar)10 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)8 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)7 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)4 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 PortInfo (org.apache.openejb.assembler.classic.PortInfo)3 EjbModule (org.apache.openejb.config.EjbModule)3 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 Beans (org.apache.openejb.jee.Beans)2 EntityBean (org.apache.openejb.jee.EntityBean)2 Interceptor (org.apache.openejb.jee.Interceptor)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1