Search in sources :

Example 1 with TransformationSupport

use of org.apache.tapestry5.services.transform.TransformationSupport 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 TransformationSupport

use of org.apache.tapestry5.services.transform.TransformationSupport in project flowlogix by flowlogix.

the class EJBAnnotationWorker method transform.

@Override
@SneakyThrows({ NamingException.class })
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
    for (PlasticField field : plasticClass.getFieldsWithAnnotation(EJB.class)) {
        final EJB annotation = field.getAnnotation(EJB.class);
        final Stateful stateful = field.getAnnotation(Stateful.class);
        final String fieldType = field.getTypeName();
        final String fieldName = field.getName();
        final String mappedName = annotation.mappedName();
        final JNDIObjectLocator locator = JNDIObjectLocator.builder().build();
        final String lookupname = getLookupName(annotation, fieldType, locator);
        Object injectionValue = lookupBean(field, fieldType, fieldName, lookupname, mappedName, stateful, locator);
        if (injectionValue != null) {
            field.claim(annotation);
        }
    }
}
Also used : Stateful(com.flowlogix.web.services.annotations.Stateful) PlasticField(org.apache.tapestry5.plastic.PlasticField) EJB(javax.ejb.EJB) JNDIObjectLocator(org.omnifaces.util.JNDIObjectLocator) SneakyThrows(lombok.SneakyThrows)

Example 3 with TransformationSupport

use of org.apache.tapestry5.services.transform.TransformationSupport 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 4 with TransformationSupport

use of org.apache.tapestry5.services.transform.TransformationSupport 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 5 with TransformationSupport

use of org.apache.tapestry5.services.transform.TransformationSupport in project tapestry-5 by apache.

the class PageActivationContextWorker method transformFields.

private void transformFields(TransformationSupport support, List<PlasticField> fields) {
    List<PlasticField> sortedFields = CollectionFactory.newList(fields);
    Collections.sort(sortedFields, INDEX_COMPARATOR);
    validateSortedFields(sortedFields);
    PlasticField firstField = sortedFields.get(0);
    PageActivationContext firstAnnotation = firstField.getAnnotation(PageActivationContext.class);
    // these arrays reduce memory usage and allow the PlasticField instances to be garbage collected
    FieldHandle[] handles = new FieldHandle[sortedFields.size()];
    String[] typeNames = new String[sortedFields.size()];
    int i = 0;
    for (PlasticField field : sortedFields) {
        handles[i] = field.getHandle();
        typeNames[i] = field.getTypeName();
        ++i;
    }
    if (firstAnnotation.activate()) {
        support.addEventHandler(EventConstants.ACTIVATE, 1, "PageActivationContextWorker activate event handler", createActivationHandler(handles, typeNames));
    }
    if (firstAnnotation.passivate()) {
        support.addEventHandler(EventConstants.PASSIVATE, 0, "PageActivationContextWorker passivate event handler", createPassivateHandler(handles));
    }
// We don't claim the field, and other workers may even replace it with a FieldConduit.
}
Also used : PageActivationContext(org.apache.tapestry5.annotations.PageActivationContext) PlasticField(org.apache.tapestry5.plastic.PlasticField) FieldHandle(org.apache.tapestry5.plastic.FieldHandle)

Aggregations

PlasticField (org.apache.tapestry5.plastic.PlasticField)8 PlasticMethod (org.apache.tapestry5.plastic.PlasticMethod)4 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)3 Component (org.apache.tapestry5.runtime.Component)3 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)3 ComponentEventHandler (org.apache.tapestry5.services.ComponentEventHandler)3 PersistenceContext (javax.persistence.PersistenceContext)2 SneakyThrows (lombok.SneakyThrows)2 FieldHandle (org.apache.tapestry5.plastic.FieldHandle)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 SessionTracker (com.flowlogix.web.mixins.SessionTracker)1 AJAX (com.flowlogix.web.services.annotations.AJAX)1 CDI (com.flowlogix.web.services.annotations.CDI)1 Stateful (com.flowlogix.web.services.annotations.Stateful)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 EJB (javax.ejb.EJB)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 ValueEncoder (org.apache.tapestry5.ValueEncoder)1 ActivationRequestParameter (org.apache.tapestry5.annotations.ActivationRequestParameter)1