KickJava   Java API By Example, From Geeks To Geeks.

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


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.jaxrpc.Wsdl2Java;
23 import org.netbeans.modules.websvc.registry.model.WebServiceData;
24 import org.netbeans.modules.websvc.registry.model.WSPort;
25 import org.netbeans.modules.websvc.registry.model.WebServiceGroup;
26 import org.netbeans.modules.websvc.registry.model.WebServiceListModel;
27 import org.netbeans.modules.websvc.registry.nodes.WebServiceGroupCookie;
28 import org.netbeans.modules.websvc.registry.util.Util;
29 import org.netbeans.modules.websvc.registry.wsdl.WSDLInfo;
30
31 import com.sun.xml.rpc.processor.model.java.JavaMethod;
32 import com.sun.xml.rpc.processor.model.java.JavaParameter;
33 import com.sun.xml.rpc.processor.model.Port;
34 import com.sun.xml.rpc.processor.model.Operation;
35
36
37 import java.awt.BorderLayout JavaDoc;
38 import java.awt.Component JavaDoc;
39 import java.awt.Point JavaDoc;
40 import java.awt.Dialog JavaDoc;
41 import java.awt.Cursor JavaDoc;
42 import java.awt.Dimension JavaDoc;
43 import java.awt.FlowLayout JavaDoc;
44 import java.awt.GridBagConstraints JavaDoc;
45 import java.awt.GridBagLayout JavaDoc;
46 import java.awt.Insets JavaDoc;
47 import java.awt.Rectangle JavaDoc;
48 import java.awt.Toolkit JavaDoc;
49 import java.awt.event.ActionEvent JavaDoc;
50 import java.awt.event.ActionListener JavaDoc;
51 import java.awt.event.WindowAdapter JavaDoc;
52 import java.awt.event.WindowEvent JavaDoc;
53 import java.awt.event.MouseAdapter JavaDoc;
54 import java.awt.event.MouseEvent JavaDoc;
55 import java.awt.event.ItemEvent JavaDoc;
56 import java.awt.event.MouseListener JavaDoc;
57 import java.beans.XMLDecoder JavaDoc;
58 import java.beans.XMLEncoder JavaDoc;
59 import java.io.*;
60 import java.net.MalformedURLException JavaDoc;
61 import java.net.URL JavaDoc;
62 import java.net.URLClassLoader JavaDoc;
63 import java.awt.EventQueue JavaDoc;
64
65 import java.text.SimpleDateFormat JavaDoc;
66 import java.util.Date JavaDoc;
67 import java.util.Iterator JavaDoc;
68 import java.util.Set JavaDoc;
69 import java.util.HashSet JavaDoc;
70 import java.util.HashMap JavaDoc;
71 import java.util.StringTokenizer JavaDoc;
72 import java.util.LinkedList JavaDoc;
73
74 import java.lang.reflect.InvocationTargetException JavaDoc;
75
76 import javax.swing.*;
77 import javax.swing.border.EmptyBorder JavaDoc;
78 import javax.swing.event.HyperlinkEvent JavaDoc;
79 import javax.swing.event.HyperlinkListener JavaDoc;
80 import javax.swing.text.ComponentView JavaDoc;
81 import javax.swing.text.Element JavaDoc;
82 import javax.swing.text.View JavaDoc;
83 import javax.swing.text.Position.Bias;
84 import javax.swing.text.html.HTMLDocument JavaDoc;
85 import javax.swing.text.html.HTML JavaDoc;
86 import javax.swing.text.AttributeSet JavaDoc;
87 import javax.swing.text.BadLocationException JavaDoc;
88 import javax.swing.text.Document JavaDoc;
89 import javax.swing.text.html.HTMLEditorKit JavaDoc;
90 import javax.swing.text.html.HTML.Attribute;
91 import javax.swing.JOptionPane JavaDoc;
92
93 import org.openide.DialogDescriptor;
94 import org.openide.DialogDisplayer;
95 import org.openide.ErrorManager;
96 import org.openide.NotifyDescriptor;
97 import org.openide.NotifyDescriptor.Message;
98 import org.openide.awt.Mnemonics;
99 import org.openide.nodes.Node;
100 import org.openide.util.HelpCtx;
101 import org.openide.util.NbBundle;
102 import org.openide.util.RequestProcessor;
103 import org.openide.windows.WindowManager;
104
105
106
107
108
109
110 /**
111  * Enables searching for Web Services, via an URL, on the local file system
112  * or in some uddiRegistry (UDDI)
113  * @author Jeff Hoffman, Octavian Tanase, Winston Prakash
114  */

115 public class AddWebServiceDlg extends JPanel implements ActionListener JavaDoc, HyperlinkListener JavaDoc {
116     
117     /** A return status code - returned if Cancel button has been pressed */
118     public static final int RET_CANCEL = 0;
119     /** A return status code - returned if OK button has been pressed */
120     public static final int RET_OK = 1;
121     
122     private DialogDescriptor dlg = null;
123     private String JavaDoc addString = "ADD"; //NOI18N
124
private String JavaDoc cancelString = "CANCEL"; //NOI18N
125
private String JavaDoc copyString = "COPY"; //NOI18N
126
private String JavaDoc clearString = "CLEAR"; //NOI18N
127

128     /**
129      * currentMessages is a running string of what's displayed in the "results" JEditorPane.
130      */

131     private String JavaDoc currentMessages ="";
132     
133     /**
134      * currentWSDL is used to determine if the user is processing a new WSDL for reporting in the Results
135      */

136     private String JavaDoc currentWSDL="";
137     /**
138      * previousWSDL is used to determine if the user is processing a new WSDL for reporting in the Results
139      */

140     private String JavaDoc previousWSDL="";
141     
142     /** Keep a list of WSDL files in a properties files */
143     static final String JavaDoc WS_URL_PROPS = "ws_urls.xml"; // NOI18N
144

145     private static BufferedWriter outFile;
146     
147     private WSDLInfo currentWSDLInfo = null;
148     
149     private Dialog JavaDoc dialog;
150     
151     private Node invokingNode;
152     
153     Set JavaDoc webServicesToProcess = null;
154     
155     private static JFileChooser wsdlFileChooser;
156     
157     private String JavaDoc URL_WSDL_MSG = NbBundle.getMessage(AddWebServiceDlg.class, "URL_WSDL_MSG");
158     private String JavaDoc LOCAL_WSDL_MSG = NbBundle.getMessage(AddWebServiceDlg.class, "LOCAL_WSDL_MSG");
159     
160     MRUPersistenceManager persistenceManager = new MRUPersistenceManager();
161     
162     /**
163      * This HashMap will serve as a cache of Jar files for the WebServiceData for testing purposes so we
164      * don't have to regenerate the Jar file everytime we test a different method.
165      * This cache will only be used for testing the client.
166      *
167      * The cache is updated everytime a jar file has to be generated for a WebServiceData. The key for
168      * the cache will be the WSDL URL.
169      */

170     
171     HashMap JavaDoc jarCache = new HashMap JavaDoc();
172     
173     private JPanel emptyPanel = new JPanel();
174     private JPanel infoTextPanel = new JPanel();
175     private JPanel selectionContainer = new JPanel();
176     private JPanel selectionPanel = new JPanel();
177     private JPanel buttonPanel = new JPanel();
178     private JPanel buttonPanelContainer = new JPanel();
179     private JPanel centerPanel = new JPanel();
180     private JPanel messagePanel = new JPanel();
181     
182     private JButton cancelButton = new JButton();
183     private JButton localFileButton = new JButton();
184     private JButton addButton = new JButton();
185     private JButton uddiRegistryButton = new JButton();
186     private JButton getInfoButton = new JButton();
187     
188     private JButton httpProxyButton = new JButton();
189     
190     private JComboBox localFileComboBox = new JComboBox();
191     private JComboBox uddiRegistryComboBox = new JComboBox();
192     private JComboBox urlComboBox = new JComboBox();
193     
194     private JEditorPane infoTextArea = new JEditorPane();
195     private JScrollPane infoTextScrollPane = new JScrollPane();
196     
197     private JEditorPane messageTextArea = new JEditorPane();
198     private JScrollPane messageTextScrollPane = new JScrollPane();
199     
200     private JLabel infoTextlabel = new JLabel();
201     private JLabel messageTextlabel = new JLabel();
202     private JLabel jLabel1 = new JLabel();
203     
204     private JRadioButton localFileRadioButton = new JRadioButton();
205     private JRadioButton uddiRegistryRadioButton = new JRadioButton();
206     private JRadioButton urlRadioButton = new JRadioButton();
207     
208     private JPopupMenu resultsPopup = new JPopupMenu();
209     private JMenuItem copyMenuItem = new JMenuItem();
210     private JMenuItem clearMenuItem = new JMenuItem();
211     
212     private ButtonGroup selectionGroup = new ButtonGroup();
213     
214     private int returnStatus = RET_CANCEL;
215     
216     private WebServiceGroup websvcGroup;
217     
218     private SimpleDateFormat JavaDoc dateFormat = new SimpleDateFormat JavaDoc("MM/dd/yyyy HH:mm:ss");
219     
220     private HTMLDocument JavaDoc document = new HTMLDocument JavaDoc();
221     
222         
223     private void initAccessibility() {
224         infoTextlabel.setLabelFor(infoTextArea);
225         messageTextlabel.setLabelFor(messageTextArea);
226         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "ADD_WEB_SERVICE"));
227         localFileButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "BROWSE"));
228         urlRadioButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_URL"));
229         localFileRadioButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_LOCAL_FILE"));
230         httpProxyButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "SET_HTTP_PROXY"));
231         getInfoButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "GET"));
232     }
233     
234     /** Default Constructor, create a modal dialog */
235     public AddWebServiceDlg() {
236         this(true,null);
237     }
238     
239     /** Creates a dialog that facilitates the selection (and test) of a W/S */
240     public AddWebServiceDlg(boolean modal, Node node) {
241         invokingNode = node;
242         //websvcGroup = wsGroup;
243
initComponents();
244         initAccessibility();
245         
246         uddiRegistryComboBox.setRenderer(new WSListCellRenderer());
247         wsdlFileChooser = new JFileChooser();
248         WSDLFileFilter myFilter = new WSDLFileFilter();
249         wsdlFileChooser.setFileFilter(myFilter);
250         
251         enableControls();
252         persistenceManager.loadMRU();
253         setDefaults();
254     }
255     
256     public void displayDialog(){
257         
258         dlg = new DialogDescriptor(this, NbBundle.getMessage(AddWebServiceDlg.class, "ADD_WEB_SERVICE"),
259         false, NotifyDescriptor.OK_CANCEL_OPTION, DialogDescriptor.CANCEL_OPTION,
260         DialogDescriptor.DEFAULT_ALIGN, this.getHelpCtx(), this);
261         addButton.setEnabled(false);
262         dlg.setOptions(new Object JavaDoc[] { addButton, cancelButton });
263         dialog = DialogDisplayer.getDefault().createDialog(dlg);
264         /**
265          * After the window is opened, set the focus to the Get information button.
266          */

267         
268         final JPanel thisPanel = this;
269         dialog.addWindowListener( new WindowAdapter JavaDoc(){
270             public void windowOpened( WindowEvent JavaDoc e ){
271                 SwingUtilities.invokeLater(
272                 new Runnable JavaDoc() {
273                     public void run() {
274                         getInfoButton.requestFocus();
275                         thisPanel.getRootPane().setDefaultButton(getInfoButton);
276                     }
277                 });
278             }
279         });
280         
281         dialog.show();
282     }
283     
284     /** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
285     public int getReturnStatus() {
286         return returnStatus;
287     }
288     
289     private void cancelButtonAction(ActionEvent JavaDoc evt) {
290         returnStatus = RET_CANCEL;
291         closeDialog();
292     }
293     
294     private void closeDialog() {
295         
296         persistenceManager.saveMRU();
297         dialog.dispose();
298         
299     }
300     private void copyMenuItemAction(ActionEvent JavaDoc evt) {
301         messageTextArea.copy();
302     }
303     private void clearMenuItemAction(ActionEvent JavaDoc evt) {
304         currentMessages="";
305         messageTextArea.setText("");
306     }
307     
308     /** XXX once we implement context sensitive help, change the return */
309     public HelpCtx getHelpCtx() {
310         return new HelpCtx(AddWebServiceDlg.class);
311     }
312     
313     private void initComponents() {
314         GridBagConstraints JavaDoc gridBagConstraints;
315         
316         setLayout(new BorderLayout JavaDoc(5, 1));
317         
318         selectionContainer.setLayout(new BorderLayout JavaDoc());
319         
320         selectionContainer.setBorder(new EmptyBorder JavaDoc(new Insets JavaDoc(5, 5, 5, 5)));
321         jLabel1.setText(NbBundle.getMessage(this.getClass(), "SELECT_SOURCE"));
322         selectionContainer.add(jLabel1, BorderLayout.NORTH);
323         
324         selectionPanel.setLayout(new GridBagLayout JavaDoc());
325         
326         selectionPanel.setBorder(new EmptyBorder JavaDoc(new Insets JavaDoc(5, 5, 5, 5)));
327         Mnemonics.setLocalizedText(urlRadioButton,NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_URL") );
328         urlRadioButton.addActionListener(new ActionListener JavaDoc() {
329             public void actionPerformed(ActionEvent JavaDoc evt) {
330                 enableControls();
331             }
332         });
333         urlRadioButton.setSelected(true);
334         selectionGroup.add(urlRadioButton);
335         gridBagConstraints = new GridBagConstraints JavaDoc();
336         gridBagConstraints.gridx = 0;
337         gridBagConstraints.gridy = 0;
338         gridBagConstraints.anchor = GridBagConstraints.WEST;
339         gridBagConstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
340         selectionPanel.add(urlRadioButton, gridBagConstraints);
341         
342         urlComboBox.setEditable(true);
343         
344         
345         gridBagConstraints = new GridBagConstraints JavaDoc();
346         gridBagConstraints.gridx = 1;
347         gridBagConstraints.gridy = 0;
348         gridBagConstraints.gridwidth = 5;
349         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
350         gridBagConstraints.anchor = GridBagConstraints.WEST;
351         gridBagConstraints.weightx = 1.0;
352         gridBagConstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
353         selectionPanel.add(urlComboBox, gridBagConstraints);
354         
355         Mnemonics.setLocalizedText(localFileRadioButton,NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_LOCAL_FILE") );
356         localFileRadioButton.setSelected(false);
357         localFileRadioButton.addActionListener(new ActionListener JavaDoc() {
358             public void actionPerformed(ActionEvent JavaDoc evt) {
359                 enableControls();
360             }
361         });
362         selectionGroup.add(localFileRadioButton);
363         gridBagConstraints = new GridBagConstraints JavaDoc();
364         gridBagConstraints.gridx = 0;
365         gridBagConstraints.gridy = 1;
366         gridBagConstraints.anchor = GridBagConstraints.WEST;
367         gridBagConstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
368         selectionPanel.add(localFileRadioButton, gridBagConstraints);
369         
370         localFileComboBox.setEditable(true);
371         
372         gridBagConstraints = new GridBagConstraints JavaDoc();
373         gridBagConstraints.gridx = 1;
374         gridBagConstraints.gridy = 1;
375         gridBagConstraints.gridwidth = 5;
376         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
377         gridBagConstraints.anchor = GridBagConstraints.WEST;
378         gridBagConstraints.weightx = 1.0;
379         gridBagConstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
380         selectionPanel.add(localFileComboBox, gridBagConstraints);
381         
382         Mnemonics.setLocalizedText(localFileButton,NbBundle.getMessage(AddWebServiceDlg.class, "BROWSE"));
383         localFileButton.addActionListener(new ActionListener JavaDoc() {
384             public void actionPerformed(ActionEvent JavaDoc evt) {
385                 localFileButtonAction(evt);
386             }
387         });
388         gridBagConstraints = new GridBagConstraints JavaDoc();
389         gridBagConstraints.gridx = 6;
390         gridBagConstraints.gridy = 1;
391         gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
392         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
393         gridBagConstraints.anchor = GridBagConstraints.WEST;
394         gridBagConstraints.insets = new Insets JavaDoc(2, 2, 2, 2);
395         selectionPanel.add(localFileButton, gridBagConstraints);
396         
397         
398         Mnemonics.setLocalizedText(getInfoButton,NbBundle.getMessage(AddWebServiceDlg.class, "GET"));
399         getInfoButton.addActionListener(new ActionListener JavaDoc() {
400             public void actionPerformed(ActionEvent JavaDoc evt) {
401                 getInfoButtonAction(evt);
402             }
403         });
404         gridBagConstraints = new GridBagConstraints JavaDoc();
405         gridBagConstraints.gridx = 0;
406         gridBagConstraints.gridy = 2;
407         gridBagConstraints.gridwidth = 2;
408         gridBagConstraints.anchor = GridBagConstraints.WEST;
409         gridBagConstraints.insets = new Insets JavaDoc(5, 2, 5, 2);
410         selectionPanel.add(getInfoButton, gridBagConstraints);
411         
412         Mnemonics.setLocalizedText(httpProxyButton,NbBundle.getMessage(AddWebServiceDlg.class, "SET_HTTP_PROXY"));
413         httpProxyButton.addActionListener(new ActionListener JavaDoc() {
414             public void actionPerformed(ActionEvent JavaDoc evt) {
415                 new ProxySelectionDialog().show();
416             }
417         });
418         
419         gridBagConstraints = new GridBagConstraints JavaDoc();
420         gridBagConstraints.gridx = 6;
421         gridBagConstraints.gridy = 2;
422         gridBagConstraints.anchor = GridBagConstraints.EAST;
423         gridBagConstraints.insets = new Insets JavaDoc(5, 2, 5, 2);
424         selectionPanel.add(httpProxyButton, gridBagConstraints);
425         
426         selectionContainer.add(selectionPanel, BorderLayout.CENTER);
427         
428         add(selectionContainer, BorderLayout.NORTH);
429         
430         infoTextPanel.setLayout(new BorderLayout JavaDoc(5, 5));
431         
432         infoTextPanel.setBorder(new EmptyBorder JavaDoc(new Insets JavaDoc(5, 5, 5, 5)));
433         infoTextArea.setEditable(false);
434         /**
435          * The focus settings are to allow the text input fields to get focus during tabbing.
436          */

437         infoTextArea.setFocusable(false);
438         infoTextArea.setFocusCycleRoot(false);
439         infoTextArea.setContentType("text/html");
440         infoTextArea.addHyperlinkListener(this);
441         
442         infoTextScrollPane.setViewportView(infoTextArea);
443         
444         infoTextPanel.add(infoTextScrollPane, BorderLayout.CENTER);
445         
446         Mnemonics.setLocalizedText(infoTextlabel,NbBundle.getMessage(AddWebServiceDlg.class, "WEBSERVICE_INFORMATION"));
447         infoTextPanel.add(infoTextlabel, BorderLayout.NORTH);
448         
449         messagePanel.setLayout(new BorderLayout JavaDoc(5,5));
450         messagePanel.setBorder(new EmptyBorder JavaDoc(new Insets JavaDoc(5, 5, 5, 5)));
451         
452         messageTextArea.setEditable(false);
453         messageTextArea.setContentType("text/html");
454         messageTextArea.setToolTipText(NbBundle.getMessage(AddWebServiceDlg.class, "TOOLTIP_MESSAGEAREA"));
455         messageTextScrollPane.setViewportView(messageTextArea);
456         
457         messagePanel.add(messageTextScrollPane, BorderLayout.CENTER);
458         org.openide.awt.Mnemonics.setLocalizedText(messageTextlabel, NbBundle.getMessage(AddWebServiceDlg.class, "RESULTS"));
459         
460         messagePanel.add(messageTextlabel, BorderLayout.NORTH);
461         
462         centerPanel.setLayout(new BorderLayout JavaDoc(5,5));
463         
464         centerPanel.add(infoTextPanel, BorderLayout.CENTER);
465         centerPanel.add(messagePanel, BorderLayout.SOUTH);
466         
467         add(centerPanel, BorderLayout.CENTER);
468         
469         Mnemonics.setLocalizedText(addButton,NbBundle.getMessage(AddWebServiceDlg.class, "Add"));
470         addButton.setActionCommand(addString);
471         Mnemonics.setLocalizedText(cancelButton,NbBundle.getMessage(AddWebServiceDlg.class, "CANCEL"));
472         cancelButton.setActionCommand(cancelString);
473         buttonPanel.setLayout(new FlowLayout JavaDoc(FlowLayout.RIGHT));
474         buttonPanel.add(addButton);
475         buttonPanel.add(cancelButton);
476         
477         Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
478         setBounds((screenSize.width-400)/2, (screenSize.height-400)/2, 400, 400);
479         
480         
481         /**
482          * set up the context menu for the results area.
483          */

484         copyMenuItem.setText(NbBundle.getMessage(AddWebServiceDlg.class, "CONTEXTMENU_COPY"));
485         copyMenuItem.setActionCommand(copyString);
486         copyMenuItem.addActionListener(this);
487         resultsPopup.add(copyMenuItem);
488         
489         clearMenuItem.setText(NbBundle.getMessage(AddWebServiceDlg.class, "CONTEXTMENU_CLEAR"));
490         clearMenuItem.setActionCommand(clearString);
491         clearMenuItem.addActionListener(this);
492         resultsPopup.add(clearMenuItem);
493         MouseListener JavaDoc popupListener = new PopupListener();
494         messageTextArea.addMouseListener(popupListener);
495         
496         
497     }
498     
499     private void enableControls(){
500         boolean enabled = false;
501         enabled = urlRadioButton.isSelected();
502         urlComboBox.setEnabled(enabled);
503         
504         enabled = localFileRadioButton.isSelected();
505         localFileComboBox.setEnabled(enabled);
506         localFileButton.setEnabled(enabled);
507         
508         enabled = uddiRegistryRadioButton.isSelected();
509         uddiRegistryComboBox.setEnabled(enabled);
510         uddiRegistryButton.setEnabled(enabled);
511         
512     }
513     
514     
515     private String JavaDoc fixFileURL(String JavaDoc inFileURL) {
516         String JavaDoc returnFileURL = inFileURL;
517         if(returnFileURL.substring(0,1).equalsIgnoreCase("/")) {
518             returnFileURL = "file://" + returnFileURL;
519         } else {
520             returnFileURL = "file:///" + returnFileURL;
521         }
522         
523         return returnFileURL;
524     }
525     
526     private String JavaDoc fixWsdlURL(String JavaDoc inURL) {
527         String JavaDoc returnWsdlURL = inURL;
528         if (!returnWsdlURL.toLowerCase().endsWith("wsdl")) { // NOI18N
529
/**
530              * If the user has left the ending withoug WSDL, they are pointing to the
531              * web service representation on a web which will if suffixed by a ?WSDL
532              * will return the WSDL. This is true for web services created with JWSDP
533              * - David Botterill 3/25/2004
534              */

535             returnWsdlURL += "?WSDL";
536         }
537         
538         return returnWsdlURL;
539     }
540     
541     private void localFileButtonAction(ActionEvent JavaDoc evt) {
542         // pickup user dir from Rave user dir rather than Windows
543
File curDir = null;
544         File curSelection = null;
545         if(localFileComboBox.getSelectedIndex() >= 0){
546             curSelection = new File((String JavaDoc)localFileComboBox.getSelectedItem());
547             if (curSelection.exists()){
548                 if (curSelection.isDirectory()) {
549                     curDir = curSelection;
550                 } else {
551                     curDir = curSelection.getParentFile();
552                 }
553             }
554         }
555         
556         if (curDir == null) curDir = new File(System.getProperty("netbeans.user"), "websvc");
557         if (curSelection != null && curSelection.exists()) wsdlFileChooser.setSelectedFile(curSelection);
558         wsdlFileChooser.setCurrentDirectory(curDir);
559         
560         if (wsdlFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
561             String JavaDoc localFile = wsdlFileChooser.getSelectedFile().getAbsolutePath();
562             if(((DefaultComboBoxModel)localFileComboBox.getModel()).getIndexOf(localFile) == -1) {
563                 localFileComboBox.addItem(localFile);
564             }
565             localFileComboBox.setSelectedItem(localFile);
566             
567             processWSDL(this.fixFileURL(localFile));
568         }
569     }
570     
571     private void getInfoButtonAction(ActionEvent JavaDoc evt) {
572         /**
573          * Determine which radio button is selected Make sure it's not the default.
574          */

575         
576         String JavaDoc urlString = null;
577         
578         if(this.urlRadioButton.isSelected()) {
579             final String JavaDoc urlStr = ((String JavaDoc) urlComboBox.getSelectedItem()).trim();
580             /**
581              * Make sure we don't have the default.
582              */

583             if(null != urlStr && urlStr.equalsIgnoreCase(this.URL_WSDL_MSG)) {
584                 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
585                 displayError(NbBundle.getMessage(this.getClass(), "ERROR_MUST_SPECIFY_URL"));
586                 
587             } else {
588                 
589                 if(((DefaultComboBoxModel)urlComboBox.getModel()).getIndexOf(urlStr) == -1) {
590                     urlComboBox.addItem(urlStr);
591                 }
592                 RequestProcessor.getDefault().post(new Runnable JavaDoc() {
593                     public void run() {
594                         processWSDL(fixWsdlURL(urlStr));
595                     }
596                 });
597                 
598             }
599         } else if(this.localFileRadioButton.isSelected()) {
600             
601             final String JavaDoc chosenFile = (String JavaDoc)this.localFileComboBox.getSelectedItem();
602             /**
603              * Make sure we don't have the default.
604              */

605             
606             if(chosenFile != null && chosenFile.equalsIgnoreCase(this.LOCAL_WSDL_MSG)) {
607                 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
608                 displayError(NbBundle.getMessage(this.getClass(), "ERROR_MUST_LOCAL_FILE"));
609             } else {
610                 /**
611                  * If the selection isn't already in the pulldown list, add it.
612                  */

613                 if(((DefaultComboBoxModel)localFileComboBox.getModel()).getIndexOf(chosenFile) == -1) {
614                     localFileComboBox.addItem(chosenFile);
615                 }
616                 RequestProcessor.getDefault().post(new Runnable JavaDoc() {
617                     public void run() {
618                         processWSDL(fixFileURL(chosenFile));
619                     }
620                 });
621             }
622         }
623         
624         
625         
626     }
627     
628     private void processWSDL(String JavaDoc inWSDLURL) {
629         
630         
631         Cursor JavaDoc normalCursor = dialog.getCursor();
632         dialog.setCursor(new Cursor JavaDoc(Cursor.WAIT_CURSOR));
633         
634         /**
635          * First set the currentWSDL that we are processing
636          */

637         setCurrentWSDL(inWSDLURL);
638         
639         if(null == inWSDLURL) {
640             return;
641         }
642         URL JavaDoc wsdlUrl = null;
643         try {
644             wsdlUrl = new URL JavaDoc(inWSDLURL);
645         } catch(MalformedURLException JavaDoc mue) {
646             displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
647             displayError(NbBundle.getMessage(this.getClass(), "INVALID_URL"));
648             dialog.setCursor(normalCursor);
649             return;
650         }
651         
652         /**
653          * generate the WSDL information
654          */

655         currentWSDLInfo = generateWsdlInfo(wsdlUrl);
656         if(null != currentWSDLInfo) {
657             /**
658              * Set the list of services to process
659              */

660             this.setWebServicesToProcess(currentWSDLInfo.getWebServices());
661             /**
662              * diplay the WSDL information
663              */

664             displayWSDLInfo(currentWSDLInfo.getWebServices());
665             /**
666              * Scroll the display area to the top
667              */

668             infoTextArea.setCaretPosition(1);
669             
670             if (!currentWSDLInfo.hasOperations()) {
671                 displayError("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "WARNING_SOLICIT") + "</FONT>");
672             }
673         }
674         
675         dialog.setCursor(normalCursor);
676         
677     }
678     
679     
680     private String JavaDoc getCurrentWSDL() {
681         return currentWSDL;
682     }
683     private void setCurrentWSDL(String JavaDoc inWSDL) {
684         currentWSDL = inWSDL;
685     }
686     
687     
688     private void uddiRegistryButtonAction(ActionEvent JavaDoc evt) {
689     }
690     
691     private WSDLInfo generateWsdlInfo(final URL JavaDoc wsdlUrl) {
692         Set JavaDoc webServices = null;
693         
694         /**
695          * Bugid: 5035872. Need to set the button to false until the WSDL is
696          * successfully parsed.
697          */

698         addButton.setEnabled(false);
699         
700         WSDLInfo returnWSDLInfo = new WSDLInfo();
701         if (dlg != null) dlg.setValid(false);
702         infoTextlabel.setEnabled(true);
703         infoTextArea.setEnabled(true);
704         
705         
706         StringWriter infoWriter = new StringWriter();
707         infoWriter.write(NbBundle.getMessage(AddWebServiceDlg.class, "PARSING_MSG"));
708         infoWriter.write("WSDL - " + wsdlUrl.toString());
709         
710         displayMessage(infoWriter.toString());
711         
712         returnWSDLInfo.setWsdlUrl(wsdlUrl);
713         Date JavaDoc date = new Date JavaDoc();
714         File tmpOutputDir = null;
715         try{
716             File tempFile = File.createTempFile("wstemp","ws");
717             tmpOutputDir = new File(tempFile.getParentFile(), "wstemp" + date.getTime());
718             if (tmpOutputDir.exists()) tmpOutputDir.mkdirs();
719         }catch (IOException exc){
720             displayError(exc.getLocalizedMessage());
721             return null;
722         }
723         
724         returnWSDLInfo.setOutputDirectory(tmpOutputDir.getAbsolutePath());
725         returnWSDLInfo.setPackageName("webservice");
726         returnWSDLInfo.setRemoveGeneratedFiles(false);
727         
728         if(!returnWSDLInfo.create()){
729             /**
730              * If we had a problem parsing the WSDL, display the probelm and reset the defaults.
731              */

732             displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
733             displayError(returnWSDLInfo.getErrorMessage());
734             return null;
735         }
736         
737         webServices = returnWSDLInfo.getWebServices();
738         if(webServices == null){
739             displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
740             displayError(NbBundle.getMessage(AddWebServiceDlg.class, "WSDL_PARSE_ERROR"));
741             return null;
742         }
743         
744         addButton.setEnabled(true);
745         /**
746          * make sure the get information button maintains the focus and default status.
747          */

748         getInfoButton.requestFocus();
749         this.getRootPane().setDefaultButton(getInfoButton);
750         
751         
752         infoWriter = new StringWriter();
753         infoWriter.write(NbBundle.getMessage(AddWebServiceDlg.class, "FINISHED_PARSING_MSG"));
754         
755         displayMessage(infoWriter.toString());
756         
757         return returnWSDLInfo;
758     }
759     
760     private void displayWSDLInfo(Set JavaDoc inWebServices) {
761         Iterator JavaDoc serviceIterator = inWebServices.iterator();
762         WebServiceData webServiceData = null;
763         String JavaDoc displayInfo = "";
764         while(serviceIterator.hasNext()) {
765             Object JavaDoc wsObj = serviceIterator.next();
766             if(null != wsObj && wsObj instanceof WebServiceData && null != currentWSDLInfo) {
767                 webServiceData = (WebServiceData) wsObj;
768                 String JavaDoc serviceInfo = currentWSDLInfo.getServiceInfo(webServiceData.getName());
769                 String JavaDoc changedServiceInfo = setDisplayName(webServiceData,serviceInfo);
770                 displayInfo += changedServiceInfo;
771             }
772         }
773         if(!displayInfo.equals("")) {
774             displayInfo(displayInfo);
775         }
776         
777     }
778     /**
779      * This method will set the display name in the HTML text to a unique name based
780      * on the web service name. This method will check the existing web service names
781      * to see if the service name has already been used as a display name. If it has, it will
782      * append a number, starting with 1 and increment that number until a unique name is found.
783      *
784      */

785     private String JavaDoc setDisplayName(WebServiceData inWSData, String JavaDoc inHTMLString) {
786         
787         WebServiceListModel wsListModel = WebServiceListModel.getInstance();
788         String JavaDoc currentDisplayName = inWSData.getName();
789         String JavaDoc newDisplayName = currentDisplayName;
790         /**
791          * The WebServiceData by default has the display name set to the service name.
792          */

793         for(int ii = 1;wsListModel.webServiceExists(inWSData);ii++) {
794             newDisplayName = currentDisplayName + Integer.toString(ii);
795             inWSData.setDisplayName(newDisplayName);
796         }
797         int tokenLocation = inHTMLString.indexOf(WSDLInfo.SERVICE_DISPLAYNAME_TOKEN);
798         
799         String JavaDoc firstPart = "";
800         String JavaDoc lastPart = "";
801         if(-1 != tokenLocation) {
802             firstPart = inHTMLString.substring(0,tokenLocation );
803             lastPart = inHTMLString.substring(tokenLocation + WSDLInfo.SERVICE_DISPLAYNAME_TOKEN.length());
804         }
805         
806         return firstPart + newDisplayName + lastPart;
807     }
808     
809     public void deleteDirectory(File dir){
810         File[] children = dir.listFiles();
811         for(int i=0; i< children.length; i++){
812             if(children[i].isDirectory()){
813                 deleteDirectory(children[i]);
814             }else{
815                 children[i].delete();
816             }
817         }
818         dir.delete();
819     }
820     
821     private void displayInfo(final String JavaDoc info){
822         
823         String JavaDoc htmlStart = "<HTML><HEAD>" +
824         "<style type=\"text/css\">" +
825 // !HIE "body { font-family: Verdana, sans-serif; font-size: 14; }" +
826
"body { font-family: Verdana, sans-serif; font-size: 11; }" +
827         "</style>" +
828         "</HEAD>" +
829         "<BODY>";
830         String JavaDoc htmlEnd = "</BODY></HTML>";
831         
832         infoTextArea.setText(htmlStart + info + htmlEnd);
833         
834     }
835     
836     
837     private void displayError(String JavaDoc inError) {
838         displayMessage("<FONT COLOR=\"RED\">" + inError + "</FONT>");
839     }
840     
841     private void displayMessage(String JavaDoc message){
842         this.displayMessage(message,true);
843     }
844     
845     private void displayMessage(String JavaDoc message,boolean useTimeStamp){
846         /**
847          * concatonate the new message onto the existing.
848          */

849         
850         String JavaDoc dateStamp = dateFormat.format(new Date JavaDoc());
851         
852         String JavaDoc htmlStart = "<HTML><HEAD>" +
853         "<style type=\"text/css\">" +
854         "body { font-family: Verdana, sans-serif; font-size: 12; }" +
855         "</style>" +
856         "</HEAD>" +
857         "<BODY>";
858         String JavaDoc htmlEnd = "</BODY></HTML>";
859         
860         /**
861          * Check to see if the WSDL has changed, if so print a marker
862          */

863         
864         if(!previousWSDL.equals(getCurrentWSDL())) {
865             /**
866              * Make sure this isn't the first time when the previousWSDL will be blank.
867              */

868             if(!previousWSDL.equals("")) {
869                 currentMessages += "<BR><FONT COLOR=\"BLUE\">" + NbBundle.getMessage(AddWebServiceDlg.class, "MESSAGE_END") +
870                 " " + previousWSDL + "</FONT>";
871             }
872             currentMessages += "<BR><FONT COLOR=\"BLUE\">" + NbBundle.getMessage(AddWebServiceDlg.class, "MESSAGE_START") +
873             " " + getCurrentWSDL() + "</FONT>";
874             previousWSDL = getCurrentWSDL();
875         }
876         
877         
878         if(useTimeStamp) {
879             currentMessages += "<BR><B><I>" + dateStamp + ":&nbsp</I></B>" + message;
880         } else {
881             currentMessages += "<BR>" + message;
882         }
883         
884         messageTextArea.setText(htmlStart + currentMessages + htmlEnd);
885     }
886     
887     private void setWebServicesToProcess(Set JavaDoc inWebServices) {
888         this.webServicesToProcess = inWebServices;
889     }
890     
891     private Set JavaDoc getWebServicesToProcess() {
892         return this.webServicesToProcess;
893     }
894     
895     /**
896      * This represents the event on the "Add" button
897      */

898     private void addButtonAction(ActionEvent JavaDoc evt) {
899         
900         
901         SwingUtilities.invokeLater(new Runnable JavaDoc(){
902             public void run(){
903                 Cursor JavaDoc normalCursor = dialog.getCursor();
904                 dialog.setCursor(new Cursor JavaDoc(Cursor.WAIT_CURSOR));
905                 addWebServices();
906                 dialog.setCursor(normalCursor);
907             }
908         });
909         
910         
911     }
912     
913     private void addWebServices() {
914         
915         Set JavaDoc webServices = getWebServicesToProcess();
916         if(webServices == null) return;
917         Iterator JavaDoc iter = webServices.iterator();
918         boolean duplicateFound = false;
919         WebServiceListModel wsListModel = WebServiceListModel.getInstance();
920         /**
921          * Assume that all of the web services adds failed. For each success,
922          * remove the web service from the failed set.
923          */

924         HashSet JavaDoc addFailedWebServices = new HashSet JavaDoc();
925         addFailedWebServices.addAll(webServices);
926         
927         while(iter.hasNext()){
928             
929             WebServiceData wsData = (WebServiceData) iter.next();
930             /**
931              * First set the display name based on what the user possibly changed it to.
932              */

933             findValuesInHTML(wsData);
934             
935             /**
936              * Now check the displayname and package name.
937              */

938             
939             if(null == wsData.getDisplayName() || wsData.getDisplayName().equals(" ") ||
940             wsData.getDisplayName().length() == 0) {
941                 displayError(wsData.getName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_BLANK_WS_DISPLAYNAME"));
942             } else if(!Util.isValidIdentifier(wsData.getDisplayName())) {
943                 displayError(wsData.getDisplayName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_INVALID_DISPLAYNAME"));
944             }else if(null == wsData.getPackageName() || wsData.getPackageName().length() == 0) {
945                 displayError(wsData.getDisplayName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_BLANK_WS_PACKAGENAME"));
946             } else if(!Util.isValidPackageName(wsData.getPackageName())) {
947                 displayError(wsData.getPackageName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_INVALID_PACKAGENAME"));
948                 
949             } else
950                 
951                 
952                 /**
953                  * Make sure the web service doesn't already exist in the list model.
954                  */

955                 if(!wsListModel.webServiceExists(wsData)){
956                     /**
957                      * Now create the client code for the web service.
958                      */

959                     String JavaDoc jarFileName = System.getProperty("netbeans.user") +"/websvc/" + "webservice" + new Date JavaDoc().getTime() + ".jar";
960                     
961                     if(!compileWebService(wsData, jarFileName)) {
962                         /**
963                          * Fix for BUGID: 5048904
964                          * -David Botterill
965                          */

966                         addButton.setEnabled(false);
967                         return;
968                     }
969                     
970                     /**
971                      * Add it to the list of web services for Server Navigator
972                      */

973                     // !PW Fixed rave code that was using casts instead of
974
// cookies on node objects.
975
wsListModel.addWebService(wsData);
976                     
977                     if(invokingNode != null) {
978                         WebServiceGroupCookie groupCookie = (WebServiceGroupCookie) invokingNode.getCookie(WebServiceGroupCookie.class);
979                         if(groupCookie != null) {
980                             groupCookie.getWebServiceGroup().add(wsData.getId());
981                             wsData.setGroupId(groupCookie.getWebServiceGroup().getId());
982                         } else {
983                             // !PW someone added this action to a node that does
984
// not implement the group cookie interface -- don't do that.
985

986                             // !PW Sometimes the invokingNode is 'WebServicesRootNodeNetBeansSide", which
987
// does not currently expose this cookie. Not sure why this is happening, but
988
// for now, if we get here, add the service to default and log it.
989
ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Add Web Service to Registry :: Invoking node w/ no GroupCookie :: class " + invokingNode.getClass());
990                             WebServiceGroup wsGroup = wsListModel.getWebServiceGroup("default");
991                             wsGroup.add(wsData.getId());
992                             wsData.setGroupId(wsGroup.getId());
993                         }
994                     } else {
995                         // If no selected node on invocation, put service in 'default'.
996
WebServiceGroup wsGroup = wsListModel.getWebServiceGroup("default");
997             if(wsGroup == null) wsGroup = new WebServiceGroup("default");
998             wsListModel.addWebServiceGroup(wsGroup);
999                         wsGroup.add(wsData.getId());
1000                        wsData.setGroupId(wsGroup.getId());
1001                    }
1002                    
1003                    this.displayMessage(wsData.getDisplayName() + " " + NbBundle.getMessage(this.getClass(), "WS_SUCCESSFULLY_ADDED"));
1004                    
1005                    //Node node = new WebServicesNode(wsData);
1006
//invokingNode.getChildren().add(new Node[]{node});
1007
addFailedWebServices.remove(wsData);
1008                    
1009                } else{
1010                    String JavaDoc msg = wsData.getDisplayName() + " " + NbBundle.getMessage(AddWebServiceDlg.class, "WS_ALREADY_EXIST_MSG");
1011                    NotifyDescriptor d = new Message(msg, NotifyDescriptor.INFORMATION_MESSAGE);
1012                    DialogDisplayer.getDefault().notify(d);
1013                }
1014        }
1015        
1016        /**
1017         * If not all the web services in the WSDL were added, set them up to display again.
1018         */

1019        if(addFailedWebServices.size() > 0) {
1020            displayWSDLInfo(addFailedWebServices);
1021            this.setWebServicesToProcess(addFailedWebServices);
1022            
1023        } else {
1024            closeDialog();
1025        }
1026        
1027    }
1028    
1029    
1030    
1031    private boolean compileWebService(WebServiceData inWSData, String JavaDoc inJarFileName) {
1032            /**
1033             * Create a piped reader so we can get the output of the client creation.
1034             *
1035             */

1036            PipedOutputStream pos = null;
1037            BufferedInputStream in = null;
1038            try {
1039                pos = new PipedOutputStream();
1040                in = new BufferedInputStream(new PipedInputStream(pos));
1041                
1042                /**
1043                 * IMPORTANT - Collect the output in a separate thread. This MUST be done
1044                 * to avoid a deadlock with the Piped streams.
1045                 */

1046                PipedReaderTask readerTask = new PipedReaderTask(in,this.messageTextArea);
1047                this.displayMessage(NbBundle.getMessage(this.getClass(), "WSCOMPILE_START"));
1048                Thread JavaDoc pipeThread = new Thread JavaDoc(readerTask);
1049                pipeThread.start();
1050                
1051                if (!Util.createWSJar(inWSData,pos,inJarFileName)) {
1052                    ErrorManager.getDefault().log(this.getClass().getName() + ": " + NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR"));
1053                    displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
1054                    displayError(NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR"));
1055                    return false;
1056                }
1057                inWSData.setProxyJarFileName(inJarFileName);
1058                this.displayMessage(NbBundle.getMessage(this.getClass(), "WSCOMPILE_END"));
1059            } catch (IOException ioe) {
1060                ErrorManager.getDefault().notify(ioe);
1061                displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>");
1062                this.displayError(NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR"));
1063                return false;
1064            } finally {
1065                if (pos != null) {
1066                    try {
1067                        pos.close();
1068                    } catch (IOException ioe) {
1069                        // TODO Log this somewhere
1070
}
1071                }
1072            }
1073
1074            return true;
1075    }
1076    
1077    private void findValuesInHTML(WebServiceData inWSData) {
1078        document = (HTMLDocument JavaDoc)infoTextArea.getDocument();
1079        Element JavaDoc rootElement = document.getDefaultRootElement();
1080        Element JavaDoc formElement = null;
1081        Element JavaDoc inputElement = null;
1082        /**
1083         * First, get the Element for the form.
1084         */

1085        formElement=document.getElement(rootElement,Attribute.NAME,"service_form." + inWSData.getName());
1086        /**
1087         * Next, get the input element named "service_name." + wsdata.getName()
1088         */

1089        inputElement = document.getElement(formElement,Attribute.NAME, "service_name." + inWSData.getName());
1090        if(null != inputElement) {
1091            
1092            /**
1093             * Simply going through the HTMLDocument won't suffice because any textfield changes in an <INPUT>
1094             * HTML field are not shown. So, we have to go through the view of the JeditorPane starting at the offset of
1095             * the named element.
1096             */

1097            
1098            int offset=inputElement.getStartOffset();
1099            View JavaDoc view=infoTextArea.getUI().getRootView(infoTextArea);
1100            Component JavaDoc currentComponent=null;
1101            while (view.getViewCount()>0) {
1102                if (view instanceof ComponentView JavaDoc) {
1103                    ComponentView JavaDoc cv=(ComponentView JavaDoc)view;
1104                    currentComponent=cv.getComponent();
1105                    break;
1106                }
1107                int index=view.getViewIndex(offset,Bias.Forward);
1108                view=view.getView(index);
1109            }
1110            
1111            if (view instanceof ComponentView JavaDoc) {
1112                ComponentView JavaDoc cv=(ComponentView JavaDoc)view;
1113                currentComponent=cv.getComponent();
1114            }
1115            
1116            if (currentComponent instanceof JTextField) {
1117                JTextField tf=(JTextField)currentComponent;
1118                inWSData.setDisplayName(tf.getText());
1119            }
1120            
1121            
1122        }
1123        /**
1124         * Next, get the input element named "package_name." + wsdata.getName()
1125         */

1126        inputElement = document.getElement(formElement,Attribute.NAME, "package_name." + inWSData.getName());
1127        if(null != inputElement) {
1128            
1129            /**
1130             * Simply going through the HTMLDocument won't suffice because any textfield changes in an <INPUT>
1131             * HTML field are not shown. So, we have to go through the view of the JeditorPane starting at the offset of
1132             * the named element.
1133             */

1134            
1135            int offset=inputElement.getStartOffset();
1136            View JavaDoc view=infoTextArea.getUI().getRootView(infoTextArea);
1137            Component JavaDoc currentComponent=null;
1138            while (view.getViewCount()>0) {
1139                if (view instanceof ComponentView JavaDoc) {
1140                    ComponentView JavaDoc cv=(ComponentView JavaDoc)view;
1141                    currentComponent=cv.getComponent();
1142                    break;
1143                }
1144                int index=view.getViewIndex(offset,Bias.Forward);
1145                view=view.getView(index);
1146            }
1147            
1148            if (view instanceof ComponentView JavaDoc) {
1149                ComponentView JavaDoc cv=(ComponentView JavaDoc)view;
1150                currentComponent=cv.getComponent();
1151            }
1152            
1153            if (currentComponent instanceof JTextField) {
1154                JTextField tf=(JTextField)currentComponent;
1155                inWSData.setPackageName(tf.getText());
1156            }
1157            
1158            
1159        }
1160        
1161        
1162    }
1163    
1164    private void setDefaults() {
1165        addButton.setEnabled(false);
1166        urlRadioButton.setSelected(true);
1167        localFileRadioButton.setSelected(false);
1168        urlComboBox.setSelectedIndex(0);
1169        localFileComboBox.setSelectedIndex(0);
1170        displayInfo("<BR><BR><BR><BR><B>" +NbBundle.getMessage(AddWebServiceDlg.class, "INSTRUCTIONS") + "</B>");
1171        enableControls();
1172    }
1173    
1174    /**
1175     * @param args the command line arguments
1176     */

1177    public static void main(String JavaDoc[] args) {
1178        System.setProperty("http.proxyHost", "webcache.sfbay.sun.com");
1179        System.setProperty("http.proxyPort", "8080");
1180        
1181        // myWS.firstTimeStart();
1182
System.setProperty("netbeans.home", "D:\\rave-slim\\nbbuild\rave");
1183        System.setProperty("netbeans.user", "D:\\rave-slim\\userdir");
1184        AddWebServiceDlg myWSPanel = new AddWebServiceDlg();
1185        JDialog dialog = new JDialog();
1186        dialog.addWindowListener(new WindowAdapter JavaDoc(){
1187            public void windowClosing(WindowEvent JavaDoc e){
1188                System.out.println("Saving ...");
1189                //persistenceManager.saveMRU();
1190
}
1191        });
1192        dialog.getContentPane().add(myWSPanel);
1193        dialog.pack();
1194        dialog.show();
1195    }
1196    
1197    public void actionPerformed(ActionEvent JavaDoc evt) {
1198        String JavaDoc actionCommand = evt.getActionCommand();
1199        if(actionCommand.equalsIgnoreCase(addString)) {
1200            addButtonAction(evt);
1201        } else if(actionCommand.equalsIgnoreCase(cancelString)) {
1202            cancelButtonAction(evt);
1203        } else if(actionCommand.equalsIgnoreCase(copyString)) {
1204            copyMenuItemAction(evt);
1205        } else if(actionCommand.equalsIgnoreCase(clearString)) {
1206            clearMenuItemAction(evt);
1207        }
1208        
1209    }
1210    
1211    public void hyperlinkUpdate(HyperlinkEvent JavaDoc e) {
1212        if(e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
1213            String JavaDoc link = e.getDescription();
1214            
1215            
1216            /**
1217             * Parse the link to find out what action to take.
1218             */

1219            String JavaDoc [] parts = link.split(WSDLInfo.TOKEN_SEPARATOR);
1220            if(null == parts) {
1221                return;
1222            }
1223            String JavaDoc actionName = parts[0];
1224            
1225            if(actionName.equalsIgnoreCase("test")) {
1226                testMethod(link);
1227            }
1228        }
1229    }
1230    
1231    
1232    private void testMethod(String JavaDoc inHyperLink) {
1233        
1234        /**
1235         * Parse the link for the service, port, and method. The patterns is
1236         * action@service@port@method@|returntype!parametertype:parametertype:..:
1237         */

1238        String JavaDoc [] parts = inHyperLink.split(WSDLInfo.TOKEN_SEPARATOR);
1239        if(null == parts) {
1240            return;
1241        }
1242        
1243        String JavaDoc actionName = parts[0];
1244        String JavaDoc serviceName = parts[1];
1245        String JavaDoc portName = parts[2];
1246        String JavaDoc methodName = parts[3];
1247        
1248        /**
1249         * Since the neither JavaParameter nor Operation override "equals()", we need to jump through
1250         * some hoops to compare the method signatures for methods with the same name.
1251         * -David Botterill 4/22/2004
1252         */

1253        
1254        /**
1255         * The signature patter will look like this from the HTML link.
1256         *
1257         * returnType!parameter type:parameter type: ...:
1258         */

1259        String JavaDoc [] patternParts = inHyperLink.split("\\" + WSDLInfo.SIG_SEPARATOR);
1260        if(null == patternParts) {
1261            return;
1262        }
1263        String JavaDoc signaturePattern = patternParts[1];
1264        
1265        
1266        
1267        
1268        /**
1269         * Now find the right WebServiceData, Port, and JavaMethod.
1270         */

1271        Set JavaDoc services =currentWSDLInfo.getWebServices();
1272        Iterator JavaDoc serviceIterator = services.iterator();
1273        JavaMethod method = null;
1274        WebServiceData wsData = null;
1275        while(serviceIterator.hasNext()) {
1276            WebServiceData currentWSData = (WebServiceData)serviceIterator.next();
1277            if(currentWSData.getName().equals(serviceName)) {
1278                Port [] ports = currentWSData.getPorts();
1279                for(int ii=0; null != ports && ii < ports.length; ii++) {
1280                    if(ports[ii].getName().getLocalPart().equals(portName)) {
1281                        Iterator JavaDoc operatorIterator = ports[ii].getOperations();
1282                        while(operatorIterator.hasNext()) {
1283                            Operation currentOperation = (Operation)operatorIterator.next();
1284                            JavaMethod currentMethod = currentOperation.getJavaMethod();
1285                            if(currentMethod.getName().equals(methodName) &&
1286                            signatureEqual(currentMethod,signaturePattern)) {
1287                                method = currentMethod;
1288                                wsData = currentWSData;
1289                                break;
1290                            }
1291                        }
1292                        if(null != method) {
1293                            break;
1294                        }
1295                    }
1296                }
1297            }
1298            if(null != method) {
1299                break;
1300            }
1301        }
1302        /**
1303         * If we found the method, make sure the WebServiceData has a Jar file, if not
1304         * we need to generate it.
1305         */

1306        if(null != wsData) {
1307            
1308            if(null == wsData.getProxyJarFileName() || wsData.getProxyJarFileName().length() == 0) {
1309                
1310                /**
1311                 * See if we have a jar in the cache for this WSDL
1312                 */

1313                
1314                String JavaDoc searchWSDL = wsData.getURL();
1315                String JavaDoc jarFileName = null;
1316                Object JavaDoc jarFileNameObject = jarCache.get(searchWSDL);
1317                if(null == jarFileNameObject) {
1318                    
1319                    /**
1320                     * Create a temporary file for the jar.
1321                     */

1322                    File tempFile = null;
1323                    try{
1324                        tempFile = File.createTempFile("wstemp",".jar");
1325                        tempFile.deleteOnExit();
1326                    }catch (IOException ioe){
1327                        ErrorManager.getDefault().notify(ioe);
1328                        return;
1329                    }
1330                    
1331                    jarFileName = tempFile.getAbsolutePath();
1332                    
1333                    Cursor JavaDoc normalCursor = dialog.getCursor();
1334                    dialog.setCursor(new Cursor JavaDoc(Cursor.WAIT_CURSOR));
1335                    
1336                    boolean compiledOK = compileWebService(wsData,jarFileName);
1337                    
1338                    dialog.setCursor(normalCursor);
1339                    
1340                    
1341                    if(!compiledOK) {
1342                        return;
1343                    }
1344                    
1345                    /**
1346                     * Add this jarFileName to the cache.
1347                     */

1348                    jarCache.put(searchWSDL, jarFileName);
1349                    
1350                } else {
1351                    jarFileName = (String JavaDoc)jarFileNameObject;
1352                }
1353                
1354                /**
1355                 * set the jar file for this WebServiceData
1356                 */

1357                wsData.setProxyJarFileName(jarFileName);
1358            }
1359            
1360            TestWebServiceMethodDlg dlg = new TestWebServiceMethodDlg(wsData, method, portName);
1361            dlg.displayDialog();
1362        }
1363        
1364        
1365    }
1366    private boolean signatureEqual(JavaMethod inMethod,String JavaDoc inPattern) {
1367        
1368        if(null == inMethod || null == inPattern) return false;
1369        /**
1370         * first parse the signature into return type and parameters.
1371         */

1372        String JavaDoc [] parts = inPattern.split(WSDLInfo.RETURN_SEPARATOR);
1373        if(null == parts) {
1374            return false;
1375        }
1376        String JavaDoc returnType = parts[0];
1377        
1378        /**
1379         * If we only have one part, then we have no parameters.
1380         */

1381        if(parts.length == 1) {
1382            if(inMethod.getParameterCount() > 0) {
1383                return false;
1384            } else {
1385                return true;
1386            }
1387        }
1388        /**
1389         * If the return types are different, return false now.
1390         */

1391        if(!returnType.equals(inMethod.getReturnType().getRealName())) {
1392            return false;
1393        }
1394        
1395        StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(parts[1],WSDLInfo.PARAM_SEPARATOR);
1396        /**
1397         * Create an LinkedList to store the parameter types to compare against the
1398         * JavaMethod.getParameterList().
1399         *
1400         *
1401         */

1402        LinkedList JavaDoc compareList = new LinkedList JavaDoc();
1403        
1404        while(tokenizer.hasMoreTokens()) {
1405            compareList.add((String JavaDoc)tokenizer.nextToken());
1406        }
1407        
1408        /**
1409         * Now create a LinkedList of the paramter types.
1410         */

1411        Iterator JavaDoc paramIterator = inMethod.getParameters();
1412        LinkedList JavaDoc inList = new LinkedList JavaDoc();
1413        while(paramIterator.hasNext()) {
1414            inList.add((String JavaDoc)((JavaParameter)paramIterator.next()).getType().getRealName());
1415        }
1416        
1417        
1418        if(!inList.equals(compareList)) {
1419            return false;
1420        }
1421        
1422        
1423        
1424        return true;
1425    }
1426    
1427    private class MRUPersistenceManager {
1428        File mruFile = new File(System.getProperty("netbeans.user"), WS_URL_PROPS);
1429        
1430        public void loadMRU() {
1431            XMLDecoder JavaDoc decoder = null;
1432            urlComboBox.addItem(URL_WSDL_MSG);
1433            localFileComboBox.addItem(LOCAL_WSDL_MSG);
1434            try {
1435                decoder = new XMLDecoder JavaDoc(new BufferedInputStream(new FileInputStream(mruFile)));
1436                if (mruFile.exists()) {
1437                    int wsDataNums = ((Integer JavaDoc)decoder.readObject()).intValue();
1438                    for(int i=0; i< wsDataNums; i++){
1439                        String JavaDoc urlItem = (String JavaDoc)decoder.readObject();
1440                        if(!urlItem.equals(URL_WSDL_MSG))urlComboBox.addItem( urlItem);
1441                        
1442                    }
1443                    
1444                    wsDataNums = ((Integer JavaDoc)decoder.readObject()).intValue();
1445                    for(int i=0; i< wsDataNums; i++){
1446                        String JavaDoc lfItem = (String JavaDoc) decoder.readObject();
1447                        if(!lfItem.equals(LOCAL_WSDL_MSG))localFileComboBox.addItem(lfItem);
1448                    }
1449                    decoder.close();
1450                }
1451            } catch (Exception JavaDoc e) {
1452                //e.printStackTrace();
1453
if(decoder != null) decoder.close();
1454            }
1455        }
1456        
1457        public void saveMRU() {
1458            if (mruFile.exists()) mruFile.delete();
1459            XMLEncoder JavaDoc encoder = null;
1460            try {
1461                encoder = new XMLEncoder JavaDoc(new BufferedOutputStream(new FileOutputStream(mruFile)));
1462                int itemCount = urlComboBox.getItemCount();
1463                encoder.writeObject(new Integer JavaDoc(itemCount));
1464                for(int i=0; i< itemCount; i++){
1465                    String JavaDoc urlItem = ((String JavaDoc) urlComboBox.getItemAt(i)).trim();
1466                    encoder.writeObject(urlItem);
1467                }
1468                itemCount = localFileComboBox.getItemCount();
1469                encoder.writeObject(new Integer JavaDoc(itemCount));
1470                for(int i=0; i< itemCount; i++){
1471                    String JavaDoc lfItem = (String JavaDoc) localFileComboBox.getItemAt(i);
1472                    encoder.writeObject(lfItem);
1473                }
1474                encoder.close();
1475                
1476            } catch (Exception JavaDoc e) {
1477                e.printStackTrace();
1478                if(encoder != null) encoder.close();
1479            }
1480        }
1481    }
1482    /**
1483     * This is the listener for the context menu in the results text area.
1484     */

1485    class PopupListener extends MouseAdapter JavaDoc {
1486        public void mousePressed(MouseEvent JavaDoc e) {
1487            maybeShowPopup(e);
1488        }
1489        
1490        public void mouseReleased(MouseEvent JavaDoc e) {
1491            maybeShowPopup(e);
1492        }
1493        
1494        private void maybeShowPopup(MouseEvent JavaDoc e) {
1495            if (e.isPopupTrigger()) {
1496                resultsPopup.show(e.getComponent(),
1497                e.getX(), e.getY());
1498            }
1499        }
1500    }
1501    
1502    
1503    public class PipedReaderTask implements Runnable JavaDoc {
1504        
1505        private BufferedInputStream inputStream;
1506        
1507        private String JavaDoc pipedOutput = "";
1508        private JEditorPane messagePane;
1509        
1510        public PipedReaderTask(BufferedInputStream inBufferedInput, JEditorPane inMessagePane) {
1511            inputStream = inBufferedInput;
1512            messagePane = inMessagePane;
1513        }
1514        
1515        public void run() {
1516            
1517            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
1518            try {
1519                String JavaDoc currentLine = null;
1520                while((currentLine =reader.readLine()) != null) {
1521                    pipedOutput += currentLine;
1522                    messagePane.setText(pipedOutput);
1523                }
1524                reader.close();
1525            } catch(IOException ioe) {
1526                pipedOutput += "IOException=" + ioe;
1527            }
1528            
1529        }
1530        
1531        public String JavaDoc getPipedOutput() {
1532            return pipedOutput;
1533        }
1534        
1535        
1536        
1537    }
1538    
1539}
1540
Popular Tags