1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.impl; |
16 |
| |
17 |
| import org.apache.commons.logging.Log; |
18 |
| import org.apache.hivemind.ApplicationRuntimeException; |
19 |
| import org.apache.hivemind.InterceptorStack; |
20 |
| import org.apache.hivemind.internal.Module; |
21 |
| import org.apache.hivemind.internal.ServiceInterceptorContribution; |
22 |
| import org.apache.hivemind.internal.ServicePoint; |
23 |
| import org.apache.hivemind.util.ToStringBuilder; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public final class InterceptorStackImpl implements InterceptorStack |
32 |
| { |
33 |
| private final Log _log; |
34 |
| |
35 |
| private ServiceInterceptorContribution _contribution; |
36 |
| private ServicePoint _sep; |
37 |
| private Class _interfaceClass; |
38 |
| private Object _top; |
39 |
| |
40 |
18
| public InterceptorStackImpl(Log log, ServicePoint sep, Object root)
|
41 |
| { |
42 |
18
| _log = log;
|
43 |
18
| _sep = sep;
|
44 |
18
| _top = root;
|
45 |
18
| _interfaceClass = sep.getServiceInterface();
|
46 |
| } |
47 |
| |
48 |
1
| public String toString()
|
49 |
| { |
50 |
1
| ToStringBuilder builder = new ToStringBuilder(this);
|
51 |
1
| builder.append("contribution", _contribution);
|
52 |
1
| builder.append("interfaceClass", _interfaceClass);
|
53 |
1
| builder.append("top", _top);
|
54 |
| |
55 |
1
| return builder.toString();
|
56 |
| } |
57 |
| |
58 |
11
| public String getServiceExtensionPointId()
|
59 |
| { |
60 |
11
| return _sep.getExtensionPointId();
|
61 |
| } |
62 |
| |
63 |
0
| public Module getServiceModule()
|
64 |
| { |
65 |
0
| return _sep.getModule();
|
66 |
| } |
67 |
| |
68 |
51
| public Class getServiceInterface()
|
69 |
| { |
70 |
51
| return _interfaceClass;
|
71 |
| } |
72 |
| |
73 |
42
| public Object peek()
|
74 |
| { |
75 |
42
| return _top;
|
76 |
| } |
77 |
| |
78 |
16
| public void push(Object interceptor)
|
79 |
| { |
80 |
16
| if (interceptor == null)
|
81 |
0
| throw new ApplicationRuntimeException(
|
82 |
| ImplMessages.nullInterceptor(_contribution, _sep), |
83 |
| _contribution.getLocation(), |
84 |
| null); |
85 |
| |
86 |
16
| if (!_interfaceClass.isAssignableFrom(interceptor.getClass()))
|
87 |
0
| throw new ApplicationRuntimeException(
|
88 |
| ImplMessages.interceptorDoesNotImplementInterface( |
89 |
| interceptor, |
90 |
| _contribution, |
91 |
| _sep, |
92 |
| _interfaceClass), |
93 |
| _contribution.getLocation(), |
94 |
| null); |
95 |
| |
96 |
16
| _top = interceptor;
|
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
18
| public void process(ServiceInterceptorContribution contribution)
|
106 |
| { |
107 |
18
| if (_log.isDebugEnabled())
|
108 |
4
| _log.debug("Applying interceptor factory " + contribution.getFactoryServiceId());
|
109 |
| |
110 |
| |
111 |
| |
112 |
18
| try
|
113 |
| { |
114 |
18
| _contribution = contribution;
|
115 |
| |
116 |
18
| contribution.createInterceptor(this);
|
117 |
| } |
118 |
| finally |
119 |
| { |
120 |
18
| _contribution = null;
|
121 |
| } |
122 |
| } |
123 |
| |
124 |
12
| public Log getServiceLog()
|
125 |
| { |
126 |
12
| return _log;
|
127 |
| } |
128 |
| } |