1 19 20 package org.netbeans.modules.websvc.registry.ui; 21 22 import org.netbeans.modules.websvc.registry.jaxrpc.Wsdl2Java; 23 import org.netbeans.modules.websvc.registry.model.WebServiceData; 24 import org.netbeans.modules.websvc.registry.model.WSPort; 25 import org.netbeans.modules.websvc.registry.model.WebServiceGroup; 26 import org.netbeans.modules.websvc.registry.model.WebServiceListModel; 27 import org.netbeans.modules.websvc.registry.nodes.WebServiceGroupCookie; 28 import org.netbeans.modules.websvc.registry.util.Util; 29 import org.netbeans.modules.websvc.registry.wsdl.WSDLInfo; 30 31 import com.sun.xml.rpc.processor.model.java.JavaMethod; 32 import com.sun.xml.rpc.processor.model.java.JavaParameter; 33 import com.sun.xml.rpc.processor.model.Port; 34 import com.sun.xml.rpc.processor.model.Operation; 35 36 37 import java.awt.BorderLayout ; 38 import java.awt.Component ; 39 import java.awt.Point ; 40 import java.awt.Dialog ; 41 import java.awt.Cursor ; 42 import java.awt.Dimension ; 43 import java.awt.FlowLayout ; 44 import java.awt.GridBagConstraints ; 45 import java.awt.GridBagLayout ; 46 import java.awt.Insets ; 47 import java.awt.Rectangle ; 48 import java.awt.Toolkit ; 49 import java.awt.event.ActionEvent ; 50 import java.awt.event.ActionListener ; 51 import java.awt.event.WindowAdapter ; 52 import java.awt.event.WindowEvent ; 53 import java.awt.event.MouseAdapter ; 54 import java.awt.event.MouseEvent ; 55 import java.awt.event.ItemEvent ; 56 import java.awt.event.MouseListener ; 57 import java.beans.XMLDecoder ; 58 import java.beans.XMLEncoder ; 59 import java.io.*; 60 import java.net.MalformedURLException ; 61 import java.net.URL ; 62 import java.net.URLClassLoader ; 63 import java.awt.EventQueue ; 64 65 import java.text.SimpleDateFormat ; 66 import java.util.Date ; 67 import java.util.Iterator ; 68 import java.util.Set ; 69 import java.util.HashSet ; 70 import java.util.HashMap ; 71 import java.util.StringTokenizer ; 72 import java.util.LinkedList ; 73 74 import java.lang.reflect.InvocationTargetException ; 75 76 import javax.swing.*; 77 import javax.swing.border.EmptyBorder ; 78 import javax.swing.event.HyperlinkEvent ; 79 import javax.swing.event.HyperlinkListener ; 80 import javax.swing.text.ComponentView ; 81 import javax.swing.text.Element ; 82 import javax.swing.text.View ; 83 import javax.swing.text.Position.Bias; 84 import javax.swing.text.html.HTMLDocument ; 85 import javax.swing.text.html.HTML ; 86 import javax.swing.text.AttributeSet ; 87 import javax.swing.text.BadLocationException ; 88 import javax.swing.text.Document ; 89 import javax.swing.text.html.HTMLEditorKit ; 90 import javax.swing.text.html.HTML.Attribute; 91 import javax.swing.JOptionPane ; 92 93 import org.openide.DialogDescriptor; 94 import org.openide.DialogDisplayer; 95 import org.openide.ErrorManager; 96 import org.openide.NotifyDescriptor; 97 import org.openide.NotifyDescriptor.Message; 98 import org.openide.awt.Mnemonics; 99 import org.openide.nodes.Node; 100 import org.openide.util.HelpCtx; 101 import org.openide.util.NbBundle; 102 import org.openide.util.RequestProcessor; 103 import org.openide.windows.WindowManager; 104 105 106 107 108 109 110 115 public class AddWebServiceDlg extends JPanel implements ActionListener , HyperlinkListener { 116 117 118 public static final int RET_CANCEL = 0; 119 120 public static final int RET_OK = 1; 121 122 private DialogDescriptor dlg = null; 123 private String addString = "ADD"; private String cancelString = "CANCEL"; private String copyString = "COPY"; private String clearString = "CLEAR"; 128 131 private String currentMessages =""; 132 133 136 private String currentWSDL=""; 137 140 private String previousWSDL=""; 141 142 143 static final String WS_URL_PROPS = "ws_urls.xml"; 145 private static BufferedWriter outFile; 146 147 private WSDLInfo currentWSDLInfo = null; 148 149 private Dialog dialog; 150 151 private Node invokingNode; 152 153 Set webServicesToProcess = null; 154 155 private static JFileChooser wsdlFileChooser; 156 157 private String URL_WSDL_MSG = NbBundle.getMessage(AddWebServiceDlg.class, "URL_WSDL_MSG"); 158 private String LOCAL_WSDL_MSG = NbBundle.getMessage(AddWebServiceDlg.class, "LOCAL_WSDL_MSG"); 159 160 MRUPersistenceManager persistenceManager = new MRUPersistenceManager(); 161 162 170 171 HashMap jarCache = new HashMap (); 172 173 private JPanel emptyPanel = new JPanel(); 174 private JPanel infoTextPanel = new JPanel(); 175 private JPanel selectionContainer = new JPanel(); 176 private JPanel selectionPanel = new JPanel(); 177 private JPanel buttonPanel = new JPanel(); 178 private JPanel buttonPanelContainer = new JPanel(); 179 private JPanel centerPanel = new JPanel(); 180 private JPanel messagePanel = new JPanel(); 181 182 private JButton cancelButton = new JButton(); 183 private JButton localFileButton = new JButton(); 184 private JButton addButton = new JButton(); 185 private JButton uddiRegistryButton = new JButton(); 186 private JButton getInfoButton = new JButton(); 187 188 private JButton httpProxyButton = new JButton(); 189 190 private JComboBox localFileComboBox = new JComboBox(); 191 private JComboBox uddiRegistryComboBox = new JComboBox(); 192 private JComboBox urlComboBox = new JComboBox(); 193 194 private JEditorPane infoTextArea = new JEditorPane(); 195 private JScrollPane infoTextScrollPane = new JScrollPane(); 196 197 private JEditorPane messageTextArea = new JEditorPane(); 198 private JScrollPane messageTextScrollPane = new JScrollPane(); 199 200 private JLabel infoTextlabel = new JLabel(); 201 private JLabel messageTextlabel = new JLabel(); 202 private JLabel jLabel1 = new JLabel(); 203 204 private JRadioButton localFileRadioButton = new JRadioButton(); 205 private JRadioButton uddiRegistryRadioButton = new JRadioButton(); 206 private JRadioButton urlRadioButton = new JRadioButton(); 207 208 private JPopupMenu resultsPopup = new JPopupMenu(); 209 private JMenuItem copyMenuItem = new JMenuItem(); 210 private JMenuItem clearMenuItem = new JMenuItem(); 211 212 private ButtonGroup selectionGroup = new ButtonGroup(); 213 214 private int returnStatus = RET_CANCEL; 215 216 private WebServiceGroup websvcGroup; 217 218 private SimpleDateFormat dateFormat = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 219 220 private HTMLDocument document = new HTMLDocument (); 221 222 223 private void initAccessibility() { 224 infoTextlabel.setLabelFor(infoTextArea); 225 messageTextlabel.setLabelFor(messageTextArea); 226 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "ADD_WEB_SERVICE")); 227 localFileButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "BROWSE")); 228 urlRadioButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_URL")); 229 localFileRadioButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_LOCAL_FILE")); 230 httpProxyButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "SET_HTTP_PROXY")); 231 getInfoButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddWebServiceDlg.class, "GET")); 232 } 233 234 235 public AddWebServiceDlg() { 236 this(true,null); 237 } 238 239 240 public AddWebServiceDlg(boolean modal, Node node) { 241 invokingNode = node; 242 initComponents(); 244 initAccessibility(); 245 246 uddiRegistryComboBox.setRenderer(new WSListCellRenderer()); 247 wsdlFileChooser = new JFileChooser(); 248 WSDLFileFilter myFilter = new WSDLFileFilter(); 249 wsdlFileChooser.setFileFilter(myFilter); 250 251 enableControls(); 252 persistenceManager.loadMRU(); 253 setDefaults(); 254 } 255 256 public void displayDialog(){ 257 258 dlg = new DialogDescriptor(this, NbBundle.getMessage(AddWebServiceDlg.class, "ADD_WEB_SERVICE"), 259 false, NotifyDescriptor.OK_CANCEL_OPTION, DialogDescriptor.CANCEL_OPTION, 260 DialogDescriptor.DEFAULT_ALIGN, this.getHelpCtx(), this); 261 addButton.setEnabled(false); 262 dlg.setOptions(new Object [] { addButton, cancelButton }); 263 dialog = DialogDisplayer.getDefault().createDialog(dlg); 264 267 268 final JPanel thisPanel = this; 269 dialog.addWindowListener( new WindowAdapter (){ 270 public void windowOpened( WindowEvent e ){ 271 SwingUtilities.invokeLater( 272 new Runnable () { 273 public void run() { 274 getInfoButton.requestFocus(); 275 thisPanel.getRootPane().setDefaultButton(getInfoButton); 276 } 277 }); 278 } 279 }); 280 281 dialog.show(); 282 } 283 284 285 public int getReturnStatus() { 286 return returnStatus; 287 } 288 289 private void cancelButtonAction(ActionEvent evt) { 290 returnStatus = RET_CANCEL; 291 closeDialog(); 292 } 293 294 private void closeDialog() { 295 296 persistenceManager.saveMRU(); 297 dialog.dispose(); 298 299 } 300 private void copyMenuItemAction(ActionEvent evt) { 301 messageTextArea.copy(); 302 } 303 private void clearMenuItemAction(ActionEvent evt) { 304 currentMessages=""; 305 messageTextArea.setText(""); 306 } 307 308 309 public HelpCtx getHelpCtx() { 310 return new HelpCtx(AddWebServiceDlg.class); 311 } 312 313 private void initComponents() { 314 GridBagConstraints gridBagConstraints; 315 316 setLayout(new BorderLayout (5, 1)); 317 318 selectionContainer.setLayout(new BorderLayout ()); 319 320 selectionContainer.setBorder(new EmptyBorder (new Insets (5, 5, 5, 5))); 321 jLabel1.setText(NbBundle.getMessage(this.getClass(), "SELECT_SOURCE")); 322 selectionContainer.add(jLabel1, BorderLayout.NORTH); 323 324 selectionPanel.setLayout(new GridBagLayout ()); 325 326 selectionPanel.setBorder(new EmptyBorder (new Insets (5, 5, 5, 5))); 327 Mnemonics.setLocalizedText(urlRadioButton,NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_URL") ); 328 urlRadioButton.addActionListener(new ActionListener () { 329 public void actionPerformed(ActionEvent evt) { 330 enableControls(); 331 } 332 }); 333 urlRadioButton.setSelected(true); 334 selectionGroup.add(urlRadioButton); 335 gridBagConstraints = new GridBagConstraints (); 336 gridBagConstraints.gridx = 0; 337 gridBagConstraints.gridy = 0; 338 gridBagConstraints.anchor = GridBagConstraints.WEST; 339 gridBagConstraints.insets = new Insets (2, 2, 2, 2); 340 selectionPanel.add(urlRadioButton, gridBagConstraints); 341 342 urlComboBox.setEditable(true); 343 344 345 gridBagConstraints = new GridBagConstraints (); 346 gridBagConstraints.gridx = 1; 347 gridBagConstraints.gridy = 0; 348 gridBagConstraints.gridwidth = 5; 349 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 350 gridBagConstraints.anchor = GridBagConstraints.WEST; 351 gridBagConstraints.weightx = 1.0; 352 gridBagConstraints.insets = new Insets (2, 2, 2, 2); 353 selectionPanel.add(urlComboBox, gridBagConstraints); 354 355 Mnemonics.setLocalizedText(localFileRadioButton,NbBundle.getMessage(AddWebServiceDlg.class, "RADIO_LOCAL_FILE") ); 356 localFileRadioButton.setSelected(false); 357 localFileRadioButton.addActionListener(new ActionListener () { 358 public void actionPerformed(ActionEvent evt) { 359 enableControls(); 360 } 361 }); 362 selectionGroup.add(localFileRadioButton); 363 gridBagConstraints = new GridBagConstraints (); 364 gridBagConstraints.gridx = 0; 365 gridBagConstraints.gridy = 1; 366 gridBagConstraints.anchor = GridBagConstraints.WEST; 367 gridBagConstraints.insets = new Insets (2, 2, 2, 2); 368 selectionPanel.add(localFileRadioButton, gridBagConstraints); 369 370 localFileComboBox.setEditable(true); 371 372 gridBagConstraints = new GridBagConstraints (); 373 gridBagConstraints.gridx = 1; 374 gridBagConstraints.gridy = 1; 375 gridBagConstraints.gridwidth = 5; 376 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 377 gridBagConstraints.anchor = GridBagConstraints.WEST; 378 gridBagConstraints.weightx = 1.0; 379 gridBagConstraints.insets = new Insets (2, 2, 2, 2); 380 selectionPanel.add(localFileComboBox, gridBagConstraints); 381 382 Mnemonics.setLocalizedText(localFileButton,NbBundle.getMessage(AddWebServiceDlg.class, "BROWSE")); 383 localFileButton.addActionListener(new ActionListener () { 384 public void actionPerformed(ActionEvent evt) { 385 localFileButtonAction(evt); 386 } 387 }); 388 gridBagConstraints = new GridBagConstraints (); 389 gridBagConstraints.gridx = 6; 390 gridBagConstraints.gridy = 1; 391 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 392 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 393 gridBagConstraints.anchor = GridBagConstraints.WEST; 394 gridBagConstraints.insets = new Insets (2, 2, 2, 2); 395 selectionPanel.add(localFileButton, gridBagConstraints); 396 397 398 Mnemonics.setLocalizedText(getInfoButton,NbBundle.getMessage(AddWebServiceDlg.class, "GET")); 399 getInfoButton.addActionListener(new ActionListener () { 400 public void actionPerformed(ActionEvent evt) { 401 getInfoButtonAction(evt); 402 } 403 }); 404 gridBagConstraints = new GridBagConstraints (); 405 gridBagConstraints.gridx = 0; 406 gridBagConstraints.gridy = 2; 407 gridBagConstraints.gridwidth = 2; 408 gridBagConstraints.anchor = GridBagConstraints.WEST; 409 gridBagConstraints.insets = new Insets (5, 2, 5, 2); 410 selectionPanel.add(getInfoButton, gridBagConstraints); 411 412 Mnemonics.setLocalizedText(httpProxyButton,NbBundle.getMessage(AddWebServiceDlg.class, "SET_HTTP_PROXY")); 413 httpProxyButton.addActionListener(new ActionListener () { 414 public void actionPerformed(ActionEvent evt) { 415 new ProxySelectionDialog().show(); 416 } 417 }); 418 419 gridBagConstraints = new GridBagConstraints (); 420 gridBagConstraints.gridx = 6; 421 gridBagConstraints.gridy = 2; 422 gridBagConstraints.anchor = GridBagConstraints.EAST; 423 gridBagConstraints.insets = new Insets (5, 2, 5, 2); 424 selectionPanel.add(httpProxyButton, gridBagConstraints); 425 426 selectionContainer.add(selectionPanel, BorderLayout.CENTER); 427 428 add(selectionContainer, BorderLayout.NORTH); 429 430 infoTextPanel.setLayout(new BorderLayout (5, 5)); 431 432 infoTextPanel.setBorder(new EmptyBorder (new Insets (5, 5, 5, 5))); 433 infoTextArea.setEditable(false); 434 437 infoTextArea.setFocusable(false); 438 infoTextArea.setFocusCycleRoot(false); 439 infoTextArea.setContentType("text/html"); 440 infoTextArea.addHyperlinkListener(this); 441 442 infoTextScrollPane.setViewportView(infoTextArea); 443 444 infoTextPanel.add(infoTextScrollPane, BorderLayout.CENTER); 445 446 Mnemonics.setLocalizedText(infoTextlabel,NbBundle.getMessage(AddWebServiceDlg.class, "WEBSERVICE_INFORMATION")); 447 infoTextPanel.add(infoTextlabel, BorderLayout.NORTH); 448 449 messagePanel.setLayout(new BorderLayout (5,5)); 450 messagePanel.setBorder(new EmptyBorder (new Insets (5, 5, 5, 5))); 451 452 messageTextArea.setEditable(false); 453 messageTextArea.setContentType("text/html"); 454 messageTextArea.setToolTipText(NbBundle.getMessage(AddWebServiceDlg.class, "TOOLTIP_MESSAGEAREA")); 455 messageTextScrollPane.setViewportView(messageTextArea); 456 457 messagePanel.add(messageTextScrollPane, BorderLayout.CENTER); 458 org.openide.awt.Mnemonics.setLocalizedText(messageTextlabel, NbBundle.getMessage(AddWebServiceDlg.class, "RESULTS")); 459 460 messagePanel.add(messageTextlabel, BorderLayout.NORTH); 461 462 centerPanel.setLayout(new BorderLayout (5,5)); 463 464 centerPanel.add(infoTextPanel, BorderLayout.CENTER); 465 centerPanel.add(messagePanel, BorderLayout.SOUTH); 466 467 add(centerPanel, BorderLayout.CENTER); 468 469 Mnemonics.setLocalizedText(addButton,NbBundle.getMessage(AddWebServiceDlg.class, "Add")); 470 addButton.setActionCommand(addString); 471 Mnemonics.setLocalizedText(cancelButton,NbBundle.getMessage(AddWebServiceDlg.class, "CANCEL")); 472 cancelButton.setActionCommand(cancelString); 473 buttonPanel.setLayout(new FlowLayout (FlowLayout.RIGHT)); 474 buttonPanel.add(addButton); 475 buttonPanel.add(cancelButton); 476 477 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 478 setBounds((screenSize.width-400)/2, (screenSize.height-400)/2, 400, 400); 479 480 481 484 copyMenuItem.setText(NbBundle.getMessage(AddWebServiceDlg.class, "CONTEXTMENU_COPY")); 485 copyMenuItem.setActionCommand(copyString); 486 copyMenuItem.addActionListener(this); 487 resultsPopup.add(copyMenuItem); 488 489 clearMenuItem.setText(NbBundle.getMessage(AddWebServiceDlg.class, "CONTEXTMENU_CLEAR")); 490 clearMenuItem.setActionCommand(clearString); 491 clearMenuItem.addActionListener(this); 492 resultsPopup.add(clearMenuItem); 493 MouseListener popupListener = new PopupListener(); 494 messageTextArea.addMouseListener(popupListener); 495 496 497 } 498 499 private void enableControls(){ 500 boolean enabled = false; 501 enabled = urlRadioButton.isSelected(); 502 urlComboBox.setEnabled(enabled); 503 504 enabled = localFileRadioButton.isSelected(); 505 localFileComboBox.setEnabled(enabled); 506 localFileButton.setEnabled(enabled); 507 508 enabled = uddiRegistryRadioButton.isSelected(); 509 uddiRegistryComboBox.setEnabled(enabled); 510 uddiRegistryButton.setEnabled(enabled); 511 512 } 513 514 515 private String fixFileURL(String inFileURL) { 516 String returnFileURL = inFileURL; 517 if(returnFileURL.substring(0,1).equalsIgnoreCase("/")) { 518 returnFileURL = "file://" + returnFileURL; 519 } else { 520 returnFileURL = "file:///" + returnFileURL; 521 } 522 523 return returnFileURL; 524 } 525 526 private String fixWsdlURL(String inURL) { 527 String returnWsdlURL = inURL; 528 if (!returnWsdlURL.toLowerCase().endsWith("wsdl")) { 535 returnWsdlURL += "?WSDL"; 536 } 537 538 return returnWsdlURL; 539 } 540 541 private void localFileButtonAction(ActionEvent evt) { 542 File curDir = null; 544 File curSelection = null; 545 if(localFileComboBox.getSelectedIndex() >= 0){ 546 curSelection = new File((String )localFileComboBox.getSelectedItem()); 547 if (curSelection.exists()){ 548 if (curSelection.isDirectory()) { 549 curDir = curSelection; 550 } else { 551 curDir = curSelection.getParentFile(); 552 } 553 } 554 } 555 556 if (curDir == null) curDir = new File(System.getProperty("netbeans.user"), "websvc"); 557 if (curSelection != null && curSelection.exists()) wsdlFileChooser.setSelectedFile(curSelection); 558 wsdlFileChooser.setCurrentDirectory(curDir); 559 560 if (wsdlFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 561 String localFile = wsdlFileChooser.getSelectedFile().getAbsolutePath(); 562 if(((DefaultComboBoxModel)localFileComboBox.getModel()).getIndexOf(localFile) == -1) { 563 localFileComboBox.addItem(localFile); 564 } 565 localFileComboBox.setSelectedItem(localFile); 566 567 processWSDL(this.fixFileURL(localFile)); 568 } 569 } 570 571 private void getInfoButtonAction(ActionEvent evt) { 572 575 576 String urlString = null; 577 578 if(this.urlRadioButton.isSelected()) { 579 final String urlStr = ((String ) urlComboBox.getSelectedItem()).trim(); 580 583 if(null != urlStr && urlStr.equalsIgnoreCase(this.URL_WSDL_MSG)) { 584 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 585 displayError(NbBundle.getMessage(this.getClass(), "ERROR_MUST_SPECIFY_URL")); 586 587 } else { 588 589 if(((DefaultComboBoxModel)urlComboBox.getModel()).getIndexOf(urlStr) == -1) { 590 urlComboBox.addItem(urlStr); 591 } 592 RequestProcessor.getDefault().post(new Runnable () { 593 public void run() { 594 processWSDL(fixWsdlURL(urlStr)); 595 } 596 }); 597 598 } 599 } else if(this.localFileRadioButton.isSelected()) { 600 601 final String chosenFile = (String )this.localFileComboBox.getSelectedItem(); 602 605 606 if(chosenFile != null && chosenFile.equalsIgnoreCase(this.LOCAL_WSDL_MSG)) { 607 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 608 displayError(NbBundle.getMessage(this.getClass(), "ERROR_MUST_LOCAL_FILE")); 609 } else { 610 613 if(((DefaultComboBoxModel)localFileComboBox.getModel()).getIndexOf(chosenFile) == -1) { 614 localFileComboBox.addItem(chosenFile); 615 } 616 RequestProcessor.getDefault().post(new Runnable () { 617 public void run() { 618 processWSDL(fixFileURL(chosenFile)); 619 } 620 }); 621 } 622 } 623 624 625 626 } 627 628 private void processWSDL(String inWSDLURL) { 629 630 631 Cursor normalCursor = dialog.getCursor(); 632 dialog.setCursor(new Cursor (Cursor.WAIT_CURSOR)); 633 634 637 setCurrentWSDL(inWSDLURL); 638 639 if(null == inWSDLURL) { 640 return; 641 } 642 URL wsdlUrl = null; 643 try { 644 wsdlUrl = new URL (inWSDLURL); 645 } catch(MalformedURLException mue) { 646 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 647 displayError(NbBundle.getMessage(this.getClass(), "INVALID_URL")); 648 dialog.setCursor(normalCursor); 649 return; 650 } 651 652 655 currentWSDLInfo = generateWsdlInfo(wsdlUrl); 656 if(null != currentWSDLInfo) { 657 660 this.setWebServicesToProcess(currentWSDLInfo.getWebServices()); 661 664 displayWSDLInfo(currentWSDLInfo.getWebServices()); 665 668 infoTextArea.setCaretPosition(1); 669 670 if (!currentWSDLInfo.hasOperations()) { 671 displayError("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "WARNING_SOLICIT") + "</FONT>"); 672 } 673 } 674 675 dialog.setCursor(normalCursor); 676 677 } 678 679 680 private String getCurrentWSDL() { 681 return currentWSDL; 682 } 683 private void setCurrentWSDL(String inWSDL) { 684 currentWSDL = inWSDL; 685 } 686 687 688 private void uddiRegistryButtonAction(ActionEvent evt) { 689 } 690 691 private WSDLInfo generateWsdlInfo(final URL wsdlUrl) { 692 Set webServices = null; 693 694 698 addButton.setEnabled(false); 699 700 WSDLInfo returnWSDLInfo = new WSDLInfo(); 701 if (dlg != null) dlg.setValid(false); 702 infoTextlabel.setEnabled(true); 703 infoTextArea.setEnabled(true); 704 705 706 StringWriter infoWriter = new StringWriter(); 707 infoWriter.write(NbBundle.getMessage(AddWebServiceDlg.class, "PARSING_MSG")); 708 infoWriter.write("WSDL - " + wsdlUrl.toString()); 709 710 displayMessage(infoWriter.toString()); 711 712 returnWSDLInfo.setWsdlUrl(wsdlUrl); 713 Date date = new Date (); 714 File tmpOutputDir = null; 715 try{ 716 File tempFile = File.createTempFile("wstemp","ws"); 717 tmpOutputDir = new File(tempFile.getParentFile(), "wstemp" + date.getTime()); 718 if (tmpOutputDir.exists()) tmpOutputDir.mkdirs(); 719 }catch (IOException exc){ 720 displayError(exc.getLocalizedMessage()); 721 return null; 722 } 723 724 returnWSDLInfo.setOutputDirectory(tmpOutputDir.getAbsolutePath()); 725 returnWSDLInfo.setPackageName("webservice"); 726 returnWSDLInfo.setRemoveGeneratedFiles(false); 727 728 if(!returnWSDLInfo.create()){ 729 732 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 733 displayError(returnWSDLInfo.getErrorMessage()); 734 return null; 735 } 736 737 webServices = returnWSDLInfo.getWebServices(); 738 if(webServices == null){ 739 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 740 displayError(NbBundle.getMessage(AddWebServiceDlg.class, "WSDL_PARSE_ERROR")); 741 return null; 742 } 743 744 addButton.setEnabled(true); 745 748 getInfoButton.requestFocus(); 749 this.getRootPane().setDefaultButton(getInfoButton); 750 751 752 infoWriter = new StringWriter(); 753 infoWriter.write(NbBundle.getMessage(AddWebServiceDlg.class, "FINISHED_PARSING_MSG")); 754 755 displayMessage(infoWriter.toString()); 756 757 return returnWSDLInfo; 758 } 759 760 private void displayWSDLInfo(Set inWebServices) { 761 Iterator serviceIterator = inWebServices.iterator(); 762 WebServiceData webServiceData = null; 763 String displayInfo = ""; 764 while(serviceIterator.hasNext()) { 765 Object wsObj = serviceIterator.next(); 766 if(null != wsObj && wsObj instanceof WebServiceData && null != currentWSDLInfo) { 767 webServiceData = (WebServiceData) wsObj; 768 String serviceInfo = currentWSDLInfo.getServiceInfo(webServiceData.getName()); 769 String changedServiceInfo = setDisplayName(webServiceData,serviceInfo); 770 displayInfo += changedServiceInfo; 771 } 772 } 773 if(!displayInfo.equals("")) { 774 displayInfo(displayInfo); 775 } 776 777 } 778 785 private String setDisplayName(WebServiceData inWSData, String inHTMLString) { 786 787 WebServiceListModel wsListModel = WebServiceListModel.getInstance(); 788 String currentDisplayName = inWSData.getName(); 789 String newDisplayName = currentDisplayName; 790 793 for(int ii = 1;wsListModel.webServiceExists(inWSData);ii++) { 794 newDisplayName = currentDisplayName + Integer.toString(ii); 795 inWSData.setDisplayName(newDisplayName); 796 } 797 int tokenLocation = inHTMLString.indexOf(WSDLInfo.SERVICE_DISPLAYNAME_TOKEN); 798 799 String firstPart = ""; 800 String lastPart = ""; 801 if(-1 != tokenLocation) { 802 firstPart = inHTMLString.substring(0,tokenLocation ); 803 lastPart = inHTMLString.substring(tokenLocation + WSDLInfo.SERVICE_DISPLAYNAME_TOKEN.length()); 804 } 805 806 return firstPart + newDisplayName + lastPart; 807 } 808 809 public void deleteDirectory(File dir){ 810 File[] children = dir.listFiles(); 811 for(int i=0; i< children.length; i++){ 812 if(children[i].isDirectory()){ 813 deleteDirectory(children[i]); 814 }else{ 815 children[i].delete(); 816 } 817 } 818 dir.delete(); 819 } 820 821 private void displayInfo(final String info){ 822 823 String htmlStart = "<HTML><HEAD>" + 824 "<style type=\"text/css\">" + 825 "body { font-family: Verdana, sans-serif; font-size: 11; }" + 827 "</style>" + 828 "</HEAD>" + 829 "<BODY>"; 830 String htmlEnd = "</BODY></HTML>"; 831 832 infoTextArea.setText(htmlStart + info + htmlEnd); 833 834 } 835 836 837 private void displayError(String inError) { 838 displayMessage("<FONT COLOR=\"RED\">" + inError + "</FONT>"); 839 } 840 841 private void displayMessage(String message){ 842 this.displayMessage(message,true); 843 } 844 845 private void displayMessage(String message,boolean useTimeStamp){ 846 849 850 String dateStamp = dateFormat.format(new Date ()); 851 852 String htmlStart = "<HTML><HEAD>" + 853 "<style type=\"text/css\">" + 854 "body { font-family: Verdana, sans-serif; font-size: 12; }" + 855 "</style>" + 856 "</HEAD>" + 857 "<BODY>"; 858 String htmlEnd = "</BODY></HTML>"; 859 860 863 864 if(!previousWSDL.equals(getCurrentWSDL())) { 865 868 if(!previousWSDL.equals("")) { 869 currentMessages += "<BR><FONT COLOR=\"BLUE\">" + NbBundle.getMessage(AddWebServiceDlg.class, "MESSAGE_END") + 870 " " + previousWSDL + "</FONT>"; 871 } 872 currentMessages += "<BR><FONT COLOR=\"BLUE\">" + NbBundle.getMessage(AddWebServiceDlg.class, "MESSAGE_START") + 873 " " + getCurrentWSDL() + "</FONT>"; 874 previousWSDL = getCurrentWSDL(); 875 } 876 877 878 if(useTimeStamp) { 879 currentMessages += "<BR><B><I>" + dateStamp + ": </I></B>" + message; 880 } else { 881 currentMessages += "<BR>" + message; 882 } 883 884 messageTextArea.setText(htmlStart + currentMessages + htmlEnd); 885 } 886 887 private void setWebServicesToProcess(Set inWebServices) { 888 this.webServicesToProcess = inWebServices; 889 } 890 891 private Set getWebServicesToProcess() { 892 return this.webServicesToProcess; 893 } 894 895 898 private void addButtonAction(ActionEvent evt) { 899 900 901 SwingUtilities.invokeLater(new Runnable (){ 902 public void run(){ 903 Cursor normalCursor = dialog.getCursor(); 904 dialog.setCursor(new Cursor (Cursor.WAIT_CURSOR)); 905 addWebServices(); 906 dialog.setCursor(normalCursor); 907 } 908 }); 909 910 911 } 912 913 private void addWebServices() { 914 915 Set webServices = getWebServicesToProcess(); 916 if(webServices == null) return; 917 Iterator iter = webServices.iterator(); 918 boolean duplicateFound = false; 919 WebServiceListModel wsListModel = WebServiceListModel.getInstance(); 920 924 HashSet addFailedWebServices = new HashSet (); 925 addFailedWebServices.addAll(webServices); 926 927 while(iter.hasNext()){ 928 929 WebServiceData wsData = (WebServiceData) iter.next(); 930 933 findValuesInHTML(wsData); 934 935 938 939 if(null == wsData.getDisplayName() || wsData.getDisplayName().equals(" ") || 940 wsData.getDisplayName().length() == 0) { 941 displayError(wsData.getName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_BLANK_WS_DISPLAYNAME")); 942 } else if(!Util.isValidIdentifier(wsData.getDisplayName())) { 943 displayError(wsData.getDisplayName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_INVALID_DISPLAYNAME")); 944 }else if(null == wsData.getPackageName() || wsData.getPackageName().length() == 0) { 945 displayError(wsData.getDisplayName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_BLANK_WS_PACKAGENAME")); 946 } else if(!Util.isValidPackageName(wsData.getPackageName())) { 947 displayError(wsData.getPackageName() + ":" + NbBundle.getMessage(this.getClass(), "ERROR_INVALID_PACKAGENAME")); 948 949 } else 950 951 952 955 if(!wsListModel.webServiceExists(wsData)){ 956 959 String jarFileName = System.getProperty("netbeans.user") +"/websvc/" + "webservice" + new Date ().getTime() + ".jar"; 960 961 if(!compileWebService(wsData, jarFileName)) { 962 966 addButton.setEnabled(false); 967 return; 968 } 969 970 973 wsListModel.addWebService(wsData); 976 977 if(invokingNode != null) { 978 WebServiceGroupCookie groupCookie = (WebServiceGroupCookie) invokingNode.getCookie(WebServiceGroupCookie.class); 979 if(groupCookie != null) { 980 groupCookie.getWebServiceGroup().add(wsData.getId()); 981 wsData.setGroupId(groupCookie.getWebServiceGroup().getId()); 982 } else { 983 986 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Add Web Service to Registry :: Invoking node w/ no GroupCookie :: class " + invokingNode.getClass()); 990 WebServiceGroup wsGroup = wsListModel.getWebServiceGroup("default"); 991 wsGroup.add(wsData.getId()); 992 wsData.setGroupId(wsGroup.getId()); 993 } 994 } else { 995 WebServiceGroup wsGroup = wsListModel.getWebServiceGroup("default"); 997 if(wsGroup == null) wsGroup = new WebServiceGroup("default"); 998 wsListModel.addWebServiceGroup(wsGroup); 999 wsGroup.add(wsData.getId()); 1000 wsData.setGroupId(wsGroup.getId()); 1001 } 1002 1003 this.displayMessage(wsData.getDisplayName() + " " + NbBundle.getMessage(this.getClass(), "WS_SUCCESSFULLY_ADDED")); 1004 1005 addFailedWebServices.remove(wsData); 1008 1009 } else{ 1010 String msg = wsData.getDisplayName() + " " + NbBundle.getMessage(AddWebServiceDlg.class, "WS_ALREADY_EXIST_MSG"); 1011 NotifyDescriptor d = new Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); 1012 DialogDisplayer.getDefault().notify(d); 1013 } 1014 } 1015 1016 1019 if(addFailedWebServices.size() > 0) { 1020 displayWSDLInfo(addFailedWebServices); 1021 this.setWebServicesToProcess(addFailedWebServices); 1022 1023 } else { 1024 closeDialog(); 1025 } 1026 1027 } 1028 1029 1030 1031 private boolean compileWebService(WebServiceData inWSData, String inJarFileName) { 1032 1036 PipedOutputStream pos = null; 1037 BufferedInputStream in = null; 1038 try { 1039 pos = new PipedOutputStream(); 1040 in = new BufferedInputStream(new PipedInputStream(pos)); 1041 1042 1046 PipedReaderTask readerTask = new PipedReaderTask(in,this.messageTextArea); 1047 this.displayMessage(NbBundle.getMessage(this.getClass(), "WSCOMPILE_START")); 1048 Thread pipeThread = new Thread (readerTask); 1049 pipeThread.start(); 1050 1051 if (!Util.createWSJar(inWSData,pos,inJarFileName)) { 1052 ErrorManager.getDefault().log(this.getClass().getName() + ": " + NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR")); 1053 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 1054 displayError(NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR")); 1055 return false; 1056 } 1057 inWSData.setProxyJarFileName(inJarFileName); 1058 this.displayMessage(NbBundle.getMessage(this.getClass(), "WSCOMPILE_END")); 1059 } catch (IOException ioe) { 1060 ErrorManager.getDefault().notify(ioe); 1061 displayInfo("<FONT COLOR=\"RED\">" + NbBundle.getMessage(AddWebServiceDlg.class, "PROCESSING_ERROR") + "</FONT>"); 1062 this.displayError(NbBundle.getMessage(this.getClass(), "PROXY_GEN_ERROR")); 1063 return false; 1064 } finally { 1065 if (pos != null) { 1066 try { 1067 pos.close(); 1068 } catch (IOException ioe) { 1069 } 1071 } 1072 } 1073 1074 return true; 1075 } 1076 1077 private void findValuesInHTML(WebServiceData inWSData) { 1078 document = (HTMLDocument )infoTextArea.getDocument(); 1079 Element rootElement = document.getDefaultRootElement(); 1080 Element formElement = null; 1081 Element inputElement = null; 1082 1085 formElement=document.getElement(rootElement,Attribute.NAME,"service_form." + inWSData.getName()); 1086 1089 inputElement = document.getElement(formElement,Attribute.NAME, "service_name." + inWSData.getName()); 1090 if(null != inputElement) { 1091 1092 1097 1098 int offset=inputElement.getStartOffset(); 1099 View view=infoTextArea.getUI().getRootView(infoTextArea); 1100 Component currentComponent=null; 1101 while (view.getViewCount()>0) { 1102 if (view instanceof ComponentView ) { 1103 ComponentView cv=(ComponentView )view; 1104 currentComponent=cv.getComponent(); 1105 break; 1106 } 1107 int index=view.getViewIndex(offset,Bias.Forward); 1108 view=view.getView(index); 1109 } 1110 1111 if (view instanceof ComponentView ) { 1112 ComponentView cv=(ComponentView )view; 1113 currentComponent=cv.getComponent(); 1114 } 1115 1116 if (currentComponent instanceof JTextField) { 1117 JTextField tf=(JTextField)currentComponent; 1118 inWSData.setDisplayName(tf.getText()); 1119 } 1120 1121 1122 } 1123 1126 inputElement = document.getElement(formElement,Attribute.NAME, "package_name." + inWSData.getName()); 1127 if(null != inputElement) { 1128 1129 1134 1135 int offset=inputElement.getStartOffset(); 1136 View view=infoTextArea.getUI().getRootView(infoTextArea); 1137 Component currentComponent=null; 1138 while (view.getViewCount()>0) { 1139 if (view instanceof ComponentView ) { 1140 ComponentView cv=(ComponentView )view; 1141 currentComponent=cv.getComponent(); 1142 break; 1143 } 1144 int index=view.getViewIndex(offset,Bias.Forward); 1145 view=view.getView(index); 1146 } 1147 1148 if (view instanceof ComponentView ) { 1149 ComponentView cv=(ComponentView )view; 1150 currentComponent=cv.getComponent(); 1151 } 1152 1153 if (currentComponent instanceof JTextField) { 1154 JTextField tf=(JTextField)currentComponent; 1155 inWSData.setPackageName(tf.getText()); 1156 } 1157 1158 1159 } 1160 1161 1162 } 1163 1164 private void setDefaults() { 1165 addButton.setEnabled(false); 1166 urlRadioButton.setSelected(true); 1167 localFileRadioButton.setSelected(false); 1168 urlComboBox.setSelectedIndex(0); 1169 localFileComboBox.setSelectedIndex(0); 1170 displayInfo("<BR><BR><BR><BR><B>" +NbBundle.getMessage(AddWebServiceDlg.class, "INSTRUCTIONS") + "</B>"); 1171 enableControls(); 1172 } 1173 1174 1177 public static void main(String [] args) { 1178 System.setProperty("http.proxyHost", "webcache.sfbay.sun.com"); 1179 System.setProperty("http.proxyPort", "8080"); 1180 1181 System.setProperty("netbeans.home", "D:\\rave-slim\\nbbuild\rave"); 1183 System.setProperty("netbeans.user", "D:\\rave-slim\\userdir"); 1184 AddWebServiceDlg myWSPanel = new AddWebServiceDlg(); 1185 JDialog dialog = new JDialog(); 1186 dialog.addWindowListener(new WindowAdapter (){ 1187 public void windowClosing(WindowEvent e){ 1188 System.out.println("Saving ..."); 1189 } 1191 }); 1192 dialog.getContentPane().add(myWSPanel); 1193 dialog.pack(); 1194 dialog.show(); 1195 } 1196 1197 public void actionPerformed(ActionEvent evt) { 1198 String actionCommand = evt.getActionCommand(); 1199 if(actionCommand.equalsIgnoreCase(addString)) { 1200 addButtonAction(evt); 1201 } else if(actionCommand.equalsIgnoreCase(cancelString)) { 1202 cancelButtonAction(evt); 1203 } else if(actionCommand.equalsIgnoreCase(copyString)) { 1204 copyMenuItemAction(evt); 1205 } else if(actionCommand.equalsIgnoreCase(clearString)) { 1206 clearMenuItemAction(evt); 1207 } 1208 1209 } 1210 1211 public void hyperlinkUpdate(HyperlinkEvent e) { 1212 if(e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { 1213 String link = e.getDescription(); 1214 1215 1216 1219 String [] parts = link.split(WSDLInfo.TOKEN_SEPARATOR); 1220 if(null == parts) { 1221 return; 1222 } 1223 String actionName = parts[0]; 1224 1225 if(actionName.equalsIgnoreCase("test")) { 1226 testMethod(link); 1227 } 1228 } 1229 } 1230 1231 1232 private void testMethod(String inHyperLink) { 1233 1234 1238 String [] parts = inHyperLink.split(WSDLInfo.TOKEN_SEPARATOR); 1239 if(null == parts) { 1240 return; 1241 } 1242 1243 String actionName = parts[0]; 1244 String serviceName = parts[1]; 1245 String portName = parts[2]; 1246 String methodName = parts[3]; 1247 1248 1253 1254 1259 String [] patternParts = inHyperLink.split("\\" + WSDLInfo.SIG_SEPARATOR); 1260 if(null == patternParts) { 1261 return; 1262 } 1263 String signaturePattern = patternParts[1]; 1264 1265 1266 1267 1268 1271 Set services =currentWSDLInfo.getWebServices(); 1272 Iterator serviceIterator = services.iterator(); 1273 JavaMethod method = null; 1274 WebServiceData wsData = null; 1275 while(serviceIterator.hasNext()) { 1276 WebServiceData currentWSData = (WebServiceData)serviceIterator.next(); 1277 if(currentWSData.getName().equals(serviceName)) { 1278 Port [] ports = currentWSData.getPorts(); 1279 for(int ii=0; null != ports && ii < ports.length; ii++) { 1280 if(ports[ii].getName().getLocalPart().equals(portName)) { 1281 Iterator operatorIterator = ports[ii].getOperations(); 1282 while(operatorIterator.hasNext()) { 1283 Operation currentOperation = (Operation)operatorIterator.next(); 1284 JavaMethod currentMethod = currentOperation.getJavaMethod(); 1285 if(currentMethod.getName().equals(methodName) && 1286 signatureEqual(currentMethod,signaturePattern)) { 1287 method = currentMethod; 1288 wsData = currentWSData; 1289 break; 1290 } 1291 } 1292 if(null != method) { 1293 break; 1294 } 1295 } 1296 } 1297 } 1298 if(null != method) { 1299 break; 1300 } 1301 } 1302 1306 if(null != wsData) { 1307 1308 if(null == wsData.getProxyJarFileName() || wsData.getProxyJarFileName().length() == 0) { 1309 1310 1313 1314 String searchWSDL = wsData.getURL(); 1315 String jarFileName = null; 1316 Object jarFileNameObject = jarCache.get(searchWSDL); 1317 if(null == jarFileNameObject) { 1318 1319 1322 File tempFile = null; 1323 try{ 1324 tempFile = File.createTempFile("wstemp",".jar"); 1325 tempFile.deleteOnExit(); 1326 }catch (IOException ioe){ 1327 ErrorManager.getDefault().notify(ioe); 1328 return; 1329 } 1330 1331 jarFileName = tempFile.getAbsolutePath(); 1332 1333 Cursor normalCursor = dialog.getCursor(); 1334 dialog.setCursor(new Cursor (Cursor.WAIT_CURSOR)); 1335 1336 boolean compiledOK = compileWebService(wsData,jarFileName); 1337 1338 dialog.setCursor(normalCursor); 1339 1340 1341 if(!compiledOK) { 1342 return; 1343 } 1344 1345 1348 jarCache.put(searchWSDL, jarFileName); 1349 1350 } else { 1351 jarFileName = (String )jarFileNameObject; 1352 } 1353 1354 1357 wsData.setProxyJarFileName(jarFileName); 1358 } 1359 1360 TestWebServiceMethodDlg dlg = new TestWebServiceMethodDlg(wsData, method, portName); 1361 dlg.displayDialog(); 1362 } 1363 1364 1365 } 1366 private boolean signatureEqual(JavaMethod inMethod,String inPattern) { 1367 1368 if(null == inMethod || null == inPattern) return false; 1369 1372 String [] parts = inPattern.split(WSDLInfo.RETURN_SEPARATOR); 1373 if(null == parts) { 1374 return false; 1375 } 1376 String returnType = parts[0]; 1377 1378 1381 if(parts.length == 1) { 1382 if(inMethod.getParameterCount() > 0) { 1383 return false; 1384 } else { 1385 return true; 1386 } 1387 } 1388 1391 if(!returnType.equals(inMethod.getReturnType().getRealName())) { 1392 return false; 1393 } 1394 1395 StringTokenizer tokenizer = new StringTokenizer (parts[1],WSDLInfo.PARAM_SEPARATOR); 1396 1402 LinkedList compareList = new LinkedList (); 1403 1404 while(tokenizer.hasMoreTokens()) { 1405 compareList.add((String )tokenizer.nextToken()); 1406 } 1407 1408 1411 Iterator paramIterator = inMethod.getParameters(); 1412 LinkedList inList = new LinkedList (); 1413 while(paramIterator.hasNext()) { 1414 inList.add((String )((JavaParameter)paramIterator.next()).getType().getRealName()); 1415 } 1416 1417 1418 if(!inList.equals(compareList)) { 1419 return false; 1420 } 1421 1422 1423 1424 return true; 1425 } 1426 1427 private class MRUPersistenceManager { 1428 File mruFile = new File(System.getProperty("netbeans.user"), WS_URL_PROPS); 1429 1430 public void loadMRU() { 1431 XMLDecoder decoder = null; 1432 urlComboBox.addItem(URL_WSDL_MSG); 1433 localFileComboBox.addItem(LOCAL_WSDL_MSG); 1434 try { 1435 decoder = new XMLDecoder (new BufferedInputStream(new FileInputStream(mruFile))); 1436 if (mruFile.exists()) { 1437 int wsDataNums = ((Integer )decoder.readObject()).intValue(); 1438 for(int i=0; i< wsDataNums; i++){ 1439 String urlItem = (String )decoder.readObject(); 1440 if(!urlItem.equals(URL_WSDL_MSG))urlComboBox.addItem( urlItem); 1441 1442 } 1443 1444 wsDataNums = ((Integer )decoder.readObject()).intValue(); 1445 for(int i=0; i< wsDataNums; i++){ 1446 String lfItem = (String ) decoder.readObject(); 1447 if(!lfItem.equals(LOCAL_WSDL_MSG))localFileComboBox.addItem(lfItem); 1448 } 1449 decoder.close(); 1450 } 1451 } catch (Exception e) { 1452 if(decoder != null) decoder.close(); 1454 } 1455 } 1456 1457 public void saveMRU() { 1458 if (mruFile.exists()) mruFile.delete(); 1459 XMLEncoder encoder = null; 1460 try { 1461 encoder = new XMLEncoder (new BufferedOutputStream(new FileOutputStream(mruFile))); 1462 int itemCount = urlComboBox.getItemCount(); 1463 encoder.writeObject(new Integer (itemCount)); 1464 for(int i=0; i< itemCount; i++){ 1465 String urlItem = ((String ) urlComboBox.getItemAt(i)).trim(); 1466 encoder.writeObject(urlItem); 1467 } 1468 itemCount = localFileComboBox.getItemCount(); 1469 encoder.writeObject(new Integer (itemCount)); 1470 for(int i=0; i< itemCount; i++){ 1471 String lfItem = (String ) localFileComboBox.getItemAt(i); 1472 encoder.writeObject(lfItem); 1473 } 1474 encoder.close(); 1475 1476 } catch (Exception e) { 1477 e.printStackTrace(); 1478 if(encoder != null) encoder.close(); 1479 } 1480 } 1481 } 1482 1485 class PopupListener extends MouseAdapter { 1486 public void mousePressed(MouseEvent e) { 1487 maybeShowPopup(e); 1488 } 1489 1490 public void mouseReleased(MouseEvent e) { 1491 maybeShowPopup(e); 1492 } 1493 1494 private void maybeShowPopup(MouseEvent e) { 1495 if (e.isPopupTrigger()) { 1496 resultsPopup.show(e.getComponent(), 1497 e.getX(), e.getY()); 1498 } 1499 } 1500 } 1501 1502 1503 public class PipedReaderTask implements Runnable { 1504 1505 private BufferedInputStream inputStream; 1506 1507 private String pipedOutput = ""; 1508 private JEditorPane messagePane; 1509 1510 public PipedReaderTask(BufferedInputStream inBufferedInput, JEditorPane inMessagePane) { 1511 inputStream = inBufferedInput; 1512 messagePane = inMessagePane; 1513 } 1514 1515 public void run() { 1516 1517 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 1518 try { 1519 String currentLine = null; 1520 while((currentLine =reader.readLine()) != null) { 1521 pipedOutput += currentLine; 1522 messagePane.setText(pipedOutput); 1523 } 1524 reader.close(); 1525 } catch(IOException ioe) { 1526 pipedOutput += "IOException=" + ioe; 1527 } 1528 1529 } 1530 1531 public String getPipedOutput() { 1532 return pipedOutput; 1533 } 1534 1535 1536 1537 } 1538 1539} 1540 | Popular Tags |