1 21 package org.jboss.system.server; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.util.Properties ; 28 29 import org.jboss.util.NestedRuntimeException; 30 import org.jboss.util.Null; 31 import org.jboss.util.Primitives; 32 import org.jboss.util.platform.Java; 33 34 56 57 58 public class BaseServerConfig 59 implements ServerConfig 60 { 61 62 private Properties props; 63 64 private File homeDir; 65 private URL homeURL; 66 private URL libraryURL; 67 68 75 private Object patchURL; 76 77 private String serverName; 78 private File serverBaseDir; 79 private File serverHomeDir; 80 private File serverLogDir; 81 private File serverTempDir; 82 private File serverDataDir; 83 private URL serverBaseURL; 84 private URL serverHomeURL; 85 private URL serverLibraryURL; 86 private URL serverConfigURL; 87 88 89 private Boolean exitOnShutdown; 90 private Boolean blockingShutdown; 91 private Boolean requireJBossURLStreamHandlerFactory; 92 private Boolean platformMBeanServer; 93 94 private String rootDeployableFilename; 95 96 103 public BaseServerConfig(final Properties props) throws Exception 104 { 105 this.props = props; 106 107 homeDir = getFile(ServerConfig.HOME_DIR); 109 if (homeDir == null) 110 throw new Exception ("Missing configuration value for: " + ServerConfig.HOME_DIR); 111 System.setProperty(ServerConfig.HOME_DIR, homeDir.toString()); 112 getServerHomeDir(); 114 } 115 116 120 public void initURLs() 121 throws MalformedURLException 122 { 123 homeURL = getURL(ServerConfig.HOME_URL); 125 if (homeURL == null) 126 homeURL = homeDir.toURL(); 127 System.setProperty(ServerConfig.HOME_URL, homeURL.toString()); 128 } 129 130 134 139 public File getHomeDir() 140 { 141 return homeDir; 142 } 143 144 149 public URL getHomeURL() 150 { 151 return homeURL; 152 } 153 154 159 public URL getLibraryURL() 160 { 161 if (libraryURL == null) 162 { 163 try 164 { 165 libraryURL = getURL(ServerConfig.LIBRARY_URL); 166 if (libraryURL == null) 167 { 168 libraryURL = new URL (homeURL, ServerConfig.LIBRARY_URL_SUFFIX); 169 } 170 System.setProperty(ServerConfig.LIBRARY_URL, libraryURL.toString()); 171 } 172 catch (MalformedURLException e) 173 { 174 throw new NestedRuntimeException(e); 175 } 176 } 177 return libraryURL; 178 } 179 180 185 public URL getPatchURL() 186 { 187 if (patchURL == null) 188 { 189 try 190 { 191 patchURL = getURL(ServerConfig.PATCH_URL); 192 if (patchURL == null) 193 { 194 patchURL = Null.VALUE; 195 } 196 else 197 { 198 System.setProperty(ServerConfig.PATCH_URL, patchURL.toString()); 199 } 200 } 201 catch (MalformedURLException e) 202 { 203 throw new NestedRuntimeException(e); 204 } 205 } 206 207 if (patchURL == Null.VALUE) 208 return null; 209 210 return (URL ) patchURL; 211 } 212 213 218 public String getServerName() 219 { 220 if (serverName == null) 221 { 222 serverName = props.getProperty(ServerConfig.SERVER_NAME, ServerConfig.DEFAULT_SERVER_NAME); 223 System.setProperty(ServerConfig.SERVER_NAME, serverName); 224 } 225 return serverName; 226 } 227 228 233 public File getServerBaseDir() 234 { 235 if (serverBaseDir == null) 236 { 237 serverBaseDir = getFile(ServerConfig.SERVER_BASE_DIR); 238 if (serverBaseDir == null) 239 { 240 serverBaseDir = new File (homeDir, ServerConfig.SERVER_BASE_DIR_SUFFIX); 241 System.setProperty(ServerConfig.SERVER_BASE_DIR, serverBaseDir.toString()); 242 } 243 } 244 return serverBaseDir; 245 } 246 247 252 public File getServerHomeDir() 253 { 254 if (serverHomeDir == null) 255 { 256 serverHomeDir = getFile(ServerConfig.SERVER_HOME_DIR); 257 if (serverHomeDir == null) 258 { 259 serverHomeDir = new File (getServerBaseDir(), getServerName()); 260 System.setProperty(ServerConfig.SERVER_HOME_DIR, serverHomeDir.toString()); 261 } 262 } 263 return serverHomeDir; 264 } 265 266 274 public File getServerLogDir() 275 { 276 if (serverLogDir == null) 277 { 278 serverLogDir = getFile(ServerConfig.SERVER_LOG_DIR); 279 if (serverLogDir == null) 280 { 281 serverLogDir = new File (getServerHomeDir(), ServerConfig.SERVER_LOG_DIR_SUFFIX); 282 System.setProperty(ServerConfig.SERVER_LOG_DIR, serverLogDir.toString()); 283 } 284 } 285 return serverLogDir; 286 } 287 288 294 public File getServerTempDir() 295 { 296 if (serverTempDir == null) 297 { 298 serverTempDir = getFile(ServerConfig.SERVER_TEMP_DIR); 299 if (serverTempDir == null) 300 { 301 serverTempDir = new File (getServerHomeDir(), ServerConfig.SERVER_TEMP_DIR_SUFFIX); 302 System.setProperty(ServerConfig.SERVER_TEMP_DIR, serverTempDir.toString()); 303 } 304 } 305 return serverTempDir; 306 } 307 308 314 public File getServerDataDir() 315 { 316 if (serverDataDir == null) 317 { 318 serverDataDir = getFile(ServerConfig.SERVER_DATA_DIR); 319 if (serverDataDir == null) 320 { 321 serverDataDir = new File (getServerHomeDir(), ServerConfig.SERVER_DATA_DIR_SUFFIX); 322 System.setProperty(ServerConfig.SERVER_DATA_DIR, serverDataDir.toString()); 323 } 324 } 325 return serverDataDir; 326 } 327 328 334 public File getServerNativeDir() 335 { 336 String fileName = System.getProperty(NATIVE_DIR_PROPERTY); 337 if (fileName != null) 338 return new File (fileName); 339 return new File (getServerTempDir(), "native"); 340 } 341 342 348 public File getServerTempDeployDir() 349 { 350 return new File (getServerTempDir(), "deploy"); 351 } 352 353 358 public URL getServerBaseURL() 359 { 360 if (serverBaseURL == null) 361 { 362 try 363 { 364 serverBaseURL = getURL(ServerConfig.SERVER_BASE_URL); 365 if (serverBaseURL == null) 366 { 367 serverBaseURL = new URL (homeURL, ServerConfig.SERVER_BASE_URL_SUFFIX); 368 } 369 System.setProperty(ServerConfig.SERVER_BASE_URL, serverBaseURL.toString()); 370 } 371 catch (MalformedURLException e) 372 { 373 throw new NestedRuntimeException(e); 374 } 375 } 376 return serverBaseURL; 377 } 378 379 384 public URL getServerHomeURL() 385 { 386 if (serverHomeURL == null) 387 { 388 try 389 { 390 serverHomeURL = getURL(ServerConfig.SERVER_HOME_URL); 391 if (serverHomeURL == null) 392 { 393 serverHomeURL = new URL (getServerBaseURL(), getServerName() + "/"); 394 } 395 System.setProperty(ServerConfig.SERVER_HOME_URL, serverHomeURL.toString()); 396 } 397 catch (MalformedURLException e) 398 { 399 throw new NestedRuntimeException(e); 400 } 401 } 402 return serverHomeURL; 403 } 404 405 410 public URL getServerLibraryURL() 411 { 412 if (serverLibraryURL == null) 413 { 414 try 415 { 416 serverLibraryURL = getURL(ServerConfig.SERVER_LIBRARY_URL); 417 if (serverLibraryURL == null) 418 { 419 serverLibraryURL = new URL (getServerHomeURL(), ServerConfig.LIBRARY_URL_SUFFIX); 420 } 421 System.setProperty(ServerConfig.SERVER_LIBRARY_URL, serverLibraryURL.toString()); 422 } 423 catch (MalformedURLException e) 424 { 425 throw new NestedRuntimeException(e); 426 } 427 } 428 return serverLibraryURL; 429 } 430 431 436 public URL getServerConfigURL() 437 { 438 if (serverConfigURL == null) 439 { 440 try 441 { 442 serverConfigURL = getURL(ServerConfig.SERVER_CONFIG_URL); 443 if (serverConfigURL == null) 444 { 445 serverConfigURL = new URL (getServerHomeURL(), ServerConfig.SERVER_CONFIG_URL_SUFFIX); 446 } 447 System.setProperty(ServerConfig.SERVER_CONFIG_URL, serverConfigURL.toString()); 448 } 449 catch (MalformedURLException e) 450 { 451 throw new NestedRuntimeException(e); 452 } 453 } 454 return serverConfigURL; 455 } 456 457 467 public boolean getPlatformMBeanServer() 468 { 469 if (platformMBeanServer == null) 470 { 471 if (Java.isCompatible(Java.VERSION_1_5)) 472 { 473 String value = props.getProperty(ServerConfig.PLATFORM_MBEANSERVER, 475 (new Boolean (ServerConfig.DEFAULT_PLATFORM_MBEANSERVER)).toString()); 476 477 value = "".equals(value) ? "true" : value; 479 480 platformMBeanServer = new Boolean (value); 482 } 483 else 484 { 485 platformMBeanServer = Boolean.FALSE; 487 } 488 } 489 return platformMBeanServer.booleanValue(); 490 } 491 492 501 public void setExitOnShutdown(final boolean flag) 502 { 503 exitOnShutdown = Primitives.valueOf(flag); 504 } 505 506 513 public boolean getExitOnShutdown() 514 { 515 if (exitOnShutdown == null) 516 { 517 String value = props.getProperty(ServerConfig.EXIT_ON_SHUTDOWN, null); 518 if (value == null) 519 { 520 exitOnShutdown = Primitives.valueOf(ServerConfig.DEFAULT_EXIT_ON_SHUTDOWN); 521 } 522 else 523 { 524 exitOnShutdown = new Boolean (value); 525 } 526 } 527 return exitOnShutdown.booleanValue(); 528 } 529 530 540 public void setBlockingShutdown(final boolean flag) 541 { 542 blockingShutdown = Primitives.valueOf(flag); 543 } 544 545 552 public boolean getBlockingShutdown() 553 { 554 if (blockingShutdown == null) 555 { 556 String value = props.getProperty(ServerConfig.BLOCKING_SHUTDOWN, null); 557 if (value == null) 558 { 559 blockingShutdown = Primitives.valueOf(ServerConfig.DEFAULT_BLOCKING_SHUTDOWN); 560 } 561 else 562 { 563 blockingShutdown = new Boolean (value); 564 } 565 } 566 return blockingShutdown.booleanValue(); 567 } 568 569 570 579 public void setRequireJBossURLStreamHandlerFactory(final boolean flag) 580 { 581 requireJBossURLStreamHandlerFactory = Primitives.valueOf(flag); 582 } 583 584 591 public boolean getRequireJBossURLStreamHandlerFactory() 592 { 593 if (requireJBossURLStreamHandlerFactory == null) 594 { 595 String value = props.getProperty(ServerConfig.REQUIRE_JBOSS_URL_STREAM_HANDLER_FACTORY, null); 596 if (value == null) 597 { 598 requireJBossURLStreamHandlerFactory = Primitives.valueOf(ServerConfig.DEFAULT_REQUIRE_JBOSS_URL_STREAM_HANDLER_FACTORY); 599 } 600 else 601 { 602 requireJBossURLStreamHandlerFactory = new Boolean (value); 603 } 604 } 605 return requireJBossURLStreamHandlerFactory.booleanValue(); 606 } 607 608 616 public void setRootDeploymentFilename(final String filename) 617 { 618 this.rootDeployableFilename = filename; 619 } 620 621 629 public String getRootDeploymentFilename() 630 { 631 if (rootDeployableFilename == null) 632 { 633 rootDeployableFilename = props.getProperty(ServerConfig.ROOT_DEPLOYMENT_FILENAME, 634 ServerConfig.DEFAULT_ROOT_DEPLOYMENT_FILENAME); 635 } 636 637 return rootDeployableFilename; 638 } 639 640 643 private URL getURL(final String name) throws MalformedURLException 644 { 645 String value = props.getProperty(name, null); 646 if (value != null) 647 { 648 if (!value.endsWith("/")) value += "/"; 649 return new URL (value); 650 } 651 652 return null; 653 } 654 655 659 private File getFile(final String name) 660 { 661 String value = props.getProperty(name, null); 662 if (value != null) 663 { 664 try 665 { 666 File f = new File (value); 667 return f.getCanonicalFile(); 668 } 669 catch(IOException e) 670 { 671 return new File (value); 672 } 673 } 674 675 return null; 676 } 677 } 678 679 | Popular Tags |