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
>();
364 // create vector for module & library instance MIs.
367 for (int j
= 0; j
< saaLib
.length
; ++j
) {
368 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
369 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
374 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
376 for (int j
= 0; j
< vMi
.size(); ++j
) {
377 ModuleIdentification nextMi
= vMi
.get(j
);
378 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], nextMi
)) {
382 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
386 catch (Exception e
) {
390 // add new Pcd from MSA file to ModuleSA.
394 for (int i
= 0; i
< vMi
.size(); ++i
) {
395 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
396 .getModuleXmlObject(vMi
398 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
401 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
402 msaPcdIter
:while (li
.hasNext()) {
403 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
404 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
406 for (int j
= 0; j
< al
.size(); ++j
) {
407 if (al
.get(j
).contains(moduleKey
)) {
413 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
414 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
415 if (spdPcd
== null) {
419 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
423 // AddItem to ModuleSA PcdBuildDefinitions
425 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
426 : msaPcd
.getDefaultValue();
428 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
429 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
);
442 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
444 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
448 String
[] s
= moduleInfo
.split(" ");
449 for(int i
= 0; i
< al
.size(); ++i
){
450 String consumer
= al
.get(i
);
451 if (consumer
.contains(s
[0]) && consumer
.contains(s
[2])){
452 String
[] consumerPart
= consumer
.split(" ");
453 if (!consumerPart
[4].equals(s
[4])) {
461 if (al
.size() == 0) {
462 defaultPcdValue
.remove(pcdKey
);
463 dynPcdMap
.remove(pcdKey
);
464 String
[] s1
= pcdKey
.split(" ");
465 removeDynamicPcdBuildData(s1
[0], s1
[1]);
470 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
472 public int getPcdDataCount (int i
){
473 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
475 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
478 return msa
.getPcdBuildDefinition().getPcdDataList().size();
482 public void getPcdData (int i
, String
[][] saa
) {
483 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
485 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
488 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
489 for (int k
= 0; k
< saa
.length
; ++k
) {
490 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
491 saa
[k
][0] = pcdData
.getCName();
492 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
493 saa
[k
][2] = pcdData
.getItemType()+"";
494 saa
[k
][3] = pcdData
.getToken().toString();
495 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
496 saa
[k
][5] = pcdData
.getDatumType()+"";
497 saa
[k
][6] = pcdData
.getValue();
502 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
503 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
504 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
508 String mg
= moduleSa
.getModuleGuid();
509 String mv
= moduleSa
.getModuleVersion();
510 String pg
= moduleSa
.getPackageGuid();
511 String pv
= moduleSa
.getPackageVersion();
512 String arch
= listToString(moduleSa
.getSupArchList());
513 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
515 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
516 if (cursor
.toFirstChild()){
519 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
520 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
521 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
522 if (getPcdDataCount(seqModuleSa
) == 1) {
529 while(cursor
.toNextSibling());
535 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
536 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
537 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
541 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
542 if (cursor
.toFirstChild()){
544 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
545 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
546 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
547 if(pcdData
.getDatumType().equals("VOID*")) {
548 pcdData
.setMaxDatumSize(new Integer(maxSize
));
550 pcdData
.setValue(value
);
551 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
555 while(cursor
.toNextSibling());
560 /**Get original Pcd info from MSA & SPD files.
561 * @param mi ModuleIdentification from which MSA & SPD come
562 * @param cName PCD cName
563 * @param sa Results: HelpText, Original item type.
566 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
) throws Exception
{
569 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
570 if (msa
.getPcdCoded() == null) {
574 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
575 m
.put("ModuleSurfaceArea", msa
);
576 SurfaceAreaQuery
.setDoc(m
);
577 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
579 // First look through MSA pcd entries.
581 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
582 ListIterator li
= l
.listIterator();
583 while(li
.hasNext()) {
584 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
585 if (!msaPcd
.getCName().equals(cName
)) {
588 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
591 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
592 if (spdPcd
== null) {
596 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
599 // Get Pcd help text and original item type.
601 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
602 sa
[1] = msaPcd
.getPcdItemType()+"";
616 /**Remove PCDBuildDefinition entries from ModuleSA
617 * @param moduleKey identifier of ModuleSA.
618 * @param consumer where these entries come from.
620 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
622 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
623 if (msa
.getPcdCoded() == null) {
627 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
628 ListIterator li
= l
.listIterator();
630 while(li
.hasNext()) {
631 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
632 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
633 if (moduleSA
.getPcdBuildDefinition() != null) {
634 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
635 if (cursor
.toFirstChild()) {
637 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
639 if (msaPcd
.getCName().equals(pcdData
.getCName())
640 && msaPcd
.getTokenSpaceGuidCName().equals(pcdData
.getTokenSpaceGuidCName())) {
642 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
647 } while (cursor
.toNextSibling());
660 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
662 public int getLibraryInstancesCount(String key
) {
663 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
664 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
667 return msa
.getLibraries().getInstanceList().size();
670 public void getLibraryInstances(String key
, String
[][] saa
){
671 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
672 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
676 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
677 for (int i
= 0; i
< saa
.length
; ++i
) {
678 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
679 saa
[i
][1] = instance
.getModuleGuid();
680 saa
[i
][2] = instance
.getModuleVersion();
681 saa
[i
][3] = instance
.getPackageGuid();
682 saa
[i
][4] = instance
.getPackageVersion();
686 public void removeLibraryInstance(String key
, int i
) {
687 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
688 if (msa
== null || msa
.getLibraries() == null){
692 XmlCursor cursor
= msa
.getLibraries().newCursor();
693 if (cursor
.toFirstChild()) {
694 for (int j
= 0; j
< i
; ++j
) {
695 cursor
.toNextSibling();
698 cursor
.toPrevToken();
699 if (cursor
.isComment()) {
704 if (getLibraryInstancesCount(key
) == 0) {
713 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
714 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
716 msa
= getfpdFrameworkModules().addNewModuleSA();
718 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
720 libs
= msa
.addNewLibraries();
723 String mn
= libMi
.getName();
724 String mg
= libMi
.getGuid();
725 String mv
= libMi
.getVersion();
726 String pn
= libMi
.getPackageId().getName();
727 String pg
= libMi
.getPackageId().getGuid();
728 String pv
= libMi
.getPackageId().getVersion();
729 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
730 XmlCursor cursor
= instance
.newCursor();
732 String comment
= "Pkg: " + pn
+ " Mod: " + mn
733 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
734 cursor
.insertComment(comment
);
743 instance
.setModuleGuid(mg
);
744 instance
.setModuleVersion(mv
);
745 instance
.setPackageGuid(pg
);
746 instance
.setPackageVersion(pv
);
750 public String
getFvBinding(String moduleKey
){
751 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
752 return getFvBinding (moduleSa
);
755 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
756 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
759 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
762 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
763 if (moduleSa
== null ) {
766 if (fvBinding
== null || fvBinding
.length() == 0) {
767 if(moduleSa
.getModuleSaBuildOptions() != null){
768 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
772 if(moduleSa
.getModuleSaBuildOptions() == null){
773 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
776 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
780 public void setFvBinding(String moduleKey
, String fvBinding
){
781 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
782 setFvBinding (moduleSa
, fvBinding
);
785 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
786 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
790 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
791 String
[] fvNamesArray
= fvNameList
.split(" ");
793 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
794 if (fvNamesArray
[i
].equals(fvName
)) {
802 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
803 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
807 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
808 String
[] fvNamesArray
= fvNameList
.split(" ");
810 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
811 if (fvNamesArray
[i
].equals(fvName
)) {
816 // jump over where the input fvName occurs in the original Fv list.
817 if (occursAt
!= -1) {
818 String newFvNameList
= " ";
819 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
823 newFvNameList
+= fvNamesArray
[i
];
825 setFvBinding (moduleSa
, newFvNameList
.trim());
831 * @param fvName The FV name that to be removed from FvBinding List.
833 public void removeFvBindingAll (String fvName
) {
834 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
835 removeElement(getfpdFrameworkModules());
836 fpdFrameworkModules
= null;
840 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
841 while (li
.hasNext()) {
842 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
843 removeFvBinding (moduleSa
, fvName
);
847 public void appendFvBindingAll (String fvName
) {
848 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
849 removeElement(getfpdFrameworkModules());
850 fpdFrameworkModules
= null;
854 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
855 while (li
.hasNext()) {
856 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
857 appendFvBinding (moduleSa
, fvName
);
861 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
862 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
863 removeElement(getfpdFrameworkModules());
864 fpdFrameworkModules
= null;
868 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
869 while (li
.hasNext()) {
870 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
871 String fvBinding
= getFvBinding (moduleSa
);
872 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
873 appendFvBinding (moduleSa
, newFvName
);
878 public void appendFvBinding (String moduleKey
, String fvName
) {
879 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
880 appendFvBinding (moduleSa
, fvName
);
883 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
884 if (moduleSa
== null) {
888 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
889 setFvBinding(moduleSa
, fvName
);
893 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
894 String newFvNameList
= fvNameList
+ " " + fvName
;
895 setFvBinding (moduleSa
, newFvNameList
.trim());
898 public void updateFvBindingInModuleSA (ModuleIdentification mi
, String fvName
) {
899 Vector
<Object
> vSupArchs
= new Vector
<Object
>();
900 getPlatformDefsSupportedArchs(vSupArchs
);
901 String moduleInfo
= mi
.getGuid() + " " + mi
.getVersion() + " " + mi
.getPackageId().getGuid() + " " + mi
.getPackageId().getVersion();
902 for (int i
= 0; i
< vSupArchs
.size(); ++i
) {
903 String moduleKey
= moduleInfo
+ " " + vSupArchs
.get(i
);
904 appendFvBinding (moduleKey
, fvName
);
908 public String
getFfsFileNameGuid(String moduleKey
){
909 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
910 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
913 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
916 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
917 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
921 if(msa
.getModuleSaBuildOptions() == null){
922 msa
.addNewModuleSaBuildOptions();
925 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
926 if (fileGuid
!= null) {
927 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
930 XmlCursor cursor
= msaBuildOpts
.newCursor();
931 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
939 public String
getFfsFormatKey(String moduleKey
){
940 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
941 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
944 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
947 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
948 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
952 if(msa
.getModuleSaBuildOptions() == null){
953 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
956 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
959 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
960 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
961 moduleSa
.setForceDebug(dbgEnable
);
964 public boolean getModuleSAForceDebug (int i
) {
965 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
966 if (moduleSa
.getForceDebug() == true) {
972 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
973 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
974 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
975 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
979 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
980 ListIterator li
= lOpt
.listIterator();
982 while(li
.hasNext()) {
983 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
984 if (opt
.getBuildTargets() != null) {
985 saa
[i
][0] = listToString(opt
.getBuildTargets());
987 saa
[i
][1] = opt
.getToolChainFamily();
988 saa
[i
][2] = opt
.getTagName();
989 saa
[i
][3] = opt
.getToolCode();
991 if (opt
.getSupArchList() != null){
992 saa
[i
][4] = listToString(opt
.getSupArchList());
998 saa
[i
][5] = opt
.getStringValue();
1004 public int getModuleSAOptionsCount(String moduleKey
){
1005 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1006 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1007 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1010 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1013 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1014 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1015 if (msa
.getModuleSaBuildOptions() == null) {
1016 msa
.addNewModuleSaBuildOptions();
1018 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1019 msa
.getModuleSaBuildOptions().addNewOptions();
1021 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1022 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1025 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1026 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1027 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1030 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1031 XmlCursor cursor
= opts
.newCursor();
1032 if (cursor
.toFirstChild()) {
1033 for (int j
= 0; j
< i
; ++j
){
1034 cursor
.toNextSibling();
1041 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1042 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1043 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1046 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1047 XmlCursor cursor
= opts
.newCursor();
1048 if (cursor
.toFirstChild()) {
1049 for (int j
= 0; j
< i
; ++j
){
1050 cursor
.toNextSibling();
1052 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1053 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1058 /**add pcd information of module mi to a ModuleSA.
1060 * @param moduleSa if null, generate a new ModuleSA.
1062 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1063 //ToDo add Arch filter
1066 if (moduleSa
== null) {
1067 moduleSa
= genModuleSA(mi
, arch
);
1070 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
1071 if (msa
.getPcdCoded() == null) {
1075 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
1076 m
.put("ModuleSurfaceArea", msa
);
1077 SurfaceAreaQuery
.setDoc(m
);
1078 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1080 // Implementing InitializePlatformPcdBuildDefinitions
1082 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1083 ListIterator li
= l
.listIterator();
1084 while(li
.hasNext()) {
1085 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
1086 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1087 if (spdPcd
== null) {
1091 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module " + mi
.getName());
1094 // AddItem to ModuleSA PcdBuildDefinitions
1096 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1098 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
1102 catch (Exception e
){
1109 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1111 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1112 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1114 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1118 for (int j
= 0; j
< xo
.length
; ++j
) {
1119 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1120 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1121 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1126 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1137 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1138 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1139 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1140 XmlCursor cursor
= msa
.newCursor();
1142 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1143 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1144 cursor
.insertComment(comment
);
1147 e
.printStackTrace();
1152 msa
.setModuleGuid(mi
.getGuid());
1153 msa
.setModuleVersion(mi
.getVersion());
1154 msa
.setPackageGuid(pi
.getGuid());
1155 msa
.setPackageVersion(pi
.getVersion());
1157 Vector
<String
> v
= new Vector
<String
>();
1159 msa
.setSupArchList(v
);
1165 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
)
1166 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1167 if (moduleSa
.getPcdBuildDefinition() == null){
1168 moduleSa
.addNewPcdBuildDefinition();
1171 // constructe pcd to modulesa mapping first.
1172 // Attention : for any error condition, remove from map this pcd.
1174 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1175 if (pcdConsumer
== null) {
1176 pcdConsumer
= new ArrayList
<String
>();
1179 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1181 if (pcdConsumer
.size() > 0) {
1182 String
[] valPart
= pcdConsumer
.get(0).split(" ");
1183 itemType
= valPart
[5];
1185 String listValue
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion()
1186 + " " + moduleSa
.getPackageGuid() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList())
1188 pcdConsumer
.add(listValue
);
1189 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1191 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1192 fpdPcd
.setCName(cName
);
1193 fpdPcd
.setToken(token
);
1194 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1195 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1196 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1198 if (defaultVal
!= null){
1199 fpdPcd
.setValue(defaultVal
);
1202 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1203 fpdPcd
.setValue("0");
1205 if (dataType
.equals("BOOLEAN")){
1206 fpdPcd
.setValue("FALSE");
1208 if (dataType
.equals("VOID*")) {
1209 fpdPcd
.setValue("");
1213 // Using existing pcd value, if this pcd already exists in other moduleSa.
1215 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1216 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1219 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1222 if (dataType
.equals("UINT8")){
1223 fpdPcd
.setMaxDatumSize(1);
1225 if (dataType
.equals("UINT16")) {
1226 fpdPcd
.setMaxDatumSize(2);
1228 if (dataType
.equals("UINT32")) {
1229 fpdPcd
.setMaxDatumSize(4);
1231 if (dataType
.equals("UINT64")){
1232 fpdPcd
.setMaxDatumSize(8);
1234 if (dataType
.equals("BOOLEAN")){
1235 fpdPcd
.setMaxDatumSize(1);
1237 if (dataType
.equals("VOID*")) {
1238 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1239 fpdPcd
.setMaxDatumSize(maxSize
);
1243 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1244 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1246 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1247 // so need to add one dyn pcd.
1249 if (al
.size() == 1) {
1250 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1256 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1257 if (datum
== null) {
1260 char ch
= datum
.charAt(0);
1264 // For void* type PCD, only three datum is support:
1265 // 1) Unicode: string with start char is "L"
1266 // 2) Ansci: String is ""
1267 // 3) byte array: String start char "{"
1270 start
= datum
.indexOf('\"');
1271 end
= datum
.lastIndexOf('\"');
1272 if ((start
> end
) ||
1273 (end
> datum
.length())||
1274 ((start
== end
) && (datum
.length() > 0))) {
1275 //ToDo Error handling here
1276 throw new PcdValueMalFormed (datum
);
1279 strValue
= datum
.substring(start
+ 1, end
);
1280 return strValue
.length() * 2;
1281 } else if (ch
== '\"'){
1282 start
= datum
.indexOf('\"');
1283 end
= datum
.lastIndexOf('\"');
1284 if ((start
> end
) ||
1285 (end
> datum
.length())||
1286 ((start
== end
) && (datum
.length() > 0))) {
1287 throw new PcdValueMalFormed (datum
);
1289 strValue
= datum
.substring(start
+ 1, end
);
1290 return strValue
.length();
1291 } else if (ch
=='{') {
1292 String
[] strValueArray
;
1294 start
= datum
.indexOf('{');
1295 end
= datum
.lastIndexOf('}');
1296 strValue
= datum
.substring(start
+ 1, end
);
1297 strValue
= strValue
.trim();
1298 if (strValue
.length() == 0) {
1301 strValueArray
= strValue
.split(",");
1302 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1303 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1306 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1307 // "it must be a byte array. But the element of %s exceed the byte range",
1308 throw new PcdValueMalFormed (datum
);
1311 return strValueArray
.length
;
1315 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1316 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1317 // "2) ANSIC string: like \"xxx\";\r\n"+
1318 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1319 // "but the datum in seems does not following above format!",
1320 throw new PcdValueMalFormed (datum
);
1325 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1326 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1331 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1333 return dynPcdMap
.get(pcdKey
);
1336 public int getDynamicPcdBuildDataCount() {
1337 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1338 removeElement(getfpdDynPcdBuildDefs());
1339 fpdDynPcdBuildDefs
= null;
1342 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1345 public void getDynamicPcdBuildData(String
[][] saa
) {
1346 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1347 removeElement(getfpdDynPcdBuildDefs());
1348 fpdDynPcdBuildDefs
= null;
1351 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1352 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1354 while(li
.hasNext()) {
1355 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1356 saa
[i
][0] = dynPcd
.getCName();
1357 saa
[i
][1] = dynPcd
.getToken().toString();
1358 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1359 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1360 saa
[i
][4] = dynPcd
.getDatumType().toString();
1366 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1367 throws PcdValueMalFormed
{
1368 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1369 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1370 dynPcdData
.setCName(cName
);
1371 dynPcdData
.setToken(token
);
1372 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1373 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1375 BigInteger bigInt
= new BigInteger("0");
1376 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1377 skuInfo
.setSkuId(bigInt
);
1378 if (defaultVal
!= null){
1379 skuInfo
.setValue(defaultVal
);
1382 if (dataType
.equals("UINT8")){
1383 skuInfo
.setValue("0");
1385 if (dataType
.equals("UINT16")) {
1386 skuInfo
.setValue("0");
1388 if (dataType
.equals("UINT32")) {
1389 skuInfo
.setValue("0");
1391 if (dataType
.equals("UINT64")){
1392 skuInfo
.setValue("0");
1394 if (dataType
.equals("BOOLEAN")){
1395 skuInfo
.setValue("false");
1397 if (dataType
.equals("VOID*")) {
1398 skuInfo
.setValue("");
1401 if (dataType
.equals("UINT8")){
1402 dynPcdData
.setMaxDatumSize(1);
1404 if (dataType
.equals("UINT16")) {
1405 dynPcdData
.setMaxDatumSize(2);
1407 if (dataType
.equals("UINT32")) {
1408 dynPcdData
.setMaxDatumSize(4);
1410 if (dataType
.equals("UINT64")){
1411 dynPcdData
.setMaxDatumSize(8);
1413 if (dataType
.equals("BOOLEAN")){
1414 dynPcdData
.setMaxDatumSize(1);
1416 if (dataType
.equals("VOID*")) {
1417 int maxSize
= setMaxSizeForPointer(defaultVal
);
1418 dynPcdData
.setMaxDatumSize(maxSize
);
1422 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1423 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1428 XmlCursor cursor
= o
.newCursor();
1429 if (cursor
.toFirstChild()) {
1431 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1432 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1433 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1435 if (getDynamicPcdBuildDataCount() == 1) {
1443 while (cursor
.toNextSibling());
1448 // Get the Sku Info count of ith dyn pcd element.
1450 public int getDynamicPcdSkuInfoCount(int i
){
1451 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1452 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1456 int skuInfoCount
= 0;
1457 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1458 if (cursor
.toFirstChild()) {
1459 for (int j
= 0; j
< i
; ++j
) {
1460 cursor
.toNextSibling();
1462 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1463 if (pcdData
.getSkuInfoList() == null) {
1467 skuInfoCount
= pcdData
.getSkuInfoList().size();
1471 return skuInfoCount
;
1474 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1475 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1476 removeElement(getfpdDynPcdBuildDefs());
1477 fpdDynPcdBuildDefs
= null;
1481 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1482 if (cursor
.toFirstChild()) {
1483 for (int j
= 0; j
< i
; ++j
) {
1484 cursor
.toNextSibling();
1486 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1487 if (pcdData
.getSkuInfoList() == null) {
1492 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1494 while (li
.hasNext()) {
1495 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1496 saa
[k
][0] = skuInfo
.getSkuId()+"";
1497 saa
[k
][1] = skuInfo
.getVariableName();
1498 saa
[k
][2] = skuInfo
.getVariableGuid();
1499 saa
[k
][3] = skuInfo
.getVariableOffset();
1500 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1501 saa
[k
][5] = skuInfo
.getVpdOffset();
1502 saa
[k
][6] = skuInfo
.getValue();
1512 public String
getDynamicPcdBuildDataValue(int i
){
1513 String value
= null;
1514 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1515 removeElement(getfpdDynPcdBuildDefs());
1516 fpdDynPcdBuildDefs
= null;
1520 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1521 if (cursor
.toFirstChild()) {
1522 for (int j
= 0; j
< i
; ++j
) {
1523 cursor
.toNextSibling();
1525 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1526 if (pcdData
.getSkuInfoList() == null) {
1530 value
= pcdData
.getSkuInfoArray(0).getValue();
1537 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1538 String vpdOffset
= null;
1539 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1540 removeElement(getfpdDynPcdBuildDefs());
1541 fpdDynPcdBuildDefs
= null;
1545 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1546 if (cursor
.toFirstChild()) {
1547 for (int j
= 0; j
< i
; ++j
) {
1548 cursor
.toNextSibling();
1550 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1551 if (pcdData
.getSkuInfoList() == null) {
1555 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1562 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1563 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1564 removeElement(getfpdDynPcdBuildDefs());
1565 fpdDynPcdBuildDefs
= null;
1569 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1570 if (cursor
.toFirstChild()) {
1571 for (int j
= 0; j
< i
; ++j
) {
1572 cursor
.toNextSibling();
1574 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1575 if (pcdData
.getSkuInfoList() == null) {
1580 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1581 cursor
.toChild(qSkuInfo
);
1588 // generate sku info for ith dyn pcd build data.
1590 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1591 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1592 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1596 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1597 if (cursor
.toFirstChild()) {
1598 for (int j
= 0; j
< i
; ++j
) {
1599 cursor
.toNextSibling();
1601 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1602 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1603 skuInfo
.setSkuId(new BigInteger(id
));
1604 if (varName
!= null){
1605 skuInfo
.setVariableName(varName
);
1606 skuInfo
.setVariableGuid(varGuid
);
1607 skuInfo
.setVariableOffset(varOffset
);
1608 skuInfo
.setHiiDefaultValue(hiiDefault
);
1610 else if (vpdOffset
!= null){
1611 skuInfo
.setVpdOffset(vpdOffset
);
1614 skuInfo
.setValue(value
);
1619 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1620 String hiiDefault
, String vpdOffset
, String value
, int i
){
1621 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1625 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1626 if (cursor
.toFirstChild()) {
1627 for (int j
= 0; j
< i
; ++j
) {
1628 cursor
.toNextSibling();
1630 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1631 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1632 while (li
.hasNext()) {
1633 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1634 if (skuInfo
.getSkuId().toString().equals(id
)){
1635 if (varName
!= null){
1636 skuInfo
.setVariableName(varName
);
1637 skuInfo
.setVariableGuid(varGuid
);
1638 skuInfo
.setVariableOffset(varOffset
);
1639 skuInfo
.setHiiDefaultValue(hiiDefault
);
1641 else if (vpdOffset
!= null){
1642 skuInfo
.setVpdOffset(vpdOffset
);
1645 skuInfo
.setValue(value
);
1653 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1654 if (fpdBuildOpts
== null) {
1655 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1657 return fpdBuildOpts
;
1660 public void genBuildOptionsUserExtensions(String fvName
, String outputFileName
, Vector
<String
[]> includeModules
) {
1661 QName elementFvName
= new QName (xmlNs
, "FvName");
1662 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1663 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1664 QName elementModule
= new QName(xmlNs
, "Module");
1666 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1667 userExts
.setUserID("IMAGES");
1668 userExts
.setIdentifier(new BigInteger("1"));
1669 XmlCursor cursor
= userExts
.newCursor();
1670 cursor
.toEndToken();
1672 cursor
.beginElement(elementFvName
);
1673 cursor
.insertChars(fvName
);
1674 cursor
.toNextToken();
1676 cursor
.beginElement(elementInfFileName
);
1677 cursor
.insertChars(fvName
+ ".inf");
1678 cursor
.toNextToken();
1680 cursor
.beginElement(elementIncludeModules
);
1681 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1682 cursor
.beginElement(elementModule
);
1683 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1684 cursor
.insertAttributeWithValue("BaseName", includeModules
.get(i
)[1]);
1685 cursor
.toEndToken();
1686 cursor
.toNextToken();
1691 public int getUserExtsIncModCount (String fvName
) {
1692 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1695 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1696 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1697 while (li
.hasNext()) {
1698 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1699 if (!ues
.getUserID().equals("IMAGES")) {
1702 XmlCursor cursor
= ues
.newCursor();
1703 cursor
.toFirstChild();
1704 String elementName
= cursor
.getTextValue();
1705 if (elementName
.equals(fvName
)) {
1706 cursor
.toNextSibling(elementIncludeModules
);
1707 if (cursor
.toFirstChild()) {
1709 for (i
= 1; cursor
.toNextSibling(); ++i
);
1721 public void getUserExtsIncMods(String fvName
, String
[][] saa
) {
1722 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1726 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1727 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1728 QName attribUserId
= new QName ("UserID");
1729 QName elementFvName
= new QName (xmlNs
, "FvName");
1730 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1731 QName attribModuleGuid
= new QName("ModuleGuid");
1732 QName attribBaseName
= new QName("BaseName");
1734 if (cursor
.toChild(elementUserExts
)) {
1737 if (cursor
.getAttributeText(attribUserId
).equals("IMAGES")) {
1738 cursor
.toChild(elementFvName
);
1739 String elementName
= cursor
.getTextValue();
1740 if (elementName
.equals(fvName
)) {
1741 cursor
.toNextSibling(elementIncludeModules
);
1742 if (cursor
.toFirstChild()) {
1745 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1746 saa
[i
][1] = cursor
.getAttributeText(attribBaseName
);
1748 }while (cursor
.toNextSibling());
1754 }while (cursor
.toNextSibling(elementUserExts
));
1760 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1761 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1764 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1765 while (li
.hasNext()) {
1766 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1767 if (!ues
.getUserID().equals("IMAGES")) {
1770 XmlCursor cursor
= ues
.newCursor();
1771 cursor
.toFirstChild();
1772 String elementName
= cursor
.getTextValue();
1773 if (elementName
.equals(oldFvName
)) {
1774 cursor
.setTextValue(newFvName
);
1781 public void removeBuildOptionsUserExtensions (String fvName
) {
1782 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1786 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1787 while (li
.hasNext()) {
1788 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1789 if (!ues
.getUserID().equals("IMAGES")) {
1792 XmlCursor cursor
= ues
.newCursor();
1793 cursor
.toFirstChild();
1794 String elementName
= cursor
.getTextValue();
1795 if (elementName
.equals(fvName
)) {
1807 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
1808 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1809 if (udats
== null) {
1810 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
1813 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
1814 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1817 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
1818 at
.setId(new Integer(id
));
1819 XmlCursor cursor
= at
.newCursor();
1820 if (fileName
!= null){
1821 at
.setFilename(fileName
);
1823 else if (cursor
.toChild(xmlNs
, "Filename")) {
1826 if (execOrder
!= null) {
1827 at
.setAntCmdOptions(execOrder
);
1829 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
1835 public void removeBuildOptionsUserDefAntTask(int i
) {
1836 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1840 XmlCursor cursor
= o
.newCursor();
1841 if (cursor
.toFirstChild()) {
1842 for (int j
= 0; j
< i
; ++j
) {
1843 cursor
.toNextSibling();
1846 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1854 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
1855 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
1859 XmlCursor cursor
= o
.newCursor();
1860 if (cursor
.toFirstChild()) {
1861 for (int j
= 0; j
< i
; ++j
) {
1862 cursor
.toNextSibling();
1864 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
1865 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
1870 public int getBuildOptionsUserDefAntTaskCount() {
1871 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1872 if (udats
== null || udats
.getAntTaskList() == null) {
1876 return udats
.getAntTaskList().size();
1879 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
1880 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
1881 if (udats
== null || udats
.getAntTaskList() == null) {
1885 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
1886 ListIterator li
= l
.listIterator();
1888 while (li
.hasNext()) {
1889 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
1890 saa
[i
][0] = at
.getId() + "";
1891 saa
[i
][1] = saa
[i
][2] = "";
1892 if (at
.getFilename() != null){
1893 saa
[i
][1] = at
.getFilename();
1895 if (at
.getAntCmdOptions() != null) {
1896 saa
[i
][2] = at
.getAntCmdOptions();
1901 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1902 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
1904 opts
= getfpdBuildOpts().addNewOptions();
1906 OptionDocument
.Option opt
= opts
.addNewOption();
1907 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1910 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
1911 opt
.setStringValue(contents
);
1913 opt
.setBuildTargets(buildTargets
);
1914 opt
.setToolChainFamily(toolChain
);
1915 opt
.setTagName(tagName
);
1916 opt
.setToolCode(toolCmd
);
1918 if (archList
!= null) {
1919 opt
.setSupArchList(archList
);
1922 if (opt
.isSetSupArchList()) {
1923 opt
.unsetSupArchList();
1928 public void removeBuildOptionsOpt(int i
){
1930 XmlObject o
= getfpdBuildOpts().getOptions();
1935 XmlCursor cursor
= o
.newCursor();
1936 if (cursor
.toFirstChild()) {
1937 for (int j
= 0; j
< i
; ++j
) {
1938 cursor
.toNextSibling();
1941 if (getBuildOptionsOptCount() == 0) {
1949 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1950 XmlObject o
= getfpdBuildOpts().getOptions();
1955 XmlCursor cursor
= o
.newCursor();
1956 if (cursor
.toFirstChild()) {
1957 for (int j
= 0; j
< i
; ++j
) {
1958 cursor
.toNextSibling();
1960 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1961 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1966 public int getBuildOptionsOptCount(){
1967 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1970 return getfpdBuildOpts().getOptions().getOptionList().size();
1973 public void getBuildOptionsOpts(String
[][] saa
) {
1974 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1978 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
1979 ListIterator li
= lOpt
.listIterator();
1981 while(li
.hasNext()) {
1982 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1983 if (opt
.getBuildTargets() != null) {
1984 saa
[i
][0] = listToString(opt
.getBuildTargets());
1986 saa
[i
][1] = opt
.getToolChainFamily();
1987 if (opt
.getSupArchList() != null){
1988 saa
[i
][2] = listToString(opt
.getSupArchList());
1991 saa
[i
][3] = opt
.getToolCode();
1992 saa
[i
][4] = opt
.getTagName();
1993 saa
[i
][5] = opt
.getStringValue();
1999 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2000 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2001 ffs
.setFfsKey(ffsKey
);
2003 ffs
.addNewSections().setEncapsulationType(type
);
2007 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2008 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2010 ffs
.addNewSections().setEncapsulationType(type
);
2014 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2015 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2016 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2017 attrib
.setName(name
);
2018 attrib
.setValue(value
);
2021 /**update jth attribute of ith ffs.
2025 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2026 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2027 XmlCursor cursor
= ffs
.newCursor();
2028 QName qAttrib
= new QName(xmlNs
, "Attribute");
2029 if (cursor
.toChild(qAttrib
)) {
2030 for (int k
= 0; k
< j
; ++k
) {
2031 cursor
.toNextSibling(qAttrib
);
2033 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2034 attrib
.setName(name
);
2035 attrib
.setValue(value
);
2040 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2041 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2042 XmlCursor cursor
= ffs
.newCursor();
2043 QName qAttrib
= new QName(xmlNs
, "Attribute");
2044 if (cursor
.toChild(qAttrib
)) {
2045 for (int k
= 0; k
< j
; ++k
) {
2046 cursor
.toNextSibling(qAttrib
);
2053 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2054 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2058 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2060 if (sections
== null){
2061 sections
= ffs
.addNewSections();
2063 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2066 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2067 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2068 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2069 if (sections
== null) {
2072 XmlCursor cursor
= sections
.newCursor();
2073 QName qSection
= new QName(xmlNs
, "Section");
2074 if (cursor
.toChild(qSection
)) {
2075 for (int k
= 0; k
< j
; ++k
) {
2076 cursor
.toNextSibling(qSection
);
2083 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2084 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2085 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2086 if (sections
== null) {
2089 XmlCursor cursor
= sections
.newCursor();
2090 QName qSection
= new QName(xmlNs
, "Section");
2091 if (cursor
.toChild(qSection
)) {
2092 for (int k
= 0; k
< j
; ++k
) {
2093 cursor
.toNextSibling(qSection
);
2095 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2096 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2101 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2102 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2106 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2108 if (sections
== null){
2109 sections
= ffs
.addNewSections();
2111 sections
.addNewSections().setEncapsulationType(encapType
);
2114 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2115 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2116 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2117 if (sections
== null) {
2120 XmlCursor cursor
= sections
.newCursor();
2121 QName qSections
= new QName(xmlNs
, "Sections");
2122 if (cursor
.toChild(qSections
)) {
2123 for (int k
= 0; k
< j
; ++k
) {
2124 cursor
.toNextSibling(qSections
);
2131 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2132 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2133 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2134 if (sections
== null) {
2137 XmlCursor cursor
= sections
.newCursor();
2138 QName qSections
= new QName(xmlNs
, "Sections");
2139 if (cursor
.toChild(qSections
)) {
2140 for (int k
= 0; k
< j
; ++k
) {
2141 cursor
.toNextSibling(qSections
);
2143 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2144 sections2
.setEncapsulationType(type
);
2149 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2150 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2154 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2155 XmlCursor cursor
= sections
.newCursor();
2156 QName qSections
= new QName(xmlNs
, "Sections");
2157 if (cursor
.toChild(qSections
)){
2158 for (int k
= 0; k
< j
; ++k
) {
2159 cursor
.toNextSibling(qSections
);
2161 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2162 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2167 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2168 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2169 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2170 if (sections
== null) {
2173 XmlCursor cursor
= sections
.newCursor();
2174 QName qSections
= new QName(xmlNs
, "Sections");
2175 if (cursor
.toChild(qSections
)) {
2176 for (int l
= 0; l
< j
; ++l
) {
2177 cursor
.toNextSibling(qSections
);
2179 if (cursor
.toFirstChild()) {
2181 for (; m
< k
; ++m
) {
2182 cursor
.toNextSibling();
2194 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2195 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2196 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2197 if (sections
== null) {
2200 XmlCursor cursor
= sections
.newCursor();
2201 QName qSections
= new QName(xmlNs
, "Sections");
2202 if (cursor
.toChild(qSections
)) {
2203 for (int l
= 0; l
< j
; ++l
) {
2204 cursor
.toNextSibling(qSections
);
2206 if (cursor
.toFirstChild()) {
2207 for (int m
= 0; m
< k
; ++m
) {
2208 cursor
.toNextSibling();
2210 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2211 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2217 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2218 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2222 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2223 XmlCursor cursor
= sections
.newCursor();
2224 QName qSections
= new QName(xmlNs
, "Sections");
2225 if (cursor
.toChild(qSections
)){
2226 for (int k
= 0; k
< j
; ++k
) {
2227 cursor
.toNextSibling(qSections
);
2229 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2230 if (sections2
.getSectionList() == null){
2234 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2235 while(li
.hasNext()) {
2236 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2237 if (section
.isSetSectionType()) {
2238 al
.add(section
.getSectionType().toString());
2247 public int getBuildOptionsFfsCount(){
2248 if (getfpdBuildOpts().getFfsList() == null) {
2251 return getfpdBuildOpts().getFfsList().size();
2254 public void getBuildOptionsFfsKey(String
[][] saa
) {
2255 if (getfpdBuildOpts().getFfsList() == null) {
2258 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2260 while(li
.hasNext()){
2261 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2262 saa
[i
][0] = ffs
.getFfsKey();
2267 public void updateBuildOptionsFfsKey(int i
, String key
) {
2268 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2272 /**Get ith FFS key and contents.
2275 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2276 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2280 sa
[0] = ffs
.getFfsKey();
2281 if (ffs
.getSections() != null) {
2282 if(ffs
.getSections().getEncapsulationType() != null){
2283 sa
[1] = ffs
.getSections().getEncapsulationType();
2285 if (ffs
.getSections().getSectionList() != null){
2286 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2287 while (li
.hasNext()) {
2288 firstLevelSection
.add(li
.next().getSectionType().toString());
2291 if (ffs
.getSections().getSectionsList() != null) {
2292 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2293 while(li
.hasNext()) {
2294 firstLevelSections
.add(li
.next().getEncapsulationType());
2298 if (ffs
.getAttributeList() != null) {
2299 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2300 while(li
.hasNext()) {
2301 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2302 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2311 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2312 XmlObject o
= getfpdBuildOpts();
2313 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2315 XmlCursor cursor
= o
.newCursor();
2316 QName qFfs
= new QName(xmlNs
, "Ffs");
2317 if (cursor
.toChild(qFfs
)) {
2318 for (int j
= 0; j
< i
; ++j
) {
2319 cursor
.toNextSibling(qFfs
);
2321 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2327 public void removeBuildOptionsFfs(int i
) {
2328 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2333 XmlCursor cursor
= ffs
.newCursor();
2340 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2341 if (fpdPlatformDefs
== null){
2342 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2344 return fpdPlatformDefs
;
2347 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2348 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2351 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2352 while(li
.hasNext()) {
2353 archs
.add(li
.next());
2357 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2358 if (archs
!= null) {
2359 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2362 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2363 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2364 // cursor.removeXml();
2366 // cursor.dispose();
2370 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2371 if (getfpdPlatformDefs().getBuildTargets() == null) {
2374 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2375 while(li
.hasNext()) {
2376 targets
.add(li
.next());
2380 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2381 getfpdPlatformDefs().setBuildTargets(targets
);
2384 public void genPlatformDefsSkuInfo(String id
, String name
) {
2385 SkuInfoDocument
.SkuInfo skuInfo
= null;
2386 if (getfpdPlatformDefs().getSkuInfo() == null) {
2387 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2389 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2390 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2391 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2392 skuName
.setSkuID(new BigInteger("0"));
2393 skuName
.setStringValue("DEFAULT");
2395 if (id
.equals("0")) {
2398 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2399 skuName
.setSkuID(new BigInteger(id
));
2400 skuName
.setStringValue(name
);
2403 public int getPlatformDefsSkuInfoCount(){
2404 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2407 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2410 public void getPlatformDefsSkuInfos(String
[][] saa
){
2411 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2412 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2413 removeElement(getfpdDynPcdBuildDefs());
2414 fpdDynPcdBuildDefs
= null;
2419 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2420 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2422 while(li
.hasNext()) {
2423 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2424 saa
[i
][0] = sku
.getSkuID()+"";
2425 saa
[i
][1] = sku
.getStringValue();
2430 public void removePlatformDefsSkuInfo(int i
) {
2431 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2432 if (skuInfo
== null || i
== 0) {
2436 XmlCursor cursor
= skuInfo
.newCursor();
2437 if (cursor
.toFirstChild()) {
2438 for (int j
= 0; j
< i
; ++j
) {
2439 cursor
.toNextSibling();
2446 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2447 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2448 if (skuInfo
== null || i
== 0) {
2452 XmlCursor cursor
= skuInfo
.newCursor();
2453 if (cursor
.toFirstChild()) {
2454 for (int j
= 0; j
< i
; ++j
) {
2455 cursor
.toNextSibling();
2457 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2458 sku
.setSkuID(new BigInteger(id
));
2459 sku
.setStringValue(name
);
2464 public String
getPlatformDefsInterDir(){
2465 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2468 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2471 public void setPlatformDefsInterDir(String interDir
){
2472 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2475 public String
getPlatformDefsOutputDir() {
2476 return getfpdPlatformDefs().getOutputDirectory();
2479 public void setPlatformDefsOutputDir(String outputDir
) {
2480 if (outputDir
!= null && outputDir
.length() > 0) {
2481 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2484 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2485 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2492 public FlashDocument
.Flash
getfpdFlash() {
2493 if (fpdFlash
== null) {
2494 fpdFlash
= fpdRoot
.addNewFlash();
2499 public void genFlashDefinitionFile(String file
) {
2500 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2502 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2505 fdf
.setStringValue(file
);
2508 public String
getFlashDefinitionFile() {
2509 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2514 return fdf
.getStringValue();
2517 public void genFvImagesNameValue(String name
, String value
) {
2519 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2521 fi
= getfpdFlash().addNewFvImages();
2524 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2529 public void removeFvImagesNameValue(int i
){
2531 XmlObject o
= getfpdFlash().getFvImages();
2536 QName qNameValue
= new QName(xmlNs
, "NameValue");
2537 XmlCursor cursor
= o
.newCursor();
2538 if (cursor
.toChild(qNameValue
)) {
2539 for (int j
= 0; j
< i
; ++j
) {
2540 cursor
.toNextSibling(qNameValue
);
2547 public void updateFvImagesNameValue(int i
, String name
, String value
){
2549 XmlObject o
= getfpdFlash().getFvImages();
2554 QName qNameValue
= new QName(xmlNs
, "NameValue");
2555 XmlCursor cursor
= o
.newCursor();
2556 if (cursor
.toChild(qNameValue
)) {
2557 for (int j
= 0; j
< i
; ++j
) {
2558 cursor
.toNextSibling(qNameValue
);
2560 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2567 public int getFvImagesNameValueCount() {
2569 FvImagesDocument
.FvImages fi
= null;
2570 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2573 return fi
.getNameValueList().size();
2576 public void getFvImagesNameValues(String
[][] nv
) {
2578 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2582 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2584 ListIterator li
= l
.listIterator();
2585 while (li
.hasNext()) {
2586 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2588 nv
[i
][0] = e
.getName();
2589 nv
[i
][1] = e
.getValue();
2595 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2596 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2597 if (fis
== null || fis
.getFvImageList() == null) {
2601 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2602 while (li
.hasNext()) {
2603 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2604 if (fi
.getType().toString().equals("ImageName")) {
2605 vImageNames
.addAll(fi
.getFvImageNamesList());
2611 public void AddFvImageFvImageNames (String
[] fvNames
) {
2612 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2613 if (fis
== null || fis
.getFvImageList() == null) {
2614 genFvImagesFvImage (fvNames
, "ImageName", null);
2618 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2619 while (li
.hasNext()) {
2620 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2621 if (fi
.getType().toString().equals("ImageName")) {
2622 for (int i
= 0; i
< fvNames
.length
; ++i
) {
2623 fi
.addFvImageNames(fvNames
[i
]);
2628 genFvImagesFvImage (fvNames
, "ImageName", null);
2632 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
2634 FvImagesDocument
.FvImages fis
= null;
2635 if ((fis
= getfpdFlash().getFvImages()) == null) {
2636 fis
= getfpdFlash().addNewFvImages();
2640 //gen FvImage with FvImageNames array
2642 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
2643 for (int i
= 0; i
< names
.length
; ++i
) {
2644 fi
.addFvImageNames(names
[i
]);
2646 fi
.setType(FvImageTypes
.Enum
.forString(types
));
2647 if (options
!= null){
2648 setFvImagesFvImageFvImageOptions(options
, fi
);
2652 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
2653 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
2655 fio
= fi
.addNewFvImageOptions();
2658 Set
<String
> key
= options
.keySet();
2659 Iterator
<String
> i
= key
.iterator();
2660 while (i
.hasNext()) {
2662 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
2663 String k
= (String
)i
.next();
2666 nv
.setValue((String
)options
.get(k
));
2673 public void removeFvImagesFvImage(int i
) {
2675 XmlObject o
= getfpdFlash().getFvImages();
2680 QName qFvImage
= new QName(xmlNs
, "FvImage");
2681 XmlCursor cursor
= o
.newCursor();
2682 if (cursor
.toChild(qFvImage
)) {
2683 for (int j
= 0; j
< i
; ++j
) {
2684 cursor
.toNextSibling(qFvImage
);
2693 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2695 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
2696 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2699 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
2700 while (li
.hasNext()) {
2701 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2702 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
2703 if (fi
.getFvImageNamesList().size() == 0) {
2711 * @param oldFvName The FV Name to be replaced.
2712 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2714 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
2715 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
2716 XmlCursor cursor
= fi
.newCursor();
2718 if (cursor
.toChild(qFvImageNames
)) {
2720 String xmlValue
= cursor
.getTextValue();
2721 if (xmlValue
.equals(oldFvName
)){
2722 if (newFvName
!= null) {
2723 cursor
.setTextValue(newFvName
);
2729 }while (cursor
.toNextSibling(qFvImageNames
));
2735 /**update the Type attribute of ith FvImage with new type.
2739 public void updateFvImagesFvImageType (int i
, String type
) {
2740 XmlObject o
= getfpdFlash().getFvImages();
2744 XmlCursor cursor
= o
.newCursor();
2745 QName qFvImage
= new QName(xmlNs
, "FvImage");
2746 if (cursor
.toChild(qFvImage
)) {
2747 for (int j
= 0; j
< i
; ++j
) {
2748 cursor
.toNextSibling(qFvImage
);
2750 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
2751 fi
.setType(FvImageTypes
.Enum
.forString(type
));
2756 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
2758 XmlObject o
= getfpdFlash().getFvImages();
2762 XmlCursor cursor
= o
.newCursor();
2763 QName qFvImage
= new QName(xmlNs
, "FvImage");
2764 if (cursor
.toChild(qFvImage
)) {
2765 for (int j
= 0; j
< i
; ++j
) {
2766 cursor
.toNextSibling(qFvImage
);
2768 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
2769 fi
.setType(FvImageTypes
.Enum
.forString(types
));
2772 // remove old FvImageNames before adding new ones
2774 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
2775 cursor
.toChild(qFvImageNames
);
2777 while (cursor
.toNextSibling(qFvImageNames
)) {
2781 for (int k
= 0; k
< names
.length
; ++k
) {
2782 fi
.addFvImageNames(names
[k
]);
2785 // remove old FvImageOptions before adding new options
2787 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
2788 cursor
.toNextSibling(qFvImageOptions
);
2791 setFvImagesFvImageFvImageOptions(options
, fi
);
2796 public int getFvImagesFvImageCount(String type
) {
2798 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2801 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2802 ListIterator li
= l
.listIterator();
2804 while(li
.hasNext()) {
2805 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2806 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2816 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
2817 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
2818 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2821 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2822 ListIterator li
= l
.listIterator();
2823 while(li
.hasNext()) {
2824 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2825 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2828 if (fi
.getFvImageNamesList().contains(fvName
)) {
2837 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
2839 public void getFvImagesFvImages(String
[][] saa
, String type
) {
2841 if (getfpdFlash().getFvImages() == null) {
2844 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2848 ListIterator li
= l
.listIterator();
2850 while(li
.hasNext()) {
2851 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2852 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2856 // get FvImageNames array, space separated
2858 List
<String
> lfn
= fi
.getFvImageNamesList();
2859 ListIterator lfni
= lfn
.listIterator();
2861 while (lfni
.hasNext()) {
2862 saa
[i
][0] += (String
)lfni
.next();
2865 saa
[i
][0] = saa
[i
][0].trim();
2867 saa
[i
][1] = fi
.getType()+"";
2873 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
2875 * @param attributeName
2877 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
2878 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
2879 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
2880 while (li
.hasNext()) {
2881 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
2882 if (nv
.getName().equals(attributeName
)) {
2889 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
2890 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
2891 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
2892 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
2893 removeFvImageNameValue (fi
, optName
);
2897 /**Add name-value pair to FvImage element with type.
2898 * @param fvName FV name to add name-value pair.
2899 * @param type FvImage attribute.
2903 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
) {
2904 boolean fvImageExists
= false;
2905 if (getfpdFlash().getFvImages() == null) {
2908 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2912 ListIterator li
= l
.listIterator();
2913 while(li
.hasNext()) {
2914 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2915 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2918 if (!fi
.getFvImageNamesList().contains(fvName
)) {
2921 fvImageExists
= true;
2922 setFvImagesFvImageNameValue (fi
, name
, value
, null);
2925 if (!fvImageExists
) {
2926 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
2927 map
.put(name
, value
);
2928 genFvImagesFvImage(new String
[]{fvName
}, type
, map
);
2932 /**Add to all FvImage elements with type, the name-value pair.
2937 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
2938 if (getfpdFlash().getFvImages() == null) {
2941 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
2945 ListIterator li
= l
.listIterator();
2946 while(li
.hasNext()) {
2947 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
2948 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
2951 setFvImagesFvImageNameValue (fi
, name
, value
, null);
2956 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
2962 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
2963 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
2967 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
2968 if (cursor
.toFirstChild()) {
2970 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
2971 if (nv
.getName().equals(name
)) {
2973 if (newName
!= null) {
2974 nv
.setName(newName
);
2979 }while (cursor
.toNextSibling());
2982 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
2985 if (newName
!= null) {
2986 nv
.setName(newName
);
2991 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
2992 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
2993 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
2994 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
2995 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
2999 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3002 while (li
.hasNext()) {
3003 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3004 m
.put(nv
.getName(), nv
.getValue());
3009 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3010 XmlObject o
= getfpdFlash().getFvImages();
3016 String
[] fvNameArray
= fvNameList
.split(" ");
3017 Vector
<String
> vFvNames
= new Vector
<String
>();
3020 XmlCursor cursor
= o
.newCursor();
3021 QName qFvImage
= new QName(xmlNs
, "FvImage");
3022 if (cursor
.toChild(qFvImage
)) {
3025 vFvNames
.removeAllElements();
3026 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3027 vFvNames
.add(fvNameArray
[i
]);
3029 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3030 if (!fi
.getType().toString().equals(type
)) {
3033 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3036 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3037 while (li
.hasNext()) {
3038 String name
= li
.next();
3039 vFvNames
.remove(name
);
3041 if (vFvNames
.size() == 0) {
3046 }while (cursor
.toNextSibling(qFvImage
));
3052 /**Get FvImage Options for FvImage i
3053 * @param i the ith FvImage
3055 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3056 XmlObject o
= getfpdFlash().getFvImages();
3060 XmlCursor cursor
= o
.newCursor();
3061 QName qFvImage
= new QName(xmlNs
, "FvImage");
3062 if (cursor
.toChild(qFvImage
)) {
3063 for (int j
= 0; j
< i
; ++j
) {
3064 cursor
.toNextSibling(qFvImage
);
3066 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3067 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3071 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3072 while(li
.hasNext()){
3073 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3074 m
.put(nv
.getName(), nv
.getValue());
3081 Get platform header element
3082 @return PlatformHeaderDocument.PlatformHeader
3084 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3085 if (fpdHdr
== null) {
3086 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3092 public String
getFpdHdrPlatformName() {
3093 return getFpdHdr().getPlatformName();
3096 public String
getFpdHdrGuidValue() {
3097 return getFpdHdr().getGuidValue();
3100 public String
getFpdHdrVer() {
3101 return getFpdHdr().getVersion();
3104 public String
getFpdHdrAbs() {
3105 return getFpdHdr().getAbstract();
3108 public String
getFpdHdrDescription() {
3109 return getFpdHdr().getDescription();
3112 public String
getFpdHdrCopyright() {
3113 return getFpdHdr().getCopyright();
3116 public String
getFpdHdrLicense() {
3117 LicenseDocument
.License l
= getFpdHdr().getLicense();
3121 return l
.getStringValue();
3124 public String
getFpdHdrUrl() {
3125 LicenseDocument
.License l
= getFpdHdr().getLicense();
3132 public String
getFpdHdrSpec() {
3134 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3135 // return getFpdHdr().getSpecification();
3138 public void setFpdHdrPlatformName(String name
){
3139 getFpdHdr().setPlatformName(name
);
3142 public void setFpdHdrGuidValue(String guid
){
3143 getFpdHdr().setGuidValue(guid
);
3146 public void setFpdHdrVer(String v
){
3147 getFpdHdr().setVersion(v
);
3150 public void setFpdHdrAbs(String abs
) {
3151 getFpdHdr().setAbstract(abs
);
3154 public void setFpdHdrDescription(String desc
){
3155 getFpdHdr().setDescription(desc
);
3158 public void setFpdHdrCopyright(String cr
) {
3159 getFpdHdr().setCopyright(cr
);
3162 public void setFpdHdrLicense(String license
){
3163 LicenseDocument
.License l
= getFpdHdr().getLicense();
3165 getFpdHdr().addNewLicense().setStringValue(license
);
3168 l
.setStringValue(license
);
3172 public void setFpdHdrUrl(String url
){
3173 LicenseDocument
.License l
= getFpdHdr().getLicense();
3179 public void setFpdHdrSpec(String s
){
3180 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3181 getFpdHdr().setSpecification(s
);
3184 Save the processed xml contents to file
3186 @param fpdFile The file to save xml contents
3187 @throws IOException Exceptions during file operation
3189 public void saveAs(File fpdFile
) throws IOException
{
3191 XmlOptions options
= new XmlOptions();
3193 options
.setCharacterEncoding("UTF-8");
3194 options
.setSavePrettyPrint();
3195 options
.setSavePrettyPrintIndent(2);
3197 fpdd
.save(fpdFile
, options
);
3198 } catch (IOException e
) {
3199 e
.printStackTrace();
3204 private String
listToString(List l
) {
3209 ListIterator li
= l
.listIterator();
3210 while(li
.hasNext()) {
3217 private void removeElement(XmlObject o
) {
3218 XmlCursor cursor
= o
.newCursor();
3224 class PcdItemTypeConflictException
extends Exception
{
3229 private static final long serialVersionUID
= 1L;
3230 private String details
= null;
3232 PcdItemTypeConflictException(String pcdName
, String info
){
3233 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3234 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3237 public String
getMessage() {
3242 class PcdDeclNotFound
extends Exception
{
3247 private static final long serialVersionUID
= 1L;
3248 private String details
= null;
3250 PcdDeclNotFound(String info
) {
3251 details
= "PcdDeclNotFound: " + info
;
3254 public String
getMessage() {
3259 class PcdValueMalFormed
extends Exception
{
3264 private static final long serialVersionUID
= 1L;
3265 private String details
= null;
3267 PcdValueMalFormed(String info
) {
3268 details
= "PcdValueMalFormed: " + info
;
3271 public String
getMessage() {