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
.FlashDefinitionFileDocument
;
36 import org
.tianocore
.FlashDeviceDefinitionsDocument
;
37 import org
.tianocore
.FlashDocument
;
38 import org
.tianocore
.FrameworkModulesDocument
;
39 import org
.tianocore
.FvRegionNameDocument
;
40 import org
.tianocore
.LibrariesDocument
;
41 import org
.tianocore
.ModuleSADocument
;
42 import org
.tianocore
.ModuleSurfaceAreaDocument
;
43 import org
.tianocore
.OptionDocument
;
44 import org
.tianocore
.OptionsDocument
;
45 import org
.tianocore
.PcdBuildDefinitionDocument
;
46 import org
.tianocore
.PcdCodedDocument
;
47 import org
.tianocore
.PcdDataTypes
;
48 import org
.tianocore
.PcdDeclarationsDocument
;
49 import org
.tianocore
.PcdItemTypes
;
50 import org
.tianocore
.PlatformDefinitionsDocument
;
51 import org
.tianocore
.PlatformSurfaceAreaDocument
;
52 import org
.tianocore
.FvImageTypes
;
53 import org
.tianocore
.FvImagesDocument
;
54 import org
.tianocore
.LicenseDocument
;
55 import org
.tianocore
.PlatformHeaderDocument
;
56 import org
.tianocore
.SkuInfoDocument
;
57 import org
.tianocore
.UserDefinedAntTasksDocument
;
58 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.GlobalData
;
59 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
60 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
64 This class processes fpd file contents such as add remove xml elements.
65 @since PackageEditor 1.0
67 public class FpdFileContents
{
69 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
71 private PlatformSurfaceAreaDocument fpdd
= null;
73 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
75 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
77 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
79 private FlashDocument
.Flash fpdFlash
= null;
81 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
83 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
85 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
87 public static HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
90 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
92 public void initDynPcdMap() {
93 if (dynPcdMap
== null) {
94 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
95 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
99 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
100 while (li
.hasNext()) {
101 ModuleSADocument
.ModuleSA msa
= li
.next();
102 if (msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null) {
105 String ModuleInfo
= msa
.getModuleGuid() + " " + msa
.getModuleVersion() +
106 " " + msa
.getPackageGuid() + " " + msa
.getPackageVersion();
107 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= msa
.getPcdBuildDefinition().getPcdDataList();
108 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
109 while (lpi
.hasNext()) {
110 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
111 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
112 if (dynPcdMap
.get(pcdKey
) == null) {
113 ArrayList
<String
> al
= new ArrayList
<String
>();
114 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
115 dynPcdMap
.put(pcdKey
, al
);
118 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
125 Constructor to create a new spd file
127 public FpdFileContents() {
129 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
130 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
135 Constructor for existing document object
138 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
140 fpdHdr
= fpdRoot
.getPlatformHeader();
141 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
142 fpdBuildOpts
= fpdRoot
.getBuildOptions();
143 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
144 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
145 fpdFlash
= fpdRoot
.getFlash();
149 Constructor based on an existing spd file
151 @param f Existing spd file
153 public FpdFileContents(File f
) {
155 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
156 fpdRoot
= fpdd
.getPlatformSurfaceArea();
157 } catch (Exception e
) {
158 System
.out
.println(e
.toString());
162 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
163 if (fpdDynPcdBuildDefs
== null){
164 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
166 return fpdDynPcdBuildDefs
;
169 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
170 if (fpdFrameworkModules
== null){
171 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
173 return fpdFrameworkModules
;
176 public int getPlatformDefsSkuInfoCount(){
177 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
180 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
183 public void getPlatformDefsSkuInfos(String
[][] saa
){
184 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
188 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
189 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
191 while(li
.hasNext()) {
192 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
193 saa
[i
][0] = sku
.getSkuID()+"";
194 saa
[i
][1] = sku
.getStringValue();
199 public int getFrameworkModulesCount() {
200 if (getfpdFrameworkModules().getModuleSAList() == null){
203 return getfpdFrameworkModules().getModuleSAList().size();
206 public void getFrameworkModulesInfo(String
[][] saa
) {
207 if (getFrameworkModulesCount() == 0){
211 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
213 while(li
.hasNext()) {
214 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
215 saa
[i
][1] = msa
.getModuleGuid();
216 saa
[i
][2] = msa
.getModuleVersion();
218 saa
[i
][3] = msa
.getPackageGuid();
219 saa
[i
][4] = msa
.getPackageVersion();
220 // saa[i][4] = listToString(msa.getSupArchList());
225 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
226 String
[] s
= key
.split(" ");
227 if (getfpdFrameworkModules().getModuleSAList() == null) {
230 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
231 while(li
.hasNext()) {
232 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
233 if (msa
.getModuleGuid().equals(s
[0]) && msa
.getModuleVersion().equals(s
[1])
234 && msa
.getPackageGuid().equals(s
[2]) && msa
.getPackageVersion().equals(s
[3])) {
241 public void removeModuleSA(int i
) {
242 XmlObject o
= getfpdFrameworkModules();
247 XmlCursor cursor
= o
.newCursor();
248 if (cursor
.toFirstChild()) {
249 for (int j
= 0; j
< i
; ++j
) {
250 cursor
.toNextSibling();
253 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
255 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
256 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
257 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion();
258 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
259 if (pcdBuildDef
!= null) {
260 maintainDynPcdMap(pcdBuildDef
, moduleInfo
);
267 private void maintainDynPcdMap(PcdBuildDefinitionDocument
.PcdBuildDefinition o
, String moduleInfo
) {
268 XmlCursor cursor
= o
.newCursor();
269 boolean fromLibInstance
= false;
270 if (!cursor
.toFirstChild()){
274 // deal with first child, same process in the while loop below for siblings.
276 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
277 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
278 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
279 for(int i
= 0; i
< al
.size(); ++i
){
280 if (al
.get(i
).startsWith(moduleInfo
)){
281 fromLibInstance
= true;
285 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
286 if (al
.size() == 0) {
287 dynPcdMap
.remove(pcdKey
);
290 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
291 if (dynPcdMap
.get(pcdKey
) == null) {
292 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
295 if (fromLibInstance
){
298 while(cursor
.toNextSibling()) {
299 fromLibInstance
= false;
300 pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
302 // remove each pcd record from dynPcdMap
304 pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
305 al
= dynPcdMap
.get(pcdKey
);
306 for(int i
= 0; i
< al
.size(); ++i
){
307 if (al
.get(i
).startsWith(moduleInfo
)){
308 fromLibInstance
= true;
312 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
313 if (al
.size() == 0) {
314 dynPcdMap
.remove(pcdKey
);
317 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
319 // First check whether this is the only consumer of this dyn pcd.
321 if (dynPcdMap
.get(pcdKey
) == null) {
323 // delete corresponding entry in DynamicPcdBuildData
325 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
328 if (fromLibInstance
){
334 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
336 public int getPcdDataCount(String key
){
337 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
338 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
341 return msa
.getPcdBuildDefinition().getPcdDataList().size();
344 public void getPcdData(String key
, String
[][] saa
) {
345 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
346 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
349 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
350 for (int i
= 0; i
< saa
.length
; ++i
) {
351 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
352 saa
[i
][0] = pcdData
.getCName();
353 saa
[i
][1] = pcdData
.getTokenSpaceGuidCName();
354 saa
[i
][2] = pcdData
.getItemType().toString();
355 saa
[i
][3] = pcdData
.getToken().toString();
356 saa
[i
][4] = pcdData
.getDatumType().toString();
357 saa
[i
][5] = pcdData
.getValue();
362 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
364 public int getLibraryInstancesCount(String key
) {
365 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
366 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
369 return msa
.getLibraries().getInstanceList().size();
372 public void getLibraryInstances(String key
, String
[][] saa
){
373 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
374 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
378 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
379 for (int i
= 0; i
< saa
.length
; ++i
) {
380 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
381 saa
[i
][1] = instance
.getModuleGuid();
382 saa
[i
][2] = instance
.getModuleVersion();
383 saa
[i
][3] = instance
.getPackageGuid();
384 saa
[i
][4] = instance
.getPackageVersion();
388 public void removeLibraryInstances(String key
) {
389 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
390 if (msa
== null || msa
.getLibraries() == null){
394 XmlCursor cursor
= msa
.getLibraries().newCursor();
399 public void genLibraryInstance(String mg
, String mv
, String pg
, String pv
, String key
) {
400 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
402 msa
= getfpdFrameworkModules().addNewModuleSA();
404 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
406 libs
= msa
.addNewLibraries();
409 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
410 instance
.setModuleGuid(mg
);
411 instance
.setModuleVersion(mv
);
412 instance
.setPackageGuid(pg
);
413 instance
.setPackageVersion(pv
);
416 /**add pcd information of module mi to a ModuleSA.
418 * @param moduleSa if null, generate a new ModuleSA.
420 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, ModuleSADocument
.ModuleSA moduleSa
){
421 //ToDo add Arch filter
424 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)GlobalData
.getModuleXmlObject(mi
);
425 if (msa
.getPcdCoded() == null) {
428 if (moduleSa
== null) {
429 moduleSa
= genModuleSA(mi
);
431 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
432 m
.put("ModuleSurfaceArea", msa
);
433 SurfaceAreaQuery
.setDoc(m
);
434 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null);
436 // Implementing InitializePlatformPcdBuildDefinitions
438 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
439 ListIterator li
= l
.listIterator();
440 while(li
.hasNext()) {
441 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
442 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
443 if (spdPcd
== null) {
450 // AddItem to ModuleSA PcdBuildDefinitions
452 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
453 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
463 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
465 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
466 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
467 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
468 m
.put("PackageSurfaceArea", GlobalData
.getPackageXmlObject(depPkgs
[i
]));
469 SurfaceAreaQuery
.setDoc(m
);
470 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations();
474 for (int j
= 0; j
< xo
.length
; ++j
) {
475 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
476 if (msaPcd
.getTokenSpaceGuidCName() == null) {
477 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
482 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
493 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
) {
494 PackageIdentification pi
= GlobalData
.getPackageForModule(mi
);
495 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
496 msa
.setModuleGuid(mi
.getGuid());
497 msa
.setModuleVersion(mi
.getVersion());
498 msa
.setPackageGuid(pi
.getGuid());
499 msa
.setPackageVersion(pi
.getVersion());
504 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
) {
505 if (moduleSa
.getPcdBuildDefinition() == null){
506 moduleSa
.addNewPcdBuildDefinition();
509 // constructe pcd to modulesa mapping first.
510 // Attention : for any error condition, remove from map this pcd.
512 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
513 if (pcdConsumer
== null) {
514 pcdConsumer
= new ArrayList
<String
>();
516 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
517 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion()
519 pcdConsumer
.add(listValue
);
520 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
522 // Special dynamic type, if this pcd already exists in other ModuleSA
524 if (itemType
.equals("DYNAMIC")) {
526 ListIterator li
= pcdConsumer
.listIterator();
527 while(li
.hasNext()) {
528 String value
= li
.next().toString();
529 String
[] valuePart
= value
.split(" ");
530 if (!valuePart
[4].equals("DYNAMIC")) {
531 //ToDo error for same pcd, other type than dynamic
532 pcdConsumer
.remove(listValue
);
538 ListIterator li
= pcdConsumer
.listIterator();
539 while(li
.hasNext()) {
540 String value
= li
.next().toString();
541 String
[] valuePart
= value
.split(" ");
542 if (valuePart
[4].equals("DYNAMIC")) {
543 //ToDo error for same pcd, other type than non-dynamic
544 pcdConsumer
.remove(listValue
);
550 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
551 fpdPcd
.setCName(cName
);
552 fpdPcd
.setToken(token
);
553 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
554 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
555 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
557 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
558 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
560 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
561 // so need to add one dyn pcd.
563 if (al
.size() == 1) {
564 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
568 if (defaultVal
!= null){
569 fpdPcd
.setValue(defaultVal
);
572 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
573 fpdPcd
.setValue("0");
575 if (dataType
.equals("BOOLEAN")){
576 fpdPcd
.setValue("false");
578 if (dataType
.equals("VOID*")) {
582 if (dataType
.equals("UINT8")){
583 fpdPcd
.setMaxDatumSize(1);
585 if (dataType
.equals("UINT16")) {
586 fpdPcd
.setMaxDatumSize(2);
588 if (dataType
.equals("UINT32")) {
589 fpdPcd
.setMaxDatumSize(4);
591 if (dataType
.equals("UINT64")){
592 fpdPcd
.setMaxDatumSize(8);
594 if (dataType
.equals("BOOLEAN")){
595 fpdPcd
.setMaxDatumSize(1);
597 if (dataType
.equals("VOID*")) {
598 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
599 fpdPcd
.setMaxDatumSize(maxSize
);
604 private int setMaxSizeForPointer(String datum
) {
608 char ch
= datum
.charAt(0);
612 // For void* type PCD, only three datum is support:
613 // 1) Unicode: string with start char is "L"
614 // 2) Ansci: String is ""
615 // 3) byte array: String start char "{"
618 start
= datum
.indexOf('\"');
619 end
= datum
.lastIndexOf('\"');
621 (end
> datum
.length())||
622 ((start
== end
) && (datum
.length() > 0))) {
623 //ToDo Error handling here
626 strValue
= datum
.substring(start
+ 1, end
);
627 return strValue
.length() * 2;
628 } else if (ch
== '\"'){
629 start
= datum
.indexOf('\"');
630 end
= datum
.lastIndexOf('\"');
632 (end
> datum
.length())||
633 ((start
== end
) && (datum
.length() > 0))) {
636 strValue
= datum
.substring(start
+ 1, end
);
637 return strValue
.length();
638 } else if (ch
=='{') {
639 String
[] strValueArray
;
641 start
= datum
.indexOf('{');
642 end
= datum
.lastIndexOf('}');
643 strValue
= datum
.substring(start
+ 1, end
);
644 strValue
= strValue
.trim();
645 if (strValue
.length() == 0) {
648 strValueArray
= strValue
.split(",");
649 for (int index
= 0; index
< strValueArray
.length
; index
++) {
650 Integer value
= Integer
.decode(strValueArray
[index
].trim());
653 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
654 // "it is byte array in fact. But the element of %s exceed the byte range",
658 return strValueArray
.length
;
662 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
663 // "1) UNICODE string: like L\"xxxx\";\r\n"+
664 // "2) ANSIC string: like \"xxx\";\r\n"+
665 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
666 // "but the datum in seems does not following above format!",
672 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
673 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
678 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
680 return dynPcdMap
.get("pcdKey");
683 public int getDynamicPcdBuildDataCount() {
684 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
687 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
690 public void getDynamicPcdBuildData(String
[][] saa
) {
691 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
694 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
695 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
697 while(li
.hasNext()) {
698 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
699 saa
[i
][0] = dynPcd
.getCName();
700 saa
[i
][1] = dynPcd
.getToken().toString();
701 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
702 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
703 saa
[i
][4] = dynPcd
.getDatumType().toString();
709 private void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
) {
710 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
711 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
712 dynPcdData
.setCName(cName
);
713 dynPcdData
.setToken(token
);
714 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
715 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
717 BigInteger bigInt
= new BigInteger("0");
718 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
719 skuInfo
.setSkuId(bigInt
);
720 if (defaultVal
!= null){
721 skuInfo
.setValue(defaultVal
);
724 if (dataType
.equals("UINT8")){
725 skuInfo
.setValue("0");
727 if (dataType
.equals("UINT16")) {
728 skuInfo
.setValue("0");
730 if (dataType
.equals("UINT32")) {
731 skuInfo
.setValue("0");
733 if (dataType
.equals("UINT64")){
734 skuInfo
.setValue("0");
736 if (dataType
.equals("BOOLEAN")){
737 skuInfo
.setValue("false");
739 if (dataType
.equals("VOID*")) {
740 skuInfo
.setValue("");
743 if (dataType
.equals("UINT8")){
744 dynPcdData
.setMaxDatumSize(1);
746 if (dataType
.equals("UINT16")) {
747 dynPcdData
.setMaxDatumSize(2);
749 if (dataType
.equals("UINT32")) {
750 dynPcdData
.setMaxDatumSize(4);
752 if (dataType
.equals("UINT64")){
753 dynPcdData
.setMaxDatumSize(8);
755 if (dataType
.equals("BOOLEAN")){
756 dynPcdData
.setMaxDatumSize(1);
758 if (dataType
.equals("VOID*")) {
759 int maxSize
= setMaxSizeForPointer(defaultVal
);
760 dynPcdData
.setMaxDatumSize(maxSize
);
764 private void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
765 XmlObject o
= getfpdDynPcdBuildDefs();
767 XmlCursor cursor
= o
.newCursor();
768 if (cursor
.toFirstChild()) {
769 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
770 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
771 while (!(pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
))) {
772 cursor
.toNextSibling();
773 pcdBuildData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
781 // Get the Sku Info count of ith dyn pcd element.
783 public int getDynamicPcdSkuInfoCount(int i
){
784 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
788 int skuInfoCount
= 0;
789 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
790 if (cursor
.toFirstChild()) {
791 for (int j
= 0; j
< i
; ++j
) {
792 cursor
.toNextSibling();
794 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
795 if (pcdData
.getSkuInfoList() == null) {
799 skuInfoCount
= pcdData
.getSkuInfoList().size();
806 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
807 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
811 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
812 if (cursor
.toFirstChild()) {
813 for (int j
= 0; j
< i
; ++j
) {
814 cursor
.toNextSibling();
816 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
817 if (pcdData
.getSkuInfoList() == null) {
822 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
824 while (li
.hasNext()) {
825 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
826 saa
[k
][0] = skuInfo
.getSkuId()+"";
827 saa
[k
][1] = skuInfo
.getVariableName();
828 saa
[k
][2] = skuInfo
.getVariableGuid();
829 saa
[k
][3] = skuInfo
.getVariableOffset();
830 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
831 saa
[k
][5] = skuInfo
.getVpdOffset();
832 saa
[k
][6] = skuInfo
.getValue();
842 public String
getDynamicPcdBuildDataValue(int i
){
844 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
848 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
849 if (cursor
.toFirstChild()) {
850 for (int j
= 0; j
< i
; ++j
) {
851 cursor
.toNextSibling();
853 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
854 if (pcdData
.getSkuInfoList() == null) {
858 value
= pcdData
.getSkuInfoArray(0).getValue();
865 public String
getDynamicPcdBuildDataVpdOffset(int i
){
866 String vpdOffset
= null;
867 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
871 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
872 if (cursor
.toFirstChild()) {
873 for (int j
= 0; j
< i
; ++j
) {
874 cursor
.toNextSibling();
876 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
877 if (pcdData
.getSkuInfoList() == null) {
881 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
888 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
889 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
893 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
894 if (cursor
.toFirstChild()) {
895 for (int j
= 0; j
< i
; ++j
) {
896 cursor
.toNextSibling();
898 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
899 if (pcdData
.getSkuInfoList() == null) {
904 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
905 cursor
.toChild(qSkuInfo
);
912 // generate sku info for ith dyn pcd build data.
914 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
915 String hiiDefault
, String vpdOffset
, String value
, int i
) {
916 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
920 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
921 if (cursor
.toFirstChild()) {
922 for (int j
= 0; j
< i
; ++j
) {
923 cursor
.toNextSibling();
925 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
926 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
927 skuInfo
.setSkuId(new BigInteger(id
));
928 if (varName
!= null){
929 skuInfo
.setVariableName(varName
);
930 skuInfo
.setVariableGuid(varGuid
);
931 skuInfo
.setVariableOffset(varOffset
);
932 skuInfo
.setHiiDefaultValue(hiiDefault
);
934 else if (vpdOffset
!= null){
935 skuInfo
.setVpdOffset(vpdOffset
);
938 skuInfo
.setValue(value
);
943 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
944 String hiiDefault
, String vpdOffset
, String value
, int i
){
945 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
949 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
950 if (cursor
.toFirstChild()) {
951 for (int j
= 0; j
< i
; ++j
) {
952 cursor
.toNextSibling();
954 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
955 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
956 while (li
.hasNext()) {
957 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
958 if (skuInfo
.getSkuId().toString().equals(id
)){
959 if (varName
!= null){
960 skuInfo
.setVariableName(varName
);
961 skuInfo
.setVariableGuid(varGuid
);
962 skuInfo
.setVariableOffset(varOffset
);
963 skuInfo
.setHiiDefaultValue(hiiDefault
);
965 else if (vpdOffset
!= null){
966 skuInfo
.setVpdOffset(vpdOffset
);
969 skuInfo
.setValue(value
);
977 public void removePcdDataFromLibraryInstance(String moduleKey
, String libInstanceKey
){
978 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
980 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
982 maintainDynPcdMap(moduleSa
.getPcdBuildDefinition(), libInstanceKey
);
986 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
987 if (fpdBuildOpts
== null) {
988 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
993 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
994 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
996 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
999 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
1000 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1003 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1004 at
.setId(new Integer(id
));
1005 if (fileName
!= null){
1006 at
.setFilename(fileName
);
1009 at
.setAntCmdOptions(execOrder
);
1013 public void removeBuildOptionsUserDefAntTask(int i
) {
1014 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1018 XmlCursor cursor
= o
.newCursor();
1019 if (cursor
.toFirstChild()) {
1020 for (int j
= 0; j
< i
; ++j
) {
1021 cursor
.toNextSibling();
1028 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1029 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1033 XmlCursor cursor
= o
.newCursor();
1034 if (cursor
.toFirstChild()) {
1035 for (int j
= 0; j
< i
; ++j
) {
1036 cursor
.toNextSibling();
1038 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1039 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1044 public int getBuildOptionsUserDefAntTaskCount() {
1045 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1046 if (udats
== null || udats
.getAntTaskList() == null) {
1050 return udats
.getAntTaskList().size();
1053 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1054 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1055 if (udats
== null || udats
.getAntTaskList() == null) {
1059 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1060 ListIterator li
= l
.listIterator();
1062 while (li
.hasNext()) {
1063 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1064 saa
[i
][0] = at
.getId() + "";
1065 saa
[i
][1] = saa
[i
][2] = "";
1066 if (at
.getFilename() != null){
1067 saa
[i
][1] = at
.getFilename();
1069 if (at
.getAntCmdOptions() != null) {
1070 saa
[i
][2] = at
.getAntCmdOptions();
1075 public void genBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1076 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1078 opts
= getfpdBuildOpts().addNewOptions();
1080 OptionDocument
.Option opt
= opts
.addNewOption();
1081 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1084 private void setBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
, OptionDocument
.Option opt
){
1085 opt
.setStringValue(contents
);
1086 // opt.setBuildTargets(buildTargets);
1087 opt
.setToolChainFamily(toolChain
);
1088 opt
.setTagName(tagName
);
1089 opt
.setToolCode(toolCmd
);
1090 String
[] s
= archList
.split(" ");
1091 ArrayList
<String
> al
= new ArrayList
<String
>();
1092 for (int i
= 0; i
< s
.length
; ++i
) {
1095 opt
.setSupArchList(al
);
1098 public void removeBuildOptionsOpt(int i
){
1100 XmlObject o
= getfpdBuildOpts().getOptions();
1105 XmlCursor cursor
= o
.newCursor();
1106 if (cursor
.toFirstChild()) {
1107 for (int j
= 0; j
< i
; ++j
) {
1108 cursor
.toNextSibling();
1115 public void updateBuildOptionsOpt(int i
, String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1116 XmlObject o
= getfpdBuildOpts().getOptions();
1121 XmlCursor cursor
= o
.newCursor();
1122 if (cursor
.toFirstChild()) {
1123 for (int j
= 0; j
< i
; ++j
) {
1124 cursor
.toNextSibling();
1126 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1127 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1132 public int getBuildOptionsOptCount(){
1133 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1136 return getfpdBuildOpts().getOptions().getOptionList().size();
1139 public void getBuildOptionsOpts(String
[][] saa
) {
1140 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1144 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1145 ListIterator li
= lOpt
.listIterator();
1147 while(li
.hasNext()) {
1148 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1149 // saa[i][0] = opt.getBuildTargets();
1150 saa
[i
][1] = opt
.getToolChainFamily();
1151 if (opt
.getSupArchList() != null){
1152 Object
[] archs
= opt
.getSupArchList().toArray();
1154 for (int j
= 0; j
< archs
.length
; ++j
){
1155 saa
[i
][2] += archs
[j
];
1158 saa
[i
][2] = saa
[i
][2].trim();
1160 saa
[i
][3] = opt
.getToolCode();
1161 saa
[i
][4] = opt
.getTagName();
1162 saa
[i
][5] = opt
.getStringValue();
1168 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
1169 if (fpdPlatformDefs
== null){
1170 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
1172 return fpdPlatformDefs
;
1175 public FlashDocument
.Flash
getfpdFlash() {
1176 if (fpdFlash
== null) {
1177 fpdFlash
= fpdRoot
.addNewFlash();
1182 public void genFlashDefinitionFile(String file
) {
1183 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1185 fdf
= getfpdFlash().addNewFlashDefinitionFile();
1188 fdf
.setStringValue(file
);
1191 public String
getFlashDefinitionFile() {
1192 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1197 return fdf
.getStringValue();
1202 public void genFvImagesNameValue(String name
, String value
) {
1204 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1206 fi
= getfpdFlash().addNewFvImages();
1209 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
1214 public void removeFvImagesNameValue(int i
){
1216 XmlObject o
= getfpdFlash().getFvImages();
1221 QName qNameValue
= new QName(xmlNs
, "NameValue");
1222 XmlCursor cursor
= o
.newCursor();
1223 if (cursor
.toChild(qNameValue
)) {
1224 for (int j
= 0; j
< i
; ++j
) {
1225 cursor
.toNextSibling(qNameValue
);
1232 public void updateFvImagesNameValue(int i
, String name
, String value
){
1234 XmlObject o
= getfpdFlash().getFvImages();
1239 QName qNameValue
= new QName(xmlNs
, "NameValue");
1240 XmlCursor cursor
= o
.newCursor();
1241 if (cursor
.toChild(qNameValue
)) {
1242 for (int j
= 0; j
< i
; ++j
) {
1243 cursor
.toNextSibling(qNameValue
);
1245 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
1252 public int getFvImagesNameValueCount() {
1254 FvImagesDocument
.FvImages fi
= null;
1255 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
1258 return fi
.getNameValueList().size();
1261 public void getFvImagesNameValues(String
[][] nv
) {
1263 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1267 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
1269 ListIterator li
= l
.listIterator();
1270 while (li
.hasNext()) {
1271 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
1273 nv
[i
][0] = e
.getName();
1274 nv
[i
][1] = e
.getValue();
1280 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
1282 FvImagesDocument
.FvImages fis
= null;
1283 if ((fis
= getfpdFlash().getFvImages()) == null) {
1284 fis
= getfpdFlash().addNewFvImages();
1288 //gen FvImage with FvImageNames array
1290 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
1291 for (int i
= 0; i
< names
.length
; ++i
) {
1292 fi
.addFvImageNames(names
[i
]);
1294 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1295 if (options
!= null){
1296 setFvImagesFvImageFvImageOptions(options
, fi
);
1300 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
1301 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
1303 fio
= fi
.addNewFvImageOptions();
1306 Set
<String
> key
= options
.keySet();
1307 Iterator
<String
> i
= key
.iterator();
1308 while (i
.hasNext()) {
1309 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
1310 String k
= (String
)i
.next();
1312 nv
.setValue((String
)options
.get(k
));
1318 public void removeFvImagesFvImage(int i
) {
1320 XmlObject o
= getfpdFlash().getFvImages();
1325 QName qFvImage
= new QName(xmlNs
, "FvImage");
1326 XmlCursor cursor
= o
.newCursor();
1327 if (cursor
.toChild(qFvImage
)) {
1328 for (int j
= 0; j
< i
; ++j
) {
1329 cursor
.toNextSibling(qFvImage
);
1336 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
1338 XmlObject o
= getfpdFlash().getFvImages();
1342 XmlCursor cursor
= o
.newCursor();
1343 QName qFvImage
= new QName(xmlNs
, "FvImage");
1344 if (cursor
.toChild(qFvImage
)) {
1345 for (int j
= 0; j
< i
; ++j
) {
1346 cursor
.toNextSibling(qFvImage
);
1348 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1349 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1352 // remove old FvImageNames before adding new ones
1354 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
1355 cursor
.toChild(qFvImageNames
);
1357 while (cursor
.toNextSibling(qFvImageNames
)) {
1361 for (int k
= 0; k
< names
.length
; ++k
) {
1362 fi
.addFvImageNames(names
[k
]);
1365 // remove old FvImageOptions before adding new options
1367 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
1368 cursor
.toNextSibling(qFvImageOptions
);
1371 setFvImagesFvImageFvImageOptions(options
, fi
);
1376 public int getFvImagesFvImageCount() {
1378 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1381 return getfpdFlash().getFvImages().getFvImageList().size();
1384 public void getFvImagesFvImages(String
[][] saa
, ArrayList
<LinkedHashMap
<String
, String
>> options
) {
1386 if (getfpdFlash().getFvImages() == null) {
1389 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
1393 ListIterator li
= l
.listIterator();
1395 while(li
.hasNext()) {
1396 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
1398 // get FvImageNames array, space separated
1400 List
<String
> lfn
= fi
.getFvImageNamesList();
1401 ListIterator lfni
= lfn
.listIterator();
1403 while (lfni
.hasNext()) {
1404 saa
[i
][0] += (String
)lfni
.next();
1407 saa
[i
][0] = saa
[i
][0].trim();
1409 saa
[i
][1] = fi
.getType()+"";
1412 // get FvImageOptions into Map[i]
1414 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fo
= fi
.getFvImageOptions();
1419 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> lnv
= fo
.getNameValueList();
1420 if (lnv
== null || lnv
.isEmpty()) {
1424 ListIterator lnvi
= lnv
.listIterator();
1425 while (lnvi
.hasNext()) {
1426 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)lnvi
.next();
1427 Map
<String
, String
> m
= options
.get(i
);
1428 m
.put(nv
.getName(), nv
.getValue());
1436 Get platform header element
1437 @return PlatformHeaderDocument.PlatformHeader
1439 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
1440 if (fpdHdr
== null) {
1441 fpdHdr
= fpdRoot
.addNewPlatformHeader();
1443 genPlatformDefsSkuInfo("0", "DEFAULT");
1447 public void genPlatformDefsSkuInfo(String id
, String name
) {
1448 SkuInfoDocument
.SkuInfo skuInfo
= null;
1449 if (getfpdPlatformDefs().getSkuInfo() == null) {
1450 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
1452 skuInfo
= getfpdPlatformDefs().getSkuInfo();
1453 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
1454 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1455 skuName
.setSkuID(new BigInteger("0"));
1456 skuName
.setStringValue("DEFAULT");
1458 if (id
.equals("0")) {
1461 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1462 skuName
.setSkuID(new BigInteger(id
));
1463 skuName
.setStringValue(name
);
1467 public String
getFpdHdrPlatformName() {
1468 return getFpdHdr().getPlatformName();
1471 public String
getFpdHdrGuidValue() {
1472 return getFpdHdr().getGuidValue();
1475 public String
getFpdHdrVer() {
1476 return getFpdHdr().getVersion();
1479 public String
getFpdHdrAbs() {
1480 return getFpdHdr().getAbstract();
1483 public String
getFpdHdrDescription() {
1484 return getFpdHdr().getDescription();
1487 public String
getFpdHdrCopyright() {
1488 return getFpdHdr().getCopyright();
1491 public String
getFpdHdrLicense() {
1492 LicenseDocument
.License l
= getFpdHdr().getLicense();
1496 return l
.getStringValue();
1499 public String
getFpdHdrUrl() {
1500 LicenseDocument
.License l
= getFpdHdr().getLicense();
1507 public String
getFpdHdrSpec() {
1509 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1510 // return getFpdHdr().getSpecification();
1513 public void setFpdHdrPlatformName(String name
){
1514 getFpdHdr().setPlatformName(name
);
1517 public void setFpdHdrGuidValue(String guid
){
1518 getFpdHdr().setGuidValue(guid
);
1521 public void setFpdHdrVer(String v
){
1522 getFpdHdr().setVersion(v
);
1525 public void setFpdHdrAbs(String abs
) {
1526 getFpdHdr().setAbstract(abs
);
1529 public void setFpdHdrDescription(String desc
){
1530 getFpdHdr().setDescription(desc
);
1533 public void setFpdHdrCopyright(String cr
) {
1534 getFpdHdr().setCopyright(cr
);
1537 public void setFpdHdrLicense(String license
){
1538 LicenseDocument
.License l
= getFpdHdr().getLicense();
1540 getFpdHdr().addNewLicense().setStringValue(license
);
1543 l
.setStringValue(license
);
1547 public void setFpdHdrUrl(String url
){
1548 LicenseDocument
.License l
= getFpdHdr().getLicense();
1554 public void setFpdHdrSpec(String s
){
1555 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1556 getFpdHdr().setSpecification(s
);
1559 Save the processed xml contents to file
1561 @param fpdFile The file to save xml contents
1562 @throws IOException Exceptions during file operation
1564 public void saveAs(File fpdFile
) throws IOException
{
1566 XmlOptions options
= new XmlOptions();
1568 options
.setCharacterEncoding("UTF-8");
1569 options
.setSavePrettyPrint();
1570 options
.setSavePrettyPrintIndent(2);
1572 fpdd
.save(fpdFile
, options
);
1573 } catch (IOException e
) {
1574 e
.printStackTrace();
1579 private String
listToString(List
<String
> l
) {
1584 ListIterator li
= l
.listIterator();
1585 while(li
.hasNext()) {