KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > converters > EndpointURIConverter


1 /*
2  * $Id: EndpointURIConverter.java 3937 2006-11-20 16:04:25Z lajos $
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.config.converters;
12
13 import org.apache.commons.beanutils.ConversionException;
14 import org.apache.commons.beanutils.Converter;
15 import org.mule.MuleManager;
16 import org.mule.impl.endpoint.MuleEndpointURI;
17 import org.mule.umo.endpoint.UMOEndpointURI;
18 import org.mule.umo.manager.UMOManager;
19 import org.mule.util.XMLEntityCodec;
20
21 /**
22  * <code>EndpointURIConverter</code> TODO
23  */

24 public class EndpointURIConverter implements Converter
25 {
26
27     /**
28      * Convert the specified input object into an output object of the specified
29      * type.
30      *
31      * @param type Data type to which this value should be converted
32      * @param value The input value to be converted
33      * @throws org.apache.commons.beanutils.ConversionException if conversion cannot
34      * be performed successfully
35      */

36     public Object JavaDoc convert(Class JavaDoc type, Object JavaDoc value)
37     {
38         if (value == null)
39         {
40             throw new ConversionException("No value specified");
41         }
42
43         if (value instanceof UMOEndpointURI)
44         {
45             return value;
46         }
47
48         try
49         {
50             UMOManager manager = MuleManager.getInstance();
51             String JavaDoc endpoint = manager.lookupEndpointIdentifier(value.toString(), value.toString());
52             endpoint = XMLEntityCodec.decodeString(endpoint);
53             return new MuleEndpointURI(endpoint);
54         }
55         catch (Exception JavaDoc e)
56         {
57             throw new ConversionException(e);
58         }
59     }
60
61 }
62
Popular Tags