0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041: package org.netbeans.modules.websvc.core.client.wizard;
0042:
0043: import java.io.File;
0044: import java.io.FileNotFoundException;
0045: import java.io.FileReader;
0046: import java.io.IOException;
0047: import java.io.LineNumberReader;
0048: import java.util.Iterator;
0049: import java.util.List;
0050:
0051: import java.awt.Component;
0052: import java.awt.Dialog;
0053:
0054: import java.io.FileOutputStream;
0055: import java.net.Proxy;
0056: import java.net.ProxySelector;
0057: import java.net.URL;
0058: import javax.swing.JPanel;
0059: import javax.swing.JFileChooser;
0060: import javax.swing.JRadioButton;
0061: import javax.swing.filechooser.FileFilter;
0062: import javax.swing.event.DocumentEvent;
0063: import javax.swing.event.DocumentListener;
0064: import javax.swing.ComboBoxModel;
0065: import javax.swing.DefaultComboBoxModel;
0066: import javax.swing.text.JTextComponent;
0067: import org.netbeans.api.java.classpath.ClassPath;
0068: import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
0069: import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
0070: import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
0071: import org.netbeans.modules.websvc.core.ClientWizardProperties;
0072: import org.netbeans.modules.websvc.core.WsdlRetriever;
0073: import org.netbeans.modules.websvc.core.WsdlRetriever;
0074: import org.netbeans.modules.websvc.core.jaxws.JaxWsExplorerPanel;
0075: import org.netbeans.modules.websvc.core.JaxWsUtils;
0076:
0077: import org.openide.DialogDescriptor;
0078: import org.openide.DialogDisplayer;
0079: import org.openide.WizardDescriptor;
0080: import org.openide.filesystems.FileUtil;
0081: import org.openide.nodes.Node;
0082: import org.openide.util.NbBundle;
0083:
0084: import org.netbeans.api.java.project.JavaProjectConstants;
0085: import org.netbeans.api.options.OptionsDisplayer;
0086: import org.netbeans.api.project.Project;
0087: import org.netbeans.api.project.ProjectUtils;
0088: import org.netbeans.api.project.SourceGroup;
0089: import org.netbeans.api.project.Sources;
0090: import org.netbeans.modules.j2ee.api.ejbjar.Car;
0091: import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
0092: import org.netbeans.modules.j2ee.common.Util;
0093: import org.netbeans.spi.java.project.support.ui.PackageView;
0094: import org.netbeans.spi.project.ui.templates.support.Templates;
0095:
0096: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
0097: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
0098: import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
0099: import org.netbeans.modules.web.api.webmodule.WebModule;
0100: import org.netbeans.modules.websvc.api.client.ClientStubDescriptor;
0101:
0102: import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
0103: import org.netbeans.modules.websvc.core.ProjectInfo;
0104: import org.netbeans.modules.websvc.core.WsWsdlCookie;
0105: import org.netbeans.modules.xml.retriever.catalog.Utilities;
0106: import org.netbeans.modules.xml.wsdl.model.Binding;
0107: import org.netbeans.modules.xml.wsdl.model.BindingOperation;
0108: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
0109: import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory;
0110: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding;
0111: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
0112: import org.openide.ErrorManager;
0113: import org.openide.WizardValidationException;
0114: import org.openide.filesystems.FileObject;
0115:
0116: /**
0117: *
0118: * @author Peter Williams
0119: */
0120: public final class ClientInfo extends JPanel implements
0121: WsdlRetriever.MessageReceiver {
0122:
0123: private static final String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
0124: private static final int WSDL_FROM_PROJECT = 0;
0125: private static final int WSDL_FROM_FILE = 1;
0126: private static final int WSDL_FROM_URL = 2;
0127: private static final FileFilter WSDL_FILE_FILTER = new WsdlFileFilter();
0128: private static String previousDirectory = ""; //NOI18N
0129: private WebServiceClientWizardDescriptor descriptorPanel;
0130: private WizardDescriptor wizardDescriptor;
0131: private boolean settingFields;
0132: private int wsdlSource;
0133: private File wsdlTmpFile;
0134: // properties for 'get from server'
0135: private WsdlRetriever retriever;
0136: private String downloadMsg;
0137: private boolean retrieverFailed = false;
0138: private Project project;
0139: private int projectType;
0140:
0141: public ClientInfo(WebServiceClientWizardDescriptor panel) {
0142: descriptorPanel = panel;
0143:
0144: this .settingFields = false;
0145: this .wsdlSource = WSDL_FROM_PROJECT;
0146: this .wsdlTmpFile = null;
0147: this .retriever = null;
0148:
0149: initComponents();
0150: jLblClientType.setVisible(false);
0151: jCbxClientType.setVisible(false);
0152: jComboBoxJaxVersion.setModel(new DefaultComboBoxModel(
0153: new String[] { ClientWizardProperties.JAX_WS,
0154: ClientWizardProperties.JAX_RPC }));
0155: initUserComponents();
0156: }
0157:
0158: /** This method is called from within the constructor to
0159: * initialize the form.
0160: * WARNING: Do NOT modify this code. The content of this method is
0161: * always regenerated by the Form Editor.
0162: */
0163: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0164: private void initComponents() {
0165: java.awt.GridBagConstraints gridBagConstraints;
0166:
0167: btnGrpWsdlSource = new javax.swing.ButtonGroup();
0168: jLblChooseSource = new javax.swing.JLabel();
0169: jRbnFilesystem = new javax.swing.JRadioButton();
0170: jTxtWsdlProject = new javax.swing.JTextField();
0171: jBtnBrowse = new javax.swing.JButton();
0172: jRbnProject = new javax.swing.JRadioButton();
0173: jTxtWsdlURL = new javax.swing.JTextField();
0174: jBtnProxy = new javax.swing.JButton();
0175: jTxtLocalFilename = new javax.swing.JTextField();
0176: jLblPackageDescription = new javax.swing.JLabel();
0177: jLblProject = new javax.swing.JLabel();
0178: jTxtProject = new javax.swing.JTextField();
0179: jLblPackageName = new javax.swing.JLabel();
0180: jCbxPackageName = new javax.swing.JComboBox();
0181: jLblClientType = new javax.swing.JLabel();
0182: jCbxClientType = new javax.swing.JComboBox();
0183: jRbnUrl = new javax.swing.JRadioButton();
0184: jBtnBrowse1 = new javax.swing.JButton();
0185: jLabelJaxVersion = new javax.swing.JLabel();
0186: jComboBoxJaxVersion = new javax.swing.JComboBox();
0187:
0188: setLayout(new java.awt.GridBagLayout());
0189:
0190: org.openide.awt.Mnemonics
0191: .setLocalizedText(jLblChooseSource, NbBundle
0192: .getMessage(ClientInfo.class, "LBL_WsdlSource")); // NOI18N
0193: gridBagConstraints = new java.awt.GridBagConstraints();
0194: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0195: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0196: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
0197: add(jLblChooseSource, gridBagConstraints);
0198:
0199: btnGrpWsdlSource.add(jRbnFilesystem);
0200: org.openide.awt.Mnemonics.setLocalizedText(jRbnFilesystem,
0201: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0202: "LBL_WsdlSourceFilesystem")); // NOI18N
0203: jRbnFilesystem
0204: .addActionListener(new java.awt.event.ActionListener() {
0205: public void actionPerformed(
0206: java.awt.event.ActionEvent evt) {
0207: jRbnFilesystemActionPerformed(evt);
0208: }
0209: });
0210: gridBagConstraints = new java.awt.GridBagConstraints();
0211: gridBagConstraints.gridx = 0;
0212: gridBagConstraints.gridy = 2;
0213: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0214: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
0215: add(jRbnFilesystem, gridBagConstraints);
0216: jRbnFilesystem.getAccessibleContext().setAccessibleDescription(
0217: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0218: "A11Y_WsdlSource")); // NOI18N
0219:
0220: jTxtWsdlProject.setEditable(false);
0221: gridBagConstraints = new java.awt.GridBagConstraints();
0222: gridBagConstraints.gridx = 1;
0223: gridBagConstraints.gridy = 1;
0224: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0225: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6);
0226: add(jTxtWsdlProject, gridBagConstraints);
0227: jTxtWsdlProject.getAccessibleContext().setAccessibleName(
0228: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0229: "ACSN_WsdlSourceFilesystem")); // NOI18N
0230: jTxtWsdlProject.getAccessibleContext()
0231: .setAccessibleDescription(
0232: org.openide.util.NbBundle
0233: .getMessage(ClientInfo.class,
0234: "ACSD_WsdlSourceFile")); // NOI18N
0235:
0236: org.openide.awt.Mnemonics.setLocalizedText(jBtnBrowse,
0237: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0238: "LBL_Browse")); // NOI18N
0239: jBtnBrowse
0240: .addActionListener(new java.awt.event.ActionListener() {
0241: public void actionPerformed(
0242: java.awt.event.ActionEvent evt) {
0243: jBtnBrowseActionPerformed(evt);
0244: }
0245: });
0246: gridBagConstraints = new java.awt.GridBagConstraints();
0247: gridBagConstraints.gridx = 2;
0248: gridBagConstraints.gridy = 2;
0249: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0250: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0251: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
0252: add(jBtnBrowse, gridBagConstraints);
0253: jBtnBrowse.getAccessibleContext().setAccessibleDescription(
0254: org.openide.util.NbBundle.getBundle(ClientInfo.class)
0255: .getString("A11Y_BrowseLocalFile")); // NOI18N
0256:
0257: btnGrpWsdlSource.add(jRbnProject);
0258: jRbnProject.setSelected(true);
0259: org.openide.awt.Mnemonics
0260: .setLocalizedText(jRbnProject, NbBundle.getMessage(
0261: ClientInfo.class, "LBL_ProjectUrl")); // NOI18N
0262: jRbnProject.setFocusable(false);
0263: jRbnProject
0264: .addActionListener(new java.awt.event.ActionListener() {
0265: public void actionPerformed(
0266: java.awt.event.ActionEvent evt) {
0267: jRbnProjectActionPerformed(evt);
0268: }
0269: });
0270: gridBagConstraints = new java.awt.GridBagConstraints();
0271: gridBagConstraints.gridx = 0;
0272: gridBagConstraints.gridy = 1;
0273: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0274: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
0275: add(jRbnProject, gridBagConstraints);
0276: jRbnProject.getAccessibleContext().setAccessibleDescription(
0277: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0278: "A11Y_WsdlSourceUrl")); // NOI18N
0279:
0280: jTxtWsdlURL.setColumns(30);
0281: gridBagConstraints = new java.awt.GridBagConstraints();
0282: gridBagConstraints.gridx = 1;
0283: gridBagConstraints.gridy = 3;
0284: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0285: gridBagConstraints.weightx = 1.0;
0286: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 6);
0287: add(jTxtWsdlURL, gridBagConstraints);
0288: jTxtWsdlURL.getAccessibleContext().setAccessibleName(
0289: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0290: "ACSN_WsdlSourceUrl")); // NOI18N
0291: jTxtWsdlURL.getAccessibleContext().setAccessibleDescription(
0292: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0293: "ACSD_WsdlSourceUrl")); // NOI18N
0294:
0295: org.openide.awt.Mnemonics.setLocalizedText(jBtnProxy,
0296: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0297: "LBL_ProxySettings")); // NOI18N
0298: jBtnProxy
0299: .addActionListener(new java.awt.event.ActionListener() {
0300: public void actionPerformed(
0301: java.awt.event.ActionEvent evt) {
0302: jBtnProxyActionPerformed(evt);
0303: }
0304: });
0305: gridBagConstraints = new java.awt.GridBagConstraints();
0306: gridBagConstraints.gridx = 2;
0307: gridBagConstraints.gridy = 3;
0308: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0309: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0310: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0311: gridBagConstraints.insets = new java.awt.Insets(0, 6, 12, 0);
0312: add(jBtnProxy, gridBagConstraints);
0313: jBtnProxy.getAccessibleContext().setAccessibleDescription(
0314: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0315: "A11Y_ProxySettings")); // NOI18N
0316:
0317: gridBagConstraints = new java.awt.GridBagConstraints();
0318: gridBagConstraints.gridx = 1;
0319: gridBagConstraints.gridy = 2;
0320: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0321: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6);
0322: add(jTxtLocalFilename, gridBagConstraints);
0323: jTxtLocalFilename.getAccessibleContext().setAccessibleName(
0324: org.openide.util.NbBundle.getBundle(ClientInfo.class)
0325: .getString("ACSN_WsdlSourceLocalFile")); // NOI18N
0326: jTxtLocalFilename
0327: .getAccessibleContext()
0328: .setAccessibleDescription(
0329: org.openide.util.NbBundle.getMessage(
0330: ClientInfo.class, "A11Y_LocalFilename")); // NOI18N
0331:
0332: jLblPackageDescription.setLabelFor(jCbxPackageName);
0333: org.openide.awt.Mnemonics.setLocalizedText(
0334: jLblPackageDescription, NbBundle.getMessage(
0335: ClientInfo.class, "LBL_PackageDescription")); // NOI18N
0336: gridBagConstraints = new java.awt.GridBagConstraints();
0337: gridBagConstraints.gridx = 0;
0338: gridBagConstraints.gridy = 4;
0339: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0340: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0341: gridBagConstraints.insets = new java.awt.Insets(12, 0, 12, 0);
0342: add(jLblPackageDescription, gridBagConstraints);
0343:
0344: jLblProject.setLabelFor(jTxtProject);
0345: org.openide.awt.Mnemonics.setLocalizedText(jLblProject,
0346: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0347: "LBL_Project")); // NOI18N
0348: gridBagConstraints = new java.awt.GridBagConstraints();
0349: gridBagConstraints.gridx = 0;
0350: gridBagConstraints.gridy = 5;
0351: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0352: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
0353: add(jLblProject, gridBagConstraints);
0354:
0355: jTxtProject.setEditable(false);
0356: gridBagConstraints = new java.awt.GridBagConstraints();
0357: gridBagConstraints.gridx = 1;
0358: gridBagConstraints.gridy = 5;
0359: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0360: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0361: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
0362: add(jTxtProject, gridBagConstraints);
0363: jTxtProject.getAccessibleContext().setAccessibleDescription(
0364: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0365: "A11Y_Project")); // NOI18N
0366:
0367: jLblPackageName.setLabelFor(jCbxPackageName);
0368: org.openide.awt.Mnemonics.setLocalizedText(jLblPackageName,
0369: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0370: "LBL_PackageName")); // NOI18N
0371: gridBagConstraints = new java.awt.GridBagConstraints();
0372: gridBagConstraints.gridx = 0;
0373: gridBagConstraints.gridy = 6;
0374: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0375: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
0376: add(jLblPackageName, gridBagConstraints);
0377:
0378: jCbxPackageName.setEditable(true);
0379: gridBagConstraints = new java.awt.GridBagConstraints();
0380: gridBagConstraints.gridx = 1;
0381: gridBagConstraints.gridy = 6;
0382: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0383: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0384: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
0385: add(jCbxPackageName, gridBagConstraints);
0386:
0387: jLblClientType.setLabelFor(jCbxClientType);
0388: org.openide.awt.Mnemonics.setLocalizedText(jLblClientType,
0389: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0390: "LBL_ClientType")); // NOI18N
0391: gridBagConstraints = new java.awt.GridBagConstraints();
0392: gridBagConstraints.gridx = 0;
0393: gridBagConstraints.gridy = 7;
0394: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0395: gridBagConstraints.ipady = 4;
0396: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0397: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6);
0398: add(jLblClientType, gridBagConstraints);
0399:
0400: gridBagConstraints = new java.awt.GridBagConstraints();
0401: gridBagConstraints.gridx = 1;
0402: gridBagConstraints.gridy = 7;
0403: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0404: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0405: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0406: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0407: add(jCbxClientType, gridBagConstraints);
0408: jCbxClientType.getAccessibleContext().setAccessibleDescription(
0409: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0410: "A11Y_ClientType")); // NOI18N
0411:
0412: btnGrpWsdlSource.add(jRbnUrl);
0413: org.openide.awt.Mnemonics.setLocalizedText(jRbnUrl,
0414: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0415: "LBL_WsdlUrl")); // NOI18N
0416: jRbnUrl.addActionListener(new java.awt.event.ActionListener() {
0417: public void actionPerformed(java.awt.event.ActionEvent evt) {
0418: jRbnUrlActionPerformed(evt);
0419: }
0420: });
0421: gridBagConstraints = new java.awt.GridBagConstraints();
0422: gridBagConstraints.gridx = 0;
0423: gridBagConstraints.gridy = 3;
0424: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0425: gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
0426: add(jRbnUrl, gridBagConstraints);
0427: jRbnUrl.getAccessibleContext().setAccessibleDescription(
0428: org.openide.util.NbBundle.getBundle(ClientInfo.class)
0429: .getString("A11Y_WsdlURL")); // NOI18N
0430:
0431: org.openide.awt.Mnemonics.setLocalizedText(jBtnBrowse1,
0432: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0433: "LBL_Browse1")); // NOI18N
0434: jBtnBrowse1
0435: .addActionListener(new java.awt.event.ActionListener() {
0436: public void actionPerformed(
0437: java.awt.event.ActionEvent evt) {
0438: jBtnBrowse1ActionPerformed(evt);
0439: }
0440: });
0441: gridBagConstraints = new java.awt.GridBagConstraints();
0442: gridBagConstraints.gridx = 2;
0443: gridBagConstraints.gridy = 1;
0444: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0445: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0446: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
0447: add(jBtnBrowse1, gridBagConstraints);
0448: jBtnBrowse1.getAccessibleContext().setAccessibleDescription(
0449: org.openide.util.NbBundle.getBundle(ClientInfo.class)
0450: .getString("A11Y_BrowseWSDLProject")); // NOI18N
0451:
0452: jLabelJaxVersion.setLabelFor(jComboBoxJaxVersion);
0453: org.openide.awt.Mnemonics.setLocalizedText(jLabelJaxVersion,
0454: org.openide.util.NbBundle.getBundle(ClientInfo.class)
0455: .getString("LBL_JAX_Version")); // NOI18N
0456: gridBagConstraints = new java.awt.GridBagConstraints();
0457: gridBagConstraints.gridx = 0;
0458: gridBagConstraints.gridy = 8;
0459: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
0460: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0461: gridBagConstraints.weighty = 1.0;
0462: gridBagConstraints.insets = new java.awt.Insets(28, 0, 0, 6);
0463: add(jLabelJaxVersion, gridBagConstraints);
0464:
0465: jComboBoxJaxVersion
0466: .addActionListener(new java.awt.event.ActionListener() {
0467: public void actionPerformed(
0468: java.awt.event.ActionEvent evt) {
0469: jaxwsVersionHandler(evt);
0470: }
0471: });
0472: gridBagConstraints = new java.awt.GridBagConstraints();
0473: gridBagConstraints.gridx = 1;
0474: gridBagConstraints.gridy = 8;
0475: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0476: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
0477: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0478: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
0479: gridBagConstraints.insets = new java.awt.Insets(24, 6, 0, 0);
0480: add(jComboBoxJaxVersion, gridBagConstraints);
0481:
0482: getAccessibleContext().setAccessibleDescription(
0483: org.openide.util.NbBundle.getMessage(ClientInfo.class,
0484: "LBL_WsdlSource")); // NOI18N
0485: }// </editor-fold>//GEN-END:initComponents
0486:
0487: private void jaxwsVersionHandler(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jaxwsVersionHandler
0488: // TODO add your handling code here:
0489: descriptorPanel.fireChangeEvent();
0490: String jaxwsVersion = (String) this .jComboBoxJaxVersion
0491: .getSelectedItem();
0492: String pName = (String) this .jCbxPackageName.getSelectedItem();
0493: if (Util.isJavaEE5orHigher(project)
0494: || (projectType == 0 && jaxwsVersion
0495: .equals(ClientWizardProperties.JAX_WS))) {
0496: if (pName == null || pName.trim().equals("")) {
0497: jCbxPackageName.setToolTipText(NbBundle.getMessage(
0498: ClientInfo.class, "TOOLTIP_DEFAULT_PACKAGE"));
0499: } else {
0500: jCbxPackageName.setToolTipText("");
0501: }
0502: } else {
0503: jCbxPackageName.setToolTipText("");
0504: }
0505: }//GEN-LAST:event_jaxwsVersionHandler
0506:
0507: private void jBtnBrowse1ActionPerformed(
0508: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowse1ActionPerformed
0509: // TODO add your handling code here:
0510: String result = browseProjectServices();
0511: if (result != null)
0512: jTxtWsdlProject.setText(result);
0513: }//GEN-LAST:event_jBtnBrowse1ActionPerformed
0514:
0515: private void jRbnUrlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRbnUrlActionPerformed
0516: // TODO add your handling code here:
0517: wsdlSource = WSDL_FROM_URL;
0518: enableWsdlSourceFields(false, false, true);
0519: descriptorPanel.fireChangeEvent();
0520: }//GEN-LAST:event_jRbnUrlActionPerformed
0521:
0522: private void jBtnProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnProxyActionPerformed
0523: OptionsDisplayer.getDefault().open("General");//NOI18N
0524: wsdlUrlChanged();
0525: }//GEN-LAST:event_jBtnProxyActionPerformed
0526:
0527: private void jBtnBrowseActionPerformed(
0528: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnBrowseActionPerformed
0529: // System.out.println("browse for wsdl file...");
0530: JFileChooser chooser = new JFileChooser(previousDirectory);
0531: chooser.setMultiSelectionEnabled(false);
0532: chooser.setAcceptAllFileFilterUsed(true);
0533: chooser.addChoosableFileFilter(WSDL_FILE_FILTER);
0534: chooser.setFileFilter(WSDL_FILE_FILTER);
0535: if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
0536: File wsdlFile = chooser.getSelectedFile();
0537: jTxtLocalFilename.setText(wsdlFile.getAbsolutePath());
0538: previousDirectory = wsdlFile.getPath();
0539: }
0540: }//GEN-LAST:event_jBtnBrowseActionPerformed
0541:
0542: private void jRbnFilesystemActionPerformed(
0543: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRbnFilesystemActionPerformed
0544: // System.out.println("get from filesystem selected.");
0545: wsdlSource = WSDL_FROM_FILE;
0546: enableWsdlSourceFields(false, true, false);
0547: descriptorPanel.fireChangeEvent();
0548: }//GEN-LAST:event_jRbnFilesystemActionPerformed
0549:
0550: private void jRbnProjectActionPerformed(
0551: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRbnProjectActionPerformed
0552: // System.out.println("get from url selected.");
0553: wsdlSource = WSDL_FROM_PROJECT;
0554: enableWsdlSourceFields(true, false, false);
0555: descriptorPanel.fireChangeEvent();
0556: }//GEN-LAST:event_jRbnProjectActionPerformed
0557:
0558: private void enableWsdlSourceFields(boolean fromProject,
0559: boolean fromFile, boolean fromUrl) {
0560: // project related fields
0561: jTxtWsdlProject.setEnabled(fromProject);
0562: jBtnBrowse1.setEnabled(fromProject);
0563:
0564: // file systam related fields
0565: jTxtLocalFilename.setEnabled(fromFile);
0566: jBtnBrowse.setEnabled(fromFile);
0567:
0568: // service related fields
0569: jTxtWsdlURL.setEnabled(fromUrl);
0570: }
0571:
0572: // Variables declaration - do not modify//GEN-BEGIN:variables
0573: private javax.swing.ButtonGroup btnGrpWsdlSource;
0574: private javax.swing.JButton jBtnBrowse;
0575: private javax.swing.JButton jBtnBrowse1;
0576: private javax.swing.JButton jBtnProxy;
0577: private javax.swing.JComboBox jCbxClientType;
0578: private javax.swing.JComboBox jCbxPackageName;
0579: private javax.swing.JComboBox jComboBoxJaxVersion;
0580: private javax.swing.JLabel jLabelJaxVersion;
0581: private javax.swing.JLabel jLblChooseSource;
0582: private javax.swing.JLabel jLblClientType;
0583: private javax.swing.JLabel jLblPackageDescription;
0584: private javax.swing.JLabel jLblPackageName;
0585: private javax.swing.JLabel jLblProject;
0586: private javax.swing.JRadioButton jRbnFilesystem;
0587: private javax.swing.JRadioButton jRbnProject;
0588: private javax.swing.JRadioButton jRbnUrl;
0589: private javax.swing.JTextField jTxtLocalFilename;
0590: private javax.swing.JTextField jTxtProject;
0591: private javax.swing.JTextField jTxtWsdlProject;
0592: private javax.swing.JTextField jTxtWsdlURL;
0593:
0594: // End of variables declaration//GEN-END:variables
0595:
0596: private void initUserComponents() {
0597: // System.out.println("wizard panel created");
0598:
0599: setName(NbBundle.getMessage(ClientInfo.class,
0600: "TITLE_WebServiceClientWizard")); // NOI18N
0601:
0602: // Register listener on the textFields to make the automatic updates
0603: jTxtWsdlURL.getDocument().addDocumentListener(
0604: new DocumentListener() {
0605: public void changedUpdate(DocumentEvent e) {
0606: wsdlUrlChanged();
0607: }
0608:
0609: public void insertUpdate(DocumentEvent e) {
0610: wsdlUrlChanged();
0611: }
0612:
0613: public void removeUpdate(DocumentEvent e) {
0614: wsdlUrlChanged();
0615: }
0616: });
0617: jTxtLocalFilename.getDocument().addDocumentListener(
0618: new DocumentListener() {
0619: public void changedUpdate(DocumentEvent e) {
0620: updateTexts();
0621: }
0622:
0623: public void insertUpdate(DocumentEvent e) {
0624: updateTexts();
0625: }
0626:
0627: public void removeUpdate(DocumentEvent e) {
0628: updateTexts();
0629: }
0630: });
0631: jTxtWsdlProject.getDocument().addDocumentListener(
0632: new DocumentListener() {
0633: public void changedUpdate(DocumentEvent e) {
0634: wsdlUrlChanged();
0635: }
0636:
0637: public void insertUpdate(DocumentEvent e) {
0638: wsdlUrlChanged();
0639: }
0640:
0641: public void removeUpdate(DocumentEvent e) {
0642: wsdlUrlChanged();
0643: }
0644: });
0645:
0646: Component editorComponent = jCbxPackageName.getEditor()
0647: .getEditorComponent();
0648: if (editorComponent instanceof JTextComponent) {
0649: ((JTextComponent) editorComponent).getDocument()
0650: .addDocumentListener(new DocumentListener() {
0651: public void changedUpdate(DocumentEvent e) {
0652: updateTexts();
0653: }
0654:
0655: public void insertUpdate(DocumentEvent e) {
0656: updateTexts();
0657: }
0658:
0659: public void removeUpdate(DocumentEvent e) {
0660: updateTexts();
0661: }
0662: });
0663: } else {
0664: // JComboBox is supposed to use a JTextComponent for editing, but in case
0665: // it isn't, at least do something to track changes.
0666: jCbxPackageName
0667: .addItemListener(new java.awt.event.ItemListener() {
0668: public void itemStateChanged(
0669: java.awt.event.ItemEvent evt) {
0670: if (!settingFields) {
0671: descriptorPanel.fireChangeEvent(); // Notify that the panel changed
0672: }
0673: }
0674: });
0675: }
0676:
0677: jCbxPackageName.setRenderer(PackageView.listRenderer());
0678: }
0679:
0680: void store(WizardDescriptor d) {
0681: // System.out.println("storing wizard properties");
0682:
0683: if (wsdlSource == WSDL_FROM_PROJECT
0684: || wsdlSource == WSDL_FROM_URL) {
0685: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL,
0686: getDownloadUrl());
0687: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_FILE,
0688: getDownloadWsdl());
0689: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_SCHEMAS,
0690: getDownloadedSchemas());
0691: d.putProperty(ClientWizardProperties.WSDL_FILE_PATH,
0692: retriever == null ? "" : retriever
0693: .getWsdlFileName()); //NOI18N
0694: } else if (wsdlSource == WSDL_FROM_FILE) {
0695: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL,
0696: null);
0697: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_FILE,
0698: null);
0699: d.putProperty(ClientWizardProperties.WSDL_DOWNLOAD_SCHEMAS,
0700: null);
0701: d.putProperty(ClientWizardProperties.WSDL_FILE_PATH,
0702: jTxtLocalFilename.getText().trim());
0703: }
0704: d.putProperty(ClientWizardProperties.WSDL_PACKAGE_NAME,
0705: getPackageName());
0706: d.putProperty(ClientWizardProperties.CLIENT_STUB_TYPE,
0707: jCbxClientType.getSelectedItem());
0708: d.putProperty(ClientWizardProperties.JAX_VERSION,
0709: jComboBoxJaxVersion.getSelectedItem());
0710: }
0711:
0712: void read(WizardDescriptor d) {
0713: // System.out.println("reading wizard properties");
0714: this .wizardDescriptor = d;
0715:
0716: project = Templates.getProject(d);
0717: WebModule wm = WebModule.getWebModule(project
0718: .getProjectDirectory());
0719: EjbJar em = EjbJar.getEjbJar(project.getProjectDirectory());
0720: Car car = Car.getCar(project.getProjectDirectory());
0721: if (car != null)
0722: projectType = 3;
0723: else if (em != null)
0724: projectType = 2;
0725: else if (wm != null)
0726: projectType = 1;
0727: else
0728: projectType = 0;
0729:
0730: if (projectType > 0) {
0731:
0732: if (!Util.isJavaEE5orHigher(project)) {
0733: jLblClientType.setVisible(true);
0734: jCbxClientType.setVisible(true);
0735: }
0736: }
0737:
0738: //test JAX-WS library
0739: SourceGroup[] sgs = ProjectUtils
0740: .getSources(project)
0741: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
0742: ClassPath classPath;
0743: FileObject wsimportFO = null;
0744: FileObject wscompileFO = null;
0745: if (sgs.length > 0) {
0746: classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),
0747: ClassPath.COMPILE);
0748:
0749: if (classPath != null) {
0750: wsimportFO = classPath
0751: .findResource("com/sun/tools/ws/ant/WsImport.class"); //NOI18N
0752: wscompileFO = classPath
0753: .findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); //NOI18N
0754: }
0755: }
0756:
0757: boolean jsr109OldSupported = isJsr109OldSupported(project);
0758: boolean jsr109Supported = isJsr109Supported(project);
0759: boolean jwsdpSupported = isJwsdpSupported(project);
0760: boolean jaxWsInJ2ee14Supported = isJaxWsInJ2ee14Supported(project);
0761: if (projectType > 0) {
0762: //jLabelJaxVersion.setEnabled(false);
0763: //jComboBoxJaxVersion.setEnabled(false);
0764: if (Util.isJavaEE5orHigher(project)
0765: || JaxWsUtils.isEjbJavaEE5orHigher(project)) //NOI18N
0766: jComboBoxJaxVersion
0767: .setSelectedItem(ClientWizardProperties.JAX_WS);
0768: else {
0769: if ((!jsr109OldSupported && !jsr109Supported)
0770: || jaxWsInJ2ee14Supported
0771: || (!jsr109Supported && jsr109OldSupported && jwsdpSupported)) {
0772: jComboBoxJaxVersion
0773: .setSelectedItem(ClientWizardProperties.JAX_WS);
0774: } else {
0775: jLabelJaxVersion.setEnabled(false);
0776: jComboBoxJaxVersion.setEnabled(false);
0777: jComboBoxJaxVersion
0778: .setSelectedItem(ClientWizardProperties.JAX_RPC);
0779: }
0780: }
0781: } else {
0782: if (Util.isSourceLevel16orHigher(project)) {
0783: //jLabelJaxVersion.setEnabled(false);
0784: //jComboBoxJaxVersion.setEnabled(false);
0785: jComboBoxJaxVersion
0786: .setSelectedItem(ClientWizardProperties.JAX_WS);
0787: } else if (Util.getSourceLevel(project).equals("1.5")) { //NOI18N
0788: if (wsimportFO != null) {
0789: //jLabelJaxVersion.setEnabled(false);
0790: //jComboBoxJaxVersion.setEnabled(false);
0791: jComboBoxJaxVersion
0792: .setSelectedItem(ClientWizardProperties.JAX_WS);
0793: } else if (wscompileFO != null) {
0794: //jLabelJaxVersion.setEnabled(false);
0795: //jComboBoxJaxVersion.setEnabled(false);
0796: jComboBoxJaxVersion
0797: .setSelectedItem(ClientWizardProperties.JAX_RPC);
0798: } else {
0799: //jLabelJaxVersion.setEnabled(true);
0800: //jComboBoxJaxVersion.setEnabled(true);
0801: }
0802: } else {
0803: //jLabelJaxVersion.setEnabled(false);
0804: //jComboBoxJaxVersion.setEnabled(false);
0805: jComboBoxJaxVersion
0806: .setSelectedItem(ClientWizardProperties.JAX_RPC);
0807: }
0808: }
0809:
0810: try {
0811: settingFields = true;
0812:
0813: Project p = Templates.getProject(d);
0814:
0815: jTxtProject.setText(ProjectUtils.getInformation(p)
0816: .getDisplayName());
0817: jTxtWsdlURL
0818: .setText((String) d
0819: .getProperty(ClientWizardProperties.WSDL_DOWNLOAD_URL));
0820: jTxtLocalFilename.setText(retriever != null ? retriever
0821: .getWsdlFileName() : ""); //NOI18N
0822: jTxtWsdlURL
0823: .setText((String) d
0824: .getProperty(ClientWizardProperties.WSDL_FILE_PATH));
0825:
0826: jCbxPackageName.setModel(getPackageModel(p));
0827: String pName = (String) d
0828: .getProperty(ClientWizardProperties.WSDL_PACKAGE_NAME);
0829: String jaxwsVersion = (String) this .jComboBoxJaxVersion
0830: .getSelectedItem();
0831: if (Util.isJavaEE5orHigher(project)
0832: || (projectType == 0 && jaxwsVersion
0833: .equals(ClientWizardProperties.JAX_WS))) {
0834: if (pName == null) {
0835: jCbxPackageName.setToolTipText(NbBundle
0836: .getMessage(ClientInfo.class,
0837: "TOOLTIP_DEFAULT_PACKAGE"));
0838: } else {
0839: jCbxPackageName.setToolTipText("");
0840: }
0841: } else {
0842: jCbxPackageName.setToolTipText("");
0843: }
0844: jCbxPackageName.setSelectedItem(getPackageItem(pName));
0845: // Normalize selection, in case it's unspecified.
0846: Integer source = (Integer) d
0847: .getProperty(ClientWizardProperties.WSDL_SOURCE);
0848: if (source == null || source.intValue() < WSDL_FROM_PROJECT
0849: || source.intValue() > WSDL_FROM_URL) {
0850: source = Integer.valueOf(WSDL_FROM_PROJECT);
0851: }
0852:
0853: this .wsdlSource = source.intValue();
0854: this .wsdlTmpFile = null;
0855: this .retriever = null;
0856: this .downloadMsg = null;
0857:
0858: enableWsdlSourceFields(wsdlSource == WSDL_FROM_PROJECT,
0859: wsdlSource == WSDL_FROM_FILE,
0860: wsdlSource == WSDL_FROM_URL);
0861: btnGrpWsdlSource.setSelected(getSelectedRadioButton(
0862: wsdlSource).getModel(), true);
0863:
0864: // Retrieve stub list from current project (have to be careful with caching
0865: // because the user might go back and change the project.)
0866: // Then set the stub list and current selected stub only if there was one
0867: // saved *and* it's in the list that the current project supports.
0868: WebServicesClientSupport clientSupport = WebServicesClientSupport
0869: .getWebServicesClientSupport(p
0870: .getProjectDirectory());
0871:
0872: Object selectedStub = d
0873: .getProperty(ClientWizardProperties.CLIENT_STUB_TYPE);
0874: DefaultComboBoxModel stubModel = new DefaultComboBoxModel();
0875: if (clientSupport != null) {
0876: List<ClientStubDescriptor> clientStubs = clientSupport
0877: .getStubDescriptors();
0878: for (Iterator iter = clientStubs.iterator(); iter
0879: .hasNext();) {
0880: stubModel.addElement(iter.next());
0881: }
0882:
0883: if (!clientStubs.contains(selectedStub)) {
0884: selectedStub = null;
0885: }
0886:
0887: //if platform is non-JSR109, select the JAXRPC static stub type
0888: //and disable the combobox
0889: if ((!jsr109OldSupported && !jsr109Supported)
0890: || (!jsr109Supported && jsr109OldSupported && jwsdpSupported)) {
0891: selectedStub = getJAXRPCClientStub(clientStubs);
0892: jCbxClientType.setEnabled(false);
0893: }
0894: } else {
0895: selectedStub = null;
0896: }
0897:
0898: jCbxClientType.setModel(stubModel);
0899:
0900: if (selectedStub != null) {
0901: jCbxClientType.setSelectedItem(selectedStub);
0902: }
0903: } finally {
0904: settingFields = false;
0905: }
0906: }
0907:
0908: private ClientStubDescriptor getJAXRPCClientStub(
0909: List<ClientStubDescriptor> clientStubs) {
0910: for (ClientStubDescriptor clientStub : clientStubs) {
0911: if (clientStub.getName().equals(
0912: ClientStubDescriptor.JAXRPC_CLIENT_STUB)) {
0913: return clientStub;
0914: }
0915: }
0916: return null;
0917: }
0918:
0919: public void validatePanel() throws WizardValidationException {
0920: if (!valid(wizardDescriptor))
0921: throw new WizardValidationException(this , "", ""); //NOI18N
0922:
0923: retrieverFailed = false;
0924: retriever = null;
0925: if (jComboBoxJaxVersion.getSelectedItem().equals(
0926: ClientWizardProperties.JAX_RPC)
0927: && (wsdlSource != WSDL_FROM_FILE)) {
0928: retriever = new WsdlRetriever(this ,
0929: wsdlSource == WSDL_FROM_PROJECT ? jTxtWsdlProject
0930: .getText() : jTxtWsdlURL.getText().trim());
0931: retriever.run();
0932:
0933: if (retriever.getState() != WsdlRetriever.STATUS_COMPLETE) {
0934: retrieverFailed = true;
0935: throw new WizardValidationException(this , "", ""); //NOI18N
0936: } else
0937: wizardDescriptor.putProperty(
0938: ClientWizardProperties.WSDL_FILE_PATH,
0939: retriever == null ? "" : retriever
0940: .getWsdlFileName()); //NOI18N
0941: }
0942: if (jComboBoxJaxVersion.getSelectedItem().equals(
0943: ClientWizardProperties.JAX_WS)
0944: && (wsdlSource != WSDL_FROM_FILE)) {
0945: boolean rpcEncoded = false;
0946: File tmpWsdl = null;
0947: try {
0948: URL tmpWsdlUrl = new URL(
0949: wsdlSource == WSDL_FROM_PROJECT ? jTxtWsdlProject
0950: .getText()
0951: : jTxtWsdlURL.getText().trim());
0952: tmpWsdl = File.createTempFile("tmp", "wsdl");
0953: List<Proxy> proxies = ProxySelector.getDefault()
0954: .select(tmpWsdlUrl.toURI());
0955: Utilities.downloadURLUsingProxyAndSave(tmpWsdlUrl,
0956: proxies.isEmpty() ? null : proxies.get(0),
0957: tmpWsdl);
0958: rpcEncoded = isRpcEncoded(tmpWsdl);
0959: } catch (Exception e) {
0960: ErrorManager.getDefault().annotate(
0961: e,
0962: ErrorManager.WARNING,
0963: "Unable to check if wsdl is rpc encoded.",
0964: NbBundle.getMessage(ClientInfo.class,
0965: "ERR_UnableToDetermineRPCEncoded"),
0966: e.getCause(), new java.util.Date());
0967: }
0968: if (tmpWsdl != null)
0969: tmpWsdl.delete();
0970: if (rpcEncoded) {
0971: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
0972: NbBundle.getMessage(ClientInfo.class,
0973: "ERR_RPCEncodedJaxrpcClientRequired")); // NOI18N
0974: throw new WizardValidationException(this , "", ""); //NOI18N
0975: }
0976: }
0977: }
0978:
0979: private ComboBoxModel getPackageModel(Project p) {
0980: ComboBoxModel result;
0981: Sources sources = ProjectUtils.getSources(p);
0982: SourceGroup[] groups = sources
0983: .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
0984:
0985: if (groups.length > 1) {
0986: // !PW We cannot make the distinction between source and test source roots, so I don't
0987: // want to merge all the packages at this time. For now, just pick the first one,
0988: // and maybe we can do better in the next version.
0989: // DefaultComboBoxModel packageModel = new DefaultComboBoxModel();
0990: // for(int i = 0; i < groups.length; i++) {
0991: // ComboBoxModel model = PackageView.createListView(groups[i]);
0992: // for(int j = 0, m = model.getSize(); j < m; j++) {
0993: // packageModel.addElement(model.getElementAt(j));
0994: // }
0995: // }
0996: // result = packageModel;
0997: // Default to showing packages from first source root only for now.
0998: result = PackageView.createListView(groups[0]);
0999: } else if (groups.length == 1) {
1000: // Only one group, no processing needed.
1001: result = PackageView.createListView(groups[0]);
1002: } else {
1003: result = new DefaultComboBoxModel();
1004: }
1005:
1006: return result;
1007: }
1008:
1009: private Object getPackageItem(String name) {
1010: Object result = name;
1011:
1012: ComboBoxModel model = jCbxPackageName.getModel();
1013: int max = model.getSize();
1014: for (int i = 0; i < max; i++) {
1015: Object item = model.getElementAt(i);
1016: if (item.toString().equals(name)) {
1017: result = item;
1018: break;
1019: }
1020: }
1021:
1022: return result;
1023: }
1024:
1025: private String getPackageName() {
1026: return jCbxPackageName.getEditor().getItem().toString().trim();
1027: }
1028:
1029: private JRadioButton getSelectedRadioButton(int selected) {
1030: JRadioButton result = jRbnProject;
1031:
1032: switch (selected) {
1033: case WSDL_FROM_PROJECT:
1034: result = jRbnProject;
1035: break;
1036: case WSDL_FROM_FILE:
1037: result = jRbnFilesystem;
1038: break;
1039: case WSDL_FROM_URL:
1040: result = jRbnUrl;
1041: break;
1042: }
1043:
1044: return result;
1045: }
1046:
1047: private byte[] getDownloadWsdl() {
1048: byte[] result = null;
1049: if (retriever != null
1050: && retriever.getState() == WsdlRetriever.STATUS_COMPLETE) {
1051: result = retriever.getWsdl();
1052: }
1053: return result;
1054: }
1055:
1056: private List /*WsdlRetriever.SchemaInfo */getDownloadedSchemas() {
1057: List result = null;
1058: if (retriever != null
1059: && retriever.getState() == WsdlRetriever.STATUS_COMPLETE) {
1060: result = retriever.getSchemas();
1061: }
1062: return result;
1063: }
1064:
1065: private String getDownloadUrl() {
1066: String result = ""; //NOI18N
1067:
1068: if (retriever != null) {
1069: // If we've done a download, save the URL that was actually used, not
1070: // what the user typed in.
1071: result = retriever.getWsdlUrl();
1072: } else {
1073: // If no download yet, then use what the user has typed.
1074: if (wsdlSource == WSDL_FROM_URL)
1075: result = WsdlRetriever.beautifyUrlName(jTxtWsdlURL
1076: .getText().trim());
1077: else if (wsdlSource == WSDL_FROM_PROJECT)
1078: result = jTxtWsdlProject.getText().trim();
1079: }
1080: return result;
1081: }
1082:
1083: boolean valid(final WizardDescriptor wizardDescriptor) {
1084: Project p = Templates.getProject(wizardDescriptor);
1085:
1086: // Project must currently have a target server that supports wscompile.
1087: /*
1088: if(!isWsCompileSupported(p)) {
1089: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_WsCompileNotSupportedByTargetServer")); // NOI18N
1090: return false; // project with web service client support, but no stub types defined.
1091: }
1092: */
1093:
1094: if (!checkNonJsr109Valid(wizardDescriptor)) {
1095: return false;
1096: }
1097:
1098: // Project selected must support at least one stub type.
1099:
1100: // Commented out temporarly (until jax-rpc client support is implemented)
1101: // WebServicesClientSupport clientSupport =
1102: // WebServicesClientSupport.getWebServicesClientSupport(p.getProjectDirectory());
1103: // List clientStubs = (clientSupport != null) ? clientSupport.getStubDescriptors() : null;
1104: // if(clientStubs == null || clientStubs.size() == 0) {
1105: // wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle.getMessage(ClientInfo.class, "ERR_NoStubsDefined")); // NOI18N
1106: // return false; // project with web service client support, but no stub types defined.
1107: // }
1108:
1109: if (jComboBoxJaxVersion.getSelectedItem().equals(
1110: ClientWizardProperties.JAX_RPC)) {
1111: if (WebServicesClientSupport
1112: .getWebServicesClientSupport(project
1113: .getProjectDirectory()) == null) {
1114: // check if jaxrpc plugin installed
1115: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1116: NbBundle.getMessage(ClientInfo.class,
1117: "ERR_NoJaxrpcPluginFound")); // NOI18N
1118: return false;
1119: }
1120: SourceGroup[] sgs = JaxWsClientCreator
1121: .getJavaSourceGroups(project);
1122: //no source root -> there must be at least one source root to create JAX-RPC client
1123: if (sgs.length <= 0) {
1124: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1125: NbBundle.getMessage(ClientInfo.class,
1126: "MSG_MissingSourceRoot")); //NOI18N
1127: return false;
1128: }
1129: }
1130:
1131: boolean rpcEncoded = false;
1132: if (wsdlSource == WSDL_FROM_PROJECT
1133: || wsdlSource == WSDL_FROM_URL) {
1134: String wsdlUrl = (wsdlSource == WSDL_FROM_PROJECT ? jTxtWsdlProject
1135: .getText().trim()
1136: : jTxtWsdlURL.getText().trim());
1137: if (wsdlUrl == null || wsdlUrl.length() == 0) {
1138: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1139: NbBundle.getMessage(ClientInfo.class,
1140: "MSG_EnterURL")); // NOI18N
1141: return false;
1142: }
1143:
1144: if (retrieverFailed && retriever != null) {
1145: if (retriever.getState() < WsdlRetriever.STATUS_COMPLETE) {
1146: wizardDescriptor
1147: .putProperty(
1148: PROP_ERROR_MESSAGE,
1149: NbBundle
1150: .getMessage(
1151: ClientInfo.class,
1152: "MSG_DownloadProgress", // NOI18N
1153: ((downloadMsg != null) ? downloadMsg
1154: : NbBundle
1155: .getMessage(
1156: ClientInfo.class,
1157: "LBL_Unknown")))); // NOI18N
1158: return false;
1159: }
1160:
1161: if (retriever.getState() > WsdlRetriever.STATUS_COMPLETE) {
1162: if (downloadMsg != null) {
1163: wizardDescriptor.putProperty(
1164: PROP_ERROR_MESSAGE, NbBundle
1165: .getMessage(ClientInfo.class,
1166: "ERR_DownloadFailed",
1167: downloadMsg)); // NOI18N
1168: } else {
1169: wizardDescriptor.putProperty(
1170: PROP_ERROR_MESSAGE,
1171: NbBundle.getMessage(ClientInfo.class,
1172: "ERR_DownloadFailedUnknown")); // NOI18N
1173: }
1174: return false;
1175: }
1176: }
1177:
1178: // url is ok, and file is downloaded if we get here. Now check generated local filename
1179: // !PW FIXME what do we want to check it for? Existence in temp directory?
1180:
1181: // Now drop down to do package validation.
1182: } else if (wsdlSource == WSDL_FROM_FILE) {
1183: String wsdlFilePath = jTxtLocalFilename.getText().trim();
1184:
1185: if (wsdlFilePath == null || wsdlFilePath.length() == 0) {
1186: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1187: NbBundle.getMessage(ClientInfo.class,
1188: "MSG_EnterFilename")); // NOI18N
1189: return false; // unspecified WSDL file
1190: }
1191:
1192: File f = new File(wsdlFilePath);
1193: if (f == null) {
1194: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1195: NbBundle.getMessage(ClientInfo.class,
1196: "ERR_WsdlInvalid")); // NOI18N
1197: return false; // invalid WSDL file
1198: }
1199:
1200: if (!f.exists()) {
1201: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1202: NbBundle.getMessage(ClientInfo.class,
1203: "ERR_WsdlDoesNotExist")); // NOI18N
1204: return false; // invalid WSDL file
1205: }
1206:
1207: // 50103 - could be done via xml api, but this way should be quicker and suffice the need
1208: FileReader fr = null;
1209: LineNumberReader lnReader = null;
1210: boolean foundWsdlNamespace = false;
1211: try {
1212: fr = new FileReader(f);
1213: lnReader = new LineNumberReader(fr);
1214: if (lnReader != null) {
1215: String line = null;
1216: try {
1217: line = lnReader.readLine();
1218: } catch (IOException ioe) {
1219: //ignore
1220: }
1221: while (line != null) {
1222: if (line
1223: .indexOf("http://schemas.xmlsoap.org/wsdl/") > 0) { //NOI18N
1224: foundWsdlNamespace = true;
1225: }
1226: if (line.indexOf("REPLACE_WITH_ACTUAL_URL") > 0) { //NOI18N
1227: wizardDescriptor.putProperty(
1228: PROP_ERROR_MESSAGE, NbBundle
1229: .getMessage(
1230: ClientInfo.class,
1231: "ERR_WrongWsdl")); // NOI18N
1232: return false;
1233: } //NOI18N
1234: try {
1235: line = lnReader.readLine();
1236: } catch (IOException ioe) {
1237: //ignore
1238: }
1239: }
1240: }
1241: } catch (FileNotFoundException fne) {
1242: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1243: NbBundle.getMessage(ClientInfo.class,
1244: "ERR_WsdlDoesNotExist")); // NOI18N
1245: } finally {
1246: try {
1247: if (lnReader != null) {
1248: lnReader.close();
1249: }
1250: } catch (IOException e) {
1251: ErrorManager.getDefault().notify(e);
1252: }
1253: }
1254:
1255: if (!foundWsdlNamespace) {
1256: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1257: NbBundle.getMessage(ClientInfo.class,
1258: "ERR_NotWsdl", f.getName())); // NOI18N
1259: return false;
1260: }
1261:
1262: // !PW FIXME should also detect if WSDL file has previously been added to
1263: // this project. Note that not doing so and overwriting the existing entry
1264: // is the equivalent of doing an update on it. Nothing bad will happen
1265: // unless it turns out the user didn't want to update the service in the
1266: // first place.
1267:
1268: try {
1269: rpcEncoded = isRpcEncoded(f);
1270: } catch (Exception e) {
1271: ErrorManager.getDefault().annotate(
1272: e,
1273: ErrorManager.WARNING,
1274: "Unable to check if wsdl is rpc encoded.",
1275: NbBundle.getMessage(ClientInfo.class,
1276: "ERR_UnableToDetermineRPCEncoded"),
1277: e.getCause(), new java.util.Date());
1278: }
1279: }
1280:
1281: if (rpcEncoded) {
1282: if (jComboBoxJaxVersion.isEnabled()) {
1283: jComboBoxJaxVersion
1284: .setSelectedItem(ClientWizardProperties.JAX_RPC);
1285: }
1286: if (!ClientWizardProperties.JAX_RPC
1287: .equals(jComboBoxJaxVersion.getSelectedItem())) {
1288: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1289: NbBundle.getMessage(ClientInfo.class,
1290: "ERR_RPCEncodedJaxrpcClientRequired")); // NOI18N
1291: return false;
1292: }
1293: }
1294:
1295: String packageName = getPackageName();
1296: if (packageName == null || packageName.length() == 0) {
1297: String jaxwsVersion = (String) this .jComboBoxJaxVersion
1298: .getSelectedItem();
1299: if (!jaxwsVersion.equals(ClientWizardProperties.JAX_WS)) {
1300: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1301: NbBundle.getMessage(ClientInfo.class,
1302: "MSG_EnterJavaPackageName")); // NOI18N
1303: return false; // unspecified java package file
1304: }
1305: }
1306:
1307: if (packageName != null && packageName.length() > 0
1308: && !JaxWsUtils.isJavaPackage(packageName)) {
1309: wizardDescriptor
1310: .putProperty(PROP_ERROR_MESSAGE, NbBundle
1311: .getMessage(ClientInfo.class,
1312: "ERR_PackageInvalid")); // NOI18N
1313: return false; // invalid package name
1314: }
1315:
1316: // Don't allow to create java artifacts to package already used by other service/client
1317: JaxWsModel jaxWsModel = (JaxWsModel) p.getLookup().lookup(
1318: JaxWsModel.class);
1319: if (packageName != null && packageName.length() > 0
1320: && jaxWsModel != null) {
1321: Service[] services = jaxWsModel.getServices();
1322: for (int i = 0; i < services.length; i++) {
1323: // test service with java artifacts (created from WSDL file)
1324: if (services[i].getWsdlUrl() != null
1325: && packageName.equals(services[i]
1326: .getPackageName())) {
1327: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1328: NbBundle.getMessage(ClientInfo.class,
1329: "ERR_PackageUsedForService",
1330: services[i].getServiceName()));
1331: return false;
1332: }
1333: // test service without java artifacts (created from java)
1334: String pn = getPackageNameFromClass(services[i]
1335: .getImplementationClass());
1336: if (services[i].getWsdlUrl() == null
1337: && packageName.equals(pn)) {
1338: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1339: NbBundle.getMessage(ClientInfo.class,
1340: "ERR_PackageUsedForService",
1341: services[i].getServiceName()));
1342: return false;
1343: }
1344: }
1345: Client[] clients = jaxWsModel.getClients();
1346: for (int i = 0; i < clients.length; i++) {
1347: if (packageName.equals(clients[i].getPackageName())) {
1348: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE,
1349: NbBundle.getMessage(ClientInfo.class,
1350: "ERR_PackageUsedForClient",
1351: clients[i].getName()));
1352: return false;
1353: }
1354: }
1355:
1356: }
1357:
1358: //warning if the project directory has embedded spaces
1359: //TODO - Remove this when the jwsdp version that fixes this problem is available
1360: if (projectHasEmbeddedSpaces()) {
1361: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, NbBundle
1362: .getMessage(ClientInfo.class,
1363: "MSG_SPACE_IN_PROJECT_PATH")); // NOI18N
1364: } else {
1365: wizardDescriptor.putProperty(PROP_ERROR_MESSAGE, ""); //NOI18N
1366: }
1367:
1368: wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
1369:
1370: return true;
1371: }
1372:
1373: private boolean projectHasEmbeddedSpaces() {
1374: FileObject projectDir = project.getProjectDirectory();
1375: File projectDirFile = FileUtil.toFile(projectDir);
1376: String path = projectDirFile.getAbsolutePath();
1377: int index = path.indexOf(" ");
1378: return index != -1;
1379: }
1380:
1381: private J2eePlatform getJ2eePlatform(Project project) {
1382: J2eeModuleProvider provider = (J2eeModuleProvider) project
1383: .getLookup().lookup(J2eeModuleProvider.class);
1384: if (provider != null) {
1385: String serverInstanceID = provider.getServerInstanceID();
1386: if (serverInstanceID != null
1387: && serverInstanceID.length() > 0) {
1388: return Deployment.getDefault().getJ2eePlatform(
1389: serverInstanceID);
1390: }
1391: }
1392: return null;
1393: }
1394:
1395: private boolean isJsr109Supported(Project project) {
1396: J2eePlatform j2eePlatform = getJ2eePlatform(project);
1397: if (j2eePlatform != null) {
1398: return j2eePlatform
1399: .isToolSupported(J2eePlatform.TOOL_JSR109);
1400: }
1401: return false;
1402: }
1403:
1404: private boolean isJsr109OldSupported(Project project) {
1405: J2eePlatform j2eePlatform = getJ2eePlatform(project);
1406: if (j2eePlatform != null) {
1407: return j2eePlatform
1408: .isToolSupported(J2eePlatform.TOOL_WSCOMPILE);
1409: }
1410: return false;
1411: }
1412:
1413: private boolean isJwsdpSupported(Project project) {
1414: J2eePlatform j2eePlatform = getJ2eePlatform(project);
1415: if (j2eePlatform != null) {
1416: return j2eePlatform
1417: .isToolSupported(J2eePlatform.TOOL_JWSDP);
1418: }
1419: return false;
1420: }
1421:
1422: public boolean isJaxWsInJ2ee14Supported(Project project) {
1423: J2eePlatform j2eePlatform = getJ2eePlatform(project);
1424: if (j2eePlatform != null) {
1425: return j2eePlatform
1426: .isToolSupported("JaxWs-in-j2ee14-supported");
1427: }
1428: return false;
1429: }
1430:
1431: /**
1432: * If the project the web service client is being created is not on a JSR 109 platform,
1433: * its Java source level must be at least 1.5
1434: */
1435: private boolean checkNonJsr109Valid(
1436: WizardDescriptor wizardDescriptor) {
1437: Project project = Templates.getProject(wizardDescriptor);
1438: ProjectInfo pInfo = new ProjectInfo(project);
1439: // javase client should be source level 1.4 or higher
1440: // other types of projects should have source level 1.5 or higher
1441: if (pInfo.getProjectType() != ProjectInfo.JSE_PROJECT_TYPE) {
1442: boolean jsr109Supported = isJsr109Supported(project);
1443: boolean jsr109oldSupported = isJsr109OldSupported(project);
1444: boolean jwsdpSupported = isJwsdpSupported(project);
1445: boolean jaxWsInJ2ee14Supported = isJaxWsInJ2ee14Supported(project);
1446: if ((!jsr109Supported && !jsr109oldSupported)
1447: || jaxWsInJ2ee14Supported
1448: || (!jsr109Supported && jsr109oldSupported && jwsdpSupported)) {
1449: if (Util.isSourceLevel14orLower(project)) {
1450: wizardDescriptor.putProperty(
1451: "WizardPanel_errorMessage",
1452: NbBundle.getMessage(ClientInfo.class,
1453: "ERR_NeedProperSourceLevel")); // NOI18N
1454: return false;
1455: }
1456: }
1457: } else {
1458: String srcLevel = Util.getSourceLevel(project);
1459: if (srcLevel != null) {
1460: return Double.parseDouble(srcLevel) >= 1.4;
1461: }
1462: return false;
1463: }
1464: return true;
1465: }
1466:
1467: private void wsdlUrlChanged() {
1468: // Throw away any existing retriever. New URL means user has to download it again.
1469: retriever = null;
1470:
1471: updateTexts();
1472: }
1473:
1474: private void updateTexts() {
1475: if (!settingFields) {
1476: descriptorPanel.fireChangeEvent(); // Notify that the panel changed
1477: }
1478: }
1479:
1480: public void setWsdlDownloadMessage(String m) {
1481: downloadMsg = m;
1482:
1483: // reenable edit control if state indicates download is completed (or failed).
1484: if (retriever.getState() >= WsdlRetriever.STATUS_COMPLETE) {
1485: jTxtWsdlURL.setEditable(true);
1486: jTxtLocalFilename.setText(retriever.getWsdlFileName());
1487: }
1488:
1489: descriptorPanel.fireChangeEvent();
1490: }
1491:
1492: private static class WsdlFileFilter extends FileFilter {
1493: public boolean accept(File f) {
1494: String ext = FileUtil.getExtension(f.getName());
1495: return f.isDirectory() || "wsdl".equalsIgnoreCase(ext)
1496: || "asmx".equalsIgnoreCase(ext); // NOI18N
1497: }
1498:
1499: public String getDescription() {
1500: return NbBundle.getMessage(ClientInfo.class,
1501: "LBL_WsdlFilterDescription"); // NOI18N
1502: }
1503: }
1504:
1505: private String browseProjectServices() {
1506: JaxWsExplorerPanel explorerPanel = new JaxWsExplorerPanel();
1507: DialogDescriptor descriptor = new DialogDescriptor(
1508: explorerPanel, NbBundle.getMessage(ClientInfo.class,
1509: "TTL_SelectService")); //NOI18N
1510: explorerPanel.setDescriptor(descriptor);
1511: // if(DialogDisplayer.getDefault().notify(descriptor).equals(NotifyDescriptor.OK_OPTION)) {
1512: Dialog dlg = DialogDisplayer.getDefault().createDialog(
1513: descriptor);
1514: dlg.getAccessibleContext().setAccessibleDescription(
1515: dlg.getTitle());
1516: dlg.setVisible(true);
1517:
1518: if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
1519:
1520: Node serviceNode = explorerPanel.getSelectedService();
1521: WsWsdlCookie wsdlCookie = (WsWsdlCookie) serviceNode
1522: .getCookie(WsWsdlCookie.class);
1523: if (wsdlCookie != null) {
1524: return wsdlCookie.getWsdlURL();
1525: }
1526: }
1527: return null;
1528: }
1529:
1530: private String getPackageNameFromClass(String className) {
1531: String packageName = null;
1532: if (className != null) {
1533: int indexDot = className.lastIndexOf('.');
1534: if (indexDot < 0)
1535: indexDot = 0;
1536: packageName = className.substring(0, indexDot);
1537: }
1538: return packageName;
1539: }
1540:
1541: private boolean isRpcEncoded(File wsdlFile) {
1542: FileObject wsdlFO = FileUtil.toFileObject(FileUtil
1543: .normalizeFile(wsdlFile));
1544: WSDLModel model = WSDLModelFactory.getDefault().getModel(
1545: Utilities.getModelSource(wsdlFO, false));
1546: for (Binding binding : model.getDefinitions().getBindings()) {
1547: for (SOAPBinding soapBinding : binding
1548: .getExtensibilityElements(SOAPBinding.class)) {
1549: if (soapBinding.getStyle() == SOAPBinding.Style.RPC) {
1550: for (BindingOperation operation : binding
1551: .getBindingOperations()) {
1552: if (operation.getBindingInput() != null) {
1553: for (SOAPBody body : operation
1554: .getBindingInput()
1555: .getExtensibilityElements(
1556: SOAPBody.class))
1557: if (body.getUse() == SOAPBody.Use.ENCODED)
1558: return true;
1559: }
1560: if (operation.getBindingOutput() != null) {
1561: for (SOAPBody body : operation
1562: .getBindingOutput()
1563: .getExtensibilityElements(
1564: SOAPBody.class))
1565: if (body.getUse() == SOAPBody.Use.ENCODED)
1566: return true;
1567: }
1568: }
1569: }
1570: }
1571: }
1572:
1573: return false;
1574: }
1575: }
|