Source Code Cross Referenced for WsdlUIPanel.java in  » IDE-Netbeans » xml » org » netbeans » modules » xml » wsdl » ui » wizard » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » xml » org.netbeans.modules.xml.wsdl.ui.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.xml.wsdl.ui.wizard;
043:
044:        import java.io.File;
045:        import java.io.IOException;
046:        import java.net.MalformedURLException;
047:        import java.net.URISyntaxException;
048:        import java.net.URL;
049:        import java.util.ArrayList;
050:        import java.util.List;
051:
052:        import javax.swing.JTextField;
053:
054:        import org.netbeans.api.project.FileOwnerQuery;
055:        import org.netbeans.api.project.Project;
056:        import org.netbeans.modules.xml.catalogsupport.DefaultProjectCatalogSupport;
057:        import org.netbeans.modules.xml.schema.model.Schema;
058:        import org.netbeans.modules.xml.schema.model.SchemaModel;
059:        import org.netbeans.modules.xml.schema.model.SchemaModelFactory;
060:        import org.netbeans.modules.xml.wsdl.model.Definitions;
061:        import org.netbeans.modules.xml.wsdl.model.WSDLModel;
062:        import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema;
063:        import org.netbeans.modules.xml.wsdl.ui.netbeans.module.UIUtilities;
064:        import org.netbeans.modules.xml.xam.Model;
065:        import org.netbeans.modules.xml.xam.ModelSource;
066:        import org.netbeans.modules.xml.xam.locator.CatalogModelException;
067:        import org.openide.DialogDescriptor;
068:        import org.openide.DialogDisplayer;
069:        import org.openide.ErrorManager;
070:        import org.openide.WizardValidationException;
071:        import org.openide.filesystems.FileObject;
072:        import org.openide.filesystems.FileUtil;
073:        import org.openide.loaders.DataObject;
074:        import org.openide.util.NbBundle;
075:        import org.xml.sax.Attributes;
076:        import org.xml.sax.InputSource;
077:        import org.xml.sax.SAXException;
078:        import org.xml.sax.XMLReader;
079:
080:        /** WsdlUIPanel.java - bottom panel for WSDL wizard
081:         *
082:         * @author  mkuchtiak
083:         */
084:        public class WsdlUIPanel extends javax.swing.JPanel {
085:
086:            private static final String TARGET_URL_PREFIX = NbBundle
087:                    .getMessage(WsdlUIPanel.class, "TXT_defaultTNS"); //NOI18N
088:
089:            private WsdlPanel wizardPanel;
090:            private javax.swing.JTextField fileNameTF;
091:
092:            private boolean hasUserModifiedNamespace = false;
093:
094:            private NamespaceDocListener mListener = new NamespaceDocListener();
095:
096:            /** Creates new form WsdlUIPanel */
097:            WsdlUIPanel(WsdlPanel wizardPanel) {
098:                initComponents();
099:                this .wizardPanel = wizardPanel;
100:                nsTF.setText(TARGET_URL_PREFIX);
101:            }
102:
103:            void attachFileNameListener(javax.swing.JTextField fileNameTextField) {
104:                this .fileNameTF = fileNameTextField;
105:                if (fileNameTF != null) {
106:                    nsTF.setText(TARGET_URL_PREFIX + fileNameTF.getText());
107:                    DocListener list = new DocListener();
108:                    javax.swing.text.Document doc = fileNameTF.getDocument();
109:                    doc.addDocumentListener(list);
110:                } else {
111:                    nsTF.setText(TARGET_URL_PREFIX);
112:                }
113:
114:                nsTF.getDocument().addDocumentListener(mListener);
115:            }
116:
117:            /** This method is called from within the constructor to
118:             * initialize the form.
119:             * WARNING: Do NOT modify this code. The content of this method is
120:             * always regenerated by the Form Editor.
121:             */
122:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
123:            private void initComponents() {
124:                java.awt.GridBagConstraints gridBagConstraints;
125:
126:                cbImport = new javax.swing.JCheckBox();
127:                schemaTF = new javax.swing.JTextField();
128:                browseButton = new javax.swing.JButton();
129:                schemaLB = new javax.swing.JLabel();
130:                namespaceLB = new javax.swing.JLabel();
131:                nsTF = new javax.swing.JTextField();
132:                jPanel1 = new javax.swing.JPanel();
133:
134:                setLayout(new java.awt.GridBagLayout());
135:
136:                org.openide.awt.Mnemonics.setLocalizedText(cbImport,
137:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
138:                                "LBL_importSchema")); // NOI18N
139:                cbImport.setToolTipText(org.openide.util.NbBundle.getMessage(
140:                        WsdlUIPanel.class, "HINT_schemaFiles")); // NOI18N
141:                cbImport.setBorder(javax.swing.BorderFactory.createEmptyBorder(
142:                        0, 0, 0, 0));
143:                cbImport.setMargin(new java.awt.Insets(0, 0, 0, 0));
144:                cbImport.addItemListener(new java.awt.event.ItemListener() {
145:                    public void itemStateChanged(java.awt.event.ItemEvent evt) {
146:                        cbImportItemStateChanged(evt);
147:                    }
148:                });
149:                gridBagConstraints = new java.awt.GridBagConstraints();
150:                gridBagConstraints.gridx = 0;
151:                gridBagConstraints.gridy = 2;
152:                gridBagConstraints.gridwidth = 3;
153:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 6, 5);
155:                add(cbImport, gridBagConstraints);
156:                cbImport.getAccessibleContext().setAccessibleName(
157:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
158:                                "LBL_importSchema")); // NOI18N
159:                cbImport.getAccessibleContext().setAccessibleDescription(
160:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
161:                                "HINT_schemaFiles")); // NOI18N
162:
163:                schemaTF.setEditable(false);
164:                schemaTF.setToolTipText(org.openide.util.NbBundle.getBundle(
165:                        WsdlUIPanel.class).getString("HINT_schemaFiles")); // NOI18N
166:                gridBagConstraints = new java.awt.GridBagConstraints();
167:                gridBagConstraints.gridx = 1;
168:                gridBagConstraints.gridy = 3;
169:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
170:                gridBagConstraints.weightx = 1.0;
171:                gridBagConstraints.insets = new java.awt.Insets(0, 5, 2, 0);
172:                add(schemaTF, gridBagConstraints);
173:                schemaTF.getAccessibleContext().setAccessibleName(
174:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
175:                                "LBL_schemaFiles")); // NOI18N
176:                schemaTF.getAccessibleContext().setAccessibleDescription(
177:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
178:                                "A11Y_schemaTF")); // NOI18N
179:
180:                org.openide.awt.Mnemonics.setLocalizedText(browseButton,
181:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
182:                                "LBL_browse")); // NOI18N
183:                browseButton.setToolTipText(org.openide.util.NbBundle
184:                        .getMessage(WsdlUIPanel.class, "A11Y_browse")); // NOI18N
185:                browseButton.setEnabled(false);
186:                browseButton
187:                        .addActionListener(new java.awt.event.ActionListener() {
188:                            public void actionPerformed(
189:                                    java.awt.event.ActionEvent evt) {
190:                                browseButtonActionPerformed(evt);
191:                            }
192:                        });
193:                gridBagConstraints = new java.awt.GridBagConstraints();
194:                gridBagConstraints.gridx = 2;
195:                gridBagConstraints.gridy = 3;
196:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
197:                gridBagConstraints.insets = new java.awt.Insets(0, 5, 2, 0);
198:                add(browseButton, gridBagConstraints);
199:                browseButton.getAccessibleContext().setAccessibleName(
200:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
201:                                "LBL_browse")); // NOI18N
202:
203:                schemaLB.setLabelFor(schemaTF);
204:                org.openide.awt.Mnemonics.setLocalizedText(schemaLB,
205:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
206:                                "LBL_schemaFiles")); // NOI18N
207:                schemaLB.setToolTipText(org.openide.util.NbBundle.getMessage(
208:                        WsdlUIPanel.class, "HINT_schemaFiles")); // NOI18N
209:                gridBagConstraints = new java.awt.GridBagConstraints();
210:                gridBagConstraints.gridx = 0;
211:                gridBagConstraints.gridy = 3;
212:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
213:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
214:                add(schemaLB, gridBagConstraints);
215:
216:                namespaceLB.setLabelFor(nsTF);
217:                org.openide.awt.Mnemonics.setLocalizedText(namespaceLB,
218:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
219:                                "LBL_targetNamespace")); // NOI18N
220:                namespaceLB.setToolTipText(org.openide.util.NbBundle
221:                        .getMessage(WsdlUIPanel.class, "HINT_targetNamespace")); // NOI18N
222:                gridBagConstraints = new java.awt.GridBagConstraints();
223:                gridBagConstraints.gridx = 0;
224:                gridBagConstraints.gridy = 0;
225:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
226:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 2, 0);
227:                add(namespaceLB, gridBagConstraints);
228:                namespaceLB.getAccessibleContext().setAccessibleName(
229:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
230:                                "LBL_targetNamespace")); // NOI18N
231:                namespaceLB.getAccessibleContext().setAccessibleDescription(
232:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
233:                                "HINT_targetNamespace")); // NOI18N
234:
235:                java.util.ResourceBundle bundle = java.util.ResourceBundle
236:                        .getBundle("org/netbeans/modules/xml/wsdl/ui/wizard/Bundle"); // NOI18N
237:                nsTF.setToolTipText(bundle.getString("HINT_targetNamespace")); // NOI18N
238:                gridBagConstraints = new java.awt.GridBagConstraints();
239:                gridBagConstraints.gridx = 1;
240:                gridBagConstraints.gridy = 0;
241:                gridBagConstraints.gridwidth = 2;
242:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
243:                gridBagConstraints.weightx = 1.0;
244:                gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 0);
245:                add(nsTF, gridBagConstraints);
246:                nsTF
247:                        .getAccessibleContext()
248:                        .setAccessibleName(
249:                                org.openide.util.NbBundle
250:                                        .getMessage(WsdlUIPanel.class,
251:                                                "WsdlUIPanel.nsTF.AccessibleContext.accessibleName")); // NOI18N
252:                nsTF.getAccessibleContext().setAccessibleDescription(
253:                        org.openide.util.NbBundle.getMessage(WsdlUIPanel.class,
254:                                "HINT_targetNamespace")); // NOI18N
255:
256:                gridBagConstraints = new java.awt.GridBagConstraints();
257:                gridBagConstraints.gridx = 0;
258:                gridBagConstraints.gridy = 5;
259:                gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
260:                gridBagConstraints.weighty = 1.0;
261:                add(jPanel1, gridBagConstraints);
262:            }// </editor-fold>//GEN-END:initComponents
263:
264:            private void browseButtonActionPerformed(
265:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
266:                // Create a temporary file and model for the import creator to use.
267:                Project project = wizardPanel.getProject();
268:                FileObject prjdir = project.getProjectDirectory();
269:                //XXX:SKINI: Relook this hack
270:                // HACK: hard-coded NB project directory name
271:                FileObject privdir = prjdir.getFileObject("nbproject/private");
272:                // We prefer to use the private directory, but at the very
273:                // least our file needs to be inside the project.
274:                File directory = FileUtil.toFile(privdir != null ? privdir
275:                        : prjdir);
276:                String fname = fileNameTF.getText();
277:                if (fname == null || fname.length() == 0) {
278:                    fname = "wizard";
279:                }
280:                File file = null;
281:                try {
282:                    file = File.createTempFile(fname, ".wsdl", directory);
283:                    wizardPanel.populateFileFromTemplate(file);
284:                } catch (Exception e) {
285:                    // This is quite unexpected.
286:                    ErrorManager.getDefault().notify(e);
287:                    if (file != null) {
288:                        file.delete();
289:                    }
290:                    return;
291:                }
292:                WSDLModel model = wizardPanel.prepareModelFromFile(file, fname);
293:                model.startTransaction();
294:                WSDLSchema wsdlSchema = model.getFactory().createWSDLSchema();
295:                Definitions defs = model.getDefinitions();
296:                defs.getTypes().addExtensibilityElement(wsdlSchema);
297:                SchemaModel schemaModel = wsdlSchema.getSchemaModel();
298:                Schema schema = schemaModel.getSchema();
299:                // Must set namespace on embedded schema for import dialog to work.
300:                schema.setTargetNamespace(defs.getTargetNamespace());
301:                model.endTransaction();
302:
303:                // Use a specialized import creator for selecting files.
304:                String original = schemaTF.getText().trim();
305:                ImportSchemaCreator creator = new ImportSchemaCreator(schema,
306:                        model, original);
307:                DialogDescriptor descriptor = UIUtilities.getCreatorDialog(
308:                        creator, NbBundle.getMessage(WsdlUIPanel.class,
309:                                "TITLE_selectSchema"), true);
310:                descriptor.setValid(false);
311:                Object result = DialogDisplayer.getDefault().notify(descriptor);
312:                if (result == DialogDescriptor.OK_OPTION) {
313:                    String selections = creator.getSelectedFiles();
314:                    schemaTF.setText(selections);
315:                    schemaTF.firePropertyChange("VALUE_SET", false, true);
316:                }
317:
318:                // Must use DataObject to delete the temporary file.
319:                file = FileUtil.normalizeFile(file);
320:                FileObject fobj = FileUtil.toFileObject(file);
321:                try {
322:                    DataObject.find(fobj).delete();
323:                } catch (IOException ex) {
324:                    // Ignore, either the file isn't there or we can't delete it.
325:                }
326:            }//GEN-LAST:event_browseButtonActionPerformed
327:
328:            private void cbImportItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbImportItemStateChanged
329:                if (cbImport.isSelected()) {
330:                    schemaTF.setEditable(true);
331:                    browseButton.setEnabled(true);
332:                } else {
333:                    schemaTF.setEditable(false);
334:                    browseButton.setEnabled(false);
335:                }
336:            }//GEN-LAST:event_cbImportItemStateChanged
337:
338:            // Variables declaration - do not modify//GEN-BEGIN:variables
339:            private javax.swing.JButton browseButton;
340:            private javax.swing.JCheckBox cbImport;
341:            private javax.swing.JPanel jPanel1;
342:            private javax.swing.JLabel namespaceLB;
343:            private javax.swing.JTextField nsTF;
344:            private javax.swing.JLabel schemaLB;
345:            private javax.swing.JTextField schemaTF;
346:
347:            // End of variables declaration//GEN-END:variables
348:
349:            private class NamespaceDocListener implements 
350:                    javax.swing.event.DocumentListener {
351:
352:                public void removeUpdate(javax.swing.event.DocumentEvent e) {
353:                    documentChanged(e);
354:                }
355:
356:                public void insertUpdate(javax.swing.event.DocumentEvent e) {
357:                    documentChanged(e);
358:                }
359:
360:                public void changedUpdate(javax.swing.event.DocumentEvent e) {
361:                    documentChanged(e);
362:                }
363:
364:                private void documentChanged(javax.swing.event.DocumentEvent e) {
365:                    hasUserModifiedNamespace = true;
366:                }
367:            }
368:
369:            private class DocListener implements 
370:                    javax.swing.event.DocumentListener {
371:
372:                public void removeUpdate(javax.swing.event.DocumentEvent e) {
373:                    documentChanged(e);
374:                }
375:
376:                public void insertUpdate(javax.swing.event.DocumentEvent e) {
377:                    documentChanged(e);
378:                }
379:
380:                public void changedUpdate(javax.swing.event.DocumentEvent e) {
381:                    documentChanged(e);
382:                }
383:
384:                private void documentChanged(javax.swing.event.DocumentEvent e) {
385:                    if (!hasUserModifiedNamespace) {
386:                        nsTF.getDocument().removeDocumentListener(mListener);
387:                        nsTF.setText(TARGET_URL_PREFIX + fileNameTF.getText());
388:                        nsTF.getDocument().addDocumentListener(mListener);
389:                    }
390:
391:                }
392:            }
393:
394:            /** Class than provides basic informationn about schema file
395:             */
396:            static class SchemaInfo {
397:                private java.net.URL url;
398:
399:                SchemaInfo(java.net.URL url) {
400:                    this .url = url;
401:                }
402:
403:                java.net.URL getURL() {
404:                    return url;
405:                }
406:
407:                String getNamespace() {
408:                    InputSource is = new InputSource(url.toExternalForm());
409:                    try {
410:                        return parse(is);
411:                    } catch (java.io.IOException ex) {
412:                    } catch (SAXException ex) {
413:                    }
414:                    return "";
415:                }
416:
417:                String getSchemaName() {
418:                    return url.toExternalForm();
419:                }
420:
421:                /** Parses XML document and creates the list of tags
422:                 */
423:                private String parse(InputSource is)
424:                        throws java.io.IOException, SAXException {
425:                    XMLReader xmlReader = org.openide.xml.XMLUtil
426:                            .createXMLReader();
427:                    NsHandler handler = new NsHandler();
428:                    xmlReader.setContentHandler(handler);
429:                    //xmlReader.setFeature("http://xml.org/sax/features/use-locator2",true);
430:                    try {
431:                        xmlReader.parse(is);
432:                    } catch (SAXException ex) {
433:                        if (!"EXIT".equals(ex.getMessage()))
434:                            throw ex; //NOI18N
435:                    }
436:                    String ns = handler.getNs();
437:                    if (ns == null)
438:                        return "";
439:                    return ns;
440:                }
441:
442:                private static class NsHandler extends
443:                        org.xml.sax.helpers.DefaultHandler {
444:                    private String ns;
445:
446:                    @Override
447:                    public void startElement(String uri, String localName,
448:                            String qName, Attributes attributes)
449:                            throws SAXException {
450:                        if (qName.endsWith("schema")) { //NOI18N
451:                            ns = attributes.getValue("targetNamespace"); //NOI18N
452:                            throw new SAXException("EXIT"); //NOI18N
453:                        }
454:                    }
455:
456:                    String getNs() {
457:                        return ns;
458:                    }
459:                }
460:
461:            }
462:
463:            String getNS() {
464:                return nsTF.getText();
465:            }
466:
467:            boolean isImport() {
468:                return cbImport.isSelected();
469:            }
470:
471:            SchemaInfo[] getSchemas() {
472:                if (cbImport.isSelected()) {
473:                    String schemas = schemaTF.getText();
474:                    String[] urls = schemas.split(",");
475:                    List<SchemaInfo> infos = new ArrayList<SchemaInfo>();
476:                    for (int i = 0; i < urls.length; i++) {
477:                        String urlString = urls[i].trim();
478:                        if (urlString.length() == 0)
479:                            continue;
480:                        URL url = null;
481:                        try {
482:                            File file = new File(urlString);
483:                            if (file.exists()) {
484:                                url = file.toURI().toURL();
485:                            } else {
486:                                url = new java.net.URL(urlString);
487:                            }
488:                            infos.add(new SchemaInfo(url));
489:                        } catch (java.net.MalformedURLException ex) {
490:                            // testing if target folder contains XML Schema
491:                            try {
492:                                org.openide.loaders.DataFolder folder = wizardPanel
493:                                        .getTemplateWizard().getTargetFolder();
494:                                org.openide.filesystems.FileObject fo = folder
495:                                        .getPrimaryFile();
496:                                if ((fo.getFileObject(urlString)) != null) {
497:                                    String parentURL = fo.getURL()
498:                                            .toExternalForm();
499:                                    infos.add(new SchemaInfo(new java.net.URL(
500:                                            parentURL + urlString)));
501:                                }
502:                            } catch (java.io.IOException ex1) {
503:                            }
504:                        }
505:                    }
506:                    return infos.toArray(new SchemaInfo[infos.size()]);
507:                }
508:                return new SchemaInfo[] {};
509:            }
510:
511:            public void validateSchemas() throws WizardValidationException {
512:                if (cbImport.isSelected()) {
513:                    String schemas = schemaTF.getText();
514:                    String[] urls = schemas.split(",");
515:                    for (int i = 0; i < urls.length; i++) {
516:                        String urlString = urls[i].trim();
517:                        if (urlString.length() == 0)
518:                            continue;
519:                        createSchemaModel(urlString);
520:                    }
521:                }
522:
523:            }
524:
525:            private void createSchemaModel(String urlString)
526:                    throws WizardValidationException {
527:                File file = new File(urlString);
528:                if (!file.exists()) {
529:                    file = null;
530:                }
531:                if (file == null) {
532:                    URL url = null;
533:                    try {
534:                        url = new java.net.URL(urlString);
535:                    } catch (MalformedURLException e) {
536:                        org.openide.loaders.DataFolder folder;
537:                        try {
538:                            folder = wizardPanel.getTemplateWizard()
539:                                    .getTargetFolder();
540:                            org.openide.filesystems.FileObject fo = folder
541:                                    .getPrimaryFile();
542:                            if ((fo.getFileObject(urlString)) != null) {
543:                                String parentURL = fo.getURL().toExternalForm();
544:                                try {
545:                                    url = new java.net.URL(parentURL
546:                                            + urlString);
547:                                } catch (MalformedURLException e1) {
548:                                    throw new WizardValidationException(
549:                                            schemaTF, e1.getMessage(), e1
550:                                                    .getLocalizedMessage());
551:                                }
552:                            }
553:                        } catch (IOException e1) {
554:                            throw new WizardValidationException(schemaTF, e1
555:                                    .getMessage(), e1.getLocalizedMessage());
556:                        }
557:                        if (url == null) {
558:                            String errorString = NbBundle.getMessage(
559:                                    WsdlUIPanel.class, "INVALID_SCHEMA_FILE",
560:                                    urlString);
561:                            throw new WizardValidationException(schemaTF,
562:                                    errorString, errorString);
563:                        }
564:                    }
565:                    try {
566:                        file = new File(url.toURI());
567:                    } catch (URISyntaxException e) {
568:                        throw new WizardValidationException(schemaTF, e
569:                                .getMessage(), e.getLocalizedMessage());
570:                    }
571:                }
572:
573:                if (!file.isFile()) {
574:                    throw new WizardValidationException(schemaTF,
575:                            "INVALID_SCHEMA_FILE", NbBundle.getMessage(
576:                                    WsdlUIPanel.class, "INVALID_SCHEMA_FILE",
577:                                    urlString));
578:                }
579:
580:                ModelSource source;
581:                try {
582:                    File normFile = FileUtil.normalizeFile(file);
583:                    FileObject fo = FileUtil.toFileObject(normFile);
584:                    if (fo == null) {
585:                        String errorMessage = NbBundle.getMessage(
586:                                WsdlUIPanel.class, "INVALID_SCHEMA_FILE",
587:                                urlString);
588:                        throw new WizardValidationException(schemaTF,
589:                                errorMessage, errorMessage);
590:                    }
591:                    checkAccessibleFromThisProject(wizardPanel.getProject(),
592:                            fo, urlString);
593:                    source = org.netbeans.modules.xml.retriever.catalog.Utilities
594:                            .createModelSource(fo, false);
595:                } catch (WizardValidationException e) {
596:                    throw e;
597:                } catch (CatalogModelException e) {
598:                    throw new WizardValidationException(schemaTF, e
599:                            .getMessage(), e.getLocalizedMessage());
600:                } catch (Throwable e) {
601:                    String errorMessage = NbBundle
602:                            .getMessage(WsdlUIPanel.class,
603:                                    "INVALID_SCHEMA_FILE", urlString);
604:                    throw new WizardValidationException(schemaTF, errorMessage,
605:                            errorMessage);
606:                }
607:                SchemaModel model = null;
608:                try {
609:                    model = SchemaModelFactory.getDefault().getModel(source);
610:                } catch (Throwable e) {
611:                    String errorMessage = NbBundle
612:                            .getMessage(WsdlUIPanel.class,
613:                                    "INVALID_SCHEMA_FILE", urlString);
614:                    throw new WizardValidationException(schemaTF, errorMessage,
615:                            errorMessage);
616:                }
617:
618:                if (model == null
619:                        || model.getState().equals(Model.State.NOT_WELL_FORMED)) {
620:                    String errorMessage = NbBundle
621:                            .getMessage(WsdlUIPanel.class,
622:                                    "INVALID_SCHEMA_FILE", urlString);
623:                    throw new WizardValidationException(schemaTF, errorMessage,
624:                            errorMessage);
625:                }
626:            }
627:
628:            private void checkAccessibleFromThisProject(Project project,
629:                    FileObject file, String fileName)
630:                    throws WizardValidationException {
631:                Project filesProject = FileOwnerQuery.getOwner(file);
632:                if (filesProject == null) {
633:                    throw new WizardValidationException(schemaTF,
634:                            "INACCESSIBLE_FILE", NbBundle.getMessage(
635:                                    WsdlUIPanel.class, "INACCESSIBLE_FILE",
636:                                    fileName));
637:                }
638:                if (project == filesProject) {
639:                    return;
640:                }
641:
642:                DefaultProjectCatalogSupport ctlgSupp = DefaultProjectCatalogSupport
643:                        .getInstance(project.getProjectDirectory());
644:                for (Object pr : ctlgSupp.getProjectReferences()) {
645:                    if (pr == filesProject) {
646:                        return;
647:                    }
648:                }
649:                throw new WizardValidationException(schemaTF,
650:                        "INACCESSIBLE_PROJECT", NbBundle.getMessage(
651:                                WsdlUIPanel.class, "INACCESSIBLE_PROJECT",
652:                                fileName, filesProject.getProjectDirectory()
653:                                        .getName()));
654:            }
655:
656:            public JTextField getSchemaFileTextField() {
657:                return schemaTF;
658:            }
659:        }
www_.___j__ava2_s.___c__o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.