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