KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > persistence > ModeParser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.persistence;
21
22 import java.util.logging.Level JavaDoc;
23 import org.netbeans.core.windows.Constants;
24 import org.netbeans.core.windows.Debug;
25 import org.netbeans.core.windows.SplitConstraint;
26 import org.openide.filesystems.FileLock;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.modules.ModuleInfo;
30 import org.openide.modules.SpecificationVersion;
31 import org.openide.util.NbBundle;
32 import org.openide.util.TopologicalSortException;
33 import org.openide.util.Utilities;
34 import org.xml.sax.*;
35 import org.xml.sax.helpers.DefaultHandler JavaDoc;
36
37 import java.awt.*;
38 import java.io.*;
39 import java.util.*;
40 import java.util.List JavaDoc;
41 import java.util.logging.Logger JavaDoc;
42
43
44 /**
45  * Handle loading/saving of Mode configuration data.
46  *
47  * @author Marek Slama
48  */

49
50 class ModeParser {
51     
52     public static final String JavaDoc INSTANCE_DTD_ID_1_0
53         = "-//NetBeans//DTD Mode Properties 1.0//EN"; // NOI18N
54
public static final String JavaDoc INSTANCE_DTD_ID_1_1
55         = "-//NetBeans//DTD Mode Properties 1.1//EN"; // NOI18N
56
public static final String JavaDoc INSTANCE_DTD_ID_1_2
57         = "-//NetBeans//DTD Mode Properties 1.2//EN"; // NOI18N
58
public static final String JavaDoc INSTANCE_DTD_ID_2_0
59         = "-//NetBeans//DTD Mode Properties 2.0//EN"; // NOI18N
60
public static final String JavaDoc INSTANCE_DTD_ID_2_1
61         = "-//NetBeans//DTD Mode Properties 2.1//EN"; // NOI18N
62
public static final String JavaDoc INSTANCE_DTD_ID_2_2
63         = "-//NetBeans//DTD Mode Properties 2.2//EN"; // NOI18N
64
public static final String JavaDoc INSTANCE_DTD_ID_2_3
65         = "-//NetBeans//DTD Mode Properties 2.3//EN"; // NOI18N
66

67     /** Name of extended attribute for order of children */
68     private static final String JavaDoc EA_ORDER = "WinSys-TCRef-Order"; // NOI18N
69

70     /** Separator of names of two files. The first file should be before
71      * the second one in partial ordering. */

72     private static final char SEP = '/';
73     
74     private static final boolean DEBUG = Debug.isLoggable(ModeParser.class);
75     
76     /** Module parent folder */
77     private FileObject moduleParentFolder;
78     
79     /** Local parent folder */
80     private FileObject localParentFolder;
81     
82     private InternalConfig internalConfig;
83     
84     /** Map of TCRefParser instances. Used for fast access. */
85     private Map<String JavaDoc, TCRefParser> tcRefParserMap = new HashMap<String JavaDoc, TCRefParser>(19);
86     
87     /** map of names of tcRefs to their index or null */
88     private Map<String JavaDoc,Integer JavaDoc> tcRefOrder;
89     
90     /** Unique mode name from file name */
91     private String JavaDoc modeName;
92     
93     /** true if wsmode file is present in module folder */
94     private boolean inModuleFolder;
95     /** true if wsmode file is present in local folder */
96     private boolean inLocalFolder;
97     
98     /** Contains names of all tcRefs placed in local folder <String> */
99     private Set maskSet;
100     
101     public ModeParser (String JavaDoc name, Set maskSet) {
102         this.modeName = name;
103         this.maskSet = maskSet;
104     }
105     
106     /** Load mode configuration including all tcrefs. */
107     ModeConfig load () throws IOException {
108         //if (DEBUG) Debug.log(ModeParser.class, "load ENTER" + " mo:" + name);
109
ModeConfig mc = new ModeConfig();
110         readProperties(mc);
111         if (mc.kind == Constants.MODE_KIND_SLIDING && mc.side != null && !mc.permanent) {
112             // now we have the 4.0 anonymous mode for the slide bar. replace with the
113
// predefined ones..
114
mc.permanent = true;
115             // well, the names are defined in core/ui.
116
// shall we at all care about the name? or is making it permanent just fine?
117
// if (mc.side.equals(Constants.BOTTOM)) {
118
// mc.name = "bottomSlidingSide"; //NOI18N
119
// } else if (mc.side.equals(Constants.LEFT)) {
120
// mc.name = "leftSlidingSide"; //NOI18N
121
// } else if (mc.side.equals(Constants.RIGHT)) {
122
// mc.name = "rightSlidingSide"; //NOI18N
123
// }
124
}
125         readTCRefs(mc);
126         //if (DEBUG) Debug.log(ModeParser.class, "load LEAVE" + " mo:" + name);
127
return mc;
128     }
129     
130     /** Save mode configuration including all tcrefs. */
131     void save (ModeConfig mc) throws IOException {
132         //if (DEBUG) Debug.log(ModeParser.class, "save ENTER" + " mo:" + name);
133
writeProperties(mc);
134         writeTCRefs(mc);
135         //if (DEBUG) Debug.log(ModeParser.class, "save LEAVE" + " mo:" + name);
136
}
137     
138     private void readProperties (ModeConfig mc) throws IOException {
139         if (DEBUG) Debug.log(ModeParser.class, "readProperties ENTER" + " mo:" + getName());
140         PropertyHandler propertyHandler = new PropertyHandler();
141         InternalConfig internalCfg = getInternalConfig();
142         internalCfg.clear();
143         propertyHandler.readData(mc, internalCfg);
144         
145         /*if (DEBUG) Debug.log(ModeParser.class, " specVersion: " + internalCfg.specVersion);
146         if (DEBUG) Debug.log(ModeParser.class, " moduleCodeNameBase: " + internalCfg.moduleCodeNameBase);
147         if (DEBUG) Debug.log(ModeParser.class, " moduleCodeNameRelease: " + internalCfg.moduleCodeNameRelease);
148         if (DEBUG) Debug.log(ModeParser.class, "moduleSpecificationVersion: " + internalCfg.moduleSpecificationVersion);*/

149         
150         if (DEBUG) Debug.log(ModeParser.class, "readProperties LEAVE" + " mo:" + getName());
151     }
152     
153     private void readTCRefs (ModeConfig mc) throws IOException {
154         if (DEBUG) Debug.log(ModeParser.class, "readTCRefs ENTER" + " mo:" + getName());
155         
156         for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
157             TCRefParser tcRefParser = tcRefParserMap.get(it.next());
158             tcRefParser.setInModuleFolder(false);
159             tcRefParser.setInLocalFolder(false);
160         }
161         
162         //if (DEBUG) Debug.log(ModeParser.class, "moduleParentFolder: " + moduleParentFolder);
163
//if (DEBUG) Debug.log(ModeParser.class, " localParentFolder: " + localParentFolder);
164
//if (DEBUG) Debug.log(ModeParser.class, " moduleModeFolder: " + moduleModeFolder);
165
//if (DEBUG) Debug.log(ModeParser.class, " localModeFolder: " + localModeFolder);
166

167         if (isInModuleFolder()) {
168             FileObject moduleModeFolder = moduleParentFolder.getFileObject(modeName);
169             if (moduleModeFolder != null) {
170                 FileObject [] files = moduleModeFolder.getChildren();
171                 for (int i = 0; i < files.length; i++) {
172                     //if (DEBUG) Debug.log(ModeParser.class, "-- -- MODULE fo[" + i + "]: " + files[i]);
173
if (!files[i].isFolder() && PersistenceManager.TCREF_EXT.equals(files[i].getExt())) {
174                         //wstcref file
175
TCRefParser tcRefParser;
176                         if (tcRefParserMap.containsKey(files[i].getName())) {
177                             tcRefParser = tcRefParserMap.get(files[i].getName());
178                         } else {
179                             tcRefParser = new TCRefParser(files[i].getName());
180                             tcRefParserMap.put(files[i].getName(), tcRefParser);
181                         }
182                         tcRefParser.setInModuleFolder(true);
183                         tcRefParser.setModuleParentFolder(moduleModeFolder);
184                     }
185                 }
186             }
187         }
188
189         if (isInLocalFolder()) {
190             FileObject localModeFolder = localParentFolder.getFileObject(modeName);
191             if (localModeFolder != null) {
192                 FileObject [] files = localModeFolder.getChildren();
193                 for (int i = 0; i < files.length; i++) {
194                     //if (DEBUG) Debug.log(ModeParser.class, "-- -- LOCAL fo[" + i + "]: " + files[i]);
195
if (!files[i].isFolder() && PersistenceManager.TCREF_EXT.equals(files[i].getExt())) {
196                         //wstcref file
197
TCRefParser tcRefParser = tcRefParserMap.get(files[i].getName());
198                         if (tcRefParser== null) {
199                             tcRefParser = new TCRefParser(files[i].getName());
200                             tcRefParserMap.put(files[i].getName(), tcRefParser);
201                         }
202                         tcRefParser.setInLocalFolder(true);
203                         tcRefParser.setLocalParentFolder(localModeFolder);
204                     }
205                 }
206             }
207         }
208         
209         /*for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
210             TCRefParser tcRefParser = (TCRefParser) tcRefParserMap.get(it.next());
211             if (DEBUG) Debug.log(ModeParser.class, "tcRefParser: " + tcRefParser.getName()
212             + " isInModuleFolder:" + tcRefParser.isInModuleFolder()
213             + " isInLocalFolder:" + tcRefParser.isInLocalFolder());
214         }*/

215
216         //Read order
217
readOrder();
218         
219         List JavaDoc<TCRefParser> localList = new ArrayList<TCRefParser>(10);
220         Map<String JavaDoc, TCRefParser> localMap = new HashMap<String JavaDoc, TCRefParser>( tcRefParserMap );
221         
222         if (tcRefOrder != null) {
223             //if (DEBUG) Debug.log(ModeParser.class, "-- -- ORDER IS DEFINED");
224
//if (DEBUG) Debug.log(ModeParser.class, "-- -- map.size:" + localMap.size());
225
//if (DEBUG) Debug.log(ModeParser.class, "-- -- order.size:" + tcRefOrder.size());
226
TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()];
227             for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) {
228                 Map.Entry en = (Map.Entry) it.next();
229                 String JavaDoc tcRefName = (String JavaDoc) en.getKey();
230                 int index = ((Integer JavaDoc) en.getValue()).intValue();
231                 TCRefParser tcRefParser = (TCRefParser) localMap.remove(tcRefName);
232                 //Put instances to array according to defined order
233
//Order should be defined from 0 to N-1
234
//if (DEBUG) Debug.log(ModeParser.class, "-- -- ADD [" + index + "]: " + tcRefParser.getName());
235
tcRefParserArray[index] = tcRefParser;
236             }
237             for (int i = 0; i < tcRefParserArray.length; i++) {
238                 if (tcRefParserArray[i] != null) {
239                     localList.add(tcRefParserArray[i]);
240                 }
241             }
242             //Append remaining instances if any
243
for (String JavaDoc s: localMap.keySet()) {
244                 TCRefParser tcRefParser = localMap.get(s);
245                 localList.add(tcRefParser);
246             }
247         } else {
248             //if (DEBUG) Debug.log(ModeParser.class, "-- -- NO ORDER, USING PARTIAL ORDERING");
249
for (String JavaDoc s: localMap.keySet()) {
250                 TCRefParser tcRefParser = localMap.get(s);
251                 localList.add(tcRefParser);
252             }
253             
254             /*if (DEBUG) Debug.log(ModeParser.class, "LIST BEFORE SORT");
255             for (int i = 0; i < localList.size(); i++) {
256                 TCRefParser tcRefParser = (TCRefParser) localList.get(i);
257                 if (DEBUG) Debug.log(ModeParser.class, " p[" + i + "]: " + tcRefParser.getName());
258             }*/

259             
260             //Sort using partial ordering
261
localList = carefullySort(localList);
262             
263             /*if (DEBUG) Debug.log(ModeParser.class, "LIST AFTER SORT");
264             for (int i = 0; i < localList.size(); i++) {
265                 TCRefParser tcRefParser = (TCRefParser) localList.get(i);
266                 if (DEBUG) Debug.log(ModeParser.class, " p[" + i + "]: " + tcRefParser.getName());
267             }*/

268             
269             if (tcRefOrder == null) {
270                 tcRefOrder = new HashMap<String JavaDoc,Integer JavaDoc>(19);
271             }
272             tcRefOrder.clear();
273             for (int i = 0; i < localList.size(); i++) {
274                 TCRefParser tcRefParser = localList.get(i);
275                 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i));
276             }
277             writeOrder();
278         }
279         
280         //Check if corresponding module is present and enabled.
281
//We must load configuration data first because module info is stored in XML.
282
List JavaDoc<TCRefConfig> tcRefCfgList = new ArrayList<TCRefConfig>(localList.size());
283         List JavaDoc<TCRefParser> toRemove = new ArrayList<TCRefParser>(localList.size());
284         for (int i = 0; i < localList.size(); i++) {
285             TCRefParser tcRefParser = localList.get(i);
286             //Special masking: Ignore tcRef which is present in module folder and
287
//is present in local folder in DIFFERENT mode. (ie. when TopComponent defined
288
//by module was moved to another module) It is to avoid creating _hidden file =>
289
//trouble when disable/enable module.
290
if (maskSet.contains(tcRefParser.getName())) {
291                 if (tcRefParser.isInModuleFolder() && !tcRefParser.isInLocalFolder()) {
292                     toRemove.add(tcRefParser);
293                     continue;
294                 }
295             }
296             TCRefConfig tcRefCfg;
297             try {
298                 tcRefCfg = tcRefParser.load();
299             } catch (IOException exc) {
300                 //If reading of one tcRef fails we want to log message
301
//and continue.
302
Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc);
303                 continue;
304             }
305             boolean tcRefAccepted = acceptTCRef(tcRefParser, tcRefCfg);
306             if (tcRefAccepted) {
307                 tcRefCfgList.add(tcRefCfg);
308             } else {
309                 toRemove.add(tcRefParser);
310                 deleteLocalTCRef(tcRefParser.getName());
311             }
312         }
313         
314         for (int i = 0; i < toRemove.size(); i++) {
315             TCRefParser tcRefParser = toRemove.get(i);
316             localList.remove(tcRefParser);
317             tcRefParserMap.remove(tcRefParser.getName());
318         }
319         
320         //Update order if any tcRef was removed
321
if (toRemove.size() > 0) {
322             if (tcRefOrder == null) {
323                 tcRefOrder = new HashMap<String JavaDoc,Integer JavaDoc>(19);
324             }
325             tcRefOrder.clear();
326             for (int i = 0; i < localList.size(); i++) {
327                 TCRefParser tcRefParser = (TCRefParser) localList.get(i);
328                 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i));
329             }
330             writeOrder();
331         }
332         
333         mc.tcRefConfigs =
334             tcRefCfgList.toArray(new TCRefConfig[tcRefCfgList.size()]);
335         
336         PersistenceManager pm = PersistenceManager.getDefault();
337         for (int i = 0; i < mc.tcRefConfigs.length; i++) {
338             pm.addUsedTCId(mc.tcRefConfigs[i].tc_id);
339         }
340         
341         if (DEBUG) Debug.log(ModeParser.class, "readTCRefs LEAVE" + " mo:" + getName());
342     }
343     
344     /** Checks if module for given tcRef exists.
345      * @return true if tcRef is valid - its module exists
346      */

347     private boolean acceptTCRef (TCRefParser tcRefParser, TCRefConfig config) {
348         InternalConfig cfg = tcRefParser.getInternalConfig();
349         //Check module info
350
if (cfg.moduleCodeNameBase != null) {
351             ModuleInfo curModuleInfo = PersistenceManager.findModule
352                                             (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
353                                              cfg.moduleSpecificationVersion);
354             if (curModuleInfo == null) {
355                 PersistenceManager.LOG.fine("Cannot find module \'" +
356                           cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " +
357                           cfg.moduleSpecificationVersion + "\' for tcref with id \'" + config.tc_id + "\'"); // NOI18N
358

359             }
360             return (curModuleInfo != null) && curModuleInfo.isEnabled();
361         } else {
362             //No module info
363
return true;
364         }
365     }
366     
367     private void writeProperties (ModeConfig mc) throws IOException {
368         if (DEBUG) Debug.log(ModeParser.class, "writeProperties ENTER" + " mo:" + getName());
369         PropertyHandler propertyHandler = new PropertyHandler();
370         InternalConfig internalCfg = getInternalConfig();
371         propertyHandler.writeData(mc, internalCfg);
372         if (DEBUG) Debug.log(ModeParser.class, "writeProperties LEAVE" + " mo:" + getName());
373     }
374     
375     private void writeTCRefs (ModeConfig mc) throws IOException {
376         if (DEBUG) Debug.log(ModeParser.class, "writeTCRefs ENTER" + " mo:" + getName());
377         //Step 0: Create order
378
if (mc.tcRefConfigs.length > 0) {
379             if (tcRefOrder == null) {
380                 tcRefOrder = new HashMap<String JavaDoc,Integer JavaDoc>(19);
381             }
382             tcRefOrder.clear();
383             for (int i = 0; i < mc.tcRefConfigs.length; i++) {
384                 tcRefOrder.put(mc.tcRefConfigs[i].tc_id, Integer.valueOf(i));
385             }
386         } else {
387             tcRefOrder = null;
388         }
389         writeOrder();
390         //Step 1: Clean obsolete tcRef parsers
391
Map<String JavaDoc, TCRefConfig> tcRefConfigMap = new HashMap<String JavaDoc, TCRefConfig>(19);
392         for (int i = 0; i < mc.tcRefConfigs.length; i++) {
393             //if (DEBUG) Debug.log(ModeParser.class, "-- -- tcRefCfg[" + i + "]: " + mc.tcRefConfigs[i].tc_id);
394
tcRefConfigMap.put(mc.tcRefConfigs[i].tc_id, mc.tcRefConfigs[i]);
395         }
396         TCRefParser tcRefParser;
397         List JavaDoc<String JavaDoc> toDelete = new ArrayList<String JavaDoc>(10);
398         for (String JavaDoc s: tcRefParserMap.keySet()) {
399             tcRefParser = tcRefParserMap.get(s);
400             if (!tcRefConfigMap.containsKey(tcRefParser.getName())) {
401                 toDelete.add(tcRefParser.getName());
402             }
403         }
404         for (int i = 0; i < toDelete.size(); i++) {
405             //if (DEBUG) Debug.log(ModeParser.class, " ** REMOVE FROM MAP tcRefParser: " + toDelete.get(i));
406
tcRefParserMap.remove(toDelete.get(i));
407             //if (DEBUG) Debug.log(ModeParser.class, " ** DELETE tcRefParser: " + toDelete.get(i));
408
deleteLocalTCRef(toDelete.get(i));
409         }
410         
411         //Step 2: Create missing tcRefs parsers
412
//if (DEBUG) Debug.log(ModeParser.class, "-- -- mc.tcRefConfigs.length:" + mc.tcRefConfigs.length);
413
for (int i = 0; i < mc.tcRefConfigs.length; i++) {
414             //if (DEBUG) Debug.log(ModeParser.class, "-- -- tcRefCfg[" + i + "]: " + mc.tcRefConfigs[i].tc_id);
415
if (!tcRefParserMap.containsKey(mc.tcRefConfigs[i].tc_id)) {
416                 tcRefParser = new TCRefParser(mc.tcRefConfigs[i].tc_id);
417                 //if (DEBUG) Debug.log(ModeParser.class, " ** CREATE tcRefParser:" + tcRefParser.getName());
418
tcRefParserMap.put(mc.tcRefConfigs[i].tc_id, tcRefParser);
419             }
420         }
421         
422         //Step 3: Save all tcRefs
423
FileObject localFolder = localParentFolder.getFileObject(getName());
424         if ((localFolder == null) && (tcRefParserMap.size() > 0)) {
425             //Create local mode folder
426
//if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.writeTCRefs" + " CREATE LOCAL FOLDER");
427
localFolder = FileUtil.createFolder(localParentFolder, getName());
428         }
429         //if (DEBUG) Debug.log(ModeParser.class, "writeTCRefs" + " localFolder:" + localFolder);
430

431         for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) {
432             tcRefParser = tcRefParserMap.get(it.next());
433             tcRefParser.setLocalParentFolder(localFolder);
434             tcRefParser.setInLocalFolder(true);
435             tcRefParser.save((TCRefConfig) tcRefConfigMap.get(tcRefParser.getName()));
436         }
437         
438         if (DEBUG) Debug.log(ModeParser.class, "writeTCRefs LEAVE" + " mo:" + getName());
439     }
440     
441     private void deleteLocalTCRef (String JavaDoc tcRefName) {
442         if (DEBUG) Debug.log(ModeParser.class, "deleteLocalTCRef" + " tcRefName:" + tcRefName);
443         if (localParentFolder == null) {
444             return;
445         }
446         FileObject localModeFolder = localParentFolder.getFileObject(modeName);
447         if (localModeFolder == null) {
448             return;
449         }
450         FileObject tcRefFO = localModeFolder.getFileObject(tcRefName, PersistenceManager.TCREF_EXT);
451         if (tcRefFO != null) {
452             PersistenceManager.deleteOneFO(tcRefFO);
453         }
454     }
455     
456     //////////////////////////////////////////////////////////////////
457
// BEGIN Code to keep order of TopComponents in Mode.
458
//
459
// It is taken from FolderOrder and FolderList where it is used
460
// to keep order of DataObjects.
461
//////////////////////////////////////////////////////////////////
462

463     /** Reads the order of tcRefs from disk.
464      */

465     private void readOrder () {
466         if (localParentFolder == null) {
467             try {
468                 localParentFolder = PersistenceManager.getDefault().getModesLocalFolder();
469             }
470             catch (IOException ex) {
471                 Logger.getLogger(ModeParser.class.getName()).log(
472                         Level.WARNING, "Cannot get access to lcoal modes folder", ex); // NOI18N
473
return;
474             }
475         }
476         FileObject localModeFolder = localParentFolder.getFileObject(modeName);
477         if (localModeFolder == null) {
478             tcRefOrder = null;
479             return;
480         }
481         Object JavaDoc o = localModeFolder.getAttribute(EA_ORDER);
482         
483         if (o == null) {
484             tcRefOrder = null;
485             return;
486         } else if (o instanceof String JavaDoc) {
487             String JavaDoc sepNames = (String JavaDoc) o;
488             Map<String JavaDoc,Integer JavaDoc> map = new HashMap<String JavaDoc,Integer JavaDoc>(19);
489             StringTokenizer tok = new StringTokenizer(sepNames, "/"); // NOI18N
490
int i = 0;
491             while (tok.hasMoreTokens()) {
492                 String JavaDoc tcRefName = tok.nextToken();
493                 map.put(tcRefName, Integer.valueOf(i));
494                 i++;
495             }
496             tcRefOrder = map;
497             return;
498         } else {
499             // Unknown format:
500
tcRefOrder = null;
501             return;
502         }
503     }
504     
505     /** Stores the order of tcRefs to disk.
506     */

507     private void writeOrder () throws IOException {
508         //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.writeOrder ENTER" + " mo:" + getName());
509
if (localParentFolder == null) {
510             localParentFolder = PersistenceManager.getDefault().getModesLocalFolder();
511         }
512         
513         FileObject localModeFolder = localParentFolder.getFileObject(modeName);
514         if (localModeFolder == null) {
515             //Create local mode folder
516
localModeFolder = FileUtil.createFolder(localParentFolder, modeName);
517         }
518         if (tcRefOrder == null) {
519             //Clear the order
520
localModeFolder.setAttribute(EA_ORDER, null);
521         } else {
522             // Stores list of file names separated by /
523
String JavaDoc[] tcRefNames = new String JavaDoc[tcRefOrder.size()];
524             for (Map.Entry<String JavaDoc, Integer JavaDoc> en: tcRefOrder.entrySet()) {
525                 String JavaDoc tcRefName = en.getKey();
526                 int index = en.getValue().intValue();
527                 tcRefNames[index] = tcRefName;
528             }
529             StringBuilder JavaDoc buf = new StringBuilder JavaDoc(255);
530             for (int i = 0; i < tcRefNames.length; i++) {
531                 if (i > 0) {
532                     buf.append(SEP);
533                 }
534                 buf.append(tcRefNames[i]);
535             }
536             //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.writeOrder buf:" + buf);
537
localModeFolder.setAttribute(EA_ORDER, buf.toString ());
538         }
539     }
540     
541     /** Read the list of intended partial orders from disk.
542      * Each element is a string of the form "a<b" for a, b filenames
543      * with extension, where a should come before b.
544      */

545     private Set<String JavaDoc> readPartials () {
546         //if (DEBUG) Debug.log(ModeParser.class, "++ ++");
547
//if (DEBUG) Debug.log(ModeParser.class, "++ ModeParser.readPartials ENTER");
548
Set<String JavaDoc> s = new HashSet<String JavaDoc>(19);
549         
550         //Partials are defined only in module folder
551
if (moduleParentFolder == null) {
552             return s;
553         }
554         FileObject moduleModeFolder = moduleParentFolder.getFileObject(modeName);
555         if (moduleModeFolder == null) {
556             //if (DEBUG) Debug.log(ModeParser.class, "++ ModeParser.readPartials LEAVE 1");
557
return s;
558         }
559         
560         Enumeration e = moduleModeFolder.getAttributes();
561         while (e.hasMoreElements()) {
562             String JavaDoc name = (String JavaDoc) e.nextElement();
563             if (name.indexOf(SEP) != -1) {
564                 Object JavaDoc value = moduleModeFolder.getAttribute(name);
565                 if ((value instanceof Boolean JavaDoc) && ((Boolean JavaDoc) value).booleanValue()) {
566                     int ind = name.indexOf(SEP);
567                     //Remove file extension 'wstcref'.
568
String JavaDoc name1 = name.substring(0, ind);
569                     String JavaDoc name2 = name.substring(ind + 1);
570                     //if (DEBUG) Debug.log(ModeParser.class, "name1:" + name1 + " name2:" + name2);
571
int indExt = name1.indexOf('.');
572                     if (indExt != -1) {
573                         name1 = name1.substring(0, indExt);
574                     }
575                     indExt = name2.indexOf('.');
576                     if (indExt != -1) {
577                         name2 = name2.substring(0, indExt);
578                     }
579                     //if (DEBUG) Debug.log(ModeParser.class, "++ ModeParser.readPartials name BEFORE:" + name);
580
name = name1 + SEP + name2;
581                     s.add(name);
582                     //if (DEBUG) Debug.log(ModeParser.class, "++ ModeParser.readPartials name AFTER:" + name);
583
}
584             }
585         }
586         //if (DEBUG) Debug.log(ModeParser.class, "++ ModeParser.readPartials LEAVE 2");
587
//if (DEBUG) Debug.log(ModeParser.class, "++");
588
return s;
589     }
590     
591     /**
592      * Get ordering constraints for this folder.
593      * Returns a map from data objects to lists of data objects they should precede.
594      * @param objects a collection of data objects known to be in the folder
595      * @return a constraint map, or null if there are no constraints
596      */

597     private Map<TCRefParser,List JavaDoc<TCRefParser>> getOrderingConstraints (List JavaDoc<TCRefParser> tcRefParsers) {
598         //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints ENTER");
599
final Set<String JavaDoc> partials = readPartials();
600         if (partials.isEmpty()) {
601             //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints LEAVE 1");
602
return null;
603         } else {
604             //Remove items from partials which are in ordering
605
if (tcRefOrder != null) {
606                 //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints CLEAN partials");
607
Iterator it = partials.iterator();
608                 while (it.hasNext()) {
609                     String JavaDoc constraint = (String JavaDoc) it.next();
610                     //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints CLEAN constraint:" + constraint);
611
int idx = constraint.indexOf(SEP);
612                     String JavaDoc a = constraint.substring(0, idx);
613                     String JavaDoc b = constraint.substring(idx + 1);
614                     //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints CLEAN a:" + a + " b:" + b);
615
if (tcRefOrder.containsKey(a) && tcRefOrder.containsKey(b)) {
616                         //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints REMOVE:" + constraint);
617
it.remove();
618                     } /*else {
619                         if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints KEEP:" + constraint);
620                     }*/

621                 }
622             }
623             Map<String JavaDoc, TCRefParser> objectsByName = new HashMap<String JavaDoc, TCRefParser>(19);
624             for (int i = 0; i < tcRefParsers.size(); i++) {
625                 TCRefParser tcRefParser = tcRefParsers.get(i);
626                 objectsByName.put(tcRefParser.getName(), tcRefParser);
627             }
628             Map<TCRefParser,List JavaDoc<TCRefParser>> m = new HashMap<TCRefParser,List JavaDoc<TCRefParser>>(19);
629             for (String JavaDoc constraint: partials) {
630                 int idx = constraint.indexOf(SEP);
631                 String JavaDoc a = constraint.substring(0, idx);
632                 String JavaDoc b = constraint.substring(idx + 1);
633                 if ((tcRefOrder != null) && (tcRefOrder.containsKey(a) && tcRefOrder.containsKey(b))) {
634                     continue;
635                 }
636                 TCRefParser ad = objectsByName.get(a);
637                 if (ad == null) {
638                     continue;
639                 }
640                 TCRefParser bd = objectsByName.get(b);
641                 if (bd == null) {
642                     continue;
643                 }
644                 List JavaDoc<TCRefParser> l = m.get(ad);
645                 if (l == null) {
646                     m.put(ad, l = new LinkedList<TCRefParser>());
647                 }
648                 l.add(bd);
649             }
650             //if (DEBUG) Debug.log(ModeParser.class, "getOrderingConstraints LEAVE 2");
651
return m;
652         }
653     }
654     
655     /** Sort a list of TCRefParsers carefully.
656      * If the partial ordering is self-contradictory,
657      * it will be ignored and a warning issued.
658      * @param l the list to sort
659      * @return the sorted list (may or may not be the same)
660      */

661     private List JavaDoc<TCRefParser> carefullySort (List JavaDoc<TCRefParser> l) {
662         Map<TCRefParser, List JavaDoc<TCRefParser>> constraints = getOrderingConstraints(l);
663         if (constraints == null) {
664             return l;
665         } else {
666             try {
667                 return Utilities.topologicalSort(l, constraints);
668             } catch (TopologicalSortException ex) {
669                 @SuppressWarnings JavaDoc("unchecked")
670                 List JavaDoc<TCRefParser> corrected = ex.partialSort();
671                 PersistenceManager.LOG.log(Level.WARNING,"Note: Mode " + getName() // NOI18N
672
+ " cannot be consistently sorted due to ordering conflicts.", ex); // NOI18N
673
PersistenceManager.LOG.log(Level.WARNING,"Using partial sort: " + corrected); // NOI18N
674
return corrected;
675             }
676         }
677     }
678     //////////////////////////////////////////////////////////////////
679
// END Code to keep order of TopComponents in Mode.
680
//////////////////////////////////////////////////////////////////
681

682     /** Removes TCRefParser from ModeParser and cleans wstcref file from local folder.
683      * @param tcRefName unique name of tcRef
684      */

685     void removeTCRef (String JavaDoc tcRefName) {
686         if (DEBUG) Debug.log(ModeParser.class, "removeTCRef ENTER" + " tcRef:" + tcRefName);
687         //Update order
688
List JavaDoc<TCRefParser> localList = new ArrayList<TCRefParser>(10);
689         Map localMap = (Map) ((HashMap) tcRefParserMap).clone();
690         
691         tcRefParserMap.remove(tcRefName);
692         
693         TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()];
694         for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) {
695             Map.Entry en = (Map.Entry) it.next();
696             String JavaDoc name = (String JavaDoc) en.getKey();
697             int index = ((Integer JavaDoc) en.getValue()).intValue();
698             TCRefParser tcRefParser = (TCRefParser) localMap.remove(name);
699             //Put instances to array according to defined order
700
//Order should be defined from 0 to N-1
701
//if (DEBUG) Debug.log(ModeParser.class, "-- -- ADD [" + index + "]: " + tcRefParser.getName());
702
tcRefParserArray[index] = tcRefParser;
703         }
704         for (int i = 0; i < tcRefParserArray.length; i++) {
705             localList.add(tcRefParserArray[i]);
706         }
707         //Append remaining instances if any
708
for (Iterator it = localMap.keySet().iterator(); it.hasNext(); ) {
709             TCRefParser tcRefParser = (TCRefParser) localMap.get(it.next());
710             localList.add(tcRefParser);
711         }
712
713         //Remove tcRef
714
for (int i = 0; i < localList.size(); i++) {
715             TCRefParser tcRefParser = localList.get(i);
716             if (tcRefName.equals(tcRefParser.getName())) {
717                 localList.remove(i);
718                 break;
719             }
720         }
721
722         //Create updated order
723
tcRefOrder.clear();
724         for (int i = 0; i < localList.size(); i++) {
725             TCRefParser tcRefParser = localList.get(i);
726             tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i));
727         }
728         try {
729             writeOrder();
730         } catch (IOException exc) {
731             PersistenceManager.LOG.log(Level.WARNING,
732             "[WinSys.ModeParser.removeTCRef]" // NOI18N
733
+ " Warning: Cannot write order of mode: " + getName(), exc); // NOI18N
734
}
735         
736         deleteLocalTCRef(tcRefName);
737         if (DEBUG) Debug.log(ModeParser.class, "removeTCRef LEAVE" + " tcRef:" + tcRefName);
738     }
739     
740     /** Adds TCRefParser to ModeParser.
741      * @param tcRefName unique name of tcRef
742      */

743     TCRefConfig addTCRef (String JavaDoc tcRefName, List JavaDoc<String JavaDoc> tcRefNameList) {
744         if (DEBUG) Debug.log(ModeParser.class, "addTCRef ENTER" + " mo:" + getName()
745         + " tcRef:" + tcRefName);
746         //Check consistency. TCRefParser instance should not exist.
747
TCRefParser tcRefParser = tcRefParserMap.get(tcRefName);
748         if (tcRefParser != null) {
749             PersistenceManager.LOG.log(Level.WARNING,
750             "[WinSys.ModeParser.addTCRef]" // NOI18N
751
+ " Warning: ModeParser " + getName() + ". TCRefParser " // NOI18N
752
+ tcRefName + " exists but it should not."); // NOI18N
753
tcRefParserMap.remove(tcRefName);
754         }
755         tcRefParser = new TCRefParser(tcRefName);
756         FileObject moduleFolder = moduleParentFolder.getFileObject(modeName);
757         tcRefParser.setModuleParentFolder(moduleFolder);
758         tcRefParser.setInModuleFolder(true);
759         tcRefParserMap.put(tcRefName, tcRefParser);
760         TCRefConfig tcRefConfig = null;
761         try {
762             tcRefConfig = tcRefParser.load();
763         } catch (IOException exc) {
764             PersistenceManager.LOG.log(Level.WARNING,
765             "[WinSys.ModeParser.addTCRef]" // NOI18N
766
+ " Warning: ModeParser " + getName() + ". Cannot load tcRef " + tcRefName, exc); // NOI18N
767
}
768         
769         // Update order
770
List JavaDoc<TCRefParser> localList = new ArrayList<TCRefParser>(10);
771         Map localMap = (Map) ((HashMap) tcRefParserMap).clone();
772         
773         TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()];
774         for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) {
775             Map.Entry en = (Map.Entry) it.next();
776             String JavaDoc name = (String JavaDoc) en.getKey();
777             int index = ((Integer JavaDoc) en.getValue()).intValue();
778             tcRefParser = (TCRefParser) localMap.remove(name);
779             //Put instances to array according to defined order
780
//Order should be defined from 0 to N-1
781
//log("-- -- ADD [" + index + "]: " + tcRefParser.getName());
782
tcRefParserArray[index] = tcRefParser;
783         }
784         for (int i = 0; i < tcRefParserArray.length; i++) {
785             localList.add(tcRefParserArray[i]);
786         }
787         //Append remaining instances if any
788
for (Iterator it = localMap.keySet().iterator(); it.hasNext(); ) {
789             tcRefParser = (TCRefParser) localMap.get(it.next());
790             localList.add(tcRefParser);
791         }
792         
793         /*if (DEBUG) Debug.log(ModeParser.class, "LIST BEFORE SORT");
794         for (int i = 0; i < localList.size(); i++) {
795             tcRefParser = (TCRefParser) localList.get(i);
796             if (DEBUG) Debug.log(ModeParser.class, "p[" + i + "]: " + tcRefParser.getName());
797         }*/

798         
799         localList = carefullySort(localList);
800         
801         /*if (DEBUG) Debug.log(ModeParser.class, "LIST AFTER SORT");
802         for (int i = 0; i < localList.size(); i++) {
803             tcRefParser = (TCRefParser) localList.get(i);
804             if (DEBUG) Debug.log(ModeParser.class, "p[" + i + "]: " + tcRefParser.getName());
805         }*/

806         
807         //Create updated order
808
tcRefOrder.clear();
809         for (int i = 0; i < localList.size(); i++) {
810             tcRefParser = (TCRefParser) localList.get(i);
811             tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i));
812         }
813         try {
814             writeOrder();
815         } catch (IOException exc) {
816             PersistenceManager.LOG.log(Level.WARNING,
817             "[WinSys.ModeParser.addTCRef]" // NOI18N
818
+ " Warning: Cannot write order of mode: " + getName(), exc); // NOI18N
819
}
820         
821         //Fill output order
822
tcRefNameList.clear();
823         for (int i = 0; i < localList.size(); i++) {
824             tcRefParser = (TCRefParser) localList.get(i);
825             tcRefNameList.add(tcRefParser.getName());
826         }
827         
828         if (DEBUG) Debug.log(ModeParser.class, "addTCRef LEAVE" + " mo:" + getName()
829         + " tcRef:" + tcRefName);
830         
831         return tcRefConfig;
832     }
833     
834     /** Adds TCRefParser to ModeParser. Called from import to pass module info
835      * to new parser.
836      * @param tcRefName unique name of tcRef
837      */

838     void addTCRefImport (String JavaDoc tcRefName, InternalConfig internalCfg) {
839         if (DEBUG) Debug.log(ModeParser.class, "addTCRefImport ENTER" + " mo:" + getName()
840         + " tcRef:" + tcRefName);
841         //Check consistency. TCRefParser instance should not exist.
842
TCRefParser tcRefParser = tcRefParserMap.get(tcRefName);
843         if (tcRefParser != null) {
844             PersistenceManager.LOG.log(Level.WARNING,
845             "[WinSys.ModeParser.addTCRef]" // NOI18N
846
+ " Warning: ModeParser " + getName() + ". TCRefParser " // NOI18N
847
+ tcRefName + " exists but it should not."); // NOI18N
848
tcRefParserMap.remove(tcRefName);
849         }
850         tcRefParser = new TCRefParser(tcRefName);
851         //FileObject moduleFolder = moduleParentFolder.getFileObject(modeName);
852
//tcRefParser.setModuleParentFolder(moduleFolder);
853
//tcRefParser.setInModuleFolder(false);
854
FileObject localFolder = localParentFolder.getFileObject(modeName);
855         tcRefParser.setLocalParentFolder(localFolder);
856         tcRefParser.setInternalConfig(internalCfg);
857         
858         //if (DEBUG) Debug.log(ModeParser.class, "CodeNameBase:" + internalCfg.moduleCodeNameBase);
859
//if (DEBUG) Debug.log(ModeParser.class, "CodeNameRelease:" + internalCfg.moduleCodeNameRelease);
860
//if (DEBUG) Debug.log(ModeParser.class, "SpecificationVersion:" + internalCfg.moduleSpecificationVersion);
861
//if (DEBUG) Debug.log(ModeParser.class, "specVersion:" + internalCfg.specVersion);
862

863         tcRefParserMap.put(tcRefName, tcRefParser);
864         
865         if (DEBUG) Debug.log(ModeParser.class, "addTCRefImport LEAVE" + " mo:" + getName()
866         + " tcRef:" + tcRefName);
867     }
868     
869     /** Finds TCRefParser with given ID. Returns null if such TCRefParser
870      * is not found.
871      * @param tcRefName unique name of tcRef
872      */

873     TCRefParser findTCRefParser (String JavaDoc tcRefName) {
874         //if (DEBUG) Debug.log(ModeParser.class, "findTCRefParser ENTER" + " tcRef:" + tcRefName);
875
return tcRefParserMap.get(tcRefName);
876     }
877     
878     /** Getter for internal configuration data.
879      * @return instance of internal configuration data
880      */

881     InternalConfig getInternalConfig () {
882         if (internalConfig == null) {
883             internalConfig = new InternalConfig();
884         }
885         return internalConfig;
886     }
887     
888     void setModuleParentFolder (FileObject moduleParentFolder) {
889         this.moduleParentFolder = moduleParentFolder;
890     }
891     
892     void setLocalParentFolder (FileObject localParentFolder) {
893         this.localParentFolder = localParentFolder;
894     }
895     
896     String JavaDoc getName () {
897         return modeName;
898     }
899     
900     boolean isInModuleFolder () {
901         return inModuleFolder;
902     }
903     
904     void setInModuleFolder (boolean inModuleFolder) {
905         this.inModuleFolder = inModuleFolder;
906     }
907     
908     boolean isInLocalFolder () {
909         return inLocalFolder;
910     }
911     
912     void setInLocalFolder (boolean inLocalFolder) {
913         this.inLocalFolder = inLocalFolder;
914     }
915     
916     private final class PropertyHandler extends DefaultHandler JavaDoc {
917         
918         /** Mode configuration data */
919         private ModeConfig modeConfig = null;
920         
921         /** Internal configuration data */
922         private InternalConfig internalConfig = null;
923         
924         /** List to store parsed path items */
925         private List JavaDoc<SplitConstraint> itemList = new ArrayList<SplitConstraint>(10);
926         
927         /** Lock to prevent mixing readData and writeData */
928         private final Object JavaDoc RW_LOCK = new Object JavaDoc();
929         
930         public PropertyHandler () {
931         }
932         
933         private FileObject getConfigFOInput () {
934             FileObject modeConfigFO;
935             if (isInLocalFolder()) {
936                 //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.getConfigFOInput" + " looking for LOCAL");
937
modeConfigFO = localParentFolder.getFileObject
938                 (ModeParser.this.getName(), PersistenceManager.MODE_EXT);
939             } else if (isInModuleFolder()) {
940                 //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.getConfigFOInput" + " looking for MODULE");
941
modeConfigFO = moduleParentFolder.getFileObject
942                 (ModeParser.this.getName(), PersistenceManager.MODE_EXT);
943             } else {
944                 //XXX should not happen
945
modeConfigFO = null;
946             }
947             //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.getConfigFOInput" + " modeConfigFO:" + modeConfigFO);
948
return modeConfigFO;
949         }
950
951         private FileObject getConfigFOOutput () throws IOException {
952             FileObject modeConfigFO;
953             modeConfigFO = localParentFolder.getFileObject
954             (ModeParser.this.getName(), PersistenceManager.MODE_EXT);
955             if (modeConfigFO != null) {
956                 //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.getConfigFOOutput" + " modeConfigFO LOCAL:" + modeConfigFO);
957
return modeConfigFO;
958             } else {
959                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
960                 buffer.append(ModeParser.this.getName());
961                 buffer.append('.');
962                 buffer.append(PersistenceManager.MODE_EXT);
963                 //XXX should be improved localParentFolder can be null
964
modeConfigFO = FileUtil.createData(localParentFolder, buffer.toString());
965                 //if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.getConfigFOOutput" + " LOCAL not found CREATE");
966

967                 return modeConfigFO;
968             }
969         }
970         /**
971          Reads mode configuration data from XML file.
972          Data are returned in output params.
973          */

974         void readData (ModeConfig modeCfg, InternalConfig internalCfg)
975         throws IOException {
976             modeConfig = modeCfg;
977             internalConfig = internalCfg;
978             itemList.clear();
979             
980             FileObject cfgFOInput = getConfigFOInput();
981             if (cfgFOInput == null) {
982                 throw new FileNotFoundException("[WinSys] Missing Mode configuration file:" // NOI18N
983
+ ModeParser.this.getName());
984             }
985             InputStream is = null;
986             try {
987                 synchronized (RW_LOCK) {
988                     //DUMP BEGIN
989
/*if ("explorer".equals(ModeParser.this.getName())) {
990                         InputStream is = cfgFOInput.getInputStream();
991                         byte [] arr = new byte [is.available()];
992                         is.read(arr);
993                         if (DEBUG) Debug.log(ModeParser.class, "DUMP Mode:");
994                         String s = new String(arr);
995                         if (DEBUG) Debug.log(ModeParser.class, s);
996                     }*/

997                     //DUMP END
998
is = cfgFOInput.getInputStream();
999                     PersistenceManager.getDefault().getXMLParser(this).parse(new InputSource(is));
1000                }
1001            } catch (SAXException exc) {
1002                // Turn into annotated IOException
1003
String JavaDoc msg = NbBundle.getMessage(ModeParser.class,
1004                                                 "EXC_ModeParse", cfgFOInput);
1005
1006                throw (IOException) new IOException(msg).initCause(exc);
1007            } finally {
1008                try {
1009                    if (is != null) {
1010                        is.close();
1011                    }
1012                } catch (IOException exc) {
1013                    Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc);
1014                }
1015            }
1016            
1017            modeConfig.constraints =
1018                itemList.toArray(new SplitConstraint[itemList.size()]);
1019            
1020            modeCfg = modeConfig;
1021            internalCfg = internalConfig;
1022            
1023            modeConfig = null;
1024            internalConfig = null;
1025        }
1026        
1027        public void startElement (String JavaDoc nameSpace, String JavaDoc name, String JavaDoc qname, Attributes attrs) throws SAXException {
1028            if ("mode".equals(qname)) { // NOI18N
1029
handleMode(attrs);
1030            } else if (internalConfig.specVersion != null &&
1031            // check for null because of #45599 - no idea how it can happen other than having a broken file which doesn't
1032
// declade 'mode' element. (see handleMode() - after this is called NPE is impossible
1033
internalConfig.specVersion.compareTo(new SpecificationVersion("2.0")) >= 0) { // NOI18N
1034
//Parse version 2.0 and beyond
1035
if ("module".equals(qname)) { // NOI18N
1036
handleModule(attrs);
1037                } else if ("name".equals(qname)) { // NOI18N
1038
handleName(attrs);
1039                } else if ("kind".equals(qname)) { // NOI18N
1040
handleKind(attrs);
1041                } else if ("slidingSide".equals(qname)) { // NOI18N
1042
handleSlidingSide(attrs);
1043                } else if ("slide-in-size".equals(qname)) { // NOI18N
1044
handleSlideInSize(attrs);
1045                } else if ("state".equals(qname)) { // NOI18N
1046
handleState(attrs);
1047                } else if ("constraints".equals(qname)) { // NOI18N
1048
handleConstraints(attrs);
1049                } else if ("path".equals(qname)) { // NOI18N
1050
handlePath(attrs);
1051                } else if ("bounds".equals(qname)) { // NOI18N
1052
handleBounds(attrs);
1053                } else if ("relative-bounds".equals(qname)) { // NOI18N
1054
handleRelativeBounds(attrs);
1055                } else if ("frame".equals(qname)) { // NOI18N
1056
handleFrame(attrs);
1057                } else if ("active-tc".equals(qname)) { // NOI18N
1058
handleActiveTC(attrs);
1059                } else if ("empty-behavior".equals(qname)) { // NOI18N
1060
handleEmptyBehavior(attrs);
1061                }
1062            } else {
1063                if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.startElement PARSING OLD");
1064                //Parse version < 2.0
1065
}
1066        }
1067        
1068        public void error(SAXParseException ex) throws SAXException {
1069            throw ex;
1070        }
1071        
1072        /** Reads element "mode" */
1073        private void handleMode (Attributes attrs) {
1074            String JavaDoc version = attrs.getValue("version"); // NOI18N
1075
if (version != null) {
1076                internalConfig.specVersion = new SpecificationVersion(version);
1077            } else {
1078                PersistenceManager.LOG.log(Level.WARNING,
1079                "[WinSys.ModeParser.handleMode]" // NOI18N
1080
+ " Warning: Missing attribute \"version\" of element \"mode\"."); // NOI18N
1081
internalConfig.specVersion = new SpecificationVersion("2.0"); // NOI18N
1082
}
1083        }
1084        
1085        /** Reads element "module" and updates mode config content */
1086        private void handleModule (Attributes attrs) {
1087            String JavaDoc moduleCodeName = attrs.getValue("name"); // NOI18N
1088
//Parse code name
1089
internalConfig.moduleCodeNameBase = null;
1090            internalConfig.moduleCodeNameRelease = null;
1091            internalConfig.moduleSpecificationVersion = null;
1092            if (moduleCodeName != null) {
1093                int i = moduleCodeName.indexOf('/');
1094                if (i != -1) {
1095                    internalConfig.moduleCodeNameBase = moduleCodeName.substring(0, i);
1096                    internalConfig.moduleCodeNameRelease = moduleCodeName.substring(i + 1);
1097                    checkReleaseCode(internalConfig);
1098                } else {
1099                    internalConfig.moduleCodeNameBase = moduleCodeName;
1100                }
1101                internalConfig.moduleSpecificationVersion = attrs.getValue("spec"); // NOI18N
1102
}
1103        }
1104
1105        /** Checks validity of <code>moduleCodeNameRelease</code> field.
1106         * Helper method. */

1107        private void checkReleaseCode (InternalConfig internalConfig) {
1108            // #24844. Repair the wrongly saved "null" string
1109
// as release number.
1110
if("null".equals(internalConfig.moduleCodeNameRelease)) { // NOI18N
1111
Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null,
1112                                  new IllegalStateException JavaDoc("Module release code was saved as null string" +
1113                                                            " for module " +
1114                                                            internalConfig.moduleCodeNameBase +
1115                                                            "! Repairing."));
1116                internalConfig.moduleCodeNameRelease = null;
1117            }
1118        }
1119        
1120        /** Reads element "name" */
1121        private void handleName (Attributes attrs) throws SAXException {
1122            String JavaDoc name = attrs.getValue("unique"); // NOI18N
1123
if (name != null) {
1124                modeConfig.name = name;
1125                if (!name.equals(ModeParser.this.getName())) {
1126                    PersistenceManager.LOG.log(Level.WARNING,
1127                    "[WinSys.ModeParser.handleName]" // NOI18N
1128
+ " Error: Value of attribute \"unique\" of element \"name\"" // NOI18N
1129
+ " and configuration file name must be the same."); // NOI18N
1130
throw new SAXException("Invalid attribute value"); // NOI18N
1131
}
1132            } else {
1133                PersistenceManager.LOG.log(Level.WARNING,
1134                "[WinSys.ModeParser.handleName]" // NOI18N
1135
+ " Error: Missing required attribute \"unique\" of element \"name\"."); // NOI18N
1136
throw new SAXException("Missing required attribute"); // NOI18N
1137
}
1138        }
1139
1140        /** Reads element "kind" */
1141        private void handleKind (Attributes attrs) {
1142            String JavaDoc type = attrs.getValue("type"); // NOI18N
1143
if (type != null) {
1144                if ("editor".equals(type)) {
1145                    modeConfig.kind = Constants.MODE_KIND_EDITOR;
1146                } else if ("view".equals(type)) {
1147                    modeConfig.kind = Constants.MODE_KIND_VIEW;
1148                } else if ("sliding".equals(type)) {
1149                    modeConfig.kind = Constants.MODE_KIND_SLIDING;
1150                } else {
1151                    PersistenceManager.LOG.log(Level.WARNING,
1152                    "[WinSys.ModeParser.handleKind]" // NOI18N
1153
+ " Warning: Invalid value of attribute \"type\"."); // NOI18N
1154
modeConfig.kind = Constants.MODE_KIND_VIEW;
1155                }
1156            } else {
1157                PersistenceManager.LOG.log(Level.WARNING,
1158                "[WinSys.ModeParser.handleKind]" // NOI18N
1159
+ " Error: Missing required attribute \"type\" of element \"kind\"."); // NOI18N
1160
modeConfig.kind = Constants.MODE_KIND_VIEW;
1161            }
1162        }
1163        
1164        /** Reads element "kind" */
1165        private void handleSlidingSide(Attributes attrs) {
1166            String JavaDoc side = attrs.getValue("side");
1167            if (side != null) {
1168                if (Constants.LEFT.equals(side) ||
1169                    Constants.RIGHT.equals(side) ||
1170                    Constants.BOTTOM.equals(side))
1171                {
1172                    modeConfig.side = side;
1173                } else {
1174                    PersistenceManager.LOG.log(Level.WARNING,
1175                    "[WinSys.ModeParser.handleSlidingSide]" // NOI18N
1176
+ " Warning: Wrong value \"" + side + "\" of attribute \"side\" for sliding mode"); // NOI18N
1177
modeConfig.side = Constants.LEFT;
1178                }
1179            } else {
1180                PersistenceManager.LOG.log(Level.WARNING,
1181                "[WinSys.ModeParser.handleSlidingSide]" // NOI18N
1182
+ " Warning: Missing value of attribute \"side\" for sliding mode."); // NOI18N
1183
modeConfig.side = Constants.LEFT;
1184            }
1185        }
1186        
1187        /** Reads element "slideInSize" */
1188        private void handleSlideInSize(Attributes attrs) {
1189            String JavaDoc tcId = attrs.getValue("tc-id");
1190            String JavaDoc size = attrs.getValue("size");
1191            if (tcId != null && size != null) {
1192                try {
1193                    Integer JavaDoc intSize = Integer.valueOf( size );
1194                    if( null == modeConfig.slideInSizes )
1195                        modeConfig.slideInSizes = new HashMap<String JavaDoc, Integer JavaDoc>(5);
1196                    modeConfig.slideInSizes.put( tcId, intSize );
1197                    return;
1198                } catch( NumberFormatException JavaDoc nfE ) {
1199                    //fall through
1200
}
1201            }
1202            PersistenceManager.LOG.log(Level.WARNING,
1203            "[WinSys.ModeParser.handleSlideInSize]" // NOI18N
1204
+ " Warning: Invalid attributes for preferred slide-in size."); // NOI18N
1205
}
1206        
1207        private void handleState(Attributes attrs) throws SAXException {
1208            String JavaDoc type = attrs.getValue("type"); // NOI18N
1209
if (type != null) {
1210                if ("joined".equals(type)) {
1211                    modeConfig.state = Constants.MODE_STATE_JOINED;
1212                } else if ("separated".equals(type)) {
1213                    modeConfig.state = Constants.MODE_STATE_SEPARATED;
1214                } else {
1215                    PersistenceManager.LOG.log(Level.WARNING,
1216                    "[WinSys.ModeParser.handleState]" // NOI18N
1217
+ " Warning: Invalid value of attribute \"type\"" // NOI18N
1218
+ " of element \"state\"."); // NOI18N
1219
modeConfig.state = Constants.MODE_STATE_JOINED;
1220                }
1221            } else {
1222                PersistenceManager.LOG.log(Level.WARNING,
1223                "[WinSys.ModeParser.handleState]" // NOI18N
1224
+ " Error: Missing required attribute \"type\""
1225                + " of element \"state\"."); // NOI18N
1226
modeConfig.state = Constants.MODE_STATE_JOINED;
1227            }
1228        }
1229        
1230        /** Reads element "constraints" */
1231        private void handleConstraints (Attributes attrs) {
1232        }
1233        
1234        /** Reads element "path" */
1235        private void handlePath (Attributes attrs) {
1236            String JavaDoc s = attrs.getValue("orientation"); // NOI18N
1237
int orientation;
1238            if ("horizontal".equals(s)) { // NOI18N
1239
orientation = Constants.HORIZONTAL;
1240            } else if ("vertical".equals(s)) { // NOI18N
1241
orientation = Constants.VERTICAL;
1242            } else {
1243                PersistenceManager.LOG.log(Level.WARNING,
1244                "[WinSys.ModeParser.handlePath]" // NOI18N
1245
+ " Warning: Invalid or missing value of attribute \"orientation\"."); // NOI18N
1246
orientation = Constants.VERTICAL;
1247            }
1248            
1249            int number;
1250            try {
1251                s = attrs.getValue("number"); // NOI18N
1252
if (s != null) {
1253                    number = Integer.parseInt(s);
1254                } else {
1255                    PersistenceManager.LOG.log(Level.WARNING,
1256                    "[WinSys.ModeParser.handlePath]" // NOI18N
1257
+ " Warning: Missing value of attribute \"number\"."); // NOI18N
1258
number = 0;
1259                }
1260            } catch (NumberFormatException JavaDoc exc) {
1261                PersistenceManager.LOG.log(Level.WARNING,
1262                "[WinSys.ModeParser.handlePath]" // NOI18N
1263
+ " Warning: Cannot read element \"path\", attribute \"number\"", exc); // NOI18N
1264
number = 0;
1265            }
1266            
1267            double weight;
1268            try {
1269                s = attrs.getValue("weight"); // NOI18N
1270
if (s != null) {
1271                    weight = Double.parseDouble(s);
1272                } else {
1273                    //Not required attribute, provide default value
1274
weight = 0.5;
1275                }
1276            } catch (NumberFormatException JavaDoc exc) {
1277                PersistenceManager.LOG.log(Level.WARNING,
1278                "[WinSys.ModeParser.handlePath]" // NOI18N
1279
+ " Warning: Cannot read element \"path\", attribute \"weight\".", exc); // NOI18N
1280
weight = 0.5;
1281            }
1282            SplitConstraint item = new SplitConstraint(orientation, number, weight);
1283            itemList.add(item);
1284        }
1285        
1286        /** Reads element "bounds" */
1287        private void handleBounds (Attributes attrs) {
1288            try {
1289                String JavaDoc s;
1290                int x, y, width, height;
1291                
1292                modeConfig.bounds = null;
1293                s = attrs.getValue("x"); // NOI18N
1294
if (s != null) {
1295                    x = Integer.parseInt(s);
1296                } else {
1297                    PersistenceManager.LOG.log(Level.WARNING,
1298                        "[WinSys.ModeParser.handleBounds]" // NOI18N
1299
+ " Warning: Missing attribute \"x\" of element \"bounds\"."); // NOI18N
1300
return;
1301                }
1302                s = attrs.getValue("y"); // NOI18N
1303
if (s != null) {
1304                    y = Integer.parseInt(s);
1305                } else {
1306                    PersistenceManager.LOG.log(Level.WARNING,
1307                    "[WinSys.ModeParser.handleBounds]" // NOI18N
1308
+ " Warning: Missing attribute \"y\" of element \"bounds\"."); // NOI18N
1309
return;
1310                }
1311                s = attrs.getValue("width"); // NOI18N
1312
if (s != null) {
1313                    width = Integer.parseInt(s);
1314                } else {
1315                    PersistenceManager.LOG.log(Level.WARNING,
1316                    "[WinSys.ModeParser.handleBounds]" // NOI18N
1317
+ " Warning: Missing attribute \"width\" of element \"bounds\"."); // NOI18N
1318
return;
1319                }
1320                s = attrs.getValue("height"); // NOI18N
1321
if (s != null) {
1322                    height = Integer.parseInt(s);
1323                } else {
1324                    PersistenceManager.LOG.log(Level.WARNING,
1325                    "[WinSys.ModeParser.handleBounds]" // NOI18N
1326
+ " Warning: Missing attribute \"height\" of element \"bounds\"."); // NOI18N
1327
return;
1328                }
1329                modeConfig.bounds = new Rectangle(x, y, width, height);
1330            } catch (NumberFormatException JavaDoc exc) {
1331                PersistenceManager.LOG.log(Level.WARNING,
1332                "[WinSys.ModeParser.handleBounds]" // NOI18N
1333
+ " Warning: Cannot read element \"bounds\".", exc); // NOI18N
1334
}
1335        }
1336        
1337        /** Reads element "relative-bounds" */
1338        private void handleRelativeBounds (Attributes attrs) {
1339            try {
1340                String JavaDoc s;
1341                int x, y, width, height;
1342                
1343                modeConfig.relativeBounds = null;
1344                s = attrs.getValue("x"); // NOI18N
1345
if (s != null) {
1346                    x = Integer.parseInt(s);
1347                } else {
1348                    PersistenceManager.LOG.log(Level.WARNING,
1349                    "[WinSys.ModeParser.handleRelativeBounds]" // NOI18N
1350
+ " Warning: Missing attribute \"x\" of element \"relative-bounds\"."); // NOI18N
1351
return;
1352                }
1353                s = attrs.getValue("y"); // NOI18N
1354
if (s != null) {
1355                    y = Integer.parseInt(s);
1356                } else {
1357                    PersistenceManager.LOG.log(Level.WARNING,
1358                    "[WinSys.ModeParser.handleRelativeBounds]" // NOI18N
1359
+ " Warning: Missing attribute \"y\" of element \"relative-bounds\"."); // NOI18N
1360
return;
1361                }
1362                s = attrs.getValue("width"); // NOI18N
1363
if (s != null) {
1364                    width = Integer.parseInt(s);
1365                } else {
1366                    PersistenceManager.LOG.log(Level.WARNING,
1367                    "[WinSys.ModeParser.handleRelativeBounds]" // NOI18N
1368
+ " Warning: Missing attribute \"width\" of element \"relative-bounds\"."); // NOI18N
1369
return;
1370                }
1371                s = attrs.getValue("height"); // NOI18N
1372
if (s != null) {
1373                    height = Integer.parseInt(s);
1374                } else {
1375                    PersistenceManager.LOG.log(Level.WARNING,
1376                    "[WinSys.ModeParser.handleRelativeBounds]" // NOI18N
1377
+ " Warning: Missing attribute \"height\" of element \"relative-bounds\"."); // NOI18N
1378
return;
1379                }
1380                modeConfig.relativeBounds = new Rectangle(x, y, width, height);
1381            } catch (NumberFormatException JavaDoc exc) {
1382                PersistenceManager.LOG.log(Level.WARNING,
1383                "[WinSys.ModeParser.handleRelativeBounds]" // NOI18N
1384
+ " Warning: Cannot read element \"relative-bounds\".", exc); // NOI18N
1385
}
1386        }
1387        
1388        /** Reads element "frame" */
1389        private void handleFrame (Attributes attrs) {
1390            String JavaDoc frameState = attrs.getValue("state"); // NOI18N
1391
if (frameState != null) {
1392                try {
1393                    modeConfig.frameState = Integer.parseInt(frameState);
1394                } catch (NumberFormatException JavaDoc exc) {
1395                    PersistenceManager.LOG.log(Level.WARNING,
1396                    "[WinSys.ModeParser.handleFrame]" // NOI18N
1397
+ " Warning: Cannot read attribute \"state\"" // NOI18N
1398
+ " of element \"frame\".", exc); // NOI18N
1399
modeConfig.frameState = Frame.NORMAL;
1400                }
1401            } else {
1402                PersistenceManager.LOG.log(Level.WARNING,
1403                "[WinSys.ModeParser.handleFrame]" // NOI18N
1404
+ " Warning: Missing value of attribute \"state\"" // NOI18N
1405
+ " of element \"frame\"."); // NOI18N
1406
modeConfig.frameState = Frame.NORMAL;
1407            }
1408        }
1409        
1410        /** Reads element "active-tc" */
1411        private void handleActiveTC (Attributes attrs) {
1412            String JavaDoc id = attrs.getValue("id"); // NOI18N
1413
if (id != null) {
1414                modeConfig.selectedTopComponentID = id;
1415            } else {
1416                modeConfig.selectedTopComponentID = ""; // NOI18N
1417
}
1418            String JavaDoc prevId = attrs.getValue("prev-id"); // NOI18N
1419
if (prevId != null) {
1420                modeConfig.previousSelectedTopComponentID = prevId;
1421            } else {
1422                modeConfig.previousSelectedTopComponentID = ""; // NOI18N
1423
}
1424        }
1425        
1426        /** Reads element "empty-behavior" */
1427        private void handleEmptyBehavior (Attributes attrs) {
1428            String JavaDoc value = attrs.getValue("permanent"); // NOI18N
1429
if ("true".equals(value)) { // NOI18N
1430
modeConfig.permanent = true;
1431            } else if ("false".equals(value)) { // NOI18N
1432
modeConfig.permanent = false;
1433            } else {
1434                PersistenceManager.LOG.log(Level.WARNING,
1435                "[WinSys.ModeParser.handleEmptyBehavior]" // NOI18N
1436
+ " Warning: Invalid value of attribute \"permanent\"."); // NOI18N
1437
modeConfig.permanent = false;
1438            }
1439        }
1440        
1441        /** Writes data from asociated mode to the xml representation */
1442        void writeData (ModeConfig mc, InternalConfig ic) throws IOException {
1443            final StringBuffer JavaDoc buff = fillBuffer(mc, ic);
1444            synchronized (RW_LOCK) {
1445                FileObject cfgFOOutput = getConfigFOOutput();
1446                FileLock lock = null;
1447                OutputStream os = null;
1448                OutputStreamWriter osw = null;
1449                try {
1450                    lock = cfgFOOutput.lock();
1451                    os = cfgFOOutput.getOutputStream(lock);
1452                    osw = new OutputStreamWriter(os, "UTF-8"); // NOI18N
1453
osw.write(buff.toString());
1454                    /*log("-- DUMP Mode:");
1455                    log(buff.toString());*/

1456                } finally {
1457                    try {
1458                        if (osw != null) {
1459                            osw.close();
1460                        }
1461                    } catch (IOException exc) {
1462                        Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc);
1463                    }
1464                    if (lock != null) {
1465                        lock.releaseLock();
1466                    }
1467                }
1468            }
1469        }
1470        
1471        /** Returns xml content in StringBuffer
1472         */

1473        private StringBuffer JavaDoc fillBuffer (ModeConfig mc, InternalConfig ic) throws IOException {
1474            StringBuffer JavaDoc buff = new StringBuffer JavaDoc(800);
1475            // header
1476
buff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"). // NOI18N
1477
/*buff.append("<!DOCTYPE mode PUBLIC\n"); // NOI18N
1478            buff.append(" \"-//NetBeans//DTD Mode Properties 2.3//EN\"\n"); // NOI18N
1479            buff.append(" \"http://www.netbeans.org/dtds/mode-properties2_3.dtd\">\n\n"); // NOI18N*/

1480                append("<mode version=\"2.3\">\n"); // NOI18N
1481

1482            appendModule(ic, buff);
1483            appendName(mc, buff);
1484            appendKind(mc, buff);
1485            if (mc.kind == Constants.MODE_KIND_SLIDING) {
1486                appendSlidingSide(mc, buff);
1487                if( null != mc.slideInSizes )
1488                    appendSlideInSize(mc, buff);
1489            }
1490            appendState(mc, buff);
1491            appendConstraints(mc, buff);
1492            if (mc.bounds != null) {
1493                appendBounds(mc, buff);
1494            } else if (mc.relativeBounds != null) {
1495                appendRelativeBounds(mc, buff);
1496            }
1497            appendFrame(mc, buff);
1498            appendActiveTC(mc, buff);
1499            appendEmptyBehavior(mc, buff);
1500            
1501            buff.append("</mode>\n"); // NOI18N
1502
return buff;
1503        }
1504        
1505        private void appendModule (InternalConfig ic, StringBuffer JavaDoc buff) {
1506            if (ic == null) {
1507                return;
1508            }
1509            if (ic.moduleCodeNameBase != null) {
1510                buff.append(" <module name=\""); // NOI18N
1511
buff.append(ic.moduleCodeNameBase);
1512                if (ic.moduleCodeNameRelease != null) {
1513                    buff.append("/").append(ic.moduleCodeNameRelease); // NOI18N
1514
}
1515                if (ic.moduleSpecificationVersion != null) {
1516                    buff.append("\" spec=\""); // NOI18N
1517
buff.append(ic.moduleSpecificationVersion);
1518                }
1519                buff.append("\" />\n"); // NOI18N
1520
}
1521        }
1522
1523        private void appendName (ModeConfig mc, StringBuffer JavaDoc buff) {
1524            buff.append(" <name unique=\""); // NOI18N
1525
buff.append(mc.name);
1526            buff.append("\" />\n"); // NOI18N
1527
}
1528
1529        private void appendKind (ModeConfig mc, StringBuffer JavaDoc buff) {
1530            buff.append(" <kind type=\""); // NOI18N
1531
if (mc.kind == Constants.MODE_KIND_EDITOR) {
1532                buff.append("editor"); // NOI18N
1533
} else if (mc.kind == Constants.MODE_KIND_VIEW) {
1534                buff.append("view"); // NOI18N
1535
} else if (mc.kind == Constants.MODE_KIND_SLIDING) {
1536                buff.append("sliding"); // NOI18N
1537
}
1538            buff.append("\" />\n"); // NOI18N
1539
}
1540        
1541        private void appendSlidingSide(ModeConfig mc, StringBuffer JavaDoc buff) {
1542            buff.append(" <slidingSide side=\"");
1543            buff.append(mc.side);
1544            buff.append("\" ");
1545            buff.append("/>\n"); // NOI18N
1546
}
1547        
1548        private void appendSlideInSize(ModeConfig mc, StringBuffer JavaDoc buff) {
1549            if( null != mc.slideInSizes ) {
1550                for( Iterator<String JavaDoc> i=mc.slideInSizes.keySet().iterator(); i.hasNext(); ) {
1551                    String JavaDoc tcId = i.next();
1552                    Integer JavaDoc size = mc.slideInSizes.get(tcId);
1553                    
1554                    buff.append(" <slide-in-size tc-id=\"");
1555                    buff.append(tcId);
1556                    buff.append("\" size=\"");
1557                    buff.append(size.intValue());
1558                    buff.append("\" />\n"); // NOI18N
1559
}
1560            }
1561        }
1562
1563        private void appendState (ModeConfig mc, StringBuffer JavaDoc buff) {
1564            buff.append(" <state type=\""); // NOI18N
1565
if (mc.state == Constants.MODE_STATE_JOINED) {
1566                buff.append("joined"); // NOI18N
1567
} else if (mc.state == Constants.MODE_STATE_SEPARATED) {
1568                buff.append("separated"); // NOI18N
1569
}
1570            buff.append("\" />\n"); // NOI18N
1571
}
1572        
1573        private void appendConstraints (ModeConfig mc, StringBuffer JavaDoc buff) {
1574            if (mc.constraints.length == 0) {
1575                return;
1576            }
1577            buff.append(" <constraints>\n"); // NOI18N
1578
for (int i = 0; i < mc.constraints.length; i++) {
1579                SplitConstraint item = mc.constraints[i];
1580                buff.append(" <path orientation=\""); // NOI18N
1581
if (item.orientation == Constants.HORIZONTAL) {
1582                    buff.append("horizontal"); // NOI18N
1583
} else {
1584                    buff.append("vertical"); // NOI18N
1585
}
1586                buff.append("\" number=\"").append(item.index).append("\" weight=\"").append(item.splitWeight).append("\"/>\n"); // NOI18N
1587
}
1588            buff.append(" </constraints>\n"); // NOI18N
1589
}
1590        
1591        private void appendBounds (ModeConfig mc, StringBuffer JavaDoc buff) {
1592            if (mc.bounds == null) {
1593                return;
1594            }
1595            buff.append(" <bounds x=\"").append(mc.bounds.x).
1596                append("\" y=\"").append(mc.bounds.y).
1597                append("\" width=\"").append(mc.bounds.width).
1598                append("\" height=\"").append(mc.bounds.height).append("\" />\n"); // NOI18N
1599
}
1600        
1601        private void appendRelativeBounds (ModeConfig mc, StringBuffer JavaDoc buff) {
1602            if (mc.relativeBounds == null) {
1603                return;
1604            }
1605            buff.append(" <relative-bounds x=\"").append(mc.relativeBounds.x).
1606                append("\" y=\"").append(mc.relativeBounds.y).
1607                append("\" width=\"").append(mc.relativeBounds.width).
1608                append("\" height=\"").append(mc.relativeBounds.height).append("\" />\n"); // NOI18N
1609
}
1610        
1611        private void appendFrame (ModeConfig mc, StringBuffer JavaDoc buff) {
1612            buff.append(" <frame state=\"").append(mc.frameState).append("\"/>\n"); // NOI18N
1613
}
1614        
1615        private void appendActiveTC (ModeConfig mc, StringBuffer JavaDoc buff) {
1616            if ((mc.selectedTopComponentID != null && !"".equals(mc.selectedTopComponentID))
1617                || (mc.previousSelectedTopComponentID != null && !"".equals(mc.previousSelectedTopComponentID)) ) {
1618                buff.append(" <active-tc ");
1619                
1620                if (mc.selectedTopComponentID != null && !"".equals(mc.selectedTopComponentID)) {
1621                    String JavaDoc tcName = PersistenceManager.escapeTcId4XmlContent(mc.selectedTopComponentID);
1622                    buff.append( " id=\"").append(tcName).append("\" "); // NOI18N
1623
}
1624                
1625                if (mc.previousSelectedTopComponentID != null && !"".equals(mc.previousSelectedTopComponentID)) {
1626                    String JavaDoc tcName = PersistenceManager.escapeTcId4XmlContent(mc.previousSelectedTopComponentID);
1627                    buff.append( " prev-id=\"").append(tcName).append("\" "); // NOI18N
1628
}
1629                buff.append("/>\n"); // NOI18N
1630
}
1631        }
1632        
1633        private void appendEmptyBehavior (ModeConfig mc, StringBuffer JavaDoc buff) {
1634            buff.append(" <empty-behavior permanent=\"").append(mc.permanent).append("\"/>\n"); // NOI18N
1635
}
1636    }
1637    
1638}
1639
Popular Tags