use of org.apache.openejb.jee.CallbackMethod in project tomee by apache.
the class EjbJarInfoBuilder method copyCallbacks.
private void copyCallbacks(final List<? extends CallbackMethod> from, final List<CallbackInfo> to) {
for (final CallbackMethod callback : from) {
final CallbackInfo info = new CallbackInfo();
info.className = callback.getClassName();
info.method = callback.getMethodName();
to.add(info);
}
}
use of org.apache.openejb.jee.CallbackMethod in project tomee by apache.
the class CheckCallbacks method checkCallback.
private void checkCallback(final Class interceptorClass, final String type, final CallbackMethod callback, final Interceptor interceptor) {
try {
Class<?> delcaringClass = null;
try {
delcaringClass = callback.getClassName() == null ? interceptorClass : loadClass(callback.getClassName());
} catch (final OpenEJBException e) {
fail(type, "missing.class", callback.getClassName(), type, interceptor.getInterceptorClass());
return;
}
final Method method = getMethod(delcaringClass, callback.getMethodName(), InvocationContext.class);
final Class<?> returnType = method.getReturnType();
if (!returnType.equals(Void.TYPE)) {
fail("Interceptor", "interceptor.callback.badReturnType", interceptorClass, type, callback.getMethodName(), returnType.getName());
}
} catch (final NoSuchMethodException e) {
final List<Method> possibleMethods = getMethods(interceptorClass, callback.getMethodName());
if (possibleMethods.size() == 0) {
fail("Interceptor", "interceptor.callback.missing", type, callback.getMethodName(), interceptorClass.getName());
} else if (possibleMethods.size() == 1) {
fail("Interceptor", "interceptor.callback.invalidArguments", type, callback.getMethodName(), getParameters(possibleMethods.get(0)), interceptorClass.getName());
final Class<?> returnType = possibleMethods.get(0).getReturnType();
if (!returnType.equals(Void.TYPE)) {
fail("Interceptor", "interceptor.callback.badReturnType", interceptorClass, type, callback.getMethodName(), returnType.getName());
}
} else {
fail("Interceptor", "interceptor.callback.missing.possibleTypo", type, callback.getMethodName(), possibleMethods.size(), interceptorClass.getName());
}
}
}
use of org.apache.openejb.jee.CallbackMethod in project tomee by apache.
the class CheckCallbacks method checkCallback.
private void checkCallback(final Class<?> ejbClass, final String type, final CallbackMethod callback, final EnterpriseBean bean, final Class... parameterTypes) {
try {
Class<?> delcaringClass = null;
try {
delcaringClass = callback.getClassName() == null ? ejbClass : loadClass(callback.getClassName());
} catch (final OpenEJBException e) {
fail(type, "missing.class", callback.getClassName(), type, bean.getEjbName());
return;
}
final Method method = getMethod(delcaringClass, callback.getMethodName(), parameterTypes);
if (implementsSessionBean(delcaringClass)) {
if ("PreDestroy".equals(type)) {
if (!callback.getMethodName().equals("ejbRemove")) {
fail(bean.getEjbName(), "callback.sessionbean.invalidusage", type, callback.getMethodName(), ejbClass);
}
} else if ("PostActivate".equals(type)) {
if (!callback.getMethodName().equals("ejbActivate")) {
fail(bean.getEjbName(), "callback.sessionbean.invalidusage", type, callback.getMethodName(), ejbClass);
}
} else if ("PrePassivate".equals(type)) {
if (!callback.getMethodName().equals("ejbPassivate")) {
fail(bean.getEjbName(), "callback.sessionbean.invalidusage", type, callback.getMethodName(), ejbClass);
}
} else if ("PostConstruct".equals(type)) {
if (!callback.getMethodName().equals("ejbCreate")) {
fail(bean.getEjbName(), "callback.sessionbean.invalidusage", type, callback.getMethodName(), ejbClass);
}
}
// @AfterCompletion, @BeforeCompletion and @AfterBegin are assumed to be allowed to be used on Stateful bean implementing javax.ejb.SessionBean
}
final Class<?> returnType = method.getReturnType();
if (!returnType.equals(Void.TYPE)) {
fail(bean, "callback.badReturnType", type, callback.getMethodName(), returnType.getName(), callback.getClassName());
}
final int methodModifiers = method.getModifiers();
if (Modifier.isFinal(methodModifiers) || Modifier.isStatic(methodModifiers)) {
fail(bean, "callback.badModifier", type, callback.getMethodName(), callback.getClassName());
}
} catch (final NoSuchMethodException e) {
final List<Method> possibleMethods = getMethods(ejbClass, callback.getMethodName());
if (possibleMethods.size() == 0) {
fail(bean, "callback.missing", type, callback.getMethodName(), callback.getClassName());
} else if (possibleMethods.size() == 1) {
final Class<?>[] parameters = possibleMethods.get(0).getParameterTypes();
if (parameters.length == 1 && parameters[0].equals(InvocationContext.class)) {
fail(bean.getEjbName(), "callback.invocationcontext.notallowed", type, callback.getMethodName());
} else {
fail(bean, "callback.invalidArguments", type, callback.getMethodName(), getParameters(possibleMethods.get(0)), callback.getClassName(), getParameters(parameterTypes));
}
} else {
fail(bean, "callback.missing.possibleTypo", type, callback.getMethodName(), possibleMethods.size(), callback.getClassName(), getParameters(parameterTypes));
}
}
}
Aggregations