1 19 20 package org.netbeans.core.startup; 21 22 import org.openide.modules.ModuleInfo; 23 import org.openide.util.Lookup; 24 import org.openide.util.lookup.AbstractLookup; 25 import org.openide.util.lookup.InstanceContent; 26 import org.openide.util.lookup.Lookups; 27 import org.openide.util.lookup.ProxyLookup; 28 29 31 public final class MainLookup extends ProxyLookup { 32 private static boolean started = false; 33 34 private static ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 35 36 private static InstanceContent instanceContent = new InstanceContent (); 37 38 private static Lookup instanceLookup = new AbstractLookup (instanceContent); 39 40 44 public static void startedNbTopManager() { 45 started = true; 46 } 47 48 50 static boolean isStarted() { 51 return started; 52 } 53 54 56 public MainLookup () { 57 super (new Lookup[] { 58 Lookups.metaInfServices(classLoader), 60 Lookups.singleton(classLoader), 61 Lookup.EMPTY, instanceLookup 63 }); 64 } 65 66 68 public static final void systemClassLoaderChanged (ClassLoader nue) { 69 if (!(Lookup.getDefault() instanceof MainLookup)) { 70 return; 72 } 73 if (classLoader != nue) { 74 classLoader = nue; 75 MainLookup l = (MainLookup)Lookup.getDefault(); 76 Lookup[] delegates = l.getLookups(); 77 Lookup[] newDelegates = delegates.clone(); 78 newDelegates[0] = Lookups.metaInfServices(classLoader); 80 newDelegates[1] = Lookups.singleton(classLoader); 81 l.setLookups(newDelegates); 82 } else { 83 moduleClassLoadersUp(); 84 } 85 } 86 87 89 public static final void moduleClassLoadersUp() { 90 MainLookup l = (MainLookup)Lookup.getDefault(); 91 Lookup[] newDelegates = null; 92 Lookup[] delegates = l.getLookups(); 93 newDelegates = delegates.clone(); 94 newDelegates[0] = Lookups.metaInfServices(classLoader); 95 l.setLookups(newDelegates); 96 } 97 98 101 public static final void moduleLookupReady(Lookup moduleLookup) { 102 MainLookup l = (MainLookup)Lookup.getDefault(); 103 Lookup[] newDelegates = l.getLookups().clone(); 104 newDelegates[2] = moduleLookup; 105 l.setLookups(newDelegates); 106 } 107 108 111 112 public static final void modulesClassPathInitialized () { 113 116 Lookup lookup = Lookup.getDefault (); 118 StartLog.logProgress ("Got Lookup"); 120 ((MainLookup)lookup).doInitializeLookup (); 121 } 122 123 127 129 public static void register (Object obj) { 130 instanceContent.add (obj); 131 } 132 133 137 public static <T,R> void register(T obj, InstanceContent.Convertor<T,R> conv) { 138 instanceContent.add(obj, conv); 139 } 140 141 143 public static void unregister (Object obj) { 144 instanceContent.remove (obj); 145 } 146 148 public static <T,R> void unregister (T obj, InstanceContent.Convertor<T,R> conv) { 149 instanceContent.remove (obj, conv); 150 } 151 152 153 154 155 156 private final void doInitializeLookup () { 157 159 Lookup[] arr = new Lookup[] { 161 getLookups()[0], getLookups()[1], getLookups()[2], instanceLookup, 165 CoreBridge.conditionallyLookupCacheLoad (), 166 }; 167 StartLog.logProgress ("prepared other Lookups"); 169 setLookups (arr); 170 StartLog.logProgress ("Lookups set"); 172 CoreBridge.lookupInitialized(); 173 } 175 176 public void storeCache() throws java.io.IOException { 177 Lookup[] ls = getLookups(); 178 if (ls.length == 5) { 179 CoreBridge.getDefault ().lookupCacheStore (ls[4]); 181 } 182 } 183 184 protected void beforeLookup(Lookup.Template templ) { 185 Class type = templ.getType(); 186 187 if (!started && (type == ModuleInfo.class || type == org.netbeans.Module.class)) { 190 Main.getModuleSystem (); 191 } 192 193 super.beforeLookup(templ); 194 } 195 } 196 197 | Popular Tags |