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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*******************************************************************************
* Copyright (c) 2003, 2004 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
*******************************************************************************/
package org.eclipse.jst.ws.internal.axis.consumption.core.command;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.apache.axis.wsdl.toJava.Emitter;
import org.apache.axis.wsdl.toJava.GeneratedFileInfo;
import org.eclipse.jst.ws.internal.axis.consumption.core.common.JavaWSDLParameter;
import org.eclipse.wst.command.env.core.SimpleCommand;
import org.eclipse.wst.command.env.core.common.Environment;
import org.eclipse.wst.command.env.core.common.Log;
import org.eclipse.wst.command.env.core.common.SimpleStatus;
import org.eclipse.wst.command.env.core.common.Status;
public class WSDL2JavaCommand extends SimpleCommand {
private final String DEPLOY_TYPE = "deploy"; //$NON-NLS-1$
private final String UNDEPLOY_TYPE = "undeploy"; //$NON-NLS-1$
private JavaWSDLParameter javaWSDLParam;
private String wsdlURI;
private String httpBasicAuthUsername;
private String httpBasicAuthPassword;
private ResourceBundle resource = ResourceBundle.getBundle("org.eclipse.jst.ws.axis.consumption.core.consumption"); //$NON-NLS-1$
private String LABEL = "TASK_LABEL_WSDL_JAVA_COMMAND";
private String DESCRIPTION = "TASK_DESC_WSDL_JAVA_COMMAND";
public WSDL2JavaCommand() {
super();
setName(getMessage(LABEL));
setDescription(getMessage(DESCRIPTION));
}
public Status execute(Environment environment) {
Status status;
if (javaWSDLParam == null) {
status = new SimpleStatus("WSDL2JavaCommand", //$NON-NLS-1$
getMessage("MSG_ERROR_JAVA_WSDL_PARAM_NOT_SET"), Status.ERROR);
environment.getStatusHandler().reportError(status);
return status;
}
if (wsdlURI != null) //bottom up case has already has the correct WSDL on javaWSDLParam
{
javaWSDLParam.setInputWsdlLocation(wsdlURI);
}
javaWSDLParam.setHTTPUsername(httpBasicAuthUsername);
javaWSDLParam.setHTTPPassword(httpBasicAuthPassword);
Emitter wsdl2Java = new Emitter();
if (environment.getLog().isEnabled("emitter")) {
wsdl2Java.setVerbose(true);
} else {
wsdl2Java.setVerbose(false);
}
boolean serverSide = javaWSDLParam.getServerSide() == JavaWSDLParameter.SERVER_SIDE_BEAN;
wsdl2Java.setServerSide(serverSide);
if (serverSide) {
wsdl2Java.setSkeletonWanted(javaWSDLParam.isSkeletonDeploy());
}
if (javaWSDLParam.isMetaInfOnly()) {
// for the case Java2WSDL-WSDL2Java
wsdl2Java.setOutputDir(removeFileProtocol(javaWSDLParam.getOutput()));
HashMap pck2nsMap = javaWSDLParam.getMappings();
if (pck2nsMap != null) {
HashMap ns2pckMap = new HashMap();
Iterator keys = pck2nsMap.keySet().iterator();
while (keys.hasNext()) {
String pakage = (String) keys.next();
String namespace = (String) pck2nsMap.get(pakage);
ns2pckMap.put(namespace, pakage);
}
wsdl2Java.setNamespaceMap(ns2pckMap);
}
} else {
// for the case WSDL2Java
wsdl2Java.setOutputDir(removeFileProtocol(javaWSDLParam.getJavaOutput()));
if (javaWSDLParam.getMappings() != null) {
wsdl2Java.setNamespaceMap(javaWSDLParam.getMappings());
}
}
environment.getLog().log(Log.INFO, 5019, this, "execute", "Java output = " + javaWSDLParam.getJavaOutput());
if (javaWSDLParam.getHTTPPassword() != null) {
wsdl2Java.setPassword(javaWSDLParam.getHTTPPassword());
environment.getLog().log(Log.INFO, 5081, this, "execute", "password: " + javaWSDLParam.getHTTPPassword());
}
if (javaWSDLParam.getHTTPUsername() != null) {
wsdl2Java.setUsername(javaWSDLParam.getHTTPUsername());
environment.getLog().log(Log.INFO, 5082, this, "execute", "username: " + javaWSDLParam.getHTTPUsername());
}
environment.getLog().log(Log.INFO, 5020, this, "execute", "WSDL Location = " + javaWSDLParam.getInputWsdlLocation());
environment.getProgressMonitor().report(getMessage("MSG_PARSING_WSDL", javaWSDLParam.getInputWsdlLocation() ) );
try {
wsdl2Java.run(javaWSDLParam.getInputWsdlLocation());
if (serverSide) {
// set deployment files
List deploymentFiles1 = wsdl2Java.getGeneratedFileInfo().findType(DEPLOY_TYPE);
List deploymentFiles2 = wsdl2Java.getGeneratedFileInfo().findType(UNDEPLOY_TYPE);
ArrayList deplFiles = new ArrayList();
if (deploymentFiles1 != null && deploymentFiles2 != null) {
deploymentFiles1.addAll(deploymentFiles2);
for (int i = 0; i < deploymentFiles1.size(); i++) {
GeneratedFileInfo.Entry entry = (GeneratedFileInfo.Entry) deploymentFiles1.get(i);
deplFiles.add(entry.fileName);
}
String[] deplFilesArray = new String[deplFiles.size()];
deplFiles.toArray(deplFilesArray);
javaWSDLParam.setDeploymentFiles(deplFilesArray);
}
// set java files
List javaFiles = wsdl2Java.getGeneratedFileNames();
javaFiles.removeAll(deplFiles);
String[] javaFileNames = new String[javaFiles.size()];
javaFiles.toArray(javaFileNames);
javaWSDLParam.setJavaFiles(javaFileNames);
}
} catch (Exception e) {
environment.getLog().log(Log.ERROR, 5021, this, "execute", e);
status = new SimpleStatus("Java2WSDLCommand", //$NON-NLS-1$
getMessage("MSG_ERROR_WSDL_JAVA_GENERATE") + " " //$NON-NLS-1$
+ e.toString(), Status.ERROR);
environment.getStatusHandler().reportError(status);
return status;
}
return new SimpleStatus("");
}
/*
* Hack: Axis doesn't like file URLs
*/
private String removeFileProtocol(String s) {
if (s.startsWith("file:")) {
String newS = s.substring(5, s.length());
int i = newS.indexOf(':');
if (i != -1) {
String protocol = newS.substring(0, i);
int j = protocol.indexOf('/');
int k = protocol.indexOf('\\');
int max = Math.max(j, k);
if (max != -1)
newS = newS.substring(max + 1, newS.length());
}
return newS;
}
return s;
}
public Status undo(Environment environment) {
return null;
}
public Status redo(Environment environment) {
return null;
}
private String getMessage(String messageId, String parm1) {
String message = resource.getString(messageId);
return MessageFormat.format(message, new String[]{parm1});
}
/**
* Returns the message string identified by the given key from
* plugin.properties.
*
* @return The String message.
*/
public String getMessage(String key) {
return resource.getString(key);
}
public void setJavaWSDLParam(JavaWSDLParameter javaWSDLParam) {
this.javaWSDLParam = javaWSDLParam;
}
public JavaWSDLParameter getJavaWSDLParam() {
return javaWSDLParam;
}
/**
* @param httpBasicAuthPassword
* The httpBasicAuthPassword to set.
*/
public void setHttpBasicAuthPassword(String httpBasicAuthPassword) {
this.httpBasicAuthPassword = httpBasicAuthPassword;
}
/**
* @param httpBasicAuthUsername
* The httpBasicAuthUsername to set.
*/
public void setHttpBasicAuthUsername(String httpBasicAuthUsername) {
this.httpBasicAuthUsername = httpBasicAuthUsername;
}
public void setWsdlURI(String wsdlURI) {
this.wsdlURI = wsdlURI;
}
}
|