use of org.apache.openejb.jee.SessionBean 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 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 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 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);
}
}
}
}
use of org.apache.openejb.jee.SessionBean in project tomee by apache.
the class CheckRestMethodArePublic method validate.
@Override
public void validate(final AppModule appModule) {
// valid standalone classes
final Collection<String> standAloneClasses = new ArrayList<String>();
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
for (final EjbModule ejb : appModule.getEjbModules()) {
Thread.currentThread().setContextClassLoader(ejb.getClassLoader());
for (final EnterpriseBean bean : ejb.getEjbJar().getEnterpriseBeans()) {
if (bean instanceof SessionBean && ((SessionBean) bean).isRestService()) {
standAloneClasses.add(bean.getEjbClass());
valid(ejb.getValidation(), ejb.getClassLoader(), bean.getEjbClass());
}
}
}
for (final WebModule web : appModule.getWebModules()) {
Thread.currentThread().setContextClassLoader(web.getClassLoader());
// build the list of classes to validate
final Collection<String> classes = new ArrayList<String>();
classes.addAll(web.getRestClasses());
classes.addAll(web.getEjbRestServices());
for (final String app : web.getRestApplications()) {
final Class<?> clazz;
try {
clazz = web.getClassLoader().loadClass(app);
} catch (final ClassNotFoundException e) {
// managed elsewhere, here we just check methods
continue;
}
final Application appInstance;
try {
appInstance = (Application) clazz.newInstance();
} catch (final Exception e) {
// managed elsewhere
continue;
}
try {
for (final Class<?> rsClass : appInstance.getClasses()) {
classes.add(rsClass.getName());
}
/* don't do it or ensure you have cdi activated! + CXF will catch it later
for (final Object rsSingleton : appInstance.getSingletons()) {
classes.add(rsSingleton.getClass().getName());
}
*/
} catch (final RuntimeException npe) {
if (appInstance == null) {
throw npe;
}
// if app relies on cdi it is null here
}
}
// try to avoid to valid twice the same classes
final Iterator<String> it = classes.iterator();
while (it.hasNext()) {
final String current = it.next();
if (standAloneClasses.contains(current)) {
it.remove();
}
}
// valid
for (final String classname : classes) {
valid(web.getValidation(), web.getClassLoader(), classname);
}
classes.clear();
}
} finally {
Thread.currentThread().setContextClassLoader(loader);
}
standAloneClasses.clear();
}
Aggregations