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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
/*******************************************************************************
* Copyright (c) 2000, 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.consumption.codegen.javamofvisitoractions;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jem.java.JavaClass;
import org.eclipse.jem.java.JavaParameter;
import org.eclipse.jem.java.Method;
import org.eclipse.jst.ws.internal.command.NullStatusMonitor;
import org.eclipse.jst.ws.internal.command.StatusMonitor;
import org.eclipse.jst.ws.internal.consumption.codegen.Visitor;
import org.eclipse.jst.ws.internal.consumption.codegen.VisitorAction;
import org.eclipse.jst.ws.internal.consumption.codegen.javamofvisitors.JavaMofAttributeVisitor;
import org.eclipse.jst.ws.internal.consumption.codegen.javamofvisitors.JavaMofFieldVisitor;
import org.eclipse.jst.ws.internal.consumption.codegen.javamofvisitors.JavaMofMethodVisitor;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.BeanElement;
import org.eclipse.jst.ws.internal.consumption.datamodel.beanmodel.BeanModelElementsFactory;
import org.eclipse.wst.command.internal.provisional.env.core.common.Choice;
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment;
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils;
import org.eclipse.wst.command.internal.provisional.env.core.common.StatusUtils;
import org.eclipse.wst.command.internal.provisional.env.core.selection.BooleanSelection;
import org.eclipse.wst.ws.internal.datamodel.Element;
import org.eclipse.wst.ws.internal.datamodel.Model;
/**
* Objects of this class represent a JavaMofBeanVisitorAction.
* This VisitorAction will create a BeanElement using the
* JavaClass and the BeanModelElementsFactory
* It will also automatically walk the methods in the JavaClass
* */
public class JavaMofBeanVisitorAction implements VisitorAction
{
// Copyright
public static final String copyright = "(c) Copyright IBM Corporation 2000, 2002.";
private MessageUtils msgUtils_;
protected Environment env_;
// protected BeanElement fBeanElement;
protected Visitor fVisitor;
/*
* The project that defines the context
**/
protected String clientProject;
/*
* The Status monitor
**/
protected StatusMonitor monitor_;
/*
* The model that will be created
**/
protected Model fModel;
/*
* This is the parent element used when creating a
* new element
*/
protected Element fParentElement;
/*
* Methods processed from proxy
*/
protected Vector fBeansCreated;
private BooleanSelection[] fMethodsSelected;
/*
* this boolean tells wether the bean is a return parameter or an input parameter
* usually this should be set around the parametervisitoraction, and passed on from there
*/
protected boolean fReturnParam=false;
public JavaMofBeanVisitorAction(String clientProject,BooleanSelection[] methods, Environment env)
{
this.clientProject = clientProject;
fMethodsSelected = methods;
String pluginId = "org.eclipse.jst.ws.consumption";
msgUtils_ = new MessageUtils(pluginId + ".plugin", this);
env_ = env;
}
/*
*Constructor
* @param Model model is the Model that this bean will be placed in
* @param IProject used in nature
**/
public JavaMofBeanVisitorAction(Model model, String clientProject, Environment env)
{
this.clientProject = clientProject;
fModel = model;
String pluginId = "org.eclipse.jst.ws.consumption";
msgUtils_ = new MessageUtils(pluginId + ".plugin", this);
env_ = env;
}
/*
*Constructor
* @param Element the parent element that this element will be added too
* @param IProject used in nature
**/
public JavaMofBeanVisitorAction(Element parentElement, String clientProject, Environment env )
{
fParentElement = parentElement;
this.clientProject = clientProject;
String pluginId = "org.eclipse.jst.ws.consumption";
msgUtils_ = new MessageUtils(pluginId + ".plugin", this);
env_ = env;
}
/**
* The visit will create the bean
* Walk the methods
* @param JavaClass the class to be used to create the bean model
**/
public IStatus visit (Object javaclass)
{
Choice OKChoice = new Choice('O', msgUtils_.getMessage("LABEL_OK"), msgUtils_.getMessage("DESCRIPTION_OK"));
Choice CancelChoice = new Choice('C', msgUtils_.getMessage("LABEL_CANCEL"), msgUtils_.getMessage("DESCRIPTION_CANCEL"));
IStatus status = Status.OK_STATUS;
JavaClass javaClass = (JavaClass)javaclass;
BeanElement beanElement = (BeanElement)BeanModelElementsFactory.getBeanModelElement(javaClass,fParentElement,fModel);
if(beanElement.isOwnerParameter()) {
resetBeansCreated();
}
fModel = beanElement.getModel();
//this for the subsequent beans that represent types
//first do the attributes
//if we are not on the root
if (!(beanElement == fModel.getRootElement())){
Enumeration e = getBeansCreated().elements();
while(e.hasMoreElements()){
String name = (String)e.nextElement();
if(name.equals(javaClass.getName())){
status = StatusUtils.warningStatus( msgUtils_.getMessage("MSG_ERROR_JTS_CYCLIC_BEAN" ) );
//getStatusMonitor().reportStatus(new Status(IStatus.WARNING,WebServiceConsumptionPlugin.ID,0,
//WebServiceConsumptionPlugin.getMessage( "%MSG_ERROR_JTS_CYCLIC_BEAN" ),null));
return status;
}
}
JavaMofAttributeVisitorAction attributeVisitorAction = new JavaMofAttributeVisitorAction(beanElement,clientProject, env_);
//attributeVisitorAction.setStatusMonitor(getStatusMonitor());
Vector childVector = ((Vector)getBeansCreated().clone());
childVector.addElement(javaClass.getName());
attributeVisitorAction.setBeansCreated(childVector);
attributeVisitorAction.setReturnParam(getReturnParam());
JavaMofAttributeVisitor attributeVisitor = new JavaMofAttributeVisitor();
attributeVisitor.setReturnParameter(getReturnParam());
attributeVisitor.setProject(getProject());
attributeVisitor.setEnvironment(env_);
status = attributeVisitor.run(javaClass,attributeVisitorAction);
//
int severity = status.getSeverity();
if (severity==Status.ERROR)
return status;
if (severity==Status.WARNING)
{
Choice result = env_.getStatusHandler().report(status, new Choice[]{OKChoice, CancelChoice});
if (result.getLabel().equals(CancelChoice.getLabel()))
{
//return an error status since the user canceled
return StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_SAMPLE_CREATION_CANCELED") );
}
}
//
JavaMofFieldVisitorAction fieldVisitorAction = new JavaMofFieldVisitorAction(beanElement,clientProject, env_);
//fieldVisitorAction.setStatusMonitor(getStatusMonitor());
Vector childVector2 = ((Vector)getBeansCreated().clone());
childVector2.addElement(javaClass.getName());
fieldVisitorAction.setBeansCreated(childVector2);
fieldVisitorAction.setReturnParam(getReturnParam());
JavaMofFieldVisitor fieldVisitor = new JavaMofFieldVisitor();
fieldVisitor.setProject(getProject());
status = fieldVisitor.run(javaClass,fieldVisitorAction);
//
severity = status.getSeverity();
if (severity==Status.ERROR)
return status;
if (severity==Status.WARNING)
{
Choice result = env_.getStatusHandler().report(status, new Choice[]{OKChoice, CancelChoice});
if (result.getLabel().equals(CancelChoice.getLabel()))
{
//return an error status since the user canceled
return StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_SAMPLE_CREATION_CANCELED") );
}
}
//
}
//this is to insure we are on the proxy
//now do the methods
if (beanElement == fModel.getRootElement()){
//first lets make sure the proxy is in good form
//-it has a default constructor
//-it has at least one method
//otherwise return the problem in the form of a status
if (!proxyCheck(javaClass, status)) return status;
JavaMofMethodVisitorAction methodVisitorAction = new JavaMofMethodVisitorAction(beanElement,clientProject, env_);
//methodVisitorAction.setStatusMonitor(getStatusMonitor());
JavaMofMethodVisitor methodVisitor = new JavaMofMethodVisitor();
methodVisitor.setMethodSelection(fMethodsSelected);
status = methodVisitor.run(javaClass,methodVisitorAction);
//
int severity = status.getSeverity();
if (severity==Status.ERROR)
return status;
if (severity==Status.WARNING)
{
Choice result = env_.getStatusHandler().report(status, new Choice[]{OKChoice, CancelChoice});
if (result.getLabel().equals(CancelChoice.getLabel()))
{
//return an error status since the user canceled
return StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_SAMPLE_CREATION_CANCELED") );
}
}
//
//This is where we check for several things:
//-if no methods were processed because of unsupported types then we send back that result
//-if there were any methods omitted we should warn them
//first no methods
if (!methodVisitorAction.wereMethodsProcessed()){
//this has to be done to insure the dialog is an error
status = StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_JTS_NO_PROXY_METHODS_PROCESSED") );
return status;
//getStatusMonitor().reportStatus( new Status(IStatus.ERROR,WebServiceConsumptionPlugin.ID,0,
// WebServiceConsumptionPlugin.getMessage( "%MSG_ERROR_JTS_NO_PROXY_METHODS_PROCESSED" ),null));
}
//now methods omitted
else if(methodVisitorAction.wereMethodsOmitted()){
//The dialog is already a warning so we just need to set the overall message
status = StatusUtils.warningStatus( msgUtils_.getMessage("MSG_WARN_JTS_PROXY_METHODS_OMITTED") );
return status;
//getStatusMonitor().reportStatus( new Status(IStatus.WARNING,WebServiceConsumptionPlugin.ID,0,
// WebServiceConsumptionPlugin.getMessage( "%MSG_WARN_JTS_PROXY_METHODS_OMITTED" ),null));
}
}
return status;
}
public void initialize(String resident)
{
//nothing to be done but must be implemented
}
/*
* Return the model that was created
* @return Model the bean model that was created
*/
public Model getModel()
{
return fModel;
}
/*
* The proxy check insures there is a default constructor and
* at Least one method
* @param JavaClass javaClass is used to traverse the methods on the proxy
*/
public boolean proxyCheck(JavaClass javaClass, IStatus status)
{
// first check for a method
Iterator m=javaClass.getPublicMethods().iterator();
if (!m.hasNext()){
status = StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_JTS_PROXY_HAS_NO_METHODS") );
//getStatusMonitor().reportStatus( new Status(IStatus.ERROR,WebServiceConsumptionPlugin.ID,0,
// WebServiceConsumptionPlugin.getMessage( "%MSG_ERROR_JTS_PROXY_HAS_NO_METHODS" ),null));
return false;
}
//now check for a default constructor
while (m.hasNext()) {
Method method=(Method)m.next();
if (javaClass.getName().equals(method.getName())){
//now the inputs
JavaParameter javaParameter[] = method.listParametersWithoutReturn();
if (javaParameter.length > 0){
//then we have no default constructor
status = StatusUtils.errorStatus( msgUtils_.getMessage("MSG_ERROR_JTS_PROXY_HAS_NO_DEFAULT") );
//getStatusMonitor().reportStatus( new Status(IStatus.ERROR,WebServiceConsumptionPlugin.ID,0,
//WebServiceConsumptionPlugin.getMessage( "%MSG_ERROR_JTS_PROXY_HAS_NO_DEFAULT" ),null));
return false;
}
}
}
return true;
}
/**
* Sets the status monitor that this action will use to report status that occres while executing the Action.
*/
public void setStatusMonitor ( StatusMonitor monitor )
{
monitor_ = monitor;
}
/**
* Returns the status monitor that this task is using to report status.
*/
public StatusMonitor getStatusMonitor ()
{
if (monitor_ == null)
{
monitor_ = new NullStatusMonitor();
}
return monitor_;
}
/**
* check if the action has finished sucsessfully
*/
/*
public boolean isSuccessful ()
{
return getStatusMonitor().canContinue();
}
*/
public void resetBeansCreated()
{
fBeansCreated = new Vector();
}
public void setEnvironment(Environment env)
{
env_ = env;
}
/*
* The command that called this will get the results of the operation in the form
* of a status.
*/
public Vector getBeansCreated ()
{
if(fBeansCreated == null) fBeansCreated = new Vector();
return fBeansCreated;
}
/*
* The command that called this will get the results of the operation in the form
* of a status.
*/
public void setBeansCreated (Vector beansCreated)
{
fBeansCreated = beansCreated;
}
/*
* This boolean tells wether we are dealing with a return param
*/
public boolean getReturnParam ()
{
return fReturnParam;
}
/*
* This boolean tells wether we are dealing with a return param
*/
public void setReturnParam (boolean returnparam)
{
fReturnParam = returnparam;
}
/*
* This boolean tells wether we are dealing with a return param
*/
public String getProject ()
{
return clientProject;
}
/*
* This boolean tells wether we are dealing with a return param
*/
public void setProject (String clientProject)
{
this.clientProject = clientProject;
}
/**
* sets the visitor that calls the visit
* @parameter Visitor
*/
public void setVisitor(Visitor visitor)
{
fVisitor = visitor;
}
/*
* Sets the parent element the child then knows where to
* add itself to the model
* @param Element parent element
*/
public void setParentElement(Element element)
{
fParentElement = element;
}
}
|