KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > client > wizard > ClientInfo


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.core.client.wizard;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.FileNotFoundException JavaDoc;
25 import java.io.FileReader JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.LineNumberReader JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import java.awt.Component JavaDoc;
32
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JFileChooser JavaDoc;
35 import javax.swing.JRadioButton JavaDoc;
36 import javax.swing.filechooser.FileFilter JavaDoc;
37 import javax.swing.event.DocumentEvent JavaDoc;
38 import javax.swing.event.DocumentListener JavaDoc;
39 import javax.swing.ComboBoxModel JavaDoc;
40 import javax.swing.DefaultComboBoxModel JavaDoc;
41 import javax.swing.text.JTextComponent JavaDoc;
42 import javax.xml.parsers.ParserConfigurationException JavaDoc;
43 import javax.xml.parsers.SAXParser JavaDoc;
44 import javax.xml.parsers.SAXParserFactory JavaDoc;
45 import org.netbeans.api.java.classpath.ClassPath;
46 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
47 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
48 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
49 import org.netbeans.modules.websvc.core.ClientWizardProperties;
50 import org.netbeans.modules.websvc.core.webservices.ui.panels.ProxySettingsDlg;
51 import org.netbeans.modules.websvc.core.webservices.ui.panels.WebProxySetter;
52 import org.netbeans.modules.websvc.core.WsdlRetriever;
53 import org.netbeans.modules.websvc.core.WsdlRetriever;
54 import org.netbeans.modules.websvc.core.jaxws.JaxWsExplorerPanel;
55 import org.netbeans.modules.websvc.core.JaxWsUtils;
56 //import org.netbeans.modules.websvc.core.webservices.action.JaxRpcWsdlCookie;
57

58 import org.openide.DialogDescriptor;
59 import org.openide.DialogDisplayer;
60 import org.openide.NotifyDescriptor;
61 import org.openide.WizardDescriptor;
62 import org.openide.filesystems.FileUtil;
63 import org.openide.nodes.Node;
64 import org.openide.util.NbBundle;
65
66 import org.netbeans.api.java.project.JavaProjectConstants;
67 import org.netbeans.spi.java.project.support.ui.PackageView;
68 import org.netbeans.api.project.Project;
69 import org.netbeans.api.project.ProjectUtils;
70 import org.netbeans.api.project.SourceGroup;
71 import org.netbeans.api.project.Sources;
72 import org.netbeans.modules.j2ee.api.ejbjar.Car;
73 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
74 import org.netbeans.modules.j2ee.common.Util;
75 import org.netbeans.spi.project.ui.templates.support.Templates;
76
77 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
78 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
79 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
80 import org.netbeans.modules.web.api.webmodule.WebModule;
81 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor;
82
83 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
84 import org.netbeans.modules.websvc.jaxws.api.JaxWsWsdlCookie;
85 import org.openide.ErrorManager;
86 import org.openide.WizardValidationException;
87 import org.openide.filesystems.FileObject;
88 import org.openide.util.Task;
89 import org.xml.sax.Attributes JavaDoc;
90 import org.xml.sax.InputSource JavaDoc;
91 import org.xml.sax.SAXException JavaDoc;
92 import org.xml.sax.helpers.DefaultHandler JavaDoc;
93
94
95 /**
96  *
97  * @author Peter Williams
98  */

99 public final class ClientInfo extends JPanel JavaDoc implements WsdlRetriever.MessageReceiver {
100     
101     private static final String JavaDoc PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
102

103     private static final int WSDL_FROM_PROJECT = 0;
104     private static final int WSDL_FROM_FILE = 1;
105     private static final int WSDL_FROM_URL = 2;
106     
107     private static final FileFilter JavaDoc WSDL_FILE_FILTER = new WsdlFileFilter();
108     private static String JavaDoc previousDirectory = ""; //NOI18N
109

110     private WebServiceClientWizardDescriptor descriptorPanel;
111     private WizardDescriptor wizardDescriptor;
112     
113     private boolean settingFields;
114     private int wsdlSource;
115     private File JavaDoc wsdlTmpFile;
116     
117     // properties for 'get from server'
118
private WsdlRetriever retriever;
119     private String JavaDoc downloadMsg;
120     
121     private boolean retrieverFailed = false;
122     private boolean isWaitingForScan = false;
123     
124     private Project project;
125     private int projectType;
126     
127     public ClientInfo(WebServiceClientWizardDescriptor panel) {
128         descriptorPanel = panel;
129         
130         this.settingFields = false;
131         this.wsdlSource = WSDL_FROM_PROJECT;
132         this.wsdlTmpFile = null;
133         this.retriever = null;
134         
135         initComponents();
136         jLblClientType.setVisible(false);
137         jCbxClientType.setVisible(false);
138         jComboBoxJaxVersion.setModel(new DefaultComboBoxModel JavaDoc(new String JavaDoc[] {ClientWizardProperties.JAX_WS, ClientWizardProperties.JAX_RPC}));
139         initUserComponents();
140     }
141     
142     /** This method is called from within the constructor to
143      * initialize the form.
144      * WARNING: Do NOT modify this code. The content of this method is
145      * always regenerated by the Form Editor.
146      */

147     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
148
private void initComponents() {
149         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
150
151         btnGrpWsdlSource = new javax.swing.ButtonGroup JavaDoc();
152         jLblChooseSource = new javax.swing.JLabel JavaDoc();
153         jRbnFilesystem = new javax.swing.JRadioButton JavaDoc();
154         jTxtWsdlProject = new javax.swing.JTextField JavaDoc();
155         jBtnBrowse = new javax.swing.JButton JavaDoc();
156         jRbnProject = new javax.swing.JRadioButton JavaDoc();
157         jTxtWsdlURL = new javax.swing.JTextField JavaDoc();
158         jBtnProxy = new javax.swing.JButton JavaDoc();
159         jTxtLocalFilename = new javax.swing.JTextField JavaDoc();
160         jLblPackageDescription = new javax.swing.JLabel JavaDoc();
161         jLblProject = new javax.swing.JLabel JavaDoc();
162         jTxtProject = new javax.swing.JTextField JavaDoc();
163         jLblPackageName = new javax.swing.JLabel JavaDoc();
164         jCbxPackageName = new javax.swing.JComboBox JavaDoc();
165         jLblClientType = new javax.swing.JLabel JavaDoc();
166         jCbxClientType = new javax.swing.JComboBox JavaDoc();
167         jRbnUrl = new javax.swing.JRadioButton JavaDoc();
168         jBtnBrowse1 = new javax.swing.JButton JavaDoc();
169         jLabelJaxVersion = new javax.swing.JLabel JavaDoc();
170         jComboBoxJaxVersion = new javax.swing.JComboBox JavaDoc();
171
172         setLayout(new java.awt.GridBagLayout JavaDoc());
173
174         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_WsdlSource"));
175         org.openide.awt.Mnemonics.setLocalizedText(jLblChooseSource, NbBundle.getMessage(ClientInfo.class, "LBL_WsdlSource"));
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
180         add(jLblChooseSource, gridBagConstraints);
181
182         btnGrpWsdlSource.add(jRbnFilesystem);
183         org.openide.awt.Mnemonics.setLocalizedText(jRbnFilesystem, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_WsdlSourceFilesystem"));
184         jRbnFilesystem.addActionListener(new java.awt.event.ActionListener JavaDoc() {
185             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
186                 jRbnFilesystemActionPerformed(evt);
187             }
188         });
189
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridx = 0;
192         gridBagConstraints.gridy = 2;
193         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
195         add(jRbnFilesystem, gridBagConstraints);
196         jRbnFilesystem.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_WsdlSource"));
197
198         jTxtWsdlProject.setEditable(false);
199         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
200         gridBagConstraints.gridx = 1;
201         gridBagConstraints.gridy = 1;
202         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 6);
204         add(jTxtWsdlProject, gridBagConstraints);
205         jTxtWsdlProject.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ClientInfo.class, "ACSN_WsdlSourceFilesystem"));
206         jTxtWsdlProject.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "ACSD_WsdlSourceFile"));
207
208         org.openide.awt.Mnemonics.setLocalizedText(jBtnBrowse, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_Browse"));
209         jBtnBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
210             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
211                 jBtnBrowseActionPerformed(evt);
212             }
213         });
214
215         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints.gridx = 2;
217         gridBagConstraints.gridy = 2;
218         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
219         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 0);
221         add(jBtnBrowse, gridBagConstraints);
222         jBtnBrowse.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ClientInfo.class).getString("A11Y_BrowseLocalFile"));
223
224         btnGrpWsdlSource.add(jRbnProject);
225         jRbnProject.setSelected(true);
226         org.openide.awt.Mnemonics.setLocalizedText(jRbnProject, NbBundle.getMessage(ClientInfo.class, "LBL_ProjectUrl"));
227         jRbnProject.setFocusable(false);
228         jRbnProject.addActionListener(new java.awt.event.ActionListener JavaDoc() {
229             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
230                 jRbnProjectActionPerformed(evt);
231             }
232         });
233
234         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
235         gridBagConstraints.gridx = 0;
236         gridBagConstraints.gridy = 1;
237         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
238         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
239         add(jRbnProject, gridBagConstraints);
240         jRbnProject.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_WsdlSourceUrl"));
241
242         jTxtWsdlURL.setColumns(30);
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 1;
245         gridBagConstraints.gridy = 3;
246         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247         gridBagConstraints.weightx = 1.0;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 12, 6);
249         add(jTxtWsdlURL, gridBagConstraints);
250         jTxtWsdlURL.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ClientInfo.class, "ACSN_WsdlSourceUrl"));
251         jTxtWsdlURL.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "ACSD_WsdlSourceUrl"));
252
253         org.openide.awt.Mnemonics.setLocalizedText(jBtnProxy, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_ProxySettings"));
254         jBtnProxy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
255             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
256                 jBtnProxyActionPerformed(evt);
257             }
258         });
259
260         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
261         gridBagConstraints.gridx = 2;
262         gridBagConstraints.gridy = 3;
263         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
264         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 12, 0);
267         add(jBtnProxy, gridBagConstraints);
268         jBtnProxy.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_ProxySettings"));
269
270         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
271         gridBagConstraints.gridx = 1;
272         gridBagConstraints.gridy = 2;
273         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 6);
275         add(jTxtLocalFilename, gridBagConstraints);
276         jTxtLocalFilename.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ClientInfo.class).getString("ACSN_WsdlSourceLocalFile"));
277         jTxtLocalFilename.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_LocalFilename"));
278
279         jLblPackageDescription.setLabelFor(jCbxPackageName);
280         org.openide.awt.Mnemonics.setLocalizedText(jLblPackageDescription, NbBundle.getMessage(ClientInfo.class, "LBL_PackageDescription"));
281         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
282         gridBagConstraints.gridx = 0;
283         gridBagConstraints.gridy = 4;
284         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
285         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
286         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 12, 0);
287         add(jLblPackageDescription, gridBagConstraints);
288
289         jLblProject.setLabelFor(jTxtProject);
290         org.openide.awt.Mnemonics.setLocalizedText(jLblProject, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_Project"));
291         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
292         gridBagConstraints.gridx = 0;
293         gridBagConstraints.gridy = 5;
294         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
295         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
296         add(jLblProject, gridBagConstraints);
297
298         jTxtProject.setEditable(false);
299         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
300         gridBagConstraints.gridx = 1;
301         gridBagConstraints.gridy = 5;
302         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
303         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 0);
305         add(jTxtProject, gridBagConstraints);
306         jTxtProject.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_Project"));
307
308         jLblPackageName.setLabelFor(jCbxPackageName);
309         org.openide.awt.Mnemonics.setLocalizedText(jLblPackageName, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_PackageName"));
310         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
311         gridBagConstraints.gridx = 0;
312         gridBagConstraints.gridy = 6;
313         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
314         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
315         add(jLblPackageName, gridBagConstraints);
316
317         jCbxPackageName.setEditable(true);
318         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
319         gridBagConstraints.gridx = 1;
320         gridBagConstraints.gridy = 6;
321         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
322         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
323         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 0);
324         add(jCbxPackageName, gridBagConstraints);
325
326         jLblClientType.setLabelFor(jCbxClientType);
327         org.openide.awt.Mnemonics.setLocalizedText(jLblClientType, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_ClientType"));
328         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
329         gridBagConstraints.gridx = 0;
330         gridBagConstraints.gridy = 7;
331         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
332         gridBagConstraints.ipady = 4;
333         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
334         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
335         add(jLblClientType, gridBagConstraints);
336
337         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
338         gridBagConstraints.gridx = 1;
339         gridBagConstraints.gridy = 7;
340         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
341         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
342         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
343         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
344         add(jCbxClientType, gridBagConstraints);
345         jCbxClientType.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ClientInfo.class, "A11Y_ClientType"));
346
347         btnGrpWsdlSource.add(jRbnUrl);
348         org.openide.awt.Mnemonics.setLocalizedText(jRbnUrl, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_WsdlUrl"));
349         jRbnUrl.addActionListener(new java.awt.event.ActionListener JavaDoc() {
350             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
351                 jRbnUrlActionPerformed(evt);
352             }
353         });
354
355         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
356         gridBagConstraints.gridx = 0;
357         gridBagConstraints.gridy = 3;
358         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
359         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
360         add(jRbnUrl, gridBagConstraints);
361         jRbnUrl.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ClientInfo.class).getString("A11Y_WsdlURL"));
362
363         org.openide.awt.Mnemonics.setLocalizedText(jBtnBrowse1, org.openide.util.NbBundle.getMessage(ClientInfo.class, "LBL_Browse1"));
364         jBtnBrowse1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
365             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
366                 jBtnBrowse1ActionPerformed(evt);
367             }
368         });
369
370         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
371         gridBagConstraints.gridx = 2;
372         gridBagConstraints.gridy = 1;
373         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
374         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
375         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 6, 0);
376         add(jBtnBrowse1, gridBagConstraints);
377         jBtnBrowse1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ClientInfo.class).getString("A11Y_BrowseWSDLProject"));
378
379         jLabelJaxVersion.setLabelFor(jComboBoxJaxVersion);
380         org.openide.awt.Mnemonics.setLocalizedText(jLabelJaxVersion, org.openide.util.NbBundle.getBundle(ClientInfo.class).getString("LBL_JAX_Version"));
381         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
382         gridBagConstraints.gridx = 0;
383         gridBagConstraints.gridy = 8;
384         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
385         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
386         gridBagConstraints.weighty = 1.0;
387         gridBagConstraints.insets = new java.awt.Insets JavaDoc(28, 0, 0, 6);
388         add(jLabelJaxVersion, gridBagConstraints);
389
390         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
391         gridBagConstraints.gridx = 1;
392         gridBagConstraints.gridy = 8;
393         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
394         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
395         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
396         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
397         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 6, 0, 0);
398         add(jComboBoxJaxVersion, gridBagConstraints);
399
400     }// </editor-fold>//GEN-END:initComponents
401

402     private void jBtnBrowse1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnBrowse1ActionPerformed
403
// TODO add your handling code here:
404
String JavaDoc result = browseProjectServices();
405         if (result!=null) jTxtWsdlProject.setText(result);
406     }//GEN-LAST:event_jBtnBrowse1ActionPerformed
407

408     private void jRbnUrlActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jRbnUrlActionPerformed
409
// TODO add your handling code here:
410
wsdlSource = WSDL_FROM_URL;
411         enableWsdlSourceFields(false, false, true);
412         descriptorPanel.fireChangeEvent();
413     }//GEN-LAST:event_jRbnUrlActionPerformed
414

415     private void jBtnProxyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnProxyActionPerformed
416
ProxySettingsDlg.showDialog();
417         wsdlUrlChanged();
418     }//GEN-LAST:event_jBtnProxyActionPerformed
419

420     private void jBtnBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed
421
// System.out.println("browse for wsdl file...");
422
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(previousDirectory);
423             chooser.setMultiSelectionEnabled(false);
424             chooser.setAcceptAllFileFilterUsed(false);
425             chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
426             chooser.setFileFilter(WSDL_FILE_FILTER);
427             
428             if(chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
429                 File JavaDoc wsdlFile = chooser.getSelectedFile();
430                 jTxtLocalFilename.setText(wsdlFile.getAbsolutePath());
431                 previousDirectory = wsdlFile.getPath();
432                 int result = resolveImports(wsdlFile);
433                 if ((result & 0x02) == 0x02) {
434                     String JavaDoc proxyHost = WebProxySetter.getInstance().getProxyHost();
435                     if (proxyHost==null || proxyHost.length()==0)
436                         DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
437                                 NbBundle.getMessage(ClientInfo.class,"MSG_SetUpProxyForImports"),NotifyDescriptor.WARNING_MESSAGE)); //NOI18N
438
}
439                 if ((result & 0x01) == 0x01) {
440                     DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
441                             NbBundle.getMessage(ClientInfo.class,"MSG_IdeGeneratedStaticStubOnly"),NotifyDescriptor.WARNING_MESSAGE)); //NOI18N
442
}
443                 
444             }
445     }//GEN-LAST:event_jBtnBrowseActionPerformed
446

447     private void jRbnFilesystemActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jRbnFilesystemActionPerformed
448
// System.out.println("get from filesystem selected.");
449
wsdlSource = WSDL_FROM_FILE;
450         enableWsdlSourceFields(false, true, false);
451         descriptorPanel.fireChangeEvent();
452     }//GEN-LAST:event_jRbnFilesystemActionPerformed
453

454     private void jRbnProjectActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jRbnProjectActionPerformed
455
// System.out.println("get from url selected.");
456
wsdlSource = WSDL_FROM_PROJECT;
457         enableWsdlSourceFields(true, false, false);
458         descriptorPanel.fireChangeEvent();
459     }//GEN-LAST:event_jRbnProjectActionPerformed
460

461     private void enableWsdlSourceFields(boolean fromProject, boolean fromFile, boolean fromUrl) {
462         // project related fields
463
jTxtWsdlProject.setEnabled(fromProject);
464         jBtnBrowse1.setEnabled(fromProject);
465         
466         // file systam related fields
467
jTxtLocalFilename.setEnabled(fromFile);
468         jBtnBrowse.setEnabled(fromFile);
469         
470         // service related fields
471
jTxtWsdlURL.setEnabled(fromUrl);
472     }
473     
474     // Variables declaration - do not modify//GEN-BEGIN:variables
475
private javax.swing.ButtonGroup JavaDoc btnGrpWsdlSource;
476     private javax.swing.JButton JavaDoc jBtnBrowse;
477     private javax.swing.JButton JavaDoc jBtnBrowse1;
478     private javax.swing.JButton JavaDoc jBtnProxy;
479     private javax.swing.JComboBox JavaDoc jCbxClientType;
480     private javax.swing.JComboBox JavaDoc jCbxPackageName;
481     private javax.swing.JComboBox JavaDoc jComboBoxJaxVersion;
482     private javax.swing.JLabel JavaDoc jLabelJaxVersion;
483     private javax.swing.JLabel JavaDoc jLblChooseSource;
484     private javax.swing.JLabel JavaDoc jLblClientType;
485     private javax.swing.JLabel JavaDoc jLblPackageDescription;
486     private javax.swing.JLabel JavaDoc jLblPackageName;
487     private javax.swing.JLabel JavaDoc jLblProject;
488     private javax.swing.JRadioButton JavaDoc jRbnFilesystem;
489     private javax.swing.JRadioButton JavaDoc jRbnProject;
490     private javax.swing.JRadioButton JavaDoc jRbnUrl;
491     private javax.swing.JTextField JavaDoc jTxtLocalFilename;
492     private javax.swing.JTextField JavaDoc jTxtProject;
493     private javax.swing.JTextField JavaDoc jTxtWsdlProject;
494     private javax.swing.JTextField JavaDoc jTxtWsdlURL;
495     // End of variables declaration//GEN-END:variables
496

497     private void initUserComponents() {
498 // System.out.println("wizard panel created");
499

500         setName(NbBundle.getMessage(ClientInfo.class, "TITLE_WebServiceClientWizard")); // NOI18N
501

502         // Register listener on the textFields to make the automatic updates
503
jTxtWsdlURL.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
504             public void changedUpdate(DocumentEvent JavaDoc e) {
505                 wsdlUrlChanged();
506             }
507             public void insertUpdate(DocumentEvent JavaDoc e) {
508                 wsdlUrlChanged();
509             }
510             public void removeUpdate(DocumentEvent JavaDoc e) {
511                 wsdlUrlChanged();
512             }
513         });
514         jTxtLocalFilename.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
515             public void changedUpdate(DocumentEvent JavaDoc e) {
516                 updateTexts();
517             }
518             public void insertUpdate(DocumentEvent JavaDoc e) {
519                 updateTexts();
520             }
521             public void removeUpdate(DocumentEvent JavaDoc e) {
522                 updateTexts();
523             }
524         });
525         jTxtWsdlProject.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
526             public void changedUpdate(DocumentEvent JavaDoc e) {
527                 wsdlUrlChanged();
528             }
529             public void insertUpdate(DocumentEvent JavaDoc e) {
530                 wsdlUrlChanged();
531             }
532             public void removeUpdate(DocumentEvent JavaDoc e) {
533                 wsdlUrlChanged();
534             }
535         });
536         
537         Component JavaDoc editorComponent = jCbxPackageName.getEditor().getEditorComponent();
538         if(editorComponent instanceof JTextComponent JavaDoc) {
539             ((JTextComponent JavaDoc) editorComponent).getDocument().addDocumentListener(new DocumentListener JavaDoc() {
540                 public void changedUpdate(DocumentEvent JavaDoc e) {
541                     updateTexts();
542                 }
543                 public void insertUpdate(DocumentEvent JavaDoc e) {
544                     updateTexts();
545                 }
546                 public void removeUpdate(DocumentEvent JavaDoc e) {
547                     updateTexts();
548                 }
549             });
550         } else {
551             // JComboBox is supposed to use a JTextComponent for editing, but in case
552
// it isn't, at least do something to track changes.
553
jCbxPackageName.addItemListener(new java.awt.event.ItemListener JavaDoc() {
554                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
555                     if(!settingFields) {
556                         descriptorPanel.fireChangeEvent(); // Notify that the panel changed
557
}
558                 }
559             });
560         }
561         
562         jCbxPackageName.setRenderer(PackageView.listRenderer());
563     }
564     
565     void store(WizardDescriptor d) {
566 // System.out.println("storing wizard properties");
567

568         if(wsdlSource == WSDL_FROM_PROJECT || wsdlSource == WSDL_FROM_URL) {
569             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL, getDownloadUrl());
570             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_FILE, getDownloadWsdl());
571             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_SCHEMAS, getDownloadedSchemas());
572             d.putProperty(ClientWizardProperties.WSDL_FILE_PATH, retriever == null ? "" : retriever.getWsdlFileName()); //NOI18N
573
} else if(wsdlSource == WSDL_FROM_FILE) {
574             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL, null);
575             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_FILE, null);
576             d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_SCHEMAS, null);
577             d.putProperty(ClientWizardProperties.WSDL_FILE_PATH, jTxtLocalFilename.getText().trim());
578         }
579         d.putProperty(ClientWizardProperties.WSDL_PACKAGE_NAME, getPackageName());
580         d.putProperty(ClientWizardProperties.CLIENT_STUB_TYPE, jCbxClientType.getSelectedItem());
581         d.putProperty(ClientWizardProperties.JAX_VERSION, jComboBoxJaxVersion.getSelectedItem());
582     }
583     
584     void read(WizardDescriptor d) {
585 // System.out.println("reading wizard properties");
586
this.wizardDescriptor = d;
587         
588         project = Templates.getProject(d);
589         WebModule wm = WebModule.getWebModule(project.getProjectDirectory());
590         EjbJar em = EjbJar.getEjbJar(project.getProjectDirectory());
591         Car car = Car.getCar(project.getProjectDirectory());
592         if (car != null)
593             projectType = 3;
594         else if (em != null)
595             projectType = 2;
596         else if (wm != null)
597             projectType = 1;
598         else
599             projectType = 0;
600         
601         if (projectType > 0) {
602             
603             if (!Util.isJavaEE5orHigher(project)) {
604                 jLblClientType.setVisible(true);
605                 jCbxClientType.setVisible(true);
606             }
607         }
608         
609         //test JAX-WS library
610
SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
611         ClassPath classPath;
612         FileObject wsimportFO = null;
613         FileObject wscompileFO = null;
614         if (sgs.length > 0) {
615             classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE);
616             if (classPath != null) {
617                 wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); //NOI18N
618
wscompileFO = classPath.findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); //NOI18N
619
}
620         }
621         
622         boolean jsr109OldSupported = isJsr109OldSupported(project);
623         boolean jsr109Supported = isJsr109Supported(project);
624         boolean jwsdpSupported = isJwsdpSupported(project);
625         if (projectType > 0) {
626             jLabelJaxVersion.setEnabled(false);
627             jComboBoxJaxVersion.setEnabled(false);
628             if (Util.isJavaEE5orHigher(project)) //NOI18N
629
jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_WS);
630             else{
631                 if((!jsr109OldSupported && !jsr109Supported)
632                 || (!jsr109Supported && jsr109OldSupported && jwsdpSupported )){
633                     jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_WS);
634                 } else{
635                     jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_RPC);
636                 }
637             }
638         } else {
639             if (Util.isSourceLevel16orHigher(project)) {
640                 jLabelJaxVersion.setEnabled(false);
641                 jComboBoxJaxVersion.setEnabled(false);
642                 jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_WS);
643             } else if (Util.getSourceLevel(project).equals("1.5")) { //NOI18N
644
if (wsimportFO != null) {
645                     jLabelJaxVersion.setEnabled(false);
646                     jComboBoxJaxVersion.setEnabled(false);
647                     jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_WS);
648                 } else if (wscompileFO != null) {
649                     jLabelJaxVersion.setEnabled(false);
650                     jComboBoxJaxVersion.setEnabled(false);
651                     jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_RPC);
652                 } else {
653                     jLabelJaxVersion.setEnabled(true);
654                     jComboBoxJaxVersion.setEnabled(true);
655                 }
656             } else {
657                 jLabelJaxVersion.setEnabled(false);
658                 jComboBoxJaxVersion.setEnabled(false);
659                 jComboBoxJaxVersion.setSelectedItem(ClientWizardProperties.JAX_RPC);
660             }
661         }
662         
663         try {
664             settingFields = true;
665             
666             Project p = Templates.getProject(d);
667             
668             jTxtProject.setText(ProjectUtils.getInformation(p).getDisplayName());
669             jTxtWsdlURL.setText((String JavaDoc) d.getProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL));
670             jTxtLocalFilename.setText(retriever != null ? retriever.getWsdlFileName() : ""); //NOI18N
671
jTxtWsdlURL.setText((String JavaDoc) d.getProperty(ClientWizardProperties.WSDL_FILE_PATH));
672             
673             jCbxPackageName.setModel(getPackageModel(p));
674             jCbxPackageName.setSelectedItem(getPackageItem((String JavaDoc) d.getProperty(ClientWizardProperties.WSDL_PACKAGE_NAME)));
675             
676             // Normalize selection, in case it's unspecified.
677
Integer JavaDoc source = (Integer JavaDoc) d.getProperty(ClientWizardProperties.WSDL_SOURCE);
678             if(source == null || source.intValue() < WSDL_FROM_PROJECT || source.intValue() > WSDL_FROM_URL) {
679                 source = new Integer JavaDoc(WSDL_FROM_PROJECT);
680             }
681             
682             this.wsdlSource = source.intValue();
683             this.wsdlTmpFile = null;
684             this.retriever = null;
685             this.downloadMsg = null;
686             
687             enableWsdlSourceFields(wsdlSource == WSDL_FROM_PROJECT, wsdlSource == WSDL_FROM_FILE, wsdlSource == WSDL_FROM_URL);
688             btnGrpWsdlSource.setSelected(getSelectedRadioButton(wsdlSource).getModel(), true);
689             
690             // Retrieve stub list from current project (have to be careful with caching
691
// because the user might go back and change the project.)
692
// Then set the stub list and current selected stub only if there was one
693
// saved *and* it's in the list that the current project supports.
694
WebServicesClientSupport clientSupport =
695                     WebServicesClientSupport.getWebServicesClientSupport(p.getProjectDirectory());
696             
697             Object JavaDoc selectedStub = d.getProperty(ClientWizardProperties.CLIENT_STUB_TYPE);
698             DefaultComboBoxModel JavaDoc stubModel = new DefaultComboBoxModel JavaDoc();
699             if(clientSupport != null) {
700                 List JavaDoc<ClientStubDescriptor> clientStubs = clientSupport.getStubDescriptors();
701                 for(Iterator JavaDoc iter = clientStubs.iterator(); iter.hasNext(); ) {
702                     stubModel.addElement(iter.next());
703                 }
704                 
705                 if(!clientStubs.contains(selectedStub)) {
706                     selectedStub = null;
707                 }
708                 
709                 //if platform is non-JSR109, select the JAXRPC static stub type
710
//and disable the combobox
711
if ((!jsr109OldSupported && !jsr109Supported)
712                 || (!jsr109Supported && jsr109OldSupported && jwsdpSupported)) {
713                     selectedStub = getJAXRPCClientStub(clientStubs);
714                     jCbxClientType.setEnabled(false);
715                 }
716             } else {
717                 selectedStub = null;
718             }
719             
720             jCbxClientType.setModel(stubModel);
721             
722             if(selectedStub != null) {
723                 jCbxClientType.setSelectedItem(selectedStub);
724             }
725         } finally {
726             settingFields = false;
727         }
728     }
729     
730     private ClientStubDescriptor getJAXRPCClientStub(List JavaDoc<ClientStubDescriptor> clientStubs){
731         for(ClientStubDescriptor clientStub : clientStubs){
732             if(clientStub.getName().equals(ClientStubDescriptor.JAXRPC_CLIENT_STUB)){
733                 return clientStub;
734             }
735         }
736         return null;
737     }
738     
739     public void validatePanel() throws WizardValidationException {
740         if (!valid(wizardDescriptor))
741             throw new WizardValidationException(this, "", ""); //NOI18N
742

743         retrieverFailed = false;
744         retriever = null;
745         if (((projectType != 0 && !Util.isJavaEE5orHigher(project))
746         || (projectType == 0 && jComboBoxJaxVersion.getSelectedItem().equals(ClientWizardProperties.JAX_RPC)))
747         && (wsdlSource != WSDL_FROM_FILE)) {
748             retriever = new WsdlRetriever(this,
749                     wsdlSource==WSDL_FROM_PROJECT?jTxtWsdlProject.getText():jTxtWsdlURL.getText().trim());
750             
751             Task task = new Task(retriever);
752             try {
753                 task.run();
754                 // not exceed one minute for retrieving large wsdl file
755
task.waitFinished(60000);
756             } catch (InterruptedException JavaDoc ex) {
757             }
758             if (retriever.getState() != WsdlRetriever.STATUS_COMPLETE) {
759                 retrieverFailed = true;
760                 throw new WizardValidationException(this, "", ""); //NOI18N
761
} else
762                 wizardDescriptor.putProperty(ClientWizardProperties.WSDL_FILE_PATH, retriever == null ? "" : retriever.getWsdlFileName()); //NOI18N
763
}
764     }
765     
766     private ComboBoxModel JavaDoc getPackageModel(Project p) {
767         ComboBoxModel JavaDoc result;
768         Sources sources = ProjectUtils.getSources(p);
769         SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
770         
771         if(groups.length > 1) {
772 // !PW We cannot make the distinction between source and test source roots, so I don't
773
// want to merge all the packages at this time. For now, just pick the first one,
774
// and maybe we can do better in the next version.
775
// DefaultComboBoxModel packageModel = new DefaultComboBoxModel();
776
// for(int i = 0; i < groups.length; i++) {
777
// ComboBoxModel model = PackageView.createListView(groups[i]);
778
// for(int j = 0, m = model.getSize(); j < m; j++) {
779
// packageModel.addElement(model.getElementAt(j));
780
// }
781
// }
782
// result = packageModel;
783
// Default to showing packages from first source root only for now.
784
result = PackageView.createListView(groups[0]);
785         } else if(groups.length == 1) {
786             // Only one group, no processing needed.
787
result = PackageView.createListView(groups[0]);
788         } else {
789             result = new DefaultComboBoxModel JavaDoc();
790         }
791         
792         return result;
793     }
794     
795     private Object JavaDoc getPackageItem(String JavaDoc name) {
796         Object JavaDoc result = name;
797         
798         ComboBoxModel JavaDoc model = jCbxPackageName.getModel();
799         int max = model.getSize();
800         for (int i = 0; i < max; i++) {
801             Object JavaDoc item = model.getElementAt(i);
802             if(item.toString().equals(name)) {
803                 result = item;
804                 break;
805             }
806         }
807         
808         return result;
809     }
810     
811     private String JavaDoc getPackageName() {
812         return jCbxPackageName.getEditor().getItem().toString().trim();
813     }
814     
815     private JRadioButton JavaDoc getSelectedRadioButton(int selected) {
816         JRadioButton JavaDoc result = jRbnProject;
817         
818         switch(selected) {
819             case WSDL_FROM_PROJECT:
820                 result = jRbnProject;
821                 break;
822             case WSDL_FROM_FILE:
823                 result = jRbnFilesystem;
824                 break;
825             case WSDL_FROM_URL:
826                 result = jRbnUrl;
827                 break;
828         }
829         
830         return result;
831     }
832     
833     private byte [] getDownloadWsdl() {
834         byte [] result = null;
835         if(retriever != null && retriever.getState() == WsdlRetriever.STATUS_COMPLETE) {
836             result = retriever.getWsdl();
837         }
838         return result;
839     }
840     
841     private List JavaDoc /*WsdlRetriever.SchemaInfo */ getDownloadedSchemas() {
842         List JavaDoc result = null;
843         if(retriever != null && retriever.getState() == WsdlRetriever.STATUS_COMPLETE) {
844             result = retriever.getSchemas();
845         }
846         return result;
847     }
848     
849     private String JavaDoc getDownloadUrl() {
850         String JavaDoc result = ""; //NOI18N
851

852         if(retriever != null) {
853             // If we've done a download, save the URL that was actually used, not
854
// what the user typed in.
855
result = retriever.getWsdlUrl();
856         } else {
857             // If no download yet, then use what the user has typed.
858
if (wsdlSource==WSDL_FROM_URL)
859                 result = WsdlRetriever.beautifyUrlName(jTxtWsdlURL.getText().trim());
860             else if (wsdlSource==WSDL_FROM_PROJECT)
861                 result = jTxtWsdlProject.getText().trim();
862         }
863         return result;
864     }
865     
866     boolean valid(final WizardDescriptor wizardDescriptor) {
867         Project p = Templates.getProject(wizardDescriptor);
868         
869         // Project must currently have a target server that supports wscompile.
870
/*
871         if(!isWsCompileSupported(p)) {
872             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsCompileNotSupportedByTargetServer")); // NOI18N
873             return false; // project with web service client support, but no stub types defined.
874         }
875          */

876         
877         if(!checkNonJsr109Valid(wizardDescriptor)){
878             return false;
879         }
880         
881         // Project selected must support at least one stub type.
882
WebServicesClientSupport clientSupport =
883                 WebServicesClientSupport.getWebServicesClientSupport(p.getProjectDirectory());
884         List JavaDoc clientStubs = (clientSupport != null) ? clientSupport.getStubDescriptors() : null;
885         if(clientStubs == null || clientStubs.size() == 0) {
886             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_NoStubsDefined")); // NOI18N
887
return false; // project with web service client support, but no stub types defined.
888
}
889         
890         if (jComboBoxJaxVersion.getSelectedItem().equals(ClientWizardProperties.JAX_RPC)) {
891             SourceGroup[] sgs = JaxWsClientCreator.getJavaSourceGroups(project);
892             //no source root -> there must be at least one source root to create JAX-RPC client
893
if (sgs.length <= 0) {
894                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class,"MSG_MissingSourceRoot")); //NOI18N
895
return false;
896             }
897         }
898         
899         if(wsdlSource == WSDL_FROM_PROJECT || wsdlSource == WSDL_FROM_URL) {
900             String JavaDoc wsdlUrl = (wsdlSource == WSDL_FROM_PROJECT?jTxtWsdlProject.getText().trim():jTxtWsdlURL.getText().trim());
901             if(wsdlUrl == null || wsdlUrl.length() == 0) {
902                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "MSG_EnterURL")); // NOI18N
903
return false;
904             }
905             
906             if (retrieverFailed && retriever != null) {
907                 if(retriever.getState() < WsdlRetriever.STATUS_COMPLETE) {
908                     wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "MSG_DownloadProgress", // NOI18N
909
((downloadMsg != null) ? downloadMsg : NbBundle.getMessage(ClientInfo.class, "LBL_Unknown")))); // NOI18N
910
return false;
911                 }
912                 
913                 if(retriever.getState() > WsdlRetriever.STATUS_COMPLETE) {
914                     if(downloadMsg != null) {
915                         wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_DownloadFailed", downloadMsg)); // NOI18N
916
} else {
917                         wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_DownloadFailedUnknown")); // NOI18N
918
}
919                     return false;
920                 }
921             }
922             
923             // url is ok, and file is downloaded if we get here. Now check generated local filename
924
// !PW FIXME what do we want to check it for? Existence in temp directory?
925

926             // Now drop down to do package validation.
927
} else if(wsdlSource == WSDL_FROM_FILE) {
928             String JavaDoc wsdlFilePath = jTxtLocalFilename.getText().trim();
929             
930             if(wsdlFilePath == null || wsdlFilePath.length() == 0) {
931                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "MSG_EnterFilename")); // NOI18N
932
return false; // unspecified WSDL file
933
}
934             
935             File JavaDoc f = new File JavaDoc(wsdlFilePath);
936             if(f == null) {
937                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsdlInvalid")); // NOI18N
938
return false; // invalid WSDL file
939
}
940             
941             if(!f.exists()) {
942                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsdlDoesNotExist")); // NOI18N
943
return false; // invalid WSDL file
944
}
945             
946             if(!"wsdl".equalsIgnoreCase(FileUtil.getExtension(f.getName()))) {
947                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsdlInvalid")); // NOI18N
948
return false; // invalid WSDL file
949
}
950             
951             // 50103 - could be done via xml api, but this way should be quicker and suffice the need
952
FileReader JavaDoc fr = null;
953             LineNumberReader JavaDoc lnReader = null;
954             try {
955                 fr = new FileReader JavaDoc(f);
956                 if (jComboBoxJaxVersion.getSelectedItem().equals(ClientWizardProperties.JAX_RPC)) {
957                     lnReader = new LineNumberReader JavaDoc(fr);
958                     if (lnReader != null) {
959                         String JavaDoc line = null;
960                         try {
961                             line = lnReader.readLine();
962                         } catch (IOException JavaDoc ioe) {
963                             //ignore
964
}
965                         while (line != null) {
966                             if (line.indexOf("REPLACE_WITH_ACTUAL_URL") > 0) { //NOI18N
967
wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WrongWsdl")); // NOI18N
968
return false;
969                             } //NOI18N
970
try {
971                                 line = lnReader.readLine();
972                             } catch (IOException JavaDoc ioe) {
973                                 //ignore
974
}
975                         }
976                     }
977                 }
978             } catch (FileNotFoundException JavaDoc fne) {
979                 wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsdlDoesNotExist")); // NOI18N
980
} finally{
981                 try{
982                     if(lnReader != null){
983                         lnReader.close();
984                     }
985                 }catch(IOException JavaDoc e){
986                     ErrorManager.getDefault().notify(e);
987                 }
988             }
989             
990             // !PW FIXME should also detect if WSDL file has previously been added to
991
// this project. Note that not doing so and overwriting the existing entry
992
// is the equivalent of doing an update on it. Nothing bad will happen
993
// unless it turns out the user didn't want to update the service in the
994
// first place.
995
}
996         
997         String JavaDoc packageName = getPackageName();
998         if(packageName == null || packageName.length() == 0) {
999             wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "MSG_EnterJavaPackageName")); // NOI18N
1000
return false; // unspecified WSDL file
1001
}
1002        
1003        if(!JaxWsUtils.isJavaPackage(packageName)) {
1004            wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_PackageInvalid")); // NOI18N
1005
return false; // invalid package name
1006
}
1007        
1008        // Don't allow to create java artifacts to package already used by other service/client
1009
JaxWsModel jaxWsModel = (JaxWsModel)p.getLookup().lookup(JaxWsModel.class);
1010        if (jaxWsModel!=null) {
1011            Service[] services = jaxWsModel.getServices();
1012            for (int i=0;i<services.length;i++) {
1013                if (services[i].getWsdlUrl()!=null && packageName.equals(services[i].getPackageName())) {
1014                    wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_PackageUsedForService",services[i].getServiceName()));
1015                    return false;
1016                }
1017            }
1018            Client[] clients = jaxWsModel.getClients();
1019            for (int i=0;i<clients.length;i++) {
1020                if (packageName.equals(clients[i].getPackageName())) {
1021                    wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_PackageUsedForClient",clients[i].getName()));
1022                    return false;
1023                }
1024            }
1025            
1026        }
1027        
1028        //warning if the project directory has embedded spaces
1029
//TODO - Remove this when the jwsdp version that fixes this problem is available
1030
if(projectHasEmbeddedSpaces()){
1031            wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1032                    NbBundle.getMessage(ClientInfo.class, "MSG_SPACE_IN_PROJECT_PATH")); // NOI18N
1033
} else{
1034            wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, ""); //NOI18N
1035
}
1036        
1037// Retouche
1038
// if (JavaMetamodel.getManager().isScanInProgress()) {
1039
// if (!isWaitingForScan) {
1040
// isWaitingForScan = true;
1041
// RequestProcessor.getDefault().post(new Runnable() {
1042
// public void run() {
1043
// JavaMetamodel.getManager().waitScanFinished();
1044
// isWaitingForScan = false;
1045
// descriptorPanel.fireChangeEvent();
1046
// }
1047
// });
1048
// }
1049
// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ClientInfo.class, "MSG_ScanningInProgress")); //NOI18N
1050
// return false;
1051
// } else
1052
wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
1053

1054        return true;
1055    }
1056    
1057    private boolean projectHasEmbeddedSpaces(){
1058        FileObject projectDir = project.getProjectDirectory();
1059        File JavaDoc projectDirFile = FileUtil.toFile(projectDir);
1060        String JavaDoc path = projectDirFile.getAbsolutePath();
1061        int index = path.indexOf(" ");
1062        return index != -1;
1063    }
1064    
1065    private J2eePlatform getJ2eePlatform(Project project){
1066        J2eeModuleProvider provider = (J2eeModuleProvider) project.getLookup().lookup(J2eeModuleProvider.class);
1067        if(provider != null){
1068            String JavaDoc serverInstanceID = provider.getServerInstanceID();
1069            if(serverInstanceID != null && serverInstanceID.length() > 0) {
1070                return Deployment.getDefault().getJ2eePlatform(serverInstanceID);
1071            }
1072        }
1073        return null;
1074    }
1075    
1076    private boolean isJsr109Supported(Project project){
1077        J2eePlatform j2eePlatform = getJ2eePlatform(project);
1078        if(j2eePlatform != null){
1079            return j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109);
1080        }
1081        return false;
1082    }
1083    
1084    private boolean isJsr109OldSupported(Project project){
1085        J2eePlatform j2eePlatform = getJ2eePlatform(project);
1086        if(j2eePlatform != null){
1087            return j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE);
1088        }
1089        return false;
1090    }
1091    
1092    private boolean isJwsdpSupported(Project project){
1093        J2eePlatform j2eePlatform = getJ2eePlatform(project);
1094        if(j2eePlatform != null){
1095            return j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP);
1096        }
1097        return false;
1098    }
1099    
1100    /**
1101     * If the project the web service client is being created is not on a JSR 109 platform,
1102     * its Java source level must be at least 1.5
1103     */

1104    private boolean checkNonJsr109Valid(WizardDescriptor wizardDescriptor){
1105        Project project = Templates.getProject(wizardDescriptor);
1106        boolean jsr109Supported = isJsr109Supported(project);
1107        boolean jsr109oldSupported = isJsr109OldSupported(project);
1108        boolean jwsdpSupported = isJwsdpSupported(project);
1109        if (!jsr109Supported && !jsr109oldSupported ||
1110                (!jsr109Supported && jsr109oldSupported && jwsdpSupported)) {
1111            if (Util.isSourceLevel14orLower(project)) {
1112                wizardDescriptor.putProperty("WizardPanel_errorMessage",
1113                        NbBundle.getMessage(ClientInfo.class, "ERR_NeedProperSourceLevel")); // NOI18N
1114
return false;
1115            }
1116        }
1117        return true;
1118    }
1119    private boolean isWsCompileSupported(Project p) {
1120        // Determine if wscompile is supported by the current target server of
1121
// this project. Default to true so that the user can still continue, if on
1122
// their own, in case we have difficulty getting the correct answer.
1123
boolean result = true;
1124        
1125        J2eeModuleProvider provider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
1126        if(provider != null) {
1127            String JavaDoc serverInstanceID = provider.getServerInstanceID();
1128            if(serverInstanceID != null && serverInstanceID.length() > 0) {
1129                J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
1130                if(!j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) {
1131                    result = false;
1132                }
1133            }
1134        }
1135        
1136        return result;
1137    }
1138    
1139    private void wsdlUrlChanged() {
1140        // Throw away any existing retriever. New URL means user has to download it again.
1141
retriever = null;
1142        
1143        updateTexts();
1144    }
1145    
1146    private void updateTexts() {
1147        if(!settingFields) {
1148            descriptorPanel.fireChangeEvent(); // Notify that the panel changed
1149
}
1150    }
1151    
1152    private boolean isValidUrl(String JavaDoc urlText) {
1153        if(urlText == null || urlText.length() == 0) {
1154            return false;
1155        }
1156        
1157        // !PW Be very careful adding conditions to this method (such as seeing if
1158
// conversion of url text to URL would throw a MalformedURLException and
1159
// reporting it to the user early.) It is a non-trivial change that would
1160
// require significant synchronization with code in the retriever object.
1161
// as well as the valid() method of this object. See IZ 52685.
1162
return true;
1163    }
1164    
1165    public void setWsdlDownloadMessage(String JavaDoc m) {
1166        downloadMsg = m;
1167        
1168        // reenable edit control if state indicates download is completed (or failed).
1169
if(retriever.getState() >= WsdlRetriever.STATUS_COMPLETE) {
1170            jTxtWsdlURL.setEditable(true);
1171            jTxtLocalFilename.setText(retriever.getWsdlFileName());
1172        }
1173        
1174        descriptorPanel.fireChangeEvent();
1175    }
1176    
1177    private static class WsdlFileFilter extends FileFilter JavaDoc {
1178        public boolean accept(File JavaDoc f) {
1179            boolean result;
1180            if(f.isDirectory() || "wsdl".equalsIgnoreCase(FileUtil.getExtension(f.getName()))) { // NOI18N
1181
result = true;
1182            } else {
1183                result = false;
1184            }
1185            return result;
1186        }
1187        
1188        public String JavaDoc getDescription() {
1189            return NbBundle.getMessage(ClientInfo.class, "LBL_WsdlFilterDescription"); // NOI18N
1190
}
1191    }
1192    
1193    
1194    /** Private method to identify wsdl imports and/or the http wsdl/schema imports
1195     */

1196    private int resolveImports(File JavaDoc file) {
1197        try {
1198            SAXParserFactory JavaDoc factory = SAXParserFactory.newInstance();
1199            factory.setNamespaceAware(true);
1200            SAXParser JavaDoc saxParser = factory.newSAXParser();
1201            ImportsHandler handler= new ImportsHandler();
1202            saxParser.parse(new InputSource JavaDoc(new FileInputStream JavaDoc(file)), handler);
1203            int httpImport = (handler.isHttpImport()?1:0);
1204            int wsdlImport = (handler.isImportingWsdl()?1:0);
1205            return httpImport*2+wsdlImport;
1206        } catch(ParserConfigurationException JavaDoc ex) {
1207            // Bogus WSDL, return null.
1208
} catch(SAXException JavaDoc ex) {
1209            // Bogus WSDL, return null.
1210
} catch(IOException JavaDoc ex) {
1211            // Bogus WSDL, return null.
1212
}
1213        return 0;
1214    }
1215    
1216    /** this is the handler for local wsdl file scanning for imported wsdl/schema files
1217     */

1218    private static class ImportsHandler extends DefaultHandler JavaDoc {
1219        
1220        private static final String JavaDoc W3C_WSDL_SCHEMA = "http://schemas.xmlsoap.org/wsdl"; // NOI18N
1221
private static final String JavaDoc W3C_WSDL_SCHEMA_SLASH = "http://schemas.xmlsoap.org/wsdl/"; // NOI18N
1222

1223        private boolean insideSchema;
1224        private boolean httpImport;
1225        private boolean importingWsdl;
1226        
1227        public void startElement(String JavaDoc uri, String JavaDoc localname, String JavaDoc qname, Attributes JavaDoc attributes) throws SAXException JavaDoc {
1228            if(W3C_WSDL_SCHEMA.equals(uri) || W3C_WSDL_SCHEMA_SLASH.equals(uri)) {
1229                if("types".equals(localname)) { // NOI18N
1230
insideSchema=true;
1231                }
1232                if("import".equals(localname)) { // NOI18N
1233
String JavaDoc wsdlLocation = attributes.getValue("location"); //NOI18N
1234
// test if wsdl is imported using http
1235
if (wsdlLocation!=null && wsdlLocation.startsWith("http://")) { //NOI18N
1236
httpImport=true;
1237                        importingWsdl=true;
1238                    }
1239                }
1240            }
1241            
1242            if(insideSchema && "import".equals(localname)) { // NOI18N
1243
String JavaDoc schemaLocation = attributes.getValue("schemaLocation"); //NOI18N
1244
// test if schema is imported using http
1245
if (schemaLocation!=null && schemaLocation.startsWith("http://")) //NOI18N
1246
httpImport=true;
1247            }
1248        }
1249        
1250        public void endElement(String JavaDoc uri, String JavaDoc localname, String JavaDoc qname) throws SAXException JavaDoc {
1251            if(W3C_WSDL_SCHEMA.equals(uri) || W3C_WSDL_SCHEMA_SLASH.equals(uri)) {
1252                if("types".equals(localname)) { // NOI18N
1253
insideSchema=false;
1254                }
1255            }
1256        }
1257        
1258        boolean isHttpImport() {
1259            return httpImport;
1260        }
1261        
1262        boolean isImportingWsdl() {
1263            return importingWsdl;
1264        }
1265    }
1266    
1267    private String JavaDoc browseProjectServices() {
1268        JaxWsExplorerPanel explorerPanel = new JaxWsExplorerPanel();
1269        DialogDescriptor descriptor = new DialogDescriptor(explorerPanel,
1270                NbBundle.getMessage(ClientInfo.class,"TTL_SelectService")); //NOI18N
1271
explorerPanel.setDescriptor(descriptor);
1272        if(DialogDisplayer.getDefault().notify(descriptor).equals(NotifyDescriptor.OK_OPTION)) {
1273            Node serviceNode = explorerPanel.getSelectedService();
1274            JaxWsWsdlCookie wsdlCookie = (JaxWsWsdlCookie)serviceNode.getCookie(JaxWsWsdlCookie.class);
1275            if (wsdlCookie!=null) return wsdlCookie.getWsdlURL();
1276            else {
1277// jaxrpc split
1278
// JaxRpcWsdlCookie wsdl1Cookie = (JaxRpcWsdlCookie)serviceNode.getCookie(JaxRpcWsdlCookie.class);
1279
// if (wsdl1Cookie!=null) return wsdl1Cookie.getWsdlURL();
1280
}
1281        }
1282        return null;
1283    }
1284    
1285}
1286
Popular Tags