FileDocCategorySizeDatePackage
BaseManager.javaAPI DocGlassfish v2 API30432Thu May 31 09:04:58 BST 2007com.sun.enterprise.instance

BaseManager

public abstract class BaseManager extends Object
author
sridatta

Fields Summary
protected volatile com.sun.enterprise.config.ConfigContext
configContext
protected volatile com.sun.enterprise.config.ConfigBean
configBean
private final com.sun.enterprise.config.serverbeans.DasConfig
appConfig
protected final InstanceEnvironment
instanceEnvironment
protected final boolean
useBackupServerXml
protected static final String
SYSTEM_PREFIX
protected static final String
SYSTEM_ADMIN_PREFIX
protected static final Logger
_logger
private static final String
DEBUG_OPTION
javac debug option
private static final String
OPTIMIZE_OPTION
javac optimize option
Constructors Summary
public BaseManager(InstanceEnvironment env, boolean useBackupServerXml)

    
        
              

        instanceEnvironment = env;
        try {
            this.useBackupServerXml = useBackupServerXml;
				//_logger.log(Level.FINE,"core.serverxml_usage",((useBackupServerXml)?"back":"hot"));

            String fileUrl;
            if(useBackupServerXml) {
                fileUrl = instanceEnvironment.getBackupConfigFilePath();
            } else {
                fileUrl = instanceEnvironment.getConfigFilePath();
            }
            
            if (useBackupServerXml) {
                AdminService as = AdminService.getAdminService();
                if (as != null) {
                    AdminContext ac = as.getAdminContext();
                    if (ac != null) {
                        configContext = ac.getAdminConfigContext();
                    }
                }
            }
            if (configContext == null) {
                configContext = ConfigFactory.createConfigContext(fileUrl);
            }
            
            configBean = ConfigBeansFactory.getConfigBeanByXPath(this.configContext, 
                                        ServerXPathHelper.XPATH_APPLICATIONS);
            //RAMAKANTH
            if (configBean == null) {
                configBean = new Applications();
            }

            //ROB: config changes
            // use 'appConfigTemp' so that 'appConfig' can be 'final'
            DasConfig appConfigTemp =
                ServerBeansFactory.getDasConfigBean(configContext);
            //RAMAKANTH
            //Why?? what does this mean??
            if (appConfigTemp == null) {
                appConfigTemp = new DasConfig();
            }
            
            appConfig   = appConfigTemp;

        }
        catch(Exception e) {
			throw new ConfigException(Localizer.getValue(ExceptionType.MISSING_SERVER_NODE), e);
        }
    
Methods Summary
public voidapplyServerXmlChanges()

        if(!this.useBackupServerXml) {
			throw new ConfigException(Localizer.getValue(ExceptionType.CANT_APPLY));	
        }
        this.configContext.flush();
        instanceEnvironment.applyServerXmlChanges(false);
    
public java.lang.String[]getBytecodeProcessorClassNames()
Returns an array of bytecode preprocessor class name(s) as set in server.xml.

throws
ConfigException
return
- an array of preprocessor class names.

        String result[] = null;        
        //ROB: config changes - use of domain.xml
        JavaConfig jc = ServerBeansFactory.getJavaConfigBean(configContext);
        if (jc != null) {
           String value = jc.getBytecodePreprocessors();
           _logger.log(Level.INFO,
              "core.preprocessor_class_name", value);
           // Split the comma delimited list of bytecode preprocessor
           // class names into the result array
           result = value.split(",");
        }                 

        return result;
    
public com.sun.enterprise.config.ConfigContextgetConfigContext()
Returns the config context associated with this manager.

return
config context associated with this manager

        return this.configContext;
    
public java.lang.StringgetContextRoot(java.lang.String id)
override for Web Modules

		throw new UnsupportedOperationException(Localizer.getValue(
				ExceptionType.UNSUPPORTED, "getContextRoot()"));
    
public abstract java.lang.StringgetDescription(java.lang.String id)

public com.sun.enterprise.deployment.ApplicationgetDescriptor(java.lang.String modId, java.lang.ClassLoader cl, boolean validateXML)
Returns a virtual application for standalone module or a fully initialized application object from the deployment descriptors

param
modId web module id
return
the deployment descriptor object for this web module
throws
ConfigException if unable to load the deployment descriptor

	
	return getDescriptor(modId, cl, getLocation(modId), validateXML);
    
public abstract com.sun.enterprise.deployment.ApplicationgetDescriptor(java.lang.String modId, java.lang.ClassLoader cl, java.lang.String loc, boolean validateXML)
Returns a virtual application for standalone module or a fully initialized application object from the deployment descriptors

param
modId web module id
return
the deployment descriptor object for this web module
throws
ConfigException if unable to load the deployment descriptor

public com.sun.enterprise.deployment.ApplicationgetDescriptor(java.lang.String appID)
This method only returns from cache. Call it only when you are are sure the application should be in the instance managers.

        return getRegisteredDescriptor(appID);
    
public abstract java.lang.StringgetGeneratedXMLLocation(java.lang.String id)

public InstanceEnvironmentgetInstanceEnvironment()

        return this.instanceEnvironment;
    
public java.util.ListgetJavacOptions()
Returns the javac options for deployment. The options can be anything except "-d", "-classpath" and "-cp". It tokenizes the options by blank space between them. It does not to detect options like "-g -g -g" since javac handles it.

return
javac options as of type java.lang.String
throws
ConfigException if an error while reading server.xml

        
        List javacOptions = new ArrayList();

        // bean that represents the java configuration
        JavaConfig jconfig = (JavaConfig) ConfigBeansFactory.
                                    getConfigBeanByXPath(this.configContext, 
                                        ServerXPathHelper.XPATH_JAVACONFIG);
        String options = jconfig.getJavacOptions();
        if (options == null) {
            options = jconfig.getDefaultJavacOptions(); 
        }
        StringTokenizer st = new StringTokenizer(options, " ");
        while (st.hasMoreTokens()) {
            String op = (String) st.nextToken();
            if ( !(op.startsWith("-d") 
                || op.startsWith("-cp") || op.startsWith("-classpath")) ) {
                javacOptions.add(op);
            } else {
				_logger.log(Level.WARNING, "core.unsupported_javac_option", op);
            }
        }
        
        return javacOptions;
    
public abstract java.lang.StringgetLocation(java.lang.String id)

public abstract javax.enterprise.deploy.shared.ModuleTypegetModuleType()

return
the module type this class is managing

public com.sun.enterprise.deployment.ApplicationgetRegisteredDescriptor(java.lang.String registrationName)

return
a registered application descriptor if exists
param
the registration name for the application descriptor

        Map map = getRegisteredDescriptors();
        if (map==null) {
            return null;
        }
        return (Application) map.get(registrationName);
    
public abstract java.util.MapgetRegisteredDescriptors()

return
the registered descriptors map

public longgetReloadPollIntervalInMillis()
Returns the reload polling interval in milli-seconds.

return
reload polling interval in milli-seconds


        // pool interval from server configuration in seconds
        String intv = appConfig.getDynamicReloadPollIntervalInSeconds(); 


        long pollIntv;

        try {
            pollIntv = Long.parseLong(intv) * 1000;
        } catch (NumberFormatException nme) {

            // use the default interval 
            intv = appConfig.getDefaultDynamicReloadPollIntervalInSeconds();

            try {
                pollIntv = Long.parseLong(intv) * 1000;
            } catch (NumberFormatException ne) { 
                // this should never happen
                pollIntv = 2000l;
            }
        }

        return pollIntv;
    
public java.util.ListgetRmicOptions()
Returns the rmic options for deployment.

return
rmic options as of type java.lang.String
throws
ConfigException if an error while reading server.xml

        
        List rmicOptions = new ArrayList();

        // bean that represents the java configuration
        JavaConfig jconfig = (JavaConfig) ConfigBeansFactory.
                                    getConfigBeanByXPath(this.configContext, 
                                        ServerXPathHelper.XPATH_JAVACONFIG);
        String options = jconfig.getRmicOptions();
        if (options == null) {
            options = jconfig.getDefaultRmicOptions(); 
        }
        StringTokenizer st = new StringTokenizer(options, " ");
        while (st.hasMoreTokens()) {
            String op = (String) st.nextToken();
            rmicOptions.add(op);
            _logger.log(Level.FINE, "Detected Rmic option: " + op);
        }
        
        return rmicOptions;
    
public java.util.ListgetSharedClasspath(boolean resolveOnDAS, java.lang.String target)
Per the platform specification, connector classes are to be availble to all applications, i.e. a connector deployed to target foo should be available to apps deployed on foo (and not target bar). In that case, we will need to figure out all connector module deployed to the target on which the application is deployed. Resolving the classpath accordlingly.

param
resolveOnDAS Whether to resolve connector classpath or not. This should only be true when running on DAS.
param
target The target on which the application is to be deployed

        List classpath = new ArrayList();

        ConnectorModule[] mods = null;
        if (resolveOnDAS && (target != null)) {
            mods = ServerHelper.getAssociatedConnectorModules(
                        configContext, target);
        } else {
            mods = ((Applications)this.configBean).getConnectorModule();
        }

        if (mods != null) {
            for (int i=0; i<mods.length; i++) {
                if (resolveOnDAS) {
                    classpath.add(RelativePathResolver.resolvePath(
                        mods[i].getLocation()));
                } else {
                    classpath.add(mods[i].getLocation());
                }
            }
        }
        
        return classpath;
        
    
public java.lang.StringgetStubLocation(java.lang.String id)

		throw new UnsupportedOperationException(Localizer.getValue(
				ExceptionType.UNSUPPORTED, "getStubLocation()"));
    
public java.util.ListgetSystemCPathPrefixNSuffix()
Returns the java class path for this server instance. It includes the "classpath-prefix" and "classpath-suffix". This method is called during deployment to construct the class loader. Deployment assumes that server class path will not differ between admin instance and a regular instance. So, only prefix and suffix are added to the class path.

return
the system class path that includes only prefix & suffix
throws
ConfigException if an error while reading the server.xml


        List classPath = new ArrayList();

        // bean that represents the java configuration
        JavaConfig jconfig = (JavaConfig) ConfigBeansFactory.
                                    getConfigBeanByXPath(this.configContext, 
                                        ServerXPathHelper.XPATH_JAVACONFIG);

        // add the class path prefix first
        String prefix = jconfig.getClasspathPrefix();
        if (prefix != null) {
            StringTokenizer st = new StringTokenizer(prefix,File.pathSeparator);
            while (st.hasMoreTokens()) {
                classPath.add(st.nextToken());
            }
        }

        // adds the class path suffix to the list
        String suffix = jconfig.getClasspathSuffix();
        if (suffix != null) {
            StringTokenizer st = new StringTokenizer(suffix,File.pathSeparator);
            while (st.hasMoreTokens()) {
                classPath.add(st.nextToken());
            }
        }

        return classPath;

    
public java.util.ListgetSystemClasspath()
Returns the system class path for this server instance. It includes the "classpath-prefix", "classpath" and "classpath-suffix".

return
the system class path
throws
ConfigException if an error while reading the server.xml

    if(!Boolean.getBoolean(com.sun.enterprise.server.PELaunch.USE_NEW_CLASSLOADER_PROPERTY)){
        List classPath = new ArrayList();

        // bean that represents the java configuration
        JavaConfig jconfig = (JavaConfig) ConfigBeansFactory.
                                    getConfigBeanByXPath(this.configContext, 
                                        ServerXPathHelper.XPATH_JAVACONFIG);

        // add the class path prefix first
        String prefix = jconfig.getClasspathPrefix();
        if (prefix != null) {
            StringTokenizer st = new StringTokenizer(prefix,File.pathSeparator);
            while (st.hasMoreTokens()) {
                classPath.add(st.nextToken());
            }
        }

        // adds the server classpath to the list
        String serverClasspath = jconfig.getServerClasspath();
        if (serverClasspath != null) {
            StringTokenizer st = 
                new StringTokenizer(serverClasspath,File.pathSeparator);
            while (st.hasMoreTokens()) {
                classPath.add(st.nextToken());
            }
        }

        // adds the class path suffix to the list
        String suffix = jconfig.getClasspathSuffix();
        if (suffix != null) {
            StringTokenizer st = new StringTokenizer(suffix,File.pathSeparator);
            while (st.hasMoreTokens()) {
                classPath.add(st.nextToken());
            }
        }

        return classPath;
    } else {
        return com.sun.enterprise.server.PELaunch.getServerClasspath();
    }
    
public booleanisByteCodePreprocessingEnabled()
Returns a boolean indicating whether or not bytecode preprocessing is enabled. The bytecode preprocessor is deemed to be enabled if if a value for bytecode-preprocessors is set in the java config.

throws
ConfigException - enabled via server.xml
return
- true if enabled, otherwise false.

        
        boolean result = false; 
        //ROB: config changes
        JavaConfig jc = ServerBeansFactory.getJavaConfigBean(configContext); 
        if (jc != null) {
            if (jc.getBytecodePreprocessors() != null) {
                result = true;
            }
        }
        return result;
    
public booleanisDynamicReloadEnabled()
Returns true if dynamic reloading is enabled.

return
true if dynamic reloading is enabled

        //ROB: config changes
        //return ((Applications)this.configBean).isDynamicReloadEnabled(); 
        return appConfig.isDynamicReloadEnabled();
    
public abstract booleanisEnabled(java.lang.String id)

public booleanisEnvClasspathIgnored()
Returns true if environment class path ignore flag is turned on.

return
true if environment class path ignore flag is turned on
throws
ConfigException if an error while reading the server.xml


        // bean that represents the java configuration
        JavaConfig jconfig = (JavaConfig) ConfigBeansFactory.
                                    getConfigBeanByXPath(this.configContext, 
                                       ServerXPathHelper.XPATH_JAVACONFIG);

        return jconfig.isEnvClasspathIgnored();
    
public final booleanisIASOwned(java.lang.String id)

		// WBN 2/7/2002 -- I don't think this bit of info is ever going
		// to be persisted.  Here is a M^2 technology way of doing it.

		assert instanceEnvironment != null;

		try
		{
			return instanceEnvironment.isIASOwned(getLocation(id));
		}
		catch(Exception e)
		{
			return false;
		}
	
booleanisReferenced(java.lang.String appId)
Returns true if the given application is referenced by this server instance.

param
appId application id
return
true if the named application is used/referred by this server
throws
ConfigException if an error while paring domain.xml

        try {
            return ServerHelper.serverReferencesApplication(this.configContext,
                instanceEnvironment.getName(), appId);
        } catch (ConfigException ex) {
            //This represents an unexpected exception. Log and return false
            _logger.log(Level.WARNING, "isReferenced.unexpectedException", ex);
            return false;
        }       
    
public booleanisRegistered(java.lang.String id)

        return isRegistered(id, this.configBean);
    
protected abstract booleanisRegistered(java.lang.String id, com.sun.enterprise.config.ConfigBean bean)

public static java.lang.StringisRegisteredAnywhere(InstanceEnvironment ienv, java.lang.String id)

author
bnevins 9-23-03 for S1AS 8.0PE The namespace has been flattened for 8.0 This method is called to see if a name is registered for a different type of J2EE Deployable Object. Deployment Backend itself will check the Manager for the same type of object to see if it is a re-deploy. If that check is negative, it will call here to check all the other types. If a different type is registered with the same name, Deployment will fail the deployment instead of wiping out the other app/module with the same name.
return
A String with the name of the deployable object type -- if the name is registered, otherwise null.

        try {
            BaseManager[] mans = new BaseManager[]{
                new WebModulesManager(ienv), 
                new EjbModulesManager(ienv), 
                new AppclientModulesManager(ienv), 
                new ConnectorModulesManager(ienv),
                new AppsManager(ienv)
            };

            String[] errors = new String[] {"Web Module", "EJB Module", "App Client Module", "Connector Module", "Application"};

            for(int i = 0; i < mans.length; i++){
                if(mans[i].listIds().contains(id)) {
                    return errors[i];
                }
            }
        }
        catch(Exception e){
        }
        return null;
    
public booleanisShared(java.lang.String id)

		throw new UnsupportedOperationException(
			Localizer.getValue(ExceptionType.UNSUPPORTED, "isShared()"));
    
public abstract booleanisSystem(java.lang.String id)

public abstract booleanisSystemAdmin(java.lang.String id)

public abstract booleanisSystemPredeployed(java.lang.String id)

public abstract java.util.ListlistIds()

protected com.sun.enterprise.deployment.deploy.shared.FileArchiveopenDDArchive(java.lang.String appId, java.lang.String appDir)

        FileArchive in = new FileArchive();
        if (isSystemPredeployed(appId)) {
            in.open(appDir);
        } else {
            String xmlDir = getGeneratedXMLLocation(appId);
            if (FileUtils.safeIsDirectory(xmlDir)) {
                in.open(xmlDir);
            } else {
                // log a warning message in the server log
                _logger.log(Level.WARNING, "core.no_xmldir",
                    new Object[]{xmlDir, appDir});
                in.open(appDir);
            }
        }
        return in;
    
protected voidreadPersistenceDeploymentDescriptors(java.lang.String appDir, com.sun.enterprise.deployment.Application application)
This method is needed because we need to read persistence descriptors from the original app exploded dir as opposed to generated dir because generated XML do not contain any information about PUs. One way to avoid this would be to write out PU details in sun-application.xml, but we have not done that yet.

param
appDir directory where application was exploded (this is not same as the directory where generated XML files are written).
param
application the application object whose persistence units will be read. This method will read all the persistence units recurssively and register at appropriate level.
throws
IOException
throws
SAXParseException

        FileArchive archive = new FileArchive();
        archive.open(appDir);
        try {
            ApplicationArchivist.readPersistenceDeploymentDescriptorsRecursively(
                    archive, application);
        } finally {
            archive.close();
        }
    
public synchronized voidrefreshConfigContext(com.sun.enterprise.config.ConfigContext ctx)
Refreshes config context using the given context. This method is called during dynamic deploy/undeploy of applications and stand alone modules.

param
ctx new config context (from the event)
throws
ConfigException if null config context or an error while retrieving the config bean


        this.configContext = ctx;
        this.configBean = ConfigBeansFactory.
                getConfigBeanByXPath(this.configContext,
                                    ServerXPathHelper.XPATH_APPLICATIONS);
    
public synchronized voidrefreshConfigContext()

        configContext.refresh(true);
        configBean = ConfigBeansFactory.getConfigBeanByXPath(this.configContext,
                                    ServerXPathHelper.XPATH_APPLICATIONS);
    
public voidregisterDescriptor(java.lang.String registrationName, com.sun.enterprise.deployment.Application descriptor)
register an new application descriptor in the map

param
registrationName is the registration name for the descriptor
param
descriptor the new application to register

        
        Map map = getRegisteredDescriptors();
        if (map==null) {
            return;
        } 
        map.put(registrationName, descriptor);
    
public abstract voidremove(java.lang.String name)

public voidsaveAppDescriptor(java.lang.String appId, com.sun.enterprise.deployment.Application appDes, java.lang.String appDir, java.lang.String generatedAppDir, boolean isVirtual)

        try {
            if (isVirtual) {
                appDes.setVirtual(true);
            }
            SerializedDescriptorHelper.store(appId, this, appDes);

            FileArchive archive = new FileArchive();
            archive.open(generatedAppDir);

            FileArchive archive2 = new FileArchive();
            archive2.open(appDir); 

            DescriptorArchivist archivist = new DescriptorArchivist();
            archivist.write(appDes, archive2, archive);

            // copy the additional webservice elements etc
            Archivist.copyExtraElements(archive2, archive);
        } catch (Throwable t) {
                        throw new ConfigException(
                Localizer.getValue(ExceptionType.FAIL_DD_SAVE, appId), t);
        }
    
public voidsaveConfigContext()


        if(!this.useBackupServerXml) {
			throw new ConfigException(Localizer.getValue(ExceptionType.CANT_APPLY));	
        }
			
        this.configContext.flush();
    
public voidsetContextRoot(java.lang.String id, java.lang.String value)
override for Web Modules

		throw new UnsupportedOperationException(Localizer.getValue(
				ExceptionType.UNSUPPORTED, "setContextRoot()"));
    
public abstract voidsetDescription(java.lang.String id, java.lang.String desc)

public abstract voidsetEnable(java.lang.String id, boolean enabled)

public abstract voidsetLocation(java.lang.String id, java.lang.String location)

public abstract voidsetOptionalAttributes(java.lang.String id, java.util.Properties optionalAttributes)

public voidsetShared(java.lang.String modId, boolean shared)

		throw new UnsupportedOperationException(Localizer.getValue(
				ExceptionType.UNSUPPORTED, "setShared()"));
    
public voidsetVirtualServers(java.lang.String modId, java.lang.String value)

    
public voidunregisterDescriptor(java.lang.String registrationName)

return
a registered application descriptor if exists
param
the registration name for the application descriptor

        Map map = getRegisteredDescriptors();
        if (map==null) {
            return;
        }
        map.remove(registrationName);