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
.FlashDocument
;
37 import org
.tianocore
.FrameworkModulesDocument
;
38 import org
.tianocore
.LibrariesDocument
;
39 import org
.tianocore
.ModuleSADocument
;
40 import org
.tianocore
.ModuleSurfaceAreaDocument
;
41 import org
.tianocore
.OptionDocument
;
42 import org
.tianocore
.OptionsDocument
;
43 import org
.tianocore
.PcdBuildDefinitionDocument
;
44 import org
.tianocore
.PcdCodedDocument
;
45 import org
.tianocore
.PcdDataTypes
;
46 import org
.tianocore
.PcdDeclarationsDocument
;
47 import org
.tianocore
.PcdItemTypes
;
48 import org
.tianocore
.PlatformDefinitionsDocument
;
49 import org
.tianocore
.PlatformSurfaceAreaDocument
;
50 import org
.tianocore
.FvImageTypes
;
51 import org
.tianocore
.FvImagesDocument
;
52 import org
.tianocore
.LicenseDocument
;
53 import org
.tianocore
.PlatformHeaderDocument
;
54 import org
.tianocore
.SkuInfoDocument
;
55 import org
.tianocore
.UserDefinedAntTasksDocument
;
56 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.GlobalData
;
57 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
58 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
59 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
62 This class processes fpd file contents such as add remove xml elements.
63 @since PackageEditor 1.0
65 public class FpdFileContents
{
67 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
69 private PlatformSurfaceAreaDocument fpdd
= null;
71 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
73 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
75 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
77 private FlashDocument
.Flash fpdFlash
= null;
79 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
81 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
83 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
85 public static HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
88 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
90 public void initDynPcdMap() {
91 if (dynPcdMap
== null) {
92 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
93 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
97 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
98 while (li
.hasNext()) {
99 ModuleSADocument
.ModuleSA msa
= li
.next();
100 if (msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null) {
103 String ModuleInfo
= msa
.getModuleGuid() + " " + msa
.getModuleVersion() +
104 " " + msa
.getPackageGuid() + " " + msa
.getPackageVersion();
105 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= msa
.getPcdBuildDefinition().getPcdDataList();
106 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
107 while (lpi
.hasNext()) {
108 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
109 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
110 if (dynPcdMap
.get(pcdKey
) == null) {
111 ArrayList
<String
> al
= new ArrayList
<String
>();
112 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
113 dynPcdMap
.put(pcdKey
, al
);
116 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
123 Constructor to create a new spd file
125 public FpdFileContents() {
127 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
128 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
133 Constructor for existing document object
136 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
138 fpdHdr
= fpdRoot
.getPlatformHeader();
139 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
140 fpdBuildOpts
= fpdRoot
.getBuildOptions();
141 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
142 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
143 fpdFlash
= fpdRoot
.getFlash();
147 Constructor based on an existing spd file
149 @param f Existing spd file
151 public FpdFileContents(File f
) {
153 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
154 fpdRoot
= fpdd
.getPlatformSurfaceArea();
155 } catch (Exception e
) {
156 System
.out
.println(e
.toString());
160 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
161 if (fpdDynPcdBuildDefs
== null){
162 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
164 return fpdDynPcdBuildDefs
;
167 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
168 if (fpdFrameworkModules
== null){
169 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
171 return fpdFrameworkModules
;
174 public int getPlatformDefsSkuInfoCount(){
175 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
178 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
181 public void getPlatformDefsSkuInfos(String
[][] saa
){
182 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
186 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
187 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
189 while(li
.hasNext()) {
190 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
191 saa
[i
][0] = sku
.getSkuID()+"";
192 saa
[i
][1] = sku
.getStringValue();
197 public int getFrameworkModulesCount() {
198 if (getfpdFrameworkModules().getModuleSAList() == null){
201 return getfpdFrameworkModules().getModuleSAList().size();
204 public void getFrameworkModulesInfo(String
[][] saa
) {
205 if (getFrameworkModulesCount() == 0){
209 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
211 while(li
.hasNext()) {
212 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
213 saa
[i
][1] = msa
.getModuleGuid();
214 saa
[i
][2] = msa
.getModuleVersion();
216 saa
[i
][3] = msa
.getPackageGuid();
217 saa
[i
][4] = msa
.getPackageVersion();
218 // saa[i][4] = listToString(msa.getSupArchList());
223 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
224 String
[] s
= key
.split(" ");
225 if (getfpdFrameworkModules().getModuleSAList() == null) {
228 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
229 while(li
.hasNext()) {
230 ModuleSADocument
.ModuleSA msa
= (ModuleSADocument
.ModuleSA
)li
.next();
231 if (msa
.getModuleGuid().equals(s
[0]) && msa
.getModuleVersion().equals(s
[1])
232 && msa
.getPackageGuid().equals(s
[2]) && msa
.getPackageVersion().equals(s
[3])) {
239 public void removeModuleSA(int i
) {
240 XmlObject o
= getfpdFrameworkModules();
245 XmlCursor cursor
= o
.newCursor();
246 if (cursor
.toFirstChild()) {
247 for (int j
= 0; j
< i
; ++j
) {
248 cursor
.toNextSibling();
251 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
253 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
254 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
255 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion();
256 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
257 if (pcdBuildDef
!= null) {
258 maintainDynPcdMap(pcdBuildDef
, moduleInfo
);
265 private void maintainDynPcdMap(PcdBuildDefinitionDocument
.PcdBuildDefinition o
, String moduleInfo
) {
266 XmlCursor cursor
= o
.newCursor();
267 boolean fromLibInstance
= false;
268 if (!cursor
.toFirstChild()){
272 // deal with first child, same process in the while loop below for siblings.
274 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
275 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
276 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
277 for(int i
= 0; i
< al
.size(); ++i
){
278 if (al
.get(i
).startsWith(moduleInfo
)){
279 fromLibInstance
= true;
283 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
284 if (al
.size() == 0) {
285 dynPcdMap
.remove(pcdKey
);
288 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
289 if (dynPcdMap
.get(pcdKey
) == null) {
290 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
293 if (fromLibInstance
){
296 while(cursor
.toNextSibling()) {
297 fromLibInstance
= false;
298 pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
300 // remove each pcd record from dynPcdMap
302 pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
303 al
= dynPcdMap
.get(pcdKey
);
304 for(int i
= 0; i
< al
.size(); ++i
){
305 if (al
.get(i
).startsWith(moduleInfo
)){
306 fromLibInstance
= true;
310 al
.remove(moduleInfo
+ " " + pcdData
.getItemType().toString());
311 if (al
.size() == 0) {
312 dynPcdMap
.remove(pcdKey
);
315 if (pcdData
.getItemType().toString().equals("DYNAMIC")) {
317 // First check whether this is the only consumer of this dyn pcd.
319 if (dynPcdMap
.get(pcdKey
) == null) {
321 // delete corresponding entry in DynamicPcdBuildData
323 removeDynamicPcdBuildData(pcdData
.getCName(), pcdData
.getTokenSpaceGuidCName());
326 if (fromLibInstance
){
332 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
334 public int getPcdDataCount(String key
){
335 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
336 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
339 return msa
.getPcdBuildDefinition().getPcdDataList().size();
342 public void getPcdData(String key
, String
[][] saa
) {
343 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
344 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
347 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
348 for (int i
= 0; i
< saa
.length
; ++i
) {
349 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
350 saa
[i
][0] = pcdData
.getCName();
351 saa
[i
][1] = pcdData
.getTokenSpaceGuidCName();
352 saa
[i
][2] = pcdData
.getItemType().toString();
353 saa
[i
][3] = pcdData
.getToken().toString();
354 saa
[i
][4] = pcdData
.getDatumType().toString();
355 saa
[i
][5] = pcdData
.getValue();
360 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
362 public int getLibraryInstancesCount(String key
) {
363 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
364 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
367 return msa
.getLibraries().getInstanceList().size();
370 public void getLibraryInstances(String key
, String
[][] saa
){
371 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
372 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
376 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
377 for (int i
= 0; i
< saa
.length
; ++i
) {
378 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
379 saa
[i
][1] = instance
.getModuleGuid();
380 saa
[i
][2] = instance
.getModuleVersion();
381 saa
[i
][3] = instance
.getPackageGuid();
382 saa
[i
][4] = instance
.getPackageVersion();
386 public void removeLibraryInstances(String key
) {
387 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
388 if (msa
== null || msa
.getLibraries() == null){
392 XmlCursor cursor
= msa
.getLibraries().newCursor();
397 public void genLibraryInstance(String mg
, String mv
, String pg
, String pv
, String key
) {
398 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
400 msa
= getfpdFrameworkModules().addNewModuleSA();
402 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
404 libs
= msa
.addNewLibraries();
407 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
408 instance
.setModuleGuid(mg
);
409 instance
.setModuleVersion(mv
);
410 instance
.setPackageGuid(pg
);
411 instance
.setPackageVersion(pv
);
414 /**add pcd information of module mi to a ModuleSA.
416 * @param moduleSa if null, generate a new ModuleSA.
418 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, ModuleSADocument
.ModuleSA moduleSa
){
419 //ToDo add Arch filter
422 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)GlobalData
.getModuleXmlObject(mi
);
423 if (msa
.getPcdCoded() == null) {
426 if (moduleSa
== null) {
427 moduleSa
= genModuleSA(mi
);
429 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
430 m
.put("ModuleSurfaceArea", msa
);
431 SurfaceAreaQuery
.setDoc(m
);
432 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null);
434 // Implementing InitializePlatformPcdBuildDefinitions
436 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
437 ListIterator li
= l
.listIterator();
438 while(li
.hasNext()) {
439 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
440 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
441 if (spdPcd
== null) {
448 // AddItem to ModuleSA PcdBuildDefinitions
450 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
451 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
461 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
463 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
464 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
465 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
466 m
.put("PackageSurfaceArea", GlobalData
.getPackageXmlObject(depPkgs
[i
]));
467 SurfaceAreaQuery
.setDoc(m
);
468 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations();
472 for (int j
= 0; j
< xo
.length
; ++j
) {
473 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
474 if (msaPcd
.getTokenSpaceGuidCName() == null) {
475 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
480 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
491 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
) {
492 PackageIdentification pi
= GlobalData
.getPackageForModule(mi
);
493 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
494 msa
.setModuleGuid(mi
.getGuid());
495 msa
.setModuleVersion(mi
.getVersion());
496 msa
.setPackageGuid(pi
.getGuid());
497 msa
.setPackageVersion(pi
.getVersion());
502 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
) {
503 if (moduleSa
.getPcdBuildDefinition() == null){
504 moduleSa
.addNewPcdBuildDefinition();
507 // constructe pcd to modulesa mapping first.
508 // Attention : for any error condition, remove from map this pcd.
510 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
511 if (pcdConsumer
== null) {
512 pcdConsumer
= new ArrayList
<String
>();
514 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
515 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion()
517 pcdConsumer
.add(listValue
);
518 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
520 // Special dynamic type, if this pcd already exists in other ModuleSA
522 if (itemType
.equals("DYNAMIC")) {
524 ListIterator li
= pcdConsumer
.listIterator();
525 while(li
.hasNext()) {
526 String value
= li
.next().toString();
527 String
[] valuePart
= value
.split(" ");
528 if (!valuePart
[4].equals("DYNAMIC")) {
529 //ToDo error for same pcd, other type than dynamic
530 pcdConsumer
.remove(listValue
);
536 ListIterator li
= pcdConsumer
.listIterator();
537 while(li
.hasNext()) {
538 String value
= li
.next().toString();
539 String
[] valuePart
= value
.split(" ");
540 if (valuePart
[4].equals("DYNAMIC")) {
541 //ToDo error for same pcd, other type than non-dynamic
542 pcdConsumer
.remove(listValue
);
548 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
549 fpdPcd
.setCName(cName
);
550 fpdPcd
.setToken(token
);
551 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
552 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
553 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
555 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
556 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
558 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
559 // so need to add one dyn pcd.
561 if (al
.size() == 1) {
562 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
566 if (defaultVal
!= null){
567 fpdPcd
.setValue(defaultVal
);
570 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
571 fpdPcd
.setValue("0");
573 if (dataType
.equals("BOOLEAN")){
574 fpdPcd
.setValue("false");
576 if (dataType
.equals("VOID*")) {
580 if (dataType
.equals("UINT8")){
581 fpdPcd
.setMaxDatumSize(1);
583 if (dataType
.equals("UINT16")) {
584 fpdPcd
.setMaxDatumSize(2);
586 if (dataType
.equals("UINT32")) {
587 fpdPcd
.setMaxDatumSize(4);
589 if (dataType
.equals("UINT64")){
590 fpdPcd
.setMaxDatumSize(8);
592 if (dataType
.equals("BOOLEAN")){
593 fpdPcd
.setMaxDatumSize(1);
595 if (dataType
.equals("VOID*")) {
596 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
597 fpdPcd
.setMaxDatumSize(maxSize
);
602 private int setMaxSizeForPointer(String datum
) {
606 char ch
= datum
.charAt(0);
610 // For void* type PCD, only three datum is support:
611 // 1) Unicode: string with start char is "L"
612 // 2) Ansci: String is ""
613 // 3) byte array: String start char "{"
616 start
= datum
.indexOf('\"');
617 end
= datum
.lastIndexOf('\"');
619 (end
> datum
.length())||
620 ((start
== end
) && (datum
.length() > 0))) {
621 //ToDo Error handling here
624 strValue
= datum
.substring(start
+ 1, end
);
625 return strValue
.length() * 2;
626 } else if (ch
== '\"'){
627 start
= datum
.indexOf('\"');
628 end
= datum
.lastIndexOf('\"');
630 (end
> datum
.length())||
631 ((start
== end
) && (datum
.length() > 0))) {
634 strValue
= datum
.substring(start
+ 1, end
);
635 return strValue
.length();
636 } else if (ch
=='{') {
637 String
[] strValueArray
;
639 start
= datum
.indexOf('{');
640 end
= datum
.lastIndexOf('}');
641 strValue
= datum
.substring(start
+ 1, end
);
642 strValue
= strValue
.trim();
643 if (strValue
.length() == 0) {
646 strValueArray
= strValue
.split(",");
647 for (int index
= 0; index
< strValueArray
.length
; index
++) {
648 Integer value
= Integer
.decode(strValueArray
[index
].trim());
651 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
652 // "it is byte array in fact. But the element of %s exceed the byte range",
656 return strValueArray
.length
;
660 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
661 // "1) UNICODE string: like L\"xxxx\";\r\n"+
662 // "2) ANSIC string: like \"xxx\";\r\n"+
663 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
664 // "but the datum in seems does not following above format!",
670 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
671 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
676 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
678 return dynPcdMap
.get("pcdKey");
681 public int getDynamicPcdBuildDataCount() {
682 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
685 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
688 public void getDynamicPcdBuildData(String
[][] saa
) {
689 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
692 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
693 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
695 while(li
.hasNext()) {
696 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
697 saa
[i
][0] = dynPcd
.getCName();
698 saa
[i
][1] = dynPcd
.getToken().toString();
699 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
700 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
701 saa
[i
][4] = dynPcd
.getDatumType().toString();
707 private void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
) {
708 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
709 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
710 dynPcdData
.setCName(cName
);
711 dynPcdData
.setToken(token
);
712 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
713 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
715 BigInteger bigInt
= new BigInteger("0");
716 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
717 skuInfo
.setSkuId(bigInt
);
718 if (defaultVal
!= null){
719 skuInfo
.setValue(defaultVal
);
722 if (dataType
.equals("UINT8")){
723 skuInfo
.setValue("0");
725 if (dataType
.equals("UINT16")) {
726 skuInfo
.setValue("0");
728 if (dataType
.equals("UINT32")) {
729 skuInfo
.setValue("0");
731 if (dataType
.equals("UINT64")){
732 skuInfo
.setValue("0");
734 if (dataType
.equals("BOOLEAN")){
735 skuInfo
.setValue("false");
737 if (dataType
.equals("VOID*")) {
738 skuInfo
.setValue("");
741 if (dataType
.equals("UINT8")){
742 dynPcdData
.setMaxDatumSize(1);
744 if (dataType
.equals("UINT16")) {
745 dynPcdData
.setMaxDatumSize(2);
747 if (dataType
.equals("UINT32")) {
748 dynPcdData
.setMaxDatumSize(4);
750 if (dataType
.equals("UINT64")){
751 dynPcdData
.setMaxDatumSize(8);
753 if (dataType
.equals("BOOLEAN")){
754 dynPcdData
.setMaxDatumSize(1);
756 if (dataType
.equals("VOID*")) {
757 int maxSize
= setMaxSizeForPointer(defaultVal
);
758 dynPcdData
.setMaxDatumSize(maxSize
);
762 private void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
763 XmlObject o
= getfpdDynPcdBuildDefs();
765 XmlCursor cursor
= o
.newCursor();
766 if (cursor
.toFirstChild()) {
767 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
768 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
769 while (!(pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
))) {
770 cursor
.toNextSibling();
771 pcdBuildData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
779 // Get the Sku Info count of ith dyn pcd element.
781 public int getDynamicPcdSkuInfoCount(int i
){
782 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
786 int skuInfoCount
= 0;
787 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
788 if (cursor
.toFirstChild()) {
789 for (int j
= 0; j
< i
; ++j
) {
790 cursor
.toNextSibling();
792 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
793 if (pcdData
.getSkuInfoList() == null) {
797 skuInfoCount
= pcdData
.getSkuInfoList().size();
804 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
805 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
809 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
810 if (cursor
.toFirstChild()) {
811 for (int j
= 0; j
< i
; ++j
) {
812 cursor
.toNextSibling();
814 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
815 if (pcdData
.getSkuInfoList() == null) {
820 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
822 while (li
.hasNext()) {
823 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
824 saa
[k
][0] = skuInfo
.getSkuId()+"";
825 saa
[k
][1] = skuInfo
.getVariableName();
826 saa
[k
][2] = skuInfo
.getVariableGuid();
827 saa
[k
][3] = skuInfo
.getVariableOffset();
828 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
829 saa
[k
][5] = skuInfo
.getVpdOffset();
830 saa
[k
][6] = skuInfo
.getValue();
840 public String
getDynamicPcdBuildDataValue(int i
){
842 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
846 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
847 if (cursor
.toFirstChild()) {
848 for (int j
= 0; j
< i
; ++j
) {
849 cursor
.toNextSibling();
851 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
852 if (pcdData
.getSkuInfoList() == null) {
856 value
= pcdData
.getSkuInfoArray(0).getValue();
863 public String
getDynamicPcdBuildDataVpdOffset(int i
){
864 String vpdOffset
= null;
865 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
869 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
870 if (cursor
.toFirstChild()) {
871 for (int j
= 0; j
< i
; ++j
) {
872 cursor
.toNextSibling();
874 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
875 if (pcdData
.getSkuInfoList() == null) {
879 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
886 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
887 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
891 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
892 if (cursor
.toFirstChild()) {
893 for (int j
= 0; j
< i
; ++j
) {
894 cursor
.toNextSibling();
896 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
897 if (pcdData
.getSkuInfoList() == null) {
902 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
903 cursor
.toChild(qSkuInfo
);
910 // generate sku info for ith dyn pcd build data.
912 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
913 String hiiDefault
, String vpdOffset
, String value
, int i
) {
914 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
918 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
919 if (cursor
.toFirstChild()) {
920 for (int j
= 0; j
< i
; ++j
) {
921 cursor
.toNextSibling();
923 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
924 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
925 skuInfo
.setSkuId(new BigInteger(id
));
926 if (varName
!= null){
927 skuInfo
.setVariableName(varName
);
928 skuInfo
.setVariableGuid(varGuid
);
929 skuInfo
.setVariableOffset(varOffset
);
930 skuInfo
.setHiiDefaultValue(hiiDefault
);
932 else if (vpdOffset
!= null){
933 skuInfo
.setVpdOffset(vpdOffset
);
936 skuInfo
.setValue(value
);
941 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
942 String hiiDefault
, String vpdOffset
, String value
, int i
){
943 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
947 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
948 if (cursor
.toFirstChild()) {
949 for (int j
= 0; j
< i
; ++j
) {
950 cursor
.toNextSibling();
952 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
953 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
954 while (li
.hasNext()) {
955 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
956 if (skuInfo
.getSkuId().toString().equals(id
)){
957 if (varName
!= null){
958 skuInfo
.setVariableName(varName
);
959 skuInfo
.setVariableGuid(varGuid
);
960 skuInfo
.setVariableOffset(varOffset
);
961 skuInfo
.setHiiDefaultValue(hiiDefault
);
963 else if (vpdOffset
!= null){
964 skuInfo
.setVpdOffset(vpdOffset
);
967 skuInfo
.setValue(value
);
975 public void removePcdDataFromLibraryInstance(String moduleKey
, String libInstanceKey
){
976 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
978 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
980 maintainDynPcdMap(moduleSa
.getPcdBuildDefinition(), libInstanceKey
);
984 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
985 if (fpdBuildOpts
== null) {
986 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
991 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
992 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
994 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
997 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
998 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1001 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1002 at
.setId(new Integer(id
));
1003 if (fileName
!= null){
1004 at
.setFilename(fileName
);
1006 if (execOrder
!= null) {
1007 at
.setAntCmdOptions(execOrder
);
1011 public void removeBuildOptionsUserDefAntTask(int i
) {
1012 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1016 XmlCursor cursor
= o
.newCursor();
1017 if (cursor
.toFirstChild()) {
1018 for (int j
= 0; j
< i
; ++j
) {
1019 cursor
.toNextSibling();
1026 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1027 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1031 XmlCursor cursor
= o
.newCursor();
1032 if (cursor
.toFirstChild()) {
1033 for (int j
= 0; j
< i
; ++j
) {
1034 cursor
.toNextSibling();
1036 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1037 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1042 public int getBuildOptionsUserDefAntTaskCount() {
1043 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1044 if (udats
== null || udats
.getAntTaskList() == null) {
1048 return udats
.getAntTaskList().size();
1051 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1052 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1053 if (udats
== null || udats
.getAntTaskList() == null) {
1057 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1058 ListIterator li
= l
.listIterator();
1060 while (li
.hasNext()) {
1061 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1062 saa
[i
][0] = at
.getId() + "";
1063 saa
[i
][1] = saa
[i
][2] = "";
1064 if (at
.getFilename() != null){
1065 saa
[i
][1] = at
.getFilename();
1067 if (at
.getAntCmdOptions() != null) {
1068 saa
[i
][2] = at
.getAntCmdOptions();
1073 public void genBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1074 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1076 opts
= getfpdBuildOpts().addNewOptions();
1078 OptionDocument
.Option opt
= opts
.addNewOption();
1079 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1082 private void setBuildOptionsOpt(String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
, OptionDocument
.Option opt
){
1083 opt
.setStringValue(contents
);
1084 // opt.setBuildTargets(buildTargets);
1085 opt
.setToolChainFamily(toolChain
);
1086 opt
.setTagName(tagName
);
1087 opt
.setToolCode(toolCmd
);
1088 String
[] s
= archList
.split(" ");
1089 ArrayList
<String
> al
= new ArrayList
<String
>();
1090 for (int i
= 0; i
< s
.length
; ++i
) {
1093 opt
.setSupArchList(al
);
1096 public void removeBuildOptionsOpt(int i
){
1098 XmlObject o
= getfpdBuildOpts().getOptions();
1103 XmlCursor cursor
= o
.newCursor();
1104 if (cursor
.toFirstChild()) {
1105 for (int j
= 0; j
< i
; ++j
) {
1106 cursor
.toNextSibling();
1113 public void updateBuildOptionsOpt(int i
, String buildTargets
, String toolChain
, String tagName
, String toolCmd
, String archList
, String contents
) {
1114 XmlObject o
= getfpdBuildOpts().getOptions();
1119 XmlCursor cursor
= o
.newCursor();
1120 if (cursor
.toFirstChild()) {
1121 for (int j
= 0; j
< i
; ++j
) {
1122 cursor
.toNextSibling();
1124 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1125 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1130 public int getBuildOptionsOptCount(){
1131 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1134 return getfpdBuildOpts().getOptions().getOptionList().size();
1137 public void getBuildOptionsOpts(String
[][] saa
) {
1138 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1142 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1143 ListIterator li
= lOpt
.listIterator();
1145 while(li
.hasNext()) {
1146 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1147 // saa[i][0] = opt.getBuildTargets();
1148 saa
[i
][1] = opt
.getToolChainFamily();
1149 if (opt
.getSupArchList() != null){
1150 Object
[] archs
= opt
.getSupArchList().toArray();
1152 for (int j
= 0; j
< archs
.length
; ++j
){
1153 saa
[i
][2] += archs
[j
];
1156 saa
[i
][2] = saa
[i
][2].trim();
1158 saa
[i
][3] = opt
.getToolCode();
1159 saa
[i
][4] = opt
.getTagName();
1160 saa
[i
][5] = opt
.getStringValue();
1166 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
1167 if (fpdPlatformDefs
== null){
1168 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
1170 return fpdPlatformDefs
;
1173 public FlashDocument
.Flash
getfpdFlash() {
1174 if (fpdFlash
== null) {
1175 fpdFlash
= fpdRoot
.addNewFlash();
1180 public void genFlashDefinitionFile(String file
) {
1181 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1183 fdf
= getfpdFlash().addNewFlashDefinitionFile();
1186 fdf
.setStringValue(file
);
1189 public String
getFlashDefinitionFile() {
1190 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
1195 return fdf
.getStringValue();
1200 public void genFvImagesNameValue(String name
, String value
) {
1202 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1204 fi
= getfpdFlash().addNewFvImages();
1207 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
1212 public void removeFvImagesNameValue(int i
){
1214 XmlObject o
= getfpdFlash().getFvImages();
1219 QName qNameValue
= new QName(xmlNs
, "NameValue");
1220 XmlCursor cursor
= o
.newCursor();
1221 if (cursor
.toChild(qNameValue
)) {
1222 for (int j
= 0; j
< i
; ++j
) {
1223 cursor
.toNextSibling(qNameValue
);
1230 public void updateFvImagesNameValue(int i
, String name
, String value
){
1232 XmlObject o
= getfpdFlash().getFvImages();
1237 QName qNameValue
= new QName(xmlNs
, "NameValue");
1238 XmlCursor cursor
= o
.newCursor();
1239 if (cursor
.toChild(qNameValue
)) {
1240 for (int j
= 0; j
< i
; ++j
) {
1241 cursor
.toNextSibling(qNameValue
);
1243 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
1250 public int getFvImagesNameValueCount() {
1252 FvImagesDocument
.FvImages fi
= null;
1253 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
1256 return fi
.getNameValueList().size();
1259 public void getFvImagesNameValues(String
[][] nv
) {
1261 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
1265 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
1267 ListIterator li
= l
.listIterator();
1268 while (li
.hasNext()) {
1269 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
1271 nv
[i
][0] = e
.getName();
1272 nv
[i
][1] = e
.getValue();
1278 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
1280 FvImagesDocument
.FvImages fis
= null;
1281 if ((fis
= getfpdFlash().getFvImages()) == null) {
1282 fis
= getfpdFlash().addNewFvImages();
1286 //gen FvImage with FvImageNames array
1288 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
1289 for (int i
= 0; i
< names
.length
; ++i
) {
1290 fi
.addFvImageNames(names
[i
]);
1292 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1293 if (options
!= null){
1294 setFvImagesFvImageFvImageOptions(options
, fi
);
1298 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
1299 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
1301 fio
= fi
.addNewFvImageOptions();
1304 Set
<String
> key
= options
.keySet();
1305 Iterator
<String
> i
= key
.iterator();
1306 while (i
.hasNext()) {
1308 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
1309 String k
= (String
)i
.next();
1312 nv
.setValue((String
)options
.get(k
));
1319 public void removeFvImagesFvImage(int i
) {
1321 XmlObject o
= getfpdFlash().getFvImages();
1326 QName qFvImage
= new QName(xmlNs
, "FvImage");
1327 XmlCursor cursor
= o
.newCursor();
1328 if (cursor
.toChild(qFvImage
)) {
1329 for (int j
= 0; j
< i
; ++j
) {
1330 cursor
.toNextSibling(qFvImage
);
1337 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
1339 XmlObject o
= getfpdFlash().getFvImages();
1343 XmlCursor cursor
= o
.newCursor();
1344 QName qFvImage
= new QName(xmlNs
, "FvImage");
1345 if (cursor
.toChild(qFvImage
)) {
1346 for (int j
= 0; j
< i
; ++j
) {
1347 cursor
.toNextSibling(qFvImage
);
1349 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1350 fi
.setType(FvImageTypes
.Enum
.forString(types
));
1353 // remove old FvImageNames before adding new ones
1355 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
1356 cursor
.toChild(qFvImageNames
);
1358 while (cursor
.toNextSibling(qFvImageNames
)) {
1362 for (int k
= 0; k
< names
.length
; ++k
) {
1363 fi
.addFvImageNames(names
[k
]);
1366 // remove old FvImageOptions before adding new options
1368 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
1369 cursor
.toNextSibling(qFvImageOptions
);
1372 setFvImagesFvImageFvImageOptions(options
, fi
);
1377 public int getFvImagesFvImageCount() {
1379 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1382 return getfpdFlash().getFvImages().getFvImageList().size();
1385 /**Only Get Fv image setting - name and type.
1388 public void getFvImagesFvImages(String
[][] saa
) {
1390 if (getfpdFlash().getFvImages() == null) {
1393 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
1397 ListIterator li
= l
.listIterator();
1399 while(li
.hasNext()) {
1400 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
1402 // get FvImageNames array, space separated
1404 List
<String
> lfn
= fi
.getFvImageNamesList();
1405 ListIterator lfni
= lfn
.listIterator();
1407 while (lfni
.hasNext()) {
1408 saa
[i
][0] += (String
)lfni
.next();
1411 saa
[i
][0] = saa
[i
][0].trim();
1413 saa
[i
][1] = fi
.getType()+"";
1419 /**Get FvImage Options for FvImage i
1420 * @param i the ith FvImage
1422 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
1423 XmlObject o
= getfpdFlash().getFvImages();
1427 XmlCursor cursor
= o
.newCursor();
1428 QName qFvImage
= new QName(xmlNs
, "FvImage");
1429 if (cursor
.toChild(qFvImage
)) {
1430 for (int j
= 0; j
< i
; ++j
) {
1431 cursor
.toNextSibling(qFvImage
);
1433 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
1434 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
1437 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
1438 while(li
.hasNext()){
1439 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
1440 m
.put(nv
.getName(), nv
.getValue());
1446 Get platform header element
1447 @return PlatformHeaderDocument.PlatformHeader
1449 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
1450 if (fpdHdr
== null) {
1451 fpdHdr
= fpdRoot
.addNewPlatformHeader();
1453 genPlatformDefsSkuInfo("0", "DEFAULT");
1457 public void genPlatformDefsSkuInfo(String id
, String name
) {
1458 SkuInfoDocument
.SkuInfo skuInfo
= null;
1459 if (getfpdPlatformDefs().getSkuInfo() == null) {
1460 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
1462 skuInfo
= getfpdPlatformDefs().getSkuInfo();
1463 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
1464 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1465 skuName
.setSkuID(new BigInteger("0"));
1466 skuName
.setStringValue("DEFAULT");
1468 if (id
.equals("0")) {
1471 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
1472 skuName
.setSkuID(new BigInteger(id
));
1473 skuName
.setStringValue(name
);
1477 public String
getFpdHdrPlatformName() {
1478 return getFpdHdr().getPlatformName();
1481 public String
getFpdHdrGuidValue() {
1482 return getFpdHdr().getGuidValue();
1485 public String
getFpdHdrVer() {
1486 return getFpdHdr().getVersion();
1489 public String
getFpdHdrAbs() {
1490 return getFpdHdr().getAbstract();
1493 public String
getFpdHdrDescription() {
1494 return getFpdHdr().getDescription();
1497 public String
getFpdHdrCopyright() {
1498 return getFpdHdr().getCopyright();
1501 public String
getFpdHdrLicense() {
1502 LicenseDocument
.License l
= getFpdHdr().getLicense();
1506 return l
.getStringValue();
1509 public String
getFpdHdrUrl() {
1510 LicenseDocument
.License l
= getFpdHdr().getLicense();
1517 public String
getFpdHdrSpec() {
1519 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1520 // return getFpdHdr().getSpecification();
1523 public void setFpdHdrPlatformName(String name
){
1524 getFpdHdr().setPlatformName(name
);
1527 public void setFpdHdrGuidValue(String guid
){
1528 getFpdHdr().setGuidValue(guid
);
1531 public void setFpdHdrVer(String v
){
1532 getFpdHdr().setVersion(v
);
1535 public void setFpdHdrAbs(String abs
) {
1536 getFpdHdr().setAbstract(abs
);
1539 public void setFpdHdrDescription(String desc
){
1540 getFpdHdr().setDescription(desc
);
1543 public void setFpdHdrCopyright(String cr
) {
1544 getFpdHdr().setCopyright(cr
);
1547 public void setFpdHdrLicense(String license
){
1548 LicenseDocument
.License l
= getFpdHdr().getLicense();
1550 getFpdHdr().addNewLicense().setStringValue(license
);
1553 l
.setStringValue(license
);
1557 public void setFpdHdrUrl(String url
){
1558 LicenseDocument
.License l
= getFpdHdr().getLicense();
1564 public void setFpdHdrSpec(String s
){
1565 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1566 getFpdHdr().setSpecification(s
);
1569 Save the processed xml contents to file
1571 @param fpdFile The file to save xml contents
1572 @throws IOException Exceptions during file operation
1574 public void saveAs(File fpdFile
) throws IOException
{
1576 XmlOptions options
= new XmlOptions();
1578 options
.setCharacterEncoding("UTF-8");
1579 options
.setSavePrettyPrint();
1580 options
.setSavePrettyPrintIndent(2);
1582 fpdd
.save(fpdFile
, options
);
1583 } catch (IOException e
) {
1584 e
.printStackTrace();
1589 private String
listToString(List
<String
> l
) {
1594 ListIterator li
= l
.listIterator();
1595 while(li
.hasNext()) {