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
, Vector
<String
> vExceptions
) throws Exception
{
387 boolean dataModified
= false;
388 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
389 int pcdCount
= getPcdDataCount(seqModuleSa
);
390 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
391 getPcdData(seqModuleSa
, saaModuleSaPcd
);
392 String mg
= moduleSa
.getModuleGuid().toLowerCase();
393 String mv
= moduleSa
.getModuleVersion();
394 String pg
= moduleSa
.getPackageGuid().toLowerCase();
395 String pv
= moduleSa
.getPackageVersion();
396 String arch
= listToString(moduleSa
.getSupArchList());
398 // delete pcd in ModuleSA but not in MSA files any longer.
400 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
401 int libCount
= getLibraryInstancesCount(moduleKey
);
402 String
[][] saaLib
= new String
[libCount
][5];
403 getLibraryInstances(moduleKey
, saaLib
);
404 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
406 vExceptions
.add("Module " + mg
+ " does NOT exist in workspace.");
407 throw new Exception ("Module does NOT exist in workspace.");
409 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
411 // create vector for module & library instance MIs.
414 for (int j
= 0; j
< saaLib
.length
; ++j
) {
415 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
416 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
422 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
424 for (int j
= 0; j
< vMi
.size(); ++j
) {
425 ModuleIdentification nextMi
= vMi
.get(j
);
426 if (nextMi
== null) {
429 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], nextMi
)) {
433 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
437 // add new Pcd from MSA file to ModuleSA.
439 for (int i
= 0; i
< vMi
.size(); ++i
) {
440 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
441 .getModuleXmlObject(vMi
443 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
446 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
447 msaPcdIter
:while (li
.hasNext()) {
448 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
449 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
451 for (int j
= 0; j
< al
.size(); ++j
) {
452 if (al
.get(j
).startsWith(moduleKey
)) {
458 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
459 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
460 if (spdPcd
== null) {
464 String errorMessage
= "No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
467 errorMessage
+= " Library Instance " + vMi
.get(i
).getName();
469 vExceptions
.add(errorMessage
);
470 throw new PcdDeclNotFound(errorMessage
);
473 // AddItem to ModuleSA PcdBuildDefinitions
475 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
476 : msaPcd
.getDefaultValue();
478 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
479 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
488 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
490 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
494 String
[] s
= moduleInfo
.split(" ");
495 for(int i
= 0; i
< al
.size(); ++i
){
496 String consumer
= al
.get(i
);
497 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
498 String
[] consumerPart
= consumer
.split(" ");
499 if (!consumerPart
[4].equals(s
[4])) {
507 if (al
.size() == 0) {
508 defaultPcdValue
.remove(pcdKey
);
509 dynPcdMap
.remove(pcdKey
);
510 String
[] s1
= pcdKey
.split(" ");
511 removeDynamicPcdBuildData(s1
[0], s1
[1]);
516 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
518 public int getPcdDataCount (int i
){
519 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
521 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
524 return msa
.getPcdBuildDefinition().getPcdDataList().size();
528 public void getPcdData (int i
, String
[][] saa
) {
529 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
531 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
534 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
535 for (int k
= 0; k
< saa
.length
; ++k
) {
536 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
537 saa
[k
][0] = pcdData
.getCName();
538 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
539 saa
[k
][2] = pcdData
.getItemType()+"";
540 saa
[k
][3] = pcdData
.getToken().toString();
541 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
542 saa
[k
][5] = pcdData
.getDatumType()+"";
543 saa
[k
][6] = pcdData
.getValue();
548 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
549 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
550 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
554 String mg
= moduleSa
.getModuleGuid();
555 String mv
= moduleSa
.getModuleVersion();
556 String pg
= moduleSa
.getPackageGuid();
557 String pv
= moduleSa
.getPackageVersion();
558 String arch
= listToString(moduleSa
.getSupArchList());
559 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
561 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
562 if (cursor
.toFirstChild()){
565 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
566 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
567 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
568 if (getPcdDataCount(seqModuleSa
) == 1) {
575 while(cursor
.toNextSibling());
581 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
582 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
583 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
587 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
588 if (cursor
.toFirstChild()){
590 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
591 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
593 // change item type while not updating dynPcdData????
595 if (itemType
!= null) {
596 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
599 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
600 pcdData
.setMaxDatumSize(new Integer(maxSize
));
603 // if value input is null, keep old value untouched.
606 pcdData
.setValue(value
);
607 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
613 while(cursor
.toNextSibling());
618 /**Get original Pcd info from MSA & SPD files.
619 * @param mi ModuleIdentification from which MSA & SPD come
620 * @param cName PCD cName
621 * @param sa Results: HelpText, Original item type.
624 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
626 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
627 .getModuleXmlObject(mi
);
628 if (msa
.getPcdCoded() == null) {
632 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
634 // First look through MSA pcd entries.
636 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
637 ListIterator li
= l
.listIterator();
638 while (li
.hasNext()) {
639 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
640 if (!msaPcd
.getCName().equals(cName
)) {
643 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
646 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
647 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
651 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
654 // Get Pcd help text and original item type.
656 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
657 sa
[1] = msaPcd
.getPcdItemType() + "";
658 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
659 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
660 while (iter
.hasNext()) {
661 String usage
= iter
.next().toString();
662 validPcdTypes
.add(usage
);
670 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
671 int libCount
= getLibraryInstancesCount(moduleKey
);
672 String
[][] saaLib
= new String
[libCount
][5];
673 getLibraryInstances(moduleKey
, saaLib
);
674 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
675 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
677 // create vector for module & library instance MIs.
680 for (int j
= 0; j
< saaLib
.length
; ++j
) {
681 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
682 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
686 int pcdSourceCount
= 0;
687 for (int i
= 0; i
< vMi
.size(); ++i
) {
688 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
693 if (pcdSourceCount
< 2) {
702 /**Remove PCDBuildDefinition entries from ModuleSA
703 * @param moduleKey identifier of ModuleSA.
704 * @param consumer where these entries come from.
706 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
708 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
709 if (msa
.getPcdCoded() == null) {
713 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
714 ListIterator li
= l
.listIterator();
716 while(li
.hasNext()) {
717 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
718 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
719 if (moduleSA
.getPcdBuildDefinition() != null) {
720 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
722 if (cursor
.toFirstChild()) {
724 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
726 String cName
= msaPcd
.getCName();
727 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
728 if (cName
.equals(pcdData
.getCName())
729 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
731 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
736 } while (cursor
.toNextSibling());
740 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
749 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
751 public int getLibraryInstancesCount(String key
) {
752 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
753 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
756 return msa
.getLibraries().getInstanceList().size();
759 public void getLibraryInstances(String key
, String
[][] saa
){
760 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
761 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
765 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
766 for (int i
= 0; i
< saa
.length
; ++i
) {
767 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
768 saa
[i
][1] = instance
.getModuleGuid();
769 saa
[i
][2] = instance
.getModuleVersion();
770 saa
[i
][3] = instance
.getPackageGuid();
771 saa
[i
][4] = instance
.getPackageVersion();
775 public void removeLibraryInstance(String key
, int i
) {
776 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
777 if (msa
== null || msa
.getLibraries() == null){
781 XmlCursor cursor
= msa
.getLibraries().newCursor();
782 if (cursor
.toFirstChild()) {
783 for (int j
= 0; j
< i
; ++j
) {
784 cursor
.toNextSibling();
787 while (cursor
.hasPrevToken()) {
788 cursor
.toPrevToken();
789 if (!cursor
.isText()) {
792 String s
= cursor
.getTextValue();
793 if (s
.matches(regExpNewLineAndSpaces
)) {
798 if (cursor
.isComment()) {
803 if (getLibraryInstancesCount(key
) == 0) {
812 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
813 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
815 msa
= getfpdFrameworkModules().addNewModuleSA();
817 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
819 libs
= msa
.addNewLibraries();
822 String mn
= libMi
.getName();
823 String mg
= libMi
.getGuid();
824 String mv
= libMi
.getVersion();
825 String pn
= libMi
.getPackageId().getName();
826 String pg
= libMi
.getPackageId().getGuid();
827 String pv
= libMi
.getPackageId().getVersion();
828 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
829 XmlCursor cursor
= instance
.newCursor();
831 String comment
= "Pkg: " + pn
+ " Mod: " + mn
832 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
833 cursor
.insertComment(comment
);
842 instance
.setModuleGuid(mg
);
843 instance
.setModuleVersion(mv
);
844 instance
.setPackageGuid(pg
);
845 instance
.setPackageVersion(pv
);
849 public String
getFvBinding(String moduleKey
){
850 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
851 return getFvBinding (moduleSa
);
854 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
855 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
858 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
861 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
862 if (moduleSa
== null ) {
865 if (fvBinding
== null || fvBinding
.length() == 0) {
866 if(moduleSa
.getModuleSaBuildOptions() != null){
867 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
871 if(moduleSa
.getModuleSaBuildOptions() == null){
872 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
875 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
879 public void setFvBinding(String moduleKey
, String fvBinding
){
880 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
881 setFvBinding (moduleSa
, fvBinding
);
884 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
885 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
889 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
890 String
[] fvNamesArray
= fvNameList
.split(" ");
892 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
893 if (fvNamesArray
[i
].equals(fvName
)) {
901 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
902 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
906 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
907 String
[] fvNamesArray
= fvNameList
.split(" ");
909 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
910 if (fvNamesArray
[i
].equals(fvName
)) {
915 // jump over where the input fvName occurs in the original Fv list.
916 if (occursAt
!= -1) {
917 String newFvNameList
= " ";
918 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
922 newFvNameList
+= fvNamesArray
[i
];
924 setFvBinding (moduleSa
, newFvNameList
.trim());
930 * @param fvName The FV name that to be removed from FvBinding List.
932 public void removeFvBindingAll (String fvName
) {
933 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
934 removeElement(getfpdFrameworkModules());
935 fpdFrameworkModules
= null;
939 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
940 while (li
.hasNext()) {
941 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
942 removeFvBinding (moduleSa
, fvName
);
946 public void appendFvBindingAll (String fvName
) {
947 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
948 removeElement(getfpdFrameworkModules());
949 fpdFrameworkModules
= null;
953 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
954 while (li
.hasNext()) {
955 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
956 appendFvBinding (moduleSa
, fvName
);
960 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
961 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
962 removeElement(getfpdFrameworkModules());
963 fpdFrameworkModules
= null;
967 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
968 while (li
.hasNext()) {
969 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
970 String fvBinding
= getFvBinding (moduleSa
);
971 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
972 appendFvBinding (moduleSa
, newFvName
);
977 public void appendFvBinding (String moduleKey
, String fvName
) {
978 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
979 appendFvBinding (moduleSa
, fvName
);
982 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
983 if (moduleSa
== null) {
987 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
988 setFvBinding(moduleSa
, fvName
);
992 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
993 String newFvNameList
= fvNameList
+ " " + fvName
;
994 setFvBinding (moduleSa
, newFvNameList
.trim());
997 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
999 appendFvBinding (moduleKey
, fvName
);
1002 public String
getFfsFileNameGuid(String moduleKey
){
1003 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1004 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
1007 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1010 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1011 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1015 if(msa
.getModuleSaBuildOptions() == null){
1016 msa
.addNewModuleSaBuildOptions();
1019 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1020 if (fileGuid
!= null) {
1021 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1024 XmlCursor cursor
= msaBuildOpts
.newCursor();
1025 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1033 public String
getFfsFormatKey(String moduleKey
){
1034 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1035 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1038 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1041 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1042 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1046 if(msa
.getModuleSaBuildOptions() == null){
1047 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1050 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1053 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1054 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1055 moduleSa
.setForceDebug(dbgEnable
);
1058 public boolean getModuleSAForceDebug (int i
) {
1059 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1060 if (moduleSa
.getForceDebug() == true) {
1066 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1067 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1068 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1069 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1073 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1074 ListIterator li
= lOpt
.listIterator();
1076 while(li
.hasNext()) {
1077 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1078 if (opt
.getBuildTargets() != null) {
1079 saa
[i
][0] = listToString(opt
.getBuildTargets());
1081 saa
[i
][1] = opt
.getToolChainFamily();
1082 saa
[i
][2] = opt
.getTagName();
1083 saa
[i
][3] = opt
.getToolCode();
1085 if (opt
.getSupArchList() != null){
1086 saa
[i
][4] = listToString(opt
.getSupArchList());
1092 saa
[i
][5] = opt
.getStringValue();
1098 public int getModuleSAOptionsCount(String moduleKey
){
1099 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1100 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1101 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1104 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1107 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1108 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1109 if (msa
.getModuleSaBuildOptions() == null) {
1110 msa
.addNewModuleSaBuildOptions();
1112 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1113 msa
.getModuleSaBuildOptions().addNewOptions();
1115 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1116 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1119 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1120 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1121 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1124 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1125 XmlCursor cursor
= opts
.newCursor();
1126 if (cursor
.toFirstChild()) {
1127 for (int j
= 0; j
< i
; ++j
){
1128 cursor
.toNextSibling();
1131 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1139 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1140 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1141 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1144 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1145 XmlCursor cursor
= opts
.newCursor();
1146 if (cursor
.toFirstChild()) {
1147 for (int j
= 0; j
< i
; ++j
){
1148 cursor
.toNextSibling();
1150 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1151 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1156 /**add pcd information of module mi to a ModuleSA.
1158 * @param moduleSa if null, generate a new ModuleSA.
1160 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1161 //ToDo add Arch filter
1163 if (moduleSa
== null) {
1164 moduleSa
= genModuleSA(mi
, arch
);
1167 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1168 .getModuleXmlObject(mi
);
1169 if (msa
.getPcdCoded() == null) {
1173 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1175 // Implementing InitializePlatformPcdBuildDefinitions
1177 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1178 ListIterator li
= l
.listIterator();
1179 while (li
.hasNext()) {
1180 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1181 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1182 if (spdPcd
== null) {
1186 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " used by Module "
1187 + mi
.getName() + " or its Library Instances.");
1190 // AddItem to ModuleSA PcdBuildDefinitions
1192 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1194 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1196 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1201 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1203 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1204 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1206 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1210 for (int j
= 0; j
< xo
.length
; ++j
) {
1211 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1212 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1213 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1218 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1229 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1230 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1231 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1232 XmlCursor cursor
= msa
.newCursor();
1234 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1235 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1236 cursor
.insertComment(comment
);
1239 e
.printStackTrace();
1244 msa
.setModuleGuid(mi
.getGuid());
1245 msa
.setModuleVersion(mi
.getVersion());
1246 msa
.setPackageGuid(pi
.getGuid());
1247 msa
.setPackageVersion(pi
.getVersion());
1249 Vector
<String
> v
= new Vector
<String
>();
1251 msa
.setSupArchList(v
);
1257 private String
chooseDefaultPcdType (List validPcdTypes
) {
1258 String choosedType
= "";
1259 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1260 choosedType
= "FIXED_AT_BUILD";
1262 else if (validPcdTypes
.contains("DYNAMIC")) {
1263 choosedType
= "DYNAMIC";
1265 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1266 choosedType
= "PATCHABLE_IN_MODULE";
1268 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1269 choosedType
= "DYNAMIC_EX";
1274 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1275 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1276 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1277 if (moduleSa
.getPcdBuildDefinition() == null){
1278 moduleSa
.addNewPcdBuildDefinition();
1281 // constructe pcd to modulesa mapping first.
1282 // Attention : for any error condition, remove from map this pcd.
1284 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1285 if (pcdConsumer
== null) {
1286 pcdConsumer
= new ArrayList
<String
>();
1289 // Check whether this PCD has already added to ModuleSA, if so, just return.
1291 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1292 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1293 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1294 String pcdInfo
= pcdConsumer
.get(i
);
1295 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1299 // if pcd type from MSA file is Dynamic
1300 // we must choose one default type from SPD file for it.
1302 List validPcdTypes
= spdPcd
.getValidUsage();
1304 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1306 if (pcdConsumer
.size() > 0) {
1308 // platform should only contain one type for each pcd.
1310 String existingItemType
= itemType (pcdConsumer
.get(0));
1311 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1312 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1313 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1317 if (itemType
.equals("DYNAMIC")) {
1318 if (!validPcdTypes
.contains(existingItemType
)) {
1319 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1321 itemType
= existingItemType
;
1324 if (!itemType
.equals(existingItemType
)) {
1325 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1330 // if this is the first occurence of this pcd.
1333 if (itemType
.equals("DYNAMIC")) {
1334 itemType
= chooseDefaultPcdType (validPcdTypes
);
1337 String listValue
= moduleInfo
+ " " + itemType
;
1338 pcdConsumer
.add(listValue
);
1339 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1341 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1342 fpdPcd
.setCName(cName
);
1343 fpdPcd
.setToken(token
);
1344 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1345 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1346 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1348 if (defaultVal
!= null){
1349 fpdPcd
.setValue(defaultVal
);
1352 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1353 fpdPcd
.setValue("0");
1355 if (dataType
.equals("BOOLEAN")){
1356 fpdPcd
.setValue("FALSE");
1358 if (dataType
.equals("VOID*")) {
1359 fpdPcd
.setValue("");
1363 // Using existing pcd value, if this pcd already exists in other moduleSa.
1365 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1366 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1369 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1372 if (dataType
.equals("UINT8")){
1373 fpdPcd
.setMaxDatumSize(1);
1375 if (dataType
.equals("UINT16")) {
1376 fpdPcd
.setMaxDatumSize(2);
1378 if (dataType
.equals("UINT32")) {
1379 fpdPcd
.setMaxDatumSize(4);
1381 if (dataType
.equals("UINT64")){
1382 fpdPcd
.setMaxDatumSize(8);
1384 if (dataType
.equals("BOOLEAN")){
1385 fpdPcd
.setMaxDatumSize(1);
1387 if (dataType
.equals("VOID*")) {
1388 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1389 fpdPcd
.setMaxDatumSize(maxSize
);
1393 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1394 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1396 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1397 // so need to add one dyn pcd.
1399 if (al
.size() == 1) {
1400 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1406 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1407 if (datum
== null) {
1410 char ch
= datum
.charAt(0);
1414 // For void* type PCD, only three datum is support:
1415 // 1) Unicode: string with start char is "L"
1416 // 2) Ansci: String is ""
1417 // 3) byte array: String start char "{"
1420 start
= datum
.indexOf('\"');
1421 end
= datum
.lastIndexOf('\"');
1422 if ((start
> end
) ||
1423 (end
> datum
.length())||
1424 ((start
== end
) && (datum
.length() > 0))) {
1425 //ToDo Error handling here
1426 throw new PcdValueMalFormed (datum
);
1429 strValue
= datum
.substring(start
+ 1, end
);
1430 return strValue
.length() * 2;
1431 } else if (ch
== '\"'){
1432 start
= datum
.indexOf('\"');
1433 end
= datum
.lastIndexOf('\"');
1434 if ((start
> end
) ||
1435 (end
> datum
.length())||
1436 ((start
== end
) && (datum
.length() > 0))) {
1437 throw new PcdValueMalFormed (datum
);
1439 strValue
= datum
.substring(start
+ 1, end
);
1440 return strValue
.length();
1441 } else if (ch
=='{') {
1442 String
[] strValueArray
;
1444 start
= datum
.indexOf('{');
1445 end
= datum
.lastIndexOf('}');
1446 strValue
= datum
.substring(start
+ 1, end
);
1447 strValue
= strValue
.trim();
1448 if (strValue
.length() == 0) {
1451 strValueArray
= strValue
.split(",");
1452 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1453 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1456 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1457 // "it must be a byte array. But the element of %s exceed the byte range",
1458 throw new PcdValueMalFormed (datum
);
1461 return strValueArray
.length
;
1465 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1466 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1467 // "2) ANSIC string: like \"xxx\";\r\n"+
1468 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1469 // "but the datum in seems does not following above format!",
1470 throw new PcdValueMalFormed (datum
);
1475 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1476 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1481 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1483 return dynPcdMap
.get(pcdKey
);
1486 public int getDynamicPcdBuildDataCount() {
1487 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1488 removeElement(getfpdDynPcdBuildDefs());
1489 fpdDynPcdBuildDefs
= null;
1492 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1495 public void getDynamicPcdBuildData(String
[][] saa
) {
1496 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1497 removeElement(getfpdDynPcdBuildDefs());
1498 fpdDynPcdBuildDefs
= null;
1501 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1502 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1504 while(li
.hasNext()) {
1505 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1506 saa
[i
][0] = dynPcd
.getCName();
1507 saa
[i
][1] = dynPcd
.getToken().toString();
1508 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1509 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1510 saa
[i
][4] = dynPcd
.getDatumType().toString();
1516 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1517 throws PcdValueMalFormed
{
1518 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1519 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1520 dynPcdData
.setCName(cName
);
1521 dynPcdData
.setToken(token
);
1522 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1523 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1525 BigInteger bigInt
= new BigInteger("0");
1526 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1527 skuInfo
.setSkuId(bigInt
);
1528 if (defaultVal
!= null){
1529 skuInfo
.setValue(defaultVal
);
1532 if (dataType
.equals("UINT8")){
1533 skuInfo
.setValue("0");
1535 if (dataType
.equals("UINT16")) {
1536 skuInfo
.setValue("0");
1538 if (dataType
.equals("UINT32")) {
1539 skuInfo
.setValue("0");
1541 if (dataType
.equals("UINT64")){
1542 skuInfo
.setValue("0");
1544 if (dataType
.equals("BOOLEAN")){
1545 skuInfo
.setValue("false");
1547 if (dataType
.equals("VOID*")) {
1548 skuInfo
.setValue("");
1551 if (dataType
.equals("UINT8")){
1552 dynPcdData
.setMaxDatumSize(1);
1554 if (dataType
.equals("UINT16")) {
1555 dynPcdData
.setMaxDatumSize(2);
1557 if (dataType
.equals("UINT32")) {
1558 dynPcdData
.setMaxDatumSize(4);
1560 if (dataType
.equals("UINT64")){
1561 dynPcdData
.setMaxDatumSize(8);
1563 if (dataType
.equals("BOOLEAN")){
1564 dynPcdData
.setMaxDatumSize(1);
1566 if (dataType
.equals("VOID*")) {
1567 int maxSize
= setMaxSizeForPointer(defaultVal
);
1568 dynPcdData
.setMaxDatumSize(maxSize
);
1572 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1573 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1578 XmlCursor cursor
= o
.newCursor();
1579 if (cursor
.toFirstChild()) {
1581 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1582 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1583 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1585 if (getDynamicPcdBuildDataCount() == 1) {
1588 fpdDynPcdBuildDefs
= null;
1596 while (cursor
.toNextSibling());
1601 // Get the Sku Info count of ith dyn pcd element.
1603 public int getDynamicPcdSkuInfoCount(int i
){
1604 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1605 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1606 removeElement(getfpdDynPcdBuildDefs());
1607 fpdDynPcdBuildDefs
= null;
1611 int skuInfoCount
= 0;
1612 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1613 if (cursor
.toFirstChild()) {
1614 for (int j
= 0; j
< i
; ++j
) {
1615 cursor
.toNextSibling();
1617 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1618 if (pcdData
.getSkuInfoList() == null) {
1622 skuInfoCount
= pcdData
.getSkuInfoList().size();
1626 return skuInfoCount
;
1629 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1630 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1631 removeElement(getfpdDynPcdBuildDefs());
1632 fpdDynPcdBuildDefs
= null;
1636 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1637 if (cursor
.toFirstChild()) {
1638 for (int j
= 0; j
< i
; ++j
) {
1639 cursor
.toNextSibling();
1641 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1642 if (pcdData
.getSkuInfoList() == null) {
1647 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1649 while (li
.hasNext()) {
1650 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1651 saa
[k
][0] = skuInfo
.getSkuId()+"";
1652 saa
[k
][1] = skuInfo
.getVariableName();
1653 saa
[k
][2] = skuInfo
.getVariableGuid();
1654 saa
[k
][3] = skuInfo
.getVariableOffset();
1655 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1656 saa
[k
][5] = skuInfo
.getVpdOffset();
1657 saa
[k
][6] = skuInfo
.getValue();
1667 public String
getDynamicPcdBuildDataValue(int i
){
1668 String value
= null;
1669 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1670 removeElement(getfpdDynPcdBuildDefs());
1671 fpdDynPcdBuildDefs
= null;
1675 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1676 if (cursor
.toFirstChild()) {
1677 for (int j
= 0; j
< i
; ++j
) {
1678 cursor
.toNextSibling();
1680 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1681 if (pcdData
.getSkuInfoList() == null) {
1685 value
= pcdData
.getSkuInfoArray(0).getValue();
1692 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1693 String vpdOffset
= null;
1694 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1695 removeElement(getfpdDynPcdBuildDefs());
1696 fpdDynPcdBuildDefs
= null;
1700 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1701 if (cursor
.toFirstChild()) {
1702 for (int j
= 0; j
< i
; ++j
) {
1703 cursor
.toNextSibling();
1705 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1706 if (pcdData
.getSkuInfoList() == null) {
1710 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1717 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1718 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1719 removeElement(getfpdDynPcdBuildDefs());
1720 fpdDynPcdBuildDefs
= null;
1724 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1725 if (cursor
.toFirstChild()) {
1726 for (int j
= 0; j
< i
; ++j
) {
1727 cursor
.toNextSibling();
1729 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1730 if (pcdData
.getSkuInfoList() == null) {
1735 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1736 cursor
.toChild(qSkuInfo
);
1743 // generate sku info for ith dyn pcd build data.
1745 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1746 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1747 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1751 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1752 if (cursor
.toFirstChild()) {
1753 for (int j
= 0; j
< i
; ++j
) {
1754 cursor
.toNextSibling();
1756 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1757 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1758 skuInfo
.setSkuId(new BigInteger(id
));
1759 if (varName
!= null){
1760 skuInfo
.setVariableName(varName
);
1761 skuInfo
.setVariableGuid(varGuid
);
1762 skuInfo
.setVariableOffset(varOffset
);
1763 skuInfo
.setHiiDefaultValue(hiiDefault
);
1765 else if (vpdOffset
!= null){
1766 skuInfo
.setVpdOffset(vpdOffset
);
1769 skuInfo
.setValue(value
);
1774 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1775 String hiiDefault
, String vpdOffset
, String value
, int i
){
1776 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1777 removeElement(getfpdDynPcdBuildDefs());
1778 fpdDynPcdBuildDefs
= null;
1782 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1783 if (cursor
.toFirstChild()) {
1784 for (int j
= 0; j
< i
; ++j
) {
1785 cursor
.toNextSibling();
1787 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1788 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1789 while (li
.hasNext()) {
1790 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1791 if (skuInfo
.getSkuId().toString().equals(id
)){
1792 if (varName
!= null){
1793 skuInfo
.setVariableName(varName
);
1794 skuInfo
.setVariableGuid(varGuid
);
1795 skuInfo
.setVariableOffset(varOffset
);
1796 skuInfo
.setHiiDefaultValue(hiiDefault
);
1798 else if (vpdOffset
!= null){
1799 skuInfo
.setVpdOffset(vpdOffset
);
1802 skuInfo
.setValue(value
);
1810 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1811 if (fpdBuildOpts
== null) {
1812 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1814 return fpdBuildOpts
;
1817 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1818 QName elementFvName
= new QName (xmlNs
, "FvName");
1819 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1820 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1821 QName elementModule
= new QName(xmlNs
, "Module");
1823 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1824 userExts
.setUserID(userId
);
1825 userExts
.setIdentifier(new BigInteger(id
));
1826 XmlCursor cursor
= userExts
.newCursor();
1827 cursor
.toEndToken();
1829 cursor
.beginElement(elementFvName
);
1830 cursor
.insertChars(fvName
);
1831 cursor
.toNextToken();
1833 cursor
.beginElement(elementInfFileName
);
1834 cursor
.insertChars(outputFileName
);
1835 cursor
.toNextToken();
1837 cursor
.beginElement(elementIncludeModules
);
1838 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1839 cursor
.beginElement(elementModule
);
1840 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1841 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1842 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1844 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1845 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1846 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1849 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1850 cursor
.toEndToken();
1851 cursor
.toNextToken();
1856 public int getUserExtsIncModCount (String fvName
, String userId
, int id
) {
1857 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1861 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1862 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1863 while (li
.hasNext()) {
1864 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1865 if (!ues
.getUserID().equals(userId
)) {
1868 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
1871 XmlCursor cursor
= ues
.newCursor();
1872 cursor
.toFirstChild();
1873 String elementName
= cursor
.getTextValue();
1874 if (elementName
.equals(fvName
)) {
1875 cursor
.toNextSibling(elementIncludeModules
);
1876 if (cursor
.toFirstChild()) {
1878 for (i
= 1; cursor
.toNextSibling(); ++i
);
1890 public void getUserExtsIncMods(String fvName
, String userId
, int id
, String
[][] saa
) {
1891 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1895 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1896 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1897 QName attribUserId
= new QName ("UserID");
1898 QName attribId
= new QName ("Identifier");
1899 QName elementFvName
= new QName (xmlNs
, "FvName");
1900 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1901 QName attribModuleGuid
= new QName("ModuleGuid");
1902 QName attribModuleVersion
= new QName("ModuleVersion");
1903 QName attribPackageGuid
= new QName("PackageGuid");
1904 QName attribPackageVersion
= new QName("PackageVersion");
1905 QName attribArch
= new QName("Arch");
1907 if (cursor
.toChild(elementUserExts
)) {
1910 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
1911 cursor
.toChild(elementFvName
);
1912 String elementName
= cursor
.getTextValue();
1913 if (elementName
.equals(fvName
)) {
1914 cursor
.toNextSibling(elementIncludeModules
);
1915 if (cursor
.toFirstChild()) {
1918 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1919 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1920 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1921 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1922 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1924 }while (cursor
.toNextSibling());
1930 }while (cursor
.toNextSibling(elementUserExts
));
1936 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1937 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1940 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1941 while (li
.hasNext()) {
1942 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1943 if (!ues
.getUserID().equals("IMAGES")) {
1946 XmlCursor cursor
= ues
.newCursor();
1947 cursor
.toFirstChild();
1948 String elementName
= cursor
.getTextValue();
1949 if (elementName
.equals(oldFvName
)) {
1950 cursor
.setTextValue(newFvName
);
1957 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, int id
) {
1958 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1962 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1963 while (li
.hasNext()) {
1964 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1965 if (!ues
.getUserID().equals(userId
)) {
1968 if (ues
.getIdentifier()== null || ues
.getIdentifier().intValue() != id
) {
1971 XmlCursor cursor
= ues
.newCursor();
1972 cursor
.toFirstChild();
1973 String elementName
= cursor
.getTextValue();
1974 if (elementName
.equals(fvName
)) {
1985 private boolean versionEqual (String v1
, String v2
) {
1987 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1988 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1992 if (v1
!= null && v1
.equals(v2
)) {
1999 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2000 boolean inList
= false;
2001 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
2002 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2003 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2004 QName attribUserId
= new QName ("UserID");
2005 QName attribId
= new QName ("Identifier");
2006 QName elementFvName
= new QName (xmlNs
, "FvName");
2007 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2008 QName attribModuleGuid
= new QName("ModuleGuid");
2009 QName attribModuleVersion
= new QName("ModuleVersion");
2010 QName attribPackageGuid
= new QName("PackageGuid");
2011 QName attribPackageVersion
= new QName("PackageVersion");
2012 QName attribArch
= new QName("Arch");
2014 if (cursor
.toChild(elementUserExts
)) {
2017 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2018 cursor
.toChild(elementFvName
);
2019 String elementName
= cursor
.getTextValue();
2020 if (elementName
.equals(fvName
)) {
2021 cursor
.toNextSibling(elementIncludeModules
);
2022 if (cursor
.toFirstChild()) {
2025 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2026 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2027 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2028 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2029 String ar
= cursor
.getAttributeText(attribArch
);
2030 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2033 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2036 if (!arch
.equalsIgnoreCase(ar
)) {
2039 if (!versionEqual(moduleVersion
, mv
)) {
2042 if (!versionEqual(packageVersion
, pv
)) {
2047 }while (cursor
.toNextSibling());
2053 }while (cursor
.toNextSibling(elementUserExts
));
2060 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2062 // if there is only one module before remove operation, the whole user extension should be removed.
2064 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2065 if (moduleAmount
== 1) {
2066 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2070 if (moduleAmount
> 1) {
2071 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2072 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2073 QName attribUserId
= new QName ("UserID");
2074 QName attribId
= new QName ("Identifier");
2075 QName elementFvName
= new QName (xmlNs
, "FvName");
2076 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2077 QName attribModuleGuid
= new QName("ModuleGuid");
2078 QName attribModuleVersion
= new QName("ModuleVersion");
2079 QName attribPackageGuid
= new QName("PackageGuid");
2080 QName attribPackageVersion
= new QName("PackageVersion");
2081 QName attribArch
= new QName("Arch");
2083 if (cursor
.toChild(elementUserExts
)) {
2086 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2087 cursor
.toChild(elementFvName
);
2088 String elementName
= cursor
.getTextValue();
2089 if (elementName
.equals(fvName
)) {
2090 cursor
.toNextSibling(elementIncludeModules
);
2091 if (cursor
.toFirstChild()) {
2094 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2095 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2096 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2097 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2098 String ar
= cursor
.getAttributeText(attribArch
);
2099 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2102 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2105 if (!arch
.equalsIgnoreCase(ar
)) {
2108 if (!versionEqual(moduleVersion
, mv
)) {
2111 if (!versionEqual(packageVersion
, pv
)) {
2115 }while (cursor
.toNextSibling());
2121 }while (cursor
.toNextSibling(elementUserExts
));
2127 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2128 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2132 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2133 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2134 QName elementModule
= new QName(xmlNs
, "Module");
2135 while (li
.hasNext()) {
2136 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2137 if (!ues
.getUserID().equals(userId
)) {
2140 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
2143 XmlCursor cursor
= ues
.newCursor();
2144 cursor
.toFirstChild();
2145 String elementName
= cursor
.getTextValue();
2146 if (elementName
.equals(fvName
)) {
2147 cursor
.toNextSibling(elementIncludeModules
);
2148 cursor
.toLastChild();
2149 cursor
.toEndToken();
2150 cursor
.toNextToken();
2151 cursor
.beginElement(elementModule
);
2152 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2153 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2154 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2156 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2157 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2158 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2161 cursor
.insertAttributeWithValue("Arch", arch
);
2170 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2171 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2172 if (udats
== null) {
2173 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2176 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2177 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2180 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2181 at
.setId(new Integer(id
));
2182 XmlCursor cursor
= at
.newCursor();
2183 if (fileName
!= null){
2184 at
.setFilename(fileName
);
2186 else if (cursor
.toChild(xmlNs
, "Filename")) {
2189 if (execOrder
!= null) {
2190 at
.setAntCmdOptions(execOrder
);
2192 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2198 public void removeBuildOptionsUserDefAntTask(int i
) {
2199 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2203 XmlCursor cursor
= o
.newCursor();
2204 if (cursor
.toFirstChild()) {
2205 for (int j
= 0; j
< i
; ++j
) {
2206 cursor
.toNextSibling();
2209 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2217 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2218 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2222 XmlCursor cursor
= o
.newCursor();
2223 if (cursor
.toFirstChild()) {
2224 for (int j
= 0; j
< i
; ++j
) {
2225 cursor
.toNextSibling();
2227 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2228 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2233 public int getBuildOptionsUserDefAntTaskCount() {
2234 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2235 if (udats
== null || udats
.getAntTaskList() == null) {
2239 return udats
.getAntTaskList().size();
2242 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2243 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2244 if (udats
== null || udats
.getAntTaskList() == null) {
2248 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2249 ListIterator li
= l
.listIterator();
2251 while (li
.hasNext()) {
2252 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2253 saa
[i
][0] = at
.getId() + "";
2254 saa
[i
][1] = saa
[i
][2] = "";
2255 if (at
.getFilename() != null){
2256 saa
[i
][1] = at
.getFilename();
2258 if (at
.getAntCmdOptions() != null) {
2259 saa
[i
][2] = at
.getAntCmdOptions();
2264 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2265 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2267 opts
= getfpdBuildOpts().addNewOptions();
2269 OptionDocument
.Option opt
= opts
.addNewOption();
2270 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2273 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2274 opt
.setStringValue(contents
);
2275 if (buildTargets
!= null) {
2276 opt
.setBuildTargets(buildTargets
);
2279 if (opt
.isSetBuildTargets()) {
2280 opt
.unsetBuildTargets();
2284 if (toolChain
!= null && toolChain
.length() > 0) {
2285 opt
.setToolChainFamily(toolChain
);
2288 if (opt
.isSetToolChainFamily()) {
2289 opt
.unsetToolChainFamily();
2293 if (tagName
!= null && tagName
.length() > 0) {
2294 opt
.setTagName(tagName
);
2297 if (opt
.isSetTagName()) {
2302 if (toolCmd
!= null && toolCmd
.length() > 0) {
2303 opt
.setToolCode(toolCmd
);
2306 if (opt
.isSetToolCode()) {
2307 opt
.unsetToolCode();
2312 if (archList
!= null) {
2313 opt
.setSupArchList(archList
);
2316 if (opt
.isSetSupArchList()) {
2317 opt
.unsetSupArchList();
2322 public void removeBuildOptionsOpt(int i
){
2324 XmlObject o
= getfpdBuildOpts().getOptions();
2329 XmlCursor cursor
= o
.newCursor();
2330 if (cursor
.toFirstChild()) {
2331 for (int j
= 0; j
< i
; ++j
) {
2332 cursor
.toNextSibling();
2335 if (getBuildOptionsOptCount() == 0) {
2343 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2344 XmlObject o
= getfpdBuildOpts().getOptions();
2349 XmlCursor cursor
= o
.newCursor();
2350 if (cursor
.toFirstChild()) {
2351 for (int j
= 0; j
< i
; ++j
) {
2352 cursor
.toNextSibling();
2354 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2355 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2360 public int getBuildOptionsOptCount(){
2361 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2364 return getfpdBuildOpts().getOptions().getOptionList().size();
2367 public void getBuildOptionsOpts(String
[][] saa
) {
2368 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2372 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2373 ListIterator li
= lOpt
.listIterator();
2375 while(li
.hasNext()) {
2376 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2377 if (opt
.getBuildTargets() != null) {
2378 saa
[i
][0] = listToString(opt
.getBuildTargets());
2380 saa
[i
][1] = opt
.getToolChainFamily();
2381 if (opt
.getSupArchList() != null){
2382 saa
[i
][2] = listToString(opt
.getSupArchList());
2385 saa
[i
][3] = opt
.getToolCode();
2386 saa
[i
][4] = opt
.getTagName();
2387 saa
[i
][5] = opt
.getStringValue();
2393 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2394 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2395 ffs
.setFfsKey(ffsKey
);
2397 ffs
.addNewSections().setEncapsulationType(type
);
2401 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2402 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2403 ffs
.getSections().setEncapsulationType(type
);
2406 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2407 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2408 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2409 attrib
.setName(name
);
2410 attrib
.setValue(value
);
2413 /**update jth attribute of ith ffs.
2417 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2418 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2419 XmlCursor cursor
= ffs
.newCursor();
2420 QName qAttrib
= new QName(xmlNs
, "Attribute");
2421 if (cursor
.toChild(qAttrib
)) {
2422 for (int k
= 0; k
< j
; ++k
) {
2423 cursor
.toNextSibling(qAttrib
);
2425 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2426 attrib
.setName(name
);
2427 attrib
.setValue(value
);
2432 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2433 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2434 XmlCursor cursor
= ffs
.newCursor();
2435 QName qAttrib
= new QName(xmlNs
, "Attribute");
2436 if (cursor
.toChild(qAttrib
)) {
2437 for (int k
= 0; k
< j
; ++k
) {
2438 cursor
.toNextSibling(qAttrib
);
2445 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2446 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2450 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2452 if (sections
== null){
2453 sections
= ffs
.addNewSections();
2455 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2458 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2459 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2460 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2461 if (sections
== null) {
2464 XmlCursor cursor
= sections
.newCursor();
2465 QName qSection
= new QName(xmlNs
, "Section");
2466 if (cursor
.toChild(qSection
)) {
2467 for (int k
= 0; k
< j
; ++k
) {
2468 cursor
.toNextSibling(qSection
);
2475 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2476 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2477 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2478 if (sections
== null) {
2481 XmlCursor cursor
= sections
.newCursor();
2482 QName qSection
= new QName(xmlNs
, "Section");
2483 if (cursor
.toChild(qSection
)) {
2484 for (int k
= 0; k
< j
; ++k
) {
2485 cursor
.toNextSibling(qSection
);
2487 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2488 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2493 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2494 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2498 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2500 if (sections
== null){
2501 sections
= ffs
.addNewSections();
2503 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2504 sections2
.setEncapsulationType(encapType
);
2505 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2508 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2509 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2510 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2511 if (sections
== null) {
2514 XmlCursor cursor
= sections
.newCursor();
2515 QName qSections
= new QName(xmlNs
, "Sections");
2516 if (cursor
.toChild(qSections
)) {
2517 for (int k
= 0; k
< j
; ++k
) {
2518 cursor
.toNextSibling(qSections
);
2525 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2526 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2527 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2528 if (sections
== null) {
2531 XmlCursor cursor
= sections
.newCursor();
2532 QName qSections
= new QName(xmlNs
, "Sections");
2533 if (cursor
.toChild(qSections
)) {
2534 for (int k
= 0; k
< j
; ++k
) {
2535 cursor
.toNextSibling(qSections
);
2537 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2538 sections2
.setEncapsulationType(type
);
2543 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2544 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2548 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2549 XmlCursor cursor
= sections
.newCursor();
2550 QName qSections
= new QName(xmlNs
, "Sections");
2551 if (cursor
.toChild(qSections
)){
2552 for (int k
= 0; k
< j
; ++k
) {
2553 cursor
.toNextSibling(qSections
);
2555 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2556 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2561 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2562 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2563 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2564 if (sections
== null) {
2567 XmlCursor cursor
= sections
.newCursor();
2568 QName qSections
= new QName(xmlNs
, "Sections");
2569 if (cursor
.toChild(qSections
)) {
2570 for (int l
= 0; l
< j
; ++l
) {
2571 cursor
.toNextSibling(qSections
);
2573 if (cursor
.toFirstChild()) {
2575 for (; m
< k
; ++m
) {
2576 cursor
.toNextSibling();
2588 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2589 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2590 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2591 if (sections
== null) {
2594 XmlCursor cursor
= sections
.newCursor();
2595 QName qSections
= new QName(xmlNs
, "Sections");
2596 if (cursor
.toChild(qSections
)) {
2597 for (int l
= 0; l
< j
; ++l
) {
2598 cursor
.toNextSibling(qSections
);
2600 if (cursor
.toFirstChild()) {
2601 for (int m
= 0; m
< k
; ++m
) {
2602 cursor
.toNextSibling();
2604 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2605 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2611 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2612 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2616 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2617 XmlCursor cursor
= sections
.newCursor();
2618 QName qSections
= new QName(xmlNs
, "Sections");
2619 if (cursor
.toChild(qSections
)){
2620 for (int k
= 0; k
< j
; ++k
) {
2621 cursor
.toNextSibling(qSections
);
2623 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2624 if (sections2
.getSectionList() == null){
2628 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2629 while(li
.hasNext()) {
2630 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2631 // if (section.isSetSectionType()) {
2632 al
.add(section
.getSectionType()+"");
2641 public int getBuildOptionsFfsCount(){
2642 if (getfpdBuildOpts().getFfsList() == null) {
2645 return getfpdBuildOpts().getFfsList().size();
2648 public void getBuildOptionsFfsKey(String
[][] saa
) {
2649 if (getfpdBuildOpts().getFfsList() == null) {
2652 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2654 while(li
.hasNext()){
2655 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2656 saa
[i
][0] = ffs
.getFfsKey();
2661 public void updateBuildOptionsFfsKey(int i
, String key
) {
2662 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2666 /**Get ith FFS key and contents.
2669 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2670 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2674 sa
[0] = ffs
.getFfsKey();
2675 if (ffs
.getSections() != null) {
2676 if(ffs
.getSections().getEncapsulationType() != null){
2677 sa
[1] = ffs
.getSections().getEncapsulationType();
2679 if (ffs
.getSections().getSectionList() != null){
2680 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2681 while (li
.hasNext()) {
2682 firstLevelSection
.add(li
.next().getSectionType()+"");
2685 if (ffs
.getSections().getSectionsList() != null) {
2686 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2687 while(li
.hasNext()) {
2688 firstLevelSections
.add(li
.next().getEncapsulationType());
2692 if (ffs
.getAttributeList() != null) {
2693 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2694 while(li
.hasNext()) {
2695 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2696 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2705 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2706 XmlObject o
= getfpdBuildOpts();
2707 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2709 XmlCursor cursor
= o
.newCursor();
2710 QName qFfs
= new QName(xmlNs
, "Ffs");
2711 if (cursor
.toChild(qFfs
)) {
2712 for (int j
= 0; j
< i
; ++j
) {
2713 cursor
.toNextSibling(qFfs
);
2715 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2721 public void removeBuildOptionsFfs(int i
) {
2722 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2727 XmlCursor cursor
= ffs
.newCursor();
2734 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2735 if (fpdPlatformDefs
== null){
2736 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2738 return fpdPlatformDefs
;
2741 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2742 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2745 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2746 while(li
.hasNext()) {
2747 archs
.add(li
.next());
2751 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2752 if (archs
!= null) {
2753 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2756 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2757 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2758 // cursor.removeXml();
2760 // cursor.dispose();
2764 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2765 if (getfpdPlatformDefs().getBuildTargets() == null) {
2768 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2769 while(li
.hasNext()) {
2770 targets
.add(li
.next());
2774 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2775 getfpdPlatformDefs().setBuildTargets(targets
);
2778 public void genPlatformDefsSkuInfo(String id
, String name
) {
2779 SkuInfoDocument
.SkuInfo skuInfo
= null;
2780 if (getfpdPlatformDefs().getSkuInfo() == null) {
2781 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2783 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2784 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2785 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2786 skuName
.setSkuID(new BigInteger("0"));
2787 skuName
.setStringValue("DEFAULT");
2789 if (id
.equals("0")) {
2792 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2793 skuName
.setSkuID(new BigInteger(id
));
2794 skuName
.setStringValue(name
);
2797 public int getPlatformDefsSkuInfoCount(){
2798 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2801 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2804 public void getPlatformDefsSkuInfos(String
[][] saa
){
2805 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2806 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2807 removeElement(getfpdDynPcdBuildDefs());
2808 fpdDynPcdBuildDefs
= null;
2813 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2814 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2816 while(li
.hasNext()) {
2817 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2818 saa
[i
][0] = sku
.getSkuID()+"";
2819 saa
[i
][1] = sku
.getStringValue();
2824 public void removePlatformDefsSkuInfo(int i
) {
2825 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2826 if (skuInfo
== null || i
== 0) {
2830 XmlCursor cursor
= skuInfo
.newCursor();
2831 if (cursor
.toFirstChild()) {
2832 for (int j
= 0; j
< i
; ++j
) {
2833 cursor
.toNextSibling();
2840 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2841 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2842 if (skuInfo
== null || i
== 0) {
2846 XmlCursor cursor
= skuInfo
.newCursor();
2847 if (cursor
.toFirstChild()) {
2848 for (int j
= 0; j
< i
; ++j
) {
2849 cursor
.toNextSibling();
2851 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2852 sku
.setSkuID(new BigInteger(id
));
2853 sku
.setStringValue(name
);
2858 public String
getPlatformDefsInterDir(){
2859 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2862 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2865 public void setPlatformDefsInterDir(String interDir
){
2866 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2869 public String
getPlatformDefsOutputDir() {
2870 return getfpdPlatformDefs().getOutputDirectory();
2873 public void setPlatformDefsOutputDir(String outputDir
) {
2874 if (outputDir
!= null && outputDir
.length() > 0) {
2875 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2878 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2879 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2886 public FlashDocument
.Flash
getfpdFlash() {
2887 if (fpdFlash
== null) {
2888 fpdFlash
= fpdRoot
.addNewFlash();
2893 public void genFlashDefinitionFile(String file
) {
2894 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2896 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2899 fdf
.setStringValue(file
);
2902 public String
getFlashDefinitionFile() {
2903 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2908 return fdf
.getStringValue();
2911 public void genFvImagesNameValue(String name
, String value
) {
2913 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2915 fi
= getfpdFlash().addNewFvImages();
2918 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2923 public void removeFvImagesNameValue(int i
){
2925 XmlObject o
= getfpdFlash().getFvImages();
2930 QName qNameValue
= new QName(xmlNs
, "NameValue");
2931 XmlCursor cursor
= o
.newCursor();
2932 if (cursor
.toChild(qNameValue
)) {
2933 for (int j
= 0; j
< i
; ++j
) {
2934 cursor
.toNextSibling(qNameValue
);
2941 public void updateFvImagesNameValue(int i
, String name
, String value
){
2943 XmlObject o
= getfpdFlash().getFvImages();
2948 QName qNameValue
= new QName(xmlNs
, "NameValue");
2949 XmlCursor cursor
= o
.newCursor();
2950 if (cursor
.toChild(qNameValue
)) {
2951 for (int j
= 0; j
< i
; ++j
) {
2952 cursor
.toNextSibling(qNameValue
);
2954 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2961 public int getFvImagesNameValueCount() {
2963 FvImagesDocument
.FvImages fi
= null;
2964 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2967 return fi
.getNameValueList().size();
2970 public void getFvImagesNameValues(String
[][] nv
) {
2972 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2976 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2978 ListIterator li
= l
.listIterator();
2979 while (li
.hasNext()) {
2980 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2982 nv
[i
][0] = e
.getName();
2983 nv
[i
][1] = e
.getValue();
2989 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2990 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2991 if (fis
== null || fis
.getFvImageList() == null) {
2995 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2996 while (li
.hasNext()) {
2997 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2998 if (fi
.getType().toString().equals("ImageName")) {
2999 vImageNames
.addAll(fi
.getFvImageNamesList());
3005 public void addFvImageFvImageNames (String
[] fvNames
) {
3006 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3007 if (fis
== null || fis
.getFvImageList() == null) {
3008 genFvImagesFvImage (fvNames
, "ImageName", null);
3012 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3013 while (li
.hasNext()) {
3014 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3015 if (fi
.getType().toString().equals("ImageName")) {
3016 addFvImageNamesInFvImage (fi
, fvNames
);
3020 genFvImagesFvImage (fvNames
, "ImageName", null);
3023 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3025 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3026 fi
.addFvImageNames(fvNames
[i
]);
3030 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3031 XmlObject o
= getfpdFlash().getFvImages();
3035 XmlCursor cursor
= o
.newCursor();
3036 QName qFvImage
= new QName(xmlNs
, "FvImage");
3037 if (cursor
.toChild(qFvImage
)) {
3038 for (int j
= 0; j
< i
; ++j
) {
3039 cursor
.toNextSibling(qFvImage
);
3041 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3042 addFvImageNamesInFvImage(fi
, fvNames
);
3047 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3049 FvImagesDocument
.FvImages fis
= null;
3050 if ((fis
= getfpdFlash().getFvImages()) == null) {
3051 fis
= getfpdFlash().addNewFvImages();
3055 //gen FvImage with FvImageNames array
3057 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3058 for (int i
= 0; i
< names
.length
; ++i
) {
3059 fi
.addFvImageNames(names
[i
]);
3061 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3062 if (options
!= null){
3063 setFvImagesFvImageFvImageOptions(options
, fi
);
3067 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3068 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3070 fio
= fi
.addNewFvImageOptions();
3073 Set
<String
> key
= options
.keySet();
3074 Iterator
<String
> i
= key
.iterator();
3075 while (i
.hasNext()) {
3077 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3078 String k
= (String
)i
.next();
3081 nv
.setValue((String
)options
.get(k
));
3088 public void removeFvImagesFvImage(int i
) {
3090 XmlObject o
= getfpdFlash().getFvImages();
3095 QName qFvImage
= new QName(xmlNs
, "FvImage");
3096 XmlCursor cursor
= o
.newCursor();
3097 if (cursor
.toChild(qFvImage
)) {
3098 for (int j
= 0; j
< i
; ++j
) {
3099 cursor
.toNextSibling(qFvImage
);
3108 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3110 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3111 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3114 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3115 while (li
.hasNext()) {
3116 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3117 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3118 if (fi
.getFvImageNamesList().size() == 0) {
3124 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3125 XmlObject o
= getfpdFlash().getFvImages();
3129 XmlCursor cursor
= o
.newCursor();
3130 QName qFvImage
= new QName(xmlNs
, "FvImage");
3131 if (cursor
.toChild(qFvImage
)) {
3132 for (int j
= 0; j
< i
; ++j
) {
3133 cursor
.toNextSibling(qFvImage
);
3135 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3136 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3142 * @param oldFvName The FV Name to be replaced.
3143 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3145 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3146 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3147 XmlCursor cursor
= fi
.newCursor();
3149 if (cursor
.toChild(qFvImageNames
)) {
3151 String xmlValue
= cursor
.getTextValue();
3152 if (xmlValue
.equals(oldFvName
)){
3153 if (newFvName
!= null) {
3154 cursor
.setTextValue(newFvName
);
3160 }while (cursor
.toNextSibling(qFvImageNames
));
3166 /**update the Type attribute of ith FvImage with new type.
3170 public void updateFvImagesFvImageType (int i
, String type
) {
3171 XmlObject o
= getfpdFlash().getFvImages();
3175 XmlCursor cursor
= o
.newCursor();
3176 QName qFvImage
= new QName(xmlNs
, "FvImage");
3177 if (cursor
.toChild(qFvImage
)) {
3178 for (int j
= 0; j
< i
; ++j
) {
3179 cursor
.toNextSibling(qFvImage
);
3181 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3182 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3187 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3189 XmlObject o
= getfpdFlash().getFvImages();
3193 XmlCursor cursor
= o
.newCursor();
3194 QName qFvImage
= new QName(xmlNs
, "FvImage");
3195 if (cursor
.toChild(qFvImage
)) {
3196 for (int j
= 0; j
< i
; ++j
) {
3197 cursor
.toNextSibling(qFvImage
);
3199 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3200 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3203 // remove old FvImageNames before adding new ones
3205 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3206 cursor
.toChild(qFvImageNames
);
3208 while (cursor
.toNextSibling(qFvImageNames
)) {
3212 for (int k
= 0; k
< names
.length
; ++k
) {
3213 fi
.addFvImageNames(names
[k
]);
3216 // remove old FvImageOptions before adding new options
3218 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3219 cursor
.toNextSibling(qFvImageOptions
);
3222 setFvImagesFvImageFvImageOptions(options
, fi
);
3227 public int getFvImagesFvImageCount(String type
) {
3229 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3232 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3233 ListIterator li
= l
.listIterator();
3235 while(li
.hasNext()) {
3236 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3237 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3247 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3248 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3249 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3252 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3253 ListIterator li
= l
.listIterator();
3254 while(li
.hasNext()) {
3255 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3256 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3259 if (fi
.getFvImageNamesList().contains(fvName
)) {
3268 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3270 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3272 if (getfpdFlash().getFvImages() == null) {
3275 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3279 ListIterator li
= l
.listIterator();
3281 while(li
.hasNext()) {
3282 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3283 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3287 // get FvImageNames array, space separated
3289 List
<String
> lfn
= fi
.getFvImageNamesList();
3290 ListIterator lfni
= lfn
.listIterator();
3292 while (lfni
.hasNext()) {
3293 saa
[i
][0] += (String
)lfni
.next();
3296 saa
[i
][0] = saa
[i
][0].trim();
3298 saa
[i
][1] = fi
.getType()+"";
3304 public void removeFvImageNameValue (int i
, String attributeName
) {
3305 XmlObject o
= getfpdFlash().getFvImages();
3309 XmlCursor cursor
= o
.newCursor();
3310 QName qFvImage
= new QName(xmlNs
, "FvImage");
3311 if (cursor
.toChild(qFvImage
)) {
3312 for (int j
= 0; j
< i
; ++j
) {
3313 cursor
.toNextSibling(qFvImage
);
3315 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3316 removeFvImageNameValue (fi
, attributeName
);
3320 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3322 * @param attributeName
3324 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3325 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3326 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3327 while (li
.hasNext()) {
3328 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3329 if (nv
.getName().equals(attributeName
)) {
3336 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3337 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3338 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3339 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3340 removeFvImageNameValue (fi
, optName
);
3344 /**Add name-value pair to FvImage element with type.
3345 * @param fvName FV name to add name-value pair.
3346 * @param type FvImage attribute.
3350 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3351 boolean fvImageExists
= false;
3352 if (getfpdFlash().getFvImages() != null) {
3354 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3356 ListIterator li
= l
.listIterator();
3357 while (li
.hasNext()) {
3358 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3359 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3362 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3365 fvImageExists
= true;
3366 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3371 if (!fvImageExists
) {
3372 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3373 map
.put(name
, value
);
3374 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3378 /**Add to all FvImage elements with type, the name-value pair.
3383 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3384 if (getfpdFlash().getFvImages() == null) {
3387 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3391 ListIterator li
= l
.listIterator();
3392 while(li
.hasNext()) {
3393 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3394 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3397 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3402 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3403 XmlObject o
= getfpdFlash().getFvImages();
3407 XmlCursor cursor
= o
.newCursor();
3408 QName qFvImage
= new QName(xmlNs
, "FvImage");
3409 if (cursor
.toChild(qFvImage
)) {
3410 for (int j
= 0; j
< i
; ++j
) {
3411 cursor
.toNextSibling(qFvImage
);
3413 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3414 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3419 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3425 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3426 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3427 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3430 if (newName
!= null && !newName
.equals(name
)) {
3431 nv
.setName(newName
);
3436 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3437 if (cursor
.toFirstChild()) {
3439 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3440 if (nv
.getName().equals(name
)) {
3442 if (newName
!= null && !newName
.equals(name
)) {
3443 nv
.setName(newName
);
3448 }while (cursor
.toNextSibling());
3451 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3454 if (newName
!= null && !newName
.equals(name
)) {
3455 nv
.setName(newName
);
3460 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3461 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3462 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3463 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3464 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3468 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3471 while (li
.hasNext()) {
3472 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3473 m
.put(nv
.getName(), nv
.getValue());
3478 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3479 XmlObject o
= getfpdFlash().getFvImages();
3485 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3486 Vector
<String
> vFvNames
= new Vector
<String
>();
3489 XmlCursor cursor
= o
.newCursor();
3490 QName qFvImage
= new QName(xmlNs
, "FvImage");
3491 if (cursor
.toChild(qFvImage
)) {
3494 vFvNames
.removeAllElements();
3495 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3496 vFvNames
.add(fvNameArray
[i
]);
3498 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3499 if (!fi
.getType().toString().equals(type
)) {
3502 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3505 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3506 while (li
.hasNext()) {
3507 String name
= li
.next();
3508 vFvNames
.remove(name
);
3510 if (vFvNames
.size() == 0) {
3515 }while (cursor
.toNextSibling(qFvImage
));
3521 /**Get FvImage Options for FvImage i
3522 * @param i the ith FvImage
3524 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3525 XmlObject o
= getfpdFlash().getFvImages();
3529 XmlCursor cursor
= o
.newCursor();
3530 QName qFvImage
= new QName(xmlNs
, "FvImage");
3531 if (cursor
.toChild(qFvImage
)) {
3532 for (int j
= 0; j
< i
; ++j
) {
3533 cursor
.toNextSibling(qFvImage
);
3535 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3536 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3540 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3541 while(li
.hasNext()){
3542 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3543 m
.put(nv
.getName(), nv
.getValue());
3550 Get platform header element
3551 @return PlatformHeaderDocument.PlatformHeader
3553 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3554 if (fpdHdr
== null) {
3555 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3561 public String
getFpdHdrPlatformName() {
3562 return getFpdHdr().getPlatformName();
3565 public String
getFpdHdrGuidValue() {
3566 return getFpdHdr().getGuidValue();
3569 public String
getFpdHdrVer() {
3570 return getFpdHdr().getVersion();
3573 public String
getFpdHdrAbs() {
3574 return getFpdHdr().getAbstract();
3577 public String
getFpdHdrDescription() {
3578 return getFpdHdr().getDescription();
3581 public String
getFpdHdrCopyright() {
3582 return getFpdHdr().getCopyright();
3585 public String
getFpdHdrLicense() {
3586 LicenseDocument
.License l
= getFpdHdr().getLicense();
3590 return l
.getStringValue();
3593 public String
getFpdHdrUrl() {
3594 LicenseDocument
.License l
= getFpdHdr().getLicense();
3601 public String
getFpdHdrSpec() {
3603 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3604 // return getFpdHdr().getSpecification();
3607 public void setFpdHdrPlatformName(String name
){
3608 getFpdHdr().setPlatformName(name
);
3611 public void setFpdHdrGuidValue(String guid
){
3612 getFpdHdr().setGuidValue(guid
);
3615 public void setFpdHdrVer(String v
){
3616 getFpdHdr().setVersion(v
);
3619 public void setFpdHdrAbs(String abs
) {
3620 getFpdHdr().setAbstract(abs
);
3623 public void setFpdHdrDescription(String desc
){
3624 getFpdHdr().setDescription(desc
);
3627 public void setFpdHdrCopyright(String cr
) {
3628 getFpdHdr().setCopyright(cr
);
3631 public void setFpdHdrLicense(String license
){
3632 LicenseDocument
.License l
= getFpdHdr().getLicense();
3634 getFpdHdr().addNewLicense().setStringValue(license
);
3637 l
.setStringValue(license
);
3641 public void setFpdHdrUrl(String url
){
3642 LicenseDocument
.License l
= getFpdHdr().getLicense();
3648 public void setFpdHdrSpec(String s
){
3649 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3650 getFpdHdr().setSpecification(s
);
3653 Save the processed xml contents to file
3655 @param fpdFile The file to save xml contents
3656 @throws IOException Exceptions during file operation
3658 public void saveAs(File fpdFile
) throws IOException
{
3660 XmlOptions options
= new XmlOptions();
3662 options
.setCharacterEncoding("UTF-8");
3663 options
.setSavePrettyPrint();
3664 options
.setSavePrettyPrintIndent(2);
3666 fpdd
.save(fpdFile
, options
);
3667 } catch (IOException e
) {
3668 e
.printStackTrace();
3673 private String
listToString(List l
) {
3678 ListIterator li
= l
.listIterator();
3679 while(li
.hasNext()) {
3686 private void removeElement(XmlObject o
) {
3687 XmlCursor cursor
= o
.newCursor();
3693 class PcdItemTypeConflictException
extends Exception
{
3698 private static final long serialVersionUID
= 1L;
3699 private String details
= null;
3701 PcdItemTypeConflictException (String pcdName
, String info
) {
3702 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3704 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3707 details
= pcdName
+ " ItemType Conflicts with " + info
;
3711 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3712 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3713 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3714 String moduleInfo1
= "";
3715 String moduleInfo2
= "";
3717 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3720 moduleInfo1
= info1
;
3724 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3727 moduleInfo2
= info2
;
3730 details
= pcdName
+ " ItemType Conflicts in " + moduleInfo1
+ " and " + moduleInfo2
;
3733 public String
getMessage() {
3738 class PcdDeclNotFound
extends Exception
{
3743 private static final long serialVersionUID
= 1L;
3744 private String details
= null;
3746 PcdDeclNotFound(String info
) {
3747 details
= "PcdDeclNotFound: " + info
;
3750 public String
getMessage() {
3755 class PcdValueMalFormed
extends Exception
{
3760 private static final long serialVersionUID
= 1L;
3761 private String details
= null;
3763 PcdValueMalFormed(String info
) {
3764 details
= "PcdValueMalFormed: " + info
;
3767 public String
getMessage() {