juergen 01/09/10 09:38:53
Modified: src/share/org/apache/slide/util/resources
messages.properties
src/share/org/apache/slide/macro ForbiddenException.java
ConflictException.java
Log:
the conflict and forbidden exception may contain a throwable now. If the constructor
with the throwable is called a warn logging with the cause is generated.
Revision Changes Path
1.12 +4 -4
jakarta-slide/src/share/org/apache/slide/util/resources/messages.properties
Index: messages.properties
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/util/resources/messages.properties,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- messages.properties 2001/09/01 16:59:04 1.11
+++ messages.properties 2001/09/10 16:38:53 1.12
@@ -1,9 +1,9 @@
#
# Slide messages
#
-# $Id: messages.properties,v 1.11 2001/09/01 16:59:04 juergen Exp $
+# $Id: messages.properties,v 1.12 2001/09/10 16:38:53 juergen Exp $
#
-# @version $Revision: 1.11 $ $Date: 2001/09/01 16:59:04 $
+# @version $Revision: 1.12 $ $Date: 2001/09/10 16:38:53 $
#
#
@@ -225,6 +225,6 @@
# Messages produced by macro
#
org.apache.slide.macro.ForbiddenException=\
- Forbidden for uri {0}
+ Forbidden for uri {0}. Cause is: {1}
org.apache.slide.macro.ConflictException=\
- Conflict with uri {0}
+ Conflict with uri {0}. Cause is: {1}
1.2 +58 -6
jakarta-slide/src/share/org/apache/slide/macro/ForbiddenException.java
Index: ForbiddenException.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ForbiddenException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ForbiddenException.java 2001/04/04 15:44:35 1.1
+++ ForbiddenException.java 2001/09/10 16:38:53 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ForbiddenException.java,v 1.1
2001/04/04 15:44:35 juergen Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/04 15:44:35 $
+ * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ForbiddenException.java,v 1.2
2001/09/10 16:38:53 juergen Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/09/10 16:38:53 $
*
* ====================================================================
*
@@ -63,8 +63,11 @@
package org.apache.slide.macro;
-import org.apache.slide.util.Messages;
+import java.io.StringWriter;
+import java.io.PrintWriter;
+
+import org.apache.slide.util.Messages;
import org.apache.slide.common.SlideException;
@@ -72,7 +75,7 @@
* The copy/move operation is forbidden, e.g. source and destination uri are
identical.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ForbiddenException extends SlideException {
@@ -80,17 +83,32 @@
// ----------------------------------------------------------- Constructors
+
/**
* Constructor.
*
* @param objectUri Uri of the forbidden operation
*/
public ForbiddenException(String objectUri) {
- super(Messages.format(ForbiddenException.class.getName(), objectUri),
false);
+ this(objectUri, new SlideException("no cause given", false));
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param objectUri Uri of the forbidden operation
+ * @param t Throwable containing the reason
+ */
+ public ForbiddenException(String objectUri, Throwable t) {
+ super(Messages.format(ConflictException.class.getName(), objectUri,
computeCause(t)), t!=null);
this.objectUri = objectUri;
+ this.nestedException = t;
}
+
+
// ----------------------------------------------------- Instance Variables
@@ -99,7 +117,13 @@
*/
private String objectUri;
+
+ /* hold the cause exception, if supplied */
+ private Throwable nestedException = null;
+
+
+
// ------------------------------------------------------------- Properties
@@ -111,5 +135,33 @@
public String getObjectUri() {
return objectUri;
}
+
+
+
+ /**
+ * computeCause.
+ *
+ * @param e if getMessage is empty the stack trace of e is used
+ */
+ private static String computeCause(Throwable e) {
+ return computeCause(e==null?"":e.getMessage(), e);
+ }
+
+ /**
+ * computeCause.
+ *
+ * @param delieveredCause the cause as a string, if null or empty e is used
+ * @param e the exception stacktrace is shown, if cause is not supplied
+ */
+ private static String computeCause(String delieveredCause, Throwable e) {
+ String result = delieveredCause;
+ if (delieveredCause == null || delieveredCause.equals("")) {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace( new PrintWriter(sw, true) ); //autoFlush=true
+ result = sw.toString();
+ }
+ return result;
+ }
+
}
1.2 +55 -5
jakarta-slide/src/share/org/apache/slide/macro/ConflictException.java
Index: ConflictException.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ConflictException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConflictException.java 2001/04/06 12:06:48 1.1
+++ ConflictException.java 2001/09/10 16:38:53 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ConflictException.java,v 1.1
2001/04/06 12:06:48 juergen Exp $
- * $Revision: 1.1 $
- * $Date: 2001/04/06 12:06:48 $
+ * $Header:
/home/cvs/jakarta-slide/src/share/org/apache/slide/macro/ConflictException.java,v 1.2
2001/09/10 16:38:53 juergen Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/09/10 16:38:53 $
*
* ====================================================================
*
@@ -63,16 +63,18 @@
package org.apache.slide.macro;
-import org.apache.slide.util.Messages;
-import org.apache.slide.common.SlideException;
+import java.io.StringWriter;
+import java.io.PrintWriter;
+import org.apache.slide.common.SlideException;
+import org.apache.slide.util.Messages;
/**
* The copy/move operation is in conflict, e.g. the path of the destination is not
created (yet).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ConflictException extends SlideException {
@@ -86,11 +88,25 @@
* @param objectUri Uri of the forbidden operation
*/
public ConflictException(String objectUri) {
- super(Messages.format(ConflictException.class.getName(), objectUri), false);
+ this(objectUri, new SlideException("no cause given", false));
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param objectUri Uri of the forbidden operation
+ * @param t Throwable containing the reason
+ */
+ public ConflictException(String objectUri, Throwable t) {
+ super(Messages.format(ConflictException.class.getName(), objectUri,
computeCause(t)), t!=null);
this.objectUri = objectUri;
+ this.nestedException = t;
}
+
+
// ----------------------------------------------------- Instance Variables
@@ -99,7 +115,13 @@
*/
private String objectUri;
+
+ /* hold the cause exception, if supplied */
+ private Throwable nestedException = null;
+
+
+
// ------------------------------------------------------------- Properties
@@ -111,5 +133,33 @@
public String getObjectUri() {
return objectUri;
}
+
+
+
+ /**
+ * computeCause.
+ *
+ * @param e if getMessage is empty the stack trace of e is used
+ */
+ private static String computeCause(Throwable e) {
+ return computeCause(e==null?"":e.getMessage(), e);
+ }
+
+ /**
+ * computeCause.
+ *
+ * @param delieveredCause the cause as a string, if null or empty e is used
+ * @param e the exception stacktrace is shown, if cause is not supplied
+ */
+ private static String computeCause(String delieveredCause, Throwable e) {
+ String result = delieveredCause;
+ if (delieveredCause == null || delieveredCause.equals("")) {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace( new PrintWriter(sw, true) ); //autoFlush=true
+ result = sw.toString();
+ }
+ return result;
+ }
+
}