vgritsenko 2003/02/02 15:26:51
Modified: src/java/org/apache/cocoon/components/notification
DefaultNotifyingBuilder.java
Log:
Align code. Use those constants. Use addExtraDescriptions instead of
replaceExtraDescriptions
Revision Changes Path
1.12 +151 -147
xml-cocoon2/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java
Index: DefaultNotifyingBuilder.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/notification/DefaultNotifyingBuilder.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DefaultNotifyingBuilder.java 31 Jan 2003 22:51:30 -0000 1.11
+++ DefaultNotifyingBuilder.java 2 Feb 2003 23:26:51 -0000 1.12
@@ -73,159 +73,163 @@
*/
public class DefaultNotifyingBuilder implements NotifyingBuilder, Component {
- /** Builds a Notifying object (SimpleNotifyingBean in this case)
- * that tries to explain what the Object o can reveal.
- * @param sender who sent this Object.
- * @param o the object to use when building the SimpleNotifyingBean
- * @return the Notifying Object that was build
- * @see org.apache.cocoon.components.notification.Notifying
- */
- public Notifying build (Object sender, Object o) {
- if (o instanceof Notifying) {
- return (Notifying) o;
- } else if (o instanceof Throwable) {
- Throwable t = (Throwable) o;
- SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
- n.setType("error");
- n.setTitle("An error occurred");
- if (t != null) {
-
- n.setSource(t.getClass().getName());
-
- Throwable rootCauseThrowable = getRootCause(t);
- n.addExtraDescription("original message", rootCauseThrowable.toString());
-
- if (rootCauseThrowable instanceof SAXParseException) {
-
- SAXParseException saxParseException = (SAXParseException)
rootCauseThrowable;
- n.setMessage (
saxParseException.getMessage() );
- n.addExtraDescription("location",
String.valueOf(saxParseException.getSystemId()) );
- n.addExtraDescription("line" ,
String.valueOf(saxParseException.getLineNumber()) );
- n.addExtraDescription("column" ,
String.valueOf(saxParseException.getColumnNumber()));
- } else if (rootCauseThrowable instanceof TransformerException) {
- TransformerException transformerException = (TransformerException)
rootCauseThrowable;
- SourceLocator sourceLocator = transformerException.getLocator();
- n.setMessage (
transformerException.getMessage());
-
- if( null != sourceLocator )
- {
- n.addExtraDescription("location",
String.valueOf(sourceLocator.getSystemId()) );
- n.addExtraDescription("line" ,
String.valueOf(sourceLocator.getLineNumber()) );
- n.addExtraDescription("column" ,
String.valueOf(sourceLocator.getColumnNumber()) );
+ /**
+ * Builds a Notifying object (SimpleNotifyingBean in this case)
+ * that tries to explain what the Object o can reveal.
+ * @param sender who sent this Object.
+ * @param o the object to use when building the SimpleNotifyingBean
+ * @return the Notifying Object that was build
+ * @see org.apache.cocoon.components.notification.Notifying
+ */
+ public Notifying build (Object sender, Object o) {
+ if (o instanceof Notifying) {
+ return (Notifying) o;
+ } else if (o instanceof Throwable) {
+ Throwable t = (Throwable) o;
+ SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
+ n.setType(Notifying.ERROR_NOTIFICATION);
+ n.setTitle("An error occurred");
+ if (t != null) {
+ n.setSource(t.getClass().getName());
+
+ Throwable rootCauseThrowable = getRootCause(t);
+ n.addExtraDescription(Notifying.EXTRA_CAUSE,
rootCauseThrowable.toString());
+
+ if (rootCauseThrowable instanceof SAXParseException) {
+ SAXParseException saxParseException = (SAXParseException)
rootCauseThrowable;
+ n.setMessage (
saxParseException.getMessage() );
+ n.addExtraDescription(Notifying.EXTRA_LOCATION,
+
String.valueOf(saxParseException.getSystemId()));
+ n.addExtraDescription(Notifying.EXTRA_LINE,
+
String.valueOf(saxParseException.getLineNumber()));
+ n.addExtraDescription(Notifying.EXTRA_COLUMN,
+
String.valueOf(saxParseException.getColumnNumber()));
+ } else if (rootCauseThrowable instanceof TransformerException) {
+ TransformerException transformerException =
(TransformerException) rootCauseThrowable;
+ SourceLocator sourceLocator = transformerException.getLocator();
+ n.setMessage (
transformerException.getMessage() );
+
+ if (null != sourceLocator) {
+ n.addExtraDescription(Notifying.EXTRA_LOCATION,
+
String.valueOf(sourceLocator.getSystemId()));
+ n.addExtraDescription(Notifying.EXTRA_LINE,
+
String.valueOf(sourceLocator.getLineNumber()));
+ n.addExtraDescription(Notifying.EXTRA_COLUMN,
+
String.valueOf(sourceLocator.getColumnNumber()));
+ }
+ } else {
+ n.setMessage(t.getMessage());
+ }
+
+ n.setDescription(t.toString());
+
+ // Get the stacktrace: if the exception is a SAXException,
+ // the stacktrace of the embedded exception is used as the
+ // SAXException does not append it automatically
+ Throwable stackTraceException;
+ if (t instanceof SAXException && ((SAXException) t).getException()
!= null) {
+ stackTraceException = ((SAXException) t).getException();
+ } else {
+ stackTraceException = t;
+ }
+ // org.apache.avalon.framework.ExceptionUtil.captureStackTrace();
+ StringWriter sw = new StringWriter();
+ stackTraceException.printStackTrace(new PrintWriter(sw));
+ n.addExtraDescription(Notifying.EXTRA_STACKTRACE, sw.toString());
+ // Add nested throwables description
+ sw = new StringWriter();
+ appendCauses(new PrintWriter(sw), stackTraceException);
+ String causes = sw.toString();
+ if (causes != null && causes.length() != 0) {
+ n.addExtraDescription(Notifying.EXTRA_FULLTRACE, causes);
+ }
}
+ return n;
} else {
- n.setMessage(t.getMessage());
+ SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
+ n.setType(Notifying.UNKNOWN_NOTIFICATION);
+ n.setTitle("Object notification");
+ n.setSource(o.getClass().getName());
+ n.setMessage(o.toString());
+ n.setDescription("No details available.");
+ return n;
}
-
- n.setDescription(t.toString());
-
- // get the stacktrace: if the exception is a SAXException,
- // the stacktrace of the embedded exception is used as the
- // SAXException does not append it automatically
- Throwable stackTraceException;
- if (t instanceof SAXException && ((SAXException) t).getException() != null)
{
- stackTraceException = ((SAXException) t).getException();
- } else {
- stackTraceException = t;
- }
- //org.apache.avalon.framework.ExceptionUtil.captureStackTrace();
- StringWriter sw = new StringWriter();
- stackTraceException.printStackTrace(new PrintWriter(sw));
- n.addExtraDescription("stacktrace", sw.toString());
- // Add nested throwables description
- sw = new StringWriter();
- appendCauses(new PrintWriter(sw), stackTraceException);
- String causes = sw.toString();
- if (causes != null && causes.length() != 0) {
- n.addExtraDescription("full exception chain stacktrace", causes);
- }
- }
- return n;
- } else {
- SimpleNotifyingBean n = new SimpleNotifyingBean(sender);
- n.setType("unknown");
- n.setTitle("Object notification");
- n.setSource(o.getClass().getName());
- n.setMessage(o.toString());
- n.setDescription("No details available.");
- return n;
}
- }
- /** Builds a Notifying object (SimpleNotifyingBean in this case)
- * that explains a notification.
- * @param sender who sent this Object.
- * @param o the object to use when building the SimpleNotifyingBean
- * @param type see the Notifying apidocs
- * @param title see the Notifying apidocs
- * @param source see the Notifying apidocs
- * @param message see the Notifying apidocs
- * @param description see the Notifying apidocs
- * @param extra see the Notifying apidocs
- * @return the Notifying Object that was build
- * @see org.apache.cocoon.components.notification.Notifying
- */
- public Notifying build(Object sender, Object o, String type, String title,
- String source, String message, String description, Map extra) {
- //NKB Cast here is secure, the method is of this class
- SimpleNotifyingBean n = (SimpleNotifyingBean) build (sender, o);
-
- if (type != null)
- n.setType(type);
- if (title != null)
- n.setTitle(title);
- if (source != null)
- n.setSource(source);
- if (message != null)
- n.setMessage(message);
- if (description != null)
- n.setDescription(description);
- if (extra != null)
- n.replaceExtraDescriptions(extra);
-
- return n;
- }
-
-
- /**
- * Print recursively all nested causes of a Throwable in a PrintWriter.
- */
- private static void appendCauses (PrintWriter out, Throwable t) {
- Throwable cause = null;
- if (t instanceof CascadingThrowable) {
- cause = ((CascadingThrowable) t).getCause();
- } else if (t instanceof SAXException) {
- cause = ((SAXException) t).getException();
- } else if (t instanceof java.sql.SQLException) {
- cause = ((java.sql.SQLException) t).getNextException();
- }
- if (cause != null) {
- out.print("Original exception : ");
- cause.printStackTrace(out);
- out.println();
- // Recurse
- appendCauses(out, cause);
+ /**
+ * Builds a Notifying object (SimpleNotifyingBean in this case)
+ * that explains a notification.
+ * @param sender who sent this Object.
+ * @param o the object to use when building the SimpleNotifyingBean
+ * @param type see the Notifying apidocs
+ * @param title see the Notifying apidocs
+ * @param source see the Notifying apidocs
+ * @param message see the Notifying apidocs
+ * @param description see the Notifying apidocs
+ * @param extra see the Notifying apidocs
+ * @return the Notifying Object that was build
+ * @see org.apache.cocoon.components.notification.Notifying
+ */
+ public Notifying build(Object sender, Object o, String type, String title,
+ String source, String message, String description, Map
extra) {
+ // NKB Cast here is secure, the method is of this class
+ SimpleNotifyingBean n = (SimpleNotifyingBean) build (sender, o);
+
+ if (type != null)
+ n.setType(type);
+ if (title != null)
+ n.setTitle(title);
+ if (source != null)
+ n.setSource(source);
+ if (message != null)
+ n.setMessage(message);
+ if (description != null)
+ n.setDescription(description);
+ if (extra != null)
+ n.addExtraDescriptions(extra);
+
+ return n;
}
- }
- /**
- * Get root Exception.
- */
- public static Throwable getRootCause (Throwable t) {
- Throwable cause = null;
- if (t instanceof CascadingThrowable) {
- cause = ((CascadingThrowable) t).getCause();
- } else if (t instanceof SAXException) {
- cause = ((SAXException) t).getException();
- } else if (t instanceof java.sql.SQLException) {
- cause = ((java.sql.SQLException) t).getNextException();
+
+ /**
+ * Print recursively all nested causes of a Throwable in a PrintWriter.
+ */
+ private static void appendCauses (PrintWriter out, Throwable t) {
+ Throwable cause = null;
+ if (t instanceof CascadingThrowable) {
+ cause = ((CascadingThrowable) t).getCause();
+ } else if (t instanceof SAXException) {
+ cause = ((SAXException) t).getException();
+ } else if (t instanceof java.sql.SQLException) {
+ cause = ((java.sql.SQLException) t).getNextException();
+ }
+ if (cause != null) {
+ out.print("Original exception : ");
+ cause.printStackTrace(out);
+ out.println();
+ // Recurse
+ appendCauses(out, cause);
+ }
}
- if (cause == null) {
- return t;
- } else {
- // Recurse
- return getRootCause(cause);
+
+ /**
+ * Get root Exception.
+ */
+ public static Throwable getRootCause (Throwable t) {
+ Throwable cause = null;
+ if (t instanceof CascadingThrowable) {
+ cause = ((CascadingThrowable) t).getCause();
+ } else if (t instanceof SAXException) {
+ cause = ((SAXException) t).getException();
+ } else if (t instanceof java.sql.SQLException) {
+ cause = ((java.sql.SQLException) t).getNextException();
+ }
+ if (cause == null) {
+ return t;
+ } else {
+ // Recurse
+ return getRootCause(cause);
+ }
}
- }
}
-
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]