Coverage Report - org.mule.samples.errorhandler.AbstractExceptionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractExceptionHandler
0%
0/29
0%
0/3
1.7
 
 1  
 /*
 2  
  * $Id: AbstractExceptionHandler.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
 
 11  
 package org.mule.samples.errorhandler;
 12  
 
 13  
 import java.util.HashMap;
 14  
 import java.util.Iterator;
 15  
 
 16  
 /**
 17  
  * <code>AbstractExceptionListener</code> TODO (document class)
 18  
  * 
 19  
  */
 20  0
 public abstract class AbstractExceptionHandler implements ExceptionHandler
 21  
 {
 22  
 
 23  0
     protected HashMap registry = new HashMap();
 24  
 
 25  
     private String endpointName;
 26  
 
 27  0
     protected ErrorManager errorManager = null;
 28  
 
 29  
     public void registerException(Class exceptionClass)
 30  
     {
 31  
 
 32  0
         registry.put(exceptionClass, exceptionClass);
 33  
 
 34  0
     }
 35  
 
 36  
     public Iterator getRegisteredClasses()
 37  
     {
 38  0
         return registry.keySet().iterator();
 39  
     }
 40  
 
 41  
     public void unRegisterException(Class exceptionClass)
 42  
     {
 43  0
         registry.remove(exceptionClass);
 44  
 
 45  0
     }
 46  
 
 47  
     public boolean isRegisteredFor(Class exceptionClass)
 48  
     {
 49  0
         Class aClass = null;
 50  0
         for (Iterator i = getRegisteredClasses(); i.hasNext();)
 51  
         {
 52  0
             aClass = (Class)i.next();
 53  0
             if (aClass.isAssignableFrom(exceptionClass))
 54  
             {
 55  0
                 return true;
 56  
             }
 57  
         }
 58  0
         return false;
 59  
     }
 60  
 
 61  
     public void onException(ErrorMessage message) throws HandlerException
 62  
     {
 63  0
         Throwable t = null;
 64  
 
 65  
         try
 66  
         {
 67  0
             t = message.getException().toException();
 68  
         }
 69  0
         catch (Exception e)
 70  
         {
 71  0
             throw new HandlerException(LocaleMessage.unretrievedException(e), e);
 72  0
         }
 73  
 
 74  0
         if (!isRegisteredFor(t.getClass()))
 75  
         {
 76  0
             throw new HandlerException(LocaleMessage.unhandledException(t.getClass(), this.getClass()));
 77  
 
 78  
         }
 79  0
         processException(message, t);
 80  0
     }
 81  
 
 82  
     protected abstract void processException(ErrorMessage message, Throwable t) throws HandlerException;
 83  
 
 84  
     /**
 85  
      * @return Returns the errorManager.
 86  
      */
 87  
     public ErrorManager getErrorManager()
 88  
     {
 89  0
         return errorManager;
 90  
     }
 91  
 
 92  
     /**
 93  
      * @param errorManager The errorManager to set.
 94  
      */
 95  
     public void setErrorManager(ErrorManager errorManager)
 96  
     {
 97  0
         this.errorManager = errorManager;
 98  0
     }
 99  
 
 100  
     /**
 101  
      * @return Returns the endpointName.
 102  
      */
 103  
     public String getendpointName()
 104  
     {
 105  0
         return endpointName;
 106  
     }
 107  
 
 108  
     /**
 109  
      * @param endpointName The endpointName to set.
 110  
      */
 111  
     public void setEndpointName(String endpointName)
 112  
     {
 113  0
         this.endpointName = endpointName;
 114  0
     }
 115  
 
 116  
 }