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