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