1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.bea.domingo;
23
24 /***
25 * Enumeration of notes errors.
26 *
27 * @see de.bea.domingo.DNotesException
28 * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
29 */
30 public final class DNotesError {
31
32 /*** error: general error. */
33 public static final DNotesError GENERAL_ERROR = new DNotesError(0);
34
35 /*** error: database not found. */
36 public static final DNotesError DATABASE_NOT_FOUND = new DNotesError(1);
37
38 /*** error: no access to database. */
39 public static final DNotesError DATABASE_NO_ACCESS = new DNotesError(2);
40
41 /*** internal error code. */
42 private final int id;
43
44 /***
45 * Private Constructor.
46 *
47 * @param theId the error code
48 */
49 public DNotesError(final int theId) {
50 this.id = theId;
51 }
52
53 /***
54 * @see java.lang.Object#equals(java.lang.Object)
55 *
56 * @param object the reference object with which to compare.
57 * @return <code>true</code> if this object is the same as the object
58 * argument; <code>false</code> otherwise.
59 */
60 public boolean equals(final Object object) {
61 if (object == null) {
62 return false;
63 }
64 if (!(object instanceof DNotesError)) {
65 return false;
66 }
67 return this.id == ((DNotesError) object).id;
68 }
69
70 /***
71 * @see java.lang.Object#hashCode()
72 *
73 * @return the id of the error
74 */
75 public int hashCode() {
76 return id;
77 }
78
79 /***
80 * @see java.lang.Object#toString()
81 *
82 * @return the id of the error
83 */
84 public String toString() {
85 return "" + id;
86 }
87
88 /***
89 * Returns a message for a given error.
90 *
91 * @param e an error
92 * @return a message for the error
93 */
94 public static String getMessage(final DNotesError e) {
95 if (e.equals(DATABASE_NOT_FOUND)) {
96 return "database not found";
97 } else if (e.equals(DATABASE_NOT_FOUND)) {
98 return "no access to database";
99 } else {
100 return "";
101 }
102 }
103 }