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  
13  package com.eviware.soapui.actions;
14  
15  import java.util.ArrayList;
16  
17  import com.eviware.soapui.model.settings.Settings;
18  import com.eviware.soapui.settings.ToolsSettings;
19  import com.eviware.soapui.support.components.DirectoryFormComponent;
20  import com.eviware.soapui.support.components.SimpleForm;
21  import com.eviware.soapui.support.types.StringToStringMap;
22  
23  /***
24   * Preferences class for ToolsSettings
25   * 
26   * @author ole.matzura
27   */
28  
29  public class ToolsPrefs implements Prefs
30  {
31  	public static final String AXIS_1_X = "Axis 1.X";
32  	public static final String WSCOMPILE = "JAX-RPC WSCompile";
33  	public static final String WSIMPORT = "JAX-WS WSImport";
34  	public static final String AXIS_2 = "Axis 2";
35  	public static final String WSTOOLS = "JBossWS wstools";
36  	public static final String JAVAC = "JDK 1.5 javac";
37  	public static final String DOTNET = ".NET 2.0 wsdl.exe";
38  	public static final String XFIRE = "XFire 1.X";
39  	public static final String CXF = "CXF 2.X";
40  	public static final String GSOAP = "GSoap";
41  	public static final String ANT = "ANT 1.6+";
42  	public static final String XMLBEANS = "XmlBeans 2.X";
43  	public static final String JAXB = "JAXB xjc";
44  	public static final String TCPMON = "Apache TcpMon";
45  	public static final String WSA = "Oracle wsa.jar";
46  	public static final String WADL = "WADL2Java";
47  	public static final String LIBRARIES = "Script libraries";
48  	public static final String HERMES_JMS = "Hermes JMS";
49  
50  	private static final String[][] TOOLS = { { WSTOOLS, ToolsSettings.JBOSSWS_WSTOOLS_LOCATION },
51  			{ AXIS_1_X, ToolsSettings.AXIS_1_X_LOCATION }, { AXIS_2, ToolsSettings.AXIS_2_LOCATION },
52  			{ WSCOMPILE, ToolsSettings.JWSDP_WSCOMPILE_LOCATION }, { WSIMPORT, ToolsSettings.JWSDP_WSIMPORT_LOCATION },
53  			{ JAVAC, ToolsSettings.JAVAC_LOCATION }, { DOTNET, ToolsSettings.DOTNET_WSDL_LOCATION },
54  			{ CXF, ToolsSettings.CXF_LOCATION }, { XFIRE, ToolsSettings.XFIRE_LOCATION },
55  			{ GSOAP, ToolsSettings.GSOAP_LOCATION }, { ANT, ToolsSettings.ANT_LOCATION },
56  			{ XMLBEANS, ToolsSettings.XMLBEANS_LOCATION }, { JAXB, ToolsSettings.JAXB_LOCATION },
57  			{ TCPMON, ToolsSettings.TCPMON_LOCATION }, { WSA, ToolsSettings.ORACLE_WSA_LOCATION },
58  			{ WADL, ToolsSettings.WADL2JAVA_LOCATION },  { HERMES_JMS, ToolsSettings.HERMES_JMS },};
59  
60  	private SimpleForm toolsForm;
61  	private final String title;
62  
63  	public ToolsPrefs( String title )
64  	{
65  		this.title = title;
66  	}
67  
68  	public String getTitle()
69  	{
70  		return title;
71  	}
72  
73  	/***
74  	 * Get the tools to be displayed in the Eclipse plugin.
75  	 * 
76  	 * @return
77  	 */
78  	public String[][] getEclipseTools()
79  	{
80  		// Return all tools except .NET related and tools that are part of
81  		// Eclipse.
82  		ArrayList<String[]> list = new ArrayList<String[]>();
83  		for( String[] s : TOOLS )
84  		{
85  			String tool = s[0];
86  
87  			// Filter out .NET related tools.
88  			if( tool != ToolsPrefs.DOTNET && tool != ToolsPrefs.GSOAP &&
89  
90  			// Filter out tools that are part of Eclipse.
91  					tool != ToolsPrefs.JAVAC && tool != ToolsPrefs.ANT )
92  			{
93  				list.add( s );
94  			}
95  		}
96  		return list.toArray( new String[list.size()][] );
97  	}
98  
99  	public SimpleForm getForm()
100 	{
101 		if( toolsForm == null )
102 		{
103 			toolsForm = new SimpleForm();
104 			toolsForm.addSpace( 5 );
105 			toolsForm.append( ToolsPrefs.WSTOOLS, new DirectoryFormComponent( "Location of JBossWS wstools" ) );
106 			toolsForm.append( ToolsPrefs.WSCOMPILE, new DirectoryFormComponent( "Location of JWSDP wscompile" ) );
107 			toolsForm.append( ToolsPrefs.WSIMPORT, new DirectoryFormComponent( "Location of JAX-WS wsimport" ) );
108 			toolsForm.append( ToolsPrefs.AXIS_1_X, new DirectoryFormComponent( "Location of Axis 1.X" ) );
109 			toolsForm.append( ToolsPrefs.AXIS_2, new DirectoryFormComponent( "Location of Axis 2" ) );
110 			toolsForm.append( ToolsPrefs.DOTNET, new DirectoryFormComponent( "Location of .NET 2.0 wsdl.exe" ) );
111 			toolsForm.append( ToolsPrefs.XFIRE, new DirectoryFormComponent( "Location of XFire 1.X" ) );
112 			toolsForm.append( ToolsPrefs.CXF, new DirectoryFormComponent( "Location of Apache CXF 2.x" ) );
113 			toolsForm.append( ToolsPrefs.ANT, new DirectoryFormComponent( "Location of Apache ANT 1.6.5 or later" ) );
114 			toolsForm.append( ToolsPrefs.GSOAP, new DirectoryFormComponent( "Location of GSoap 2.X" ) );
115 			toolsForm.append( ToolsPrefs.JAXB, new DirectoryFormComponent( "Location of JAXB xjc" ) );
116 			toolsForm.append( ToolsPrefs.XMLBEANS, new DirectoryFormComponent( "Location of XMLBeans 2.X" ) );
117 			toolsForm.append( ToolsPrefs.JAVAC, new DirectoryFormComponent( "Location of JDK 1.5 javac" ) );
118 			toolsForm.append( ToolsPrefs.TCPMON, new DirectoryFormComponent( "Location of TcpMon directory" ) );
119 			toolsForm.append( ToolsPrefs.WSA, new DirectoryFormComponent( "Location of Orace wsa.jar" ) );
120 			toolsForm.append( ToolsPrefs.WADL, new DirectoryFormComponent( "Location of wadl2java script" ) );
121 			toolsForm.append( ToolsPrefs.HERMES_JMS, new DirectoryFormComponent( "Location of HermesJMS" ) );
122 			toolsForm.addSpace( 5 );
123 		}
124 
125 		return toolsForm;
126 	}
127 
128 	public void getFormValues( Settings settings )
129 	{
130 		StringToStringMap values = new StringToStringMap();
131 		toolsForm.getValues( values );
132 		storeValues( values, settings );
133 	}
134 
135 	public void storeValues( StringToStringMap values, Settings settings )
136 	{
137 		for( int i = 0; i < TOOLS.length; i++ )
138 		{
139 			settings.setString( TOOLS[i][1], values.get( TOOLS[i][0] ) );
140 		}
141 	}
142 
143 	public void setFormValues( Settings settings )
144 	{
145 		getForm().setValues( getValues( settings ) );
146 	}
147 
148 	public StringToStringMap getValues( Settings settings )
149 	{
150 		StringToStringMap toolsValues = new StringToStringMap();
151 		for( int i = 0; i < TOOLS.length; i++ )
152 		{
153 			toolsValues.put( TOOLS[i][0], settings.getString( TOOLS[i][1], "" ) );
154 		}
155 		return toolsValues;
156 	}
157 }