Search in sources :

Example 1 with MutableComponentModel

use of org.apache.tapestry5.model.MutableComponentModel 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 MutableComponentModel

use of org.apache.tapestry5.model.MutableComponentModel 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 MutableComponentModel

use of org.apache.tapestry5.model.MutableComponentModel in project tapestry-5 by apache.

the class MutableComponentModelImplTest method get_mixin_class_names_mixes_with_parent_model.

@Test
public void get_mixin_class_names_mixes_with_parent_model() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel parent = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    parent.addMixinClassName("Wilma");
    MutableComponentModel child = new MutableComponentModelImpl(CLASS_NAME, logger, r, parent, false, null);
    child.addMixinClassName("Fred");
    child.addMixinClassName("Barney");
    assertEquals(child.getMixinClassNames(), Arrays.asList("Barney", "Fred", "Wilma"));
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 4 with MutableComponentModel

use of org.apache.tapestry5.model.MutableComponentModel in project tapestry-5 by apache.

the class MutableComponentModelImplTest method parent_handles_render_phase.

/**
 * @since 5.0.19
 */
@Test
public void parent_handles_render_phase() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel parent = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    MutableComponentModel child = new MutableComponentModelImpl(CLASS_NAME, logger, r, parent, false, null);
    parent.addRenderPhase(BeginRender.class);
    assertTrue(child.getHandledRenderPhases().contains(BeginRender.class));
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) BeginRender(org.apache.tapestry5.annotations.BeginRender) Test(org.testng.annotations.Test)

Example 5 with MutableComponentModel

use of org.apache.tapestry5.model.MutableComponentModel in project tapestry-5 by apache.

the class MutableComponentModelImplTest method add_duplicate_parameters_to_embedded.

@Test
public void add_duplicate_parameters_to_embedded() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    MutableEmbeddedComponentModel fred = model.addEmbeddedComponent("fred", "Fred", COMPONENT_CLASS_NAME, false, null);
    fred.addParameter("city", "bedrock");
    try {
        fred.addParameter("city", "slateville");
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "A value for parameter 'city' of embedded component fred (of component class org.example.components.Foo) has already been provided.");
    }
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) MutableEmbeddedComponentModel(org.apache.tapestry5.model.MutableEmbeddedComponentModel) Test(org.testng.annotations.Test)

Aggregations

MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)42 Test (org.testng.annotations.Test)42 Resource (org.apache.tapestry5.commons.Resource)37 Logger (org.slf4j.Logger)37 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)10 PlasticField (org.apache.tapestry5.plastic.PlasticField)7 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)6 PlasticMethod (org.apache.tapestry5.plastic.PlasticMethod)4 BeginRender (org.apache.tapestry5.annotations.BeginRender)3 Location (org.apache.tapestry5.commons.Location)3 Annotation (java.lang.annotation.Annotation)2 PersistenceContext (javax.persistence.PersistenceContext)2 SneakyThrows (lombok.SneakyThrows)2 ComponentResources (org.apache.tapestry5.ComponentResources)2 Import (org.apache.tapestry5.annotations.Import)2 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)2 JSONArray (org.apache.tapestry5.json.JSONArray)2 InstanceContext (org.apache.tapestry5.plastic.InstanceContext)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 SessionTracker (com.flowlogix.web.mixins.SessionTracker)1