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);
}
}
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));
}
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations