1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.log4j;
22  
23  import org.apache.log4j.spi.LocationInfo;
24  /*
25   * Created on 21.11.2004
26   *
27   * Contributing Author(s):
28   *
29   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
30   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
31   */
32  /***
33   * TODO Add docs
34   * @author vlads
35   * @version $Revision: 1.4 $ ($Author: vlads $)
36   */
37  public class Java14LocationInfo extends LocationInfo {
38  
39      /***
40       * Caller's line number.
41       */
42      transient String lineNumber;
43  
44      /***
45       * Caller's file name.
46       */
47      transient String fileName;
48  
49      /***
50       * Caller's fully qualified class name.
51       */
52      transient String className;
53  
54      /***
55       * Caller's method name.
56       */
57      transient String methodName;
58      
59      public final static String NA = "?";
60      
61      public static long callCount;
62   
63      public Java14LocationInfo(Throwable t, String fqnOfCallingClass) {
64          super(null, null);
65          if (t == null) {
66              return;
67          }
68          callCount ++;
69          StackTraceElement[] ste =  t.getStackTrace();
70          boolean found = false;
71          for (int i = 0; i < ste.length; i++ ) {
72              if (ste[i].getClassName().equals(fqnOfCallingClass)) {
73                  found = true;
74              } else if (found) {
75                  StackTraceElement e = ste[i];
76                  this.lineNumber = new Integer(e.getLineNumber()).toString();
77                  this.fileName = e.getFileName();
78                  this.methodName = e.getMethodName();
79                  this.className = e.getClassName();
80          		return;
81              }
82          }
83          this.lineNumber = NA;
84          this.fileName = NA;
85          this.methodName = NA;
86          this.className = NA;        
87      }
88     
89      /***
90       * @return Returns the className.
91       */
92      public String getClassName() {
93          return className;
94      }
95      /***
96       * @return Returns the fileName.
97       */
98      public String getFileName() {
99          return fileName;
100     }
101     /***
102      * @return Returns the lineNumber.
103      */
104     public String getLineNumber() {
105         return lineNumber;
106     }
107     /***
108      * @return Returns the methodName.
109      */
110     public String getMethodName() {
111         return methodName;
112     }
113 }