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 exception codes for problems with the configuration of the
23   * library.
24   */
25  public enum ConfigurationExceptionCode implements NumberCode
26  {
27    // ****************************** Enumeration *******************************
28  
29    /**
30     * The generic configuration error.
31     */
32    GENERIC(1000),
33  
34    /**
35     * A configuration error signaling missing getter.
36     */
37    CONFIGURATION_MISSING_GETTER(1000, 1),
38  
39    /**
40     * A configuration error signaling an inaccessible getter.
41     */
42    CONFIGURATION_INACCESSIBLE_GETTER(1000, 2),
43  
44    /**
45     * A configuration error signaling a runtime problem while running the getter
46     * method's code.
47     */
48    CONFIGURATION_RUNTIME_ACCESS(1000, 3),
49  
50    /**
51     * A configuration error signaling that the getter method does not exist.
52     */
53    CONFIGURATION_NOARG(1000, 4),
54  
55    /**
56     * A configuration error signaling that accessing the getter raised a security
57     * exception.
58     */
59    CONFIGURATION_SECURITY(1000, 5),
60  
61    /**
62     * A configuration error signaling a runtime problem while accessing the
63     * property.
64     */
65    CONFIGURATION_PROPERTY_RUNTIME_ACCESS(1000, 6),
66  
67    /**
68     * A configuration error signaling that a property is not accessible.
69     */
70    CONFIGURATION_INACCESSIBLE_PROPERTY(1000, 7),
71  
72    /**
73     * A configuration error signaling that there is no getter to access a
74     * property.
75     */
76    CONFIGURATION_NO_GETTER_FOR_PROPERTY(1000, 8),
77  
78    /**
79     * A configuration error signaling that there is an error in the OGNL
80     * expression of a value.
81     */
82    CONFIGURATION_OGNL_SYNTAX_ERROR(1000, 9),
83  
84    /**
85     * A configuration error signaling that values for a compound message a
86     * missing.
87     */
88    COMPOUND_MESSAGE_MISSING(1000, 10);
89  
90    // ********************************* Fields *********************************
91  
92    // --- constants ------------------------------------------------------------
93  
94    // --- members --------------------------------------------------------------
95  
96    /**
97     * The code information.
98     */
99    private final NumberCodeInfo info;
100 
101   // ****************************** Constructors ******************************
102 
103   /**
104    * Convenience constructor.
105    *
106    * @param majorNumber the major part of the error code.
107    */
108   private ConfigurationExceptionCode(final Integer majorNumber)
109   {
110     this(majorNumber, null);
111   }
112 
113   /**
114    * Convenience constructor.
115    *
116    * @param majorNumber the major part of the error code.
117    * @param minorNumber the minor part of the error code.
118    */
119   private ConfigurationExceptionCode(final Integer majorNumber,
120       final Integer minorNumber)
121   {
122     this(readComponentId(), majorNumber, minorNumber);
123   }
124 
125   /**
126    * Default constructor.
127    *
128    * @param componentId the component identifier.
129    * @param majorNumber the major part of the error code.
130    * @param minorNumber the minor part of the error code.
131    */
132   private ConfigurationExceptionCode(final String componentId,
133       final Integer majorNumber, final Integer minorNumber)
134   {
135     this.info = new NumberCodeInfo(componentId, majorNumber, minorNumber);
136   }
137 
138   // ********************************* Methods ********************************
139 
140   // --- init -----------------------------------------------------------------
141 
142   /**
143    * Used to access the identify for the exceptions raised by this component.
144    *
145    * @return the component identifier of this exception library.
146    */
147   private static String readComponentId()
148   {
149     return Constant.COMPONENT_ID;
150   }
151 
152   // --- get&set --------------------------------------------------------------
153 
154   // --- business -------------------------------------------------------------
155 
156   /**
157    * {@inheritDoc}
158    */
159   // @Override Java 6 feature
160   public String getCode()
161   {
162     return info.getCode();
163   }
164 
165   /**
166    * {@inheritDoc}
167    */
168   // @Override Java 6 feature
169   public String getComponentId()
170   {
171     return info.getComponentId();
172   }
173 
174   /**
175    * {@inheritDoc}
176    *
177    * @see de.smartics.exceptions.code.NumberCode#getMajorNumber()
178    */
179   // @Override Java 6 feature
180   public Integer getMajorNumber()
181   {
182     return info.getMajorNumber();
183   }
184 
185   /**
186    * {@inheritDoc}
187    *
188    * @see de.smartics.exceptions.code.NumberCode#getMinorNumber()
189    */
190   // @Override Java 6 feature
191   public Integer getMinorNumber()
192   {
193     return info.getMinorNumber();
194   }
195 
196   /**
197    * {@inheritDoc}
198    *
199    * @see de.smartics.exceptions.core.Code#getDisplayId()
200    */
201   public String getDisplayId()
202   {
203     return info.getDisplayId();
204   }
205 
206   // --- object basics --------------------------------------------------------
207 
208   /**
209    * Returns the string representation of the object.
210    *
211    * @return the string representation of the object.
212    */
213   @Override
214   public String toString()
215   {
216     return info.toString();
217   }
218 }