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() + " used by Module "
1179 + mi
.getName() + " or its Library Instances.");
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
= getFfs(i
);
2395 ffs
.getSections().setEncapsulationType(type
);
2398 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2399 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2400 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2401 attrib
.setName(name
);
2402 attrib
.setValue(value
);
2405 /**update jth attribute of ith ffs.
2409 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2410 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2411 XmlCursor cursor
= ffs
.newCursor();
2412 QName qAttrib
= new QName(xmlNs
, "Attribute");
2413 if (cursor
.toChild(qAttrib
)) {
2414 for (int k
= 0; k
< j
; ++k
) {
2415 cursor
.toNextSibling(qAttrib
);
2417 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2418 attrib
.setName(name
);
2419 attrib
.setValue(value
);
2424 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2425 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2426 XmlCursor cursor
= ffs
.newCursor();
2427 QName qAttrib
= new QName(xmlNs
, "Attribute");
2428 if (cursor
.toChild(qAttrib
)) {
2429 for (int k
= 0; k
< j
; ++k
) {
2430 cursor
.toNextSibling(qAttrib
);
2437 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2438 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2442 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2444 if (sections
== null){
2445 sections
= ffs
.addNewSections();
2447 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2450 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2451 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2452 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2453 if (sections
== null) {
2456 XmlCursor cursor
= sections
.newCursor();
2457 QName qSection
= new QName(xmlNs
, "Section");
2458 if (cursor
.toChild(qSection
)) {
2459 for (int k
= 0; k
< j
; ++k
) {
2460 cursor
.toNextSibling(qSection
);
2467 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2468 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2469 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2470 if (sections
== null) {
2473 XmlCursor cursor
= sections
.newCursor();
2474 QName qSection
= new QName(xmlNs
, "Section");
2475 if (cursor
.toChild(qSection
)) {
2476 for (int k
= 0; k
< j
; ++k
) {
2477 cursor
.toNextSibling(qSection
);
2479 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2480 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2485 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2486 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2490 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2492 if (sections
== null){
2493 sections
= ffs
.addNewSections();
2495 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2496 sections2
.setEncapsulationType(encapType
);
2497 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2500 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2501 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2502 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2503 if (sections
== null) {
2506 XmlCursor cursor
= sections
.newCursor();
2507 QName qSections
= new QName(xmlNs
, "Sections");
2508 if (cursor
.toChild(qSections
)) {
2509 for (int k
= 0; k
< j
; ++k
) {
2510 cursor
.toNextSibling(qSections
);
2517 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2518 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2519 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2520 if (sections
== null) {
2523 XmlCursor cursor
= sections
.newCursor();
2524 QName qSections
= new QName(xmlNs
, "Sections");
2525 if (cursor
.toChild(qSections
)) {
2526 for (int k
= 0; k
< j
; ++k
) {
2527 cursor
.toNextSibling(qSections
);
2529 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2530 sections2
.setEncapsulationType(type
);
2535 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2536 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2540 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2541 XmlCursor cursor
= sections
.newCursor();
2542 QName qSections
= new QName(xmlNs
, "Sections");
2543 if (cursor
.toChild(qSections
)){
2544 for (int k
= 0; k
< j
; ++k
) {
2545 cursor
.toNextSibling(qSections
);
2547 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2548 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2553 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2554 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2555 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2556 if (sections
== null) {
2559 XmlCursor cursor
= sections
.newCursor();
2560 QName qSections
= new QName(xmlNs
, "Sections");
2561 if (cursor
.toChild(qSections
)) {
2562 for (int l
= 0; l
< j
; ++l
) {
2563 cursor
.toNextSibling(qSections
);
2565 if (cursor
.toFirstChild()) {
2567 for (; m
< k
; ++m
) {
2568 cursor
.toNextSibling();
2580 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2581 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2582 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2583 if (sections
== null) {
2586 XmlCursor cursor
= sections
.newCursor();
2587 QName qSections
= new QName(xmlNs
, "Sections");
2588 if (cursor
.toChild(qSections
)) {
2589 for (int l
= 0; l
< j
; ++l
) {
2590 cursor
.toNextSibling(qSections
);
2592 if (cursor
.toFirstChild()) {
2593 for (int m
= 0; m
< k
; ++m
) {
2594 cursor
.toNextSibling();
2596 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2597 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2603 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2604 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2608 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2609 XmlCursor cursor
= sections
.newCursor();
2610 QName qSections
= new QName(xmlNs
, "Sections");
2611 if (cursor
.toChild(qSections
)){
2612 for (int k
= 0; k
< j
; ++k
) {
2613 cursor
.toNextSibling(qSections
);
2615 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2616 if (sections2
.getSectionList() == null){
2620 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2621 while(li
.hasNext()) {
2622 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2623 // if (section.isSetSectionType()) {
2624 al
.add(section
.getSectionType()+"");
2633 public int getBuildOptionsFfsCount(){
2634 if (getfpdBuildOpts().getFfsList() == null) {
2637 return getfpdBuildOpts().getFfsList().size();
2640 public void getBuildOptionsFfsKey(String
[][] saa
) {
2641 if (getfpdBuildOpts().getFfsList() == null) {
2644 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2646 while(li
.hasNext()){
2647 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2648 saa
[i
][0] = ffs
.getFfsKey();
2653 public void updateBuildOptionsFfsKey(int i
, String key
) {
2654 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2658 /**Get ith FFS key and contents.
2661 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2662 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2666 sa
[0] = ffs
.getFfsKey();
2667 if (ffs
.getSections() != null) {
2668 if(ffs
.getSections().getEncapsulationType() != null){
2669 sa
[1] = ffs
.getSections().getEncapsulationType();
2671 if (ffs
.getSections().getSectionList() != null){
2672 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2673 while (li
.hasNext()) {
2674 firstLevelSection
.add(li
.next().getSectionType()+"");
2677 if (ffs
.getSections().getSectionsList() != null) {
2678 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2679 while(li
.hasNext()) {
2680 firstLevelSections
.add(li
.next().getEncapsulationType());
2684 if (ffs
.getAttributeList() != null) {
2685 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2686 while(li
.hasNext()) {
2687 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2688 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2697 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2698 XmlObject o
= getfpdBuildOpts();
2699 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2701 XmlCursor cursor
= o
.newCursor();
2702 QName qFfs
= new QName(xmlNs
, "Ffs");
2703 if (cursor
.toChild(qFfs
)) {
2704 for (int j
= 0; j
< i
; ++j
) {
2705 cursor
.toNextSibling(qFfs
);
2707 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2713 public void removeBuildOptionsFfs(int i
) {
2714 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2719 XmlCursor cursor
= ffs
.newCursor();
2726 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2727 if (fpdPlatformDefs
== null){
2728 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2730 return fpdPlatformDefs
;
2733 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2734 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2737 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2738 while(li
.hasNext()) {
2739 archs
.add(li
.next());
2743 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2744 if (archs
!= null) {
2745 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2748 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2749 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2750 // cursor.removeXml();
2752 // cursor.dispose();
2756 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2757 if (getfpdPlatformDefs().getBuildTargets() == null) {
2760 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2761 while(li
.hasNext()) {
2762 targets
.add(li
.next());
2766 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2767 getfpdPlatformDefs().setBuildTargets(targets
);
2770 public void genPlatformDefsSkuInfo(String id
, String name
) {
2771 SkuInfoDocument
.SkuInfo skuInfo
= null;
2772 if (getfpdPlatformDefs().getSkuInfo() == null) {
2773 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2775 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2776 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2777 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2778 skuName
.setSkuID(new BigInteger("0"));
2779 skuName
.setStringValue("DEFAULT");
2781 if (id
.equals("0")) {
2784 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2785 skuName
.setSkuID(new BigInteger(id
));
2786 skuName
.setStringValue(name
);
2789 public int getPlatformDefsSkuInfoCount(){
2790 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2793 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2796 public void getPlatformDefsSkuInfos(String
[][] saa
){
2797 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2798 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2799 removeElement(getfpdDynPcdBuildDefs());
2800 fpdDynPcdBuildDefs
= null;
2805 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2806 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2808 while(li
.hasNext()) {
2809 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2810 saa
[i
][0] = sku
.getSkuID()+"";
2811 saa
[i
][1] = sku
.getStringValue();
2816 public void removePlatformDefsSkuInfo(int i
) {
2817 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2818 if (skuInfo
== null || i
== 0) {
2822 XmlCursor cursor
= skuInfo
.newCursor();
2823 if (cursor
.toFirstChild()) {
2824 for (int j
= 0; j
< i
; ++j
) {
2825 cursor
.toNextSibling();
2832 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2833 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2834 if (skuInfo
== null || i
== 0) {
2838 XmlCursor cursor
= skuInfo
.newCursor();
2839 if (cursor
.toFirstChild()) {
2840 for (int j
= 0; j
< i
; ++j
) {
2841 cursor
.toNextSibling();
2843 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2844 sku
.setSkuID(new BigInteger(id
));
2845 sku
.setStringValue(name
);
2850 public String
getPlatformDefsInterDir(){
2851 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2854 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2857 public void setPlatformDefsInterDir(String interDir
){
2858 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2861 public String
getPlatformDefsOutputDir() {
2862 return getfpdPlatformDefs().getOutputDirectory();
2865 public void setPlatformDefsOutputDir(String outputDir
) {
2866 if (outputDir
!= null && outputDir
.length() > 0) {
2867 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2870 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2871 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2878 public FlashDocument
.Flash
getfpdFlash() {
2879 if (fpdFlash
== null) {
2880 fpdFlash
= fpdRoot
.addNewFlash();
2885 public void genFlashDefinitionFile(String file
) {
2886 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2888 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2891 fdf
.setStringValue(file
);
2894 public String
getFlashDefinitionFile() {
2895 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2900 return fdf
.getStringValue();
2903 public void genFvImagesNameValue(String name
, String value
) {
2905 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2907 fi
= getfpdFlash().addNewFvImages();
2910 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2915 public void removeFvImagesNameValue(int i
){
2917 XmlObject o
= getfpdFlash().getFvImages();
2922 QName qNameValue
= new QName(xmlNs
, "NameValue");
2923 XmlCursor cursor
= o
.newCursor();
2924 if (cursor
.toChild(qNameValue
)) {
2925 for (int j
= 0; j
< i
; ++j
) {
2926 cursor
.toNextSibling(qNameValue
);
2933 public void updateFvImagesNameValue(int i
, String name
, String value
){
2935 XmlObject o
= getfpdFlash().getFvImages();
2940 QName qNameValue
= new QName(xmlNs
, "NameValue");
2941 XmlCursor cursor
= o
.newCursor();
2942 if (cursor
.toChild(qNameValue
)) {
2943 for (int j
= 0; j
< i
; ++j
) {
2944 cursor
.toNextSibling(qNameValue
);
2946 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2953 public int getFvImagesNameValueCount() {
2955 FvImagesDocument
.FvImages fi
= null;
2956 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2959 return fi
.getNameValueList().size();
2962 public void getFvImagesNameValues(String
[][] nv
) {
2964 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2968 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2970 ListIterator li
= l
.listIterator();
2971 while (li
.hasNext()) {
2972 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2974 nv
[i
][0] = e
.getName();
2975 nv
[i
][1] = e
.getValue();
2981 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2982 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2983 if (fis
== null || fis
.getFvImageList() == null) {
2987 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2988 while (li
.hasNext()) {
2989 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
2990 if (fi
.getType().toString().equals("ImageName")) {
2991 vImageNames
.addAll(fi
.getFvImageNamesList());
2997 public void addFvImageFvImageNames (String
[] fvNames
) {
2998 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2999 if (fis
== null || fis
.getFvImageList() == null) {
3000 genFvImagesFvImage (fvNames
, "ImageName", null);
3004 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3005 while (li
.hasNext()) {
3006 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3007 if (fi
.getType().toString().equals("ImageName")) {
3008 addFvImageNamesInFvImage (fi
, fvNames
);
3012 genFvImagesFvImage (fvNames
, "ImageName", null);
3015 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3017 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3018 fi
.addFvImageNames(fvNames
[i
]);
3022 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3023 XmlObject o
= getfpdFlash().getFvImages();
3027 XmlCursor cursor
= o
.newCursor();
3028 QName qFvImage
= new QName(xmlNs
, "FvImage");
3029 if (cursor
.toChild(qFvImage
)) {
3030 for (int j
= 0; j
< i
; ++j
) {
3031 cursor
.toNextSibling(qFvImage
);
3033 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3034 addFvImageNamesInFvImage(fi
, fvNames
);
3039 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3041 FvImagesDocument
.FvImages fis
= null;
3042 if ((fis
= getfpdFlash().getFvImages()) == null) {
3043 fis
= getfpdFlash().addNewFvImages();
3047 //gen FvImage with FvImageNames array
3049 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3050 for (int i
= 0; i
< names
.length
; ++i
) {
3051 fi
.addFvImageNames(names
[i
]);
3053 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3054 if (options
!= null){
3055 setFvImagesFvImageFvImageOptions(options
, fi
);
3059 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3060 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3062 fio
= fi
.addNewFvImageOptions();
3065 Set
<String
> key
= options
.keySet();
3066 Iterator
<String
> i
= key
.iterator();
3067 while (i
.hasNext()) {
3069 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3070 String k
= (String
)i
.next();
3073 nv
.setValue((String
)options
.get(k
));
3080 public void removeFvImagesFvImage(int i
) {
3082 XmlObject o
= getfpdFlash().getFvImages();
3087 QName qFvImage
= new QName(xmlNs
, "FvImage");
3088 XmlCursor cursor
= o
.newCursor();
3089 if (cursor
.toChild(qFvImage
)) {
3090 for (int j
= 0; j
< i
; ++j
) {
3091 cursor
.toNextSibling(qFvImage
);
3100 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3102 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3103 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3106 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3107 while (li
.hasNext()) {
3108 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3109 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3110 if (fi
.getFvImageNamesList().size() == 0) {
3116 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3117 XmlObject o
= getfpdFlash().getFvImages();
3121 XmlCursor cursor
= o
.newCursor();
3122 QName qFvImage
= new QName(xmlNs
, "FvImage");
3123 if (cursor
.toChild(qFvImage
)) {
3124 for (int j
= 0; j
< i
; ++j
) {
3125 cursor
.toNextSibling(qFvImage
);
3127 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3128 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3134 * @param oldFvName The FV Name to be replaced.
3135 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3137 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3138 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3139 XmlCursor cursor
= fi
.newCursor();
3141 if (cursor
.toChild(qFvImageNames
)) {
3143 String xmlValue
= cursor
.getTextValue();
3144 if (xmlValue
.equals(oldFvName
)){
3145 if (newFvName
!= null) {
3146 cursor
.setTextValue(newFvName
);
3152 }while (cursor
.toNextSibling(qFvImageNames
));
3158 /**update the Type attribute of ith FvImage with new type.
3162 public void updateFvImagesFvImageType (int i
, String type
) {
3163 XmlObject o
= getfpdFlash().getFvImages();
3167 XmlCursor cursor
= o
.newCursor();
3168 QName qFvImage
= new QName(xmlNs
, "FvImage");
3169 if (cursor
.toChild(qFvImage
)) {
3170 for (int j
= 0; j
< i
; ++j
) {
3171 cursor
.toNextSibling(qFvImage
);
3173 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3174 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3179 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3181 XmlObject o
= getfpdFlash().getFvImages();
3185 XmlCursor cursor
= o
.newCursor();
3186 QName qFvImage
= new QName(xmlNs
, "FvImage");
3187 if (cursor
.toChild(qFvImage
)) {
3188 for (int j
= 0; j
< i
; ++j
) {
3189 cursor
.toNextSibling(qFvImage
);
3191 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3192 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3195 // remove old FvImageNames before adding new ones
3197 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3198 cursor
.toChild(qFvImageNames
);
3200 while (cursor
.toNextSibling(qFvImageNames
)) {
3204 for (int k
= 0; k
< names
.length
; ++k
) {
3205 fi
.addFvImageNames(names
[k
]);
3208 // remove old FvImageOptions before adding new options
3210 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3211 cursor
.toNextSibling(qFvImageOptions
);
3214 setFvImagesFvImageFvImageOptions(options
, fi
);
3219 public int getFvImagesFvImageCount(String type
) {
3221 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3224 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3225 ListIterator li
= l
.listIterator();
3227 while(li
.hasNext()) {
3228 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3229 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3239 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3240 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3241 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3244 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3245 ListIterator li
= l
.listIterator();
3246 while(li
.hasNext()) {
3247 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3248 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3251 if (fi
.getFvImageNamesList().contains(fvName
)) {
3260 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3262 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3264 if (getfpdFlash().getFvImages() == null) {
3267 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3271 ListIterator li
= l
.listIterator();
3273 while(li
.hasNext()) {
3274 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3275 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3279 // get FvImageNames array, space separated
3281 List
<String
> lfn
= fi
.getFvImageNamesList();
3282 ListIterator lfni
= lfn
.listIterator();
3284 while (lfni
.hasNext()) {
3285 saa
[i
][0] += (String
)lfni
.next();
3288 saa
[i
][0] = saa
[i
][0].trim();
3290 saa
[i
][1] = fi
.getType()+"";
3296 public void removeFvImageNameValue (int i
, String attributeName
) {
3297 XmlObject o
= getfpdFlash().getFvImages();
3301 XmlCursor cursor
= o
.newCursor();
3302 QName qFvImage
= new QName(xmlNs
, "FvImage");
3303 if (cursor
.toChild(qFvImage
)) {
3304 for (int j
= 0; j
< i
; ++j
) {
3305 cursor
.toNextSibling(qFvImage
);
3307 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3308 removeFvImageNameValue (fi
, attributeName
);
3312 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3314 * @param attributeName
3316 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3317 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3318 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3319 while (li
.hasNext()) {
3320 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3321 if (nv
.getName().equals(attributeName
)) {
3328 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3329 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3330 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3331 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3332 removeFvImageNameValue (fi
, optName
);
3336 /**Add name-value pair to FvImage element with type.
3337 * @param fvName FV name to add name-value pair.
3338 * @param type FvImage attribute.
3342 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3343 boolean fvImageExists
= false;
3344 if (getfpdFlash().getFvImages() != null) {
3346 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3348 ListIterator li
= l
.listIterator();
3349 while (li
.hasNext()) {
3350 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3351 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3354 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3357 fvImageExists
= true;
3358 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3363 if (!fvImageExists
) {
3364 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3365 map
.put(name
, value
);
3366 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3370 /**Add to all FvImage elements with type, the name-value pair.
3375 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3376 if (getfpdFlash().getFvImages() == null) {
3379 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3383 ListIterator li
= l
.listIterator();
3384 while(li
.hasNext()) {
3385 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3386 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3389 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3394 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3395 XmlObject o
= getfpdFlash().getFvImages();
3399 XmlCursor cursor
= o
.newCursor();
3400 QName qFvImage
= new QName(xmlNs
, "FvImage");
3401 if (cursor
.toChild(qFvImage
)) {
3402 for (int j
= 0; j
< i
; ++j
) {
3403 cursor
.toNextSibling(qFvImage
);
3405 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3406 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3411 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3417 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3418 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3419 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3422 if (newName
!= null && !newName
.equals(name
)) {
3423 nv
.setName(newName
);
3428 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3429 if (cursor
.toFirstChild()) {
3431 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3432 if (nv
.getName().equals(name
)) {
3434 if (newName
!= null && !newName
.equals(name
)) {
3435 nv
.setName(newName
);
3440 }while (cursor
.toNextSibling());
3443 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3446 if (newName
!= null && !newName
.equals(name
)) {
3447 nv
.setName(newName
);
3452 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3453 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3454 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3455 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3456 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3460 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3463 while (li
.hasNext()) {
3464 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3465 m
.put(nv
.getName(), nv
.getValue());
3470 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3471 XmlObject o
= getfpdFlash().getFvImages();
3477 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3478 Vector
<String
> vFvNames
= new Vector
<String
>();
3481 XmlCursor cursor
= o
.newCursor();
3482 QName qFvImage
= new QName(xmlNs
, "FvImage");
3483 if (cursor
.toChild(qFvImage
)) {
3486 vFvNames
.removeAllElements();
3487 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3488 vFvNames
.add(fvNameArray
[i
]);
3490 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3491 if (!fi
.getType().toString().equals(type
)) {
3494 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3497 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3498 while (li
.hasNext()) {
3499 String name
= li
.next();
3500 vFvNames
.remove(name
);
3502 if (vFvNames
.size() == 0) {
3507 }while (cursor
.toNextSibling(qFvImage
));
3513 /**Get FvImage Options for FvImage i
3514 * @param i the ith FvImage
3516 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3517 XmlObject o
= getfpdFlash().getFvImages();
3521 XmlCursor cursor
= o
.newCursor();
3522 QName qFvImage
= new QName(xmlNs
, "FvImage");
3523 if (cursor
.toChild(qFvImage
)) {
3524 for (int j
= 0; j
< i
; ++j
) {
3525 cursor
.toNextSibling(qFvImage
);
3527 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3528 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3532 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3533 while(li
.hasNext()){
3534 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3535 m
.put(nv
.getName(), nv
.getValue());
3542 Get platform header element
3543 @return PlatformHeaderDocument.PlatformHeader
3545 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3546 if (fpdHdr
== null) {
3547 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3553 public String
getFpdHdrPlatformName() {
3554 return getFpdHdr().getPlatformName();
3557 public String
getFpdHdrGuidValue() {
3558 return getFpdHdr().getGuidValue();
3561 public String
getFpdHdrVer() {
3562 return getFpdHdr().getVersion();
3565 public String
getFpdHdrAbs() {
3566 return getFpdHdr().getAbstract();
3569 public String
getFpdHdrDescription() {
3570 return getFpdHdr().getDescription();
3573 public String
getFpdHdrCopyright() {
3574 return getFpdHdr().getCopyright();
3577 public String
getFpdHdrLicense() {
3578 LicenseDocument
.License l
= getFpdHdr().getLicense();
3582 return l
.getStringValue();
3585 public String
getFpdHdrUrl() {
3586 LicenseDocument
.License l
= getFpdHdr().getLicense();
3593 public String
getFpdHdrSpec() {
3595 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3596 // return getFpdHdr().getSpecification();
3599 public void setFpdHdrPlatformName(String name
){
3600 getFpdHdr().setPlatformName(name
);
3603 public void setFpdHdrGuidValue(String guid
){
3604 getFpdHdr().setGuidValue(guid
);
3607 public void setFpdHdrVer(String v
){
3608 getFpdHdr().setVersion(v
);
3611 public void setFpdHdrAbs(String abs
) {
3612 getFpdHdr().setAbstract(abs
);
3615 public void setFpdHdrDescription(String desc
){
3616 getFpdHdr().setDescription(desc
);
3619 public void setFpdHdrCopyright(String cr
) {
3620 getFpdHdr().setCopyright(cr
);
3623 public void setFpdHdrLicense(String license
){
3624 LicenseDocument
.License l
= getFpdHdr().getLicense();
3626 getFpdHdr().addNewLicense().setStringValue(license
);
3629 l
.setStringValue(license
);
3633 public void setFpdHdrUrl(String url
){
3634 LicenseDocument
.License l
= getFpdHdr().getLicense();
3640 public void setFpdHdrSpec(String s
){
3641 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3642 getFpdHdr().setSpecification(s
);
3645 Save the processed xml contents to file
3647 @param fpdFile The file to save xml contents
3648 @throws IOException Exceptions during file operation
3650 public void saveAs(File fpdFile
) throws IOException
{
3652 XmlOptions options
= new XmlOptions();
3654 options
.setCharacterEncoding("UTF-8");
3655 options
.setSavePrettyPrint();
3656 options
.setSavePrettyPrintIndent(2);
3658 fpdd
.save(fpdFile
, options
);
3659 } catch (IOException e
) {
3660 e
.printStackTrace();
3665 private String
listToString(List l
) {
3670 ListIterator li
= l
.listIterator();
3671 while(li
.hasNext()) {
3678 private void removeElement(XmlObject o
) {
3679 XmlCursor cursor
= o
.newCursor();
3685 class PcdItemTypeConflictException
extends Exception
{
3690 private static final long serialVersionUID
= 1L;
3691 private String details
= null;
3693 PcdItemTypeConflictException (String pcdName
, String info
) {
3694 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3696 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + " in Pkg " + mi
.getPackageId().getName();
3699 details
= pcdName
+ " ItemType Conflicts with " + info
;
3703 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3704 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3705 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3706 String moduleInfo1
= "";
3707 String moduleInfo2
= "";
3709 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3712 moduleInfo1
= info1
;
3716 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3719 moduleInfo2
= info2
;
3722 details
= pcdName
+ " ItemType Conflicts in " + moduleInfo1
+ " and " + moduleInfo2
;
3725 public String
getMessage() {
3730 class PcdDeclNotFound
extends Exception
{
3735 private static final long serialVersionUID
= 1L;
3736 private String details
= null;
3738 PcdDeclNotFound(String info
) {
3739 details
= "PcdDeclNotFound: " + info
;
3742 public String
getMessage() {
3747 class PcdValueMalFormed
extends Exception
{
3752 private static final long serialVersionUID
= 1L;
3753 private String details
= null;
3755 PcdValueMalFormed(String info
) {
3756 details
= "PcdValueMalFormed: " + info
;
3759 public String
getMessage() {