Coverage Report - org.mule.model.resolvers.DefaultEntryPointResolverSet
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultEntryPointResolverSet
78%
18/23
83%
5/6
2
 
 1  
 /*
 2  
  * $Id: DefaultEntryPointResolverSet.java 10529 2008-01-25 05:58:36Z dfeist $
 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  
 package org.mule.model.resolvers;
 11  
 
 12  
 import org.mule.api.MuleEventContext;
 13  
 import org.mule.api.model.EntryPointResolver;
 14  
 import org.mule.api.model.EntryPointResolverSet;
 15  
 import org.mule.api.model.InvocationResult;
 16  
 import org.mule.util.CollectionUtils;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.LinkedHashSet;
 20  
 import java.util.List;
 21  
 import java.util.Set;
 22  
 
 23  
 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * Provides the default implementation of an {@link org.mule.api.model.EntryPointResolverSet}
 30  
  * It resolves a method to call on the given service when an event is received.
 31  
  * This object maintains a set of Resolvers that will be used in order to resolve
 32  
  * an entrypoint on a service object until one is found or until the set is
 33  
  * exhausted.
 34  
  */
 35  68
 public class DefaultEntryPointResolverSet implements EntryPointResolverSet
 36  
 {
 37  
 
 38  68
     protected final Log logger = LogFactory.getLog(getClass());
 39  
 
 40  68
     private final Set entryPointResolvers = new LinkedHashSet(4);
 41  68
     private List exceptions = new CopyOnWriteArrayList();
 42  
 
 43  
     public Object invoke(Object component, MuleEventContext context) throws Exception
 44  
     {
 45  
         try
 46  
         {
 47  24
             for (Iterator iterator = entryPointResolvers.iterator(); iterator.hasNext();)
 48  
             {
 49  80
                 EntryPointResolver resolver = (EntryPointResolver) iterator.next();
 50  80
                 InvocationResult result = resolver.invoke(component, context);
 51  80
                 if (result.getState() == InvocationResult.STATE_INVOKED_SUCESSFUL)
 52  
                 {
 53  18
                     return result.getResult();
 54  
                 }
 55  
                 else
 56  
                 {
 57  62
                     if (result.hasError())
 58  
                     {
 59  62
                         exceptions.add(result.getErrorMessage());
 60  
                     }
 61  
                 }
 62  62
             }
 63  6
             throw new EntryPointNotFoundException(CollectionUtils.toString(exceptions, true));
 64  
         }
 65  
         finally
 66  
         {
 67  24
             exceptions.clear();
 68  
         }
 69  
 
 70  
     }
 71  
 
 72  
     public Set getEntryPointResolvers()
 73  
     {
 74  0
         return entryPointResolvers;
 75  
     }
 76  
 
 77  
     public void setEntryPointResolvers(Set entryPointResolvers)
 78  
     {
 79  0
         this.entryPointResolvers.clear();
 80  0
         this.entryPointResolvers.addAll(entryPointResolvers);
 81  0
     }
 82  
 
 83  
     public void addEntryPointResolver(EntryPointResolver resolver)
 84  
     {
 85  274
         synchronized (entryPointResolvers)
 86  
         {
 87  274
             this.entryPointResolvers.add(resolver);
 88  274
         }
 89  274
     }
 90  
 
 91  
     public boolean removeEntryPointResolver(EntryPointResolver resolver)
 92  
     {
 93  0
         return this.entryPointResolvers.remove(resolver);
 94  
     }
 95  
 }