FileDocCategorySizeDatePackage
StandAloneManager.javaAPI DocGlassfish v2 API12566Fri May 04 22:35:02 BST 2007com.sun.enterprise.tools.deployment.main

StandAloneManager

public class StandAloneManager extends Object implements NotificationListener

Fields Summary
public static final String
STANDALONE_PROPERTY
public static final String
STANDALONE_ADDED
public static final String
STANDALONE_REMOVED
public static final String
LISTENER_ADDED
public static final String
ACTIVE_CHANGED
private Vector
standalones
private Vector
standaloneListeners
private Descriptor
activeStandAlone
private File
preferencesDirectory
private File
temp
public static final String
CFG_CONNECTOR_FILE
private String
configFileName
Constructors Summary
public StandAloneManager(File preferencesDirectory, File temp)


    /* ------------------------------------------------------------------------ 
    ** constructors 
    */

         
    
	this.preferencesDirectory = preferencesDirectory;
	this.temp = temp;
    
Methods Summary
public voidaddNotificationListener(NotificationListener nl)

	standaloneListeners.addElement(nl);
	this.notify(LISTENER_ADDED, null, null);
    
public voidaddStandAlone(Descriptor desc)

	String oldName = desc.getName();
	String newName = this.getUniqueStandAloneName(oldName);
	if (!oldName.equals(newName)) {
	    desc.setName(newName);
	}
	this.standalones.addElement(desc);
	desc.addNotificationListener(this);
	this.notify(STANDALONE_ADDED, STANDALONE_PROPERTY, desc);
	this.setActiveStandAlone(desc);	
    
public voidcloseStandAlone(Descriptor desc)
Close the given stand-alone object

	this.standalones.removeElement(desc);
//	UIProject.removeProject(desc);
//	ProjectImpl proj = (ProjectImpl)Project.getProject(desc);
//	if (proj != null) {
//	    proj.remove();
//	    Project.removeProject(desc);
//	}
	this.setActiveStandAlone(null);
	this.notify(STANDALONE_REMOVED, STANDALONE_PROPERTY, desc);
    
public DescriptorgetActiveStandAlone()
Return the active stand-alone object

	return this.activeStandAlone;
    
protected java.lang.StringgetConfigFileName()

       
    
	return this.configFileName;
    
public java.util.VectorgetStandAloneNames()

	Vector names = new Vector();
	Enumeration e = this.standalones.elements();
	for (;e.hasMoreElements();) {
	    names.addElement(((Descriptor)e.nextElement()).getName());   
	}
	return names;
    
public DescriptorgetStandAloneWithJar(java.io.File jarFilename)

	String absPath = jarFilename.getAbsolutePath();
	Enumeration e = this.standalones.elements();
	for (;e.hasMoreElements();) {
	    Descriptor d = (Descriptor)e.nextElement();
	    if (d instanceof ConnectorDescriptor) {
		String uri = ((ConnectorDescriptor)d).getArchivist().
		    getArchiveUri();
	        if ((new File(uri)).getAbsolutePath().equals(absPath)) {
		    return d;
	        }
	    } else
	    if (d instanceof Application) {
	        if (((Application)d).getApplicationArchivist().
		    getApplicationFile().getAbsolutePath().equals(absPath)) {
		    return d;
	        }
	    } else {
		// XXX - unknown descriptor
	    }
	}
	return null;
    
public java.util.VectorgetStandAlones()

	return (Vector)this.standalones.clone();
    
public java.io.FilegetTemp()
Gets the temporary directory.

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

	return Descriptor.createUniqueNameAmongst(trialName, 
	    this.getStandAloneNames());
    
public booleanisDirty(Descriptor desc)

	if (desc instanceof ConnectorDescriptor) {
	    return ((ConnectorDescriptor)desc).isDirty();
	} else
	if (desc instanceof Application) {
	    return ((Application)desc).isDirty();
	}
	return false;
    
public booleanisStandAloneDescriptor(Descriptor desc)

	Enumeration e = this.standalones.elements();
	for (;e.hasMoreElements();) {
	    if (desc == e.nextElement()) {
		return true;
	    }   
	}
	return false;
    
public voidnotification(NotificationEvent ne)

	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 = (name == null)?
	    new NotificationEvent(this, type) :
	    new NotificationEvent(this, type, name, value);

	/* make a copy of the listener list */
	Vector listenersClone = null;
	synchronized (standaloneListeners) {
	    listenersClone = (Vector)standaloneListeners.clone();
	}

	/* notify listeners */
	for (Enumeration e = listenersClone.elements(); e.hasMoreElements();) {
	    NotificationListener nl = (NotificationListener)e.nextElement();
	    nl.notification(ne);   
	}

    
public DescriptoropenStandAlone(java.io.File name)


	/* ConnectorDescriptor */
	if (ConnectorArchivist.isConnector(name)) {
            //IASRI 4691307  Anissa
            //Open the rar file with ValidateXML set to false, and include S1AS descriptor.
	    ConnectorDescriptor d = ConnectorArchivist.open(name, false, true);
            // IASRI 4691307 end.
            
	    this.addStandAlone(d);
            
//	    ProjectImpl newProj = new ProjectImpl(d);
//	    newProj.load();
//	    Project.addProject(d, newProj);
	    return d;
	}

	/* Application */
	if (ApplicationArchivist.isApplication(name)) {
	    Application d = ApplicationArchivist.openAT(name);  //bug# 4774785;  4691307
	    this.addStandAlone(d);
//	    ProjectImpl newProj = new ProjectImpl(d);
//	    newProj.load();
//	    Project.addProject(d, newProj);
	    d.doneOpening();
	    return d;
	}

	/* not found */
	return null;

    
public voidremoveNotificationListener(NotificationListener nl)

	standaloneListeners.removeElement(nl);
    
public java.util.HashtablerestoreFromUserHome()

	Hashtable badFiles = new Hashtable();
	File propsFile = new File(preferencesDirectory, getConfigFileName());
	if (propsFile.exists()) {
	    FileInputStream fis = new FileInputStream(propsFile);
	    Properties props = new Properties();
	    props.load(fis);  
	    for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
		String name = (String)e.nextElement();
		String jarFilename = (String)props.getProperty(name);
		try {
		    this.openStandAlone(new File(jarFilename)); 
		} catch (Throwable t) {
		    badFiles.put(jarFilename, t);
		} 
	    }
            fis.close();
	}
	return badFiles;
    
public voidsaveStandAlone(Descriptor desc)

	if (desc instanceof ConnectorDescriptor) {
	    ConnectorDescriptor cd = (ConnectorDescriptor)desc;
	    ConnectorArchivist ca = (ConnectorArchivist)cd.getArchivist();
	    ca.save(new File(ca.getArchiveUri()), true);
	}
    
public voidsaveStandAloneAs(Descriptor desc, java.io.File newFile)

	if (desc instanceof ConnectorDescriptor) {
	    ConnectorDescriptor cd = (ConnectorDescriptor)desc;
	    ConnectorArchivist ca = (ConnectorArchivist)cd.getArchivist();
	    ca.save(newFile, true);
	}
    
public voidsaveToUserHome()
Saves the list of open stand-alone objects to the working dir

	File propsFile = new File(preferencesDirectory, getConfigFileName());	
	FileOutputStream fos = new FileOutputStream(propsFile);
	Properties props = new Properties();
	Enumeration e = this.standalones.elements();
	for (;e.hasMoreElements();) {
	    Descriptor next = (Descriptor)e.nextElement();
	    String loc = null;
	    if (next instanceof ConnectorDescriptor) {
		loc = ((ConnectorDescriptor)next).getArchivist().
		    getArchiveUri();
	    } else
	    if (next instanceof Application) {
		loc = ((Application)next).getApplicationArchivist().
		    getApplicationFile().toString();
	    }
	    if (loc != null) {
	        props.put(next.getName(), loc);
	    } else {
		System.err.println("Unsupported Stand-Alone descriptor type:");
	 	System.err.println("  " + next.getClass().getName());
	    }
	}
	props.store(fos, "J2EE Stand-Alone Descriptors"); // NOI18N
        fos.close();
    
public voidsetActiveStandAlone(Descriptor desc)

	if (desc != this.activeStandAlone) {
	    this.activeStandAlone = desc;
	    if (desc != null) {
		this.notify(ACTIVE_CHANGED, STANDALONE_PROPERTY, desc);
	    } else {
		this.notify(ACTIVE_CHANGED, null, null);
	    }
	}
    
public java.lang.StringtoString()
Formatted String.

	return "Stand-Alone Manager"; // NOI18N