Search in sources :

Example 1 with PlasticMethod

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);
                }
            }
        });
    }
}
Also used : SneakyThrows(lombok.SneakyThrows) MethodInvocation(org.apache.tapestry5.plastic.MethodInvocation) SessionTracker(com.flowlogix.web.mixins.SessionTracker) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) MethodAdvice(org.apache.tapestry5.plastic.MethodAdvice) IOException(java.io.IOException) AJAX(com.flowlogix.web.services.annotations.AJAX)

Example 2 with PlasticMethod

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);
    }
}
Also used : LoggingAdvice(org.apache.tapestry5.ioc.internal.services.LoggingAdvice) PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) MethodAdvice(org.apache.tapestry5.plastic.MethodAdvice)

Example 3 with PlasticMethod

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()));
    }
}
Also used : PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod) Operation(org.apache.tapestry5.ioc.annotations.Operation)

Example 4 with PlasticMethod

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);
        }
    };
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 5 with PlasticMethod

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);
}
Also used : Import(org.apache.tapestry5.annotations.Import)

Aggregations

PlasticMethod (org.apache.tapestry5.plastic.PlasticMethod)7 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)3 ComponentResources (org.apache.tapestry5.ComponentResources)2 ValueEncoder (org.apache.tapestry5.ValueEncoder)2 Import (org.apache.tapestry5.annotations.Import)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 InstructionBuilder (org.apache.tapestry5.plastic.InstructionBuilder)2 InstructionBuilderCallback (org.apache.tapestry5.plastic.InstructionBuilderCallback)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 PlasticField (org.apache.tapestry5.plastic.PlasticField)2 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)2 SessionTracker (com.flowlogix.web.mixins.SessionTracker)1 AJAX (com.flowlogix.web.services.annotations.AJAX)1 IOException (java.io.IOException)1 Array (java.lang.reflect.Array)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 List (java.util.List)1