1 /* 2 * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH 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 de.smartics.properties.api.config.domain; 17 18 import de.smartics.properties.api.core.domain.PropertyValidationException; 19 20 /** 21 * Signals that the value does not match the given constraints and provides 22 * information about the source location of the culprit. 23 */ 24 public class PropertyValidationWithSourceException extends 25 PropertyValidationException 26 { 27 // ********************************* Fields ********************************* 28 29 // --- constants ------------------------------------------------------------ 30 31 /** 32 * The class version identifier. 33 * <p> 34 * The value of this constant is {@value}. 35 */ 36 private static final long serialVersionUID = 1L; 37 38 // --- members -------------------------------------------------------------- 39 40 /** 41 * The source where the property value has been defined. 42 * 43 * @serial 44 */ 45 private final PropertyLocation source; 46 47 // ****************************** Initializer ******************************* 48 49 // ****************************** Constructors ****************************** 50 51 /** 52 * Default constructor. 53 * 54 * @param original the original property validation exception without the 55 * origin information. 56 * @param source the source where the property value has been defined. 57 */ 58 public PropertyValidationWithSourceException( 59 final PropertyValidationException original, final PropertyLocation source) 60 { 61 super(createMessage(original, source), original, original 62 .getPropertyDescriptor(), original.getConstraints(), original 63 .getValue()); 64 this.source = source; 65 } 66 67 // ****************************** Inner Classes ***************************** 68 69 // ********************************* Methods ******************************** 70 71 // --- init ----------------------------------------------------------------- 72 73 // --- get&set -------------------------------------------------------------- 74 75 private static String createMessage( 76 final PropertyValidationException original, final PropertyLocation source) 77 { 78 final StringBuilder buffer = new StringBuilder(512); 79 80 buffer.append(original.getMessage()) 81 .append("\n Source location of the property '") 82 .append(original.getPropertyDescriptor().getKey()).append('=') 83 .append(original.getValue()).append("': ").append(source); 84 85 appendMetaDataMessage(buffer, original.getPropertyDescriptor()); 86 87 return buffer.toString(); 88 } 89 90 /** 91 * Returns the source where the property value has been defined. 92 * 93 * @return the source where the property value has been defined. 94 */ 95 public final PropertyLocation getSource() 96 { 97 return source; 98 } 99 100 // --- business ------------------------------------------------------------- 101 102 // --- object basics -------------------------------------------------------- 103 104 }