1 19 package org.netbeans.modules.j2ee.websphere6.ui; 20 21 import java.util.*; 22 import java.io.*; 23 import java.awt.*; 24 import java.awt.event.*; 25 import javax.swing.*; 26 import javax.swing.event.*; 27 import javax.xml.parsers.*; 28 import org.netbeans.modules.j2ee.websphere6.ui.wizard.WSInstantiatingIterator; 29 import org.w3c.dom.*; 30 import org.xml.sax.*; 31 import org.openide.*; 32 import org.openide.util.*; 33 import org.netbeans.modules.j2ee.websphere6.util.WSDebug; 34 35 39 public class ServerProperties { 40 41 private JComboBox serverTypeCombo; 42 private JComboBox localInstancesCombo; 43 private JTextField domainPathField; 44 private JTextField hostField; 45 private JTextField portField; 46 ServerTypeActionListener serverTypeActionListener=null; 47 InstanceSelectionListener instanceSelectionListener=null; 48 WSInstantiatingIterator instantiatingIterator; 49 50 51 public ServerProperties() { 52 serverTypeCombo=null; 53 localInstancesCombo=null; 54 domainPathField=null; 55 hostField=null; 56 portField=null; 57 } 58 59 public ServerProperties(JComboBox serverCombobox, 60 JComboBox localInstancesCombobox, 61 JTextField domainPathField, 62 JTextField hostField, 63 JTextField portField) { 64 65 66 this.serverTypeCombo=serverCombobox; 67 this.localInstancesCombo=localInstancesCombobox; 68 this.domainPathField=domainPathField; 69 this.hostField=hostField; 70 this.portField=portField; 71 72 } 73 public void setVariables(JComboBox serverCombobox, 74 JComboBox localInstancesCombobox, 75 JTextField domainPathField, 76 JTextField hostField, 77 JTextField portField, 78 WSInstantiatingIterator instantiatingIterator) { 79 80 81 if(this.serverTypeCombo==null) this.serverTypeCombo=serverCombobox; 82 if(this.localInstancesCombo==null) this.localInstancesCombo=localInstancesCombobox; 83 if(this.domainPathField==null) this.domainPathField=domainPathField; 84 if(this.hostField==null) this.hostField=hostField; 85 if(this.portField==null) this.portField=portField; 86 if(this.instantiatingIterator==null) this.instantiatingIterator=instantiatingIterator; 87 } 88 89 97 public static String [] getRegisteredDomains(String serverRoot) { 98 Vector result = new Vector(); 100 101 if (serverRoot == null) { 103 return new String [0]; 104 } 105 106 String domainListFile = "/properties/profileRegistry.xml"; 109 InputStream inputStream = null; 111 Document document = null; 112 113 try { 114 inputStream = new FileInputStream(new File(serverRoot + 116 domainListFile)); 117 118 document = DocumentBuilderFactory.newInstance(). 120 newDocumentBuilder().parse(inputStream); 121 122 Element root = document.getDocumentElement(); 124 125 NodeList children = root.getChildNodes(); 127 128 for (int i = 0; i < children.getLength(); i++) { 130 Node child = children.item(i); 131 if (child.getNodeName().equals("profile")) { String path = child.getAttributes(). 135 getNamedItem("path").getNodeValue(); result.add(path); 137 } 138 } 139 } catch (FileNotFoundException e) { 140 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 141 } catch (ParserConfigurationException e) { 142 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 143 } catch (SAXException e) { 144 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 145 } catch (IOException e) { 146 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 147 } finally { 148 try { 150 if (inputStream != null) { 151 inputStream.close(); 152 } 153 } catch (IOException e) { 154 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 155 } 156 } 157 158 return (String []) result.toArray(new String [result.size()]); 160 } 161 168 169 public static String getCellPort(String cellPath) { 170 String [] files = new File(cellPath + "/nodes").list(); 172 173 for (int i = 0; i < files.length; i++) { 176 String path = cellPath + "/nodes/" + files[i] + "/serverindex.xml"; 177 if (new File(path).exists()) { cellPath = path; break; 180 } 181 } 182 183 InputStream inputStream = null; 185 Document document = null; 186 187 try { 188 inputStream = new FileInputStream(new File(cellPath)); 190 191 document = DocumentBuilderFactory.newInstance(). 193 newDocumentBuilder().parse(inputStream); 194 195 Element root = document.getDocumentElement(); 197 198 NodeList children = root.getChildNodes(); 200 201 for (int i = 0; i < children.getLength(); i++) { 203 Node child = children.item(i); 204 if (child.getNodeName().equals("serverEntries")) { NodeList nl = child.getChildNodes(); 208 for (int j = 0; j < nl.getLength(); j++){ 209 Node ch = nl.item(j); 210 if (ch.getNodeName().equals( 213 "specialEndpoints") && ch. getAttributes().getNamedItem 215 ("endPointName").getNodeValue(). equals("SOAP_CONNECTOR_ADDRESS")) { NodeList nl2 = ch.getChildNodes(); 218 for (int k = 0; k < nl2.getLength(); k++) { 223 Node ch2 = nl2.item(k); 224 if (ch2.getNodeName().equals( 225 "endPoint")) { String port = ch2.getAttributes(). 227 getNamedItem("port"). getNodeValue(); 229 return port; 230 } 231 } 232 } 233 } 234 } 235 } 236 } catch (FileNotFoundException e) { 237 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 238 } catch (ParserConfigurationException e) { 239 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 240 } catch (SAXException e) { 241 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 242 } catch (IOException e) { 243 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 244 } finally { 245 try { 247 if (inputStream != null) { 248 inputStream.close(); 249 } 250 } catch (IOException e) { 251 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 252 } 253 } 254 255 return ""; 258 } 259 260 public static String getCellAdminPort(String cellPath) { 261 String [] files = new File(cellPath + "/nodes").list(); 263 264 for (int i = 0; i < files.length; i++) { 267 String path = cellPath + "/nodes/" + files[i] + "/serverindex.xml"; 268 if (new File(path).exists()) { cellPath = path; break; 271 } 272 } 273 274 InputStream inputStream = null; 276 Document document = null; 277 278 try { 279 inputStream = new FileInputStream(new File(cellPath)); 281 282 document = DocumentBuilderFactory.newInstance(). 284 newDocumentBuilder().parse(inputStream); 285 286 Element root = document.getDocumentElement(); 288 289 NodeList children = root.getChildNodes(); 291 292 for (int i = 0; i < children.getLength(); i++) { 294 Node child = children.item(i); 295 if (child.getNodeName().equals("serverEntries")) { NodeList nl = child.getChildNodes(); 299 for (int j = 0; j < nl.getLength(); j++){ 300 Node ch = nl.item(j); 301 if (ch.getNodeName().equals( 304 "specialEndpoints") && ch. getAttributes().getNamedItem 306 ("endPointName").getNodeValue(). equals("WC_adminhost")) { NodeList nl2 = ch.getChildNodes(); 309 for (int k = 0; k < nl2.getLength(); k++) { 314 Node ch2 = nl2.item(k); 315 if (ch2.getNodeName().equals( 316 "endPoint")) { String port = ch2.getAttributes(). 318 getNamedItem("port"). getNodeValue(); 320 return port; 321 } 322 } 323 } 324 } 325 } 326 } 327 } catch (FileNotFoundException e) { 328 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 329 } catch (ParserConfigurationException e) { 330 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 331 } catch (SAXException e) { 332 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 333 } catch (IOException e) { 334 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 335 } finally { 336 try { 338 if (inputStream != null) { 339 inputStream.close(); 340 } 341 } catch (IOException e) { 342 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 343 } 344 } 345 346 return ""; 349 } 350 public static String getCellDefaultHostPort(String cellPath) { 351 String [] files = new File(cellPath + "/nodes").list(); 353 354 for (int i = 0; i < files.length; i++) { 357 String path = cellPath + "/nodes/" + files[i] + "/serverindex.xml"; 358 if (new File(path).exists()) { cellPath = path; break; 361 } 362 } 363 364 InputStream inputStream = null; 366 Document document = null; 367 368 try { 369 inputStream = new FileInputStream(new File(cellPath)); 371 372 document = DocumentBuilderFactory.newInstance(). 374 newDocumentBuilder().parse(inputStream); 375 376 Element root = document.getDocumentElement(); 378 379 NodeList children = root.getChildNodes(); 381 382 for (int i = 0; i < children.getLength(); i++) { 384 Node child = children.item(i); 385 if (child.getNodeName().equals("serverEntries")) { NodeList nl = child.getChildNodes(); 389 for (int j = 0; j < nl.getLength(); j++){ 390 Node ch = nl.item(j); 391 if (ch.getNodeName().equals( 394 "specialEndpoints") && ch. getAttributes().getNamedItem 396 ("endPointName").getNodeValue(). equals("WC_defaulthost")) { NodeList nl2 = ch.getChildNodes(); 399 for (int k = 0; k < nl2.getLength(); k++) { 404 Node ch2 = nl2.item(k); 405 if (ch2.getNodeName().equals( 406 "endPoint")) { String port = ch2.getAttributes(). 408 getNamedItem("port"). getNodeValue(); 410 return port; 411 } 412 } 413 } 414 } 415 } 416 } 417 } catch (FileNotFoundException e) { 418 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 419 } catch (ParserConfigurationException e) { 420 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 421 } catch (SAXException e) { 422 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 423 } catch (IOException e) { 424 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 425 } finally { 426 try { 428 if (inputStream != null) { 429 inputStream.close(); 430 } 431 } catch (IOException e) { 432 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 433 } 434 } 435 436 return ""; 439 } 440 441 public static String getCellHttpPort(String cellPath) { 442 String [] files = new File(cellPath + "/nodes").list(); 444 445 for (int i = 0; i < files.length; i++) { 448 String path = cellPath + "/nodes/" + files[i] + "/serverindex.xml"; 449 if (new File(path).exists()) { cellPath = path; break; 452 } 453 } 454 455 InputStream inputStream = null; 457 Document document = null; 458 459 try { 460 inputStream = new FileInputStream(new File(cellPath)); 462 463 document = DocumentBuilderFactory.newInstance(). 465 newDocumentBuilder().parse(inputStream); 466 467 Element root = document.getDocumentElement(); 469 470 NodeList children = root.getChildNodes(); 472 473 for (int i = 0; i < children.getLength(); i++) { 475 Node child = children.item(i); 476 if (child.getNodeName().equals("serverEntries")) { NodeList nl = child.getChildNodes(); 480 for (int j = 0; j < nl.getLength(); j++){ 481 Node ch = nl.item(j); 482 if (ch.getNodeName().equals( 485 "specialEndpoints") && ch. getAttributes().getNamedItem 487 ("endPointName").getNodeValue(). equals("WC_defaulthost")) { NodeList nl2 = ch.getChildNodes(); 490 for (int k = 0; k < nl2.getLength(); k++) { 495 Node ch2 = nl2.item(k); 496 if (ch2.getNodeName().equals( 497 "endPoint")) { String port = ch2.getAttributes(). 499 getNamedItem("port"). getNodeValue(); 501 return port; 502 } 503 } 504 } 505 } 506 } 507 } 508 } catch (FileNotFoundException e) { 509 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 510 } catch (ParserConfigurationException e) { 511 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 512 } catch (SAXException e) { 513 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 514 } catch (IOException e) { 515 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 516 } finally { 517 try { 519 if (inputStream != null) { 520 inputStream.close(); 521 } 522 } catch (IOException e) { 523 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 524 } 525 } 526 527 return ""; 530 } 531 538 public static String getConfigXmlPath(String cellPath) { 539 String [] files = new File(cellPath + "/nodes").list(); 542 String serverName = getServerName(cellPath); 544 545 for (int i = 0; i < files.length; i++) { 548 String path = cellPath + "/nodes/" + files[i] + "/servers/" + serverName + "/server.xml"; if (new File(path).exists()) { 551 if (WSDebug.isEnabled()) 552 WSDebug.notify(path); 553 return path; 554 } 555 } 556 557 return ""; 558 } 559 560 568 public static String getServerName(String cellPath) { 569 String [] files = new File(cellPath + "/nodes").list(); 572 for (int i = 0; i < files.length; i++) { 575 String path = cellPath + "/nodes/" + files[i] + "/serverindex.xml"; if (new File(path).exists()) { 578 cellPath = path; break; 580 } 581 } 582 583 InputStream inputStream = null; 585 Document document = null; 586 587 try { 588 inputStream = new FileInputStream(new File(cellPath)); 589 document = DocumentBuilderFactory.newInstance(). 590 newDocumentBuilder().parse(inputStream); 591 592 Element root = document.getDocumentElement(); 594 595 NodeList children = root.getChildNodes(); 597 598 for (int i = 0; i < children.getLength(); i++) { 599 Node child = children.item(i); 602 603 if (child.getNodeName().equals("serverEntries")) { return child.getAttributes().getNamedItem( 607 "serverName").getNodeValue(); } 609 } 610 } catch (FileNotFoundException e) { 611 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 612 } catch (ParserConfigurationException e) { 613 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 614 } catch (SAXException e) { 615 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 616 } catch (IOException e) { 617 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 618 } finally { 619 try { 621 if (inputStream != null) { 622 inputStream.close(); 623 } 624 } catch (IOException e) { 625 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 626 } 627 } 628 629 return ""; } 632 633 634 639 640 public static Vector getServerInstances(String serverRoot){ 641 Vector result = new Vector(); 643 644 String [] domains = ServerProperties.getRegisteredDomains( 646 serverRoot); 647 648 for (int i = 0; i < domains.length; i++) { 650 File file = new File(domains[i] + "/config/cells"); 653 String [] files = file.list(new DirectoryFilter()); 655 656 for (int j = 0; j < files.length; j++){ 659 String nextCellPath = file.getAbsolutePath() + File.separator + 660 files[j]; 661 String address = "localhost"; String port = ServerProperties.getCellPort(nextCellPath); 663 String adminPort = ServerProperties.getCellAdminPort(nextCellPath); 664 String httpPort = ServerProperties.getCellAdminPort(nextCellPath); 665 String serverName = ServerProperties.getServerName(nextCellPath); 666 String configXmlPath = ServerProperties.getConfigXmlPath(nextCellPath); 667 String defaultHostPort = ServerProperties.getCellDefaultHostPort(nextCellPath); 668 result.add(new Instance(serverName, address, port, domains[i], 669 configXmlPath, adminPort,httpPort,defaultHostPort)); 670 } 671 } 672 673 return result; 675 } 676 681 public static boolean isValidDomainRoot(String path) { 682 String [] children = { 685 "config/cells", "etc/ws-security", "properties/soap.client.props", "properties/wsadmin.properties", }; 690 return ServerProperties.hasChildren(path, children); 691 } 692 693 698 public static boolean hasChildren(String parent, String [] children) { 699 if (parent == null) { 701 return false; 702 } 703 704 if (children == null) { 706 return true; 707 } 708 709 for (int i = 0; i < children.length; i++) { 712 if (!(new File(parent + File.separator + children[i]).exists())) { 713 return false; 714 } 715 } 716 717 return true; 719 } 720 721 722 723 724 725 726 732 733 private static class DirectoryFilter implements FilenameFilter { 734 740 public boolean accept(File dir, String name) { 741 if ((new File(dir.getAbsolutePath()+File.separator+name)). 743 isDirectory()) { 744 return true; 745 } 746 747 return false; 749 } 750 } 751 758 public class ServerTypeActionListener implements ActionListener { 759 763 764 public void actionPerformed(ActionEvent e) { 765 if (serverTypeCombo.getSelectedItem().equals(NbBundle. 767 getMessage(ServerProperties.class, 768 "TXT_ServerTypeLocal"))) { Instance instance = (Instance) localInstancesCombo. 770 getSelectedItem(); 771 772 localInstancesCombo.setEnabled(true); 774 775 domainPathField.setEnabled(true); 777 domainPathField.setEditable(false); 778 779 hostField.setEnabled(true); 781 hostField.setEditable(false); 782 hostField.setText(instance.getHost()); 783 784 portField.setEnabled(true); 787 portField.setEditable(false); 788 portField.setText(instance.getPort()); 790 } else { 791 localInstancesCombo.setEnabled(false); 793 794 domainPathField.setEnabled(false); 796 domainPathField.setEditable(false); 797 798 hostField.setEnabled(true); 800 hostField.setEditable(true); 801 802 portField.setEnabled(true); 804 portField.setEditable(true); 805 } 806 } 807 } 808 public ServerTypeActionListener getServerTypeActionListener() { 809 if(serverTypeActionListener==null) { 810 serverTypeActionListener=new ServerTypeActionListener(); 811 } 812 813 return serverTypeActionListener; 814 } 815 821 private Vector listeners = new Vector(); 822 823 828 public void removeChangeListener(ChangeListener listener) { 829 if (listeners != null) { 830 synchronized (listeners) { 831 listeners.remove(listener); 832 } 833 } 834 } 835 836 841 public void addChangeListener(ChangeListener listener) { 842 synchronized (listeners) { 843 listeners.add(listener); 844 } 845 } 846 847 850 private void fireChangeEvent() { 851 ChangeEvent event = new ChangeEvent(this); 852 fireChangeEvent(event); 853 } 854 855 860 private void fireChangeEvent(ChangeEvent event) { 861 Vector targetListeners; 862 synchronized (listeners) { 863 targetListeners = (Vector) listeners.clone(); 864 } 865 866 for (int i = 0; i < targetListeners.size(); i++) { 867 ChangeListener listener = 868 (ChangeListener) targetListeners.elementAt(i); 869 listener.stateChanged(event); 870 } 871 } 872 880 public class KeyListener extends KeyAdapter { 881 884 public void keyTyped(KeyEvent event) { 885 fireChangeEvent(); 886 } 887 888 891 public void keyReleased(KeyEvent event) { 892 fireChangeEvent(); 893 } 894 } 895 896 897 901 public void updateInstancesList(String serverRoot) { 902 localInstancesCombo.setModel( 903 new InstancesModel( 904 getServerInstances(serverRoot))); 905 906 updateInstanceInfo(); 907 } 908 909 913 private void updateInstanceInfo() { 914 Instance instance = (Instance) localInstancesCombo.getSelectedItem(); 916 917 domainPathField.setText(instance.getDomainPath()); 919 hostField.setText(instance.getHost()); 920 portField.setText(instance.getPort()); 922 if(instantiatingIterator!=null) { 923 instantiatingIterator.setHost(instance.getHost()); 924 instantiatingIterator.setPort(instance.getPort()); 925 instantiatingIterator.setAdminPort(instance.getAdminPort()); 926 instantiatingIterator.setConfigXmlPath(instance.getConfigXmlPath()); 927 instantiatingIterator.setDefaultHostPort(instance.getDefaultHostPort()); 928 instantiatingIterator.setDomainRoot(instance.getDomainPath()); 929 instantiatingIterator.setServerName(instance.getName()); 930 } 931 } 932 938 public class InstanceSelectionListener implements ActionListener { 939 943 public void actionPerformed(ActionEvent e) { 944 updateInstanceInfo(); 945 } 946 } 947 950 public InstanceSelectionListener getInstanceSelectionListener() { 951 if(instanceSelectionListener==null) { 952 instanceSelectionListener=new InstanceSelectionListener(); 953 } 954 return instanceSelectionListener; 955 } 956 } 957 958 | Popular Tags |