1 10 11 package org.mule.util; 12 13 import java.util.Iterator ; 14 import java.util.Map ; 15 import java.util.StringTokenizer ; 16 17 import org.mule.MuleException; 18 import org.mule.MuleManager; 19 import org.mule.config.i18n.Message; 20 import org.mule.config.i18n.Messages; 21 import org.mule.impl.endpoint.MuleEndpoint; 22 import org.mule.routing.filters.EqualsFilter; 23 import org.mule.routing.filters.ObjectFilter; 24 import org.mule.routing.filters.WildcardFilter; 25 import org.mule.umo.endpoint.UMOEndpoint; 26 import org.mule.umo.endpoint.UMOImmutableEndpoint; 27 import org.mule.umo.manager.UMOManager; 28 import org.mule.umo.transformer.UMOTransformer; 29 30 34 public class MuleObjectHelper 36 { 37 38 47 public static UMOTransformer getTransformer(String list, String delim) throws MuleException 48 { 49 StringTokenizer st = new StringTokenizer (list, delim); 50 UMOManager manager = MuleManager.getInstance(); 51 UMOTransformer currentTrans = null; 52 UMOTransformer returnTrans = null; 53 54 while (st.hasMoreTokens()) 55 { 56 String key = st.nextToken().trim(); 57 UMOTransformer tempTrans = manager.lookupTransformer(key); 58 59 if (tempTrans == null) 60 { 61 throw new MuleException(new Message(Messages.X_NOT_REGISTERED_WITH_MANAGER, "Transformer: " 62 + key)); 63 } 64 65 if (currentTrans == null) 66 { 67 currentTrans = tempTrans; 68 returnTrans = tempTrans; 69 } 70 else 71 { 72 currentTrans.setNextTransformer(tempTrans); 73 currentTrans = tempTrans; 74 } 75 } 76 77 return returnTrans; 78 } 79 80 public static UMOEndpoint getEndpointByProtocol(String protocol) 81 { 82 UMOImmutableEndpoint iprovider; 83 Map endpoints = MuleManager.getInstance().getEndpoints(); 84 for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) 85 { 86 iprovider = (UMOImmutableEndpoint)iterator.next(); 87 if (iprovider.getProtocol().equals(protocol)) 88 { 89 return new MuleEndpoint(iprovider); 90 } 91 } 92 return null; 93 } 94 95 public static UMOEndpoint getEndpointByEndpointUri(String endpointUri, boolean wildcardMatch) 96 { 97 ObjectFilter filter; 98 99 if (wildcardMatch) 100 { 101 filter = new WildcardFilter(endpointUri); 102 } 103 else 104 { 105 filter = new EqualsFilter(endpointUri); 106 } 107 108 UMOImmutableEndpoint iprovider; 109 Map endpoints = MuleManager.getInstance().getEndpoints(); 110 111 for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) 112 { 113 iprovider = (UMOImmutableEndpoint)iterator.next(); 114 if (filter.accept(iprovider.getEndpointURI())) 115 { 116 return new MuleEndpoint(iprovider); 117 } 118 } 119 120 return null; 121 } 122 123 } 124 | Popular Tags |