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 org.seasar.cubby.action.ActionResult;
19
20 /**
21 * 入力検証に失敗した場合に後続の入力検証を実行しないようにするためにスローする例外です。
22 *
23 * @author baba
24 * @since 1.1.0
25 */
26 public class ValidationException extends RuntimeException {
27
28 /** シリアルバージョンUID。 */
29 private static final long serialVersionUID = 1L;
30
31 /** 入力検証でエラーがあった場合の振る舞い。 */
32 private final ValidationFailBehaviour behaviour;
33
34 /**
35 * 新規例外を構築します。
36 */
37 public ValidationException(final ValidationFailBehaviour behaviour) {
38 this.behaviour = behaviour;
39 }
40
41 /**
42 * 新規例外を構築します。
43 */
44 public ValidationException() {
45 this(new ErrorPageValidationFailBehaviour());
46 }
47
48 /**
49 * 新規例外を構築します。
50 *
51 * @param errorMessage
52 * メッセージ
53 * @param fieldNames
54 * フィールド名
55 */
56 public ValidationException(final String errorMessage,
57 final String... fieldNames) {
58 this(new ErrorPageValidationFailBehaviour(errorMessage, fieldNames));
59 }
60
61 /**
62 * 新規例外を構築します。
63 *
64 * @param actionResult
65 * エラーページの遷移などを行う {@link ActionResult}
66 */
67 public ValidationException(final ActionResult actionResult) {
68 this(new ActionResultValidationFailBehaviour(actionResult));
69 }
70
71 /**
72 * 入力検証でエラーがあった場合の振る舞いを取得します。
73 *
74 * @return 入力検証でエラーがあった場合の振る舞い
75 */
76 public ValidationFailBehaviour getBehaviour() {
77 return behaviour;
78 }
79
80 }