View Javadoc

1   /***
2    * Created on Aug 5, 2005, Copyright UC Regents
3    */
4   package wise2.converter;
5   
6   import java.util.logging.Logger;
7   
8   import net.sf.sail.common.beansupport.ITitleAware;
9   import net.sf.sail.core.beans.Pod;
10  
11  /***
12   * @author turadg
13   */
14  public class ConverterFactory {
15  	/***
16  	 * Logger for this class
17  	 */
18  	private static final Logger logger = Logger
19  			.getLogger(ConverterFactory.class.getName());
20  
21  	/***
22  	 * @param stepType
23  	 *            specified by WISE PHP
24  	 * @return class to convert
25  	 */
26  	public static AbstractStepConverter converterClass(String stepType) {
27  		String className = "wise2.converter.converters." + stepType
28  				+ "Converter";
29  		try {
30  			Class converterClass = Class.forName(className);
31  			return (AbstractStepConverter) converterClass.newInstance();
32  		} catch (ClassNotFoundException e) {
33  			logger.warning("conversion of " + stepType + " not supported");
34  			return new wise2.converter.converters.UnsupportedConverter();
35  		} catch (Exception e) {
36  			logger.severe("String -  : exception: " + e); //$NON-NLS-1$
37  			return new wise2.converter.converters.UnsupportedConverter();
38  		}
39  	}
40  
41  	public static <T> T createBeanInPod(Pod pod, Class<T> beanClass,
42  			String title) throws InstantiationException, IllegalAccessException {
43  		T bean = beanClass.newInstance();
44  		((ITitleAware) bean).setTitle(title);
45  		pod.add(bean);
46  		return bean;
47  	}
48  
49  }