View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util;
8   
9   import java.beans.ExceptionListener;
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  import org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  
16  /** TODO */
17  public class ExceptionHolder implements ExceptionListener
18  {
19      protected final Log logger = LogFactory.getLog(getClass());
20      private List<Exception> exceptions = new ArrayList<Exception>(2);
21  
22      public void exceptionThrown(Exception e)
23      {
24          exceptions.add(e);
25      }
26  
27      public List getExceptions()
28      {
29          return exceptions;
30      }
31  
32      public boolean isExceptionThrown()
33      {
34          return exceptions.size() > 0;
35      }
36  
37      public void clear()
38      {
39          exceptions.clear();
40      }
41  
42      public void print()
43      {
44          for (Exception exception : exceptions)
45          {
46              logger.error(exception);
47          }
48      }
49  }