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
.LibrariesDocument
.Libraries
.Instance
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.WorkspaceProfile
;
63 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
64 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
65 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
66 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
69 This class processes fpd file contents such as add remove xml elements.
70 @since PackageEditor 1.0
72 public class FpdFileContents
{
74 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
75 static final String regExpNewLineAndSpaces
= "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
77 private PlatformSurfaceAreaDocument fpdd
= null;
79 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
81 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
83 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
85 private FlashDocument
.Flash fpdFlash
= null;
87 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
89 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
91 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
93 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
95 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
97 private String
itemType (String pcdInfo
) {
99 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
103 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
105 public void initDynPcdMap() {
106 if (dynPcdMap
== null) {
107 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
108 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
110 removeElement(getfpdFrameworkModules());
111 fpdFrameworkModules
= null;
114 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
115 while (li
.hasNext()) {
116 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
117 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
120 String ModuleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion() +
121 " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
122 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
123 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
124 while (lpi
.hasNext()) {
125 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
126 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
127 if (dynPcdMap
.get(pcdKey
) == null) {
128 ArrayList
<String
> al
= new ArrayList
<String
>();
129 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
130 dynPcdMap
.put(pcdKey
, al
);
133 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
140 public ArrayList
<String
> getDynPcdMapValue(String key
) {
141 return dynPcdMap
.get(key
);
144 Constructor to create a new spd file
146 public FpdFileContents() {
148 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
149 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
154 Constructor for existing document object
157 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
159 fpdHdr
= fpdRoot
.getPlatformHeader();
160 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
161 fpdBuildOpts
= fpdRoot
.getBuildOptions();
162 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
163 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
164 fpdFlash
= fpdRoot
.getFlash();
168 Constructor based on an existing spd file
170 @param f Existing spd file
172 public FpdFileContents(File f
) {
174 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
175 fpdRoot
= fpdd
.getPlatformSurfaceArea();
176 } catch (Exception e
) {
177 System
.out
.println(e
.toString());
181 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
182 if (fpdDynPcdBuildDefs
== null){
183 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
185 return fpdDynPcdBuildDefs
;
188 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
189 if (fpdFrameworkModules
== null){
190 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
192 return fpdFrameworkModules
;
195 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
196 if (getFrameworkModulesCount() == 0){
200 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
201 while(li
.hasNext()) {
202 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
203 if (moduleSa
.getModuleSaBuildOptions() == null) {
206 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
207 if (fvBinding
== null) {
211 String
[] fvNames
= fvBinding
.split(" ");
212 for (int i
= 0; i
< fvNames
.length
; ++i
) {
214 // BugBug : underscore "_" should not be replaced!!!
215 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
217 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
218 String
[] sa
= new String
[] {moduleSa
.getModuleGuid(), moduleSa
.getModuleVersion(),
219 moduleSa
.getPackageGuid(), moduleSa
.getPackageVersion(),
220 listToString(moduleSa
.getSupArchList())};
228 public int getFrameworkModulesCount() {
229 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
230 removeElement(getfpdFrameworkModules());
231 fpdFrameworkModules
= null;
234 return getfpdFrameworkModules().getModuleSAList().size();
237 public void getFrameworkModulesInfo(String
[][] saa
) {
238 if (getFrameworkModulesCount() == 0){
242 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
244 while(li
.hasNext()) {
245 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
246 saa
[i
][0] = moduleSa
.getModuleGuid();
247 saa
[i
][1] = moduleSa
.getModuleVersion();
249 saa
[i
][2] = moduleSa
.getPackageGuid();
250 saa
[i
][3] = moduleSa
.getPackageVersion();
251 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
256 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
257 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
261 sa
[0] = msa
.getModuleGuid();
262 sa
[1] = msa
.getModuleVersion();
263 sa
[2] = msa
.getPackageGuid();
264 sa
[3] = msa
.getPackageVersion();
265 sa
[4] = listToString(msa
.getSupArchList());
268 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
270 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
271 removeElement(getfpdFrameworkModules());
272 fpdFrameworkModules
= null;
275 String
[] s
= key
.split(" ");
276 String archsInKey
= "";
278 for (int i
= 4; i
< s
.length
; ++i
) {
282 archsInKey
= archsInKey
.trim();
285 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
286 while(li
.hasNext()) {
287 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
288 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
289 if (moduleSa
.getModuleVersion() != null) {
290 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
294 if (moduleSa
.getPackageVersion() != null) {
295 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
299 //ToDo add arch check .
300 if (moduleSa
.getSupArchList() != null) {
301 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
306 if (archsInKey
.length() == 0) {
315 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
316 ModuleSADocument
.ModuleSA moduleSa
= null;
317 if (fpdRoot
.getFrameworkModules() == null) {
320 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
321 if (cursor
.toFirstChild()) {
322 for (int j
= 0; j
< i
; ++j
) {
323 cursor
.toNextSibling();
325 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
331 public void removeModuleSA(int i
) {
332 XmlObject o
= fpdRoot
.getFrameworkModules();
337 XmlCursor cursor
= o
.newCursor();
338 if (cursor
.toFirstChild()) {
339 for (int j
= 0; j
< i
; ++j
) {
340 cursor
.toNextSibling();
343 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
345 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
346 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
347 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
348 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
349 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
350 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
351 while(li
.hasNext()) {
352 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
353 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
358 while (cursor
.hasPrevToken()) {
359 cursor
.toPrevToken();
360 if (!cursor
.isText()) {
363 if (cursor
.getObject() == null) {
366 String s
= cursor
.getTextValue();
367 if (s
.matches(regExpNewLineAndSpaces
)) {
372 if (cursor
.isComment()) {
378 if (getFrameworkModulesCount() == 0) {
380 removeElement(getfpdFrameworkModules());
381 fpdFrameworkModules
= null;
388 public boolean adjustPcd (String seqModuleSa
, Vector
<String
> vExceptions
) throws Exception
{
389 boolean dataModified
= false;
390 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
391 int pcdCount
= getPcdDataCount(seqModuleSa
);
392 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
393 getPcdData(seqModuleSa
, saaModuleSaPcd
);
394 String mg
= moduleSa
.getModuleGuid().toLowerCase();
395 String mv
= moduleSa
.getModuleVersion();
396 String pg
= moduleSa
.getPackageGuid().toLowerCase();
397 String pv
= moduleSa
.getPackageVersion();
398 String arch
= listToString(moduleSa
.getSupArchList());
400 // delete pcd in ModuleSA but not in MSA files any longer.
402 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
403 int libCount
= getLibraryInstancesCount(moduleKey
);
404 String
[][] saaLib
= new String
[libCount
][5];
405 getLibraryInstances(moduleKey
, saaLib
);
406 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
408 vExceptions
.add("Module " + mg
+ " does NOT exist in workspace.");
409 throw new Exception ("Module does NOT exist in workspace.");
411 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
413 // create vector for module & library instance MIs.
416 for (int j
= 0; j
< saaLib
.length
; ++j
) {
417 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
418 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
424 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
426 for (int j
= 0; j
< vMi
.size(); ++j
) {
427 ModuleIdentification nextMi
= vMi
.get(j
);
428 if (nextMi
== null) {
431 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], arch
, nextMi
)) {
435 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
439 // add new Pcd from MSA file to ModuleSA.
441 for (int i
= 0; i
< vMi
.size(); ++i
) {
442 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
443 .getModuleXmlObject(vMi
445 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
448 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
449 msaPcdIter
:while (li
.hasNext()) {
450 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
451 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
453 for (int j
= 0; j
< al
.size(); ++j
) {
454 if (al
.get(j
).startsWith(moduleKey
)) {
459 // Check sup arch conformance for the new PCD
460 if (msaPcd
.getSupArchList() != null) {
461 String newPcdArch
= msaPcd
.getSupArchList().toString();
462 if (!newPcdArch
.toLowerCase().contains(arch
.toLowerCase())) {
467 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
468 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
469 if (spdPcd
== null) {
473 String errorMessage
= "No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
476 errorMessage
+= " Library Instance " + vMi
.get(i
).getName();
478 vExceptions
.add(errorMessage
);
479 throw new PcdDeclNotFound(errorMessage
);
482 // AddItem to ModuleSA PcdBuildDefinitions
484 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
485 : msaPcd
.getDefaultValue();
487 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
488 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
497 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
499 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
503 String
[] s
= moduleInfo
.split(" ");
504 for(int i
= 0; i
< al
.size(); ++i
){
505 String consumer
= al
.get(i
);
506 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
507 String
[] consumerPart
= consumer
.split(" ");
508 if (!consumerPart
[4].equals(s
[4])) {
516 if (al
.size() == 0) {
517 defaultPcdValue
.remove(pcdKey
);
518 dynPcdMap
.remove(pcdKey
);
519 String
[] s1
= pcdKey
.split(" ");
520 removeDynamicPcdBuildData(s1
[0], s1
[1]);
525 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
527 public int getPcdDataCount (String key
){
528 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
530 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
533 return msa
.getPcdBuildDefinition().getPcdDataList().size();
537 public void getPcdData (String key
, String
[][] saa
) {
538 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
540 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
543 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
544 for (int k
= 0; k
< saa
.length
; ++k
) {
545 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
546 saa
[k
][0] = pcdData
.getCName();
547 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
548 saa
[k
][2] = pcdData
.getItemType()+"";
549 saa
[k
][3] = pcdData
.getToken().toString();
550 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
551 saa
[k
][5] = pcdData
.getDatumType()+"";
552 saa
[k
][6] = pcdData
.getValue();
557 public void removePcdData (String key
, String cName
, String tsGuid
) {
558 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
559 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
563 String mg
= moduleSa
.getModuleGuid();
564 String mv
= moduleSa
.getModuleVersion();
565 String pg
= moduleSa
.getPackageGuid();
566 String pv
= moduleSa
.getPackageVersion();
567 String arch
= listToString(moduleSa
.getSupArchList());
568 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
570 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
571 if (cursor
.toFirstChild()){
574 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
575 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
576 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
577 if (getPcdDataCount(key
) == 1) {
584 while(cursor
.toNextSibling());
590 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
591 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
592 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
596 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
597 if (cursor
.toFirstChild()){
599 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
600 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
602 // change item type while not updating dynPcdData????
604 if (itemType
!= null) {
605 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
608 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
609 pcdData
.setMaxDatumSize(new Integer(maxSize
));
612 // if value input is null, keep old value untouched.
615 pcdData
.setValue(value
);
616 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
622 while(cursor
.toNextSibling());
627 /**Get original Pcd info from MSA & SPD files.
628 * @param mi ModuleIdentification from which MSA & SPD come
629 * @param cName PCD cName
630 * @param sa Results: HelpText, Original item type.
633 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
635 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
636 .getModuleXmlObject(mi
);
637 if (msa
.getPcdCoded() == null) {
641 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
643 // First look through MSA pcd entries.
645 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
646 ListIterator li
= l
.listIterator();
647 while (li
.hasNext()) {
648 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
649 if (!msaPcd
.getCName().equals(cName
)) {
652 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
655 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
656 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
660 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
663 // Get Pcd help text and original item type.
665 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
666 sa
[1] = msaPcd
.getPcdItemType() + "";
667 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
668 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
669 while (iter
.hasNext()) {
670 String usage
= iter
.next().toString();
671 validPcdTypes
.add(usage
);
679 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
680 int libCount
= getLibraryInstancesCount(moduleKey
);
681 String
[][] saaLib
= new String
[libCount
][5];
682 getLibraryInstances(moduleKey
, saaLib
);
683 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
684 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
686 // create vector for module & library instance MIs.
689 for (int j
= 0; j
< saaLib
.length
; ++j
) {
690 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
691 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
695 int pcdSourceCount
= 0;
696 for (int i
= 0; i
< vMi
.size(); ++i
) {
697 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, null, vMi
.get(i
))) {
702 if (pcdSourceCount
< 2) {
711 /**Remove PCDBuildDefinition entries from ModuleSA
712 * @param moduleKey identifier of ModuleSA.
713 * @param consumer where these entries come from.
715 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
717 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
718 if (msa
.getPcdCoded() == null) {
722 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
723 ListIterator li
= l
.listIterator();
725 while(li
.hasNext()) {
726 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
727 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
728 if (moduleSA
.getPcdBuildDefinition() != null) {
729 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
731 if (cursor
.toFirstChild()) {
733 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
735 String cName
= msaPcd
.getCName();
736 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
737 if (cName
.equals(pcdData
.getCName())
738 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
740 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
745 } while (cursor
.toNextSibling());
749 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
758 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
760 public int getLibraryInstancesCount(String key
) {
761 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
762 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
765 return msa
.getLibraries().getInstanceList().size();
768 public void getLibraryInstances(String key
, String
[][] saa
){
769 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
770 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
774 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
775 for (int i
= 0; i
< saa
.length
; ++i
) {
776 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
777 saa
[i
][1] = instance
.getModuleGuid();
778 saa
[i
][2] = instance
.getModuleVersion();
779 saa
[i
][3] = instance
.getPackageGuid();
780 saa
[i
][4] = instance
.getPackageVersion();
784 public boolean instanceExistsInModuleSA (String key
, String mg
, String mv
, String pg
, String pv
) {
786 if ((count
= getLibraryInstancesCount(key
)) > 0) {
787 String
[][] saa
= new String
[count
][5];
788 getLibraryInstances (key
, saa
);
789 for (int i
= 0; i
< count
; ++i
) {
790 if (mg
.equalsIgnoreCase(saa
[i
][1]) && pg
.equalsIgnoreCase(saa
[i
][3])) {
791 boolean modVerMatch
= false;
792 boolean pkgVerMatch
= false;
793 if ((mv
.equals("null") || saa
[i
][2] == null)) {
796 if (pv
.equals("null") || saa
[i
][4] == null) {
799 if (modVerMatch
&& pkgVerMatch
) {
803 if (mv
.equals(saa
[i
][2]) && pv
.equals(saa
[i
][4])) {
813 public void removeLibraryInstance(String key
, String instanceKey
) {
814 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
815 if (msa
== null || msa
.getLibraries() == null){
819 String
[] instanceInfo
= instanceKey
.split(" ");
820 XmlCursor cursor
= msa
.getLibraries().newCursor();
821 if (cursor
.toFirstChild()) {
823 Instance libIns
= (Instance
)cursor
.getObject();
824 if (libIns
.getModuleGuid().equalsIgnoreCase(instanceInfo
[0]) && libIns
.getPackageGuid().equalsIgnoreCase(instanceInfo
[2])) {
827 }while (cursor
.toNextSibling());
829 while (cursor
.hasPrevToken()) {
830 cursor
.toPrevToken();
831 if (!cursor
.isText()) {
834 String s
= cursor
.getTextValue();
835 if (s
.matches(regExpNewLineAndSpaces
)) {
840 if (cursor
.isComment()) {
845 if (getLibraryInstancesCount(key
) == 0) {
854 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
855 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
857 msa
= getfpdFrameworkModules().addNewModuleSA();
859 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
861 libs
= msa
.addNewLibraries();
864 String mn
= libMi
.getName();
865 String mg
= libMi
.getGuid();
866 String mv
= libMi
.getVersion();
867 String pn
= libMi
.getPackageId().getName();
868 String pg
= libMi
.getPackageId().getGuid();
869 String pv
= libMi
.getPackageId().getVersion();
870 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
871 XmlCursor cursor
= instance
.newCursor();
873 String comment
= "Pkg: " + pn
+ " Mod: " + mn
874 + " Path: " + libMi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
875 cursor
.insertComment(comment
);
884 instance
.setModuleGuid(mg
);
885 instance
.setModuleVersion(mv
);
886 instance
.setPackageGuid(pg
);
887 instance
.setPackageVersion(pv
);
891 public String
getFvBinding(String moduleKey
){
892 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
893 return getFvBinding (moduleSa
);
896 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
897 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
900 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
903 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
904 if (moduleSa
== null ) {
907 if (fvBinding
== null || fvBinding
.length() == 0) {
908 if(moduleSa
.getModuleSaBuildOptions() != null){
909 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
913 if(moduleSa
.getModuleSaBuildOptions() == null){
914 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
917 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
921 public void setFvBinding(String moduleKey
, String fvBinding
){
922 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
923 setFvBinding (moduleSa
, fvBinding
);
926 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
927 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
931 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
932 String
[] fvNamesArray
= fvNameList
.split(" ");
934 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
935 if (fvNamesArray
[i
].equals(fvName
)) {
943 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
944 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
948 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
949 String
[] fvNamesArray
= fvNameList
.split(" ");
951 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
952 if (fvNamesArray
[i
].equals(fvName
)) {
957 // jump over where the input fvName occurs in the original Fv list.
958 if (occursAt
!= -1) {
959 String newFvNameList
= " ";
960 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
964 newFvNameList
+= fvNamesArray
[i
];
966 setFvBinding (moduleSa
, newFvNameList
.trim());
972 * @param fvName The FV name that to be removed from FvBinding List.
974 public void removeFvBindingAll (String fvName
) {
975 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
976 removeElement(getfpdFrameworkModules());
977 fpdFrameworkModules
= null;
981 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
982 while (li
.hasNext()) {
983 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
984 removeFvBinding (moduleSa
, fvName
);
988 public void appendFvBindingAll (String fvName
) {
989 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
990 removeElement(getfpdFrameworkModules());
991 fpdFrameworkModules
= null;
995 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
996 while (li
.hasNext()) {
997 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
998 appendFvBinding (moduleSa
, fvName
);
1002 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
1003 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
1004 removeElement(getfpdFrameworkModules());
1005 fpdFrameworkModules
= null;
1009 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
1010 while (li
.hasNext()) {
1011 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
1012 String fvBinding
= getFvBinding (moduleSa
);
1013 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
1014 appendFvBinding (moduleSa
, newFvName
);
1019 public void appendFvBinding (String moduleKey
, String fvName
) {
1020 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1021 appendFvBinding (moduleSa
, fvName
);
1024 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
1025 if (moduleSa
== null) {
1029 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
1030 setFvBinding(moduleSa
, fvName
);
1034 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
1035 String newFvNameList
= fvNameList
+ " " + fvName
;
1036 setFvBinding (moduleSa
, newFvNameList
.trim());
1039 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
1041 appendFvBinding (moduleKey
, fvName
);
1044 public String
getFfsFileNameGuid(String moduleKey
){
1045 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1046 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
1049 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1052 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1053 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1057 if(msa
.getModuleSaBuildOptions() == null){
1058 msa
.addNewModuleSaBuildOptions();
1061 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1062 if (fileGuid
!= null) {
1063 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1066 XmlCursor cursor
= msaBuildOpts
.newCursor();
1067 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1075 public String
getFfsFormatKey(String moduleKey
){
1076 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1077 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1080 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1083 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1084 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1088 if(msa
.getModuleSaBuildOptions() == null){
1089 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1092 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1095 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1096 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1097 moduleSa
.setForceDebug(dbgEnable
);
1100 public boolean getModuleSAForceDebug (int i
) {
1101 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1102 if (moduleSa
.getForceDebug() == true) {
1108 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1109 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1110 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1111 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1115 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1116 ListIterator li
= lOpt
.listIterator();
1118 while(li
.hasNext()) {
1119 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1120 if (opt
.getBuildTargets() != null) {
1121 saa
[i
][0] = listToString(opt
.getBuildTargets());
1123 saa
[i
][1] = opt
.getToolChainFamily();
1124 saa
[i
][2] = opt
.getTagName();
1125 saa
[i
][3] = opt
.getToolCode();
1127 if (opt
.getSupArchList() != null){
1128 saa
[i
][4] = listToString(opt
.getSupArchList());
1134 saa
[i
][5] = opt
.getStringValue();
1140 public int getModuleSAOptionsCount(String moduleKey
){
1141 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1142 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1143 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1146 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1149 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1150 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1151 if (msa
.getModuleSaBuildOptions() == null) {
1152 msa
.addNewModuleSaBuildOptions();
1154 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1155 msa
.getModuleSaBuildOptions().addNewOptions();
1157 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1158 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1161 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1162 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1163 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1166 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1167 XmlCursor cursor
= opts
.newCursor();
1168 if (cursor
.toFirstChild()) {
1169 for (int j
= 0; j
< i
; ++j
){
1170 cursor
.toNextSibling();
1173 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1181 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1182 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1183 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1186 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1187 XmlCursor cursor
= opts
.newCursor();
1188 if (cursor
.toFirstChild()) {
1189 for (int j
= 0; j
< i
; ++j
){
1190 cursor
.toNextSibling();
1192 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1193 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1198 /**add pcd information of module mi to a ModuleSA.
1200 * @param moduleSa if null, generate a new ModuleSA.
1202 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1203 //ToDo add Arch filter
1205 if (moduleSa
== null) {
1206 moduleSa
= genModuleSA(mi
, arch
);
1209 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1210 .getModuleXmlObject(mi
);
1211 if (msa
.getPcdCoded() == null) {
1215 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1217 // Implementing InitializePlatformPcdBuildDefinitions
1219 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1220 ListIterator li
= l
.listIterator();
1221 while (li
.hasNext()) {
1222 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1223 if (msaPcd
.getSupArchList() != null) {
1224 if (!msaPcd
.getSupArchList().toString().toLowerCase().contains(arch
.toLowerCase())) {
1228 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1229 if (spdPcd
== null) {
1233 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + "\n used by Module "
1234 + mi
.getName() + " or its Library Instances.");
1237 // AddItem to ModuleSA PcdBuildDefinitions
1239 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1241 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1243 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1248 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1250 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1251 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1253 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1257 for (int j
= 0; j
< xo
.length
; ++j
) {
1258 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1259 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1260 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1265 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1276 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1277 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1278 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1279 XmlCursor cursor
= msa
.newCursor();
1281 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1282 + mi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
1283 cursor
.insertComment(comment
);
1286 e
.printStackTrace();
1291 msa
.setModuleGuid(mi
.getGuid());
1292 msa
.setModuleVersion(mi
.getVersion());
1293 msa
.setPackageGuid(pi
.getGuid());
1294 msa
.setPackageVersion(pi
.getVersion());
1296 Vector
<String
> v
= new Vector
<String
>();
1298 msa
.setSupArchList(v
);
1304 private String
chooseDefaultPcdType (List validPcdTypes
) {
1305 String choosedType
= "";
1306 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1307 choosedType
= "FIXED_AT_BUILD";
1309 else if (validPcdTypes
.contains("DYNAMIC")) {
1310 choosedType
= "DYNAMIC";
1312 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1313 choosedType
= "PATCHABLE_IN_MODULE";
1315 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1316 choosedType
= "DYNAMIC_EX";
1321 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1322 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1323 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1324 if (moduleSa
.getPcdBuildDefinition() == null){
1325 moduleSa
.addNewPcdBuildDefinition();
1328 // constructe pcd to modulesa mapping first.
1329 // Attention : for any error condition, remove from map this pcd.
1331 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1332 if (pcdConsumer
== null) {
1333 pcdConsumer
= new ArrayList
<String
>();
1336 // Check whether this PCD has already added to ModuleSA, if so, just return.
1338 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1339 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1340 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1341 String pcdInfo
= pcdConsumer
.get(i
);
1342 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1346 // if pcd type from MSA file is Dynamic
1347 // we must choose one default type from SPD file for it.
1349 List validPcdTypes
= spdPcd
.getValidUsage();
1351 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1353 if (pcdConsumer
.size() > 0) {
1355 // platform should only contain one type for each pcd.
1357 String existingItemType
= itemType (pcdConsumer
.get(0));
1358 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1359 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1360 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1364 if (itemType
.equals("DYNAMIC")) {
1365 if (!validPcdTypes
.contains(existingItemType
)) {
1366 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1368 itemType
= existingItemType
;
1371 if (!itemType
.equals(existingItemType
)) {
1372 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1377 // if this is the first occurence of this pcd.
1380 if (itemType
.equals("DYNAMIC")) {
1381 itemType
= chooseDefaultPcdType (validPcdTypes
);
1384 String listValue
= moduleInfo
+ " " + itemType
;
1385 pcdConsumer
.add(listValue
);
1386 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1388 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1389 fpdPcd
.setCName(cName
);
1390 fpdPcd
.setToken(token
);
1391 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1392 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1393 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1395 if (defaultVal
!= null && defaultVal
.length() > 0){
1396 fpdPcd
.setValue(defaultVal
);
1399 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1400 fpdPcd
.setValue("0");
1402 if (dataType
.equals("BOOLEAN")){
1403 fpdPcd
.setValue("FALSE");
1405 if (dataType
.equals("VOID*")) {
1406 fpdPcd
.setValue("L\"\"");
1410 // Using existing pcd value, if this pcd already exists in other moduleSa.
1412 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1413 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1416 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1419 if (dataType
.equals("UINT8")){
1420 fpdPcd
.setMaxDatumSize(1);
1422 if (dataType
.equals("UINT16")) {
1423 fpdPcd
.setMaxDatumSize(2);
1425 if (dataType
.equals("UINT32")) {
1426 fpdPcd
.setMaxDatumSize(4);
1428 if (dataType
.equals("UINT64")){
1429 fpdPcd
.setMaxDatumSize(8);
1431 if (dataType
.equals("BOOLEAN")){
1432 fpdPcd
.setMaxDatumSize(1);
1434 if (dataType
.equals("VOID*")) {
1435 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1436 fpdPcd
.setMaxDatumSize(maxSize
);
1440 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1441 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1443 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1444 // so need to add one dyn pcd.
1446 if (al
.size() == 1) {
1447 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1453 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1454 if (datum
== null) {
1457 char ch
= datum
.charAt(0);
1461 // For void* type PCD, only three datum is support:
1462 // 1) Unicode: string with start char is "L"
1463 // 2) Ansci: String is ""
1464 // 3) byte array: String start char "{"
1467 start
= datum
.indexOf('\"');
1468 end
= datum
.lastIndexOf('\"');
1469 if ((start
> end
) ||
1470 (end
> datum
.length())||
1471 ((start
== end
) && (datum
.length() > 0))) {
1472 //ToDo Error handling here
1473 throw new PcdValueMalFormed (datum
);
1476 strValue
= datum
.substring(start
+ 1, end
);
1477 return strValue
.length() * 2;
1478 } else if (ch
== '\"'){
1479 start
= datum
.indexOf('\"');
1480 end
= datum
.lastIndexOf('\"');
1481 if ((start
> end
) ||
1482 (end
> datum
.length())||
1483 ((start
== end
) && (datum
.length() > 0))) {
1484 throw new PcdValueMalFormed (datum
);
1486 strValue
= datum
.substring(start
+ 1, end
);
1487 return strValue
.length();
1488 } else if (ch
=='{') {
1489 String
[] strValueArray
;
1491 start
= datum
.indexOf('{');
1492 end
= datum
.lastIndexOf('}');
1493 strValue
= datum
.substring(start
+ 1, end
);
1494 strValue
= strValue
.trim();
1495 if (strValue
.length() == 0) {
1498 strValueArray
= strValue
.split(",");
1499 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1500 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1503 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1504 // "it must be a byte array. But the element of %s exceed the byte range",
1505 throw new PcdValueMalFormed (datum
);
1508 return strValueArray
.length
;
1512 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1513 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1514 // "2) ANSIC string: like \"xxx\";\r\n"+
1515 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1516 // "but the datum in seems does not following above format!",
1517 throw new PcdValueMalFormed (datum
);
1522 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1523 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1528 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1530 return dynPcdMap
.get(pcdKey
);
1533 public int getDynamicPcdBuildDataCount() {
1534 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1535 removeElement(getfpdDynPcdBuildDefs());
1536 fpdDynPcdBuildDefs
= null;
1539 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1542 public void getDynamicPcdBuildData(String
[][] saa
) {
1543 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1544 removeElement(getfpdDynPcdBuildDefs());
1545 fpdDynPcdBuildDefs
= null;
1548 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1549 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1551 while(li
.hasNext()) {
1552 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1553 saa
[i
][0] = dynPcd
.getCName();
1554 saa
[i
][1] = dynPcd
.getToken().toString();
1555 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1556 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1557 saa
[i
][4] = dynPcd
.getDatumType()+"";
1563 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1564 throws PcdValueMalFormed
{
1565 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1566 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1567 dynPcdData
.setCName(cName
);
1568 dynPcdData
.setToken(token
);
1569 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1570 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1572 BigInteger bigInt
= new BigInteger("0");
1573 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1574 skuInfo
.setSkuId(bigInt
);
1575 if (defaultVal
!= null){
1576 skuInfo
.setValue(defaultVal
);
1579 if (dataType
.equals("UINT8")){
1580 skuInfo
.setValue("0");
1582 if (dataType
.equals("UINT16")) {
1583 skuInfo
.setValue("0");
1585 if (dataType
.equals("UINT32")) {
1586 skuInfo
.setValue("0");
1588 if (dataType
.equals("UINT64")){
1589 skuInfo
.setValue("0");
1591 if (dataType
.equals("BOOLEAN")){
1592 skuInfo
.setValue("false");
1594 if (dataType
.equals("VOID*")) {
1595 skuInfo
.setValue("");
1598 if (dataType
.equals("UINT8")){
1599 dynPcdData
.setMaxDatumSize(1);
1601 if (dataType
.equals("UINT16")) {
1602 dynPcdData
.setMaxDatumSize(2);
1604 if (dataType
.equals("UINT32")) {
1605 dynPcdData
.setMaxDatumSize(4);
1607 if (dataType
.equals("UINT64")){
1608 dynPcdData
.setMaxDatumSize(8);
1610 if (dataType
.equals("BOOLEAN")){
1611 dynPcdData
.setMaxDatumSize(1);
1613 if (dataType
.equals("VOID*")) {
1614 int maxSize
= setMaxSizeForPointer(defaultVal
);
1615 dynPcdData
.setMaxDatumSize(maxSize
);
1619 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1620 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1625 XmlCursor cursor
= o
.newCursor();
1626 if (cursor
.toFirstChild()) {
1628 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1629 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1630 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1632 if (getDynamicPcdBuildDataCount() == 1) {
1635 fpdDynPcdBuildDefs
= null;
1643 while (cursor
.toNextSibling());
1648 // Get the Sku Info count of ith dyn pcd element.
1650 public int getDynamicPcdSkuInfoCount(int i
){
1651 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1652 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1653 removeElement(getfpdDynPcdBuildDefs());
1654 fpdDynPcdBuildDefs
= null;
1658 int skuInfoCount
= 0;
1659 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1660 if (cursor
.toFirstChild()) {
1661 for (int j
= 0; j
< i
; ++j
) {
1662 cursor
.toNextSibling();
1664 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1665 if (pcdData
.getSkuInfoList() == null) {
1669 skuInfoCount
= pcdData
.getSkuInfoList().size();
1673 return skuInfoCount
;
1676 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1677 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1678 removeElement(getfpdDynPcdBuildDefs());
1679 fpdDynPcdBuildDefs
= null;
1683 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1684 if (cursor
.toFirstChild()) {
1685 for (int j
= 0; j
< i
; ++j
) {
1686 cursor
.toNextSibling();
1688 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1689 if (pcdData
.getSkuInfoList() == null) {
1694 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1696 while (li
.hasNext()) {
1697 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1698 saa
[k
][0] = skuInfo
.getSkuId()+"";
1699 saa
[k
][1] = skuInfo
.getVariableName();
1700 saa
[k
][2] = skuInfo
.getVariableGuid();
1701 saa
[k
][3] = skuInfo
.getVariableOffset();
1702 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1703 saa
[k
][5] = skuInfo
.getVpdOffset();
1704 saa
[k
][6] = skuInfo
.getValue();
1714 public String
getDynamicPcdBuildDataValue(int i
){
1715 String value
= null;
1716 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1717 removeElement(getfpdDynPcdBuildDefs());
1718 fpdDynPcdBuildDefs
= null;
1722 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1723 if (cursor
.toFirstChild()) {
1724 for (int j
= 0; j
< i
; ++j
) {
1725 cursor
.toNextSibling();
1727 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1728 if (pcdData
.getSkuInfoList() == null) {
1732 value
= pcdData
.getSkuInfoArray(0).getValue();
1739 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1740 String vpdOffset
= null;
1741 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1742 removeElement(getfpdDynPcdBuildDefs());
1743 fpdDynPcdBuildDefs
= null;
1747 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1748 if (cursor
.toFirstChild()) {
1749 for (int j
= 0; j
< i
; ++j
) {
1750 cursor
.toNextSibling();
1752 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1753 if (pcdData
.getSkuInfoList() == null) {
1757 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1764 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1765 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1766 removeElement(getfpdDynPcdBuildDefs());
1767 fpdDynPcdBuildDefs
= null;
1771 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1772 if (cursor
.toFirstChild()) {
1773 for (int j
= 0; j
< i
; ++j
) {
1774 cursor
.toNextSibling();
1776 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1777 if (pcdData
.getSkuInfoList() == null) {
1782 pcdData
.getSkuInfoList().clear();
1783 // QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1784 // cursor.toChild(qSkuInfo);
1785 // cursor.removeXml();
1791 // generate sku info for ith dyn pcd build data.
1793 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1794 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1795 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1799 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1800 if (cursor
.toFirstChild()) {
1801 for (int j
= 0; j
< i
; ++j
) {
1802 cursor
.toNextSibling();
1804 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1805 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1806 skuInfo
.setSkuId(new BigInteger(id
));
1807 if (varName
!= null){
1808 skuInfo
.setVariableName(varName
);
1809 skuInfo
.setVariableGuid(varGuid
);
1810 skuInfo
.setVariableOffset(varOffset
);
1811 skuInfo
.setHiiDefaultValue(hiiDefault
);
1813 else if (vpdOffset
!= null){
1814 skuInfo
.setVpdOffset(vpdOffset
);
1817 skuInfo
.setValue(value
);
1822 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1823 String hiiDefault
, String vpdOffset
, String value
, int i
){
1824 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1825 removeElement(getfpdDynPcdBuildDefs());
1826 fpdDynPcdBuildDefs
= null;
1830 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1831 if (cursor
.toFirstChild()) {
1832 for (int j
= 0; j
< i
; ++j
) {
1833 cursor
.toNextSibling();
1835 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1836 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1837 while (li
.hasNext()) {
1838 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1839 if (skuInfo
.getSkuId().toString().equals(id
)){
1840 if (varName
!= null){
1841 skuInfo
.setVariableName(varName
);
1842 skuInfo
.setVariableGuid(varGuid
);
1843 skuInfo
.setVariableOffset(varOffset
);
1844 skuInfo
.setHiiDefaultValue(hiiDefault
);
1846 else if (vpdOffset
!= null){
1847 skuInfo
.setVpdOffset(vpdOffset
);
1850 skuInfo
.setValue(value
);
1858 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1859 if (fpdBuildOpts
== null) {
1860 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1862 return fpdBuildOpts
;
1865 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1866 QName elementFvName
= new QName (xmlNs
, "FvName");
1867 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1868 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1869 QName elementModule
= new QName(xmlNs
, "Module");
1871 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1872 userExts
.setUserID(userId
);
1873 userExts
.setIdentifier(id
);
1874 XmlCursor cursor
= userExts
.newCursor();
1875 cursor
.toEndToken();
1877 cursor
.beginElement(elementFvName
);
1878 cursor
.insertChars(fvName
);
1879 cursor
.toNextToken();
1881 cursor
.beginElement(elementInfFileName
);
1882 cursor
.insertChars(outputFileName
);
1883 cursor
.toNextToken();
1885 cursor
.beginElement(elementIncludeModules
);
1886 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1887 cursor
.beginElement(elementModule
);
1888 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1889 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1890 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1892 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1893 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1894 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1897 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1898 cursor
.toEndToken();
1899 cursor
.toNextToken();
1904 public int getUserExtsIncModCount (String fvName
, String userId
, String id
) {
1905 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1909 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1910 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1911 while (li
.hasNext()) {
1912 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1913 if (!ues
.getUserID().equals(userId
)) {
1916 if (ues
.getIdentifier() == null || !ues
.getIdentifier().equals(id
)) {
1919 XmlCursor cursor
= ues
.newCursor();
1920 cursor
.toFirstChild();
1921 String elementName
= cursor
.getTextValue();
1922 if (elementName
.equals(fvName
)) {
1923 cursor
.toNextSibling(elementIncludeModules
);
1924 if (cursor
.toFirstChild()) {
1926 for (i
= 1; cursor
.toNextSibling(); ++i
);
1938 public void getUserExtsIncMods(String fvName
, String userId
, String id
, String
[][] saa
) {
1939 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1943 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1944 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1945 QName attribUserId
= new QName ("UserID");
1946 QName attribId
= new QName ("Identifier");
1947 QName elementFvName
= new QName (xmlNs
, "FvName");
1948 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1949 QName attribModuleGuid
= new QName("ModuleGuid");
1950 QName attribModuleVersion
= new QName("ModuleVersion");
1951 QName attribPackageGuid
= new QName("PackageGuid");
1952 QName attribPackageVersion
= new QName("PackageVersion");
1953 QName attribArch
= new QName("Arch");
1955 if (cursor
.toChild(elementUserExts
)) {
1958 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
1959 cursor
.toChild(elementFvName
);
1960 String elementName
= cursor
.getTextValue();
1961 if (elementName
.equals(fvName
)) {
1962 cursor
.toNextSibling(elementIncludeModules
);
1963 if (cursor
.toFirstChild()) {
1966 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1967 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1968 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1969 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1970 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1972 }while (cursor
.toNextSibling());
1978 }while (cursor
.toNextSibling(elementUserExts
));
1984 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1985 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1988 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1989 while (li
.hasNext()) {
1990 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1991 if (!ues
.getUserID().equals("IMAGES")) {
1994 XmlCursor cursor
= ues
.newCursor();
1995 cursor
.toFirstChild();
1996 String elementName
= cursor
.getTextValue();
1997 if (elementName
.equals(oldFvName
)) {
1998 cursor
.setTextValue(newFvName
);
2005 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, String id
) {
2006 if (getfpdBuildOpts().getUserExtensionsList() == null) {
2010 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2011 while (li
.hasNext()) {
2012 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2013 if (!ues
.getUserID().equals(userId
)) {
2016 if (ues
.getIdentifier()== null || !ues
.getIdentifier().equals(id
)) {
2019 XmlCursor cursor
= ues
.newCursor();
2020 cursor
.toFirstChild();
2021 String elementName
= cursor
.getTextValue();
2022 if (elementName
.equals(fvName
)) {
2033 private boolean versionEqual (String v1
, String v2
) {
2035 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
2036 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
2040 if (v1
!= null && v1
.equals(v2
)) {
2047 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2048 boolean inList
= false;
2049 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
2050 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2051 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2052 QName attribUserId
= new QName ("UserID");
2053 QName attribId
= new QName ("Identifier");
2054 QName elementFvName
= new QName (xmlNs
, "FvName");
2055 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2056 QName attribModuleGuid
= new QName("ModuleGuid");
2057 QName attribModuleVersion
= new QName("ModuleVersion");
2058 QName attribPackageGuid
= new QName("PackageGuid");
2059 QName attribPackageVersion
= new QName("PackageVersion");
2060 QName attribArch
= new QName("Arch");
2062 if (cursor
.toChild(elementUserExts
)) {
2065 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
2066 cursor
.toChild(elementFvName
);
2067 String elementName
= cursor
.getTextValue();
2068 if (elementName
.equals(fvName
)) {
2069 cursor
.toNextSibling(elementIncludeModules
);
2070 if (cursor
.toFirstChild()) {
2073 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2074 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2075 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2076 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2077 String ar
= cursor
.getAttributeText(attribArch
);
2078 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2081 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2084 if (!arch
.equalsIgnoreCase(ar
)) {
2087 if (!versionEqual(moduleVersion
, mv
)) {
2090 if (!versionEqual(packageVersion
, pv
)) {
2095 }while (cursor
.toNextSibling());
2101 }while (cursor
.toNextSibling(elementUserExts
));
2108 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2110 // if there is only one module before remove operation, the whole user extension should be removed.
2112 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2113 if (moduleAmount
== 1) {
2114 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2118 if (moduleAmount
> 1) {
2119 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2120 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2121 QName attribUserId
= new QName ("UserID");
2122 QName attribId
= new QName ("Identifier");
2123 QName elementFvName
= new QName (xmlNs
, "FvName");
2124 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2125 QName attribModuleGuid
= new QName("ModuleGuid");
2126 QName attribModuleVersion
= new QName("ModuleVersion");
2127 QName attribPackageGuid
= new QName("PackageGuid");
2128 QName attribPackageVersion
= new QName("PackageVersion");
2129 QName attribArch
= new QName("Arch");
2131 if (cursor
.toChild(elementUserExts
)) {
2134 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
2135 cursor
.toChild(elementFvName
);
2136 String elementName
= cursor
.getTextValue();
2137 if (elementName
.equals(fvName
)) {
2138 cursor
.toNextSibling(elementIncludeModules
);
2139 if (cursor
.toFirstChild()) {
2142 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2143 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2144 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2145 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2146 String ar
= cursor
.getAttributeText(attribArch
);
2147 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2150 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2153 if (!arch
.equalsIgnoreCase(ar
)) {
2156 if (!versionEqual(moduleVersion
, mv
)) {
2159 if (!versionEqual(packageVersion
, pv
)) {
2163 }while (cursor
.toNextSibling());
2169 }while (cursor
.toNextSibling(elementUserExts
));
2175 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2176 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2180 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2181 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2182 QName elementModule
= new QName(xmlNs
, "Module");
2183 while (li
.hasNext()) {
2184 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2185 if (!ues
.getUserID().equals(userId
)) {
2188 if (ues
.getIdentifier() == null || !ues
.getIdentifier().equals(id
)) {
2191 XmlCursor cursor
= ues
.newCursor();
2192 cursor
.toFirstChild();
2193 String elementName
= cursor
.getTextValue();
2194 if (elementName
.equals(fvName
)) {
2195 cursor
.toNextSibling(elementIncludeModules
);
2196 cursor
.toLastChild();
2197 cursor
.toEndToken();
2198 cursor
.toNextToken();
2199 cursor
.beginElement(elementModule
);
2200 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2201 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2202 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2204 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2205 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2206 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2209 cursor
.insertAttributeWithValue("Arch", arch
);
2218 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2219 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2220 if (udats
== null) {
2221 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2224 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2225 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2228 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2229 at
.setId(new Integer(id
));
2230 XmlCursor cursor
= at
.newCursor();
2231 if (fileName
!= null){
2232 at
.setFilename(fileName
);
2234 else if (cursor
.toChild(xmlNs
, "Filename")) {
2237 if (execOrder
!= null) {
2238 at
.setAntCmdOptions(execOrder
);
2240 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2246 public void removeBuildOptionsUserDefAntTask(int i
) {
2247 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2251 XmlCursor cursor
= o
.newCursor();
2252 if (cursor
.toFirstChild()) {
2253 for (int j
= 0; j
< i
; ++j
) {
2254 cursor
.toNextSibling();
2257 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2265 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2266 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2270 XmlCursor cursor
= o
.newCursor();
2271 if (cursor
.toFirstChild()) {
2272 for (int j
= 0; j
< i
; ++j
) {
2273 cursor
.toNextSibling();
2275 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2276 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2281 public int getBuildOptionsUserDefAntTaskCount() {
2282 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2283 if (udats
== null || udats
.getAntTaskList() == null) {
2287 return udats
.getAntTaskList().size();
2290 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2291 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2292 if (udats
== null || udats
.getAntTaskList() == null) {
2296 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2297 ListIterator li
= l
.listIterator();
2299 while (li
.hasNext()) {
2300 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2301 saa
[i
][0] = at
.getId() + "";
2302 saa
[i
][1] = saa
[i
][2] = "";
2303 if (at
.getFilename() != null){
2304 saa
[i
][1] = at
.getFilename();
2306 if (at
.getAntCmdOptions() != null) {
2307 saa
[i
][2] = at
.getAntCmdOptions();
2312 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2313 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2315 opts
= getfpdBuildOpts().addNewOptions();
2317 OptionDocument
.Option opt
= opts
.addNewOption();
2318 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2321 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2322 opt
.setStringValue(contents
);
2323 if (buildTargets
!= null) {
2324 opt
.setBuildTargets(buildTargets
);
2327 if (opt
.isSetBuildTargets()) {
2328 opt
.unsetBuildTargets();
2332 if (toolChain
!= null && toolChain
.length() > 0) {
2333 opt
.setToolChainFamily(toolChain
);
2336 if (opt
.isSetToolChainFamily()) {
2337 opt
.unsetToolChainFamily();
2341 if (tagName
!= null && tagName
.length() > 0) {
2342 opt
.setTagName(tagName
);
2345 if (opt
.isSetTagName()) {
2350 if (toolCmd
!= null && toolCmd
.length() > 0) {
2351 opt
.setToolCode(toolCmd
);
2354 if (opt
.isSetToolCode()) {
2355 opt
.unsetToolCode();
2360 if (archList
!= null) {
2361 opt
.setSupArchList(archList
);
2364 if (opt
.isSetSupArchList()) {
2365 opt
.unsetSupArchList();
2370 public void removeBuildOptionsOpt(int i
){
2372 XmlObject o
= getfpdBuildOpts().getOptions();
2377 XmlCursor cursor
= o
.newCursor();
2378 if (cursor
.toFirstChild()) {
2379 for (int j
= 0; j
< i
; ++j
) {
2380 cursor
.toNextSibling();
2383 if (getBuildOptionsOptCount() == 0) {
2391 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2392 XmlObject o
= getfpdBuildOpts().getOptions();
2397 XmlCursor cursor
= o
.newCursor();
2398 if (cursor
.toFirstChild()) {
2399 for (int j
= 0; j
< i
; ++j
) {
2400 cursor
.toNextSibling();
2402 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2403 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2408 public int getBuildOptionsOptCount(){
2409 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2412 return getfpdBuildOpts().getOptions().getOptionList().size();
2415 public void getBuildOptionsOpts(String
[][] saa
) {
2416 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2420 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2421 ListIterator li
= lOpt
.listIterator();
2423 while(li
.hasNext()) {
2424 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2425 if (opt
.getBuildTargets() != null) {
2426 saa
[i
][0] = listToString(opt
.getBuildTargets());
2428 saa
[i
][1] = opt
.getToolChainFamily();
2429 if (opt
.getSupArchList() != null){
2430 saa
[i
][2] = listToString(opt
.getSupArchList());
2433 saa
[i
][3] = opt
.getToolCode();
2434 saa
[i
][4] = opt
.getTagName();
2435 saa
[i
][5] = opt
.getStringValue();
2441 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2442 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2443 ffs
.setFfsKey(ffsKey
);
2445 ffs
.addNewSections().setEncapsulationType(type
);
2449 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2450 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2451 ffs
.getSections().setEncapsulationType(type
);
2454 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2455 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2456 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2457 attrib
.setName(name
);
2458 attrib
.setValue(value
);
2461 /**update jth attribute of ith ffs.
2465 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2466 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2467 XmlCursor cursor
= ffs
.newCursor();
2468 QName qAttrib
= new QName(xmlNs
, "Attribute");
2469 if (cursor
.toChild(qAttrib
)) {
2470 for (int k
= 0; k
< j
; ++k
) {
2471 cursor
.toNextSibling(qAttrib
);
2473 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2474 attrib
.setName(name
);
2475 attrib
.setValue(value
);
2480 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2481 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2482 XmlCursor cursor
= ffs
.newCursor();
2483 QName qAttrib
= new QName(xmlNs
, "Attribute");
2484 if (cursor
.toChild(qAttrib
)) {
2485 for (int k
= 0; k
< j
; ++k
) {
2486 cursor
.toNextSibling(qAttrib
);
2493 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2494 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2498 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2500 if (sections
== null){
2501 sections
= ffs
.addNewSections();
2503 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2506 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2507 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2508 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2509 if (sections
== null) {
2512 XmlCursor cursor
= sections
.newCursor();
2513 QName qSection
= new QName(xmlNs
, "Section");
2514 if (cursor
.toChild(qSection
)) {
2515 for (int k
= 0; k
< j
; ++k
) {
2516 cursor
.toNextSibling(qSection
);
2523 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2524 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2525 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2526 if (sections
== null) {
2529 XmlCursor cursor
= sections
.newCursor();
2530 QName qSection
= new QName(xmlNs
, "Section");
2531 if (cursor
.toChild(qSection
)) {
2532 for (int k
= 0; k
< j
; ++k
) {
2533 cursor
.toNextSibling(qSection
);
2535 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2536 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2541 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2542 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2546 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2548 if (sections
== null){
2549 sections
= ffs
.addNewSections();
2551 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2552 sections2
.setEncapsulationType(encapType
);
2553 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2556 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2557 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2558 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2559 if (sections
== null) {
2562 XmlCursor cursor
= sections
.newCursor();
2563 QName qSections
= new QName(xmlNs
, "Sections");
2564 if (cursor
.toChild(qSections
)) {
2565 for (int k
= 0; k
< j
; ++k
) {
2566 cursor
.toNextSibling(qSections
);
2573 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2574 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2575 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2576 if (sections
== null) {
2579 XmlCursor cursor
= sections
.newCursor();
2580 QName qSections
= new QName(xmlNs
, "Sections");
2581 if (cursor
.toChild(qSections
)) {
2582 for (int k
= 0; k
< j
; ++k
) {
2583 cursor
.toNextSibling(qSections
);
2585 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2586 sections2
.setEncapsulationType(type
);
2591 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2592 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2596 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2597 XmlCursor cursor
= sections
.newCursor();
2598 QName qSections
= new QName(xmlNs
, "Sections");
2599 if (cursor
.toChild(qSections
)){
2600 for (int k
= 0; k
< j
; ++k
) {
2601 cursor
.toNextSibling(qSections
);
2603 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2604 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2609 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2610 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2611 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2612 if (sections
== null) {
2615 XmlCursor cursor
= sections
.newCursor();
2616 QName qSections
= new QName(xmlNs
, "Sections");
2617 if (cursor
.toChild(qSections
)) {
2618 for (int l
= 0; l
< j
; ++l
) {
2619 cursor
.toNextSibling(qSections
);
2621 if (cursor
.toFirstChild()) {
2623 for (; m
< k
; ++m
) {
2624 cursor
.toNextSibling();
2636 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2637 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2638 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2639 if (sections
== null) {
2642 XmlCursor cursor
= sections
.newCursor();
2643 QName qSections
= new QName(xmlNs
, "Sections");
2644 if (cursor
.toChild(qSections
)) {
2645 for (int l
= 0; l
< j
; ++l
) {
2646 cursor
.toNextSibling(qSections
);
2648 if (cursor
.toFirstChild()) {
2649 for (int m
= 0; m
< k
; ++m
) {
2650 cursor
.toNextSibling();
2652 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2653 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2659 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2660 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2664 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2665 XmlCursor cursor
= sections
.newCursor();
2666 QName qSections
= new QName(xmlNs
, "Sections");
2667 if (cursor
.toChild(qSections
)){
2668 for (int k
= 0; k
< j
; ++k
) {
2669 cursor
.toNextSibling(qSections
);
2671 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2672 if (sections2
.getSectionList() == null){
2676 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2677 while(li
.hasNext()) {
2678 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2679 // if (section.isSetSectionType()) {
2680 al
.add(section
.getSectionType()+"");
2689 public int getBuildOptionsFfsCount(){
2690 if (getfpdBuildOpts().getFfsList() == null) {
2693 return getfpdBuildOpts().getFfsList().size();
2696 public void getBuildOptionsFfsKey(String
[][] saa
) {
2697 if (getfpdBuildOpts().getFfsList() == null) {
2700 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2702 while(li
.hasNext()){
2703 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2704 saa
[i
][0] = ffs
.getFfsKey();
2709 public void updateBuildOptionsFfsKey(int i
, String key
) {
2710 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2714 /**Get ith FFS key and contents.
2717 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2718 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2722 sa
[0] = ffs
.getFfsKey();
2723 if (ffs
.getSections() != null) {
2724 if(ffs
.getSections().getEncapsulationType() != null){
2725 sa
[1] = ffs
.getSections().getEncapsulationType();
2727 if (ffs
.getSections().getSectionList() != null){
2728 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2729 while (li
.hasNext()) {
2730 firstLevelSection
.add(li
.next().getSectionType()+"");
2733 if (ffs
.getSections().getSectionsList() != null) {
2734 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2735 while(li
.hasNext()) {
2736 firstLevelSections
.add(li
.next().getEncapsulationType());
2740 if (ffs
.getAttributeList() != null) {
2741 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2742 while(li
.hasNext()) {
2743 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2744 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2753 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2754 XmlObject o
= getfpdBuildOpts();
2755 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2757 XmlCursor cursor
= o
.newCursor();
2758 QName qFfs
= new QName(xmlNs
, "Ffs");
2759 if (cursor
.toChild(qFfs
)) {
2760 for (int j
= 0; j
< i
; ++j
) {
2761 cursor
.toNextSibling(qFfs
);
2763 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2769 public void removeBuildOptionsFfs(int i
) {
2770 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2775 XmlCursor cursor
= ffs
.newCursor();
2782 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2783 if (fpdPlatformDefs
== null){
2784 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2786 return fpdPlatformDefs
;
2789 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2790 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2793 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2794 while(li
.hasNext()) {
2795 archs
.add(li
.next());
2799 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2800 if (archs
!= null) {
2801 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2804 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2805 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2806 // cursor.removeXml();
2808 // cursor.dispose();
2812 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2813 if (getfpdPlatformDefs().getBuildTargets() == null) {
2816 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2817 while(li
.hasNext()) {
2818 targets
.add(li
.next());
2822 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2823 getfpdPlatformDefs().setBuildTargets(targets
);
2826 public void genPlatformDefsSkuInfo(String id
, String name
) {
2827 SkuInfoDocument
.SkuInfo skuInfo
= null;
2828 if (getfpdPlatformDefs().getSkuInfo() == null) {
2829 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2831 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2832 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2833 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2834 skuName
.setSkuID(new BigInteger("0"));
2835 skuName
.setStringValue("DEFAULT");
2837 if (id
.equals("0")) {
2840 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2841 skuName
.setSkuID(new BigInteger(id
));
2842 skuName
.setStringValue(name
);
2845 public int getPlatformDefsSkuInfoCount(){
2846 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2849 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2852 public void getPlatformDefsSkuInfos(String
[][] saa
){
2853 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2854 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2855 removeElement(getfpdDynPcdBuildDefs());
2856 fpdDynPcdBuildDefs
= null;
2861 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2862 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2864 while(li
.hasNext()) {
2865 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2866 saa
[i
][0] = sku
.getSkuID()+"";
2867 saa
[i
][1] = sku
.getStringValue();
2872 public void removePlatformDefsSkuInfo(int i
) {
2873 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2874 if (skuInfo
== null || i
== 0) {
2878 XmlCursor cursor
= skuInfo
.newCursor();
2879 if (cursor
.toFirstChild()) {
2880 for (int j
= 0; j
< i
; ++j
) {
2881 cursor
.toNextSibling();
2888 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2889 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2890 if (skuInfo
== null || i
== 0) {
2894 XmlCursor cursor
= skuInfo
.newCursor();
2895 if (cursor
.toFirstChild()) {
2896 for (int j
= 0; j
< i
; ++j
) {
2897 cursor
.toNextSibling();
2899 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2900 sku
.setSkuID(new BigInteger(id
));
2901 sku
.setStringValue(name
);
2906 public String
getPlatformDefsInterDir(){
2907 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2910 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2913 public void setPlatformDefsInterDir(String interDir
){
2914 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2917 public String
getPlatformDefsOutputDir() {
2918 return getfpdPlatformDefs().getOutputDirectory();
2921 public void setPlatformDefsOutputDir(String outputDir
) {
2922 if (outputDir
!= null && outputDir
.length() > 0) {
2923 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2926 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2927 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2934 public FlashDocument
.Flash
getfpdFlash() {
2935 if (fpdFlash
== null) {
2936 fpdFlash
= fpdRoot
.addNewFlash();
2941 public void genFlashDefinitionFile(String file
) {
2942 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2944 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2947 fdf
.setStringValue(file
);
2950 public String
getFlashDefinitionFile() {
2951 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2956 return fdf
.getStringValue();
2959 public void genFvImagesNameValue(String name
, String value
) {
2961 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2963 fi
= getfpdFlash().addNewFvImages();
2966 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2971 public void removeFvImagesNameValue(int i
){
2973 XmlObject o
= getfpdFlash().getFvImages();
2978 QName qNameValue
= new QName(xmlNs
, "NameValue");
2979 XmlCursor cursor
= o
.newCursor();
2980 if (cursor
.toChild(qNameValue
)) {
2981 for (int j
= 0; j
< i
; ++j
) {
2982 cursor
.toNextSibling(qNameValue
);
2989 public void updateFvImagesNameValue(int i
, String name
, String value
){
2991 XmlObject o
= getfpdFlash().getFvImages();
2996 QName qNameValue
= new QName(xmlNs
, "NameValue");
2997 XmlCursor cursor
= o
.newCursor();
2998 if (cursor
.toChild(qNameValue
)) {
2999 for (int j
= 0; j
< i
; ++j
) {
3000 cursor
.toNextSibling(qNameValue
);
3002 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
3009 public int getFvImagesNameValueCount() {
3011 FvImagesDocument
.FvImages fi
= null;
3012 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
3015 return fi
.getNameValueList().size();
3018 public void getFvImagesNameValues(String
[][] nv
) {
3020 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
3024 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
3026 ListIterator li
= l
.listIterator();
3027 while (li
.hasNext()) {
3028 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
3030 nv
[i
][0] = e
.getName();
3031 nv
[i
][1] = e
.getValue();
3037 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
3038 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3039 if (fis
== null || fis
.getFvImageList() == null) {
3043 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3044 while (li
.hasNext()) {
3045 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3046 if (fi
.getType().toString().equals("ImageName")) {
3047 vImageNames
.addAll(fi
.getFvImageNamesList());
3053 public void addFvImageFvImageNames (String
[] fvNames
) {
3054 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3055 if (fis
== null || fis
.getFvImageList() == null) {
3056 genFvImagesFvImage (fvNames
, "ImageName", null);
3060 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3061 while (li
.hasNext()) {
3062 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3063 if (fi
.getType().toString().equals("ImageName")) {
3064 addFvImageNamesInFvImage (fi
, fvNames
);
3068 genFvImagesFvImage (fvNames
, "ImageName", null);
3071 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3073 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3074 fi
.addFvImageNames(fvNames
[i
]);
3078 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3079 XmlObject o
= getfpdFlash().getFvImages();
3083 XmlCursor cursor
= o
.newCursor();
3084 QName qFvImage
= new QName(xmlNs
, "FvImage");
3085 if (cursor
.toChild(qFvImage
)) {
3086 for (int j
= 0; j
< i
; ++j
) {
3087 cursor
.toNextSibling(qFvImage
);
3089 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3090 addFvImageNamesInFvImage(fi
, fvNames
);
3095 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3097 FvImagesDocument
.FvImages fis
= null;
3098 if ((fis
= getfpdFlash().getFvImages()) == null) {
3099 fis
= getfpdFlash().addNewFvImages();
3103 //gen FvImage with FvImageNames array
3105 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3106 for (int i
= 0; i
< names
.length
; ++i
) {
3107 fi
.addFvImageNames(names
[i
]);
3109 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3110 if (options
!= null){
3111 setFvImagesFvImageFvImageOptions(options
, fi
);
3115 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3116 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3118 fio
= fi
.addNewFvImageOptions();
3121 Set
<String
> key
= options
.keySet();
3122 Iterator
<String
> i
= key
.iterator();
3123 while (i
.hasNext()) {
3125 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3126 String k
= (String
)i
.next();
3129 nv
.setValue((String
)options
.get(k
));
3136 public void removeFvImagesFvImage(int i
) {
3138 XmlObject o
= getfpdFlash().getFvImages();
3143 QName qFvImage
= new QName(xmlNs
, "FvImage");
3144 XmlCursor cursor
= o
.newCursor();
3145 if (cursor
.toChild(qFvImage
)) {
3146 for (int j
= 0; j
< i
; ++j
) {
3147 cursor
.toNextSibling(qFvImage
);
3156 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3158 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3159 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3162 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3163 while (li
.hasNext()) {
3164 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3165 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3166 if (fi
.getFvImageNamesList().size() == 0) {
3172 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3173 XmlObject o
= getfpdFlash().getFvImages();
3177 XmlCursor cursor
= o
.newCursor();
3178 QName qFvImage
= new QName(xmlNs
, "FvImage");
3179 if (cursor
.toChild(qFvImage
)) {
3180 for (int j
= 0; j
< i
; ++j
) {
3181 cursor
.toNextSibling(qFvImage
);
3183 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3184 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3190 * @param oldFvName The FV Name to be replaced.
3191 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3193 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3194 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3195 XmlCursor cursor
= fi
.newCursor();
3197 if (cursor
.toChild(qFvImageNames
)) {
3199 String xmlValue
= cursor
.getTextValue();
3200 if (xmlValue
.equals(oldFvName
)){
3201 if (newFvName
!= null) {
3202 cursor
.setTextValue(newFvName
);
3208 }while (cursor
.toNextSibling(qFvImageNames
));
3214 /**update the Type attribute of ith FvImage with new type.
3218 public void updateFvImagesFvImageType (int i
, String type
) {
3219 XmlObject o
= getfpdFlash().getFvImages();
3223 XmlCursor cursor
= o
.newCursor();
3224 QName qFvImage
= new QName(xmlNs
, "FvImage");
3225 if (cursor
.toChild(qFvImage
)) {
3226 for (int j
= 0; j
< i
; ++j
) {
3227 cursor
.toNextSibling(qFvImage
);
3229 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3230 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3235 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3237 XmlObject o
= getfpdFlash().getFvImages();
3241 XmlCursor cursor
= o
.newCursor();
3242 QName qFvImage
= new QName(xmlNs
, "FvImage");
3243 if (cursor
.toChild(qFvImage
)) {
3244 for (int j
= 0; j
< i
; ++j
) {
3245 cursor
.toNextSibling(qFvImage
);
3247 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3248 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3251 // remove old FvImageNames before adding new ones
3253 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3254 cursor
.toChild(qFvImageNames
);
3256 while (cursor
.toNextSibling(qFvImageNames
)) {
3260 for (int k
= 0; k
< names
.length
; ++k
) {
3261 fi
.addFvImageNames(names
[k
]);
3264 // remove old FvImageOptions before adding new options
3266 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3267 cursor
.toNextSibling(qFvImageOptions
);
3270 setFvImagesFvImageFvImageOptions(options
, fi
);
3275 public int getFvImagesFvImageCount(String type
) {
3277 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3280 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3281 ListIterator li
= l
.listIterator();
3283 while(li
.hasNext()) {
3284 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3285 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3295 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3296 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3297 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3300 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3301 ListIterator li
= l
.listIterator();
3302 while(li
.hasNext()) {
3303 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3304 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3307 if (fi
.getFvImageNamesList().contains(fvName
)) {
3316 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3318 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3320 if (getfpdFlash().getFvImages() == null) {
3323 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3327 ListIterator li
= l
.listIterator();
3329 while(li
.hasNext()) {
3330 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3331 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3335 // get FvImageNames array, space separated
3337 List
<String
> lfn
= fi
.getFvImageNamesList();
3338 ListIterator lfni
= lfn
.listIterator();
3340 while (lfni
.hasNext()) {
3341 saa
[i
][0] += (String
)lfni
.next();
3344 saa
[i
][0] = saa
[i
][0].trim();
3346 saa
[i
][1] = fi
.getType()+"";
3352 public void removeFvImageNameValue (int i
, String attributeName
) {
3353 XmlObject o
= getfpdFlash().getFvImages();
3357 XmlCursor cursor
= o
.newCursor();
3358 QName qFvImage
= new QName(xmlNs
, "FvImage");
3359 if (cursor
.toChild(qFvImage
)) {
3360 for (int j
= 0; j
< i
; ++j
) {
3361 cursor
.toNextSibling(qFvImage
);
3363 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3364 removeFvImageNameValue (fi
, attributeName
);
3368 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3370 * @param attributeName
3372 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3373 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3374 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3375 while (li
.hasNext()) {
3376 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3377 if (nv
.getName().equals(attributeName
)) {
3384 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3385 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3386 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3387 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3388 removeFvImageNameValue (fi
, optName
);
3392 /**Add name-value pair to FvImage element with type.
3393 * @param fvName FV name to add name-value pair.
3394 * @param type FvImage attribute.
3398 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3399 boolean fvImageExists
= false;
3400 if (getfpdFlash().getFvImages() != null) {
3402 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3404 ListIterator li
= l
.listIterator();
3405 while (li
.hasNext()) {
3406 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3407 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3410 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3413 fvImageExists
= true;
3414 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3419 if (!fvImageExists
) {
3420 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3421 map
.put(name
, value
);
3422 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3426 /**Add to all FvImage elements with type, the name-value pair.
3431 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3432 if (getfpdFlash().getFvImages() == null) {
3435 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3439 ListIterator li
= l
.listIterator();
3440 while(li
.hasNext()) {
3441 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3442 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3445 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3450 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3451 XmlObject o
= getfpdFlash().getFvImages();
3455 XmlCursor cursor
= o
.newCursor();
3456 QName qFvImage
= new QName(xmlNs
, "FvImage");
3457 if (cursor
.toChild(qFvImage
)) {
3458 for (int j
= 0; j
< i
; ++j
) {
3459 cursor
.toNextSibling(qFvImage
);
3461 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3462 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3467 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3473 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3474 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3475 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3478 if (newName
!= null && !newName
.equals(name
)) {
3479 nv
.setName(newName
);
3484 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3485 if (cursor
.toFirstChild()) {
3487 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3488 if (nv
.getName().equals(name
)) {
3490 if (newName
!= null && !newName
.equals(name
)) {
3491 nv
.setName(newName
);
3496 }while (cursor
.toNextSibling());
3499 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3502 if (newName
!= null && !newName
.equals(name
)) {
3503 nv
.setName(newName
);
3508 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3509 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3510 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3511 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3512 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3516 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3519 while (li
.hasNext()) {
3520 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3521 m
.put(nv
.getName(), nv
.getValue());
3526 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3527 XmlObject o
= getfpdFlash().getFvImages();
3533 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3534 Vector
<String
> vFvNames
= new Vector
<String
>();
3537 XmlCursor cursor
= o
.newCursor();
3538 QName qFvImage
= new QName(xmlNs
, "FvImage");
3539 if (cursor
.toChild(qFvImage
)) {
3542 vFvNames
.removeAllElements();
3543 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3544 vFvNames
.add(fvNameArray
[i
]);
3546 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3547 if (!fi
.getType().toString().equals(type
)) {
3550 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3553 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3554 while (li
.hasNext()) {
3555 String name
= li
.next();
3556 vFvNames
.remove(name
);
3558 if (vFvNames
.size() == 0) {
3563 }while (cursor
.toNextSibling(qFvImage
));
3569 /**Get FvImage Options for FvImage i
3570 * @param i the ith FvImage
3572 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3573 XmlObject o
= getfpdFlash().getFvImages();
3577 XmlCursor cursor
= o
.newCursor();
3578 QName qFvImage
= new QName(xmlNs
, "FvImage");
3579 if (cursor
.toChild(qFvImage
)) {
3580 for (int j
= 0; j
< i
; ++j
) {
3581 cursor
.toNextSibling(qFvImage
);
3583 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3584 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3588 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3589 while(li
.hasNext()){
3590 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3591 m
.put(nv
.getName(), nv
.getValue());
3598 Get platform header element
3599 @return PlatformHeaderDocument.PlatformHeader
3601 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3602 if (fpdHdr
== null) {
3603 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3609 public String
getFpdHdrPlatformName() {
3610 return getFpdHdr().getPlatformName();
3613 public String
getFpdHdrGuidValue() {
3614 return getFpdHdr().getGuidValue();
3617 public String
getFpdHdrVer() {
3618 return getFpdHdr().getVersion();
3621 public String
getFpdHdrAbs() {
3622 return getFpdHdr().getAbstract();
3625 public String
getFpdHdrDescription() {
3626 return getFpdHdr().getDescription();
3629 public String
getFpdHdrCopyright() {
3630 return getFpdHdr().getCopyright();
3633 public String
getFpdHdrLicense() {
3634 LicenseDocument
.License l
= getFpdHdr().getLicense();
3638 return l
.getStringValue();
3641 public String
getFpdHdrUrl() {
3642 LicenseDocument
.License l
= getFpdHdr().getLicense();
3649 public String
getFpdHdrSpec() {
3651 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3652 // return getFpdHdr().getSpecification();
3655 public void setFpdHdrPlatformName(String name
){
3656 getFpdHdr().setPlatformName(name
);
3659 public void setFpdHdrGuidValue(String guid
){
3660 getFpdHdr().setGuidValue(guid
);
3663 public void setFpdHdrVer(String v
){
3664 getFpdHdr().setVersion(v
);
3667 public void setFpdHdrAbs(String abs
) {
3668 getFpdHdr().setAbstract(abs
);
3671 public void setFpdHdrDescription(String desc
){
3672 getFpdHdr().setDescription(desc
);
3675 public void setFpdHdrCopyright(String cr
) {
3676 getFpdHdr().setCopyright(cr
);
3679 public void setFpdHdrLicense(String license
){
3680 LicenseDocument
.License l
= getFpdHdr().getLicense();
3682 getFpdHdr().addNewLicense().setStringValue(license
);
3685 l
.setStringValue(license
);
3689 public void setFpdHdrUrl(String url
){
3690 LicenseDocument
.License l
= getFpdHdr().getLicense();
3696 public void setFpdHdrSpec(String s
){
3697 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3698 getFpdHdr().setSpecification(s
);
3701 Save the processed xml contents to file
3703 @param fpdFile The file to save xml contents
3704 @throws IOException Exceptions during file operation
3706 public void saveAs(File fpdFile
) throws IOException
{
3708 XmlOptions options
= new XmlOptions();
3710 options
.setCharacterEncoding("UTF-8");
3711 options
.setSavePrettyPrint();
3712 options
.setSavePrettyPrintIndent(2);
3714 fpdd
.save(fpdFile
, options
);
3715 } catch (IOException e
) {
3716 e
.printStackTrace();
3721 private String
listToString(List l
) {
3726 ListIterator li
= l
.listIterator();
3727 while(li
.hasNext()) {
3734 private void removeElement(XmlObject o
) {
3735 XmlCursor cursor
= o
.newCursor();
3741 class PcdItemTypeConflictException
extends Exception
{
3746 private static final long serialVersionUID
= 1L;
3747 private String details
= null;
3749 PcdItemTypeConflictException (String pcdName
, String info
) {
3750 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3752 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + "\n in Pkg " + mi
.getPackageId().getName();
3755 details
= pcdName
+ " ItemType Conflicts with \n" + info
;
3759 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3760 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3761 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3762 String moduleInfo1
= "";
3763 String moduleInfo2
= "";
3765 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3768 moduleInfo1
= info1
;
3772 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3775 moduleInfo2
= info2
;
3778 details
= pcdName
+ " ItemType Conflicts in \n" + moduleInfo1
+ "\n and " + moduleInfo2
;
3781 public String
getMessage() {
3786 class PcdDeclNotFound
extends Exception
{
3791 private static final long serialVersionUID
= 1L;
3792 private String details
= null;
3794 PcdDeclNotFound(String info
) {
3795 details
= "PcdDeclNotFound: " + info
;
3798 public String
getMessage() {
3803 class PcdValueMalFormed
extends Exception
{
3808 private static final long serialVersionUID
= 1L;
3809 private String details
= null;
3811 PcdValueMalFormed(String info
) {
3812 details
= "PcdValueMalFormed: " + info
;
3815 public String
getMessage() {