[Schmitzm-commits] r662 - branches/2.0-RC2/src/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 3 17:55:19 CET 2010


Author: mojays
Date: 2010-02-03 17:55:14 +0100 (Wed, 03 Feb 2010)
New Revision: 662

Modified:
   branches/2.0-RC2/src/schmitzm/lang/LangUtil.java
   branches/2.0-RC2/src/schmitzm/lang/ResourceProvider.java
Log:
LangUtil: new methods to explore a stack trace
ResourceProvider: location (class) of a missing resource is printed to standard output as stack trace

Modified: branches/2.0-RC2/src/schmitzm/lang/LangUtil.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/lang/LangUtil.java	2010-02-03 16:50:39 UTC (rev 661)
+++ branches/2.0-RC2/src/schmitzm/lang/LangUtil.java	2010-02-03 16:55:14 UTC (rev 662)
@@ -31,6 +31,7 @@
 
 import java.awt.Toolkit;
 import java.awt.datatransfer.StringSelection;
+import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -909,8 +910,55 @@
     StringSelection sel = new StringSelection( str );
     Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel,sel);
   }
+  
+  
+  /**
+   * Returns the class names of the top of a stack trace. Duplicate class names
+   * are eliminated.
+   * @param stackTrace stack trace to explore
+   * @param depth      maximum count of classes, which are explored in the stack
+   *                   trace
+   */
+  public static String[] getLastStackTraceClasses(StackTraceElement[] stackTrace, int depth) {
+    Vector<String> lastClasses = new Vector<String>();
+    for (StackTraceElement st : stackTrace) {
+      String className = st.getClassName();
+      if ( !lastClasses.contains(className) )
+        lastClasses.add(className);
+      if ( lastClasses.size() >= depth )
+        break;
+    }
+    return lastClasses.toArray(new String[0]);
+  }
 
   /**
+   * Prints the last X classes from a stack trace.
+   * @param stackTrace stack trace to explore
+   * @param depth      maximum count of classes, which are explored in the stack
+   *                   trace
+   * @param out        output stream to write to
+   */
+  public static void printLastStackTraceClasses(StackTraceElement[] stackTrace, int depth, PrintStream out) {
+    String[] lastClasses = getLastStackTraceClasses(stackTrace, depth);
+    for (int i=0; i<lastClasses.length; i++) {
+      if (i > 0)
+        out.print("\t...");
+      out.println(lastClasses[i]);
+    }
+  }
+
+  /**
+   * Prints the last X classes from a stack trace to the standard output.
+   * @param stackTrace stack trace to explore
+   * @param depth      maximum count of classes, which are explored in the stack
+   *                   trace
+   * @see System#out
+   */
+  public static void printLastStackTraceClasses(StackTraceElement[] stackTrace, int depth) {
+    printLastStackTraceClasses(stackTrace, depth, System.out);
+  }
+
+  /**
    * Erzeugt einen Log4j-Logger fuer ein Objekt. Als Identifier fuer den Logger
    * wird der Klassenname des Objekts verwendet.
    * @param object ein Objekt

Modified: branches/2.0-RC2/src/schmitzm/lang/ResourceProvider.java
===================================================================
--- branches/2.0-RC2/src/schmitzm/lang/ResourceProvider.java	2010-02-03 16:50:39 UTC (rev 661)
+++ branches/2.0-RC2/src/schmitzm/lang/ResourceProvider.java	2010-02-03 16:55:14 UTC (rev 662)
@@ -319,9 +319,7 @@
     if (requestedLocale == null) {
     	requestedLocale = Locale.getDefault();
     } 
-//    LOGGER.debug("Requested locale = "+requestedLocale.getLanguage());
     
-    
     // Wenn gesetzt, dann das alternative Bundle (mit Key-Prefix)
     // verwenden. Ansonsten das Standard-Bundle ohne Prefix.
     if ( resourceBundle != null ) {
@@ -335,7 +333,6 @@
     try {
       // Ressource im gesetzten Bundle suchen
       final ResourceBundle pBundle = ResourceBundle.getBundle(primaryBundle, requestedLocale);
-//      LOGGER.debug("And the result is ="+pBundle.getLocale());
 	  return pBundle.getObject(prefix+key);
     } catch (final MissingResourceException err) {
       // Ressource im Standard-Bundle suchen
@@ -345,7 +342,8 @@
         // Wenn Ressource auch im Standard-Bundle nicht vorhanden ist,
         // Fehler werfen (oder ignorieren
         if ( ignoreMissingResource ) {
-          LOGGER.warn("ResourceBundle "+primaryBundle+": "+err.getMessage());
+          LOGGER.warn("ResourceBundle "+primaryBundle+": "+err.getMessage()+" in");
+          LangUtil.printLastStackTraceClasses(err.getStackTrace(), 4);
           return null;
         }
         throw err2;



More information about the Schmitzm-commits mailing list