2 Java class FpdFileContents is used to parse fpd xml file.
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
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.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
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
;
27 import javax
.xml
.namespace
.QName
;
29 import org
.apache
.xmlbeans
.XmlCursor
;
30 import org
.apache
.xmlbeans
.XmlObject
;
31 import org
.apache
.xmlbeans
.XmlOptions
;
32 import org
.tianocore
.AntTaskDocument
;
33 import org
.tianocore
.BuildOptionsDocument
;
34 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
35 import org
.tianocore
.EfiSectionType
;
36 import org
.tianocore
.FlashDefinitionFileDocument
;
37 import org
.tianocore
.FlashDocument
;
38 import org
.tianocore
.FrameworkModulesDocument
;
39 import org
.tianocore
.LibrariesDocument
;
40 import org
.tianocore
.ModuleSADocument
;
41 import org
.tianocore
.ModuleSurfaceAreaDocument
;
42 import org
.tianocore
.OptionDocument
;
43 import org
.tianocore
.OptionsDocument
;
44 import org
.tianocore
.PcdBuildDefinitionDocument
;
45 import org
.tianocore
.PcdCodedDocument
;
46 import org
.tianocore
.PcdDataTypes
;
47 import org
.tianocore
.PcdDeclarationsDocument
;
48 import org
.tianocore
.PcdItemTypes
;
49 import org
.tianocore
.PlatformDefinitionsDocument
;
50 import org
.tianocore
.PlatformSurfaceAreaDocument
;
51 import org
.tianocore
.FvImageTypes
;
52 import org
.tianocore
.FvImagesDocument
;
53 import org
.tianocore
.LicenseDocument
;
54 import org
.tianocore
.PlatformHeaderDocument
;
55 import org
.tianocore
.SkuInfoDocument
;
56 import org
.tianocore
.UserDefinedAntTasksDocument
;
57 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.GlobalData
;
58 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
59 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
60 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
63 This class processes fpd file contents such as add remove xml elements.
64 @since PackageEditor 1.0
66 public class FpdFileContents
{
68 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
70 private PlatformSurfaceAreaDocument fpdd
= null;
72 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
74 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
76 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
78 private FlashDocument
.Flash fpdFlash
= null;
80 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
82 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
84 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
86 public static HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
89 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
91 public void initDynPcdMap() {
92 if (dynPcdMap
== null) {
93 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
94 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
98 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
99 while (li
.hasNext()) {
100 ModuleSADocument
.ModuleSA msa
= li
.next();
101 if (msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null) {
104 String ModuleInfo
= msa
.getModuleGuid() + " " + msa
.getModuleVersion() +
105 " " + msa
.getPackageGuid() + " " + msa
.getPackageVersion();
106 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= msa
.getPcdBuildDefinition().getPcdDataList();
107 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
108 while (lpi
.hasNext()) {
109 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
110 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
111 if (dynPcdMap
.get(pcdKey
) == null) {
112 ArrayList
<String
> al
= new ArrayList
<String
>();
113 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
114 dynPcdMap
.put(pcdKey
, al
);
117 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
124 Constructor to create a new spd file
126 public FpdFileContents() {
128 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
129 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
134 Constructor for existing document object
137 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
139 fpdHdr
= fpdRoot
.getPlatformHeader();
140 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
141 fpdBuildOpts
= fpdRoot
.getBuildOptions();
142 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
143 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
144 fpdFlash
= fpdRoot
.getFlash();
148 Constructor based on an existing spd file
150 @param f Existing spd file
152 public FpdFileContents(File f
) {
154 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
155 fpdRoot
= fpdd
.getPlatformSurfaceArea();
156 } catch (Exception e
) {
157 System
.out
.println(e
.toString());
161 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
162 if (fpdDynPcdBuildDefs
== null){
163 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
165 return fpdDynPcdBuildDefs
;
168 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
169 if (fpdFrameworkModules
== null){
170 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
172 return fpdFrameworkModules
;
175 public int getPlatformDefsSkuInfoCount(){
176 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
179 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
182 public void getPlatformDefsSkuInfos(String
[][] saa
){
183 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
187 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
188 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
190 while(li
.hasNext()) {
191 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
192 saa
[i
][0] = sku
.getSkuID()+"";
193 saa
[i
][1] = sku
.getStringValue();
198 public int getFrameworkModulesCount() {
199 if (getfpdFrameworkModules().getModuleSAList() == null){
202 return getfpdFrameworkModules().getModuleSAList().size();
205 public void getFrameworkModulesInfo(String
[][] saa
) {
206 if (getFrameworkModulesCount() == 0){
210 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
212 while(li
.hasNext()) {
213 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
214 saa
[i
][1] = msa
.getModuleGuid();
215 saa
[i
][2] = msa
.getModuleVersion();
217 saa
[i
][3] = msa
.getPackageGuid();
218 saa
[i
][4] = msa
.getPackageVersion();
219 // saa[i][4] = listToString(msa.getSupArchList());
224 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
225 String
[] s
= key
.split(" ");
226 if (getfpdFrameworkModules().getModuleSAList() == null) {
229 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
230 while(li
.hasNext()) {
231 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
232 if (msa
.getModuleGuid().equals(s
[0]) && msa
.getModuleVersion().equals(s
[1])
233 && msa
.getPackageGuid().equals(s
[2]) && msa
.getPackageVersion().equals(s
[3])) {
240 public void removeModuleSA(int i
) {
241 XmlObject o
= getfpdFrameworkModules();
246 XmlCursor cursor
= o
.newCursor();
247 if (cursor
.toFirstChild()) {
248 for (int j
= 0; j
< i
; ++j
) {
249 cursor
.toNextSibling();
252 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
254 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
255 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
256 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion();
257 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
258 if (pcdBuildDef
!= null) {
259 maintainDynPcdMap(pcdBuildDef
, moduleInfo
);
266 private void maintainDynPcdMap(PcdBuildDefinitionDocument
.PcdBuildDefinition o
, String moduleInfo
) {
267 XmlCursor cursor
= o
.newCursor();
268 boolean fromLibInstance
= false;
269 if (!cursor
.toFirstChild()){
273 // deal with first child, same process in the while loop below for siblings.
275 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
276 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
277 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
278 for(int i
= 0; i
< al
.size(); ++i
){
279 if (al
.get(i
).startsWith(moduleInfo
)){
280 fromLibInstance
= true;
284 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
285 if (al
.size() == 0) {
286 dynPcdMap
.remove(pcdKey
);
289 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
290 if (dynPcdMap
.get(pcdKey
) == null) {
291 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
294 if (fromLibInstance
){
297 while(cursor
.toNextSibling()) {
298 fromLibInstance
= false;
299 pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
301 // remove each pcd record from dynPcdMap
303 pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
304 al
= dynPcdMap
.get(pcdKey
);
305 for(int i
= 0; i
< al
.size(); ++i
){
306 if (al
.get(i
).startsWith(moduleInfo
)){
307 fromLibInstance
= true;
311 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
312 if (al
.size() == 0) {
313 dynPcdMap
.remove(pcdKey
);
316 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
318 // First check whether this is the only consumer of this dyn pcd.
320 if (dynPcdMap
.get(pcdKey
) == null) {
322 // delete corresponding entry in DynamicPcdBuildData
324 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
327 if (fromLibInstance
){
333 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
335 public int getPcdDataCount(String key
){
336 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
337 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
340 return msa
.getPcdBuildDefinition().getPcdDataList().size();
343 public void getPcdData(String key
, String
[][] saa
) {
344 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
345 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
348 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
349 for (int i
= 0; i
< saa
.length
; ++i
) {
350 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
351 saa
[i
][0] = pcdData
.getCName();
352 saa
[i
][1] = pcdData
.getTokenSpaceGuidCName();
353 saa
[i
][2] = pcdData
.getItemType().toString();
354 saa
[i
][3] = pcdData
.getToken().toString();
355 saa
[i
][4] = pcdData
.getDatumType().toString();
356 saa
[i
][5] = pcdData
.getValue();
361 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
363 public int getLibraryInstancesCount(String key
) {
364 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
365 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
368 return msa
.getLibraries().getInstanceList().size();
371 public void getLibraryInstances(String key
, String
[][] saa
){
372 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
373 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
377 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
378 for (int i
= 0; i
< saa
.length
; ++i
) {
379 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
380 saa
[i
][1] = instance
.getModuleGuid();
381 saa
[i
][2] = instance
.getModuleVersion();
382 saa
[i
][3] = instance
.getPackageGuid();
383 saa
[i
][4] = instance
.getPackageVersion();
387 public void removeLibraryInstances(String key
) {
388 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
389 if (msa
== null || msa
.getLibraries() == null){
393 XmlCursor cursor
= msa
.getLibraries().newCursor();
398 public void genLibraryInstance(String mg
, String mv
, String pg
, String pv
, String key
) {
399 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
401 msa
= getfpdFrameworkModules().addNewModuleSA();
403 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
405 libs
= msa
.addNewLibraries();
408 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
409 instance
.setModuleGuid(mg
);
410 instance
.setModuleVersion(mv
);
411 instance
.setPackageGuid(pg
);
412 instance
.setPackageVersion(pv
);
415 /**add pcd information of module mi to a ModuleSA.
417 * @param moduleSa if null, generate a new ModuleSA.
419 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, ModuleSADocument
.ModuleSA moduleSa
){
420 //ToDo add Arch filter
423 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)GlobalData
.getModuleXmlObject(mi
);
424 if (msa
.getPcdCoded() == null) {
427 if (moduleSa
== null) {
428 moduleSa
= genModuleSA(mi
);
430 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
431 m
.put("ModuleSurfaceArea", msa
);
432 SurfaceAreaQuery
.setDoc(m
);
433 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null);
435 // Implementing InitializePlatformPcdBuildDefinitions
437 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
438 ListIterator li
= l
.listIterator();
439 while(li
.hasNext()) {
440 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
441 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
442 if (spdPcd
== null) {
449 // AddItem to ModuleSA PcdBuildDefinitions
451 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
452 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
462 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
464 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
465 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
466 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
467 m
.put("PackageSurfaceArea", GlobalData
.getPackageXmlObject(depPkgs
[i
]));
468 SurfaceAreaQuery
.setDoc(m
);
469 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations();
473 for (int j
= 0; j
< xo
.length
; ++j
) {
474 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
475 if (msaPcd
.getTokenSpaceGuidCName() == null) {
476 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
481 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
492 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
) {
493 PackageIdentification pi
= GlobalData
.getPackageForModule(mi
);
494 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
495 msa
.setModuleGuid(mi
.getGuid());
496 msa
.setModuleVersion(mi
.getVersion());
497 msa
.setPackageGuid(pi
.getGuid());
498 msa
.setPackageVersion(pi
.getVersion());
503 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
) {
504 if (moduleSa
.getPcdBuildDefinition() == null){
505 moduleSa
.addNewPcdBuildDefinition();
508 // constructe pcd to modulesa mapping first.
509 // Attention : for any error condition, remove from map this pcd.
511 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
512 if (pcdConsumer
== null) {
513 pcdConsumer
= new ArrayList
<String
>();
515 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
516 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion()
518 pcdConsumer
.add(listValue
);
519 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
521 // Special dynamic type, if this pcd already exists in other ModuleSA
523 if (itemType
.equals("DYNAMIC")) {
525 ListIterator li
= pcdConsumer
.listIterator();
526 while(li
.hasNext()) {
527 String value
= li
.next().toString();
528 String
[] valuePart
= value
.split(" ");
529 if (!valuePart
[4].equals("DYNAMIC")) {
530 //ToDo error for same pcd, other type than dynamic
531 pcdConsumer
.remove(listValue
);
537 ListIterator li
= pcdConsumer
.listIterator();
538 while(li
.hasNext()) {
539 String value
= li
.next().toString();
540 String
[] valuePart
= value
.split(" ");
541 if (valuePart
[4].equals("DYNAMIC")) {
542 //ToDo error for same pcd, other type than non-dynamic
543 pcdConsumer
.remove(listValue
);
549 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
550 fpdPcd
.setCName(cName
);
551 fpdPcd
.setToken(token
);
552 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
553 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
554 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
556 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
557 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
559 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
560 // so need to add one dyn pcd.
562 if (al
.size() == 1) {
563 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
567 if (defaultVal
!= null){
568 fpdPcd
.setValue(defaultVal
);
571 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
572 fpdPcd
.setValue("0");
574 if (dataType
.equals("BOOLEAN")){
575 fpdPcd
.setValue("false");
577 if (dataType
.equals("VOID*")) {
581 if (dataType
.equals("UINT8")){
582 fpdPcd
.setMaxDatumSize(1);
584 if (dataType
.equals("UINT16")) {
585 fpdPcd
.setMaxDatumSize(2);
587 if (dataType
.equals("UINT32")) {
588 fpdPcd
.setMaxDatumSize(4);
590 if (dataType
.equals("UINT64")){
591 fpdPcd
.setMaxDatumSize(8);
593 if (dataType
.equals("BOOLEAN")){
594 fpdPcd
.setMaxDatumSize(1);
596 if (dataType
.equals("VOID*")) {
597 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
598 fpdPcd
.setMaxDatumSize(maxSize
);
603 private int setMaxSizeForPointer(String datum
) {
607 char ch
= datum
.charAt(0);
611 // For void* type PCD, only three datum is support:
612 // 1) Unicode: string with start char is "L"
613 // 2) Ansci: String is ""
614 // 3) byte array: String start char "{"
617 start
= datum
.indexOf('\"');
618 end
= datum
.lastIndexOf('\"');
620 (end
> datum
.length())||
621 ((start
== end
) && (datum
.length() > 0))) {
622 //ToDo Error handling here
625 strValue
= datum
.substring(start
+ 1, end
);
626 return strValue
.length() * 2;
627 } else if (ch
== '\"'){
628 start
= datum
.indexOf('\"');
629 end
= datum
.lastIndexOf('\"');
631 (end
> datum
.length())||
632 ((start
== end
) && (datum
.length() > 0))) {
635 strValue
= datum
.substring(start
+ 1, end
);
636 return strValue
.length();
637 } else if (ch
=='{') {
638 String
[] strValueArray
;
640 start
= datum
.indexOf('{');
641 end
= datum
.lastIndexOf('}');
642 strValue
= datum
.substring(start
+ 1, end
);
643 strValue
= strValue
.trim();
644 if (strValue
.length() == 0) {
647 strValueArray
= strValue
.split(",");
648 for (int index
= 0; index
< strValueArray
.length
; index
++) {
649 Integer value
= Integer
.decode(strValueArray
[index
].trim());
652 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
653 // "it is byte array in fact. But the element of %s exceed the byte range",
657 return strValueArray
.length
;
661 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
662 // "1) UNICODE string: like L\"xxxx\";\r\n"+
663 // "2) ANSIC string: like \"xxx\";\r\n"+
664 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
665 // "but the datum in seems does not following above format!",
671 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
672 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
677 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
679 return dynPcdMap
.get("pcdKey");
682 public int getDynamicPcdBuildDataCount() {
683 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
686 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
689 public void getDynamicPcdBuildData(String
[][] saa
) {
690 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
693 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
694 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
696 while(li
.hasNext()) {
697 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
698 saa
[i
][0] = dynPcd
.getCName();
699 saa
[i
][1] = dynPcd
.getToken().toString();
700 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
701 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
702 saa
[i
][4] = dynPcd
.getDatumType().toString();
708 private void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
) {
709 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
710 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
711 dynPcdData
.setCName(cName
);
712 dynPcdData
.setToken(token
);
713 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
714 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
716 BigInteger bigInt
= new BigInteger("0");
717 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
718 skuInfo
.setSkuId(bigInt
);
719 if (defaultVal
!= null){
720 skuInfo
.setValue(defaultVal
);
723 if (dataType
.equals("UINT8")){
724 skuInfo
.setValue("0");
726 if (dataType
.equals("UINT16")) {
727 skuInfo
.setValue("0");
729 if (dataType
.equals("UINT32")) {
730 skuInfo
.setValue("0");
732 if (dataType
.equals("UINT64")){
733 skuInfo
.setValue("0");
735 if (dataType
.equals("BOOLEAN")){
736 skuInfo
.setValue("false");
738 if (dataType
.equals("VOID*")) {
739 skuInfo
.setValue("");
742 if (dataType
.equals("UINT8")){
743 dynPcdData
.setMaxDatumSize(1);
745 if (dataType
.equals("UINT16")) {
746 dynPcdData
.setMaxDatumSize(2);
748 if (dataType
.equals("UINT32")) {
749 dynPcdData
.setMaxDatumSize(4);
751 if (dataType
.equals("UINT64")){
752 dynPcdData
.setMaxDatumSize(8);
754 if (dataType
.equals("BOOLEAN")){
755 dynPcdData
.setMaxDatumSize(1);
757 if (dataType
.equals("VOID*")) {
758 int maxSize
= setMaxSizeForPointer(defaultVal
);
759 dynPcdData
.setMaxDatumSize(maxSize
);
763 private void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
764 XmlObject o
= getfpdDynPcdBuildDefs();
766 XmlCursor cursor
= o
.newCursor();
767 if (cursor
.toFirstChild()) {
768 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
769 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
770 while (!(pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
))) {
771 cursor
.toNextSibling();
772 pcdBuildData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
780 // Get the Sku Info count of ith dyn pcd element.
782 public int getDynamicPcdSkuInfoCount(int i
){
783 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
787 int skuInfoCount
= 0;
788 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
789 if (cursor
.toFirstChild()) {
790 for (int j
= 0; j
< i
; ++j
) {
791 cursor
.toNextSibling();
793 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
794 if (pcdData
.getSkuInfoList() == null) {
798 skuInfoCount
= pcdData
.getSkuInfoList().size();
805 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
806 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
810 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
811 if (cursor
.toFirstChild()) {
812 for (int j
= 0; j
< i
; ++j
) {
813 cursor
.toNextSibling();
815 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
816 if (pcdData
.getSkuInfoList() == null) {
821 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
823 while (li
.hasNext()) {
824 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
825 saa
[k
][0] = skuInfo
.getSkuId()+"";
826 saa
[k
][1] = skuInfo
.getVariableName();
827 saa
[k
][2] = skuInfo
.getVariableGuid();
828 saa
[k
][3] = skuInfo
.getVariableOffset();
829 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
830 saa
[k
][5] = skuInfo
.getVpdOffset();
831 saa
[k
][6] = skuInfo
.getValue();
841 public String
getDynamicPcdBuildDataValue(int i
){
843 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
847 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
848 if (cursor
.toFirstChild()) {
849 for (int j
= 0; j
< i
; ++j
) {
850 cursor
.toNextSibling();
852 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
853 if (pcdData
.getSkuInfoList() == null) {
857 value
= pcdData
.getSkuInfoArray(0).getValue();
864 public String
getDynamicPcdBuildDataVpdOffset(int i
){
865 String vpdOffset
= null;
866 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
870 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
871 if (cursor
.toFirstChild()) {
872 for (int j
= 0; j
< i
; ++j
) {
873 cursor
.toNextSibling();
875 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
876 if (pcdData
.getSkuInfoList() == null) {
880 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
887 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
888 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
892 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
893 if (cursor
.toFirstChild()) {
894 for (int j
= 0; j
< i
; ++j
) {
895 cursor
.toNextSibling();
897 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
898 if (pcdData
.getSkuInfoList() == null) {
903 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
904 cursor
.toChild(qSkuInfo
);
911 // generate sku info for ith dyn pcd build data.
913 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
914 String hiiDefault
, String vpdOffset
, String value
, int i
) {
915 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
919 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
920 if (cursor
.toFirstChild()) {
921 for (int j
= 0; j
< i
; ++j
) {
922 cursor
.toNextSibling();
924 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
925 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
926 skuInfo
.setSkuId(new BigInteger(id
));
927 if (varName
!= null){
928 skuInfo
.setVariableName(varName
);
929 skuInfo
.setVariableGuid(varGuid
);
930 skuInfo
.setVariableOffset(varOffset
);
931 skuInfo
.setHiiDefaultValue(hiiDefault
);
933 else if (vpdOffset
!= null){
934 skuInfo
.setVpdOffset(vpdOffset
);
937 skuInfo
.setValue(value
);
942 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
943 String hiiDefault
, String vpdOffset
, String value
, int i
){
944 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
948 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
949 if (cursor
.toFirstChild()) {
950 for (int j
= 0; j
< i
; ++j
) {
951 cursor
.toNextSibling();
953 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
954 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
955 while (li
.hasNext()) {
956 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
957 if (skuInfo
.getSkuId().toString().equals(id
)){
958 if (varName
!= null){
959 skuInfo
.setVariableName(varName
);
960 skuInfo
.setVariableGuid(varGuid
);
961 skuInfo
.setVariableOffset(varOffset
);
962 skuInfo
.setHiiDefaultValue(hiiDefault
);
964 else if (vpdOffset
!= null){
965 skuInfo
.setVpdOffset(vpdOffset
);
968 skuInfo
.setValue(value
);
976 public void removePcdDataFromLibraryInstance(String moduleKey
, String libInstanceKey
){
977 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
979 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
981 maintainDynPcdMap(moduleSa
.getPcdBuildDefinition(), libInstanceKey
);
985 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
986 if (fpdBuildOpts
== null) {
987 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
992 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
993 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
995 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
998 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
999 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1002 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1003 at
.setId(new Integer(id
));
1004 if (fileName
!= null){
1005 at
.setFilename(fileName
);
1007 if (execOrder
!= null) {
1008 at
.setAntCmdOptions(execOrder
);
1012 public void removeBuildOptionsUserDefAntTask(int i
) {
1013 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1017 XmlCursor cursor
= o
.newCursor();
1018 if (cursor
.toFirstChild()) {
1019 for (int j
= 0; j
< i
; ++j
) {
1020 cursor
.toNextSibling();
1027 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1028 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1032 XmlCursor cursor
= o
.newCursor();
1033 if (cursor
.toFirstChild()) {
1034 for (int j
= 0; j
< i
; ++j
) {
1035 cursor
.toNextSibling();
1037 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1038 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1043 public int getBuildOptionsUserDefAntTaskCount() {
1044 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1045 if (udats
== null || udats
.getAntTaskList() == null) {
1049 return udats
.getAntTaskList().size();
1052 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1053 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1054 if (udats
== null || udats
.getAntTaskList() == null) {
1058 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1059 ListIterator li
= l
.listIterator();
1061 while (li
.hasNext()) {
1062 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1063 saa
[i
][0] = at
.getId() + "";
1064 saa
[i
][1] = saa
[i
][2] = "";
1065 if (at
.getFilename() != null){
1066 saa
[i
][1] = at
.getFilename();
1068 if (at
.getAntCmdOptions() != null) {
1069 saa
[i
][2] = at
.getAntCmdOptions();
1074 public void genBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1075 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1077 opts
= getfpdBuildOpts().addNewOptions();
1079 OptionDocument
.Option opt
= opts
.addNewOption();
1080 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1083 private void setBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
, OptionDocument
.Option opt
){
1084 opt
.setStringValue(contents
);
1085 // opt.setBuildTargets(buildTargets);
1086 opt
.setToolChainFamily(toolChain
);
1087 opt
.setTagName(tagName
);
1088 opt
.setToolCode(toolCmd
);
1089 String
[] s
= archList
.split(" ");
1090 ArrayList
<String
> al
= new ArrayList
<String
>();
1091 for (int i
= 0; i
< s
.length
; ++i
) {
1094 opt
.setSupArchList(al
);
1097 public void removeBuildOptionsOpt(int i
){
1099 XmlObject o
= getfpdBuildOpts().getOptions();
1104 XmlCursor cursor
= o
.newCursor();
1105 if (cursor
.toFirstChild()) {
1106 for (int j
= 0; j
< i
; ++j
) {
1107 cursor
.toNextSibling();
1114 public void updateBuildOptionsOpt(int i
, String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1115 XmlObject o
= getfpdBuildOpts().getOptions();
1120 XmlCursor cursor
= o
.newCursor();
1121 if (cursor
.toFirstChild()) {
1122 for (int j
= 0; j
< i
; ++j
) {
1123 cursor
.toNextSibling();
1125 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1126 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1131 public int getBuildOptionsOptCount(){
1132 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1135 return getfpdBuildOpts().getOptions().getOptionList().size();
1138 public void getBuildOptionsOpts(String
[][] saa
) {
1139 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1143 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1144 ListIterator li
= lOpt
.listIterator();
1146 while(li
.hasNext()) {
1147 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1148 if (opt
.getBuildTargets() != null) {
1149 saa
[i
][0] = listToString(opt
.getBuildTargets());
1151 saa
[i
][1] = opt
.getToolChainFamily();
1152 if (opt
.getSupArchList() != null){
1153 saa
[i
][2] = listToString(opt
.getSupArchList());
1156 saa
[i
][3] = opt
.getToolCode();
1157 saa
[i
][4] = opt
.getTagName();
1158 saa
[i
][5] = opt
.getStringValue();
1164 public void genBuildOptionsFfs(String ffsKey
, String type
) {
1165 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
1166 ffs
.setFfsKey(ffsKey
);
1168 ffs
.addNewSections().setEncapsulationType(type
);
1172 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
1173 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
1175 ffs
.addNewSections().setEncapsulationType(type
);
1179 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
1180 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1181 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
1182 attrib
.setName(name
);
1183 attrib
.setValue(value
);
1186 /**update jth attribute of ith ffs.
1190 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
1191 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1192 XmlCursor cursor
= ffs
.newCursor();
1193 QName qAttrib
= new QName(xmlNs
, "Attribute");
1194 if (cursor
.toChild(qAttrib
)) {
1195 for (int k
= 0; k
< j
; ++k
) {
1196 cursor
.toNextSibling(qAttrib
);
1198 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
1199 attrib
.setName(name
);
1200 attrib
.setValue(value
);
1205 public void removeBuildOptionsFfsAttribute(int i
, int j
){
1206 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1207 XmlCursor cursor
= ffs
.newCursor();
1208 QName qAttrib
= new QName(xmlNs
, "Attribute");
1209 if (cursor
.toChild(qAttrib
)) {
1210 for (int k
= 0; k
< j
; ++k
) {
1211 cursor
.toNextSibling(qAttrib
);
1218 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
1219 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1223 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1225 if (sections
== null){
1226 sections
= ffs
.addNewSections();
1228 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
1231 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
1232 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1233 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1234 if (sections
== null) {
1237 XmlCursor cursor
= sections
.newCursor();
1238 QName qSection
= new QName(xmlNs
, "Section");
1239 if (cursor
.toChild(qSection
)) {
1240 for (int k
= 0; k
< j
; ++k
) {
1241 cursor
.toNextSibling(qSection
);
1248 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
1249 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1250 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1251 if (sections
== null) {
1254 XmlCursor cursor
= sections
.newCursor();
1255 QName qSection
= new QName(xmlNs
, "Section");
1256 if (cursor
.toChild(qSection
)) {
1257 for (int k
= 0; k
< j
; ++k
) {
1258 cursor
.toNextSibling(qSection
);
1260 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
1261 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
1266 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
1267 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1271 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1273 if (sections
== null){
1274 sections
= ffs
.addNewSections();
1276 sections
.addNewSections().setEncapsulationType(encapType
);
1279 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
1280 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1281 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1282 if (sections
== null) {
1285 XmlCursor cursor
= sections
.newCursor();
1286 QName qSections
= new QName(xmlNs
, "Sections");
1287 if (cursor
.toChild(qSections
)) {
1288 for (int k
= 0; k
< j
; ++k
) {
1289 cursor
.toNextSibling(qSections
);
1296 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
1297 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1298 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1299 if (sections
== null) {
1302 XmlCursor cursor
= sections
.newCursor();
1303 QName qSections
= new QName(xmlNs
, "Sections");
1304 if (cursor
.toChild(qSections
)) {
1305 for (int k
= 0; k
< j
; ++k
) {
1306 cursor
.toNextSibling(qSections
);
1308 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
1309 sections2
.setEncapsulationType(type
);
1314 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
1315 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1319 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1320 XmlCursor cursor
= sections
.newCursor();
1321 QName qSections
= new QName(xmlNs
, "Sections");
1322 if (cursor
.toChild(qSections
)){
1323 for (int k
= 0; k
< j
; ++k
) {
1324 cursor
.toNextSibling(qSections
);
1326 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
1327 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
1332 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
1333 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1334 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1335 if (sections
== null) {
1338 XmlCursor cursor
= sections
.newCursor();
1339 QName qSections
= new QName(xmlNs
, "Sections");
1340 if (cursor
.toChild(qSections
)) {
1341 for (int l
= 0; l
< j
; ++l
) {
1342 cursor
.toNextSibling(qSections
);
1344 if (cursor
.toFirstChild()) {
1345 for (int m
= 0; m
< k
; ++m
) {
1346 cursor
.toNextSibling();
1354 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
1355 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1356 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1357 if (sections
== null) {
1360 XmlCursor cursor
= sections
.newCursor();
1361 QName qSections
= new QName(xmlNs
, "Sections");
1362 if (cursor
.toChild(qSections
)) {
1363 for (int l
= 0; l
< j
; ++l
) {
1364 cursor
.toNextSibling(qSections
);
1366 if (cursor
.toFirstChild()) {
1367 for (int m
= 0; m
< k
; ++m
) {
1368 cursor
.toNextSibling();
1370 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
1371 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
1377 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
1378 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1382 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
1383 XmlCursor cursor
= sections
.newCursor();
1384 QName qSections
= new QName(xmlNs
, "Sections");
1385 if (cursor
.toChild(qSections
)){
1386 for (int k
= 0; k
< j
; ++k
) {
1387 cursor
.toNextSibling(qSections
);
1389 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
1390 if (sections2
.getSectionList() == null){
1394 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
1395 while(li
.hasNext()) {
1396 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
1397 if (section
.isSetSectionType()) {
1398 al
.add(section
.getSectionType().toString());
1407 public int getBuildOptionsFfsCount(){
1408 if (getfpdBuildOpts().getFfsList() == null) {
1411 return getfpdBuildOpts().getFfsList().size();
1414 public void getBuildOptionsFfsKey(String
[][] saa
) {
1415 if (getfpdBuildOpts().getFfsList() == null) {
1418 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
1420 while(li
.hasNext()){
1421 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
1422 saa
[i
][0] = ffs
.getFfsKey();
1427 public void updateBuildOptionsFfsKey(int i
, String key
) {
1428 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1432 /**Get ith FFS key and contents.
1435 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
1436 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1440 sa
[0] = ffs
.getFfsKey();
1441 if (ffs
.getSections() != null) {
1442 if(ffs
.getSections().getEncapsulationType() != null){
1443 sa
[1] = ffs
.getSections().getEncapsulationType();
1445 if (ffs
.getSections().getSectionList() != null){
1446 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
1447 while (li
.hasNext()) {
1448 firstLevelSection
.add(li
.next().getSectionType().toString());
1451 if (ffs
.getSections().getSectionsList() != null) {
1452 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
1453 while(li
.hasNext()) {
1454 firstLevelSections
.add(li
.next().getEncapsulationType());
1458 if (ffs
.getAttributeList() != null) {
1459 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
1460 while(li
.hasNext()) {
1461 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
1462 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
1471 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
1472 XmlObject o
= getfpdBuildOpts();
1473 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
1475 XmlCursor cursor
= o
.newCursor();
1476 QName qFfs
= new QName(xmlNs
, "Ffs");
1477 if (cursor
.toChild(qFfs
)) {
1478 for (int j
= 0; j
< i
; ++j
) {
1479 cursor
.toNextSibling(qFfs
);
1481 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
1487 public void removeBuildOptionsFfs(int i
) {
1488 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
1493 XmlCursor cursor
= ffs
.newCursor();
1500 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
1501 if (fpdPlatformDefs
== null){
1502 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
1504 return fpdPlatformDefs
;
1507 public FlashDocument
.Flash
getfpdFlash() {
1508 if (fpdFlash
== null) {
1509 fpdFlash
= fpdRoot
.addNewFlash();
1514 public void genFlashDefinitionFile(String file
) {
1515 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1517 fdf
= getfpdFlash().addNewFlashDefinitionFile();
1520 fdf
.setStringValue(file
);
1523 public String
getFlashDefinitionFile() {
1524 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1529 return fdf
.getStringValue();
1534 public void genFvImagesNameValue(String name
, String value
) {
1536 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1538 fi
= getfpdFlash().addNewFvImages();
1541 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
1546 public void removeFvImagesNameValue(int i
){
1548 XmlObject o
= getfpdFlash().getFvImages();
1553 QName qNameValue
= new QName(xmlNs
, "NameValue");
1554 XmlCursor cursor
= o
.newCursor();
1555 if (cursor
.toChild(qNameValue
)) {
1556 for (int j
= 0; j
< i
; ++j
) {
1557 cursor
.toNextSibling(qNameValue
);
1564 public void updateFvImagesNameValue(int i
, String name
, String value
){
1566 XmlObject o
= getfpdFlash().getFvImages();
1571 QName qNameValue
= new QName(xmlNs
, "NameValue");
1572 XmlCursor cursor
= o
.newCursor();
1573 if (cursor
.toChild(qNameValue
)) {
1574 for (int j
= 0; j
< i
; ++j
) {
1575 cursor
.toNextSibling(qNameValue
);
1577 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
1584 public int getFvImagesNameValueCount() {
1586 FvImagesDocument
.FvImages fi
= null;
1587 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
1590 return fi
.getNameValueList().size();
1593 public void getFvImagesNameValues(String
[][] nv
) {
1595 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1599 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
1601 ListIterator li
= l
.listIterator();
1602 while (li
.hasNext()) {
1603 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
1605 nv
[i
][0] = e
.getName();
1606 nv
[i
][1] = e
.getValue();
1612 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
1614 FvImagesDocument
.FvImages fis
= null;
1615 if ((fis
= getfpdFlash().getFvImages()) == null) {
1616 fis
= getfpdFlash().addNewFvImages();
1620 //gen FvImage with FvImageNames array
1622 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
1623 for (int i
= 0; i
< names
.length
; ++i
) {
1624 fi
.addFvImageNames(names
[i
]);
1626 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1627 if (options
!= null){
1628 setFvImagesFvImageFvImageOptions(options
, fi
);
1632 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
1633 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
1635 fio
= fi
.addNewFvImageOptions();
1638 Set
<String
> key
= options
.keySet();
1639 Iterator
<String
> i
= key
.iterator();
1640 while (i
.hasNext()) {
1642 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
1643 String k
= (String
)i
.next();
1646 nv
.setValue((String
)options
.get(k
));
1653 public void removeFvImagesFvImage(int i
) {
1655 XmlObject o
= getfpdFlash().getFvImages();
1660 QName qFvImage
= new QName(xmlNs
, "FvImage");
1661 XmlCursor cursor
= o
.newCursor();
1662 if (cursor
.toChild(qFvImage
)) {
1663 for (int j
= 0; j
< i
; ++j
) {
1664 cursor
.toNextSibling(qFvImage
);
1671 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
1673 XmlObject o
= getfpdFlash().getFvImages();
1677 XmlCursor cursor
= o
.newCursor();
1678 QName qFvImage
= new QName(xmlNs
, "FvImage");
1679 if (cursor
.toChild(qFvImage
)) {
1680 for (int j
= 0; j
< i
; ++j
) {
1681 cursor
.toNextSibling(qFvImage
);
1683 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1684 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1687 // remove old FvImageNames before adding new ones
1689 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
1690 cursor
.toChild(qFvImageNames
);
1692 while (cursor
.toNextSibling(qFvImageNames
)) {
1696 for (int k
= 0; k
< names
.length
; ++k
) {
1697 fi
.addFvImageNames(names
[k
]);
1700 // remove old FvImageOptions before adding new options
1702 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
1703 cursor
.toNextSibling(qFvImageOptions
);
1706 setFvImagesFvImageFvImageOptions(options
, fi
);
1711 public int getFvImagesFvImageCount() {
1713 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1716 return getfpdFlash().getFvImages().getFvImageList().size();
1719 /**Only Get Fv image setting - name and type.
1722 public void getFvImagesFvImages(String
[][] saa
) {
1724 if (getfpdFlash().getFvImages() == null) {
1727 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
1731 ListIterator li
= l
.listIterator();
1733 while(li
.hasNext()) {
1734 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
1736 // get FvImageNames array, space separated
1738 List
<String
> lfn
= fi
.getFvImageNamesList();
1739 ListIterator lfni
= lfn
.listIterator();
1741 while (lfni
.hasNext()) {
1742 saa
[i
][0] += (String
)lfni
.next();
1745 saa
[i
][0] = saa
[i
][0].trim();
1747 saa
[i
][1] = fi
.getType()+"";
1753 /**Get FvImage Options for FvImage i
1754 * @param i the ith FvImage
1756 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
1757 XmlObject o
= getfpdFlash().getFvImages();
1761 XmlCursor cursor
= o
.newCursor();
1762 QName qFvImage
= new QName(xmlNs
, "FvImage");
1763 if (cursor
.toChild(qFvImage
)) {
1764 for (int j
= 0; j
< i
; ++j
) {
1765 cursor
.toNextSibling(qFvImage
);
1767 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1768 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
1771 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
1772 while(li
.hasNext()){
1773 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
1774 m
.put(nv
.getName(), nv
.getValue());
1780 Get platform header element
1781 @return PlatformHeaderDocument.PlatformHeader
1783 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
1784 if (fpdHdr
== null) {
1785 fpdHdr
= fpdRoot
.addNewPlatformHeader();
1787 genPlatformDefsSkuInfo("0", "DEFAULT");
1791 public void genPlatformDefsSkuInfo(String id
, String name
) {
1792 SkuInfoDocument
.SkuInfo skuInfo
= null;
1793 if (getfpdPlatformDefs().getSkuInfo() == null) {
1794 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
1796 skuInfo
= getfpdPlatformDefs().getSkuInfo();
1797 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
1798 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1799 skuName
.setSkuID(new BigInteger("0"));
1800 skuName
.setStringValue("DEFAULT");
1802 if (id
.equals("0")) {
1805 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1806 skuName
.setSkuID(new BigInteger(id
));
1807 skuName
.setStringValue(name
);
1811 public String
getFpdHdrPlatformName() {
1812 return getFpdHdr().getPlatformName();
1815 public String
getFpdHdrGuidValue() {
1816 return getFpdHdr().getGuidValue();
1819 public String
getFpdHdrVer() {
1820 return getFpdHdr().getVersion();
1823 public String
getFpdHdrAbs() {
1824 return getFpdHdr().getAbstract();
1827 public String
getFpdHdrDescription() {
1828 return getFpdHdr().getDescription();
1831 public String
getFpdHdrCopyright() {
1832 return getFpdHdr().getCopyright();
1835 public String
getFpdHdrLicense() {
1836 LicenseDocument
.License l
= getFpdHdr().getLicense();
1840 return l
.getStringValue();
1843 public String
getFpdHdrUrl() {
1844 LicenseDocument
.License l
= getFpdHdr().getLicense();
1851 public String
getFpdHdrSpec() {
1853 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1854 // return getFpdHdr().getSpecification();
1857 public void setFpdHdrPlatformName(String name
){
1858 getFpdHdr().setPlatformName(name
);
1861 public void setFpdHdrGuidValue(String guid
){
1862 getFpdHdr().setGuidValue(guid
);
1865 public void setFpdHdrVer(String v
){
1866 getFpdHdr().setVersion(v
);
1869 public void setFpdHdrAbs(String abs
) {
1870 getFpdHdr().setAbstract(abs
);
1873 public void setFpdHdrDescription(String desc
){
1874 getFpdHdr().setDescription(desc
);
1877 public void setFpdHdrCopyright(String cr
) {
1878 getFpdHdr().setCopyright(cr
);
1881 public void setFpdHdrLicense(String license
){
1882 LicenseDocument
.License l
= getFpdHdr().getLicense();
1884 getFpdHdr().addNewLicense().setStringValue(license
);
1887 l
.setStringValue(license
);
1891 public void setFpdHdrUrl(String url
){
1892 LicenseDocument
.License l
= getFpdHdr().getLicense();
1898 public void setFpdHdrSpec(String s
){
1899 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1900 getFpdHdr().setSpecification(s
);
1903 Save the processed xml contents to file
1905 @param fpdFile The file to save xml contents
1906 @throws IOException Exceptions during file operation
1908 public void saveAs(File fpdFile
) throws IOException
{
1910 XmlOptions options
= new XmlOptions();
1912 options
.setCharacterEncoding("UTF-8");
1913 options
.setSavePrettyPrint();
1914 options
.setSavePrettyPrintIndent(2);
1916 fpdd
.save(fpdFile
, options
);
1917 } catch (IOException e
) {
1918 e
.printStackTrace();
1923 private String
listToString(List
<String
> l
) {
1928 ListIterator li
= l
.listIterator();
1929 while(li
.hasNext()) {