]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java
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
.slc
.process
;
19 import java
.io
.Serializable
;
20 import java
.util
.ArrayList
;
21 import java
.util
.Date
;
22 import java
.util
.List
;
23 import java
.util
.StringTokenizer
;
24 import java
.util
.UUID
;
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.
30 public class SlcExecutionStep
implements Serializable
{
31 private static final long serialVersionUID
= -7308643628104726471L;
33 public final static String START
= "START";
34 public final static String END
= "END";
35 public final static String PHASE_START
= "PHASE_START";
36 public final static String PHASE_END
= "PHASE_END";
37 public final static String ERROR
= "ERROR";
38 public final static String WARNING
= "WARNING";
39 public final static String INFO
= "INFO";
40 public final static String DEBUG
= "DEBUG";
41 public final static String TRACE
= "TRACE";
43 private String uuid
= UUID
.randomUUID().toString();
45 private String thread
;
46 private Date timestamp
= new Date();
47 private List
<String
> logLines
= new ArrayList
<String
>();
49 /** Empty constructor */
50 public SlcExecutionStep() {
51 thread
= Thread
.currentThread().getName();
54 /** Creates a step at the current date of type INFO */
55 public SlcExecutionStep(String log
) {
56 this(new Date(), INFO
, log
);
59 /** Creates a step at the current date */
60 public SlcExecutionStep(String type
, String log
) {
61 this(new Date(), type
, log
);
64 /** Creates a step of the given type. */
65 public SlcExecutionStep(Date timestamp
, String type
, String log
) {
66 this(timestamp
, type
, log
, Thread
.currentThread().getName());
69 public SlcExecutionStep(Date timestamp
, String type
, String log
,
72 this.timestamp
= timestamp
;
77 public String
getUuid() {
81 public void setUuid(String uuid
) {
85 public String
getType() {
89 public void setType(String type
) {
93 public Date
getTimestamp() {
97 public void setTimestamp(Date begin
) {
98 this.timestamp
= begin
;
101 public String
getThread() {
105 public void setThread(String thread
) {
106 this.thread
= thread
;
109 public List
<String
> getLogLines() {
113 public void setLogLines(List
<String
> logLines
) {
114 this.logLines
= logLines
;
117 public void addLog(String log
) {
121 StringTokenizer st
= new StringTokenizer(log
, "\n");
122 while (st
.hasMoreTokens())
123 logLines
.add(removeNonXmlChars(st
.nextToken()));
127 * Removes non XML compliant characters (from
128 * http://stackoverflow.com/questions
129 * /20762/how-do-you-remove-invalid-hexadecimal
130 * -characters-from-an-xml-based-data-source-pr)
132 private static String
removeNonXmlChars(String inString
) {
133 if (inString
== null)
136 StringBuilder newString
= new StringBuilder();
139 for (int i
= 0; i
< inString
.length(); i
++) {
141 ch
= inString
.charAt(i
);
142 // remove any characters outside the valid UTF-8 range as well as
143 // all control characters
144 // except tabs and new lines
145 if ((ch
< 0x00FD && ch
> 0x001F) || ch
== '\t' || ch
== '\n'
147 newString
.append(ch
);
150 return newString
.toString();
155 public String
toString() {
156 return getClass().getSimpleName() + "#" + uuid
;