]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/ServerAnswer.java
de15add0d49fda8c760b7817bb84ef0a568278ac
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.server
;
19 import java
.io
.PrintWriter
;
20 import java
.io
.StringWriter
;
22 import org
.apache
.commons
.io
.IOUtils
;
23 import org
.argeo
.ArgeoException
;
25 /** Answer to an execution of a remote service which performed changes. */
26 public class ServerAnswer
{
27 public final static String OK
= "OK";
28 public final static String ERROR
= "ERROR";
30 private String status
= OK
;
31 private String message
= "";
33 // TODO: add an exception field
35 /** Canonical constructor */
36 public ServerAnswer(String status
, String message
) {
39 throw new ArgeoException("Message cannot be null");
40 this.message
= message
;
43 /** Empty constructor */
44 public ServerAnswer() {
47 public String
getStatus() {
51 public void setStatus(String status
) {
52 if (status
== null || (!status
.equals(OK
) && !status
.equals(ERROR
)))
53 throw new ArgeoException("Bad status format: " + status
);
57 public String
getMessage() {
61 public void setMessage(String message
) {
62 this.message
= message
;
65 public Boolean
isOk() {
66 return status
.equals(OK
);
69 public Boolean
isError() {
70 return status
.equals(ERROR
);
73 public static ServerAnswer
error(String message
) {
74 return new ServerAnswer(ERROR
, message
);
77 public static ServerAnswer
error(Throwable e
) {
78 StringWriter writer
= new StringWriter();
80 e
.printStackTrace(new PrintWriter(writer
));
81 return new ServerAnswer(ERROR
, writer
.toString());
83 IOUtils
.closeQuietly(writer
);
87 public static ServerAnswer
ok(String message
) {
88 return new ServerAnswer(OK
, message
);
92 public String
toString() {
93 return "ServerAnswer{status:" + status
+ ", message:" + message
+ "}";