1 23 24 29 30 package com.sun.enterprise.instance; 31 32 33 import javax.enterprise.deploy.shared.ModuleType ; 34 35 import com.sun.enterprise.admin.AdminContext; 36 import com.sun.enterprise.admin.server.core.AdminService; 37 import com.sun.enterprise.config.ConfigBean; 38 import com.sun.enterprise.config.ConfigBeansFactory; 39 import com.sun.enterprise.config.ConfigContext; 40 import com.sun.enterprise.config.ConfigException; 41 import com.sun.enterprise.config.ConfigFactory; 42 import com.sun.enterprise.config.serverbeans.ApplicationRef; 43 import com.sun.enterprise.config.serverbeans.Applications; 44 import com.sun.enterprise.config.serverbeans.ConnectorModule; 45 import com.sun.enterprise.config.serverbeans.DasConfig; 46 import com.sun.enterprise.config.serverbeans.Domain; 47 import com.sun.enterprise.config.serverbeans.JavaConfig; 48 import com.sun.enterprise.config.serverbeans.Server; 49 import com.sun.enterprise.config.serverbeans.Server; 50 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 51 import com.sun.enterprise.config.serverbeans.ServerHelper; 52 import com.sun.enterprise.config.serverbeans.Servers; 53 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 54 import com.sun.enterprise.deployment.Application; 55 import com.sun.enterprise.deployment.BundleDescriptor; 56 import com.sun.enterprise.deployment.util.ModuleDescriptor; 57 import com.sun.enterprise.deployment.archivist.Archivist; 58 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 59 import com.sun.enterprise.deployment.archivist.EjbArchivist; 60 import com.sun.enterprise.deployment.archivist.WebArchivist; 61 import com.sun.enterprise.deployment.backend.DeployableObjectInfo; 62 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 63 import com.sun.enterprise.util.io.FileUtils; 64 import com.sun.enterprise.util.StringUtils; 65 import com.sun.enterprise.util.RelativePathResolver; 66 import com.sun.logging.LogDomains; 67 68 import java.io.File ; 69 import java.io.IOException ; 70 import java.util.*; 71 import java.util.logging.Level ; 72 import java.util.logging.Logger ; 73 74 import org.xml.sax.SAXParseException ; 75 76 80 public abstract class BaseManager { 81 82 protected ConfigContext configContext; 83 protected ConfigBean configBean; 84 private DasConfig appConfig; 85 protected InstanceEnvironment instanceEnvironment; 86 protected boolean useBackupServerXml = true; 87 protected static final String SYSTEM_PREFIX = "system-"; 88 protected static final String SYSTEM_ADMIN_PREFIX = "system-admin"; 89 protected static Logger _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER); 90 private static Map registeredDescriptors; 91 92 93 private static final String DEBUG_OPTION = "-g"; 94 95 96 private static final String OPTIMIZE_OPTION = "-O"; 97 98 public BaseManager(InstanceEnvironment env, boolean useBackupServerXml) 99 throws ConfigException { 100 101 instanceEnvironment = env; 102 try { 103 this.useBackupServerXml = useBackupServerXml; 104 106 String fileUrl; 107 if(useBackupServerXml) { 108 fileUrl = instanceEnvironment.getBackupConfigFilePath(); 109 } else { 110 fileUrl = instanceEnvironment.getConfigFilePath(); 111 } 112 113 if (useBackupServerXml) { 114 AdminService as = AdminService.getAdminService(); 115 if (as != null) { 116 AdminContext ac = as.getAdminContext(); 117 if (ac != null) { 118 configContext = ac.getAdminConfigContext(); 119 } 120 } 121 } 122 if (configContext == null) { 123 configContext = ConfigFactory.createConfigContext(fileUrl); 124 } 125 configBean = ConfigBeansFactory.getConfigBeanByXPath(this.configContext, 126 ServerXPathHelper.XPATH_APPLICATIONS); 127 if (configBean == null) { 129 configBean = new Applications(); 130 } 131 132 appConfig = ServerBeansFactory.getDasConfigBean(configContext); 134 135 if (appConfig == null) { 138 appConfig = new DasConfig(); 139 } 140 141 } 142 catch(Exception e) { 143 throw new ConfigException(Localizer.getValue(ExceptionType.MISSING_SERVER_NODE), e); 144 } 145 } 146 147 150 public abstract ModuleType getModuleType(); 151 152 165 166 public static String isRegisteredAnywhere(InstanceEnvironment ienv, String id) 167 { 168 try { 169 BaseManager[] mans = new BaseManager[]{ 170 new WebModulesManager(ienv), 171 new EjbModulesManager(ienv), 172 new AppclientModulesManager(ienv), 173 new ConnectorModulesManager(ienv), 174 new AppsManager(ienv) 175 }; 176 177 String [] errors = new String [] {"Web Module", "EJB Module", "App Client Module", "Connector Module", "Application"}; 178 179 for(int i = 0; i < mans.length; i++){ 180 if(mans[i].listIds().contains(id)) { 181 return errors[i]; 182 } 183 } 184 } 185 catch(Exception e){ 186 } 187 return null; 188 } 189 190 200 public Application getDescriptor(String modId, ClassLoader cl, 201 boolean validateXML) throws ConfigException { 202 203 return getDescriptor(modId, cl, getLocation(modId), validateXML); 204 } 205 206 216 public abstract Application getDescriptor(String modId, ClassLoader cl, String loc, boolean validateXML) 217 throws ConfigException; 218 219 220 224 public Application getDescriptor(String appID) 225 throws ConfigException { 226 return getRegisteredDescriptor(appID); 227 } 228 229 237 public boolean isByteCodePreprocessingEnabled() 238 throws ConfigException { 239 boolean result = false; 240 JavaConfig jc = ServerBeansFactory.getJavaConfigBean(configContext); 242 if (jc != null) { 243 if (jc.getBytecodePreprocessors() != null) { 244 result = true; 245 } 246 } 247 return result; 248 } 249 250 256 public String [] getBytecodeProcessorClassNames() 257 throws ConfigException { 258 String result[] = null; 259 JavaConfig jc = ServerBeansFactory.getJavaConfigBean(configContext); 261 if (jc != null) { 262 String value = jc.getBytecodePreprocessors(); 263 _logger.log(Level.INFO, 264 "core.preprocessor_class_name", value); 265 result = value.split(","); 268 } 269 270 return result; 271 } 272 274 279 public boolean isDynamicReloadEnabled() { 280 return appConfig.isDynamicReloadEnabled(); 283 } 284 285 290 public long getReloadPollIntervalInMillis() { 291 292 String intv = appConfig.getDynamicReloadPollIntervalInSeconds(); 294 295 296 long pollIntv; 297 298 try { 299 pollIntv = Long.parseLong(intv) * 1000; 300 } catch (NumberFormatException nme) { 301 302 intv = appConfig.getDefaultDynamicReloadPollIntervalInSeconds(); 304 305 try { 306 pollIntv = Long.parseLong(intv) * 1000; 307 } catch (NumberFormatException ne) { 308 pollIntv = 2000l; 310 } 311 } 312 313 return pollIntv; 314 } 315 316 328 public List getSystemCPathPrefixNSuffix() throws ConfigException { 329 330 List classPath = new ArrayList(); 331 332 JavaConfig jconfig = (JavaConfig) ConfigBeansFactory. 334 getConfigBeanByXPath(this.configContext, 335 ServerXPathHelper.XPATH_JAVACONFIG); 336 337 String prefix = jconfig.getClasspathPrefix(); 339 if (prefix != null) { 340 StringTokenizer st = new StringTokenizer(prefix,File.pathSeparator); 341 while (st.hasMoreTokens()) { 342 classPath.add(st.nextToken()); 343 } 344 } 345 346 String suffix = jconfig.getClasspathSuffix(); 348 if (suffix != null) { 349 StringTokenizer st = new StringTokenizer(suffix,File.pathSeparator); 350 while (st.hasMoreTokens()) { 351 classPath.add(st.nextToken()); 352 } 353 } 354 355 return classPath; 356 357 } 358 359 367 368 public List getSystemClasspath() throws ConfigException { 369 if(!Boolean.getBoolean(com.sun.enterprise.server.PELaunch.USE_NEW_CLASSLOADER_PROPERTY)){ 370 List classPath = new ArrayList(); 371 372 JavaConfig jconfig = (JavaConfig) ConfigBeansFactory. 374 getConfigBeanByXPath(this.configContext, 375 ServerXPathHelper.XPATH_JAVACONFIG); 376 377 String prefix = jconfig.getClasspathPrefix(); 379 if (prefix != null) { 380 StringTokenizer st = new StringTokenizer(prefix,File.pathSeparator); 381 while (st.hasMoreTokens()) { 382 classPath.add(st.nextToken()); 383 } 384 } 385 386 String serverClasspath = jconfig.getServerClasspath(); 388 if (serverClasspath != null) { 389 StringTokenizer st = 390 new StringTokenizer(serverClasspath,File.pathSeparator); 391 while (st.hasMoreTokens()) { 392 classPath.add(st.nextToken()); 393 } 394 } 395 396 String suffix = jconfig.getClasspathSuffix(); 398 if (suffix != null) { 399 StringTokenizer st = new StringTokenizer(suffix,File.pathSeparator); 400 while (st.hasMoreTokens()) { 401 classPath.add(st.nextToken()); 402 } 403 } 404 405 return classPath; 406 } else { 407 return com.sun.enterprise.server.PELaunch.getServerClasspath(); 408 } 409 } 410 411 426 public List getSharedClasspath(boolean resolveOnDAS, String target) 427 throws ConfigException { 428 List classpath = new ArrayList(); 429 430 ConnectorModule[] mods = null; 431 if (resolveOnDAS && (target != null)) { 432 mods = ServerHelper.getAssociatedConnectorModules( 433 configContext, target); 434 } else { 435 mods = ((Applications)this.configBean).getConnectorModule(); 436 } 437 438 if (mods != null) { 439 for (int i=0; i<mods.length; i++) { 440 if (resolveOnDAS) { 441 classpath.add(RelativePathResolver.resolvePath( 442 mods[i].getLocation())); 443 } else { 444 classpath.add(mods[i].getLocation()); 445 } 446 } 447 } 448 449 return classpath; 450 451 } 452 453 454 460 public List getRmicOptions() throws ConfigException { 461 462 List rmicOptions = new ArrayList(); 463 464 JavaConfig jconfig = (JavaConfig) ConfigBeansFactory. 466 getConfigBeanByXPath(this.configContext, 467 ServerXPathHelper.XPATH_JAVACONFIG); 468 String options = jconfig.getRmicOptions(); 469 if (options == null) { 470 options = jconfig.getDefaultRmicOptions(); 471 } 472 StringTokenizer st = new StringTokenizer(options, " "); 473 while (st.hasMoreTokens()) { 474 String op = (String ) st.nextToken(); 475 rmicOptions.add(op); 476 _logger.log(Level.FINE, "Detected Rmic option: " + op); 477 } 478 479 return rmicOptions; 480 } 481 482 491 public List getJavacOptions() throws ConfigException { 492 493 List javacOptions = new ArrayList(); 494 495 JavaConfig jconfig = (JavaConfig) ConfigBeansFactory. 497 getConfigBeanByXPath(this.configContext, 498 ServerXPathHelper.XPATH_JAVACONFIG); 499 String options = jconfig.getJavacOptions(); 500 if (options == null) { 501 options = jconfig.getDefaultJavacOptions(); 502 } 503 StringTokenizer st = new StringTokenizer(options, " "); 504 while (st.hasMoreTokens()) { 505 String op = (String ) st.nextToken(); 506 if ( !(op.startsWith("-d") 507 || op.startsWith("-cp") || op.startsWith("-classpath")) ) { 508 javacOptions.add(op); 509 } else { 510 _logger.log(Level.WARNING, "core.unsupported_javac_option", op); 511 } 512 } 513 514 return javacOptions; 515 } 516 517 523 public boolean isEnvClasspathIgnored() throws ConfigException { 524 525 JavaConfig jconfig = (JavaConfig) ConfigBeansFactory. 527 getConfigBeanByXPath(this.configContext, 528 ServerXPathHelper.XPATH_JAVACONFIG); 529 530 return jconfig.isEnvClasspathIgnored(); 531 } 532 533 public final boolean isIASOwned(String id) 534 { 535 538 assert instanceEnvironment != null; 539 540 try 541 { 542 return instanceEnvironment.isIASOwned(getLocation(id)); 543 } 544 catch(Exception e) 545 { 546 return false; 547 } 548 } 549 550 558 public void refreshConfigContext(ConfigContext ctx) throws ConfigException { 559 560 this.configContext = ctx; 561 this.configBean = ConfigBeansFactory. 562 getConfigBeanByXPath(this.configContext, 563 ServerXPathHelper.XPATH_APPLICATIONS); 564 } 565 566 public void refreshConfigContext() throws ConfigException { 567 configContext.refresh(true); 568 configBean = ConfigBeansFactory.getConfigBeanByXPath(this.configContext, 569 ServerXPathHelper.XPATH_APPLICATIONS); 570 } 571 572 573 public InstanceEnvironment getInstanceEnvironment() { 574 return this.instanceEnvironment; 575 } 576 577 public boolean isShared(String id) throws ConfigException { 578 throw new UnsupportedOperationException ( 579 Localizer.getValue(ExceptionType.UNSUPPORTED, "isShared()")); 580 } 581 public void setShared(String modId, boolean shared) throws ConfigException { 582 throw new UnsupportedOperationException (Localizer.getValue( 583 ExceptionType.UNSUPPORTED, "setShared()")); 584 } 585 586 public String getStubLocation(String id) { 587 throw new UnsupportedOperationException (Localizer.getValue( 588 ExceptionType.UNSUPPORTED, "getStubLocation()")); 589 } 590 591 public boolean isRegistered(String id) { 592 return isRegistered(id, this.configBean); 593 } 594 595 public void saveConfigContext() throws ConfigException { 596 597 if(!this.useBackupServerXml) { 598 throw new ConfigException(Localizer.getValue(ExceptionType.CANT_APPLY)); 599 } 600 601 this.configContext.flush(); 602 } 603 604 public void applyServerXmlChanges() throws ConfigException { 605 if(!this.useBackupServerXml) { 606 throw new ConfigException(Localizer.getValue(ExceptionType.CANT_APPLY)); 607 } 608 this.configContext.flush(); 609 instanceEnvironment.applyServerXmlChanges(false); 610 } 611 612 public void setVirtualServers(String modId, String value) 613 throws ConfigException { 614 } 615 616 619 public String getContextRoot(String id) throws ConfigException { 620 throw new UnsupportedOperationException (Localizer.getValue( 621 ExceptionType.UNSUPPORTED, "getContextRoot()")); 622 } 623 624 627 public void setContextRoot(String id, String value) throws ConfigException { 628 throw new UnsupportedOperationException (Localizer.getValue( 629 ExceptionType.UNSUPPORTED, "setContextRoot()")); 630 } 631 632 635 public abstract Map getRegisteredDescriptors(); 636 637 643 public void registerDescriptor(String registrationName, Application descriptor) { 644 645 Map map = getRegisteredDescriptors(); 646 if (map==null) { 647 return; 648 } 649 map.put(registrationName, descriptor); 650 } 651 652 656 public Application getRegisteredDescriptor(String registrationName) { 657 Map map = getRegisteredDescriptors(); 658 if (map==null) { 659 return null; 660 } 661 return (Application) map.get(registrationName); 662 } 663 664 668 public void unregisterDescriptor(String registrationName) { 669 Map map = getRegisteredDescriptors(); 670 if (map==null) { 671 return; 672 } 673 map.remove(registrationName); 674 } 675 676 public void saveAppDescriptor(String appId, Application appDes, 678 String appDir, String generatedAppDir, boolean isVirtual) 679 throws ConfigException { 680 try { 681 if (isVirtual) { 682 appDes.setVirtual(true); 683 } 684 FileArchive archive = new FileArchive(); 685 archive.open(generatedAppDir); 686 687 FileArchive archive2 = new FileArchive(); 688 archive2.open(appDir); 689 690 DescriptorArchivist archivist = new DescriptorArchivist(); 691 archivist.write(appDes, archive2, archive); 692 693 Archivist.copyExtraElements(archive2, archive); 695 } catch (Throwable t) { 696 throw new ConfigException( 697 Localizer.getValue(ExceptionType.FAIL_DD_SAVE, appId), t); 698 } 699 } 700 701 703 712 boolean isReferenced(String appId) 713 { 714 try { 715 return ServerHelper.serverReferencesApplication(this.configContext, 716 instanceEnvironment.getName(), appId); 717 } catch (ConfigException ex) { 718 _logger.log(Level.WARNING, "isReferenced.unexpectedException", ex); 720 return false; 721 } 722 } 723 724 726 731 public ConfigContext getConfigContext() { 732 return this.configContext; 733 } 734 735 public abstract String getLocation(String id) throws ConfigException; 736 public abstract void setLocation(String id, String location) throws ConfigException; 737 public abstract String getGeneratedXMLLocation(String id); 738 public abstract boolean isEnabled(String id) throws ConfigException; 739 public abstract void setEnable(String id, boolean enabled) throws ConfigException; 740 public abstract boolean isSystem(String id) throws ConfigException; 741 public abstract boolean isSystemAdmin(String id) throws ConfigException; 742 public abstract void setOptionalAttributes(String id, Properties optionalAttributes) throws ConfigException; 743 public abstract String getDescription(String id) throws ConfigException; 744 public abstract void setDescription(String id, String desc) throws ConfigException; 745 protected abstract boolean isRegistered(String id, ConfigBean bean); 746 public abstract void remove(String name) throws ConfigException; 747 public abstract List listIds() throws ConfigException; 748 749 763 protected void readPersistenceDeploymentDescriptors( 764 String appDir, Application application) 765 throws IOException , SAXParseException { 766 FileArchive archive = new FileArchive(); 767 archive.open(appDir); 768 try { 769 ApplicationArchivist.readPersistenceDeploymentDescriptorsRecursively( 770 archive, application); 771 } finally { 772 archive.close(); 773 } 774 } 775 } 776 | Popular Tags |