use of com.flowlogix.web.services.annotations.AJAX in project flowlogix by flowlogix.
the class AjaxAnnotationWorker method transform.
@Override
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
boolean hasTrackerMixin = model.getMixinClassNames().contains(SessionTracker.class.getName());
for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(AJAX.class)) {
final AJAX annotation = method.getAnnotation(AJAX.class);
final boolean isVoid = method.isVoid();
if (annotation.requireSession() && (!hasTrackerMixin)) {
model.addMixinClassName(SessionTracker.class.getName());
hasTrackerMixin = true;
}
method.addAdvice(new MethodAdvice() {
@Override
@SneakyThrows(IOException.class)
public void advise(MethodInvocation invocation) {
if (!request.isXHR() || annotation.requireSession() == false) {
invocation.proceed();
} else {
// do not invoke on bad sessions
if (SessionTrackerUtil.isValidSession(rg.getActivePageName(), rg.getRequest().getSession(false))) {
invocation.proceed();
} else {
showSessionExpiredMessage = true;
SessionTrackerUtil.redirectToSelf(rg, linkSource);
if (!isVoid) {
invocation.setReturnValue(null);
}
return;
}
}
Object result = null;
if (!isVoid) {
result = invocation.getReturnValue();
}
if (!request.isXHR()) {
if (result != null) {
result = defaultForReturnType(result.getClass());
}
} else {
if (annotation.discardAfter()) {
cs.getActivePage().getComponentResources().discardPersistentFieldChanges();
}
}
if (!isVoid) {
invocation.setReturnValue(result);
}
}
});
}
}
Aggregations