KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > MuleObjectHelper


1 /*
2  * $Id: MuleObjectHelper.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
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 /**
31  * <code>MuleObjectHelper</code> is a helper class to assist in finding mule server
32  * objects, such as endpoint and transformers
33  */

34 // @ThreadSafe
35
public class MuleObjectHelper
36 {
37
38     /**
39      * Builds a linked list of UMOTransformers.
40      *
41      * @param list - a list of transformers separated by "delim"
42      * @param delim - the character used to delimit the transformers in the list
43      * @return an UMOTransformer whose method getNextTransformer() will return the
44      * next transformer in the list.
45      * @throws MuleException
46      */

47     public static UMOTransformer getTransformer(String JavaDoc list, String JavaDoc delim) throws MuleException
48     {
49         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(list, delim);
50         UMOManager manager = MuleManager.getInstance();
51         UMOTransformer currentTrans = null;
52         UMOTransformer returnTrans = null;
53
54         while (st.hasMoreTokens())
55         {
56             String JavaDoc 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 JavaDoc protocol)
81     {
82         UMOImmutableEndpoint iprovider;
83         Map JavaDoc endpoints = MuleManager.getInstance().getEndpoints();
84         for (Iterator JavaDoc 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 JavaDoc 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 JavaDoc endpoints = MuleManager.getInstance().getEndpoints();
110
111         for (Iterator JavaDoc 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