001/* 002 * ============================================================================ 003 * Copyright © 2002-2021 by Thomas Thrien. 004 * All Rights Reserved. 005 * ============================================================================ 006 * 007 * Licensed to the public under the agreements of the GNU Lesser General Public 008 * License, version 3.0 (the "License"). You may obtain a copy of the License at 009 * 010 * http://www.gnu.org/licenses/lgpl.html 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 015 * License for the specific language governing permissions and limitations 016 * under the License. 017 */ 018 019package org.tquadrat.foundation.config.spi; 020 021import static org.tquadrat.foundation.config.internal.Commons.retrieveMessage; 022import static org.tquadrat.foundation.lang.Objects.requireNonNullArgument; 023import static org.tquadrat.foundation.lang.Objects.requireNotEmptyArgument; 024 025import java.io.Serial; 026import java.util.prefs.Preferences; 027 028import org.tquadrat.foundation.annotation.ClassVersion; 029import org.tquadrat.foundation.config.spi.prefs.PreferenceAccessor; 030import org.tquadrat.foundation.i18n.Message; 031import org.tquadrat.foundation.i18n.Translation; 032 033/** 034 * The is exception will be thrown by implementations of 035 * {@link PreferenceAccessor} 036 * in cases when the value from the preferences node (that is stored there as 037 * a 038 * {@link String}) 039 * cannot be converted into the target format, for whatever reason. 040 * 041 * @extauthor Thomas Thrien - thomas.thrien@tquadrat.org 042 * @version $Id: InvalidPreferenceValueException.java 914 2021-05-07 21:22:12Z tquadrat $ 043 * @since 0.0.1 044 * 045 * @UMLGraph.link 046 */ 047@ClassVersion( sourceVersion = "$Id: InvalidPreferenceValueException.java 914 2021-05-07 21:22:12Z tquadrat $" ) 048public class InvalidPreferenceValueException extends IllegalArgumentException 049{ 050 /*-----------*\ 051 ====** Constants **======================================================== 052 \*-----------*/ 053 /** 054 * The message indicating an invalid preference value. 055 */ 056 @SuppressWarnings( "SimplifiableAnnotation" ) 057 @Message 058 ( 059 description = "The message indicating an invalid preference value.", 060 translations = 061 { 062 @Translation( language = "en", text = "Preference value for '%2$s' from '%1$s' cannot converted to target format" ) 063 } 064 ) 065 public static final int MSGKEY_InvalidValue1 = 37; 066 067 /** 068 * The message indicating an invalid preference value. 069 */ 070 @SuppressWarnings( "SimplifiableAnnotation" ) 071 @Message 072 ( 073 description = "The message indicating an invalid preference value.", 074 translations = 075 { 076 @Translation( language = "en", text = "Preference value '%3$s' for '%2$s' from '%1$s' cannot converted to target format" ) 077 } 078 ) 079 public static final int MSGKEY_InvalidValue2 = 38; 080 081 /*------------------------*\ 082 ====** Static Initialisations **=========================================== 083 \*------------------------*/ 084 /** 085 * The serial version UID for objects of this class: {@value}. 086 * 087 * @hidden 088 */ 089 @Serial 090 private static final long serialVersionUID = 1L; 091 092 /*--------------*\ 093 ====** Constructors **===================================================== 094 \*--------------*/ 095 /** 096 * Creates a new {@code InvalidPreferenceValueException}. 097 * 098 * @param preferences The preferences node. 099 * @param propertyName The name of the property. 100 */ 101 public InvalidPreferenceValueException( final Preferences preferences, final String propertyName ) 102 { 103 super( retrieveMessage( MSGKEY_InvalidValue1, true, requireNonNullArgument( preferences, "preferences" ).absolutePath(), requireNotEmptyArgument( propertyName, "propertyName" ) ) ); 104 } // InvalidPreferencesValueException() 105 106 /** 107 * Creates a new {@code InvalidPreferenceValueException}. 108 * 109 * @param preferences The preferences node. 110 * @param propertyName The name of the property. 111 * @param value The invalid value. 112 */ 113 public InvalidPreferenceValueException( final Preferences preferences, final String propertyName, final String value ) 114 { 115 super( retrieveMessage( MSGKEY_InvalidValue1, true, requireNonNullArgument( preferences, "preferences" ).absolutePath(), requireNotEmptyArgument( propertyName, "propertyName" ), value ) ); 116 } // InvalidPreferencesValueException() 117 118 /** 119 * Creates a new {@code InvalidPreferenceValueException}. 120 * 121 * @param preferences The preferences node. 122 * @param propertyName The name of the property. 123 * @param cause The exception that caused the failure. 124 */ 125 public InvalidPreferenceValueException( final Preferences preferences, final String propertyName, final Throwable cause ) 126 { 127 super( retrieveMessage( MSGKEY_InvalidValue1, true, requireNonNullArgument( preferences, "preferences" ).absolutePath(), requireNotEmptyArgument( propertyName, "propertyName" ) ), cause ); 128 } // InvalidPreferencesValueException() 129 130 /** 131 * Creates a new {@code InvalidPreferenceValueException}. 132 * 133 * @param preferences The preferences node. 134 * @param propertyName The name of the property. 135 * @param value The invalid value. 136 * @param cause The exception that caused the failure. 137 */ 138 public InvalidPreferenceValueException( final Preferences preferences, final String propertyName, final String value, final Throwable cause ) 139 { 140 super( retrieveMessage( MSGKEY_InvalidValue1, true, requireNonNullArgument( preferences, "preferences" ).absolutePath(), requireNotEmptyArgument( propertyName, "propertyName" ), value ), cause ); 141 } // InvalidPreferencesValueException() 142} 143// class InvalidPreferenceValueException 144 145/* 146 * End of File 147 */