]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Ensure the validity of Ffs Sections when adding a new Sections to Ffs.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
1 /** @file
2 Java class FpdFileContents is used to parse fpd xml file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.platform.ui;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.math.BigInteger;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.ListIterator;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Vector;
27
28 import javax.xml.namespace.QName;
29
30 import org.apache.xmlbeans.XmlCursor;
31 import org.apache.xmlbeans.XmlObject;
32 import org.apache.xmlbeans.XmlOptions;
33 import org.tianocore.AntTaskDocument;
34 import org.tianocore.BuildOptionsDocument;
35 import org.tianocore.DynamicPcdBuildDefinitionsDocument;
36 import org.tianocore.EfiSectionType;
37 import org.tianocore.FlashDefinitionFileDocument;
38 import org.tianocore.FlashDocument;
39 import org.tianocore.FrameworkModulesDocument;
40 import org.tianocore.IntermediateOutputType;
41 import org.tianocore.LibrariesDocument;
42 import org.tianocore.ModuleSADocument;
43 import org.tianocore.ModuleSaBuildOptionsDocument;
44 import org.tianocore.ModuleSurfaceAreaDocument;
45 import org.tianocore.OptionDocument;
46 import org.tianocore.OptionsDocument;
47 import org.tianocore.PcdBuildDefinitionDocument;
48 import org.tianocore.PcdCodedDocument;
49 import org.tianocore.PcdDataTypes;
50 import org.tianocore.PcdDeclarationsDocument;
51 import org.tianocore.PcdItemTypes;
52 import org.tianocore.PlatformDefinitionsDocument;
53 import org.tianocore.PlatformSurfaceAreaDocument;
54 import org.tianocore.FvImageTypes;
55 import org.tianocore.FvImagesDocument;
56 import org.tianocore.LicenseDocument;
57 import org.tianocore.PlatformHeaderDocument;
58 import org.tianocore.SkuInfoDocument;
59 import org.tianocore.UserDefinedAntTasksDocument;
60 import org.tianocore.UserExtensionsDocument;
61 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
62 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
63 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
64 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
65
66 /**
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
69 **/
70 public class FpdFileContents {
71
72 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
73 static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
74
75 private PlatformSurfaceAreaDocument fpdd = null;
76
77 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
78
79 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
80
81 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
82
83 private FlashDocument.Flash fpdFlash = null;
84
85 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
86
87 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
88
89 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
90
91 private HashMap<String, ArrayList<String>> dynPcdMap = null;
92
93 private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();
94
95 private String itemType (String pcdInfo) {
96
97 return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1);
98 }
99
100 /**
101 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
102 */
103 public void initDynPcdMap() {
104 if (dynPcdMap == null) {
105 dynPcdMap = new HashMap<String, ArrayList<String>>();
106 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
107 if (l == null) {
108 removeElement(getfpdFrameworkModules());
109 fpdFrameworkModules = null;
110 return;
111 }
112 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
113 while (li.hasNext()) {
114 ModuleSADocument.ModuleSA moduleSa = li.next();
115 if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {
116 continue;
117 }
118 String ModuleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() +
119 " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
120 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();
121 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
122 while (lpi.hasNext()) {
123 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
124 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
125 if (dynPcdMap.get(pcdKey) == null) {
126 ArrayList<String> al = new ArrayList<String>();
127 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
128 dynPcdMap.put(pcdKey, al);
129 }
130 else{
131 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
132 }
133 }
134 }
135 }
136 }
137
138 public ArrayList<String> getDynPcdMapValue(String key) {
139 return dynPcdMap.get(key);
140 }
141 /**
142 Constructor to create a new spd file
143 **/
144 public FpdFileContents() {
145
146 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
147 fpdRoot = fpdd.addNewPlatformSurfaceArea();
148
149 }
150
151 /**
152 Constructor for existing document object
153 @param psa
154 **/
155 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
156 fpdRoot = fpd;
157 fpdHdr = fpdRoot.getPlatformHeader();
158 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
159 fpdBuildOpts = fpdRoot.getBuildOptions();
160 fpdFrameworkModules = fpdRoot.getFrameworkModules();
161 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
162 fpdFlash = fpdRoot.getFlash();
163 }
164
165 /**
166 Constructor based on an existing spd file
167
168 @param f Existing spd file
169 **/
170 public FpdFileContents(File f) {
171 try {
172 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
173 fpdRoot = fpdd.getPlatformSurfaceArea();
174 } catch (Exception e) {
175 System.out.println(e.toString());
176 }
177 }
178
179 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
180 if (fpdDynPcdBuildDefs == null){
181 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
182 }
183 return fpdDynPcdBuildDefs;
184 }
185
186 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
187 if (fpdFrameworkModules == null){
188 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
189 }
190 return fpdFrameworkModules;
191 }
192
193 public void getFrameworkModuleSAByFvBinding (String fvName, Vector<String[]> vGuid) {
194 if (getFrameworkModulesCount() == 0){
195 return;
196 }
197
198 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
199 while(li.hasNext()) {
200 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
201 if (moduleSa.getModuleSaBuildOptions() == null) {
202 continue;
203 }
204 String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();
205 if (fvBinding == null) {
206 continue;
207 }
208
209 String[] fvNames = fvBinding.split(" ");
210 for (int i = 0; i < fvNames.length; ++i) {
211 //
212 // BugBug : underscore "_" should not be replaced!!!
213 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
214 //
215 if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {
216 String[] sa = new String[] {moduleSa.getModuleGuid(), moduleSa.getModuleVersion(),
217 moduleSa.getPackageGuid(), moduleSa.getPackageVersion(),
218 listToString(moduleSa.getSupArchList())};
219 vGuid.add(sa);
220 break;
221 }
222 }
223 }
224 }
225
226 public int getFrameworkModulesCount() {
227 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
228 removeElement(getfpdFrameworkModules());
229 fpdFrameworkModules = null;
230 return 0;
231 }
232 return getfpdFrameworkModules().getModuleSAList().size();
233 }
234
235 public void getFrameworkModulesInfo(String[][] saa) {
236 if (getFrameworkModulesCount() == 0){
237 return;
238 }
239
240 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
241 int i = 0;
242 while(li.hasNext()) {
243 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
244 saa[i][0] = moduleSa.getModuleGuid();
245 saa[i][1] = moduleSa.getModuleVersion();
246
247 saa[i][2] = moduleSa.getPackageGuid();
248 saa[i][3] = moduleSa.getPackageVersion();
249 saa[i][4] = listToString(moduleSa.getSupArchList());
250 ++i;
251 }
252 }
253
254 public void getFrameworkModuleInfo(int i, String[] sa) {
255 ModuleSADocument.ModuleSA msa = getModuleSA(i);
256 if (msa == null) {
257 return;
258 }
259 sa[0] = msa.getModuleGuid();
260 sa[1] = msa.getModuleVersion();
261 sa[2] = msa.getPackageGuid();
262 sa[3] = msa.getPackageVersion();
263 sa[4] = listToString(msa.getSupArchList());
264 }
265
266 public ModuleSADocument.ModuleSA getModuleSA(String key) {
267
268 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
269 removeElement(getfpdFrameworkModules());
270 fpdFrameworkModules = null;
271 return null;
272 }
273 String[] s = key.split(" ");
274 String archsInKey = "";
275 if (s.length > 4) {
276 for (int i = 4; i < s.length; ++i) {
277 archsInKey += s[i];
278 archsInKey += " ";
279 }
280 archsInKey = archsInKey.trim();
281 }
282
283 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
284 while(li.hasNext()) {
285 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
286 if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {
287 if (moduleSa.getModuleVersion() != null) {
288 if (!moduleSa.getModuleVersion().equals(s[1])) {
289 continue;
290 }
291 }
292 if (moduleSa.getPackageVersion() != null) {
293 if (!moduleSa.getPackageVersion().equals(s[3])) {
294 continue;
295 }
296 }
297 //ToDo add arch check .
298 if (moduleSa.getSupArchList() != null) {
299 if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) {
300 return moduleSa;
301 }
302 }
303 else {
304 if (archsInKey.length() == 0) {
305 return moduleSa;
306 }
307 }
308 }
309 }
310 return null;
311 }
312
313 private ModuleSADocument.ModuleSA getModuleSA(int i) {
314 ModuleSADocument.ModuleSA moduleSa = null;
315 if (fpdRoot.getFrameworkModules() == null) {
316 return null;
317 }
318 XmlCursor cursor = fpdRoot.getFrameworkModules().newCursor();
319 if (cursor.toFirstChild()) {
320 for (int j = 0; j < i; ++j) {
321 cursor.toNextSibling();
322 }
323 moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
324 }
325 cursor.dispose();
326 return moduleSa;
327 }
328
329 public void removeModuleSA(int i) {
330 XmlObject o = fpdRoot.getFrameworkModules();
331 if (o == null) {
332 return;
333 }
334
335 XmlCursor cursor = o.newCursor();
336 if (cursor.toFirstChild()) {
337 for (int j = 0; j < i; ++j) {
338 cursor.toNextSibling();
339 }
340 //
341 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
342 //
343 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
344 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
345 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
346 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
347 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {
348 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();
349 while(li.hasNext()) {
350 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
351 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);
352 }
353 }
354
355 cursor.push();
356 while (cursor.hasPrevToken()) {
357 cursor.toPrevToken();
358 if (!cursor.isText()) {
359 break;
360 }
361 if (cursor.getObject() == null) {
362 break;
363 }
364 String s = cursor.getTextValue();
365 if (s.matches(regExpNewLineAndSpaces)) {
366 continue;
367 }
368 }
369
370 if (cursor.isComment()) {
371 cursor.removeXml();
372 }
373
374 cursor.pop();
375 cursor.removeXml();
376 if (getFrameworkModulesCount() == 0) {
377 cursor.dispose();
378 removeElement(getfpdFrameworkModules());
379 fpdFrameworkModules = null;
380 return;
381 }
382 }
383 cursor.dispose();
384 }
385
386 public boolean adjustPcd (int seqModuleSa) throws Exception {
387 boolean dataModified = false;
388 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
389 int pcdCount = getPcdDataCount(seqModuleSa);
390 String[][] saaModuleSaPcd = new String[pcdCount][7];
391 getPcdData(seqModuleSa, saaModuleSaPcd);
392 String mg = moduleSa.getModuleGuid();
393 String mv = moduleSa.getModuleVersion();
394 String pg = moduleSa.getPackageGuid();
395 String pv = moduleSa.getPackageVersion();
396 String arch = listToString(moduleSa.getSupArchList());
397 //
398 // delete pcd in ModuleSA but not in MSA files any longer.
399 //
400 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
401 int libCount = getLibraryInstancesCount(moduleKey);
402 String[][] saaLib = new String[libCount][5];
403 getLibraryInstances(moduleKey, saaLib);
404 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
405 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
406 //
407 // create vector for module & library instance MIs.
408 //
409 vMi.add(mi);
410 for (int j = 0; j < saaLib.length; ++j) {
411 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
412 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
413 vMi.add(libMi);
414 }
415
416 nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {
417
418 for (int j = 0; j < vMi.size(); ++j) {
419 ModuleIdentification nextMi = vMi.get(j);
420 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) {
421 continue nextPcd;
422 }
423 }
424 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);
425 dataModified = true;
426 }
427 //
428 // add new Pcd from MSA file to ModuleSA.
429 //
430 for (int i = 0; i < vMi.size(); ++i) {
431 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
432 .getModuleXmlObject(vMi
433 .get(i));
434 if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {
435 continue;
436 }
437 ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();
438 msaPcdIter:while (li.hasNext()) {
439 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
440 ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());
441 if (al != null) {
442 for (int j = 0; j < al.size(); ++j) {
443 if (al.get(j).contains(moduleKey)) {
444 continue msaPcdIter;
445 }
446 }
447 }
448
449 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));
450 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
451 if (spdPcd == null) {
452 //
453 // ToDo Error
454 //
455 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "
456 + mi.getName());
457 }
458 //
459 // AddItem to ModuleSA PcdBuildDefinitions
460 //
461 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()
462 : msaPcd.getDefaultValue();
463
464 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),
465 msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);
466 dataModified = true;
467 }
468
469 }
470
471 return dataModified;
472 }
473
474 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {
475
476 ArrayList<String> al = dynPcdMap.get(pcdKey);
477 if (al == null) {
478 return;
479 }
480 String[] s = moduleInfo.split(" ");
481 for(int i = 0; i < al.size(); ++i){
482 String consumer = al.get(i);
483 if (consumer.contains(s[0].toLowerCase()) && consumer.contains(s[2].toLowerCase())){
484 String[] consumerPart = consumer.split(" ");
485 if (!consumerPart[4].equals(s[4])) {
486 continue;
487 }
488 al.remove(consumer);
489 break;
490 }
491 }
492
493 if (al.size() == 0) {
494 defaultPcdValue.remove(pcdKey);
495 dynPcdMap.remove(pcdKey);
496 String[] s1 = pcdKey.split(" ");
497 removeDynamicPcdBuildData(s1[0], s1[1]);
498 }
499
500 }
501 //
502 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
503 //
504 public int getPcdDataCount (int i){
505 ModuleSADocument.ModuleSA msa = getModuleSA(i);
506
507 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
508 return 0;
509 }
510 return msa.getPcdBuildDefinition().getPcdDataList().size();
511
512 }
513
514 public void getPcdData (int i, String[][] saa) {
515 ModuleSADocument.ModuleSA msa = getModuleSA(i);
516
517 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
518 return;
519 }
520 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
521 for (int k = 0; k < saa.length; ++k) {
522 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
523 saa[k][0] = pcdData.getCName();
524 saa[k][1] = pcdData.getTokenSpaceGuidCName();
525 saa[k][2] = pcdData.getItemType()+"";
526 saa[k][3] = pcdData.getToken().toString();
527 saa[k][4] = pcdData.getMaxDatumSize()+"";
528 saa[k][5] = pcdData.getDatumType()+"";
529 saa[k][6] = pcdData.getValue();
530
531 }
532 }
533
534 public void removePcdData (int seqModuleSa, String cName, String tsGuid) {
535 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
536 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
537 return;
538 }
539
540 String mg = moduleSa.getModuleGuid();
541 String mv = moduleSa.getModuleVersion();
542 String pg = moduleSa.getPackageGuid();
543 String pv = moduleSa.getPackageVersion();
544 String arch = listToString(moduleSa.getSupArchList());
545 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
546
547 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
548 if (cursor.toFirstChild()){
549
550 do {
551 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
552 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
553 maintainDynPcdMap(cName + " " + tsGuid, moduleKey);
554 if (getPcdDataCount(seqModuleSa) == 1) {
555 cursor.toParent();
556 }
557 cursor.removeXml();
558 break;
559 }
560 }
561 while(cursor.toNextSibling());
562
563 }
564 cursor.dispose();
565 }
566
567 public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){
568 ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);
569 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
570 return;
571 }
572
573 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
574 if (cursor.toFirstChild()){
575 do {
576 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
577 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
578 //
579 // change item type while not updating dynPcdData????
580 //
581 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
582 if(pcdData.getDatumType().equals("VOID*")) {
583 pcdData.setMaxDatumSize(new Integer(maxSize));
584 }
585 pcdData.setValue(value);
586 defaultPcdValue.put(cName + " " + tsGuid, value);
587 break;
588 }
589 }
590 while(cursor.toNextSibling());
591 }
592 cursor.dispose();
593 }
594
595 /**Get original Pcd info from MSA & SPD files.
596 * @param mi ModuleIdentification from which MSA & SPD come
597 * @param cName PCD cName
598 * @param sa Results: HelpText, Original item type.
599 * @return
600 */
601 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{
602 try {
603
604 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
605 if (msa.getPcdCoded() == null) {
606 return false;
607 }
608
609 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
610 m.put("ModuleSurfaceArea", msa);
611 SurfaceAreaQuery.setDoc(m);
612 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
613 //
614 // First look through MSA pcd entries.
615 //
616 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
617 ListIterator li = l.listIterator();
618 while(li.hasNext()) {
619 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
620 if (!msaPcd.getCName().equals(cName)) {
621 continue;
622 }
623 if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {
624 continue;
625 }
626 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
627 if (spdPcd == null) {
628 //
629 // ToDo Error
630 //
631 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());
632 }
633 //
634 // Get Pcd help text and original item type.
635 //
636 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();
637 sa[1] = msaPcd.getPcdItemType()+"";
638 sa[2] = msa.getModuleDefinitions().getBinaryModule()+"";
639 return true;
640 }
641
642
643 }
644 catch (Exception e){
645 e.printStackTrace();
646 throw e;
647 }
648
649 return false;
650 }
651
652 private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) {
653 int libCount = getLibraryInstancesCount(moduleKey);
654 String[][] saaLib = new String[libCount][5];
655 getLibraryInstances(moduleKey, saaLib);
656 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
657 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
658 //
659 // create vector for module & library instance MIs.
660 //
661 vMi.add(mi);
662 for (int j = 0; j < saaLib.length; ++j) {
663 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
664 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
665 vMi.add(libMi);
666 }
667
668 int pcdSourceCount = 0;
669 for (int i = 0; i < vMi.size(); ++i) {
670 if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) {
671 pcdSourceCount++;
672 }
673 }
674
675 if (pcdSourceCount < 2) {
676 return false;
677 }
678 else {
679 return true;
680 }
681
682 }
683
684 /**Remove PCDBuildDefinition entries from ModuleSA
685 * @param moduleKey identifier of ModuleSA.
686 * @param consumer where these entries come from.
687 */
688 public void removePcdData(String moduleKey, ModuleIdentification consumer) {
689
690 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);
691 if (msa.getPcdCoded() == null) {
692 return;
693 }
694
695 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
696 ListIterator li = l.listIterator();
697
698 while(li.hasNext()) {
699 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
700 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);
701 if (moduleSA.getPcdBuildDefinition() != null) {
702 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();
703 cursor.push();
704 if (cursor.toFirstChild()) {
705 do {
706 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor
707 .getObject();
708 String cName = msaPcd.getCName();
709 String tsGuidCName = msaPcd.getTokenSpaceGuidCName();
710 if (cName.equals(pcdData.getCName())
711 && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) {
712
713 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),
714 moduleKey);
715 cursor.removeXml();
716 break;
717 }
718 } while (cursor.toNextSibling());
719 }
720
721 cursor.pop();
722 if (moduleSA.getPcdBuildDefinition().getPcdDataList().size() == 0) {
723 cursor.removeXml();
724 }
725 cursor.dispose();
726 }
727 }
728
729 }
730 //
731 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
732 //
733 public int getLibraryInstancesCount(String key) {
734 ModuleSADocument.ModuleSA msa = getModuleSA(key);
735 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
736 return 0;
737 }
738 return msa.getLibraries().getInstanceList().size();
739 }
740
741 public void getLibraryInstances(String key, String[][] saa){
742 ModuleSADocument.ModuleSA msa = getModuleSA(key);
743 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
744 return ;
745 }
746
747 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
748 for (int i = 0; i < saa.length; ++i) {
749 LibrariesDocument.Libraries.Instance instance = li.next();
750 saa[i][1] = instance.getModuleGuid();
751 saa[i][2] = instance.getModuleVersion();
752 saa[i][3] = instance.getPackageGuid();
753 saa[i][4] = instance.getPackageVersion();
754 }
755 }
756
757 public void removeLibraryInstance(String key, int i) {
758 ModuleSADocument.ModuleSA msa = getModuleSA(key);
759 if (msa == null || msa.getLibraries() == null){
760 return ;
761 }
762
763 XmlCursor cursor = msa.getLibraries().newCursor();
764 if (cursor.toFirstChild()) {
765 for (int j = 0; j < i; ++j) {
766 cursor.toNextSibling();
767 }
768 cursor.push();
769 while (cursor.hasPrevToken()) {
770 cursor.toPrevToken();
771 if (!cursor.isText()) {
772 break;
773 }
774 String s = cursor.getTextValue();
775 if (s.matches(regExpNewLineAndSpaces)) {
776 continue;
777 }
778 }
779
780 if (cursor.isComment()) {
781 cursor.removeXml();
782 }
783 cursor.pop();
784 cursor.removeXml();
785 if (getLibraryInstancesCount(key) == 0) {
786 cursor.toParent();
787 cursor.removeXml();
788 }
789 }
790
791 cursor.dispose();
792 }
793
794 public void genLibraryInstance(ModuleIdentification libMi, String key) {
795 ModuleSADocument.ModuleSA msa = getModuleSA(key);
796 if (msa == null){
797 msa = getfpdFrameworkModules().addNewModuleSA();
798 }
799 LibrariesDocument.Libraries libs = msa.getLibraries();
800 if(libs == null){
801 libs = msa.addNewLibraries();
802 }
803
804 String mn = libMi.getName();
805 String mg = libMi.getGuid();
806 String mv = libMi.getVersion();
807 String pn = libMi.getPackageId().getName();
808 String pg = libMi.getPackageId().getGuid();
809 String pv = libMi.getPackageId().getVersion();
810 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
811 XmlCursor cursor = instance.newCursor();
812 try{
813 String comment = "Pkg: " + pn + " Mod: " + mn
814 + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
815 cursor.insertComment(comment);
816 }
817 catch (Exception e){
818 e.printStackTrace();
819 }
820 finally {
821 cursor.dispose();
822 }
823
824 instance.setModuleGuid(mg);
825 instance.setModuleVersion(mv);
826 instance.setPackageGuid(pg);
827 instance.setPackageVersion(pv);
828
829 }
830
831 public String getFvBinding(String moduleKey){
832 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
833 return getFvBinding (moduleSa);
834 }
835
836 public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {
837 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
838 return null;
839 }
840 return moduleSa.getModuleSaBuildOptions().getFvBinding();
841 }
842
843 public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {
844 if (moduleSa == null ) {
845 return;
846 }
847 if (fvBinding == null || fvBinding.length() == 0) {
848 if(moduleSa.getModuleSaBuildOptions() != null){
849 moduleSa.getModuleSaBuildOptions().unsetFvBinding();
850 }
851 }
852 else {
853 if(moduleSa.getModuleSaBuildOptions() == null){
854 moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
855 return;
856 }
857 moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding);
858 }
859 }
860
861 public void setFvBinding(String moduleKey, String fvBinding){
862 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
863 setFvBinding (moduleSa, fvBinding);
864 }
865
866 private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {
867 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
868 return -1;
869 }
870
871 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
872 String[] fvNamesArray = fvNameList.split(" ");
873 int occursAt = -1;
874 for (int i = 0; i < fvNamesArray.length; ++i) {
875 if (fvNamesArray[i].equals(fvName)) {
876 occursAt = i;
877 break;
878 }
879 }
880 return occursAt;
881 }
882
883 public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
884 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
885 return;
886 }
887
888 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
889 String[] fvNamesArray = fvNameList.split(" ");
890 int occursAt = -1;
891 for (int i = 0; i < fvNamesArray.length; ++i) {
892 if (fvNamesArray[i].equals(fvName)) {
893 occursAt = i;
894 break;
895 }
896 }
897 // jump over where the input fvName occurs in the original Fv list.
898 if (occursAt != -1) {
899 String newFvNameList = " ";
900 for (int i = 0; i < fvNamesArray.length; ++i) {
901 if (i == occursAt) {
902 continue;
903 }
904 newFvNameList += fvNamesArray[i];
905 }
906 setFvBinding (moduleSa, newFvNameList.trim());
907 }
908
909 }
910
911 /**
912 * @param fvName The FV name that to be removed from FvBinding List.
913 */
914 public void removeFvBindingAll (String fvName) {
915 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
916 removeElement(getfpdFrameworkModules());
917 fpdFrameworkModules = null;
918 return;
919 }
920
921 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
922 while (li.hasNext()) {
923 ModuleSADocument.ModuleSA moduleSa = li.next();
924 removeFvBinding (moduleSa, fvName);
925 }
926 }
927
928 public void appendFvBindingAll (String fvName) {
929 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
930 removeElement(getfpdFrameworkModules());
931 fpdFrameworkModules = null;
932 return;
933 }
934
935 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
936 while (li.hasNext()) {
937 ModuleSADocument.ModuleSA moduleSa = li.next();
938 appendFvBinding (moduleSa, fvName);
939 }
940 }
941
942 public void appendFvBindingFor (String oldFvName, String newFvName) {
943 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
944 removeElement(getfpdFrameworkModules());
945 fpdFrameworkModules = null;
946 return;
947 }
948
949 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
950 while (li.hasNext()) {
951 ModuleSADocument.ModuleSA moduleSa = li.next();
952 String fvBinding = getFvBinding (moduleSa);
953 if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {
954 appendFvBinding (moduleSa, newFvName);
955 }
956 }
957 }
958
959 public void appendFvBinding (String moduleKey, String fvName) {
960 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
961 appendFvBinding (moduleSa, fvName);
962 }
963
964 public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
965 if (moduleSa == null) {
966 return;
967 }
968
969 if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
970 setFvBinding(moduleSa, fvName);
971 return;
972 }
973
974 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
975 String newFvNameList = fvNameList + " " + fvName;
976 setFvBinding (moduleSa, newFvNameList.trim());
977 }
978
979 public void updateFvBindingInModuleSA (String moduleKey, String fvName) {
980
981 appendFvBinding (moduleKey, fvName);
982 }
983
984 public String getFfsFileNameGuid(String moduleKey){
985 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
986 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
987 return null;
988 }
989 return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid();
990 }
991
992 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
993 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
994 if (msa == null ) {
995 return;
996 }
997 if(msa.getModuleSaBuildOptions() == null){
998 msa.addNewModuleSaBuildOptions();
999
1000 }
1001 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();
1002 if (fileGuid != null) {
1003 msaBuildOpts.setFfsFileNameGuid(fileGuid);
1004 }
1005 else{
1006 XmlCursor cursor = msaBuildOpts.newCursor();
1007 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {
1008 cursor.removeXml();
1009 }
1010 cursor.dispose();
1011 }
1012
1013 }
1014
1015 public String getFfsFormatKey(String moduleKey){
1016 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1017 if (msa == null || msa.getModuleSaBuildOptions() == null) {
1018 return null;
1019 }
1020 return msa.getModuleSaBuildOptions().getFfsFormatKey();
1021 }
1022
1023 public void setFfsFormatKey(String moduleKey, String ffsKey){
1024 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1025 if (msa == null ) {
1026 return;
1027 }
1028 if(msa.getModuleSaBuildOptions() == null){
1029 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1030 return;
1031 }
1032 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1033 }
1034
1035 public void setModuleSAForceDebug(int i, boolean dbgEnable) {
1036 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1037 moduleSa.setForceDebug(dbgEnable);
1038 }
1039
1040 public boolean getModuleSAForceDebug (int i) {
1041 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1042 if (moduleSa.getForceDebug() == true) {
1043 return true;
1044 }
1045 return false;
1046 }
1047
1048 public void getModuleSAOptions(String moduleKey, String[][] saa) {
1049 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1050 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1051 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1052 return ;
1053 }
1054
1055 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
1056 ListIterator li = lOpt.listIterator();
1057 int i = 0;
1058 while(li.hasNext()) {
1059 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1060 if (opt.getBuildTargets() != null) {
1061 saa[i][0] = listToString(opt.getBuildTargets());
1062 }
1063 saa[i][1] = opt.getToolChainFamily();
1064 saa[i][2] = opt.getTagName();
1065 saa[i][3] = opt.getToolCode();
1066
1067 if (opt.getSupArchList() != null){
1068 saa[i][4] = listToString(opt.getSupArchList());
1069 }
1070 else {
1071 saa[i][4] = "";
1072 }
1073
1074 saa[i][5] = opt.getStringValue();
1075
1076 ++i;
1077 }
1078 }
1079
1080 public int getModuleSAOptionsCount(String moduleKey){
1081 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1082 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1083 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1084 return 0;
1085 }
1086 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
1087 }
1088
1089 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1090 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1091 if (msa.getModuleSaBuildOptions() == null) {
1092 msa.addNewModuleSaBuildOptions();
1093 }
1094 if (msa.getModuleSaBuildOptions().getOptions() == null){
1095 msa.getModuleSaBuildOptions().addNewOptions();
1096 }
1097 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
1098 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1099 }
1100
1101 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
1102 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1103 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1104 return ;
1105 }
1106 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1107 XmlCursor cursor = opts.newCursor();
1108 if (cursor.toFirstChild()) {
1109 for (int j = 0; j < i; ++j){
1110 cursor.toNextSibling();
1111 }
1112 cursor.removeXml();
1113 if (getModuleSAOptionsCount(moduleKey) == 0) {
1114 cursor.toParent();
1115 cursor.removeXml();
1116 }
1117 }
1118 cursor.dispose();
1119 }
1120
1121 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1122 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1123 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1124 return ;
1125 }
1126 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1127 XmlCursor cursor = opts.newCursor();
1128 if (cursor.toFirstChild()) {
1129 for (int j = 0; j < i; ++j){
1130 cursor.toNextSibling();
1131 }
1132 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1133 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1134 }
1135 cursor.dispose();
1136 }
1137
1138 /**add pcd information of module mi to a ModuleSA.
1139 * @param mi
1140 * @param moduleSa if null, generate a new ModuleSA.
1141 */
1142 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
1143 //ToDo add Arch filter
1144
1145 try {
1146 if (moduleSa == null) {
1147 moduleSa = genModuleSA(mi, arch);
1148 }
1149
1150 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
1151 if (msa.getPcdCoded() == null) {
1152 return;
1153 }
1154
1155 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
1156 m.put("ModuleSurfaceArea", msa);
1157 SurfaceAreaQuery.setDoc(m);
1158 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
1159 //
1160 // Implementing InitializePlatformPcdBuildDefinitions
1161 //
1162 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
1163 ListIterator li = l.listIterator();
1164 while(li.hasNext()) {
1165 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
1166 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
1167 if (spdPcd == null) {
1168 //
1169 // ToDo Error
1170 //
1171 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());
1172 }
1173 //
1174 // AddItem to ModuleSA PcdBuildDefinitions
1175 //
1176 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
1177
1178 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
1179 }
1180
1181 }
1182 catch (Exception e){
1183
1184 throw e;
1185 }
1186
1187 }
1188
1189 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
1190
1191 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
1192 for (int i = 0; i < depPkgs.length; ++i) {
1193
1194 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);
1195 if (xo == null) {
1196 continue;
1197 }
1198 for (int j = 0; j < xo.length; ++j) {
1199 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
1200 if (msaPcd.getTokenSpaceGuidCName() == null) {
1201 if (spdPcd.getCName().equals(msaPcd.getCName())) {
1202 return spdPcd;
1203 }
1204 }
1205 else{
1206 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
1207 return spdPcd;
1208 }
1209 }
1210
1211 }
1212
1213 }
1214 return null;
1215 }
1216
1217 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
1218 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
1219 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
1220 XmlCursor cursor = msa.newCursor();
1221 try{
1222 String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "
1223 + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
1224 cursor.insertComment(comment);
1225 }
1226 catch(Exception e){
1227 e.printStackTrace();
1228 }
1229 finally {
1230 cursor.dispose();
1231 }
1232 msa.setModuleGuid(mi.getGuid());
1233 msa.setModuleVersion(mi.getVersion());
1234 msa.setPackageGuid(pi.getGuid());
1235 msa.setPackageVersion(pi.getVersion());
1236 if (arch != null) {
1237 Vector<String> v = new Vector<String>();
1238 v.add(arch);
1239 msa.setSupArchList(v);
1240 }
1241
1242 return msa;
1243 }
1244
1245 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa)
1246 throws PcdItemTypeConflictException, PcdValueMalFormed{
1247 if (moduleSa.getPcdBuildDefinition() == null){
1248 moduleSa.addNewPcdBuildDefinition();
1249 }
1250 //
1251 // constructe pcd to modulesa mapping first.
1252 // Attention : for any error condition, remove from map this pcd.
1253 //
1254 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1255 if (pcdConsumer == null) {
1256 pcdConsumer = new ArrayList<String>();
1257 }
1258 //
1259 // Check whether this PCD has already added to ModuleSA, if so, just return.
1260 //
1261 String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion()
1262 + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
1263 for (int i = 0; i < pcdConsumer.size(); ++i) {
1264 String pcdInfo = pcdConsumer.get(i);
1265 if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){
1266 return;
1267 }
1268 }
1269 //
1270 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1271 //
1272 if (pcdConsumer.size() > 0) {
1273
1274 itemType = itemType (pcdConsumer.get(0));
1275 }
1276 String listValue = moduleInfo + " " + itemType;
1277 pcdConsumer.add(listValue);
1278 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1279
1280 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1281 fpdPcd.setCName(cName);
1282 fpdPcd.setToken(token);
1283 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1284 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1285 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1286
1287 if (defaultVal != null){
1288 fpdPcd.setValue(defaultVal);
1289 }
1290 else {
1291 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1292 fpdPcd.setValue("0");
1293 }
1294 if (dataType.equals("BOOLEAN")){
1295 fpdPcd.setValue("FALSE");
1296 }
1297 if (dataType.equals("VOID*")) {
1298 fpdPcd.setValue("");
1299 }
1300 }
1301 //
1302 // Using existing pcd value, if this pcd already exists in other moduleSa.
1303 //
1304 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1305 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1306 }
1307 else {
1308 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1309 }
1310
1311 if (dataType.equals("UINT8")){
1312 fpdPcd.setMaxDatumSize(1);
1313 }
1314 if (dataType.equals("UINT16")) {
1315 fpdPcd.setMaxDatumSize(2);
1316 }
1317 if (dataType.equals("UINT32")) {
1318 fpdPcd.setMaxDatumSize(4);
1319 }
1320 if (dataType.equals("UINT64")){
1321 fpdPcd.setMaxDatumSize(8);
1322 }
1323 if (dataType.equals("BOOLEAN")){
1324 fpdPcd.setMaxDatumSize(1);
1325 }
1326 if (dataType.equals("VOID*")) {
1327 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1328 fpdPcd.setMaxDatumSize(maxSize);
1329 }
1330
1331
1332 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1333 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1334 //
1335 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1336 // so need to add one dyn pcd.
1337 //
1338 if (al.size() == 1) {
1339 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1340 }
1341 }
1342
1343 }
1344
1345 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1346 if (datum == null) {
1347 return 0;
1348 }
1349 char ch = datum.charAt(0);
1350 int start, end;
1351 String strValue;
1352 //
1353 // For void* type PCD, only three datum is support:
1354 // 1) Unicode: string with start char is "L"
1355 // 2) Ansci: String is ""
1356 // 3) byte array: String start char "{"
1357 //
1358 if (ch == 'L') {
1359 start = datum.indexOf('\"');
1360 end = datum.lastIndexOf('\"');
1361 if ((start > end) ||
1362 (end > datum.length())||
1363 ((start == end) && (datum.length() > 0))) {
1364 //ToDo Error handling here
1365 throw new PcdValueMalFormed (datum);
1366 }
1367
1368 strValue = datum.substring(start + 1, end);
1369 return strValue.length() * 2;
1370 } else if (ch == '\"'){
1371 start = datum.indexOf('\"');
1372 end = datum.lastIndexOf('\"');
1373 if ((start > end) ||
1374 (end > datum.length())||
1375 ((start == end) && (datum.length() > 0))) {
1376 throw new PcdValueMalFormed (datum);
1377 }
1378 strValue = datum.substring(start + 1, end);
1379 return strValue.length();
1380 } else if (ch =='{') {
1381 String[] strValueArray;
1382
1383 start = datum.indexOf('{');
1384 end = datum.lastIndexOf('}');
1385 strValue = datum.substring(start + 1, end);
1386 strValue = strValue.trim();
1387 if (strValue.length() == 0) {
1388 return 0;
1389 }
1390 strValueArray = strValue.split(",");
1391 for (int index = 0; index < strValueArray.length; index ++) {
1392 Integer value = Integer.decode(strValueArray[index].trim());
1393
1394 if (value > 0xFF) {
1395 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1396 // "it must be a byte array. But the element of %s exceed the byte range",
1397 throw new PcdValueMalFormed (datum);
1398 }
1399 }
1400 return strValueArray.length;
1401
1402
1403 } else {
1404 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1405 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1406 // "2) ANSIC string: like \"xxx\";\r\n"+
1407 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1408 // "but the datum in seems does not following above format!",
1409 throw new PcdValueMalFormed (datum);
1410
1411 }
1412 }
1413
1414 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1415 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1416
1417 return al;
1418 }
1419
1420 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1421
1422 return dynPcdMap.get(pcdKey);
1423 }
1424
1425 public int getDynamicPcdBuildDataCount() {
1426 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1427 removeElement(getfpdDynPcdBuildDefs());
1428 fpdDynPcdBuildDefs = null;
1429 return 0;
1430 }
1431 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1432 }
1433
1434 public void getDynamicPcdBuildData(String[][] saa) {
1435 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1436 removeElement(getfpdDynPcdBuildDefs());
1437 fpdDynPcdBuildDefs = null;
1438 return ;
1439 }
1440 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1441 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1442 int i = 0;
1443 while(li.hasNext()) {
1444 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1445 saa[i][0] = dynPcd.getCName();
1446 saa[i][1] = dynPcd.getToken().toString();
1447 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1448 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1449 saa[i][4] = dynPcd.getDatumType().toString();
1450
1451 ++i;
1452 }
1453 }
1454
1455 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1456 throws PcdValueMalFormed{
1457 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1458 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1459 dynPcdData.setCName(cName);
1460 dynPcdData.setToken(token);
1461 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1462 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1463
1464 BigInteger bigInt = new BigInteger("0");
1465 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1466 skuInfo.setSkuId(bigInt);
1467 if (defaultVal != null){
1468 skuInfo.setValue(defaultVal);
1469 }
1470 else {
1471 if (dataType.equals("UINT8")){
1472 skuInfo.setValue("0");
1473 }
1474 if (dataType.equals("UINT16")) {
1475 skuInfo.setValue("0");
1476 }
1477 if (dataType.equals("UINT32")) {
1478 skuInfo.setValue("0");
1479 }
1480 if (dataType.equals("UINT64")){
1481 skuInfo.setValue("0");
1482 }
1483 if (dataType.equals("BOOLEAN")){
1484 skuInfo.setValue("false");
1485 }
1486 if (dataType.equals("VOID*")) {
1487 skuInfo.setValue("");
1488 }
1489 }
1490 if (dataType.equals("UINT8")){
1491 dynPcdData.setMaxDatumSize(1);
1492 }
1493 if (dataType.equals("UINT16")) {
1494 dynPcdData.setMaxDatumSize(2);
1495 }
1496 if (dataType.equals("UINT32")) {
1497 dynPcdData.setMaxDatumSize(4);
1498 }
1499 if (dataType.equals("UINT64")){
1500 dynPcdData.setMaxDatumSize(8);
1501 }
1502 if (dataType.equals("BOOLEAN")){
1503 dynPcdData.setMaxDatumSize(1);
1504 }
1505 if (dataType.equals("VOID*")) {
1506 int maxSize = setMaxSizeForPointer(defaultVal);
1507 dynPcdData.setMaxDatumSize(maxSize);
1508 }
1509 }
1510
1511 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1512 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1513 if (o == null) {
1514 return;
1515 }
1516
1517 XmlCursor cursor = o.newCursor();
1518 if (cursor.toFirstChild()) {
1519 do {
1520 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1521 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1522 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1523
1524 if (getDynamicPcdBuildDataCount() == 1) {
1525 cursor.toParent();
1526 }
1527 cursor.removeXml();
1528 cursor.dispose();
1529 return;
1530 }
1531 }
1532 while (cursor.toNextSibling());
1533 }
1534 cursor.dispose();
1535 }
1536 //
1537 // Get the Sku Info count of ith dyn pcd element.
1538 //
1539 public int getDynamicPcdSkuInfoCount(int i){
1540 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1541 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1542 return 0;
1543 }
1544
1545 int skuInfoCount = 0;
1546 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1547 if (cursor.toFirstChild()) {
1548 for (int j = 0; j < i; ++j) {
1549 cursor.toNextSibling();
1550 }
1551 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1552 if (pcdData.getSkuInfoList() == null) {
1553 skuInfoCount = 0;
1554 }
1555 else {
1556 skuInfoCount = pcdData.getSkuInfoList().size();
1557 }
1558 }
1559 cursor.dispose();
1560 return skuInfoCount;
1561 }
1562
1563 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1564 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1565 removeElement(getfpdDynPcdBuildDefs());
1566 fpdDynPcdBuildDefs = null;
1567 return;
1568 }
1569
1570 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1571 if (cursor.toFirstChild()) {
1572 for (int j = 0; j < i; ++j) {
1573 cursor.toNextSibling();
1574 }
1575 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1576 if (pcdData.getSkuInfoList() == null) {
1577 cursor.dispose();
1578 return;
1579 }
1580 else {
1581 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1582 int k = 0;
1583 while (li.hasNext()) {
1584 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1585 saa[k][0] = skuInfo.getSkuId()+"";
1586 saa[k][1] = skuInfo.getVariableName();
1587 saa[k][2] = skuInfo.getVariableGuid();
1588 saa[k][3] = skuInfo.getVariableOffset();
1589 saa[k][4] = skuInfo.getHiiDefaultValue();
1590 saa[k][5] = skuInfo.getVpdOffset();
1591 saa[k][6] = skuInfo.getValue();
1592 ++k;
1593 }
1594
1595 }
1596 }
1597 cursor.dispose();
1598
1599 }
1600
1601 public String getDynamicPcdBuildDataValue(int i){
1602 String value = null;
1603 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1604 removeElement(getfpdDynPcdBuildDefs());
1605 fpdDynPcdBuildDefs = null;
1606 return value;
1607 }
1608
1609 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1610 if (cursor.toFirstChild()) {
1611 for (int j = 0; j < i; ++j) {
1612 cursor.toNextSibling();
1613 }
1614 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1615 if (pcdData.getSkuInfoList() == null) {
1616 value = null;
1617 }
1618 else {
1619 value = pcdData.getSkuInfoArray(0).getValue();
1620 }
1621 }
1622 cursor.dispose();
1623 return value;
1624 }
1625
1626 public String getDynamicPcdBuildDataVpdOffset(int i){
1627 String vpdOffset = null;
1628 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1629 removeElement(getfpdDynPcdBuildDefs());
1630 fpdDynPcdBuildDefs = null;
1631 return vpdOffset;
1632 }
1633
1634 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1635 if (cursor.toFirstChild()) {
1636 for (int j = 0; j < i; ++j) {
1637 cursor.toNextSibling();
1638 }
1639 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1640 if (pcdData.getSkuInfoList() == null) {
1641 vpdOffset = null;
1642 }
1643 else {
1644 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1645 }
1646 }
1647 cursor.dispose();
1648 return vpdOffset;
1649 }
1650
1651 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1652 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1653 removeElement(getfpdDynPcdBuildDefs());
1654 fpdDynPcdBuildDefs = null;
1655 return;
1656 }
1657
1658 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1659 if (cursor.toFirstChild()) {
1660 for (int j = 0; j < i; ++j) {
1661 cursor.toNextSibling();
1662 }
1663 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1664 if (pcdData.getSkuInfoList() == null) {
1665 cursor.dispose();
1666 return;
1667 }
1668 else {
1669 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1670 cursor.toChild(qSkuInfo);
1671 cursor.removeXml();
1672 }
1673 }
1674 cursor.dispose();
1675 }
1676 //
1677 // generate sku info for ith dyn pcd build data.
1678 //
1679 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1680 String hiiDefault, String vpdOffset, String value, int i) {
1681 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1682 // return;
1683 // }
1684
1685 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1686 if (cursor.toFirstChild()) {
1687 for (int j = 0; j < i; ++j) {
1688 cursor.toNextSibling();
1689 }
1690 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1691 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1692 skuInfo.setSkuId(new BigInteger(id));
1693 if (varName != null){
1694 skuInfo.setVariableName(varName);
1695 skuInfo.setVariableGuid(varGuid);
1696 skuInfo.setVariableOffset(varOffset);
1697 skuInfo.setHiiDefaultValue(hiiDefault);
1698 }
1699 else if (vpdOffset != null){
1700 skuInfo.setVpdOffset(vpdOffset);
1701 }
1702 else{
1703 skuInfo.setValue(value);
1704 }
1705 }
1706 }
1707
1708 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1709 String hiiDefault, String vpdOffset, String value, int i){
1710 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1711 // return;
1712 // }
1713
1714 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1715 if (cursor.toFirstChild()) {
1716 for (int j = 0; j < i; ++j) {
1717 cursor.toNextSibling();
1718 }
1719 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1720 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1721 while (li.hasNext()) {
1722 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1723 if (skuInfo.getSkuId().toString().equals(id)){
1724 if (varName != null){
1725 skuInfo.setVariableName(varName);
1726 skuInfo.setVariableGuid(varGuid);
1727 skuInfo.setVariableOffset(varOffset);
1728 skuInfo.setHiiDefaultValue(hiiDefault);
1729 }
1730 else if (vpdOffset != null){
1731 skuInfo.setVpdOffset(vpdOffset);
1732 }
1733 else{
1734 skuInfo.setValue(value);
1735 }
1736 break;
1737 }
1738 }
1739 }
1740 }
1741
1742 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1743 if (fpdBuildOpts == null) {
1744 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1745 }
1746 return fpdBuildOpts;
1747 }
1748
1749 public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {
1750 QName elementFvName = new QName (xmlNs, "FvName");
1751 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1752 QName elementInfFileName = new QName(xmlNs, "InfFileName");
1753 QName elementModule = new QName(xmlNs, "Module");
1754
1755 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1756 userExts.setUserID("IMAGES");
1757 userExts.setIdentifier(new BigInteger("1"));
1758 XmlCursor cursor = userExts.newCursor();
1759 cursor.toEndToken();
1760
1761 cursor.beginElement(elementFvName);
1762 cursor.insertChars(fvName);
1763 cursor.toNextToken();
1764
1765 cursor.beginElement(elementInfFileName);
1766 cursor.insertChars(fvName + ".inf");
1767 cursor.toNextToken();
1768
1769 cursor.beginElement(elementIncludeModules);
1770 for (int i = 0; i < includeModules.size(); ++i) {
1771 cursor.beginElement(elementModule);
1772 cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);
1773 if (!includeModules.get(i)[1].equals("null") && includeModules.get(i)[1].length() != 0) {
1774 cursor.insertAttributeWithValue("ModuleVersion", includeModules.get(i)[1]);
1775 }
1776 cursor.insertAttributeWithValue("PackageGuid", includeModules.get(i)[2]);
1777 if (!includeModules.get(i)[3].equals("null") && includeModules.get(i)[3].length() != 0) {
1778 cursor.insertAttributeWithValue("PackageVersion", includeModules.get(i)[3]);
1779 }
1780
1781 cursor.insertAttributeWithValue("Arch", includeModules.get(i)[4]);
1782 cursor.toEndToken();
1783 cursor.toNextToken();
1784 }
1785 cursor.dispose();
1786 }
1787
1788 public int getUserExtsIncModCount (String fvName) {
1789 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1790 return -1;
1791 }
1792 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1793 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1794 while (li.hasNext()) {
1795 UserExtensionsDocument.UserExtensions ues = li.next();
1796 if (!ues.getUserID().equals("IMAGES")) {
1797 continue;
1798 }
1799 XmlCursor cursor = ues.newCursor();
1800 cursor.toFirstChild();
1801 String elementName = cursor.getTextValue();
1802 if (elementName.equals(fvName)) {
1803 cursor.toNextSibling(elementIncludeModules);
1804 if (cursor.toFirstChild()) {
1805 int i = 1;
1806 for (i = 1; cursor.toNextSibling(); ++i);
1807 cursor.dispose();
1808 return i;
1809 }
1810 cursor.dispose();
1811 return 0;
1812 }
1813 cursor.dispose();
1814 }
1815 return -1;
1816 }
1817
1818 public void getUserExtsIncMods(String fvName, String[][] saa) {
1819 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1820 return;
1821 }
1822
1823 XmlCursor cursor = getfpdBuildOpts().newCursor();
1824 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1825 QName attribUserId = new QName ("UserID");
1826 QName elementFvName = new QName (xmlNs, "FvName");
1827 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1828 QName attribModuleGuid = new QName("ModuleGuid");
1829 QName attribModuleVersion = new QName("ModuleVersion");
1830 QName attribPackageGuid = new QName("PackageGuid");
1831 QName attribPackageVersion = new QName("PackageVersion");
1832 QName attribArch = new QName("Arch");
1833
1834 if (cursor.toChild(elementUserExts)) {
1835 do {
1836 cursor.push();
1837 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1838 cursor.toChild(elementFvName);
1839 String elementName = cursor.getTextValue();
1840 if (elementName.equals(fvName)) {
1841 cursor.toNextSibling(elementIncludeModules);
1842 if (cursor.toFirstChild()) {
1843 int i = 0;
1844 do {
1845 saa[i][0] = cursor.getAttributeText(attribModuleGuid);
1846 saa[i][1] = cursor.getAttributeText(attribModuleVersion);
1847 saa[i][2] = cursor.getAttributeText(attribPackageGuid);
1848 saa[i][3] = cursor.getAttributeText(attribPackageVersion);
1849 saa[i][4] = cursor.getAttributeText(attribArch);
1850 ++i;
1851 }while (cursor.toNextSibling());
1852 }
1853 break;
1854 }
1855 }
1856 cursor.pop();
1857 }while (cursor.toNextSibling(elementUserExts));
1858 }
1859 cursor.dispose();
1860
1861 }
1862
1863 public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {
1864 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1865 return;
1866 }
1867 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1868 while (li.hasNext()) {
1869 UserExtensionsDocument.UserExtensions ues = li.next();
1870 if (!ues.getUserID().equals("IMAGES")) {
1871 continue;
1872 }
1873 XmlCursor cursor = ues.newCursor();
1874 cursor.toFirstChild();
1875 String elementName = cursor.getTextValue();
1876 if (elementName.equals(oldFvName)) {
1877 cursor.setTextValue(newFvName);
1878 }
1879 cursor.dispose();
1880 }
1881
1882 }
1883
1884 public void removeBuildOptionsUserExtensions (String fvName) {
1885 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1886 return;
1887 }
1888
1889 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1890 while (li.hasNext()) {
1891 UserExtensionsDocument.UserExtensions ues = li.next();
1892 if (!ues.getUserID().equals("IMAGES")) {
1893 continue;
1894 }
1895 XmlCursor cursor = ues.newCursor();
1896 cursor.toFirstChild();
1897 String elementName = cursor.getTextValue();
1898 if (elementName.equals(fvName)) {
1899 cursor.toParent();
1900 cursor.removeXml();
1901 cursor.dispose();
1902 return;
1903 }
1904 cursor.dispose();
1905 }
1906
1907 }
1908
1909 private boolean versionEqual (String v1, String v2) {
1910
1911 if ((v1 == null || v1.length() == 0 || v1.equalsIgnoreCase("null"))
1912 && (v2 == null || v2.length() == 0 || v2.equalsIgnoreCase("null"))) {
1913 return true;
1914 }
1915
1916 if (v1 != null && v1.equals(v2)) {
1917 return true;
1918 }
1919
1920 return false;
1921 }
1922
1923 public boolean moduleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
1924 boolean inList = false;
1925 if (getUserExtsIncModCount(fvName) > 0) {
1926
1927 XmlCursor cursor = getfpdBuildOpts().newCursor();
1928 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1929 QName attribUserId = new QName ("UserID");
1930 QName elementFvName = new QName (xmlNs, "FvName");
1931 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1932 QName attribModuleGuid = new QName("ModuleGuid");
1933 QName attribModuleVersion = new QName("ModuleVersion");
1934 QName attribPackageGuid = new QName("PackageGuid");
1935 QName attribPackageVersion = new QName("PackageVersion");
1936 QName attribArch = new QName("Arch");
1937
1938 if (cursor.toChild(elementUserExts)) {
1939 do {
1940 cursor.push();
1941 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1942 cursor.toChild(elementFvName);
1943 String elementName = cursor.getTextValue();
1944 if (elementName.equals(fvName)) {
1945 cursor.toNextSibling(elementIncludeModules);
1946 if (cursor.toFirstChild()) {
1947
1948 do {
1949 String mg = cursor.getAttributeText(attribModuleGuid);
1950 String mv = cursor.getAttributeText(attribModuleVersion);
1951 String pg = cursor.getAttributeText(attribPackageGuid);
1952 String pv = cursor.getAttributeText(attribPackageVersion);
1953 String ar = cursor.getAttributeText(attribArch);
1954 if (!moduleGuid.equalsIgnoreCase(mg)) {
1955 continue;
1956 }
1957 if (!packageGuid.equalsIgnoreCase(pg)) {
1958 continue;
1959 }
1960 if (!arch.equalsIgnoreCase(ar)) {
1961 continue;
1962 }
1963 if (!versionEqual(moduleVersion, mv)) {
1964 continue;
1965 }
1966 if (!versionEqual(packageVersion, pv)) {
1967 continue;
1968 }
1969 inList = true;
1970 break;
1971 }while (cursor.toNextSibling());
1972 }
1973 break;
1974 }
1975 }
1976 cursor.pop();
1977 }while (cursor.toNextSibling(elementUserExts));
1978 }
1979 cursor.dispose();
1980 }
1981 return inList;
1982 }
1983
1984 public void removeModuleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
1985 if (getUserExtsIncModCount(fvName) > 0) {
1986
1987 XmlCursor cursor = getfpdBuildOpts().newCursor();
1988 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1989 QName attribUserId = new QName ("UserID");
1990 QName elementFvName = new QName (xmlNs, "FvName");
1991 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1992 QName attribModuleGuid = new QName("ModuleGuid");
1993 QName attribModuleVersion = new QName("ModuleVersion");
1994 QName attribPackageGuid = new QName("PackageGuid");
1995 QName attribPackageVersion = new QName("PackageVersion");
1996 QName attribArch = new QName("Arch");
1997
1998 if (cursor.toChild(elementUserExts)) {
1999 do {
2000 cursor.push();
2001 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
2002 cursor.toChild(elementFvName);
2003 String elementName = cursor.getTextValue();
2004 if (elementName.equals(fvName)) {
2005 cursor.toNextSibling(elementIncludeModules);
2006 if (cursor.toFirstChild()) {
2007
2008 do {
2009 String mg = cursor.getAttributeText(attribModuleGuid);
2010 String mv = cursor.getAttributeText(attribModuleVersion);
2011 String pg = cursor.getAttributeText(attribPackageGuid);
2012 String pv = cursor.getAttributeText(attribPackageVersion);
2013 String ar = cursor.getAttributeText(attribArch);
2014 if (!moduleGuid.equalsIgnoreCase(mg)) {
2015 continue;
2016 }
2017 if (!packageGuid.equalsIgnoreCase(pg)) {
2018 continue;
2019 }
2020 if (!arch.equalsIgnoreCase(ar)) {
2021 continue;
2022 }
2023 if (!versionEqual(moduleVersion, mv)) {
2024 continue;
2025 }
2026 if (!versionEqual(packageVersion, pv)) {
2027 continue;
2028 }
2029 cursor.removeXml();
2030 }while (cursor.toNextSibling());
2031 }
2032 break;
2033 }
2034 }
2035 cursor.pop();
2036 }while (cursor.toNextSibling(elementUserExts));
2037 }
2038 cursor.dispose();
2039 }
2040 }
2041
2042 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
2043 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2044 if (udats == null) {
2045 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
2046 }
2047
2048 AntTaskDocument.AntTask at = udats.addNewAntTask();
2049 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2050 }
2051
2052 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
2053 at.setId(new Integer(id));
2054 XmlCursor cursor = at.newCursor();
2055 if (fileName != null){
2056 at.setFilename(fileName);
2057 }
2058 else if (cursor.toChild(xmlNs, "Filename")) {
2059 cursor.removeXml();
2060 }
2061 if (execOrder != null) {
2062 at.setAntCmdOptions(execOrder);
2063 }
2064 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
2065 cursor.removeXml();
2066 }
2067 cursor.dispose();
2068 }
2069
2070 public void removeBuildOptionsUserDefAntTask(int i) {
2071 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2072 if (o == null) {
2073 return;
2074 }
2075 XmlCursor cursor = o.newCursor();
2076 if (cursor.toFirstChild()) {
2077 for (int j = 0; j < i; ++j) {
2078 cursor.toNextSibling();
2079 }
2080 cursor.removeXml();
2081 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2082 cursor.toParent();
2083 cursor.removeXml();
2084 }
2085 }
2086 cursor.dispose();
2087 }
2088
2089 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
2090 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2091 if (o == null) {
2092 return;
2093 }
2094 XmlCursor cursor = o.newCursor();
2095 if (cursor.toFirstChild()) {
2096 for (int j = 0; j < i; ++j) {
2097 cursor.toNextSibling();
2098 }
2099 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
2100 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2101 }
2102 cursor.dispose();
2103 }
2104
2105 public int getBuildOptionsUserDefAntTaskCount() {
2106 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2107 if (udats == null || udats.getAntTaskList() == null) {
2108 return 0;
2109 }
2110
2111 return udats.getAntTaskList().size();
2112 }
2113
2114 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
2115 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2116 if (udats == null || udats.getAntTaskList() == null) {
2117 return ;
2118 }
2119
2120 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
2121 ListIterator li = l.listIterator();
2122 int i = 0;
2123 while (li.hasNext()) {
2124 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
2125 saa[i][0] = at.getId() + "";
2126 saa[i][1] = saa[i][2] = "";
2127 if (at.getFilename() != null){
2128 saa[i][1] = at.getFilename();
2129 }
2130 if (at.getAntCmdOptions() != null) {
2131 saa[i][2] = at.getAntCmdOptions();
2132 }
2133 ++i;
2134 }
2135 }
2136 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2137 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
2138 if (opts == null) {
2139 opts = getfpdBuildOpts().addNewOptions();
2140 }
2141 OptionDocument.Option opt = opts.addNewOption();
2142 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2143 }
2144
2145 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
2146 opt.setStringValue(contents);
2147 if (buildTargets != null) {
2148 opt.setBuildTargets(buildTargets);
2149 }
2150 else {
2151 if (opt.isSetBuildTargets()) {
2152 opt.unsetBuildTargets();
2153 }
2154 }
2155
2156 if (toolChain != null && toolChain.length() > 0) {
2157 opt.setToolChainFamily(toolChain);
2158 }
2159 else {
2160 if (opt.isSetToolChainFamily()) {
2161 opt.unsetToolChainFamily();
2162 }
2163 }
2164
2165 if (tagName != null && tagName.length() > 0) {
2166 opt.setTagName(tagName);
2167 }
2168 else {
2169 if (opt.isSetTagName()) {
2170 opt.unsetTagName();
2171 }
2172 }
2173
2174 if (toolCmd != null && toolCmd.length() > 0) {
2175 opt.setToolCode(toolCmd);
2176 }
2177 else {
2178 if (opt.isSetToolCode()) {
2179 opt.unsetToolCode();
2180 }
2181 }
2182
2183
2184 if (archList != null) {
2185 opt.setSupArchList(archList);
2186 }
2187 else {
2188 if (opt.isSetSupArchList()) {
2189 opt.unsetSupArchList();
2190 }
2191 }
2192 }
2193
2194 public void removeBuildOptionsOpt(int i){
2195
2196 XmlObject o = getfpdBuildOpts().getOptions();
2197 if (o == null) {
2198 return;
2199 }
2200
2201 XmlCursor cursor = o.newCursor();
2202 if (cursor.toFirstChild()) {
2203 for (int j = 0; j < i; ++j) {
2204 cursor.toNextSibling();
2205 }
2206 cursor.removeXml();
2207 if (getBuildOptionsOptCount() == 0) {
2208 cursor.toParent();
2209 cursor.removeXml();
2210 }
2211 }
2212 cursor.dispose();
2213 }
2214
2215 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2216 XmlObject o = getfpdBuildOpts().getOptions();
2217 if (o == null) {
2218 return;
2219 }
2220
2221 XmlCursor cursor = o.newCursor();
2222 if (cursor.toFirstChild()) {
2223 for (int j = 0; j < i; ++j) {
2224 cursor.toNextSibling();
2225 }
2226 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
2227 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2228 }
2229 cursor.dispose();
2230 }
2231
2232 public int getBuildOptionsOptCount(){
2233 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2234 return 0;
2235 }
2236 return getfpdBuildOpts().getOptions().getOptionList().size();
2237 }
2238
2239 public void getBuildOptionsOpts(String[][] saa) {
2240 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2241 return ;
2242 }
2243
2244 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
2245 ListIterator li = lOpt.listIterator();
2246 int i = 0;
2247 while(li.hasNext()) {
2248 OptionDocument.Option opt = (OptionDocument.Option)li.next();
2249 if (opt.getBuildTargets() != null) {
2250 saa[i][0] = listToString(opt.getBuildTargets());
2251 }
2252 saa[i][1] = opt.getToolChainFamily();
2253 if (opt.getSupArchList() != null){
2254 saa[i][2] = listToString(opt.getSupArchList());
2255
2256 }
2257 saa[i][3] = opt.getToolCode();
2258 saa[i][4] = opt.getTagName();
2259 saa[i][5] = opt.getStringValue();
2260
2261 ++i;
2262 }
2263 }
2264
2265 public void genBuildOptionsFfs(String ffsKey, String type) {
2266 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2267 ffs.setFfsKey(ffsKey);
2268 if (type != null) {
2269 ffs.addNewSections().setEncapsulationType(type);
2270 }
2271 }
2272
2273 public void updateBuildOptionsFfsSectionsType(int i, String type) {
2274 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2275 if (type != null) {
2276 ffs.addNewSections().setEncapsulationType(type);
2277 }
2278 }
2279
2280 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2281 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2282 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2283 attrib.setName(name);
2284 attrib.setValue(value);
2285 }
2286
2287 /**update jth attribute of ith ffs.
2288 * @param i
2289 * @param j
2290 */
2291 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2292 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2293 XmlCursor cursor = ffs.newCursor();
2294 QName qAttrib = new QName(xmlNs, "Attribute");
2295 if (cursor.toChild(qAttrib)) {
2296 for (int k = 0; k < j; ++k) {
2297 cursor.toNextSibling(qAttrib);
2298 }
2299 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2300 attrib.setName(name);
2301 attrib.setValue(value);
2302 }
2303 cursor.dispose();
2304 }
2305
2306 public void removeBuildOptionsFfsAttribute(int i, int j){
2307 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2308 XmlCursor cursor = ffs.newCursor();
2309 QName qAttrib = new QName(xmlNs, "Attribute");
2310 if (cursor.toChild(qAttrib)) {
2311 for (int k = 0; k < j; ++k) {
2312 cursor.toNextSibling(qAttrib);
2313 }
2314 cursor.removeXml();
2315 }
2316 cursor.dispose();
2317 }
2318
2319 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2320 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2321 if (ffs == null) {
2322 return;
2323 }
2324 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2325
2326 if (sections == null){
2327 sections = ffs.addNewSections();
2328 }
2329 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2330 }
2331
2332 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2333 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2334 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2335 if (sections == null) {
2336 return;
2337 }
2338 XmlCursor cursor = sections.newCursor();
2339 QName qSection = new QName(xmlNs, "Section");
2340 if (cursor.toChild(qSection)) {
2341 for (int k = 0; k < j; ++k) {
2342 cursor.toNextSibling(qSection);
2343 }
2344 cursor.removeXml();
2345 }
2346 cursor.dispose();
2347 }
2348
2349 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2350 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2351 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2352 if (sections == null) {
2353 return;
2354 }
2355 XmlCursor cursor = sections.newCursor();
2356 QName qSection = new QName(xmlNs, "Section");
2357 if (cursor.toChild(qSection)) {
2358 for (int k = 0; k < j; ++k) {
2359 cursor.toNextSibling(qSection);
2360 }
2361 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2362 section.setSectionType(EfiSectionType.Enum.forString(type));
2363 }
2364 cursor.dispose();
2365 }
2366
2367 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2368 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2369 if (ffs == null) {
2370 return;
2371 }
2372 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2373
2374 if (sections == null){
2375 sections = ffs.addNewSections();
2376 }
2377 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections();
2378 sections2.setEncapsulationType(encapType);
2379 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32"));
2380 }
2381
2382 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2383 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2384 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2385 if (sections == null) {
2386 return;
2387 }
2388 XmlCursor cursor = sections.newCursor();
2389 QName qSections = new QName(xmlNs, "Sections");
2390 if (cursor.toChild(qSections)) {
2391 for (int k = 0; k < j; ++k) {
2392 cursor.toNextSibling(qSections);
2393 }
2394 cursor.removeXml();
2395 }
2396 cursor.dispose();
2397 }
2398
2399 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2400 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2401 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2402 if (sections == null) {
2403 return;
2404 }
2405 XmlCursor cursor = sections.newCursor();
2406 QName qSections = new QName(xmlNs, "Sections");
2407 if (cursor.toChild(qSections)) {
2408 for (int k = 0; k < j; ++k) {
2409 cursor.toNextSibling(qSections);
2410 }
2411 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2412 sections2.setEncapsulationType(type);
2413 }
2414 cursor.dispose();
2415 }
2416
2417 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2418 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2419 if (ffs == null) {
2420 return;
2421 }
2422 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2423 XmlCursor cursor = sections.newCursor();
2424 QName qSections = new QName(xmlNs, "Sections");
2425 if (cursor.toChild(qSections)){
2426 for (int k = 0; k < j; ++k) {
2427 cursor.toNextSibling(qSections);
2428 }
2429 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2430 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2431 }
2432 cursor.dispose();
2433 }
2434
2435 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2436 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2437 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2438 if (sections == null) {
2439 return;
2440 }
2441 XmlCursor cursor = sections.newCursor();
2442 QName qSections = new QName(xmlNs, "Sections");
2443 if (cursor.toChild(qSections)) {
2444 for (int l = 0; l < j; ++l) {
2445 cursor.toNextSibling(qSections);
2446 }
2447 if (cursor.toFirstChild()) {
2448 int m = 0;
2449 for (; m < k; ++m) {
2450 cursor.toNextSibling();
2451 }
2452 cursor.removeXml();
2453 if (m == 0) {
2454 cursor.toParent();
2455 cursor.removeXml();
2456 }
2457 }
2458 }
2459 cursor.dispose();
2460 }
2461
2462 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2463 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2464 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2465 if (sections == null) {
2466 return;
2467 }
2468 XmlCursor cursor = sections.newCursor();
2469 QName qSections = new QName(xmlNs, "Sections");
2470 if (cursor.toChild(qSections)) {
2471 for (int l = 0; l < j; ++l) {
2472 cursor.toNextSibling(qSections);
2473 }
2474 if (cursor.toFirstChild()) {
2475 for (int m = 0; m < k; ++m) {
2476 cursor.toNextSibling();
2477 }
2478 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2479 section.setSectionType(EfiSectionType.Enum.forString(type));
2480 }
2481 }
2482 cursor.dispose();
2483 }
2484
2485 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2486 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2487 if (ffs == null) {
2488 return;
2489 }
2490 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2491 XmlCursor cursor = sections.newCursor();
2492 QName qSections = new QName(xmlNs, "Sections");
2493 if (cursor.toChild(qSections)){
2494 for (int k = 0; k < j; ++k) {
2495 cursor.toNextSibling(qSections);
2496 }
2497 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2498 if (sections2.getSectionList() == null){
2499 cursor.dispose();
2500 return;
2501 }
2502 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2503 while(li.hasNext()) {
2504 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2505 // if (section.isSetSectionType()) {
2506 al.add(section.getSectionType()+"");
2507 // }
2508
2509 }
2510 }
2511 cursor.dispose();
2512
2513 }
2514
2515 public int getBuildOptionsFfsCount(){
2516 if (getfpdBuildOpts().getFfsList() == null) {
2517 return 0;
2518 }
2519 return getfpdBuildOpts().getFfsList().size();
2520 }
2521
2522 public void getBuildOptionsFfsKey(String[][] saa) {
2523 if (getfpdBuildOpts().getFfsList() == null) {
2524 return;
2525 }
2526 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2527 int i = 0;
2528 while(li.hasNext()){
2529 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2530 saa[i][0] = ffs.getFfsKey();
2531 ++i;
2532 }
2533 }
2534
2535 public void updateBuildOptionsFfsKey(int i, String key) {
2536 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2537 ffs.setFfsKey(key);
2538 }
2539
2540 /**Get ith FFS key and contents.
2541 * @param saa
2542 */
2543 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2544 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2545
2546 if (ffs != null) {
2547
2548 sa[0] = ffs.getFfsKey();
2549 if (ffs.getSections() != null) {
2550 if(ffs.getSections().getEncapsulationType() != null){
2551 sa[1] = ffs.getSections().getEncapsulationType();
2552 }
2553 if (ffs.getSections().getSectionList() != null){
2554 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2555 while (li.hasNext()) {
2556 firstLevelSection.add(li.next().getSectionType()+"");
2557 }
2558 }
2559 if (ffs.getSections().getSectionsList() != null) {
2560 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2561 while(li.hasNext()) {
2562 firstLevelSections.add(li.next().getEncapsulationType());
2563 }
2564 }
2565 }
2566 if (ffs.getAttributeList() != null) {
2567 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2568 while(li.hasNext()) {
2569 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2570 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2571 }
2572
2573 }
2574 }
2575
2576
2577 }
2578
2579 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2580 XmlObject o = getfpdBuildOpts();
2581 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2582
2583 XmlCursor cursor = o.newCursor();
2584 QName qFfs = new QName(xmlNs, "Ffs");
2585 if (cursor.toChild(qFfs)) {
2586 for (int j = 0; j < i; ++j) {
2587 cursor.toNextSibling(qFfs);
2588 }
2589 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2590 }
2591 cursor.dispose();
2592 return ffs;
2593 }
2594
2595 public void removeBuildOptionsFfs(int i) {
2596 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2597 if (ffs == null){
2598 return;
2599 }
2600
2601 XmlCursor cursor = ffs.newCursor();
2602 cursor.removeXml();
2603 cursor.dispose();
2604 }
2605
2606
2607
2608 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2609 if (fpdPlatformDefs == null){
2610 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2611 }
2612 return fpdPlatformDefs;
2613 }
2614
2615 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2616 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2617 return;
2618 }
2619 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2620 while(li.hasNext()) {
2621 archs.add(li.next());
2622 }
2623 }
2624
2625 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2626 if (archs != null) {
2627 getfpdPlatformDefs().setSupportedArchitectures(archs);
2628 }
2629 // else {
2630 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2631 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2632 // cursor.removeXml();
2633 // }
2634 // cursor.dispose();
2635 // }
2636 }
2637
2638 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2639 if (getfpdPlatformDefs().getBuildTargets() == null) {
2640 return;
2641 }
2642 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2643 while(li.hasNext()) {
2644 targets.add(li.next());
2645 }
2646 }
2647
2648 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2649 getfpdPlatformDefs().setBuildTargets(targets);
2650 }
2651
2652 public void genPlatformDefsSkuInfo(String id, String name) {
2653 SkuInfoDocument.SkuInfo skuInfo = null;
2654 if (getfpdPlatformDefs().getSkuInfo() == null) {
2655 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2656 }
2657 skuInfo = getfpdPlatformDefs().getSkuInfo();
2658 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2659 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2660 skuName.setSkuID(new BigInteger("0"));
2661 skuName.setStringValue("DEFAULT");
2662 }
2663 if (id.equals("0")) {
2664 return;
2665 }
2666 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2667 skuName.setSkuID(new BigInteger(id));
2668 skuName.setStringValue(name);
2669 }
2670
2671 public int getPlatformDefsSkuInfoCount(){
2672 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2673 return 0;
2674 }
2675 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2676 }
2677
2678 public void getPlatformDefsSkuInfos(String[][] saa){
2679 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2680 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2681 removeElement(getfpdDynPcdBuildDefs());
2682 fpdDynPcdBuildDefs = null;
2683 }
2684 return ;
2685 }
2686
2687 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2688 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2689 int i = 0;
2690 while(li.hasNext()) {
2691 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2692 saa[i][0] = sku.getSkuID()+"";
2693 saa[i][1] = sku.getStringValue();
2694 ++i;
2695 }
2696 }
2697
2698 public void removePlatformDefsSkuInfo(int i) {
2699 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2700 if (skuInfo == null || i == 0) {
2701 return ;
2702 }
2703
2704 XmlCursor cursor = skuInfo.newCursor();
2705 if (cursor.toFirstChild()) {
2706 for (int j = 0; j < i; ++j) {
2707 cursor.toNextSibling();
2708 }
2709 cursor.removeXml();
2710 }
2711 cursor.dispose();
2712 }
2713
2714 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2715 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2716 if (skuInfo == null || i == 0) {
2717 return ;
2718 }
2719
2720 XmlCursor cursor = skuInfo.newCursor();
2721 if (cursor.toFirstChild()) {
2722 for (int j = 0; j < i; ++j) {
2723 cursor.toNextSibling();
2724 }
2725 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2726 sku.setSkuID(new BigInteger(id));
2727 sku.setStringValue(name);
2728 }
2729 cursor.dispose();
2730 }
2731
2732 public String getPlatformDefsInterDir(){
2733 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2734 return null;
2735 }
2736 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2737 }
2738
2739 public void setPlatformDefsInterDir(String interDir){
2740 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2741 }
2742
2743 public String getPlatformDefsOutputDir() {
2744 return getfpdPlatformDefs().getOutputDirectory();
2745 }
2746
2747 public void setPlatformDefsOutputDir(String outputDir) {
2748 if (outputDir != null && outputDir.length() > 0) {
2749 getfpdPlatformDefs().setOutputDirectory(outputDir);
2750 }
2751 else{
2752 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2753 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2754 cursor.removeXml();
2755 }
2756 cursor.dispose();
2757 }
2758 }
2759
2760 public FlashDocument.Flash getfpdFlash() {
2761 if (fpdFlash == null) {
2762 fpdFlash = fpdRoot.addNewFlash();
2763 }
2764 return fpdFlash;
2765 }
2766
2767 public void genFlashDefinitionFile(String file) {
2768 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2769 if (fdf == null) {
2770 fdf = getfpdFlash().addNewFlashDefinitionFile();
2771 }
2772
2773 fdf.setStringValue(file);
2774 }
2775
2776 public String getFlashDefinitionFile() {
2777 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2778 if (fdf == null) {
2779 return "";
2780 }
2781
2782 return fdf.getStringValue();
2783 }
2784
2785 public void genFvImagesNameValue(String name, String value) {
2786
2787 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2788 if (fi == null) {
2789 fi = getfpdFlash().addNewFvImages();
2790 }
2791
2792 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2793 nv.setName(name);
2794 nv.setValue(value);
2795 }
2796
2797 public void removeFvImagesNameValue(int i){
2798
2799 XmlObject o = getfpdFlash().getFvImages();
2800 if (o == null) {
2801 return;
2802 }
2803
2804 QName qNameValue = new QName(xmlNs, "NameValue");
2805 XmlCursor cursor = o.newCursor();
2806 if (cursor.toChild(qNameValue)) {
2807 for (int j = 0; j < i; ++j) {
2808 cursor.toNextSibling(qNameValue);
2809 }
2810 cursor.removeXml();
2811 }
2812 cursor.dispose();
2813 }
2814
2815 public void updateFvImagesNameValue(int i, String name, String value){
2816
2817 XmlObject o = getfpdFlash().getFvImages();
2818 if (o == null) {
2819 return;
2820 }
2821
2822 QName qNameValue = new QName(xmlNs, "NameValue");
2823 XmlCursor cursor = o.newCursor();
2824 if (cursor.toChild(qNameValue)) {
2825 for (int j = 0; j < i; ++j) {
2826 cursor.toNextSibling(qNameValue);
2827 }
2828 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2829 nv.setName(name);
2830 nv.setValue(value);
2831 }
2832 cursor.dispose();
2833 }
2834
2835 public int getFvImagesNameValueCount() {
2836
2837 FvImagesDocument.FvImages fi = null;
2838 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2839 return 0;
2840 }
2841 return fi.getNameValueList().size();
2842 }
2843
2844 public void getFvImagesNameValues(String[][] nv) {
2845
2846 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2847 if (fi == null){
2848 return;
2849 }
2850 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2851 int i = 0;
2852 ListIterator li = l.listIterator();
2853 while (li.hasNext()) {
2854 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2855 .next();
2856 nv[i][0] = e.getName();
2857 nv[i][1] = e.getValue();
2858
2859 i++;
2860 }
2861 }
2862
2863 public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {
2864 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2865 if (fis == null || fis.getFvImageList() == null) {
2866 return;
2867 }
2868
2869 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2870 while (li.hasNext()) {
2871 FvImagesDocument.FvImages.FvImage fi = li.next();
2872 if (fi.getType().toString().equals("ImageName")) {
2873 vImageNames.addAll(fi.getFvImageNamesList());
2874 return;
2875 }
2876 }
2877 }
2878
2879 public void addFvImageFvImageNames (String[] fvNames) {
2880 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2881 if (fis == null || fis.getFvImageList() == null) {
2882 genFvImagesFvImage (fvNames, "ImageName", null);
2883 return;
2884 }
2885
2886 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2887 while (li.hasNext()) {
2888 FvImagesDocument.FvImages.FvImage fi = li.next();
2889 if (fi.getType().toString().equals("ImageName")) {
2890 addFvImageNamesInFvImage (fi, fvNames);
2891 return;
2892 }
2893 }
2894 genFvImagesFvImage (fvNames, "ImageName", null);
2895 }
2896
2897 public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) {
2898
2899 for (int i = 0; i < fvNames.length; ++i) {
2900 fi.addFvImageNames(fvNames[i]);
2901 }
2902 }
2903
2904 public void addFvImageNamesInFvImage (int i, String[] fvNames) {
2905 XmlObject o = getfpdFlash().getFvImages();
2906 if (o == null) {
2907 return;
2908 }
2909 XmlCursor cursor = o.newCursor();
2910 QName qFvImage = new QName(xmlNs, "FvImage");
2911 if (cursor.toChild(qFvImage)) {
2912 for (int j = 0; j < i; ++j) {
2913 cursor.toNextSibling(qFvImage);
2914 }
2915 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2916 addFvImageNamesInFvImage(fi, fvNames);
2917 }
2918 cursor.dispose();
2919 }
2920
2921 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2922
2923 FvImagesDocument.FvImages fis = null;
2924 if ((fis = getfpdFlash().getFvImages()) == null) {
2925 fis = getfpdFlash().addNewFvImages();
2926 }
2927
2928 //
2929 //gen FvImage with FvImageNames array
2930 //
2931 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2932 for (int i = 0; i < names.length; ++i) {
2933 fi.addFvImageNames(names[i]);
2934 }
2935 fi.setType(FvImageTypes.Enum.forString(types));
2936 if (options != null){
2937 setFvImagesFvImageFvImageOptions(options, fi);
2938 }
2939 }
2940
2941 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2942 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
2943 if (fio == null){
2944 fio = fi.addNewFvImageOptions();
2945 }
2946
2947 Set<String> key = options.keySet();
2948 Iterator<String> i = key.iterator();
2949 while (i.hasNext()) {
2950
2951 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
2952 String k = (String)i.next();
2953
2954 nv.setName(k);
2955 nv.setValue((String)options.get(k));
2956
2957 }
2958
2959 }
2960
2961
2962 public void removeFvImagesFvImage(int i) {
2963
2964 XmlObject o = getfpdFlash().getFvImages();
2965 if (o == null) {
2966 return;
2967 }
2968
2969 QName qFvImage = new QName(xmlNs, "FvImage");
2970 XmlCursor cursor = o.newCursor();
2971 if (cursor.toChild(qFvImage)) {
2972 for (int j = 0; j < i; ++j) {
2973 cursor.toNextSibling(qFvImage);
2974 }
2975 cursor.removeXml();
2976 }
2977 cursor.dispose();
2978 }
2979
2980 /**
2981 * @param oldFvName
2982 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2983 */
2984 public void updateFvImageNameAll (String oldFvName, String newFvName) {
2985 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2986 return;
2987 }
2988 ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();
2989 while (li.hasNext()) {
2990 FvImagesDocument.FvImages.FvImage fi = li.next();
2991 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
2992 if (fi.getFvImageNamesList().size() == 0) {
2993 li.remove();
2994 }
2995 }
2996 }
2997
2998 public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) {
2999 XmlObject o = getfpdFlash().getFvImages();
3000 if (o == null) {
3001 return;
3002 }
3003 XmlCursor cursor = o.newCursor();
3004 QName qFvImage = new QName(xmlNs, "FvImage");
3005 if (cursor.toChild(qFvImage)) {
3006 for (int j = 0; j < i; ++j) {
3007 cursor.toNextSibling(qFvImage);
3008 }
3009 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3010 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
3011 }
3012 cursor.dispose();
3013 }
3014 /**
3015 * @param fi
3016 * @param oldFvName The FV Name to be replaced.
3017 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3018 */
3019 public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {
3020 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3021 XmlCursor cursor = fi.newCursor();
3022
3023 if (cursor.toChild(qFvImageNames)) {
3024 do {
3025 String xmlValue = cursor.getTextValue();
3026 if (xmlValue.equals(oldFvName)){
3027 if (newFvName != null) {
3028 cursor.setTextValue(newFvName);
3029 }
3030 else {
3031 cursor.removeXml();
3032 }
3033 }
3034 }while (cursor.toNextSibling(qFvImageNames));
3035 }
3036
3037 cursor.dispose();
3038 }
3039
3040 /**update the Type attribute of ith FvImage with new type.
3041 * @param i
3042 * @param type
3043 */
3044 public void updateFvImagesFvImageType (int i, String type) {
3045 XmlObject o = getfpdFlash().getFvImages();
3046 if (o == null) {
3047 return;
3048 }
3049 XmlCursor cursor = o.newCursor();
3050 QName qFvImage = new QName(xmlNs, "FvImage");
3051 if (cursor.toChild(qFvImage)) {
3052 for (int j = 0; j < i; ++j) {
3053 cursor.toNextSibling(qFvImage);
3054 }
3055 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3056 fi.setType(FvImageTypes.Enum.forString(type));
3057 }
3058 cursor.dispose();
3059 }
3060
3061 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
3062
3063 XmlObject o = getfpdFlash().getFvImages();
3064 if (o == null) {
3065 return;
3066 }
3067 XmlCursor cursor = o.newCursor();
3068 QName qFvImage = new QName(xmlNs, "FvImage");
3069 if (cursor.toChild(qFvImage)) {
3070 for (int j = 0; j < i; ++j) {
3071 cursor.toNextSibling(qFvImage);
3072 }
3073 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3074 fi.setType(FvImageTypes.Enum.forString(types));
3075
3076 //
3077 // remove old FvImageNames before adding new ones
3078 //
3079 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3080 cursor.toChild(qFvImageNames);
3081 cursor.removeXml();
3082 while (cursor.toNextSibling(qFvImageNames)) {
3083 cursor.removeXml();
3084 }
3085
3086 for (int k = 0; k < names.length; ++k) {
3087 fi.addFvImageNames(names[k]);
3088 }
3089 //
3090 // remove old FvImageOptions before adding new options
3091 //
3092 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
3093 cursor.toNextSibling(qFvImageOptions);
3094 cursor.removeXml();
3095
3096 setFvImagesFvImageFvImageOptions(options, fi);
3097 }
3098 cursor.dispose();
3099 }
3100
3101 public int getFvImagesFvImageCount(String type) {
3102
3103 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3104 return 0;
3105 }
3106 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3107 ListIterator li = l.listIterator();
3108 int i = 0;
3109 while(li.hasNext()) {
3110 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3111 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3112 continue;
3113 }
3114
3115 ++i;
3116 }
3117
3118 return i;
3119 }
3120
3121 public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {
3122 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();
3123 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3124 return vFvImage;
3125 }
3126 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3127 ListIterator li = l.listIterator();
3128 while(li.hasNext()) {
3129 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3130 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3131 continue;
3132 }
3133 if (fi.getFvImageNamesList().contains(fvName)) {
3134 vFvImage.add(fi);
3135 }
3136 }
3137
3138 return vFvImage;
3139 }
3140 /**
3141 * @param saa
3142 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3143 */
3144 public void getFvImagesFvImages(String[][] saa, String type) {
3145
3146 if (getfpdFlash().getFvImages() == null) {
3147 return;
3148 }
3149 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3150 if (l == null) {
3151 return;
3152 }
3153 ListIterator li = l.listIterator();
3154 int i = 0;
3155 while(li.hasNext()) {
3156 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3157 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3158 continue;
3159 }
3160 //
3161 // get FvImageNames array, space separated
3162 //
3163 List<String> lfn = fi.getFvImageNamesList();
3164 ListIterator lfni = lfn.listIterator();
3165 saa[i][0] = " ";
3166 while (lfni.hasNext()) {
3167 saa[i][0] += (String)lfni.next();
3168 saa[i][0] += " ";
3169 }
3170 saa[i][0] = saa[i][0].trim();
3171
3172 saa[i][1] = fi.getType()+"";
3173
3174 ++i;
3175 }
3176 }
3177
3178 public void removeFvImageNameValue (int i, String attributeName) {
3179 XmlObject o = getfpdFlash().getFvImages();
3180 if (o == null) {
3181 return;
3182 }
3183 XmlCursor cursor = o.newCursor();
3184 QName qFvImage = new QName(xmlNs, "FvImage");
3185 if (cursor.toChild(qFvImage)) {
3186 for (int j = 0; j < i; ++j) {
3187 cursor.toNextSibling(qFvImage);
3188 }
3189 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3190 removeFvImageNameValue (fi, attributeName);
3191 }
3192 cursor.dispose();
3193 }
3194 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3195 * @param fi
3196 * @param attributeName
3197 */
3198 public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) {
3199 if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) {
3200 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3201 while (li.hasNext()) {
3202 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3203 if (nv.getName().equals(attributeName)) {
3204 li.remove();
3205 }
3206 }
3207 }
3208 }
3209
3210 public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) {
3211 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName(fvName, type);
3212 for (int i = 0; i < vFvImage.size(); ++i) {
3213 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3214 removeFvImageNameValue (fi, optName);
3215 }
3216 }
3217
3218 /**Add name-value pair to FvImage element with type.
3219 * @param fvName FV name to add name-value pair.
3220 * @param type FvImage attribute.
3221 * @param name
3222 * @param value
3223 */
3224 public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {
3225 boolean fvImageExists = false;
3226 if (getfpdFlash().getFvImages() == null) {
3227 return;
3228 }
3229 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3230 if (l == null) {
3231 return;
3232 }
3233 ListIterator li = l.listIterator();
3234 while(li.hasNext()) {
3235 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3236 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3237 continue;
3238 }
3239 if (!fi.getFvImageNamesList().contains(fvName)) {
3240 continue;
3241 }
3242 fvImageExists = true;
3243 setFvImagesFvImageNameValue (fi, name, value, null);
3244 }
3245
3246 if (!fvImageExists) {
3247 HashMap<String, String> map = new HashMap<String, String>();
3248 map.put(name, value);
3249 genFvImagesFvImage(new String[]{fvName}, type, map);
3250 }
3251 }
3252
3253 /**Add to all FvImage elements with type, the name-value pair.
3254 * @param type
3255 * @param name
3256 * @param value
3257 */
3258 public void setTypedFvImageNameValue (String type, String name, String value) {
3259 if (getfpdFlash().getFvImages() == null) {
3260 return;
3261 }
3262 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3263 if (l == null) {
3264 return;
3265 }
3266 ListIterator li = l.listIterator();
3267 while(li.hasNext()) {
3268 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3269 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3270 continue;
3271 }
3272 setFvImagesFvImageNameValue (fi, name, value, null);
3273 }
3274
3275 }
3276
3277 public void setFvImagesFvImageNameValue (int i, String name, String value) {
3278 XmlObject o = getfpdFlash().getFvImages();
3279 if (o == null) {
3280 return;
3281 }
3282 XmlCursor cursor = o.newCursor();
3283 QName qFvImage = new QName(xmlNs, "FvImage");
3284 if (cursor.toChild(qFvImage)) {
3285 for (int j = 0; j < i; ++j) {
3286 cursor.toNextSibling(qFvImage);
3287 }
3288 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3289 setFvImagesFvImageNameValue (fi, name, value, null);
3290 }
3291 cursor.dispose();
3292 }
3293
3294 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3295 * @param fi
3296 * @param name
3297 * @param value
3298 * @param newName
3299 */
3300 public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {
3301 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3302 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();
3303 nv.setName(name);
3304 nv.setValue(value);
3305 if (newName != null) {
3306 nv.setName(newName);
3307 }
3308 return;
3309 }
3310
3311 XmlCursor cursor = fi.getFvImageOptions().newCursor();
3312 if (cursor.toFirstChild()) {
3313 do {
3314 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();
3315 if (nv.getName().equals(name)) {
3316 nv.setValue(value);
3317 if (newName != null) {
3318 nv.setName(newName);
3319 }
3320 cursor.dispose();
3321 return;
3322 }
3323 }while (cursor.toNextSibling());
3324 }
3325
3326 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();
3327 nv.setName(name);
3328 nv.setValue(value);
3329 if (newName != null) {
3330 nv.setName(newName);
3331 }
3332 cursor.dispose();
3333 }
3334
3335 public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {
3336 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");
3337 for (int i = 0; i < vFvImage.size(); ++i) {
3338 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3339 if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3340 continue;
3341 }
3342
3343 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()
3344 .getNameValueList()
3345 .listIterator();
3346 while (li.hasNext()) {
3347 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3348 m.put(nv.getName(), nv.getValue());
3349 }
3350 }
3351 }
3352
3353 public int getFvImagePosInFvImages (String fvNameList, String type) {
3354 XmlObject o = getfpdFlash().getFvImages();
3355 if (o == null) {
3356 return -1;
3357 }
3358
3359 int pos = -1;
3360 String[] fvNameArray = fvNameList.trim().split(" ");
3361 Vector<String> vFvNames = new Vector<String>();
3362
3363
3364 XmlCursor cursor = o.newCursor();
3365 QName qFvImage = new QName(xmlNs, "FvImage");
3366 if (cursor.toChild(qFvImage)) {
3367 do {
3368 pos++;
3369 vFvNames.removeAllElements();
3370 for (int i = 0; i < fvNameArray.length; ++i) {
3371 vFvNames.add(fvNameArray[i]);
3372 }
3373 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3374 if (!fi.getType().toString().equals(type)) {
3375 continue;
3376 }
3377 if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) {
3378 continue;
3379 }
3380 ListIterator<String> li = fi.getFvImageNamesList().listIterator();
3381 while (li.hasNext()) {
3382 String name = li.next();
3383 vFvNames.remove(name);
3384 }
3385 if (vFvNames.size() == 0) {
3386 cursor.dispose();
3387 return pos;
3388 }
3389
3390 }while (cursor.toNextSibling(qFvImage));
3391
3392 }
3393 cursor.dispose();
3394 return -1;
3395 }
3396 /**Get FvImage Options for FvImage i
3397 * @param i the ith FvImage
3398 */
3399 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
3400 XmlObject o = getfpdFlash().getFvImages();
3401 if (o == null) {
3402 return;
3403 }
3404 XmlCursor cursor = o.newCursor();
3405 QName qFvImage = new QName(xmlNs, "FvImage");
3406 if (cursor.toChild(qFvImage)) {
3407 for (int j = 0; j < i; ++j) {
3408 cursor.toNextSibling(qFvImage);
3409 }
3410 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3411 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
3412 cursor.dispose();
3413 return;
3414 }
3415 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3416 while(li.hasNext()){
3417 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3418 m.put(nv.getName(), nv.getValue());
3419 }
3420 }
3421 cursor.dispose();
3422 }
3423
3424 /**
3425 Get platform header element
3426 @return PlatformHeaderDocument.PlatformHeader
3427 **/
3428 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
3429 if (fpdHdr == null) {
3430 fpdHdr = fpdRoot.addNewPlatformHeader();
3431 }
3432
3433 return fpdHdr;
3434 }
3435
3436 public String getFpdHdrPlatformName() {
3437 return getFpdHdr().getPlatformName();
3438 }
3439
3440 public String getFpdHdrGuidValue() {
3441 return getFpdHdr().getGuidValue();
3442 }
3443
3444 public String getFpdHdrVer() {
3445 return getFpdHdr().getVersion();
3446 }
3447
3448 public String getFpdHdrAbs() {
3449 return getFpdHdr().getAbstract();
3450 }
3451
3452 public String getFpdHdrDescription() {
3453 return getFpdHdr().getDescription();
3454 }
3455
3456 public String getFpdHdrCopyright() {
3457 return getFpdHdr().getCopyright();
3458 }
3459
3460 public String getFpdHdrLicense() {
3461 LicenseDocument.License l = getFpdHdr().getLicense();
3462 if (l == null) {
3463 return null;
3464 }
3465 return l.getStringValue();
3466 }
3467
3468 public String getFpdHdrUrl() {
3469 LicenseDocument.License l = getFpdHdr().getLicense();
3470 if (l == null) {
3471 return null;
3472 }
3473 return l.getURL();
3474 }
3475
3476 public String getFpdHdrSpec() {
3477
3478 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3479 // return getFpdHdr().getSpecification();
3480 }
3481
3482 public void setFpdHdrPlatformName(String name){
3483 getFpdHdr().setPlatformName(name);
3484 }
3485
3486 public void setFpdHdrGuidValue(String guid){
3487 getFpdHdr().setGuidValue(guid);
3488 }
3489
3490 public void setFpdHdrVer(String v){
3491 getFpdHdr().setVersion(v);
3492 }
3493
3494 public void setFpdHdrAbs(String abs) {
3495 getFpdHdr().setAbstract(abs);
3496 }
3497
3498 public void setFpdHdrDescription(String desc){
3499 getFpdHdr().setDescription(desc);
3500 }
3501
3502 public void setFpdHdrCopyright(String cr) {
3503 getFpdHdr().setCopyright(cr);
3504 }
3505
3506 public void setFpdHdrLicense(String license){
3507 LicenseDocument.License l = getFpdHdr().getLicense();
3508 if (l == null) {
3509 getFpdHdr().addNewLicense().setStringValue(license);
3510 }
3511 else {
3512 l.setStringValue(license);
3513 }
3514 }
3515
3516 public void setFpdHdrUrl(String url){
3517 LicenseDocument.License l = getFpdHdr().getLicense();
3518
3519 l.setURL(url);
3520
3521 }
3522
3523 public void setFpdHdrSpec(String s){
3524 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3525 getFpdHdr().setSpecification(s);
3526 }
3527 /**
3528 Save the processed xml contents to file
3529
3530 @param fpdFile The file to save xml contents
3531 @throws IOException Exceptions during file operation
3532 **/
3533 public void saveAs(File fpdFile) throws IOException {
3534
3535 XmlOptions options = new XmlOptions();
3536
3537 options.setCharacterEncoding("UTF-8");
3538 options.setSavePrettyPrint();
3539 options.setSavePrettyPrintIndent(2);
3540 try {
3541 fpdd.save(fpdFile, options);
3542 } catch (IOException e) {
3543 e.printStackTrace();
3544 }
3545
3546 }
3547
3548 private String listToString(List l) {
3549 if (l == null) {
3550 return null;
3551 }
3552 String s = " ";
3553 ListIterator li = l.listIterator();
3554 while(li.hasNext()) {
3555 s += li.next();
3556 s += " ";
3557 }
3558 return s.trim();
3559 }
3560
3561 private void removeElement(XmlObject o) {
3562 XmlCursor cursor = o.newCursor();
3563 cursor.removeXml();
3564 cursor.dispose();
3565 }
3566 }
3567
3568 class PcdItemTypeConflictException extends Exception {
3569
3570 /**
3571 *
3572 */
3573 private static final long serialVersionUID = 1L;
3574 private String details = null;
3575
3576 PcdItemTypeConflictException(String pcdName, String info){
3577 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
3578 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();
3579 }
3580
3581 public String getMessage() {
3582 return details;
3583 }
3584 }
3585
3586 class PcdDeclNotFound extends Exception {
3587
3588 /**
3589 *
3590 */
3591 private static final long serialVersionUID = 1L;
3592 private String details = null;
3593
3594 PcdDeclNotFound(String info) {
3595 details = "PcdDeclNotFound: " + info;
3596 }
3597
3598 public String getMessage() {
3599 return details;
3600 }
3601 }
3602
3603 class PcdValueMalFormed extends Exception {
3604
3605 /**
3606 *
3607 */
3608 private static final long serialVersionUID = 1L;
3609 private String details = null;
3610
3611 PcdValueMalFormed(String info) {
3612 details = "PcdValueMalFormed: " + info;
3613 }
3614
3615 public String getMessage() {
3616 return details;
3617 }
3618 }