1 23 24 package com.sun.enterprise.admin.servermgmt.pe; 25 26 import java.util.Vector ; 27 import java.util.Iterator ; 28 import java.io.File ; 29 30 import com.sun.enterprise.util.OS; 31 import com.sun.enterprise.util.io.FileUtils; 32 import com.sun.enterprise.util.i18n.StringManager; 33 34 import com.sun.enterprise.admin.servermgmt.RepositoryException; 35 import com.sun.enterprise.admin.servermgmt.RepositoryConfig; 36 import com.sun.enterprise.util.SystemPropertyConstants; 37 38 import com.sun.enterprise.security.store.PasswordAdapter; 39 40 public class PEFileLayout 41 { 42 private static final StringManager _strMgr = 43 StringManager.getManager(PEFileLayout.class); 44 45 public static final String DEFAULT_INSTANCE_NAME = 46 SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME; 47 48 protected final RepositoryConfig _config; 49 50 51 public PEFileLayout(RepositoryConfig config) { 52 _config = config; 53 } 54 55 public void createRepositoryDirectories() throws RepositoryException 56 { 57 createDirectory(getRepositoryRootDir()); 58 createDirectory(getRepositoryDir()); 59 createDirectory(getConfigRoot()); 60 createDirectory(getDocRoot()); 61 createDirectory(getJavaWebStartRoot()); 62 createDirectory(getLibDir()); 63 createDirectory(getBinDir()); 64 createDirectory(getClassesDir()); 65 createDirectory(getExtLibDir()); 66 createDirectory(getAppLibsDir()); 67 createDirectory(getLogsDir()); 68 createDirectory(getGeneratedDir()); 69 createDirectory(getJspRootDir()); 70 createDirectory(getEjbRootDir()); 71 createDirectory(getXmlRootDir()); 72 createDirectory(getApplicationsRootDir()); 73 createDirectory(getJ2EEAppsDir()); 74 createDirectory(getJ2EEModulesDir()); 75 createDirectory(getLifecycleModulesDir()); 76 createDirectory(getMbeansDir()); 77 createDirectory(getSessionStore()); 78 createDirectory(getAutoDeployDir()); 79 createDirectory(getAutoDeployStatusDir()); 80 createDirectory(getTimerDatabaseDir()); 81 } 82 83 protected RepositoryConfig getConfig() { 84 return _config; 85 } 86 87 public void createRepositoryRoot() throws RepositoryException 88 { 89 createDirectory(getRepositoryRootDir()); 90 } 91 92 protected void createDirectory(File dir) throws RepositoryException 93 { 94 if (!dir.exists()) { 95 try { 96 if (!dir.mkdirs()) { 97 throw new RepositoryException(_strMgr.getString("directoryCreationError", 98 dir)); 99 } 100 } catch (Exception e) { 101 throw new RepositoryException(_strMgr.getString("directoryCreationError", 102 dir), e); 103 } 104 } 105 } 106 107 public static final String CONFIG_DIR = "config"; 108 public File getConfigRoot() 109 { 110 return new File (getRepositoryDir(), CONFIG_DIR); 111 } 112 113 public static final String CONFIG_BACKUP_DIR = "backup"; 114 public File getRepositoryBackupRoot() 115 { 116 return new File (getConfigRoot(), CONFIG_BACKUP_DIR); 117 } 118 119 public static final String DOC_ROOT_DIR = "docroot"; 120 public File getDocRoot() 121 { 122 123 return new File (getRepositoryDir(), DOC_ROOT_DIR); 124 } 125 126 public static final String JAVA_WEB_START_DIR = "java-web-start"; 127 public File getJavaWebStartRoot() 128 { 129 130 return new File (getRepositoryDir(), JAVA_WEB_START_DIR); 131 } 132 133 public static final String LIB_DIR = "lib"; 134 public File getLibDir() 135 { 136 return new File (getRepositoryDir(), LIB_DIR); 137 } 138 139 public File getBinDir() 140 { 141 return new File (getRepositoryDir(), BIN_DIR); 142 } 143 144 public static final String CLASSES_DIR = "classes"; 145 public File getClassesDir() 146 { 147 return new File (getLibDir(), CLASSES_DIR); 148 } 149 150 public static final String APPLIBS_DIR = "applibs"; 151 public File getAppLibsDir() 152 { 153 return new File (getLibDir(), APPLIBS_DIR); 154 } 155 156 public static final String EXTLIB_DIR = "ext"; 157 public File getExtLibDir() 158 { 159 return new File (getLibDir(), EXTLIB_DIR); 160 } 161 162 public static final String TIMERDB_DIR = "databases"; 163 public File getTimerDatabaseDir() 164 { 165 return new File (getLibDir(), TIMERDB_DIR); 166 } 167 168 public static final String LOGS_DIR = "logs"; 169 public File getLogsDir() 170 { 171 return new File (getRepositoryDir(), LOGS_DIR); 172 } 173 174 public static final String APPS_ROOT_DIR = "applications"; 175 public File getApplicationsRootDir() 176 { 177 return new File (getRepositoryDir(), APPS_ROOT_DIR); 178 } 179 180 public static final String J2EE_APPS_DIR = "j2ee-apps"; 181 public File getJ2EEAppsDir() 182 { 183 return new File (getApplicationsRootDir(), J2EE_APPS_DIR); 184 } 185 186 public static final String J2EE_MODULES_DIR = "j2ee-modules"; 187 public File getJ2EEModulesDir() 188 { 189 return new File (getApplicationsRootDir(), J2EE_MODULES_DIR); 190 } 191 192 public static final String LIFECYCLE_MODULES_DIR = "lifecycle-modules"; 193 public File getLifecycleModulesDir() 194 { 195 return new File (getApplicationsRootDir(), LIFECYCLE_MODULES_DIR); 196 } 197 198 public static final String MBEAN_FOLDER_NAME = "mbeans"; 199 public File getMbeansDir() 200 { 201 return new File (getApplicationsRootDir(), MBEAN_FOLDER_NAME); 202 } 203 204 public static final String GENERATED_DIR = "generated"; 205 public File getGeneratedDir() 206 { 207 return new File (getRepositoryDir(), GENERATED_DIR); 208 } 209 210 212 public static final String POLICY_DIR = "policy"; 213 public static final String POLICY_FILE_EXT = "granted.policy"; 214 public File getPolicyDir() 215 { 216 return new File (getGeneratedDir(), POLICY_DIR); 217 } 218 219 221 public static final String JSP_DIR = "jsp"; 222 public File getJspRootDir() 223 { 224 return new File (getGeneratedDir(), JSP_DIR); 225 } 226 227 public static final String EJB_DIR = "ejb"; 228 public File getEjbRootDir() 229 { 230 return new File (getGeneratedDir(), EJB_DIR); 231 } 232 233 public static final String XML_DIR = "xml"; 234 public File getXmlRootDir() 235 { 236 return new File (getGeneratedDir(), XML_DIR); 237 } 238 239 public File getRepositoryDir() 240 { 241 return new File (getRepositoryRootDir(), getConfig().getRepositoryName()); 242 } 243 244 public static final String DOMAIN_XML_FILE = "domain.xml"; 245 public File getDomainConfigFile() 246 { 247 return new File (getConfigRoot(), DOMAIN_XML_FILE); 248 } 249 250 public File getDomainConfigBackupFile() 251 { 252 return new File (getRepositoryBackupRoot(), DOMAIN_XML_FILE); 253 } 254 255 public static final String IMQ = "imq"; 256 public File getImqDir() 257 { 258 return new File (getInstallRootDir(), IMQ); 259 } 260 261 public static final String IMQ_VAR_DIR = "imq"; 262 public File getImqVarHome() 263 { 264 return new File (getRepositoryDir(), IMQ_VAR_DIR); 265 } 266 267 public static final String BIN_DIR = "bin"; 268 public File getImqBinDir() 269 { 270 return new File (getImqDir(), BIN_DIR); 271 } 272 273 public File getImqLibDir() 274 { 275 return new File (getImqDir(), LIB_DIR); 276 } 277 278 public File getInstallRootDir() 279 { 280 return getCanonicalFile(new File (getConfig().getInstallRoot())); 281 } 282 283 public File getRepositoryRootDir() 284 { 285 return getCanonicalFile(new File (getConfig().getRepositoryRoot())); 286 } 287 288 public static final String SHARE = "share"; 289 public File getShareDir() 290 { 291 return new File (getInstallRootDir(), SHARE); 292 } 293 294 public File getWebServicesLibDir() 295 { 296 return new File (getShareDir(), LIB_DIR); 297 } 298 299 public static final String INSTALL_DIR = "install"; 301 public static final String TEMPLATES_DIR = "templates"; 302 303 protected String _templatesSubdir = null; 304 305 protected String getTemplatesSubDir() { 306 return _templatesSubdir; 307 } 308 309 public File getTemplatesDir() 310 { 311 final File lib = new File (getInstallRootDir(), LIB_DIR); 312 final File install = new File (lib, INSTALL_DIR); 313 File templates = new File (install, TEMPLATES_DIR); 314 if (getTemplatesSubDir() != null) { 315 return new File (templates, getTemplatesSubDir()); 316 } else { 317 return templates; 318 } 319 } 320 321 323 public static final String APPLICATIONS_DIR = "applications"; 324 public File getInstallApplicationsDir() 325 { 326 final File lib = new File (getInstallRootDir(), LIB_DIR); 327 final File install = new File (lib, INSTALL_DIR); 328 return new File (install, APPLICATIONS_DIR); 329 } 330 331 333 public static final String DATABASES_DIR = "databases"; 334 public File getInstallDatabasesDir() 335 { 336 final File lib = new File (getInstallRootDir(), LIB_DIR); 337 final File install = new File (lib, INSTALL_DIR); 338 return new File (install, DATABASES_DIR); 339 } 340 341 343 public static final String DTDS_DIR = "dtds"; 344 public File getDtdsDir() 345 { 346 final File lib = new File (getInstallRootDir(), LIB_DIR); 347 return new File (lib, DTDS_DIR); 348 } 349 350 352 public static final String DOMAIN_DTD = "sun-domain_1_2.dtd"; 353 public File getDtdFile() 354 { 355 return new File (getDtdsDir(), DOMAIN_DTD); 356 } 357 358 public static final String DOMAIN_XML_TEMPLATE = "default-domain.xml.template"; 359 public File getDomainXmlTemplate() 360 { 361 return new File (getTemplatesDir(), DOMAIN_XML_TEMPLATE); 362 } 363 364 public File getDomainXmlTemplate(String templateName) 365 { 366 if(new File (templateName).isAbsolute()) 370 return new File (templateName); 371 else 372 return new File (getTemplatesDir(), templateName); 373 } 374 375 public static final String IMQBROKERD_UNIX = "imqbrokerd"; 376 public static final String IMQBROKERD_WIN = "imqbrokerd.exe"; 377 public static final String IMQBROKERD = isWindows() ? IMQBROKERD_WIN : IMQBROKERD_UNIX; 378 public File getImqBrokerExecutable() 379 { 380 return new File (getImqBinDir(), IMQBROKERD); 381 } 382 383 public static final String START_SERV_UNIX = "startserv"; 384 public static final String START_SERV_WIN = "startserv.bat"; 385 public static final String START_SERV_OS = isWindows() ? START_SERV_WIN : START_SERV_UNIX; 386 public File getStartServ() 387 { 388 return new File (getBinDir(), START_SERV_OS); 389 } 390 391 public static final String START_SERV_TEMPLATE_UNIX = "startserv.tomcat.template"; 392 public static final String START_SERV_TEMPLATE_WIN = "startserv.tomcat.bat.template"; 393 public static final String START_SERV_TEMPLATE_OS = isWindows() ? START_SERV_TEMPLATE_WIN : 394 START_SERV_TEMPLATE_UNIX; 395 396 public File getStartServTemplate() 397 { 398 return new File (getTemplatesDir(), START_SERV_TEMPLATE_OS); 399 } 400 401 public static final String STOP_SERV_UNIX = "stopserv"; 402 public static final String STOP_SERV_WIN = "stopserv.bat"; 403 public static final String STOP_SERV_OS = isWindows() ? STOP_SERV_WIN : STOP_SERV_UNIX; 404 405 public File getStopServ() 406 { 407 return new File (getBinDir(), STOP_SERV_OS); 408 } 409 410 public static final String STOP_SERV_TEMPLATE_UNIX = "stopserv.tomcat.template"; 411 public static final String STOP_SERV_TEMPLATE_WIN = "stopserv.tomcat.bat.template"; 412 public static final String STOP_SERV_TEMPLATE_OS = isWindows() ? STOP_SERV_TEMPLATE_WIN : 413 STOP_SERV_TEMPLATE_UNIX; 414 public File getStopServTemplate() 415 { 416 return new File (getTemplatesDir(), STOP_SERV_TEMPLATE_OS); 417 } 418 419 public static final String POLICY_FILE = "server.policy"; 420 public File getPolicyFileTemplate() 421 { 422 return new File (getTemplatesDir(), POLICY_FILE); 423 } 424 425 public File getPolicyFile() 426 { 427 return new File (getConfigRoot(), POLICY_FILE); 428 } 429 430 431 public static final String STUB_FILE = "admch"; 432 public File getStubFile() 433 { 434 return new File (getConfigRoot(), STUB_FILE); 435 } 436 437 public static final String SEED_FILE = "admsn"; 438 public File getSeedFile() 439 { 440 return new File (getConfigRoot(), SEED_FILE); 441 } 442 443 public File getInstallConfigRoot() 444 { 445 return new File (getInstallRootDir(), CONFIG_DIR); 446 } 447 448 public static final String ACC_XML_TEMPLATE = "sun-acc.xml.template"; 449 public File getAppClientContainerXmlTemplate() 450 { 451 return new File (getTemplatesDir(), ACC_XML_TEMPLATE); 452 } 453 454 public static final String ACC_XML = "sun-acc.xml"; 455 public File getAppClientContainerXml() 456 { 457 return new File (getConfigRoot(), ACC_XML); 458 } 459 460 public static final String SESSION_STORE = "session-store"; 461 public File getSessionStore() 462 { 463 return new File (getRepositoryDir(), SESSION_STORE); 464 } 465 466 public static final String AUTO_DEPLOY = "autodeploy"; 467 public File getAutoDeployDir() 468 { 469 return new File (getRepositoryDir(), AUTO_DEPLOY); 470 } 471 472 public static final String AUTO_DEPLOY_STATUS = ".autodeploystatus"; 473 public File getAutoDeployStatusDir() 474 { 475 return new File (getAutoDeployDir(), AUTO_DEPLOY_STATUS); 476 } 477 478 public static final String KEY_FILE_TEMPLATE = "keyfile"; 479 public File getKeyFileTemplate() 480 { 481 return new File (getTemplatesDir(), KEY_FILE_TEMPLATE); 482 } 483 484 public static final String KEY_FILE = "keyfile"; 485 public File getKeyFile() 486 { 487 return new File (getConfigRoot(), KEY_FILE); 488 } 489 490 public static final String ADMIN_KEY_FILE = "admin-keyfile"; 491 public File getAdminKeyFile() 492 { 493 return new File (getConfigRoot(), ADMIN_KEY_FILE); 494 } 495 496 public File getBackupKeyFile() 497 { 498 return new File (getRepositoryBackupRoot(), KEY_FILE); 499 } 500 501 public static final String INDEX_FILE = "index.html"; 502 public File getIndexFileTemplate() 503 { 504 return new File (getTemplatesDir(), INDEX_FILE); 505 } 506 507 public File getIndexFile() 508 { 509 return new File (getDocRoot(), INDEX_FILE); 510 } 511 512 public static final String DEFAULT_WEB_XML = "default-web.xml"; 513 public File getDefaultWebXmlTemplate() 514 { 515 return new File (getTemplatesDir(), DEFAULT_WEB_XML); 516 } 517 518 public File getDefaultWebXml() 519 { 520 return new File (getConfigRoot(), DEFAULT_WEB_XML); 521 } 522 523 public static final String LOGIN_CONF = "login.conf"; 524 public File getLoginConfTemplate() 525 { 526 return new File (getTemplatesDir(), LOGIN_CONF); 527 } 528 529 public File getLoginConf() 530 { 531 return new File (getConfigRoot(), LOGIN_CONF); 532 } 533 534 public static final String WSSSERVERCONFIGOLD = "wss-server-config-1.0.xml"; 535 public File getWssServerConfigOldTemplate() 536 { 537 return new File (getTemplatesDir(), WSSSERVERCONFIGOLD); 538 } 539 540 public File getWssServerConfigOld() 541 { 542 return new File (getConfigRoot(), WSSSERVERCONFIGOLD); 543 } 544 545 public static final String WSSSERVERCONFIG = "wss-server-config-2.0.xml"; 546 public File getWssServerConfigTemplate() 547 { 548 return new File (getTemplatesDir(), WSSSERVERCONFIG); 549 } 550 551 public File getWssServerConfig() 552 { 553 return new File (getConfigRoot(), WSSSERVERCONFIG); 554 } 555 556 public static final String KEYSTORE = "keystore.jks"; 557 public File getKeyStore() 558 { 559 return new File (getConfigRoot(), KEYSTORE); 560 } 561 562 public static final String TRUSTSTORE_TEMPLATE = "cacerts.jks"; 563 public File getTrustStoreTemplate() 564 { 565 return new File (getTemplatesDir(), TRUSTSTORE_TEMPLATE); 566 } 567 568 public static final String TRUSTSTORE = "cacerts.jks"; 569 public File getTrustStore() 570 { 571 return new File (getConfigRoot(), TRUSTSTORE); 572 } 573 574 public static final String MASTERPASSWORD_FILE = "master-password"; 575 public File getMasterPasswordFile() 576 { 577 return new File (getRepositoryDir(), MASTERPASSWORD_FILE); 578 } 579 580 public static final String PASSWORD_ALIAS_KEYSTORE = PasswordAdapter.PASSWORD_ALIAS_KEYSTORE; 581 public File getPasswordAliasKeystore() 582 { 583 return new File (getConfigRoot(), PASSWORD_ALIAS_KEYSTORE); 584 } 585 586 public static final String TIMERDB_WAL_TEMPLATE = "ejbtimer$1.wal"; 587 public File getTimerWalTemplate() { 588 return new File (getInstallDatabasesDir(), TIMERDB_WAL_TEMPLATE); 589 } 590 591 public static final String TIMERDB_WAL = "ejbtimer$1.wal"; 592 public File getTimerWal() { 593 return new File (getTimerDatabaseDir(), TIMERDB_WAL); 594 } 595 596 public static final String TIMERDB_DBN_TEMPLATE = "ejbtimer.dbn"; 597 public File getTimerDbnTemplate() { 598 return new File (getInstallDatabasesDir(), TIMERDB_DBN_TEMPLATE); 599 } 600 601 public static final String TIMERDB_DBN = "ejbtimer.dbn"; 602 public File getTimerDbn() { 603 return new File (getTimerDatabaseDir(), TIMERDB_DBN); 604 } 605 public static final String DERBY_SQL_FILE = "ejbtimer_derby.sql"; 606 public static final String EJB_TIMER_TABLE_NAME = "EJB__TIMER__TBL"; public File getDerbyEjbTimerSqlFile() { 608 return new File (getInstallDatabasesDir(), DERBY_SQL_FILE); 609 } 610 public static final String DERBY_DATABASE_DIRECTORY = "ejbtimer"; 611 public File getDerbyEjbTimerDatabaseDirectory() { 612 return new File (getTimerDatabaseDir(), DERBY_DATABASE_DIRECTORY); 613 } 615 616 protected static boolean isWindows() 617 { 618 return OS.isWindows(); 619 } 620 621 File getCanonicalFile(File f) 622 { 623 return FileUtils.safeGetCanonicalFile(f); 624 } 625 } 626 | Popular Tags |