Coverage Report - org.mule.interceptor.InterceptorStack
 
Classes in this File Line Coverage Branch Coverage Complexity
InterceptorStack
0%
0/37
0%
0/24
0
 
 1  
 /*
 2  
  * $Id: InterceptorStack.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.interceptor;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.interceptor.Interceptor;
 16  
 import org.mule.api.lifecycle.Disposable;
 17  
 import org.mule.api.lifecycle.Initialisable;
 18  
 import org.mule.api.lifecycle.InitialisationException;
 19  
 import org.mule.api.processor.MessageProcessor;
 20  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 21  
 import org.mule.processor.builder.InterceptingChainMessageProcessorBuilder;
 22  
 
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * Maintains a list of interceptors that can be applied to components.
 27  
  */
 28  
 public class InterceptorStack extends AbstractInterceptingMessageProcessor
 29  
     implements Interceptor, Initialisable, Disposable
 30  
 {
 31  
 
 32  
     private List<Interceptor> interceptors;
 33  
     private MessageProcessor chain;
 34  
 
 35  
     public InterceptorStack()
 36  0
     {
 37  
         // For spring
 38  0
     }
 39  
 
 40  
     public InterceptorStack(List<Interceptor> interceptors)
 41  0
     {
 42  0
         this.interceptors = interceptors;
 43  0
     }
 44  
 
 45  
     public MuleEvent process(MuleEvent event) throws MuleException
 46  
     {
 47  0
         return chain.process(event);
 48  
     }
 49  
 
 50  
     public List<Interceptor> getInterceptors()
 51  
     {
 52  0
         return interceptors;
 53  
     }
 54  
 
 55  
     public void setInterceptors(List<Interceptor> interceptors)
 56  
     {
 57  0
         this.interceptors = interceptors;
 58  0
     }
 59  
 
 60  
     public void initialise() throws InitialisationException
 61  
     {
 62  0
         InterceptingChainMessageProcessorBuilder chainBuilder = new InterceptingChainMessageProcessorBuilder();
 63  0
         for (Interceptor interceptor : interceptors)
 64  
         {
 65  0
             if (interceptor instanceof Initialisable)
 66  
             {
 67  0
                 ((Initialisable) interceptor).initialise();
 68  
             }
 69  0
             chainBuilder.chain(interceptor);
 70  
         }
 71  0
         if (next != null)
 72  
         {
 73  0
             chainBuilder.chain(next);
 74  
         }
 75  
         try
 76  
         {
 77  0
             chain = chainBuilder.build();
 78  
         }
 79  0
         catch (MuleException e)
 80  
         {
 81  0
             throw new InitialisationException(e, this);
 82  0
         }
 83  0
     }
 84  
 
 85  
     public void dispose()
 86  
     {
 87  0
         for (Interceptor interceptor : interceptors)
 88  
         {
 89  0
             if (interceptor instanceof Disposable)
 90  
             {
 91  0
                 ((Disposable) interceptor).dispose();
 92  
             }
 93  
         }
 94  0
     }
 95  
 
 96  
     @Override
 97  
     public int hashCode()
 98  
     {
 99  0
         final int prime = 31;
 100  0
         int result = 1;
 101  0
         result = prime * result + ((interceptors == null) ? 0 : interceptors.hashCode());
 102  0
         return result;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public boolean equals(Object obj)
 107  
     {
 108  0
         if (this == obj) return true;
 109  0
         if (obj == null) return false;
 110  0
         if (getClass() != obj.getClass()) return false;
 111  0
         InterceptorStack other = (InterceptorStack) obj;
 112  0
         if (interceptors == null)
 113  
         {
 114  0
             if (other.interceptors != null) return false;
 115  
         }
 116  0
         else if (!interceptors.equals(other.interceptors)) return false;
 117  0
         return true;
 118  
     }
 119  
 
 120  
 }