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