01: package org.mockejb.interceptor;
02:
03: /**
04: * This class provides a simple way to create an aspect
05: * from the existing interceptor and pointcut. Used internally by the AspectSystem.
06: *
07: * @author Alexander Ananiev
08: */
09: class InterceptorContainerAspect implements Aspect {
10:
11: private Pointcut pointcut;
12: private Interceptor interceptor;
13:
14: public InterceptorContainerAspect(Pointcut pointcut,
15: Interceptor interceptor) {
16:
17: if (pointcut == null)
18: throw new IllegalArgumentException(
19: "Interceptor can't be null");
20:
21: if (interceptor == null)
22: throw new IllegalArgumentException("Pointcut can't be null");
23:
24: this .pointcut = pointcut;
25: this .interceptor = interceptor;
26: }
27:
28: public Pointcut getPointcut() {
29: return pointcut;
30: }
31:
32: public void intercept(InvocationContext invocationContext)
33: throws Exception {
34: interceptor.intercept(invocationContext);
35: }
36:
37: public Interceptor getInterceptor() {
38: return interceptor;
39: }
40:
41: /**
42: * Returns true if the given object is of type Aspect
43: * and its pointcut and interceptor equal to the ones of this object
44: */
45: public boolean equals(Object obj) {
46:
47: if (!(obj instanceof InterceptorContainerAspect))
48: return false;
49:
50: InterceptorContainerAspect aspect = (InterceptorContainerAspect) obj;
51:
52: return (pointcut.equals(aspect.pointcut) && interceptor
53: .equals(aspect.interceptor));
54: }
55:
56: public int hashCode() {
57:
58: int result = 17;
59: result = 37 * result + pointcut.hashCode();
60: result = 37 * result + interceptor.hashCode();
61:
62: return result;
63:
64: }
65:
66: }
|