View Javadoc

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