]>
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
;
26 public class SlcExecutionStep
implements Serializable
{
27 private static final long serialVersionUID
= -7308643628104726471L;
29 public final static String START
= "START";
30 public final static String END
= "END";
31 public final static String PHASE_START
= "PHASE_START";
32 public final static String PHASE_END
= "PHASE_END";
33 public final static String ERROR
= "ERROR";
34 public final static String WARNING
= "WARNING";
35 public final static String INFO
= "INFO";
36 public final static String DEBUG
= "DEBUG";
37 public final static String TRACE
= "TRACE";
39 private String uuid
= UUID
.randomUUID().toString();
41 private String thread
;
42 private Date timestamp
= new Date();
43 private List
<String
> logLines
= new ArrayList
<String
>();
45 /** Empty constructor */
46 public SlcExecutionStep() {
47 thread
= Thread
.currentThread().getName();
50 /** Creates a step at the current date of type INFO */
51 public SlcExecutionStep(String log
) {
52 this(new Date(), INFO
, log
);
55 /** Creates a step at the current date */
56 public SlcExecutionStep(String type
, String log
) {
57 this(new Date(), type
, log
);
60 /** Creates a step of the given type. */
61 public SlcExecutionStep(Date timestamp
, String type
, String log
) {
62 this(timestamp
, type
, log
, Thread
.currentThread().getName());
65 public SlcExecutionStep(Date timestamp
, String type
, String log
,
68 this.timestamp
= timestamp
;
73 public String
getUuid() {
77 public void setUuid(String uuid
) {
81 public String
getType() {
85 public void setType(String type
) {
89 public Date
getTimestamp() {
93 public void setTimestamp(Date begin
) {
94 this.timestamp
= begin
;
97 public String
getThread() {
101 public void setThread(String thread
) {
102 this.thread
= thread
;
105 public List
<String
> getLogLines() {
109 public void setLogLines(List
<String
> logLines
) {
110 this.logLines
= logLines
;
113 public void addLog(String log
) {
117 StringTokenizer st
= new StringTokenizer(log
, "\n");
118 while (st
.hasMoreTokens())
119 logLines
.add(removeNonXmlChars(st
.nextToken()));
123 * Removes non XML compliant characters (from
124 * http://stackoverflow.com/questions
125 * /20762/how-do-you-remove-invalid-hexadecimal
126 * -characters-from-an-xml-based-data-source-pr)
128 private static String
removeNonXmlChars(String inString
) {
129 if (inString
== null)
132 StringBuilder newString
= new StringBuilder();
135 for (int i
= 0; i
< inString
.length(); i
++) {
137 ch
= inString
.charAt(i
);
138 // remove any characters outside the valid UTF-8 range as well as
139 // all control characters
140 // except tabs and new lines
141 if ((ch
< 0x00FD && ch
> 0x001F) || ch
== '\t' || ch
== '\n'
143 newString
.append(ch
);
146 return newString
.toString();
151 public String
toString() {
152 return getClass().getSimpleName() + "#" + uuid
;