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