01: package org.vraptor.component;
02:
03: import java.lang.reflect.Type;
04:
05: import org.vraptor.converter.Converter;
06: import org.vraptor.introspector.ReadParameter;
07: import org.vraptor.reflection.SettingException;
08:
09: /**
10: * Defines an argument that a logic method receives.
11: *
12: * @author Guilherme Silveira
13: * @since 2.3
14: */
15: public class MethodParameter implements ReadParameter {
16:
17: private final Clazz paramType;
18:
19: private final String key;
20:
21: private final int position;
22:
23: private final Type generic;
24:
25: public MethodParameter(Class<?> param, Type generic, int position,
26: String key) {
27: this .paramType = new Clazz(param);
28: this .position = position;
29: this .generic = generic;
30: this .key = key;
31: }
32:
33: public String getKey() {
34: return key;
35: }
36:
37: public Class<? extends Converter> getOverridenConverter() {
38: return null;
39: }
40:
41: public Object guaranteeExistence(Object component,
42: Object methodParams[]) throws SettingException {
43: return methodParams[position];
44: }
45:
46: public boolean mightCreate() {
47: return true;
48: }
49:
50: public Class<?> getType() {
51: return paramType.getType();
52: }
53:
54: public void set(Object component, Object[] methodParams,
55: Object value) throws SettingException {
56: methodParams[position] = value;
57: }
58:
59: public Type getGenericType() {
60: return generic;
61: }
62:
63: public Object newInstance() throws ComponentInstantiationException {
64: return paramType.newInstance();
65: }
66:
67: public int getPosition() {
68: return this.position;
69: }
70:
71: }
|