01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.console.derbylogmanager;
17:
18: import java.io.BufferedReader;
19: import java.io.File;
20: import java.io.FileReader;
21: import java.io.IOException;
22: import java.io.InputStreamReader;
23: import java.util.ArrayList;
24: import java.util.Collection;
25: import java.util.Stack;
26:
27: import org.apache.geronimo.console.util.KernelHelper;
28:
29: import org.apache.geronimo.console.internaldb.DerbyConnectionUtil;
30:
31: public class DerbyLogHelper extends KernelHelper {
32: private static ArrayList logs = new ArrayList();
33:
34: private static boolean cached = false;
35:
36: private static int lineCount = 0;
37:
38: private static final String LOG_FILENAME = "derby.log";
39:
40: public static Collection getLogs() throws IOException {
41: if (!cached) {
42: refresh();
43: }
44: return logs;
45: }
46:
47: public static void refresh() throws IOException {
48: cached = false;
49: logs.clear();
50: BufferedReader in = new BufferedReader(getFileReader());
51: lineCount = 0;
52: Stack holder = new Stack();
53: for (String line = in.readLine(); line != null; line = in
54: .readLine()) {
55: holder.push(line);
56: lineCount++;
57: }
58: logs.addAll(holder);
59: cached = true;
60: }
61:
62: public static int getLineCount() {
63: return lineCount;
64: }
65:
66: private static InputStreamReader getFileReader() throws IOException {
67: String pathToFile = getSystemHome() + File.separator
68: + LOG_FILENAME;
69: return new FileReader(new File(pathToFile));
70: }
71:
72: public static String getSystemHome() {
73: return DerbyConnectionUtil.getDerbyHome();
74: }
75:
76: }
|