FileDocCategorySizeDatePackage
ApplicationManager.javaAPI DocGlassfish v2 API13194Fri May 04 22:35:00 BST 2007com.sun.enterprise.tools.deployment.main

ApplicationManager

public class ApplicationManager extends Object implements com.sun.enterprise.util.NotificationListener
Objects of this type manage applications within a tool.
author
Danny Coward

Fields Summary
public static String
ACTIVE_CHANGED
Notification type for change of active application.
public static String
APPLICATION_CHANGED
Notification type for an application change.
public static String
APPLICATION_LIST_CHANGED
Notification type that the list of apps changed in this manager.
public static String
LISTENER_ADDED
Notification type that a listener was added.
public static String
APPLICATION_ADDED
Notification type for addition of an application.
public static String
APPLICATION_REMOVED
Notification type that an application was removed.
public static String
APPLICATION_PROPERTY
Notification property to store the application that changed.
private Application
activeApplication
private Vector
applications
private Vector
applicationListeners
private File
preferencesDirectory
private File
temp
private static String
CFG_APP_FILE
private String
configFileName
Constructors Summary
public ApplicationManager(File preferencesDirectory, File temp)
Construct a new application manager storing its preferences in the given directory.

    
                     
         
	this.preferencesDirectory = preferencesDirectory;
	this.temp = temp;
    
Methods Summary
public voidaddApplication(Application application)
Adds an application to the manager.

	String newName = this.getUniqueApplicationName(application.getName());
	application.setName(newName);
	applications.addElement(application);
	application.addNotificationListener(this);
	this.notify(APPLICATION_ADDED, APPLICATION_PROPERTY, application);
	this.setActiveApplication(application);	
    
public voidaddNotificationListener(com.sun.enterprise.util.NotificationListener nl)
Register for state changes.

	applicationListeners.addElement(nl);
	this.notify(LISTENER_ADDED, null, null);
    
public voidcloseApplication(Application application)
Close the given application.

	applications.removeElement(application);

//	UIProject.removeProject(application);
//	ProjectImpl proj = (ProjectImpl)Project.getProject(application);
//	if ( proj != null ) {
//	    proj.remove();
//	    Project.removeProject(application);
//	}

	this.setActiveApplication(null);
	this.notify(APPLICATION_REMOVED, APPLICATION_PROPERTY, application);
    
public ApplicationgetActiveApplication()
Return the active application.

	return activeApplication;
    
public java.util.VectorgetApplicationNames()

	Vector names = new Vector();
	for (Enumeration e = applications.elements();e.hasMoreElements();) {
	    names.addElement(((Application) e.nextElement()).getName());   
	}
	return names;
    
public ApplicationgetApplicationWithJar(java.io.File jarFilename)

	for (Enumeration e = this.getApplications().elements(); 
	    e.hasMoreElements();) {
	    Application application = (Application) e.nextElement();
	    if (application.getApplicationArchivist().
		getApplicationFile().getAbsolutePath().equals(
		    jarFilename.getAbsolutePath())) {
		return application;
	    }
	}
	return null;
    
public java.util.VectorgetApplications()
The Vector open application objects.

	Vector clone = (Vector) applications.clone();
	return clone;
    
protected java.lang.StringgetConfigAppFileName()

       
	return this.configFileName;
    
public java.io.FilegetTemp()
Gets the temporary directory.

	return temp;
    
protected java.lang.StringgetUniqueApplicationName(java.lang.String trialName)

	return Application.createUniqueNameAmongst(trialName, 
	    this.getApplicationNames());
    
public ApplicationnewApplication(java.lang.String name, java.lang.String jarFile)
Create a new application with the given name and jar file and makes it the active one..

	Application newApplication = new Application(
	    this.getUniqueApplicationName(name), new File(jarFile));

//	Project newProj = new ProjectImpl(newApplication);
//	Project.addProject(newApplication, newProj);

	try {
	    this.saveApplication(newApplication);
	} catch (IOException ioe) {
	    Log.print(this, ioe);
	}
	this.addApplication(newApplication);
	return newApplication;
    
public voidnotification(com.sun.enterprise.util.NotificationEvent ne)
I am recieving a notification event.

	this.notify(ne.getType(), NotificationEvent.OBJECT_THAT_CHANGED, 
	    ne.getObjectThatChanged());
    
public voidnotify(java.lang.String type, java.lang.String name, java.lang.Object value)
Convenience method for notifying listeners.

	NotificationEvent ne = null;
	if (name == null) {
	    ne = new NotificationEvent(this, type);
	} else {
	    ne = new NotificationEvent(this, type, name, value);
	}    
	Vector listenersClone = null;
	synchronized (applicationListeners) {
	    listenersClone = (Vector) applicationListeners.clone();
	}
	for (Enumeration e = listenersClone.elements(); e.hasMoreElements();) {
	    NotificationListener nl = (NotificationListener) e.nextElement();
	    //System.out.println("notifying " + nl);
	    nl.notification(ne);   
	    //System.out.println("Done");
	}
	//System.out.println("Notify: " + (System.currentTimeMillis() - time));
    
public ApplicationopenApplication(java.io.File name)
Open the JAR file application.

	Application openedApplication = ApplicationArchivist.openAT(name);   //4691307; 4774785
        // fix bug# 4766725
        for (java.util.Iterator itr = openedApplication.getWebBundleDescriptors().iterator(); itr.hasNext();) {
                WebBundleDescriptor webBundleDescriptor = (WebBundleDescriptor) itr.next();
                for(Enumeration e = webBundleDescriptor.getWebComponentDescriptors(); e.hasMoreElements();){
                        WebComponentDescriptorImpl comp = (WebComponentDescriptorImpl) e.nextElement();
                        if (comp.getName().equals(""))
                            comp.setName(comp.getCanonicalName());
                }
        }
        
        // start IASRI4691307
        // Initialize Sun Specific Descriptors HERE
        //
        com.sun.enterprise.tools.deployment.ui.sunone.SunOneUtils.createSunOneXml(openedApplication);
        com.sun.enterprise.tools.deployment.Util.addMappingsSkeleton(openedApplication);
        // end IASRI4691307
	this.addApplication(openedApplication);
//	ProjectImpl newProj = new ProjectImpl(openedApplication);
//	newProj.load();
//	Project.addProject(openedApplication, newProj);
	openedApplication.doneOpening();
	return openedApplication;
    
public voidremoveNotificationListener(com.sun.enterprise.util.NotificationListener nl)
Deregister for state changes.

	applicationListeners.removeElement(nl);
    
public java.util.HashtablerestoreFromUserHome()
retore state from the last session, returning a Hashtable of filenames to exceptions for each application that could not be reopened.

	Hashtable badApplicationJarFilenamesToExceptions = new Hashtable();
	File appsFile = new File(preferencesDirectory, getConfigAppFileName());
	if (appsFile.exists()) {
	    FileInputStream fis = new FileInputStream(appsFile);
	    Properties applications = new Properties();
	    applications.load(fis);  
	    for (Enumeration e = applications.propertyNames(); 
		e.hasMoreElements();) {
		String appName = (String) e.nextElement();
		String appJarFilename = (String) 
		    applications.getProperty(appName);
		Application openedApp=null;
		try {
		    this.openApplication(new File(appJarFilename)); 
		} catch (Throwable t) {
		    badApplicationJarFilenamesToExceptions.put(
			appJarFilename, t);
		} 
	    }
            if (fis != null) {
                fis.close();
            }
	}
	return badApplicationJarFilenamesToExceptions;
    
public voidsaveApplication(Application application)
Save the given applicastion to its JAR file.

	ApplicationArchivist archivist = application.getApplicationArchivist();
	archivist.save(archivist.getApplicationFile(), true);

//	ProjectImpl proj = (ProjectImpl)Project.getProject(application);
//	if (proj != null) {
//	    proj.save();
//	}
    
public voidsaveAsApplication(Application application, java.io.File newJar)
Save the given application to the supllied file.

	ApplicationArchivist archivist = application.getApplicationArchivist();
	archivist.save(newJar, true);
//	ProjectImpl proj = (ProjectImpl)Project.getProject(application);
//	if (proj != null) {
//	    proj.save();
//	}
    
public voidsaveToUserHome()
Saves the list of open applications to the working dir under '.jpedeploytool/.'

	File appsFile = new File(preferencesDirectory, getConfigAppFileName());	
	FileOutputStream fos = new FileOutputStream(appsFile);
	Properties applications = new Properties();
	for (Enumeration e = this.getApplications().elements(); 
	    e.hasMoreElements();) {
	    Application nextApplication = (Application) e.nextElement();
	    applications.put(nextApplication.getName(), 
		nextApplication.getApplicationArchivist().
		    getApplicationFile().toString());
	}
	applications.store(fos, "J2EE Applications"); // NOI18N
        if (fos != null) {
            fos.close();
        }
    
public voidsetActiveApplication(Application application)
Sets the active application.

	if (application != activeApplication) {
	    this.activeApplication = application;
	    if (application != null) {
		this.notify(ACTIVE_CHANGED, APPLICATION_PROPERTY, application);
	    } else {
		this.notify(ACTIVE_CHANGED, null, null);
	    }
	}
    
public voidsetConfigAppFileName(java.lang.String cfgAppFile)

	this.configFileName = (cfgAppFile != null)? cfgAppFile : CFG_APP_FILE;
    
public java.lang.StringtoString()
Formatted String.

	return "Application Manager"; // NOI18N