01: package com.silvermindsoftware.hitch;
02:
03: /**
04: * Copyright 2007 Brandon Goodin
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: public class ErrorContext {
23:
24: private static class ThreadLocalList extends ThreadLocal {
25: public Object initialValue() {
26: return new ArrayList<String>();
27: }
28:
29: public List<String> getList() {
30: return (List<String>) super .get();
31: }
32: }
33:
34: private static ThreadLocalList list = new ThreadLocalList();
35: private static String[] stringArray = new String[0];
36:
37: public static void clear() {
38: list.getList().clear();
39: }
40:
41: public static void put(String text) {
42: list.getList().add(text);
43: }
44:
45: public static void removeLast() {
46: list.getList().remove(list.getList().size() - 1);
47: }
48:
49: public static String[] get() {
50: return (String[]) list.getList().toArray(stringArray);
51: }
52:
53: public static String getAsString() {
54: StringBuilder sb = new StringBuilder();
55: for (String error : list.getList()) {
56: sb.append(error).append('\n');
57: }
58: return sb.toString();
59: }
60:
61: }
|