001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.bo.job;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.qedeq.kernel.bo.common.ModuleServiceResult;
020
021
022 /**
023 * Execution result of a {@link ModuleServiceCall}.
024 *
025 * @author Michael Meyling
026 */
027 public class ServiceResultImpl implements ModuleServiceResult {
028
029 /** A simple service result that has a user interrupt. */
030 public static final ModuleServiceResult INTERRUPTED = new ServiceResultImpl(true);
031
032 /** A simple successful (=ok) service result. */
033 public static final ModuleServiceResult SUCCESSFUL = new ServiceResultImpl(false);
034
035 /** Did a user interrupt occur and ended the service call? */
036 private final boolean interrupted;
037
038 /** Was the call fully successful (finished ok without errors and warnings)? */
039 private final boolean ok;
040
041 /** Did warnings occur? */
042 private final boolean hasWarnings;
043
044 /** Did errors occur? */
045 private final boolean hasErrors;
046
047 /** Error message. Might be empty. */
048 private final String message;
049
050 /** Result of service call. Might be null even for a successful call. */
051 private Object result;
052
053 /**
054 * Constructor.
055 *
056 * @param interrupted Did a user interrupt occur and ended the service call?
057 * @param ok Was the call fully successful (finished ok without errors and warnings)?
058 * @param hasWarnings Did warnings occur?
059 * @param hasErrors Did errors occur?
060 * @param message Error message. Might be empty.
061 * @param result Result of service call. Might be null even for a successful call.
062 */
063 public ServiceResultImpl(final boolean interrupted, final boolean ok, final boolean hasWarnings,
064 final boolean hasErrors, final String message, final Object result) {
065 this.interrupted = interrupted;
066 this.ok = ok;
067 this.hasWarnings = hasWarnings;
068 this.hasErrors = hasErrors;
069 this.message = message;
070 this.result = result;
071 }
072
073 /**
074 * Constructor for a failure call.
075 *
076 * @param errorMessage Error message. Should not be empty.
077 */
078 public ServiceResultImpl(final String errorMessage) {
079 this.interrupted = false;
080 this.ok = false;
081 this.hasErrors = true;
082 this.hasWarnings = false;
083 this.message = errorMessage;
084 this.result = null;
085 }
086
087 /**
088 * Constructor for simple successful or user interrupted call.
089 *
090 * @param interrupted Did a user interrupt occur and ended the service call?
091 */
092 private ServiceResultImpl(final boolean interrupted) {
093 if (interrupted) {
094 this.interrupted = true;
095 this.ok = false;
096 this.hasErrors = true;
097 this.message = "User interrupted service call.";
098 } else {
099 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 }
|