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