2 Java class FpdFileContents is used to parse fpd xml file.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
16 import java
.io
.IOException
;
17 import java
.math
.BigInteger
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
22 import java
.util
.List
;
23 import java
.util
.ListIterator
;
26 import java
.util
.Vector
;
28 import javax
.xml
.namespace
.QName
;
30 import org
.apache
.xmlbeans
.XmlCursor
;
31 import org
.apache
.xmlbeans
.XmlObject
;
32 import org
.apache
.xmlbeans
.XmlOptions
;
33 import org
.tianocore
.AntTaskDocument
;
34 import org
.tianocore
.BuildOptionsDocument
;
35 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
36 import org
.tianocore
.EfiSectionType
;
37 import org
.tianocore
.FlashDefinitionFileDocument
;
38 import org
.tianocore
.FlashDocument
;
39 import org
.tianocore
.FrameworkModulesDocument
;
40 import org
.tianocore
.IntermediateOutputType
;
41 import org
.tianocore
.LibrariesDocument
;
42 import org
.tianocore
.ModuleSADocument
;
43 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
44 import org
.tianocore
.ModuleSurfaceAreaDocument
;
45 import org
.tianocore
.OptionDocument
;
46 import org
.tianocore
.OptionsDocument
;
47 import org
.tianocore
.PcdBuildDefinitionDocument
;
48 import org
.tianocore
.PcdCodedDocument
;
49 import org
.tianocore
.PcdDataTypes
;
50 import org
.tianocore
.PcdDeclarationsDocument
;
51 import org
.tianocore
.PcdItemTypes
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PlatformSurfaceAreaDocument
;
54 import org
.tianocore
.FvImageTypes
;
55 import org
.tianocore
.FvImagesDocument
;
56 import org
.tianocore
.LicenseDocument
;
57 import org
.tianocore
.PlatformHeaderDocument
;
58 import org
.tianocore
.SkuInfoDocument
;
59 import org
.tianocore
.UserDefinedAntTasksDocument
;
60 import org
.tianocore
.UserExtensionsDocument
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.WorkspaceProfile
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
63 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
64 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
65 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
68 This class processes fpd file contents such as add remove xml elements.
69 @since PackageEditor 1.0
71 public class FpdFileContents
{
73 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
74 static final String regExpNewLineAndSpaces
= "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
76 private PlatformSurfaceAreaDocument fpdd
= null;
78 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
80 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
82 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
84 private FlashDocument
.Flash fpdFlash
= null;
86 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
88 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
90 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
92 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
94 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
96 private String
itemType (String pcdInfo
) {
98 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
102 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
104 public void initDynPcdMap() {
105 if (dynPcdMap
== null) {
106 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
107 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
109 removeElement(getfpdFrameworkModules());
110 fpdFrameworkModules
= null;
113 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
114 while (li
.hasNext()) {
115 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
116 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
119 String ModuleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion() +
120 " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
121 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
122 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
123 while (lpi
.hasNext()) {
124 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
125 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
126 if (dynPcdMap
.get(pcdKey
) == null) {
127 ArrayList
<String
> al
= new ArrayList
<String
>();
128 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
129 dynPcdMap
.put(pcdKey
, al
);
132 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
139 public ArrayList
<String
> getDynPcdMapValue(String key
) {
140 return dynPcdMap
.get(key
);
143 Constructor to create a new spd file
145 public FpdFileContents() {
147 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
148 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
153 Constructor for existing document object
156 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
158 fpdHdr
= fpdRoot
.getPlatformHeader();
159 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
160 fpdBuildOpts
= fpdRoot
.getBuildOptions();
161 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
162 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
163 fpdFlash
= fpdRoot
.getFlash();
167 Constructor based on an existing spd file
169 @param f Existing spd file
171 public FpdFileContents(File f
) {
173 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
174 fpdRoot
= fpdd
.getPlatformSurfaceArea();
175 } catch (Exception e
) {
176 System
.out
.println(e
.toString());
180 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
181 if (fpdDynPcdBuildDefs
== null){
182 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
184 return fpdDynPcdBuildDefs
;
187 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
188 if (fpdFrameworkModules
== null){
189 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
191 return fpdFrameworkModules
;
194 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
195 if (getFrameworkModulesCount() == 0){
199 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
200 while(li
.hasNext()) {
201 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
202 if (moduleSa
.getModuleSaBuildOptions() == null) {
205 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
206 if (fvBinding
== null) {
210 String
[] fvNames
= fvBinding
.split(" ");
211 for (int i
= 0; i
< fvNames
.length
; ++i
) {
213 // BugBug : underscore "_" should not be replaced!!!
214 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
216 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
217 String
[] sa
= new String
[] {moduleSa
.getModuleGuid(), moduleSa
.getModuleVersion(),
218 moduleSa
.getPackageGuid(), moduleSa
.getPackageVersion(),
219 listToString(moduleSa
.getSupArchList())};
227 public int getFrameworkModulesCount() {
228 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
229 removeElement(getfpdFrameworkModules());
230 fpdFrameworkModules
= null;
233 return getfpdFrameworkModules().getModuleSAList().size();
236 public void getFrameworkModulesInfo(String
[][] saa
) {
237 if (getFrameworkModulesCount() == 0){
241 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
243 while(li
.hasNext()) {
244 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
245 saa
[i
][0] = moduleSa
.getModuleGuid();
246 saa
[i
][1] = moduleSa
.getModuleVersion();
248 saa
[i
][2] = moduleSa
.getPackageGuid();
249 saa
[i
][3] = moduleSa
.getPackageVersion();
250 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
255 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
256 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
260 sa
[0] = msa
.getModuleGuid();
261 sa
[1] = msa
.getModuleVersion();
262 sa
[2] = msa
.getPackageGuid();
263 sa
[3] = msa
.getPackageVersion();
264 sa
[4] = listToString(msa
.getSupArchList());
267 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
269 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
270 removeElement(getfpdFrameworkModules());
271 fpdFrameworkModules
= null;
274 String
[] s
= key
.split(" ");
275 String archsInKey
= "";
277 for (int i
= 4; i
< s
.length
; ++i
) {
281 archsInKey
= archsInKey
.trim();
284 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
285 while(li
.hasNext()) {
286 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
287 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
288 if (moduleSa
.getModuleVersion() != null) {
289 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
293 if (moduleSa
.getPackageVersion() != null) {
294 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
298 //ToDo add arch check .
299 if (moduleSa
.getSupArchList() != null) {
300 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
305 if (archsInKey
.length() == 0) {
314 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
315 ModuleSADocument
.ModuleSA moduleSa
= null;
316 if (fpdRoot
.getFrameworkModules() == null) {
319 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
320 if (cursor
.toFirstChild()) {
321 for (int j
= 0; j
< i
; ++j
) {
322 cursor
.toNextSibling();
324 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
330 public void removeModuleSA(int i
) {
331 XmlObject o
= fpdRoot
.getFrameworkModules();
336 XmlCursor cursor
= o
.newCursor();
337 if (cursor
.toFirstChild()) {
338 for (int j
= 0; j
< i
; ++j
) {
339 cursor
.toNextSibling();
342 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
344 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
345 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
346 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
347 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
348 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
349 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
350 while(li
.hasNext()) {
351 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
352 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
357 while (cursor
.hasPrevToken()) {
358 cursor
.toPrevToken();
359 if (!cursor
.isText()) {
362 if (cursor
.getObject() == null) {
365 String s
= cursor
.getTextValue();
366 if (s
.matches(regExpNewLineAndSpaces
)) {
371 if (cursor
.isComment()) {
377 if (getFrameworkModulesCount() == 0) {
379 removeElement(getfpdFrameworkModules());
380 fpdFrameworkModules
= null;
387 public boolean adjustPcd (int seqModuleSa
, Vector
<String
> vExceptions
) throws Exception
{
388 boolean dataModified
= false;
389 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
390 int pcdCount
= getPcdDataCount(seqModuleSa
);
391 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
392 getPcdData(seqModuleSa
, saaModuleSaPcd
);
393 String mg
= moduleSa
.getModuleGuid().toLowerCase();
394 String mv
= moduleSa
.getModuleVersion();
395 String pg
= moduleSa
.getPackageGuid().toLowerCase();
396 String pv
= moduleSa
.getPackageVersion();
397 String arch
= listToString(moduleSa
.getSupArchList());
399 // delete pcd in ModuleSA but not in MSA files any longer.
401 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
402 int libCount
= getLibraryInstancesCount(moduleKey
);
403 String
[][] saaLib
= new String
[libCount
][5];
404 getLibraryInstances(moduleKey
, saaLib
);
405 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
407 vExceptions
.add("Module " + mg
+ " does NOT exist in workspace.");
408 throw new Exception ("Module does NOT exist in workspace.");
410 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
412 // create vector for module & library instance MIs.
415 for (int j
= 0; j
< saaLib
.length
; ++j
) {
416 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
417 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
423 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
425 for (int j
= 0; j
< vMi
.size(); ++j
) {
426 ModuleIdentification nextMi
= vMi
.get(j
);
427 if (nextMi
== null) {
430 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], arch
, nextMi
)) {
434 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
438 // add new Pcd from MSA file to ModuleSA.
440 for (int i
= 0; i
< vMi
.size(); ++i
) {
441 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
442 .getModuleXmlObject(vMi
444 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
447 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
448 msaPcdIter
:while (li
.hasNext()) {
449 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
450 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
452 for (int j
= 0; j
< al
.size(); ++j
) {
453 if (al
.get(j
).startsWith(moduleKey
)) {
458 // Check sup arch conformance for the new PCD
459 if (msaPcd
.getSupArchList() != null) {
460 String newPcdArch
= msaPcd
.getSupArchList().toString();
461 if (!newPcdArch
.toLowerCase().contains(arch
.toLowerCase())) {
466 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
467 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
468 if (spdPcd
== null) {
472 String errorMessage
= "No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
475 errorMessage
+= " Library Instance " + vMi
.get(i
).getName();
477 vExceptions
.add(errorMessage
);
478 throw new PcdDeclNotFound(errorMessage
);
481 // AddItem to ModuleSA PcdBuildDefinitions
483 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
484 : msaPcd
.getDefaultValue();
486 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
487 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
496 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
498 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
502 String
[] s
= moduleInfo
.split(" ");
503 for(int i
= 0; i
< al
.size(); ++i
){
504 String consumer
= al
.get(i
);
505 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
506 String
[] consumerPart
= consumer
.split(" ");
507 if (!consumerPart
[4].equals(s
[4])) {
515 if (al
.size() == 0) {
516 defaultPcdValue
.remove(pcdKey
);
517 dynPcdMap
.remove(pcdKey
);
518 String
[] s1
= pcdKey
.split(" ");
519 removeDynamicPcdBuildData(s1
[0], s1
[1]);
524 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
526 public int getPcdDataCount (int i
){
527 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
529 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
532 return msa
.getPcdBuildDefinition().getPcdDataList().size();
536 public void getPcdData (int i
, String
[][] saa
) {
537 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
539 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
542 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
543 for (int k
= 0; k
< saa
.length
; ++k
) {
544 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
545 saa
[k
][0] = pcdData
.getCName();
546 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
547 saa
[k
][2] = pcdData
.getItemType()+"";
548 saa
[k
][3] = pcdData
.getToken().toString();
549 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
550 saa
[k
][5] = pcdData
.getDatumType()+"";
551 saa
[k
][6] = pcdData
.getValue();
556 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
557 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
558 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
562 String mg
= moduleSa
.getModuleGuid();
563 String mv
= moduleSa
.getModuleVersion();
564 String pg
= moduleSa
.getPackageGuid();
565 String pv
= moduleSa
.getPackageVersion();
566 String arch
= listToString(moduleSa
.getSupArchList());
567 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
569 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
570 if (cursor
.toFirstChild()){
573 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
574 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
575 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
576 if (getPcdDataCount(seqModuleSa
) == 1) {
583 while(cursor
.toNextSibling());
589 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
590 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
591 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
595 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
596 if (cursor
.toFirstChild()){
598 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
599 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
601 // change item type while not updating dynPcdData????
603 if (itemType
!= null) {
604 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
607 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
608 pcdData
.setMaxDatumSize(new Integer(maxSize
));
611 // if value input is null, keep old value untouched.
614 pcdData
.setValue(value
);
615 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
621 while(cursor
.toNextSibling());
626 /**Get original Pcd info from MSA & SPD files.
627 * @param mi ModuleIdentification from which MSA & SPD come
628 * @param cName PCD cName
629 * @param sa Results: HelpText, Original item type.
632 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
634 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
635 .getModuleXmlObject(mi
);
636 if (msa
.getPcdCoded() == null) {
640 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
642 // First look through MSA pcd entries.
644 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
645 ListIterator li
= l
.listIterator();
646 while (li
.hasNext()) {
647 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
648 if (!msaPcd
.getCName().equals(cName
)) {
651 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
654 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
655 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
659 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
662 // Get Pcd help text and original item type.
664 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
665 sa
[1] = msaPcd
.getPcdItemType() + "";
666 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
667 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
668 while (iter
.hasNext()) {
669 String usage
= iter
.next().toString();
670 validPcdTypes
.add(usage
);
678 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
679 int libCount
= getLibraryInstancesCount(moduleKey
);
680 String
[][] saaLib
= new String
[libCount
][5];
681 getLibraryInstances(moduleKey
, saaLib
);
682 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
683 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
685 // create vector for module & library instance MIs.
688 for (int j
= 0; j
< saaLib
.length
; ++j
) {
689 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
690 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
694 int pcdSourceCount
= 0;
695 for (int i
= 0; i
< vMi
.size(); ++i
) {
696 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, null, vMi
.get(i
))) {
701 if (pcdSourceCount
< 2) {
710 /**Remove PCDBuildDefinition entries from ModuleSA
711 * @param moduleKey identifier of ModuleSA.
712 * @param consumer where these entries come from.
714 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
716 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
717 if (msa
.getPcdCoded() == null) {
721 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
722 ListIterator li
= l
.listIterator();
724 while(li
.hasNext()) {
725 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
726 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
727 if (moduleSA
.getPcdBuildDefinition() != null) {
728 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
730 if (cursor
.toFirstChild()) {
732 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
734 String cName
= msaPcd
.getCName();
735 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
736 if (cName
.equals(pcdData
.getCName())
737 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
739 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
744 } while (cursor
.toNextSibling());
748 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
757 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
759 public int getLibraryInstancesCount(String key
) {
760 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
761 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
764 return msa
.getLibraries().getInstanceList().size();
767 public void getLibraryInstances(String key
, String
[][] saa
){
768 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
769 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
773 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
774 for (int i
= 0; i
< saa
.length
; ++i
) {
775 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
776 saa
[i
][1] = instance
.getModuleGuid();
777 saa
[i
][2] = instance
.getModuleVersion();
778 saa
[i
][3] = instance
.getPackageGuid();
779 saa
[i
][4] = instance
.getPackageVersion();
783 public boolean instanceExistsInModuleSA (String key
, String mg
, String mv
, String pg
, String pv
) {
785 if ((count
= getLibraryInstancesCount(key
)) > 0) {
786 String
[][] saa
= new String
[count
][5];
787 getLibraryInstances (key
, saa
);
788 for (int i
= 0; i
< count
; ++i
) {
789 if (mg
.equalsIgnoreCase(saa
[i
][1]) && pg
.equalsIgnoreCase(saa
[i
][3])) {
790 boolean modVerMatch
= false;
791 boolean pkgVerMatch
= false;
792 if ((mv
.equals("null") || saa
[i
][2] == null)) {
795 if (pv
.equals("null") || saa
[i
][4] == null) {
798 if (modVerMatch
&& pkgVerMatch
) {
802 if (mv
.equals(saa
[i
][2]) && pv
.equals(saa
[i
][4])) {
812 public void removeLibraryInstance(String key
, int i
) {
813 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
814 if (msa
== null || msa
.getLibraries() == null){
818 XmlCursor cursor
= msa
.getLibraries().newCursor();
819 if (cursor
.toFirstChild()) {
820 for (int j
= 0; j
< i
; ++j
) {
821 cursor
.toNextSibling();
824 while (cursor
.hasPrevToken()) {
825 cursor
.toPrevToken();
826 if (!cursor
.isText()) {
829 String s
= cursor
.getTextValue();
830 if (s
.matches(regExpNewLineAndSpaces
)) {
835 if (cursor
.isComment()) {
840 if (getLibraryInstancesCount(key
) == 0) {
849 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
850 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
852 msa
= getfpdFrameworkModules().addNewModuleSA();
854 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
856 libs
= msa
.addNewLibraries();
859 String mn
= libMi
.getName();
860 String mg
= libMi
.getGuid();
861 String mv
= libMi
.getVersion();
862 String pn
= libMi
.getPackageId().getName();
863 String pg
= libMi
.getPackageId().getGuid();
864 String pv
= libMi
.getPackageId().getVersion();
865 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
866 XmlCursor cursor
= instance
.newCursor();
868 String comment
= "Pkg: " + pn
+ " Mod: " + mn
869 + " Path: " + libMi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
870 cursor
.insertComment(comment
);
879 instance
.setModuleGuid(mg
);
880 instance
.setModuleVersion(mv
);
881 instance
.setPackageGuid(pg
);
882 instance
.setPackageVersion(pv
);
886 public String
getFvBinding(String moduleKey
){
887 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
888 return getFvBinding (moduleSa
);
891 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
892 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
895 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
898 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
899 if (moduleSa
== null ) {
902 if (fvBinding
== null || fvBinding
.length() == 0) {
903 if(moduleSa
.getModuleSaBuildOptions() != null){
904 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
908 if(moduleSa
.getModuleSaBuildOptions() == null){
909 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
912 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
916 public void setFvBinding(String moduleKey
, String fvBinding
){
917 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
918 setFvBinding (moduleSa
, fvBinding
);
921 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
922 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
926 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
927 String
[] fvNamesArray
= fvNameList
.split(" ");
929 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
930 if (fvNamesArray
[i
].equals(fvName
)) {
938 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
939 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
943 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
944 String
[] fvNamesArray
= fvNameList
.split(" ");
946 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
947 if (fvNamesArray
[i
].equals(fvName
)) {
952 // jump over where the input fvName occurs in the original Fv list.
953 if (occursAt
!= -1) {
954 String newFvNameList
= " ";
955 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
959 newFvNameList
+= fvNamesArray
[i
];
961 setFvBinding (moduleSa
, newFvNameList
.trim());
967 * @param fvName The FV name that to be removed from FvBinding List.
969 public void removeFvBindingAll (String fvName
) {
970 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
971 removeElement(getfpdFrameworkModules());
972 fpdFrameworkModules
= null;
976 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
977 while (li
.hasNext()) {
978 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
979 removeFvBinding (moduleSa
, fvName
);
983 public void appendFvBindingAll (String fvName
) {
984 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
985 removeElement(getfpdFrameworkModules());
986 fpdFrameworkModules
= null;
990 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
991 while (li
.hasNext()) {
992 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
993 appendFvBinding (moduleSa
, fvName
);
997 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
998 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
999 removeElement(getfpdFrameworkModules());
1000 fpdFrameworkModules
= null;
1004 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
1005 while (li
.hasNext()) {
1006 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
1007 String fvBinding
= getFvBinding (moduleSa
);
1008 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
1009 appendFvBinding (moduleSa
, newFvName
);
1014 public void appendFvBinding (String moduleKey
, String fvName
) {
1015 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1016 appendFvBinding (moduleSa
, fvName
);
1019 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
1020 if (moduleSa
== null) {
1024 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
1025 setFvBinding(moduleSa
, fvName
);
1029 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
1030 String newFvNameList
= fvNameList
+ " " + fvName
;
1031 setFvBinding (moduleSa
, newFvNameList
.trim());
1034 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
1036 appendFvBinding (moduleKey
, fvName
);
1039 public String
getFfsFileNameGuid(String moduleKey
){
1040 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1041 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
1044 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1047 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1048 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1052 if(msa
.getModuleSaBuildOptions() == null){
1053 msa
.addNewModuleSaBuildOptions();
1056 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1057 if (fileGuid
!= null) {
1058 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1061 XmlCursor cursor
= msaBuildOpts
.newCursor();
1062 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1070 public String
getFfsFormatKey(String moduleKey
){
1071 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1072 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1075 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1078 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1079 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1083 if(msa
.getModuleSaBuildOptions() == null){
1084 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1087 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1090 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1091 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1092 moduleSa
.setForceDebug(dbgEnable
);
1095 public boolean getModuleSAForceDebug (int i
) {
1096 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1097 if (moduleSa
.getForceDebug() == true) {
1103 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1104 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1105 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1106 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1110 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1111 ListIterator li
= lOpt
.listIterator();
1113 while(li
.hasNext()) {
1114 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1115 if (opt
.getBuildTargets() != null) {
1116 saa
[i
][0] = listToString(opt
.getBuildTargets());
1118 saa
[i
][1] = opt
.getToolChainFamily();
1119 saa
[i
][2] = opt
.getTagName();
1120 saa
[i
][3] = opt
.getToolCode();
1122 if (opt
.getSupArchList() != null){
1123 saa
[i
][4] = listToString(opt
.getSupArchList());
1129 saa
[i
][5] = opt
.getStringValue();
1135 public int getModuleSAOptionsCount(String moduleKey
){
1136 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1137 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1138 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1141 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1144 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1145 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1146 if (msa
.getModuleSaBuildOptions() == null) {
1147 msa
.addNewModuleSaBuildOptions();
1149 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1150 msa
.getModuleSaBuildOptions().addNewOptions();
1152 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1153 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1156 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1157 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1158 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1161 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1162 XmlCursor cursor
= opts
.newCursor();
1163 if (cursor
.toFirstChild()) {
1164 for (int j
= 0; j
< i
; ++j
){
1165 cursor
.toNextSibling();
1168 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1176 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1177 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1178 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1181 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1182 XmlCursor cursor
= opts
.newCursor();
1183 if (cursor
.toFirstChild()) {
1184 for (int j
= 0; j
< i
; ++j
){
1185 cursor
.toNextSibling();
1187 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1188 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1193 /**add pcd information of module mi to a ModuleSA.
1195 * @param moduleSa if null, generate a new ModuleSA.
1197 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1198 //ToDo add Arch filter
1200 if (moduleSa
== null) {
1201 moduleSa
= genModuleSA(mi
, arch
);
1204 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1205 .getModuleXmlObject(mi
);
1206 if (msa
.getPcdCoded() == null) {
1210 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1212 // Implementing InitializePlatformPcdBuildDefinitions
1214 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1215 ListIterator li
= l
.listIterator();
1216 while (li
.hasNext()) {
1217 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1218 if (msaPcd
.getSupArchList() != null) {
1219 if (!msaPcd
.getSupArchList().toString().toLowerCase().contains(arch
.toLowerCase())) {
1223 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1224 if (spdPcd
== null) {
1228 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + "\n used by Module "
1229 + mi
.getName() + " or its Library Instances.");
1232 // AddItem to ModuleSA PcdBuildDefinitions
1234 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1236 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1238 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1243 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1245 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1246 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1248 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1252 for (int j
= 0; j
< xo
.length
; ++j
) {
1253 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1254 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1255 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1260 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1271 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1272 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1273 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1274 XmlCursor cursor
= msa
.newCursor();
1276 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1277 + mi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
1278 cursor
.insertComment(comment
);
1281 e
.printStackTrace();
1286 msa
.setModuleGuid(mi
.getGuid());
1287 msa
.setModuleVersion(mi
.getVersion());
1288 msa
.setPackageGuid(pi
.getGuid());
1289 msa
.setPackageVersion(pi
.getVersion());
1291 Vector
<String
> v
= new Vector
<String
>();
1293 msa
.setSupArchList(v
);
1299 private String
chooseDefaultPcdType (List validPcdTypes
) {
1300 String choosedType
= "";
1301 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1302 choosedType
= "FIXED_AT_BUILD";
1304 else if (validPcdTypes
.contains("DYNAMIC")) {
1305 choosedType
= "DYNAMIC";
1307 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1308 choosedType
= "PATCHABLE_IN_MODULE";
1310 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1311 choosedType
= "DYNAMIC_EX";
1316 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1317 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1318 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1319 if (moduleSa
.getPcdBuildDefinition() == null){
1320 moduleSa
.addNewPcdBuildDefinition();
1323 // constructe pcd to modulesa mapping first.
1324 // Attention : for any error condition, remove from map this pcd.
1326 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1327 if (pcdConsumer
== null) {
1328 pcdConsumer
= new ArrayList
<String
>();
1331 // Check whether this PCD has already added to ModuleSA, if so, just return.
1333 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1334 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1335 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1336 String pcdInfo
= pcdConsumer
.get(i
);
1337 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1341 // if pcd type from MSA file is Dynamic
1342 // we must choose one default type from SPD file for it.
1344 List validPcdTypes
= spdPcd
.getValidUsage();
1346 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1348 if (pcdConsumer
.size() > 0) {
1350 // platform should only contain one type for each pcd.
1352 String existingItemType
= itemType (pcdConsumer
.get(0));
1353 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1354 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1355 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1359 if (itemType
.equals("DYNAMIC")) {
1360 if (!validPcdTypes
.contains(existingItemType
)) {
1361 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1363 itemType
= existingItemType
;
1366 if (!itemType
.equals(existingItemType
)) {
1367 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1372 // if this is the first occurence of this pcd.
1375 if (itemType
.equals("DYNAMIC")) {
1376 itemType
= chooseDefaultPcdType (validPcdTypes
);
1379 String listValue
= moduleInfo
+ " " + itemType
;
1380 pcdConsumer
.add(listValue
);
1381 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1383 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1384 fpdPcd
.setCName(cName
);
1385 fpdPcd
.setToken(token
);
1386 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1387 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1388 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1390 if (defaultVal
!= null && defaultVal
.length() > 0){
1391 fpdPcd
.setValue(defaultVal
);
1394 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1395 fpdPcd
.setValue("0");
1397 if (dataType
.equals("BOOLEAN")){
1398 fpdPcd
.setValue("FALSE");
1400 if (dataType
.equals("VOID*")) {
1401 fpdPcd
.setValue("L\"\"");
1405 // Using existing pcd value, if this pcd already exists in other moduleSa.
1407 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1408 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1411 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1414 if (dataType
.equals("UINT8")){
1415 fpdPcd
.setMaxDatumSize(1);
1417 if (dataType
.equals("UINT16")) {
1418 fpdPcd
.setMaxDatumSize(2);
1420 if (dataType
.equals("UINT32")) {
1421 fpdPcd
.setMaxDatumSize(4);
1423 if (dataType
.equals("UINT64")){
1424 fpdPcd
.setMaxDatumSize(8);
1426 if (dataType
.equals("BOOLEAN")){
1427 fpdPcd
.setMaxDatumSize(1);
1429 if (dataType
.equals("VOID*")) {
1430 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1431 fpdPcd
.setMaxDatumSize(maxSize
);
1435 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1436 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1438 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1439 // so need to add one dyn pcd.
1441 if (al
.size() == 1) {
1442 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1448 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1449 if (datum
== null) {
1452 char ch
= datum
.charAt(0);
1456 // For void* type PCD, only three datum is support:
1457 // 1) Unicode: string with start char is "L"
1458 // 2) Ansci: String is ""
1459 // 3) byte array: String start char "{"
1462 start
= datum
.indexOf('\"');
1463 end
= datum
.lastIndexOf('\"');
1464 if ((start
> end
) ||
1465 (end
> datum
.length())||
1466 ((start
== end
) && (datum
.length() > 0))) {
1467 //ToDo Error handling here
1468 throw new PcdValueMalFormed (datum
);
1471 strValue
= datum
.substring(start
+ 1, end
);
1472 return strValue
.length() * 2;
1473 } else if (ch
== '\"'){
1474 start
= datum
.indexOf('\"');
1475 end
= datum
.lastIndexOf('\"');
1476 if ((start
> end
) ||
1477 (end
> datum
.length())||
1478 ((start
== end
) && (datum
.length() > 0))) {
1479 throw new PcdValueMalFormed (datum
);
1481 strValue
= datum
.substring(start
+ 1, end
);
1482 return strValue
.length();
1483 } else if (ch
=='{') {
1484 String
[] strValueArray
;
1486 start
= datum
.indexOf('{');
1487 end
= datum
.lastIndexOf('}');
1488 strValue
= datum
.substring(start
+ 1, end
);
1489 strValue
= strValue
.trim();
1490 if (strValue
.length() == 0) {
1493 strValueArray
= strValue
.split(",");
1494 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1495 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1498 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1499 // "it must be a byte array. But the element of %s exceed the byte range",
1500 throw new PcdValueMalFormed (datum
);
1503 return strValueArray
.length
;
1507 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1508 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1509 // "2) ANSIC string: like \"xxx\";\r\n"+
1510 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1511 // "but the datum in seems does not following above format!",
1512 throw new PcdValueMalFormed (datum
);
1517 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1518 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1523 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1525 return dynPcdMap
.get(pcdKey
);
1528 public int getDynamicPcdBuildDataCount() {
1529 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1530 removeElement(getfpdDynPcdBuildDefs());
1531 fpdDynPcdBuildDefs
= null;
1534 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1537 public void getDynamicPcdBuildData(String
[][] saa
) {
1538 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1539 removeElement(getfpdDynPcdBuildDefs());
1540 fpdDynPcdBuildDefs
= null;
1543 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1544 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1546 while(li
.hasNext()) {
1547 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1548 saa
[i
][0] = dynPcd
.getCName();
1549 saa
[i
][1] = dynPcd
.getToken().toString();
1550 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1551 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1552 saa
[i
][4] = dynPcd
.getDatumType()+"";
1558 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1559 throws PcdValueMalFormed
{
1560 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1561 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1562 dynPcdData
.setCName(cName
);
1563 dynPcdData
.setToken(token
);
1564 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1565 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1567 BigInteger bigInt
= new BigInteger("0");
1568 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1569 skuInfo
.setSkuId(bigInt
);
1570 if (defaultVal
!= null){
1571 skuInfo
.setValue(defaultVal
);
1574 if (dataType
.equals("UINT8")){
1575 skuInfo
.setValue("0");
1577 if (dataType
.equals("UINT16")) {
1578 skuInfo
.setValue("0");
1580 if (dataType
.equals("UINT32")) {
1581 skuInfo
.setValue("0");
1583 if (dataType
.equals("UINT64")){
1584 skuInfo
.setValue("0");
1586 if (dataType
.equals("BOOLEAN")){
1587 skuInfo
.setValue("false");
1589 if (dataType
.equals("VOID*")) {
1590 skuInfo
.setValue("");
1593 if (dataType
.equals("UINT8")){
1594 dynPcdData
.setMaxDatumSize(1);
1596 if (dataType
.equals("UINT16")) {
1597 dynPcdData
.setMaxDatumSize(2);
1599 if (dataType
.equals("UINT32")) {
1600 dynPcdData
.setMaxDatumSize(4);
1602 if (dataType
.equals("UINT64")){
1603 dynPcdData
.setMaxDatumSize(8);
1605 if (dataType
.equals("BOOLEAN")){
1606 dynPcdData
.setMaxDatumSize(1);
1608 if (dataType
.equals("VOID*")) {
1609 int maxSize
= setMaxSizeForPointer(defaultVal
);
1610 dynPcdData
.setMaxDatumSize(maxSize
);
1614 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1615 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1620 XmlCursor cursor
= o
.newCursor();
1621 if (cursor
.toFirstChild()) {
1623 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1624 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1625 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1627 if (getDynamicPcdBuildDataCount() == 1) {
1630 fpdDynPcdBuildDefs
= null;
1638 while (cursor
.toNextSibling());
1643 // Get the Sku Info count of ith dyn pcd element.
1645 public int getDynamicPcdSkuInfoCount(int i
){
1646 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1647 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1648 removeElement(getfpdDynPcdBuildDefs());
1649 fpdDynPcdBuildDefs
= null;
1653 int skuInfoCount
= 0;
1654 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1655 if (cursor
.toFirstChild()) {
1656 for (int j
= 0; j
< i
; ++j
) {
1657 cursor
.toNextSibling();
1659 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1660 if (pcdData
.getSkuInfoList() == null) {
1664 skuInfoCount
= pcdData
.getSkuInfoList().size();
1668 return skuInfoCount
;
1671 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1672 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1673 removeElement(getfpdDynPcdBuildDefs());
1674 fpdDynPcdBuildDefs
= null;
1678 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1679 if (cursor
.toFirstChild()) {
1680 for (int j
= 0; j
< i
; ++j
) {
1681 cursor
.toNextSibling();
1683 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1684 if (pcdData
.getSkuInfoList() == null) {
1689 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1691 while (li
.hasNext()) {
1692 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1693 saa
[k
][0] = skuInfo
.getSkuId()+"";
1694 saa
[k
][1] = skuInfo
.getVariableName();
1695 saa
[k
][2] = skuInfo
.getVariableGuid();
1696 saa
[k
][3] = skuInfo
.getVariableOffset();
1697 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1698 saa
[k
][5] = skuInfo
.getVpdOffset();
1699 saa
[k
][6] = skuInfo
.getValue();
1709 public String
getDynamicPcdBuildDataValue(int i
){
1710 String value
= null;
1711 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1712 removeElement(getfpdDynPcdBuildDefs());
1713 fpdDynPcdBuildDefs
= null;
1717 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1718 if (cursor
.toFirstChild()) {
1719 for (int j
= 0; j
< i
; ++j
) {
1720 cursor
.toNextSibling();
1722 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1723 if (pcdData
.getSkuInfoList() == null) {
1727 value
= pcdData
.getSkuInfoArray(0).getValue();
1734 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1735 String vpdOffset
= null;
1736 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1737 removeElement(getfpdDynPcdBuildDefs());
1738 fpdDynPcdBuildDefs
= null;
1742 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1743 if (cursor
.toFirstChild()) {
1744 for (int j
= 0; j
< i
; ++j
) {
1745 cursor
.toNextSibling();
1747 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1748 if (pcdData
.getSkuInfoList() == null) {
1752 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1759 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1760 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1761 removeElement(getfpdDynPcdBuildDefs());
1762 fpdDynPcdBuildDefs
= null;
1766 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1767 if (cursor
.toFirstChild()) {
1768 for (int j
= 0; j
< i
; ++j
) {
1769 cursor
.toNextSibling();
1771 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1772 if (pcdData
.getSkuInfoList() == null) {
1777 pcdData
.getSkuInfoList().clear();
1778 // QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1779 // cursor.toChild(qSkuInfo);
1780 // cursor.removeXml();
1786 // generate sku info for ith dyn pcd build data.
1788 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1789 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1790 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1794 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1795 if (cursor
.toFirstChild()) {
1796 for (int j
= 0; j
< i
; ++j
) {
1797 cursor
.toNextSibling();
1799 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1800 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1801 skuInfo
.setSkuId(new BigInteger(id
));
1802 if (varName
!= null){
1803 skuInfo
.setVariableName(varName
);
1804 skuInfo
.setVariableGuid(varGuid
);
1805 skuInfo
.setVariableOffset(varOffset
);
1806 skuInfo
.setHiiDefaultValue(hiiDefault
);
1808 else if (vpdOffset
!= null){
1809 skuInfo
.setVpdOffset(vpdOffset
);
1812 skuInfo
.setValue(value
);
1817 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1818 String hiiDefault
, String vpdOffset
, String value
, int i
){
1819 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1820 removeElement(getfpdDynPcdBuildDefs());
1821 fpdDynPcdBuildDefs
= null;
1825 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1826 if (cursor
.toFirstChild()) {
1827 for (int j
= 0; j
< i
; ++j
) {
1828 cursor
.toNextSibling();
1830 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1831 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1832 while (li
.hasNext()) {
1833 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1834 if (skuInfo
.getSkuId().toString().equals(id
)){
1835 if (varName
!= null){
1836 skuInfo
.setVariableName(varName
);
1837 skuInfo
.setVariableGuid(varGuid
);
1838 skuInfo
.setVariableOffset(varOffset
);
1839 skuInfo
.setHiiDefaultValue(hiiDefault
);
1841 else if (vpdOffset
!= null){
1842 skuInfo
.setVpdOffset(vpdOffset
);
1845 skuInfo
.setValue(value
);
1853 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1854 if (fpdBuildOpts
== null) {
1855 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1857 return fpdBuildOpts
;
1860 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1861 QName elementFvName
= new QName (xmlNs
, "FvName");
1862 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1863 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1864 QName elementModule
= new QName(xmlNs
, "Module");
1866 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1867 userExts
.setUserID(userId
);
1868 userExts
.setIdentifier(id
);
1869 XmlCursor cursor
= userExts
.newCursor();
1870 cursor
.toEndToken();
1872 cursor
.beginElement(elementFvName
);
1873 cursor
.insertChars(fvName
);
1874 cursor
.toNextToken();
1876 cursor
.beginElement(elementInfFileName
);
1877 cursor
.insertChars(outputFileName
);
1878 cursor
.toNextToken();
1880 cursor
.beginElement(elementIncludeModules
);
1881 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1882 cursor
.beginElement(elementModule
);
1883 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1884 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1885 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1887 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1888 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1889 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1892 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1893 cursor
.toEndToken();
1894 cursor
.toNextToken();
1899 public int getUserExtsIncModCount (String fvName
, String userId
, String id
) {
1900 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1904 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1905 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1906 while (li
.hasNext()) {
1907 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1908 if (!ues
.getUserID().equals(userId
)) {
1911 if (ues
.getIdentifier() == null || !ues
.getIdentifier().equals(id
)) {
1914 XmlCursor cursor
= ues
.newCursor();
1915 cursor
.toFirstChild();
1916 String elementName
= cursor
.getTextValue();
1917 if (elementName
.equals(fvName
)) {
1918 cursor
.toNextSibling(elementIncludeModules
);
1919 if (cursor
.toFirstChild()) {
1921 for (i
= 1; cursor
.toNextSibling(); ++i
);
1933 public void getUserExtsIncMods(String fvName
, String userId
, String id
, String
[][] saa
) {
1934 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1938 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1939 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1940 QName attribUserId
= new QName ("UserID");
1941 QName attribId
= new QName ("Identifier");
1942 QName elementFvName
= new QName (xmlNs
, "FvName");
1943 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1944 QName attribModuleGuid
= new QName("ModuleGuid");
1945 QName attribModuleVersion
= new QName("ModuleVersion");
1946 QName attribPackageGuid
= new QName("PackageGuid");
1947 QName attribPackageVersion
= new QName("PackageVersion");
1948 QName attribArch
= new QName("Arch");
1950 if (cursor
.toChild(elementUserExts
)) {
1953 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
1954 cursor
.toChild(elementFvName
);
1955 String elementName
= cursor
.getTextValue();
1956 if (elementName
.equals(fvName
)) {
1957 cursor
.toNextSibling(elementIncludeModules
);
1958 if (cursor
.toFirstChild()) {
1961 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1962 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1963 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1964 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1965 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1967 }while (cursor
.toNextSibling());
1973 }while (cursor
.toNextSibling(elementUserExts
));
1979 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1980 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1983 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1984 while (li
.hasNext()) {
1985 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1986 if (!ues
.getUserID().equals("IMAGES")) {
1989 XmlCursor cursor
= ues
.newCursor();
1990 cursor
.toFirstChild();
1991 String elementName
= cursor
.getTextValue();
1992 if (elementName
.equals(oldFvName
)) {
1993 cursor
.setTextValue(newFvName
);
2000 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, String id
) {
2001 if (getfpdBuildOpts().getUserExtensionsList() == null) {
2005 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2006 while (li
.hasNext()) {
2007 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2008 if (!ues
.getUserID().equals(userId
)) {
2011 if (ues
.getIdentifier()== null || !ues
.getIdentifier().equals(id
)) {
2014 XmlCursor cursor
= ues
.newCursor();
2015 cursor
.toFirstChild();
2016 String elementName
= cursor
.getTextValue();
2017 if (elementName
.equals(fvName
)) {
2028 private boolean versionEqual (String v1
, String v2
) {
2030 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
2031 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
2035 if (v1
!= null && v1
.equals(v2
)) {
2042 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2043 boolean inList
= false;
2044 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
2045 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2046 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2047 QName attribUserId
= new QName ("UserID");
2048 QName attribId
= new QName ("Identifier");
2049 QName elementFvName
= new QName (xmlNs
, "FvName");
2050 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2051 QName attribModuleGuid
= new QName("ModuleGuid");
2052 QName attribModuleVersion
= new QName("ModuleVersion");
2053 QName attribPackageGuid
= new QName("PackageGuid");
2054 QName attribPackageVersion
= new QName("PackageVersion");
2055 QName attribArch
= new QName("Arch");
2057 if (cursor
.toChild(elementUserExts
)) {
2060 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
2061 cursor
.toChild(elementFvName
);
2062 String elementName
= cursor
.getTextValue();
2063 if (elementName
.equals(fvName
)) {
2064 cursor
.toNextSibling(elementIncludeModules
);
2065 if (cursor
.toFirstChild()) {
2068 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2069 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2070 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2071 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2072 String ar
= cursor
.getAttributeText(attribArch
);
2073 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2076 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2079 if (!arch
.equalsIgnoreCase(ar
)) {
2082 if (!versionEqual(moduleVersion
, mv
)) {
2085 if (!versionEqual(packageVersion
, pv
)) {
2090 }while (cursor
.toNextSibling());
2096 }while (cursor
.toNextSibling(elementUserExts
));
2103 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2105 // if there is only one module before remove operation, the whole user extension should be removed.
2107 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2108 if (moduleAmount
== 1) {
2109 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2113 if (moduleAmount
> 1) {
2114 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2115 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2116 QName attribUserId
= new QName ("UserID");
2117 QName attribId
= new QName ("Identifier");
2118 QName elementFvName
= new QName (xmlNs
, "FvName");
2119 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2120 QName attribModuleGuid
= new QName("ModuleGuid");
2121 QName attribModuleVersion
= new QName("ModuleVersion");
2122 QName attribPackageGuid
= new QName("PackageGuid");
2123 QName attribPackageVersion
= new QName("PackageVersion");
2124 QName attribArch
= new QName("Arch");
2126 if (cursor
.toChild(elementUserExts
)) {
2129 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
)) {
2130 cursor
.toChild(elementFvName
);
2131 String elementName
= cursor
.getTextValue();
2132 if (elementName
.equals(fvName
)) {
2133 cursor
.toNextSibling(elementIncludeModules
);
2134 if (cursor
.toFirstChild()) {
2137 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2138 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2139 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2140 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2141 String ar
= cursor
.getAttributeText(attribArch
);
2142 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2145 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2148 if (!arch
.equalsIgnoreCase(ar
)) {
2151 if (!versionEqual(moduleVersion
, mv
)) {
2154 if (!versionEqual(packageVersion
, pv
)) {
2158 }while (cursor
.toNextSibling());
2164 }while (cursor
.toNextSibling(elementUserExts
));
2170 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, String id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2171 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2175 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2176 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2177 QName elementModule
= new QName(xmlNs
, "Module");
2178 while (li
.hasNext()) {
2179 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2180 if (!ues
.getUserID().equals(userId
)) {
2183 if (ues
.getIdentifier() == null || !ues
.getIdentifier().equals(id
)) {
2186 XmlCursor cursor
= ues
.newCursor();
2187 cursor
.toFirstChild();
2188 String elementName
= cursor
.getTextValue();
2189 if (elementName
.equals(fvName
)) {
2190 cursor
.toNextSibling(elementIncludeModules
);
2191 cursor
.toLastChild();
2192 cursor
.toEndToken();
2193 cursor
.toNextToken();
2194 cursor
.beginElement(elementModule
);
2195 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2196 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2197 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2199 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2200 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2201 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2204 cursor
.insertAttributeWithValue("Arch", arch
);
2213 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2214 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2215 if (udats
== null) {
2216 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2219 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2220 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2223 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2224 at
.setId(new Integer(id
));
2225 XmlCursor cursor
= at
.newCursor();
2226 if (fileName
!= null){
2227 at
.setFilename(fileName
);
2229 else if (cursor
.toChild(xmlNs
, "Filename")) {
2232 if (execOrder
!= null) {
2233 at
.setAntCmdOptions(execOrder
);
2235 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2241 public void removeBuildOptionsUserDefAntTask(int i
) {
2242 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2246 XmlCursor cursor
= o
.newCursor();
2247 if (cursor
.toFirstChild()) {
2248 for (int j
= 0; j
< i
; ++j
) {
2249 cursor
.toNextSibling();
2252 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2260 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2261 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2265 XmlCursor cursor
= o
.newCursor();
2266 if (cursor
.toFirstChild()) {
2267 for (int j
= 0; j
< i
; ++j
) {
2268 cursor
.toNextSibling();
2270 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2271 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2276 public int getBuildOptionsUserDefAntTaskCount() {
2277 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2278 if (udats
== null || udats
.getAntTaskList() == null) {
2282 return udats
.getAntTaskList().size();
2285 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2286 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2287 if (udats
== null || udats
.getAntTaskList() == null) {
2291 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2292 ListIterator li
= l
.listIterator();
2294 while (li
.hasNext()) {
2295 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2296 saa
[i
][0] = at
.getId() + "";
2297 saa
[i
][1] = saa
[i
][2] = "";
2298 if (at
.getFilename() != null){
2299 saa
[i
][1] = at
.getFilename();
2301 if (at
.getAntCmdOptions() != null) {
2302 saa
[i
][2] = at
.getAntCmdOptions();
2307 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2308 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2310 opts
= getfpdBuildOpts().addNewOptions();
2312 OptionDocument
.Option opt
= opts
.addNewOption();
2313 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2316 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2317 opt
.setStringValue(contents
);
2318 if (buildTargets
!= null) {
2319 opt
.setBuildTargets(buildTargets
);
2322 if (opt
.isSetBuildTargets()) {
2323 opt
.unsetBuildTargets();
2327 if (toolChain
!= null && toolChain
.length() > 0) {
2328 opt
.setToolChainFamily(toolChain
);
2331 if (opt
.isSetToolChainFamily()) {
2332 opt
.unsetToolChainFamily();
2336 if (tagName
!= null && tagName
.length() > 0) {
2337 opt
.setTagName(tagName
);
2340 if (opt
.isSetTagName()) {
2345 if (toolCmd
!= null && toolCmd
.length() > 0) {
2346 opt
.setToolCode(toolCmd
);
2349 if (opt
.isSetToolCode()) {
2350 opt
.unsetToolCode();
2355 if (archList
!= null) {
2356 opt
.setSupArchList(archList
);
2359 if (opt
.isSetSupArchList()) {
2360 opt
.unsetSupArchList();
2365 public void removeBuildOptionsOpt(int i
){
2367 XmlObject o
= getfpdBuildOpts().getOptions();
2372 XmlCursor cursor
= o
.newCursor();
2373 if (cursor
.toFirstChild()) {
2374 for (int j
= 0; j
< i
; ++j
) {
2375 cursor
.toNextSibling();
2378 if (getBuildOptionsOptCount() == 0) {
2386 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2387 XmlObject o
= getfpdBuildOpts().getOptions();
2392 XmlCursor cursor
= o
.newCursor();
2393 if (cursor
.toFirstChild()) {
2394 for (int j
= 0; j
< i
; ++j
) {
2395 cursor
.toNextSibling();
2397 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2398 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2403 public int getBuildOptionsOptCount(){
2404 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2407 return getfpdBuildOpts().getOptions().getOptionList().size();
2410 public void getBuildOptionsOpts(String
[][] saa
) {
2411 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2415 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2416 ListIterator li
= lOpt
.listIterator();
2418 while(li
.hasNext()) {
2419 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2420 if (opt
.getBuildTargets() != null) {
2421 saa
[i
][0] = listToString(opt
.getBuildTargets());
2423 saa
[i
][1] = opt
.getToolChainFamily();
2424 if (opt
.getSupArchList() != null){
2425 saa
[i
][2] = listToString(opt
.getSupArchList());
2428 saa
[i
][3] = opt
.getToolCode();
2429 saa
[i
][4] = opt
.getTagName();
2430 saa
[i
][5] = opt
.getStringValue();
2436 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2437 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2438 ffs
.setFfsKey(ffsKey
);
2440 ffs
.addNewSections().setEncapsulationType(type
);
2444 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2445 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2446 ffs
.getSections().setEncapsulationType(type
);
2449 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2450 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2451 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2452 attrib
.setName(name
);
2453 attrib
.setValue(value
);
2456 /**update jth attribute of ith ffs.
2460 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2461 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2462 XmlCursor cursor
= ffs
.newCursor();
2463 QName qAttrib
= new QName(xmlNs
, "Attribute");
2464 if (cursor
.toChild(qAttrib
)) {
2465 for (int k
= 0; k
< j
; ++k
) {
2466 cursor
.toNextSibling(qAttrib
);
2468 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2469 attrib
.setName(name
);
2470 attrib
.setValue(value
);
2475 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2476 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2477 XmlCursor cursor
= ffs
.newCursor();
2478 QName qAttrib
= new QName(xmlNs
, "Attribute");
2479 if (cursor
.toChild(qAttrib
)) {
2480 for (int k
= 0; k
< j
; ++k
) {
2481 cursor
.toNextSibling(qAttrib
);
2488 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2489 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2493 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2495 if (sections
== null){
2496 sections
= ffs
.addNewSections();
2498 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2501 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2502 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2503 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2504 if (sections
== null) {
2507 XmlCursor cursor
= sections
.newCursor();
2508 QName qSection
= new QName(xmlNs
, "Section");
2509 if (cursor
.toChild(qSection
)) {
2510 for (int k
= 0; k
< j
; ++k
) {
2511 cursor
.toNextSibling(qSection
);
2518 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2519 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2520 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2521 if (sections
== null) {
2524 XmlCursor cursor
= sections
.newCursor();
2525 QName qSection
= new QName(xmlNs
, "Section");
2526 if (cursor
.toChild(qSection
)) {
2527 for (int k
= 0; k
< j
; ++k
) {
2528 cursor
.toNextSibling(qSection
);
2530 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2531 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2536 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2537 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2541 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2543 if (sections
== null){
2544 sections
= ffs
.addNewSections();
2546 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2547 sections2
.setEncapsulationType(encapType
);
2548 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2551 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2552 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2553 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2554 if (sections
== null) {
2557 XmlCursor cursor
= sections
.newCursor();
2558 QName qSections
= new QName(xmlNs
, "Sections");
2559 if (cursor
.toChild(qSections
)) {
2560 for (int k
= 0; k
< j
; ++k
) {
2561 cursor
.toNextSibling(qSections
);
2568 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2569 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2570 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2571 if (sections
== null) {
2574 XmlCursor cursor
= sections
.newCursor();
2575 QName qSections
= new QName(xmlNs
, "Sections");
2576 if (cursor
.toChild(qSections
)) {
2577 for (int k
= 0; k
< j
; ++k
) {
2578 cursor
.toNextSibling(qSections
);
2580 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2581 sections2
.setEncapsulationType(type
);
2586 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2587 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2591 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2592 XmlCursor cursor
= sections
.newCursor();
2593 QName qSections
= new QName(xmlNs
, "Sections");
2594 if (cursor
.toChild(qSections
)){
2595 for (int k
= 0; k
< j
; ++k
) {
2596 cursor
.toNextSibling(qSections
);
2598 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2599 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2604 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2605 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2606 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2607 if (sections
== null) {
2610 XmlCursor cursor
= sections
.newCursor();
2611 QName qSections
= new QName(xmlNs
, "Sections");
2612 if (cursor
.toChild(qSections
)) {
2613 for (int l
= 0; l
< j
; ++l
) {
2614 cursor
.toNextSibling(qSections
);
2616 if (cursor
.toFirstChild()) {
2618 for (; m
< k
; ++m
) {
2619 cursor
.toNextSibling();
2631 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2632 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2633 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2634 if (sections
== null) {
2637 XmlCursor cursor
= sections
.newCursor();
2638 QName qSections
= new QName(xmlNs
, "Sections");
2639 if (cursor
.toChild(qSections
)) {
2640 for (int l
= 0; l
< j
; ++l
) {
2641 cursor
.toNextSibling(qSections
);
2643 if (cursor
.toFirstChild()) {
2644 for (int m
= 0; m
< k
; ++m
) {
2645 cursor
.toNextSibling();
2647 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2648 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2654 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2655 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2659 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2660 XmlCursor cursor
= sections
.newCursor();
2661 QName qSections
= new QName(xmlNs
, "Sections");
2662 if (cursor
.toChild(qSections
)){
2663 for (int k
= 0; k
< j
; ++k
) {
2664 cursor
.toNextSibling(qSections
);
2666 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2667 if (sections2
.getSectionList() == null){
2671 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2672 while(li
.hasNext()) {
2673 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2674 // if (section.isSetSectionType()) {
2675 al
.add(section
.getSectionType()+"");
2684 public int getBuildOptionsFfsCount(){
2685 if (getfpdBuildOpts().getFfsList() == null) {
2688 return getfpdBuildOpts().getFfsList().size();
2691 public void getBuildOptionsFfsKey(String
[][] saa
) {
2692 if (getfpdBuildOpts().getFfsList() == null) {
2695 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2697 while(li
.hasNext()){
2698 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2699 saa
[i
][0] = ffs
.getFfsKey();
2704 public void updateBuildOptionsFfsKey(int i
, String key
) {
2705 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2709 /**Get ith FFS key and contents.
2712 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2713 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2717 sa
[0] = ffs
.getFfsKey();
2718 if (ffs
.getSections() != null) {
2719 if(ffs
.getSections().getEncapsulationType() != null){
2720 sa
[1] = ffs
.getSections().getEncapsulationType();
2722 if (ffs
.getSections().getSectionList() != null){
2723 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2724 while (li
.hasNext()) {
2725 firstLevelSection
.add(li
.next().getSectionType()+"");
2728 if (ffs
.getSections().getSectionsList() != null) {
2729 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2730 while(li
.hasNext()) {
2731 firstLevelSections
.add(li
.next().getEncapsulationType());
2735 if (ffs
.getAttributeList() != null) {
2736 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2737 while(li
.hasNext()) {
2738 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2739 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2748 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2749 XmlObject o
= getfpdBuildOpts();
2750 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2752 XmlCursor cursor
= o
.newCursor();
2753 QName qFfs
= new QName(xmlNs
, "Ffs");
2754 if (cursor
.toChild(qFfs
)) {
2755 for (int j
= 0; j
< i
; ++j
) {
2756 cursor
.toNextSibling(qFfs
);
2758 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2764 public void removeBuildOptionsFfs(int i
) {
2765 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2770 XmlCursor cursor
= ffs
.newCursor();
2777 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2778 if (fpdPlatformDefs
== null){
2779 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2781 return fpdPlatformDefs
;
2784 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2785 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2788 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2789 while(li
.hasNext()) {
2790 archs
.add(li
.next());
2794 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2795 if (archs
!= null) {
2796 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2799 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2800 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2801 // cursor.removeXml();
2803 // cursor.dispose();
2807 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2808 if (getfpdPlatformDefs().getBuildTargets() == null) {
2811 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2812 while(li
.hasNext()) {
2813 targets
.add(li
.next());
2817 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2818 getfpdPlatformDefs().setBuildTargets(targets
);
2821 public void genPlatformDefsSkuInfo(String id
, String name
) {
2822 SkuInfoDocument
.SkuInfo skuInfo
= null;
2823 if (getfpdPlatformDefs().getSkuInfo() == null) {
2824 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2826 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2827 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2828 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2829 skuName
.setSkuID(new BigInteger("0"));
2830 skuName
.setStringValue("DEFAULT");
2832 if (id
.equals("0")) {
2835 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2836 skuName
.setSkuID(new BigInteger(id
));
2837 skuName
.setStringValue(name
);
2840 public int getPlatformDefsSkuInfoCount(){
2841 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2844 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2847 public void getPlatformDefsSkuInfos(String
[][] saa
){
2848 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2849 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2850 removeElement(getfpdDynPcdBuildDefs());
2851 fpdDynPcdBuildDefs
= null;
2856 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2857 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2859 while(li
.hasNext()) {
2860 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2861 saa
[i
][0] = sku
.getSkuID()+"";
2862 saa
[i
][1] = sku
.getStringValue();
2867 public void removePlatformDefsSkuInfo(int i
) {
2868 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2869 if (skuInfo
== null || i
== 0) {
2873 XmlCursor cursor
= skuInfo
.newCursor();
2874 if (cursor
.toFirstChild()) {
2875 for (int j
= 0; j
< i
; ++j
) {
2876 cursor
.toNextSibling();
2883 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2884 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2885 if (skuInfo
== null || i
== 0) {
2889 XmlCursor cursor
= skuInfo
.newCursor();
2890 if (cursor
.toFirstChild()) {
2891 for (int j
= 0; j
< i
; ++j
) {
2892 cursor
.toNextSibling();
2894 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2895 sku
.setSkuID(new BigInteger(id
));
2896 sku
.setStringValue(name
);
2901 public String
getPlatformDefsInterDir(){
2902 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2905 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2908 public void setPlatformDefsInterDir(String interDir
){
2909 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2912 public String
getPlatformDefsOutputDir() {
2913 return getfpdPlatformDefs().getOutputDirectory();
2916 public void setPlatformDefsOutputDir(String outputDir
) {
2917 if (outputDir
!= null && outputDir
.length() > 0) {
2918 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2921 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2922 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2929 public FlashDocument
.Flash
getfpdFlash() {
2930 if (fpdFlash
== null) {
2931 fpdFlash
= fpdRoot
.addNewFlash();
2936 public void genFlashDefinitionFile(String file
) {
2937 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2939 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2942 fdf
.setStringValue(file
);
2945 public String
getFlashDefinitionFile() {
2946 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2951 return fdf
.getStringValue();
2954 public void genFvImagesNameValue(String name
, String value
) {
2956 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2958 fi
= getfpdFlash().addNewFvImages();
2961 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2966 public void removeFvImagesNameValue(int i
){
2968 XmlObject o
= getfpdFlash().getFvImages();
2973 QName qNameValue
= new QName(xmlNs
, "NameValue");
2974 XmlCursor cursor
= o
.newCursor();
2975 if (cursor
.toChild(qNameValue
)) {
2976 for (int j
= 0; j
< i
; ++j
) {
2977 cursor
.toNextSibling(qNameValue
);
2984 public void updateFvImagesNameValue(int i
, String name
, String value
){
2986 XmlObject o
= getfpdFlash().getFvImages();
2991 QName qNameValue
= new QName(xmlNs
, "NameValue");
2992 XmlCursor cursor
= o
.newCursor();
2993 if (cursor
.toChild(qNameValue
)) {
2994 for (int j
= 0; j
< i
; ++j
) {
2995 cursor
.toNextSibling(qNameValue
);
2997 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
3004 public int getFvImagesNameValueCount() {
3006 FvImagesDocument
.FvImages fi
= null;
3007 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
3010 return fi
.getNameValueList().size();
3013 public void getFvImagesNameValues(String
[][] nv
) {
3015 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
3019 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
3021 ListIterator li
= l
.listIterator();
3022 while (li
.hasNext()) {
3023 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
3025 nv
[i
][0] = e
.getName();
3026 nv
[i
][1] = e
.getValue();
3032 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
3033 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3034 if (fis
== null || fis
.getFvImageList() == null) {
3038 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3039 while (li
.hasNext()) {
3040 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3041 if (fi
.getType().toString().equals("ImageName")) {
3042 vImageNames
.addAll(fi
.getFvImageNamesList());
3048 public void addFvImageFvImageNames (String
[] fvNames
) {
3049 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3050 if (fis
== null || fis
.getFvImageList() == null) {
3051 genFvImagesFvImage (fvNames
, "ImageName", null);
3055 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3056 while (li
.hasNext()) {
3057 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3058 if (fi
.getType().toString().equals("ImageName")) {
3059 addFvImageNamesInFvImage (fi
, fvNames
);
3063 genFvImagesFvImage (fvNames
, "ImageName", null);
3066 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3068 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3069 fi
.addFvImageNames(fvNames
[i
]);
3073 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3074 XmlObject o
= getfpdFlash().getFvImages();
3078 XmlCursor cursor
= o
.newCursor();
3079 QName qFvImage
= new QName(xmlNs
, "FvImage");
3080 if (cursor
.toChild(qFvImage
)) {
3081 for (int j
= 0; j
< i
; ++j
) {
3082 cursor
.toNextSibling(qFvImage
);
3084 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3085 addFvImageNamesInFvImage(fi
, fvNames
);
3090 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3092 FvImagesDocument
.FvImages fis
= null;
3093 if ((fis
= getfpdFlash().getFvImages()) == null) {
3094 fis
= getfpdFlash().addNewFvImages();
3098 //gen FvImage with FvImageNames array
3100 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3101 for (int i
= 0; i
< names
.length
; ++i
) {
3102 fi
.addFvImageNames(names
[i
]);
3104 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3105 if (options
!= null){
3106 setFvImagesFvImageFvImageOptions(options
, fi
);
3110 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3111 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3113 fio
= fi
.addNewFvImageOptions();
3116 Set
<String
> key
= options
.keySet();
3117 Iterator
<String
> i
= key
.iterator();
3118 while (i
.hasNext()) {
3120 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3121 String k
= (String
)i
.next();
3124 nv
.setValue((String
)options
.get(k
));
3131 public void removeFvImagesFvImage(int i
) {
3133 XmlObject o
= getfpdFlash().getFvImages();
3138 QName qFvImage
= new QName(xmlNs
, "FvImage");
3139 XmlCursor cursor
= o
.newCursor();
3140 if (cursor
.toChild(qFvImage
)) {
3141 for (int j
= 0; j
< i
; ++j
) {
3142 cursor
.toNextSibling(qFvImage
);
3151 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3153 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3154 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3157 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3158 while (li
.hasNext()) {
3159 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3160 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3161 if (fi
.getFvImageNamesList().size() == 0) {
3167 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3168 XmlObject o
= getfpdFlash().getFvImages();
3172 XmlCursor cursor
= o
.newCursor();
3173 QName qFvImage
= new QName(xmlNs
, "FvImage");
3174 if (cursor
.toChild(qFvImage
)) {
3175 for (int j
= 0; j
< i
; ++j
) {
3176 cursor
.toNextSibling(qFvImage
);
3178 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3179 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3185 * @param oldFvName The FV Name to be replaced.
3186 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3188 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3189 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3190 XmlCursor cursor
= fi
.newCursor();
3192 if (cursor
.toChild(qFvImageNames
)) {
3194 String xmlValue
= cursor
.getTextValue();
3195 if (xmlValue
.equals(oldFvName
)){
3196 if (newFvName
!= null) {
3197 cursor
.setTextValue(newFvName
);
3203 }while (cursor
.toNextSibling(qFvImageNames
));
3209 /**update the Type attribute of ith FvImage with new type.
3213 public void updateFvImagesFvImageType (int i
, String type
) {
3214 XmlObject o
= getfpdFlash().getFvImages();
3218 XmlCursor cursor
= o
.newCursor();
3219 QName qFvImage
= new QName(xmlNs
, "FvImage");
3220 if (cursor
.toChild(qFvImage
)) {
3221 for (int j
= 0; j
< i
; ++j
) {
3222 cursor
.toNextSibling(qFvImage
);
3224 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3225 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3230 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3232 XmlObject o
= getfpdFlash().getFvImages();
3236 XmlCursor cursor
= o
.newCursor();
3237 QName qFvImage
= new QName(xmlNs
, "FvImage");
3238 if (cursor
.toChild(qFvImage
)) {
3239 for (int j
= 0; j
< i
; ++j
) {
3240 cursor
.toNextSibling(qFvImage
);
3242 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3243 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3246 // remove old FvImageNames before adding new ones
3248 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3249 cursor
.toChild(qFvImageNames
);
3251 while (cursor
.toNextSibling(qFvImageNames
)) {
3255 for (int k
= 0; k
< names
.length
; ++k
) {
3256 fi
.addFvImageNames(names
[k
]);
3259 // remove old FvImageOptions before adding new options
3261 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3262 cursor
.toNextSibling(qFvImageOptions
);
3265 setFvImagesFvImageFvImageOptions(options
, fi
);
3270 public int getFvImagesFvImageCount(String type
) {
3272 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3275 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3276 ListIterator li
= l
.listIterator();
3278 while(li
.hasNext()) {
3279 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3280 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3290 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3291 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3292 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3295 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3296 ListIterator li
= l
.listIterator();
3297 while(li
.hasNext()) {
3298 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3299 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3302 if (fi
.getFvImageNamesList().contains(fvName
)) {
3311 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3313 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3315 if (getfpdFlash().getFvImages() == null) {
3318 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3322 ListIterator li
= l
.listIterator();
3324 while(li
.hasNext()) {
3325 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3326 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3330 // get FvImageNames array, space separated
3332 List
<String
> lfn
= fi
.getFvImageNamesList();
3333 ListIterator lfni
= lfn
.listIterator();
3335 while (lfni
.hasNext()) {
3336 saa
[i
][0] += (String
)lfni
.next();
3339 saa
[i
][0] = saa
[i
][0].trim();
3341 saa
[i
][1] = fi
.getType()+"";
3347 public void removeFvImageNameValue (int i
, String attributeName
) {
3348 XmlObject o
= getfpdFlash().getFvImages();
3352 XmlCursor cursor
= o
.newCursor();
3353 QName qFvImage
= new QName(xmlNs
, "FvImage");
3354 if (cursor
.toChild(qFvImage
)) {
3355 for (int j
= 0; j
< i
; ++j
) {
3356 cursor
.toNextSibling(qFvImage
);
3358 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3359 removeFvImageNameValue (fi
, attributeName
);
3363 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3365 * @param attributeName
3367 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3368 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3369 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3370 while (li
.hasNext()) {
3371 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3372 if (nv
.getName().equals(attributeName
)) {
3379 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3380 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3381 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3382 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3383 removeFvImageNameValue (fi
, optName
);
3387 /**Add name-value pair to FvImage element with type.
3388 * @param fvName FV name to add name-value pair.
3389 * @param type FvImage attribute.
3393 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3394 boolean fvImageExists
= false;
3395 if (getfpdFlash().getFvImages() != null) {
3397 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3399 ListIterator li
= l
.listIterator();
3400 while (li
.hasNext()) {
3401 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3402 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3405 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3408 fvImageExists
= true;
3409 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3414 if (!fvImageExists
) {
3415 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3416 map
.put(name
, value
);
3417 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3421 /**Add to all FvImage elements with type, the name-value pair.
3426 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3427 if (getfpdFlash().getFvImages() == null) {
3430 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3434 ListIterator li
= l
.listIterator();
3435 while(li
.hasNext()) {
3436 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3437 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3440 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3445 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3446 XmlObject o
= getfpdFlash().getFvImages();
3450 XmlCursor cursor
= o
.newCursor();
3451 QName qFvImage
= new QName(xmlNs
, "FvImage");
3452 if (cursor
.toChild(qFvImage
)) {
3453 for (int j
= 0; j
< i
; ++j
) {
3454 cursor
.toNextSibling(qFvImage
);
3456 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3457 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3462 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3468 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3469 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3470 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3473 if (newName
!= null && !newName
.equals(name
)) {
3474 nv
.setName(newName
);
3479 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3480 if (cursor
.toFirstChild()) {
3482 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3483 if (nv
.getName().equals(name
)) {
3485 if (newName
!= null && !newName
.equals(name
)) {
3486 nv
.setName(newName
);
3491 }while (cursor
.toNextSibling());
3494 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3497 if (newName
!= null && !newName
.equals(name
)) {
3498 nv
.setName(newName
);
3503 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3504 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3505 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3506 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3507 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3511 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3514 while (li
.hasNext()) {
3515 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3516 m
.put(nv
.getName(), nv
.getValue());
3521 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3522 XmlObject o
= getfpdFlash().getFvImages();
3528 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3529 Vector
<String
> vFvNames
= new Vector
<String
>();
3532 XmlCursor cursor
= o
.newCursor();
3533 QName qFvImage
= new QName(xmlNs
, "FvImage");
3534 if (cursor
.toChild(qFvImage
)) {
3537 vFvNames
.removeAllElements();
3538 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3539 vFvNames
.add(fvNameArray
[i
]);
3541 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3542 if (!fi
.getType().toString().equals(type
)) {
3545 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3548 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3549 while (li
.hasNext()) {
3550 String name
= li
.next();
3551 vFvNames
.remove(name
);
3553 if (vFvNames
.size() == 0) {
3558 }while (cursor
.toNextSibling(qFvImage
));
3564 /**Get FvImage Options for FvImage i
3565 * @param i the ith FvImage
3567 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3568 XmlObject o
= getfpdFlash().getFvImages();
3572 XmlCursor cursor
= o
.newCursor();
3573 QName qFvImage
= new QName(xmlNs
, "FvImage");
3574 if (cursor
.toChild(qFvImage
)) {
3575 for (int j
= 0; j
< i
; ++j
) {
3576 cursor
.toNextSibling(qFvImage
);
3578 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3579 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3583 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3584 while(li
.hasNext()){
3585 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3586 m
.put(nv
.getName(), nv
.getValue());
3593 Get platform header element
3594 @return PlatformHeaderDocument.PlatformHeader
3596 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3597 if (fpdHdr
== null) {
3598 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3604 public String
getFpdHdrPlatformName() {
3605 return getFpdHdr().getPlatformName();
3608 public String
getFpdHdrGuidValue() {
3609 return getFpdHdr().getGuidValue();
3612 public String
getFpdHdrVer() {
3613 return getFpdHdr().getVersion();
3616 public String
getFpdHdrAbs() {
3617 return getFpdHdr().getAbstract();
3620 public String
getFpdHdrDescription() {
3621 return getFpdHdr().getDescription();
3624 public String
getFpdHdrCopyright() {
3625 return getFpdHdr().getCopyright();
3628 public String
getFpdHdrLicense() {
3629 LicenseDocument
.License l
= getFpdHdr().getLicense();
3633 return l
.getStringValue();
3636 public String
getFpdHdrUrl() {
3637 LicenseDocument
.License l
= getFpdHdr().getLicense();
3644 public String
getFpdHdrSpec() {
3646 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3647 // return getFpdHdr().getSpecification();
3650 public void setFpdHdrPlatformName(String name
){
3651 getFpdHdr().setPlatformName(name
);
3654 public void setFpdHdrGuidValue(String guid
){
3655 getFpdHdr().setGuidValue(guid
);
3658 public void setFpdHdrVer(String v
){
3659 getFpdHdr().setVersion(v
);
3662 public void setFpdHdrAbs(String abs
) {
3663 getFpdHdr().setAbstract(abs
);
3666 public void setFpdHdrDescription(String desc
){
3667 getFpdHdr().setDescription(desc
);
3670 public void setFpdHdrCopyright(String cr
) {
3671 getFpdHdr().setCopyright(cr
);
3674 public void setFpdHdrLicense(String license
){
3675 LicenseDocument
.License l
= getFpdHdr().getLicense();
3677 getFpdHdr().addNewLicense().setStringValue(license
);
3680 l
.setStringValue(license
);
3684 public void setFpdHdrUrl(String url
){
3685 LicenseDocument
.License l
= getFpdHdr().getLicense();
3691 public void setFpdHdrSpec(String s
){
3692 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3693 getFpdHdr().setSpecification(s
);
3696 Save the processed xml contents to file
3698 @param fpdFile The file to save xml contents
3699 @throws IOException Exceptions during file operation
3701 public void saveAs(File fpdFile
) throws IOException
{
3703 XmlOptions options
= new XmlOptions();
3705 options
.setCharacterEncoding("UTF-8");
3706 options
.setSavePrettyPrint();
3707 options
.setSavePrettyPrintIndent(2);
3709 fpdd
.save(fpdFile
, options
);
3710 } catch (IOException e
) {
3711 e
.printStackTrace();
3716 private String
listToString(List l
) {
3721 ListIterator li
= l
.listIterator();
3722 while(li
.hasNext()) {
3729 private void removeElement(XmlObject o
) {
3730 XmlCursor cursor
= o
.newCursor();
3736 class PcdItemTypeConflictException
extends Exception
{
3741 private static final long serialVersionUID
= 1L;
3742 private String details
= null;
3744 PcdItemTypeConflictException (String pcdName
, String info
) {
3745 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3747 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + "\n in Pkg " + mi
.getPackageId().getName();
3750 details
= pcdName
+ " ItemType Conflicts with \n" + info
;
3754 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3755 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3756 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3757 String moduleInfo1
= "";
3758 String moduleInfo2
= "";
3760 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3763 moduleInfo1
= info1
;
3767 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3770 moduleInfo2
= info2
;
3773 details
= pcdName
+ " ItemType Conflicts in \n" + moduleInfo1
+ "\n and " + moduleInfo2
;
3776 public String
getMessage() {
3781 class PcdDeclNotFound
extends Exception
{
3786 private static final long serialVersionUID
= 1L;
3787 private String details
= null;
3789 PcdDeclNotFound(String info
) {
3790 details
= "PcdDeclNotFound: " + info
;
3793 public String
getMessage() {
3798 class PcdValueMalFormed
extends Exception
{
3803 private static final long serialVersionUID
= 1L;
3804 private String details
= null;
3806 PcdValueMalFormed(String info
) {
3807 details
= "PcdValueMalFormed: " + info
;
3810 public String
getMessage() {