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