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
;
26 import java
.util
.Vector
;
28 import javax
.xml
.namespace
.QName
;
30 import org
.apache
.xmlbeans
.XmlCursor
;
31 import org
.apache
.xmlbeans
.XmlObject
;
32 import org
.apache
.xmlbeans
.XmlOptions
;
33 import org
.tianocore
.AntTaskDocument
;
34 import org
.tianocore
.BuildOptionsDocument
;
35 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
36 import org
.tianocore
.EfiSectionType
;
37 import org
.tianocore
.FlashDefinitionFileDocument
;
38 import org
.tianocore
.FlashDocument
;
39 import org
.tianocore
.FrameworkModulesDocument
;
40 import org
.tianocore
.IntermediateOutputType
;
41 import org
.tianocore
.LibrariesDocument
;
42 import org
.tianocore
.ModuleSADocument
;
43 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
44 import org
.tianocore
.ModuleSurfaceAreaDocument
;
45 import org
.tianocore
.OptionDocument
;
46 import org
.tianocore
.OptionsDocument
;
47 import org
.tianocore
.PcdBuildDefinitionDocument
;
48 import org
.tianocore
.PcdCodedDocument
;
49 import org
.tianocore
.PcdDataTypes
;
50 import org
.tianocore
.PcdDeclarationsDocument
;
51 import org
.tianocore
.PcdItemTypes
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PlatformSurfaceAreaDocument
;
54 import org
.tianocore
.FvImageTypes
;
55 import org
.tianocore
.FvImagesDocument
;
56 import org
.tianocore
.LicenseDocument
;
57 import org
.tianocore
.PlatformHeaderDocument
;
58 import org
.tianocore
.SkuInfoDocument
;
59 import org
.tianocore
.UserDefinedAntTasksDocument
;
60 import org
.tianocore
.UserExtensionsDocument
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.WorkspaceProfile
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
63 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
64 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
70 public class FpdFileContents
{
72 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
74 private PlatformSurfaceAreaDocument fpdd
= null;
76 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
78 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
80 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
82 private FlashDocument
.Flash fpdFlash
= null;
84 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
86 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
88 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
90 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
92 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
95 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
97 public void initDynPcdMap() {
98 if (dynPcdMap
== null) {
99 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
100 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
102 removeElement(getfpdFrameworkModules());
103 fpdFrameworkModules
= null;
106 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
107 while (li
.hasNext()) {
108 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
109 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
112 String ModuleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() +
113 " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
114 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
115 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
116 while (lpi
.hasNext()) {
117 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
118 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
119 if (dynPcdMap
.get(pcdKey
) == null) {
120 ArrayList
<String
> al
= new ArrayList
<String
>();
121 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
122 dynPcdMap
.put(pcdKey
, al
);
125 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
132 public ArrayList
<String
> getDynPcdMapValue(String key
) {
133 return dynPcdMap
.get(key
);
136 Constructor to create a new spd file
138 public FpdFileContents() {
140 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
141 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
146 Constructor for existing document object
149 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
151 fpdHdr
= fpdRoot
.getPlatformHeader();
152 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
153 fpdBuildOpts
= fpdRoot
.getBuildOptions();
154 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
155 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
156 fpdFlash
= fpdRoot
.getFlash();
160 Constructor based on an existing spd file
162 @param f Existing spd file
164 public FpdFileContents(File f
) {
166 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
167 fpdRoot
= fpdd
.getPlatformSurfaceArea();
168 } catch (Exception e
) {
169 System
.out
.println(e
.toString());
173 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
174 if (fpdDynPcdBuildDefs
== null){
175 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
177 return fpdDynPcdBuildDefs
;
180 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
181 if (fpdFrameworkModules
== null){
182 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
184 return fpdFrameworkModules
;
187 public void getFrameworkModuleGuid (String fvName
, Vector
<String
> vGuid
) {
188 if (getFrameworkModulesCount() == 0){
192 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
193 while(li
.hasNext()) {
194 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
195 if (moduleSa
.getModuleSaBuildOptions() == null) {
198 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
199 if (fvBinding
== null) {
203 String
[] fvNames
= fvBinding
.split(" ");
204 for (int i
= 0; i
< fvNames
.length
; ++i
) {
205 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
206 vGuid
.add(moduleSa
.getModuleGuid());
213 public int getFrameworkModulesCount() {
214 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
215 removeElement(getfpdFrameworkModules());
216 fpdFrameworkModules
= null;
219 return getfpdFrameworkModules().getModuleSAList().size();
222 public void getFrameworkModulesInfo(String
[][] saa
) {
223 if (getFrameworkModulesCount() == 0){
227 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
229 while(li
.hasNext()) {
230 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
231 saa
[i
][0] = moduleSa
.getModuleGuid();
232 saa
[i
][1] = moduleSa
.getModuleVersion();
234 saa
[i
][2] = moduleSa
.getPackageGuid();
235 saa
[i
][3] = moduleSa
.getPackageVersion();
236 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
241 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
242 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
246 sa
[0] = msa
.getModuleGuid();
247 sa
[1] = msa
.getModuleVersion();
248 sa
[2] = msa
.getPackageGuid();
249 sa
[3] = msa
.getPackageVersion();
250 sa
[4] = listToString(msa
.getSupArchList());
253 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
254 String
[] s
= key
.split(" ");
255 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
256 removeElement(getfpdFrameworkModules());
257 fpdFrameworkModules
= null;
260 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
261 while(li
.hasNext()) {
262 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
263 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
264 if (moduleSa
.getModuleVersion() != null) {
265 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
269 if (moduleSa
.getPackageVersion() != null) {
270 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
274 //ToDo add arch check for s[4]
275 if (moduleSa
.getSupArchList() != null) {
276 if (!listToString(moduleSa
.getSupArchList()).equals(s
[4])) {
286 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
287 ModuleSADocument
.ModuleSA moduleSa
= null;
288 if (fpdRoot
.getFrameworkModules() == null) {
291 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
292 if (cursor
.toFirstChild()) {
293 for (int j
= 0; j
< i
; ++j
) {
294 cursor
.toNextSibling();
296 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
302 public void removeModuleSA(int i
) {
303 XmlObject o
= fpdRoot
.getFrameworkModules();
308 XmlCursor cursor
= o
.newCursor();
309 if (cursor
.toFirstChild()) {
310 for (int j
= 0; j
< i
; ++j
) {
311 cursor
.toNextSibling();
314 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
316 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
317 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
318 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
319 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
320 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
321 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
322 while(li
.hasNext()) {
323 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
324 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
329 cursor
.toPrevToken();
330 if (cursor
.isComment()) {
335 if (getFrameworkModulesCount() == 0) {
343 public boolean adjustPcd (int seqModuleSa
) throws Exception
{
344 boolean dataModified
= false;
345 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
346 int pcdCount
= getPcdDataCount(seqModuleSa
);
347 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
348 getPcdData(seqModuleSa
, saaModuleSaPcd
);
349 String mg
= moduleSa
.getModuleGuid();
350 String mv
= moduleSa
.getModuleVersion();
351 String pg
= moduleSa
.getPackageGuid();
352 String pv
= moduleSa
.getPackageVersion();
353 String arch
= listToString(moduleSa
.getSupArchList());
355 // delete pcd in ModuleSA but not in MSA files any longer.
357 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
358 int libCount
= getLibraryInstancesCount(moduleKey
);
359 String
[][] saaLib
= new String
[libCount
][5];
360 getLibraryInstances(moduleKey
, saaLib
);
361 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
362 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
365 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
366 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], mi
)){
369 for (int j
= 0; j
< saaLib
.length
; ++j
) {
370 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
371 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
373 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], libMi
)) {
377 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
381 catch (Exception e
) {
385 // add new Pcd from MSA file to ModuleSA.
389 for (int i
= 0; i
< vMi
.size(); ++i
) {
390 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
391 .getModuleXmlObject(vMi
393 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
396 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
397 msaPcdIter
:while (li
.hasNext()) {
398 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
399 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
401 for (int j
= 0; j
< al
.size(); ++j
) {
402 if (al
.get(j
).contains(moduleKey
)) {
408 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
409 m
.put("ModuleSurfaceArea", msa
);
410 SurfaceAreaQuery
.setDoc(m
);
411 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
412 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
413 if (spdPcd
== null) {
417 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
421 // AddItem to ModuleSA PcdBuildDefinitions
423 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
424 : msaPcd
.getDefaultValue();
426 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
427 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
);
440 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
442 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
446 String
[] s
= moduleInfo
.split(" ");
447 for(int i
= 0; i
< al
.size(); ++i
){
448 String consumer
= al
.get(i
);
449 if (consumer
.contains(s
[0]) && consumer
.contains(s
[2])){
450 String
[] consumerPart
= consumer
.split(" ");
451 if (!consumerPart
[4].equals(s
[4])) {
459 if (al
.size() == 0) {
460 defaultPcdValue
.remove(pcdKey
);
461 dynPcdMap
.remove(pcdKey
);
462 String
[] s1
= pcdKey
.split(" ");
463 removeDynamicPcdBuildData(s1
[0], s1
[1]);
468 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
470 public int getPcdDataCount (int i
){
471 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
473 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
476 return msa
.getPcdBuildDefinition().getPcdDataList().size();
480 public void getPcdData (int i
, String
[][] saa
) {
481 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
483 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
486 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
487 for (int k
= 0; k
< saa
.length
; ++k
) {
488 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
489 saa
[k
][0] = pcdData
.getCName();
490 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
491 saa
[k
][2] = pcdData
.getItemType()+"";
492 saa
[k
][3] = pcdData
.getToken().toString();
493 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
494 saa
[k
][5] = pcdData
.getDatumType()+"";
495 saa
[k
][6] = pcdData
.getValue();
500 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
501 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
502 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
506 String mg
= moduleSa
.getModuleGuid();
507 String mv
= moduleSa
.getModuleVersion();
508 String pg
= moduleSa
.getPackageGuid();
509 String pv
= moduleSa
.getPackageVersion();
510 String arch
= listToString(moduleSa
.getSupArchList());
511 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
513 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
514 if (cursor
.toFirstChild()){
517 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
518 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
519 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
520 if (getPcdDataCount(seqModuleSa
) == 1) {
527 while(cursor
.toNextSibling());
533 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
534 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
535 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
539 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
540 if (cursor
.toFirstChild()){
542 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
543 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
544 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
545 if(pcdData
.getDatumType().equals("VOID*")) {
546 pcdData
.setMaxDatumSize(new Integer(maxSize
));
548 pcdData
.setValue(value
);
549 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
553 while(cursor
.toNextSibling());
558 /**Get original Pcd info from MSA & SPD files.
559 * @param mi ModuleIdentification from which MSA & SPD come
560 * @param cName PCD cName
561 * @param sa Results: HelpText, Original item type.
564 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
) throws Exception
{
567 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
568 if (msa
.getPcdCoded() == null) {
572 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
573 m
.put("ModuleSurfaceArea", msa
);
574 SurfaceAreaQuery
.setDoc(m
);
575 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
577 // First look through MSA pcd entries.
579 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
580 ListIterator li
= l
.listIterator();
581 while(li
.hasNext()) {
582 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
583 if (!msaPcd
.getCName().equals(cName
)) {
586 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
589 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
590 if (spdPcd
== null) {
594 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
597 // Get Pcd help text and original item type.
599 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
600 sa
[1] = msaPcd
.getPcdItemType()+"";
614 /**Remove PCDBuildDefinition entries from ModuleSA
615 * @param moduleKey identifier of ModuleSA.
616 * @param consumer where these entries come from.
618 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
620 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
621 if (msa
.getPcdCoded() == null) {
625 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
626 ListIterator li
= l
.listIterator();
628 while(li
.hasNext()) {
629 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
630 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
631 if (moduleSA
.getPcdBuildDefinition() != null) {
632 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
633 if (cursor
.toFirstChild()) {
635 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
637 if (msaPcd
.getCName().equals(pcdData
.getCName())
638 && msaPcd
.getTokenSpaceGuidCName().equals(pcdData
.getTokenSpaceGuidCName())) {
640 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
645 } while (cursor
.toNextSibling());
658 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
660 public int getLibraryInstancesCount(String key
) {
661 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
662 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
665 return msa
.getLibraries().getInstanceList().size();
668 public void getLibraryInstances(String key
, String
[][] saa
){
669 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
670 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
674 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
675 for (int i
= 0; i
< saa
.length
; ++i
) {
676 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
677 saa
[i
][1] = instance
.getModuleGuid();
678 saa
[i
][2] = instance
.getModuleVersion();
679 saa
[i
][3] = instance
.getPackageGuid();
680 saa
[i
][4] = instance
.getPackageVersion();
684 public void removeLibraryInstance(String key
, int i
) {
685 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
686 if (msa
== null || msa
.getLibraries() == null){
690 XmlCursor cursor
= msa
.getLibraries().newCursor();
691 if (cursor
.toFirstChild()) {
692 for (int j
= 0; j
< i
; ++j
) {
693 cursor
.toNextSibling();
696 cursor
.toPrevToken();
697 if (cursor
.isComment()) {
702 if (getLibraryInstancesCount(key
) == 0) {
711 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
712 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
714 msa
= getfpdFrameworkModules().addNewModuleSA();
716 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
718 libs
= msa
.addNewLibraries();
721 String mn
= libMi
.getName();
722 String mg
= libMi
.getGuid();
723 String mv
= libMi
.getVersion();
724 String pn
= libMi
.getPackageId().getName();
725 String pg
= libMi
.getPackageId().getGuid();
726 String pv
= libMi
.getPackageId().getVersion();
727 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
728 XmlCursor cursor
= instance
.newCursor();
730 String comment
= "Pkg: " + pn
+ " Mod: " + mn
731 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
732 cursor
.insertComment(comment
);
741 instance
.setModuleGuid(mg
);
742 instance
.setModuleVersion(mv
);
743 instance
.setPackageGuid(pg
);
744 instance
.setPackageVersion(pv
);
748 public String
getFvBinding(String moduleKey
){
749 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
750 return getFvBinding (moduleSa
);
753 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
754 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
757 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
760 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
761 if (moduleSa
== null ) {
764 if (fvBinding
== null || fvBinding
.length() == 0) {
765 if(moduleSa
.getModuleSaBuildOptions() != null){
766 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
770 if(moduleSa
.getModuleSaBuildOptions() == null){
771 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
774 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
778 public void setFvBinding(String moduleKey
, String fvBinding
){
779 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
780 setFvBinding (moduleSa
, fvBinding
);
783 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
784 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
788 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
789 String
[] fvNamesArray
= fvNameList
.split(" ");
791 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
792 if (fvNamesArray
[i
].equals(fvName
)) {
800 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
801 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
805 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
806 String
[] fvNamesArray
= fvNameList
.split(" ");
808 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
809 if (fvNamesArray
[i
].equals(fvName
)) {
814 // jump over where the input fvName occurs in the original Fv list.
815 if (occursAt
!= -1) {
816 String newFvNameList
= " ";
817 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
821 newFvNameList
+= fvNamesArray
[i
];
823 setFvBinding (moduleSa
, newFvNameList
.trim());
829 * @param fvName The FV name that to be removed from FvBinding List.
831 public void removeFvBindingAll (String fvName
) {
832 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
833 removeElement(getfpdFrameworkModules());
834 fpdFrameworkModules
= null;
838 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
839 while (li
.hasNext()) {
840 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
841 removeFvBinding (moduleSa
, fvName
);
845 public void appendFvBindingAll (String fvName
) {
846 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
847 removeElement(getfpdFrameworkModules());
848 fpdFrameworkModules
= null;
852 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
853 while (li
.hasNext()) {
854 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
855 appendFvBinding (moduleSa
, fvName
);
859 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
860 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
861 removeElement(getfpdFrameworkModules());
862 fpdFrameworkModules
= null;
866 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
867 while (li
.hasNext()) {
868 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
869 String fvBinding
= getFvBinding (moduleSa
);
870 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
871 appendFvBinding (moduleSa
, newFvName
);
876 public void appendFvBinding (String moduleKey
, String fvName
) {
877 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
878 appendFvBinding (moduleSa
, fvName
);
881 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
882 if (moduleSa
== null) {
886 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
887 setFvBinding(moduleSa
, fvName
);
891 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
892 String newFvNameList
= fvNameList
+ " " + fvName
;
893 setFvBinding (moduleSa
, newFvNameList
.trim());
896 public void updateFvBindingInModuleSA (ModuleIdentification mi
, String fvName
) {
897 Vector
<Object
> vSupArchs
= new Vector
<Object
>();
898 getPlatformDefsSupportedArchs(vSupArchs
);
899 String moduleInfo
= mi
.getGuid() + " " + mi
.getVersion() + " " + mi
.getPackageId().getGuid() + " " + mi
.getPackageId().getVersion();
900 for (int i
= 0; i
< vSupArchs
.size(); ++i
) {
901 String moduleKey
= moduleInfo
+ " " + vSupArchs
.get(i
);
902 appendFvBinding (moduleKey
, fvName
);
906 public String
getFfsFileNameGuid(String moduleKey
){
907 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
908 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
911 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
914 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
915 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
919 if(msa
.getModuleSaBuildOptions() == null){
920 msa
.addNewModuleSaBuildOptions();
923 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
924 if (fileGuid
!= null) {
925 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
928 XmlCursor cursor
= msaBuildOpts
.newCursor();
929 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
937 public String
getFfsFormatKey(String moduleKey
){
938 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
939 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
942 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
945 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
946 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
950 if(msa
.getModuleSaBuildOptions() == null){
951 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
954 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
957 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
958 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
959 moduleSa
.setForceDebug(dbgEnable
);
962 public boolean getModuleSAForceDebug (int i
) {
963 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
964 if (moduleSa
.getForceDebug() == true) {
970 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
971 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
972 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
973 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
977 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
978 ListIterator li
= lOpt
.listIterator();
980 while(li
.hasNext()) {
981 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
982 if (opt
.getBuildTargets() != null) {
983 saa
[i
][0] = listToString(opt
.getBuildTargets());
985 saa
[i
][1] = opt
.getToolChainFamily();
986 saa
[i
][2] = opt
.getTagName();
987 saa
[i
][3] = opt
.getToolCode();
989 if (opt
.getSupArchList() != null){
990 saa
[i
][4] = listToString(opt
.getSupArchList());
996 saa
[i
][5] = opt
.getStringValue();
1002 public int getModuleSAOptionsCount(String moduleKey
){
1003 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1004 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1005 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1008 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1011 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1012 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1013 if (msa
.getModuleSaBuildOptions() == null) {
1014 msa
.addNewModuleSaBuildOptions();
1016 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1017 msa
.getModuleSaBuildOptions().addNewOptions();
1019 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1020 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1023 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1024 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1025 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1028 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1029 XmlCursor cursor
= opts
.newCursor();
1030 if (cursor
.toFirstChild()) {
1031 for (int j
= 0; j
< i
; ++j
){
1032 cursor
.toNextSibling();
1039 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1040 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1041 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1044 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1045 XmlCursor cursor
= opts
.newCursor();
1046 if (cursor
.toFirstChild()) {
1047 for (int j
= 0; j
< i
; ++j
){
1048 cursor
.toNextSibling();
1050 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1051 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1056 /**add pcd information of module mi to a ModuleSA.
1058 * @param moduleSa if null, generate a new ModuleSA.
1060 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1061 //ToDo add Arch filter
1064 if (moduleSa
== null) {
1065 moduleSa
= genModuleSA(mi
, arch
);
1068 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
1069 if (msa
.getPcdCoded() == null) {
1073 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
1074 m
.put("ModuleSurfaceArea", msa
);
1075 SurfaceAreaQuery
.setDoc(m
);
1076 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1078 // Implementing InitializePlatformPcdBuildDefinitions
1080 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1081 ListIterator li
= l
.listIterator();
1082 while(li
.hasNext()) {
1083 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
1084 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1085 if (spdPcd
== null) {
1089 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module " + mi
.getName());
1092 // AddItem to ModuleSA PcdBuildDefinitions
1094 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1096 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
1100 catch (Exception e
){
1107 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1109 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1110 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1112 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1116 for (int j
= 0; j
< xo
.length
; ++j
) {
1117 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1118 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1119 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1124 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1135 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1136 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1137 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1138 XmlCursor cursor
= msa
.newCursor();
1140 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1141 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1142 cursor
.insertComment(comment
);
1145 e
.printStackTrace();
1150 msa
.setModuleGuid(mi
.getGuid());
1151 msa
.setModuleVersion(mi
.getVersion());
1152 msa
.setPackageGuid(pi
.getGuid());
1153 msa
.setPackageVersion(pi
.getVersion());
1155 Vector
<String
> v
= new Vector
<String
>();
1157 msa
.setSupArchList(v
);
1163 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
)
1164 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1165 if (moduleSa
.getPcdBuildDefinition() == null){
1166 moduleSa
.addNewPcdBuildDefinition();
1169 // constructe pcd to modulesa mapping first.
1170 // Attention : for any error condition, remove from map this pcd.
1172 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1173 if (pcdConsumer
== null) {
1174 pcdConsumer
= new ArrayList
<String
>();
1177 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1179 if (pcdConsumer
.size() > 0) {
1180 String
[] valPart
= pcdConsumer
.get(0).split(" ");
1181 itemType
= valPart
[5];
1183 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
1184 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList())
1186 pcdConsumer
.add(listValue
);
1187 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1189 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1190 fpdPcd
.setCName(cName
);
1191 fpdPcd
.setToken(token
);
1192 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1193 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1194 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1196 if (defaultVal
!= null){
1197 fpdPcd
.setValue(defaultVal
);
1200 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1201 fpdPcd
.setValue("0");
1203 if (dataType
.equals("BOOLEAN")){
1204 fpdPcd
.setValue("FALSE");
1206 if (dataType
.equals("VOID*")) {
1207 fpdPcd
.setValue("");
1211 // Using existing pcd value, if this pcd already exists in other moduleSa.
1213 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1214 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1217 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1220 if (dataType
.equals("UINT8")){
1221 fpdPcd
.setMaxDatumSize(1);
1223 if (dataType
.equals("UINT16")) {
1224 fpdPcd
.setMaxDatumSize(2);
1226 if (dataType
.equals("UINT32")) {
1227 fpdPcd
.setMaxDatumSize(4);
1229 if (dataType
.equals("UINT64")){
1230 fpdPcd
.setMaxDatumSize(8);
1232 if (dataType
.equals("BOOLEAN")){
1233 fpdPcd
.setMaxDatumSize(1);
1235 if (dataType
.equals("VOID*")) {
1236 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1237 fpdPcd
.setMaxDatumSize(maxSize
);
1241 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1242 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1244 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1245 // so need to add one dyn pcd.
1247 if (al
.size() == 1) {
1248 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1254 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1255 if (datum
== null) {
1258 char ch
= datum
.charAt(0);
1262 // For void* type PCD, only three datum is support:
1263 // 1) Unicode: string with start char is "L"
1264 // 2) Ansci: String is ""
1265 // 3) byte array: String start char "{"
1268 start
= datum
.indexOf('\"');
1269 end
= datum
.lastIndexOf('\"');
1270 if ((start
> end
) ||
1271 (end
> datum
.length())||
1272 ((start
== end
) && (datum
.length() > 0))) {
1273 //ToDo Error handling here
1274 throw new PcdValueMalFormed (datum
);
1277 strValue
= datum
.substring(start
+ 1, end
);
1278 return strValue
.length() * 2;
1279 } else if (ch
== '\"'){
1280 start
= datum
.indexOf('\"');
1281 end
= datum
.lastIndexOf('\"');
1282 if ((start
> end
) ||
1283 (end
> datum
.length())||
1284 ((start
== end
) && (datum
.length() > 0))) {
1285 throw new PcdValueMalFormed (datum
);
1287 strValue
= datum
.substring(start
+ 1, end
);
1288 return strValue
.length();
1289 } else if (ch
=='{') {
1290 String
[] strValueArray
;
1292 start
= datum
.indexOf('{');
1293 end
= datum
.lastIndexOf('}');
1294 strValue
= datum
.substring(start
+ 1, end
);
1295 strValue
= strValue
.trim();
1296 if (strValue
.length() == 0) {
1299 strValueArray
= strValue
.split(",");
1300 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1301 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1304 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1305 // "it must be a byte array. But the element of %s exceed the byte range",
1306 throw new PcdValueMalFormed (datum
);
1309 return strValueArray
.length
;
1313 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1314 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1315 // "2) ANSIC string: like \"xxx\";\r\n"+
1316 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1317 // "but the datum in seems does not following above format!",
1318 throw new PcdValueMalFormed (datum
);
1323 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1324 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1329 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1331 return dynPcdMap
.get(pcdKey
);
1334 public int getDynamicPcdBuildDataCount() {
1335 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1336 removeElement(getfpdDynPcdBuildDefs());
1337 fpdDynPcdBuildDefs
= null;
1340 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1343 public void getDynamicPcdBuildData(String
[][] saa
) {
1344 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1345 removeElement(getfpdDynPcdBuildDefs());
1346 fpdDynPcdBuildDefs
= null;
1349 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1350 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1352 while(li
.hasNext()) {
1353 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1354 saa
[i
][0] = dynPcd
.getCName();
1355 saa
[i
][1] = dynPcd
.getToken().toString();
1356 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1357 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1358 saa
[i
][4] = dynPcd
.getDatumType().toString();
1364 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1365 throws PcdValueMalFormed
{
1366 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1367 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1368 dynPcdData
.setCName(cName
);
1369 dynPcdData
.setToken(token
);
1370 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1371 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1373 BigInteger bigInt
= new BigInteger("0");
1374 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1375 skuInfo
.setSkuId(bigInt
);
1376 if (defaultVal
!= null){
1377 skuInfo
.setValue(defaultVal
);
1380 if (dataType
.equals("UINT8")){
1381 skuInfo
.setValue("0");
1383 if (dataType
.equals("UINT16")) {
1384 skuInfo
.setValue("0");
1386 if (dataType
.equals("UINT32")) {
1387 skuInfo
.setValue("0");
1389 if (dataType
.equals("UINT64")){
1390 skuInfo
.setValue("0");
1392 if (dataType
.equals("BOOLEAN")){
1393 skuInfo
.setValue("false");
1395 if (dataType
.equals("VOID*")) {
1396 skuInfo
.setValue("");
1399 if (dataType
.equals("UINT8")){
1400 dynPcdData
.setMaxDatumSize(1);
1402 if (dataType
.equals("UINT16")) {
1403 dynPcdData
.setMaxDatumSize(2);
1405 if (dataType
.equals("UINT32")) {
1406 dynPcdData
.setMaxDatumSize(4);
1408 if (dataType
.equals("UINT64")){
1409 dynPcdData
.setMaxDatumSize(8);
1411 if (dataType
.equals("BOOLEAN")){
1412 dynPcdData
.setMaxDatumSize(1);
1414 if (dataType
.equals("VOID*")) {
1415 int maxSize
= setMaxSizeForPointer(defaultVal
);
1416 dynPcdData
.setMaxDatumSize(maxSize
);
1420 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1421 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1426 XmlCursor cursor
= o
.newCursor();
1427 if (cursor
.toFirstChild()) {
1429 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1430 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1431 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1433 if (getDynamicPcdBuildDataCount() == 1) {
1441 while (cursor
.toNextSibling());
1446 // Get the Sku Info count of ith dyn pcd element.
1448 public int getDynamicPcdSkuInfoCount(int i
){
1449 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1450 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1454 int skuInfoCount
= 0;
1455 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1456 if (cursor
.toFirstChild()) {
1457 for (int j
= 0; j
< i
; ++j
) {
1458 cursor
.toNextSibling();
1460 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1461 if (pcdData
.getSkuInfoList() == null) {
1465 skuInfoCount
= pcdData
.getSkuInfoList().size();
1469 return skuInfoCount
;
1472 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1473 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1474 removeElement(getfpdDynPcdBuildDefs());
1475 fpdDynPcdBuildDefs
= null;
1479 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1480 if (cursor
.toFirstChild()) {
1481 for (int j
= 0; j
< i
; ++j
) {
1482 cursor
.toNextSibling();
1484 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1485 if (pcdData
.getSkuInfoList() == null) {
1490 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1492 while (li
.hasNext()) {
1493 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1494 saa
[k
][0] = skuInfo
.getSkuId()+"";
1495 saa
[k
][1] = skuInfo
.getVariableName();
1496 saa
[k
][2] = skuInfo
.getVariableGuid();
1497 saa
[k
][3] = skuInfo
.getVariableOffset();
1498 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1499 saa
[k
][5] = skuInfo
.getVpdOffset();
1500 saa
[k
][6] = skuInfo
.getValue();
1510 public String
getDynamicPcdBuildDataValue(int i
){
1511 String value
= null;
1512 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1513 removeElement(getfpdDynPcdBuildDefs());
1514 fpdDynPcdBuildDefs
= null;
1518 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1519 if (cursor
.toFirstChild()) {
1520 for (int j
= 0; j
< i
; ++j
) {
1521 cursor
.toNextSibling();
1523 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1524 if (pcdData
.getSkuInfoList() == null) {
1528 value
= pcdData
.getSkuInfoArray(0).getValue();
1535 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1536 String vpdOffset
= null;
1537 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1538 removeElement(getfpdDynPcdBuildDefs());
1539 fpdDynPcdBuildDefs
= null;
1543 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1544 if (cursor
.toFirstChild()) {
1545 for (int j
= 0; j
< i
; ++j
) {
1546 cursor
.toNextSibling();
1548 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1549 if (pcdData
.getSkuInfoList() == null) {
1553 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1560 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1561 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1562 removeElement(getfpdDynPcdBuildDefs());
1563 fpdDynPcdBuildDefs
= null;
1567 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1568 if (cursor
.toFirstChild()) {
1569 for (int j
= 0; j
< i
; ++j
) {
1570 cursor
.toNextSibling();
1572 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1573 if (pcdData
.getSkuInfoList() == null) {
1578 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1579 cursor
.toChild(qSkuInfo
);
1586 // generate sku info for ith dyn pcd build data.
1588 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1589 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1590 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1594 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1595 if (cursor
.toFirstChild()) {
1596 for (int j
= 0; j
< i
; ++j
) {
1597 cursor
.toNextSibling();
1599 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1600 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1601 skuInfo
.setSkuId(new BigInteger(id
));
1602 if (varName
!= null){
1603 skuInfo
.setVariableName(varName
);
1604 skuInfo
.setVariableGuid(varGuid
);
1605 skuInfo
.setVariableOffset(varOffset
);
1606 skuInfo
.setHiiDefaultValue(hiiDefault
);
1608 else if (vpdOffset
!= null){
1609 skuInfo
.setVpdOffset(vpdOffset
);
1612 skuInfo
.setValue(value
);
1617 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1618 String hiiDefault
, String vpdOffset
, String value
, int i
){
1619 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1623 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1624 if (cursor
.toFirstChild()) {
1625 for (int j
= 0; j
< i
; ++j
) {
1626 cursor
.toNextSibling();
1628 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1629 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1630 while (li
.hasNext()) {
1631 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1632 if (skuInfo
.getSkuId().toString().equals(id
)){
1633 if (varName
!= null){
1634 skuInfo
.setVariableName(varName
);
1635 skuInfo
.setVariableGuid(varGuid
);
1636 skuInfo
.setVariableOffset(varOffset
);
1637 skuInfo
.setHiiDefaultValue(hiiDefault
);
1639 else if (vpdOffset
!= null){
1640 skuInfo
.setVpdOffset(vpdOffset
);
1643 skuInfo
.setValue(value
);
1651 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1652 if (fpdBuildOpts
== null) {
1653 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1655 return fpdBuildOpts
;
1658 public void genBuildOptionsUserExtensions(String fvName
, String outputFileName
, Vector
<String
[]> includeModules
) {
1659 QName elementFvName
= new QName (xmlNs
, "FvName");
1660 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1661 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1662 QName elementModule
= new QName(xmlNs
, "Module");
1664 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1665 userExts
.setUserID("IMAGES");
1666 userExts
.setIdentifier(new BigInteger("1"));
1667 XmlCursor cursor
= userExts
.newCursor();
1668 cursor
.toEndToken();
1670 cursor
.beginElement(elementFvName
);
1671 cursor
.insertChars(fvName
);
1672 cursor
.toNextToken();
1674 cursor
.beginElement(elementInfFileName
);
1675 cursor
.insertChars(fvName
+ ".inf");
1676 cursor
.toNextToken();
1678 cursor
.beginElement(elementIncludeModules
);
1679 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1680 cursor
.beginElement(elementModule
);
1681 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1682 cursor
.insertAttributeWithValue("BaseName", includeModules
.get(i
)[1]);
1683 cursor
.toEndToken();
1684 cursor
.toNextToken();
1689 public int getUserExtsIncModCount (String fvName
) {
1690 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1693 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1694 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1695 while (li
.hasNext()) {
1696 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1697 if (!ues
.getUserID().equals("IMAGES")) {
1700 XmlCursor cursor
= ues
.newCursor();
1701 cursor
.toFirstChild();
1702 String elementName
= cursor
.getTextValue();
1703 if (elementName
.equals(fvName
)) {
1704 cursor
.toNextSibling(elementIncludeModules
);
1705 if (cursor
.toFirstChild()) {
1707 for (i
= 1; cursor
.toNextSibling(); ++i
);
1719 public void getUserExtsIncMods(String fvName
, String
[][] saa
) {
1720 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1724 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1725 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1726 QName attribUserId
= new QName ("UserID");
1727 QName elementFvName
= new QName (xmlNs
, "FvName");
1728 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1729 QName attribModuleGuid
= new QName("ModuleGuid");
1730 QName attribBaseName
= new QName("BaseName");
1732 if (cursor
.toChild(elementUserExts
)) {
1735 if (cursor
.getAttributeText(attribUserId
).equals("IMAGES")) {
1736 cursor
.toChild(elementFvName
);
1737 String elementName
= cursor
.getTextValue();
1738 if (elementName
.equals(fvName
)) {
1739 cursor
.toNextSibling(elementIncludeModules
);
1740 if (cursor
.toFirstChild()) {
1743 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1744 saa
[i
][1] = cursor
.getAttributeText(attribBaseName
);
1746 }while (cursor
.toNextSibling());
1752 }while (cursor
.toNextSibling(elementUserExts
));
1758 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1759 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1762 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1763 while (li
.hasNext()) {
1764 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1765 if (!ues
.getUserID().equals("IMAGES")) {
1768 XmlCursor cursor
= ues
.newCursor();
1769 cursor
.toFirstChild();
1770 String elementName
= cursor
.getTextValue();
1771 if (elementName
.equals(oldFvName
)) {
1772 cursor
.setTextValue(newFvName
);
1779 public void removeBuildOptionsUserExtensions (String fvName
) {
1780 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1784 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1785 while (li
.hasNext()) {
1786 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1787 if (!ues
.getUserID().equals("IMAGES")) {
1790 XmlCursor cursor
= ues
.newCursor();
1791 cursor
.toFirstChild();
1792 String elementName
= cursor
.getTextValue();
1793 if (elementName
.equals(fvName
)) {
1805 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
1806 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1807 if (udats
== null) {
1808 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
1811 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
1812 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1815 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1816 at
.setId(new Integer(id
));
1817 XmlCursor cursor
= at
.newCursor();
1818 if (fileName
!= null){
1819 at
.setFilename(fileName
);
1821 else if (cursor
.toChild(xmlNs
, "Filename")) {
1824 if (execOrder
!= null) {
1825 at
.setAntCmdOptions(execOrder
);
1827 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
1833 public void removeBuildOptionsUserDefAntTask(int i
) {
1834 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1838 XmlCursor cursor
= o
.newCursor();
1839 if (cursor
.toFirstChild()) {
1840 for (int j
= 0; j
< i
; ++j
) {
1841 cursor
.toNextSibling();
1844 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1852 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1853 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1857 XmlCursor cursor
= o
.newCursor();
1858 if (cursor
.toFirstChild()) {
1859 for (int j
= 0; j
< i
; ++j
) {
1860 cursor
.toNextSibling();
1862 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1863 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1868 public int getBuildOptionsUserDefAntTaskCount() {
1869 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1870 if (udats
== null || udats
.getAntTaskList() == null) {
1874 return udats
.getAntTaskList().size();
1877 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1878 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1879 if (udats
== null || udats
.getAntTaskList() == null) {
1883 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1884 ListIterator li
= l
.listIterator();
1886 while (li
.hasNext()) {
1887 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1888 saa
[i
][0] = at
.getId() + "";
1889 saa
[i
][1] = saa
[i
][2] = "";
1890 if (at
.getFilename() != null){
1891 saa
[i
][1] = at
.getFilename();
1893 if (at
.getAntCmdOptions() != null) {
1894 saa
[i
][2] = at
.getAntCmdOptions();
1899 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1900 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1902 opts
= getfpdBuildOpts().addNewOptions();
1904 OptionDocument
.Option opt
= opts
.addNewOption();
1905 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1908 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
1909 opt
.setStringValue(contents
);
1911 opt
.setBuildTargets(buildTargets
);
1912 opt
.setToolChainFamily(toolChain
);
1913 opt
.setTagName(tagName
);
1914 opt
.setToolCode(toolCmd
);
1916 if (archList
!= null) {
1917 opt
.setSupArchList(archList
);
1920 if (opt
.isSetSupArchList()) {
1921 opt
.unsetSupArchList();
1926 public void removeBuildOptionsOpt(int i
){
1928 XmlObject o
= getfpdBuildOpts().getOptions();
1933 XmlCursor cursor
= o
.newCursor();
1934 if (cursor
.toFirstChild()) {
1935 for (int j
= 0; j
< i
; ++j
) {
1936 cursor
.toNextSibling();
1939 if (getBuildOptionsOptCount() == 0) {
1947 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1948 XmlObject o
= getfpdBuildOpts().getOptions();
1953 XmlCursor cursor
= o
.newCursor();
1954 if (cursor
.toFirstChild()) {
1955 for (int j
= 0; j
< i
; ++j
) {
1956 cursor
.toNextSibling();
1958 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1959 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1964 public int getBuildOptionsOptCount(){
1965 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1968 return getfpdBuildOpts().getOptions().getOptionList().size();
1971 public void getBuildOptionsOpts(String
[][] saa
) {
1972 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1976 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1977 ListIterator li
= lOpt
.listIterator();
1979 while(li
.hasNext()) {
1980 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1981 if (opt
.getBuildTargets() != null) {
1982 saa
[i
][0] = listToString(opt
.getBuildTargets());
1984 saa
[i
][1] = opt
.getToolChainFamily();
1985 if (opt
.getSupArchList() != null){
1986 saa
[i
][2] = listToString(opt
.getSupArchList());
1989 saa
[i
][3] = opt
.getToolCode();
1990 saa
[i
][4] = opt
.getTagName();
1991 saa
[i
][5] = opt
.getStringValue();
1997 public void genBuildOptionsFfs(String ffsKey
, String type
) {
1998 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
1999 ffs
.setFfsKey(ffsKey
);
2001 ffs
.addNewSections().setEncapsulationType(type
);
2005 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2006 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2008 ffs
.addNewSections().setEncapsulationType(type
);
2012 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2013 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2014 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2015 attrib
.setName(name
);
2016 attrib
.setValue(value
);
2019 /**update jth attribute of ith ffs.
2023 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2024 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2025 XmlCursor cursor
= ffs
.newCursor();
2026 QName qAttrib
= new QName(xmlNs
, "Attribute");
2027 if (cursor
.toChild(qAttrib
)) {
2028 for (int k
= 0; k
< j
; ++k
) {
2029 cursor
.toNextSibling(qAttrib
);
2031 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2032 attrib
.setName(name
);
2033 attrib
.setValue(value
);
2038 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2039 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2040 XmlCursor cursor
= ffs
.newCursor();
2041 QName qAttrib
= new QName(xmlNs
, "Attribute");
2042 if (cursor
.toChild(qAttrib
)) {
2043 for (int k
= 0; k
< j
; ++k
) {
2044 cursor
.toNextSibling(qAttrib
);
2051 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2052 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2056 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2058 if (sections
== null){
2059 sections
= ffs
.addNewSections();
2061 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2064 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2065 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2066 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2067 if (sections
== null) {
2070 XmlCursor cursor
= sections
.newCursor();
2071 QName qSection
= new QName(xmlNs
, "Section");
2072 if (cursor
.toChild(qSection
)) {
2073 for (int k
= 0; k
< j
; ++k
) {
2074 cursor
.toNextSibling(qSection
);
2081 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2082 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2083 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2084 if (sections
== null) {
2087 XmlCursor cursor
= sections
.newCursor();
2088 QName qSection
= new QName(xmlNs
, "Section");
2089 if (cursor
.toChild(qSection
)) {
2090 for (int k
= 0; k
< j
; ++k
) {
2091 cursor
.toNextSibling(qSection
);
2093 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2094 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2099 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2100 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2104 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2106 if (sections
== null){
2107 sections
= ffs
.addNewSections();
2109 sections
.addNewSections().setEncapsulationType(encapType
);
2112 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2113 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2114 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2115 if (sections
== null) {
2118 XmlCursor cursor
= sections
.newCursor();
2119 QName qSections
= new QName(xmlNs
, "Sections");
2120 if (cursor
.toChild(qSections
)) {
2121 for (int k
= 0; k
< j
; ++k
) {
2122 cursor
.toNextSibling(qSections
);
2129 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2130 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2131 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2132 if (sections
== null) {
2135 XmlCursor cursor
= sections
.newCursor();
2136 QName qSections
= new QName(xmlNs
, "Sections");
2137 if (cursor
.toChild(qSections
)) {
2138 for (int k
= 0; k
< j
; ++k
) {
2139 cursor
.toNextSibling(qSections
);
2141 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2142 sections2
.setEncapsulationType(type
);
2147 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2148 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2152 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2153 XmlCursor cursor
= sections
.newCursor();
2154 QName qSections
= new QName(xmlNs
, "Sections");
2155 if (cursor
.toChild(qSections
)){
2156 for (int k
= 0; k
< j
; ++k
) {
2157 cursor
.toNextSibling(qSections
);
2159 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2160 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2165 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2166 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2167 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2168 if (sections
== null) {
2171 XmlCursor cursor
= sections
.newCursor();
2172 QName qSections
= new QName(xmlNs
, "Sections");
2173 if (cursor
.toChild(qSections
)) {
2174 for (int l
= 0; l
< j
; ++l
) {
2175 cursor
.toNextSibling(qSections
);
2177 if (cursor
.toFirstChild()) {
2179 for (; m
< k
; ++m
) {
2180 cursor
.toNextSibling();
2192 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2193 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2194 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2195 if (sections
== null) {
2198 XmlCursor cursor
= sections
.newCursor();
2199 QName qSections
= new QName(xmlNs
, "Sections");
2200 if (cursor
.toChild(qSections
)) {
2201 for (int l
= 0; l
< j
; ++l
) {
2202 cursor
.toNextSibling(qSections
);
2204 if (cursor
.toFirstChild()) {
2205 for (int m
= 0; m
< k
; ++m
) {
2206 cursor
.toNextSibling();
2208 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2209 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2215 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2216 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2220 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2221 XmlCursor cursor
= sections
.newCursor();
2222 QName qSections
= new QName(xmlNs
, "Sections");
2223 if (cursor
.toChild(qSections
)){
2224 for (int k
= 0; k
< j
; ++k
) {
2225 cursor
.toNextSibling(qSections
);
2227 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2228 if (sections2
.getSectionList() == null){
2232 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2233 while(li
.hasNext()) {
2234 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2235 if (section
.isSetSectionType()) {
2236 al
.add(section
.getSectionType().toString());
2245 public int getBuildOptionsFfsCount(){
2246 if (getfpdBuildOpts().getFfsList() == null) {
2249 return getfpdBuildOpts().getFfsList().size();
2252 public void getBuildOptionsFfsKey(String
[][] saa
) {
2253 if (getfpdBuildOpts().getFfsList() == null) {
2256 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2258 while(li
.hasNext()){
2259 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2260 saa
[i
][0] = ffs
.getFfsKey();
2265 public void updateBuildOptionsFfsKey(int i
, String key
) {
2266 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2270 /**Get ith FFS key and contents.
2273 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2274 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2278 sa
[0] = ffs
.getFfsKey();
2279 if (ffs
.getSections() != null) {
2280 if(ffs
.getSections().getEncapsulationType() != null){
2281 sa
[1] = ffs
.getSections().getEncapsulationType();
2283 if (ffs
.getSections().getSectionList() != null){
2284 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2285 while (li
.hasNext()) {
2286 firstLevelSection
.add(li
.next().getSectionType().toString());
2289 if (ffs
.getSections().getSectionsList() != null) {
2290 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2291 while(li
.hasNext()) {
2292 firstLevelSections
.add(li
.next().getEncapsulationType());
2296 if (ffs
.getAttributeList() != null) {
2297 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2298 while(li
.hasNext()) {
2299 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2300 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2309 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2310 XmlObject o
= getfpdBuildOpts();
2311 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2313 XmlCursor cursor
= o
.newCursor();
2314 QName qFfs
= new QName(xmlNs
, "Ffs");
2315 if (cursor
.toChild(qFfs
)) {
2316 for (int j
= 0; j
< i
; ++j
) {
2317 cursor
.toNextSibling(qFfs
);
2319 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2325 public void removeBuildOptionsFfs(int i
) {
2326 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2331 XmlCursor cursor
= ffs
.newCursor();
2338 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2339 if (fpdPlatformDefs
== null){
2340 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2342 return fpdPlatformDefs
;
2345 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2346 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2349 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2350 while(li
.hasNext()) {
2351 archs
.add(li
.next());
2355 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2356 if (archs
!= null) {
2357 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2360 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2361 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2362 // cursor.removeXml();
2364 // cursor.dispose();
2368 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2369 if (getfpdPlatformDefs().getBuildTargets() == null) {
2372 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2373 while(li
.hasNext()) {
2374 targets
.add(li
.next());
2378 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2379 getfpdPlatformDefs().setBuildTargets(targets
);
2382 public void genPlatformDefsSkuInfo(String id
, String name
) {
2383 SkuInfoDocument
.SkuInfo skuInfo
= null;
2384 if (getfpdPlatformDefs().getSkuInfo() == null) {
2385 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2387 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2388 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2389 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2390 skuName
.setSkuID(new BigInteger("0"));
2391 skuName
.setStringValue("DEFAULT");
2393 if (id
.equals("0")) {
2396 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2397 skuName
.setSkuID(new BigInteger(id
));
2398 skuName
.setStringValue(name
);
2401 public int getPlatformDefsSkuInfoCount(){
2402 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2405 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2408 public void getPlatformDefsSkuInfos(String
[][] saa
){
2409 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2410 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2411 removeElement(getfpdDynPcdBuildDefs());
2412 fpdDynPcdBuildDefs
= null;
2417 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2418 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2420 while(li
.hasNext()) {
2421 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2422 saa
[i
][0] = sku
.getSkuID()+"";
2423 saa
[i
][1] = sku
.getStringValue();
2428 public void removePlatformDefsSkuInfo(int i
) {
2429 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2430 if (skuInfo
== null || i
== 0) {
2434 XmlCursor cursor
= skuInfo
.newCursor();
2435 if (cursor
.toFirstChild()) {
2436 for (int j
= 0; j
< i
; ++j
) {
2437 cursor
.toNextSibling();
2444 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2445 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2446 if (skuInfo
== null || i
== 0) {
2450 XmlCursor cursor
= skuInfo
.newCursor();
2451 if (cursor
.toFirstChild()) {
2452 for (int j
= 0; j
< i
; ++j
) {
2453 cursor
.toNextSibling();
2455 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2456 sku
.setSkuID(new BigInteger(id
));
2457 sku
.setStringValue(name
);
2462 public String
getPlatformDefsInterDir(){
2463 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2466 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2469 public void setPlatformDefsInterDir(String interDir
){
2470 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2473 public String
getPlatformDefsOutputDir() {
2474 return getfpdPlatformDefs().getOutputDirectory();
2477 public void setPlatformDefsOutputDir(String outputDir
) {
2478 if (outputDir
!= null && outputDir
.length() > 0) {
2479 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2482 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2483 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2490 public FlashDocument
.Flash
getfpdFlash() {
2491 if (fpdFlash
== null) {
2492 fpdFlash
= fpdRoot
.addNewFlash();
2497 public void genFlashDefinitionFile(String file
) {
2498 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2500 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2503 fdf
.setStringValue(file
);
2506 public String
getFlashDefinitionFile() {
2507 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2512 return fdf
.getStringValue();
2515 public void genFvImagesNameValue(String name
, String value
) {
2517 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2519 fi
= getfpdFlash().addNewFvImages();
2522 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2527 public void removeFvImagesNameValue(int i
){
2529 XmlObject o
= getfpdFlash().getFvImages();
2534 QName qNameValue
= new QName(xmlNs
, "NameValue");
2535 XmlCursor cursor
= o
.newCursor();
2536 if (cursor
.toChild(qNameValue
)) {
2537 for (int j
= 0; j
< i
; ++j
) {
2538 cursor
.toNextSibling(qNameValue
);
2545 public void updateFvImagesNameValue(int i
, String name
, String value
){
2547 XmlObject o
= getfpdFlash().getFvImages();
2552 QName qNameValue
= new QName(xmlNs
, "NameValue");
2553 XmlCursor cursor
= o
.newCursor();
2554 if (cursor
.toChild(qNameValue
)) {
2555 for (int j
= 0; j
< i
; ++j
) {
2556 cursor
.toNextSibling(qNameValue
);
2558 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2565 public int getFvImagesNameValueCount() {
2567 FvImagesDocument
.FvImages fi
= null;
2568 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2571 return fi
.getNameValueList().size();
2574 public void getFvImagesNameValues(String
[][] nv
) {
2576 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2580 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2582 ListIterator li
= l
.listIterator();
2583 while (li
.hasNext()) {
2584 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2586 nv
[i
][0] = e
.getName();
2587 nv
[i
][1] = e
.getValue();
2593 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2594 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2595 if (fis
== null || fis
.getFvImageList() == null) {
2599 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2600 while (li
.hasNext()) {
2601 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2602 if (fi
.getType().toString().equals("ImageName")) {
2603 vImageNames
.addAll(fi
.getFvImageNamesList());
2609 public void AddFvImageFvImageNames (String
[] fvNames
) {
2610 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2611 if (fis
== null || fis
.getFvImageList() == null) {
2612 genFvImagesFvImage (fvNames
, "ImageName", null);
2616 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2617 while (li
.hasNext()) {
2618 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2619 if (fi
.getType().toString().equals("ImageName")) {
2620 for (int i
= 0; i
< fvNames
.length
; ++i
) {
2621 fi
.addFvImageNames(fvNames
[i
]);
2626 genFvImagesFvImage (fvNames
, "ImageName", null);
2630 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
2632 FvImagesDocument
.FvImages fis
= null;
2633 if ((fis
= getfpdFlash().getFvImages()) == null) {
2634 fis
= getfpdFlash().addNewFvImages();
2638 //gen FvImage with FvImageNames array
2640 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
2641 for (int i
= 0; i
< names
.length
; ++i
) {
2642 fi
.addFvImageNames(names
[i
]);
2644 fi
.setType(FvImageTypes
.Enum
.forString(types
));
2645 if (options
!= null){
2646 setFvImagesFvImageFvImageOptions(options
, fi
);
2650 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
2651 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
2653 fio
= fi
.addNewFvImageOptions();
2656 Set
<String
> key
= options
.keySet();
2657 Iterator
<String
> i
= key
.iterator();
2658 while (i
.hasNext()) {
2660 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
2661 String k
= (String
)i
.next();
2664 nv
.setValue((String
)options
.get(k
));
2671 public void removeFvImagesFvImage(int i
) {
2673 XmlObject o
= getfpdFlash().getFvImages();
2678 QName qFvImage
= new QName(xmlNs
, "FvImage");
2679 XmlCursor cursor
= o
.newCursor();
2680 if (cursor
.toChild(qFvImage
)) {
2681 for (int j
= 0; j
< i
; ++j
) {
2682 cursor
.toNextSibling(qFvImage
);
2691 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2693 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
2694 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2697 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
2698 while (li
.hasNext()) {
2699 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2700 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
2706 * @param oldFvName The FV Name to be replaced.
2707 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2709 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
2710 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
2711 XmlCursor cursor
= fi
.newCursor();
2713 if (cursor
.toChild(qFvImageNames
)) {
2715 if (cursor
.getTextValue().equals(oldFvName
)){
2716 if (newFvName
!= null) {
2717 cursor
.setTextValue(newFvName
);
2720 if (fi
.getFvImageNamesList().size() == 1) {
2729 }while (cursor
.toNextSibling(qFvImageNames
));
2735 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
2737 XmlObject o
= getfpdFlash().getFvImages();
2741 XmlCursor cursor
= o
.newCursor();
2742 QName qFvImage
= new QName(xmlNs
, "FvImage");
2743 if (cursor
.toChild(qFvImage
)) {
2744 for (int j
= 0; j
< i
; ++j
) {
2745 cursor
.toNextSibling(qFvImage
);
2747 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
2748 fi
.setType(FvImageTypes
.Enum
.forString(types
));
2751 // remove old FvImageNames before adding new ones
2753 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
2754 cursor
.toChild(qFvImageNames
);
2756 while (cursor
.toNextSibling(qFvImageNames
)) {
2760 for (int k
= 0; k
< names
.length
; ++k
) {
2761 fi
.addFvImageNames(names
[k
]);
2764 // remove old FvImageOptions before adding new options
2766 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
2767 cursor
.toNextSibling(qFvImageOptions
);
2770 setFvImagesFvImageFvImageOptions(options
, fi
);
2775 public int getFvImagesFvImageCount(String type
) {
2777 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2780 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2781 ListIterator li
= l
.listIterator();
2783 while(li
.hasNext()) {
2784 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2785 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2795 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
2796 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
2797 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2800 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2801 ListIterator li
= l
.listIterator();
2802 while(li
.hasNext()) {
2803 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2804 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2807 if (fi
.getFvImageNamesList().contains(fvName
)) {
2816 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
2818 public void getFvImagesFvImages(String
[][] saa
, String type
) {
2820 if (getfpdFlash().getFvImages() == null) {
2823 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2827 ListIterator li
= l
.listIterator();
2829 while(li
.hasNext()) {
2830 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2831 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2835 // get FvImageNames array, space separated
2837 List
<String
> lfn
= fi
.getFvImageNamesList();
2838 ListIterator lfni
= lfn
.listIterator();
2840 while (lfni
.hasNext()) {
2841 saa
[i
][0] += (String
)lfni
.next();
2844 saa
[i
][0] = saa
[i
][0].trim();
2846 saa
[i
][1] = fi
.getType()+"";
2852 /**Add name-value pair to FvImage element with type.
2853 * @param fvName FV name to add name-value pair.
2854 * @param type FvImage attribute.
2858 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
) {
2859 if (getfpdFlash().getFvImages() == null) {
2862 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2866 ListIterator li
= l
.listIterator();
2867 while(li
.hasNext()) {
2868 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2869 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2872 if (!fi
.getFvImageNamesList().contains(fvName
)) {
2875 setFvImagesFvImageNameValue (fi
, name
, value
, null);
2879 /**Add to all FvImage elements with type, the name-value pair.
2884 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
2885 if (getfpdFlash().getFvImages() == null) {
2888 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2892 ListIterator li
= l
.listIterator();
2893 while(li
.hasNext()) {
2894 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2895 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2898 setFvImagesFvImageNameValue (fi
, name
, value
, null);
2902 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
2908 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
2909 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
2913 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
2914 if (cursor
.toFirstChild()) {
2916 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
2917 if (nv
.getName().equals(name
)) {
2919 if (newName
!= null) {
2920 nv
.setName(newName
);
2925 }while (cursor
.toNextSibling());
2928 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
2931 if (newName
!= null) {
2932 nv
.setName(newName
);
2937 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
2938 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
2939 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
2940 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
2941 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
2945 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
2948 while (li
.hasNext()) {
2949 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
2950 m
.put(nv
.getName(), nv
.getValue());
2954 /**Get FvImage Options for FvImage i
2955 * @param i the ith FvImage
2957 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
2958 XmlObject o
= getfpdFlash().getFvImages();
2962 XmlCursor cursor
= o
.newCursor();
2963 QName qFvImage
= new QName(xmlNs
, "FvImage");
2964 if (cursor
.toChild(qFvImage
)) {
2965 for (int j
= 0; j
< i
; ++j
) {
2966 cursor
.toNextSibling(qFvImage
);
2968 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
2969 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
2972 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
2973 while(li
.hasNext()){
2974 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
2975 m
.put(nv
.getName(), nv
.getValue());
2981 Get platform header element
2982 @return PlatformHeaderDocument.PlatformHeader
2984 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
2985 if (fpdHdr
== null) {
2986 fpdHdr
= fpdRoot
.addNewPlatformHeader();
2992 public String
getFpdHdrPlatformName() {
2993 return getFpdHdr().getPlatformName();
2996 public String
getFpdHdrGuidValue() {
2997 return getFpdHdr().getGuidValue();
3000 public String
getFpdHdrVer() {
3001 return getFpdHdr().getVersion();
3004 public String
getFpdHdrAbs() {
3005 return getFpdHdr().getAbstract();
3008 public String
getFpdHdrDescription() {
3009 return getFpdHdr().getDescription();
3012 public String
getFpdHdrCopyright() {
3013 return getFpdHdr().getCopyright();
3016 public String
getFpdHdrLicense() {
3017 LicenseDocument
.License l
= getFpdHdr().getLicense();
3021 return l
.getStringValue();
3024 public String
getFpdHdrUrl() {
3025 LicenseDocument
.License l
= getFpdHdr().getLicense();
3032 public String
getFpdHdrSpec() {
3034 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3035 // return getFpdHdr().getSpecification();
3038 public void setFpdHdrPlatformName(String name
){
3039 getFpdHdr().setPlatformName(name
);
3042 public void setFpdHdrGuidValue(String guid
){
3043 getFpdHdr().setGuidValue(guid
);
3046 public void setFpdHdrVer(String v
){
3047 getFpdHdr().setVersion(v
);
3050 public void setFpdHdrAbs(String abs
) {
3051 getFpdHdr().setAbstract(abs
);
3054 public void setFpdHdrDescription(String desc
){
3055 getFpdHdr().setDescription(desc
);
3058 public void setFpdHdrCopyright(String cr
) {
3059 getFpdHdr().setCopyright(cr
);
3062 public void setFpdHdrLicense(String license
){
3063 LicenseDocument
.License l
= getFpdHdr().getLicense();
3065 getFpdHdr().addNewLicense().setStringValue(license
);
3068 l
.setStringValue(license
);
3072 public void setFpdHdrUrl(String url
){
3073 LicenseDocument
.License l
= getFpdHdr().getLicense();
3079 public void setFpdHdrSpec(String s
){
3080 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3081 getFpdHdr().setSpecification(s
);
3084 Save the processed xml contents to file
3086 @param fpdFile The file to save xml contents
3087 @throws IOException Exceptions during file operation
3089 public void saveAs(File fpdFile
) throws IOException
{
3091 XmlOptions options
= new XmlOptions();
3093 options
.setCharacterEncoding("UTF-8");
3094 options
.setSavePrettyPrint();
3095 options
.setSavePrettyPrintIndent(2);
3097 fpdd
.save(fpdFile
, options
);
3098 } catch (IOException e
) {
3099 e
.printStackTrace();
3104 private String
listToString(List l
) {
3109 ListIterator li
= l
.listIterator();
3110 while(li
.hasNext()) {
3117 private void removeElement(XmlObject o
) {
3118 XmlCursor cursor
= o
.newCursor();
3124 class PcdItemTypeConflictException
extends Exception
{
3129 private static final long serialVersionUID
= 1L;
3130 private String details
= null;
3132 PcdItemTypeConflictException(String pcdName
, String info
){
3133 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3134 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3137 public String
getMessage() {
3142 class PcdDeclNotFound
extends Exception
{
3147 private static final long serialVersionUID
= 1L;
3148 private String details
= null;
3150 PcdDeclNotFound(String info
) {
3151 details
= "PcdDeclNotFound: " + info
;
3154 public String
getMessage() {
3159 class PcdValueMalFormed
extends Exception
{
3164 private static final long serialVersionUID
= 1L;
3165 private String details
= null;
3167 PcdValueMalFormed(String info
) {
3168 details
= "PcdValueMalFormed: " + info
;
3171 public String
getMessage() {