За исключением проблемы, заключающейся в том, что мне придется проверять имя метода, чтобы добавить метод- конкретное поведение перехватчика:
Перехватчик:
Код: Выделить всё
@Nice
@Interceptor
public class NiceGreeterInterceptor {
@AroundInvoke
public Object decorate(InvocationContext ic) throws Exception {
Method method = ic.getMethod();
String methodName = method.getName();
Object result = ic.proceed();
if (methodName.equals("greet")) {
return "NEW " + result;
}
}
}
Код: Выделить всё
@Decorator
public class GreeterDecorator implements Greeter {
@Inject
@Any
@Delegate
private Greeter greeter;
@Override
public String greet() {
return "NEW " + greeter.greet();
}
}
Подробнее здесь: https://stackoverflow.com/questions/357 ... decorators
Мобильная версия