Skip to main content
summaryrefslogtreecommitdiffstats
blob: d748a6d159ffc3ed8ae94d8279cc0818315024cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*******************************************************************************
 * Copyright (c) 2006, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060509   125094 sengpl@ca.ibm.com - Seng Phung-Lu
 * 20060515   115225 sengpl@ca.ibm.com - Seng Phung-Lu
 * 20060728   145426 kathy@ca.ibm.com - Kathy Chan
 * 20080603   235367 makandre@ca.ibm.com - Andrew Mak, "IWAB0014E Unexpected exception occurred" from ant task for web service client generation
 * 20080626   229867 makandre@ca.ibm.com - Andrew Mak, Missing method in generated proxy class
 * 20080709   240225 kathy@ca.ibm.com - Kathy Chan
 * 20120409   376345 yenlu@ca.ibm.com, kchong@ca.ibm.com - Stability improvements to web services commands/operations
 *******************************************************************************/
package org.eclipse.jst.ws.internal.axis.consumption.ui.task;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.ws.internal.axis.consumption.core.command.WSDL2JavaCommand;
import org.eclipse.jst.ws.internal.axis.consumption.core.common.JavaWSDLParameter;
import org.eclipse.jst.ws.internal.axis.consumption.ui.plugin.WebServiceAxisConsumptionUIPlugin;
import org.eclipse.jst.ws.internal.consumption.command.common.BuildProjectCommand;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.ws.internal.parser.wsil.WebServicesParser;

public class ClientCodeGenOperation extends AbstractDataModelOperation {
	
	private CopyAxisJarCommand copyAxisJarCommand = null;
	
	private WSDL2JavaCommand wsdl2JavaCommand = null;
	private JavaWSDLParameter javaWSDLParam;
	private String wsdlURI;
	
	private IProject project;
	
	private Stub2BeanCommand stub2BeanCommand = null;
	private WebServicesParser webServicesParser;
	private String outputFolder;
	private String proxyBean;
	private String proxyEndpoint;
	
	private RefreshProjectCommand refreshProjectCommand = null;

	public ClientCodeGenOperation(){
		copyAxisJarCommand = new CopyAxisJarCommand();
		wsdl2JavaCommand = new WSDL2JavaCommand();
		stub2BeanCommand = new Stub2BeanCommand();
		refreshProjectCommand = new RefreshProjectCommand();
	}
	
	public IStatus execute(IProgressMonitor monitor, IAdaptable info) {

		IEnvironment env = getEnvironment();
		ClientWSModifyOperation clientOperation = new ClientWSModifyOperation(info, env);
		try {
			clientOperation.run(monitor);
			
			//project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
			BuildProjectCommand buildCommand = new BuildProjectCommand();
			buildCommand.setProject(project);
			buildCommand.setEnvironment(env);
			buildCommand.setForceBuild(true);
			buildCommand.execute(monitor, info);
			
			GenProxyBeanOperation genProxyBeanOperation = new GenProxyBeanOperation(info, env);
			genProxyBeanOperation.run(monitor);

		}
		catch(Exception e){
			IStatus status = new Status(IStatus.ERROR, WebServiceAxisConsumptionUIPlugin.ID, e.getMessage(), e);
			return status;
		}
		return Status.OK_STATUS;

	}

	private class GenProxyBeanOperation extends WorkspaceModifyOperation
	{
		private IAdaptable info = null;
		private IEnvironment env = null;
		
		protected GenProxyBeanOperation(IAdaptable adaptable, IEnvironment environment)
		{
			//super(project);
			info = adaptable;
			env = environment;
		}
		
		protected void execute(IProgressMonitor monitor) throws CoreException
		{
			// Stub2BeanCommand
			stub2BeanCommand.setEnvironment(env);
			stub2BeanCommand.setWebServicesParser(webServicesParser);
			stub2BeanCommand.setOutputFolder(outputFolder);
			stub2BeanCommand.setJavaWSDLParam(javaWSDLParam);
			stub2BeanCommand.setClientProject(project);
			IStatus status = stub2BeanCommand.execute(monitor, info);
			if (status.getSeverity() == Status.ERROR) {
				throw new CoreException(status);
			}
			proxyBean = stub2BeanCommand.getProxyBean();
			proxyEndpoint = stub2BeanCommand.getProxyEndpoint();			
		}
	}
	
	private class ClientWSModifyOperation extends WorkspaceModifyOperation {
		
		  private IAdaptable info = null;
		  private IEnvironment env = null;

		  
		  protected ClientWSModifyOperation(IAdaptable adaptable, IEnvironment environment){
			  info = adaptable;
			  env = environment;
		  }
		  
		  protected void execute(IProgressMonitor monitor) throws CoreException{
		  
			    IStatus status = null;

			    // CopyAxisJarCommand
			    copyAxisJarCommand.setEnvironment(env);
			    copyAxisJarCommand.setProject(project);
			    status = copyAxisJarCommand.execute(monitor, info);
			    if (status.getSeverity() == Status.ERROR){
			    	throw new CoreException(status);
			    }
				
				// WSDL2JavaCommand
				wsdl2JavaCommand.setEnvironment(env);
				wsdl2JavaCommand.setJavaWSDLParam(javaWSDLParam);
				wsdl2JavaCommand.setWsdlURI(wsdlURI);
				status = wsdl2JavaCommand.execute(monitor, info);
				if (status.getSeverity() == Status.ERROR) {
					throw new CoreException(status);
				}

				// RefreshProjectCommand
				refreshProjectCommand.setEnvironment(env);
				refreshProjectCommand.setProject(project);
				status = refreshProjectCommand.execute(monitor, info);
				if (status.getSeverity() == Status.ERROR) {
					throw new CoreException(status);
				}
				
		  }
		
	}

	public JavaWSDLParameter getJavaWSDLParam() {
		return javaWSDLParam;
	}
	
	public void setJavaWSDLParam(JavaWSDLParameter javaWSDLParam) {
		this.javaWSDLParam = javaWSDLParam;
	}

	public void setOutputFolder(String outputFolder) {
		this.outputFolder = outputFolder;
	}

	public void setProject(IProject project) {
		this.project = project;
	}

	public void setWebServicesParser(WebServicesParser webServicesParser) {
		this.webServicesParser = webServicesParser;
	}

	public void setWsdlURI(String wsdlURI) {
		this.wsdlURI = wsdlURI;
	}
		
	public String getProxyBean() {
		return proxyBean;
	}
	
	public String getProxyEndpoint() {
		return proxyEndpoint;
	}
	
}

Back to the top