View Javadoc

1   /*
2    * $Id: InterceptorsInvoker.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.impl;
12  
13  import org.mule.umo.Invocation;
14  import org.mule.umo.UMOException;
15  import org.mule.umo.UMOImmutableDescriptor;
16  import org.mule.umo.UMOInterceptor;
17  import org.mule.umo.UMOMessage;
18  
19  import java.util.List;
20  
21  /**
22   * <code>InterceptorsInvoker</code> is used to trigger an interceptor chain.
23   */
24  
25  public class InterceptorsInvoker extends Invocation
26  {
27      private final List interceptors;
28      private int cursor = 0;
29  
30      public InterceptorsInvoker(List interceptors, MuleDescriptor descriptor, UMOMessage message)
31      {
32          this(interceptors, new ImmutableMuleDescriptor(descriptor), message);
33      }
34  
35      public InterceptorsInvoker(List interceptors, UMOImmutableDescriptor descriptor, UMOMessage message)
36      {
37          super(descriptor, message, null);
38          this.interceptors = interceptors;
39      }
40  
41      public UMOMessage execute() throws UMOException
42      {
43          if (cursor < interceptors.size())
44          {
45              UMOInterceptor interceptor = (UMOInterceptor) interceptors.get(cursor);
46              incCursor();
47              return interceptor.intercept(this);
48          }
49          return getMessage();
50      }
51  
52      private synchronized void incCursor()
53      {
54          cursor++;
55      }
56  
57  }