KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > TestWebServiceMethodDlg


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.ui;
21
22 import org.netbeans.modules.websvc.registry.model.WebServiceData;
23 import org.netbeans.modules.websvc.registry.util.Util;
24 import com.sun.xml.rpc.processor.model.java.*;
25 import java.awt.Cursor JavaDoc;
26 import java.awt.Dialog JavaDoc;
27 import java.awt.EventQueue JavaDoc;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.awt.event.WindowAdapter JavaDoc;
31 import java.awt.event.WindowEvent JavaDoc;
32 import java.io.File JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.lang.reflect.Array JavaDoc;
35 import java.math.BigDecimal JavaDoc;
36 import java.math.BigInteger JavaDoc;
37 import java.net.*;
38 import java.util.*;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JPanel JavaDoc;
41 import javax.swing.SwingUtilities JavaDoc;
42 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
43 import javax.swing.tree.DefaultTreeModel JavaDoc;
44 import javax.xml.parsers.DocumentBuilder JavaDoc;
45 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
46 import javax.xml.parsers.ParserConfigurationException JavaDoc;
47 import org.netbeans.swing.outline.DefaultOutlineModel;
48 import org.netbeans.swing.outline.Outline;
49 import org.netbeans.swing.outline.OutlineModel;
50 import org.openide.DialogDescriptor;
51 import org.openide.DialogDisplayer;
52 import org.openide.ErrorManager;
53 import org.openide.NotifyDescriptor;
54 import org.openide.awt.StatusDisplayer;
55 import org.openide.util.HelpCtx;
56 import org.openide.util.NbBundle;
57 import org.openide.util.RequestProcessor;
58 import org.w3c.dom.*;
59 import org.xml.sax.SAXException JavaDoc;
60
61 import org.openide.modules.InstalledFileLocator;
62 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
63 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
64
65
66 /**
67  *
68  * @author David Botterill
69  */

70 public class TestWebServiceMethodDlg extends JPanel JavaDoc /* implements ActionListener*/ {
71     private Dialog JavaDoc dialog;
72     private DialogDescriptor dlg = null;
73     private JavaMethod method;
74     /**
75      * The runtimeClassLoader should be used when running the web service client. This classloader
76      * only includes the necessary runtime jars for JAX-RPC to run. The classloader does NOT have a
77      * parent to delegate to. I did this because of Xerces classloader clashes with other netbeans
78      * modules.
79      * -David Botterill 4/21/2004
80      */

81     private URLClassLoader runtimeClassLoader;
82
83     private String JavaDoc packageName;
84     private DefaultMutableTreeNode JavaDoc parameterRootNode = new DefaultMutableTreeNode JavaDoc();
85     private DefaultMutableTreeNode JavaDoc resultRootNode = new DefaultMutableTreeNode JavaDoc();
86     private WebServiceData wsData;
87     public String JavaDoc portName;
88     public String JavaDoc modifiedMethodName;
89
90     /** Creates new form TestWebServiceMethodDlg */
91     public TestWebServiceMethodDlg(WebServiceData inWSData, JavaMethod inMethod, String JavaDoc inPortName) {
92         this.setJavaMethod(inMethod);
93         wsData = inWSData;
94         packageName = inWSData.getPackageName();
95         portName = inPortName;
96         modifiedMethodName = Util.getProperPortName(inPortName).toLowerCase() + Util.upperCaseFirstChar(inMethod.getName());
97
98         initComponents();
99         myInitComponents();
100
101         this.lblTitle.setText(NbBundle.getMessage(this.getClass(), "TEST_WEBSVC_LABEL") + " " + modifiedMethodName);
102     }
103
104
105     /**
106      * This method returns the classloader of the Jar file containing the web service for which we are testing the methods.
107      * This class loader should be used for the runtime environment when invoking a web service.
108      * TODO: determine if the tree components should get the class loader here, store the classloader in the tree nodes, or pass
109      * to the tree component constructors.
110      *@returns URLClassLoader - the class loader of the Jar file for the web service with the methods to test.
111      */

112     private URLClassLoader getRuntimeClassLoader() {
113         if(null == runtimeClassLoader) {
114             /**
115              * Read in the Runtime Jar file Names
116              */

117
118             DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
119             DocumentBuilder JavaDoc builder = null;
120
121             try {
122                 builder = factory.newDocumentBuilder();
123
124             } catch(ParserConfigurationException JavaDoc pe) {
125                 ErrorManager.getDefault().notify(pe);
126                 ErrorManager.getDefault().log("ParserConfigurationException=" + pe);
127                 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS"));
128                 return null;
129             }
130
131             Document document = null;
132             try {
133                 File JavaDoc runtimeJarsFile = InstalledFileLocator.getDefault().locate(
134                         "config" + File.separator + "WebServices" + File.separator +
135                         "websvc_runtimejars.xml", null, false);
136                 document = builder.parse(runtimeJarsFile);
137             } catch(SAXException JavaDoc se) {
138                 ErrorManager.getDefault().notify(se);
139                 ErrorManager.getDefault().log("SAXException=" + se);
140                 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS"));
141                 return null;
142             } catch(IOException JavaDoc ioe) {
143                 ErrorManager.getDefault().notify(ioe);
144                 ErrorManager.getDefault().log("IOException=" + ioe);
145                 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ERROR_READING_RUNTIMEJARS"));
146                 return null;
147             }
148
149             NodeList list = document.getElementsByTagName("Jar");
150
151             ArrayList urlList = new ArrayList();
152             /**
153              * First add the URL to the jar file for this web service.
154              */

155             try {
156                 /**
157                  * If they are testing this from an existing web service in server navigator, or if they
158                  * renamed their user directory, the path may have changed. So if the file doesn't exist,
159                  * try getting it from the current user directory.
160                  */

161                 urlList.add(new URL("file:" + this.getWebServiceData().getProxyJarFileName()));
162             } catch(MalformedURLException mfu) {
163                 ErrorManager.getDefault().notify(mfu);
164                 ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + mfu);
165 // StatusDisplayer.getDefault().displayError(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"),2);
166
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"));
167                 return null;
168             }
169
170             // Now build remainder of class path from websvc_runtimejars.xml
171
String JavaDoc serverInstanceIDs[] = Deployment.getDefault().getServerInstanceIDs ();
172             J2eePlatform platform = null;
173             for (int i = 0; i < serverInstanceIDs.length; i++) {
174                 J2eePlatform p = Deployment.getDefault().getJ2eePlatform (serverInstanceIDs [i]);
175                 if (p != null && p.isToolSupported ("wscompile")) {
176                     platform = p;
177                     break;
178                 }
179             }
180             File JavaDoc appserverRoot = platform == null ? null : platform.getPlatformRoots () [0];
181             String JavaDoc asRootPath = (appserverRoot != null) ? appserverRoot.getAbsolutePath() : "";
182             asRootPath = asRootPath.replace('\\', '/');
183                         
184             Node JavaDoc currentNode = null;
185             for (int ii=0; ii < list.getLength(); ii++) {
186                 currentNode = list.item(ii);
187                 String JavaDoc name =currentNode.getNodeName();
188                 String JavaDoc localName =currentNode.getLocalName();
189                 String JavaDoc value = currentNode.getNodeValue();
190                 NamedNodeMap nodeMap = currentNode.getAttributes();
191                 Node JavaDoc fileNode = nodeMap.getNamedItem("file");
192                 String JavaDoc jarString = "";
193                 try {
194                     jarString = fileNode.getNodeValue();
195                 } catch(DOMException de) {
196                     ErrorManager.getDefault().notify(de);
197                     ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + de);
198 // StatusDisplayer.getDefault().displayError(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"),2);
199
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"));
200                     return null;
201                 }
202
203                 if (jarString.indexOf("\\{appserv\\.home\\}") > -1) {
204                     jarString = jarString.replaceAll("\\{appserv\\.home\\}", asRootPath);
205                 } else {
206                     File JavaDoc f = InstalledFileLocator.getDefault().locate(jarString, null, false);
207                     if (f != null) {
208                         jarString = f.getPath();
209                     }
210                 }
211                 
212                 /**
213                  * Make sure we are starting with "file:". If not, ifthe first character is
214                  * not a "/", It's probably a drive letter and colon like
215                  * "c:" on windows so we need to add an extra "/".
216                  */

217                 if(!jarString.startsWith("file:")) {
218                     if(jarString.substring(1,1).equals("/")) {
219                         jarString = "file:/" + jarString;
220                     } else {
221                         jarString = "file:///" + jarString;
222                     }
223                 }
224
225                 URL newURL = null;
226                 try {
227                     newURL = new URL(jarString);
228                 } catch(MalformedURLException mfu) {
229                     ErrorManager.getDefault().notify(mfu);
230                     ErrorManager.getDefault().log(this.getClass().getName() + ":IOException=" + mfu);
231 // StatusDisplayer.getDefault().displayError(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"),2);
232
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(this.getClass(), "ERROR_READING_RUNTIMEJARS"));
233                     return null;
234
235                 }
236                 urlList.add(newURL);
237
238             }
239
240             URL [] urls = (URL [])urlList.toArray(new URL[0]);
241             /**
242              * Make sure we don't have a parent to delegate to. I first experienced Xerces classloader
243              * clashes with the currentLoader as the parent.
244              */

245
246 // for(int i = 0; i < urls.length; i++) {
247
// System.out.println("JAR: " + urls[i]);
248
// }
249

250             runtimeClassLoader = new URLClassLoader(urls, null);
251
252         }
253
254         return runtimeClassLoader;
255     }
256     /**
257      * This method returns the package name of the web service for which we are testing the methods.
258      * TODO: determine if the tree components should get the class loader here, store the classloader in the tree nodes, or pass
259      * to the tree component constructors.
260      *@returns URLClassLoader - the class loader of the Jar file for the web service with the methods to test.
261      */

262     public String JavaDoc getPackageName() {
263         return packageName;
264     }
265
266     public WebServiceData getWebServiceData() {
267         return this.wsData;
268     }
269
270     public void displayDialog(){
271
272         dlg = new DialogDescriptor(this, NbBundle.getMessage(this.getClass(), "TEST_WEB_SERVICE_METHOD"),
273             false, new Object JavaDoc[]{NotifyDescriptor.CLOSED_OPTION}, DialogDescriptor.CLOSED_OPTION,
274             DialogDescriptor.DEFAULT_ALIGN, this.getHelpCtx(), null);
275         dialog = DialogDisplayer.getDefault().createDialog(dlg);
276         /**
277          * After the window is opened, set the focus to the Get information button.
278          */

279
280         final JPanel JavaDoc thisPanel = this;
281         final Dialog JavaDoc thisDialog = dialog;
282         dialog.addWindowListener( new WindowAdapter JavaDoc(){
283             public void windowOpened( WindowEvent JavaDoc e ){
284                 SwingUtilities.invokeLater(
285                 new Runnable JavaDoc() {
286                     public void run() {
287                         btnSubmit.requestFocus();
288                         thisPanel.getRootPane().setDefaultButton(btnSubmit);
289                     }
290                 });
291             }
292
293             public void windowClosing(WindowEvent JavaDoc e) {
294                 thisDialog.dispose();
295             }
296         });
297
298         dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_TEST_WEB_SERVICE_DLG"));
299         dialog.show();
300     }
301     public HelpCtx getHelpCtx() {
302         return new HelpCtx(TestWebServiceMethodDlg.class);
303     }
304
305     /** This method is called from within the constructor to
306      * initialize the form.
307      * WARNING: Do NOT modify this code. The content of this method is
308      * always regenerated by the Form Editor.
309      */

310     private void initComponents() {
311         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
312         pnlParameter = new javax.swing.JPanel JavaDoc();
313         btnPanel = new javax.swing.JPanel JavaDoc();
314         btnSubmit = new javax.swing.JButton JavaDoc();
315         scrollPaneParameter = new javax.swing.JScrollPane JavaDoc();
316         pnlLabel = new javax.swing.JPanel JavaDoc();
317         lblTitle = new javax.swing.JLabel JavaDoc();
318         jLabel1 = new javax.swing.JLabel JavaDoc();
319         pnlResults = new javax.swing.JPanel JavaDoc();
320         jPanel4 = new javax.swing.JPanel JavaDoc();
321         jLabel2 = new javax.swing.JLabel JavaDoc();
322         scrollPaneResults = new javax.swing.JScrollPane JavaDoc();
323
324         setLayout(new java.awt.BorderLayout JavaDoc());
325
326         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 5, 5, 5)));
327         jSplitPane1.setDividerLocation(400);
328         jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
329         jSplitPane1.setResizeWeight(1.0);
330         pnlParameter.setLayout(new java.awt.BorderLayout JavaDoc());
331
332         org.openide.awt.Mnemonics.setLocalizedText(btnSubmit, NbBundle.getMessage(TestWebServiceMethodDlg.class, "BUTTON_SUBMIT"));
333         btnSubmit.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_BUTTON_SUBMIT"));
334         btnSubmit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
335             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
336                 btnSubmitActionPerformed(evt);
337             }
338         });
339
340         btnPanel.add(btnSubmit);
341
342         pnlParameter.add(btnPanel, java.awt.BorderLayout.SOUTH);
343
344         pnlParameter.add(scrollPaneParameter, java.awt.BorderLayout.CENTER);
345
346         pnlLabel.setLayout(new java.awt.GridLayout JavaDoc(2, 0, 10, 10));
347
348         pnlLabel.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 5, 5, 5)));
349         lblTitle.setFont(new java.awt.Font JavaDoc(getFont().getName(), getFont().getStyle(), getFont().getSize()+2));
350         lblTitle.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/registry/ui/Bundle").getString("TEST_WEBSVC_LABEL"));
351         lblTitle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
352         pnlLabel.add(lblTitle);
353
354         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(TestWebServiceMethodDlg.class, "PARAMETERS"));
355         jLabel1.setToolTipText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "TEST_WEBSVC_INSTRUCTIONS"));
356         jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
357         pnlLabel.add(jLabel1);
358
359         pnlParameter.add(pnlLabel, java.awt.BorderLayout.NORTH);
360
361         jSplitPane1.setTopComponent(pnlParameter);
362
363         pnlResults.setLayout(new java.awt.BorderLayout JavaDoc());
364
365         jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
366
367         jPanel4.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 5, 5, 5)));
368         org.openide.awt.Mnemonics.setLocalizedText(jLabel2,NbBundle.getMessage(TestWebServiceMethodDlg.class,"RESULTS"));
369         jLabel2.setToolTipText(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_RESULT_TABLE"));
370         jPanel4.add(jLabel2, java.awt.BorderLayout.NORTH);
371
372         jPanel4.add(scrollPaneResults, java.awt.BorderLayout.CENTER);
373
374         pnlResults.add(jPanel4, java.awt.BorderLayout.CENTER);
375
376         jSplitPane1.setBottomComponent(pnlResults);
377
378         add(jSplitPane1, java.awt.BorderLayout.CENTER);
379
380     }
381
382     private void btnSubmitActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
383         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
384             public void run(){
385                 Cursor JavaDoc normalCursor = dialog.getCursor();
386                 dialog.setCursor(new Cursor JavaDoc(Cursor.WAIT_CURSOR));
387                 invokeMethod();
388                 dialog.setCursor(normalCursor);
389             }
390         });
391
392     }
393
394
395     private void invokeMethod() {
396         /**
397          * Steps to call the method.
398          * 1. Get the parameter values from the tree
399          * 2. Get the client wrapper class
400          * 3. Get the method.
401          * 4. call the Method with the parameter values
402          * 5. Display the return value.
403          */

404
405         /**
406          * Get the parameter values from the tree. The parameters will be the children of the root node only. Any children
407          * of the parameter nodes are values used to derive the parameter values.
408          */

409
410         /**
411          * Use a LinkedList because we care about the order of the parameters.
412          */

413         LinkedList paramList = new LinkedList();
414         for(int ii=0; null != this.getParamterRootNode() && ii < this.getParamterRootNode().getChildCount(); ii++) {
415             DefaultMutableTreeNode JavaDoc childNode = (DefaultMutableTreeNode JavaDoc) this.getParamterRootNode().getChildAt(ii);
416             TypeNodeData nodeData = (TypeNodeData)childNode.getUserObject();
417             Object JavaDoc parameterValue = nodeData.getParameterValue();
418             if(parameterValue instanceof ArrayList) {
419                 try {
420                     parameterValue = ReflectionHelper.getTypedParameterArray((ArrayList)parameterValue, nodeData.getParameterType(),
421                     this.getRuntimeClassLoader(), getPackageName());
422                 } catch(WebServiceReflectionException wsre) {
423                     Throwable JavaDoc cause = wsre.getCause();
424                     ErrorManager.getDefault().notify(cause);
425                     ErrorManager.getDefault().log(this.getClass().getName() +
426                     ": Error trying to create a typed parameter array for type:" + nodeData.getParameterType() +
427                     "WebServiceReflectionException=" + cause);
428                     return;
429                 }
430             }
431             paramList.add(parameterValue);
432         }
433
434         /**
435          * specify the wrapper client class name for this method.
436          */

437         String JavaDoc clientClassName = wsData.getPackageName() + "." + wsData.getDisplayName() + "Client";
438
439         /**
440          * Now invoke the method using the ReflectionHelper.
441          */

442         Object JavaDoc returnObject=null;
443         try {
444             returnObject = ReflectionHelper.callMethodWithParams(clientClassName, paramList, this.getJavaMethod(),
445             this.getRuntimeClassLoader(),modifiedMethodName);
446         } catch(WebServiceReflectionException wsre) {
447             MethodExceptionDialog errorDialog = new MethodExceptionDialog(wsre);
448             errorDialog.show();
449             return;
450         }
451
452         showResults(returnObject);
453
454     }
455
456     private void showResults(Object JavaDoc inResultObject) {
457         /**
458          * Create a tree of the result object types.
459          */

460
461         outline = loadResultTreeTable(this.getJavaMethod(), inResultObject);
462         scrollPaneResults.setViewportView(outline);
463         jLabel2.setLabelFor(outline);
464     }
465
466
467     private void myInitComponents() {
468
469         /**
470          * Now set up the Nodes for the TreeTableView
471          */

472         if(null == this.getJavaMethod()) {
473             return;
474         }
475
476         outline = loadParameterTreeTable(this.getJavaMethod());
477
478
479
480         /**
481          * Add it to the correct Panel.
482          */

483
484         scrollPaneParameter.setViewportView(outline);
485         jLabel1.setLabelFor(outline);
486
487     }
488     private DefaultMutableTreeNode JavaDoc getParamterRootNode() {
489         return parameterRootNode;
490     }
491
492     private void setParameterRootNode(DefaultMutableTreeNode JavaDoc inNode) {
493         parameterRootNode = inNode;
494     }
495     private DefaultMutableTreeNode JavaDoc getResultRootNode() {
496         return resultRootNode;
497     }
498
499     private void setResultRootNode(DefaultMutableTreeNode JavaDoc inNode) {
500         resultRootNode = inNode;
501     }
502
503     private JavaMethod getJavaMethod() {
504         return method;
505     }
506
507     private void setJavaMethod(JavaMethod inMethod) {
508         method = inMethod;
509     }
510
511     private Outline loadResultTreeTable(JavaMethod inMethod, Object JavaDoc inResultObject) {
512         if(null == inMethod) {
513             return null;
514         }
515         JavaType currentType = inMethod.getReturnType();
516
517
518         ResultNodeData data = new ResultNodeData(currentType,inResultObject);
519         DefaultMutableTreeNode JavaDoc node = new DefaultMutableTreeNode JavaDoc(data);
520
521         if(currentType instanceof JavaArrayType) {
522             /**
523              * Create the instances of the array.
524              */

525
526             addResultArrayInstances(node);
527         } else if(currentType instanceof JavaStructureType) {
528
529             /**
530              * If this is a JavaStructureType, we need to traverse the types until we have either all JavaSimpleType or
531              * JavaEnumerationType.
532              */

533             traverseResultType(node);
534         }
535         /**
536          * Make sure to create a new result root each time since the user can change the parameters and submit many
537          * times.
538          */

539         this.setResultRootNode(new DefaultMutableTreeNode JavaDoc());
540         /**
541          * Add it to the root.
542          */

543         this.getResultRootNode().add(node);
544
545
546         DefaultTreeModel JavaDoc treeModel = new DefaultTreeModel JavaDoc(this.getResultRootNode());
547         ResultRowModel rowModel = new ResultRowModel();
548         OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(treeModel,rowModel, false);
549         outlineModel.setNodeColumnName(NbBundle.getMessage(this.getClass(), "TYPE_COLUMN_NAME"));
550         Outline returnOutline = new Outline(outlineModel);
551         ResultCellEditor cellEditor = new ResultCellEditor();
552         returnOutline.setDefaultEditor(Object JavaDoc.class,cellEditor);
553         returnOutline.setRootVisible(false);
554
555         returnOutline.setRenderDataProvider(new TypeDataProvider());
556
557         returnOutline.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSN_RESULT_TABLE"));
558         //returnOutline.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_RESULT_TABLE"));
559

560         return returnOutline;
561     }
562
563     private Outline loadParameterTreeTable(JavaMethod inMethod) {
564         if(null == inMethod) {
565             return null;
566         }
567         Iterator paramIterator = inMethod.getParameters();
568         JavaParameter currentParameter = null;
569
570         while(paramIterator.hasNext()) {
571             /**
572              * Add all Parameter's to the root tree node.
573              */

574             currentParameter = (JavaParameter)paramIterator.next();
575             JavaType currentType = currentParameter.getType();
576             Object JavaDoc value = null;
577             value = getParameterDefaultValue(currentType);
578
579             TypeNodeData data = new TypeNodeData(currentType,currentParameter.getName(),value);
580             DefaultMutableTreeNode JavaDoc node = null;
581
582             if(currentType instanceof JavaArrayType) {
583                 node = new ArrayTypeTreeNode(data);
584                 /**
585                  * Create some instances of the array.
586                  */

587
588                 JavaType elementType = ((JavaArrayType)currentType).getElementType();
589                 addParameterArrayInstances(elementType,node);
590             } else if(currentType instanceof JavaStructureType) {
591                 node = new StructureTypeTreeNode(data,this.getRuntimeClassLoader(),this.getPackageName());
592
593                 /**
594                  * If this is a JavaStructureType, we need to traverse the types until we have either all JavaSimpleType or
595                  * JavaEnumerationType.
596                  */

597                 traverseType(node);
598             } else {
599                 node = new DefaultMutableTreeNode JavaDoc(data);
600             }
601             /**
602              * Add it to the root.
603              */

604             this.getParamterRootNode().add(node);
605
606         }
607
608         DefaultTreeModel JavaDoc treeModel = new DefaultTreeModel JavaDoc(this.getParamterRootNode());
609         TypeRowModel rowModel = new TypeRowModel(this.getRuntimeClassLoader(),this.getPackageName());
610         OutlineModel outlineModel = DefaultOutlineModel.createOutlineModel(treeModel,rowModel, false);
611         outlineModel.setNodeColumnName(NbBundle.getMessage(this.getClass(), "TYPE_COLUMN_NAME"));
612         Outline returnOutline = new Outline(outlineModel);
613         TypeCellEditor cellEditor = new TypeCellEditor();
614         returnOutline.setDefaultEditor(Object JavaDoc.class,cellEditor);
615         returnOutline.setRootVisible(false);
616         returnOutline.setRenderDataProvider(new TypeDataProvider());
617         /**
618          * Fix Bug 5052705. This setting will cause the cells values to take affect when
619          * the focus is lost. This will remove the requirement of hitting "ENTER" after
620          * entering a value in a cell to get the value to take affect.
621          */

622         returnOutline.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // NOI18N
623

624         returnOutline.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSN_PARAMETER_TABLE"));
625         returnOutline.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TestWebServiceMethodDlg.class, "ACSD_PARAMETER_TABLE"));
626         
627         return returnOutline;
628     }
629
630     private void traverseType(DefaultMutableTreeNode JavaDoc inNode) {
631
632         if(null == inNode) {
633             return;
634         }
635
636         JavaType inType = ((NodeData)inNode.getUserObject()).getNodeType();
637         /**
638          * We should only be traversing JavaStructureTypes but let's make sure.
639          */

640         if(!(inType instanceof JavaStructureType)) {
641             return;
642         }
643         JavaStructureType type = (JavaStructureType)inType;
644         Iterator typeIterator = type.getMembers();
645         while(null != typeIterator && typeIterator.hasNext()) {
646             JavaStructureMember entry = (JavaStructureMember)typeIterator.next();
647             JavaType entryType = entry.getType();
648             if(entryType instanceof JavaEnumerationType || entryType instanceof JavaSimpleType) {
649                 /**
650                  * add this node to the input node, the parameter name is null since this is somewhere
651                  * in a JavaStructureType hierarchy.
652                  */

653                 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType));
654                 DefaultMutableTreeNode JavaDoc node = new DefaultMutableTreeNode JavaDoc(data);
655                 inNode.add(node);
656             } else if(entryType instanceof JavaArrayType) {
657                 /**
658                  * add this node to the input node, the parameter name is null since this is somewhere
659                  * in a JavaStructureType hierarchy.
660                  */

661                 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType));
662                 ArrayTypeTreeNode node = new ArrayTypeTreeNode(data);
663                 inNode.add(node);
664                 JavaType elementType = ((JavaArrayType)entryType).getElementType();
665                 addParameterArrayInstances(elementType,node);
666             } else if(entryType instanceof JavaStructureType) {
667                 /**
668                  * add this node to the input node, the parameter name is null since this is somewhere
669                  * in a JavaStructureType hierarchy.
670                  */

671                 TypeNodeData data = new TypeNodeData(entryType,entry.getName(),getParameterDefaultValue(entryType));
672                 StructureTypeTreeNode node = new StructureTypeTreeNode(data,this.getRuntimeClassLoader(),this.getPackageName());
673                 inNode.add(node);
674                 /**
675                  * Now traverse this new JavaStructureType node.
676                  */

677                 traverseType(node);
678             }
679         }
680
681     }
682
683     private void traverseResultType(DefaultMutableTreeNode JavaDoc inParentNode) {
684
685         if(null == inParentNode) {
686             return;
687         }
688
689         ResultNodeData parentData = (ResultNodeData)inParentNode.getUserObject();
690         JavaType parentType = parentData.getResultType();
691         Object JavaDoc parentValue = parentData.getResultValue();
692         /**
693          * We should only be traversing JavaStructureTypes but let's make sure.
694          */

695         if(!(parentType instanceof JavaStructureType)) {
696             return;
697         }
698         JavaStructureType type = (JavaStructureType)parentType;
699         Iterator typeIterator = type.getMembers();
700         while(null != typeIterator && typeIterator.hasNext()) {
701             JavaStructureMember member = (JavaStructureMember)typeIterator.next();
702             JavaType memberType = member.getType();
703             String JavaDoc memberName = member.getName();
704             Object JavaDoc subTypeValue = null;
705             /**
706              * If the parentValue is null, we know the subtype value will also be null so don't
707              * try to get the value. However, we still want to show the structure subtypes so we'll
708              * keep traversing.
709              */

710             if(null != parentValue) {
711
712                 try {
713                     subTypeValue = ReflectionHelper.getStructureValue(parentData,member,this.getRuntimeClassLoader(),
714                     this.getPackageName());
715                 } catch(WebServiceReflectionException wsfe) {
716
717                 }
718             }
719             ResultNodeData data = new ResultNodeData(memberType,subTypeValue);
720             DefaultMutableTreeNode JavaDoc node = new DefaultMutableTreeNode JavaDoc(data);
721             inParentNode.add(node);
722             if(memberType instanceof JavaArrayType) {
723                 addResultArrayInstances(node);
724             } else if(memberType instanceof JavaStructureType) {
725                 /**
726                  * Now traverse the JavaStructureType node.
727                  */

728                 traverseResultType(node);
729             }
730         }
731
732     }
733     private void addParameterArrayInstances(JavaType inType, DefaultMutableTreeNode JavaDoc parentNode) {
734         /**
735          * Now add some instances of the array.
736          * TODO: figure out some better way to pick the number of instances of the array to create
737          */

738         DefaultMutableTreeNode JavaDoc childNode = null;
739         TypeNodeData data = null;
740         for(int ii=0; ii < 9; ii++) {
741             data = new TypeNodeData(inType,"[" + ii + "]",getParameterDefaultValue(inType));
742             childNode = new DefaultMutableTreeNode JavaDoc(data);
743             parentNode.add(childNode);
744
745             /**
746              * If these entries are of type JavaStructureType, traverse through them.
747              */

748             if(inType instanceof JavaStructureType) {
749                 this.traverseType(childNode);
750             }
751
752         }
753
754     }
755     private void addResultArrayInstances(DefaultMutableTreeNode JavaDoc parentNode) {
756         /**
757          * The result value is an array of a certain type that needs to be shown.
758          * 1. first get the type of the array.
759          * 2. create a node for each occurance of the array.
760          *
761          */

762         DefaultMutableTreeNode JavaDoc childNode = null;
763
764         ResultNodeData parentData = (ResultNodeData)parentNode.getUserObject();
765         JavaType parentType = parentData.getResultType();
766         if(!(parentType instanceof JavaArrayType)) {
767             return;
768         }
769         /**
770          * get the value type
771          */

772         JavaType valueType = ((JavaArrayType)parentType).getElementType();
773         Object JavaDoc resultValue = parentData.getResultValue();
774         if(null == resultValue) return;
775         // !PW The code I wrote for native types is shorter and simpler than what
776
// was here (that only worked on Objects and appears to work with Objects
777
// properly so why not use it for both...
778
ResultNodeData childData = null;
779         int length = Array.getLength(resultValue);
780         for(int i = 0; i < length; i++) {
781             childData = new ResultNodeData(valueType, Array.get(resultValue, i));
782             childNode = new DefaultMutableTreeNode JavaDoc(childData);
783             parentNode.add(childNode);
784             /**
785              * If these array elements are of type JavaStructureType, we must traverse them
786              * as well.
787              */

788             if(valueType instanceof JavaStructureType) {
789                 this.traverseResultType(childNode);
790             }
791         }
792     }
793     
794     /**
795      * This method will create a default value for based on the JavaType of the parameter. If the
796      * Type is JavaStructureType, there will be no default value.
797      */

798     private Object JavaDoc getParameterDefaultValue(JavaType type) {
799
800         Object JavaDoc value = null;
801
802         if(null == type) return null;
803
804         /**
805          * If the type is JavaStructureType, instantiate one if it's types using reflection and
806          * the default constructor.
807          */

808         if(type instanceof JavaStructureType) {
809             Object JavaDoc returnValue = null;
810             try {
811                 returnValue = ReflectionHelper.makeStructureType((JavaStructureType)type,
812                 this.getRuntimeClassLoader(),this.getPackageName());
813             } catch(WebServiceReflectionException wsre) {
814                 Throwable JavaDoc cause = wsre.getCause();
815                 ErrorManager.getDefault().notify(cause);
816                 ErrorManager.getDefault().log(this.getClass().getName() +
817                 ": Error trying to do Class.forName on: " + packageName + "." + type.getFormalName() + "WebServiceReflectionException=" + cause);
818                 return null;
819             }
820
821             return returnValue;
822         }
823         /**
824          * If we have an Enumeration Type, instantiate the default as the first of the entries.
825          */

826         else if(type instanceof JavaEnumerationType) {
827             Object JavaDoc returnValue = null;
828             try {
829                 returnValue = ReflectionHelper.makeEnumerationType((JavaEnumerationType)type,
830                 this.getRuntimeClassLoader(),this.getPackageName());
831             } catch(WebServiceReflectionException wsre) {
832                 Throwable JavaDoc cause = wsre.getCause();
833                 ErrorManager.getDefault().notify(cause);
834                 ErrorManager.getDefault().log(this.getClass().getName() +
835                 ": Error trying to create an Enumeration Type: " + packageName + "." + type.getFormalName() + "ClassNWebServiceReflectionExceptionotFoundException=" + cause);
836                 return null;
837             }
838
839             return returnValue;
840
841
842         }
843         /**
844          * If we have an Array Type, create an ArrayList
845          */

846         else if(type instanceof JavaArrayType) {
847             return new ArrayList();
848         }
849         /**
850          * Must be a JavaSimpleType
851          */

852         else {
853
854
855             String JavaDoc currentType = type.getRealName();
856
857
858             if(currentType.equals(int.class.getName()) ||
859             currentType.equals(Integer JavaDoc.class.getName())) {
860                 value = new Integer JavaDoc(0);
861             } else if(currentType.equals(byte.class.getName()) ||
862             currentType.equals(Byte JavaDoc.class.getName())) {
863                 value = new Byte JavaDoc("0");
864             } else if("byte[]".equals(currentType)) {
865                 value = new Byte JavaDoc[]{};
866             } else if(currentType.equals(boolean.class.getName()) ||
867             currentType.equals(Boolean JavaDoc.class.getName())) {
868                 value = new Boolean JavaDoc(false);
869             } else if(currentType.equals(float.class.getName()) ||
870             currentType.equals(Float JavaDoc.class.getName())) {
871                 value = new Float JavaDoc(0);
872             } else if(currentType.equals(double.class.getName()) ||
873             currentType.equals(Double JavaDoc.class.getName())) {
874                 value = new Double JavaDoc(0);
875             } else if(currentType.equals(long.class.getName()) ||
876             currentType.equals(Long JavaDoc.class.getName())) {
877                 value = new Long JavaDoc(0L);
878             } else if(currentType.equals(short.class.getName()) ||
879             currentType.equals(Short JavaDoc.class.getName())) {
880                 value = new Short JavaDoc("0");
881             } else if(currentType.equals(String JavaDoc.class.getName())) {
882                 value = "";
883             } else if(currentType.equals(BigDecimal JavaDoc.class.getName())) {
884                 value = new BigDecimal JavaDoc("0");
885             } else if(currentType.equals(BigInteger JavaDoc.class.getName())) {
886                 value = new BigInteger JavaDoc("0");
887             } else if(currentType.equals(URI.class.getName())) {
888                 try {
889                     value = new URI("http://java.sun.com");
890                 } catch(URISyntaxException uri) {
891
892                 }
893             } else if(currentType.equals(Calendar.class.getName())) {
894                 value = Calendar.getInstance();
895             } else if(currentType.equalsIgnoreCase(Date.class.getName())) {
896                 value = new Date();
897             }
898
899             return value;
900         }
901     }
902
903     // Variables declaration - do not modify
904
private javax.swing.JPanel JavaDoc btnPanel;
905     private javax.swing.JButton JavaDoc btnSubmit;
906     private javax.swing.JLabel JavaDoc jLabel1;
907     private javax.swing.JLabel JavaDoc jLabel2;
908     private javax.swing.JPanel JavaDoc jPanel4;
909     private javax.swing.JSplitPane JavaDoc jSplitPane1;
910     private javax.swing.JLabel JavaDoc lblTitle;
911     private javax.swing.JPanel JavaDoc pnlLabel;
912     private javax.swing.JPanel JavaDoc pnlParameter;
913     private javax.swing.JPanel JavaDoc pnlResults;
914     private javax.swing.JScrollPane JavaDoc scrollPaneParameter;
915     private javax.swing.JScrollPane JavaDoc scrollPaneResults;
916     // End of variables declaration
917
// private TreeTableView treeTableView;
918
private Outline outline;
919 }
920
Popular Tags