1 7 package org.enhydra.base.tool; 8 9 import javax.swing.JFrame ; 10 11 import javax.swing.JPanel ; 12 import java.awt.BorderLayout ; 13 14 import javax.swing.JButton ; 15 import java.awt.Toolkit ; 16 import java.awt.event.ActionEvent ; 17 import java.awt.event.ActionListener ; 18 import java.io.BufferedReader ; 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 import java.util.Properties ; 26 27 import javax.swing.AbstractAction ; 28 29 import javax.swing.JTabbedPane ; 30 31 37 public class WizardFrame extends JFrame { 38 39 private javax.swing.JPanel jContentPane = null; 40 41 private JPanel backPanel = null; 42 43 private JPanel buttonPanell = null; 44 45 private JButton configureButton = null; 46 47 private JButton closeButton = null; 48 49 private JPanel settingPanel = null; 50 51 private String enhydraDir = null; 52 53 private JTabbedPane tabBase = null; 54 55 private ConnectorConfigurationPanel connectorPanel = null; 56 57 private AdaptorConfigurationPanel adaptorPanel = null; 58 59 private ServerShutdownConfigurationPanel serverPanel = null; 60 61 private AuthenticationConfigurationPanel authenticationPanel = null; 62 63 private EnhydraBasePanel enhydraBasePanel = null; 64 65 private JavaConfigurationPanel javaPanel = null; 66 67 private OutputPanel outputPanel = null; 68 69 private String httpenabled = "on"; 71 72 private String sslenabled = "on"; 73 74 private String ajpenabled = "on"; 75 76 private String directorenabled = "on"; 77 78 private String httpport = "8080"; 79 80 private String sslport = "8443"; 81 82 private String ajpport = "9009"; 83 84 private String directorport = "9003"; 85 86 private String httpadaptorenabled = "on"; 87 88 private String rmiadaptorenabled = "on"; 89 90 private String httpadaptorport = "9050"; 91 92 private String rmiadaptorport = "1099"; 93 94 private String serverport = "8005"; 95 96 private String servershutdown = "SHUTDOWN"; 97 98 private String authmode = "none"; 99 100 private String username = "admin"; 101 102 private String password = "enhydra"; 103 104 private String servicename = "Enhydra"; 105 106 private String basedir = ""; 107 108 private String jdkdir = ""; 109 110 private Properties props = null; 111 112 private String basePropertyFile = "base.properties"; 113 114 private String enhydraPropertyFile = "build.properties"; 115 116 private String propertyFileName = ""; 117 118 121 public WizardFrame(String enhydraDir) { 122 super(); 123 this.enhydraDir = enhydraDir; 124 initialize(); 125 } 126 127 130 public WizardFrame() { 131 super(); 132 this.enhydraDir = null; 133 initialize(); 134 } 135 136 private void loadProperties() { 137 props = new Properties (); 138 File propertyFile = null; 139 FileInputStream propertyFileIS = null; 140 try { 141 propertyFile = new File (this.enhydraDir + File.separator 142 + basePropertyFile); 143 if (propertyFile.exists()) { 144 propertyFileIS = new FileInputStream (propertyFile); 145 props.load(propertyFileIS); 146 propertyFileName = basePropertyFile; 147 } else { 148 propertyFile = new File (this.enhydraDir + File.separator 149 + enhydraPropertyFile); 150 if (propertyFile.exists()) { 151 propertyFileIS = new FileInputStream (propertyFile); 152 props.load(propertyFileIS); 153 propertyFileName = enhydraPropertyFile; 154 } 155 } 156 } catch (Exception ex) { 157 System.out 158 .println("Unable to properly initialize property values!"); 159 } finally { 160 try { 161 if (propertyFileIS != null) 162 propertyFileIS.close(); 163 } catch (IOException ex) { 164 System.out 165 .println("Unable to close property file input stream!"); 166 } 167 } 168 169 if (props != null) { 170 if (props.containsKey("httpenabled")) 172 httpenabled = props.getProperty("httpenabled"); 173 if (props.containsKey("httpport")) 174 httpport = props.getProperty("httpport"); 175 if (props.containsKey("sslenabled")) 176 sslenabled = props.getProperty("sslenabled"); 177 if (props.containsKey("ajpenabled")) 178 ajpenabled = props.getProperty("ajpenabled"); 179 if (props.containsKey("directorenabled")) 180 directorenabled = props.getProperty("directorenabled"); 181 if (props.containsKey("sslport")) 182 sslport = props.getProperty("sslport"); 183 if (props.containsKey("ajpport")) 184 ajpport = props.getProperty("ajpport"); 185 if (props.containsKey("directorport")) 186 directorport = props.getProperty("directorport"); 187 if (props.containsKey("httpadaptorenabled")) 188 httpadaptorenabled = props.getProperty("httpadaptorenabled"); 189 if (props.containsKey("rmiadaptorenabled")) 190 rmiadaptorenabled = props.getProperty("rmiadaptorenabled"); 191 if (props.containsKey("httpadaptorport")) 192 httpadaptorport = props.getProperty("httpadaptorport"); 193 if (props.containsKey("rmiadaptorport")) 194 rmiadaptorport = props.getProperty("rmiadaptorport"); 195 if (props.containsKey("serverport")) 196 serverport = props.getProperty("serverport"); 197 if (props.containsKey("servershutdown")) 198 servershutdown = props.getProperty("servershutdown"); 199 if (props.containsKey("authmode")) 200 authmode = props.getProperty("authmode"); 201 if (props.containsKey("username")) 202 username = props.getProperty("username"); 203 if (props.containsKey("password")) 204 password = props.getProperty("password"); 205 if (props.containsKey("servicename") 206 && basePropertyFile.equals(propertyFileName)) 207 servicename = props.getProperty("servicename"); 208 if (props.containsKey("base.dir") 209 && basePropertyFile.equals(propertyFileName)) 210 basedir = props.getProperty("base.dir"); 211 if (props.containsKey("jdk.dir")) 212 jdkdir = props.getProperty("jdk.dir"); 213 } 214 } 215 216 private void saveProperties() { 217 setProperties(); 218 219 if (props == null) { 220 props = new Properties (); 221 } 222 props.setProperty("httpenabled", httpenabled); 224 props.setProperty("httpport", httpport); 225 props.setProperty("sslenabled", sslenabled); 226 props.setProperty("ajpenabled", ajpenabled); 227 props.setProperty("directorenabled", directorenabled); 228 props.setProperty("sslport", sslport); 229 props.setProperty("ajpport", ajpport); 230 props.setProperty("directorport", directorport); 231 props.setProperty("httpadaptorenabled", httpadaptorenabled); 232 props.setProperty("rmiadaptorenabled", rmiadaptorenabled); 233 props.setProperty("httpadaptorport", httpadaptorport); 234 props.setProperty("rmiadaptorport", rmiadaptorport); 235 props.setProperty("serverport", serverport); 236 props.setProperty("servershutdown", servershutdown); 237 props.setProperty("authmode", authmode); 238 props.setProperty("username", username); 239 props.setProperty("password", password); 240 props.setProperty("jdk.dir", jdkdir); 241 242 propertyFileName = enhydraPropertyFile; 243 if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) { 244 propertyFileName = basePropertyFile; 245 props.setProperty("servicename", servicename); 246 props.setProperty("base.dir", basedir); 247 } 248 249 File propertyFile = null; 250 FileOutputStream propertyFileOS = null; 251 252 try { 253 propertyFile = new File (this.enhydraDir + File.separator 254 + propertyFileName); 255 if (!propertyFile.exists()) { 256 propertyFile.createNewFile(); 257 } 258 propertyFileOS = new FileOutputStream (propertyFile); 259 props 260 .store(propertyFileOS, 261 "Created by Enhydra Configuration Tool"); 262 } catch (Exception ex) { 263 System.out.println("Unable to save property values!"); 264 } finally { 265 try { 266 if (propertyFileOS != null) 267 propertyFileOS.close(); 268 } catch (IOException ex) { 269 System.out 270 .println("Unable to close property file output stream!"); 271 } 272 } 273 } 274 275 private void setProperties() { 276 if (connectorPanel.getHttpChecked()) { 277 httpenabled = "on"; 278 httpport = connectorPanel.getHttpPort(); 279 } else { 280 httpenabled = "off"; 281 } 282 283 if (connectorPanel.getSslHttpChecked()) { 284 sslenabled = "on"; 285 sslport = connectorPanel.getSslHttpPort(); 286 } else { 287 sslenabled = "off"; 288 } 289 290 if (connectorPanel.getAjpChecked()) { 291 ajpenabled = "on"; 292 ajpport = connectorPanel.getAjpPort(); 293 } else { 294 ajpenabled = "off"; 295 } 296 297 if (connectorPanel.getDirectorChecked()) { 298 directorenabled = "on"; 299 directorport = connectorPanel.getDirectorPort(); 300 } else { 301 directorenabled = "off"; 302 } 303 304 if (adaptorPanel.getHttpChecked()) { 305 httpadaptorenabled = "on"; 306 httpadaptorport = adaptorPanel.getHttpPort(); 307 } else { 308 httpadaptorenabled = "off"; 309 } 310 311 authmode = adaptorPanel.getComboSelection(); 312 313 if (adaptorPanel.getRmiChecked()) { 314 rmiadaptorenabled = "on"; 315 rmiadaptorport = adaptorPanel.getRmiPort(); 316 } else { 317 rmiadaptorenabled = "off"; 318 } 319 320 serverport = serverPanel.getServerPort(); 321 servershutdown = serverPanel.getServerString(); 322 323 username = authenticationPanel.getUserName(); 324 password = authenticationPanel.getPassword(); 325 326 jdkdir = javaPanel.getJavaPath(); 327 328 if (enhydraBasePanel.getBaseChecked()) { 329 servicename = enhydraBasePanel.getServiceName(); 330 basedir = enhydraBasePanel.getBasePath(); 331 propertyFileName = basePropertyFile; 332 } else { 333 basedir = ""; 334 servicename = ""; 335 propertyFileName = enhydraPropertyFile; 336 } 337 } 338 339 344 private void initialize() { 345 loadProperties(); 346 347 this.setSize(350, 250); 348 349 int width = Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 175; 350 int height = Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 125; 351 352 this.setLocation(width, height); 353 this.setResizable(false); 354 this 355 .setIconImage(Toolkit.getDefaultToolkit().getImage( 356 getClass().getResource( 357 "/org/enhydra/base/tool/largeicon.gif"))); 358 this.setName("wizardFrame"); 359 this.setTitle("Enhydra Configurator"); 360 this.setContentPane(getJContentPane()); 361 362 connectorPanel = new ConnectorConfigurationPanel(); 363 if ("on".equals(httpenabled)) 364 connectorPanel.setHttpChecked(true); 365 else 366 connectorPanel.setHttpChecked(false); 367 connectorPanel.setHttpPort(httpport); 368 if ("on".equals(sslenabled)) 369 connectorPanel.setSslHttpChecked(true); 370 else 371 connectorPanel.setSslHttpChecked(false); 372 connectorPanel.setSslHttpPort(sslport); 373 if ("on".equals(ajpenabled)) 374 connectorPanel.setAjpChecked(true); 375 else 376 connectorPanel.setAjpChecked(false); 377 connectorPanel.setAjpPort(ajpport); 378 if ("on".equals(directorenabled)) 379 connectorPanel.setDirectorChecked(true); 380 else 381 connectorPanel.setDirectorChecked(false); 382 connectorPanel.setDirectorPort(directorport); 383 getTabBase().addTab("Connectors", connectorPanel); 384 385 adaptorPanel = new AdaptorConfigurationPanel(); 386 if ("on".equals(httpadaptorenabled)) 387 adaptorPanel.setHttpChecked(true); 388 else 389 adaptorPanel.setHttpChecked(false); 390 adaptorPanel.setHttpPort(httpadaptorport); 391 if ("on".equals(rmiadaptorenabled)) 392 adaptorPanel.setRmiChecked(true); 393 else 394 adaptorPanel.setRmiChecked(false); 395 adaptorPanel.setRmiPort(rmiadaptorport); 396 397 adaptorPanel.setComboSelection(authmode); 398 399 getTabBase().addTab("Adaptors", adaptorPanel); 400 401 serverPanel = new ServerShutdownConfigurationPanel(); 402 serverPanel.setServerPort(serverport); 403 serverPanel.setServerString(servershutdown); 404 getTabBase().addTab("Server Shutdown", serverPanel); 405 406 authenticationPanel = new AuthenticationConfigurationPanel(); 407 authenticationPanel.setPassword(password); 408 authenticationPanel.setUserName(username); 409 getTabBase().addTab("Administrator", authenticationPanel); 410 411 javaPanel = new JavaConfigurationPanel(); 412 javaPanel.setJavaPath(jdkdir); 413 getTabBase().addTab("Java", javaPanel); 414 415 enhydraBasePanel = new EnhydraBasePanel(); 416 enhydraBasePanel.setBaseChecked(!("".equals(basedir))); 417 enhydraBasePanel.setServiceName(servicename); 418 enhydraBasePanel.setBasePath(basedir); 419 getTabBase().addTab("Enhydra Base", enhydraBasePanel); 420 421 outputPanel = new OutputPanel(); 422 getTabBase().addTab("Output", outputPanel); 423 424 this.setVisible(true); 425 } 426 427 432 private javax.swing.JPanel getJContentPane() { 433 if (jContentPane == null) { 434 jContentPane = new javax.swing.JPanel (); 435 jContentPane.setLayout(new java.awt.BorderLayout ()); 436 jContentPane.add(getBackPanel(), java.awt.BorderLayout.CENTER); 437 } 438 return jContentPane; 439 } 440 441 446 private JPanel getBackPanel() { 447 if (backPanel == null) { 448 backPanel = new JPanel (); 449 backPanel.setLayout(new BorderLayout ()); 450 backPanel.add(getButtonPanell(), java.awt.BorderLayout.SOUTH); 451 backPanel.add(getSettingPanel(), java.awt.BorderLayout.CENTER); 452 } 453 return backPanel; 454 } 455 456 461 private JPanel getButtonPanell() { 462 if (buttonPanell == null) { 463 buttonPanell = new JPanel (); 464 buttonPanell.setPreferredSize(new java.awt.Dimension (10, 35)); 465 buttonPanell.setBorder(javax.swing.BorderFactory 466 .createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); 467 buttonPanell.add(getConfigureButton(), null); 468 buttonPanell.add(getCloseButton(), null); 469 } 470 return buttonPanell; 471 } 472 473 478 private JButton getConfigureButton() { 479 if (configureButton == null) { 480 configureButton = new JButton (); 481 configureButton.setPreferredSize(new java.awt.Dimension (100, 20)); 482 configureButton.setText("Configure"); 483 configureButton.setSelected(true); 484 configureButton.setToolTipText("Generate Enhydra Base Directory"); 485 configureButton.setName("configureButton"); 486 configureButton.addActionListener(new CustomActionListener()); 487 } 488 return configureButton; 489 } 490 491 496 private JButton getCloseButton() { 497 if (closeButton == null) { 498 closeButton = new JButton (); 499 closeButton.setPreferredSize(new java.awt.Dimension (100, 20)); 500 closeButton.setText("Close"); 501 closeButton.setToolTipText("Close Enhydra Base Generator Dialog"); 502 closeButton.setName("closeButton"); 503 closeButton.addActionListener(new CustomActionListener()); 504 } 505 return closeButton; 506 } 507 508 513 private JPanel getSettingPanel() { 514 if (settingPanel == null) { 515 516 settingPanel = new JPanel (); 517 settingPanel.setLayout(new BorderLayout ()); 518 settingPanel.setPreferredSize(new java.awt.Dimension (300, 35)); 519 settingPanel.add(getTabBase(), java.awt.BorderLayout.CENTER); 520 } 521 return settingPanel; 522 } 523 524 private class CustomAction extends AbstractAction { 525 public void actionPerformed(ActionEvent ae) { 526 String command = ae.getActionCommand(); 527 if ("Close".equals(command)) { 528 System.exit(0); 529 } else if ("Configure".equals(command)) { 530 getTabBase().setSelectedComponent(enhydraBasePanel); 531 if (enhydraBasePanel.checkEntries()) { 532 getTabBase().setSelectedComponent(adaptorPanel); 533 if (adaptorPanel.checkEntries()) { 534 getTabBase().setSelectedComponent(connectorPanel); 535 if (connectorPanel.checkEntries()) { 536 getTabBase().setSelectedComponent(serverPanel); 537 if (serverPanel.checkEntries()) { 538 getTabBase().setSelectedComponent( 539 authenticationPanel); 540 if (authenticationPanel.checkEntries()) { 541 getTabBase() 542 .setSelectedComponent(javaPanel); 543 if (javaPanel.checkEntries()) { 544 getTabBase().setSelectedComponent( 545 outputPanel); 546 547 new Thread () { 548 public void run() { 549 saveProperties(); 550 executeConfiguration(); 551 } 552 }.start(); 553 } 554 } 555 } 556 } 557 } 558 } 559 } 560 } 561 } 562 563 private int executeConfiguration() { 564 outputPanel.clearText(); 565 File root = new File (enhydraDir); 566 567 String executable = "configure"; 568 if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) { 569 executable = "configureBase"; 570 } 571 if ('/' != File.separatorChar) { 572 executable = executable + ".bat"; 573 } 574 575 String execLine = enhydraDir + File.separator + executable; 576 577 execLine = execLine + " -jdk.dir " + jdkdir; 578 579 if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) { 580 execLine = execLine + " -base.dir " + basedir; 581 } 582 583 InputStream inputStream = null; 584 BufferedReader bufferedReader = null; 585 586 try { 587 Process process = Runtime.getRuntime().exec(execLine, null, root); 588 589 inputStream = process.getInputStream(); 590 bufferedReader = new BufferedReader (new InputStreamReader ( 591 inputStream)); 592 593 String s = null; 594 while ((s = bufferedReader.readLine()) != null) { 595 outputPanel.appendTextLine(s); 596 s = null; 597 } 598 599 process.waitFor(); 600 return process.exitValue(); 601 } catch (Exception ex) { 602 System.out.println("Unable to execute configuration process!"); 603 return -1; 604 } finally { 605 try { 606 if (inputStream != null) 607 inputStream.close(); 608 if (bufferedReader != null) 609 bufferedReader.close(); 610 } catch (Exception exc) { 611 System.out.println("Unable to close process stream!"); 612 } 613 } 614 } 615 616 private class CustomActionListener implements ActionListener { 617 618 protected AbstractAction action; 619 620 public CustomActionListener() { 621 action = new CustomAction(); 622 } 623 624 public void actionPerformed(ActionEvent e) { 625 action.actionPerformed(e); 626 } 627 } 628 629 public void setEnhydraDir(String enhydraDir) { 630 this.enhydraDir = enhydraDir; 631 } 632 633 public String getEnhydraDir() { 634 return enhydraDir; 635 } 636 637 642 private JTabbedPane getTabBase() { 643 if (tabBase == null) { 644 tabBase = new JTabbedPane (); 645 tabBase.setName("tabBase"); 646 } 647 return tabBase; 648 } 649 } | Popular Tags |