]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java
Provide SlcAgentFactory in the core agent
[gpl/argeo-slc.git] / runtime / org.argeo.slc.specs / src / main / java / org / argeo / slc / process / SlcExecutionStep.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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.process;
17
18 import java.util.ArrayList;
19 import java.util.Date;
20 import java.util.List;
21 import java.util.StringTokenizer;
22 import java.util.UUID;
23
24 import org.argeo.slc.execution.ExecutionStep;
25
26 /**
27 * An atomic step to be notified in during an {@link SlcExecution}. Can be a log
28 * or the start/end of a phase, etc.
29 *
30 * @deprecated use {@link ExecutionStep} instead
31 */
32 public class SlcExecutionStep extends ExecutionStep {
33 private static final long serialVersionUID = -7308643628104726471L;
34
35 private String uuid = UUID.randomUUID().toString();
36 private List<String> logLines = new ArrayList<String>();
37
38 /** Empty constructor */
39 public SlcExecutionStep() {
40 }
41
42 /** Creates a step at the current date of type INFO */
43 public SlcExecutionStep(String log) {
44 this(new Date(), INFO, log);
45 }
46
47 /** Creates a step at the current date */
48 public SlcExecutionStep(String type, String log) {
49 this(new Date(), type, log);
50 }
51
52 /** Creates a step of the given type. */
53 public SlcExecutionStep(Date timestamp, String type, String log) {
54 this(timestamp, type, log, Thread.currentThread().getName());
55 }
56
57 public SlcExecutionStep(Date timestamp, String type, String log,
58 String thread) {
59 super("UNKOWN_LOCATION", timestamp, type, log, thread);
60 }
61
62 public String getUuid() {
63 return uuid;
64 }
65
66 public void setUuid(String uuid) {
67 this.uuid = uuid;
68 }
69
70 public void setType(String type) {
71 this.type = type;
72 }
73
74 public void setTimestamp(Date begin) {
75 this.timestamp = begin;
76 }
77
78 public void setThread(String thread) {
79 this.thread = thread;
80 }
81
82 public List<String> getLogLines() {
83 return logLines;
84 }
85
86 public void setLogLines(List<String> logLines) {
87 this.logLines = logLines;
88 }
89
90 /** public for legacy reasons */
91 public String addLog(String log) {
92 if (logLines == null)
93 logLines = new ArrayList<String>();
94
95 if (log == null)
96 return null;
97
98 StringTokenizer st = new StringTokenizer(log, "\n");
99 while (st.hasMoreTokens())
100 logLines.add(removeNonXmlChars(st.nextToken()));
101 return null;
102 }
103
104 /**
105 * Removes non XML compliant characters (from
106 * http://stackoverflow.com/questions
107 * /20762/how-do-you-remove-invalid-hexadecimal
108 * -characters-from-an-xml-based-data-source-pr)
109 */
110 private static String removeNonXmlChars(String inString) {
111 if (inString == null)
112 return null;
113
114 StringBuilder newString = new StringBuilder();
115 char ch;
116
117 for (int i = 0; i < inString.length(); i++) {
118
119 ch = inString.charAt(i);
120 // remove any characters outside the valid UTF-8 range as well as
121 // all control characters
122 // except tabs and new lines
123 if ((ch < 0x00FD && ch > 0x001F) || ch == '\t' || ch == '\n'
124 || ch == '\r') {
125 newString.append(ch);
126 }
127 }
128 return newString.toString();
129
130 }
131
132 @Override
133 public String toString() {
134 return getClass().getSimpleName() + "#" + uuid;
135 }
136
137 }