| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ValidationException |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2009-2010 Steve Chaloner | |
| 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, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package be.objectify.led.validation; | |
| 17 | ||
| 18 | /** | |
| 19 | * Indicates validation has failed. | |
| 20 | * | |
| 21 | * @author Steve Chaloner | |
| 22 | */ | |
| 23 | public class ValidationException extends RuntimeException | |
| 24 | { | |
| 25 | private String fieldName; | |
| 26 | ||
| 27 | private String reason; | |
| 28 | ||
| 29 | /** | |
| 30 | * Initialises a new instance with the target field name and reason for the validation failure. | |
| 31 | * | |
| 32 | * @param fieldName the field name | |
| 33 | * @param reason the reason | |
| 34 | */ | |
| 35 | public ValidationException(String fieldName, | |
| 36 | String reason) | |
| 37 | { | |
| 38 | 1 | super(String.format("Validation failed on field [%s] because [%s]", |
| 39 | fieldName, | |
| 40 | reason)); | |
| 41 | 1 | this.fieldName = fieldName; |
| 42 | 1 | this.reason = reason; |
| 43 | 1 | } |
| 44 | ||
| 45 | /** | |
| 46 | * Initialises a new instance with the target field name, reason for the validation failure and | |
| 47 | * a root cause. | |
| 48 | * | |
| 49 | * @param fieldName the field name | |
| 50 | * @param reason the reason | |
| 51 | * @param cause an associated exception | |
| 52 | */ | |
| 53 | public ValidationException(String fieldName, | |
| 54 | String reason, | |
| 55 | Throwable cause) | |
| 56 | { | |
| 57 | 1 | super(String.format("Validation failed on field [%s] because [%s]", |
| 58 | fieldName, | |
| 59 | reason), | |
| 60 | cause); | |
| 61 | 1 | this.fieldName = fieldName; |
| 62 | 1 | this.reason = reason; |
| 63 | 1 | } |
| 64 | ||
| 65 | ||
| 66 | public String getFieldName() | |
| 67 | { | |
| 68 | 2 | return fieldName; |
| 69 | } | |
| 70 | ||
| 71 | public String getReason() | |
| 72 | { | |
| 73 | 2 | return reason; |
| 74 | } | |
| 75 | } |