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);
}
}
});
}
}
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);
}
}
}
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();
}
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();
}
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();
}
Aggregations