2 Java class FpdFileContents is used to parse fpd xml file.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.frameworkwizard
.platform
.ui
;
16 import java
.io
.IOException
;
17 import java
.math
.BigInteger
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
22 import java
.util
.List
;
23 import java
.util
.ListIterator
;
26 import java
.util
.Vector
;
28 import javax
.xml
.namespace
.QName
;
30 import org
.apache
.xmlbeans
.XmlCursor
;
31 import org
.apache
.xmlbeans
.XmlObject
;
32 import org
.apache
.xmlbeans
.XmlOptions
;
33 import org
.tianocore
.AntTaskDocument
;
34 import org
.tianocore
.BuildOptionsDocument
;
35 import org
.tianocore
.DynamicPcdBuildDefinitionsDocument
;
36 import org
.tianocore
.EfiSectionType
;
37 import org
.tianocore
.FlashDefinitionFileDocument
;
38 import org
.tianocore
.FlashDocument
;
39 import org
.tianocore
.FrameworkModulesDocument
;
40 import org
.tianocore
.IntermediateOutputType
;
41 import org
.tianocore
.LibrariesDocument
;
42 import org
.tianocore
.ModuleSADocument
;
43 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
44 import org
.tianocore
.ModuleSurfaceAreaDocument
;
45 import org
.tianocore
.OptionDocument
;
46 import org
.tianocore
.OptionsDocument
;
47 import org
.tianocore
.PcdBuildDefinitionDocument
;
48 import org
.tianocore
.PcdCodedDocument
;
49 import org
.tianocore
.PcdDataTypes
;
50 import org
.tianocore
.PcdDeclarationsDocument
;
51 import org
.tianocore
.PcdItemTypes
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PlatformSurfaceAreaDocument
;
54 import org
.tianocore
.FvImageTypes
;
55 import org
.tianocore
.FvImagesDocument
;
56 import org
.tianocore
.LicenseDocument
;
57 import org
.tianocore
.PlatformHeaderDocument
;
58 import org
.tianocore
.SkuInfoDocument
;
59 import org
.tianocore
.UserDefinedAntTasksDocument
;
60 import org
.tianocore
.UserExtensionsDocument
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.WorkspaceProfile
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.global
.SurfaceAreaQuery
;
63 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
64 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
70 public class FpdFileContents
{
72 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
73 static final String regExpNewLineAndSpaces
= "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
75 private PlatformSurfaceAreaDocument fpdd
= null;
77 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
79 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
81 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
83 private FlashDocument
.Flash fpdFlash
= null;
85 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
87 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
89 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
91 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
93 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
95 private String
itemType (String pcdInfo
) {
97 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
101 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
103 public void initDynPcdMap() {
104 if (dynPcdMap
== null) {
105 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
106 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
108 removeElement(getfpdFrameworkModules());
109 fpdFrameworkModules
= null;
112 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
113 while (li
.hasNext()) {
114 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
115 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
118 String ModuleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion() +
119 " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
120 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
121 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
122 while (lpi
.hasNext()) {
123 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
124 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
125 if (dynPcdMap
.get(pcdKey
) == null) {
126 ArrayList
<String
> al
= new ArrayList
<String
>();
127 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
128 dynPcdMap
.put(pcdKey
, al
);
131 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
138 public ArrayList
<String
> getDynPcdMapValue(String key
) {
139 return dynPcdMap
.get(key
);
142 Constructor to create a new spd file
144 public FpdFileContents() {
146 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
147 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
152 Constructor for existing document object
155 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
157 fpdHdr
= fpdRoot
.getPlatformHeader();
158 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
159 fpdBuildOpts
= fpdRoot
.getBuildOptions();
160 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
161 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
162 fpdFlash
= fpdRoot
.getFlash();
166 Constructor based on an existing spd file
168 @param f Existing spd file
170 public FpdFileContents(File f
) {
172 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
173 fpdRoot
= fpdd
.getPlatformSurfaceArea();
174 } catch (Exception e
) {
175 System
.out
.println(e
.toString());
179 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
180 if (fpdDynPcdBuildDefs
== null){
181 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
183 return fpdDynPcdBuildDefs
;
186 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
187 if (fpdFrameworkModules
== null){
188 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
190 return fpdFrameworkModules
;
193 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
194 if (getFrameworkModulesCount() == 0){
198 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
199 while(li
.hasNext()) {
200 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
201 if (moduleSa
.getModuleSaBuildOptions() == null) {
204 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
205 if (fvBinding
== null) {
209 String
[] fvNames
= fvBinding
.split(" ");
210 for (int i
= 0; i
< fvNames
.length
; ++i
) {
212 // BugBug : underscore "_" should not be replaced!!!
213 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
215 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
216 String
[] sa
= new String
[] {moduleSa
.getModuleGuid(), moduleSa
.getModuleVersion(),
217 moduleSa
.getPackageGuid(), moduleSa
.getPackageVersion(),
218 listToString(moduleSa
.getSupArchList())};
226 public int getFrameworkModulesCount() {
227 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
228 removeElement(getfpdFrameworkModules());
229 fpdFrameworkModules
= null;
232 return getfpdFrameworkModules().getModuleSAList().size();
235 public void getFrameworkModulesInfo(String
[][] saa
) {
236 if (getFrameworkModulesCount() == 0){
240 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
242 while(li
.hasNext()) {
243 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
244 saa
[i
][0] = moduleSa
.getModuleGuid();
245 saa
[i
][1] = moduleSa
.getModuleVersion();
247 saa
[i
][2] = moduleSa
.getPackageGuid();
248 saa
[i
][3] = moduleSa
.getPackageVersion();
249 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
254 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
255 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
259 sa
[0] = msa
.getModuleGuid();
260 sa
[1] = msa
.getModuleVersion();
261 sa
[2] = msa
.getPackageGuid();
262 sa
[3] = msa
.getPackageVersion();
263 sa
[4] = listToString(msa
.getSupArchList());
266 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
268 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
269 removeElement(getfpdFrameworkModules());
270 fpdFrameworkModules
= null;
273 String
[] s
= key
.split(" ");
274 String archsInKey
= "";
276 for (int i
= 4; i
< s
.length
; ++i
) {
280 archsInKey
= archsInKey
.trim();
283 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
284 while(li
.hasNext()) {
285 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
286 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
287 if (moduleSa
.getModuleVersion() != null) {
288 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
292 if (moduleSa
.getPackageVersion() != null) {
293 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
297 //ToDo add arch check .
298 if (moduleSa
.getSupArchList() != null) {
299 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
304 if (archsInKey
.length() == 0) {
313 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
314 ModuleSADocument
.ModuleSA moduleSa
= null;
315 if (fpdRoot
.getFrameworkModules() == null) {
318 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
319 if (cursor
.toFirstChild()) {
320 for (int j
= 0; j
< i
; ++j
) {
321 cursor
.toNextSibling();
323 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
329 public void removeModuleSA(int i
) {
330 XmlObject o
= fpdRoot
.getFrameworkModules();
335 XmlCursor cursor
= o
.newCursor();
336 if (cursor
.toFirstChild()) {
337 for (int j
= 0; j
< i
; ++j
) {
338 cursor
.toNextSibling();
341 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
343 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
344 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
345 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
346 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
347 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
348 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
349 while(li
.hasNext()) {
350 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
351 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
356 while (cursor
.hasPrevToken()) {
357 cursor
.toPrevToken();
358 if (!cursor
.isText()) {
361 if (cursor
.getObject() == null) {
364 String s
= cursor
.getTextValue();
365 if (s
.matches(regExpNewLineAndSpaces
)) {
370 if (cursor
.isComment()) {
376 if (getFrameworkModulesCount() == 0) {
378 removeElement(getfpdFrameworkModules());
379 fpdFrameworkModules
= null;
386 public boolean adjustPcd (int seqModuleSa
) throws Exception
{
387 boolean dataModified
= false;
388 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
389 int pcdCount
= getPcdDataCount(seqModuleSa
);
390 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
391 getPcdData(seqModuleSa
, saaModuleSaPcd
);
392 String mg
= moduleSa
.getModuleGuid().toLowerCase();
393 String mv
= moduleSa
.getModuleVersion();
394 String pg
= moduleSa
.getPackageGuid().toLowerCase();
395 String pv
= moduleSa
.getPackageVersion();
396 String arch
= listToString(moduleSa
.getSupArchList());
398 // delete pcd in ModuleSA but not in MSA files any longer.
400 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
401 int libCount
= getLibraryInstancesCount(moduleKey
);
402 String
[][] saaLib
= new String
[libCount
][5];
403 getLibraryInstances(moduleKey
, saaLib
);
404 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
406 throw new Exception ("Module does NOT exist in workspace.");
408 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
410 // create vector for module & library instance MIs.
413 for (int j
= 0; j
< saaLib
.length
; ++j
) {
414 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
415 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
419 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
421 for (int j
= 0; j
< vMi
.size(); ++j
) {
422 ModuleIdentification nextMi
= vMi
.get(j
);
423 if (nextMi
== null) {
426 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], nextMi
)) {
430 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
434 // add new Pcd from MSA file to ModuleSA.
436 for (int i
= 0; i
< vMi
.size(); ++i
) {
437 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
438 .getModuleXmlObject(vMi
440 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
443 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
444 msaPcdIter
:while (li
.hasNext()) {
445 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
446 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
448 for (int j
= 0; j
< al
.size(); ++j
) {
449 if (al
.get(j
).startsWith(moduleKey
)) {
455 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
456 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
457 if (spdPcd
== null) {
461 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
465 // AddItem to ModuleSA PcdBuildDefinitions
467 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
468 : msaPcd
.getDefaultValue();
470 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
471 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
480 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
482 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
486 String
[] s
= moduleInfo
.split(" ");
487 for(int i
= 0; i
< al
.size(); ++i
){
488 String consumer
= al
.get(i
);
489 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
490 String
[] consumerPart
= consumer
.split(" ");
491 if (!consumerPart
[4].equals(s
[4])) {
499 if (al
.size() == 0) {
500 defaultPcdValue
.remove(pcdKey
);
501 dynPcdMap
.remove(pcdKey
);
502 String
[] s1
= pcdKey
.split(" ");
503 removeDynamicPcdBuildData(s1
[0], s1
[1]);
508 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
510 public int getPcdDataCount (int i
){
511 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
513 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
516 return msa
.getPcdBuildDefinition().getPcdDataList().size();
520 public void getPcdData (int i
, String
[][] saa
) {
521 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
523 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
526 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
527 for (int k
= 0; k
< saa
.length
; ++k
) {
528 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
529 saa
[k
][0] = pcdData
.getCName();
530 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
531 saa
[k
][2] = pcdData
.getItemType()+"";
532 saa
[k
][3] = pcdData
.getToken().toString();
533 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
534 saa
[k
][5] = pcdData
.getDatumType()+"";
535 saa
[k
][6] = pcdData
.getValue();
540 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
541 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
542 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
546 String mg
= moduleSa
.getModuleGuid();
547 String mv
= moduleSa
.getModuleVersion();
548 String pg
= moduleSa
.getPackageGuid();
549 String pv
= moduleSa
.getPackageVersion();
550 String arch
= listToString(moduleSa
.getSupArchList());
551 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
553 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
554 if (cursor
.toFirstChild()){
557 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
558 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
559 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
560 if (getPcdDataCount(seqModuleSa
) == 1) {
567 while(cursor
.toNextSibling());
573 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
574 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
575 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
579 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
580 if (cursor
.toFirstChild()){
582 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
583 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
585 // change item type while not updating dynPcdData????
587 if (itemType
!= null) {
588 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
591 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
592 pcdData
.setMaxDatumSize(new Integer(maxSize
));
595 // if value input is null, keep old value untouched.
598 pcdData
.setValue(value
);
599 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
605 while(cursor
.toNextSibling());
610 /**Get original Pcd info from MSA & SPD files.
611 * @param mi ModuleIdentification from which MSA & SPD come
612 * @param cName PCD cName
613 * @param sa Results: HelpText, Original item type.
616 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
618 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
619 .getModuleXmlObject(mi
);
620 if (msa
.getPcdCoded() == null) {
624 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
626 // First look through MSA pcd entries.
628 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
629 ListIterator li
= l
.listIterator();
630 while (li
.hasNext()) {
631 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
632 if (!msaPcd
.getCName().equals(cName
)) {
635 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
638 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
639 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
643 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
646 // Get Pcd help text and original item type.
648 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
649 sa
[1] = msaPcd
.getPcdItemType() + "";
650 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
651 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
652 while (iter
.hasNext()) {
653 String usage
= iter
.next().toString();
654 validPcdTypes
.add(usage
);
662 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
663 int libCount
= getLibraryInstancesCount(moduleKey
);
664 String
[][] saaLib
= new String
[libCount
][5];
665 getLibraryInstances(moduleKey
, saaLib
);
666 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
667 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
669 // create vector for module & library instance MIs.
672 for (int j
= 0; j
< saaLib
.length
; ++j
) {
673 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
674 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
678 int pcdSourceCount
= 0;
679 for (int i
= 0; i
< vMi
.size(); ++i
) {
680 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
685 if (pcdSourceCount
< 2) {
694 /**Remove PCDBuildDefinition entries from ModuleSA
695 * @param moduleKey identifier of ModuleSA.
696 * @param consumer where these entries come from.
698 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
700 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
701 if (msa
.getPcdCoded() == null) {
705 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
706 ListIterator li
= l
.listIterator();
708 while(li
.hasNext()) {
709 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
710 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
711 if (moduleSA
.getPcdBuildDefinition() != null) {
712 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
714 if (cursor
.toFirstChild()) {
716 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
718 String cName
= msaPcd
.getCName();
719 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
720 if (cName
.equals(pcdData
.getCName())
721 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
723 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
728 } while (cursor
.toNextSibling());
732 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
741 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
743 public int getLibraryInstancesCount(String key
) {
744 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
745 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
748 return msa
.getLibraries().getInstanceList().size();
751 public void getLibraryInstances(String key
, String
[][] saa
){
752 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
753 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
757 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
758 for (int i
= 0; i
< saa
.length
; ++i
) {
759 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
760 saa
[i
][1] = instance
.getModuleGuid();
761 saa
[i
][2] = instance
.getModuleVersion();
762 saa
[i
][3] = instance
.getPackageGuid();
763 saa
[i
][4] = instance
.getPackageVersion();
767 public void removeLibraryInstance(String key
, int i
) {
768 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
769 if (msa
== null || msa
.getLibraries() == null){
773 XmlCursor cursor
= msa
.getLibraries().newCursor();
774 if (cursor
.toFirstChild()) {
775 for (int j
= 0; j
< i
; ++j
) {
776 cursor
.toNextSibling();
779 while (cursor
.hasPrevToken()) {
780 cursor
.toPrevToken();
781 if (!cursor
.isText()) {
784 String s
= cursor
.getTextValue();
785 if (s
.matches(regExpNewLineAndSpaces
)) {
790 if (cursor
.isComment()) {
795 if (getLibraryInstancesCount(key
) == 0) {
804 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
805 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
807 msa
= getfpdFrameworkModules().addNewModuleSA();
809 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
811 libs
= msa
.addNewLibraries();
814 String mn
= libMi
.getName();
815 String mg
= libMi
.getGuid();
816 String mv
= libMi
.getVersion();
817 String pn
= libMi
.getPackageId().getName();
818 String pg
= libMi
.getPackageId().getGuid();
819 String pv
= libMi
.getPackageId().getVersion();
820 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
821 XmlCursor cursor
= instance
.newCursor();
823 String comment
= "Pkg: " + pn
+ " Mod: " + mn
824 + " Path: " + libMi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
825 cursor
.insertComment(comment
);
834 instance
.setModuleGuid(mg
);
835 instance
.setModuleVersion(mv
);
836 instance
.setPackageGuid(pg
);
837 instance
.setPackageVersion(pv
);
841 public String
getFvBinding(String moduleKey
){
842 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
843 return getFvBinding (moduleSa
);
846 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
847 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
850 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
853 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
854 if (moduleSa
== null ) {
857 if (fvBinding
== null || fvBinding
.length() == 0) {
858 if(moduleSa
.getModuleSaBuildOptions() != null){
859 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
863 if(moduleSa
.getModuleSaBuildOptions() == null){
864 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
867 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
871 public void setFvBinding(String moduleKey
, String fvBinding
){
872 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
873 setFvBinding (moduleSa
, fvBinding
);
876 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
877 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
881 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
882 String
[] fvNamesArray
= fvNameList
.split(" ");
884 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
885 if (fvNamesArray
[i
].equals(fvName
)) {
893 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
894 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
898 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
899 String
[] fvNamesArray
= fvNameList
.split(" ");
901 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
902 if (fvNamesArray
[i
].equals(fvName
)) {
907 // jump over where the input fvName occurs in the original Fv list.
908 if (occursAt
!= -1) {
909 String newFvNameList
= " ";
910 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
914 newFvNameList
+= fvNamesArray
[i
];
916 setFvBinding (moduleSa
, newFvNameList
.trim());
922 * @param fvName The FV name that to be removed from FvBinding List.
924 public void removeFvBindingAll (String fvName
) {
925 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
926 removeElement(getfpdFrameworkModules());
927 fpdFrameworkModules
= null;
931 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
932 while (li
.hasNext()) {
933 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
934 removeFvBinding (moduleSa
, fvName
);
938 public void appendFvBindingAll (String fvName
) {
939 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
940 removeElement(getfpdFrameworkModules());
941 fpdFrameworkModules
= null;
945 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
946 while (li
.hasNext()) {
947 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
948 appendFvBinding (moduleSa
, fvName
);
952 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
953 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
954 removeElement(getfpdFrameworkModules());
955 fpdFrameworkModules
= null;
959 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
960 while (li
.hasNext()) {
961 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
962 String fvBinding
= getFvBinding (moduleSa
);
963 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
964 appendFvBinding (moduleSa
, newFvName
);
969 public void appendFvBinding (String moduleKey
, String fvName
) {
970 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
971 appendFvBinding (moduleSa
, fvName
);
974 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
975 if (moduleSa
== null) {
979 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
980 setFvBinding(moduleSa
, fvName
);
984 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
985 String newFvNameList
= fvNameList
+ " " + fvName
;
986 setFvBinding (moduleSa
, newFvNameList
.trim());
989 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
991 appendFvBinding (moduleKey
, fvName
);
994 public String
getFfsFileNameGuid(String moduleKey
){
995 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
996 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
999 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1002 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1003 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1007 if(msa
.getModuleSaBuildOptions() == null){
1008 msa
.addNewModuleSaBuildOptions();
1011 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1012 if (fileGuid
!= null) {
1013 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1016 XmlCursor cursor
= msaBuildOpts
.newCursor();
1017 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1025 public String
getFfsFormatKey(String moduleKey
){
1026 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1027 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1030 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1033 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1034 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1038 if(msa
.getModuleSaBuildOptions() == null){
1039 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1042 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1045 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1046 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1047 moduleSa
.setForceDebug(dbgEnable
);
1050 public boolean getModuleSAForceDebug (int i
) {
1051 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1052 if (moduleSa
.getForceDebug() == true) {
1058 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1059 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1060 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1061 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1065 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1066 ListIterator li
= lOpt
.listIterator();
1068 while(li
.hasNext()) {
1069 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1070 if (opt
.getBuildTargets() != null) {
1071 saa
[i
][0] = listToString(opt
.getBuildTargets());
1073 saa
[i
][1] = opt
.getToolChainFamily();
1074 saa
[i
][2] = opt
.getTagName();
1075 saa
[i
][3] = opt
.getToolCode();
1077 if (opt
.getSupArchList() != null){
1078 saa
[i
][4] = listToString(opt
.getSupArchList());
1084 saa
[i
][5] = opt
.getStringValue();
1090 public int getModuleSAOptionsCount(String moduleKey
){
1091 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1092 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1093 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1096 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1099 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1100 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1101 if (msa
.getModuleSaBuildOptions() == null) {
1102 msa
.addNewModuleSaBuildOptions();
1104 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1105 msa
.getModuleSaBuildOptions().addNewOptions();
1107 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1108 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1111 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1112 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1113 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1116 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1117 XmlCursor cursor
= opts
.newCursor();
1118 if (cursor
.toFirstChild()) {
1119 for (int j
= 0; j
< i
; ++j
){
1120 cursor
.toNextSibling();
1123 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1131 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1132 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1133 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1136 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1137 XmlCursor cursor
= opts
.newCursor();
1138 if (cursor
.toFirstChild()) {
1139 for (int j
= 0; j
< i
; ++j
){
1140 cursor
.toNextSibling();
1142 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1143 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1148 /**add pcd information of module mi to a ModuleSA.
1150 * @param moduleSa if null, generate a new ModuleSA.
1152 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1153 //ToDo add Arch filter
1155 if (moduleSa
== null) {
1156 moduleSa
= genModuleSA(mi
, arch
);
1159 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1160 .getModuleXmlObject(mi
);
1161 if (msa
.getPcdCoded() == null) {
1165 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1167 // Implementing InitializePlatformPcdBuildDefinitions
1169 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1170 ListIterator li
= l
.listIterator();
1171 while (li
.hasNext()) {
1172 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1173 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1174 if (spdPcd
== null) {
1178 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
1182 // AddItem to ModuleSA PcdBuildDefinitions
1184 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1186 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1188 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1193 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1195 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1196 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1198 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1202 for (int j
= 0; j
< xo
.length
; ++j
) {
1203 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1204 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1205 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1210 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1221 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1222 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1223 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1224 XmlCursor cursor
= msa
.newCursor();
1226 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1227 + mi
.getPath().substring(System
.getenv("WORKSPACE").length() + 1);
1228 cursor
.insertComment(comment
);
1231 e
.printStackTrace();
1236 msa
.setModuleGuid(mi
.getGuid());
1237 msa
.setModuleVersion(mi
.getVersion());
1238 msa
.setPackageGuid(pi
.getGuid());
1239 msa
.setPackageVersion(pi
.getVersion());
1241 Vector
<String
> v
= new Vector
<String
>();
1243 msa
.setSupArchList(v
);
1249 private String
chooseDefaultPcdType (List validPcdTypes
) {
1250 String choosedType
= "";
1251 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1252 choosedType
= "FIXED_AT_BUILD";
1254 else if (validPcdTypes
.contains("DYNAMIC")) {
1255 choosedType
= "DYNAMIC";
1257 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1258 choosedType
= "PATCHABLE_IN_MODULE";
1260 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1261 choosedType
= "DYNAMIC_EX";
1266 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1267 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1268 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1269 if (moduleSa
.getPcdBuildDefinition() == null){
1270 moduleSa
.addNewPcdBuildDefinition();
1273 // constructe pcd to modulesa mapping first.
1274 // Attention : for any error condition, remove from map this pcd.
1276 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1277 if (pcdConsumer
== null) {
1278 pcdConsumer
= new ArrayList
<String
>();
1281 // Check whether this PCD has already added to ModuleSA, if so, just return.
1283 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1284 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1285 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1286 String pcdInfo
= pcdConsumer
.get(i
);
1287 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1291 // if pcd type from MSA file is Dynamic
1292 // we must choose one default type from SPD file for it.
1294 List validPcdTypes
= spdPcd
.getValidUsage();
1296 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1298 if (pcdConsumer
.size() > 0) {
1300 // platform should only contain one type for each pcd.
1302 String existingItemType
= itemType (pcdConsumer
.get(0));
1303 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1304 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1305 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1309 if (itemType
.equals("DYNAMIC")) {
1310 if (!validPcdTypes
.contains(existingItemType
)) {
1311 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1313 itemType
= existingItemType
;
1316 if (!itemType
.equals(existingItemType
)) {
1317 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1322 // if this is the first occurence of this pcd.
1325 if (itemType
.equals("DYNAMIC")) {
1326 itemType
= chooseDefaultPcdType (validPcdTypes
);
1329 String listValue
= moduleInfo
+ " " + itemType
;
1330 pcdConsumer
.add(listValue
);
1331 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1333 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1334 fpdPcd
.setCName(cName
);
1335 fpdPcd
.setToken(token
);
1336 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1337 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1338 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1340 if (defaultVal
!= null){
1341 fpdPcd
.setValue(defaultVal
);
1344 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1345 fpdPcd
.setValue("0");
1347 if (dataType
.equals("BOOLEAN")){
1348 fpdPcd
.setValue("FALSE");
1350 if (dataType
.equals("VOID*")) {
1351 fpdPcd
.setValue("");
1355 // Using existing pcd value, if this pcd already exists in other moduleSa.
1357 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1358 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1361 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1364 if (dataType
.equals("UINT8")){
1365 fpdPcd
.setMaxDatumSize(1);
1367 if (dataType
.equals("UINT16")) {
1368 fpdPcd
.setMaxDatumSize(2);
1370 if (dataType
.equals("UINT32")) {
1371 fpdPcd
.setMaxDatumSize(4);
1373 if (dataType
.equals("UINT64")){
1374 fpdPcd
.setMaxDatumSize(8);
1376 if (dataType
.equals("BOOLEAN")){
1377 fpdPcd
.setMaxDatumSize(1);
1379 if (dataType
.equals("VOID*")) {
1380 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1381 fpdPcd
.setMaxDatumSize(maxSize
);
1385 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1386 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1388 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1389 // so need to add one dyn pcd.
1391 if (al
.size() == 1) {
1392 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1398 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1399 if (datum
== null) {
1402 char ch
= datum
.charAt(0);
1406 // For void* type PCD, only three datum is support:
1407 // 1) Unicode: string with start char is "L"
1408 // 2) Ansci: String is ""
1409 // 3) byte array: String start char "{"
1412 start
= datum
.indexOf('\"');
1413 end
= datum
.lastIndexOf('\"');
1414 if ((start
> end
) ||
1415 (end
> datum
.length())||
1416 ((start
== end
) && (datum
.length() > 0))) {
1417 //ToDo Error handling here
1418 throw new PcdValueMalFormed (datum
);
1421 strValue
= datum
.substring(start
+ 1, end
);
1422 return strValue
.length() * 2;
1423 } else if (ch
== '\"'){
1424 start
= datum
.indexOf('\"');
1425 end
= datum
.lastIndexOf('\"');
1426 if ((start
> end
) ||
1427 (end
> datum
.length())||
1428 ((start
== end
) && (datum
.length() > 0))) {
1429 throw new PcdValueMalFormed (datum
);
1431 strValue
= datum
.substring(start
+ 1, end
);
1432 return strValue
.length();
1433 } else if (ch
=='{') {
1434 String
[] strValueArray
;
1436 start
= datum
.indexOf('{');
1437 end
= datum
.lastIndexOf('}');
1438 strValue
= datum
.substring(start
+ 1, end
);
1439 strValue
= strValue
.trim();
1440 if (strValue
.length() == 0) {
1443 strValueArray
= strValue
.split(",");
1444 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1445 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1448 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1449 // "it must be a byte array. But the element of %s exceed the byte range",
1450 throw new PcdValueMalFormed (datum
);
1453 return strValueArray
.length
;
1457 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1458 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1459 // "2) ANSIC string: like \"xxx\";\r\n"+
1460 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1461 // "but the datum in seems does not following above format!",
1462 throw new PcdValueMalFormed (datum
);
1467 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1468 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1473 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1475 return dynPcdMap
.get(pcdKey
);
1478 public int getDynamicPcdBuildDataCount() {
1479 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1480 removeElement(getfpdDynPcdBuildDefs());
1481 fpdDynPcdBuildDefs
= null;
1484 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1487 public void getDynamicPcdBuildData(String
[][] saa
) {
1488 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1489 removeElement(getfpdDynPcdBuildDefs());
1490 fpdDynPcdBuildDefs
= null;
1493 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1494 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1496 while(li
.hasNext()) {
1497 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1498 saa
[i
][0] = dynPcd
.getCName();
1499 saa
[i
][1] = dynPcd
.getToken().toString();
1500 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1501 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1502 saa
[i
][4] = dynPcd
.getDatumType().toString();
1508 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1509 throws PcdValueMalFormed
{
1510 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1511 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1512 dynPcdData
.setCName(cName
);
1513 dynPcdData
.setToken(token
);
1514 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1515 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1517 BigInteger bigInt
= new BigInteger("0");
1518 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1519 skuInfo
.setSkuId(bigInt
);
1520 if (defaultVal
!= null){
1521 skuInfo
.setValue(defaultVal
);
1524 if (dataType
.equals("UINT8")){
1525 skuInfo
.setValue("0");
1527 if (dataType
.equals("UINT16")) {
1528 skuInfo
.setValue("0");
1530 if (dataType
.equals("UINT32")) {
1531 skuInfo
.setValue("0");
1533 if (dataType
.equals("UINT64")){
1534 skuInfo
.setValue("0");
1536 if (dataType
.equals("BOOLEAN")){
1537 skuInfo
.setValue("false");
1539 if (dataType
.equals("VOID*")) {
1540 skuInfo
.setValue("");
1543 if (dataType
.equals("UINT8")){
1544 dynPcdData
.setMaxDatumSize(1);
1546 if (dataType
.equals("UINT16")) {
1547 dynPcdData
.setMaxDatumSize(2);
1549 if (dataType
.equals("UINT32")) {
1550 dynPcdData
.setMaxDatumSize(4);
1552 if (dataType
.equals("UINT64")){
1553 dynPcdData
.setMaxDatumSize(8);
1555 if (dataType
.equals("BOOLEAN")){
1556 dynPcdData
.setMaxDatumSize(1);
1558 if (dataType
.equals("VOID*")) {
1559 int maxSize
= setMaxSizeForPointer(defaultVal
);
1560 dynPcdData
.setMaxDatumSize(maxSize
);
1564 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1565 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1570 XmlCursor cursor
= o
.newCursor();
1571 if (cursor
.toFirstChild()) {
1573 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1574 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1575 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1577 if (getDynamicPcdBuildDataCount() == 1) {
1580 fpdDynPcdBuildDefs
= null;
1588 while (cursor
.toNextSibling());
1593 // Get the Sku Info count of ith dyn pcd element.
1595 public int getDynamicPcdSkuInfoCount(int i
){
1596 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1597 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1598 removeElement(getfpdDynPcdBuildDefs());
1599 fpdDynPcdBuildDefs
= null;
1603 int skuInfoCount
= 0;
1604 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1605 if (cursor
.toFirstChild()) {
1606 for (int j
= 0; j
< i
; ++j
) {
1607 cursor
.toNextSibling();
1609 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1610 if (pcdData
.getSkuInfoList() == null) {
1614 skuInfoCount
= pcdData
.getSkuInfoList().size();
1618 return skuInfoCount
;
1621 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1622 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1623 removeElement(getfpdDynPcdBuildDefs());
1624 fpdDynPcdBuildDefs
= null;
1628 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1629 if (cursor
.toFirstChild()) {
1630 for (int j
= 0; j
< i
; ++j
) {
1631 cursor
.toNextSibling();
1633 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1634 if (pcdData
.getSkuInfoList() == null) {
1639 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1641 while (li
.hasNext()) {
1642 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1643 saa
[k
][0] = skuInfo
.getSkuId()+"";
1644 saa
[k
][1] = skuInfo
.getVariableName();
1645 saa
[k
][2] = skuInfo
.getVariableGuid();
1646 saa
[k
][3] = skuInfo
.getVariableOffset();
1647 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1648 saa
[k
][5] = skuInfo
.getVpdOffset();
1649 saa
[k
][6] = skuInfo
.getValue();
1659 public String
getDynamicPcdBuildDataValue(int i
){
1660 String value
= null;
1661 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1662 removeElement(getfpdDynPcdBuildDefs());
1663 fpdDynPcdBuildDefs
= null;
1667 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1668 if (cursor
.toFirstChild()) {
1669 for (int j
= 0; j
< i
; ++j
) {
1670 cursor
.toNextSibling();
1672 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1673 if (pcdData
.getSkuInfoList() == null) {
1677 value
= pcdData
.getSkuInfoArray(0).getValue();
1684 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1685 String vpdOffset
= null;
1686 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1687 removeElement(getfpdDynPcdBuildDefs());
1688 fpdDynPcdBuildDefs
= null;
1692 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1693 if (cursor
.toFirstChild()) {
1694 for (int j
= 0; j
< i
; ++j
) {
1695 cursor
.toNextSibling();
1697 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1698 if (pcdData
.getSkuInfoList() == null) {
1702 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1709 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1710 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1711 removeElement(getfpdDynPcdBuildDefs());
1712 fpdDynPcdBuildDefs
= null;
1716 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1717 if (cursor
.toFirstChild()) {
1718 for (int j
= 0; j
< i
; ++j
) {
1719 cursor
.toNextSibling();
1721 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1722 if (pcdData
.getSkuInfoList() == null) {
1727 QName qSkuInfo
= new QName(xmlNs
, "SkuInfo");
1728 cursor
.toChild(qSkuInfo
);
1735 // generate sku info for ith dyn pcd build data.
1737 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1738 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1739 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1743 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1744 if (cursor
.toFirstChild()) {
1745 for (int j
= 0; j
< i
; ++j
) {
1746 cursor
.toNextSibling();
1748 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1749 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1750 skuInfo
.setSkuId(new BigInteger(id
));
1751 if (varName
!= null){
1752 skuInfo
.setVariableName(varName
);
1753 skuInfo
.setVariableGuid(varGuid
);
1754 skuInfo
.setVariableOffset(varOffset
);
1755 skuInfo
.setHiiDefaultValue(hiiDefault
);
1757 else if (vpdOffset
!= null){
1758 skuInfo
.setVpdOffset(vpdOffset
);
1761 skuInfo
.setValue(value
);
1766 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1767 String hiiDefault
, String vpdOffset
, String value
, int i
){
1768 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1769 removeElement(getfpdDynPcdBuildDefs());
1770 fpdDynPcdBuildDefs
= null;
1774 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1775 if (cursor
.toFirstChild()) {
1776 for (int j
= 0; j
< i
; ++j
) {
1777 cursor
.toNextSibling();
1779 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1780 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1781 while (li
.hasNext()) {
1782 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1783 if (skuInfo
.getSkuId().toString().equals(id
)){
1784 if (varName
!= null){
1785 skuInfo
.setVariableName(varName
);
1786 skuInfo
.setVariableGuid(varGuid
);
1787 skuInfo
.setVariableOffset(varOffset
);
1788 skuInfo
.setHiiDefaultValue(hiiDefault
);
1790 else if (vpdOffset
!= null){
1791 skuInfo
.setVpdOffset(vpdOffset
);
1794 skuInfo
.setValue(value
);
1802 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1803 if (fpdBuildOpts
== null) {
1804 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1806 return fpdBuildOpts
;
1809 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1810 QName elementFvName
= new QName (xmlNs
, "FvName");
1811 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1812 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1813 QName elementModule
= new QName(xmlNs
, "Module");
1815 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1816 userExts
.setUserID(userId
);
1817 userExts
.setIdentifier(new BigInteger(id
));
1818 XmlCursor cursor
= userExts
.newCursor();
1819 cursor
.toEndToken();
1821 cursor
.beginElement(elementFvName
);
1822 cursor
.insertChars(fvName
);
1823 cursor
.toNextToken();
1825 cursor
.beginElement(elementInfFileName
);
1826 cursor
.insertChars(outputFileName
);
1827 cursor
.toNextToken();
1829 cursor
.beginElement(elementIncludeModules
);
1830 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1831 cursor
.beginElement(elementModule
);
1832 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1833 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1834 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1836 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1837 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1838 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1841 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1842 cursor
.toEndToken();
1843 cursor
.toNextToken();
1848 public int getUserExtsIncModCount (String fvName
, String userId
, int id
) {
1849 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1853 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1854 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1855 while (li
.hasNext()) {
1856 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1857 if (!ues
.getUserID().equals(userId
)) {
1860 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
1863 XmlCursor cursor
= ues
.newCursor();
1864 cursor
.toFirstChild();
1865 String elementName
= cursor
.getTextValue();
1866 if (elementName
.equals(fvName
)) {
1867 cursor
.toNextSibling(elementIncludeModules
);
1868 if (cursor
.toFirstChild()) {
1870 for (i
= 1; cursor
.toNextSibling(); ++i
);
1882 public void getUserExtsIncMods(String fvName
, String userId
, int id
, String
[][] saa
) {
1883 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1887 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1888 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1889 QName attribUserId
= new QName ("UserID");
1890 QName attribId
= new QName ("Identifier");
1891 QName elementFvName
= new QName (xmlNs
, "FvName");
1892 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1893 QName attribModuleGuid
= new QName("ModuleGuid");
1894 QName attribModuleVersion
= new QName("ModuleVersion");
1895 QName attribPackageGuid
= new QName("PackageGuid");
1896 QName attribPackageVersion
= new QName("PackageVersion");
1897 QName attribArch
= new QName("Arch");
1899 if (cursor
.toChild(elementUserExts
)) {
1902 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
1903 cursor
.toChild(elementFvName
);
1904 String elementName
= cursor
.getTextValue();
1905 if (elementName
.equals(fvName
)) {
1906 cursor
.toNextSibling(elementIncludeModules
);
1907 if (cursor
.toFirstChild()) {
1910 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1911 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1912 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1913 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1914 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1916 }while (cursor
.toNextSibling());
1922 }while (cursor
.toNextSibling(elementUserExts
));
1928 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1929 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1932 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1933 while (li
.hasNext()) {
1934 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1935 if (!ues
.getUserID().equals("IMAGES")) {
1938 XmlCursor cursor
= ues
.newCursor();
1939 cursor
.toFirstChild();
1940 String elementName
= cursor
.getTextValue();
1941 if (elementName
.equals(oldFvName
)) {
1942 cursor
.setTextValue(newFvName
);
1949 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, int id
) {
1950 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1954 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1955 while (li
.hasNext()) {
1956 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1957 if (!ues
.getUserID().equals(userId
)) {
1960 if (ues
.getIdentifier()== null || ues
.getIdentifier().intValue() != id
) {
1963 XmlCursor cursor
= ues
.newCursor();
1964 cursor
.toFirstChild();
1965 String elementName
= cursor
.getTextValue();
1966 if (elementName
.equals(fvName
)) {
1977 private boolean versionEqual (String v1
, String v2
) {
1979 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1980 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1984 if (v1
!= null && v1
.equals(v2
)) {
1991 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
1992 boolean inList
= false;
1993 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
1994 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1995 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1996 QName attribUserId
= new QName ("UserID");
1997 QName attribId
= new QName ("Identifier");
1998 QName elementFvName
= new QName (xmlNs
, "FvName");
1999 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2000 QName attribModuleGuid
= new QName("ModuleGuid");
2001 QName attribModuleVersion
= new QName("ModuleVersion");
2002 QName attribPackageGuid
= new QName("PackageGuid");
2003 QName attribPackageVersion
= new QName("PackageVersion");
2004 QName attribArch
= new QName("Arch");
2006 if (cursor
.toChild(elementUserExts
)) {
2009 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2010 cursor
.toChild(elementFvName
);
2011 String elementName
= cursor
.getTextValue();
2012 if (elementName
.equals(fvName
)) {
2013 cursor
.toNextSibling(elementIncludeModules
);
2014 if (cursor
.toFirstChild()) {
2017 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2018 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2019 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2020 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2021 String ar
= cursor
.getAttributeText(attribArch
);
2022 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2025 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2028 if (!arch
.equalsIgnoreCase(ar
)) {
2031 if (!versionEqual(moduleVersion
, mv
)) {
2034 if (!versionEqual(packageVersion
, pv
)) {
2039 }while (cursor
.toNextSibling());
2045 }while (cursor
.toNextSibling(elementUserExts
));
2052 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2054 // if there is only one module before remove operation, the whole user extension should be removed.
2056 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2057 if (moduleAmount
== 1) {
2058 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2062 if (moduleAmount
> 1) {
2063 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2064 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2065 QName attribUserId
= new QName ("UserID");
2066 QName attribId
= new QName ("Identifier");
2067 QName elementFvName
= new QName (xmlNs
, "FvName");
2068 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2069 QName attribModuleGuid
= new QName("ModuleGuid");
2070 QName attribModuleVersion
= new QName("ModuleVersion");
2071 QName attribPackageGuid
= new QName("PackageGuid");
2072 QName attribPackageVersion
= new QName("PackageVersion");
2073 QName attribArch
= new QName("Arch");
2075 if (cursor
.toChild(elementUserExts
)) {
2078 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2079 cursor
.toChild(elementFvName
);
2080 String elementName
= cursor
.getTextValue();
2081 if (elementName
.equals(fvName
)) {
2082 cursor
.toNextSibling(elementIncludeModules
);
2083 if (cursor
.toFirstChild()) {
2086 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2087 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2088 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2089 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2090 String ar
= cursor
.getAttributeText(attribArch
);
2091 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2094 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2097 if (!arch
.equalsIgnoreCase(ar
)) {
2100 if (!versionEqual(moduleVersion
, mv
)) {
2103 if (!versionEqual(packageVersion
, pv
)) {
2107 }while (cursor
.toNextSibling());
2113 }while (cursor
.toNextSibling(elementUserExts
));
2119 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2120 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2124 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2125 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2126 QName elementModule
= new QName(xmlNs
, "Module");
2127 while (li
.hasNext()) {
2128 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2129 if (!ues
.getUserID().equals(userId
)) {
2132 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
2135 XmlCursor cursor
= ues
.newCursor();
2136 cursor
.toFirstChild();
2137 String elementName
= cursor
.getTextValue();
2138 if (elementName
.equals(fvName
)) {
2139 cursor
.toNextSibling(elementIncludeModules
);
2140 cursor
.toLastChild();
2141 cursor
.toEndToken();
2142 cursor
.toNextToken();
2143 cursor
.beginElement(elementModule
);
2144 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2145 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2146 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2148 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2149 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2150 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2153 cursor
.insertAttributeWithValue("Arch", arch
);
2162 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2163 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2164 if (udats
== null) {
2165 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2168 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2169 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2172 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2173 at
.setId(new Integer(id
));
2174 XmlCursor cursor
= at
.newCursor();
2175 if (fileName
!= null){
2176 at
.setFilename(fileName
);
2178 else if (cursor
.toChild(xmlNs
, "Filename")) {
2181 if (execOrder
!= null) {
2182 at
.setAntCmdOptions(execOrder
);
2184 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2190 public void removeBuildOptionsUserDefAntTask(int i
) {
2191 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2195 XmlCursor cursor
= o
.newCursor();
2196 if (cursor
.toFirstChild()) {
2197 for (int j
= 0; j
< i
; ++j
) {
2198 cursor
.toNextSibling();
2201 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2209 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2210 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2214 XmlCursor cursor
= o
.newCursor();
2215 if (cursor
.toFirstChild()) {
2216 for (int j
= 0; j
< i
; ++j
) {
2217 cursor
.toNextSibling();
2219 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2220 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2225 public int getBuildOptionsUserDefAntTaskCount() {
2226 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2227 if (udats
== null || udats
.getAntTaskList() == null) {
2231 return udats
.getAntTaskList().size();
2234 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2235 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2236 if (udats
== null || udats
.getAntTaskList() == null) {
2240 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2241 ListIterator li
= l
.listIterator();
2243 while (li
.hasNext()) {
2244 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2245 saa
[i
][0] = at
.getId() + "";
2246 saa
[i
][1] = saa
[i
][2] = "";
2247 if (at
.getFilename() != null){
2248 saa
[i
][1] = at
.getFilename();
2250 if (at
.getAntCmdOptions() != null) {
2251 saa
[i
][2] = at
.getAntCmdOptions();
2256 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2257 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2259 opts
= getfpdBuildOpts().addNewOptions();
2261 OptionDocument
.Option opt
= opts
.addNewOption();
2262 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2265 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2266 opt
.setStringValue(contents
);
2267 if (buildTargets
!= null) {
2268 opt
.setBuildTargets(buildTargets
);
2271 if (opt
.isSetBuildTargets()) {
2272 opt
.unsetBuildTargets();
2276 if (toolChain
!= null && toolChain
.length() > 0) {
2277 opt
.setToolChainFamily(toolChain
);
2280 if (opt
.isSetToolChainFamily()) {
2281 opt
.unsetToolChainFamily();
2285 if (tagName
!= null && tagName
.length() > 0) {
2286 opt
.setTagName(tagName
);
2289 if (opt
.isSetTagName()) {
2294 if (toolCmd
!= null && toolCmd
.length() > 0) {
2295 opt
.setToolCode(toolCmd
);
2298 if (opt
.isSetToolCode()) {
2299 opt
.unsetToolCode();
2304 if (archList
!= null) {
2305 opt
.setSupArchList(archList
);
2308 if (opt
.isSetSupArchList()) {
2309 opt
.unsetSupArchList();
2314 public void removeBuildOptionsOpt(int i
){
2316 XmlObject o
= getfpdBuildOpts().getOptions();
2321 XmlCursor cursor
= o
.newCursor();
2322 if (cursor
.toFirstChild()) {
2323 for (int j
= 0; j
< i
; ++j
) {
2324 cursor
.toNextSibling();
2327 if (getBuildOptionsOptCount() == 0) {
2335 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2336 XmlObject o
= getfpdBuildOpts().getOptions();
2341 XmlCursor cursor
= o
.newCursor();
2342 if (cursor
.toFirstChild()) {
2343 for (int j
= 0; j
< i
; ++j
) {
2344 cursor
.toNextSibling();
2346 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2347 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2352 public int getBuildOptionsOptCount(){
2353 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2356 return getfpdBuildOpts().getOptions().getOptionList().size();
2359 public void getBuildOptionsOpts(String
[][] saa
) {
2360 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2364 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2365 ListIterator li
= lOpt
.listIterator();
2367 while(li
.hasNext()) {
2368 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2369 if (opt
.getBuildTargets() != null) {
2370 saa
[i
][0] = listToString(opt
.getBuildTargets());
2372 saa
[i
][1] = opt
.getToolChainFamily();
2373 if (opt
.getSupArchList() != null){
2374 saa
[i
][2] = listToString(opt
.getSupArchList());
2377 saa
[i
][3] = opt
.getToolCode();
2378 saa
[i
][4] = opt
.getTagName();
2379 saa
[i
][5] = opt
.getStringValue();
2385 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2386 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2387 ffs
.setFfsKey(ffsKey
);
2389 ffs
.addNewSections().setEncapsulationType(type
);
2393 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2394 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2396 ffs
.addNewSections().setEncapsulationType(type
);
2400 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2401 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2402 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2403 attrib
.setName(name
);
2404 attrib
.setValue(value
);
2407 /**update jth attribute of ith ffs.
2411 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2412 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2413 XmlCursor cursor
= ffs
.newCursor();
2414 QName qAttrib
= new QName(xmlNs
, "Attribute");
2415 if (cursor
.toChild(qAttrib
)) {
2416 for (int k
= 0; k
< j
; ++k
) {
2417 cursor
.toNextSibling(qAttrib
);
2419 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2420 attrib
.setName(name
);
2421 attrib
.setValue(value
);
2426 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2427 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2428 XmlCursor cursor
= ffs
.newCursor();
2429 QName qAttrib
= new QName(xmlNs
, "Attribute");
2430 if (cursor
.toChild(qAttrib
)) {
2431 for (int k
= 0; k
< j
; ++k
) {
2432 cursor
.toNextSibling(qAttrib
);
2439 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2440 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2444 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2446 if (sections
== null){
2447 sections
= ffs
.addNewSections();
2449 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2452 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2453 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2454 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2455 if (sections
== null) {
2458 XmlCursor cursor
= sections
.newCursor();
2459 QName qSection
= new QName(xmlNs
, "Section");
2460 if (cursor
.toChild(qSection
)) {
2461 for (int k
= 0; k
< j
; ++k
) {
2462 cursor
.toNextSibling(qSection
);
2469 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2470 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2471 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2472 if (sections
== null) {
2475 XmlCursor cursor
= sections
.newCursor();
2476 QName qSection
= new QName(xmlNs
, "Section");
2477 if (cursor
.toChild(qSection
)) {
2478 for (int k
= 0; k
< j
; ++k
) {
2479 cursor
.toNextSibling(qSection
);
2481 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2482 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2487 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2488 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2492 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2494 if (sections
== null){
2495 sections
= ffs
.addNewSections();
2497 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2498 sections2
.setEncapsulationType(encapType
);
2499 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2502 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2503 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2504 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2505 if (sections
== null) {
2508 XmlCursor cursor
= sections
.newCursor();
2509 QName qSections
= new QName(xmlNs
, "Sections");
2510 if (cursor
.toChild(qSections
)) {
2511 for (int k
= 0; k
< j
; ++k
) {
2512 cursor
.toNextSibling(qSections
);
2519 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2520 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2521 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2522 if (sections
== null) {
2525 XmlCursor cursor
= sections
.newCursor();
2526 QName qSections
= new QName(xmlNs
, "Sections");
2527 if (cursor
.toChild(qSections
)) {
2528 for (int k
= 0; k
< j
; ++k
) {
2529 cursor
.toNextSibling(qSections
);
2531 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2532 sections2
.setEncapsulationType(type
);
2537 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2538 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2542 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2543 XmlCursor cursor
= sections
.newCursor();
2544 QName qSections
= new QName(xmlNs
, "Sections");
2545 if (cursor
.toChild(qSections
)){
2546 for (int k
= 0; k
< j
; ++k
) {
2547 cursor
.toNextSibling(qSections
);
2549 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2550 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2555 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2556 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2557 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2558 if (sections
== null) {
2561 XmlCursor cursor
= sections
.newCursor();
2562 QName qSections
= new QName(xmlNs
, "Sections");
2563 if (cursor
.toChild(qSections
)) {
2564 for (int l
= 0; l
< j
; ++l
) {
2565 cursor
.toNextSibling(qSections
);
2567 if (cursor
.toFirstChild()) {
2569 for (; m
< k
; ++m
) {
2570 cursor
.toNextSibling();
2582 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2583 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2584 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2585 if (sections
== null) {
2588 XmlCursor cursor
= sections
.newCursor();
2589 QName qSections
= new QName(xmlNs
, "Sections");
2590 if (cursor
.toChild(qSections
)) {
2591 for (int l
= 0; l
< j
; ++l
) {
2592 cursor
.toNextSibling(qSections
);
2594 if (cursor
.toFirstChild()) {
2595 for (int m
= 0; m
< k
; ++m
) {
2596 cursor
.toNextSibling();
2598 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2599 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2605 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2606 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2610 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2611 XmlCursor cursor
= sections
.newCursor();
2612 QName qSections
= new QName(xmlNs
, "Sections");
2613 if (cursor
.toChild(qSections
)){
2614 for (int k
= 0; k
< j
; ++k
) {
2615 cursor
.toNextSibling(qSections
);
2617 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2618 if (sections2
.getSectionList() == null){
2622 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2623 while(li
.hasNext()) {
2624 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2625 // if (section.isSetSectionType()) {
2626 al
.add(section
.getSectionType()+"");
2635 public int getBuildOptionsFfsCount(){
2636 if (getfpdBuildOpts().getFfsList() == null) {
2639 return getfpdBuildOpts().getFfsList().size();
2642 public void getBuildOptionsFfsKey(String
[][] saa
) {
2643 if (getfpdBuildOpts().getFfsList() == null) {
2646 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2648 while(li
.hasNext()){
2649 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2650 saa
[i
][0] = ffs
.getFfsKey();
2655 public void updateBuildOptionsFfsKey(int i
, String key
) {
2656 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2660 /**Get ith FFS key and contents.
2663 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2664 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2668 sa
[0] = ffs
.getFfsKey();
2669 if (ffs
.getSections() != null) {
2670 if(ffs
.getSections().getEncapsulationType() != null){
2671 sa
[1] = ffs
.getSections().getEncapsulationType();
2673 if (ffs
.getSections().getSectionList() != null){
2674 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2675 while (li
.hasNext()) {
2676 firstLevelSection
.add(li
.next().getSectionType()+"");
2679 if (ffs
.getSections().getSectionsList() != null) {
2680 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2681 while(li
.hasNext()) {
2682 firstLevelSections
.add(li
.next().getEncapsulationType());
2686 if (ffs
.getAttributeList() != null) {
2687 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2688 while(li
.hasNext()) {
2689 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2690 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2699 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2700 XmlObject o
= getfpdBuildOpts();
2701 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2703 XmlCursor cursor
= o
.newCursor();
2704 QName qFfs
= new QName(xmlNs
, "Ffs");
2705 if (cursor
.toChild(qFfs
)) {
2706 for (int j
= 0; j
< i
; ++j
) {
2707 cursor
.toNextSibling(qFfs
);
2709 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2715 public void removeBuildOptionsFfs(int i
) {
2716 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2721 XmlCursor cursor
= ffs
.newCursor();
2728 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2729 if (fpdPlatformDefs
== null){
2730 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2732 return fpdPlatformDefs
;
2735 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2736 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2739 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2740 while(li
.hasNext()) {
2741 archs
.add(li
.next());
2745 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2746 if (archs
!= null) {
2747 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2750 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2751 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2752 // cursor.removeXml();
2754 // cursor.dispose();
2758 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2759 if (getfpdPlatformDefs().getBuildTargets() == null) {
2762 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2763 while(li
.hasNext()) {
2764 targets
.add(li
.next());
2768 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2769 getfpdPlatformDefs().setBuildTargets(targets
);
2772 public void genPlatformDefsSkuInfo(String id
, String name
) {
2773 SkuInfoDocument
.SkuInfo skuInfo
= null;
2774 if (getfpdPlatformDefs().getSkuInfo() == null) {
2775 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2777 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2778 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2779 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2780 skuName
.setSkuID(new BigInteger("0"));
2781 skuName
.setStringValue("DEFAULT");
2783 if (id
.equals("0")) {
2786 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2787 skuName
.setSkuID(new BigInteger(id
));
2788 skuName
.setStringValue(name
);
2791 public int getPlatformDefsSkuInfoCount(){
2792 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2795 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2798 public void getPlatformDefsSkuInfos(String
[][] saa
){
2799 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2800 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2801 removeElement(getfpdDynPcdBuildDefs());
2802 fpdDynPcdBuildDefs
= null;
2807 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2808 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2810 while(li
.hasNext()) {
2811 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2812 saa
[i
][0] = sku
.getSkuID()+"";
2813 saa
[i
][1] = sku
.getStringValue();
2818 public void removePlatformDefsSkuInfo(int i
) {
2819 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2820 if (skuInfo
== null || i
== 0) {
2824 XmlCursor cursor
= skuInfo
.newCursor();
2825 if (cursor
.toFirstChild()) {
2826 for (int j
= 0; j
< i
; ++j
) {
2827 cursor
.toNextSibling();
2834 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2835 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2836 if (skuInfo
== null || i
== 0) {
2840 XmlCursor cursor
= skuInfo
.newCursor();
2841 if (cursor
.toFirstChild()) {
2842 for (int j
= 0; j
< i
; ++j
) {
2843 cursor
.toNextSibling();
2845 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2846 sku
.setSkuID(new BigInteger(id
));
2847 sku
.setStringValue(name
);
2852 public String
getPlatformDefsInterDir(){
2853 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2856 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2859 public void setPlatformDefsInterDir(String interDir
){
2860 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2863 public String
getPlatformDefsOutputDir() {
2864 return getfpdPlatformDefs().getOutputDirectory();
2867 public void setPlatformDefsOutputDir(String outputDir
) {
2868 if (outputDir
!= null && outputDir
.length() > 0) {
2869 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2872 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2873 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2880 public FlashDocument
.Flash
getfpdFlash() {
2881 if (fpdFlash
== null) {
2882 fpdFlash
= fpdRoot
.addNewFlash();
2887 public void genFlashDefinitionFile(String file
) {
2888 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2890 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2893 fdf
.setStringValue(file
);
2896 public String
getFlashDefinitionFile() {
2897 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2902 return fdf
.getStringValue();
2905 public void genFvImagesNameValue(String name
, String value
) {
2907 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2909 fi
= getfpdFlash().addNewFvImages();
2912 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2917 public void removeFvImagesNameValue(int i
){
2919 XmlObject o
= getfpdFlash().getFvImages();
2924 QName qNameValue
= new QName(xmlNs
, "NameValue");
2925 XmlCursor cursor
= o
.newCursor();
2926 if (cursor
.toChild(qNameValue
)) {
2927 for (int j
= 0; j
< i
; ++j
) {
2928 cursor
.toNextSibling(qNameValue
);
2935 public void updateFvImagesNameValue(int i
, String name
, String value
){
2937 XmlObject o
= getfpdFlash().getFvImages();
2942 QName qNameValue
= new QName(xmlNs
, "NameValue");
2943 XmlCursor cursor
= o
.newCursor();
2944 if (cursor
.toChild(qNameValue
)) {
2945 for (int j
= 0; j
< i
; ++j
) {
2946 cursor
.toNextSibling(qNameValue
);
2948 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2955 public int getFvImagesNameValueCount() {
2957 FvImagesDocument
.FvImages fi
= null;
2958 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2961 return fi
.getNameValueList().size();
2964 public void getFvImagesNameValues(String
[][] nv
) {
2966 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2970 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2972 ListIterator li
= l
.listIterator();
2973 while (li
.hasNext()) {
2974 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2976 nv
[i
][0] = e
.getName();
2977 nv
[i
][1] = e
.getValue();
2983 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2984 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2985 if (fis
== null || fis
.getFvImageList() == null) {
2989 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2990 while (li
.hasNext()) {
2991 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2992 if (fi
.getType().toString().equals("ImageName")) {
2993 vImageNames
.addAll(fi
.getFvImageNamesList());
2999 public void addFvImageFvImageNames (String
[] fvNames
) {
3000 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3001 if (fis
== null || fis
.getFvImageList() == null) {
3002 genFvImagesFvImage (fvNames
, "ImageName", null);
3006 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3007 while (li
.hasNext()) {
3008 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3009 if (fi
.getType().toString().equals("ImageName")) {
3010 addFvImageNamesInFvImage (fi
, fvNames
);
3014 genFvImagesFvImage (fvNames
, "ImageName", null);
3017 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3019 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3020 fi
.addFvImageNames(fvNames
[i
]);
3024 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3025 XmlObject o
= getfpdFlash().getFvImages();
3029 XmlCursor cursor
= o
.newCursor();
3030 QName qFvImage
= new QName(xmlNs
, "FvImage");
3031 if (cursor
.toChild(qFvImage
)) {
3032 for (int j
= 0; j
< i
; ++j
) {
3033 cursor
.toNextSibling(qFvImage
);
3035 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3036 addFvImageNamesInFvImage(fi
, fvNames
);
3041 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3043 FvImagesDocument
.FvImages fis
= null;
3044 if ((fis
= getfpdFlash().getFvImages()) == null) {
3045 fis
= getfpdFlash().addNewFvImages();
3049 //gen FvImage with FvImageNames array
3051 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3052 for (int i
= 0; i
< names
.length
; ++i
) {
3053 fi
.addFvImageNames(names
[i
]);
3055 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3056 if (options
!= null){
3057 setFvImagesFvImageFvImageOptions(options
, fi
);
3061 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3062 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3064 fio
= fi
.addNewFvImageOptions();
3067 Set
<String
> key
= options
.keySet();
3068 Iterator
<String
> i
= key
.iterator();
3069 while (i
.hasNext()) {
3071 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3072 String k
= (String
)i
.next();
3075 nv
.setValue((String
)options
.get(k
));
3082 public void removeFvImagesFvImage(int i
) {
3084 XmlObject o
= getfpdFlash().getFvImages();
3089 QName qFvImage
= new QName(xmlNs
, "FvImage");
3090 XmlCursor cursor
= o
.newCursor();
3091 if (cursor
.toChild(qFvImage
)) {
3092 for (int j
= 0; j
< i
; ++j
) {
3093 cursor
.toNextSibling(qFvImage
);
3102 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3104 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3105 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3108 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3109 while (li
.hasNext()) {
3110 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3111 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3112 if (fi
.getFvImageNamesList().size() == 0) {
3118 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3119 XmlObject o
= getfpdFlash().getFvImages();
3123 XmlCursor cursor
= o
.newCursor();
3124 QName qFvImage
= new QName(xmlNs
, "FvImage");
3125 if (cursor
.toChild(qFvImage
)) {
3126 for (int j
= 0; j
< i
; ++j
) {
3127 cursor
.toNextSibling(qFvImage
);
3129 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3130 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3136 * @param oldFvName The FV Name to be replaced.
3137 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3139 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3140 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3141 XmlCursor cursor
= fi
.newCursor();
3143 if (cursor
.toChild(qFvImageNames
)) {
3145 String xmlValue
= cursor
.getTextValue();
3146 if (xmlValue
.equals(oldFvName
)){
3147 if (newFvName
!= null) {
3148 cursor
.setTextValue(newFvName
);
3154 }while (cursor
.toNextSibling(qFvImageNames
));
3160 /**update the Type attribute of ith FvImage with new type.
3164 public void updateFvImagesFvImageType (int i
, String type
) {
3165 XmlObject o
= getfpdFlash().getFvImages();
3169 XmlCursor cursor
= o
.newCursor();
3170 QName qFvImage
= new QName(xmlNs
, "FvImage");
3171 if (cursor
.toChild(qFvImage
)) {
3172 for (int j
= 0; j
< i
; ++j
) {
3173 cursor
.toNextSibling(qFvImage
);
3175 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3176 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3181 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3183 XmlObject o
= getfpdFlash().getFvImages();
3187 XmlCursor cursor
= o
.newCursor();
3188 QName qFvImage
= new QName(xmlNs
, "FvImage");
3189 if (cursor
.toChild(qFvImage
)) {
3190 for (int j
= 0; j
< i
; ++j
) {
3191 cursor
.toNextSibling(qFvImage
);
3193 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3194 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3197 // remove old FvImageNames before adding new ones
3199 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3200 cursor
.toChild(qFvImageNames
);
3202 while (cursor
.toNextSibling(qFvImageNames
)) {
3206 for (int k
= 0; k
< names
.length
; ++k
) {
3207 fi
.addFvImageNames(names
[k
]);
3210 // remove old FvImageOptions before adding new options
3212 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3213 cursor
.toNextSibling(qFvImageOptions
);
3216 setFvImagesFvImageFvImageOptions(options
, fi
);
3221 public int getFvImagesFvImageCount(String type
) {
3223 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3226 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3227 ListIterator li
= l
.listIterator();
3229 while(li
.hasNext()) {
3230 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3231 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3241 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3242 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3243 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3246 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3247 ListIterator li
= l
.listIterator();
3248 while(li
.hasNext()) {
3249 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3250 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3253 if (fi
.getFvImageNamesList().contains(fvName
)) {
3262 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3264 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3266 if (getfpdFlash().getFvImages() == null) {
3269 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3273 ListIterator li
= l
.listIterator();
3275 while(li
.hasNext()) {
3276 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3277 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3281 // get FvImageNames array, space separated
3283 List
<String
> lfn
= fi
.getFvImageNamesList();
3284 ListIterator lfni
= lfn
.listIterator();
3286 while (lfni
.hasNext()) {
3287 saa
[i
][0] += (String
)lfni
.next();
3290 saa
[i
][0] = saa
[i
][0].trim();
3292 saa
[i
][1] = fi
.getType()+"";
3298 public void removeFvImageNameValue (int i
, String attributeName
) {
3299 XmlObject o
= getfpdFlash().getFvImages();
3303 XmlCursor cursor
= o
.newCursor();
3304 QName qFvImage
= new QName(xmlNs
, "FvImage");
3305 if (cursor
.toChild(qFvImage
)) {
3306 for (int j
= 0; j
< i
; ++j
) {
3307 cursor
.toNextSibling(qFvImage
);
3309 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3310 removeFvImageNameValue (fi
, attributeName
);
3314 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3316 * @param attributeName
3318 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3319 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3320 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3321 while (li
.hasNext()) {
3322 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3323 if (nv
.getName().equals(attributeName
)) {
3330 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3331 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3332 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3333 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3334 removeFvImageNameValue (fi
, optName
);
3338 /**Add name-value pair to FvImage element with type.
3339 * @param fvName FV name to add name-value pair.
3340 * @param type FvImage attribute.
3344 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3345 boolean fvImageExists
= false;
3346 if (getfpdFlash().getFvImages() != null) {
3348 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3350 ListIterator li
= l
.listIterator();
3351 while (li
.hasNext()) {
3352 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3353 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3356 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3359 fvImageExists
= true;
3360 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3365 if (!fvImageExists
) {
3366 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3367 map
.put(name
, value
);
3368 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3372 /**Add to all FvImage elements with type, the name-value pair.
3377 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3378 if (getfpdFlash().getFvImages() == null) {
3381 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3385 ListIterator li
= l
.listIterator();
3386 while(li
.hasNext()) {
3387 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3388 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3391 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3396 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3397 XmlObject o
= getfpdFlash().getFvImages();
3401 XmlCursor cursor
= o
.newCursor();
3402 QName qFvImage
= new QName(xmlNs
, "FvImage");
3403 if (cursor
.toChild(qFvImage
)) {
3404 for (int j
= 0; j
< i
; ++j
) {
3405 cursor
.toNextSibling(qFvImage
);
3407 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3408 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3413 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3419 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3420 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3421 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3424 if (newName
!= null && !newName
.equals(name
)) {
3425 nv
.setName(newName
);
3430 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3431 if (cursor
.toFirstChild()) {
3433 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3434 if (nv
.getName().equals(name
)) {
3436 if (newName
!= null && !newName
.equals(name
)) {
3437 nv
.setName(newName
);
3442 }while (cursor
.toNextSibling());
3445 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3448 if (newName
!= null && !newName
.equals(name
)) {
3449 nv
.setName(newName
);
3454 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3455 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3456 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3457 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3458 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3462 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3465 while (li
.hasNext()) {
3466 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3467 m
.put(nv
.getName(), nv
.getValue());
3472 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3473 XmlObject o
= getfpdFlash().getFvImages();
3479 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3480 Vector
<String
> vFvNames
= new Vector
<String
>();
3483 XmlCursor cursor
= o
.newCursor();
3484 QName qFvImage
= new QName(xmlNs
, "FvImage");
3485 if (cursor
.toChild(qFvImage
)) {
3488 vFvNames
.removeAllElements();
3489 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3490 vFvNames
.add(fvNameArray
[i
]);
3492 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3493 if (!fi
.getType().toString().equals(type
)) {
3496 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3499 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3500 while (li
.hasNext()) {
3501 String name
= li
.next();
3502 vFvNames
.remove(name
);
3504 if (vFvNames
.size() == 0) {
3509 }while (cursor
.toNextSibling(qFvImage
));
3515 /**Get FvImage Options for FvImage i
3516 * @param i the ith FvImage
3518 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3519 XmlObject o
= getfpdFlash().getFvImages();
3523 XmlCursor cursor
= o
.newCursor();
3524 QName qFvImage
= new QName(xmlNs
, "FvImage");
3525 if (cursor
.toChild(qFvImage
)) {
3526 for (int j
= 0; j
< i
; ++j
) {
3527 cursor
.toNextSibling(qFvImage
);
3529 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3530 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3534 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3535 while(li
.hasNext()){
3536 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3537 m
.put(nv
.getName(), nv
.getValue());
3544 Get platform header element
3545 @return PlatformHeaderDocument.PlatformHeader
3547 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3548 if (fpdHdr
== null) {
3549 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3555 public String
getFpdHdrPlatformName() {
3556 return getFpdHdr().getPlatformName();
3559 public String
getFpdHdrGuidValue() {
3560 return getFpdHdr().getGuidValue();
3563 public String
getFpdHdrVer() {
3564 return getFpdHdr().getVersion();
3567 public String
getFpdHdrAbs() {
3568 return getFpdHdr().getAbstract();
3571 public String
getFpdHdrDescription() {
3572 return getFpdHdr().getDescription();
3575 public String
getFpdHdrCopyright() {
3576 return getFpdHdr().getCopyright();
3579 public String
getFpdHdrLicense() {
3580 LicenseDocument
.License l
= getFpdHdr().getLicense();
3584 return l
.getStringValue();
3587 public String
getFpdHdrUrl() {
3588 LicenseDocument
.License l
= getFpdHdr().getLicense();
3595 public String
getFpdHdrSpec() {
3597 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3598 // return getFpdHdr().getSpecification();
3601 public void setFpdHdrPlatformName(String name
){
3602 getFpdHdr().setPlatformName(name
);
3605 public void setFpdHdrGuidValue(String guid
){
3606 getFpdHdr().setGuidValue(guid
);
3609 public void setFpdHdrVer(String v
){
3610 getFpdHdr().setVersion(v
);
3613 public void setFpdHdrAbs(String abs
) {
3614 getFpdHdr().setAbstract(abs
);
3617 public void setFpdHdrDescription(String desc
){
3618 getFpdHdr().setDescription(desc
);
3621 public void setFpdHdrCopyright(String cr
) {
3622 getFpdHdr().setCopyright(cr
);
3625 public void setFpdHdrLicense(String license
){
3626 LicenseDocument
.License l
= getFpdHdr().getLicense();
3628 getFpdHdr().addNewLicense().setStringValue(license
);
3631 l
.setStringValue(license
);
3635 public void setFpdHdrUrl(String url
){
3636 LicenseDocument
.License l
= getFpdHdr().getLicense();
3642 public void setFpdHdrSpec(String s
){
3643 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3644 getFpdHdr().setSpecification(s
);
3647 Save the processed xml contents to file
3649 @param fpdFile The file to save xml contents
3650 @throws IOException Exceptions during file operation
3652 public void saveAs(File fpdFile
) throws IOException
{
3654 XmlOptions options
= new XmlOptions();
3656 options
.setCharacterEncoding("UTF-8");
3657 options
.setSavePrettyPrint();
3658 options
.setSavePrettyPrintIndent(2);
3660 fpdd
.save(fpdFile
, options
);
3661 } catch (IOException e
) {
3662 e
.printStackTrace();
3667 private String
listToString(List l
) {
3672 ListIterator li
= l
.listIterator();
3673 while(li
.hasNext()) {
3680 private void removeElement(XmlObject o
) {
3681 XmlCursor cursor
= o
.newCursor();
3687 class PcdItemTypeConflictException
extends Exception
{
3692 private static final long serialVersionUID
= 1L;
3693 private String details
= null;
3695 PcdItemTypeConflictException (String pcdName
, String info
) {
3696 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3698 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3701 details
= pcdName
+ " ItemType Conflicts with " + info
;
3705 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3706 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3707 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3708 String moduleInfo1
= "";
3709 String moduleInfo2
= "";
3711 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3714 moduleInfo1
= info1
;
3718 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3721 moduleInfo2
= info2
;
3724 details
= pcdName
+ " ItemType Conflicts in " + moduleInfo1
+ " and " + moduleInfo2
;
3727 public String
getMessage() {
3732 class PcdDeclNotFound
extends Exception
{
3737 private static final long serialVersionUID
= 1L;
3738 private String details
= null;
3740 PcdDeclNotFound(String info
) {
3741 details
= "PcdDeclNotFound: " + info
;
3744 public String
getMessage() {
3749 class PcdValueMalFormed
extends Exception
{
3754 private static final long serialVersionUID
= 1L;
3755 private String details
= null;
3757 PcdValueMalFormed(String info
) {
3758 details
= "PcdValueMalFormed: " + info
;
3761 public String
getMessage() {