1 19 20 package org.netbeans.api.enode; 21 22 import java.util.*; 23 import javax.swing.Action ; 24 import org.netbeans.modules.enode.ExtensibleActionsImpl; 25 import org.netbeans.modules.enode.TimedSoftReference; 26 27 38 public abstract class ExtensibleActions { 39 44 private static Map cache = new HashMap(); 45 46 50 protected ExtensibleActions() { 51 if (! getClass().equals(ExtensibleActionsImpl.class)) { 52 throw new IllegalStateException ("You cannot create a subclass of this class. Please read the JavaDoc comment"); } 54 } 55 56 61 public abstract Action [] getActions(); 62 63 75 public static ExtensibleActions getInstance(String path, boolean recurse) { 76 String [] paths = null; 77 if (recurse) { 78 paths = ExtensibleNode.computeHierarchicalPaths(path); 79 } else { 80 paths = new String [] { path }; 81 } 82 return getInstance(paths); 83 } 84 85 95 public static ExtensibleActions getInstance(String [] paths) { 96 Object key = Arrays.asList(paths); 99 100 TimedSoftReference ref = null; 101 synchronized (cache) { 102 ref = (TimedSoftReference)cache.get(key); 103 } 104 ExtensibleActions instance = null; 105 if (ref != null) { 106 instance = (ExtensibleActions)ref.get(); 107 } 108 if (instance == null) { 109 instance = new ExtensibleActionsImpl(paths); 110 synchronized (cache) { 111 cache.put(key, new TimedSoftReference(instance, cache, key)); 112 } 113 } 114 return instance; 115 } 116 } 117 118 | Popular Tags |