View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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  
49  	private static final String[][] TOOLS = { { WSTOOLS, ToolsSettings.JBOSSWS_WSTOOLS_LOCATION },
50  			{ AXIS_1_X, ToolsSettings.AXIS_1_X_LOCATION }, { AXIS_2, ToolsSettings.AXIS_2_LOCATION },
51  			{ WSCOMPILE, ToolsSettings.JWSDP_WSCOMPILE_LOCATION }, { WSIMPORT, ToolsSettings.JWSDP_WSIMPORT_LOCATION },
52  			{ JAVAC, ToolsSettings.JAVAC_LOCATION }, { DOTNET, ToolsSettings.DOTNET_WSDL_LOCATION },
53  			{ CXF, ToolsSettings.CXF_LOCATION }, { XFIRE, ToolsSettings.XFIRE_LOCATION },
54  			{ GSOAP, ToolsSettings.GSOAP_LOCATION }, { ANT, ToolsSettings.ANT_LOCATION },
55  			{ XMLBEANS, ToolsSettings.XMLBEANS_LOCATION }, { JAXB, ToolsSettings.JAXB_LOCATION },
56  			{ TCPMON, ToolsSettings.TCPMON_LOCATION }, { WSA, ToolsSettings.ORACLE_WSA_LOCATION },
57  			{ WADL, ToolsSettings.WADL2JAVA_LOCATION }, };
58  
59  	private SimpleForm toolsForm;
60  	private final String title;
61  
62  	public ToolsPrefs( String title )
63  	{
64  		this.title = title;
65  	}
66  
67  	public String getTitle()
68  	{
69  		return title;
70  	}
71  
72  	/***
73  	 * Get the tools to be displayed in the Eclipse plugin.
74  	 * 
75  	 * @return
76  	 */
77  	public String[][] getEclipseTools()
78  	{
79  		// Return all tools except .NET related and tools that are part of
80  		// Eclipse.
81  		ArrayList<String[]> list = new ArrayList<String[]>();
82  		for( String[] s : TOOLS )
83  		{
84  			String tool = s[0];
85  
86  			// Filter out .NET related tools.
87  			if( tool != ToolsPrefs.DOTNET && tool != ToolsPrefs.GSOAP &&
88  
89  			// Filter out tools that are part of Eclipse.
90  					tool != ToolsPrefs.JAVAC && tool != ToolsPrefs.ANT )
91  			{
92  				list.add( s );
93  			}
94  		}
95  		return list.toArray( new String[list.size()][] );
96  	}
97  
98  	public SimpleForm getForm()
99  	{
100 		if( toolsForm == null )
101 		{
102 			toolsForm = new SimpleForm();
103 			toolsForm.addSpace( 5 );
104 			toolsForm.append( ToolsPrefs.WSTOOLS, new DirectoryFormComponent( "Location of JBossWS wstools" ) );
105 			toolsForm.append( ToolsPrefs.WSCOMPILE, new DirectoryFormComponent( "Location of JWSDP wscompile" ) );
106 			toolsForm.append( ToolsPrefs.WSIMPORT, new DirectoryFormComponent( "Location of JAX-WS wsimport" ) );
107 			toolsForm.append( ToolsPrefs.AXIS_1_X, new DirectoryFormComponent( "Location of Axis 1.X" ) );
108 			toolsForm.append( ToolsPrefs.AXIS_2, new DirectoryFormComponent( "Location of Axis 2" ) );
109 			toolsForm.append( ToolsPrefs.DOTNET, new DirectoryFormComponent( "Location of .NET 2.0 wsdl.exe" ) );
110 			toolsForm.append( ToolsPrefs.XFIRE, new DirectoryFormComponent( "Location of XFire 1.X" ) );
111 			toolsForm.append( ToolsPrefs.CXF, new DirectoryFormComponent( "Location of Apache CXF 2.x" ) );
112 			toolsForm.append( ToolsPrefs.ANT, new DirectoryFormComponent( "Location of Apache ANT 1.6.5 or later" ) );
113 			toolsForm.append( ToolsPrefs.GSOAP, new DirectoryFormComponent( "Location of GSoap 2.X" ) );
114 			toolsForm.append( ToolsPrefs.JAXB, new DirectoryFormComponent( "Location of JAXB xjc" ) );
115 			toolsForm.append( ToolsPrefs.XMLBEANS, new DirectoryFormComponent( "Location of XMLBeans 2.X" ) );
116 			toolsForm.append( ToolsPrefs.JAVAC, new DirectoryFormComponent( "Location of JDK 1.5 javac" ) );
117 			toolsForm.append( ToolsPrefs.TCPMON, new DirectoryFormComponent( "Location of TcpMon directory" ) );
118 			toolsForm.append( ToolsPrefs.WSA, new DirectoryFormComponent( "Location of Orace wsa.jar" ) );
119 			toolsForm.append( ToolsPrefs.WADL, new DirectoryFormComponent( "Location of wadl2java script" ) );
120 			toolsForm.addSpace( 5 );
121 		}
122 
123 		return toolsForm;
124 	}
125 
126 	public void getFormValues( Settings settings )
127 	{
128 		StringToStringMap values = new StringToStringMap();
129 		toolsForm.getValues( values );
130 		storeValues( values, settings );
131 	}
132 
133 	public void storeValues( StringToStringMap values, Settings settings )
134 	{
135 		for( int i = 0; i < TOOLS.length; i++ )
136 		{
137 			settings.setString( TOOLS[i][1], values.get( TOOLS[i][0] ) );
138 		}
139 	}
140 
141 	public void setFormValues( Settings settings )
142 	{
143 		getForm().setValues( getValues( settings ) );
144 	}
145 
146 	public StringToStringMap getValues( Settings settings )
147 	{
148 		StringToStringMap toolsValues = new StringToStringMap();
149 		for( int i = 0; i < TOOLS.length; i++ )
150 		{
151 			toolsValues.put( TOOLS[i][0], settings.getString( TOOLS[i][1], "" ) );
152 		}
153 		return toolsValues;
154 	}
155 }