Coverage Report - org.mule.model.resolvers.DefaultEntryPointResolverSet
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultEntryPointResolverSet
0%
0/24
0%
0/6
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.model.resolvers;
 8  
 
 9  
 import org.mule.api.MuleEventContext;
 10  
 import org.mule.api.model.EntryPointResolver;
 11  
 import org.mule.api.model.EntryPointResolverSet;
 12  
 import org.mule.api.model.InvocationResult;
 13  
 import org.mule.util.CollectionUtils;
 14  
 
 15  
 import java.util.HashSet;
 16  
 import java.util.LinkedHashSet;
 17  
 import java.util.Set;
 18  
 
 19  
 /**
 20  
  * Provides the default implementation of an {@link org.mule.api.model.EntryPointResolverSet}
 21  
  * It resolves a method to call on the given service when an event is received.
 22  
  * This object maintains a set of Resolvers that will be used in order to resolve
 23  
  * an entrypoint on a service object until one is found or until the set is
 24  
  * exhausted.
 25  
  */
 26  0
 public class DefaultEntryPointResolverSet implements EntryPointResolverSet
 27  
 {
 28  0
     private final Set<EntryPointResolver> entryPointResolvers = new LinkedHashSet<EntryPointResolver>(4);
 29  
 
 30  
     public Object invoke(Object component, MuleEventContext context) throws Exception
 31  
     {
 32  0
         Set<String> exceptions = new HashSet<String>();
 33  
 
 34  0
         for (EntryPointResolver resolver : entryPointResolvers)
 35  
         {
 36  0
             InvocationResult result = resolver.invoke(component, context);
 37  0
             if (result.getState() == InvocationResult.State.SUCCESSFUL)
 38  
             {
 39  0
                 return result.getResult();
 40  
             }
 41  
             else
 42  
             {
 43  0
                 if (result.hasError())
 44  
                 {
 45  0
                     exceptions.add(result.getErrorMessage());
 46  
                 }
 47  
             }
 48  0
         }
 49  0
         throw new EntryPointNotFoundException(CollectionUtils.toString(exceptions, true));
 50  
     }
 51  
 
 52  
     /**
 53  
      * @return the entry point resolves configured in this resolver set. Note that access to the
 54  
      * set is not thread safe. Client code must take proper precautions to synchronize.
 55  
      */
 56  
     public Set<EntryPointResolver> getEntryPointResolvers()
 57  
     {
 58  0
         return entryPointResolvers;
 59  
     }
 60  
 
 61  
     public void setEntryPointResolvers(Set<EntryPointResolver> entryPointResolvers)
 62  
     {
 63  0
         synchronized (this.entryPointResolvers)
 64  
         {
 65  0
             this.entryPointResolvers.clear();
 66  0
             this.entryPointResolvers.addAll(entryPointResolvers);
 67  0
         }
 68  0
     }
 69  
 
 70  
     public void addEntryPointResolver(EntryPointResolver resolver)
 71  
     {
 72  0
         synchronized (entryPointResolvers)
 73  
         {
 74  0
             this.entryPointResolvers.add(resolver);
 75  0
         }
 76  0
     }
 77  
 
 78  
     public boolean removeEntryPointResolver(EntryPointResolver resolver)
 79  
     {
 80  0
         synchronized (entryPointResolvers)
 81  
         {
 82  0
             return this.entryPointResolvers.remove(resolver);
 83  0
         }
 84  
     }
 85  
 }