? core/X Index: openide/src/org/openide/loaders/Environment.java =================================================================== RCS file: /cvs/openide/src/org/openide/loaders/Environment.java,v retrieving revision 1.7 diff -c -r1.7 Environment.java *** openide/src/org/openide/loaders/Environment.java 5 Oct 2001 14:06:32 -0000 1.7 --- openide/src/org/openide/loaders/Environment.java 14 Feb 2002 10:40:37 -0000 *************** *** 80,85 **** --- 80,98 ---- } */ + // try to resolve the environment with just the first provider + Environment.Provider first = (Environment.Provider)Lookup.getDefault ().lookup (Environment.Provider.class); + { + if (first == null) { + return null; + } + Lookup lookup = first.getEnvironment (obj); + if (lookup != null) { + return lookup; + } + } + + if (result == null) { result = Lookup.getDefault ().lookup (new Lookup.Template (Environment.Provider.class)); } *************** *** 87,92 **** --- 100,110 ---- Iterator it = result.allInstances ().iterator (); while (it.hasNext ()) { Environment.Provider ep = (Environment.Provider)it.next (); + if (ep == first) { + // has already been asked + continue; + } + Lookup lookup = ep.getEnvironment (obj); if (lookup != null) { return lookup; Index: openide/src/org/openide/loaders/FolderLookup.java =================================================================== RCS file: /cvs/openide/src/org/openide/loaders/FolderLookup.java,v retrieving revision 1.17 diff -c -r1.17 FolderLookup.java *** openide/src/org/openide/loaders/FolderLookup.java 1 Feb 2002 12:12:21 -0000 1.17 --- openide/src/org/openide/loaders/FolderLookup.java 14 Feb 2002 10:40:37 -0000 *************** *** 29,34 **** --- 29,38 ---- import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.ProxyLookup; import org.openide.util.Task; + import java.io.ObjectInputStream; + import java.io.ObjectOutputStream; + import org.openide.filesystems.FileObject; + import java.io.Serializable; /** Implements a lookup, that scans a content of a folder for its *************** *** 41,47 **** * @since 1.11 */ public class FolderLookup extends FolderInstance { - /** Lock for initiliazation of lookup. */ private static final Object LOCK = new Object (); --- 45,50 ---- *************** *** 243,254 **** /** Notifies the exception. Helper method. */ private static void exception (Exception e) { ! ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, e); } /** ProxyLookup delegate so we can change the lookups on fly. */ ! private static final class ProxyLkp extends ProxyLookup { /** FolderLookup we are associated with. */ private FolderLookup fl; --- 246,262 ---- /** Notifies the exception. Helper method. */ private static void exception (Exception e) { ! String prop = System.getProperty ("netbeans.lookup"); ! if (!"quite".equals (prop)) { ! // do not report when running the "lookup" module ! ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, e); ! } } /** ProxyLookup delegate so we can change the lookups on fly. */ ! private static final class ProxyLkp extends ProxyLookup ! implements java.io.Serializable { /** FolderLookup we are associated with. */ private FolderLookup fl; *************** *** 256,261 **** --- 264,270 ---- /** Content to control the abstract lookup. */ private AbstractLookup.Content content; + private boolean readFromStream; /** Constructs lookup which holds all items+lookups from underlying world. * @param folder FolderLookup to associate to */ *************** *** 271,282 **** --- 280,316 ---- this.content = content; } + private void writeObject (ObjectOutputStream oos) throws IOException { + oos.writeObject (getLookups ()); + oos.writeObject (fl.folder); + oos.writeObject (fl.rootName); + oos.writeObject (content); + } + + private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException { + + Lookup[] arr = (Lookup[])ois.readObject (); + DataFolder df = (DataFolder)ois.readObject (); + String root = (String)ois.readObject (); + + fl = new FolderLookup (df, root, true); + fl.lookup = this; + + content = (AbstractLookup.Content)ois.readObject (); + + setLookups (arr); + + readFromStream = true; + } + /** Updates internal data. * @param items Items to assign to all pairs * @param lookups delegates to delegate to (first item is null) */ public void update(Collection items, List lookups) { + readFromStream = false; + // remember the instance lookup Lookup pairs = getLookups ()[0]; *************** *** 293,298 **** --- 327,337 ---- /** Waits before the processing of changes is finished. */ protected void beforeLookup (Template template) { + if (readFromStream) { + // ok + return; + } + // do not wait in folder recognizer, but in all other cases if (!FolderList.isFolderRecognizerThread ()) { fl.instanceFinished (); *************** *** 304,315 **** /** Item that delegates to InstanceCookie. Item which * the internal lookup data structure is made from. */ ! private static final class ICItem extends AbstractLookup.Pair { ! private InstanceCookie ic; /** source data object */ ! private DataObject obj; /** reference to created object */ ! private WeakReference ref; /** root folder */ private String rootName; --- 343,360 ---- /** Item that delegates to InstanceCookie. Item which * the internal lookup data structure is made from. */ ! private static final class ICItem extends AbstractLookup.Pair ! implements java.io.Serializable { ! static final long serialVersionUID = 10L; ! ! /** when deserialized only primary file is stored */ ! private FileObject fo; ! ! private transient InstanceCookie ic; /** source data object */ ! private transient DataObject obj; /** reference to created object */ ! private transient WeakReference ref; /** root folder */ private String rootName; *************** *** 318,323 **** --- 363,394 ---- this.ic = ic; this.obj = obj; this.rootName = rootName; + this.fo = obj.getPrimaryFile(); + } + + /** Initializes the item + */ + public void init () { + if (ic != null) return; + + if (fo.toString ().equals ("Services/Hidden/org-netbeans-modules-web-core-resources-EntityCatalog.xml")) { + System.out.println("Cookie for problematic class"); + } + + ic = (InstanceCookie)obj.getCookie (InstanceCookie.class); + if (ic == null) { + ic = (InstanceCookie)obj.getCookie (InstanceCookie.class); + throw new IllegalStateException ("No cookie: " + obj); + } + } + + + /** Initializes the cookie from data object. + */ + private void readObject (ObjectInputStream ois) + throws IOException, ClassNotFoundException { + ois.defaultReadObject(); + obj = DataObject.find (fo); } *************** *** 325,330 **** --- 396,403 ---- * @return the class of the item */ protected boolean instanceOf (Class clazz) { + init (); + if (ic instanceof InstanceCookie.Of) { // special handling for special cookies InstanceCookie.Of of = (InstanceCookie.Of)ic; *************** *** 346,351 **** --- 419,426 ---- * @return the instance of the object or null if it cannot be created */ public Object getInstance() { + init (); + try { Object obj = ic.instanceCreate(); ref = new WeakReference (obj); *************** *** 360,365 **** --- 435,442 ---- /** Hash code is the InstanceCookie's code. */ public int hashCode () { + init (); + return System.identityHashCode (ic); } *************** *** 367,372 **** --- 444,451 ---- public boolean equals (Object obj) { if (obj instanceof ICItem) { ICItem i = (ICItem)obj; + i.init (); + init (); return ic == i.ic; } return false; *************** *** 376,386 **** --- 455,469 ---- * @return string representing the item, that can be used for * persistance purposes to locate the same item next time */ public String getId() { + init (); + return objectName(rootName, obj); } /** Display name is extracted from name of the objects node. */ public String getDisplayName () { + init (); + return obj.getNodeDelegate ().getDisplayName (); } *************** *** 400,405 **** --- 483,490 ---- * @return the correct class */ public Class getType() { + init (); + try { return ic.instanceClass (); } catch (IOException ex) { Index: openide/src/org/openide/loaders/XMLDataObject.java =================================================================== RCS file: /cvs/openide/src/org/openide/loaders/XMLDataObject.java,v retrieving revision 1.111 diff -c -r1.111 XMLDataObject.java *** openide/src/org/openide/loaders/XMLDataObject.java 20 Jan 2002 16:13:27 -0000 1.111 --- openide/src/org/openide/loaders/XMLDataObject.java 14 Feb 2002 10:40:46 -0000 *************** *** 957,962 **** --- 957,963 ---- private static final Lookup.Template TEMPLATE = new Lookup.Template (Node.Cookie.class); /** a string to signal null value for parsedId */ private static final String NULL = ""; // NOI18N + private static String SP = ""; /** * Parser that parses XML document header to get some hints from it (such as DOCTYPE public ID. *************** *** 978,983 **** --- 979,986 ---- /** result used for this lookup */ private Lookup.Result result; + private ThreadLocal QUERY = new ThreadLocal (); + //~~~~~~~~~~~~~~~~~~~~~ Task body and control of queue ~~~~~~~~~~~~~~~~~~~ /** Getter for public ID of the document. *************** *** 993,1010 **** * * @param class to look for */ ! public Object lookupCookie (Class clazz) { ! waitFinished (); ! ! Lookup l = lookup != null ? lookup : Lookup.EMPTY; ! Lookup.Result r = result; ! if (r != null) { ! // just to initialize all listeners ! r.allItems (); } - - return l.lookup (clazz); } /* --- 996,1036 ---- * * @param class to look for */ ! public Object lookupCookie (final Class clazz) { ! if (QUERY.get () == clazz) { ! // somebody is querying for the same cookie in the same thread ! // probably neverending-loop - ignore ! return new InstanceCookie () { ! public Class instanceClass () { ! return clazz; ! } ! ! public Object instanceCreate () throws IOException { ! throw new IOException ("Cyclic reference, sorry: " + clazz); ! } ! ! public String instanceName () { ! return clazz.getName (); ! } ! }; ! } ! Object previous = QUERY.get (); ! try { ! QUERY.set (clazz); ! waitFinished (); ! ! Lookup l = lookup != null ? lookup : Lookup.EMPTY; ! ! Lookup.Result r = result; ! if (r != null) { ! // just to initialize all listeners ! r.allItems (); ! } ! return l.lookup (clazz); ! } finally { ! QUERY.set (previous); } } /* Index: openide/src/org/openide/util/lookup/AbstractLookup.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/lookup/AbstractLookup.java,v retrieving revision 1.14 diff -c -r1.14 AbstractLookup.java *** openide/src/org/openide/util/lookup/AbstractLookup.java 26 Oct 2001 14:19:59 -0000 1.14 --- openide/src/org/openide/util/lookup/AbstractLookup.java 14 Feb 2002 10:40:47 -0000 *************** *** 20,25 **** --- 20,26 ---- import org.openide.util.Lookup; import org.openide.util.LookupListener; import org.openide.util.LookupEvent; + import java.io.Serializable; /** Implementation of the lookup from OpenAPIs that is based on the * introduction of Item. This class should provide the default way *************** *** 29,35 **** * @author Jaroslav Tulach * @since 1.9 */ ! public class AbstractLookup extends Lookup { /** lock for initialization of the map */ private Content treeLock; /** the tree that registers all items */ --- 30,38 ---- * @author Jaroslav Tulach * @since 1.9 */ ! public class AbstractLookup extends Lookup implements Serializable { ! static final long serialVersionUID = 5L; ! /** lock for initialization of the map */ private Content treeLock; /** the tree that registers all items */ *************** *** 37,43 **** /** set (Class, List (Reference (Result)) of all listeners that are waiting in * changes in class Class */ ! private Map reg; /** count of items in to lookup */ private int count; --- 40,46 ---- /** set (Class, List (Reference (Result)) of all listeners that are waiting in * changes in class Class */ ! private transient Map reg; /** count of items in to lookup */ private int count; *************** *** 341,347 **** /** Extension to the default lookup item that offers additional information * for the data structures use in AbstractLookup */ ! public static abstract class Pair extends Lookup.Item { /** possition of this item in the lookup, manipulated in addPair, removePair, setPairs methods */ int index = -1; --- 344,350 ---- /** Extension to the default lookup item that offers additional information * for the data structures use in AbstractLookup */ ! public static abstract class Pair extends Lookup.Item implements Serializable { /** possition of this item in the lookup, manipulated in addPair, removePair, setPairs methods */ int index = -1; *************** *** 558,569 **** * * @since 1.25 */ ! public static class Content extends Object { // one of them is always null (except attach stage) /** abstract lookup we are connected to */ private AbstractLookup al = null; ! private ArrayList earlyPairs = new ArrayList(3); /** A lookup attaches to this object. */ --- 561,572 ---- * * @since 1.25 */ ! public static class Content extends Object implements Serializable { // one of them is always null (except attach stage) /** abstract lookup we are connected to */ private AbstractLookup al = null; ! private transient ArrayList earlyPairs = new ArrayList(3); /** A lookup attaches to this object. */ Index: openide/src/org/openide/util/lookup/InheritanceTree.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/lookup/InheritanceTree.java,v retrieving revision 1.9 diff -c -r1.9 InheritanceTree.java *** openide/src/org/openide/util/lookup/InheritanceTree.java 26 Oct 2001 14:19:59 -0000 1.9 --- openide/src/org/openide/util/lookup/InheritanceTree.java 14 Feb 2002 10:40:47 -0000 *************** *** 30,35 **** --- 30,39 ---- import org.openide.util.enum.EmptyEnumeration; import org.openide.util.enum.QueueEnumeration; import org.openide.util.enum.SequenceEnumeration; + import java.io.Serializable; + import java.io.IOException; + import java.io.ObjectOutputStream; + import java.io.ObjectInputStream; /** A tree to represent classes with inheritance. Description of the *************** *** 96,102 **** * * @author Jaroslav Tulach */ ! final class InheritanceTree extends Object { /** the root item (represents Object) */ private Node object; /** map of queried interfaces (Class, Set) */ --- 100,109 ---- * * @author Jaroslav Tulach */ ! final class InheritanceTree extends Object implements java.io.Serializable { ! static final long serialVersionUID = 5L; ! ! /** the root item (represents Object) */ private Node object; /** map of queried interfaces (Class, Set) */ *************** *** 108,113 **** --- 115,153 ---- object = new Node (java.lang.Object.class); } + private synchronized void writeObject (ObjectOutputStream oos) throws IOException { + oos.writeObject (object); + + Iterator it = interfaces.entrySet ().iterator (); + while (it.hasNext ()) { + Map.Entry e = (Map.Entry)it.next (); + + Class c = (Class)e.getKey (); + HashSet s = (HashSet)e.getValue (); + + oos.writeObject (c); + oos.writeObject (s); + } + oos.writeObject (null); + } + + private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException { + object = (Node)ois.readObject (); + + Map m = new WeakHashMap (); + for (;;) { + Class c = (Class)ois.readObject (); + if (c == null) break; + + HashSet set = (HashSet)ois.readObject (); + + m.put (c, set); + } + + interfaces = m; + + } + /** Adds an item into the tree. * @param item to add *************** *** 618,624 **** /** Node in the tree. */ ! static final class Node extends WeakReference { /** children nodes */ public ArrayList children; --- 658,665 ---- /** Node in the tree. */ ! static final class Node extends WeakReference implements Serializable { ! static final long serialVersionUID = 3L; /** children nodes */ public ArrayList children; *************** *** 674,678 **** --- 715,747 ---- return !was; } } + + private Object writeReplace () { + return new R (this); + } + } // End of class Node. + + private static final class R implements Serializable { + static final long serialVersionUID = 1L; + + private Class clazz; + public ArrayList children; + public ArrayList items; + + public R (Node n) { + this.clazz = n.getType (); + this.children = n.children; + this.items = n.items; + } + + private Object readResolve () { + Node n = new Node (clazz); + n.children = children; + n.items = items; + + return n; + } + + } // end of R } Index: openide/src/org/openide/util/lookup/ProxyLookup.java =================================================================== RCS file: /cvs/openide/src/org/openide/util/lookup/ProxyLookup.java,v retrieving revision 1.6 diff -c -r1.6 ProxyLookup.java *** openide/src/org/openide/util/lookup/ProxyLookup.java 18 Aug 2001 09:12:02 -0000 1.6 --- openide/src/org/openide/util/lookup/ProxyLookup.java 14 Feb 2002 10:40:47 -0000 *************** *** 34,39 **** --- 34,45 ---- /** map of templates to currently active results */ private HashMap results; + /** Creates empty proxy. + */ + protected ProxyLookup () { + this.lookups = new Lookup[0]; + } + /** Create a proxy to some other lookups. * @param lookups the initial delegates */ Index: core/src/org/netbeans/core/NbTopManager.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/NbTopManager.java,v retrieving revision 1.137 diff -c -r1.137 NbTopManager.java *** core/src/org/netbeans/core/NbTopManager.java 13 Feb 2002 14:38:48 -0000 1.137 --- core/src/org/netbeans/core/NbTopManager.java 14 Feb 2002 10:40:53 -0000 *************** *** 64,69 **** --- 64,71 ---- import org.netbeans.core.perftool.StartLog; import org.netbeans.core.modules.ModuleManager; import org.netbeans.core.modules.ModuleSystem; + import java.util.Arrays; + import org.openide.util.io.NbObjectInputStream; import org.openide.xml.EntityCatalog; import org.openide.loaders.Environment; *************** *** 740,748 **** --- 742,772 ---- // system is down; the IDE cannot be used further. ErrorManager.getDefault().notify(t); } + + + + if (System.getProperty ("netbeans.lookup") != null) { + File f = new File (System.getProperty ("netbeans.user") + "/lookup.ser"); + System.err.println("Saving the lookup: " + f); + try { + ObjectOutputStream oos = new ObjectOutputStream ( + new BufferedOutputStream (new FileOutputStream (f)) + ); + oos.writeObject (Lookup.getDefault ()); + oos.close (); + System.err.println("Successfully saved"); + } catch (Exception ex) { + ErrorManager.getDefault().notify (ex); + } + } + + Runtime.getRuntime().exit ( 0 ); } } + + + } finally { synchronized (this) { doingExit = false; *************** *** 949,955 **** /** The default lookup for the system. */ ! public static final class Lkp extends ProxyLookup { private static final boolean suppressMetaInfServicesLookup = !Boolean.getBoolean("netbeans.lookup.usemetainfservices"); // NOI18N --- 973,979 ---- /** The default lookup for the system. */ ! public static final class Lkp extends ProxyLookup implements java.io.Serializable { private static final boolean suppressMetaInfServicesLookup = !Boolean.getBoolean("netbeans.lookup.usemetainfservices"); // NOI18N *************** *** 970,975 **** --- 994,1010 ---- //System.err.println("creating default lookup; suppressMetaInfServicesLookup=" + suppressMetaInfServicesLookup); } + public Object writeReplace () { + Lookup[] arr = getLookups (); + for (int i = 0; i < arr.length; i++) { + if (arr[i].getClass ().getName ().startsWith ("org.openide.loaders")) { + return arr[i]; + } + } + + throw new IllegalStateException ("Lookups: " + Arrays.asList (arr)); + } + /** @param modules if true, use module classloader, else not */ private static Lookup createMetaInfServicesLookup(boolean modules) { try { *************** *** 1017,1023 **** folderLookupFinished = true; // FolderLookup has finished recognizing things. Remove the forced ErrorManager // override from the set of lookups. ! task.removeTaskListener(this); Lookup lookup = Lookup.getDefault(); if (lookup instanceof Lkp) { Lkp lkp = (Lkp)lookup; --- 1052,1060 ---- folderLookupFinished = true; // FolderLookup has finished recognizing things. Remove the forced ErrorManager // override from the set of lookups. ! if (task != null) { ! task.removeTaskListener(this); ! } Lookup lookup = Lookup.getDefault(); if (lookup instanceof Lkp) { Lkp lkp = (Lkp)lookup; *************** *** 1112,1123 **** DataFolder rootFolder = DataFolder.findFolder ( org.openide.TopManager.getDefault ().getRepository ().getDefaultFileSystem ().getRoot () ); - DataFolder df = DataFolder.create (rootFolder, "Services"); // NOI18N - StartLog.logProgress ("Got Services folder"); // NOI18N ! FolderLookup folder = new FolderLookup (df, "SL["); // NOI18N ! folder.addTaskListener(new ConvertorListener()); ! StartLog.logProgress ("created FolderLookup"); // NOI18N // extend the lookup Lookup[] arr = suppressMetaInfServicesLookup ? --- 1149,1183 ---- DataFolder rootFolder = DataFolder.findFolder ( org.openide.TopManager.getDefault ().getRepository ().getDefaultFileSystem ().getRoot () ); ! Lookup folderLookup = null; ! ! File f = new File (System.getProperty ("netbeans.user") + "/lookup.ser"); ! if (f.exists ()) { ! try { ! ObjectInputStream ios = new NbObjectInputStream ( ! new BufferedInputStream (new FileInputStream (f)) ! ); ! folderLookup = (Lookup)ios.readObject (); ! System.err.println(" lookupread: " + folderLookup); ! ios.close (); ! } catch (Exception ex) { ! ErrorManager.getDefault().notify (ex); ! } ! } ! ! if (folderLookup == null) { ! System.err.println(" lookup does not exist"); ! ! FolderLookup folder = null; ! DataFolder df = DataFolder.create (rootFolder, "Services"); // NOI18N ! StartLog.logProgress ("Got Services folder"); // NOI18N ! folder = new FolderLookup (df, "SL["); // NOI18N ! folder.addTaskListener(new ConvertorListener()); ! StartLog.logProgress ("created FolderLookup"); // NOI18N ! ! folderLookup = folder.getLookup(); ! } // extend the lookup Lookup[] arr = suppressMetaInfServicesLookup ? *************** *** 1127,1133 **** // is actually ready and usable lkp.getLookups()[1], // initialErrorManagerLookup NbTopManager.get ().getInstanceLookup (), ! folder.getLookup (), NbTopManager.get().getModuleSystem().getManager().getModuleLookup(), } : new Lookup[] { --- 1187,1193 ---- // is actually ready and usable lkp.getLookups()[1], // initialErrorManagerLookup NbTopManager.get ().getInstanceLookup (), ! folderLookup, NbTopManager.get().getModuleSystem().getManager().getModuleLookup(), } : new Lookup[] { *************** *** 1137,1149 **** // is actually ready and usable lkp.getLookups()[2], // initialErrorManagerLookup NbTopManager.get ().getInstanceLookup (), ! folder.getLookup (), NbTopManager.get().getModuleSystem().getManager().getModuleLookup(), }; StartLog.logProgress ("prepared other Lookups"); // NOI18N lkp.setLookups (arr); StartLog.logProgress ("Lookups set"); // NOI18N if (!suppressMetaInfServicesLookup) { // Also listen for changes in modules, as META-INF/services/ would change: --- 1197,1213 ---- // is actually ready and usable lkp.getLookups()[2], // initialErrorManagerLookup NbTopManager.get ().getInstanceLookup (), ! folderLookup, NbTopManager.get().getModuleSystem().getManager().getModuleLookup(), }; StartLog.logProgress ("prepared other Lookups"); // NOI18N lkp.setLookups (arr); StartLog.logProgress ("Lookups set"); // NOI18N + + if (f.exists ()) { + new ConvertorListener ().taskFinished (null); + } if (!suppressMetaInfServicesLookup) { // Also listen for changes in modules, as META-INF/services/ would change: