KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ConnectorConverter.java 3831 2006-11-07 22:29:59Z 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.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.umo.provider.UMOConnector;
17
18 /**
19  * <code>ConnectorConverter</code> TODO
20  */

21 public class ConnectorConverter implements Converter
22 {
23
24     // --------------------------------------------------------- Public Methods
25

26     /**
27      * Convert the specified input object into an output object of the specified
28      * type.
29      *
30      * @param type Data type to which this value should be converted
31      * @param value The input value to be converted
32      * @throws ConversionException if conversion cannot be performed successfully
33      */

34     public Object JavaDoc convert(Class JavaDoc type, Object JavaDoc value)
35     {
36         if (value == null)
37         {
38             throw new ConversionException("No value specified");
39         }
40         if (value instanceof UMOConnector)
41         {
42             return (value);
43         }
44         try
45         {
46             UMOConnector c = MuleManager.getInstance().lookupConnector(value.toString());
47             if (c == null)
48             {
49                 throw new ConversionException("UMOConnector: " + value.toString()
50                                               + " has not been registered with Mule");
51             }
52             return c;
53         }
54         catch (Exception JavaDoc e)
55         {
56             throw new ConversionException(e);
57         }
58     }
59 }
60
Popular Tags