-
Notifications
You must be signed in to change notification settings - Fork 283
/
CombinedInterceptorAndDecoratorStackMethodHandler.java
99 lines (83 loc) · 3.62 KB
/
CombinedInterceptorAndDecoratorStackMethodHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.jboss.weld.bean.proxy;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.jboss.weld.bean.proxy.InterceptionDecorationContext.Stack;
import org.jboss.weld.exceptions.UnsupportedOperationException;
import org.jboss.weld.interceptor.proxy.InterceptorMethodHandler;
import org.jboss.weld.util.reflection.Reflections;
/**
* A method handler that wraps the invocation of interceptors and decorators.
*
* @author Marius Bogoevici
*/
public class CombinedInterceptorAndDecoratorStackMethodHandler implements StackAwareMethodHandler, Serializable {
public static final CombinedInterceptorAndDecoratorStackMethodHandler NULL_INSTANCE = new CombinedInterceptorAndDecoratorStackMethodHandler() {
@Override
public void setInterceptorMethodHandler(InterceptorMethodHandler interceptorMethodHandler) {
throw new UnsupportedOperationException();
}
@Override
public void setOuterDecorator(Object outerDecorator) {
throw new UnsupportedOperationException();
}
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
throw new UnsupportedOperationException();
}
};
private InterceptorMethodHandler interceptorMethodHandler;
private Object outerDecorator;
public void setInterceptorMethodHandler(InterceptorMethodHandler interceptorMethodHandler) {
this.interceptorMethodHandler = interceptorMethodHandler;
}
public void setOuterDecorator(Object outerDecorator) {
this.outerDecorator = outerDecorator;
}
@Override
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
return invoke(null, self, thisMethod, proceed, args);
}
@Override
public Object invoke(Stack stack, Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
if (stack == null) {
stack = InterceptionDecorationContext.getStack();
}
if (stack.startIfNotOnTop(this)) {
try {
if (interceptorMethodHandler != null) {
if (proceed != null) {
if (outerDecorator == null) {
// use WeldSubclass.method$$super() as proceed
return this.interceptorMethodHandler.invoke(stack, self, thisMethod, proceed, args);
} else {
return this.interceptorMethodHandler.invoke(stack, outerDecorator, thisMethod, thisMethod, args);
}
} else {
return this.interceptorMethodHandler.invoke(stack, self, thisMethod, null, args);
}
} else {
if (outerDecorator != null) {
SecurityActions.ensureAccessible(thisMethod);
return Reflections.invokeAndUnwrap(outerDecorator, thisMethod, args);
}
}
} finally {
stack.end();
}
}
SecurityActions.ensureAccessible(proceed);
return Reflections.invokeAndUnwrap(self, proceed, args);
}
public InterceptorMethodHandler getInterceptorMethodHandler() {
return interceptorMethodHandler;
}
public Object getOuterDecorator() {
return outerDecorator;
}
public boolean isDisabledHandler() {
return this == InterceptionDecorationContext.peekIfNotEmpty();
}
public boolean isDisabledHandler(Stack stack) {
return this == stack.peek();
}
}