1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.binding.value.command;
17
18 import java.lang.annotation.Annotation;
19 import java.lang.reflect.Field;
20
21 import org.seasar.framework.beans.PropertyDesc;
22 import org.seasar.framework.util.StringUtil;
23 import org.seasar.uruma.binding.value.BindingCommand;
24 import org.seasar.uruma.binding.value.ValueBinder;
25 import org.seasar.uruma.binding.value.ValueBinderFactory;
26 import org.seasar.uruma.component.UIComponent;
27 import org.seasar.uruma.core.UrumaMessageCodes;
28 import org.seasar.uruma.exception.NotFoundException;
29
30
31
32
33
34
35
36
37 public abstract class AbstractBindingCommand<ANNOTATION_CLASS extends Annotation>
38 implements BindingCommand {
39
40
41
42
43 public void doBind(final Object widget, final Object formObj,
44 final PropertyDesc propDesc, final UIComponent uiComp) {
45 doBind(getValueBinder(widget), widget, formObj, propDesc, uiComp);
46 }
47
48
49
50
51 public String getId(final Field field) {
52 ANNOTATION_CLASS anno = getAnnotation(field);
53 String id = getId(anno);
54 return StringUtil.isEmpty(id) ? field.getName() : id;
55 }
56
57 private ValueBinder getValueBinder(final Object widget) {
58 ValueBinder valueBinder = ValueBinderFactory.getValueBinder(widget
59 .getClass());
60 if (valueBinder != null) {
61 return valueBinder;
62 } else {
63 throw new NotFoundException(
64 UrumaMessageCodes.VALUE_BINDER_NOT_FOUND, widget.getClass()
65 .getName());
66 }
67 }
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 protected abstract void doBind(ValueBinder binder, Object widget,
84 Object formObj, PropertyDesc propDesc, UIComponent uiComp);
85
86
87
88
89
90
91
92
93
94
95 protected abstract String getId(ANNOTATION_CLASS annotation);
96
97
98
99
100
101
102
103
104
105
106 protected abstract ANNOTATION_CLASS getAnnotation(Field field);
107 }