001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.saas.ui.wizards;
043:
044: import com.sun.tools.ws.processor.model.java.JavaMethod;
045: import com.sun.tools.ws.processor.model.java.JavaParameter;
046: import com.sun.tools.ws.processor.model.java.JavaType;
047: import java.awt.Component;
048: import java.awt.Container;
049: import java.awt.Cursor;
050: import java.awt.Dialog;
051: import java.awt.FocusTraversalPolicy;
052: import java.awt.event.ActionEvent;
053: import java.awt.event.ActionListener;
054: import java.awt.event.FocusEvent;
055: import java.awt.event.FocusListener;
056: import java.awt.event.MouseAdapter;
057: import java.awt.event.MouseEvent;
058: import java.awt.event.WindowAdapter;
059: import java.awt.event.WindowEvent;
060: import java.io.File;
061: import java.io.IOException;
062: import java.net.*;
063: import java.util.*;
064: import java.util.LinkedList;
065: import javax.swing.JButton;
066: import javax.swing.JPanel;
067: import javax.swing.JTable;
068: import javax.swing.SwingUtilities;
069: import javax.swing.table.TableModel;
070: import javax.swing.tree.DefaultMutableTreeNode;
071: import javax.swing.tree.DefaultTreeModel;
072: import javax.swing.table.TableModel;
073: import javax.swing.event.TableModelEvent;
074: import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlPort;
075: import org.netbeans.modules.websvc.saas.model.WsdlSaas;
076: import org.netbeans.modules.websvc.saas.model.WsdlSaasMethod;
077: import org.netbeans.modules.websvc.saas.spi.websvcmgr.WsdlServiceProxyDescriptor;
078: import org.netbeans.modules.websvc.saas.util.TypeUtil;
079: import org.netbeans.swing.outline.DefaultOutlineModel;
080: import org.netbeans.swing.outline.Outline;
081: import org.netbeans.swing.outline.OutlineModel;
082:
083: import org.openide.DialogDescriptor;
084: import org.openide.DialogDisplayer;
085: import org.openide.ErrorManager;
086: import org.openide.NotifyDescriptor;
087: import org.openide.util.HelpCtx;
088: import org.openide.util.NbBundle;
089:
090: /**
091: * Dialog that tests JAX-WS client methods
092: *
093: * @author David Botterill
094: */
095: public class TestWebServiceMethodDlg extends JPanel implements
096: ActionListener, MethodTaskListener {
097: private Dialog dialog;
098: private DialogDescriptor dlg = null;
099: private String okString = NbBundle.getMessage(this .getClass(),
100: "CLOSE");
101: /**
102: * The runtimeClassLoader should be used when running the web service client. This classloader
103: * only includes the necessary runtime jars for JAX-RPC to run. The classloader does NOT have a
104: * parent to delegate to. I did this because of Xerces classloader clashes with other netbeans
105: * modules.
106: * -David Botterill 4/21/2004
107: */
108: private URLClassLoader runtimeClassLoader;
109:
110: private DefaultMutableTreeNode parameterRootNode = new DefaultMutableTreeNode();
111: private DefaultMutableTreeNode resultRootNode = new DefaultMutableTreeNode();
112: private final WsdlSaas wsData;
113: private final WsdlPort port;
114: private final JavaMethod method;
115: private MethodTask methodTask;
116:
117: /** Creates new form TestWebServiceMethodDlg */
118: public TestWebServiceMethodDlg(WsdlSaasMethod saasMethod) {
119: method = saasMethod.getJavaMethod();
120: wsData = saasMethod.getSaas();
121: port = saasMethod.getWsdlPort();
122: assert wsData.getWsdlData().getJaxWsDescriptor() != null;
123:
124: initComponents();
125: myInitComponents();
126:
127: this .lblTitle.setText(NbBundle.getMessage(this .getClass(),
128: "TEST_WEBSVC_LABEL")
129: + " " + method.getName());
130: }
131:
132: /**
133: * This method returns the classloader of the Jar file containing the web service for which we are testing the methods.
134: * This class loader should be used for the runtime environment when invoking a web service.
135: * TODO: determine if the tree components should get the class loader here, store the classloader in the tree nodes, or pass
136: * to the tree component constructors.
137: *@returns URLClassLoader - the class loader of the Jar file for the web service with the methods to test.
138: */
139: private URLClassLoader getRuntimeClassLoader() {
140: if (null == runtimeClassLoader) {
141:
142: /**
143: * First add the URL to the jar file for this web service.
144: */
145: try {
146: List<URL> urlList = null;
147:
148: urlList = TypeUtil.buildClasspath(null, true); // NOI18N
149:
150: WsdlServiceProxyDescriptor descriptor = wsData
151: .getWsdlData().getJaxWsDescriptor();
152: for (WsdlServiceProxyDescriptor.JarEntry entry : descriptor
153: .getJars()) {
154: if (entry
155: .getType()
156: .equals(
157: WsdlServiceProxyDescriptor.JarEntry.PROXY_JAR_TYPE)) {
158: File jarFile = new File(descriptor
159: .getXmlDescriptorFile().getParent(),
160: entry.getName());
161: File tmpJarFile = createTempCopy(jarFile);
162:
163: urlList.add(tmpJarFile.toURI().toURL());
164: }
165: }
166:
167: URL[] urls = (URL[]) urlList.toArray(new URL[0]);
168: /**
169: * Delegate to the module's classloader since core/startup/NbInstaller
170: * overrides the JAX-WS 2.0 jars present in JDK 6
171: */
172:
173: runtimeClassLoader = new URLClassLoader(urls, this
174: .getClass().getClassLoader());
175: } catch (IOException mfu) {
176: ErrorManager.getDefault().notify(mfu);
177: ErrorManager.getDefault().log(
178: this .getClass().getName() + ":IOException="
179: + mfu);
180: return null;
181: }
182: }
183:
184: return runtimeClassLoader;
185: }
186:
187: private File createTempCopy(File src) {
188: try {
189: java.io.File tempFile = java.io.File.createTempFile(
190: "proxyjar", "jar");
191: java.nio.channels.FileChannel inChannel = new java.io.FileInputStream(
192: src).getChannel();
193: java.nio.channels.FileChannel outChannel = new java.io.FileOutputStream(
194: tempFile).getChannel();
195: inChannel.transferTo(0, inChannel.size(), outChannel);
196:
197: inChannel.close();
198: outChannel.close();
199: return tempFile;
200: } catch (IOException ex) {
201: ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
202: return null;
203: }
204: }
205:
206: public void displayDialog() {
207:
208: dlg = new DialogDescriptor(this , NbBundle.getMessage(this
209: .getClass(), "TEST_WEB_SERVICE_METHOD"), false,
210: NotifyDescriptor.OK_CANCEL_OPTION,
211: DialogDescriptor.OK_OPTION,
212: DialogDescriptor.DEFAULT_ALIGN, this .getHelpCtx(), this );
213: dlg.setOptions(new Object[] { okButton });
214: dialog = DialogDisplayer.getDefault().createDialog(dlg);
215: /**
216: * After the window is opened, set the focus to the Get information button.
217: */
218:
219: final JPanel this Panel = this ;
220: dialog.addWindowListener(new WindowAdapter() {
221: public void windowOpened(WindowEvent e) {
222: SwingUtilities.invokeLater(new Runnable() {
223: public void run() {
224: btnSubmit.requestFocus();
225: this Panel.getRootPane().setDefaultButton(
226: btnSubmit);
227: }
228: });
229: }
230: });
231:
232: /**
233: * Fix for Bug: 6217545
234: * Need to know what the normal cursor is so we can reset it when
235: * the dialog is closed.
236: * - David Botterill 1/14/2005
237: *
238: */
239: normalCursor = dialog.getCursor();
240: /**
241: * Fix for Bug: 6217545
242: * Set the MouseListener for the OK button to a special adapter that will
243: * make the cursor look normal ALWAYS when over the OK button.
244: * - David Botterill 1/14/2005
245: */
246: BusyMouseAdapter mouseAdapter = new BusyMouseAdapter(
247: normalCursor);
248: okButton.addMouseListener(mouseAdapter);
249:
250: dialog.show();
251: }
252:
253: public HelpCtx getHelpCtx() {
254: return new HelpCtx(
255: "projrave_ui_elements_server_nav_test_websvcdb");
256: }
257:
258: /** This method is called from within the constructor to
259: * initialize the form.
260: * WARNING: Do NOT modify this code. The content of this method is
261: * always regenerated by the Form Editor.
262: */
263: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
264: private void initComponents() {
265:
266: jSplitPane1 = new javax.swing.JSplitPane();
267: pnlParameter = new javax.swing.JPanel();
268: pnlLabel = new javax.swing.JPanel();
269: lblTitle = new javax.swing.JLabel();
270: lblParameters = new javax.swing.JLabel();
271: scrollPaneParameter = new javax.swing.JScrollPane();
272: btnPanel = new javax.swing.JPanel();
273: btnSubmit = new javax.swing.JButton();
274: pnlResults = new javax.swing.JPanel();
275: lblResults = new javax.swing.JLabel();
276: scrollPaneResults = new javax.swing.JScrollPane();
277:
278: setToolTipText("");
279: setPreferredSize(new java.awt.Dimension(600, 450));
280: setLayout(new java.awt.BorderLayout());
281:
282: jSplitPane1.setDividerLocation(250);
283: jSplitPane1
284: .setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
285:
286: pnlParameter.setBorder(javax.swing.BorderFactory
287: .createEmptyBorder(12, 12, 5, 12));
288: pnlParameter.setLayout(new java.awt.BorderLayout());
289:
290: pnlLabel.setLayout(new java.awt.GridLayout(2, 0));
291:
292: lblTitle.setFont(lblTitle.getFont().deriveFont(
293: lblTitle.getFont().getStyle() | java.awt.Font.BOLD,
294: lblTitle.getFont().getSize() - 2));
295: lblTitle
296: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
297: lblTitle.setText(org.openide.util.NbBundle.getMessage(
298: TestWebServiceMethodDlg.class,
299: "TEST_WEB_SERVICE_METHOD")); // NOI18N
300: pnlLabel.add(lblTitle);
301: lblTitle.getAccessibleContext().setAccessibleName(
302: org.openide.util.NbBundle.getMessage(
303: TestWebServiceMethodDlg.class,
304: "TestWebServiceMethodDlg.lblTitle.ACC_name")); // NOI18N
305: lblTitle.getAccessibleContext().setAccessibleDescription(
306: org.openide.util.NbBundle.getMessage(
307: TestWebServiceMethodDlg.class,
308: "TestWebServiceMethodDlg.lblTitle.ACC_desc")); // NOI18N
309:
310: lblParameters.setFont(lblParameters.getFont().deriveFont(
311: lblParameters.getFont().getSize() - 4f));
312: lblParameters
313: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
314: lblParameters.setText(org.openide.util.NbBundle.getMessage(
315: TestWebServiceMethodDlg.class,
316: "TEST_WEBSVC_INSTRUCTIONS")); // NOI18N
317: lblParameters.setToolTipText(org.openide.util.NbBundle
318: .getMessage(TestWebServiceMethodDlg.class,
319: "TestWebServiceMethodDlg.jLabel1.tooltip")); // NOI18N
320: pnlLabel.add(lblParameters);
321: lblParameters.getAccessibleContext().setAccessibleName(
322: org.openide.util.NbBundle.getMessage(
323: TestWebServiceMethodDlg.class,
324: "TestWebServiceMethodDlg.jLabel1.ACC_name")); // NOI18N
325: lblParameters.getAccessibleContext().setAccessibleDescription(
326: org.openide.util.NbBundle.getMessage(
327: TestWebServiceMethodDlg.class,
328: "TestWebServiceMethodDlg.jLabel1.ACC_desc")); // NOI18N
329:
330: pnlParameter.add(pnlLabel, java.awt.BorderLayout.NORTH);
331: pnlLabel.getAccessibleContext().setAccessibleName(
332: org.openide.util.NbBundle.getMessage(
333: TestWebServiceMethodDlg.class,
334: "TestWebServiceMethodDlg.pnlLabel.ACC_name")); // NOI18N
335: pnlLabel.getAccessibleContext().setAccessibleDescription(
336: org.openide.util.NbBundle.getMessage(
337: TestWebServiceMethodDlg.class,
338: "TestWebServiceMethodDlg.pnlLabel.ACC_desc")); // NOI18N
339:
340: scrollPaneParameter.setToolTipText("");
341: pnlParameter.add(scrollPaneParameter,
342: java.awt.BorderLayout.CENTER);
343: scrollPaneParameter
344: .getAccessibleContext()
345: .setAccessibleName(
346: org.openide.util.NbBundle
347: .getMessage(
348: TestWebServiceMethodDlg.class,
349: "TestWebServiceMethodDlg.scrollPaneParameter.ACC_name")); // NOI18N
350: scrollPaneParameter
351: .getAccessibleContext()
352: .setAccessibleDescription(
353: org.openide.util.NbBundle
354: .getMessage(
355: TestWebServiceMethodDlg.class,
356: "TestWebServiceMethodDlg.scrollPaneParameter.ACC_desc")); // NOI18N
357:
358: btnSubmit.setMnemonic(org.openide.util.NbBundle.getMessage(
359: TestWebServiceMethodDlg.class,
360: "TestWebServiceMethodDlg.btnSubmit.ACC_mnemonic")
361: .charAt(0));
362: btnSubmit.setText(org.openide.util.NbBundle.getMessage(
363: TestWebServiceMethodDlg.class, "BUTTON_SUBMIT")); // NOI18N
364: btnSubmit.setToolTipText("");
365: btnSubmit
366: .addActionListener(new java.awt.event.ActionListener() {
367: public void actionPerformed(
368: java.awt.event.ActionEvent evt) {
369: btnSubmitActionPerformed(evt);
370: }
371: });
372: btnPanel.add(btnSubmit);
373: btnSubmit.getAccessibleContext().setAccessibleName(
374: org.openide.util.NbBundle.getMessage(
375: TestWebServiceMethodDlg.class,
376: "TestWebServiceMethodDlg.btnSubmit.ACC_name")); // NOI18N
377: btnSubmit.getAccessibleContext().setAccessibleDescription(
378: org.openide.util.NbBundle.getMessage(
379: TestWebServiceMethodDlg.class,
380: "TestWebServiceMethodDlg.btnSubmit.ACC_desc")); // NOI18N
381:
382: pnlParameter.add(btnPanel, java.awt.BorderLayout.SOUTH);
383: btnPanel.getAccessibleContext().setAccessibleName(
384: org.openide.util.NbBundle.getMessage(
385: TestWebServiceMethodDlg.class,
386: "TestWebServiceMethodDlg.btnPanel.ACC_name")); // NOI18N
387: btnPanel.getAccessibleContext().setAccessibleDescription(
388: org.openide.util.NbBundle.getMessage(
389: TestWebServiceMethodDlg.class,
390: "TestWebServiceMethodDlg.btnPanel.ACC_desc")); // NOI18N
391:
392: jSplitPane1.setLeftComponent(pnlParameter);
393: pnlParameter
394: .getAccessibleContext()
395: .setAccessibleName(
396: org.openide.util.NbBundle
397: .getMessage(
398: TestWebServiceMethodDlg.class,
399: "TestWebServiceMethodDlg.pnlParameter.ACC_name")); // NOI18N
400: pnlParameter
401: .getAccessibleContext()
402: .setAccessibleDescription(
403: org.openide.util.NbBundle
404: .getMessage(
405: TestWebServiceMethodDlg.class,
406: "TestWebServiceMethodDlg.pnlParameter.ACC_desc")); // NOI18N
407:
408: pnlResults.setBorder(javax.swing.BorderFactory
409: .createEmptyBorder(5, 12, 5, 12));
410: pnlResults.setLayout(new java.awt.BorderLayout(0, 5));
411:
412: lblResults
413: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
414: lblResults.setText(org.openide.util.NbBundle.getMessage(
415: TestWebServiceMethodDlg.class, "RESULTS")); // NOI18N
416: lblResults.setToolTipText("");
417: pnlResults.add(lblResults, java.awt.BorderLayout.NORTH);
418: lblResults.getAccessibleContext().setAccessibleName(
419: org.openide.util.NbBundle.getMessage(
420: TestWebServiceMethodDlg.class,
421: "TestWebServiceMethodDlg.lblResults.ACC_name")); // NOI18N
422: lblResults.getAccessibleContext().setAccessibleDescription(
423: org.openide.util.NbBundle.getMessage(
424: TestWebServiceMethodDlg.class,
425: "TestWebServiceMethodDlg.lblResults.ACC_desc")); // NOI18N
426:
427: scrollPaneResults.setToolTipText("");
428: pnlResults.add(scrollPaneResults, java.awt.BorderLayout.CENTER);
429: scrollPaneResults
430: .getAccessibleContext()
431: .setAccessibleName(
432: org.openide.util.NbBundle
433: .getMessage(
434: TestWebServiceMethodDlg.class,
435: "TestWebServiceMethodDlg.scrollPaneResults.ACC_name")); // NOI18N
436: scrollPaneResults
437: .getAccessibleContext()
438: .setAccessibleDescription(
439: org.openide.util.NbBundle
440: .getMessage(
441: TestWebServiceMethodDlg.class,
442: "TestWebServiceMethodDlg.scrollPaneResults.ACC_desc")); // NOI18N
443:
444: jSplitPane1.setRightComponent(pnlResults);
445: pnlResults.getAccessibleContext().setAccessibleName(
446: org.openide.util.NbBundle.getMessage(
447: TestWebServiceMethodDlg.class,
448: "TestWebServiceMethodDlg.pnResults.ACC_name")); // NOI18N
449: pnlResults.getAccessibleContext().setAccessibleDescription(
450: org.openide.util.NbBundle.getMessage(
451: TestWebServiceMethodDlg.class,
452: "TestWebServiceMethodDlg.pnResults.ACC_desc")); // NOI18N
453:
454: add(jSplitPane1, java.awt.BorderLayout.CENTER);
455: jSplitPane1
456: .getAccessibleContext()
457: .setAccessibleName(
458: org.openide.util.NbBundle
459: .getMessage(
460: TestWebServiceMethodDlg.class,
461: "TestWebServiceMethodDlg.jsplintPane1.ACC_name")); // NOI18N
462: jSplitPane1
463: .getAccessibleContext()
464: .setAccessibleDescription(
465: org.openide.util.NbBundle
466: .getMessage(
467: TestWebServiceMethodDlg.class,
468: "TestWebServiceMethodDlg.jsplintPane1.ACC_desc")); // NOI18N
469:
470: getAccessibleContext().setAccessibleName(
471: org.openide.util.NbBundle.getMessage(
472: TestWebServiceMethodDlg.class,
473: "TestWebServiceMethodDlg.main.ACC_name")); // NOI18N
474: getAccessibleContext().setAccessibleDescription(
475: org.openide.util.NbBundle.getMessage(
476: TestWebServiceMethodDlg.class,
477: "TestWebServiceMethodDlg.main.ACC_desc")); // NOI18N
478: }// </editor-fold>//GEN-END:initComponents
479:
480: private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
481: dialog.setCursor(new Cursor(Cursor.WAIT_CURSOR));
482: invokeMethod();
483: }//GEN-LAST:event_btnSubmitActionPerformed
484:
485: private void invokeMethod() {
486: /**
487: * Steps to call the method.
488: * 1. Get the parameter values from the tree
489: * 2. Get the client wrapper class
490: * 3. Get the method.
491: * 4. call the Method with the parameter values
492: * 5. Display the return value.
493: */
494:
495: /**
496: * Get the parameter values from the tree. The parameters will be the children of the root node only. Any children
497: * of the parameter nodes are values used to derive the parameter values. This means only the first children of the root
498: * node will be used a parameters. The logic to "roll-up" a parameter value is left to the TypeCellEditor class.
499: */
500:
501: /**
502: * Use a LinkedList because we care about the order of the parameters.
503: */
504: LinkedList<Object> paramList = new LinkedList<Object>();
505: for (int ii = 0; null != this .getParamterRootNode()
506: && ii < this .getParamterRootNode().getChildCount(); ii++) {
507: DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) this
508: .getParamterRootNode().getChildAt(ii);
509: TypeNodeData nodeData = (TypeNodeData) childNode
510: .getUserObject();
511: Object parameterValue = nodeData.getTypeValue();
512:
513: paramList.add(parameterValue);
514: }
515:
516: /**
517: * specify the wrapper client class name for this method.
518: */
519: String clientClassName = wsData.getWsdlModel().getJavaName();
520:
521: /**
522: * Fix for Bug: 6217545
523: * We need to run the method in a separate thread so the user can cancel if the method call
524: * locks up.
525: * First we need to create the thread, then register for a listener so we can get notified when the method's
526: * finished.
527: * -David Botterill 1/14/2005
528: */
529: methodTask = new MethodTask(clientClassName, paramList,
530: this .method, this .getRuntimeClassLoader());
531:
532: methodTask.registerListener(this );
533:
534: Thread methodThread = new Thread(methodTask);
535:
536: methodThread.start();
537: }
538:
539: public void methodFinished(Object inReturnedObject,
540: LinkedList inParamList) {
541: dialog.setCursor(normalCursor);
542:
543: showResults(inReturnedObject);
544:
545: /**
546: * Fix for Bug#: 5059732
547: * Now we need to also set the parameter values in the tree nodes since they may have changed due
548: * to the support for pass by reference ("Holders").
549: * - David Botterill 8/12/2004
550: */
551:
552: for (int ii = 0; null != this .getParamterRootNode()
553: && ii < this .getParamterRootNode().getChildCount(); ii++) {
554: DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) this
555: .getParamterRootNode().getChildAt(ii);
556: TypeNodeData nodeData = (TypeNodeData) childNode
557: .getUserObject();
558: nodeData.setTypeValue(inParamList.get(ii));
559: /**
560: * We really only care about Holder types from here since they are the only type of parameter that
561: * can have the value changed by the endpoint service.
562: */
563: String topNodeType = nodeData.getTypeClass();
564: if (ReflectionHelper.isHolder(topNodeType)) {
565: ((ParameterTreeNode) childNode).updateChildren();
566: }
567: }
568: /**
569: * Update the table since we may have changed some tree node values.
570: */
571: parameterOutline.tableChanged(new TableModelEvent(
572: (TableModel) parameterOutline.getOutlineModel()
573: .getRowNodeModel()));
574:
575: }
576:
577: private void showResults(Object inResultObject) {
578: /**
579: * Create a tree of the result object types.
580: */
581: try {
582: resultOutline = loadResultTreeTable(this .method,
583: inResultObject);
584: resultOutline.getTableHeader().setReorderingAllowed(false);
585: resultOutline
586: .getAccessibleContext()
587: .setAccessibleName(
588: org.openide.util.NbBundle
589: .getMessage(
590: TestWebServiceMethodDlg.class,
591: "TestWebServiceMethodDlg.resultOutline.ACC_name"));
592: resultOutline
593: .getAccessibleContext()
594: .setAccessibleDescription(
595: org.openide.util.NbBundle
596: .getMessage(
597: TestWebServiceMethodDlg.class,
598: "TestWebServiceMethodDlg.resultOutline.ACC_desc"));
599: addFocusListener(resultOutline);
600:
601: lblResults.setLabelFor(resultOutline);
602:
603: scrollPaneResults.setViewportView(resultOutline);
604: } catch (WebServiceReflectionException ex) {
605: Throwable cause = ex.getCause();
606: ErrorManager.getDefault().notify(cause);
607: ErrorManager.getDefault().log(
608: this .getClass().getName()
609: + ": WebServiceReflectionException="
610: + cause);
611: }
612: }
613:
614: private void myInitComponents() {
615: okButton.setText(okString);
616:
617: /**
618: * Now set up the Nodes for the TreeTableView
619: */
620: if (null == this .method) {
621: return;
622: }
623:
624: try {
625: NodeHelper.createInstance(getRuntimeClassLoader());
626:
627: parameterOutline = loadParameterTreeTable(this .method);
628:
629: // Turn off the reordering
630: /**
631: * Add it to the correct Panel.
632: */
633:
634: scrollPaneParameter.setViewportView(parameterOutline);
635:
636: /**
637: * Set up Accessibility stuff for not UI-Editor stuff.
638: *
639: */
640:
641: okButton
642: .getAccessibleContext()
643: .setAccessibleName(
644: org.openide.util.NbBundle
645: .getMessage(
646: TestWebServiceMethodDlg.class,
647: "TestWebServiceMethodDlg.okButton.ACC_name"));
648: okButton
649: .getAccessibleContext()
650: .setAccessibleDescription(
651: org.openide.util.NbBundle
652: .getMessage(
653: TestWebServiceMethodDlg.class,
654: "TestWebServiceMethodDlg.okButton.ACC_desc"));
655: okButton.setMnemonic(org.openide.util.NbBundle.getMessage(
656: TestWebServiceMethodDlg.class,
657: "TestWebServiceMethodDlg.okButton.ACC_mnemonic")
658: .charAt(0));
659:
660: parameterOutline
661: .getAccessibleContext()
662: .setAccessibleName(
663: org.openide.util.NbBundle
664: .getMessage(
665: TestWebServiceMethodDlg.class,
666: "TestWebServiceMethodDlg.parameterOutline.ACC_name"));
667: parameterOutline
668: .getAccessibleContext()
669: .setAccessibleDescription(
670: org.openide.util.NbBundle
671: .getMessage(
672: TestWebServiceMethodDlg.class,
673: "TestWebServiceMethodDlg.parameterOutline.ACC_desc"));
674: lblParameters.setLabelFor(parameterOutline);
675: addFocusListener(parameterOutline);
676: } catch (WebServiceReflectionException ex) {
677: Throwable cause = ex.getCause();
678: ErrorManager.getDefault().notify(cause);
679: ErrorManager.getDefault().log(
680: this .getClass().getName()
681: + ": WebServiceReflectionException="
682: + cause);
683: }
684: }
685:
686: private void addFocusListener(final JTable table) {
687: // fixes tab cycle when the table is empty
688: table.addFocusListener(new FocusListener() {
689: public void focusGained(FocusEvent evt) {
690: Container cycleRoot = table.getFocusCycleRootAncestor();
691: FocusTraversalPolicy policy = table
692: .getFocusTraversalPolicy();
693: if (policy == null && cycleRoot != null) {
694: policy = cycleRoot.getFocusTraversalPolicy();
695: }
696:
697: if (table.getRowCount() == 0 && policy != null) {
698: Component target = policy.getComponentAfter(
699: cycleRoot, table);
700: if (target != null
701: && target == evt.getOppositeComponent()) {
702: target = policy.getComponentBefore(cycleRoot,
703: table);
704: }
705:
706: if (target != null) {
707: target.requestFocusInWindow();
708: }
709: }
710: }
711:
712: public void focusLost(FocusEvent evt) {
713: }
714: });
715: }
716:
717: private DefaultMutableTreeNode getParamterRootNode() {
718: return parameterRootNode;
719: }
720:
721: private void setParameterRootNode(DefaultMutableTreeNode inNode) {
722: parameterRootNode = inNode;
723: }
724:
725: private DefaultMutableTreeNode getResultRootNode() {
726: return resultRootNode;
727: }
728:
729: private void setResultRootNode(DefaultMutableTreeNode inNode) {
730: resultRootNode = inNode;
731: }
732:
733: private Outline loadResultTreeTable(JavaMethod inMethod,
734: Object inResultObject) throws WebServiceReflectionException {
735: if (null == inMethod) {
736: return null;
737: }
738: JavaType currentType = inMethod.getReturnType();
739: String typeName = currentType.getRealName();
740: TypeNodeData data = ReflectionHelper.createTypeData(typeName,
741: inResultObject);
742:
743: DefaultMutableTreeNode node = NodeHelper.getInstance()
744: .createResultNodeFromData(data);
745:
746: /**
747: * Make sure to create a new result root each time since the user can change the parameters and submit many
748: * times.
749: */
750: this .setResultRootNode(new DefaultMutableTreeNode());
751: /**
752: * Add it to the root.
753: */
754: this .getResultRootNode().add(node);
755:
756: DefaultTreeModel treeModel = new DefaultTreeModel(this
757: .getResultRootNode());
758: ResultRowModel rowModel = new ResultRowModel();
759: OutlineModel outlineModel = DefaultOutlineModel
760: .createOutlineModel(treeModel, rowModel, false);
761: outlineModel.setNodeColumnName(NbBundle.getMessage(this
762: .getClass(), "TYPE_COLUMN_NAME")); // NOI18N
763: Outline returnOutline = new Outline(outlineModel);
764: ResultCellEditor cellEditor = new ResultCellEditor(
765: runtimeClassLoader);
766: returnOutline.setDefaultEditor(Object.class, cellEditor);
767: returnOutline.setRootVisible(false);
768:
769: returnOutline.setRenderDataProvider(new TypeDataProvider());
770:
771: return returnOutline;
772: }
773:
774: private Outline loadParameterTreeTable(JavaMethod inMethod)
775: throws WebServiceReflectionException {
776: if (null == inMethod) {
777: return null;
778: }
779:
780: List<JavaParameter> parameters = inMethod.getParametersList();
781: for (JavaParameter currentParameter : parameters) {
782: /**
783: * Add all Parameter's to the root tree node.
784: */
785: JavaType currentType = currentParameter.getType();
786:
787: String typeName = currentType.getRealName();
788: String typeParamName = currentParameter.getName();
789:
790: if (currentParameter.isHolder()) {
791: typeName = "javax.xml.ws.Holder<" + typeName + ">"; // NOI18N
792: }
793:
794: TypeNodeData data = ReflectionHelper.createTypeData(
795: typeName, typeParamName);
796: data.setTypeValue(NodeHelper.getInstance()
797: .getParameterDefaultValue(data));
798: if (currentParameter.isHolder()) {
799: if (currentParameter.getParameter().isIN())
800: data.setHolderType(TypeNodeData.IN);
801: if (currentParameter.getParameter().isOUT())
802: data.setHolderType(TypeNodeData.OUT);
803: if (currentParameter.getParameter().isINOUT())
804: data.setHolderType(TypeNodeData.IN_OUT);
805: }
806:
807: DefaultMutableTreeNode node = NodeHelper.getInstance()
808: .createNodeFromData(data);
809:
810: /**
811: * Add it to the root.
812: */
813: this .getParamterRootNode().add(node);
814: }
815:
816: DefaultTreeModel treeModel = new DefaultTreeModel(this
817: .getParamterRootNode());
818: rowModel = new TypeRowModel(this .getRuntimeClassLoader());
819: OutlineModel outlineModel = DefaultOutlineModel
820: .createOutlineModel(treeModel, rowModel, false);
821: outlineModel.setNodeColumnName(NbBundle.getMessage(this
822: .getClass(), "TYPE_COLUMN_NAME"));
823: Outline returnOutline = new Outline(outlineModel);
824: TypeCellEditor cellEditor = new TypeCellEditor(
825: getRuntimeClassLoader());
826: returnOutline.setDefaultEditor(Object.class, cellEditor);
827: returnOutline.setRootVisible(false);
828: returnOutline.setRenderDataProvider(new TypeDataProvider());
829: /**
830: * Fix Bug 5052705. This setting will cause the cells values to take affect when
831: * the focus is lost. This will remove the requirement of hitting "ENTER" after
832: * entering a value in a cell to get the value to take affect.
833: */
834: returnOutline.putClientProperty("terminateEditOnFocusLost",
835: Boolean.TRUE); // NOI18N
836:
837: return returnOutline;
838: }
839:
840: public void actionPerformed(ActionEvent evt) {
841: String actionCommand = evt.getActionCommand();
842: if (actionCommand.equalsIgnoreCase(okString)) {
843: okButtonAction(evt);
844: }
845: }
846:
847: private void okButtonAction(ActionEvent evt) {
848: /**
849: * If the MethodTask is not null, the MethodTask
850: * thread may still be running so we need to tell
851: * it we've cancelled.
852: */
853: if (null != methodTask) {
854: methodTask.cancel();
855: }
856: dialog.setCursor(normalCursor);
857: dialog.dispose();
858: }
859:
860: // Variables declaration - do not modify//GEN-BEGIN:variables
861: private javax.swing.JPanel btnPanel;
862: private javax.swing.JButton btnSubmit;
863: private javax.swing.JSplitPane jSplitPane1;
864: private javax.swing.JLabel lblParameters;
865: private javax.swing.JLabel lblResults;
866: private javax.swing.JLabel lblTitle;
867: private javax.swing.JPanel pnlLabel;
868: private javax.swing.JPanel pnlParameter;
869: private javax.swing.JPanel pnlResults;
870: private javax.swing.JScrollPane scrollPaneParameter;
871: private javax.swing.JScrollPane scrollPaneResults;
872: // End of variables declaration//GEN-END:variables
873:
874: private JButton okButton = new JButton();
875: private Outline parameterOutline;
876: private Outline resultOutline;
877: private TypeRowModel rowModel;
878: private Cursor normalCursor;
879:
880: class MethodTask implements Runnable {
881:
882: private String clientClassName;
883: private LinkedList paramList;
884: private JavaMethod javaMethod;
885: private URLClassLoader urlClassLoader;
886: private ArrayList listeners = new ArrayList();
887: private boolean cancelled = false;
888:
889: MethodTask(String inClientClassName, LinkedList inParamList,
890: JavaMethod inJavaMethod, URLClassLoader inURLClassLoader) {
891: clientClassName = inClientClassName;
892: paramList = inParamList;
893: javaMethod = inJavaMethod;
894: urlClassLoader = inURLClassLoader;
895: }
896:
897: public void registerListener(MethodTaskListener inListener) {
898: if (!listeners.contains(inListener)) {
899: listeners.add(inListener);
900: }
901: }
902:
903: private void notifyListeners(Object returnedObject) {
904: Iterator listenerIterator = listeners.iterator();
905: MethodTaskListener currentListener = null;
906: while (listenerIterator.hasNext()) {
907: currentListener = (MethodTaskListener) listenerIterator
908: .next();
909: currentListener.methodFinished(returnedObject,
910: paramList);
911: }
912: }
913:
914: public void run() {
915: /**
916: * Now invoke the method using the ReflectionHelper.
917: */
918: Object returnObject = null;
919: try {
920: returnObject = ReflectionHelper.callMethodWithParams(
921: clientClassName, paramList, javaMethod,
922: urlClassLoader, wsData.getWsdlData(), port);
923: } catch (Exception wsre) {
924: if (!cancelled) {
925: Throwable exception = wsre;
926: if (wsre.getCause() instanceof java.lang.reflect.InvocationTargetException) {
927: exception = wsre.getCause();
928: }
929: MethodExceptionDialog errorDialog = new MethodExceptionDialog(
930: exception);
931: /**
932: * Notify the listeners so the cursor will be reset;
933: */
934: notifyListeners(null);
935: errorDialog.show();
936: }
937: return;
938: }
939:
940: notifyListeners(returnObject);
941: }
942:
943: public void cancel() {
944: cancelled = true;
945: }
946: }
947:
948: private static class BusyMouseAdapter extends MouseAdapter {
949: private Cursor normalCursor;
950:
951: public BusyMouseAdapter(Cursor inNormalCursor) {
952: normalCursor = inNormalCursor;
953: }
954:
955: public void mouseEntered(MouseEvent e) {
956: e.getComponent().setCursor(normalCursor);
957: }
958:
959: public void mouseExited(MouseEvent e) {
960: }
961: }
962: }
|