1 /* 2 * Copyright 2004-2010 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 17 package org.seasar.cubby.validator; 18 19 import org.seasar.cubby.action.ActionResult; 20 21 /** 22 * 入力検証に失敗した場合に後続の入力検証を実行しないようにするためにスローする例外です。 23 * 24 * @author baba 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 * @param behaviour 38 * 入力検証でエラーがあった場合の振る舞い 39 */ 40 public ValidationException(final ValidationFailBehaviour behaviour) { 41 this.behaviour = behaviour; 42 } 43 44 /** 45 * 新規例外を構築します。 46 */ 47 public ValidationException() { 48 this(new ErrorPageValidationFailBehaviour()); 49 } 50 51 /** 52 * 新規例外を構築します。 53 * 54 * @param errorMessage 55 * メッセージ 56 * @param fieldNames 57 * フィールド名 58 */ 59 public ValidationException(final String errorMessage, 60 final String... fieldNames) { 61 this(new ErrorPageValidationFailBehaviour(errorMessage, fieldNames)); 62 } 63 64 /** 65 * 新規例外を構築します。 66 * 67 * @param actionResult 68 * エラーページの遷移などを行う {@link ActionResult} 69 */ 70 public ValidationException(final ActionResult actionResult) { 71 this(new ActionResultValidationFailBehaviour(actionResult)); 72 } 73 74 /** 75 * 入力検証でエラーがあった場合の振る舞いを取得します。 76 * 77 * @return 入力検証でエラーがあった場合の振る舞い 78 */ 79 public ValidationFailBehaviour getBehaviour() { 80 return behaviour; 81 } 82 83 }