01: package org.vraptor.component;
02:
03: import java.lang.reflect.Method;
04:
05: import org.vraptor.annotations.Out;
06: import org.vraptor.reflection.MethodInvocationException;
07: import org.vraptor.reflection.ReflectionUtil;
08: import org.vraptor.scope.ScopeType;
09:
10: /**
11: * A getter outjection.
12: *
13: * @author Guilherme Silveira
14: * @since 2.2.3
15: */
16: public class GetterOutjecter implements Outjecter {
17:
18: private static final Object[] EMPTY_ARRAY = new Object[0];
19:
20: private final ScopeType scope;
21:
22: private final String key;
23:
24: private final Method method;
25:
26: public GetterOutjecter(String key, Method method) {
27: Out out = method.getAnnotation(Out.class);
28: if (out == null) {
29: scope = ScopeType.REQUEST;
30: this .key = key;
31: } else {
32: scope = out.scope();
33: if (out.key() == null || out.key().equals("")) {
34: this .key = key;
35: } else {
36: this .key = out.key();
37: }
38: }
39: this .method = method;
40: }
41:
42: public String getKey() {
43: return key;
44: }
45:
46: public ScopeType getScope() {
47: return scope;
48: }
49:
50: public Object getValue(Object obj) throws MethodInvocationException {
51: return ReflectionUtil.invoke(obj, method, EMPTY_ARRAY);
52: }
53:
54: }
|