Coverage Report - org.mule.example.errorhandler.AbstractExceptionHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractExceptionHandler
0%
0/29
0%
0/6
1.7
 
 1  
 /*
 2  
  * $Id: AbstractExceptionHandler.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  
 
 11  
 package org.mule.example.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  0
         processException(message, t);
 79  0
     }
 80  
 
 81  
     protected abstract void processException(ErrorMessage message, Throwable t) throws HandlerException;
 82  
 
 83  
     /**
 84  
      * @return Returns the errorManager.
 85  
      */
 86  
     public ErrorManager getErrorManager()
 87  
     {
 88  0
         return errorManager;
 89  
     }
 90  
 
 91  
     /**
 92  
      * @param errorManager The errorManager to set.
 93  
      */
 94  
     public void setErrorManager(ErrorManager errorManager)
 95  
     {
 96  0
         this.errorManager = errorManager;
 97  0
     }
 98  
 
 99  
     /**
 100  
      * @return Returns the endpointName.
 101  
      */
 102  
     public String getendpointName()
 103  
     {
 104  0
         return endpointName;
 105  
     }
 106  
 
 107  
     /**
 108  
      * @param endpointName The endpointName to set.
 109  
      */
 110  
     public void setEndpointName(String endpointName)
 111  
     {
 112  0
         this.endpointName = endpointName;
 113  0
     }
 114  
 
 115  
 }