]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.core/src/main/java/org/argeo/server/ServerAnswer.java
2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.server
;
18 import java
.io
.PrintWriter
;
19 import java
.io
.StringWriter
;
21 import org
.apache
.commons
.io
.IOUtils
;
22 import org
.argeo
.ArgeoException
;
24 /** Answer to an execution of a remote service which performed changes. */
25 public class ServerAnswer
{
26 public final static String OK
= "OK";
27 public final static String ERROR
= "ERROR";
29 private String status
= OK
;
30 private String message
= "";
32 // TODO: add an exception field
34 /** Canonical constructor */
35 public ServerAnswer(String status
, String message
) {
38 throw new ArgeoException("Message cannot be null");
39 this.message
= message
;
42 /** Empty constructor */
43 public ServerAnswer() {
46 public String
getStatus() {
50 public void setStatus(String status
) {
51 if (status
== null || (!status
.equals(OK
) && !status
.equals(ERROR
)))
52 throw new ArgeoException("Bad status format: " + status
);
56 public String
getMessage() {
60 public void setMessage(String message
) {
61 this.message
= message
;
64 public Boolean
isOk() {
65 return status
.equals(OK
);
68 public Boolean
isError() {
69 return status
.equals(ERROR
);
72 public static ServerAnswer
error(String message
) {
73 return new ServerAnswer(ERROR
, message
);
76 public static ServerAnswer
error(Throwable e
) {
77 StringWriter writer
= new StringWriter();
79 e
.printStackTrace(new PrintWriter(writer
));
80 return new ServerAnswer(ERROR
, writer
.toString());
82 IOUtils
.closeQuietly(writer
);
86 public static ServerAnswer
ok(String message
) {
87 return new ServerAnswer(OK
, message
);
91 public String
toString() {
92 return "ServerAnswer{status:" + status
+ ", message:" + message
+ "}";