add multi-source pcd check before adding/deleting lib instance for ModuleSA in platform.
[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 static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
74
75 private PlatformSurfaceAreaDocument fpdd = null;
76
77 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
78
79 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
80
81 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
82
83 private FlashDocument.Flash fpdFlash = null;
84
85 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
86
87 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
88
89 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
90
91 private HashMap<String, ArrayList<String>> dynPcdMap = null;
92
93 private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();
94
95 private String itemType (String pcdInfo) {
96
97 return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1);
98 }
99
100 /**
101 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
102 */
103 public void initDynPcdMap() {
104 if (dynPcdMap == null) {
105 dynPcdMap = new HashMap<String, ArrayList<String>>();
106 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
107 if (l == null) {
108 removeElement(getfpdFrameworkModules());
109 fpdFrameworkModules = null;
110 return;
111 }
112 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
113 while (li.hasNext()) {
114 ModuleSADocument.ModuleSA moduleSa = li.next();
115 if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {
116 continue;
117 }
118 String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() +
119 " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
120 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();
121 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
122 while (lpi.hasNext()) {
123 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
124 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
125 if (dynPcdMap.get(pcdKey) == null) {
126 ArrayList<String> al = new ArrayList<String>();
127 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
128 dynPcdMap.put(pcdKey, al);
129 }
130 else{
131 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
132 }
133 }
134 }
135 }
136 }
137
138 public ArrayList<String> getDynPcdMapValue(String key) {
139 return dynPcdMap.get(key);
140 }
141 /**
142 Constructor to create a new spd file
143 **/
144 public FpdFileContents() {
145
146 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
147 fpdRoot = fpdd.addNewPlatformSurfaceArea();
148
149 }
150
151 /**
152 Constructor for existing document object
153 @param psa
154 **/
155 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
156 fpdRoot = fpd;
157 fpdHdr = fpdRoot.getPlatformHeader();
158 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
159 fpdBuildOpts = fpdRoot.getBuildOptions();
160 fpdFrameworkModules = fpdRoot.getFrameworkModules();
161 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
162 fpdFlash = fpdRoot.getFlash();
163 }
164
165 /**
166 Constructor based on an existing spd file
167
168 @param f Existing spd file
169 **/
170 public FpdFileContents(File f) {
171 try {
172 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
173 fpdRoot = fpdd.getPlatformSurfaceArea();
174 } catch (Exception e) {
175 System.out.println(e.toString());
176 }
177 }
178
179 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
180 if (fpdDynPcdBuildDefs == null){
181 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
182 }
183 return fpdDynPcdBuildDefs;
184 }
185
186 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
187 if (fpdFrameworkModules == null){
188 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
189 }
190 return fpdFrameworkModules;
191 }
192
193 public void getFrameworkModuleGuid (String fvName, Vector<String> vGuid) {
194 if (getFrameworkModulesCount() == 0){
195 return;
196 }
197
198 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
199 while(li.hasNext()) {
200 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
201 if (moduleSa.getModuleSaBuildOptions() == null) {
202 continue;
203 }
204 String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();
205 if (fvBinding == null) {
206 continue;
207 }
208
209 String[] fvNames = fvBinding.split(" ");
210 for (int i = 0; i < fvNames.length; ++i) {
211 if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {
212 vGuid.add(moduleSa.getModuleGuid());
213 break;
214 }
215 }
216 }
217 }
218
219 public int getFrameworkModulesCount() {
220 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
221 removeElement(getfpdFrameworkModules());
222 fpdFrameworkModules = null;
223 return 0;
224 }
225 return getfpdFrameworkModules().getModuleSAList().size();
226 }
227
228 public void getFrameworkModulesInfo(String[][] saa) {
229 if (getFrameworkModulesCount() == 0){
230 return;
231 }
232
233 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
234 int i = 0;
235 while(li.hasNext()) {
236 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
237 saa[i][0] = moduleSa.getModuleGuid();
238 saa[i][1] = moduleSa.getModuleVersion();
239
240 saa[i][2] = moduleSa.getPackageGuid();
241 saa[i][3] = moduleSa.getPackageVersion();
242 saa[i][4] = listToString(moduleSa.getSupArchList());
243 ++i;
244 }
245 }
246
247 public void getFrameworkModuleInfo(int i, String[] sa) {
248 ModuleSADocument.ModuleSA msa = getModuleSA(i);
249 if (msa == null) {
250 return;
251 }
252 sa[0] = msa.getModuleGuid();
253 sa[1] = msa.getModuleVersion();
254 sa[2] = msa.getPackageGuid();
255 sa[3] = msa.getPackageVersion();
256 sa[4] = listToString(msa.getSupArchList());
257 }
258
259 public ModuleSADocument.ModuleSA getModuleSA(String key) {
260
261 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
262 removeElement(getfpdFrameworkModules());
263 fpdFrameworkModules = null;
264 return null;
265 }
266 String[] s = key.split(" ");
267 String archsInKey = "";
268 if (s.length > 4) {
269 for (int i = 4; i < s.length; ++i) {
270 archsInKey += s[i];
271 archsInKey += " ";
272 }
273 archsInKey = archsInKey.trim();
274 }
275
276 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
277 while(li.hasNext()) {
278 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
279 if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {
280 if (moduleSa.getModuleVersion() != null) {
281 if (!moduleSa.getModuleVersion().equals(s[1])) {
282 continue;
283 }
284 }
285 if (moduleSa.getPackageVersion() != null) {
286 if (!moduleSa.getPackageVersion().equals(s[3])) {
287 continue;
288 }
289 }
290 //ToDo add arch check .
291 if (moduleSa.getSupArchList() != null) {
292 if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) {
293 return moduleSa;
294 }
295 }
296 else {
297 if (archsInKey.length() == 0) {
298 return moduleSa;
299 }
300 }
301 }
302 }
303 return null;
304 }
305
306 private ModuleSADocument.ModuleSA getModuleSA(int i) {
307 ModuleSADocument.ModuleSA moduleSa = null;
308 if (fpdRoot.getFrameworkModules() == null) {
309 return null;
310 }
311 XmlCursor cursor = fpdRoot.getFrameworkModules().newCursor();
312 if (cursor.toFirstChild()) {
313 for (int j = 0; j < i; ++j) {
314 cursor.toNextSibling();
315 }
316 moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
317 }
318 cursor.dispose();
319 return moduleSa;
320 }
321
322 public void removeModuleSA(int i) {
323 XmlObject o = fpdRoot.getFrameworkModules();
324 if (o == null) {
325 return;
326 }
327
328 XmlCursor cursor = o.newCursor();
329 if (cursor.toFirstChild()) {
330 for (int j = 0; j < i; ++j) {
331 cursor.toNextSibling();
332 }
333 //
334 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
335 //
336 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
337 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
338 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
339 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
340 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {
341 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();
342 while(li.hasNext()) {
343 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
344 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);
345 }
346 }
347
348 cursor.push();
349 while (cursor.hasPrevToken()) {
350 cursor.toPrevToken();
351 if (!cursor.isText()) {
352 break;
353 }
354 String s = cursor.getTextValue();
355 if (s.matches(regExpNewLineAndSpaces)) {
356 continue;
357 }
358 }
359
360 if (cursor.isComment()) {
361 cursor.removeXml();
362 }
363
364 cursor.pop();
365 cursor.removeXml();
366 if (getFrameworkModulesCount() == 0) {
367 cursor.toParent();
368 cursor.removeXml();
369 }
370 }
371 cursor.dispose();
372 }
373
374 public boolean adjustPcd (int seqModuleSa) throws Exception {
375 boolean dataModified = false;
376 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
377 int pcdCount = getPcdDataCount(seqModuleSa);
378 String[][] saaModuleSaPcd = new String[pcdCount][7];
379 getPcdData(seqModuleSa, saaModuleSaPcd);
380 String mg = moduleSa.getModuleGuid();
381 String mv = moduleSa.getModuleVersion();
382 String pg = moduleSa.getPackageGuid();
383 String pv = moduleSa.getPackageVersion();
384 String arch = listToString(moduleSa.getSupArchList());
385 //
386 // delete pcd in ModuleSA but not in MSA files any longer.
387 //
388 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
389 int libCount = getLibraryInstancesCount(moduleKey);
390 String[][] saaLib = new String[libCount][5];
391 getLibraryInstances(moduleKey, saaLib);
392 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
393 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
394 //
395 // create vector for module & library instance MIs.
396 //
397 vMi.add(mi);
398 for (int j = 0; j < saaLib.length; ++j) {
399 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
400 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
401 vMi.add(libMi);
402 }
403
404 nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {
405
406 for (int j = 0; j < vMi.size(); ++j) {
407 ModuleIdentification nextMi = vMi.get(j);
408 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) {
409 continue nextPcd;
410 }
411 }
412 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);
413 dataModified = true;
414 }
415 //
416 // add new Pcd from MSA file to ModuleSA.
417 //
418 for (int i = 0; i < vMi.size(); ++i) {
419 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
420 .getModuleXmlObject(vMi
421 .get(i));
422 if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {
423 continue;
424 }
425 ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();
426 msaPcdIter:while (li.hasNext()) {
427 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
428 ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());
429 if (al != null) {
430 for (int j = 0; j < al.size(); ++j) {
431 if (al.get(j).contains(moduleKey)) {
432 continue msaPcdIter;
433 }
434 }
435 }
436
437 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));
438 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
439 if (spdPcd == null) {
440 //
441 // ToDo Error
442 //
443 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "
444 + mi.getName());
445 }
446 //
447 // AddItem to ModuleSA PcdBuildDefinitions
448 //
449 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()
450 : msaPcd.getDefaultValue();
451
452 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),
453 msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);
454 dataModified = true;
455 }
456
457 }
458
459 return dataModified;
460 }
461
462 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {
463
464 ArrayList<String> al = dynPcdMap.get(pcdKey);
465 if (al == null) {
466 return;
467 }
468 String[] s = moduleInfo.split(" ");
469 for(int i = 0; i < al.size(); ++i){
470 String consumer = al.get(i);
471 if (consumer.contains(s[0]) && consumer.contains(s[2])){
472 String[] consumerPart = consumer.split(" ");
473 if (!consumerPart[4].equals(s[4])) {
474 continue;
475 }
476 al.remove(consumer);
477 break;
478 }
479 }
480
481 if (al.size() == 0) {
482 defaultPcdValue.remove(pcdKey);
483 dynPcdMap.remove(pcdKey);
484 String[] s1 = pcdKey.split(" ");
485 removeDynamicPcdBuildData(s1[0], s1[1]);
486 }
487
488 }
489 //
490 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
491 //
492 public int getPcdDataCount (int i){
493 ModuleSADocument.ModuleSA msa = getModuleSA(i);
494
495 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
496 return 0;
497 }
498 return msa.getPcdBuildDefinition().getPcdDataList().size();
499
500 }
501
502 public void getPcdData (int i, String[][] saa) {
503 ModuleSADocument.ModuleSA msa = getModuleSA(i);
504
505 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
506 return;
507 }
508 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
509 for (int k = 0; k < saa.length; ++k) {
510 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
511 saa[k][0] = pcdData.getCName();
512 saa[k][1] = pcdData.getTokenSpaceGuidCName();
513 saa[k][2] = pcdData.getItemType()+"";
514 saa[k][3] = pcdData.getToken().toString();
515 saa[k][4] = pcdData.getMaxDatumSize()+"";
516 saa[k][5] = pcdData.getDatumType()+"";
517 saa[k][6] = pcdData.getValue();
518
519 }
520 }
521
522 public void removePcdData (int seqModuleSa, String cName, String tsGuid) {
523 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
524 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
525 return;
526 }
527
528 String mg = moduleSa.getModuleGuid();
529 String mv = moduleSa.getModuleVersion();
530 String pg = moduleSa.getPackageGuid();
531 String pv = moduleSa.getPackageVersion();
532 String arch = listToString(moduleSa.getSupArchList());
533 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
534
535 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
536 if (cursor.toFirstChild()){
537
538 do {
539 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
540 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
541 maintainDynPcdMap(cName + " " + tsGuid, moduleKey);
542 if (getPcdDataCount(seqModuleSa) == 1) {
543 cursor.toParent();
544 }
545 cursor.removeXml();
546 break;
547 }
548 }
549 while(cursor.toNextSibling());
550
551 }
552 cursor.dispose();
553 }
554
555 public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){
556 ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);
557 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
558 return;
559 }
560
561 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
562 if (cursor.toFirstChild()){
563 do {
564 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
565 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
566 //
567 // change item type while not updating dynPcdData????
568 //
569 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
570 if(pcdData.getDatumType().equals("VOID*")) {
571 pcdData.setMaxDatumSize(new Integer(maxSize));
572 }
573 pcdData.setValue(value);
574 defaultPcdValue.put(cName + " " + tsGuid, value);
575 break;
576 }
577 }
578 while(cursor.toNextSibling());
579 }
580 cursor.dispose();
581 }
582
583 /**Get original Pcd info from MSA & SPD files.
584 * @param mi ModuleIdentification from which MSA & SPD come
585 * @param cName PCD cName
586 * @param sa Results: HelpText, Original item type.
587 * @return
588 */
589 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{
590 try {
591
592 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
593 if (msa.getPcdCoded() == null) {
594 return false;
595 }
596
597 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
598 m.put("ModuleSurfaceArea", msa);
599 SurfaceAreaQuery.setDoc(m);
600 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
601 //
602 // First look through MSA pcd entries.
603 //
604 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
605 ListIterator li = l.listIterator();
606 while(li.hasNext()) {
607 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
608 if (!msaPcd.getCName().equals(cName)) {
609 continue;
610 }
611 if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {
612 continue;
613 }
614 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
615 if (spdPcd == null) {
616 //
617 // ToDo Error
618 //
619 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());
620 }
621 //
622 // Get Pcd help text and original item type.
623 //
624 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();
625 sa[1] = msaPcd.getPcdItemType()+"";
626 sa[2] = msa.getModuleDefinitions().getBinaryModule()+"";
627 return true;
628 }
629
630
631 }
632 catch (Exception e){
633 e.printStackTrace();
634 throw e;
635 }
636
637 return false;
638 }
639
640 private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) {
641 int libCount = getLibraryInstancesCount(moduleKey);
642 String[][] saaLib = new String[libCount][5];
643 getLibraryInstances(moduleKey, saaLib);
644 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
645 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
646 //
647 // create vector for module & library instance MIs.
648 //
649 vMi.add(mi);
650 for (int j = 0; j < saaLib.length; ++j) {
651 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
652 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
653 vMi.add(libMi);
654 }
655
656 int pcdSourceCount = 0;
657 for (int i = 0; i < vMi.size(); ++i) {
658 if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) {
659 pcdSourceCount++;
660 }
661 }
662
663 if (pcdSourceCount < 2) {
664 return false;
665 }
666 else {
667 return true;
668 }
669
670 }
671
672 /**Remove PCDBuildDefinition entries from ModuleSA
673 * @param moduleKey identifier of ModuleSA.
674 * @param consumer where these entries come from.
675 */
676 public void removePcdData(String moduleKey, ModuleIdentification consumer) {
677
678 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);
679 if (msa.getPcdCoded() == null) {
680 return;
681 }
682
683 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
684 ListIterator li = l.listIterator();
685
686 while(li.hasNext()) {
687 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
688 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);
689 if (moduleSA.getPcdBuildDefinition() != null) {
690 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();
691 cursor.push();
692 if (cursor.toFirstChild()) {
693 do {
694 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor
695 .getObject();
696 String cName = msaPcd.getCName();
697 String tsGuidCName = msaPcd.getTokenSpaceGuidCName();
698 if (cName.equals(pcdData.getCName())
699 && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) {
700
701 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),
702 moduleKey);
703 cursor.removeXml();
704 break;
705 }
706 } while (cursor.toNextSibling());
707 }
708
709 cursor.pop();
710 if (moduleSA.getPcdBuildDefinition().getPcdDataList().size() == 0) {
711 cursor.removeXml();
712 }
713 cursor.dispose();
714 }
715 }
716
717 }
718 //
719 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
720 //
721 public int getLibraryInstancesCount(String key) {
722 ModuleSADocument.ModuleSA msa = getModuleSA(key);
723 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
724 return 0;
725 }
726 return msa.getLibraries().getInstanceList().size();
727 }
728
729 public void getLibraryInstances(String key, String[][] saa){
730 ModuleSADocument.ModuleSA msa = getModuleSA(key);
731 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
732 return ;
733 }
734
735 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
736 for (int i = 0; i < saa.length; ++i) {
737 LibrariesDocument.Libraries.Instance instance = li.next();
738 saa[i][1] = instance.getModuleGuid();
739 saa[i][2] = instance.getModuleVersion();
740 saa[i][3] = instance.getPackageGuid();
741 saa[i][4] = instance.getPackageVersion();
742 }
743 }
744
745 public void removeLibraryInstance(String key, int i) {
746 ModuleSADocument.ModuleSA msa = getModuleSA(key);
747 if (msa == null || msa.getLibraries() == null){
748 return ;
749 }
750
751 XmlCursor cursor = msa.getLibraries().newCursor();
752 if (cursor.toFirstChild()) {
753 for (int j = 0; j < i; ++j) {
754 cursor.toNextSibling();
755 }
756 cursor.push();
757 while (cursor.hasPrevToken()) {
758 cursor.toPrevToken();
759 if (!cursor.isText()) {
760 break;
761 }
762 String s = cursor.getTextValue();
763 if (s.matches(regExpNewLineAndSpaces)) {
764 continue;
765 }
766 }
767
768 if (cursor.isComment()) {
769 cursor.removeXml();
770 }
771 cursor.pop();
772 cursor.removeXml();
773 if (getLibraryInstancesCount(key) == 0) {
774 cursor.toParent();
775 cursor.removeXml();
776 }
777 }
778
779 cursor.dispose();
780 }
781
782 public void genLibraryInstance(ModuleIdentification libMi, String key) {
783 ModuleSADocument.ModuleSA msa = getModuleSA(key);
784 if (msa == null){
785 msa = getfpdFrameworkModules().addNewModuleSA();
786 }
787 LibrariesDocument.Libraries libs = msa.getLibraries();
788 if(libs == null){
789 libs = msa.addNewLibraries();
790 }
791
792 String mn = libMi.getName();
793 String mg = libMi.getGuid();
794 String mv = libMi.getVersion();
795 String pn = libMi.getPackageId().getName();
796 String pg = libMi.getPackageId().getGuid();
797 String pv = libMi.getPackageId().getVersion();
798 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
799 XmlCursor cursor = instance.newCursor();
800 try{
801 String comment = "Pkg: " + pn + " Mod: " + mn
802 + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
803 cursor.insertComment(comment);
804 }
805 catch (Exception e){
806 e.printStackTrace();
807 }
808 finally {
809 cursor.dispose();
810 }
811
812 instance.setModuleGuid(mg);
813 instance.setModuleVersion(mv);
814 instance.setPackageGuid(pg);
815 instance.setPackageVersion(pv);
816
817 }
818
819 public String getFvBinding(String moduleKey){
820 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
821 return getFvBinding (moduleSa);
822 }
823
824 public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {
825 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
826 return null;
827 }
828 return moduleSa.getModuleSaBuildOptions().getFvBinding();
829 }
830
831 public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {
832 if (moduleSa == null ) {
833 return;
834 }
835 if (fvBinding == null || fvBinding.length() == 0) {
836 if(moduleSa.getModuleSaBuildOptions() != null){
837 moduleSa.getModuleSaBuildOptions().unsetFvBinding();
838 }
839 }
840 else {
841 if(moduleSa.getModuleSaBuildOptions() == null){
842 moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
843 return;
844 }
845 moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding);
846 }
847 }
848
849 public void setFvBinding(String moduleKey, String fvBinding){
850 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
851 setFvBinding (moduleSa, fvBinding);
852 }
853
854 private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {
855 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
856 return -1;
857 }
858
859 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
860 String[] fvNamesArray = fvNameList.split(" ");
861 int occursAt = -1;
862 for (int i = 0; i < fvNamesArray.length; ++i) {
863 if (fvNamesArray[i].equals(fvName)) {
864 occursAt = i;
865 break;
866 }
867 }
868 return occursAt;
869 }
870
871 public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
872 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
873 return;
874 }
875
876 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
877 String[] fvNamesArray = fvNameList.split(" ");
878 int occursAt = -1;
879 for (int i = 0; i < fvNamesArray.length; ++i) {
880 if (fvNamesArray[i].equals(fvName)) {
881 occursAt = i;
882 break;
883 }
884 }
885 // jump over where the input fvName occurs in the original Fv list.
886 if (occursAt != -1) {
887 String newFvNameList = " ";
888 for (int i = 0; i < fvNamesArray.length; ++i) {
889 if (i == occursAt) {
890 continue;
891 }
892 newFvNameList += fvNamesArray[i];
893 }
894 setFvBinding (moduleSa, newFvNameList.trim());
895 }
896
897 }
898
899 /**
900 * @param fvName The FV name that to be removed from FvBinding List.
901 */
902 public void removeFvBindingAll (String fvName) {
903 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
904 removeElement(getfpdFrameworkModules());
905 fpdFrameworkModules = null;
906 return;
907 }
908
909 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
910 while (li.hasNext()) {
911 ModuleSADocument.ModuleSA moduleSa = li.next();
912 removeFvBinding (moduleSa, fvName);
913 }
914 }
915
916 public void appendFvBindingAll (String fvName) {
917 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
918 removeElement(getfpdFrameworkModules());
919 fpdFrameworkModules = null;
920 return;
921 }
922
923 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
924 while (li.hasNext()) {
925 ModuleSADocument.ModuleSA moduleSa = li.next();
926 appendFvBinding (moduleSa, fvName);
927 }
928 }
929
930 public void appendFvBindingFor (String oldFvName, String newFvName) {
931 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
932 removeElement(getfpdFrameworkModules());
933 fpdFrameworkModules = null;
934 return;
935 }
936
937 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
938 while (li.hasNext()) {
939 ModuleSADocument.ModuleSA moduleSa = li.next();
940 String fvBinding = getFvBinding (moduleSa);
941 if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {
942 appendFvBinding (moduleSa, newFvName);
943 }
944 }
945 }
946
947 public void appendFvBinding (String moduleKey, String fvName) {
948 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
949 appendFvBinding (moduleSa, fvName);
950 }
951
952 public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
953 if (moduleSa == null) {
954 return;
955 }
956
957 if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
958 setFvBinding(moduleSa, fvName);
959 return;
960 }
961
962 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
963 String newFvNameList = fvNameList + " " + fvName;
964 setFvBinding (moduleSa, newFvNameList.trim());
965 }
966
967 public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) {
968 Vector<Object> vSupArchs = new Vector<Object>();
969 getPlatformDefsSupportedArchs(vSupArchs);
970 String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion();
971 for (int i = 0; i < vSupArchs.size(); ++i) {
972 String moduleKey = moduleInfo + " " + vSupArchs.get(i);
973 appendFvBinding (moduleKey, fvName);
974 }
975 }
976
977 public String getFfsFileNameGuid(String moduleKey){
978 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
979 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
980 return null;
981 }
982 return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid();
983 }
984
985 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
986 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
987 if (msa == null ) {
988 return;
989 }
990 if(msa.getModuleSaBuildOptions() == null){
991 msa.addNewModuleSaBuildOptions();
992
993 }
994 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();
995 if (fileGuid != null) {
996 msaBuildOpts.setFfsFileNameGuid(fileGuid);
997 }
998 else{
999 XmlCursor cursor = msaBuildOpts.newCursor();
1000 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {
1001 cursor.removeXml();
1002 }
1003 cursor.dispose();
1004 }
1005
1006 }
1007
1008 public String getFfsFormatKey(String moduleKey){
1009 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1010 if (msa == null || msa.getModuleSaBuildOptions() == null) {
1011 return null;
1012 }
1013 return msa.getModuleSaBuildOptions().getFfsFormatKey();
1014 }
1015
1016 public void setFfsFormatKey(String moduleKey, String ffsKey){
1017 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1018 if (msa == null ) {
1019 return;
1020 }
1021 if(msa.getModuleSaBuildOptions() == null){
1022 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1023 return;
1024 }
1025 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);
1026 }
1027
1028 public void setModuleSAForceDebug(int i, boolean dbgEnable) {
1029 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1030 moduleSa.setForceDebug(dbgEnable);
1031 }
1032
1033 public boolean getModuleSAForceDebug (int i) {
1034 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
1035 if (moduleSa.getForceDebug() == true) {
1036 return true;
1037 }
1038 return false;
1039 }
1040
1041 public void getModuleSAOptions(String moduleKey, String[][] saa) {
1042 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1043 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1044 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1045 return ;
1046 }
1047
1048 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
1049 ListIterator li = lOpt.listIterator();
1050 int i = 0;
1051 while(li.hasNext()) {
1052 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1053 if (opt.getBuildTargets() != null) {
1054 saa[i][0] = listToString(opt.getBuildTargets());
1055 }
1056 saa[i][1] = opt.getToolChainFamily();
1057 saa[i][2] = opt.getTagName();
1058 saa[i][3] = opt.getToolCode();
1059
1060 if (opt.getSupArchList() != null){
1061 saa[i][4] = listToString(opt.getSupArchList());
1062 }
1063 else {
1064 saa[i][4] = "";
1065 }
1066
1067 saa[i][5] = opt.getStringValue();
1068
1069 ++i;
1070 }
1071 }
1072
1073 public int getModuleSAOptionsCount(String moduleKey){
1074 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1075 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1076 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1077 return 0;
1078 }
1079 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
1080 }
1081
1082 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1083 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1084 if (msa.getModuleSaBuildOptions() == null) {
1085 msa.addNewModuleSaBuildOptions();
1086 }
1087 if (msa.getModuleSaBuildOptions().getOptions() == null){
1088 msa.getModuleSaBuildOptions().addNewOptions();
1089 }
1090 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
1091 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1092 }
1093
1094 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
1095 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1096 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1097 return ;
1098 }
1099 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1100 XmlCursor cursor = opts.newCursor();
1101 if (cursor.toFirstChild()) {
1102 for (int j = 0; j < i; ++j){
1103 cursor.toNextSibling();
1104 }
1105 cursor.removeXml();
1106 }
1107 cursor.dispose();
1108 }
1109
1110 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1111 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1112 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1113 return ;
1114 }
1115 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1116 XmlCursor cursor = opts.newCursor();
1117 if (cursor.toFirstChild()) {
1118 for (int j = 0; j < i; ++j){
1119 cursor.toNextSibling();
1120 }
1121 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1122 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1123 }
1124 cursor.dispose();
1125 }
1126
1127 /**add pcd information of module mi to a ModuleSA.
1128 * @param mi
1129 * @param moduleSa if null, generate a new ModuleSA.
1130 */
1131 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
1132 //ToDo add Arch filter
1133
1134 try {
1135 if (moduleSa == null) {
1136 moduleSa = genModuleSA(mi, arch);
1137 }
1138
1139 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
1140 if (msa.getPcdCoded() == null) {
1141 return;
1142 }
1143
1144 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
1145 m.put("ModuleSurfaceArea", msa);
1146 SurfaceAreaQuery.setDoc(m);
1147 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
1148 //
1149 // Implementing InitializePlatformPcdBuildDefinitions
1150 //
1151 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
1152 ListIterator li = l.listIterator();
1153 while(li.hasNext()) {
1154 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
1155 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
1156 if (spdPcd == null) {
1157 //
1158 // ToDo Error
1159 //
1160 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());
1161 }
1162 //
1163 // AddItem to ModuleSA PcdBuildDefinitions
1164 //
1165 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
1166
1167 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
1168 }
1169
1170 }
1171 catch (Exception e){
1172
1173 throw e;
1174 }
1175
1176 }
1177
1178 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
1179
1180 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
1181 for (int i = 0; i < depPkgs.length; ++i) {
1182
1183 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);
1184 if (xo == null) {
1185 continue;
1186 }
1187 for (int j = 0; j < xo.length; ++j) {
1188 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
1189 if (msaPcd.getTokenSpaceGuidCName() == null) {
1190 if (spdPcd.getCName().equals(msaPcd.getCName())) {
1191 return spdPcd;
1192 }
1193 }
1194 else{
1195 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
1196 return spdPcd;
1197 }
1198 }
1199
1200 }
1201
1202 }
1203 return null;
1204 }
1205
1206 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
1207 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
1208 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
1209 XmlCursor cursor = msa.newCursor();
1210 try{
1211 String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "
1212 + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
1213 cursor.insertComment(comment);
1214 }
1215 catch(Exception e){
1216 e.printStackTrace();
1217 }
1218 finally {
1219 cursor.dispose();
1220 }
1221 msa.setModuleGuid(mi.getGuid());
1222 msa.setModuleVersion(mi.getVersion());
1223 msa.setPackageGuid(pi.getGuid());
1224 msa.setPackageVersion(pi.getVersion());
1225 if (arch != null) {
1226 Vector<String> v = new Vector<String>();
1227 v.add(arch);
1228 msa.setSupArchList(v);
1229 }
1230
1231 return msa;
1232 }
1233
1234 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa)
1235 throws PcdItemTypeConflictException, PcdValueMalFormed{
1236 if (moduleSa.getPcdBuildDefinition() == null){
1237 moduleSa.addNewPcdBuildDefinition();
1238 }
1239 //
1240 // constructe pcd to modulesa mapping first.
1241 // Attention : for any error condition, remove from map this pcd.
1242 //
1243 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1244 if (pcdConsumer == null) {
1245 pcdConsumer = new ArrayList<String>();
1246 }
1247 //
1248 // Check whether this PCD has already added to ModuleSA, if so, just return.
1249 //
1250 String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion()
1251 + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
1252 for (int i = 0; i < pcdConsumer.size(); ++i) {
1253 String pcdInfo = pcdConsumer.get(i);
1254 if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){
1255 return;
1256 }
1257 }
1258 //
1259 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1260 //
1261 if (pcdConsumer.size() > 0) {
1262
1263 itemType = itemType (pcdConsumer.get(0));
1264 }
1265 String listValue = moduleInfo + " " + itemType;
1266 pcdConsumer.add(listValue);
1267 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1268
1269 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1270 fpdPcd.setCName(cName);
1271 fpdPcd.setToken(token);
1272 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1273 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1274 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1275
1276 if (defaultVal != null){
1277 fpdPcd.setValue(defaultVal);
1278 }
1279 else {
1280 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1281 fpdPcd.setValue("0");
1282 }
1283 if (dataType.equals("BOOLEAN")){
1284 fpdPcd.setValue("FALSE");
1285 }
1286 if (dataType.equals("VOID*")) {
1287 fpdPcd.setValue("");
1288 }
1289 }
1290 //
1291 // Using existing pcd value, if this pcd already exists in other moduleSa.
1292 //
1293 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1294 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1295 }
1296 else {
1297 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1298 }
1299
1300 if (dataType.equals("UINT8")){
1301 fpdPcd.setMaxDatumSize(1);
1302 }
1303 if (dataType.equals("UINT16")) {
1304 fpdPcd.setMaxDatumSize(2);
1305 }
1306 if (dataType.equals("UINT32")) {
1307 fpdPcd.setMaxDatumSize(4);
1308 }
1309 if (dataType.equals("UINT64")){
1310 fpdPcd.setMaxDatumSize(8);
1311 }
1312 if (dataType.equals("BOOLEAN")){
1313 fpdPcd.setMaxDatumSize(1);
1314 }
1315 if (dataType.equals("VOID*")) {
1316 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1317 fpdPcd.setMaxDatumSize(maxSize);
1318 }
1319
1320
1321 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1322 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1323 //
1324 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1325 // so need to add one dyn pcd.
1326 //
1327 if (al.size() == 1) {
1328 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1329 }
1330 }
1331
1332 }
1333
1334 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1335 if (datum == null) {
1336 return 0;
1337 }
1338 char ch = datum.charAt(0);
1339 int start, end;
1340 String strValue;
1341 //
1342 // For void* type PCD, only three datum is support:
1343 // 1) Unicode: string with start char is "L"
1344 // 2) Ansci: String is ""
1345 // 3) byte array: String start char "{"
1346 //
1347 if (ch == 'L') {
1348 start = datum.indexOf('\"');
1349 end = datum.lastIndexOf('\"');
1350 if ((start > end) ||
1351 (end > datum.length())||
1352 ((start == end) && (datum.length() > 0))) {
1353 //ToDo Error handling here
1354 throw new PcdValueMalFormed (datum);
1355 }
1356
1357 strValue = datum.substring(start + 1, end);
1358 return strValue.length() * 2;
1359 } else if (ch == '\"'){
1360 start = datum.indexOf('\"');
1361 end = datum.lastIndexOf('\"');
1362 if ((start > end) ||
1363 (end > datum.length())||
1364 ((start == end) && (datum.length() > 0))) {
1365 throw new PcdValueMalFormed (datum);
1366 }
1367 strValue = datum.substring(start + 1, end);
1368 return strValue.length();
1369 } else if (ch =='{') {
1370 String[] strValueArray;
1371
1372 start = datum.indexOf('{');
1373 end = datum.lastIndexOf('}');
1374 strValue = datum.substring(start + 1, end);
1375 strValue = strValue.trim();
1376 if (strValue.length() == 0) {
1377 return 0;
1378 }
1379 strValueArray = strValue.split(",");
1380 for (int index = 0; index < strValueArray.length; index ++) {
1381 Integer value = Integer.decode(strValueArray[index].trim());
1382
1383 if (value > 0xFF) {
1384 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1385 // "it must be a byte array. But the element of %s exceed the byte range",
1386 throw new PcdValueMalFormed (datum);
1387 }
1388 }
1389 return strValueArray.length;
1390
1391
1392 } else {
1393 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1394 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1395 // "2) ANSIC string: like \"xxx\";\r\n"+
1396 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1397 // "but the datum in seems does not following above format!",
1398 throw new PcdValueMalFormed (datum);
1399
1400 }
1401 }
1402
1403 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1404 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1405
1406 return al;
1407 }
1408
1409 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1410
1411 return dynPcdMap.get(pcdKey);
1412 }
1413
1414 public int getDynamicPcdBuildDataCount() {
1415 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1416 removeElement(getfpdDynPcdBuildDefs());
1417 fpdDynPcdBuildDefs = null;
1418 return 0;
1419 }
1420 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1421 }
1422
1423 public void getDynamicPcdBuildData(String[][] saa) {
1424 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1425 removeElement(getfpdDynPcdBuildDefs());
1426 fpdDynPcdBuildDefs = null;
1427 return ;
1428 }
1429 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1430 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1431 int i = 0;
1432 while(li.hasNext()) {
1433 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1434 saa[i][0] = dynPcd.getCName();
1435 saa[i][1] = dynPcd.getToken().toString();
1436 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1437 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1438 saa[i][4] = dynPcd.getDatumType().toString();
1439
1440 ++i;
1441 }
1442 }
1443
1444 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1445 throws PcdValueMalFormed{
1446 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1447 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1448 dynPcdData.setCName(cName);
1449 dynPcdData.setToken(token);
1450 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1451 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1452
1453 BigInteger bigInt = new BigInteger("0");
1454 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1455 skuInfo.setSkuId(bigInt);
1456 if (defaultVal != null){
1457 skuInfo.setValue(defaultVal);
1458 }
1459 else {
1460 if (dataType.equals("UINT8")){
1461 skuInfo.setValue("0");
1462 }
1463 if (dataType.equals("UINT16")) {
1464 skuInfo.setValue("0");
1465 }
1466 if (dataType.equals("UINT32")) {
1467 skuInfo.setValue("0");
1468 }
1469 if (dataType.equals("UINT64")){
1470 skuInfo.setValue("0");
1471 }
1472 if (dataType.equals("BOOLEAN")){
1473 skuInfo.setValue("false");
1474 }
1475 if (dataType.equals("VOID*")) {
1476 skuInfo.setValue("");
1477 }
1478 }
1479 if (dataType.equals("UINT8")){
1480 dynPcdData.setMaxDatumSize(1);
1481 }
1482 if (dataType.equals("UINT16")) {
1483 dynPcdData.setMaxDatumSize(2);
1484 }
1485 if (dataType.equals("UINT32")) {
1486 dynPcdData.setMaxDatumSize(4);
1487 }
1488 if (dataType.equals("UINT64")){
1489 dynPcdData.setMaxDatumSize(8);
1490 }
1491 if (dataType.equals("BOOLEAN")){
1492 dynPcdData.setMaxDatumSize(1);
1493 }
1494 if (dataType.equals("VOID*")) {
1495 int maxSize = setMaxSizeForPointer(defaultVal);
1496 dynPcdData.setMaxDatumSize(maxSize);
1497 }
1498 }
1499
1500 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1501 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1502 if (o == null) {
1503 return;
1504 }
1505
1506 XmlCursor cursor = o.newCursor();
1507 if (cursor.toFirstChild()) {
1508 do {
1509 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1510 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1511 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1512
1513 if (getDynamicPcdBuildDataCount() == 1) {
1514 cursor.toParent();
1515 }
1516 cursor.removeXml();
1517 cursor.dispose();
1518 return;
1519 }
1520 }
1521 while (cursor.toNextSibling());
1522 }
1523 cursor.dispose();
1524 }
1525 //
1526 // Get the Sku Info count of ith dyn pcd element.
1527 //
1528 public int getDynamicPcdSkuInfoCount(int i){
1529 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1530 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1531 return 0;
1532 }
1533
1534 int skuInfoCount = 0;
1535 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1536 if (cursor.toFirstChild()) {
1537 for (int j = 0; j < i; ++j) {
1538 cursor.toNextSibling();
1539 }
1540 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1541 if (pcdData.getSkuInfoList() == null) {
1542 skuInfoCount = 0;
1543 }
1544 else {
1545 skuInfoCount = pcdData.getSkuInfoList().size();
1546 }
1547 }
1548 cursor.dispose();
1549 return skuInfoCount;
1550 }
1551
1552 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1553 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1554 removeElement(getfpdDynPcdBuildDefs());
1555 fpdDynPcdBuildDefs = null;
1556 return;
1557 }
1558
1559 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1560 if (cursor.toFirstChild()) {
1561 for (int j = 0; j < i; ++j) {
1562 cursor.toNextSibling();
1563 }
1564 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1565 if (pcdData.getSkuInfoList() == null) {
1566 cursor.dispose();
1567 return;
1568 }
1569 else {
1570 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1571 int k = 0;
1572 while (li.hasNext()) {
1573 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1574 saa[k][0] = skuInfo.getSkuId()+"";
1575 saa[k][1] = skuInfo.getVariableName();
1576 saa[k][2] = skuInfo.getVariableGuid();
1577 saa[k][3] = skuInfo.getVariableOffset();
1578 saa[k][4] = skuInfo.getHiiDefaultValue();
1579 saa[k][5] = skuInfo.getVpdOffset();
1580 saa[k][6] = skuInfo.getValue();
1581 ++k;
1582 }
1583
1584 }
1585 }
1586 cursor.dispose();
1587
1588 }
1589
1590 public String getDynamicPcdBuildDataValue(int i){
1591 String value = null;
1592 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1593 removeElement(getfpdDynPcdBuildDefs());
1594 fpdDynPcdBuildDefs = null;
1595 return value;
1596 }
1597
1598 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1599 if (cursor.toFirstChild()) {
1600 for (int j = 0; j < i; ++j) {
1601 cursor.toNextSibling();
1602 }
1603 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1604 if (pcdData.getSkuInfoList() == null) {
1605 value = null;
1606 }
1607 else {
1608 value = pcdData.getSkuInfoArray(0).getValue();
1609 }
1610 }
1611 cursor.dispose();
1612 return value;
1613 }
1614
1615 public String getDynamicPcdBuildDataVpdOffset(int i){
1616 String vpdOffset = null;
1617 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1618 removeElement(getfpdDynPcdBuildDefs());
1619 fpdDynPcdBuildDefs = null;
1620 return vpdOffset;
1621 }
1622
1623 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1624 if (cursor.toFirstChild()) {
1625 for (int j = 0; j < i; ++j) {
1626 cursor.toNextSibling();
1627 }
1628 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1629 if (pcdData.getSkuInfoList() == null) {
1630 vpdOffset = null;
1631 }
1632 else {
1633 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1634 }
1635 }
1636 cursor.dispose();
1637 return vpdOffset;
1638 }
1639
1640 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1641 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1642 removeElement(getfpdDynPcdBuildDefs());
1643 fpdDynPcdBuildDefs = null;
1644 return;
1645 }
1646
1647 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1648 if (cursor.toFirstChild()) {
1649 for (int j = 0; j < i; ++j) {
1650 cursor.toNextSibling();
1651 }
1652 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1653 if (pcdData.getSkuInfoList() == null) {
1654 cursor.dispose();
1655 return;
1656 }
1657 else {
1658 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1659 cursor.toChild(qSkuInfo);
1660 cursor.removeXml();
1661 }
1662 }
1663 cursor.dispose();
1664 }
1665 //
1666 // generate sku info for ith dyn pcd build data.
1667 //
1668 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1669 String hiiDefault, String vpdOffset, String value, int i) {
1670 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1671 // return;
1672 // }
1673
1674 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1675 if (cursor.toFirstChild()) {
1676 for (int j = 0; j < i; ++j) {
1677 cursor.toNextSibling();
1678 }
1679 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1680 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1681 skuInfo.setSkuId(new BigInteger(id));
1682 if (varName != null){
1683 skuInfo.setVariableName(varName);
1684 skuInfo.setVariableGuid(varGuid);
1685 skuInfo.setVariableOffset(varOffset);
1686 skuInfo.setHiiDefaultValue(hiiDefault);
1687 }
1688 else if (vpdOffset != null){
1689 skuInfo.setVpdOffset(vpdOffset);
1690 }
1691 else{
1692 skuInfo.setValue(value);
1693 }
1694 }
1695 }
1696
1697 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1698 String hiiDefault, String vpdOffset, String value, int i){
1699 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1700 // return;
1701 // }
1702
1703 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1704 if (cursor.toFirstChild()) {
1705 for (int j = 0; j < i; ++j) {
1706 cursor.toNextSibling();
1707 }
1708 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1709 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1710 while (li.hasNext()) {
1711 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1712 if (skuInfo.getSkuId().toString().equals(id)){
1713 if (varName != null){
1714 skuInfo.setVariableName(varName);
1715 skuInfo.setVariableGuid(varGuid);
1716 skuInfo.setVariableOffset(varOffset);
1717 skuInfo.setHiiDefaultValue(hiiDefault);
1718 }
1719 else if (vpdOffset != null){
1720 skuInfo.setVpdOffset(vpdOffset);
1721 }
1722 else{
1723 skuInfo.setValue(value);
1724 }
1725 break;
1726 }
1727 }
1728 }
1729 }
1730
1731 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1732 if (fpdBuildOpts == null) {
1733 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1734 }
1735 return fpdBuildOpts;
1736 }
1737
1738 public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {
1739 QName elementFvName = new QName (xmlNs, "FvName");
1740 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1741 QName elementInfFileName = new QName(xmlNs, "InfFileName");
1742 QName elementModule = new QName(xmlNs, "Module");
1743
1744 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1745 userExts.setUserID("IMAGES");
1746 userExts.setIdentifier(new BigInteger("1"));
1747 XmlCursor cursor = userExts.newCursor();
1748 cursor.toEndToken();
1749
1750 cursor.beginElement(elementFvName);
1751 cursor.insertChars(fvName);
1752 cursor.toNextToken();
1753
1754 cursor.beginElement(elementInfFileName);
1755 cursor.insertChars(fvName + ".inf");
1756 cursor.toNextToken();
1757
1758 cursor.beginElement(elementIncludeModules);
1759 for (int i = 0; i < includeModules.size(); ++i) {
1760 cursor.beginElement(elementModule);
1761 cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);
1762 cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]);
1763 cursor.toEndToken();
1764 cursor.toNextToken();
1765 }
1766 cursor.dispose();
1767 }
1768
1769 public int getUserExtsIncModCount (String fvName) {
1770 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1771 return -1;
1772 }
1773 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1774 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1775 while (li.hasNext()) {
1776 UserExtensionsDocument.UserExtensions ues = li.next();
1777 if (!ues.getUserID().equals("IMAGES")) {
1778 continue;
1779 }
1780 XmlCursor cursor = ues.newCursor();
1781 cursor.toFirstChild();
1782 String elementName = cursor.getTextValue();
1783 if (elementName.equals(fvName)) {
1784 cursor.toNextSibling(elementIncludeModules);
1785 if (cursor.toFirstChild()) {
1786 int i = 1;
1787 for (i = 1; cursor.toNextSibling(); ++i);
1788 cursor.dispose();
1789 return i;
1790 }
1791 cursor.dispose();
1792 return 0;
1793 }
1794 cursor.dispose();
1795 }
1796 return -1;
1797 }
1798
1799 public void getUserExtsIncMods(String fvName, String[][] saa) {
1800 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1801 return;
1802 }
1803
1804 XmlCursor cursor = getfpdBuildOpts().newCursor();
1805 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1806 QName attribUserId = new QName ("UserID");
1807 QName elementFvName = new QName (xmlNs, "FvName");
1808 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1809 QName attribModuleGuid = new QName("ModuleGuid");
1810 QName attribBaseName = new QName("BaseName");
1811
1812 if (cursor.toChild(elementUserExts)) {
1813 do {
1814 cursor.push();
1815 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1816 cursor.toChild(elementFvName);
1817 String elementName = cursor.getTextValue();
1818 if (elementName.equals(fvName)) {
1819 cursor.toNextSibling(elementIncludeModules);
1820 if (cursor.toFirstChild()) {
1821 int i = 0;
1822 do {
1823 saa[i][0] = cursor.getAttributeText(attribModuleGuid);
1824 saa[i][1] = cursor.getAttributeText(attribBaseName);
1825 ++i;
1826 }while (cursor.toNextSibling());
1827 }
1828 break;
1829 }
1830 }
1831 cursor.pop();
1832 }while (cursor.toNextSibling(elementUserExts));
1833 }
1834 cursor.dispose();
1835
1836 }
1837
1838 public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {
1839 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1840 return;
1841 }
1842 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1843 while (li.hasNext()) {
1844 UserExtensionsDocument.UserExtensions ues = li.next();
1845 if (!ues.getUserID().equals("IMAGES")) {
1846 continue;
1847 }
1848 XmlCursor cursor = ues.newCursor();
1849 cursor.toFirstChild();
1850 String elementName = cursor.getTextValue();
1851 if (elementName.equals(oldFvName)) {
1852 cursor.setTextValue(newFvName);
1853 }
1854 cursor.dispose();
1855 }
1856
1857 }
1858
1859 public void removeBuildOptionsUserExtensions (String fvName) {
1860 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1861 return;
1862 }
1863
1864 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1865 while (li.hasNext()) {
1866 UserExtensionsDocument.UserExtensions ues = li.next();
1867 if (!ues.getUserID().equals("IMAGES")) {
1868 continue;
1869 }
1870 XmlCursor cursor = ues.newCursor();
1871 cursor.toFirstChild();
1872 String elementName = cursor.getTextValue();
1873 if (elementName.equals(fvName)) {
1874 cursor.toParent();
1875 cursor.removeXml();
1876 cursor.dispose();
1877 return;
1878 }
1879 cursor.dispose();
1880 }
1881
1882 }
1883
1884
1885 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1886 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1887 if (udats == null) {
1888 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1889 }
1890
1891 AntTaskDocument.AntTask at = udats.addNewAntTask();
1892 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1893 }
1894
1895 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1896 at.setId(new Integer(id));
1897 XmlCursor cursor = at.newCursor();
1898 if (fileName != null){
1899 at.setFilename(fileName);
1900 }
1901 else if (cursor.toChild(xmlNs, "Filename")) {
1902 cursor.removeXml();
1903 }
1904 if (execOrder != null) {
1905 at.setAntCmdOptions(execOrder);
1906 }
1907 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
1908 cursor.removeXml();
1909 }
1910 cursor.dispose();
1911 }
1912
1913 public void removeBuildOptionsUserDefAntTask(int i) {
1914 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1915 if (o == null) {
1916 return;
1917 }
1918 XmlCursor cursor = o.newCursor();
1919 if (cursor.toFirstChild()) {
1920 for (int j = 0; j < i; ++j) {
1921 cursor.toNextSibling();
1922 }
1923 cursor.removeXml();
1924 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1925 cursor.toParent();
1926 cursor.removeXml();
1927 }
1928 }
1929 cursor.dispose();
1930 }
1931
1932 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1933 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1934 if (o == null) {
1935 return;
1936 }
1937 XmlCursor cursor = o.newCursor();
1938 if (cursor.toFirstChild()) {
1939 for (int j = 0; j < i; ++j) {
1940 cursor.toNextSibling();
1941 }
1942 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1943 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1944 }
1945 cursor.dispose();
1946 }
1947
1948 public int getBuildOptionsUserDefAntTaskCount() {
1949 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1950 if (udats == null || udats.getAntTaskList() == null) {
1951 return 0;
1952 }
1953
1954 return udats.getAntTaskList().size();
1955 }
1956
1957 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1958 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1959 if (udats == null || udats.getAntTaskList() == null) {
1960 return ;
1961 }
1962
1963 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1964 ListIterator li = l.listIterator();
1965 int i = 0;
1966 while (li.hasNext()) {
1967 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1968 saa[i][0] = at.getId() + "";
1969 saa[i][1] = saa[i][2] = "";
1970 if (at.getFilename() != null){
1971 saa[i][1] = at.getFilename();
1972 }
1973 if (at.getAntCmdOptions() != null) {
1974 saa[i][2] = at.getAntCmdOptions();
1975 }
1976 ++i;
1977 }
1978 }
1979 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1980 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1981 if (opts == null) {
1982 opts = getfpdBuildOpts().addNewOptions();
1983 }
1984 OptionDocument.Option opt = opts.addNewOption();
1985 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1986 }
1987
1988 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1989 opt.setStringValue(contents);
1990
1991 opt.setBuildTargets(buildTargets);
1992 opt.setToolChainFamily(toolChain);
1993 opt.setTagName(tagName);
1994 opt.setToolCode(toolCmd);
1995
1996 if (archList != null) {
1997 opt.setSupArchList(archList);
1998 }
1999 else {
2000 if (opt.isSetSupArchList()) {
2001 opt.unsetSupArchList();
2002 }
2003 }
2004 }
2005
2006 public void removeBuildOptionsOpt(int i){
2007
2008 XmlObject o = getfpdBuildOpts().getOptions();
2009 if (o == null) {
2010 return;
2011 }
2012
2013 XmlCursor cursor = o.newCursor();
2014 if (cursor.toFirstChild()) {
2015 for (int j = 0; j < i; ++j) {
2016 cursor.toNextSibling();
2017 }
2018 cursor.removeXml();
2019 if (getBuildOptionsOptCount() == 0) {
2020 cursor.toParent();
2021 cursor.removeXml();
2022 }
2023 }
2024 cursor.dispose();
2025 }
2026
2027 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2028 XmlObject o = getfpdBuildOpts().getOptions();
2029 if (o == null) {
2030 return;
2031 }
2032
2033 XmlCursor cursor = o.newCursor();
2034 if (cursor.toFirstChild()) {
2035 for (int j = 0; j < i; ++j) {
2036 cursor.toNextSibling();
2037 }
2038 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
2039 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2040 }
2041 cursor.dispose();
2042 }
2043
2044 public int getBuildOptionsOptCount(){
2045 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2046 return 0;
2047 }
2048 return getfpdBuildOpts().getOptions().getOptionList().size();
2049 }
2050
2051 public void getBuildOptionsOpts(String[][] saa) {
2052 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2053 return ;
2054 }
2055
2056 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
2057 ListIterator li = lOpt.listIterator();
2058 int i = 0;
2059 while(li.hasNext()) {
2060 OptionDocument.Option opt = (OptionDocument.Option)li.next();
2061 if (opt.getBuildTargets() != null) {
2062 saa[i][0] = listToString(opt.getBuildTargets());
2063 }
2064 saa[i][1] = opt.getToolChainFamily();
2065 if (opt.getSupArchList() != null){
2066 saa[i][2] = listToString(opt.getSupArchList());
2067
2068 }
2069 saa[i][3] = opt.getToolCode();
2070 saa[i][4] = opt.getTagName();
2071 saa[i][5] = opt.getStringValue();
2072
2073 ++i;
2074 }
2075 }
2076
2077 public void genBuildOptionsFfs(String ffsKey, String type) {
2078 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2079 ffs.setFfsKey(ffsKey);
2080 if (type != null) {
2081 ffs.addNewSections().setEncapsulationType(type);
2082 }
2083 }
2084
2085 public void updateBuildOptionsFfsSectionsType(int i, String type) {
2086 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2087 if (type != null) {
2088 ffs.addNewSections().setEncapsulationType(type);
2089 }
2090 }
2091
2092 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2093 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2094 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2095 attrib.setName(name);
2096 attrib.setValue(value);
2097 }
2098
2099 /**update jth attribute of ith ffs.
2100 * @param i
2101 * @param j
2102 */
2103 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2104 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2105 XmlCursor cursor = ffs.newCursor();
2106 QName qAttrib = new QName(xmlNs, "Attribute");
2107 if (cursor.toChild(qAttrib)) {
2108 for (int k = 0; k < j; ++k) {
2109 cursor.toNextSibling(qAttrib);
2110 }
2111 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2112 attrib.setName(name);
2113 attrib.setValue(value);
2114 }
2115 cursor.dispose();
2116 }
2117
2118 public void removeBuildOptionsFfsAttribute(int i, int j){
2119 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2120 XmlCursor cursor = ffs.newCursor();
2121 QName qAttrib = new QName(xmlNs, "Attribute");
2122 if (cursor.toChild(qAttrib)) {
2123 for (int k = 0; k < j; ++k) {
2124 cursor.toNextSibling(qAttrib);
2125 }
2126 cursor.removeXml();
2127 }
2128 cursor.dispose();
2129 }
2130
2131 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2132 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2133 if (ffs == null) {
2134 return;
2135 }
2136 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2137
2138 if (sections == null){
2139 sections = ffs.addNewSections();
2140 }
2141 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2142 }
2143
2144 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2145 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2146 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2147 if (sections == null) {
2148 return;
2149 }
2150 XmlCursor cursor = sections.newCursor();
2151 QName qSection = new QName(xmlNs, "Section");
2152 if (cursor.toChild(qSection)) {
2153 for (int k = 0; k < j; ++k) {
2154 cursor.toNextSibling(qSection);
2155 }
2156 cursor.removeXml();
2157 }
2158 cursor.dispose();
2159 }
2160
2161 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2162 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2163 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2164 if (sections == null) {
2165 return;
2166 }
2167 XmlCursor cursor = sections.newCursor();
2168 QName qSection = new QName(xmlNs, "Section");
2169 if (cursor.toChild(qSection)) {
2170 for (int k = 0; k < j; ++k) {
2171 cursor.toNextSibling(qSection);
2172 }
2173 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2174 section.setSectionType(EfiSectionType.Enum.forString(type));
2175 }
2176 cursor.dispose();
2177 }
2178
2179 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2180 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2181 if (ffs == null) {
2182 return;
2183 }
2184 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2185
2186 if (sections == null){
2187 sections = ffs.addNewSections();
2188 }
2189 sections.addNewSections().setEncapsulationType(encapType);
2190 }
2191
2192 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2193 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2194 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2195 if (sections == null) {
2196 return;
2197 }
2198 XmlCursor cursor = sections.newCursor();
2199 QName qSections = new QName(xmlNs, "Sections");
2200 if (cursor.toChild(qSections)) {
2201 for (int k = 0; k < j; ++k) {
2202 cursor.toNextSibling(qSections);
2203 }
2204 cursor.removeXml();
2205 }
2206 cursor.dispose();
2207 }
2208
2209 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2210 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2211 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2212 if (sections == null) {
2213 return;
2214 }
2215 XmlCursor cursor = sections.newCursor();
2216 QName qSections = new QName(xmlNs, "Sections");
2217 if (cursor.toChild(qSections)) {
2218 for (int k = 0; k < j; ++k) {
2219 cursor.toNextSibling(qSections);
2220 }
2221 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2222 sections2.setEncapsulationType(type);
2223 }
2224 cursor.dispose();
2225 }
2226
2227 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2228 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2229 if (ffs == null) {
2230 return;
2231 }
2232 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2233 XmlCursor cursor = sections.newCursor();
2234 QName qSections = new QName(xmlNs, "Sections");
2235 if (cursor.toChild(qSections)){
2236 for (int k = 0; k < j; ++k) {
2237 cursor.toNextSibling(qSections);
2238 }
2239 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2240 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2241 }
2242 cursor.dispose();
2243 }
2244
2245 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2246 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2247 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2248 if (sections == null) {
2249 return;
2250 }
2251 XmlCursor cursor = sections.newCursor();
2252 QName qSections = new QName(xmlNs, "Sections");
2253 if (cursor.toChild(qSections)) {
2254 for (int l = 0; l < j; ++l) {
2255 cursor.toNextSibling(qSections);
2256 }
2257 if (cursor.toFirstChild()) {
2258 int m = 0;
2259 for (; m < k; ++m) {
2260 cursor.toNextSibling();
2261 }
2262 cursor.removeXml();
2263 if (m == 0) {
2264 cursor.toParent();
2265 cursor.removeXml();
2266 }
2267 }
2268 }
2269 cursor.dispose();
2270 }
2271
2272 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2273 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2274 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2275 if (sections == null) {
2276 return;
2277 }
2278 XmlCursor cursor = sections.newCursor();
2279 QName qSections = new QName(xmlNs, "Sections");
2280 if (cursor.toChild(qSections)) {
2281 for (int l = 0; l < j; ++l) {
2282 cursor.toNextSibling(qSections);
2283 }
2284 if (cursor.toFirstChild()) {
2285 for (int m = 0; m < k; ++m) {
2286 cursor.toNextSibling();
2287 }
2288 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2289 section.setSectionType(EfiSectionType.Enum.forString(type));
2290 }
2291 }
2292 cursor.dispose();
2293 }
2294
2295 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2296 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2297 if (ffs == null) {
2298 return;
2299 }
2300 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2301 XmlCursor cursor = sections.newCursor();
2302 QName qSections = new QName(xmlNs, "Sections");
2303 if (cursor.toChild(qSections)){
2304 for (int k = 0; k < j; ++k) {
2305 cursor.toNextSibling(qSections);
2306 }
2307 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2308 if (sections2.getSectionList() == null){
2309 cursor.dispose();
2310 return;
2311 }
2312 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2313 while(li.hasNext()) {
2314 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2315 if (section.isSetSectionType()) {
2316 al.add(section.getSectionType().toString());
2317 }
2318
2319 }
2320 }
2321 cursor.dispose();
2322
2323 }
2324
2325 public int getBuildOptionsFfsCount(){
2326 if (getfpdBuildOpts().getFfsList() == null) {
2327 return 0;
2328 }
2329 return getfpdBuildOpts().getFfsList().size();
2330 }
2331
2332 public void getBuildOptionsFfsKey(String[][] saa) {
2333 if (getfpdBuildOpts().getFfsList() == null) {
2334 return;
2335 }
2336 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2337 int i = 0;
2338 while(li.hasNext()){
2339 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2340 saa[i][0] = ffs.getFfsKey();
2341 ++i;
2342 }
2343 }
2344
2345 public void updateBuildOptionsFfsKey(int i, String key) {
2346 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2347 ffs.setFfsKey(key);
2348 }
2349
2350 /**Get ith FFS key and contents.
2351 * @param saa
2352 */
2353 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2354 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2355
2356 if (ffs != null) {
2357
2358 sa[0] = ffs.getFfsKey();
2359 if (ffs.getSections() != null) {
2360 if(ffs.getSections().getEncapsulationType() != null){
2361 sa[1] = ffs.getSections().getEncapsulationType();
2362 }
2363 if (ffs.getSections().getSectionList() != null){
2364 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2365 while (li.hasNext()) {
2366 firstLevelSection.add(li.next().getSectionType().toString());
2367 }
2368 }
2369 if (ffs.getSections().getSectionsList() != null) {
2370 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2371 while(li.hasNext()) {
2372 firstLevelSections.add(li.next().getEncapsulationType());
2373 }
2374 }
2375 }
2376 if (ffs.getAttributeList() != null) {
2377 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2378 while(li.hasNext()) {
2379 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2380 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2381 }
2382
2383 }
2384 }