1 11 package org.eclipse.team.internal.core; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.team.core.ICache; 18 import org.eclipse.team.core.ICacheListener; 19 20 28 public class Cache implements ICache { 29 30 Map properties; 31 ListenerList listeners; 32 33 36 public synchronized void put(String name, Object value) { 37 if (properties == null) { 38 properties = new HashMap (); 39 } 40 properties.put(name, value); 41 } 42 43 public synchronized Object get(String name) { 44 if (properties == null) 45 return null; 46 return properties.get(name); 47 } 48 49 52 public synchronized void remove(String name) { 53 if (properties != null) 54 properties.remove(name); 55 if (properties.isEmpty()) { 56 properties = null; 57 } 58 59 } 60 61 64 public synchronized void addCacheListener(ICacheListener listener) { 65 if (listeners == null) 66 listeners = new ListenerList(ListenerList.IDENTITY); 67 listeners.add(listener); 68 69 } 70 71 74 public synchronized void removeDisposeListener(ICacheListener listener) { 75 removeCacheListener(listener); 76 } 77 78 81 public synchronized void removeCacheListener(ICacheListener listener) { 82 if (listeners != null) 83 listeners.remove(listener); 84 } 85 86 89 public void dispose() { 90 if (listeners != null) { 91 Object [] allListeners = listeners.getListeners(); 92 for (int i = 0; i < allListeners.length; i++) { 93 final Object listener = allListeners[i]; 94 SafeRunner.run(new ISafeRunnable(){ 95 public void run() throws Exception { 96 ((ICacheListener)listener).cacheDisposed(Cache.this); 97 } 98 public void handleException(Throwable exception) { 99 101 } 102 }); 103 } 104 } 105 properties = null; 106 } 107 108 } 109 | Popular Tags |