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