1 /*
2 * Copyright 2012-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.properties.report.data;
17
18 import java.io.Serializable;
19
20 /**
21 * Stores a problem found by the report builder.
22 */
23 public final class ReportProblem implements Serializable
24 {
25 // ********************************* Fields *********************************
26
27 // --- constants ------------------------------------------------------------
28
29 /**
30 * The class version identifier.
31 * <p>
32 * The value of this constant is {@value}.
33 * </p>
34 */
35 private static final long serialVersionUID = 1L;
36
37 // --- members --------------------------------------------------------------
38
39 /**
40 * The message to the problem.
41 */
42 private final String message;
43
44 /**
45 * The optional root cause to the problem.
46 */
47 private final Throwable cause;
48
49 // ****************************** Initializer *******************************
50
51 // ****************************** Constructors ******************************
52
53 /**
54 * Convenience constructor to use the message of the root cause.
55 *
56 * @param cause the optional root cause to the problem.
57 */
58 public ReportProblem(final Throwable cause)
59 {
60 this(cause.getMessage(), cause);
61 }
62
63 /**
64 * Convenience constructor without a root cause.
65 *
66 * @param message the message to the problem.
67 */
68 public ReportProblem(final String message)
69 {
70 this(message, null);
71 }
72
73 /**
74 * Default constructor.
75 *
76 * @param message the message to the problem.
77 * @param cause the optional root cause to the problem.
78 */
79 public ReportProblem(final String message, final Throwable cause)
80 {
81 this.message = message;
82 this.cause = cause;
83 }
84
85 // ****************************** Inner Classes *****************************
86
87 // ********************************* Methods ********************************
88
89 // --- init -----------------------------------------------------------------
90
91 // --- get&set --------------------------------------------------------------
92
93 /**
94 * Returns the message to the problem.
95 *
96 * @return the message to the problem.
97 */
98 public String getMessage()
99 {
100 return message;
101 }
102
103 /**
104 * Returns the optional root cause to the problem.
105 *
106 * @return the optional root cause to the problem.
107 */
108 public Throwable getCause()
109 {
110 return cause;
111 }
112
113 // --- business -------------------------------------------------------------
114
115 // --- object basics --------------------------------------------------------
116
117 /**
118 * Returns the string representation of the object.
119 *
120 * @return the string representation of the object.
121 */
122 @Override
123 public String toString()
124 {
125 final StringBuilder buffer = new StringBuilder();
126
127 buffer.append(message);
128 if (cause != null)
129 {
130 buffer.append(": ").append(cause);
131 }
132
133 return buffer.toString();
134 }
135 }