use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.
the class EjbSessionDescriptor method addPrePassivateDescriptor.
public void addPrePassivateDescriptor(LifecycleCallbackDescriptor prePassivateDesc) {
String className = prePassivateDesc.getLifecycleCallbackClass();
boolean found = false;
for (LifecycleCallbackDescriptor next : getPrePassivateDescriptors()) {
if (next.getLifecycleCallbackClass().equals(className)) {
found = true;
break;
}
}
if (!found) {
getPrePassivateDescriptors().add(prePassivateDesc);
}
}
use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.
the class CallbackMethodException method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
ClassLoader cl = getVerifierContext().getClassLoader();
Set<LifecycleCallbackDescriptor> callbackDescs = new HashSet<LifecycleCallbackDescriptor>();
for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
callbackDescs.addAll(interceptor.getPostConstructDescriptors());
callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
}
if (descriptor.hasPostConstructMethod())
callbackDescs.addAll(descriptor.getPostConstructDescriptors());
if (descriptor.hasPreDestroyMethod())
callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
// session descriptor has two extra interceptor methods.
if (descriptor instanceof EjbSessionDescriptor) {
EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor) descriptor);
if (ejbSessionDescriptor.hasPostActivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
if (ejbSessionDescriptor.hasPrePassivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
}
for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
try {
Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
Class[] excepClasses = method.getExceptionTypes();
for (Class exception : excepClasses) {
if (!(RuntimeException.class.isAssignableFrom(exception) || java.rmi.RemoteException.class.isAssignableFrom(exception))) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws an application exception.", new Object[] { method }));
}
}
}// will be caught in other tests
catch (Exception e) {
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Callback methods."));
}
return result;
}
use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.
the class CallbacksOnBeanClass method check.
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
for (EjbInterceptor interceptor : interceptors) {
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE);
reportError(callBackDescs, "ejbActivate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE);
reportError(callBackDescs, "ejbPassivate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT);
reportError(callBackDescs, "ejbCreate", interceptor.getInterceptorClassName());
}
if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY)) {
Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY);
reportError(callBackDescs, "ejbRemove", interceptor.getInterceptorClassName());
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid lifecycle callback method(s)"));
}
return result;
}
use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.
the class EjbServicesImpl method makeInterceptorChain.
private List<EjbInterceptor> makeInterceptorChain(InterceptionType interceptionType, List<Interceptor<?>> lifecycleList, com.sun.enterprise.deployment.EjbDescriptor ejbDesc) {
List<EjbInterceptor> ejbInterceptorList = new LinkedList<EjbInterceptor>();
if (lifecycleList == null) {
return ejbInterceptorList;
}
for (Interceptor<?> next : lifecycleList) {
EjbInterceptor ejbInt = makeEjbInterceptor(next, ejbDesc.getEjbBundleDescriptor());
Class<?> interceptorClass = next.getBeanClass();
while (interceptorClass != null && !interceptorClass.equals(Object.class)) {
String methodName = getInterceptorMethod(interceptorClass, getInterceptorAnnotationType(interceptionType));
if (methodName != null) {
LifecycleCallbackDescriptor lifecycleDesc = new LifecycleCallbackDescriptor();
lifecycleDesc.setLifecycleCallbackClass(interceptorClass.getName());
lifecycleDesc.setLifecycleCallbackMethod(methodName);
switch(interceptionType) {
case POST_CONSTRUCT:
ejbInt.addPostConstructDescriptor(lifecycleDesc);
break;
case PRE_DESTROY:
ejbInt.addPreDestroyDescriptor(lifecycleDesc);
break;
case PRE_PASSIVATE:
ejbInt.addPrePassivateDescriptor(lifecycleDesc);
break;
case POST_ACTIVATE:
ejbInt.addPostActivateDescriptor(lifecycleDesc);
break;
case AROUND_INVOKE:
lifecycleDesc.setRequiresInvocationContextArgument(true);
ejbInt.addAroundInvokeDescriptor(lifecycleDesc);
break;
case AROUND_TIMEOUT:
lifecycleDesc.setRequiresInvocationContextArgument(true);
ejbInt.addAroundTimeoutDescriptor(lifecycleDesc);
break;
case AROUND_CONSTRUCT:
ejbInt.addAroundConstructDescriptor(lifecycleDesc);
break;
default:
throw new IllegalArgumentException("Invalid lifecycle interception type " + interceptionType);
}
}
interceptorClass = interceptorClass.getSuperclass();
}
ejbInterceptorList.add(ejbInt);
}
return ejbInterceptorList;
}
use of com.sun.enterprise.deployment.LifecycleCallbackDescriptor in project Payara by payara.
the class BeanCallbackInterceptor method createCallbackInterceptors.
private List<CallbackInterceptor> createCallbackInterceptors(CallbackType eventType, InterceptorDescriptor inter, ClassLoader classLoaderToUse) throws Exception {
List<CallbackInterceptor> callbackList = new ArrayList<CallbackInterceptor>();
List<LifecycleCallbackDescriptor> orderedCallbackMethods = inter.getOrderedCallbackDescriptors(eventType, classLoaderToUse);
String className = inter.getInterceptorClassName();
for (LifecycleCallbackDescriptor callbackDesc : orderedCallbackMethods) {
Method method = null;
try {
method = callbackDesc.getLifecycleCallbackMethodObject(classLoaderToUse);
} catch (Exception e) {
throw new IllegalStateException("No callback method of name " + callbackDesc.getLifecycleCallbackMethod() + " found on class " + className, e);
}
CallbackInterceptor interceptor = null;
if (inter.getFromBeanClass()) {
interceptor = new BeanCallbackInterceptor(method);
} else {
Integer bigInt = instanceIndexMap.get(className);
int index = (bigInt == null) ? -1 : bigInt;
if (index == -1) {
throw new IllegalStateException(getInternalErrorString(className));
}
interceptor = new CallbackInterceptor(index, method);
}
callbackList.add(interceptor);
}
return callbackList;
}
Aggregations