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