You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/08/03 16:27:14 UTC

svn commit: r227228 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location: LocatedException.java LocatedRuntimeException.java

Author: sylvain
Date: Wed Aug  3 07:27:11 2005
New Revision: 227228

URL: http://svn.apache.org/viewcvs?rev=227228&view=rev
Log:
Refactor Ugo's null sanity check, and factorize getMessage() that was duplicated

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java?rev=227228&r1=227227&r2=227228&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedException.java Wed Aug  3 07:27:11 2005
@@ -60,17 +60,30 @@
         return super.getMessage();
     }
 
-    public String getMessage() {
-        if (this.locations == null) {
-            return super.getMessage();
+    /**
+     * Standard way of building the message of a {@link LocatableException}, as a Java-like
+     * stack trace of locations.
+     * 
+     * @param message the exception's message, given by <code>super.getMessage()</code> (can be null)
+     * @param locations the location list (can be null)
+     * 
+     * @return the message, or <code>null</code> no message and locations were given.
+     */
+    public static String getMessage(String message, List locations) {
+        if (locations == null || locations.isEmpty()) {
+            return message;
         }
 
         // Produce a Java-like stacktrace with locations
-        StringBuffer buf = new StringBuffer(super.getMessage());
+        StringBuffer buf = message == null ? new StringBuffer() : new StringBuffer(message);
         for (int i = 0; i < locations.size(); i++) {
             buf.append("\n\tat ").append(locations.get(i));
         }
         return buf.toString();
+    }
+
+    public String getMessage() {
+        return getMessage(super.getMessage(), locations);
     }
     
     public void addLocation(Location loc) {

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java?rev=227228&r1=227227&r2=227228&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/location/LocatedRuntimeException.java Wed Aug  3 07:27:11 2005
@@ -61,16 +61,7 @@
     }
 
     public String getMessage() {
-        if (this.locations == null || super.getMessage() == null) {
-            return super.getMessage();
-        }
-
-        // Produce a Java-like stacktrace with locations
-        StringBuffer buf = new StringBuffer(super.getMessage());
-        for (int i = 0; i < locations.size(); i++) {
-            buf.append("\n\tat ").append(locations.get(i));
-        }
-        return buf.toString();
+        return LocatedException.getMessage(super.getMessage(), locations);
     }
     
     public void addLocation(Location loc) {