Lines 13-22
Link Here
|
13 |
|
13 |
|
14 |
package org.netbeans.core.windows.persistence; |
14 |
package org.netbeans.core.windows.persistence; |
15 |
|
15 |
|
16 |
import org.netbeans.core.windows.Constants; |
|
|
17 |
import org.netbeans.core.windows.Debug; |
16 |
import org.netbeans.core.windows.Debug; |
18 |
import org.netbeans.core.windows.RegistryImpl; |
|
|
19 |
import org.netbeans.core.windows.WindowManagerImpl; |
20 |
import org.openide.ErrorManager; |
17 |
import org.openide.ErrorManager; |
21 |
import org.openide.cookies.InstanceCookie; |
18 |
import org.openide.cookies.InstanceCookie; |
22 |
import org.openide.cookies.SaveCookie; |
19 |
import org.openide.cookies.SaveCookie; |
Lines 36-47
Link Here
|
36 |
|
33 |
|
37 |
import java.beans.PropertyChangeEvent; |
34 |
import java.beans.PropertyChangeEvent; |
38 |
import java.beans.PropertyChangeListener; |
35 |
import java.beans.PropertyChangeListener; |
|
|
36 |
import java.io.ByteArrayInputStream; |
39 |
import java.io.FileNotFoundException; |
37 |
import java.io.FileNotFoundException; |
40 |
import java.io.IOException; |
38 |
import java.io.IOException; |
|
|
39 |
import java.io.InputStream; |
41 |
import java.io.InvalidObjectException; |
40 |
import java.io.InvalidObjectException; |
42 |
import java.io.NotSerializableException; |
41 |
import java.io.NotSerializableException; |
43 |
import java.lang.ref.WeakReference; |
42 |
import java.lang.ref.WeakReference; |
44 |
import java.util.*; |
43 |
import java.util.*; |
|
|
44 |
import org.openide.xml.XMLUtil; |
45 |
import org.xml.sax.EntityResolver; |
46 |
import org.xml.sax.InputSource; |
47 |
import org.xml.sax.SAXException; |
48 |
import org.xml.sax.XMLReader; |
49 |
import org.xml.sax.helpers.DefaultHandler; |
45 |
|
50 |
|
46 |
|
51 |
|
47 |
/** Manages persistent data of window system, currently stored in XML format. |
52 |
/** Manages persistent data of window system, currently stored in XML format. |
Lines 132-139
Link Here
|
132 |
/** Lock for synchronizing access to IDs. */ |
137 |
/** Lock for synchronizing access to IDs. */ |
133 |
private final Object LOCK_IDS = new Object(); |
138 |
private final Object LOCK_IDS = new Object(); |
134 |
|
139 |
|
135 |
/** true if we are saving just now, false otherwise */ |
140 |
/** xml parser */ |
136 |
private boolean isSaveInProgress; |
141 |
private XMLReader parser; |
137 |
|
142 |
|
138 |
private static PersistenceManager defaultInstance; |
143 |
private static PersistenceManager defaultInstance; |
139 |
|
144 |
|
Lines 533-546
Link Here
|
533 |
} |
538 |
} |
534 |
} |
539 |
} |
535 |
|
540 |
|
536 |
/** Destroys settings files of component with given string ID. */ |
|
|
537 |
private void deleteTopComponentFile(String stringId) throws IOException { |
538 |
DataObject dob = findTopComponentDataObject(getComponentsLocalFolder(), stringId); |
539 |
if(dob != null) { |
540 |
dob.delete(); |
541 |
} |
542 |
} |
543 |
|
544 |
/** Try to find the data object representing a top component ref in some folder. |
541 |
/** Try to find the data object representing a top component ref in some folder. |
545 |
* Only the TC name is known, but we can guess at some likely filenames before |
542 |
* Only the TC name is known, but we can guess at some likely filenames before |
546 |
* doing an exhaustive search. Produces either a FileObject or DataObject, |
543 |
* doing an exhaustive search. Produces either a FileObject or DataObject, |
Lines 810-878
Link Here
|
810 |
return srcName; |
807 |
return srcName; |
811 |
} |
808 |
} |
812 |
|
809 |
|
813 |
/** Called during projects switch BEFORE new project is loaded and AFTER |
|
|
814 |
* project layer is switched. */ |
815 |
public void resetAfterLayerSwitch() { |
816 |
resetAllTCPairs(); |
817 |
resetWindowManagerParser(); |
818 |
copySettingsFiles(); |
819 |
restoreAllTCPairs(); |
820 |
} |
821 |
|
822 |
/** Must be called during Project switch */ |
823 |
private void resetAllTCPairs () { |
824 |
synchronized(LOCK_IDS) { |
825 |
invalidIds = new HashSet(topComponent2IDMap.values()); |
826 |
/*System.out.println("-- PM.resetAllTCPairs ENTER"); |
827 |
for (Iterator it = invalidIds.iterator(); it.hasNext(); ) { |
828 |
System.out.println("-- item:" + it.next()); |
829 |
}*/ |
830 |
|
831 |
id2TopComponentMap.clear(); |
832 |
} |
833 |
} |
834 |
|
835 |
/** Must be called during Project switch */ |
836 |
private void restoreAllTCPairs () { |
837 |
synchronized(LOCK_IDS) { |
838 |
//System.out.println("-- PM.restoreAllTCPairs ENTER"); |
839 |
|
840 |
for (Iterator it = topComponent2IDMap.keySet().iterator(); it.hasNext(); ) { |
841 |
TopComponent tc = (TopComponent) it.next(); |
842 |
String id = (String) topComponent2IDMap.get(tc); |
843 |
//System.out.println("-- PM.restoreAllTCPairs id:" + id); |
844 |
if (isInvalidId(id)) { |
845 |
restorePair(tc, id); |
846 |
} |
847 |
} |
848 |
|
849 |
/*for (Iterator it = id2TopComponentMap.keySet().iterator(); it.hasNext(); ) { |
850 |
System.out.println("-- item:" + it.next()); |
851 |
}*/ |
852 |
|
853 |
Set toRemove = new HashSet(); |
854 |
for (Iterator it = topComponent2IDMap.keySet().iterator(); it.hasNext(); ) { |
855 |
TopComponent tc = (TopComponent) it.next(); |
856 |
String id = (String) topComponent2IDMap.get(tc); |
857 |
if (!id2TopComponentMap.containsKey(id)) { |
858 |
//System.out.println("-- PM.restoreAllTCPairs REMOVE tc:" + tc.getName()); |
859 |
toRemove.add(tc); |
860 |
} /*else { |
861 |
System.out.println("-- PM.restoreAllTCPairs KEEP tc:" + tc.getName()); |
862 |
}*/ |
863 |
} |
864 |
|
865 |
for (Iterator it = toRemove.iterator(); it.hasNext(); ) { |
866 |
topComponent2IDMap.remove(it.next()); |
867 |
} |
868 |
|
869 |
/*System.out.println("-- PM.restoreAllTCPairs topComponent2IDMap.size:" |
870 |
+ topComponent2IDMap.size()); |
871 |
System.out.println("-- PM.restoreAllTCPairs id2TopComponentMap.size:" |
872 |
+ id2TopComponentMap.size());*/ |
873 |
} |
874 |
} |
875 |
|
876 |
/** Reuses existing settings files */ |
810 |
/** Reuses existing settings files */ |
877 |
private String restorePair (TopComponent tc, String id) { |
811 |
private String restorePair (TopComponent tc, String id) { |
878 |
//System.out.println("++ PM.restorePair ENTER" |
812 |
//System.out.println("++ PM.restorePair ENTER" |
Lines 941-957
Link Here
|
941 |
failedCompsMap = null; |
875 |
failedCompsMap = null; |
942 |
} |
876 |
} |
943 |
|
877 |
|
944 |
private void setSaveInProgress (boolean isSaveInProgress) { |
|
|
945 |
this.isSaveInProgress = isSaveInProgress; |
946 |
} // TEMP |
947 |
|
948 |
/** @return true if saving of window system is currently being processed, |
949 |
* false otherwise. Used to disallow interferation of parsing and saving. |
950 |
*/ |
951 |
boolean isSaveInProgress () { |
952 |
return isSaveInProgress; |
953 |
} // TEMP |
954 |
|
955 |
/** Accessor to WindowManagerParser instance. */ |
878 |
/** Accessor to WindowManagerParser instance. */ |
956 |
public WindowManagerParser getWindowManagerParser () { |
879 |
public WindowManagerParser getWindowManagerParser () { |
957 |
if (windowManagerParser == null) { |
880 |
if (windowManagerParser == null) { |
Lines 960-968
Link Here
|
960 |
return windowManagerParser; |
883 |
return windowManagerParser; |
961 |
} |
884 |
} |
962 |
|
885 |
|
963 |
/** Reset WindowManagerParser instance. Called during project switch. */ |
886 |
/** Returns a XML parser. The same parser can be returned assuming that config files |
964 |
private void resetWindowManagerParser() { |
887 |
* are parser sequentially. |
965 |
windowManagerParser = null; |
888 |
* |
|
|
889 |
* @return XML parser with set content handler, errror handler |
890 |
* and entity resolver. |
891 |
*/ |
892 |
public XMLReader getXMLParser (DefaultHandler h) throws SAXException { |
893 |
if (parser == null) { |
894 |
// get non validating, not namespace aware parser |
895 |
parser = XMLUtil.createXMLReader(); |
896 |
parser.setEntityResolver(new EntityResolver () { |
897 |
/** Implementation of entity resolver. Points to the local DTD |
898 |
* for our public ID */ |
899 |
public InputSource resolveEntity (String publicId, String systemId) |
900 |
throws SAXException { |
901 |
if (ModeParser.INSTANCE_DTD_ID_1_0.equals(publicId) |
902 |
|| ModeParser.INSTANCE_DTD_ID_1_1.equals(publicId) |
903 |
|| ModeParser.INSTANCE_DTD_ID_1_2.equals(publicId) |
904 |
|| ModeParser.INSTANCE_DTD_ID_2_0.equals(publicId) |
905 |
|| ModeParser.INSTANCE_DTD_ID_2_1.equals(publicId) |
906 |
|| GroupParser.INSTANCE_DTD_ID_2_0.equals(publicId) |
907 |
|| TCGroupParser.INSTANCE_DTD_ID_2_0.equals(publicId) |
908 |
|| TCRefParser.INSTANCE_DTD_ID_1_0.equals(publicId) |
909 |
|| TCRefParser.INSTANCE_DTD_ID_2_0.equals(publicId) |
910 |
|| TCRefParser.INSTANCE_DTD_ID_2_1.equals(publicId) |
911 |
|| WindowManagerParser.INSTANCE_DTD_ID_1_0.equals(publicId) |
912 |
|| WindowManagerParser.INSTANCE_DTD_ID_1_1.equals(publicId) |
913 |
|| WindowManagerParser.INSTANCE_DTD_ID_2_0.equals(publicId) |
914 |
|| WindowManagerParser.INSTANCE_DTD_ID_2_1.equals(publicId)) { |
915 |
InputStream is = new ByteArrayInputStream(new byte[0]); |
916 |
return new InputSource(is); |
917 |
} |
918 |
return null; // i.e. follow advice of systemID |
919 |
} |
920 |
}); |
921 |
} |
922 |
parser.setContentHandler(h); |
923 |
parser.setErrorHandler(h); |
924 |
return parser; |
966 |
} |
925 |
} |
967 |
|
926 |
|
968 |
/** Adds TopComponent Id to set of used Ids. Called from ModeParser and |
927 |
/** Adds TopComponent Id to set of used Ids. Called from ModeParser and |
Lines 1024-1030
Link Here
|
1024 |
* @return window system configuration |
983 |
* @return window system configuration |
1025 |
*/ |
984 |
*/ |
1026 |
public WindowManagerConfig loadWindowSystem() { |
985 |
public WindowManagerConfig loadWindowSystem() { |
1027 |
//long start = System.currentTimeMillis(); |
986 |
// long start = System.currentTimeMillis(); |
1028 |
|
987 |
|
1029 |
//Clear set of used tc_id |
988 |
//Clear set of used tc_id |
1030 |
synchronized (LOCK_IDS) { |
989 |
synchronized (LOCK_IDS) { |
Lines 1050-1058
Link Here
|
1050 |
changeHandler = new ModuleChangeHandler(); |
1009 |
changeHandler = new ModuleChangeHandler(); |
1051 |
changeHandler.startHandling(); |
1010 |
changeHandler.startHandling(); |
1052 |
} |
1011 |
} |
1053 |
//long end = System.currentTimeMillis(); |
1012 |
parser = null; // clear the ref to XML parser |
1054 |
//long diff = end - start; |
1013 |
|
1055 |
//System.out.println("Loading of window system takes " + diff + " ms"); |
1014 |
// long end = System.currentTimeMillis(); |
|
|
1015 |
// long diff = end - start; |
1016 |
// System.out.println("Loading of window system takes " + diff + " ms"); |
1056 |
return wmc; |
1017 |
return wmc; |
1057 |
} |
1018 |
} |
1058 |
|
1019 |
|
Lines 1245-1251
Link Here
|
1245 |
Lookup.getDefault().lookup(new Lookup.Template(ModuleInfo.class)); |
1206 |
Lookup.getDefault().lookup(new Lookup.Template(ModuleInfo.class)); |
1246 |
Collection infos = modulesResult.allInstances(); |
1207 |
Collection infos = modulesResult.allInstances(); |
1247 |
ModuleInfo curInfo = null; |
1208 |
ModuleInfo curInfo = null; |
1248 |
boolean equalsName = false; |
|
|
1249 |
for (Iterator iter = infos.iterator(); iter.hasNext(); ) { |
1209 |
for (Iterator iter = infos.iterator(); iter.hasNext(); ) { |
1250 |
curInfo = (ModuleInfo)iter.next(); |
1210 |
curInfo = (ModuleInfo)iter.next(); |
1251 |
// search for equal base name and then compare release and |
1211 |
// search for equal base name and then compare release and |