View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  package com.eviware.soapui.tools;
13  
14  import java.util.Hashtable;
15  
16  import org.apache.log4j.Logger;
17  
18  import com.eviware.soapui.impl.wsdl.actions.iface.tools.axis1.Axis1XWSDL2JavaAction;
19  import com.eviware.soapui.impl.wsdl.actions.iface.tools.axis2.Axis2WSDL2CodeAction;
20  import com.eviware.soapui.impl.wsdl.actions.iface.tools.cxf.CXFAction;
21  import com.eviware.soapui.impl.wsdl.actions.iface.tools.dotnet.DotNetWsdlAction;
22  import com.eviware.soapui.impl.wsdl.actions.iface.tools.gsoap.GSoapAction;
23  import com.eviware.soapui.impl.wsdl.actions.iface.tools.jaxb.JaxbXjcAction;
24  import com.eviware.soapui.impl.wsdl.actions.iface.tools.jbossws.JBossWSConsumeAction;
25  import com.eviware.soapui.impl.wsdl.actions.iface.tools.jbossws.WSToolsWsdl2JavaAction;
26  import com.eviware.soapui.impl.wsdl.actions.iface.tools.oracle.OracleWsaGenProxyAction;
27  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
28  import com.eviware.soapui.impl.wsdl.actions.iface.tools.wscompile.WSCompileAction;
29  import com.eviware.soapui.impl.wsdl.actions.iface.tools.wsi.WSIAnalyzeAction;
30  import com.eviware.soapui.impl.wsdl.actions.iface.tools.wsimport.WSImportAction;
31  import com.eviware.soapui.impl.wsdl.actions.iface.tools.xfire.XFireAction;
32  import com.eviware.soapui.impl.wsdl.actions.iface.tools.xmlbeans.XmlBeans2Action;
33  import com.eviware.soapui.model.iface.Interface;
34  
35  /***
36   * Factory class used to create a tool action instances based on action's
37   * logical human-readable name.
38   * 
39   * @author <a href="mailto:nenadn@eviware.com">Nenad V. Nikolic</a>
40   */
41  @SuppressWarnings( "unchecked" )
42  public class ToolActionFactory
43  {
44  
45  	protected static final Logger log = Logger.getLogger( ToolActionFactory.class );
46  	private static Hashtable<String, Class> toolActionTypeMap;
47  
48  	static
49  	{
50  		toolActionTypeMap = new Hashtable<String, Class>();
51  		toolActionTypeMap.put( "axis1", Axis1XWSDL2JavaAction.class );
52  		toolActionTypeMap.put( "axis2", Axis2WSDL2CodeAction.class );
53  		toolActionTypeMap.put( "dotnet", DotNetWsdlAction.class );
54  		toolActionTypeMap.put( "gsoap", GSoapAction.class );
55  		toolActionTypeMap.put( "jaxb", JaxbXjcAction.class );
56  		toolActionTypeMap.put( "wstools", WSToolsWsdl2JavaAction.class );
57  		toolActionTypeMap.put( "wscompile", WSCompileAction.class );
58  		toolActionTypeMap.put( "wsimport", WSImportAction.class );
59  		toolActionTypeMap.put( "wsconsume", JBossWSConsumeAction.class );
60  		toolActionTypeMap.put( "xfire", XFireAction.class );
61  		toolActionTypeMap.put( "cxf", CXFAction.class );
62  		toolActionTypeMap.put( "xmlbeans", XmlBeans2Action.class );
63  		toolActionTypeMap.put( "ora", OracleWsaGenProxyAction.class );
64  		toolActionTypeMap.put( "wsi", WSIAnalyzeAction.class );
65  	}
66  
67  	public static AbstractToolsAction<Interface> createToolAction( String toolName )
68  	{
69  
70  		Class toolActionType = toolActionTypeMap.get( toolName );
71  		AbstractToolsAction<Interface> toolActionObject = null;
72  
73  		if( toolActionType == null )
74  		{
75  			return null;
76  		}
77  		try
78  		{
79  			toolActionObject = ( AbstractToolsAction<Interface> )toolActionType.newInstance();
80  		}
81  		catch( IllegalAccessException e )
82  		{
83  			log.error( "Constructor is not accessible." );
84  			log.error( "Check your source code." );
85  		}
86  		catch( InstantiationException ie )
87  		{
88  			log.error( "Could not instantiate " + toolActionType + " for some reason." );
89  			log.error( "Check your source code." );
90  		}
91  		catch( Exception e )
92  		{
93  			log.error( "Some error while instantiating " + toolActionType + " occurred." );
94  			log.error( "Check your source code." );
95  		}
96  		return toolActionObject;
97  	}
98  }