View Javadoc

1   /*
2    * $Id: ConnectorConverter.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.config.converters;
12  
13  import org.mule.MuleManager;
14  import org.mule.umo.provider.UMOConnector;
15  
16  import org.apache.commons.beanutils.ConversionException;
17  import org.apache.commons.beanutils.Converter;
18  
19  /**
20   * <code>ConnectorConverter</code> TODO
21   */
22  public class ConnectorConverter implements Converter
23  {
24  
25      // --------------------------------------------------------- Public Methods
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 ConversionException if conversion cannot be performed successfully
34       */
35      public Object convert(Class type, Object value)
36      {
37          if (value == null)
38          {
39              throw new ConversionException("No value specified");
40          }
41          if (value instanceof UMOConnector)
42          {
43              return (value);
44          }
45          try
46          {
47              UMOConnector c = MuleManager.getInstance().lookupConnector(value.toString());
48              if (c == null)
49              {
50                  throw new ConversionException("UMOConnector: " + value.toString()
51                                                + " has not been registered with Mule");
52              }
53              return c;
54          }
55          catch (Exception e)
56          {
57              throw new ConversionException(e);
58          }
59      }
60  }