Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractBindingCommand |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2008 the Seasar Foundation and the Others. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
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 | * {@link BindingCommand} の基底クラスです。<br /> | |
32 | * | |
33 | * @param <ANNOTATION_CLASS> | |
34 | * 対応するアノテーション | |
35 | * @author y-komori | |
36 | */ | |
37 | 16 | public abstract class AbstractBindingCommand<ANNOTATION_CLASS extends Annotation> |
38 | implements BindingCommand { | |
39 | /* | |
40 | * @see org.seasar.uruma.binding.value.BindingCommand#doBind(java.lang.Object, | |
41 | * java.lang.Object, org.seasar.framework.beans.PropertyDesc) | |
42 | */ | |
43 | public void doBind(final Object widget, final Object formObj, | |
44 | final PropertyDesc propDesc, final UIComponent uiComp) { | |
45 | 36 | doBind(getValueBinder(widget), widget, formObj, propDesc, uiComp); |
46 | 36 | } |
47 | ||
48 | /* | |
49 | * @see org.seasar.uruma.binding.value.BindingCommand#getId(java.lang.reflect.Field) | |
50 | */ | |
51 | public String getId(final Field field) { | |
52 | 4 | ANNOTATION_CLASS anno = getAnnotation(field); |
53 | 4 | String id = getId(anno); |
54 | 4 | return StringUtil.isEmpty(id) ? field.getName() : id; |
55 | } | |
56 | ||
57 | private ValueBinder getValueBinder(final Object widget) { | |
58 | 36 | ValueBinder valueBinder = ValueBinderFactory.getValueBinder(widget |
59 | .getClass()); | |
60 | 36 | if (valueBinder != null) { |
61 | 36 | return valueBinder; |
62 | } else { | |
63 | 0 | throw new NotFoundException( |
64 | UrumaMessageCodes.VALUE_BINDER_NOT_FOUND, widget.getClass() | |
65 | .getName()); | |
66 | } | |
67 | } | |
68 | ||
69 | /** | |
70 | * バインド処理を実行します。<br /> | |
71 | * 本メソッドは、サブクラスで実装してください。<br /> | |
72 | * 引数で渡された {@link ValueBinder} オブジェクトの適切なメソッドを呼び出して、バインド処理を実行してください。<br /> | |
73 | * | |
74 | * @param binder | |
75 | * {@link ValueBinder} オブジェクト | |
76 | * @param widget | |
77 | * バインド対象のウィジット側オブジェクト | |
78 | * @param formObj | |
79 | * バインド対象のフォーム側オブジェクト | |
80 | * @param propDesc | |
81 | * フォーム側のプロパティを表す {@link PropertyDesc} オブジェクト | |
82 | */ | |
83 | protected abstract void doBind(ValueBinder binder, Object widget, | |
84 | Object formObj, PropertyDesc propDesc, UIComponent uiComp); | |
85 | ||
86 | /** | |
87 | * アノテーションから id を取り出します。<br /> | |
88 | * 本メソッドはサブクラスで実装してください。<br /> | |
89 | * 引数で渡されたアノテーションから id を取得して返してください。<br /> | |
90 | * | |
91 | * @param annotation | |
92 | * アノテーション | |
93 | * @return id | |
94 | */ | |
95 | protected abstract String getId(ANNOTATION_CLASS annotation); | |
96 | ||
97 | /** | |
98 | * フィールドからアノテーションを取り出します。<br /> | |
99 | * 本メソッドはサブクラスで実装してください。<br /> | |
100 | * 引数で渡されたフィールドからアノテーションを取得して返してください。<br /> | |
101 | * | |
102 | * @param field | |
103 | * アノテーションを取り出す {@link Field} オブジェクト | |
104 | * @return アノテーション | |
105 | */ | |
106 | protected abstract ANNOTATION_CLASS getAnnotation(Field field); | |
107 | } |