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.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   * <p>
28   * Since the implementing classes are used as members of exceptions they have to
29   * be serializable. Instances of implementing classes should also be immutable.
30   * </p>
31   */
32  public interface Code extends Serializable
33  {
34    // ********************************* Fields *********************************
35  
36    // --- constants ------------------------------------------------------------
37  
38    // ****************************** Inner Classes *****************************
39  
40    // ********************************* Methods ********************************
41  
42    // --- get&set --------------------------------------------------------------
43  
44    /**
45     * Returns the component identifier that raised an exception with this code.
46     * <p>
47     * This number enables the system to separate the error codes of different sub
48     * systems.
49     *
50     * @return the component identifier.
51     */
52    String getComponentId();
53  
54    /**
55     * Returns the string representation of the code.
56     * <p>
57     * This is the code within the component and lacks the component identifier.
58     * If the component is interested in the code, this identifier is used.
59     *
60     * @return the string representation of the code.
61     */
62    String getCode();
63  
64    /**
65     * Returns the string representation of the code. This includes the component
66     * identifier and the code. If the code is presented (e.g. in a log file) the
67     * return value of this method is used.
68     * <p>
69     * This returns the same value as {@link #toString()} as this method can be
70     * used via property getter.
71     *
72     * @return the string representation of the code.
73     */
74    String getDisplayId();
75  
76    // --- business -------------------------------------------------------------
77  
78    // --- object basics --------------------------------------------------------
79  
80    /**
81     * Returns the string representation of the code. This includes the component
82     * identifier and the code. If the code is presented (e.g. in a log file) the
83     * return value of this method is used.
84     * <p>
85     * This returns the same value as {@link #getDisplayId()} as this makes it
86     * easier to print the code in a {@link String} context (e.g. writing to a log
87     * file).
88     *
89     * @return the string representation of the code.
90     */
91    String toString();
92  }