whitlock    2002/10/30 09:42:45

  Modified:    java/src/org/apache/wsif/logging Tag: pre1_2_0-patches
                        Trc.java
  Log:
  Fix calculation of method names
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +31 -17    xml-axis-wsif/java/src/org/apache/wsif/logging/Trc.java
  
  Index: Trc.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/src/org/apache/wsif/logging/Trc.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- Trc.java  18 Sep 2002 15:38:19 -0000      1.7
  +++ Trc.java  30 Oct 2002 17:42:45 -0000      1.7.2.1
  @@ -1114,19 +1114,20 @@
           PrintWriter pw = new PrintWriter(sw);
           e.printStackTrace(pw);
           String stack = sw.getBuffer().toString();
  -
  +        
           // The next while loop tries to find the method that called
  -        // Trc. The method name will have (...parmeters...) after it
  -        // and will be after the last call to Trc. 
  -        StringTokenizer st1 = new StringTokenizer(stack);
  +        // Trc. The line with the method name will be after the last 
  +        // call to Trc. 
  +        StringTokenizer st1 =
  +            new StringTokenizer(
  +                stack,
  +                System.getProperty("line.separator", "\n"));
           boolean foundWsifLogging = false;
  -        String tok = null;
  +        String tok1 = null;
           while (st1.hasMoreTokens()) {
  -            tok = st1.nextToken();
  -            if (tok.indexOf("(") == -1)
  -                continue;
  +            tok1 = st1.nextToken();
   
  -            if (tok.startsWith(wsifPackageName + ".logging")) {
  +            if (tok1.indexOf(wsifPackageName + ".logging") != -1) {
                   foundWsifLogging = true;
                   continue;
               }
  @@ -1135,22 +1136,35 @@
                   break;
           }
   
  +        // Now find the first word which contains a (. This should be 
  +        // prefixed by the method name. If there isn't a (, which 
  +        // is unlikely, use the whole line.
  +        StringTokenizer st2 = new StringTokenizer(tok1);
  +        String tok2 = null;
  +        while (st2.hasMoreTokens()) {
  +            tok2 = st2.nextToken();
  +            if (tok2.indexOf("(") != -1)
  +                break;
  +        }
  +        if (tok2.indexOf("(") == -1)
  +            tok2 = tok1;
  +
           // Indent the method name by the number of WSIF calls 
           // higher up the stack. This improves readability. There
           // were various other ways of calculating the indentation
           // but this seemed the most reliable (and simplest).
           buff.append(" ");
           while (st1.hasMoreTokens()) {
  -            if (st1.nextToken().startsWith(wsifPackageName))
  +            if (st1.nextToken().indexOf(wsifPackageName) != -1)
                   buff.append(" ");
           }
   
           // Strip off the (... parameters...). I expect there will
           // always be a ( in the token, but this code copes even if 
           // there isn't.
  -        int idx = tok.indexOf("(");
  +        int idx = tok2.indexOf("(");
           if (idx != -1)
  -            tok = tok.substring(0, idx);
  +            tok2 = tok2.substring(0, idx);
   
           // Now strip off the WSIF package name off the front of 
           // the class name. All WSIF class names are unique, so 
  @@ -1159,17 +1173,17 @@
           // WSIF (unlikely) then output the whole 
           // packagename.classname.methodname.
           String result = null;
  -        if (tok.startsWith(wsifPackageName)) {
  -            StringTokenizer st2 = new StringTokenizer(tok, ".");
  +        if (tok2.startsWith(wsifPackageName)) {
  +            StringTokenizer st3 = new StringTokenizer(tok2, ".");
               String previous = null;
  -            while (st2.hasMoreTokens()) {
  +            while (st3.hasMoreTokens()) {
                   previous = result;
  -                result = st2.nextToken();
  +                result = st3.nextToken();
               }
               if (previous != null)
                   result = previous + "." + result;
           } else
  -            result = tok;
  +            result = tok2;
   
           buff.append(result);
       }
  
  
  


Reply via email to