1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
2 | * |
3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
4 | * |
5 | * "Hilbert II" is free software; you can redistribute |
6 | * it and/or modify it under the terms of the GNU General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | */ |
15 | |
16 | package org.qedeq.kernel.bo.job; |
17 | |
18 | import org.apache.commons.lang.StringUtils; |
19 | import org.qedeq.kernel.bo.common.ModuleServiceResult; |
20 | |
21 | |
22 | /** |
23 | * Execution result of a {@link ModuleServiceCall}. |
24 | * |
25 | * @author Michael Meyling |
26 | */ |
27 | public class ServiceResultImpl implements ModuleServiceResult { |
28 | |
29 | /** A simple service result that has a user interrupt. */ |
30 | public static final ModuleServiceResult INTERRUPTED = new ServiceResultImpl(true); |
31 | |
32 | /** A simple successful (=ok) service result. */ |
33 | public static final ModuleServiceResult SUCCESSFUL = new ServiceResultImpl(false); |
34 | |
35 | /** Did a user interrupt occur and ended the service call? */ |
36 | private final boolean interrupted; |
37 | |
38 | /** Was the call fully successful (finished ok without errors and warnings)? */ |
39 | private final boolean ok; |
40 | |
41 | /** Did warnings occur? */ |
42 | private final boolean hasWarnings; |
43 | |
44 | /** Did errors occur? */ |
45 | private final boolean hasErrors; |
46 | |
47 | /** Error message. Might be empty. */ |
48 | private final String message; |
49 | |
50 | /** Result of service call. Might be null even for a successful call. */ |
51 | private Object result; |
52 | |
53 | /** |
54 | * Constructor. |
55 | * |
56 | * @param interrupted Did a user interrupt occur and ended the service call? |
57 | * @param ok Was the call fully successful (finished ok without errors and warnings)? |
58 | * @param hasWarnings Did warnings occur? |
59 | * @param hasErrors Did errors occur? |
60 | * @param message Error message. Might be empty. |
61 | * @param result Result of service call. Might be null even for a successful call. |
62 | */ |
63 | public ServiceResultImpl(final boolean interrupted, final boolean ok, final boolean hasWarnings, |
64 | final boolean hasErrors, final String message, final Object result) { |
65 | this.interrupted = interrupted; |
66 | this.ok = ok; |
67 | this.hasWarnings = hasWarnings; |
68 | this.hasErrors = hasErrors; |
69 | this.message = message; |
70 | this.result = result; |
71 | } |
72 | |
73 | /** |
74 | * Constructor for a failure call. |
75 | * |
76 | * @param errorMessage Error message. Should not be empty. |
77 | */ |
78 | public ServiceResultImpl(final String errorMessage) { |
79 | this.interrupted = false; |
80 | this.ok = false; |
81 | this.hasErrors = true; |
82 | this.hasWarnings = false; |
83 | this.message = errorMessage; |
84 | this.result = null; |
85 | } |
86 | |
87 | /** |
88 | * Constructor for simple successful or user interrupted call. |
89 | * |
90 | * @param interrupted Did a user interrupt occur and ended the service call? |
91 | */ |
92 | private ServiceResultImpl(final boolean interrupted) { |
93 | if (interrupted) { |
94 | this.interrupted = true; |
95 | this.ok = false; |
96 | this.hasErrors = true; |
97 | this.message = "User interrupted service call."; |
98 | } else { |
99 | this.interrupted = false; |
100 | this.ok = true; |
101 | this.hasErrors = true; |
102 | this.message = StringUtils.EMPTY; |
103 | } |
104 | this.hasWarnings = false; |
105 | this.result = null; |
106 | } |
107 | |
108 | public boolean wasInterrupted() { |
109 | return interrupted; |
110 | } |
111 | |
112 | public boolean isOk() { |
113 | return ok; |
114 | } |
115 | |
116 | public boolean hasWarnings() { |
117 | return hasWarnings; |
118 | } |
119 | |
120 | public boolean hasErrors() { |
121 | return hasErrors; |
122 | } |
123 | |
124 | public String getErrorMessage() { |
125 | return message; |
126 | } |
127 | |
128 | public Object getExecutionResult() { |
129 | return result; |
130 | } |
131 | |
132 | /** |
133 | * Remove execution result. This might be necessary because it is really big. |
134 | */ |
135 | public void deleteExecutionResult() { |
136 | result = null; |
137 | } |
138 | } |