FileDocCategorySizeDatePackage
AppsManager.javaAPI DocGlassfish v2 API20595Fri May 04 22:34:58 BST 2007com.sun.enterprise.instance

AppsManager

public class AppsManager extends BaseManager
Provides access to application information per server instance.

Fields Summary
private static Map
apps
Constructors Summary
public AppsManager(InstanceEnvironment env)

        super(env, true);
    
public AppsManager(InstanceEnvironment env, boolean useBackupServerXml)

        super(env, useBackupServerXml);
        //FIXME: HACK START
	J2eeApplication[] jArray = ((Applications)configBean).getJ2eeApplication();
	if(jArray!=null) {
            for(int i=0;i<jArray.length;i++) {
                jArray[i].setConfigContext(configContext);
		jArray[i].setXPath(ServerXPathHelper.getAppIdXpathExpression(jArray[i].getName()));
            }
	}
	//FIXME: HACK END
    
Methods Summary
public com.sun.enterprise.config.serverbeans.J2eeApplication[]getAllApps()
Returns an array of all applications deployed with the server.

        J2eeApplication[] apps = ((Applications)this.configBean).getJ2eeApplication();
        if(apps == null) return new J2eeApplication[0];

        ArrayList list = new ArrayList();
        for (int i=0; i<apps.length; i++) {            
            // add the application to the list if it is referenced
            // by this server
            if ( isReferenced(apps[i].getName()) ) {
                list.add(apps[i]);
            }
        }
        // returns an array of applications referenced by this server
        J2eeApplication[] refList = new J2eeApplication[list.size()];
        return ( (J2eeApplication[]) list.toArray(refList) );
	
public com.sun.enterprise.deployment.ApplicationgetAppDescriptor(java.lang.String appID, java.lang.ClassLoader parentClassLoader)
This method is called by ResourcesUtil during server start up and by ApplicationLoader when the dd for this app is not registered. We need to construct the top level application and its classloader before calling getAppDescriptor(Application) to fully populate the application object.


        Application application = getRegisteredDescriptor(appID);
        if (application != null) {
            return application;
        }
        Application deserializedApplication = null;

        // Try to load the previously-serialized form of the descriptor.
        SerializedDescriptorHelper.Loader sdLoader = 
                SerializedDescriptorHelper.load(appID, this);
        try {
            // partially load the deployment descriptor...
            ApplicationArchivist archivist = new ApplicationArchivist();
            FileArchive appArchive = new FileArchive();
            appArchive.open(getLocation(appID));

            //for upgrade senario, we still load from the original
            //application repository for application.xml first
            if (!archivist.hasStandardDeploymentDescriptor(appArchive)) {
                //read from generated/xml location
                appArchive.open(getGeneratedXMLLocation(appID));
            }

            deserializedApplication = sdLoader.getApplication();
            if (deserializedApplication != null) {
                application = deserializedApplication;
            } else {
                // There was no serialized descriptor file or it could not
                // be loaded, so load the application info from the XML descriptors.
                application = Application.createApplication(appArchive,false);
            }
            application.setRegistrationName(appID);
            String moduleRoot = getLocation(application.getRegistrationName());
            String[] classPaths = (String[]) EJBClassPathUtils.getAppClasspath(
                                                            application, this).toArray(new String[0]);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "[AppsManager] :: appID " + appID + " classpaths " 
                                                + classPaths + " moduleRoot " + moduleRoot 
                                                + " parentClassLoader " + parentClassLoader);
            }
            ClassLoader cl = EJBClassPathUtils.createEJBClassLoader(classPaths,
                                                            moduleRoot , appID, parentClassLoader,
                                                            application.getModuleType());
            application.setClassLoader(cl);
        } catch (Exception confEx) {
            _logger.log(Level.SEVERE,"loader.error_while_loading_app_desc", confEx);
            throw new ConfigException(confEx);
        }

        Application fullyLoadedApp = getAppDescriptor(application);
        
        // If needed, write out the new app into the serialized descriptor file.
        sdLoader.store(fullyLoadedApp);
        
        return fullyLoadedApp;
    
public com.sun.enterprise.deployment.ApplicationgetAppDescriptor(com.sun.enterprise.deployment.Application application)
Returns the deployment descriptor object for the application DD. Given the top level application object, this method populates it with all the submodule information by loading from disc.

param
application the top level application
return
the deployment descriptor object for the given application id
throws
ConfigException if unable to load the deployment descriptor


        if (application == null) {
            throw new ConfigException("Application object should not be null");
        }

        ClassLoader cl = application.getClassLoader();

        // We need to use a temp CL until we are done with validate().
        // See https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
        // for details.
        if (cl instanceof InstrumentableClassLoader) {
            ClassLoader tcl = InstrumentableClassLoader.class.cast(cl).copy();
            application.setClassLoader(tcl);
            // set it in all the bundles as well,
            for (BundleDescriptor bd : (Collection<BundleDescriptor>)
                    application.getBundleDescriptors()) {
                bd.setClassLoader(tcl);
            }
        }
        String appId = application.getRegistrationName();
        
        // we need to load this puppy, save it in the cache...
        try {
            String appDir = getLocation(appId);
            FileArchive in = openDDArchive(appId, appDir);

            ApplicationArchivist archivist = new ApplicationArchivist();
            archivist.readModulesDescriptors(application, in);
            archivist.readRuntimeDeploymentDescriptor(in, application);
            if(!isSystemAdmin(appId) && !isSystem(appId)) {
                // we need to read persistence descriptors separately
                // because they are read from appDir as oppsed to xmlDir.
                readPersistenceDeploymentDescriptors(appDir, application);
            }
            archivist.setDescriptor(application);

            // use temp CL that is set in the application. For details,
            // see https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
            archivist.validate(application.getClassLoader());
            
            application.setGeneratedXMLDirectory(getGeneratedXMLLocation(appId));
            
            if (!application.getWebServiceDescriptors().isEmpty()) {
                ModuleContentLinker visitor = new ModuleContentLinker(in);
                application.visit((com.sun.enterprise.deployment.util.ApplicationVisitor) visitor);
            }

            // Now that validate() is called, we can set the actual CL.
            // See https://glassfish.dev.java.net/issues/show_bug.cgi?id=223
            // for details.
            application.setClassLoader(cl);
            // set it in all the bundles as well,
            for (BundleDescriptor bd : (Collection<BundleDescriptor>)
                    application.getBundleDescriptors()) {
                bd.setClassLoader(cl);
            }
            registerDescriptor(appId, application);

            return application;
        } catch (ConfigException ce) {
            throw ce;
        } catch (Throwable t) {
			throw new ConfigException(
                Localizer.getValue(ExceptionType.FAIL_DD_LOAD, appId), t);
        }
    
public java.lang.StringgetDescription(java.lang.String id)

        return getJ2eeApplication(id).getDescription();
    
public com.sun.enterprise.deployment.ApplicationgetDescriptor(java.lang.String appID, java.lang.ClassLoader cl, java.lang.String loc, boolean validateXML)
This method only returns from cache. To force the creation of an application object, see getAppDescriptor method. Only parameter appID is used. The rest of the params are kept for backward compatibility purpose until we clean up the instance managers completely.

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

        ApplicationEnvironment env = instanceEnvironment.getApplicationEnvironment(name);
        return env.getAppGeneratedXMLPath();
    
private com.sun.enterprise.config.serverbeans.J2eeApplicationgetJ2eeApplication(java.lang.String appId)


        J2eeApplication app = (J2eeApplication)
            ((Applications)this.configBean).getJ2eeApplicationByName(appId);

        if(app == null)
			throw new ConfigException(
                Localizer.getValue(ExceptionType.APP_NOT_EXIST));
        return app;
        
    
public java.lang.StringgetJSPLocation(java.lang.String appId)


        ApplicationEnvironment env = 
            instanceEnvironment.getApplicationEnvironment(appId);
        return env.getAppJSPPath();
    
public java.lang.StringgetLocation(java.lang.String appId)

        J2eeApplication app = (J2eeApplication) getJ2eeApplication(appId);
        InstanceEnvironment instEnv;
        if ((instEnv = getInstanceEnvironment()) == null) {
            throw new ConfigException("instEnv was null");
        }
        PropertyResolver resolver = new PropertyResolver(super.configContext, 
                instEnv.getName());
        String appLocation;
        if ((appLocation = app.getLocation()) == null) {
            throw new ConfigException("appLocation was null");
        };
        String resolvedPath = resolver.resolve(appLocation);
        return resolvedPath;
        
    
public javax.enterprise.deploy.shared.ModuleTypegetModuleType()

        return ModuleType.EAR;
    
public java.util.MapgetRegisteredDescriptors()

return
the registered descriptors map

                
        if (apps==null) {
            synchronized (AppsManager.class) {
                if (apps==null) {
                    apps = new HashMap();
                }
            }
        } 
        return apps;
    
public java.lang.StringgetStubLocation(java.lang.String appId)


        ApplicationEnvironment env = 
            instanceEnvironment.getApplicationEnvironment(appId);
        return env.getAppStubPath();
    
public java.lang.StringgetVirtualServersByAppName(java.lang.String appName)

            return ServerBeansFactory.getVirtualServersByAppName(configContext, appName);
    
public booleanisEnabled(java.lang.String appId)

        return getJ2eeApplication(appId).isEnabled();
    
public booleanisJavaWebStartEnabled(java.lang.String appId)
Reports whether Java Web Start access is enabled for the app clients in the specified application.

param
appId the module ID of the app to check
return
boolean indicating whether access is permitted

        return getJ2eeApplication(appId).isJavaWebStartEnabled();
    
protected booleanisRegistered(java.lang.String appId, com.sun.enterprise.config.ConfigBean bean)

        ConfigBean cb = null;
        try {
            cb = ((Applications)bean).getJ2eeApplicationByName(appId);
        } catch(Exception cn) {
        }
        
        if(cb != null) return true;
        return false;
    
public booleanisSystem(java.lang.String appId)
Checks whether this application is a system app ResourceType in domain.xml should start with "system-"

return
true if resourceType starts with "system-"

	   J2eeApplication ja = getJ2eeApplication(appId);
	   String resourceType = ja.getObjectType();
	   if(resourceType.startsWith(SYSTEM_PREFIX))
	       return true;
	   else
	       return false;
	
public booleanisSystemAdmin(java.lang.String appId)
Checks whether this application is a system admin app ResourceType in domain.xml should start with "system-admin"

return
true if resourceType starts with "system-admin"

           J2eeApplication ja = getJ2eeApplication(appId);
           String resourceType = ja.getObjectType();
           if(resourceType.startsWith(SYSTEM_ADMIN_PREFIX))
               return true;
           else
               return false;
        
public booleanisSystemPredeployed(java.lang.String appId)
Checks whether this module is a pre-deployed system module ResourceType in domain.xml should start with "system" Also it should be directory deployed.

return
true if its a predeployed system module

        J2eeApplication ja = getJ2eeApplication(appId);
        String resourceType = ja.getObjectType();
        boolean isDirectoryDeployed = ja.isDirectoryDeployed();
        if (resourceType.startsWith(SYSTEM_PREFIX) && isDirectoryDeployed) {
            return true;
        } else {
            return false;
        }
    
public java.util.ListlistIds()
Returns a list of all applications deployed with the server.

        ArrayList arr = new ArrayList();
        J2eeApplication[] apps = ((Applications)this.configBean).getJ2eeApplication();
        if(apps == null) return arr;
            
        for (int i=0;i<apps.length;i++) {
            String name = apps[i].getName();
            // adds the application to the list if 
            // it is referenced by this server             
            if ( isReferenced(name) ) {
                arr.add(name);
            }
        }        
        return arr;
    
public voidremove(java.lang.String appId)
Removes the application information from the configuration file.

param
appId a unique identifier for the application

        J2eeApplication backJa = (J2eeApplication)
            ((Applications)configBean).getJ2eeApplicationByName(appId);
        ((Applications)configBean).removeJ2eeApplication(backJa);
    
public voidsetDescription(java.lang.String id, java.lang.String desc)

        getJ2eeApplication(id).setDescription(desc);
    
public voidsetEnable(java.lang.String appId, boolean enabled)
Identifies whether an application is enabled or disabled.

param
appId unique idenitifier for the application
param
isEnabled flag for enabling or disabling the application

        getJ2eeApplication(appId).setEnabled(enabled);
    
public voidsetLocation(java.lang.String appId, java.lang.String location)
Set the location for an App

param
appId unique idenitifier for the application
param
location

        getJ2eeApplication(appId).setLocation(location);
    
public voidsetOptionalAttributes(java.lang.String appId, java.util.Properties optionalAttributes)
Set the optional attributes for an App

param
appId unique idenitifier for the application
param
optionalAttributes - pairs tag/value to set

        if(optionalAttributes!=null) {
            J2eeApplication ja = getJ2eeApplication(appId);
            Enumeration tags = optionalAttributes.keys();
            while(tags.hasMoreElements())
            {
                String tag = (String)tags.nextElement();
                String value = optionalAttributes.getProperty(tag);
                ja.setAttributeValue(tag, value);
            }
        }