Coverage Report - org.mule.interceptors.InterceptorStack
 
Classes in this File Line Coverage Branch Coverage Complexity
InterceptorStack
27%
6/22
0%
0/8
1.556
InterceptorStack$Invoc
100%
13/13
75%
3/4
1.556
 
 1  
 /*
 2  
  * $Id: InterceptorStack.java 7963 2007-08-21 08:53:15Z 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.interceptors;
 12  
 
 13  
 import org.mule.umo.Invocation;
 14  
 import org.mule.umo.UMOException;
 15  
 import org.mule.umo.UMOInterceptor;
 16  
 import org.mule.umo.UMOInterceptorStack;
 17  
 import org.mule.umo.UMOMessage;
 18  
 import org.mule.umo.lifecycle.Disposable;
 19  
 import org.mule.umo.lifecycle.Initialisable;
 20  
 import org.mule.umo.lifecycle.InitialisationException;
 21  
 
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * Maintains a list of interceptors that can be applied to components.
 27  
  */
 28  16
 public class InterceptorStack implements UMOInterceptorStack, Initialisable, Disposable
 29  
 {
 30  
 
 31  
     private List interceptors;
 32  
 
 33  
     public InterceptorStack()
 34  
     {
 35  2
         super();
 36  2
     }
 37  
 
 38  
     public InterceptorStack(List interceptors)
 39  0
     {
 40  0
         this.interceptors = interceptors;
 41  0
     }
 42  
 
 43  
     public UMOMessage intercept(Invocation invocation) throws UMOException
 44  
     {
 45  2
         return new Invoc(invocation).execute();
 46  
     }
 47  
 
 48  
     private class Invoc extends Invocation
 49  
     {
 50  2
         private int cursor = 0;
 51  
         private Invocation invocation;
 52  
 
 53  
         public Invoc(Invocation invocation)
 54  2
         {
 55  2
             super(invocation.getDescriptor(), invocation.getMessage(), invocation);
 56  2
             this.invocation = invocation;
 57  2
         }
 58  
 
 59  
         public UMOMessage execute() throws UMOException
 60  
         {
 61  6
             if (interceptors != null && cursor < interceptors.size())
 62  
             {
 63  4
                 UMOInterceptor interceptor = (UMOInterceptor) interceptors.get(cursor);
 64  4
                 cursor++;
 65  4
                 setMessage(interceptor.intercept(this));
 66  4
             }
 67  
             else
 68  
             {
 69  2
                 invocation.setMessage(getMessage());
 70  2
                 setMessage(invocation.execute());
 71  
             }
 72  6
             return getMessage();
 73  
         }
 74  
 
 75  
     }
 76  
 
 77  
     public List getInterceptors()
 78  
     {
 79  0
         return interceptors;
 80  
     }
 81  
 
 82  
     public void setInterceptors(List interceptors)
 83  
     {
 84  2
         this.interceptors = interceptors;
 85  2
     }
 86  
 
 87  
     public void initialise() throws InitialisationException
 88  
     {
 89  0
         for (Iterator it = interceptors.iterator(); it.hasNext();)
 90  
         {
 91  0
             UMOInterceptor interceptor = (UMOInterceptor) it.next();
 92  0
             if (interceptor instanceof Initialisable)
 93  
             {
 94  0
                 ((Initialisable) interceptor).initialise();
 95  
             }
 96  0
         }
 97  0
     }
 98  
 
 99  
     public void dispose()
 100  
     {
 101  0
         for (Iterator it = interceptors.iterator(); it.hasNext();)
 102  
         {
 103  0
             UMOInterceptor interceptor = (UMOInterceptor) it.next();
 104  0
             if (interceptor instanceof Disposable)
 105  
             {
 106  0
                 ((Disposable) interceptor).dispose();
 107  
             }
 108  0
         }
 109  0
     }
 110  
 
 111  
 }