]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/ExecutionAnswer.java
1 package org
.argeo
.slc
.msg
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.StringWriter
;
6 import org
.apache
.commons
.io
.IOUtils
;
7 import org
.argeo
.slc
.SlcException
;
9 /** Answer to an execution of a remote service which performed changes. */
10 public class ExecutionAnswer
{
11 public final static String OK
= "OK";
12 public final static String ERROR
= "ERROR";
14 private String status
= OK
;
15 private String message
= "";
17 /** Canonical constructor */
18 public ExecutionAnswer(String status
, String message
) {
21 throw new SlcException("Message cannot be null");
22 this.message
= message
;
25 /** Empty constructor */
26 public ExecutionAnswer() {
29 public String
getStatus() {
33 public void setStatus(String status
) {
34 if (status
== null || (!status
.equals(OK
) && !status
.equals(ERROR
)))
35 throw new SlcException("Bad status format: " + status
);
39 public String
getMessage() {
43 public void setMessage(String message
) {
44 this.message
= message
;
47 public Boolean
isOk() {
48 return status
.equals(OK
);
51 public Boolean
isError() {
52 return status
.equals(ERROR
);
55 public static ExecutionAnswer
error(String message
) {
56 return new ExecutionAnswer(ERROR
, message
);
59 public static ExecutionAnswer
error(Throwable e
) {
60 StringWriter writer
= new StringWriter();
62 e
.printStackTrace(new PrintWriter(writer
));
63 return new ExecutionAnswer(ERROR
, writer
.toString());
65 IOUtils
.closeQuietly(writer
);
69 public static ExecutionAnswer
ok(String message
) {
70 return new ExecutionAnswer(OK
, message
);