2 Java class FpdFileContents is used to parse fpd xml file.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
16 import java
.io
.IOException
;
17 import java
.math
.BigInteger
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
22 import java
.util
.List
;
23 import java
.util
.ListIterator
;
26 import java
.util
.Vector
;
28 import javax
.xml
.namespace
.QName
;
30 import org
.apache
.xmlbeans
.XmlCursor
;
31 import org
.apache
.xmlbeans
.XmlObject
;
32 import org
.apache
.xmlbeans
.XmlOptions
;
33 import org
.tianocore
.AntTaskDocument
;
34 import org
.tianocore
.BuildOptionsDocument
;
35 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
36 import org
.tianocore
.EfiSectionType
;
37 import org
.tianocore
.FlashDefinitionFileDocument
;
38 import org
.tianocore
.FlashDocument
;
39 import org
.tianocore
.FrameworkModulesDocument
;
40 import org
.tianocore
.IntermediateOutputType
;
41 import org
.tianocore
.LibrariesDocument
;
42 import org
.tianocore
.ModuleSADocument
;
43 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
44 import org
.tianocore
.ModuleSurfaceAreaDocument
;
45 import org
.tianocore
.OptionDocument
;
46 import org
.tianocore
.OptionsDocument
;
47 import org
.tianocore
.PcdBuildDefinitionDocument
;
48 import org
.tianocore
.PcdCodedDocument
;
49 import org
.tianocore
.PcdDataTypes
;
50 import org
.tianocore
.PcdDeclarationsDocument
;
51 import org
.tianocore
.PcdItemTypes
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PlatformSurfaceAreaDocument
;
54 import org
.tianocore
.FvImageTypes
;
55 import org
.tianocore
.FvImagesDocument
;
56 import org
.tianocore
.LicenseDocument
;
57 import org
.tianocore
.PlatformHeaderDocument
;
58 import org
.tianocore
.SkuInfoDocument
;
59 import org
.tianocore
.UserDefinedAntTasksDocument
;
60 import org
.tianocore
.UserExtensionsDocument
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.WorkspaceProfile
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
63 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
64 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
70 public class FpdFileContents
{
72 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
73 static final String regExpNewLineAndSpaces
= "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
75 private PlatformSurfaceAreaDocument fpdd
= null;
77 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
79 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
81 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
83 private FlashDocument
.Flash fpdFlash
= null;
85 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
87 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
89 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
91 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
93 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
95 private String
itemType (String pcdInfo
) {
97 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
101 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
103 public void initDynPcdMap() {
104 if (dynPcdMap
== null) {
105 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
106 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
108 removeElement(getfpdFrameworkModules());
109 fpdFrameworkModules
= null;
112 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
113 while (li
.hasNext()) {
114 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
115 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
118 String ModuleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion() +
119 " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
120 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
121 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
122 while (lpi
.hasNext()) {
123 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
124 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
125 if (dynPcdMap
.get(pcdKey
) == null) {
126 ArrayList
<String
> al
= new ArrayList
<String
>();
127 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
128 dynPcdMap
.put(pcdKey
, al
);
131 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
138 public ArrayList
<String
> getDynPcdMapValue(String key
) {
139 return dynPcdMap
.get(key
);
142 Constructor to create a new spd file
144 public FpdFileContents() {
146 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
147 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
152 Constructor for existing document object
155 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
157 fpdHdr
= fpdRoot
.getPlatformHeader();
158 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
159 fpdBuildOpts
= fpdRoot
.getBuildOptions();
160 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
161 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
162 fpdFlash
= fpdRoot
.getFlash();
166 Constructor based on an existing spd file
168 @param f Existing spd file
170 public FpdFileContents(File f
) {
172 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
173 fpdRoot
= fpdd
.getPlatformSurfaceArea();
174 } catch (Exception e
) {
175 System
.out
.println(e
.toString());
179 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
180 if (fpdDynPcdBuildDefs
== null){
181 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
183 return fpdDynPcdBuildDefs
;
186 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
187 if (fpdFrameworkModules
== null){
188 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
190 return fpdFrameworkModules
;
193 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
194 if (getFrameworkModulesCount() == 0){
198 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
199 while(li
.hasNext()) {
200 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
201 if (moduleSa
.getModuleSaBuildOptions() == null) {
204 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
205 if (fvBinding
== null) {
209 String
[] fvNames
= fvBinding
.split(" ");
210 for (int i
= 0; i
< fvNames
.length
; ++i
) {
212 // BugBug : underscore "_" should not be replaced!!!
213 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
215 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
216 String
[] sa
= new String
[] {moduleSa
.getModuleGuid(), moduleSa
.getModuleVersion(),
217 moduleSa
.getPackageGuid(), moduleSa
.getPackageVersion(),
218 listToString(moduleSa
.getSupArchList())};
226 public int getFrameworkModulesCount() {
227 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
228 removeElement(getfpdFrameworkModules());
229 fpdFrameworkModules
= null;
232 return getfpdFrameworkModules().getModuleSAList().size();
235 public void getFrameworkModulesInfo(String
[][] saa
) {
236 if (getFrameworkModulesCount() == 0){
240 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
242 while(li
.hasNext()) {
243 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
244 saa
[i
][0] = moduleSa
.getModuleGuid();
245 saa
[i
][1] = moduleSa
.getModuleVersion();
247 saa
[i
][2] = moduleSa
.getPackageGuid();
248 saa
[i
][3] = moduleSa
.getPackageVersion();
249 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
254 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
255 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
259 sa
[0] = msa
.getModuleGuid();
260 sa
[1] = msa
.getModuleVersion();
261 sa
[2] = msa
.getPackageGuid();
262 sa
[3] = msa
.getPackageVersion();
263 sa
[4] = listToString(msa
.getSupArchList());
266 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
268 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
269 removeElement(getfpdFrameworkModules());
270 fpdFrameworkModules
= null;
273 String
[] s
= key
.split(" ");
274 String archsInKey
= "";
276 for (int i
= 4; i
< s
.length
; ++i
) {
280 archsInKey
= archsInKey
.trim();
283 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
284 while(li
.hasNext()) {
285 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
286 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
287 if (moduleSa
.getModuleVersion() != null) {
288 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
292 if (moduleSa
.getPackageVersion() != null) {
293 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
297 //ToDo add arch check .
298 if (moduleSa
.getSupArchList() != null) {
299 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
304 if (archsInKey
.length() == 0) {
313 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
314 ModuleSADocument
.ModuleSA moduleSa
= null;
315 if (fpdRoot
.getFrameworkModules() == null) {
318 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
319 if (cursor
.toFirstChild()) {
320 for (int j
= 0; j
< i
; ++j
) {
321 cursor
.toNextSibling();
323 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
329 public void removeModuleSA(int i
) {
330 XmlObject o
= fpdRoot
.getFrameworkModules();
335 XmlCursor cursor
= o
.newCursor();
336 if (cursor
.toFirstChild()) {
337 for (int j
= 0; j
< i
; ++j
) {
338 cursor
.toNextSibling();
341 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
343 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
344 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
345 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
346 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
347 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
348 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
349 while(li
.hasNext()) {
350 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
351 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
356 while (cursor
.hasPrevToken()) {
357 cursor
.toPrevToken();
358 if (!cursor
.isText()) {
361 if (cursor
.getObject() == null) {
364 String s
= cursor
.getTextValue();
365 if (s
.matches(regExpNewLineAndSpaces
)) {
370 if (cursor
.isComment()) {
376 if (getFrameworkModulesCount() == 0) {
378 removeElement(getfpdFrameworkModules());
379 fpdFrameworkModules
= null;
386 public boolean adjustPcd (int seqModuleSa
) throws Exception
{
387 boolean dataModified
= false;
388 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
389 int pcdCount
= getPcdDataCount(seqModuleSa
);
390 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
391 getPcdData(seqModuleSa
, saaModuleSaPcd
);
392 String mg
= moduleSa
.getModuleGuid().toLowerCase();
393 String mv
= moduleSa
.getModuleVersion();
394 String pg
= moduleSa
.getPackageGuid().toLowerCase();
395 String pv
= moduleSa
.getPackageVersion();
396 String arch
= listToString(moduleSa
.getSupArchList());
398 // delete pcd in ModuleSA but not in MSA files any longer.
400 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
401 int libCount
= getLibraryInstancesCount(moduleKey
);
402 String
[][] saaLib
= new String
[libCount
][5];
403 getLibraryInstances(moduleKey
, saaLib
);
404 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
405 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
407 // create vector for module & library instance MIs.
410 for (int j
= 0; j
< saaLib
.length
; ++j
) {
411 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
412 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
416 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
418 for (int j
= 0; j
< vMi
.size(); ++j
) {
419 ModuleIdentification nextMi
= vMi
.get(j
);
420 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], nextMi
)) {
424 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
428 // add new Pcd from MSA file to ModuleSA.
430 for (int i
= 0; i
< vMi
.size(); ++i
) {
431 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
432 .getModuleXmlObject(vMi
434 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
437 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
438 msaPcdIter
:while (li
.hasNext()) {
439 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
440 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
442 for (int j
= 0; j
< al
.size(); ++j
) {
443 if (al
.get(j
).startsWith(moduleKey
)) {
449 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
450 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
451 if (spdPcd
== null) {
455 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
459 // AddItem to ModuleSA PcdBuildDefinitions
461 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
462 : msaPcd
.getDefaultValue();
464 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
465 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
474 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
476 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
480 String
[] s
= moduleInfo
.split(" ");
481 for(int i
= 0; i
< al
.size(); ++i
){
482 String consumer
= al
.get(i
);
483 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
484 String
[] consumerPart
= consumer
.split(" ");
485 if (!consumerPart
[4].equals(s
[4])) {
493 if (al
.size() == 0) {
494 defaultPcdValue
.remove(pcdKey
);
495 dynPcdMap
.remove(pcdKey
);
496 String
[] s1
= pcdKey
.split(" ");
497 removeDynamicPcdBuildData(s1
[0], s1
[1]);
502 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
504 public int getPcdDataCount (int i
){
505 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
507 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
510 return msa
.getPcdBuildDefinition().getPcdDataList().size();
514 public void getPcdData (int i
, String
[][] saa
) {
515 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
517 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
520 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
521 for (int k
= 0; k
< saa
.length
; ++k
) {
522 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
523 saa
[k
][0] = pcdData
.getCName();
524 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
525 saa
[k
][2] = pcdData
.getItemType()+"";
526 saa
[k
][3] = pcdData
.getToken().toString();
527 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
528 saa
[k
][5] = pcdData
.getDatumType()+"";
529 saa
[k
][6] = pcdData
.getValue();
534 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
535 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
536 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
540 String mg
= moduleSa
.getModuleGuid();
541 String mv
= moduleSa
.getModuleVersion();
542 String pg
= moduleSa
.getPackageGuid();
543 String pv
= moduleSa
.getPackageVersion();
544 String arch
= listToString(moduleSa
.getSupArchList());
545 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
547 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
548 if (cursor
.toFirstChild()){
551 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
552 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
553 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
554 if (getPcdDataCount(seqModuleSa
) == 1) {
561 while(cursor
.toNextSibling());
567 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
568 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
569 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
573 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
574 if (cursor
.toFirstChild()){
576 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
577 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
579 // change item type while not updating dynPcdData????
581 if (itemType
!= null) {
582 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
585 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
586 pcdData
.setMaxDatumSize(new Integer(maxSize
));
589 // if value input is null, keep old value untouched.
592 pcdData
.setValue(value
);
593 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
599 while(cursor
.toNextSibling());
604 /**Get original Pcd info from MSA & SPD files.
605 * @param mi ModuleIdentification from which MSA & SPD come
606 * @param cName PCD cName
607 * @param sa Results: HelpText, Original item type.
610 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
612 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
613 .getModuleXmlObject(mi
);
614 if (msa
.getPcdCoded() == null) {
618 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
620 // First look through MSA pcd entries.
622 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
623 ListIterator li
= l
.listIterator();
624 while (li
.hasNext()) {
625 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
626 if (!msaPcd
.getCName().equals(cName
)) {
629 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
632 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
633 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
637 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
640 // Get Pcd help text and original item type.
642 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
643 sa
[1] = msaPcd
.getPcdItemType() + "";
644 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
645 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
646 while (iter
.hasNext()) {
647 String usage
= iter
.next().toString();
648 validPcdTypes
.add(usage
);
656 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
657 int libCount
= getLibraryInstancesCount(moduleKey
);
658 String
[][] saaLib
= new String
[libCount
][5];
659 getLibraryInstances(moduleKey
, saaLib
);
660 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
661 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
663 // create vector for module & library instance MIs.
666 for (int j
= 0; j
< saaLib
.length
; ++j
) {
667 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
668 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
672 int pcdSourceCount
= 0;
673 for (int i
= 0; i
< vMi
.size(); ++i
) {
674 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
679 if (pcdSourceCount
< 2) {
688 /**Remove PCDBuildDefinition entries from ModuleSA
689 * @param moduleKey identifier of ModuleSA.
690 * @param consumer where these entries come from.
692 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
694 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
695 if (msa
.getPcdCoded() == null) {
699 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
700 ListIterator li
= l
.listIterator();
702 while(li
.hasNext()) {
703 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
704 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
705 if (moduleSA
.getPcdBuildDefinition() != null) {
706 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
708 if (cursor
.toFirstChild()) {
710 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
712 String cName
= msaPcd
.getCName();
713 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
714 if (cName
.equals(pcdData
.getCName())
715 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
717 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
722 } while (cursor
.toNextSibling());
726 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
735 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
737 public int getLibraryInstancesCount(String key
) {
738 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
739 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
742 return msa
.getLibraries().getInstanceList().size();
745 public void getLibraryInstances(String key
, String
[][] saa
){
746 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
747 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
751 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
752 for (int i
= 0; i
< saa
.length
; ++i
) {
753 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
754 saa
[i
][1] = instance
.getModuleGuid();
755 saa
[i
][2] = instance
.getModuleVersion();
756 saa
[i
][3] = instance
.getPackageGuid();
757 saa
[i
][4] = instance
.getPackageVersion();
761 public void removeLibraryInstance(String key
, int i
) {
762 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
763 if (msa
== null || msa
.getLibraries() == null){
767 XmlCursor cursor
= msa
.getLibraries().newCursor();
768 if (cursor
.toFirstChild()) {
769 for (int j
= 0; j
< i
; ++j
) {
770 cursor
.toNextSibling();
773 while (cursor
.hasPrevToken()) {
774 cursor
.toPrevToken();
775 if (!cursor
.isText()) {
778 String s
= cursor
.getTextValue();
779 if (s
.matches(regExpNewLineAndSpaces
)) {
784 if (cursor
.isComment()) {
789 if (getLibraryInstancesCount(key
) == 0) {
798 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
799 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
801 msa
= getfpdFrameworkModules().addNewModuleSA();
803 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
805 libs
= msa
.addNewLibraries();
808 String mn
= libMi
.getName();
809 String mg
= libMi
.getGuid();
810 String mv
= libMi
.getVersion();
811 String pn
= libMi
.getPackageId().getName();
812 String pg
= libMi
.getPackageId().getGuid();
813 String pv
= libMi
.getPackageId().getVersion();
814 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
815 XmlCursor cursor
= instance
.newCursor();
817 String comment
= "Pkg: " + pn
+ " Mod: " + mn
818 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
819 cursor
.insertComment(comment
);
828 instance
.setModuleGuid(mg
);
829 instance
.setModuleVersion(mv
);
830 instance
.setPackageGuid(pg
);
831 instance
.setPackageVersion(pv
);
835 public String
getFvBinding(String moduleKey
){
836 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
837 return getFvBinding (moduleSa
);
840 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
841 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
844 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
847 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
848 if (moduleSa
== null ) {
851 if (fvBinding
== null || fvBinding
.length() == 0) {
852 if(moduleSa
.getModuleSaBuildOptions() != null){
853 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
857 if(moduleSa
.getModuleSaBuildOptions() == null){
858 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
861 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
865 public void setFvBinding(String moduleKey
, String fvBinding
){
866 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
867 setFvBinding (moduleSa
, fvBinding
);
870 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
871 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
875 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
876 String
[] fvNamesArray
= fvNameList
.split(" ");
878 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
879 if (fvNamesArray
[i
].equals(fvName
)) {
887 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
888 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
892 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
893 String
[] fvNamesArray
= fvNameList
.split(" ");
895 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
896 if (fvNamesArray
[i
].equals(fvName
)) {
901 // jump over where the input fvName occurs in the original Fv list.
902 if (occursAt
!= -1) {
903 String newFvNameList
= " ";
904 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
908 newFvNameList
+= fvNamesArray
[i
];
910 setFvBinding (moduleSa
, newFvNameList
.trim());
916 * @param fvName The FV name that to be removed from FvBinding List.
918 public void removeFvBindingAll (String fvName
) {
919 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
920 removeElement(getfpdFrameworkModules());
921 fpdFrameworkModules
= null;
925 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
926 while (li
.hasNext()) {
927 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
928 removeFvBinding (moduleSa
, fvName
);
932 public void appendFvBindingAll (String fvName
) {
933 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
934 removeElement(getfpdFrameworkModules());
935 fpdFrameworkModules
= null;
939 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
940 while (li
.hasNext()) {
941 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
942 appendFvBinding (moduleSa
, fvName
);
946 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
947 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
948 removeElement(getfpdFrameworkModules());
949 fpdFrameworkModules
= null;
953 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
954 while (li
.hasNext()) {
955 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
956 String fvBinding
= getFvBinding (moduleSa
);
957 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
958 appendFvBinding (moduleSa
, newFvName
);
963 public void appendFvBinding (String moduleKey
, String fvName
) {
964 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
965 appendFvBinding (moduleSa
, fvName
);
968 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
969 if (moduleSa
== null) {
973 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
974 setFvBinding(moduleSa
, fvName
);
978 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
979 String newFvNameList
= fvNameList
+ " " + fvName
;
980 setFvBinding (moduleSa
, newFvNameList
.trim());
983 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
985 appendFvBinding (moduleKey
, fvName
);
988 public String
getFfsFileNameGuid(String moduleKey
){
989 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
990 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
993 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
996 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
997 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1001 if(msa
.getModuleSaBuildOptions() == null){
1002 msa
.addNewModuleSaBuildOptions();
1005 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1006 if (fileGuid
!= null) {
1007 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1010 XmlCursor cursor
= msaBuildOpts
.newCursor();
1011 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1019 public String
getFfsFormatKey(String moduleKey
){
1020 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1021 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1024 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1027 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1028 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1032 if(msa
.getModuleSaBuildOptions() == null){
1033 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1036 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1039 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1040 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1041 moduleSa
.setForceDebug(dbgEnable
);
1044 public boolean getModuleSAForceDebug (int i
) {
1045 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1046 if (moduleSa
.getForceDebug() == true) {
1052 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1053 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1054 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1055 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1059 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1060 ListIterator li
= lOpt
.listIterator();
1062 while(li
.hasNext()) {
1063 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1064 if (opt
.getBuildTargets() != null) {
1065 saa
[i
][0] = listToString(opt
.getBuildTargets());
1067 saa
[i
][1] = opt
.getToolChainFamily();
1068 saa
[i
][2] = opt
.getTagName();
1069 saa
[i
][3] = opt
.getToolCode();
1071 if (opt
.getSupArchList() != null){
1072 saa
[i
][4] = listToString(opt
.getSupArchList());
1078 saa
[i
][5] = opt
.getStringValue();
1084 public int getModuleSAOptionsCount(String moduleKey
){
1085 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1086 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1087 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1090 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1093 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1094 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1095 if (msa
.getModuleSaBuildOptions() == null) {
1096 msa
.addNewModuleSaBuildOptions();
1098 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1099 msa
.getModuleSaBuildOptions().addNewOptions();
1101 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1102 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1105 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1106 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1107 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1110 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1111 XmlCursor cursor
= opts
.newCursor();
1112 if (cursor
.toFirstChild()) {
1113 for (int j
= 0; j
< i
; ++j
){
1114 cursor
.toNextSibling();
1117 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1125 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1126 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1127 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1130 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1131 XmlCursor cursor
= opts
.newCursor();
1132 if (cursor
.toFirstChild()) {
1133 for (int j
= 0; j
< i
; ++j
){
1134 cursor
.toNextSibling();
1136 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1137 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1142 /**add pcd information of module mi to a ModuleSA.
1144 * @param moduleSa if null, generate a new ModuleSA.
1146 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1147 //ToDo add Arch filter
1149 if (moduleSa
== null) {
1150 moduleSa
= genModuleSA(mi
, arch
);
1153 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1154 .getModuleXmlObject(mi
);
1155 if (msa
.getPcdCoded() == null) {
1159 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1161 // Implementing InitializePlatformPcdBuildDefinitions
1163 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1164 ListIterator li
= l
.listIterator();
1165 while (li
.hasNext()) {
1166 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1167 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1168 if (spdPcd
== null) {
1172 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
1176 // AddItem to ModuleSA PcdBuildDefinitions
1178 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1180 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1182 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1187 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1189 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1190 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1192 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1196 for (int j
= 0; j
< xo
.length
; ++j
) {
1197 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1198 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1199 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1204 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1215 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1216 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1217 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1218 XmlCursor cursor
= msa
.newCursor();
1220 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1221 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1222 cursor
.insertComment(comment
);
1225 e
.printStackTrace();
1230 msa
.setModuleGuid(mi
.getGuid());
1231 msa
.setModuleVersion(mi
.getVersion());
1232 msa
.setPackageGuid(pi
.getGuid());
1233 msa
.setPackageVersion(pi
.getVersion());
1235 Vector
<String
> v
= new Vector
<String
>();
1237 msa
.setSupArchList(v
);
1243 private String
chooseDefaultPcdType (List validPcdTypes
) {
1244 String choosedType
= "";
1245 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1246 choosedType
= "FIXED_AT_BUILD";
1248 else if (validPcdTypes
.contains("DYNAMIC")) {
1249 choosedType
= "DYNAMIC";
1251 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1252 choosedType
= "PATCHABLE_IN_MODULE";
1254 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1255 choosedType
= "DYNAMIC_EX";
1260 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1261 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1262 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1263 if (moduleSa
.getPcdBuildDefinition() == null){
1264 moduleSa
.addNewPcdBuildDefinition();
1267 // constructe pcd to modulesa mapping first.
1268 // Attention : for any error condition, remove from map this pcd.
1270 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1271 if (pcdConsumer
== null) {
1272 pcdConsumer
= new ArrayList
<String
>();
1275 // Check whether this PCD has already added to ModuleSA, if so, just return.
1277 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1278 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1279 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1280 String pcdInfo
= pcdConsumer
.get(i
);
1281 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1285 // if pcd type from MSA file is Dynamic
1286 // we must choose one default type from SPD file for it.
1288 List validPcdTypes
= spdPcd
.getValidUsage();
1290 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1292 if (pcdConsumer
.size() > 0) {
1294 // platform should only contain one type for each pcd.
1296 String existingItemType
= itemType (pcdConsumer
.get(0));
1297 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1298 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1299 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1303 if (itemType
.equals("DYNAMIC")) {
1304 if (!validPcdTypes
.contains(existingItemType
)) {
1305 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1307 itemType
= existingItemType
;
1310 if (!itemType
.equals(existingItemType
)) {
1311 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1316 // if this is the first occurence of this pcd.
1319 if (itemType
.equals("DYNAMIC")) {
1320 itemType
= chooseDefaultPcdType (validPcdTypes
);
1323 String listValue
= moduleInfo
+ " " + itemType
;
1324 pcdConsumer
.add(listValue
);
1325 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1327 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1328 fpdPcd
.setCName(cName
);
1329 fpdPcd
.setToken(token
);
1330 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1331 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1332 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1334 if (defaultVal
!= null){
1335 fpdPcd
.setValue(defaultVal
);
1338 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1339 fpdPcd
.setValue("0");
1341 if (dataType
.equals("BOOLEAN")){
1342 fpdPcd
.setValue("FALSE");
1344 if (dataType
.equals("VOID*")) {
1345 fpdPcd
.setValue("");
1349 // Using existing pcd value, if this pcd already exists in other moduleSa.
1351 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1352 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1355 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1358 if (dataType
.equals("UINT8")){
1359 fpdPcd
.setMaxDatumSize(1);
1361 if (dataType
.equals("UINT16")) {
1362 fpdPcd
.setMaxDatumSize(2);
1364 if (dataType
.equals("UINT32")) {
1365 fpdPcd
.setMaxDatumSize(4);
1367 if (dataType
.equals("UINT64")){
1368 fpdPcd
.setMaxDatumSize(8);
1370 if (dataType
.equals("BOOLEAN")){
1371 fpdPcd
.setMaxDatumSize(1);
1373 if (dataType
.equals("VOID*")) {
1374 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1375 fpdPcd
.setMaxDatumSize(maxSize
);
1379 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1380 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1382 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1383 // so need to add one dyn pcd.
1385 if (al
.size() == 1) {
1386 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1392 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1393 if (datum
== null) {
1396 char ch
= datum
.charAt(0);
1400 // For void* type PCD, only three datum is support:
1401 // 1) Unicode: string with start char is "L"
1402 // 2) Ansci: String is ""
1403 // 3) byte array: String start char "{"
1406 start
= datum
.indexOf('\"');
1407 end
= datum
.lastIndexOf('\"');
1408 if ((start
> end
) ||
1409 (end
> datum
.length())||
1410 ((start
== end
) && (datum
.length() > 0))) {
1411 //ToDo Error handling here
1412 throw new PcdValueMalFormed (datum
);
1415 strValue
= datum
.substring(start
+ 1, end
);
1416 return strValue
.length() * 2;
1417 } else if (ch
== '\"'){
1418 start
= datum
.indexOf('\"');
1419 end
= datum
.lastIndexOf('\"');
1420 if ((start
> end
) ||
1421 (end
> datum
.length())||
1422 ((start
== end
) && (datum
.length() > 0))) {
1423 throw new PcdValueMalFormed (datum
);
1425 strValue
= datum
.substring(start
+ 1, end
);
1426 return strValue
.length();
1427 } else if (ch
=='{') {
1428 String
[] strValueArray
;
1430 start
= datum
.indexOf('{');
1431 end
= datum
.lastIndexOf('}');
1432 strValue
= datum
.substring(start
+ 1, end
);
1433 strValue
= strValue
.trim();
1434 if (strValue
.length() == 0) {
1437 strValueArray
= strValue
.split(",");
1438 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1439 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1442 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1443 // "it must be a byte array. But the element of %s exceed the byte range",
1444 throw new PcdValueMalFormed (datum
);
1447 return strValueArray
.length
;
1451 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1452 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1453 // "2) ANSIC string: like \"xxx\";\r\n"+
1454 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1455 // "but the datum in seems does not following above format!",
1456 throw new PcdValueMalFormed (datum
);
1461 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1462 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1467 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1469 return dynPcdMap
.get(pcdKey
);
1472 public int getDynamicPcdBuildDataCount() {
1473 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1474 removeElement(getfpdDynPcdBuildDefs());
1475 fpdDynPcdBuildDefs
= null;
1478 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1481 public void getDynamicPcdBuildData(String
[][] saa
) {
1482 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1483 removeElement(getfpdDynPcdBuildDefs());
1484 fpdDynPcdBuildDefs
= null;
1487 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1488 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1490 while(li
.hasNext()) {
1491 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1492 saa
[i
][0] = dynPcd
.getCName();
1493 saa
[i
][1] = dynPcd
.getToken().toString();
1494 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1495 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1496 saa
[i
][4] = dynPcd
.getDatumType().toString();
1502 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1503 throws PcdValueMalFormed
{
1504 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1505 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1506 dynPcdData
.setCName(cName
);
1507 dynPcdData
.setToken(token
);
1508 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1509 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1511 BigInteger bigInt
= new BigInteger("0");
1512 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1513 skuInfo
.setSkuId(bigInt
);
1514 if (defaultVal
!= null){
1515 skuInfo
.setValue(defaultVal
);
1518 if (dataType
.equals("UINT8")){
1519 skuInfo
.setValue("0");
1521 if (dataType
.equals("UINT16")) {
1522 skuInfo
.setValue("0");
1524 if (dataType
.equals("UINT32")) {
1525 skuInfo
.setValue("0");
1527 if (dataType
.equals("UINT64")){
1528 skuInfo
.setValue("0");
1530 if (dataType
.equals("BOOLEAN")){
1531 skuInfo
.setValue("false");
1533 if (dataType
.equals("VOID*")) {
1534 skuInfo
.setValue("");
1537 if (dataType
.equals("UINT8")){
1538 dynPcdData
.setMaxDatumSize(1);
1540 if (dataType
.equals("UINT16")) {
1541 dynPcdData
.setMaxDatumSize(2);
1543 if (dataType
.equals("UINT32")) {
1544 dynPcdData
.setMaxDatumSize(4);
1546 if (dataType
.equals("UINT64")){
1547 dynPcdData
.setMaxDatumSize(8);
1549 if (dataType
.equals("BOOLEAN")){
1550 dynPcdData
.setMaxDatumSize(1);
1552 if (dataType
.equals("VOID*")) {
1553 int maxSize
= setMaxSizeForPointer(defaultVal
);
1554 dynPcdData
.setMaxDatumSize(maxSize
);
1558 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1559 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1564 XmlCursor cursor
= o
.newCursor();
1565 if (cursor
.toFirstChild()) {
1567 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1568 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1569 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1571 if (getDynamicPcdBuildDataCount() == 1) {
1574 fpdDynPcdBuildDefs
= null;
1582 while (cursor
.toNextSibling());
1587 // Get the Sku Info count of ith dyn pcd element.
1589 public int getDynamicPcdSkuInfoCount(int i
){
1590 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1591 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1592 removeElement(getfpdDynPcdBuildDefs());
1593 fpdDynPcdBuildDefs
= null;
1597 int skuInfoCount
= 0;
1598 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1599 if (cursor
.toFirstChild()) {
1600 for (int j
= 0; j
< i
; ++j
) {
1601 cursor
.toNextSibling();
1603 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1604 if (pcdData
.getSkuInfoList() == null) {
1608 skuInfoCount
= pcdData
.getSkuInfoList().size();
1612 return skuInfoCount
;
1615 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1616 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1617 removeElement(getfpdDynPcdBuildDefs());
1618 fpdDynPcdBuildDefs
= null;
1622 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1623 if (cursor
.toFirstChild()) {
1624 for (int j
= 0; j
< i
; ++j
) {
1625 cursor
.toNextSibling();
1627 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1628 if (pcdData
.getSkuInfoList() == null) {
1633 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1635 while (li
.hasNext()) {
1636 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1637 saa
[k
][0] = skuInfo
.getSkuId()+"";
1638 saa
[k
][1] = skuInfo
.getVariableName();
1639 saa
[k
][2] = skuInfo
.getVariableGuid();
1640 saa
[k
][3] = skuInfo
.getVariableOffset();
1641 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1642 saa
[k
][5] = skuInfo
.getVpdOffset();
1643 saa
[k
][6] = skuInfo
.getValue();
1653 public String
getDynamicPcdBuildDataValue(int i
){
1654 String value
= null;
1655 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1656 removeElement(getfpdDynPcdBuildDefs());
1657 fpdDynPcdBuildDefs
= null;
1661 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1662 if (cursor
.toFirstChild()) {
1663 for (int j
= 0; j
< i
; ++j
) {
1664 cursor
.toNextSibling();
1666 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1667 if (pcdData
.getSkuInfoList() == null) {
1671 value
= pcdData
.getSkuInfoArray(0).getValue();
1678 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1679 String vpdOffset
= null;
1680 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1681 removeElement(getfpdDynPcdBuildDefs());
1682 fpdDynPcdBuildDefs
= null;
1686 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1687 if (cursor
.toFirstChild()) {
1688 for (int j
= 0; j
< i
; ++j
) {
1689 cursor
.toNextSibling();
1691 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1692 if (pcdData
.getSkuInfoList() == null) {
1696 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1703 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1704 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1705 removeElement(getfpdDynPcdBuildDefs());
1706 fpdDynPcdBuildDefs
= null;
1710 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1711 if (cursor
.toFirstChild()) {
1712 for (int j
= 0; j
< i
; ++j
) {
1713 cursor
.toNextSibling();
1715 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1716 if (pcdData
.getSkuInfoList() == null) {
1721 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1722 cursor
.toChild(qSkuInfo
);
1729 // generate sku info for ith dyn pcd build data.
1731 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1732 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1733 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1737 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1738 if (cursor
.toFirstChild()) {
1739 for (int j
= 0; j
< i
; ++j
) {
1740 cursor
.toNextSibling();
1742 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1743 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1744 skuInfo
.setSkuId(new BigInteger(id
));
1745 if (varName
!= null){
1746 skuInfo
.setVariableName(varName
);
1747 skuInfo
.setVariableGuid(varGuid
);
1748 skuInfo
.setVariableOffset(varOffset
);
1749 skuInfo
.setHiiDefaultValue(hiiDefault
);
1751 else if (vpdOffset
!= null){
1752 skuInfo
.setVpdOffset(vpdOffset
);
1755 skuInfo
.setValue(value
);
1760 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1761 String hiiDefault
, String vpdOffset
, String value
, int i
){
1762 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1763 removeElement(getfpdDynPcdBuildDefs());
1764 fpdDynPcdBuildDefs
= null;
1768 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1769 if (cursor
.toFirstChild()) {
1770 for (int j
= 0; j
< i
; ++j
) {
1771 cursor
.toNextSibling();
1773 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1774 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1775 while (li
.hasNext()) {
1776 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1777 if (skuInfo
.getSkuId().toString().equals(id
)){
1778 if (varName
!= null){
1779 skuInfo
.setVariableName(varName
);
1780 skuInfo
.setVariableGuid(varGuid
);
1781 skuInfo
.setVariableOffset(varOffset
);
1782 skuInfo
.setHiiDefaultValue(hiiDefault
);
1784 else if (vpdOffset
!= null){
1785 skuInfo
.setVpdOffset(vpdOffset
);
1788 skuInfo
.setValue(value
);
1796 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1797 if (fpdBuildOpts
== null) {
1798 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1800 return fpdBuildOpts
;
1803 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1804 QName elementFvName
= new QName (xmlNs
, "FvName");
1805 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1806 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1807 QName elementModule
= new QName(xmlNs
, "Module");
1809 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1810 userExts
.setUserID(userId
);
1811 userExts
.setIdentifier(new BigInteger(id
));
1812 XmlCursor cursor
= userExts
.newCursor();
1813 cursor
.toEndToken();
1815 cursor
.beginElement(elementFvName
);
1816 cursor
.insertChars(fvName
);
1817 cursor
.toNextToken();
1819 cursor
.beginElement(elementInfFileName
);
1820 cursor
.insertChars(outputFileName
);
1821 cursor
.toNextToken();
1823 cursor
.beginElement(elementIncludeModules
);
1824 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1825 cursor
.beginElement(elementModule
);
1826 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1827 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1828 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1830 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1831 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1832 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1835 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1836 cursor
.toEndToken();
1837 cursor
.toNextToken();
1842 public int getUserExtsIncModCount (String fvName
, String userId
, int id
) {
1843 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1847 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1848 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1849 while (li
.hasNext()) {
1850 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1851 if (!ues
.getUserID().equals(userId
)) {
1854 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
1857 XmlCursor cursor
= ues
.newCursor();
1858 cursor
.toFirstChild();
1859 String elementName
= cursor
.getTextValue();
1860 if (elementName
.equals(fvName
)) {
1861 cursor
.toNextSibling(elementIncludeModules
);
1862 if (cursor
.toFirstChild()) {
1864 for (i
= 1; cursor
.toNextSibling(); ++i
);
1876 public void getUserExtsIncMods(String fvName
, String userId
, int id
, String
[][] saa
) {
1877 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1881 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1882 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1883 QName attribUserId
= new QName ("UserID");
1884 QName attribId
= new QName ("Identifier");
1885 QName elementFvName
= new QName (xmlNs
, "FvName");
1886 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1887 QName attribModuleGuid
= new QName("ModuleGuid");
1888 QName attribModuleVersion
= new QName("ModuleVersion");
1889 QName attribPackageGuid
= new QName("PackageGuid");
1890 QName attribPackageVersion
= new QName("PackageVersion");
1891 QName attribArch
= new QName("Arch");
1893 if (cursor
.toChild(elementUserExts
)) {
1896 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
1897 cursor
.toChild(elementFvName
);
1898 String elementName
= cursor
.getTextValue();
1899 if (elementName
.equals(fvName
)) {
1900 cursor
.toNextSibling(elementIncludeModules
);
1901 if (cursor
.toFirstChild()) {
1904 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1905 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1906 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1907 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1908 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1910 }while (cursor
.toNextSibling());
1916 }while (cursor
.toNextSibling(elementUserExts
));
1922 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1923 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1926 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1927 while (li
.hasNext()) {
1928 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1929 if (!ues
.getUserID().equals("IMAGES")) {
1932 XmlCursor cursor
= ues
.newCursor();
1933 cursor
.toFirstChild();
1934 String elementName
= cursor
.getTextValue();
1935 if (elementName
.equals(oldFvName
)) {
1936 cursor
.setTextValue(newFvName
);
1943 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, int id
) {
1944 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1948 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1949 while (li
.hasNext()) {
1950 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1951 if (!ues
.getUserID().equals(userId
)) {
1954 if (ues
.getIdentifier()== null || ues
.getIdentifier().intValue() != id
) {
1957 XmlCursor cursor
= ues
.newCursor();
1958 cursor
.toFirstChild();
1959 String elementName
= cursor
.getTextValue();
1960 if (elementName
.equals(fvName
)) {
1971 private boolean versionEqual (String v1
, String v2
) {
1973 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1974 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1978 if (v1
!= null && v1
.equals(v2
)) {
1985 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
1986 boolean inList
= false;
1987 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
1988 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1989 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1990 QName attribUserId
= new QName ("UserID");
1991 QName attribId
= new QName ("Identifier");
1992 QName elementFvName
= new QName (xmlNs
, "FvName");
1993 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1994 QName attribModuleGuid
= new QName("ModuleGuid");
1995 QName attribModuleVersion
= new QName("ModuleVersion");
1996 QName attribPackageGuid
= new QName("PackageGuid");
1997 QName attribPackageVersion
= new QName("PackageVersion");
1998 QName attribArch
= new QName("Arch");
2000 if (cursor
.toChild(elementUserExts
)) {
2003 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2004 cursor
.toChild(elementFvName
);
2005 String elementName
= cursor
.getTextValue();
2006 if (elementName
.equals(fvName
)) {
2007 cursor
.toNextSibling(elementIncludeModules
);
2008 if (cursor
.toFirstChild()) {
2011 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2012 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2013 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2014 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2015 String ar
= cursor
.getAttributeText(attribArch
);
2016 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2019 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2022 if (!arch
.equalsIgnoreCase(ar
)) {
2025 if (!versionEqual(moduleVersion
, mv
)) {
2028 if (!versionEqual(packageVersion
, pv
)) {
2033 }while (cursor
.toNextSibling());
2039 }while (cursor
.toNextSibling(elementUserExts
));
2046 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2048 // if there is only one module before remove operation, the whole user extension should be removed.
2050 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2051 if (moduleAmount
== 1) {
2052 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2056 if (moduleAmount
> 1) {
2057 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2058 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2059 QName attribUserId
= new QName ("UserID");
2060 QName attribId
= new QName ("Identifier");
2061 QName elementFvName
= new QName (xmlNs
, "FvName");
2062 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2063 QName attribModuleGuid
= new QName("ModuleGuid");
2064 QName attribModuleVersion
= new QName("ModuleVersion");
2065 QName attribPackageGuid
= new QName("PackageGuid");
2066 QName attribPackageVersion
= new QName("PackageVersion");
2067 QName attribArch
= new QName("Arch");
2069 if (cursor
.toChild(elementUserExts
)) {
2072 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2073 cursor
.toChild(elementFvName
);
2074 String elementName
= cursor
.getTextValue();
2075 if (elementName
.equals(fvName
)) {
2076 cursor
.toNextSibling(elementIncludeModules
);
2077 if (cursor
.toFirstChild()) {
2080 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2081 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2082 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2083 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2084 String ar
= cursor
.getAttributeText(attribArch
);
2085 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2088 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2091 if (!arch
.equalsIgnoreCase(ar
)) {
2094 if (!versionEqual(moduleVersion
, mv
)) {
2097 if (!versionEqual(packageVersion
, pv
)) {
2101 }while (cursor
.toNextSibling());
2107 }while (cursor
.toNextSibling(elementUserExts
));
2113 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2114 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2118 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2119 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2120 QName elementModule
= new QName(xmlNs
, "Module");
2121 while (li
.hasNext()) {
2122 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2123 if (!ues
.getUserID().equals(userId
)) {
2126 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
2129 XmlCursor cursor
= ues
.newCursor();
2130 cursor
.toFirstChild();
2131 String elementName
= cursor
.getTextValue();
2132 if (elementName
.equals(fvName
)) {
2133 cursor
.toNextSibling(elementIncludeModules
);
2134 cursor
.toLastChild();
2135 cursor
.toEndToken();
2136 cursor
.toNextToken();
2137 cursor
.beginElement(elementModule
);
2138 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2139 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2140 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2142 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2143 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2144 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2147 cursor
.insertAttributeWithValue("Arch", arch
);
2156 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2157 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2158 if (udats
== null) {
2159 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2162 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2163 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2166 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2167 at
.setId(new Integer(id
));
2168 XmlCursor cursor
= at
.newCursor();
2169 if (fileName
!= null){
2170 at
.setFilename(fileName
);
2172 else if (cursor
.toChild(xmlNs
, "Filename")) {
2175 if (execOrder
!= null) {
2176 at
.setAntCmdOptions(execOrder
);
2178 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2184 public void removeBuildOptionsUserDefAntTask(int i
) {
2185 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2189 XmlCursor cursor
= o
.newCursor();
2190 if (cursor
.toFirstChild()) {
2191 for (int j
= 0; j
< i
; ++j
) {
2192 cursor
.toNextSibling();
2195 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2203 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2204 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2208 XmlCursor cursor
= o
.newCursor();
2209 if (cursor
.toFirstChild()) {
2210 for (int j
= 0; j
< i
; ++j
) {
2211 cursor
.toNextSibling();
2213 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2214 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2219 public int getBuildOptionsUserDefAntTaskCount() {
2220 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2221 if (udats
== null || udats
.getAntTaskList() == null) {
2225 return udats
.getAntTaskList().size();
2228 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2229 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2230 if (udats
== null || udats
.getAntTaskList() == null) {
2234 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2235 ListIterator li
= l
.listIterator();
2237 while (li
.hasNext()) {
2238 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2239 saa
[i
][0] = at
.getId() + "";
2240 saa
[i
][1] = saa
[i
][2] = "";
2241 if (at
.getFilename() != null){
2242 saa
[i
][1] = at
.getFilename();
2244 if (at
.getAntCmdOptions() != null) {
2245 saa
[i
][2] = at
.getAntCmdOptions();
2250 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2251 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2253 opts
= getfpdBuildOpts().addNewOptions();
2255 OptionDocument
.Option opt
= opts
.addNewOption();
2256 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2259 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2260 opt
.setStringValue(contents
);
2261 if (buildTargets
!= null) {
2262 opt
.setBuildTargets(buildTargets
);
2265 if (opt
.isSetBuildTargets()) {
2266 opt
.unsetBuildTargets();
2270 if (toolChain
!= null && toolChain
.length() > 0) {
2271 opt
.setToolChainFamily(toolChain
);
2274 if (opt
.isSetToolChainFamily()) {
2275 opt
.unsetToolChainFamily();
2279 if (tagName
!= null && tagName
.length() > 0) {
2280 opt
.setTagName(tagName
);
2283 if (opt
.isSetTagName()) {
2288 if (toolCmd
!= null && toolCmd
.length() > 0) {
2289 opt
.setToolCode(toolCmd
);
2292 if (opt
.isSetToolCode()) {
2293 opt
.unsetToolCode();
2298 if (archList
!= null) {
2299 opt
.setSupArchList(archList
);
2302 if (opt
.isSetSupArchList()) {
2303 opt
.unsetSupArchList();
2308 public void removeBuildOptionsOpt(int i
){
2310 XmlObject o
= getfpdBuildOpts().getOptions();
2315 XmlCursor cursor
= o
.newCursor();
2316 if (cursor
.toFirstChild()) {
2317 for (int j
= 0; j
< i
; ++j
) {
2318 cursor
.toNextSibling();
2321 if (getBuildOptionsOptCount() == 0) {
2329 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2330 XmlObject o
= getfpdBuildOpts().getOptions();
2335 XmlCursor cursor
= o
.newCursor();
2336 if (cursor
.toFirstChild()) {
2337 for (int j
= 0; j
< i
; ++j
) {
2338 cursor
.toNextSibling();
2340 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2341 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2346 public int getBuildOptionsOptCount(){
2347 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2350 return getfpdBuildOpts().getOptions().getOptionList().size();
2353 public void getBuildOptionsOpts(String
[][] saa
) {
2354 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2358 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2359 ListIterator li
= lOpt
.listIterator();
2361 while(li
.hasNext()) {
2362 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2363 if (opt
.getBuildTargets() != null) {
2364 saa
[i
][0] = listToString(opt
.getBuildTargets());
2366 saa
[i
][1] = opt
.getToolChainFamily();
2367 if (opt
.getSupArchList() != null){
2368 saa
[i
][2] = listToString(opt
.getSupArchList());
2371 saa
[i
][3] = opt
.getToolCode();
2372 saa
[i
][4] = opt
.getTagName();
2373 saa
[i
][5] = opt
.getStringValue();
2379 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2380 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2381 ffs
.setFfsKey(ffsKey
);
2383 ffs
.addNewSections().setEncapsulationType(type
);
2387 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2388 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2390 ffs
.addNewSections().setEncapsulationType(type
);
2394 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2395 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2396 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2397 attrib
.setName(name
);
2398 attrib
.setValue(value
);
2401 /**update jth attribute of ith ffs.
2405 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2406 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2407 XmlCursor cursor
= ffs
.newCursor();
2408 QName qAttrib
= new QName(xmlNs
, "Attribute");
2409 if (cursor
.toChild(qAttrib
)) {
2410 for (int k
= 0; k
< j
; ++k
) {
2411 cursor
.toNextSibling(qAttrib
);
2413 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2414 attrib
.setName(name
);
2415 attrib
.setValue(value
);
2420 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2421 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2422 XmlCursor cursor
= ffs
.newCursor();
2423 QName qAttrib
= new QName(xmlNs
, "Attribute");
2424 if (cursor
.toChild(qAttrib
)) {
2425 for (int k
= 0; k
< j
; ++k
) {
2426 cursor
.toNextSibling(qAttrib
);
2433 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2434 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2438 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2440 if (sections
== null){
2441 sections
= ffs
.addNewSections();
2443 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2446 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2447 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2448 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2449 if (sections
== null) {
2452 XmlCursor cursor
= sections
.newCursor();
2453 QName qSection
= new QName(xmlNs
, "Section");
2454 if (cursor
.toChild(qSection
)) {
2455 for (int k
= 0; k
< j
; ++k
) {
2456 cursor
.toNextSibling(qSection
);
2463 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2464 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2465 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2466 if (sections
== null) {
2469 XmlCursor cursor
= sections
.newCursor();
2470 QName qSection
= new QName(xmlNs
, "Section");
2471 if (cursor
.toChild(qSection
)) {
2472 for (int k
= 0; k
< j
; ++k
) {
2473 cursor
.toNextSibling(qSection
);
2475 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2476 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2481 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2482 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2486 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2488 if (sections
== null){
2489 sections
= ffs
.addNewSections();
2491 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2492 sections2
.setEncapsulationType(encapType
);
2493 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2496 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2497 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2498 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2499 if (sections
== null) {
2502 XmlCursor cursor
= sections
.newCursor();
2503 QName qSections
= new QName(xmlNs
, "Sections");
2504 if (cursor
.toChild(qSections
)) {
2505 for (int k
= 0; k
< j
; ++k
) {
2506 cursor
.toNextSibling(qSections
);
2513 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2514 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2515 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2516 if (sections
== null) {
2519 XmlCursor cursor
= sections
.newCursor();
2520 QName qSections
= new QName(xmlNs
, "Sections");
2521 if (cursor
.toChild(qSections
)) {
2522 for (int k
= 0; k
< j
; ++k
) {
2523 cursor
.toNextSibling(qSections
);
2525 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2526 sections2
.setEncapsulationType(type
);
2531 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2532 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2536 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2537 XmlCursor cursor
= sections
.newCursor();
2538 QName qSections
= new QName(xmlNs
, "Sections");
2539 if (cursor
.toChild(qSections
)){
2540 for (int k
= 0; k
< j
; ++k
) {
2541 cursor
.toNextSibling(qSections
);
2543 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2544 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2549 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2550 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2551 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2552 if (sections
== null) {
2555 XmlCursor cursor
= sections
.newCursor();
2556 QName qSections
= new QName(xmlNs
, "Sections");
2557 if (cursor
.toChild(qSections
)) {
2558 for (int l
= 0; l
< j
; ++l
) {
2559 cursor
.toNextSibling(qSections
);
2561 if (cursor
.toFirstChild()) {
2563 for (; m
< k
; ++m
) {
2564 cursor
.toNextSibling();
2576 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2577 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2578 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2579 if (sections
== null) {
2582 XmlCursor cursor
= sections
.newCursor();
2583 QName qSections
= new QName(xmlNs
, "Sections");
2584 if (cursor
.toChild(qSections
)) {
2585 for (int l
= 0; l
< j
; ++l
) {
2586 cursor
.toNextSibling(qSections
);
2588 if (cursor
.toFirstChild()) {
2589 for (int m
= 0; m
< k
; ++m
) {
2590 cursor
.toNextSibling();
2592 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2593 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2599 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2600 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2604 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2605 XmlCursor cursor
= sections
.newCursor();
2606 QName qSections
= new QName(xmlNs
, "Sections");
2607 if (cursor
.toChild(qSections
)){
2608 for (int k
= 0; k
< j
; ++k
) {
2609 cursor
.toNextSibling(qSections
);
2611 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2612 if (sections2
.getSectionList() == null){
2616 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2617 while(li
.hasNext()) {
2618 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2619 // if (section.isSetSectionType()) {
2620 al
.add(section
.getSectionType()+"");
2629 public int getBuildOptionsFfsCount(){
2630 if (getfpdBuildOpts().getFfsList() == null) {
2633 return getfpdBuildOpts().getFfsList().size();
2636 public void getBuildOptionsFfsKey(String
[][] saa
) {
2637 if (getfpdBuildOpts().getFfsList() == null) {
2640 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2642 while(li
.hasNext()){
2643 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2644 saa
[i
][0] = ffs
.getFfsKey();
2649 public void updateBuildOptionsFfsKey(int i
, String key
) {
2650 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2654 /**Get ith FFS key and contents.
2657 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2658 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2662 sa
[0] = ffs
.getFfsKey();
2663 if (ffs
.getSections() != null) {
2664 if(ffs
.getSections().getEncapsulationType() != null){
2665 sa
[1] = ffs
.getSections().getEncapsulationType();
2667 if (ffs
.getSections().getSectionList() != null){
2668 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2669 while (li
.hasNext()) {
2670 firstLevelSection
.add(li
.next().getSectionType()+"");
2673 if (ffs
.getSections().getSectionsList() != null) {
2674 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2675 while(li
.hasNext()) {
2676 firstLevelSections
.add(li
.next().getEncapsulationType());
2680 if (ffs
.getAttributeList() != null) {
2681 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2682 while(li
.hasNext()) {
2683 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2684 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2693 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2694 XmlObject o
= getfpdBuildOpts();
2695 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2697 XmlCursor cursor
= o
.newCursor();
2698 QName qFfs
= new QName(xmlNs
, "Ffs");
2699 if (cursor
.toChild(qFfs
)) {
2700 for (int j
= 0; j
< i
; ++j
) {
2701 cursor
.toNextSibling(qFfs
);
2703 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2709 public void removeBuildOptionsFfs(int i
) {
2710 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2715 XmlCursor cursor
= ffs
.newCursor();
2722 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2723 if (fpdPlatformDefs
== null){
2724 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2726 return fpdPlatformDefs
;
2729 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2730 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2733 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2734 while(li
.hasNext()) {
2735 archs
.add(li
.next());
2739 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2740 if (archs
!= null) {
2741 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2744 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2745 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2746 // cursor.removeXml();
2748 // cursor.dispose();
2752 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2753 if (getfpdPlatformDefs().getBuildTargets() == null) {
2756 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2757 while(li
.hasNext()) {
2758 targets
.add(li
.next());
2762 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2763 getfpdPlatformDefs().setBuildTargets(targets
);
2766 public void genPlatformDefsSkuInfo(String id
, String name
) {
2767 SkuInfoDocument
.SkuInfo skuInfo
= null;
2768 if (getfpdPlatformDefs().getSkuInfo() == null) {
2769 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2771 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2772 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2773 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2774 skuName
.setSkuID(new BigInteger("0"));
2775 skuName
.setStringValue("DEFAULT");
2777 if (id
.equals("0")) {
2780 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2781 skuName
.setSkuID(new BigInteger(id
));
2782 skuName
.setStringValue(name
);
2785 public int getPlatformDefsSkuInfoCount(){
2786 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2789 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2792 public void getPlatformDefsSkuInfos(String
[][] saa
){
2793 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2794 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2795 removeElement(getfpdDynPcdBuildDefs());
2796 fpdDynPcdBuildDefs
= null;
2801 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2802 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2804 while(li
.hasNext()) {
2805 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2806 saa
[i
][0] = sku
.getSkuID()+"";
2807 saa
[i
][1] = sku
.getStringValue();
2812 public void removePlatformDefsSkuInfo(int i
) {
2813 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2814 if (skuInfo
== null || i
== 0) {
2818 XmlCursor cursor
= skuInfo
.newCursor();
2819 if (cursor
.toFirstChild()) {
2820 for (int j
= 0; j
< i
; ++j
) {
2821 cursor
.toNextSibling();
2828 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2829 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2830 if (skuInfo
== null || i
== 0) {
2834 XmlCursor cursor
= skuInfo
.newCursor();
2835 if (cursor
.toFirstChild()) {
2836 for (int j
= 0; j
< i
; ++j
) {
2837 cursor
.toNextSibling();
2839 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2840 sku
.setSkuID(new BigInteger(id
));
2841 sku
.setStringValue(name
);
2846 public String
getPlatformDefsInterDir(){
2847 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2850 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2853 public void setPlatformDefsInterDir(String interDir
){
2854 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2857 public String
getPlatformDefsOutputDir() {
2858 return getfpdPlatformDefs().getOutputDirectory();
2861 public void setPlatformDefsOutputDir(String outputDir
) {
2862 if (outputDir
!= null && outputDir
.length() > 0) {
2863 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2866 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2867 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2874 public FlashDocument
.Flash
getfpdFlash() {
2875 if (fpdFlash
== null) {
2876 fpdFlash
= fpdRoot
.addNewFlash();
2881 public void genFlashDefinitionFile(String file
) {
2882 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2884 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2887 fdf
.setStringValue(file
);
2890 public String
getFlashDefinitionFile() {
2891 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2896 return fdf
.getStringValue();
2899 public void genFvImagesNameValue(String name
, String value
) {
2901 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2903 fi
= getfpdFlash().addNewFvImages();
2906 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2911 public void removeFvImagesNameValue(int i
){
2913 XmlObject o
= getfpdFlash().getFvImages();
2918 QName qNameValue
= new QName(xmlNs
, "NameValue");
2919 XmlCursor cursor
= o
.newCursor();
2920 if (cursor
.toChild(qNameValue
)) {
2921 for (int j
= 0; j
< i
; ++j
) {
2922 cursor
.toNextSibling(qNameValue
);
2929 public void updateFvImagesNameValue(int i
, String name
, String value
){
2931 XmlObject o
= getfpdFlash().getFvImages();
2936 QName qNameValue
= new QName(xmlNs
, "NameValue");
2937 XmlCursor cursor
= o
.newCursor();
2938 if (cursor
.toChild(qNameValue
)) {
2939 for (int j
= 0; j
< i
; ++j
) {
2940 cursor
.toNextSibling(qNameValue
);
2942 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2949 public int getFvImagesNameValueCount() {
2951 FvImagesDocument
.FvImages fi
= null;
2952 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2955 return fi
.getNameValueList().size();
2958 public void getFvImagesNameValues(String
[][] nv
) {
2960 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2964 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2966 ListIterator li
= l
.listIterator();
2967 while (li
.hasNext()) {
2968 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2970 nv
[i
][0] = e
.getName();
2971 nv
[i
][1] = e
.getValue();
2977 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2978 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2979 if (fis
== null || fis
.getFvImageList() == null) {
2983 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2984 while (li
.hasNext()) {
2985 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2986 if (fi
.getType().toString().equals("ImageName")) {
2987 vImageNames
.addAll(fi
.getFvImageNamesList());
2993 public void addFvImageFvImageNames (String
[] fvNames
) {
2994 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2995 if (fis
== null || fis
.getFvImageList() == null) {
2996 genFvImagesFvImage (fvNames
, "ImageName", null);
3000 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3001 while (li
.hasNext()) {
3002 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3003 if (fi
.getType().toString().equals("ImageName")) {
3004 addFvImageNamesInFvImage (fi
, fvNames
);
3008 genFvImagesFvImage (fvNames
, "ImageName", null);
3011 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3013 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3014 fi
.addFvImageNames(fvNames
[i
]);
3018 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3019 XmlObject o
= getfpdFlash().getFvImages();
3023 XmlCursor cursor
= o
.newCursor();
3024 QName qFvImage
= new QName(xmlNs
, "FvImage");
3025 if (cursor
.toChild(qFvImage
)) {
3026 for (int j
= 0; j
< i
; ++j
) {
3027 cursor
.toNextSibling(qFvImage
);
3029 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3030 addFvImageNamesInFvImage(fi
, fvNames
);
3035 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3037 FvImagesDocument
.FvImages fis
= null;
3038 if ((fis
= getfpdFlash().getFvImages()) == null) {
3039 fis
= getfpdFlash().addNewFvImages();
3043 //gen FvImage with FvImageNames array
3045 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3046 for (int i
= 0; i
< names
.length
; ++i
) {
3047 fi
.addFvImageNames(names
[i
]);
3049 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3050 if (options
!= null){
3051 setFvImagesFvImageFvImageOptions(options
, fi
);
3055 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3056 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3058 fio
= fi
.addNewFvImageOptions();
3061 Set
<String
> key
= options
.keySet();
3062 Iterator
<String
> i
= key
.iterator();
3063 while (i
.hasNext()) {
3065 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3066 String k
= (String
)i
.next();
3069 nv
.setValue((String
)options
.get(k
));
3076 public void removeFvImagesFvImage(int i
) {
3078 XmlObject o
= getfpdFlash().getFvImages();
3083 QName qFvImage
= new QName(xmlNs
, "FvImage");
3084 XmlCursor cursor
= o
.newCursor();
3085 if (cursor
.toChild(qFvImage
)) {
3086 for (int j
= 0; j
< i
; ++j
) {
3087 cursor
.toNextSibling(qFvImage
);
3096 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3098 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3099 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3102 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3103 while (li
.hasNext()) {
3104 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3105 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3106 if (fi
.getFvImageNamesList().size() == 0) {
3112 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3113 XmlObject o
= getfpdFlash().getFvImages();
3117 XmlCursor cursor
= o
.newCursor();
3118 QName qFvImage
= new QName(xmlNs
, "FvImage");
3119 if (cursor
.toChild(qFvImage
)) {
3120 for (int j
= 0; j
< i
; ++j
) {
3121 cursor
.toNextSibling(qFvImage
);
3123 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3124 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3130 * @param oldFvName The FV Name to be replaced.
3131 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3133 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3134 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3135 XmlCursor cursor
= fi
.newCursor();
3137 if (cursor
.toChild(qFvImageNames
)) {
3139 String xmlValue
= cursor
.getTextValue();
3140 if (xmlValue
.equals(oldFvName
)){
3141 if (newFvName
!= null) {
3142 cursor
.setTextValue(newFvName
);
3148 }while (cursor
.toNextSibling(qFvImageNames
));
3154 /**update the Type attribute of ith FvImage with new type.
3158 public void updateFvImagesFvImageType (int i
, String type
) {
3159 XmlObject o
= getfpdFlash().getFvImages();
3163 XmlCursor cursor
= o
.newCursor();
3164 QName qFvImage
= new QName(xmlNs
, "FvImage");
3165 if (cursor
.toChild(qFvImage
)) {
3166 for (int j
= 0; j
< i
; ++j
) {
3167 cursor
.toNextSibling(qFvImage
);
3169 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3170 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3175 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3177 XmlObject o
= getfpdFlash().getFvImages();
3181 XmlCursor cursor
= o
.newCursor();
3182 QName qFvImage
= new QName(xmlNs
, "FvImage");
3183 if (cursor
.toChild(qFvImage
)) {
3184 for (int j
= 0; j
< i
; ++j
) {
3185 cursor
.toNextSibling(qFvImage
);
3187 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3188 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3191 // remove old FvImageNames before adding new ones
3193 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3194 cursor
.toChild(qFvImageNames
);
3196 while (cursor
.toNextSibling(qFvImageNames
)) {
3200 for (int k
= 0; k
< names
.length
; ++k
) {
3201 fi
.addFvImageNames(names
[k
]);
3204 // remove old FvImageOptions before adding new options
3206 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3207 cursor
.toNextSibling(qFvImageOptions
);
3210 setFvImagesFvImageFvImageOptions(options
, fi
);
3215 public int getFvImagesFvImageCount(String type
) {
3217 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3220 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3221 ListIterator li
= l
.listIterator();
3223 while(li
.hasNext()) {
3224 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3225 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3235 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3236 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3237 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3240 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3241 ListIterator li
= l
.listIterator();
3242 while(li
.hasNext()) {
3243 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3244 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3247 if (fi
.getFvImageNamesList().contains(fvName
)) {
3256 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3258 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3260 if (getfpdFlash().getFvImages() == null) {
3263 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3267 ListIterator li
= l
.listIterator();
3269 while(li
.hasNext()) {
3270 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3271 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3275 // get FvImageNames array, space separated
3277 List
<String
> lfn
= fi
.getFvImageNamesList();
3278 ListIterator lfni
= lfn
.listIterator();
3280 while (lfni
.hasNext()) {
3281 saa
[i
][0] += (String
)lfni
.next();
3284 saa
[i
][0] = saa
[i
][0].trim();
3286 saa
[i
][1] = fi
.getType()+"";
3292 public void removeFvImageNameValue (int i
, String attributeName
) {
3293 XmlObject o
= getfpdFlash().getFvImages();
3297 XmlCursor cursor
= o
.newCursor();
3298 QName qFvImage
= new QName(xmlNs
, "FvImage");
3299 if (cursor
.toChild(qFvImage
)) {
3300 for (int j
= 0; j
< i
; ++j
) {
3301 cursor
.toNextSibling(qFvImage
);
3303 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3304 removeFvImageNameValue (fi
, attributeName
);
3308 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3310 * @param attributeName
3312 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3313 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3314 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3315 while (li
.hasNext()) {
3316 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3317 if (nv
.getName().equals(attributeName
)) {
3324 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3325 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3326 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3327 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3328 removeFvImageNameValue (fi
, optName
);
3332 /**Add name-value pair to FvImage element with type.
3333 * @param fvName FV name to add name-value pair.
3334 * @param type FvImage attribute.
3338 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3339 boolean fvImageExists
= false;
3340 if (getfpdFlash().getFvImages() != null) {
3342 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3344 ListIterator li
= l
.listIterator();
3345 while (li
.hasNext()) {
3346 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3347 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3350 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3353 fvImageExists
= true;
3354 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3359 if (!fvImageExists
) {
3360 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3361 map
.put(name
, value
);
3362 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3366 /**Add to all FvImage elements with type, the name-value pair.
3371 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3372 if (getfpdFlash().getFvImages() == null) {
3375 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3379 ListIterator li
= l
.listIterator();
3380 while(li
.hasNext()) {
3381 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3382 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3385 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3390 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3391 XmlObject o
= getfpdFlash().getFvImages();
3395 XmlCursor cursor
= o
.newCursor();
3396 QName qFvImage
= new QName(xmlNs
, "FvImage");
3397 if (cursor
.toChild(qFvImage
)) {
3398 for (int j
= 0; j
< i
; ++j
) {
3399 cursor
.toNextSibling(qFvImage
);
3401 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3402 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3407 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3413 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3414 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3415 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3418 if (newName
!= null && !newName
.equals(name
)) {
3419 nv
.setName(newName
);
3424 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3425 if (cursor
.toFirstChild()) {
3427 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3428 if (nv
.getName().equals(name
)) {
3430 if (newName
!= null && !newName
.equals(name
)) {
3431 nv
.setName(newName
);
3436 }while (cursor
.toNextSibling());
3439 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3442 if (newName
!= null && !newName
.equals(name
)) {
3443 nv
.setName(newName
);
3448 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3449 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3450 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3451 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3452 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3456 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3459 while (li
.hasNext()) {
3460 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3461 m
.put(nv
.getName(), nv
.getValue());
3466 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3467 XmlObject o
= getfpdFlash().getFvImages();
3473 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3474 Vector
<String
> vFvNames
= new Vector
<String
>();
3477 XmlCursor cursor
= o
.newCursor();
3478 QName qFvImage
= new QName(xmlNs
, "FvImage");
3479 if (cursor
.toChild(qFvImage
)) {
3482 vFvNames
.removeAllElements();
3483 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3484 vFvNames
.add(fvNameArray
[i
]);
3486 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3487 if (!fi
.getType().toString().equals(type
)) {
3490 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3493 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3494 while (li
.hasNext()) {
3495 String name
= li
.next();
3496 vFvNames
.remove(name
);
3498 if (vFvNames
.size() == 0) {
3503 }while (cursor
.toNextSibling(qFvImage
));
3509 /**Get FvImage Options for FvImage i
3510 * @param i the ith FvImage
3512 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3513 XmlObject o
= getfpdFlash().getFvImages();
3517 XmlCursor cursor
= o
.newCursor();
3518 QName qFvImage
= new QName(xmlNs
, "FvImage");
3519 if (cursor
.toChild(qFvImage
)) {
3520 for (int j
= 0; j
< i
; ++j
) {
3521 cursor
.toNextSibling(qFvImage
);
3523 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3524 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3528 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3529 while(li
.hasNext()){
3530 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3531 m
.put(nv
.getName(), nv
.getValue());
3538 Get platform header element
3539 @return PlatformHeaderDocument.PlatformHeader
3541 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3542 if (fpdHdr
== null) {
3543 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3549 public String
getFpdHdrPlatformName() {
3550 return getFpdHdr().getPlatformName();
3553 public String
getFpdHdrGuidValue() {
3554 return getFpdHdr().getGuidValue();
3557 public String
getFpdHdrVer() {
3558 return getFpdHdr().getVersion();
3561 public String
getFpdHdrAbs() {
3562 return getFpdHdr().getAbstract();
3565 public String
getFpdHdrDescription() {
3566 return getFpdHdr().getDescription();
3569 public String
getFpdHdrCopyright() {
3570 return getFpdHdr().getCopyright();
3573 public String
getFpdHdrLicense() {
3574 LicenseDocument
.License l
= getFpdHdr().getLicense();
3578 return l
.getStringValue();
3581 public String
getFpdHdrUrl() {
3582 LicenseDocument
.License l
= getFpdHdr().getLicense();
3589 public String
getFpdHdrSpec() {
3591 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3592 // return getFpdHdr().getSpecification();
3595 public void setFpdHdrPlatformName(String name
){
3596 getFpdHdr().setPlatformName(name
);
3599 public void setFpdHdrGuidValue(String guid
){
3600 getFpdHdr().setGuidValue(guid
);
3603 public void setFpdHdrVer(String v
){
3604 getFpdHdr().setVersion(v
);
3607 public void setFpdHdrAbs(String abs
) {
3608 getFpdHdr().setAbstract(abs
);
3611 public void setFpdHdrDescription(String desc
){
3612 getFpdHdr().setDescription(desc
);
3615 public void setFpdHdrCopyright(String cr
) {
3616 getFpdHdr().setCopyright(cr
);
3619 public void setFpdHdrLicense(String license
){
3620 LicenseDocument
.License l
= getFpdHdr().getLicense();
3622 getFpdHdr().addNewLicense().setStringValue(license
);
3625 l
.setStringValue(license
);
3629 public void setFpdHdrUrl(String url
){
3630 LicenseDocument
.License l
= getFpdHdr().getLicense();
3636 public void setFpdHdrSpec(String s
){
3637 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3638 getFpdHdr().setSpecification(s
);
3641 Save the processed xml contents to file
3643 @param fpdFile The file to save xml contents
3644 @throws IOException Exceptions during file operation
3646 public void saveAs(File fpdFile
) throws IOException
{
3648 XmlOptions options
= new XmlOptions();
3650 options
.setCharacterEncoding("UTF-8");
3651 options
.setSavePrettyPrint();
3652 options
.setSavePrettyPrintIndent(2);
3654 fpdd
.save(fpdFile
, options
);
3655 } catch (IOException e
) {
3656 e
.printStackTrace();
3661 private String
listToString(List l
) {
3666 ListIterator li
= l
.listIterator();
3667 while(li
.hasNext()) {
3674 private void removeElement(XmlObject o
) {
3675 XmlCursor cursor
= o
.newCursor();
3681 class PcdItemTypeConflictException
extends Exception
{
3686 private static final long serialVersionUID
= 1L;
3687 private String details
= null;
3689 PcdItemTypeConflictException (String pcdName
, String info
) {
3690 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3692 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3695 details
= pcdName
+ " ItemType Conflicts with " + info
;
3699 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3700 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3701 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3702 String moduleInfo1
= "";
3703 String moduleInfo2
= "";
3705 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3708 moduleInfo1
= info1
;
3712 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3715 moduleInfo2
= info2
;
3718 details
= pcdName
+ " ItemType Conflicts in " + moduleInfo1
+ " and " + moduleInfo2
;
3721 public String
getMessage() {
3726 class PcdDeclNotFound
extends Exception
{
3731 private static final long serialVersionUID
= 1L;
3732 private String details
= null;
3734 PcdDeclNotFound(String info
) {
3735 details
= "PcdDeclNotFound: " + info
;
3738 public String
getMessage() {
3743 class PcdValueMalFormed
extends Exception
{
3748 private static final long serialVersionUID
= 1L;
3749 private String details
= null;
3751 PcdValueMalFormed(String info
) {
3752 details
= "PcdValueMalFormed: " + info
;
3755 public String
getMessage() {