1 /*
2 * $Id: TransactionFactoryConverter.java 7963 2007-08-21 08:53:15Z 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.umo.UMOTransactionFactory;
14 import org.mule.util.ClassUtils;
15
16 import org.apache.commons.beanutils.ConversionException;
17 import org.apache.commons.beanutils.Converter;
18
19 /**
20 * <code>TransactionFactoryConverter</code> TODO
21 */
22 public class TransactionFactoryConverter implements Converter
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 org.apache.commons.beanutils.ConversionException if conversion cannot
33 * 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 UMOTransactionFactory)
42 {
43 return (value);
44 }
45 try
46 {
47 Object factory = ClassUtils.loadClass(value.toString(), getClass()).newInstance();
48 return factory;
49 }
50 catch (Exception e)
51 {
52 throw new ConversionException(e);
53 }
54 }
55 }