use of org.apache.tapestry5.ioc.MethodAdviceReceiver in project tapestry-5 by apache.
the class ServiceAdvisorImpl method advise.
/**
* Invokes the configured method, passing the builder. The method will always take, as a parameter, a
* MethodAdvisor.
*/
@Override
public void advise(MethodAdviceReceiver methodAdviceReceiver) {
Map<Class, Object> resources = CollectionFactory.newMap(this.resourcesDefaults);
resources.put(MethodAdviceReceiver.class, methodAdviceReceiver);
InjectionResources injectionResources = new MapInjectionResources(resources);
// By design, advise methods return void, so we know that the return value is null.
invoke(injectionResources);
}
use of org.apache.tapestry5.ioc.MethodAdviceReceiver in project tapestry-5 by apache.
the class JpaTransactionAdvisorImpl method addTransactionCommitAdvice.
@Override
public void addTransactionCommitAdvice(MethodAdviceReceiver receiver) {
for (final Method m : receiver.getInterface().getMethods()) {
if (m.getAnnotation(CommitAfter.class) != null) {
PersistenceContext annotation = receiver.getMethodAnnotation(m, PersistenceContext.class);
receiver.adviseMethod(m, methodAdvices.get(annotation == null ? null : annotation.unitName()));
}
}
}
use of org.apache.tapestry5.ioc.MethodAdviceReceiver in project tapestry-5 by apache.
the class TapestryModule method componentReplacer.
@Advise(serviceInterface = ComponentInstantiatorSource.class)
public static void componentReplacer(MethodAdviceReceiver methodAdviceReceiver, final ComponentOverride componentReplacer) throws NoSuchMethodException, SecurityException {
if (componentReplacer.hasReplacements()) {
MethodAdvice advice = new MethodAdvice() {
@Override
public void advise(MethodInvocation invocation) {
String className = (String) invocation.getParameter(0);
final Class<?> replacement = componentReplacer.getReplacement(className);
if (replacement != null) {
invocation.setParameter(0, replacement.getName());
}
invocation.proceed();
}
};
methodAdviceReceiver.adviseMethod(ComponentInstantiatorSource.class.getMethod("getInstantiator", String.class), advice);
}
}
use of org.apache.tapestry5.ioc.MethodAdviceReceiver in project tapestry-5 by apache.
the class LazyAdvisorImpl method addAdvice.
private void addAdvice(Method method, MethodAdviceReceiver receiver) {
final Class thunkType = method.getReturnType();
final String description = String.format("<%s Thunk for %s>", thunkType.getName(), InternalUtils.asString(method));
MethodAdvice advice = new MethodAdvice() {
/**
* When the method is invoked, we don't immediately proceed. Instead, we return a thunk instance
* that defers its behavior to the lazily invoked invocation.
*/
@Override
public void advise(final MethodInvocation invocation) {
ObjectCreator deferred = new ObjectCreator() {
@Override
public Object createObject() {
invocation.proceed();
return invocation.getReturnValue();
}
};
ObjectCreator cachingObjectCreator = new CachingObjectCreator(deferred);
Object thunk = thunkCreator.createThunk(thunkType, cachingObjectCreator, description);
invocation.setReturnValue(thunk);
}
};
receiver.adviseMethod(method, advice);
}
use of org.apache.tapestry5.ioc.MethodAdviceReceiver in project tapestry-5 by apache.
the class LoggingAdvisorImpl method addLoggingAdvice.
@Override
public void addLoggingAdvice(Logger logger, MethodAdviceReceiver receiver) {
MethodAdvice advice = new LoggingAdvice(logger, exceptionTracker);
receiver.adviseAllMethods(advice);
}
Aggregations