01: package org.vraptor;
02:
03: import java.util.ArrayList;
04: import java.util.Collections;
05: import java.util.List;
06:
07: import org.vraptor.interceptor.InterceptorType;
08: import org.vraptor.introspector.Introspector;
09: import org.vraptor.plugin.interceptor.ConcatenateInterceptorsLogicFlow;
10: import org.vraptor.view.ViewException;
11:
12: /**
13: * An interceptor that can be used to group common interceptors into one,
14: * avoiding lots of classes inside an InterceptedBy annotation.
15: *
16: * @author Paulo Silveira
17: * @author Guilherme Silveira
18: * @since 2.3.1
19: */
20: public class InterceptorStack implements Interceptor {
21:
22: private final List<InterceptorType> interceptors;
23:
24: /**
25: * Constructs an InterceptorStack with the given interceptors
26: *
27: * @param interceptors
28: */
29: public InterceptorStack(
30: Class<? extends Interceptor>... interceptorClasses) {
31: if (interceptorClasses == null) {
32: throw new NullPointerException();
33: }
34:
35: this .interceptors = new ArrayList<InterceptorType>();
36:
37: for (Class<? extends Interceptor> interceptorClass : interceptorClasses) {
38: InterceptorType type = InterceptorType
39: .getType(interceptorClass);
40: interceptors.add(type);
41: }
42: }
43:
44: /**
45: * Intercepts the logic flow with the given interceptors, respecting the
46: * order.
47: */
48: public void intercept(LogicFlow realFlow) throws LogicException,
49: ViewException {
50: Introspector introspector = (Introspector) realFlow
51: .getLogicRequest().getApplicationContext()
52: .getAttribute(Introspector.class.getName());
53: new ConcatenateInterceptorsLogicFlow(interceptors, realFlow,
54: introspector).execute();
55: }
56:
57: public List<InterceptorType> getInterceptors() {
58: return Collections.unmodifiableList(interceptors);
59: }
60: }
|