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