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.app;
17  
18  import de.smartics.exceptions.code.NumberCode;
19  import de.smartics.exceptions.code.NumberCodeInfo;
20  
21  /**
22   * Defines the parsing exception codes for this package.
23   */
24  public enum ParseExceptionCode implements NumberCode
25  {
26    // ****************************** Enumeration *******************************
27  
28    /**
29     * The generic parsing error.
30     */
31    GENERIC(2000),
32  
33    /**
34     * Parsing an OGNL path expression failed.
35     */
36    OGNL(2000, 1),
37  
38    /**
39     * Parsing the value for a parent attribute failed because the <code>=</code>
40     * -sign is missing. The <code>=</code>-sign separates the attribute name from
41     * the index information.
42     * <p>
43     * The parent attribute is an attribute specified by the super class of an
44     * exception. The parent exception may be of a standard library and therefore
45     * cannot be annotated so the annotation is placed in the subclass.
46     * </p>
47     */
48    MISSING_PARENT_PROPERTY_SEPARATOR(2000, 2),
49  
50    /**
51     * Parsing the value for a parent attribute failed because the attribute in
52     * front of the <code>=</code>-sign is missing.
53     * <p>
54     * The parent attribute is an attribute specified by the super class of an
55     * exception. The parent exception may be of a standard library and therefore
56     * cannot be annotated so the annotation is placed in the subclass.
57     * </p>
58     */
59    MISSING_PARENT_PROPERTY_ATTRIBUTE(2000, 3),
60  
61    /**
62     * Parsing the value for a parent attribute failed because the index after the
63     * <code>=</code>-sign is missing.
64     * <p>
65     * The parent attribute is an attribute specified by the super class of an
66     * exception. The parent exception may be of a standard library and therefore
67     * cannot be annotated so the annotation is placed in the subclass.
68     * </p>
69     */
70    MISSING_PARENT_PROPERTY_INDEX(2000, 4);
71  
72    // ********************************* Fields *********************************
73  
74    // --- constants ------------------------------------------------------------
75  
76    // --- members --------------------------------------------------------------
77  
78    /**
79     * The code information.
80     */
81    private final NumberCodeInfo info;
82  
83    // ****************************** Constructors ******************************
84  
85    /**
86     * Convenience constructor.
87     *
88     * @param majorNumber the major part of the error code.
89     */
90    private ParseExceptionCode(final Integer majorNumber)
91    {
92      this(majorNumber, null);
93    }
94  
95    /**
96     * Convenience constructor.
97     *
98     * @param majorNumber the major part of the error code.
99     * @param minorNumber the minor part of the error code.
100    */
101   private ParseExceptionCode(final Integer majorNumber,
102       final Integer minorNumber)
103   {
104     this(readComponentId(), majorNumber, minorNumber);
105   }
106 
107   /**
108    * Default constructor.
109    *
110    * @param componentId the component identifier.
111    * @param majorNumber the major part of the error code.
112    * @param minorNumber the minor part of the error code.
113    */
114   private ParseExceptionCode(final String componentId,
115       final Integer majorNumber, final Integer minorNumber)
116   {
117     this.info = new NumberCodeInfo(componentId, majorNumber, minorNumber);
118   }
119 
120   // ********************************* Methods ********************************
121 
122   // --- init -----------------------------------------------------------------
123 
124   /**
125    * Used to access the identify for the exceptions raised by this component.
126    *
127    * @return the component identifier of this exception library.
128    */
129   private static String readComponentId()
130   {
131     return Constant.COMPONENT_ID;
132   }
133 
134   // --- get&set --------------------------------------------------------------
135 
136   // --- business -------------------------------------------------------------
137 
138   @Override
139   public String getCode()
140   {
141     return info.getCode();
142   }
143 
144   @Override
145   public String getComponentId()
146   {
147     return info.getComponentId();
148   }
149 
150   @Override
151   public Integer getMajorNumber()
152   {
153     return info.getMajorNumber();
154   }
155 
156   @Override
157   public Integer getMinorNumber()
158   {
159     return info.getMinorNumber();
160   }
161 
162   @Override
163   public String getDisplayId()
164   {
165     return info.getDisplayId();
166   }
167 
168   // --- object basics --------------------------------------------------------
169 
170   /**
171    * Returns the string representation of the object.
172    *
173    * @return the string representation of the object.
174    */
175   @Override
176   public String toString()
177   {
178     return info.toString();
179   }
180 }