1 /* 2 * Copyright 2007-2011 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.exceptions.i18n.message; 17 18 import de.smartics.exceptions.i18n.AbstractLocalizedRuntimeException; 19 import de.smartics.exceptions.i18n.app.ParseExceptionCode; 20 21 /** 22 * This exception is thrown if a string cannot be parsed because information is 23 * missing or the format syntax is violated. 24 * 25 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 26 * @version $Revision$ 27 */ 28 public class ParseException extends AbstractLocalizedRuntimeException 29 { 30 // ********************************* Fields ********************************* 31 32 // --- constants ------------------------------------------------------------ 33 34 /** 35 * The class version identifier. 36 * <p> 37 * The value of this constant is {@value}. 38 */ 39 private static final long serialVersionUID = 1L; 40 41 // --- members -------------------------------------------------------------- 42 43 /** 44 * The input that cannot be parsed. 45 * 46 * @serial 47 */ 48 @MessageParam("0") 49 protected final String input; 50 51 /** 52 * The index within the input string where the parsing error occurred. 53 * 54 * @serial 55 */ 56 @MessageParam("1") 57 protected final int index; 58 59 // ****************************** Initializer ******************************* 60 61 // ****************************** Constructors ****************************** 62 63 /** 64 * Constructor. 65 * 66 * @param code the error or exception code of the exception. 67 * @param bundleBaseName the fully qualified name of the bundle to use. 68 * @param input the input that cannot be parsed. 69 * @param index the index within the input string where the parsing error 70 * occurred. 71 * @see de.smartics.exceptions.i18n.message.ParseException#ParseException(Throwable,ParseExceptionCode,java.lang.String,java.lang.String,int) 72 */ 73 public ParseException(final ParseExceptionCode code, 74 final String bundleBaseName, final String input, final int index) 75 { 76 this(null, code, bundleBaseName, input, index); 77 } 78 79 /** 80 * Constructor. 81 * 82 * @param code the error or exception code of the exception. 83 * @param input the input that cannot be parsed. 84 * @param index the index within the input string where the parsing error 85 * occurred. 86 * @see de.smartics.exceptions.i18n.message.ParseException#ParseException(ParseExceptionCode,String,java.lang.String,int) 87 */ 88 public ParseException(final ParseExceptionCode code, final String input, 89 final int index) 90 { 91 this(code, null, input, index); 92 } 93 94 /** 95 * Constructor. 96 * 97 * @param cause the cause (which is saved for later retrieval by the 98 * {@link #getCause()} method). (A <tt>null</tt> value is permitted, 99 * and indicates that the cause is nonexistent or unknown.) 100 * @param code the error or exception code of the exception. 101 * @param bundleBaseName the fully qualified name of the bundle to use. 102 * @param input the input that cannot be parsed. 103 * @param index the index within the input string where the parsing error 104 * occurred. 105 * @see AbstractLocalizedRuntimeException#AbstractLocalizedRuntimeException(Throwable,de.smartics.exceptions.core.Code,String) 106 */ 107 protected ParseException(final Throwable cause, 108 final ParseExceptionCode code, final String bundleBaseName, 109 final String input, final int index) 110 { 111 super(cause, code, bundleBaseName); 112 this.input = input; 113 this.index = index; 114 } 115 116 /** 117 * Constructor. 118 * 119 * @param cause the cause (which is saved for later retrieval by the 120 * {@link #getCause()} method). (A <tt>null</tt> value is permitted, 121 * and indicates that the cause is nonexistent or unknown.) 122 * @param code the error or exception code of the exception. 123 * @param input the input that cannot be parsed. 124 * @param index the index within the input string where the parsing error 125 * occurred. 126 * @see de.smartics.exceptions.i18n.message.ParseException#ParseException(Throwable,ParseExceptionCode,String,String,int) 127 */ 128 protected ParseException(final Throwable cause, 129 final ParseExceptionCode code, final String input, final int index) 130 { 131 this(cause, code, null, input, index); 132 } 133 134 // ****************************** Inner Classes ***************************** 135 136 // ********************************* Methods ******************************** 137 138 // --- init ----------------------------------------------------------------- 139 140 // --- get&set -------------------------------------------------------------- 141 142 /** 143 * Returns the input that cannot be parsed. 144 * 145 * @return the input that cannot be parsed. 146 */ 147 public String getInput() 148 { 149 return input; 150 } 151 152 /** 153 * Returns the index within the input string where the parsing error occurred. 154 * 155 * @return the index within the input string where the parsing error occurred. 156 */ 157 public int getIndex() 158 { 159 return index; 160 } 161 162 // --- business ------------------------------------------------------------- 163 164 // --- object basics -------------------------------------------------------- 165 }