Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ValidationUtils |
|
| 1.0;1 |
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.cubby.validator; | |
17 | ||
18 | import java.lang.reflect.Method; | |
19 | ||
20 | import org.seasar.cubby.action.Action; | |
21 | import org.seasar.cubby.action.Validation; | |
22 | import org.seasar.framework.beans.BeanDesc; | |
23 | import org.seasar.framework.beans.PropertyDesc; | |
24 | import org.seasar.framework.beans.factory.BeanDescFactory; | |
25 | ||
26 | /** | |
27 | * バリデーションのユーティリティクラスです。 | |
28 | * | |
29 | * @author baba | |
30 | * @since 1.1.0 | |
31 | */ | |
32 | 0 | public class ValidationUtils { |
33 | ||
34 | /** | |
35 | * 指定されたメソッドを修飾する {@link Validation} を取得します。 | |
36 | * | |
37 | * @param method | |
38 | * メソッド | |
39 | * @return {@link Validation}、修飾されていない場合は <code>null</code> | |
40 | */ | |
41 | public static Validation getValidation(final Method method) { | |
42 | 6 | return method.getAnnotation(Validation.class); |
43 | } | |
44 | ||
45 | /** | |
46 | * 実行しているアクションメソッドの入力検証ルールの集合を取得します。 | |
47 | * | |
48 | * @param action | |
49 | * アクション | |
50 | * @param rulesPropertyName | |
51 | * 入力検証ルールの集合が定義されたプロパティ名 | |
52 | * @return アクションメソッドの入力検証ルールの集合 | |
53 | */ | |
54 | public static ValidationRules getValidationRules(final Action action, | |
55 | final String rulesPropertyName) { | |
56 | 5 | final BeanDesc beanDesc = BeanDescFactory |
57 | .getBeanDesc(action.getClass()); | |
58 | 5 | final PropertyDesc propertyDesc = beanDesc |
59 | .getPropertyDesc(rulesPropertyName); | |
60 | 5 | final ValidationRules rules = (ValidationRules) propertyDesc |
61 | .getValue(action); | |
62 | 5 | return rules; |
63 | } | |
64 | ||
65 | } |