]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/DetachedAnswer.java
Update headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.detached / src / main / java / org / argeo / slc / detached / DetachedAnswer.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.detached;
17
18 import java.util.Properties;
19
20 /** An answer returned by the detached server. Always related to a request. */
21 public class DetachedAnswer implements DetachedCommunication {
22 static final long serialVersionUID = 1l;
23
24 public final static int UNKOWN = -1;
25 public final static int PROCESSED = 0;
26 public final static int ERROR = 1;
27 public final static int SKIPPED = 2;
28 public final static int CLOSED_SESSION = 10;
29
30 private Properties properties = new Properties();
31 private int status = UNKOWN;
32 private String log;
33 private String uuid;
34
35 public DetachedAnswer() {
36
37 }
38
39 public DetachedAnswer(DetachedRequest request) {
40 uuid = request.getUuid();
41 }
42
43 public DetachedAnswer(DetachedRequest request, String message) {
44 this(request);
45 log = message;
46 status = PROCESSED;
47 }
48
49 public Properties getProperties() {
50 return properties;
51 }
52
53 public void setProperties(Properties outputParameters) {
54 this.properties = outputParameters;
55 }
56
57 public int getStatus() {
58 return status;
59 }
60
61 public void setStatus(int outputStatus) {
62 this.status = outputStatus;
63 }
64
65 public String getLog() {
66 return log;
67 }
68
69 public void setLog(String log) {
70 this.log = log;
71 }
72
73 public void addToLog(String msg) {
74 this.log = new StringBuffer(this.log).append(msg).toString();
75 }
76
77 /** The unique identifier of this answer. */
78 public String getUuid() {
79 return uuid;
80 }
81
82 public void setUuid(String uuid) {
83 this.uuid = uuid;
84 }
85
86 public String getStatusAsString() {
87 return convertStatus(getStatus());
88 }
89
90 public static String convertStatus(int status) {
91 switch (status) {
92 case UNKOWN:
93 return "UNKOWN";
94 case PROCESSED:
95 return "PROCESSED";
96 case SKIPPED:
97 return "SKIPPED";
98 case ERROR:
99 return "ERROR";
100 case CLOSED_SESSION:
101 return "CLOSED_SESSION";
102 default:
103 throw new DetachedException("Unkown status " + status);
104 }
105 }
106
107 public String toString() {
108 StringBuffer buf = new StringBuffer("detached answer ");
109 buf.append('#').append(uuid);
110 buf.append(" status=").append(convertStatus(status));
111 buf.append(" properties=").append(properties);
112 buf.append(" log=").append(log);
113 return buf.toString();
114 }
115 }