KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > dev > wizard > design > WSDesignFromWSDLPanel


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.dev.wizard.design;
21
22 import org.netbeans.modules.websvc.core.dev.wizard.*;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33 import javax.swing.JFileChooser JavaDoc;
34 import javax.swing.event.ChangeEvent JavaDoc;
35 import javax.swing.event.ChangeListener JavaDoc;
36 import javax.swing.event.DocumentEvent JavaDoc;
37 import javax.swing.event.DocumentListener JavaDoc;
38 import javax.swing.filechooser.FileFilter JavaDoc;
39 import javax.xml.parsers.ParserConfigurationException JavaDoc;
40 import javax.xml.transform.stream.StreamSource JavaDoc;
41 import org.netbeans.api.project.Project;
42 import org.netbeans.modules.j2ee.common.Util;
43 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
44 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
45 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModel;
46 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelListener;
47 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModeler;
48 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelerFactory;
49 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlPort;
50 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlService;
51 import org.netbeans.modules.websvc.core.dev.wizard.nodes.WsdlNode;
52 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
53 import org.netbeans.modules.websvc.jaxws.api.WsdlWrapperGenerator;
54 import org.netbeans.modules.websvc.jaxws.api.WsdlWrapperHandler;
55 import org.openide.DialogDescriptor;
56 import org.openide.DialogDisplayer;
57 import org.openide.ErrorManager;
58 import org.openide.NotifyDescriptor;
59 import org.openide.WizardDescriptor;
60 import org.openide.filesystems.FileObject;
61 import org.openide.filesystems.FileUtil;
62 import org.openide.nodes.Node;
63 import org.openide.util.HelpCtx;
64 import org.openide.util.NbBundle;
65 import org.openide.util.RequestProcessor;
66 import org.xml.sax.SAXException JavaDoc;
67
68 /**
69  *
70  * @author radko
71  */

72 public class WSDesignFromWSDLPanel extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider, DocumentListener JavaDoc {
73     
74     private final List JavaDoc<ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
75     private static String JavaDoc previousDirectory = "";
76     private final FileFilter JavaDoc WSDL_FILE_FILTER = new WsdlFileFilter();
77     private boolean isWaitingForScan = false;
78     
79     private WsdlModeler wsdlModeler;
80     private WsdlModel wsdlModel;
81     private WsdlService service;
82     private WsdlPort port;
83     private WsdlServiceHandler wsdlServiceHandler;
84     private Project project;
85     private WizardDescriptor wizardDescriptor;
86     
87     private JAXWSSupport wss;
88     private boolean jsr109Supported;
89     private boolean jsr109oldSupported;
90     private boolean jwsdpSupported;
91     
92     private RequestProcessor.Task generateWsdlModelTask;
93     private URL JavaDoc wsdlURL;
94     
95     /** Creates new form WebServiceFromWSDLPanel */
96     public WSDesignFromWSDLPanel(Project project) {
97         this.project = project;
98         initComponents();
99         initJsr109Info();
100         
101         jTextFieldWSDLFile.getDocument().addDocumentListener(this);
102         
103         generateWsdlModelTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
104             public void run() {
105                 
106                 WsdlWrapperHandler handler = null;
107                 try {
108                     handler=WsdlWrapperGenerator.parse(wsdlURL.toExternalForm());
109                 } catch (ParserConfigurationException JavaDoc ex) {
110                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,ex);
111                 } catch (SAXException JavaDoc ex) {
112                     String JavaDoc mes = NbBundle.getMessage(WebServiceFromWSDLPanel.class, "ERR_SAXException", ex.getLocalizedMessage()); // NOI18N
113
NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
114                     DialogDisplayer.getDefault().notify(desc);
115                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,ex);
116                 } catch (IOException JavaDoc ex) {
117                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,ex);
118                 }
119                 if (handler!=null && !handler.isServiceElement()) {
120                     StreamSource JavaDoc source = new StreamSource JavaDoc(wsdlURL.toExternalForm());
121                     try {
122                         File JavaDoc wsdlFile = new File JavaDoc(System.getProperty("java.io.tmpdir"), WsdlWrapperGenerator.getWrapperName(wsdlURL)); //NOI18N
123

124                         if(!wsdlFile.exists()) {
125                             try {
126                                 wsdlFile.createNewFile();
127                             } catch(IOException JavaDoc ex) {
128                                 String JavaDoc mes = NbBundle.getMessage(WebServiceFromWSDLPanel.class, "ERR_UnableToCreateTempFile", wsdlFile.getPath()); // NOI18N
129
NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE);
130                                 DialogDisplayer.getDefault().notify(desc);
131                                 return;
132                             }
133                         }
134                         WsdlWrapperGenerator.generateWrapperWSDLContent(wsdlFile,source,handler.getTargetNsPrefix(),wsdlURL.toExternalForm());
135                         wsdlURL=wsdlFile.toURL();
136                     } catch (IOException JavaDoc ex) {
137                         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,ex);
138                     }
139                 }
140                 
141                 final WsdlWrapperHandler wsdlHandler = handler;
142                 
143                 wsdlModeler = WsdlModelerFactory.getDefault().getWsdlModeler(wsdlURL);
144                 wsdlModeler.generateWsdlModel(new WsdlModelListener() {
145                     public void modelCreated(WsdlModel model) {
146                         wsdlModel=model;
147                         if (wsdlModel==null) {
148                             String JavaDoc serviceName=null;
149                             String JavaDoc portName=null;
150                             try {
151                                 wsdlServiceHandler = WsdlServiceHandler.parse(wsdlURL.toExternalForm());
152                                 serviceName = wsdlServiceHandler.getServiceName();
153                                 portName = wsdlServiceHandler.getPortName();
154                             } catch (ParserConfigurationException JavaDoc ex) {
155                             } catch (SAXException JavaDoc ex) {
156                             } catch (IOException JavaDoc ex) {}
157                             if (serviceName!=null && portName!=null) {
158                                 jTextFieldPort.setText(serviceName + "#" + portName);
159                             } else {
160                                 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
161                                         NbBundle.getMessage(WebServiceFromWSDLPanel.class,"TXT_CannotGenerateService",
162                                         wsdlModeler.getCreationException().getLocalizedMessage()),
163                                         NotifyDescriptor.WARNING_MESSAGE)
164                                         );
165                             }
166                         } else {
167                             jButtonBrowsePort.setEnabled(true);
168                             List JavaDoc services = wsdlModel.getServices();
169                             if (services != null && services.size() > 0) {
170                                 service = (WsdlService) services.get(0);
171                                 List JavaDoc ports = service.getPorts();
172                                 if (ports != null && ports.size() > 0)
173                                     port = (WsdlPort) ports.get(0);
174                             }
175                         }
176                         
177                         if (service != null && port != null) {
178                             jTextFieldPort.setText(service.getName() + "#" + port.getName()); //NOI18N
179
if (wsdlHandler!=null) {
180                                 String JavaDoc bindingType = wsdlHandler.getBindingTypeForPort(port.getName());
181                                 if (bindingType!=null) port.setSOAPVersion(bindingType);
182                             }
183                         }
184                         
185                         fireChange(); //refresh wizard buttons
186
}
187                 });
188             }
189         });
190     }
191     
192     /** This method is called from within the constructor to
193      * initialize the form.
194      * WARNING: Do NOT modify this code. The content of this method is
195      * always regenerated by the Form Editor.
196      */

197     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
198
private void initComponents() {
199
200         jLabelWSDLFile = new javax.swing.JLabel JavaDoc();
201         jTextFieldWSDLFile = new javax.swing.JTextField JavaDoc();
202         jButtonWSDLFileBrowse = new javax.swing.JButton JavaDoc();
203         jLabelPortDescription = new javax.swing.JLabel JavaDoc();
204         jLabelPort = new javax.swing.JLabel JavaDoc();
205         jTextFieldPort = new javax.swing.JTextField JavaDoc();
206         jButtonBrowsePort = new javax.swing.JButton JavaDoc();
207         fromWsdlCB = new javax.swing.JCheckBox JavaDoc();
208
209         jLabelWSDLFile.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("MNE_WSDL_File").charAt(0));
210         jLabelWSDLFile.setLabelFor(jTextFieldWSDLFile);
211         jLabelWSDLFile.setText(org.openide.util.NbBundle.getMessage(WSDesignFromWSDLPanel.class, "LBL_WSDL_File")); // NOI18N
212

213         jButtonWSDLFileBrowse.setMnemonic(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("MNE_Browse").charAt(0));
214         jButtonWSDLFileBrowse.setText(org.openide.util.NbBundle.getMessage(WSDesignFromWSDLPanel.class, "LBL_Browse")); // NOI18N
215
jButtonWSDLFileBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
216             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
217                 jButtonWSDLFileBrowseActionPerformed(evt);
218             }
219         });
220
221         jLabelPortDescription.setText(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("LBL_PortMessage")); // NOI18N
222

223         jLabelPort.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("MNE_WebServicePort").charAt(0));
224         jLabelPort.setLabelFor(jTextFieldPort);
225         jLabelPort.setText(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("LBL_WebServicePort")); // NOI18N
226

227         jTextFieldPort.setEditable(false);
228
229         jButtonBrowsePort.setMnemonic(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("MNE_BrowsePort").charAt(0));
230         jButtonBrowsePort.setText(org.openide.util.NbBundle.getBundle(WSDesignFromWSDLPanel.class).getString("LBL_Browse")); // NOI18N
231
jButtonBrowsePort.setEnabled(false);
232         jButtonBrowsePort.addActionListener(new java.awt.event.ActionListener JavaDoc() {
233             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
234                 jButtonBrowsePortActionPerformed(evt);
235             }
236         });
237
238         fromWsdlCB.setSelected(true);
239         fromWsdlCB.setText(org.openide.util.NbBundle.getMessage(WSDesignFromWSDLPanel.class, "CB_Create_from_WSDL")); // NOI18N
240
fromWsdlCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
241         fromWsdlCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
242         fromWsdlCB.addActionListener(new java.awt.event.ActionListener JavaDoc() {
243             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
244                 fromWsdlCBActionPerformed(evt);
245             }
246         });
247
248         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
249         this.setLayout(layout);
250         layout.setHorizontalGroup(
251             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
252             .add(layout.createSequentialGroup()
253                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
254                     .add(layout.createSequentialGroup()
255                         .addContainerGap()
256                         .add(jLabelPortDescription))
257                     .add(layout.createSequentialGroup()
258                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
259                             .add(jLabelPort)
260                             .add(layout.createSequentialGroup()
261                                 .addContainerGap()
262                                 .add(jLabelWSDLFile))
263                             .add(layout.createSequentialGroup()
264                                 .addContainerGap()
265                                 .add(fromWsdlCB)))
266                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
267                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
268                             .add(layout.createSequentialGroup()
269                                 .add(jTextFieldWSDLFile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
270                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
271                                 .add(jButtonWSDLFileBrowse))
272                             .add(layout.createSequentialGroup()
273                                 .add(jTextFieldPort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 575, Short.MAX_VALUE)
274                                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
275                                 .add(jButtonBrowsePort, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)))))
276                 .addContainerGap())
277         );
278         layout.setVerticalGroup(
279             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
280             .add(layout.createSequentialGroup()
281                 .add(20, 20, 20)
282                 .add(fromWsdlCB)
283                 .add(18, 18, 18)
284                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
285                     .add(jButtonWSDLFileBrowse)
286                     .add(jTextFieldWSDLFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
287                     .add(jLabelWSDLFile))
288                 .add(16, 16, 16)
289                 .add(jLabelPortDescription)
290                 .add(17, 17, 17)
291                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
292                     .add(jLabelPort)
293                     .add(jButtonBrowsePort)
294                     .add(jTextFieldPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
295                 .addContainerGap(149, Short.MAX_VALUE))
296         );
297
298         jTextFieldWSDLFile.getAccessibleContext().setAccessibleDescription(null);
299         jButtonWSDLFileBrowse.getAccessibleContext().setAccessibleDescription(null);
300         jTextFieldPort.getAccessibleContext().setAccessibleDescription(null);
301     }// </editor-fold>//GEN-END:initComponents
302

303     private void fromWsdlCBActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_fromWsdlCBActionPerformed
304
boolean enabled = this.fromWsdlCB.isSelected();
305         this.enableWidgets(enabled);
306 }//GEN-LAST:event_fromWsdlCBActionPerformed
307

308     private void jButtonBrowsePortActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowsePortActionPerformed
309
Node root = new WsdlNode(wsdlModel);
310         PortChooser chooser = new PortChooser(root);
311         final DialogDescriptor dd = new DialogDescriptor(chooser, org.openide.util.NbBundle.getMessage(WebServiceFromWSDLPanel.class, "LBL_SelectPortDescription")); //NOI18N
312

313         chooser.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
314             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
315                 if (evt.getPropertyName().equals(PortChooser.IS_VALID)) {
316                     Object JavaDoc newvalue = evt.getNewValue();
317                     if ((newvalue != null) && (newvalue instanceof Boolean JavaDoc)) {
318                         dd.setValid(((Boolean JavaDoc) newvalue).booleanValue());
319                     }
320                 }
321             }
322         });
323         
324         Object JavaDoc result = DialogDisplayer.getDefault().notify(dd);
325         
326         if (result == DialogDescriptor.OK_OPTION) {
327             if (Util.isJavaEE5orHigher(project) ||
328                     (!jsr109Supported && !jsr109oldSupported ||
329                     (!jsr109Supported && jsr109oldSupported && jwsdpSupported ))) {
330                 jTextFieldPort.setText(chooser.getSelectedPortOwnerName() + "#" + chooser.getSelectedNodes()[0].getDisplayName()); //NOI18N
331
service = wsdlModel.getServiceByName(chooser.getSelectedPortOwnerName());
332                 port = service.getPortByName(chooser.getSelectedNodes()[0].getDisplayName());
333             }
334         }
335     }//GEN-LAST:event_jButtonBrowsePortActionPerformed
336

337     private void jButtonWSDLFileBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonWSDLFileBrowseActionPerformed
338
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(previousDirectory);
339         chooser.setMultiSelectionEnabled(false);
340         chooser.setAcceptAllFileFilterUsed(false);
341         chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
342         chooser.setFileFilter(WSDL_FILE_FILTER);
343         
344         if(chooser.showOpenDialog(WSDesignFromWSDLPanel.this) == JFileChooser.APPROVE_OPTION) {
345             File JavaDoc wsdlFile = chooser.getSelectedFile();
346             jTextFieldWSDLFile.setText(wsdlFile.getAbsolutePath());
347             previousDirectory = wsdlFile.getPath();
348         }
349     }//GEN-LAST:event_jButtonWSDLFileBrowseActionPerformed
350

351     
352     // Variables declaration - do not modify//GEN-BEGIN:variables
353
private javax.swing.JCheckBox JavaDoc fromWsdlCB;
354     private javax.swing.JButton JavaDoc jButtonBrowsePort;
355     private javax.swing.JButton JavaDoc jButtonWSDLFileBrowse;
356     private javax.swing.JLabel JavaDoc jLabelPort;
357     private javax.swing.JLabel JavaDoc jLabelPortDescription;
358     private javax.swing.JLabel JavaDoc jLabelWSDLFile;
359     private javax.swing.JTextField JavaDoc jTextFieldPort;
360     private javax.swing.JTextField JavaDoc jTextFieldWSDLFile;
361     // End of variables declaration//GEN-END:variables
362

363     void validate(WizardDescriptor wizardDescriptor) {
364     }
365     
366     private void initJsr109Info() {
367         wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory());
368         if (wss != null) {
369             Map JavaDoc properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
370             String JavaDoc serverInstance = (String JavaDoc)properties.get("j2ee.server.instance"); //NOI18N
371
if (serverInstance != null) {
372                 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance);
373                 if (j2eePlatform != null) {
374                     jsr109Supported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109);
375                     jsr109oldSupported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE);
376                     jwsdpSupported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP);
377                 }
378             }
379         }
380     }
381     
382     /**
383      * If the project the web service is being created is not on a JSR 109 platform,
384      * its Java source level must be at least 1.5
385      */

386     private boolean checkNonJsr109Valid() {
387         if (wss != null) {
388             if(!jsr109Supported && !jsr109oldSupported ||
389                     (!jsr109Supported && jsr109oldSupported && jwsdpSupported )){
390                 if (Util.isSourceLevel14orLower(project)) {
391                     wizardDescriptor.putProperty("WizardPanel_errorMessage",
392                             NbBundle.getMessage(WebServiceFromWSDLPanel.class, "ERR_NeedProperSourceLevel")); // NOI18N
393
return false;
394                 }
395             }
396         }
397         return true;
398     }
399     
400     private boolean projectHasEmbeddedSpaces(){
401         FileObject projectDir = project.getProjectDirectory();
402         File JavaDoc projectDirFile = FileUtil.toFile(projectDir);
403         String JavaDoc path = projectDirFile.getAbsolutePath();
404         int index = path.indexOf(" ");
405         return index != -1;
406     }
407     
408     boolean isValid(WizardDescriptor wizardDescriptor) {
409         //first check for JDK compliance (for non-JSR 109)
410
if(!checkNonJsr109Valid()){
411             return false;
412         }
413         
414         String JavaDoc wsdlFilePath = jTextFieldWSDLFile.getText().trim();
415         
416         if(wsdlFilePath == null || wsdlFilePath.length() == 0) {
417             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
418
NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_EnterWsdlName")); // NOI18N
419
return false; // unspecified WSDL file
420
}
421         
422         File JavaDoc f = new File JavaDoc(wsdlFilePath);
423         String JavaDoc wsdlFileText = f.getAbsolutePath();
424         f = getCanonicalFile(f);
425         if(f == null) {
426             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
427
NbBundle.getMessage(WebServiceFromWSDLPanel.class, "ERR_WsdlInvalid")); // NOI18N
428
return false; // invalid WSDL file
429
}
430         
431         if(!f.exists()) {
432             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
433
NbBundle.getMessage(WebServiceFromWSDLPanel.class, "ERR_WsdlDoesNotExist")); // NOI18N
434
return false; // invalid WSDL file
435
}
436         
437         if (Util.isJavaEE5orHigher(project) ||
438                 (!jsr109Supported && !jsr109oldSupported ||
439                 (!jsr109Supported && jsr109oldSupported && jwsdpSupported ))) {
440             if (wsdlModel != null) {
441                 if (service == null) {
442                     wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_NoService")); // NOI18N
443
return false;
444                 }
445                 
446                 if (port == null) {
447                     wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_NoPort")); // NOI18N
448
return false;
449                 }
450             } else {
451                 if (wsdlServiceHandler!=null && wsdlServiceHandler.getServiceName()!=null && wsdlServiceHandler.getPortName()!=null) {
452                     return true;
453                 } else {
454                     wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_NoPort")); // NOI18N
455
return false;
456                 }
457             }
458         }
459         
460         //warning if the project directory has embedded spaces
461
//TODO - Remove this when the jwsdp version that fixes this problem is available
462
if(projectHasEmbeddedSpaces()){
463             wizardDescriptor.putProperty("WizardPanel_errorMessage",
464                     NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_SPACE_IN_PROJECT_PATH")); // NOI18N
465
} else{
466             wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); // NOI18N
467
}
468         // Retouche
469
// if (JavaMetamodel.getManager().isScanInProgress()) {
470
// if (!isWaitingForScan) {
471
// isWaitingForScan = true;
472
// RequestProcessor.getDefault().post(new Runnable() {
473
// public void run() {
474
// JavaMetamodel.getManager().waitScanFinished();
475
// isWaitingForScan = false;
476
// fireChange();
477
// }
478
// });
479
// }
480
// wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceFromWSDLPanel.class, "MSG_ScanningInProgress")); //NOI18N
481
// return false;
482
// } else
483
wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
484

485         return true;
486     }
487     
488     void store(WizardDescriptor d) {
489         d.putProperty(WizardProperties.WEB_SERVICE_TYPE, getServiceType());
490         d.putProperty(WizardProperties.WSDL_FILE_PATH, jTextFieldWSDLFile.getText().trim());
491         d.putProperty(WizardProperties.WSDL_MODEL, wsdlModel);
492         d.putProperty(WizardProperties.WSDL_MODELER, wsdlModeler);
493         d.putProperty(WizardProperties.WSDL_SERVICE, service);
494         d.putProperty(WizardProperties.WSDL_PORT, port);
495         d.putProperty(WizardProperties.WSDL_SERVICE_HANDLER,wsdlServiceHandler);
496     }
497     
498     public int getServiceType() {
499         if (!this.fromWsdlCB.isSelected())
500             return WizardProperties.FROM_SCRATCH;
501         else
502            return -1; //TODO: Need to define a service type for from-wsdl
503
}
504     
505     void read(WizardDescriptor wizardDescriptor) {
506         this.wizardDescriptor = wizardDescriptor;
507     }
508     
509     public HelpCtx getHelpCtx() {
510         return new HelpCtx(WebServiceFromWSDLPanel.class);
511     }
512     
513     public void addChangeListener(ChangeListener JavaDoc l) {
514         listeners.add(l);
515     }
516     
517     public void removeChangeListener(ChangeListener JavaDoc l) {
518         listeners.remove(l);
519     }
520     
521     private void fireChange() {
522         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
523         Iterator JavaDoc<ChangeListener JavaDoc> it = listeners.iterator();
524         while (it.hasNext()) {
525             it.next().stateChanged(e);
526         }
527     }
528     
529     private void updatePortBrowseButton() {
530         wsdlModel = null;
531         service = null;
532         port = null;
533         jTextFieldPort.setText(""); //NOI18N
534

535         String JavaDoc wsdlFilePath = jTextFieldWSDLFile.getText().trim();
536         
537         if(wsdlFilePath == null || wsdlFilePath.length() == 0) {
538             jButtonBrowsePort.setEnabled(false);
539         } else {
540             File JavaDoc f = new File JavaDoc(wsdlFilePath);
541             String JavaDoc wsdlFileText = f.getAbsolutePath();
542             f = getCanonicalFile(f);
543             if(f == null) {
544                 jButtonBrowsePort.setEnabled(false);
545             } else if(!f.exists()) {
546                 jButtonBrowsePort.setEnabled(false);
547             } else {
548                 fireChange(); //call to disable Finish button
549
if (Util.isJavaEE5orHigher(project) ||
550                         (!jsr109Supported && !jsr109oldSupported ||
551                         (!jsr109Supported && jsr109oldSupported && jwsdpSupported))) {
552                     createModel();
553                 }
554             }
555         }
556     }
557     
558     private void createModel() {
559         File JavaDoc normalizedWsdlFilePath = FileUtil.normalizeFile(new File JavaDoc(jTextFieldWSDLFile.getText().trim()));
560         wsdlURL = null;
561         try {
562             wsdlURL = normalizedWsdlFilePath.toURL();
563         } catch (MalformedURLException JavaDoc ex) {
564             ex.printStackTrace();
565         }
566         
567         generateWsdlModelTask.schedule(1000);
568     }
569     
570     public void insertUpdate(DocumentEvent JavaDoc e) {
571         updatePortBrowseButton();
572         fireChange();
573     }
574     
575     public void removeUpdate(DocumentEvent JavaDoc e) {
576         updatePortBrowseButton();
577         fireChange();
578     }
579     
580     public void changedUpdate(DocumentEvent JavaDoc e) {
581         updatePortBrowseButton();
582         fireChange();
583     }
584     
585     /** Retrieve the canonical version of a File instance, converting the possible
586      * IOException into a null (presumably for error presentation purposes).
587      * Copied from Utilities in core.
588      * FIX-ME: removet this when proper dependencies have been set up
589      */

590     public static File JavaDoc getCanonicalFile(File JavaDoc f) {
591         File JavaDoc f1;
592         try {
593             f1 = f.getCanonicalFile();
594         } catch (java.io.IOException JavaDoc e) {
595             f1 = null;
596         }
597         return f1;
598     }
599     
600     private static class WsdlFileFilter extends FileFilter JavaDoc {
601         public boolean accept(File JavaDoc f) {
602             boolean result;
603             if(f.isDirectory() || "wsdl".equalsIgnoreCase(FileUtil.getExtension(f.getName()))) { // NOI18N
604
result = true;
605             } else {
606                 result = false;
607             }
608             return result;
609         }
610         
611         public String JavaDoc getDescription() {
612             return NbBundle.getMessage(WebServiceFromWSDLPanel.class, "LBL_WsdlFilterDescription"); // NOI18N
613
}
614     }
615     
616     private void enableWidgets(boolean enable){
617         this.jButtonBrowsePort.setEnabled(enable);
618         this.jButtonWSDLFileBrowse.setEnabled(enable);
619         this.jLabelPort.setEnabled(enable);
620         this.jLabelPortDescription.setEnabled(enable);
621         this.jLabelWSDLFile.setEnabled(enable);
622         this.jTextFieldPort.setEnabled(enable);
623         this.jTextFieldWSDLFile.setEnabled(enable);
624     }
625 }
626
Popular Tags