use of org.apache.tapestry5.plastic.PlasticMethod 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);
}
}
});
}
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class LogWorker method transform.
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
List<PlasticMethod> methods = plasticClass.getMethodsWithAnnotation(Log.class);
if (methods.isEmpty()) {
return;
}
final MethodAdvice loggingAdvice = new LoggingAdvice(model.getLogger(), exceptionTracker);
for (PlasticMethod method : methods) {
method.addAdvice(loggingAdvice);
}
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class OperationWorker method transform.
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(Operation.class)) {
Operation annotation = method.getAnnotation(Operation.class);
method.addAdvice(advisor.createAdvice(annotation.value()));
}
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class CachedWorker method createFactory.
private MethodResultCacheFactory createFactory(PlasticClass plasticClass, final String watch, PlasticMethod method) {
// will suffice.
if (watch.equals("")) {
return nonWatchFactory;
}
// Because of the watch, its necessary to create a factory for instances of this component and method.
final FieldHandle bindingFieldHandle = plasticClass.introduceField(Binding.class, "cache$watchBinding$" + method.getDescription().methodName).getHandle();
// Each component instance will get its own Binding instance. That handles both different locales,
// and reuse of a component (with a cached method) within a page or across pages. However, the binding can't be initialized
// until the page loads.
plasticClass.introduceInterface(PageLifecycleListener.class);
plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION).addAdvice(new MethodAdvice() {
public void advise(MethodInvocation invocation) {
ComponentResources resources = invocation.getInstanceContext().get(ComponentResources.class);
Binding binding = bindingSource.newBinding("@Cached watch", resources, BindingConstants.PROP, watch);
bindingFieldHandle.set(invocation.getInstance(), binding);
invocation.proceed();
}
});
return new MethodResultCacheFactory() {
public MethodResultCache create(Object instance) {
Binding binding = (Binding) bindingFieldHandle.get(instance);
return new WatchedBindingMethodResultCache(binding);
}
};
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class ImportWorker method decorateMethod.
private void decorateMethod(PlasticClass componentClass, MutableComponentModel model, PlasticMethod method) {
Import annotation = method.getAnnotation(Import.class);
decorateMethod(componentClass, model, method, annotation);
}
Aggregations