Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.console.derbylogmanager » [javadoc | source]
    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;
   21   import java.io.File;
   22   import java.io.FileReader;
   23   import java.io.IOException;
   24   import java.io.InputStreamReader;
   25   import java.util.ArrayList;
   26   import java.util.Collection;
   27   import java.util.Stack;
   28   
   29   import org.apache.geronimo.console.util.KernelHelper;
   30   
   31   import org.apache.geronimo.console.internaldb.DerbyConnectionUtil;
   32   
   33   public class DerbyLogHelper extends KernelHelper {
   34       private static ArrayList logs = new ArrayList();
   35   
   36       private static boolean cached = false;
   37   
   38       private static int lineCount = 0;
   39   
   40       private static final String LOG_FILENAME = "derby.log";
   41   
   42       public static Collection getLogs() throws IOException {
   43           if (!cached) {
   44               refresh();
   45           }
   46           return logs;
   47       }
   48   
   49       public static void refresh() throws IOException {
   50           cached = false;
   51           logs.clear();
   52           BufferedReader in = new BufferedReader(getFileReader());
   53           lineCount = 0;
   54           Stack holder = new Stack();
   55           for (String 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 getFileReader() throws IOException {
   68           String pathToFile = getSystemHome() + File.separator + LOG_FILENAME;
   69           return new FileReader(new File(pathToFile));
   70       }
   71   
   72       public static String getSystemHome() {
   73           return DerbyConnectionUtil.getDerbyHome();
   74       }
   75   
   76   }

Save This Page
Home » geronimo-2.2-source-release » org.apache.geronimo.console.derbylogmanager » [javadoc | source]