KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > derbylogmanager > DerbyLogHelper


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17
18 package org.apache.geronimo.console.derbylogmanager;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.File JavaDoc;
22 import java.io.FileReader JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Stack JavaDoc;
28
29 import org.apache.geronimo.console.util.KernelHelper;
30
31 public class DerbyLogHelper extends KernelHelper {
32     private static ArrayList JavaDoc logs = new ArrayList JavaDoc();
33
34     private static boolean cached = false;
35
36     private static int lineCount = 0;
37
38     private static final String JavaDoc DERBY_SYSTEM_HOME = "derby.system.home";
39
40     private static final String JavaDoc LOG_FILENAME = "derby.log";
41
42     public static Collection JavaDoc getLogs() throws IOException JavaDoc {
43         if (!cached) {
44             refresh();
45         }
46         return logs;
47     }
48
49     public static void refresh() throws IOException JavaDoc {
50         cached = false;
51         logs.clear();
52         BufferedReader JavaDoc in = new BufferedReader JavaDoc(getFileReader());
53         lineCount = 0;
54         Stack JavaDoc holder = new Stack JavaDoc();
55         for (String JavaDoc line = in.readLine(); line != null; line = in.readLine()) {
56             holder.push(line);
57             lineCount++;
58         }
59         logs.addAll(holder);
60         cached = true;
61     }
62
63     public static int getLineCount() {
64         return lineCount;
65     }
66
67     private static InputStreamReader JavaDoc getFileReader() throws IOException JavaDoc {
68         String JavaDoc pathToFile = getSystemHome() + File.separator + LOG_FILENAME;
69         return new FileReader JavaDoc(new File JavaDoc(pathToFile));
70     }
71
72     public static String JavaDoc getSystemHome() {
73         return System.getProperty(DERBY_SYSTEM_HOME);
74     }
75
76
77 }
78
Popular Tags