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();
393 String mv
= moduleSa
.getModuleVersion();
394 String pg
= moduleSa
.getPackageGuid();
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
).contains(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
);
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
) throws Exception
{
613 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
614 if (msa
.getPcdCoded() == null) {
618 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
619 m
.put("ModuleSurfaceArea", msa
);
620 SurfaceAreaQuery
.setDoc(m
);
621 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
623 // First look through MSA pcd entries.
625 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
626 ListIterator li
= l
.listIterator();
627 while(li
.hasNext()) {
628 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
629 if (!msaPcd
.getCName().equals(cName
)) {
632 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
635 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
636 if (spdPcd
== null) {
640 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
643 // Get Pcd help text and original item type.
645 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
646 sa
[1] = msaPcd
.getPcdItemType()+"";
647 sa
[2] = msa
.getModuleDefinitions().getBinaryModule()+"";
661 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
662 int libCount
= getLibraryInstancesCount(moduleKey
);
663 String
[][] saaLib
= new String
[libCount
][5];
664 getLibraryInstances(moduleKey
, saaLib
);
665 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
666 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
668 // create vector for module & library instance MIs.
671 for (int j
= 0; j
< saaLib
.length
; ++j
) {
672 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
673 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
677 int pcdSourceCount
= 0;
678 for (int i
= 0; i
< vMi
.size(); ++i
) {
679 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
684 if (pcdSourceCount
< 2) {
693 /**Remove PCDBuildDefinition entries from ModuleSA
694 * @param moduleKey identifier of ModuleSA.
695 * @param consumer where these entries come from.
697 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
699 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
700 if (msa
.getPcdCoded() == null) {
704 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
705 ListIterator li
= l
.listIterator();
707 while(li
.hasNext()) {
708 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
709 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
710 if (moduleSA
.getPcdBuildDefinition() != null) {
711 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
713 if (cursor
.toFirstChild()) {
715 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
717 String cName
= msaPcd
.getCName();
718 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
719 if (cName
.equals(pcdData
.getCName())
720 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
722 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
727 } while (cursor
.toNextSibling());
731 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
740 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
742 public int getLibraryInstancesCount(String key
) {
743 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
744 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
747 return msa
.getLibraries().getInstanceList().size();
750 public void getLibraryInstances(String key
, String
[][] saa
){
751 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
752 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
756 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
757 for (int i
= 0; i
< saa
.length
; ++i
) {
758 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
759 saa
[i
][1] = instance
.getModuleGuid();
760 saa
[i
][2] = instance
.getModuleVersion();
761 saa
[i
][3] = instance
.getPackageGuid();
762 saa
[i
][4] = instance
.getPackageVersion();
766 public void removeLibraryInstance(String key
, int i
) {
767 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
768 if (msa
== null || msa
.getLibraries() == null){
772 XmlCursor cursor
= msa
.getLibraries().newCursor();
773 if (cursor
.toFirstChild()) {
774 for (int j
= 0; j
< i
; ++j
) {
775 cursor
.toNextSibling();
778 while (cursor
.hasPrevToken()) {
779 cursor
.toPrevToken();
780 if (!cursor
.isText()) {
783 String s
= cursor
.getTextValue();
784 if (s
.matches(regExpNewLineAndSpaces
)) {
789 if (cursor
.isComment()) {
794 if (getLibraryInstancesCount(key
) == 0) {
803 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
804 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
806 msa
= getfpdFrameworkModules().addNewModuleSA();
808 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
810 libs
= msa
.addNewLibraries();
813 String mn
= libMi
.getName();
814 String mg
= libMi
.getGuid();
815 String mv
= libMi
.getVersion();
816 String pn
= libMi
.getPackageId().getName();
817 String pg
= libMi
.getPackageId().getGuid();
818 String pv
= libMi
.getPackageId().getVersion();
819 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
820 XmlCursor cursor
= instance
.newCursor();
822 String comment
= "Pkg: " + pn
+ " Mod: " + mn
823 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
824 cursor
.insertComment(comment
);
833 instance
.setModuleGuid(mg
);
834 instance
.setModuleVersion(mv
);
835 instance
.setPackageGuid(pg
);
836 instance
.setPackageVersion(pv
);
840 public String
getFvBinding(String moduleKey
){
841 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
842 return getFvBinding (moduleSa
);
845 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
846 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
849 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
852 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
853 if (moduleSa
== null ) {
856 if (fvBinding
== null || fvBinding
.length() == 0) {
857 if(moduleSa
.getModuleSaBuildOptions() != null){
858 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
862 if(moduleSa
.getModuleSaBuildOptions() == null){
863 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
866 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
870 public void setFvBinding(String moduleKey
, String fvBinding
){
871 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
872 setFvBinding (moduleSa
, fvBinding
);
875 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
876 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
880 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
881 String
[] fvNamesArray
= fvNameList
.split(" ");
883 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
884 if (fvNamesArray
[i
].equals(fvName
)) {
892 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
893 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
897 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
898 String
[] fvNamesArray
= fvNameList
.split(" ");
900 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
901 if (fvNamesArray
[i
].equals(fvName
)) {
906 // jump over where the input fvName occurs in the original Fv list.
907 if (occursAt
!= -1) {
908 String newFvNameList
= " ";
909 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
913 newFvNameList
+= fvNamesArray
[i
];
915 setFvBinding (moduleSa
, newFvNameList
.trim());
921 * @param fvName The FV name that to be removed from FvBinding List.
923 public void removeFvBindingAll (String fvName
) {
924 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
925 removeElement(getfpdFrameworkModules());
926 fpdFrameworkModules
= null;
930 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
931 while (li
.hasNext()) {
932 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
933 removeFvBinding (moduleSa
, fvName
);
937 public void appendFvBindingAll (String fvName
) {
938 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
939 removeElement(getfpdFrameworkModules());
940 fpdFrameworkModules
= null;
944 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
945 while (li
.hasNext()) {
946 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
947 appendFvBinding (moduleSa
, fvName
);
951 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
952 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
953 removeElement(getfpdFrameworkModules());
954 fpdFrameworkModules
= null;
958 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
959 while (li
.hasNext()) {
960 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
961 String fvBinding
= getFvBinding (moduleSa
);
962 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
963 appendFvBinding (moduleSa
, newFvName
);
968 public void appendFvBinding (String moduleKey
, String fvName
) {
969 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
970 appendFvBinding (moduleSa
, fvName
);
973 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
974 if (moduleSa
== null) {
978 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
979 setFvBinding(moduleSa
, fvName
);
983 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
984 String newFvNameList
= fvNameList
+ " " + fvName
;
985 setFvBinding (moduleSa
, newFvNameList
.trim());
988 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
990 appendFvBinding (moduleKey
, fvName
);
993 public String
getFfsFileNameGuid(String moduleKey
){
994 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
995 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
998 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1001 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1002 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1006 if(msa
.getModuleSaBuildOptions() == null){
1007 msa
.addNewModuleSaBuildOptions();
1010 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1011 if (fileGuid
!= null) {
1012 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1015 XmlCursor cursor
= msaBuildOpts
.newCursor();
1016 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1024 public String
getFfsFormatKey(String moduleKey
){
1025 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1026 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1029 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1032 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1033 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1037 if(msa
.getModuleSaBuildOptions() == null){
1038 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1041 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1044 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1045 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1046 moduleSa
.setForceDebug(dbgEnable
);
1049 public boolean getModuleSAForceDebug (int i
) {
1050 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1051 if (moduleSa
.getForceDebug() == true) {
1057 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1058 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1059 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1060 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1064 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1065 ListIterator li
= lOpt
.listIterator();
1067 while(li
.hasNext()) {
1068 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1069 if (opt
.getBuildTargets() != null) {
1070 saa
[i
][0] = listToString(opt
.getBuildTargets());
1072 saa
[i
][1] = opt
.getToolChainFamily();
1073 saa
[i
][2] = opt
.getTagName();
1074 saa
[i
][3] = opt
.getToolCode();
1076 if (opt
.getSupArchList() != null){
1077 saa
[i
][4] = listToString(opt
.getSupArchList());
1083 saa
[i
][5] = opt
.getStringValue();
1089 public int getModuleSAOptionsCount(String moduleKey
){
1090 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1091 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1092 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1095 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1098 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1099 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1100 if (msa
.getModuleSaBuildOptions() == null) {
1101 msa
.addNewModuleSaBuildOptions();
1103 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1104 msa
.getModuleSaBuildOptions().addNewOptions();
1106 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1107 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1110 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1111 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1112 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1115 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1116 XmlCursor cursor
= opts
.newCursor();
1117 if (cursor
.toFirstChild()) {
1118 for (int j
= 0; j
< i
; ++j
){
1119 cursor
.toNextSibling();
1122 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1130 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1131 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1132 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1135 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1136 XmlCursor cursor
= opts
.newCursor();
1137 if (cursor
.toFirstChild()) {
1138 for (int j
= 0; j
< i
; ++j
){
1139 cursor
.toNextSibling();
1141 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1142 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1147 /**add pcd information of module mi to a ModuleSA.
1149 * @param moduleSa if null, generate a new ModuleSA.
1151 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1152 //ToDo add Arch filter
1155 if (moduleSa
== null) {
1156 moduleSa
= genModuleSA(mi
, arch
);
1159 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
1160 if (msa
.getPcdCoded() == null) {
1164 Map
<String
, XmlObject
> m
= new HashMap
<String
, XmlObject
>();
1165 m
.put("ModuleSurfaceArea", msa
);
1166 SurfaceAreaQuery
.setDoc(m
);
1167 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1169 // Implementing InitializePlatformPcdBuildDefinitions
1171 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1172 ListIterator li
= l
.listIterator();
1173 while(li
.hasNext()) {
1174 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
1175 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1176 if (spdPcd
== null) {
1180 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module " + mi
.getName());
1183 // AddItem to ModuleSA PcdBuildDefinitions
1185 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1187 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType()+"", defaultVal
, moduleSa
);
1191 catch (Exception e
){
1198 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1200 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1201 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1203 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1207 for (int j
= 0; j
< xo
.length
; ++j
) {
1208 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1209 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1210 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1215 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1226 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1227 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1228 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1229 XmlCursor cursor
= msa
.newCursor();
1231 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1232 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1233 cursor
.insertComment(comment
);
1236 e
.printStackTrace();
1241 msa
.setModuleGuid(mi
.getGuid());
1242 msa
.setModuleVersion(mi
.getVersion());
1243 msa
.setPackageGuid(pi
.getGuid());
1244 msa
.setPackageVersion(pi
.getVersion());
1246 Vector
<String
> v
= new Vector
<String
>();
1248 msa
.setSupArchList(v
);
1254 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
, ModuleSADocument
.ModuleSA moduleSa
)
1255 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1256 if (moduleSa
.getPcdBuildDefinition() == null){
1257 moduleSa
.addNewPcdBuildDefinition();
1260 // constructe pcd to modulesa mapping first.
1261 // Attention : for any error condition, remove from map this pcd.
1263 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1264 if (pcdConsumer
== null) {
1265 pcdConsumer
= new ArrayList
<String
>();
1268 // Check whether this PCD has already added to ModuleSA, if so, just return.
1270 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1271 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1272 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1273 String pcdInfo
= pcdConsumer
.get(i
);
1274 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1279 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1281 if (pcdConsumer
.size() > 0) {
1283 itemType
= itemType (pcdConsumer
.get(0));
1285 String listValue
= moduleInfo
+ " " + itemType
;
1286 pcdConsumer
.add(listValue
);
1287 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1289 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1290 fpdPcd
.setCName(cName
);
1291 fpdPcd
.setToken(token
);
1292 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1293 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1294 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1296 if (defaultVal
!= null){
1297 fpdPcd
.setValue(defaultVal
);
1300 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1301 fpdPcd
.setValue("0");
1303 if (dataType
.equals("BOOLEAN")){
1304 fpdPcd
.setValue("FALSE");
1306 if (dataType
.equals("VOID*")) {
1307 fpdPcd
.setValue("");
1311 // Using existing pcd value, if this pcd already exists in other moduleSa.
1313 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1314 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1317 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1320 if (dataType
.equals("UINT8")){
1321 fpdPcd
.setMaxDatumSize(1);
1323 if (dataType
.equals("UINT16")) {
1324 fpdPcd
.setMaxDatumSize(2);
1326 if (dataType
.equals("UINT32")) {
1327 fpdPcd
.setMaxDatumSize(4);
1329 if (dataType
.equals("UINT64")){
1330 fpdPcd
.setMaxDatumSize(8);
1332 if (dataType
.equals("BOOLEAN")){
1333 fpdPcd
.setMaxDatumSize(1);
1335 if (dataType
.equals("VOID*")) {
1336 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1337 fpdPcd
.setMaxDatumSize(maxSize
);
1341 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1342 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1344 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1345 // so need to add one dyn pcd.
1347 if (al
.size() == 1) {
1348 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1354 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1355 if (datum
== null) {
1358 char ch
= datum
.charAt(0);
1362 // For void* type PCD, only three datum is support:
1363 // 1) Unicode: string with start char is "L"
1364 // 2) Ansci: String is ""
1365 // 3) byte array: String start char "{"
1368 start
= datum
.indexOf('\"');
1369 end
= datum
.lastIndexOf('\"');
1370 if ((start
> end
) ||
1371 (end
> datum
.length())||
1372 ((start
== end
) && (datum
.length() > 0))) {
1373 //ToDo Error handling here
1374 throw new PcdValueMalFormed (datum
);
1377 strValue
= datum
.substring(start
+ 1, end
);
1378 return strValue
.length() * 2;
1379 } else if (ch
== '\"'){
1380 start
= datum
.indexOf('\"');
1381 end
= datum
.lastIndexOf('\"');
1382 if ((start
> end
) ||
1383 (end
> datum
.length())||
1384 ((start
== end
) && (datum
.length() > 0))) {
1385 throw new PcdValueMalFormed (datum
);
1387 strValue
= datum
.substring(start
+ 1, end
);
1388 return strValue
.length();
1389 } else if (ch
=='{') {
1390 String
[] strValueArray
;
1392 start
= datum
.indexOf('{');
1393 end
= datum
.lastIndexOf('}');
1394 strValue
= datum
.substring(start
+ 1, end
);
1395 strValue
= strValue
.trim();
1396 if (strValue
.length() == 0) {
1399 strValueArray
= strValue
.split(",");
1400 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1401 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1404 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1405 // "it must be a byte array. But the element of %s exceed the byte range",
1406 throw new PcdValueMalFormed (datum
);
1409 return strValueArray
.length
;
1413 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1414 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1415 // "2) ANSIC string: like \"xxx\";\r\n"+
1416 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1417 // "but the datum in seems does not following above format!",
1418 throw new PcdValueMalFormed (datum
);
1423 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1424 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1429 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1431 return dynPcdMap
.get(pcdKey
);
1434 public int getDynamicPcdBuildDataCount() {
1435 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1436 removeElement(getfpdDynPcdBuildDefs());
1437 fpdDynPcdBuildDefs
= null;
1440 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1443 public void getDynamicPcdBuildData(String
[][] saa
) {
1444 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1445 removeElement(getfpdDynPcdBuildDefs());
1446 fpdDynPcdBuildDefs
= null;
1449 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1450 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1452 while(li
.hasNext()) {
1453 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1454 saa
[i
][0] = dynPcd
.getCName();
1455 saa
[i
][1] = dynPcd
.getToken().toString();
1456 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1457 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1458 saa
[i
][4] = dynPcd
.getDatumType().toString();
1464 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1465 throws PcdValueMalFormed
{
1466 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1467 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1468 dynPcdData
.setCName(cName
);
1469 dynPcdData
.setToken(token
);
1470 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1471 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1473 BigInteger bigInt
= new BigInteger("0");
1474 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1475 skuInfo
.setSkuId(bigInt
);
1476 if (defaultVal
!= null){
1477 skuInfo
.setValue(defaultVal
);
1480 if (dataType
.equals("UINT8")){
1481 skuInfo
.setValue("0");
1483 if (dataType
.equals("UINT16")) {
1484 skuInfo
.setValue("0");
1486 if (dataType
.equals("UINT32")) {
1487 skuInfo
.setValue("0");
1489 if (dataType
.equals("UINT64")){
1490 skuInfo
.setValue("0");
1492 if (dataType
.equals("BOOLEAN")){
1493 skuInfo
.setValue("false");
1495 if (dataType
.equals("VOID*")) {
1496 skuInfo
.setValue("");
1499 if (dataType
.equals("UINT8")){
1500 dynPcdData
.setMaxDatumSize(1);
1502 if (dataType
.equals("UINT16")) {
1503 dynPcdData
.setMaxDatumSize(2);
1505 if (dataType
.equals("UINT32")) {
1506 dynPcdData
.setMaxDatumSize(4);
1508 if (dataType
.equals("UINT64")){
1509 dynPcdData
.setMaxDatumSize(8);
1511 if (dataType
.equals("BOOLEAN")){
1512 dynPcdData
.setMaxDatumSize(1);
1514 if (dataType
.equals("VOID*")) {
1515 int maxSize
= setMaxSizeForPointer(defaultVal
);
1516 dynPcdData
.setMaxDatumSize(maxSize
);
1520 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1521 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1526 XmlCursor cursor
= o
.newCursor();
1527 if (cursor
.toFirstChild()) {
1529 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1530 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1531 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1533 if (getDynamicPcdBuildDataCount() == 1) {
1541 while (cursor
.toNextSibling());
1546 // Get the Sku Info count of ith dyn pcd element.
1548 public int getDynamicPcdSkuInfoCount(int i
){
1549 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1550 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1554 int skuInfoCount
= 0;
1555 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1556 if (cursor
.toFirstChild()) {
1557 for (int j
= 0; j
< i
; ++j
) {
1558 cursor
.toNextSibling();
1560 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1561 if (pcdData
.getSkuInfoList() == null) {
1565 skuInfoCount
= pcdData
.getSkuInfoList().size();
1569 return skuInfoCount
;
1572 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1573 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1574 removeElement(getfpdDynPcdBuildDefs());
1575 fpdDynPcdBuildDefs
= null;
1579 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1580 if (cursor
.toFirstChild()) {
1581 for (int j
= 0; j
< i
; ++j
) {
1582 cursor
.toNextSibling();
1584 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1585 if (pcdData
.getSkuInfoList() == null) {
1590 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1592 while (li
.hasNext()) {
1593 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1594 saa
[k
][0] = skuInfo
.getSkuId()+"";
1595 saa
[k
][1] = skuInfo
.getVariableName();
1596 saa
[k
][2] = skuInfo
.getVariableGuid();
1597 saa
[k
][3] = skuInfo
.getVariableOffset();
1598 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1599 saa
[k
][5] = skuInfo
.getVpdOffset();
1600 saa
[k
][6] = skuInfo
.getValue();
1610 public String
getDynamicPcdBuildDataValue(int i
){
1611 String value
= null;
1612 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1613 removeElement(getfpdDynPcdBuildDefs());
1614 fpdDynPcdBuildDefs
= null;
1618 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1619 if (cursor
.toFirstChild()) {
1620 for (int j
= 0; j
< i
; ++j
) {
1621 cursor
.toNextSibling();
1623 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1624 if (pcdData
.getSkuInfoList() == null) {
1628 value
= pcdData
.getSkuInfoArray(0).getValue();
1635 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1636 String vpdOffset
= null;
1637 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1638 removeElement(getfpdDynPcdBuildDefs());
1639 fpdDynPcdBuildDefs
= null;
1643 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1644 if (cursor
.toFirstChild()) {
1645 for (int j
= 0; j
< i
; ++j
) {
1646 cursor
.toNextSibling();
1648 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1649 if (pcdData
.getSkuInfoList() == null) {
1653 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1660 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1661 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1662 removeElement(getfpdDynPcdBuildDefs());
1663 fpdDynPcdBuildDefs
= null;
1667 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1668 if (cursor
.toFirstChild()) {
1669 for (int j
= 0; j
< i
; ++j
) {
1670 cursor
.toNextSibling();
1672 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1673 if (pcdData
.getSkuInfoList() == null) {
1678 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1679 cursor
.toChild(qSkuInfo
);
1686 // generate sku info for ith dyn pcd build data.
1688 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1689 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1690 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1694 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1695 if (cursor
.toFirstChild()) {
1696 for (int j
= 0; j
< i
; ++j
) {
1697 cursor
.toNextSibling();
1699 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1700 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1701 skuInfo
.setSkuId(new BigInteger(id
));
1702 if (varName
!= null){
1703 skuInfo
.setVariableName(varName
);
1704 skuInfo
.setVariableGuid(varGuid
);
1705 skuInfo
.setVariableOffset(varOffset
);
1706 skuInfo
.setHiiDefaultValue(hiiDefault
);
1708 else if (vpdOffset
!= null){
1709 skuInfo
.setVpdOffset(vpdOffset
);
1712 skuInfo
.setValue(value
);
1717 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1718 String hiiDefault
, String vpdOffset
, String value
, int i
){
1719 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1723 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1724 if (cursor
.toFirstChild()) {
1725 for (int j
= 0; j
< i
; ++j
) {
1726 cursor
.toNextSibling();
1728 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1729 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1730 while (li
.hasNext()) {
1731 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1732 if (skuInfo
.getSkuId().toString().equals(id
)){
1733 if (varName
!= null){
1734 skuInfo
.setVariableName(varName
);
1735 skuInfo
.setVariableGuid(varGuid
);
1736 skuInfo
.setVariableOffset(varOffset
);
1737 skuInfo
.setHiiDefaultValue(hiiDefault
);
1739 else if (vpdOffset
!= null){
1740 skuInfo
.setVpdOffset(vpdOffset
);
1743 skuInfo
.setValue(value
);
1751 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1752 if (fpdBuildOpts
== null) {
1753 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1755 return fpdBuildOpts
;
1758 public void genBuildOptionsUserExtensions(String fvName
, String outputFileName
, Vector
<String
[]> includeModules
) {
1759 QName elementFvName
= new QName (xmlNs
, "FvName");
1760 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1761 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1762 QName elementModule
= new QName(xmlNs
, "Module");
1764 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1765 userExts
.setUserID("IMAGES");
1766 userExts
.setIdentifier(new BigInteger("1"));
1767 XmlCursor cursor
= userExts
.newCursor();
1768 cursor
.toEndToken();
1770 cursor
.beginElement(elementFvName
);
1771 cursor
.insertChars(fvName
);
1772 cursor
.toNextToken();
1774 cursor
.beginElement(elementInfFileName
);
1775 cursor
.insertChars(fvName
+ ".inf");
1776 cursor
.toNextToken();
1778 cursor
.beginElement(elementIncludeModules
);
1779 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1780 cursor
.beginElement(elementModule
);
1781 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1782 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1783 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1785 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1786 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1787 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1790 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1791 cursor
.toEndToken();
1792 cursor
.toNextToken();
1797 public int getUserExtsIncModCount (String fvName
) {
1798 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1801 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1802 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1803 while (li
.hasNext()) {
1804 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1805 if (!ues
.getUserID().equals("IMAGES")) {
1808 XmlCursor cursor
= ues
.newCursor();
1809 cursor
.toFirstChild();
1810 String elementName
= cursor
.getTextValue();
1811 if (elementName
.equals(fvName
)) {
1812 cursor
.toNextSibling(elementIncludeModules
);
1813 if (cursor
.toFirstChild()) {
1815 for (i
= 1; cursor
.toNextSibling(); ++i
);
1827 public void getUserExtsIncMods(String fvName
, String
[][] saa
) {
1828 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1832 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1833 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1834 QName attribUserId
= new QName ("UserID");
1835 QName elementFvName
= new QName (xmlNs
, "FvName");
1836 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1837 QName attribModuleGuid
= new QName("ModuleGuid");
1838 QName attribModuleVersion
= new QName("ModuleVersion");
1839 QName attribPackageGuid
= new QName("PackageGuid");
1840 QName attribPackageVersion
= new QName("PackageVersion");
1841 QName attribArch
= new QName("Arch");
1843 if (cursor
.toChild(elementUserExts
)) {
1846 if (cursor
.getAttributeText(attribUserId
).equals("IMAGES")) {
1847 cursor
.toChild(elementFvName
);
1848 String elementName
= cursor
.getTextValue();
1849 if (elementName
.equals(fvName
)) {
1850 cursor
.toNextSibling(elementIncludeModules
);
1851 if (cursor
.toFirstChild()) {
1854 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1855 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1856 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1857 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1858 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1860 }while (cursor
.toNextSibling());
1866 }while (cursor
.toNextSibling(elementUserExts
));
1872 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1873 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1876 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1877 while (li
.hasNext()) {
1878 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1879 if (!ues
.getUserID().equals("IMAGES")) {
1882 XmlCursor cursor
= ues
.newCursor();
1883 cursor
.toFirstChild();
1884 String elementName
= cursor
.getTextValue();
1885 if (elementName
.equals(oldFvName
)) {
1886 cursor
.setTextValue(newFvName
);
1893 public void removeBuildOptionsUserExtensions (String fvName
) {
1894 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1898 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1899 while (li
.hasNext()) {
1900 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1901 if (!ues
.getUserID().equals("IMAGES")) {
1904 XmlCursor cursor
= ues
.newCursor();
1905 cursor
.toFirstChild();
1906 String elementName
= cursor
.getTextValue();
1907 if (elementName
.equals(fvName
)) {
1918 private boolean versionEqual (String v1
, String v2
) {
1920 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1921 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1925 if (v1
!= null && v1
.equals(v2
)) {
1932 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
1933 boolean inList
= false;
1934 if (getUserExtsIncModCount(fvName
) > 0) {
1936 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1937 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1938 QName attribUserId
= new QName ("UserID");
1939 QName elementFvName
= new QName (xmlNs
, "FvName");
1940 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1941 QName attribModuleGuid
= new QName("ModuleGuid");
1942 QName attribModuleVersion
= new QName("ModuleVersion");
1943 QName attribPackageGuid
= new QName("PackageGuid");
1944 QName attribPackageVersion
= new QName("PackageVersion");
1945 QName attribArch
= new QName("Arch");
1947 if (cursor
.toChild(elementUserExts
)) {
1950 if (cursor
.getAttributeText(attribUserId
).equals("IMAGES")) {
1951 cursor
.toChild(elementFvName
);
1952 String elementName
= cursor
.getTextValue();
1953 if (elementName
.equals(fvName
)) {
1954 cursor
.toNextSibling(elementIncludeModules
);
1955 if (cursor
.toFirstChild()) {
1958 String mg
= cursor
.getAttributeText(attribModuleGuid
);
1959 String mv
= cursor
.getAttributeText(attribModuleVersion
);
1960 String pg
= cursor
.getAttributeText(attribPackageGuid
);
1961 String pv
= cursor
.getAttributeText(attribPackageVersion
);
1962 String ar
= cursor
.getAttributeText(attribArch
);
1963 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
1966 if (!packageGuid
.equalsIgnoreCase(pg
)) {
1969 if (!arch
.equalsIgnoreCase(ar
)) {
1972 if (!versionEqual(moduleVersion
, mv
)) {
1975 if (!versionEqual(packageVersion
, pv
)) {
1980 }while (cursor
.toNextSibling());
1986 }while (cursor
.toNextSibling(elementUserExts
));
1993 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
1994 if (getUserExtsIncModCount(fvName
) > 0) {
1996 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1997 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1998 QName attribUserId
= new QName ("UserID");
1999 QName elementFvName
= new QName (xmlNs
, "FvName");
2000 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2001 QName attribModuleGuid
= new QName("ModuleGuid");
2002 QName attribModuleVersion
= new QName("ModuleVersion");
2003 QName attribPackageGuid
= new QName("PackageGuid");
2004 QName attribPackageVersion
= new QName("PackageVersion");
2005 QName attribArch
= new QName("Arch");
2007 if (cursor
.toChild(elementUserExts
)) {
2010 if (cursor
.getAttributeText(attribUserId
).equals("IMAGES")) {
2011 cursor
.toChild(elementFvName
);
2012 String elementName
= cursor
.getTextValue();
2013 if (elementName
.equals(fvName
)) {
2014 cursor
.toNextSibling(elementIncludeModules
);
2015 if (cursor
.toFirstChild()) {
2018 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2019 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2020 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2021 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2022 String ar
= cursor
.getAttributeText(attribArch
);
2023 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2026 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2029 if (!arch
.equalsIgnoreCase(ar
)) {
2032 if (!versionEqual(moduleVersion
, mv
)) {
2035 if (!versionEqual(packageVersion
, pv
)) {
2039 }while (cursor
.toNextSibling());
2045 }while (cursor
.toNextSibling(elementUserExts
));
2051 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2052 if (moduleInBuildOptionsUserExtensions (fvName
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2055 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2056 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2057 QName elementModule
= new QName(xmlNs
, "Module");
2058 while (li
.hasNext()) {
2059 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2060 if (!ues
.getUserID().equals("IMAGES")) {
2063 XmlCursor cursor
= ues
.newCursor();
2064 cursor
.toFirstChild();
2065 String elementName
= cursor
.getTextValue();
2066 if (elementName
.equals(fvName
)) {
2067 cursor
.toNextSibling(elementIncludeModules
);
2068 cursor
.toLastChild();
2069 cursor
.toEndToken();
2070 cursor
.toNextToken();
2071 cursor
.beginElement(elementModule
);
2072 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2073 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2074 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2076 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2077 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2078 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2081 cursor
.insertAttributeWithValue("Arch", arch
);
2090 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2091 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2092 if (udats
== null) {
2093 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2096 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2097 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2100 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2101 at
.setId(new Integer(id
));
2102 XmlCursor cursor
= at
.newCursor();
2103 if (fileName
!= null){
2104 at
.setFilename(fileName
);
2106 else if (cursor
.toChild(xmlNs
, "Filename")) {
2109 if (execOrder
!= null) {
2110 at
.setAntCmdOptions(execOrder
);
2112 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2118 public void removeBuildOptionsUserDefAntTask(int i
) {
2119 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2123 XmlCursor cursor
= o
.newCursor();
2124 if (cursor
.toFirstChild()) {
2125 for (int j
= 0; j
< i
; ++j
) {
2126 cursor
.toNextSibling();
2129 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2137 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2138 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2142 XmlCursor cursor
= o
.newCursor();
2143 if (cursor
.toFirstChild()) {
2144 for (int j
= 0; j
< i
; ++j
) {
2145 cursor
.toNextSibling();
2147 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2148 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2153 public int getBuildOptionsUserDefAntTaskCount() {
2154 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2155 if (udats
== null || udats
.getAntTaskList() == null) {
2159 return udats
.getAntTaskList().size();
2162 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2163 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2164 if (udats
== null || udats
.getAntTaskList() == null) {
2168 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2169 ListIterator li
= l
.listIterator();
2171 while (li
.hasNext()) {
2172 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2173 saa
[i
][0] = at
.getId() + "";
2174 saa
[i
][1] = saa
[i
][2] = "";
2175 if (at
.getFilename() != null){
2176 saa
[i
][1] = at
.getFilename();
2178 if (at
.getAntCmdOptions() != null) {
2179 saa
[i
][2] = at
.getAntCmdOptions();
2184 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2185 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2187 opts
= getfpdBuildOpts().addNewOptions();
2189 OptionDocument
.Option opt
= opts
.addNewOption();
2190 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2193 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2194 opt
.setStringValue(contents
);
2195 if (buildTargets
!= null) {
2196 opt
.setBuildTargets(buildTargets
);
2199 if (opt
.isSetBuildTargets()) {
2200 opt
.unsetBuildTargets();
2204 if (toolChain
!= null && toolChain
.length() > 0) {
2205 opt
.setToolChainFamily(toolChain
);
2208 if (opt
.isSetToolChainFamily()) {
2209 opt
.unsetToolChainFamily();
2213 if (tagName
!= null && tagName
.length() > 0) {
2214 opt
.setTagName(tagName
);
2217 if (opt
.isSetTagName()) {
2222 if (toolCmd
!= null && toolCmd
.length() > 0) {
2223 opt
.setToolCode(toolCmd
);
2226 if (opt
.isSetToolCode()) {
2227 opt
.unsetToolCode();
2232 if (archList
!= null) {
2233 opt
.setSupArchList(archList
);
2236 if (opt
.isSetSupArchList()) {
2237 opt
.unsetSupArchList();
2242 public void removeBuildOptionsOpt(int i
){
2244 XmlObject o
= getfpdBuildOpts().getOptions();
2249 XmlCursor cursor
= o
.newCursor();
2250 if (cursor
.toFirstChild()) {
2251 for (int j
= 0; j
< i
; ++j
) {
2252 cursor
.toNextSibling();
2255 if (getBuildOptionsOptCount() == 0) {
2263 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2264 XmlObject o
= getfpdBuildOpts().getOptions();
2269 XmlCursor cursor
= o
.newCursor();
2270 if (cursor
.toFirstChild()) {
2271 for (int j
= 0; j
< i
; ++j
) {
2272 cursor
.toNextSibling();
2274 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2275 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2280 public int getBuildOptionsOptCount(){
2281 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2284 return getfpdBuildOpts().getOptions().getOptionList().size();
2287 public void getBuildOptionsOpts(String
[][] saa
) {
2288 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2292 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2293 ListIterator li
= lOpt
.listIterator();
2295 while(li
.hasNext()) {
2296 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2297 if (opt
.getBuildTargets() != null) {
2298 saa
[i
][0] = listToString(opt
.getBuildTargets());
2300 saa
[i
][1] = opt
.getToolChainFamily();
2301 if (opt
.getSupArchList() != null){
2302 saa
[i
][2] = listToString(opt
.getSupArchList());
2305 saa
[i
][3] = opt
.getToolCode();
2306 saa
[i
][4] = opt
.getTagName();
2307 saa
[i
][5] = opt
.getStringValue();
2313 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2314 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2315 ffs
.setFfsKey(ffsKey
);
2317 ffs
.addNewSections().setEncapsulationType(type
);
2321 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2322 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2324 ffs
.addNewSections().setEncapsulationType(type
);
2328 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2329 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2330 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2331 attrib
.setName(name
);
2332 attrib
.setValue(value
);
2335 /**update jth attribute of ith ffs.
2339 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2340 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2341 XmlCursor cursor
= ffs
.newCursor();
2342 QName qAttrib
= new QName(xmlNs
, "Attribute");
2343 if (cursor
.toChild(qAttrib
)) {
2344 for (int k
= 0; k
< j
; ++k
) {
2345 cursor
.toNextSibling(qAttrib
);
2347 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2348 attrib
.setName(name
);
2349 attrib
.setValue(value
);
2354 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2355 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2356 XmlCursor cursor
= ffs
.newCursor();
2357 QName qAttrib
= new QName(xmlNs
, "Attribute");
2358 if (cursor
.toChild(qAttrib
)) {
2359 for (int k
= 0; k
< j
; ++k
) {
2360 cursor
.toNextSibling(qAttrib
);
2367 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2368 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2372 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2374 if (sections
== null){
2375 sections
= ffs
.addNewSections();
2377 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2380 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2381 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2382 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2383 if (sections
== null) {
2386 XmlCursor cursor
= sections
.newCursor();
2387 QName qSection
= new QName(xmlNs
, "Section");
2388 if (cursor
.toChild(qSection
)) {
2389 for (int k
= 0; k
< j
; ++k
) {
2390 cursor
.toNextSibling(qSection
);
2397 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2398 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2399 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2400 if (sections
== null) {
2403 XmlCursor cursor
= sections
.newCursor();
2404 QName qSection
= new QName(xmlNs
, "Section");
2405 if (cursor
.toChild(qSection
)) {
2406 for (int k
= 0; k
< j
; ++k
) {
2407 cursor
.toNextSibling(qSection
);
2409 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2410 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2415 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2416 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2420 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2422 if (sections
== null){
2423 sections
= ffs
.addNewSections();
2425 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2426 sections2
.setEncapsulationType(encapType
);
2427 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2430 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2431 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2432 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2433 if (sections
== null) {
2436 XmlCursor cursor
= sections
.newCursor();
2437 QName qSections
= new QName(xmlNs
, "Sections");
2438 if (cursor
.toChild(qSections
)) {
2439 for (int k
= 0; k
< j
; ++k
) {
2440 cursor
.toNextSibling(qSections
);
2447 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2448 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2449 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2450 if (sections
== null) {
2453 XmlCursor cursor
= sections
.newCursor();
2454 QName qSections
= new QName(xmlNs
, "Sections");
2455 if (cursor
.toChild(qSections
)) {
2456 for (int k
= 0; k
< j
; ++k
) {
2457 cursor
.toNextSibling(qSections
);
2459 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2460 sections2
.setEncapsulationType(type
);
2465 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2466 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2470 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2471 XmlCursor cursor
= sections
.newCursor();
2472 QName qSections
= new QName(xmlNs
, "Sections");
2473 if (cursor
.toChild(qSections
)){
2474 for (int k
= 0; k
< j
; ++k
) {
2475 cursor
.toNextSibling(qSections
);
2477 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2478 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2483 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2484 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2485 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2486 if (sections
== null) {
2489 XmlCursor cursor
= sections
.newCursor();
2490 QName qSections
= new QName(xmlNs
, "Sections");
2491 if (cursor
.toChild(qSections
)) {
2492 for (int l
= 0; l
< j
; ++l
) {
2493 cursor
.toNextSibling(qSections
);
2495 if (cursor
.toFirstChild()) {
2497 for (; m
< k
; ++m
) {
2498 cursor
.toNextSibling();
2510 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2511 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2512 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2513 if (sections
== null) {
2516 XmlCursor cursor
= sections
.newCursor();
2517 QName qSections
= new QName(xmlNs
, "Sections");
2518 if (cursor
.toChild(qSections
)) {
2519 for (int l
= 0; l
< j
; ++l
) {
2520 cursor
.toNextSibling(qSections
);
2522 if (cursor
.toFirstChild()) {
2523 for (int m
= 0; m
< k
; ++m
) {
2524 cursor
.toNextSibling();
2526 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2527 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2533 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2534 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2538 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2539 XmlCursor cursor
= sections
.newCursor();
2540 QName qSections
= new QName(xmlNs
, "Sections");
2541 if (cursor
.toChild(qSections
)){
2542 for (int k
= 0; k
< j
; ++k
) {
2543 cursor
.toNextSibling(qSections
);
2545 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2546 if (sections2
.getSectionList() == null){
2550 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2551 while(li
.hasNext()) {
2552 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2553 // if (section.isSetSectionType()) {
2554 al
.add(section
.getSectionType()+"");
2563 public int getBuildOptionsFfsCount(){
2564 if (getfpdBuildOpts().getFfsList() == null) {
2567 return getfpdBuildOpts().getFfsList().size();
2570 public void getBuildOptionsFfsKey(String
[][] saa
) {
2571 if (getfpdBuildOpts().getFfsList() == null) {
2574 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2576 while(li
.hasNext()){
2577 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2578 saa
[i
][0] = ffs
.getFfsKey();
2583 public void updateBuildOptionsFfsKey(int i
, String key
) {
2584 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2588 /**Get ith FFS key and contents.
2591 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2592 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2596 sa
[0] = ffs
.getFfsKey();
2597 if (ffs
.getSections() != null) {
2598 if(ffs
.getSections().getEncapsulationType() != null){
2599 sa
[1] = ffs
.getSections().getEncapsulationType();
2601 if (ffs
.getSections().getSectionList() != null){
2602 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2603 while (li
.hasNext()) {
2604 firstLevelSection
.add(li
.next().getSectionType()+"");
2607 if (ffs
.getSections().getSectionsList() != null) {
2608 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2609 while(li
.hasNext()) {
2610 firstLevelSections
.add(li
.next().getEncapsulationType());
2614 if (ffs
.getAttributeList() != null) {
2615 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2616 while(li
.hasNext()) {
2617 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2618 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2627 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2628 XmlObject o
= getfpdBuildOpts();
2629 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2631 XmlCursor cursor
= o
.newCursor();
2632 QName qFfs
= new QName(xmlNs
, "Ffs");
2633 if (cursor
.toChild(qFfs
)) {
2634 for (int j
= 0; j
< i
; ++j
) {
2635 cursor
.toNextSibling(qFfs
);
2637 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2643 public void removeBuildOptionsFfs(int i
) {
2644 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2649 XmlCursor cursor
= ffs
.newCursor();
2656 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2657 if (fpdPlatformDefs
== null){
2658 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2660 return fpdPlatformDefs
;
2663 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2664 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2667 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2668 while(li
.hasNext()) {
2669 archs
.add(li
.next());
2673 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2674 if (archs
!= null) {
2675 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2678 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2679 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2680 // cursor.removeXml();
2682 // cursor.dispose();
2686 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2687 if (getfpdPlatformDefs().getBuildTargets() == null) {
2690 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2691 while(li
.hasNext()) {
2692 targets
.add(li
.next());
2696 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2697 getfpdPlatformDefs().setBuildTargets(targets
);
2700 public void genPlatformDefsSkuInfo(String id
, String name
) {
2701 SkuInfoDocument
.SkuInfo skuInfo
= null;
2702 if (getfpdPlatformDefs().getSkuInfo() == null) {
2703 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2705 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2706 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2707 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2708 skuName
.setSkuID(new BigInteger("0"));
2709 skuName
.setStringValue("DEFAULT");
2711 if (id
.equals("0")) {
2714 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2715 skuName
.setSkuID(new BigInteger(id
));
2716 skuName
.setStringValue(name
);
2719 public int getPlatformDefsSkuInfoCount(){
2720 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2723 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2726 public void getPlatformDefsSkuInfos(String
[][] saa
){
2727 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2728 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2729 removeElement(getfpdDynPcdBuildDefs());
2730 fpdDynPcdBuildDefs
= null;
2735 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2736 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2738 while(li
.hasNext()) {
2739 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2740 saa
[i
][0] = sku
.getSkuID()+"";
2741 saa
[i
][1] = sku
.getStringValue();
2746 public void removePlatformDefsSkuInfo(int i
) {
2747 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2748 if (skuInfo
== null || i
== 0) {
2752 XmlCursor cursor
= skuInfo
.newCursor();
2753 if (cursor
.toFirstChild()) {
2754 for (int j
= 0; j
< i
; ++j
) {
2755 cursor
.toNextSibling();
2762 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2763 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2764 if (skuInfo
== null || i
== 0) {
2768 XmlCursor cursor
= skuInfo
.newCursor();
2769 if (cursor
.toFirstChild()) {
2770 for (int j
= 0; j
< i
; ++j
) {
2771 cursor
.toNextSibling();
2773 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2774 sku
.setSkuID(new BigInteger(id
));
2775 sku
.setStringValue(name
);
2780 public String
getPlatformDefsInterDir(){
2781 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2784 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2787 public void setPlatformDefsInterDir(String interDir
){
2788 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2791 public String
getPlatformDefsOutputDir() {
2792 return getfpdPlatformDefs().getOutputDirectory();
2795 public void setPlatformDefsOutputDir(String outputDir
) {
2796 if (outputDir
!= null && outputDir
.length() > 0) {
2797 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2800 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2801 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2808 public FlashDocument
.Flash
getfpdFlash() {
2809 if (fpdFlash
== null) {
2810 fpdFlash
= fpdRoot
.addNewFlash();
2815 public void genFlashDefinitionFile(String file
) {
2816 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2818 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2821 fdf
.setStringValue(file
);
2824 public String
getFlashDefinitionFile() {
2825 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2830 return fdf
.getStringValue();
2833 public void genFvImagesNameValue(String name
, String value
) {
2835 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2837 fi
= getfpdFlash().addNewFvImages();
2840 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2845 public void removeFvImagesNameValue(int i
){
2847 XmlObject o
= getfpdFlash().getFvImages();
2852 QName qNameValue
= new QName(xmlNs
, "NameValue");
2853 XmlCursor cursor
= o
.newCursor();
2854 if (cursor
.toChild(qNameValue
)) {
2855 for (int j
= 0; j
< i
; ++j
) {
2856 cursor
.toNextSibling(qNameValue
);
2863 public void updateFvImagesNameValue(int i
, String name
, String value
){
2865 XmlObject o
= getfpdFlash().getFvImages();
2870 QName qNameValue
= new QName(xmlNs
, "NameValue");
2871 XmlCursor cursor
= o
.newCursor();
2872 if (cursor
.toChild(qNameValue
)) {
2873 for (int j
= 0; j
< i
; ++j
) {
2874 cursor
.toNextSibling(qNameValue
);
2876 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2883 public int getFvImagesNameValueCount() {
2885 FvImagesDocument
.FvImages fi
= null;
2886 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2889 return fi
.getNameValueList().size();
2892 public void getFvImagesNameValues(String
[][] nv
) {
2894 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2898 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2900 ListIterator li
= l
.listIterator();
2901 while (li
.hasNext()) {
2902 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2904 nv
[i
][0] = e
.getName();
2905 nv
[i
][1] = e
.getValue();
2911 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2912 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2913 if (fis
== null || fis
.getFvImageList() == null) {
2917 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2918 while (li
.hasNext()) {
2919 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2920 if (fi
.getType().toString().equals("ImageName")) {
2921 vImageNames
.addAll(fi
.getFvImageNamesList());
2927 public void addFvImageFvImageNames (String
[] fvNames
) {
2928 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2929 if (fis
== null || fis
.getFvImageList() == null) {
2930 genFvImagesFvImage (fvNames
, "ImageName", null);
2934 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2935 while (li
.hasNext()) {
2936 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2937 if (fi
.getType().toString().equals("ImageName")) {
2938 addFvImageNamesInFvImage (fi
, fvNames
);
2942 genFvImagesFvImage (fvNames
, "ImageName", null);
2945 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
2947 for (int i
= 0; i
< fvNames
.length
; ++i
) {
2948 fi
.addFvImageNames(fvNames
[i
]);
2952 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
2953 XmlObject o
= getfpdFlash().getFvImages();
2957 XmlCursor cursor
= o
.newCursor();
2958 QName qFvImage
= new QName(xmlNs
, "FvImage");
2959 if (cursor
.toChild(qFvImage
)) {
2960 for (int j
= 0; j
< i
; ++j
) {
2961 cursor
.toNextSibling(qFvImage
);
2963 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
2964 addFvImageNamesInFvImage(fi
, fvNames
);
2969 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
2971 FvImagesDocument
.FvImages fis
= null;
2972 if ((fis
= getfpdFlash().getFvImages()) == null) {
2973 fis
= getfpdFlash().addNewFvImages();
2977 //gen FvImage with FvImageNames array
2979 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
2980 for (int i
= 0; i
< names
.length
; ++i
) {
2981 fi
.addFvImageNames(names
[i
]);
2983 fi
.setType(FvImageTypes
.Enum
.forString(types
));
2984 if (options
!= null){
2985 setFvImagesFvImageFvImageOptions(options
, fi
);
2989 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
2990 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
2992 fio
= fi
.addNewFvImageOptions();
2995 Set
<String
> key
= options
.keySet();
2996 Iterator
<String
> i
= key
.iterator();
2997 while (i
.hasNext()) {
2999 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3000 String k
= (String
)i
.next();
3003 nv
.setValue((String
)options
.get(k
));
3010 public void removeFvImagesFvImage(int i
) {
3012 XmlObject o
= getfpdFlash().getFvImages();
3017 QName qFvImage
= new QName(xmlNs
, "FvImage");
3018 XmlCursor cursor
= o
.newCursor();
3019 if (cursor
.toChild(qFvImage
)) {
3020 for (int j
= 0; j
< i
; ++j
) {
3021 cursor
.toNextSibling(qFvImage
);
3030 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3032 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3033 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3036 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3037 while (li
.hasNext()) {
3038 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3039 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3040 if (fi
.getFvImageNamesList().size() == 0) {
3046 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3047 XmlObject o
= getfpdFlash().getFvImages();
3051 XmlCursor cursor
= o
.newCursor();
3052 QName qFvImage
= new QName(xmlNs
, "FvImage");
3053 if (cursor
.toChild(qFvImage
)) {
3054 for (int j
= 0; j
< i
; ++j
) {
3055 cursor
.toNextSibling(qFvImage
);
3057 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3058 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3064 * @param oldFvName The FV Name to be replaced.
3065 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3067 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3068 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3069 XmlCursor cursor
= fi
.newCursor();
3071 if (cursor
.toChild(qFvImageNames
)) {
3073 String xmlValue
= cursor
.getTextValue();
3074 if (xmlValue
.equals(oldFvName
)){
3075 if (newFvName
!= null) {
3076 cursor
.setTextValue(newFvName
);
3082 }while (cursor
.toNextSibling(qFvImageNames
));
3088 /**update the Type attribute of ith FvImage with new type.
3092 public void updateFvImagesFvImageType (int i
, String type
) {
3093 XmlObject o
= getfpdFlash().getFvImages();
3097 XmlCursor cursor
= o
.newCursor();
3098 QName qFvImage
= new QName(xmlNs
, "FvImage");
3099 if (cursor
.toChild(qFvImage
)) {
3100 for (int j
= 0; j
< i
; ++j
) {
3101 cursor
.toNextSibling(qFvImage
);
3103 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3104 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3109 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3111 XmlObject o
= getfpdFlash().getFvImages();
3115 XmlCursor cursor
= o
.newCursor();
3116 QName qFvImage
= new QName(xmlNs
, "FvImage");
3117 if (cursor
.toChild(qFvImage
)) {
3118 for (int j
= 0; j
< i
; ++j
) {
3119 cursor
.toNextSibling(qFvImage
);
3121 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3122 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3125 // remove old FvImageNames before adding new ones
3127 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3128 cursor
.toChild(qFvImageNames
);
3130 while (cursor
.toNextSibling(qFvImageNames
)) {
3134 for (int k
= 0; k
< names
.length
; ++k
) {
3135 fi
.addFvImageNames(names
[k
]);
3138 // remove old FvImageOptions before adding new options
3140 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3141 cursor
.toNextSibling(qFvImageOptions
);
3144 setFvImagesFvImageFvImageOptions(options
, fi
);
3149 public int getFvImagesFvImageCount(String type
) {
3151 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3154 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3155 ListIterator li
= l
.listIterator();
3157 while(li
.hasNext()) {
3158 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3159 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3169 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3170 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3171 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3174 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3175 ListIterator li
= l
.listIterator();
3176 while(li
.hasNext()) {
3177 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3178 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3181 if (fi
.getFvImageNamesList().contains(fvName
)) {
3190 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3192 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3194 if (getfpdFlash().getFvImages() == null) {
3197 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3201 ListIterator li
= l
.listIterator();
3203 while(li
.hasNext()) {
3204 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3205 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3209 // get FvImageNames array, space separated
3211 List
<String
> lfn
= fi
.getFvImageNamesList();
3212 ListIterator lfni
= lfn
.listIterator();
3214 while (lfni
.hasNext()) {
3215 saa
[i
][0] += (String
)lfni
.next();
3218 saa
[i
][0] = saa
[i
][0].trim();
3220 saa
[i
][1] = fi
.getType()+"";
3226 public void removeFvImageNameValue (int i
, String attributeName
) {
3227 XmlObject o
= getfpdFlash().getFvImages();
3231 XmlCursor cursor
= o
.newCursor();
3232 QName qFvImage
= new QName(xmlNs
, "FvImage");
3233 if (cursor
.toChild(qFvImage
)) {
3234 for (int j
= 0; j
< i
; ++j
) {
3235 cursor
.toNextSibling(qFvImage
);
3237 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3238 removeFvImageNameValue (fi
, attributeName
);
3242 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3244 * @param attributeName
3246 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3247 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3248 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3249 while (li
.hasNext()) {
3250 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3251 if (nv
.getName().equals(attributeName
)) {
3258 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3259 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3260 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3261 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3262 removeFvImageNameValue (fi
, optName
);
3266 /**Add name-value pair to FvImage element with type.
3267 * @param fvName FV name to add name-value pair.
3268 * @param type FvImage attribute.
3272 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
) {
3273 boolean fvImageExists
= false;
3274 if (getfpdFlash().getFvImages() == null) {
3277 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3281 ListIterator li
= l
.listIterator();
3282 while(li
.hasNext()) {
3283 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3284 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3287 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3290 fvImageExists
= true;
3291 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3294 if (!fvImageExists
) {
3295 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3296 map
.put(name
, value
);
3297 genFvImagesFvImage(new String
[]{fvName
}, type
, map
);
3301 /**Add to all FvImage elements with type, the name-value pair.
3306 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3307 if (getfpdFlash().getFvImages() == null) {
3310 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3314 ListIterator li
= l
.listIterator();
3315 while(li
.hasNext()) {
3316 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3317 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3320 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3325 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3326 XmlObject o
= getfpdFlash().getFvImages();
3330 XmlCursor cursor
= o
.newCursor();
3331 QName qFvImage
= new QName(xmlNs
, "FvImage");
3332 if (cursor
.toChild(qFvImage
)) {
3333 for (int j
= 0; j
< i
; ++j
) {
3334 cursor
.toNextSibling(qFvImage
);
3336 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3337 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3342 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3348 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3349 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3350 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3353 if (newName
!= null) {
3354 nv
.setName(newName
);
3359 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3360 if (cursor
.toFirstChild()) {
3362 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3363 if (nv
.getName().equals(name
)) {
3365 if (newName
!= null) {
3366 nv
.setName(newName
);
3371 }while (cursor
.toNextSibling());
3374 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3377 if (newName
!= null) {
3378 nv
.setName(newName
);
3383 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3384 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3385 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3386 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3387 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3391 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3394 while (li
.hasNext()) {
3395 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3396 m
.put(nv
.getName(), nv
.getValue());
3401 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3402 XmlObject o
= getfpdFlash().getFvImages();
3408 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3409 Vector
<String
> vFvNames
= new Vector
<String
>();
3412 XmlCursor cursor
= o
.newCursor();
3413 QName qFvImage
= new QName(xmlNs
, "FvImage");
3414 if (cursor
.toChild(qFvImage
)) {
3417 vFvNames
.removeAllElements();
3418 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3419 vFvNames
.add(fvNameArray
[i
]);
3421 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3422 if (!fi
.getType().toString().equals(type
)) {
3425 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3428 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3429 while (li
.hasNext()) {
3430 String name
= li
.next();
3431 vFvNames
.remove(name
);
3433 if (vFvNames
.size() == 0) {
3438 }while (cursor
.toNextSibling(qFvImage
));
3444 /**Get FvImage Options for FvImage i
3445 * @param i the ith FvImage
3447 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3448 XmlObject o
= getfpdFlash().getFvImages();
3452 XmlCursor cursor
= o
.newCursor();
3453 QName qFvImage
= new QName(xmlNs
, "FvImage");
3454 if (cursor
.toChild(qFvImage
)) {
3455 for (int j
= 0; j
< i
; ++j
) {
3456 cursor
.toNextSibling(qFvImage
);
3458 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3459 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3463 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3464 while(li
.hasNext()){
3465 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3466 m
.put(nv
.getName(), nv
.getValue());
3473 Get platform header element
3474 @return PlatformHeaderDocument.PlatformHeader
3476 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3477 if (fpdHdr
== null) {
3478 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3484 public String
getFpdHdrPlatformName() {
3485 return getFpdHdr().getPlatformName();
3488 public String
getFpdHdrGuidValue() {
3489 return getFpdHdr().getGuidValue();
3492 public String
getFpdHdrVer() {
3493 return getFpdHdr().getVersion();
3496 public String
getFpdHdrAbs() {
3497 return getFpdHdr().getAbstract();
3500 public String
getFpdHdrDescription() {
3501 return getFpdHdr().getDescription();
3504 public String
getFpdHdrCopyright() {
3505 return getFpdHdr().getCopyright();
3508 public String
getFpdHdrLicense() {
3509 LicenseDocument
.License l
= getFpdHdr().getLicense();
3513 return l
.getStringValue();
3516 public String
getFpdHdrUrl() {
3517 LicenseDocument
.License l
= getFpdHdr().getLicense();
3524 public String
getFpdHdrSpec() {
3526 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3527 // return getFpdHdr().getSpecification();
3530 public void setFpdHdrPlatformName(String name
){
3531 getFpdHdr().setPlatformName(name
);
3534 public void setFpdHdrGuidValue(String guid
){
3535 getFpdHdr().setGuidValue(guid
);
3538 public void setFpdHdrVer(String v
){
3539 getFpdHdr().setVersion(v
);
3542 public void setFpdHdrAbs(String abs
) {
3543 getFpdHdr().setAbstract(abs
);
3546 public void setFpdHdrDescription(String desc
){
3547 getFpdHdr().setDescription(desc
);
3550 public void setFpdHdrCopyright(String cr
) {
3551 getFpdHdr().setCopyright(cr
);
3554 public void setFpdHdrLicense(String license
){
3555 LicenseDocument
.License l
= getFpdHdr().getLicense();
3557 getFpdHdr().addNewLicense().setStringValue(license
);
3560 l
.setStringValue(license
);
3564 public void setFpdHdrUrl(String url
){
3565 LicenseDocument
.License l
= getFpdHdr().getLicense();
3571 public void setFpdHdrSpec(String s
){
3572 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3573 getFpdHdr().setSpecification(s
);
3576 Save the processed xml contents to file
3578 @param fpdFile The file to save xml contents
3579 @throws IOException Exceptions during file operation
3581 public void saveAs(File fpdFile
) throws IOException
{
3583 XmlOptions options
= new XmlOptions();
3585 options
.setCharacterEncoding("UTF-8");
3586 options
.setSavePrettyPrint();
3587 options
.setSavePrettyPrintIndent(2);
3589 fpdd
.save(fpdFile
, options
);
3590 } catch (IOException e
) {
3591 e
.printStackTrace();
3596 private String
listToString(List l
) {
3601 ListIterator li
= l
.listIterator();
3602 while(li
.hasNext()) {
3609 private void removeElement(XmlObject o
) {
3610 XmlCursor cursor
= o
.newCursor();
3616 class PcdItemTypeConflictException
extends Exception
{
3621 private static final long serialVersionUID
= 1L;
3622 private String details
= null;
3624 PcdItemTypeConflictException(String pcdName
, String info
){
3625 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3626 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3629 public String
getMessage() {
3634 class PcdDeclNotFound
extends Exception
{
3639 private static final long serialVersionUID
= 1L;
3640 private String details
= null;
3642 PcdDeclNotFound(String info
) {
3643 details
= "PcdDeclNotFound: " + info
;
3646 public String
getMessage() {
3651 class PcdValueMalFormed
extends Exception
{
3656 private static final long serialVersionUID
= 1L;
3657 private String details
= null;
3659 PcdValueMalFormed(String info
) {
3660 details
= "PcdValueMalFormed: " + info
;
3663 public String
getMessage() {