Coverage Report - org.mule.util.MuleObjectHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleObjectHelper
0%
0/32
0%
0/8
3.75
 
 1  
 /*
 2  
  * $Id: MuleObjectHelper.java 7976 2007-08-21 14:26:13Z 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.util;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.MuleManager;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.impl.endpoint.MuleEndpoint;
 17  
 import org.mule.routing.filters.EqualsFilter;
 18  
 import org.mule.routing.filters.ObjectFilter;
 19  
 import org.mule.routing.filters.WildcardFilter;
 20  
 import org.mule.umo.endpoint.UMOEndpoint;
 21  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 22  
 import org.mule.umo.manager.UMOManager;
 23  
 import org.mule.umo.transformer.UMOTransformer;
 24  
 
 25  
 import java.util.Iterator;
 26  
 import java.util.Map;
 27  
 import java.util.StringTokenizer;
 28  
 
 29  
 /**
 30  
  * <code>MuleObjectHelper</code> is a helper class to assist in finding mule server
 31  
  * objects, such as endpoint and transformers
 32  
  */
 33  
 // @ThreadSafe
 34  
 public final class MuleObjectHelper
 35  
 {
 36  
 
 37  
     /** Do not instanciate. */
 38  
     private MuleObjectHelper ()
 39  0
     {
 40  
         // no-op
 41  0
     }
 42  
 
 43  
     /**
 44  
      * Builds a linked list of UMOTransformers.
 45  
      * 
 46  
      * @param list - a list of transformers separated by "delim"
 47  
      * @param delim - the character used to delimit the transformers in the list
 48  
      * @return an UMOTransformer whose method getNextTransformer() will return the
 49  
      *         next transformer in the list.
 50  
      * @throws MuleException
 51  
      */
 52  
     public static UMOTransformer getTransformer(String list, String delim) throws MuleException
 53  
     {
 54  0
         StringTokenizer st = new StringTokenizer(list, delim);
 55  0
         UMOManager manager = MuleManager.getInstance();
 56  0
         UMOTransformer currentTrans = null;
 57  0
         UMOTransformer returnTrans = null;
 58  
 
 59  0
         while (st.hasMoreTokens())
 60  
         {
 61  0
             String key = st.nextToken().trim();
 62  0
             UMOTransformer tempTrans = manager.lookupTransformer(key);
 63  
 
 64  0
             if (tempTrans == null)
 65  
             {
 66  0
                 throw new MuleException(
 67  
                     CoreMessages.objectNotRegisteredWithManager("Transformer: " + key));
 68  
             }
 69  
 
 70  0
             if (currentTrans == null)
 71  
             {
 72  0
                 currentTrans = tempTrans;
 73  0
                 returnTrans = tempTrans;
 74  
             }
 75  
             else
 76  
             {
 77  0
                 currentTrans.setNextTransformer(tempTrans);
 78  0
                 currentTrans = tempTrans;
 79  
             }
 80  
         }
 81  
 
 82  0
         return returnTrans;
 83  
     }
 84  
 
 85  
     public static UMOEndpoint getEndpointByProtocol(String protocol)
 86  
     {
 87  
         UMOImmutableEndpoint iprovider;
 88  0
         Map endpoints = MuleManager.getInstance().getEndpoints();
 89  0
         for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();)
 90  
         {
 91  0
             iprovider = (UMOImmutableEndpoint) iterator.next();
 92  0
             if (iprovider.getProtocol().equals(protocol))
 93  
             {
 94  0
                 return new MuleEndpoint(iprovider);
 95  
             }
 96  
         }
 97  0
         return null;
 98  
     }
 99  
 
 100  
     public static UMOEndpoint getEndpointByEndpointUri(String endpointUri, boolean wildcardMatch)
 101  
     {
 102  
         ObjectFilter filter;
 103  
 
 104  0
         if (wildcardMatch)
 105  
         {
 106  0
             filter = new WildcardFilter(endpointUri);
 107  
         }
 108  
         else
 109  
         {
 110  0
             filter = new EqualsFilter(endpointUri);
 111  
         }
 112  
 
 113  
         UMOImmutableEndpoint iprovider;
 114  0
         Map endpoints = MuleManager.getInstance().getEndpoints();
 115  
 
 116  0
         for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();)
 117  
         {
 118  0
             iprovider = (UMOImmutableEndpoint) iterator.next();
 119  0
             if (filter.accept(iprovider.getEndpointURI()))
 120  
             {
 121  0
                 return new MuleEndpoint(iprovider);
 122  
             }
 123  
         }
 124  
 
 125  0
         return null;
 126  
     }
 127  
 
 128  
 }