1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.web.portlet;
18
19 import java.util.ArrayList;
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.springframework.util.CollectionUtils;
24 import org.springframework.util.ObjectUtils;
25
26
27
28
29
30
31
32
33
34
35 public class HandlerExecutionChain {
36
37 private final Object handler;
38
39 private HandlerInterceptor[] interceptors;
40
41 private List<HandlerInterceptor> interceptorList;
42
43
44
45
46
47
48 public HandlerExecutionChain(Object handler) {
49 this(handler, (HandlerInterceptor[]) null);
50 }
51
52
53
54
55
56
57
58 public HandlerExecutionChain(Object handler, HandlerInterceptor... interceptors) {
59 if (handler instanceof HandlerExecutionChain) {
60 HandlerExecutionChain originalChain = (HandlerExecutionChain) handler;
61 this.handler = originalChain.getHandler();
62 this.interceptorList = new ArrayList<HandlerInterceptor>();
63 CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList);
64 CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList);
65 }
66 else {
67 this.handler = handler;
68 this.interceptors = interceptors;
69 }
70 }
71
72
73
74
75
76
77 public Object getHandler() {
78 return this.handler;
79 }
80
81 public void addInterceptor(HandlerInterceptor interceptor) {
82 initInterceptorList().add(interceptor);
83 }
84
85 public void addInterceptors(HandlerInterceptor... interceptors) {
86 if (!ObjectUtils.isEmpty(interceptors)) {
87 initInterceptorList().addAll(Arrays.asList(interceptors));
88 }
89 }
90
91 private List<HandlerInterceptor> initInterceptorList() {
92 if (this.interceptorList == null) {
93 this.interceptorList = new ArrayList<HandlerInterceptor>();
94 if (this.interceptors != null) {
95
96 this.interceptorList.addAll(Arrays.asList(this.interceptors));
97 }
98 }
99 this.interceptors = null;
100 return this.interceptorList;
101 }
102
103
104
105
106
107 public HandlerInterceptor[] getInterceptors() {
108 if (this.interceptors == null && this.interceptorList != null) {
109 this.interceptors = this.interceptorList.toArray(new HandlerInterceptor[this.interceptorList.size()]);
110 }
111 return this.interceptors;
112 }
113
114
115
116
117
118 @Override
119 public String toString() {
120 return String.valueOf(this.handler);
121 }
122
123 }