View Javadoc

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.core;
17  
18  import java.io.Serializable;
19  
20  /**
21   * This interface defines error and exception codes to identify exception
22   * classes.
23   * <p>
24   * It is intended that this interface is implemented by enumerations that define
25   * all or part of these codes for an application.
26   * <p>
27   * Since the implementing classes are used as members of exceptions they have to
28   * be serializable. Instances of implementing classes should also be immutable.
29   *
30   * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a>
31   * @version $Revision$
32   */
33  public interface Code extends Serializable
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    // ****************************** Inner Classes *****************************
40  
41    // ********************************* Methods ********************************
42  
43    // --- get&set --------------------------------------------------------------
44  
45    /**
46     * Returns the component identifier that raised an exception with this code.
47     * <p>
48     * This number enables the system to separate the error codes of different sub
49     * systems.
50     *
51     * @return the component identifier.
52     */
53    String getComponentId();
54  
55    /**
56     * Returns the string representation of the code.
57     * <p>
58     * This is the code within the component and lacks the component identifier.
59     * If the component is interested in the code, this identifier is used.
60     *
61     * @return the string representation of the code.
62     */
63    String getCode();
64  
65    /**
66     * Returns the string representation of the code. This includes the component
67     * identifier and the code. If the code is presented (e.g. in a log file) the
68     * return value of this method is used.
69     * <p>
70     * This returns the same value as {@link #toString()} as this method can be
71     * used via property getter..
72     *
73     * @return the string representation of the code.
74     */
75    String getDisplayId();
76  
77    // --- business -------------------------------------------------------------
78  
79    // --- object basics --------------------------------------------------------
80  
81    /**
82     * Returns the string representation of the code. This includes the component
83     * identifier and the code. If the code is presented (e.g. in a log file) the
84     * return value of this method is used.
85     * <p>
86     * This returns the same value as {@link #getDisplayId()} as this makes it
87     * easier to print the code in a {@link String} context (e.g. writing to a log
88     * file).
89     *
90     * @return the string representation of the code.
91     */
92    String toString();
93  }