|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InterceptorStackImpl.java | 66.7% | 91.7% | 100% | 89.5% |
|
1 |
// Copyright 2004 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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 |
* Implementation of the {@link org.apache.hivemind.InterceptorStack} interface; localizes
|
|
27 |
* error checking in one place.
|
|
28 |
*
|
|
29 |
* @author Howard Lewis Ship
|
|
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 | 16 |
public InterceptorStackImpl(Log log, ServicePoint sep, Object root)
|
41 |
{ |
|
42 | 16 |
_log = log; |
43 | 16 |
_sep = sep; |
44 | 16 |
_top = root; |
45 | 16 |
_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 | 27 |
public String getServiceExtensionPointId()
|
59 |
{ |
|
60 | 27 |
return _sep.getExtensionPointId();
|
61 |
} |
|
62 |
|
|
63 | 9 |
public Module getServiceModule()
|
64 |
{ |
|
65 | 9 |
return _sep.getModule();
|
66 |
} |
|
67 |
|
|
68 | 37 |
public Class getServiceInterface()
|
69 |
{ |
|
70 | 37 |
return _interfaceClass;
|
71 |
} |
|
72 |
|
|
73 | 34 |
public Object peek()
|
74 |
{ |
|
75 | 34 |
return _top;
|
76 |
} |
|
77 |
|
|
78 | 14 |
public void push(Object interceptor) |
79 |
{ |
|
80 | 14 |
if (interceptor == null) |
81 | 0 |
throw new ApplicationRuntimeException( |
82 |
ImplMessages.nullInterceptor(_contribution, _sep), |
|
83 |
_contribution.getLocation(), |
|
84 |
null);
|
|
85 |
|
|
86 | 14 |
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 | 14 |
_top = interceptor; |
97 |
} |
|
98 |
|
|
99 |
/**
|
|
100 |
* Invoked to process the next interceptor contribution; these should
|
|
101 |
* be processed in ascending order.
|
|
102 |
*
|
|
103 |
*/
|
|
104 |
|
|
105 | 17 |
public void process(ServiceInterceptorContribution contribution) |
106 |
{ |
|
107 | 17 |
if (_log.isDebugEnabled())
|
108 | 9 |
_log.debug("Applying interceptor factory " + contribution.getFactoryServiceId());
|
109 |
|
|
110 |
// And now we can finally do this!
|
|
111 |
|
|
112 | 17 |
try
|
113 |
{ |
|
114 | 17 |
_contribution = contribution; |
115 |
|
|
116 | 17 |
contribution.createInterceptor(this);
|
117 |
} |
|
118 |
finally
|
|
119 |
{ |
|
120 | 17 |
_contribution = null;
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
} |
|
125 |
|
|