Coverage Report - org.mule.api.processor.policy.PolicyInvocation
 
Classes in this File Line Coverage Branch Coverage Complexity
PolicyInvocation
0%
0/20
0%
0/2
0
 
 1  
 /*
 2  
  * $Id: PolicyInvocation.java 20320 2010-11-24 15:03:31Z dfeist $
 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.api.processor.policy;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.processor.MessageProcessor;
 16  
 
 17  
 import java.util.LinkedList;
 18  
 import java.util.List;
 19  
 
 20  
 /**
 21  
  *
 22  
  */
 23  
 public class PolicyInvocation
 24  
 {
 25  
     private MuleEvent event;
 26  0
     private List<AroundPolicy> policies = new LinkedList<AroundPolicy>();
 27  0
     private volatile int currentPolicyIndex = 0;
 28  
     private MessageProcessor messageProcessor;
 29  
 
 30  
     public PolicyInvocation(MuleEvent event, List<AroundPolicy> policies, MessageProcessor processor)
 31  0
     {
 32  0
         this.event = event;
 33  0
         this.policies = policies;
 34  0
         this.messageProcessor = processor;
 35  0
     }
 36  
 
 37  
     /**
 38  
      * Proceed using the current event.
 39  
      *
 40  
      * @see #setEvent(org.mule.api.MuleEvent)
 41  
      */
 42  
     public MuleEvent proceed() throws MuleException
 43  
     {
 44  0
         currentPolicyIndex++;
 45  0
         if (currentPolicyIndex == policies.size())
 46  
         {
 47  
             // end of chain
 48  0
             return messageProcessor.process(event);
 49  
         }
 50  0
         final AroundPolicy currentPolicy = getCurrentPolicy();
 51  0
         final MuleEvent result = currentPolicy.invoke(this);
 52  0
         setEvent(result);
 53  0
         return event;
 54  
     }
 55  
 
 56  
     public MuleEvent getEvent()
 57  
     {
 58  0
         return event;
 59  
     }
 60  
 
 61  
     /**
 62  
      * Replace the event object completely. Note that most of the time it's enough to simply
 63  
      * modify the event without any rewriting.
 64  
      *
 65  
      * @see #getEvent()
 66  
      */
 67  
     public void setEvent(MuleEvent event)
 68  
     {
 69  0
         this.event = event;
 70  0
     }
 71  
 
 72  
     /**
 73  
      * @return policy at the current index in the list
 74  
      */
 75  
     public AroundPolicy getCurrentPolicy()
 76  
     {
 77  0
         return policies.get(currentPolicyIndex);
 78  
     }
 79  
 
 80  
     public MessageProcessor getMessageProcessor()
 81  
     {
 82  0
         return messageProcessor;
 83  
     }
 84  
 
 85  
     public List<AroundPolicy> getPolicies()
 86  
     {
 87  0
         return policies;
 88  
     }
 89  
 }