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