View Javadoc

1   /* $Id: MultiplexorException.java,v 1.1 2004/03/17 21:18:40 johndavidtaylor Exp $
2    * Created on Mar 13, 2004 by jdt
3    * The alipes project
4    * (c) 2004 
5    *
6    */
7   package org.abraracourcix.alipes.pipes;
8   
9   import java.util.ArrayList;
10  import java.util.Collection;
11  import java.util.Iterator;
12  
13  import org.abraracourcix.alipes.listeners.ListenerException;
14  
15  /***
16   * Can occur if one or more of the multiplexor's listeners throw an exception.
17   * Since any or all of the multiplexor's listeners can throw exceptions during
18   * multiplexing this exception bundles them all up into one.
19   * 
20   * @author jdt
21   */
22  public class MultiplexorException extends ListenerException {
23      /***
24       * Underlying exceptions bundled in.
25       */
26      private Collection causes = new ArrayList();
27      /***
28       * Constructor
29       * @param cause root cause
30       */
31      public MultiplexorException(final Throwable cause) {
32          super(cause);
33          causes.add(cause);
34      }
35      /***
36       * Constructor
37       * @param description Description of error
38       * @param cause root cause
39       */
40      public MultiplexorException(final String description, final Throwable cause) {
41          super(description, cause);
42          causes.add(cause);
43      }
44      
45      /***
46       * Add a new exception
47       * @param cause yet another cause
48       */
49      public final void addCause(final Throwable cause) {
50          causes.add(cause);
51      }
52      /***
53       * Override to append all enclosed exceptions
54       * @return see below
55       * @see java.lang.Throwable#getMessage()
56       */
57      public final String getMessage() {
58          final StringBuffer buff = new StringBuffer(super.getMessage()+":\n");
59          final Iterator it = causes.iterator();
60          while (it.hasNext()) {
61              final Throwable ex = (Throwable) it.next();
62              buff.append(ex.getMessage()+"\n");
63          }
64          return buff.toString();
65      }
66  }
67  
68  
69  /*
70   *  $Log: MultiplexorException.java,v $
71   *  Revision 1.1  2004/03/17 21:18:40  johndavidtaylor
72   *  Copied across from incubation in beanpeeler
73   *
74   *  Revision 1.1  2004/03/14 00:44:22  johndavidtaylor
75   *  Added ListenerException
76   *
77   */