View Javadoc

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