View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/RegistryBrowser.java,v 1.75 2003/08/30 23:09:45 farrukh_najmi Exp $ 9 * 10 * ==================================================================== 11 */ 12 13 package com.sun.xml.registry.client.browser; 14 15 import com.sun.xml.registry.ebxml.infomodel.InternationalStringImpl; 16 import java.awt.BorderLayout; 17 import java.awt.FileDialog; 18 import java.awt.GridBagConstraints; 19 import java.awt.event.ActionEvent; 20 import java.awt.event.ActionListener; 21 import java.io.File; 22 import java.io.IOException; 23 import java.net.URL; 24 import javax.swing.*; 25 import javax.xml.registry.JAXRException; 26 27 import javax.xml.registry.infomodel.AuditableEvent; 28 29 /*** 30 * The ebXML Registry Browser 31 * 32 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 33 */ 34 public class RegistryBrowser extends javax.swing.JFrame { 35 36 /*** DOCUMENT ME! */ 37 private static final org.apache.commons.logging.Log log = 38 org.apache.commons.logging.LogFactory.getLog(RegistryBrowser.class); 39 static JAXRClient client = new JAXRClient(); 40 static JAXRResourceBundle resourceBundle = 41 JAXRResourceBundle.getInstance(); 42 43 /*** Bound Properties. */ 44 public static String PROPERTY_AUTHENTICATED = "PROPERTY_AUTHENTICATED"; 45 46 /*** DOCUMENT ME! */ 47 static final String selectAnItem = 48 resourceBundle.getString("listBox.enterURL"); 49 static RegistryBrowser instance; 50 51 /*** DOCUMENT ME! */ 52 public ClassLoader classLoader; 53 54 /*** DOCUMENT ME! */ 55 java.awt.Color buttonBackground; 56 57 /*** DOCUMENT ME! */ 58 ConceptsTreeDialog conceptsTreeDialog = null; 59 60 /*** A dialog for selecting a Locale for RegistryBrowser. */ 61 LocaleSelectorDialog localeSelectorDialog = null; 62 63 /*** DOCUMENT ME! */ 64 javax.swing.JMenuBar menuBar; 65 66 /*** DOCUMENT ME! */ 67 JMenuItem newItem; 68 69 /*** DOCUMENT ME! */ 70 JMenuItem openItem; 71 72 /*** DOCUMENT ME! */ 73 JMenuItem saveItem; 74 75 /*** DOCUMENT ME! */ 76 JMenuItem saveAsItem; 77 78 /*** DOCUMENT ME! */ 79 JMenuItem exitItem; 80 81 /*** DOCUMENT ME! */ 82 JMenuItem cutItem; 83 84 /*** DOCUMENT ME! */ 85 JMenuItem copyItem; 86 87 /*** DOCUMENT ME! */ 88 JMenuItem pasteItem; 89 90 /*** DOCUMENT ME! */ 91 JMenuItem aboutItem; 92 93 // move inside constructor later 94 95 /*** DOCUMENT ME! */ 96 FileDialog saveFileDialog = new FileDialog(this); 97 98 /*** DOCUMENT ME! */ 99 FileDialog compositionDialog = new FileDialog(this); 100 101 /*** DOCUMENT ME! */ 102 JFileChooser openFileDialog = new JFileChooser(); 103 104 /*** DOCUMENT ME! */ 105 JPanel tabbedPaneParent = new JPanel(); 106 107 /*** The tabbed pane */ 108 JBTabbedPane tabbedPane=null; 109 110 /*** DOCUMENT ME! */ 111 JPanel topPanel = new JPanel(); 112 113 /*** DOCUMENT ME! */ 114 javax.swing.JComboBox registryCombo = new javax.swing.JComboBox(); 115 116 /*** TextField to show user name for currently authenticated user */ 117 JTextField currentUserText = new JTextField(); 118 119 /*** DOCUMENT ME! */ 120 JPanel toolbarPanel = new JPanel(); 121 122 /*** DOCUMENT ME! */ 123 javax.swing.JToolBar discoveryToolBar = null; 124 125 /*** DOCUMENT ME! */ 126 JPanel registryObjectsPanel = new JPanel(); 127 128 /*** 129 * Creates a new RegistryBrowser object. 130 */ 131 private RegistryBrowser() { 132 instance = this; 133 134 classLoader = getClass().getClassLoader(); //new JAXRBrowserClassLoader(getClass().getClassLoader()); 135 Thread.currentThread().setContextClassLoader(classLoader); 136 137 try { 138 classLoader.loadClass("javax.xml.messaging.Endpoint"); 139 } catch (ClassNotFoundException e) { 140 log.error("Could not find class javax.xml.messaging.Endpoint", 141 e); 142 } 143 144 menuBar = new javax.swing.JMenuBar(); 145 146 JMenu fileMenu = new JMenu(); 147 JMenu editMenu = new JMenu(); 148 JMenu helpMenu = new JMenu(); 149 javax.swing.JSeparator JSeparator1 = new javax.swing.JSeparator(); 150 151 newItem = new JMenuItem(); 152 openItem = new JMenuItem(); 153 saveItem = new JMenuItem(); 154 saveAsItem = new JMenuItem(); 155 exitItem = new JMenuItem(); 156 cutItem = new JMenuItem(); 157 copyItem = new JMenuItem(); 158 pasteItem = new JMenuItem(); 159 aboutItem = new JMenuItem(); 160 setJMenuBar(menuBar); 161 setTitle("Registry Browser"); 162 setDefaultCloseOperation(javax.swing.JFrame.DO_NOTHING_ON_CLOSE); 163 getContentPane().setLayout(new BorderLayout(0, 0)); 164 165 // Scale window to be centered using 70% of screen 166 java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 167 168 setBounds((int)(dim.getWidth() * .15), 169 (int)(dim.getHeight() * .1), 170 (int)(dim.getWidth() * .7), 171 (int)(dim.getHeight() * .75)); 172 setVisible(false); 173 saveFileDialog.setMode(FileDialog.SAVE); 174 saveFileDialog.setTitle("Save"); 175 compositionDialog.setMode(FileDialog.SAVE); 176 compositionDialog.setTitle("Save"); 177 178 java.awt.GridBagLayout gb = new java.awt.GridBagLayout(); 179 180 topPanel.setLayout(gb); 181 getContentPane().add("North", topPanel); 182 183 GridBagConstraints c = new GridBagConstraints(); 184 185 toolbarPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0)); 186 toolbarPanel.setBounds(0, 0, 488, 29); 187 188 discoveryToolBar = createDiscoveryToolBar(); 189 toolbarPanel.add(discoveryToolBar); 190 191 c.gridx = 0; 192 c.gridy = 0; 193 c.gridwidth = 1; 194 c.gridheight = 1; 195 c.weightx = 0.5; 196 c.weighty = 0.5; 197 c.fill = GridBagConstraints.HORIZONTAL; 198 c.anchor = GridBagConstraints.WEST; 199 c.insets = new java.awt.Insets(0, 0, 0, 0); 200 gb.setConstraints(toolbarPanel, c); 201 topPanel.add(toolbarPanel); 202 203 //Panel containing context info like registry location and user context 204 JPanel contextPanel = new JPanel(); 205 java.awt.GridBagLayout gb1 = new java.awt.GridBagLayout(); 206 207 contextPanel.setLayout(gb1); 208 209 javax.swing.JLabel locationLabel = 210 new javax.swing.JLabel(resourceBundle.getString("label.registryLocation")); 211 212 // locationLabel.setPreferredSize(new Dimension(80, 23)); 213 c.gridx = 0; 214 c.gridy = 0; 215 c.gridwidth = 1; 216 c.gridheight = 1; 217 c.weightx = 0.0; 218 c.weighty = 0.5; 219 c.fill = GridBagConstraints.NONE; 220 c.anchor = GridBagConstraints.WEST; 221 c.insets = new java.awt.Insets(0, 5, 0, 0); 222 gb1.setConstraints(locationLabel, c); 223 224 // contextPanel.setBackground(Color.green); 225 contextPanel.add(locationLabel); 226 227 String pathSep = System.getProperty("file.separator"); 228 229 registryCombo.addItem(selectAnItem); 230 231 com.sun.xml.registry.client.browser.conf.bindings.Configuration cfg = getConfiguration(); 232 com.sun.xml.registry.client.browser.conf.bindings.RegistryURIList urlList = cfg.getRegistryURIList(); 233 String[] urls = urlList.getRegistryURI(); 234 235 for (int i = 0; i < urls.length; i++) { 236 registryCombo.addItem(urls[i]); 237 } 238 239 registryCombo.setEditable(true); 240 registryCombo.setEnabled(true); 241 registryCombo.addActionListener(new ActionListener() { 242 public void actionPerformed(ActionEvent e) { 243 244 String url = 245 (String)registryCombo 246 .getSelectedItem(); 247 248 if (url.equals(selectAnItem)) { 249 250 return; 251 } 252 253 RegistryBrowser.setWaitCursor(); 254 connectToRegistry(url); 255 256 Thread.currentThread().setContextClassLoader(RegistryBrowser 257 .getInstance().classLoader); 258 259 conceptsTreeDialog = null; 260 ConceptsTreeDialog.clearCache(); 261 262 try { 263 tabbedPane = new JBTabbedPane(); 264 tabbedPaneParent.removeAll(); 265 tabbedPaneParent.add(tabbedPane, BorderLayout.CENTER); 266 267 getRootPane().updateUI(); 268 } 269 catch (JAXRException e1) { 270 displayError(e1); 271 } 272 273 274 RegistryBrowser.setDefaultCursor(); 275 } 276 }); 277 c.gridx = 1; 278 c.gridy = 0; 279 c.gridwidth = 1; 280 c.gridheight = 1; 281 c.weightx = 0.9; 282 c.weighty = 0.5; 283 c.fill = GridBagConstraints.HORIZONTAL; 284 c.anchor = GridBagConstraints.CENTER; 285 c.insets = new java.awt.Insets(0, 0, 5, 0); 286 gb1.setConstraints(registryCombo, c); 287 contextPanel.add(registryCombo); 288 289 JLabel currentUserLabel = new JLabel("Current User:", SwingConstants.LEFT); 290 c.gridx = 2; 291 c.gridy = 0; 292 c.gridwidth = 1; 293 c.gridheight = 1; 294 c.weightx = 0.0; 295 c.weighty = 0.0; 296 c.fill = GridBagConstraints.NONE; 297 c.anchor = GridBagConstraints.WEST; 298 c.insets = new java.awt.Insets(0, 5, 5, 0); 299 gb1.setConstraints(currentUserLabel, c); 300 //contextPanel.add(currentUserLabel); 301 302 currentUserText.addActionListener(new ActionListener() { 303 public void actionPerformed(ActionEvent evt) { 304 String text = currentUserText.getText(); 305 } 306 }); 307 308 currentUserText.setEditable(false); 309 c.gridx = 3; 310 c.gridy = 0; 311 c.gridwidth = 1; 312 c.gridheight = 1; 313 c.weightx = 0.9; 314 c.weighty = 0.5; 315 c.fill = GridBagConstraints.HORIZONTAL; 316 c.anchor = GridBagConstraints.WEST; 317 c.insets = new java.awt.Insets(0, 0, 5, 5); 318 gb1.setConstraints(currentUserText, c); 319 //contextPanel.add(currentUserText); 320 321 c.gridx = 0; 322 c.gridy = 1; 323 c.gridwidth = 1; 324 c.gridheight = 1; 325 c.weightx = 0.9; 326 c.weighty = 0.5; 327 c.fill = GridBagConstraints.HORIZONTAL; 328 c.anchor = GridBagConstraints.CENTER; 329 c.insets = new java.awt.Insets(0, 0, 0, 0); 330 gb.setConstraints(contextPanel, c); 331 topPanel.add(contextPanel, c); 332 333 tabbedPaneParent.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); 334 tabbedPaneParent.setLayout(new BorderLayout()); 335 tabbedPaneParent.setToolTipText("Select registry location"); 336 337 getContentPane().add("Center", tabbedPaneParent); 338 339 fileMenu.setText(resourceBundle.getString("menu.file")); 340 fileMenu.setActionCommand("File"); 341 fileMenu.setMnemonic((int)'F'); 342 menuBar.add(fileMenu); 343 344 saveItem.setHorizontalTextPosition(SwingConstants.RIGHT); 345 saveItem.setText(resourceBundle.getString("menu.file.save")); 346 saveItem.setActionCommand("Save"); 347 saveItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, 348 java.awt.Event.CTRL_MASK)); 349 saveItem.setMnemonic((int)'S'); 350 //fileMenu.add(saveItem); 351 352 fileMenu.add(JSeparator1); 353 exitItem.setText(resourceBundle.getString("menu.file.exit")); 354 exitItem.setActionCommand("Exit"); 355 exitItem.setMnemonic((int)'X'); 356 fileMenu.add(exitItem); 357 editMenu.setText(resourceBundle.getString("menu.edit")); 358 editMenu.setActionCommand("Edit"); 359 editMenu.setMnemonic((int)'E'); 360 //menuBar.add(editMenu); 361 cutItem.setHorizontalTextPosition(SwingConstants.RIGHT); 362 cutItem.setText(resourceBundle.getString("menu.edit.cut")); 363 cutItem.setActionCommand("Cut"); 364 cutItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, 365 java.awt.Event.CTRL_MASK)); 366 cutItem.setMnemonic((int)'T'); 367 editMenu.add(cutItem); 368 copyItem.setHorizontalTextPosition(SwingConstants.RIGHT); 369 copyItem.setText(resourceBundle.getString("menu.edit.copy")); 370 copyItem.setActionCommand("Copy"); 371 copyItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, 372 java.awt.Event.CTRL_MASK)); 373 copyItem.setMnemonic((int)'C'); 374 editMenu.add(copyItem); 375 pasteItem.setHorizontalTextPosition(SwingConstants.RIGHT); 376 pasteItem.setText(resourceBundle.getString("menu.edit.paste")); 377 pasteItem.setActionCommand("Paste"); 378 pasteItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, 379 java.awt.Event.CTRL_MASK)); 380 pasteItem.setMnemonic((int)'P'); 381 editMenu.add(pasteItem); 382 helpMenu.setText(resourceBundle.getString("menu.help")); 383 helpMenu.setActionCommand("Help"); 384 helpMenu.setMnemonic((int)'H'); 385 menuBar.add(helpMenu); 386 aboutItem.setHorizontalTextPosition(SwingConstants.RIGHT); 387 aboutItem.setText(resourceBundle.getString("menu.help.about")); 388 aboutItem.setActionCommand("About..."); 389 aboutItem.setMnemonic((int)'A'); 390 391 aboutItem.addActionListener(new ActionListener() { 392 public void actionPerformed(ActionEvent e) { 393 JOptionPane.showMessageDialog(RegistryBrowser.this, 394 "ebxmlrr Registry Browser version: 2.1final1", 395 "About ebXML Registry Browser", 396 JOptionPane.INFORMATION_MESSAGE); 397 } 398 }); 399 400 helpMenu.add(aboutItem); 401 402 // REGISTER_LISTENERS 403 SymWindow aSymWindow = new SymWindow(); 404 405 this.addWindowListener(aSymWindow); 406 407 SymAction lSymAction = new SymAction(); 408 409 saveItem.addActionListener(lSymAction); 410 exitItem.addActionListener(lSymAction); 411 412 javax.swing.SwingUtilities.updateComponentTreeUI(getContentPane()); 413 javax.swing.SwingUtilities.updateComponentTreeUI(menuBar); 414 javax.swing.SwingUtilities.updateComponentTreeUI(openFileDialog); 415 416 //Auto select the registry that is configured to connect to by default 417 String selectedIndexStr = com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance(). 418 getProperty("jaxr-ebxml.registryBrowser.registryLocationCombo.initialSelectionIndex", "0"); 419 int index = Integer.parseInt(selectedIndexStr); 420 try { 421 registryCombo.setSelectedIndex(index); 422 } 423 catch (IllegalArgumentException e) { 424 displayError("Invalid property value '" + index + "' for jaxr-ebxml.registryBrowser.registryLocationCombo.initialSelectionIndex. Check jaxr-ebxml.properties file.", e ); 425 } 426 427 } 428 429 //UserRegistrationWizardAction userRegAction = new UserRegistrationWizardAction(); 430 public static RegistryBrowser getInstance() { 431 432 if (instance == null) { 433 instance = new RegistryBrowser(); 434 } 435 436 return instance; 437 } 438 439 /*** 440 * DOCUMENT ME! 441 * 442 * @return DOCUMENT ME! 443 */ 444 public JAXRClient getClient() { 445 446 return client; 447 } 448 449 /*** 450 * Action for the Find tool. 451 */ 452 public void findAction() { 453 tabbedPane.findAction(); 454 } 455 456 /*** 457 * DOCUMENT ME! 458 * 459 * @return DOCUMENT ME! 460 */ 461 public javax.swing.JToolBar createDiscoveryToolBar() { 462 463 javax.swing.JToolBar toolBar = new javax.swing.JToolBar(); 464 toolBar.setFloatable(true); 465 466 // Find 467 URL findUrl = 468 getClass().getClassLoader().getResource("icons/find.gif"); 469 ImageIcon findIcon = new ImageIcon(findUrl); 470 JButton findButton = 471 toolBar.add(new AbstractAction("", findIcon) { 472 public void actionPerformed(ActionEvent e) { 473 findAction(); 474 } 475 }); 476 477 findButton.setToolTipText("Search"); 478 479 // showSchemes 480 URL showSchemesUrl = 481 getClass().getClassLoader().getResource("icons/schemeViewer.gif"); 482 ImageIcon showSchemesIcon = new ImageIcon(showSchemesUrl); 483 JButton showSchemesButton = 484 toolBar.add(new AbstractAction("", showSchemesIcon) { 485 public void actionPerformed(ActionEvent e) { 486 487 if (RegistryBrowser.client.connection == null) { 488 RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); 489 } else { 490 ConceptsTreeDialog.showSchemes(RegistryBrowser.getInstance(), 491 false, isAuthenticated()); 492 } 493 } 494 }); 495 496 showSchemesButton.setToolTipText("Show ClassificationScheme/Concept Dialog"); 497 498 // Re-authenticate 499 URL authenticateUrl = 500 getClass().getClassLoader().getResource("icons/authenticate.gif"); 501 ImageIcon authenticateIcon = new ImageIcon(authenticateUrl); 502 JButton authenticateButton = 503 toolBar.add(new AbstractAction("", authenticateIcon) { 504 public void actionPerformed(ActionEvent e) { 505 authenticate(); 506 } 507 }); 508 509 authenticateButton.setToolTipText("Log on"); 510 511 // Logout 512 URL logoutUrl = 513 getClass().getClassLoader().getResource("icons/logoff.gif"); 514 ImageIcon logoutIcon = new ImageIcon(logoutUrl); 515 JButton logoutButton = 516 toolBar.add(new AbstractAction("", logoutIcon) { 517 public void actionPerformed(ActionEvent e) { 518 logout(); 519 } 520 }); 521 522 logoutButton.setToolTipText("Log off"); 523 524 525 // user registration 526 URL userRegUrl = 527 getClass().getClassLoader().getResource("icons/userReg.gif"); 528 ImageIcon userRegIcon = new ImageIcon(userRegUrl); 529 JButton userRegButton = 530 toolBar.add(new AbstractAction("", userRegIcon) { 531 public void actionPerformed(ActionEvent e) { 532 RegistryBrowser.setWaitCursor(); 533 534 //showUserRegistrationWizard(); 535 if (RegistryBrowser.client.connection == null) { 536 RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); 537 } else { 538 539 com.sun.xml.registry.client.browser.registration.UserManager userMgr = com.sun.xml.registry.client.browser.registration.UserManager.getInstance(); 540 541 try { 542 userMgr.registerNewUser(); 543 } catch (Exception er) { 544 RegistryBrowser.displayError(er); 545 } 546 } 547 548 RegistryBrowser.setDefaultCursor(); 549 } 550 }); 551 552 userRegButton.setToolTipText("Show User Registration Wizard"); 553 554 // locale selection 555 URL localeSelUrl = 556 getClass().getClassLoader().getResource("icons/localeSel.gif"); 557 ImageIcon localeSelIcon = new ImageIcon(localeSelUrl); 558 JButton localeSelButton = 559 toolBar.add(new AbstractAction("", localeSelIcon) { 560 public void actionPerformed(ActionEvent e) { 561 RegistryBrowser.setWaitCursor(); 562 563 // Show LocaleSelectorDialog 564 if (RegistryBrowser.client.connection == null) { 565 RegistryBrowser.displayError("Connect to a registry by specifying Registry Location first."); 566 } else { 567 LocaleSelectorDialog dialog = getLocaleSelectorDialog(); 568 dialog.setVisible(true); 569 } 570 571 RegistryBrowser.setDefaultCursor(); 572 } 573 }); 574 localeSelButton.setToolTipText("Show Locale Selection Dialog"); 575 576 return toolBar; 577 } 578 579 /*** 580 * Getter for property localeSelectorDialog. Instantiates a new 581 * LocaleSelectorDialog with Locale.getDefault() if property is null. 582 * 583 * @return value of property localeSelectorDialog. 584 */ 585 public LocaleSelectorDialog getLocaleSelectorDialog() { 586 if (localeSelectorDialog == null) { 587 RegistryBrowser.setWaitCursor(); 588 localeSelectorDialog = new LocaleSelectorDialog(java.util.Locale.getDefault(), 589 RegistryBrowser.getInstance(), true); 590 RegistryBrowser.setDefaultCursor(); 591 } 592 return localeSelectorDialog; 593 } 594 595 /*** 596 * Getter for RegistryBrowser's current Locale. Intended to be used when 597 * displaying InternationalString values. 598 * 599 * @return The currently selected Locale. 600 */ 601 public java.util.Locale getSelectedLocale() { 602 return getLocaleSelectorDialog().getSelectedLocale(); 603 } 604 605 /*** 606 * Determine whether the user has already authenticated and setCredentials 607 * on the Connection or not. 608 * Add to JAXR 2.0?? 609 * 610 * @param handler DOCUMENT ME! 611 */ 612 public boolean isAuthenticated() { 613 boolean authenticated = false; 614 615 if (RegistryBrowser.client.connection == null) { 616 RegistryBrowser.displayError(resourceBundle.getString("message.error.noConnection")); 617 } else { 618 619 try { 620 com.sun.xml.registry.ebxml.ConnectionImpl connection = 621 (com.sun.xml.registry.ebxml.ConnectionImpl)(RegistryBrowser.client.connection); 622 authenticated = connection.isAuthenticated(); 623 } catch (JAXRException e) { 624 displayError(e); 625 } 626 } 627 628 return authenticated; 629 } 630 631 /*** 632 * Forces authentication to occur. 633 * 634 */ 635 public void authenticate() { 636 RegistryBrowser.setWaitCursor(); 637 638 if (RegistryBrowser.client.connection == null) { 639 RegistryBrowser.displayError(resourceBundle.getString("message.error.noConnection")); 640 } else { 641 642 try { 643 com.sun.xml.registry.ebxml.ConnectionImpl connection = 644 (com.sun.xml.registry.ebxml.ConnectionImpl)(RegistryBrowser.client.connection); 645 boolean oldValue = connection.isAuthenticated(); 646 647 connection.authenticate(); 648 649 boolean newValue = connection.isAuthenticated(); 650 651 //Notify listeners of this bound property that it has changed. 652 firePropertyChange(PROPERTY_AUTHENTICATED, oldValue, newValue); 653 654 } catch (JAXRException e) { 655 displayError(e); 656 } 657 } 658 659 RegistryBrowser.setDefaultCursor(); 660 } 661 662 /*** 663 * Handles logout action from toolbar and logs current user out. 664 */ 665 public void logout() { 666 RegistryBrowser.setWaitCursor(); 667 668 if (RegistryBrowser.client.connection == null) { 669 RegistryBrowser.displayError(resourceBundle.getString("message.error.noConnection")); 670 } else { 671 672 try { 673 com.sun.xml.registry.ebxml.ConnectionImpl connection = 674 (com.sun.xml.registry.ebxml.ConnectionImpl)(RegistryBrowser.client.connection); 675 boolean oldValue = connection.isAuthenticated(); 676 677 connection.logoff(); 678 679 boolean newValue = connection.isAuthenticated(); 680 681 //Notify listeners of this bound property that it has changed. 682 firePropertyChange(PROPERTY_AUTHENTICATED, oldValue, newValue); 683 684 } catch (JAXRException e) { 685 displayError(e); 686 } 687 } 688 689 RegistryBrowser.setDefaultCursor(); 690 } 691 692 /*** 693 * DOCUMENT ME! 694 */ 695 void showUserRegistrationWizard() { 696 RegistryBrowser.setWaitCursor(); 697 698 if (RegistryBrowser.client.connection == null) { 699 RegistryBrowser.displayError(resourceBundle.getString("message.error.noConnection")); 700 } else { 701 702 //userRegAction.performAction(); 703 } 704 705 RegistryBrowser.setDefaultCursor(); 706 } 707 708 /*** 709 * DOCUMENT ME! 710 * 711 * @param url DOCUMENT ME! 712 */ 713 public void connectToRegistry(String url) { 714 client.createConnection(url); 715 } 716 717 /*** 718 * Helper method to let browser subcomponents set a wait cursor 719 * while performing long operations. 720 */ 721 public static void setWaitCursor() { 722 instance.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); 723 } 724 725 /*** 726 * Helper method for browser subcomponents to set the cursor back 727 * to its default version. 728 */ 729 public static void setDefaultCursor() { 730 instance.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); 731 } 732 733 /*** 734 * DOCUMENT ME! 735 * 736 * @param message DOCUMENT ME! 737 */ 738 public static void displayInfo(String message) { 739 log.info(message); 740 JOptionPane.showMessageDialog(RegistryBrowser.getInstance(), 741 message, "Information", 742 JOptionPane.INFORMATION_MESSAGE); 743 } 744 745 /*** 746 * Display an error message. 747 * 748 * @param message the message to display 749 */ 750 public static void displayError(String message) { 751 log.error(message); 752 JOptionPane.showMessageDialog(RegistryBrowser.getInstance(), 753 message, "Error", 754 JOptionPane.ERROR_MESSAGE); 755 } 756 757 /*** 758 * Method Declaration. 759 * 760 * @param message 761 * @param t 762 * 763 * @see 764 */ 765 public static void displayError(String message, Throwable t) { 766 log.error(message, t); 767 768 String msg = t.getMessage(); 769 770 if (msg.length() > 200) { 771 msg = msg.substring(0, 200); 772 msg += "....See stderr for full message."; 773 } 774 775 displayError((message + "\n" + msg)); 776 } 777 778 /*** 779 * Method Declaration. 780 * 781 * @param t 782 * 783 * @see 784 */ 785 public static void displayError(Throwable t) { 786 log.error(t); 787 788 String msg = t.getMessage(); 789 790 if ((msg != null) && (msg.length() > 200)) { 791 msg = msg.substring(0, 200); 792 msg += "....See stderr for full message."; 793 } 794 795 displayError(msg); 796 } 797 798 /*** 799 * The entry point for this application. Sets the Look and Feel to 800 * the System Look and Feel. Creates a new RegistryBrowser and 801 * makes it visible. 802 * 803 * @param args DOCUMENT ME! 804 */ 805 public static void main(String[] args) { 806 807 try { 808 809 // Create a new instance of our application's frame, and make it visible. 810 RegistryBrowser browser = getInstance(); 811 812 browser.pack(); 813 814 java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 815 browser.setBounds(0, 0, (int)(dim.getWidth()), 816 (int)(dim.getHeight())); 817 818 browser.setVisible(true); 819 } catch (Throwable t) { 820 log.fatal(t); 821 t.printStackTrace(); 822 823 // Ensure the application exits with an error condition. 824 System.exit(1); 825 } 826 } 827 828 /*** 829 * Method Declaration. 830 * 831 * @param doConfirm 832 * @param exitStatus 833 */ 834 void exitApplication(boolean doConfirm, int exitStatus) { 835 836 boolean doExit = true; 837 838 if (doConfirm) { 839 840 try { 841 842 // Show a confirmation dialog 843 int reply = 844 JOptionPane.showConfirmDialog(this, 845 resourceBundle 846 .getString("message.confirmExit"), 847 "Registry Browser", 848 JOptionPane.YES_NO_OPTION, 849 JOptionPane.QUESTION_MESSAGE); 850 851 // If the confirmation was affirmative, handle exiting. 852 if (reply == JOptionPane.YES_OPTION) { 853 this.setVisible(false); // hide the Frame 854 this.dispose(); // free the system resources 855 exitStatus = 0; 856 } else { 857 doExit = false; 858 } 859 } catch (Exception e) { 860 } 861 } 862 863 if (doExit) { 864 System.exit(exitStatus); 865 } 866 } 867 868 /*** 869 * Method Declaration. 870 * 871 * @param event 872 * 873 * @see 874 */ 875 void RegistryBrowser_windowClosing(java.awt.event.WindowEvent event) { 876 877 // to do: code goes here. 878 RegistryBrowser_windowClosing_Interaction1(event); 879 } 880 881 /*** 882 * Method Declaration. 883 * 884 * @param event 885 * 886 * @see 887 */ 888 void RegistryBrowser_windowClosing_Interaction1(java.awt.event.WindowEvent event) { 889 890 try { 891 this.exitApplication(true, 0); 892 } catch (Exception e) { 893 } 894 } 895 896 /*** 897 * Method Declaration. 898 * 899 * @param event 900 * 901 * @see 902 */ 903 void saveItem_actionPerformed(ActionEvent event) { 904 905 // to do: code goes here. 906 if (RegistryBrowser.client.connection != null) { 907 908 try { 909 ((com.sun.xml.registry.ebxml.BusinessLifeCycleManagerImpl)(RegistryBrowser.client 910 .getBusinessLifeCycleManager())).saveAllObjects(); 911 } catch (JAXRException e) { 912 displayError(e); 913 } 914 } 915 } 916 917 /*** 918 * Method Declaration. 919 * 920 * @param event 921 * 922 * @see 923 */ 924 void exitItem_actionPerformed(ActionEvent event) { 925 926 // to do: code goes here. 927 exitItem_actionPerformed_Interaction1(event); 928 } 929 930 /*** 931 * Method Declaration. 932 * 933 * @param event 934 * 935 * @see 936 */ 937 void exitItem_actionPerformed_Interaction1(ActionEvent event) { 938 939 try { 940 this.exitApplication(true, 0); 941 } catch (Exception e) { 942 } 943 } 944 945 /*** 946 * Method Declaration. 947 * 948 * @param event 949 * 950 * @see 951 */ 952 void saveButton_actionPerformed(ActionEvent event) { 953 954 // to do: code goes here. 955 saveButton_actionPerformed_Interaction1(event); 956 } 957 958 /*** 959 * Method Declaration. 960 * 961 * @param event 962 * 963 * @see 964 */ 965 void saveButton_actionPerformed_Interaction1(ActionEvent event) { 966 967 try { 968 969 // saveFileDialog Show the FileDialog 970 saveFileDialog.setVisible(true); 971 } catch (Exception e) { 972 } 973 } 974 975 /*** 976 * A method to load the Configuration Object for RegistryBrowser 977 * from a XML file. The file should be located at 978 * "<jaxr-ebxml.home>/registry-browser-config.xml". If not, 979 * then it wil be copied there from classpath 980 * ("./conf/config.xml") in order to allow the user to customize 981 * the RegistryBrowser. 982 * 983 * @return DOCUMENT ME! 984 */ 985 public com.sun.xml.registry.client.browser.conf.bindings.Configuration getConfiguration() { 986 987 com.sun.xml.registry.client.browser.conf.bindings.Configuration cfg = null; 988 java.io.InputStream is = null; 989 File cfgFile = null; 990 boolean readCfgFromHome = true; 991 String jaxrHome = null; 992 993 jaxrHome = com.sun.xml.registry.ebxml.util.ProviderProperties.getInstance().getProperty("jaxr-ebxml.home"); 994 995 java.io.BufferedInputStream bis = null; 996 java.io.BufferedOutputStream bos = null; 997 998 try { 999 File jaxrHomeDir = new File(jaxrHome); 1000 if (! jaxrHomeDir.exists()) { 1001 jaxrHomeDir.mkdir(); 1002 } 1003 cfgFile = new File(jaxrHomeDir, "registry-browser-config.xml"); 1004 1005 if (!cfgFile.canRead()) { 1006 1007 1008 URL cfgFileUrl = 1009 getClass().getResource("conf/config.xml"); 1010 bis = new java.io.BufferedInputStream(cfgFileUrl.openStream()); 1011 bos = new java.io.BufferedOutputStream(new java.io.FileOutputStream(cfgFile)); 1012 1013 byte[] buffer = new byte[1024]; 1014 int bytesRead = 0; 1015 1016 while ((bytesRead = bis.read(buffer)) != -1) { 1017 bos.write(buffer, 0, bytesRead); 1018 } 1019 } 1020 } catch (IOException ioe) { 1021 readCfgFromHome = false; 1022 log.warn("Unable to store browser configuration in user home"); 1023 // displayError("Unable to store browser configuration in user home", 1024 // ioe); 1025 } finally { 1026 1027 if (bis != null) { 1028 1029 try { 1030 bis.close(); 1031 } catch (IOException e) { 1032 } 1033 } 1034 1035 if (bos != null) { 1036 1037 try { 1038 bos.close(); 1039 } catch (IOException e) { 1040 } 1041 } 1042 } 1043 1044 1045 // Now get the configuration 1046 try { 1047 1048 if (readCfgFromHome) { 1049 is = new java.io.FileInputStream(cfgFile); 1050 } else { 1051 1052 URL cfgFileUrl = 1053 getClass().getResource("conf/config.xml"); 1054 is = cfgFileUrl.openStream(); 1055 } 1056 1057 cfg = com.sun.xml.registry.client.browser.conf.bindings.Configuration.unmarshal(new java.io.InputStreamReader(is)); 1058 } catch (IOException e) { 1059 displayError("Unable to load browser configuration", e); 1060 } catch (org.exolab.castor.xml.ValidationException e) { 1061 displayError("Unable to load browser configuration", e); 1062 } catch (org.exolab.castor.xml.MarshalException e) { 1063 displayError("Unable to load browser configuration", e); 1064 } finally { 1065 1066 if (is != null) { 1067 1068 try { 1069 is.close(); 1070 } catch (IOException e) { 1071 } 1072 } 1073 } 1074 1075 return cfg; 1076 } 1077 1078 /*** 1079 * DOCUMENT ME! 1080 * 1081 * @param ro DOCUMENT ME! 1082 * 1083 * @return DOCUMENT ME! 1084 * 1085 * @throws JAXRException DOCUMENT ME! 1086 */ 1087 public static String getName(javax.xml.registry.infomodel.RegistryObject ro) throws JAXRException { 1088 try { 1089 return ((InternationalStringImpl)ro.getName()).getClosestValue(); 1090 } catch (NullPointerException npe) { 1091 return ""; 1092 } 1093 } 1094 1095 /*** 1096 * DOCUMENT ME! 1097 * 1098 * @param ro DOCUMENT ME! 1099 * 1100 * @return DOCUMENT ME! 1101 * 1102 * @throws JAXRException DOCUMENT ME! 1103 */ 1104 public static String getDescription(javax.xml.registry.infomodel.RegistryObject ro) throws JAXRException { 1105 try { 1106 return ((InternationalStringImpl)ro.getDescription()).getClosestValue(); 1107 } catch (NullPointerException npe) { 1108 return ""; 1109 } 1110 } 1111 1112 /*** 1113 * DOCUMENT ME! 1114 * 1115 * @param registryObject DOCUMENT ME! 1116 */ 1117 public static void retrieveItem(javax.xml.registry.infomodel.RegistryObject registryObject) { 1118 1119 javax.activation.DataHandler repositoryItem = null; 1120 File defaultItemFile = null; 1121 1122 try { 1123 repositoryItem = 1124 ((javax.xml.registry.infomodel.ExtrinsicObject)registryObject).getRepositoryItem(); 1125 1126 if (repositoryItem == null) { 1127 displayInfo("There is no repository item for this object"); 1128 1129 return; 1130 } else { 1131 // TO DO: find better modelling for this. Depending on current 1132 // Locale existing file migt not be found. Use Slot?? 1133 String fileName = RegistryBrowser.getName(registryObject); 1134 1135 // to use something like javax.activation.MimetypesFileTypeMap? 1136 // String fileType = tranaslateMimetypeToFiletype(((ExtrinsicObject)registryObject).getMimeType()); 1137 defaultItemFile = new File(fileName); // + "." + fileType); 1138 } 1139 } catch (JAXRException e) { 1140 displayError(e); 1141 } 1142 1143 JFileChooser saveChooser = new JFileChooser(); 1144 saveChooser.setDialogTitle("Save As..."); 1145 saveChooser.setApproveButtonText("Save"); 1146 saveChooser.setSelectedFile(defaultItemFile); 1147 1148 int returnVal = saveChooser.showDialog(null, null); 1149 1150 if (returnVal == JFileChooser.APPROVE_OPTION) { 1151 1152 try { 1153 1154 java.io.InputStream item = repositoryItem.getInputStream(); 1155 File itemFile = saveChooser.getSelectedFile(); 1156 itemFile.createNewFile(); 1157 1158 java.io.FileOutputStream itemFileOut = 1159 new java.io.FileOutputStream(itemFile); 1160 1161 int size = item.available(); 1162 byte[] buff = new byte[size]; 1163 1164 while (item.read(buff) != -1) { 1165 itemFileOut.write(buff); 1166 } 1167 1168 itemFileOut.flush(); 1169 itemFileOut.close(); 1170 } catch (IOException e) { 1171 displayError(e); 1172 } 1173 } 1174 } 1175 1176 /*** 1177 * DOCUMENT ME! 1178 * 1179 * @param registryObject DOCUMENT ME! 1180 */ 1181 public static void showAuditTrail(javax.xml.registry.infomodel.RegistryObject registryObject) { 1182 1183 AuditableEventsDialog dialog = 1184 new AuditableEventsDialog((javax.swing.JFrame)RegistryBrowser 1185 .getInstance(), false, 1186 registryObject); 1187 dialog.setVisible(true); 1188 } 1189 1190 /*** 1191 * DOCUMENT ME! 1192 * 1193 * @param user DOCUMENT ME! 1194 * @param registryLevel DOCUMENT ME! 1195 * 1196 * @return DOCUMENT ME! 1197 * 1198 * @throws JAXRException DOCUMENT ME! 1199 */ 1200 public static String getUserName(javax.xml.registry.infomodel.User user, int registryLevel) throws JAXRException { 1201 1202 String userName = ""; 1203 1204 if ((user != null) && (user.getPersonName() != null)) { 1205 1206 javax.xml.registry.infomodel.PersonName personName = user.getPersonName(); 1207 1208 if (registryLevel == 0) { 1209 userName = personName.getFullName(); 1210 } else { 1211 1212 String firstName = personName.getFirstName(); 1213 String middleName = personName.getMiddleName(); 1214 String lastName = personName.getLastName(); 1215 1216 if (firstName != null) { 1217 userName = firstName; 1218 } 1219 1220 if (middleName != null) { 1221 userName += (" " + middleName); 1222 } 1223 1224 if (lastName != null) { 1225 userName += (" " + lastName); 1226 } 1227 } 1228 } 1229 1230 return userName; 1231 } 1232 1233 // util method -> should be implemented as any other predefined enumeration and moved to proper place 1234 public static String getEventTypeAsString(int eventType) 1235 throws JAXRException { 1236 1237 if (eventType == AuditableEvent.EVENT_TYPE_CREATED) { 1238 1239 return ("Created"); 1240 } else if (eventType == AuditableEvent.EVENT_TYPE_DELETED) { 1241 1242 return ("Deleted"); 1243 } else if (eventType == AuditableEvent.EVENT_TYPE_DEPRECATED) { 1244 1245 return ("Deprecated"); 1246 } else if (eventType == AuditableEvent.EVENT_TYPE_UNDEPRECATED) { 1247 1248 return ("Undeprecated"); 1249 } else if (eventType == AuditableEvent.EVENT_TYPE_UPDATED) { 1250 1251 return ("Updated"); 1252 } else if (eventType == AuditableEvent.EVENT_TYPE_VERSIONED) { 1253 1254 return ("Versioned"); 1255 } else { 1256 1257 return ("Unknown Event Type"); 1258 } 1259 } 1260 1261 /*** 1262 * DOCUMENT ME! 1263 * 1264 * @author $author$ 1265 * @version $Revision: 1.75 $ 1266 */ 1267 class SymWindow extends java.awt.event.WindowAdapter { 1268 1269 /*** 1270 * DOCUMENT ME! 1271 * 1272 * @param event DOCUMENT ME! 1273 */ 1274 public void windowClosing(java.awt.event.WindowEvent event) { 1275 1276 Object object = event.getSource(); 1277 1278 if (object == RegistryBrowser.this) { 1279 RegistryBrowser_windowClosing(event); 1280 } 1281 } 1282 } 1283 1284 /*** 1285 * Class Declaration. 1286 * 1287 * @author 1288 * @version 1.17, 03/29/00 1289 * 1290 * @see 1291 */ 1292 class SymAction implements ActionListener { 1293 1294 /*** 1295 * Method Declaration. 1296 * 1297 * @param event 1298 * 1299 * @see 1300 */ 1301 public void actionPerformed(ActionEvent event) { 1302 1303 Object object = event.getSource(); 1304 1305 if (object == saveItem) { 1306 saveItem_actionPerformed(event); 1307 } else if (object == exitItem) { 1308 exitItem_actionPerformed(event); 1309 } 1310 } 1311 } 1312 1313 /*** 1314 * DOCUMENT ME! 1315 * 1316 * @author $author$ 1317 * @version $Revision: 1.75 $ 1318 */ 1319 class JAXRBrowserClassLoader extends ClassLoader { 1320 1321 /*** 1322 * Creates a new JAXRBrowserClassLoader object. 1323 * 1324 * @param parent DOCUMENT ME! 1325 */ 1326 JAXRBrowserClassLoader(ClassLoader parent) { 1327 log.info("JAXRBrowserClassLoader: Using parent classloader: " 1328 + parent); 1329 } 1330 1331 /*** 1332 * DOCUMENT ME! 1333 * 1334 * @param className DOCUMENT ME! 1335 * 1336 * @return DOCUMENT ME! 1337 * 1338 * @throws ClassNotFoundException DOCUMENT ME! 1339 */ 1340 protected Class findClass(String className) 1341 throws ClassNotFoundException { 1342 log.info("findClass: " + className); 1343 1344 return super.findClass(className); 1345 } 1346 1347 /*** 1348 * DOCUMENT ME! 1349 * 1350 * @param className DOCUMENT ME! 1351 * @param resolve DOCUMENT ME! 1352 * 1353 * @return DOCUMENT ME! 1354 * 1355 * @throws ClassNotFoundException DOCUMENT ME! 1356 */ 1357 protected Class loadClass(String className, boolean resolve) 1358 throws ClassNotFoundException { 1359 log.info("loadClass: " + className + " resolve = " 1360 + resolve); 1361 1362 return super.loadClass(className, resolve); 1363 } 1364 1365 /*** 1366 * DOCUMENT ME! 1367 * 1368 * @param className DOCUMENT ME! 1369 * 1370 * @return DOCUMENT ME! 1371 * 1372 * @throws ClassNotFoundException DOCUMENT ME! 1373 */ 1374 public Class loadClass(String className) 1375 throws ClassNotFoundException { 1376 log.info("loadClass: " + className); 1377 1378 Class clazz; 1379 1380 try { 1381 clazz = super.loadClass(className); 1382 } catch (ClassNotFoundException e) { 1383 log.error(e); 1384 clazz = getParent().loadClass(className); 1385 } 1386 1387 return clazz; 1388 } 1389 } 1390 }

This page was automatically generated by Maven