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.core.domain; 17 18 import java.io.Serializable; 19 20 import de.smartics.exceptions.i18n.message.MessageParam; 21 import de.smartics.properties.api.core.app.PropertiesCode; 22 23 /** 24 * Provides context information for errors concerning a property value. 25 */ 26 public class PropertyValueMessageBean extends PropertyDescriptorMessageBean 27 { 28 // ********************************* Fields ********************************* 29 30 // --- constants ------------------------------------------------------------ 31 32 /** 33 * The class version identifier. 34 */ 35 private static final long serialVersionUID = 1L; 36 37 // --- members -------------------------------------------------------------- 38 39 /** 40 * The value of the property that does not meet the constraints. 41 * 42 * @serial 43 */ 44 @MessageParam 45 private final Serializable value; 46 47 /** 48 * The type of the value if not <code>null</code>. 49 * 50 * @serial 51 */ 52 @MessageParam 53 private final String valueType; // NOPMD 54 55 // ****************************** Initializer ******************************* 56 57 // ****************************** Constructors ****************************** 58 59 /** 60 * Convenience constructor with no message and no root cause. 61 * 62 * @param propertyDescriptor the descriptor of the property raising the 63 * exception. 64 * @param value the value of the property that does not meet the constraints. 65 * If the value is not serializable, its string representation is 66 * stored. 67 */ 68 public PropertyValueMessageBean(final PropertyDescriptor propertyDescriptor, 69 final Object value) 70 { 71 this(null, propertyDescriptor, value); 72 } 73 74 /** 75 * Convenience constructor with cause. 76 * 77 * @param cause the cause (which is saved for later retrieval by the 78 * {@link #getCause()} method). (A <tt>null</tt> value is permitted, 79 * and indicates that the cause is nonexistent or unknown.) 80 * @param propertyDescriptor the descriptor of the property raising the 81 * exception. 82 * @param value the value of the property that does not meet the constraints. 83 * If the value is not serializable, its string representation is 84 * stored. 85 */ 86 public PropertyValueMessageBean(final Throwable cause, 87 final PropertyDescriptor propertyDescriptor, final Object value) 88 { 89 this(PropertyCode.CONVERSION_PROBLEM, cause, propertyDescriptor, value); 90 } 91 92 /** 93 * Default constructor. 94 * 95 * @param code the error or exception code of the exception. 96 * @param cause the cause (which is saved for later retrieval by the 97 * {@link #getCause()} method). (A <tt>null</tt> value is permitted, 98 * and indicates that the cause is nonexistent or unknown.) 99 * @param propertyDescriptor the descriptor of the property raising the 100 * exception. 101 * @param value the value of the property that does not meet the constraints. 102 * If the value is not serializable, its string representation is 103 * stored. 104 */ 105 public PropertyValueMessageBean(final PropertiesCode code, 106 final Throwable cause, final PropertyDescriptor propertyDescriptor, 107 final Object value) 108 { 109 super(code, cause, propertyDescriptor); 110 111 this.value = 112 value instanceof Serializable ? (Serializable) value : String 113 .valueOf(value); 114 this.valueType = 115 (value != null ? " (" + value.getClass().getSimpleName() + ')' : ""); 116 } 117 118 // ****************************** Inner Classes ***************************** 119 120 // ********************************* Methods ******************************** 121 122 // --- init ----------------------------------------------------------------- 123 124 // --- get&set -------------------------------------------------------------- 125 126 /** 127 * Returns the value of the property that does not meet the constraints. 128 * 129 * @return the value of the property that does not meet the constraints. 130 */ 131 public final Serializable getValue() 132 { 133 return value; 134 } 135 136 // --- business ------------------------------------------------------------- 137 138 // --- object basics -------------------------------------------------------- 139 140 }