Coverage Report - org.mule.api.processor.policy.Policies
 
Classes in this File Line Coverage Branch Coverage Complexity
Policies
0%
0/18
0%
0/4
0
 
 1  
 /*
 2  
  * $Id: Policies.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.processor.MessageProcessorChain;
 14  
 import org.mule.util.CollectionUtils;
 15  
 
 16  
 import java.util.Collections;
 17  
 import java.util.LinkedList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate;
 21  
 
 22  
 public class Policies
 23  
 {
 24  
 
 25  
     private final MessageProcessorChain messageProcessorChain;
 26  0
     private LinkedList<AroundPolicy> policies = new LinkedList<AroundPolicy>();
 27  
 
 28  
     public Policies(MessageProcessorChain messageProcessorChain)
 29  0
     {
 30  0
         this.messageProcessorChain = messageProcessorChain;
 31  0
     }
 32  
 
 33  
     public void add(AroundPolicy policy)
 34  
     {
 35  
         // TODO concurrency
 36  0
         if (find(policy.getName()) != null)
 37  
         {
 38  0
             final String msg = String.format("There's already a policy registered under name [%s] for chain [%s]:%s",
 39  
                                              policy.getName(), messageProcessorChain.getName(), messageProcessorChain);
 40  0
             throw new IllegalArgumentException(msg);
 41  
         }
 42  0
         this.policies.add(policy);
 43  0
     }
 44  
 
 45  
     public AroundPolicy remove(String policyName)
 46  
     {
 47  
         // TODO concurrency
 48  0
         final AroundPolicy policy = find(policyName);
 49  0
         if (policy == null)
 50  
         {
 51  0
             return null;
 52  
         }
 53  0
         this.policies.remove(policy);
 54  
 
 55  0
         return policy;
 56  
     }
 57  
 
 58  
     public List<AroundPolicy> list()
 59  
     {
 60  
         // TODO concurrency
 61  0
         return Collections.unmodifiableList(this.policies);
 62  
     }
 63  
 
 64  
     public void clear()
 65  
     {
 66  
         // TODO concurrency
 67  0
         this.policies.clear();
 68  0
     }
 69  
 
 70  
     /**
 71  
      * @return policy with that name or null if not found
 72  
      */
 73  
     public AroundPolicy find(String policyName)
 74  
     {
 75  
         // TODO concurrency
 76  
         // find { policy.name == policyName }
 77  0
         return (AroundPolicy) CollectionUtils.find(this.policies,
 78  
                                                    new BeanPropertyValueEqualsPredicate("name", policyName));
 79  
     }
 80  
 }