/* * FileObjectIdentity.java * * Created on February 19, 2003, 12:40 PM */ package org.openide.filesystems; import java.beans.*; import java.util.*; import org.openide.util.*; /** * * @author rm111737 */ final public class FileObjectIdentity { public static final String PROP_IDENTITY_CHANGE = "identityChange"; // NOI18N private static Map identityMap; private FileObject fo; private FileChangeListener fsListener; private PropertyChangeSupport changeSupport; private FileObjectIdentity() {} /** Creates a new instance of FileObjectIdentity */ private FileObjectIdentity(FileObject fo) { this.fo = fo; } /** * @param fo * @return FileObjectIdentity or null if there is no guarantee, that identity * can be succesfully kept. */ static public FileObjectIdentity getFileObjectIdentity (FileObject fo) { FileObjectIdentity retVal = null; boolean guarantee = ((fo instanceof AbstractFileObject) || (fo instanceof MultiFileObject)); if (guarantee) { synchronized (FileObjectIdentity.class) { if (identityMap == null) { identityMap = new WeakHashMap (); } retVal = (FileObjectIdentity)identityMap.get(fo); if (retVal == null) { retVal = new FileObjectIdentity (fo); identityMap.put(retVal.fo, retVal); //retVal.initListener (fo); } } } return retVal; } public FileObject getFileObject () { return fo; } public final void addPropertyChangeListener(PropertyChangeListener listener) { synchronized (FileObjectIdentity.class) { if (changeSupport == null) changeSupport = new PropertyChangeSupport(this); } changeSupport.addPropertyChangeListener(listener); } public final void removePropertyChangeListener(PropertyChangeListener listener) { if (changeSupport != null) changeSupport.removePropertyChangeListener(listener); } static void moveNotify (FileObject oldInstance, FileObject newInstance) { synchronized (FileObjectIdentity.class) { FileObjectIdentity identity = (FileObjectIdentity)identityMap.get(oldInstance); if (identity != null) { identity.changeIdentity (newInstance); identityMap.remove(oldInstance); identityMap.put(newInstance, identity); } } } private void changeIdentity (FileObject fo) { FileObject oldInstance = this.fo; FileObject newInstance = fo; //reInitListener (oldInstance, newInstance); this.fo = fo; if (changeSupport != null) changeSupport.firePropertyChange(PROP_IDENTITY_CHANGE, oldInstance, newInstance); } }