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
;
65 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
68 This class processes fpd file contents such as add remove xml elements.
69 @since PackageEditor 1.0
71 public class FpdFileContents
{
73 static final String xmlNs
= "http://www.TianoCore.org/2006/Edk2.0";
74 static final String regExpNewLineAndSpaces
= "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*";
76 private PlatformSurfaceAreaDocument fpdd
= null;
78 private PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpdRoot
= null;
80 private PlatformHeaderDocument
.PlatformHeader fpdHdr
= null;
82 private PlatformDefinitionsDocument
.PlatformDefinitions fpdPlatformDefs
= null;
84 private FlashDocument
.Flash fpdFlash
= null;
86 private BuildOptionsDocument
.BuildOptions fpdBuildOpts
= null;
88 private FrameworkModulesDocument
.FrameworkModules fpdFrameworkModules
= null;
90 private DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs
= null;
92 private HashMap
<String
, ArrayList
<String
>> dynPcdMap
= null;
94 private HashMap
<String
, String
> defaultPcdValue
= new HashMap
<String
, String
>();
96 private String
itemType (String pcdInfo
) {
98 return pcdInfo
.substring(pcdInfo
.lastIndexOf(" ") + 1);
102 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
104 public void initDynPcdMap() {
105 if (dynPcdMap
== null) {
106 dynPcdMap
= new HashMap
<String
, ArrayList
<String
>>();
107 List
<ModuleSADocument
.ModuleSA
> l
= getfpdFrameworkModules().getModuleSAList();
109 removeElement(getfpdFrameworkModules());
110 fpdFrameworkModules
= null;
113 ListIterator
<ModuleSADocument
.ModuleSA
> li
= l
.listIterator();
114 while (li
.hasNext()) {
115 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
116 if (moduleSa
.getPcdBuildDefinition() == null || moduleSa
.getPcdBuildDefinition().getPcdDataList() == null) {
119 String ModuleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion() +
120 " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
121 List
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lp
= moduleSa
.getPcdBuildDefinition().getPcdDataList();
122 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> lpi
= lp
.listIterator();
123 while (lpi
.hasNext()) {
124 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= lpi
.next();
125 String pcdKey
= pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName();
126 if (dynPcdMap
.get(pcdKey
) == null) {
127 ArrayList
<String
> al
= new ArrayList
<String
>();
128 al
.add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
129 dynPcdMap
.put(pcdKey
, al
);
132 dynPcdMap
.get(pcdKey
).add(ModuleInfo
+ " " + pcdData
.getItemType().toString());
139 public ArrayList
<String
> getDynPcdMapValue(String key
) {
140 return dynPcdMap
.get(key
);
143 Constructor to create a new spd file
145 public FpdFileContents() {
147 fpdd
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
148 fpdRoot
= fpdd
.addNewPlatformSurfaceArea();
153 Constructor for existing document object
156 public FpdFileContents(PlatformSurfaceAreaDocument
.PlatformSurfaceArea fpd
) {
158 fpdHdr
= fpdRoot
.getPlatformHeader();
159 fpdPlatformDefs
= fpdRoot
.getPlatformDefinitions();
160 fpdBuildOpts
= fpdRoot
.getBuildOptions();
161 fpdFrameworkModules
= fpdRoot
.getFrameworkModules();
162 fpdDynPcdBuildDefs
= fpdRoot
.getDynamicPcdBuildDefinitions();
163 fpdFlash
= fpdRoot
.getFlash();
167 Constructor based on an existing spd file
169 @param f Existing spd file
171 public FpdFileContents(File f
) {
173 fpdd
= PlatformSurfaceAreaDocument
.Factory
.parse(f
);
174 fpdRoot
= fpdd
.getPlatformSurfaceArea();
175 } catch (Exception e
) {
176 System
.out
.println(e
.toString());
180 public DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
getfpdDynPcdBuildDefs() {
181 if (fpdDynPcdBuildDefs
== null){
182 fpdDynPcdBuildDefs
= fpdRoot
.addNewDynamicPcdBuildDefinitions();
184 return fpdDynPcdBuildDefs
;
187 public FrameworkModulesDocument
.FrameworkModules
getfpdFrameworkModules() {
188 if (fpdFrameworkModules
== null){
189 fpdFrameworkModules
= fpdRoot
.addNewFrameworkModules();
191 return fpdFrameworkModules
;
194 public void getFrameworkModuleSAByFvBinding (String fvName
, Vector
<String
[]> vGuid
) {
195 if (getFrameworkModulesCount() == 0){
199 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
200 while(li
.hasNext()) {
201 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
202 if (moduleSa
.getModuleSaBuildOptions() == null) {
205 String fvBinding
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
206 if (fvBinding
== null) {
210 String
[] fvNames
= fvBinding
.split(" ");
211 for (int i
= 0; i
< fvNames
.length
; ++i
) {
213 // BugBug : underscore "_" should not be replaced!!!
214 // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file.
216 if (fvNames
[i
].equals(fvName
) || fvNames
[i
].replaceAll("_", "").equals(fvName
)) {
217 String
[] sa
= new String
[] {moduleSa
.getModuleGuid(), moduleSa
.getModuleVersion(),
218 moduleSa
.getPackageGuid(), moduleSa
.getPackageVersion(),
219 listToString(moduleSa
.getSupArchList())};
227 public int getFrameworkModulesCount() {
228 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
229 removeElement(getfpdFrameworkModules());
230 fpdFrameworkModules
= null;
233 return getfpdFrameworkModules().getModuleSAList().size();
236 public void getFrameworkModulesInfo(String
[][] saa
) {
237 if (getFrameworkModulesCount() == 0){
241 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
243 while(li
.hasNext()) {
244 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
245 saa
[i
][0] = moduleSa
.getModuleGuid();
246 saa
[i
][1] = moduleSa
.getModuleVersion();
248 saa
[i
][2] = moduleSa
.getPackageGuid();
249 saa
[i
][3] = moduleSa
.getPackageVersion();
250 saa
[i
][4] = listToString(moduleSa
.getSupArchList());
255 public void getFrameworkModuleInfo(int i
, String
[] sa
) {
256 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
260 sa
[0] = msa
.getModuleGuid();
261 sa
[1] = msa
.getModuleVersion();
262 sa
[2] = msa
.getPackageGuid();
263 sa
[3] = msa
.getPackageVersion();
264 sa
[4] = listToString(msa
.getSupArchList());
267 public ModuleSADocument
.ModuleSA
getModuleSA(String key
) {
269 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
270 removeElement(getfpdFrameworkModules());
271 fpdFrameworkModules
= null;
274 String
[] s
= key
.split(" ");
275 String archsInKey
= "";
277 for (int i
= 4; i
< s
.length
; ++i
) {
281 archsInKey
= archsInKey
.trim();
284 ListIterator li
= getfpdFrameworkModules().getModuleSAList().listIterator();
285 while(li
.hasNext()) {
286 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)li
.next();
287 if (moduleSa
.getModuleGuid().equalsIgnoreCase(s
[0]) && moduleSa
.getPackageGuid().equalsIgnoreCase(s
[2])) {
288 if (moduleSa
.getModuleVersion() != null) {
289 if (!moduleSa
.getModuleVersion().equals(s
[1])) {
293 if (moduleSa
.getPackageVersion() != null) {
294 if (!moduleSa
.getPackageVersion().equals(s
[3])) {
298 //ToDo add arch check .
299 if (moduleSa
.getSupArchList() != null) {
300 if (listToString(moduleSa
.getSupArchList()).equals(archsInKey
)) {
305 if (archsInKey
.length() == 0) {
314 private ModuleSADocument
.ModuleSA
getModuleSA(int i
) {
315 ModuleSADocument
.ModuleSA moduleSa
= null;
316 if (fpdRoot
.getFrameworkModules() == null) {
319 XmlCursor cursor
= fpdRoot
.getFrameworkModules().newCursor();
320 if (cursor
.toFirstChild()) {
321 for (int j
= 0; j
< i
; ++j
) {
322 cursor
.toNextSibling();
324 moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
330 public void removeModuleSA(int i
) {
331 XmlObject o
= fpdRoot
.getFrameworkModules();
336 XmlCursor cursor
= o
.newCursor();
337 if (cursor
.toFirstChild()) {
338 for (int j
= 0; j
< i
; ++j
) {
339 cursor
.toNextSibling();
342 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
344 ModuleSADocument
.ModuleSA moduleSa
= (ModuleSADocument
.ModuleSA
)cursor
.getObject();
345 String moduleInfo
= moduleSa
.getModuleGuid() + " " + moduleSa
.getModuleVersion() + " " +
346 moduleSa
.getPackageGuid()+ " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
347 PcdBuildDefinitionDocument
.PcdBuildDefinition pcdBuildDef
= moduleSa
.getPcdBuildDefinition();
348 if (pcdBuildDef
!= null && pcdBuildDef
.getPcdDataList() != null) {
349 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
> li
= pcdBuildDef
.getPcdDataList().listIterator();
350 while(li
.hasNext()) {
351 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
352 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(), moduleInfo
);
357 while (cursor
.hasPrevToken()) {
358 cursor
.toPrevToken();
359 if (!cursor
.isText()) {
362 if (cursor
.getObject() == null) {
365 String s
= cursor
.getTextValue();
366 if (s
.matches(regExpNewLineAndSpaces
)) {
371 if (cursor
.isComment()) {
377 if (getFrameworkModulesCount() == 0) {
379 removeElement(getfpdFrameworkModules());
380 fpdFrameworkModules
= null;
387 public boolean adjustPcd (int seqModuleSa
, Vector
<String
> vExceptions
) throws Exception
{
388 boolean dataModified
= false;
389 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
390 int pcdCount
= getPcdDataCount(seqModuleSa
);
391 String
[][] saaModuleSaPcd
= new String
[pcdCount
][7];
392 getPcdData(seqModuleSa
, saaModuleSaPcd
);
393 String mg
= moduleSa
.getModuleGuid().toLowerCase();
394 String mv
= moduleSa
.getModuleVersion();
395 String pg
= moduleSa
.getPackageGuid().toLowerCase();
396 String pv
= moduleSa
.getPackageVersion();
397 String arch
= listToString(moduleSa
.getSupArchList());
399 // delete pcd in ModuleSA but not in MSA files any longer.
401 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
402 int libCount
= getLibraryInstancesCount(moduleKey
);
403 String
[][] saaLib
= new String
[libCount
][5];
404 getLibraryInstances(moduleKey
, saaLib
);
405 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
407 vExceptions
.add("Module " + mg
+ " does NOT exist in workspace.");
408 throw new Exception ("Module does NOT exist in workspace.");
410 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
412 // create vector for module & library instance MIs.
415 for (int j
= 0; j
< saaLib
.length
; ++j
) {
416 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
417 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
423 nextPcd
:for (int i
= 0; i
< saaModuleSaPcd
.length
; ++i
) {
425 for (int j
= 0; j
< vMi
.size(); ++j
) {
426 ModuleIdentification nextMi
= vMi
.get(j
);
427 if (nextMi
== null) {
430 if (WorkspaceProfile
.pcdInMsa(saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1], nextMi
)) {
434 removePcdData(seqModuleSa
, saaModuleSaPcd
[i
][0], saaModuleSaPcd
[i
][1]);
438 // add new Pcd from MSA file to ModuleSA.
440 for (int i
= 0; i
< vMi
.size(); ++i
) {
441 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
442 .getModuleXmlObject(vMi
444 if (msa
.getPcdCoded() == null || msa
.getPcdCoded().getPcdEntryList() == null) {
447 ListIterator li
= msa
.getPcdCoded().getPcdEntryList().listIterator();
448 msaPcdIter
:while (li
.hasNext()) {
449 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
450 ArrayList
<String
> al
= getDynPcdMapValue(msaPcd
.getCName() + " " + msaPcd
.getTokenSpaceGuidCName());
452 for (int j
= 0; j
< al
.size(); ++j
) {
453 if (al
.get(j
).startsWith(moduleKey
)) {
459 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, vMi
.get(i
));
460 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
461 if (spdPcd
== null) {
465 String errorMessage
= "No Declaration for PCD Entry " + msaPcd
.getCName() + " in Module "
468 errorMessage
+= " Library Instance " + vMi
.get(i
).getName();
470 vExceptions
.add(errorMessage
);
471 throw new PcdDeclNotFound(errorMessage
);
474 // AddItem to ModuleSA PcdBuildDefinitions
476 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue()
477 : msaPcd
.getDefaultValue();
479 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(),
480 msaPcd
.getPcdItemType().toString(), spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
489 private void maintainDynPcdMap(String pcdKey
, String moduleInfo
) {
491 ArrayList
<String
> al
= dynPcdMap
.get(pcdKey
);
495 String
[] s
= moduleInfo
.split(" ");
496 for(int i
= 0; i
< al
.size(); ++i
){
497 String consumer
= al
.get(i
);
498 if (consumer
.contains(s
[0].toLowerCase()) && consumer
.contains(s
[2].toLowerCase())){
499 String
[] consumerPart
= consumer
.split(" ");
500 if (!consumerPart
[4].equals(s
[4])) {
508 if (al
.size() == 0) {
509 defaultPcdValue
.remove(pcdKey
);
510 dynPcdMap
.remove(pcdKey
);
511 String
[] s1
= pcdKey
.split(" ");
512 removeDynamicPcdBuildData(s1
[0], s1
[1]);
517 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
519 public int getPcdDataCount (int i
){
520 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
522 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
525 return msa
.getPcdBuildDefinition().getPcdDataList().size();
529 public void getPcdData (int i
, String
[][] saa
) {
530 ModuleSADocument
.ModuleSA msa
= getModuleSA(i
);
532 if (msa
== null || msa
.getPcdBuildDefinition() == null || msa
.getPcdBuildDefinition().getPcdDataList() == null){
535 ListIterator
<PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
>li
= msa
.getPcdBuildDefinition().getPcdDataList().listIterator();
536 for (int k
= 0; k
< saa
.length
; ++k
) {
537 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= li
.next();
538 saa
[k
][0] = pcdData
.getCName();
539 saa
[k
][1] = pcdData
.getTokenSpaceGuidCName();
540 saa
[k
][2] = pcdData
.getItemType()+"";
541 saa
[k
][3] = pcdData
.getToken().toString();
542 saa
[k
][4] = pcdData
.getMaxDatumSize()+"";
543 saa
[k
][5] = pcdData
.getDatumType()+"";
544 saa
[k
][6] = pcdData
.getValue();
549 public void removePcdData (int seqModuleSa
, String cName
, String tsGuid
) {
550 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(seqModuleSa
);
551 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
555 String mg
= moduleSa
.getModuleGuid();
556 String mv
= moduleSa
.getModuleVersion();
557 String pg
= moduleSa
.getPackageGuid();
558 String pv
= moduleSa
.getPackageVersion();
559 String arch
= listToString(moduleSa
.getSupArchList());
560 String moduleKey
= mg
+ " " + mv
+ " " + pg
+ " " + pv
+ " " + arch
;
562 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
563 if (cursor
.toFirstChild()){
566 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
567 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
568 maintainDynPcdMap(cName
+ " " + tsGuid
, moduleKey
);
569 if (getPcdDataCount(seqModuleSa
) == 1) {
576 while(cursor
.toNextSibling());
582 public void updatePcdData (String key
, String cName
, String tsGuid
, String itemType
, String maxSize
, String value
){
583 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(key
);
584 if (moduleSa
== null || moduleSa
.getPcdBuildDefinition() == null){
588 XmlCursor cursor
= moduleSa
.getPcdBuildDefinition().newCursor();
589 if (cursor
.toFirstChild()){
591 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)cursor
.getObject();
592 if (pcdData
.getCName().equals(cName
) && pcdData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
594 // change item type while not updating dynPcdData????
596 if (itemType
!= null) {
597 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
600 if(pcdData
.getDatumType().equals("VOID*") && maxSize
!= null) {
601 pcdData
.setMaxDatumSize(new Integer(maxSize
));
604 // if value input is null, keep old value untouched.
607 pcdData
.setValue(value
);
608 defaultPcdValue
.put(cName
+ " " + tsGuid
, value
);
614 while(cursor
.toNextSibling());
619 /**Get original Pcd info from MSA & SPD files.
620 * @param mi ModuleIdentification from which MSA & SPD come
621 * @param cName PCD cName
622 * @param sa Results: HelpText, Original item type.
625 public boolean getPcdBuildDataInfo(ModuleIdentification mi
, String cName
, String tsGuid
, String
[] sa
, Vector
<String
> validPcdTypes
) throws Exception
{
627 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
628 .getModuleXmlObject(mi
);
629 if (msa
.getPcdCoded() == null) {
633 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
635 // First look through MSA pcd entries.
637 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
638 ListIterator li
= l
.listIterator();
639 while (li
.hasNext()) {
640 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
641 if (!msaPcd
.getCName().equals(cName
)) {
644 if (!msaPcd
.getTokenSpaceGuidCName().equals(tsGuid
)) {
647 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
648 if (spdPcd
== null || spdPcd
.getValidUsage() == null) {
652 throw new PcdDeclNotFound(mi
.getName() + " " + msaPcd
.getCName());
655 // Get Pcd help text and original item type.
657 sa
[0] = spdPcd
.getHelpText() + msaPcd
.getHelpText();
658 sa
[1] = msaPcd
.getPcdItemType() + "";
659 sa
[2] = msa
.getModuleDefinitions().getBinaryModule() + "";
660 ListIterator iter
= spdPcd
.getValidUsage().listIterator();
661 while (iter
.hasNext()) {
662 String usage
= iter
.next().toString();
663 validPcdTypes
.add(usage
);
671 private boolean multiSourcePcd (String cName
, String tsGuidCName
, String moduleKey
) {
672 int libCount
= getLibraryInstancesCount(moduleKey
);
673 String
[][] saaLib
= new String
[libCount
][5];
674 getLibraryInstances(moduleKey
, saaLib
);
675 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(moduleKey
);
676 Vector
<ModuleIdentification
> vMi
= new Vector
<ModuleIdentification
>();
678 // create vector for module & library instance MIs.
681 for (int j
= 0; j
< saaLib
.length
; ++j
) {
682 String libKey
= saaLib
[j
][1] + " " + saaLib
[j
][2] + " " + saaLib
[j
][3] + " " + saaLib
[j
][4];
683 ModuleIdentification libMi
= WorkspaceProfile
.getModuleId(libKey
);
687 int pcdSourceCount
= 0;
688 for (int i
= 0; i
< vMi
.size(); ++i
) {
689 if (WorkspaceProfile
.pcdInMsa(cName
, tsGuidCName
, vMi
.get(i
))) {
694 if (pcdSourceCount
< 2) {
703 /**Remove PCDBuildDefinition entries from ModuleSA
704 * @param moduleKey identifier of ModuleSA.
705 * @param consumer where these entries come from.
707 public void removePcdData(String moduleKey
, ModuleIdentification consumer
) {
709 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(consumer
);
710 if (msa
.getPcdCoded() == null) {
714 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
715 ListIterator li
= l
.listIterator();
717 while(li
.hasNext()) {
718 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
)li
.next();
719 ModuleSADocument
.ModuleSA moduleSA
= getModuleSA(moduleKey
);
720 if (moduleSA
.getPcdBuildDefinition() != null) {
721 XmlCursor cursor
= moduleSA
.getPcdBuildDefinition().newCursor();
723 if (cursor
.toFirstChild()) {
725 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
) cursor
727 String cName
= msaPcd
.getCName();
728 String tsGuidCName
= msaPcd
.getTokenSpaceGuidCName();
729 if (cName
.equals(pcdData
.getCName())
730 && tsGuidCName
.equals(pcdData
.getTokenSpaceGuidCName()) && !multiSourcePcd(cName
, tsGuidCName
, moduleKey
)) {
732 maintainDynPcdMap(pcdData
.getCName() + " " + pcdData
.getTokenSpaceGuidCName(),
737 } while (cursor
.toNextSibling());
741 if (moduleSA
.getPcdBuildDefinition().getPcdDataList().size() == 0) {
750 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
752 public int getLibraryInstancesCount(String key
) {
753 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
754 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
757 return msa
.getLibraries().getInstanceList().size();
760 public void getLibraryInstances(String key
, String
[][] saa
){
761 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
762 if (msa
== null || msa
.getLibraries() == null || msa
.getLibraries().getInstanceList() == null){
766 ListIterator
<LibrariesDocument
.Libraries
.Instance
> li
= msa
.getLibraries().getInstanceList().listIterator();
767 for (int i
= 0; i
< saa
.length
; ++i
) {
768 LibrariesDocument
.Libraries
.Instance instance
= li
.next();
769 saa
[i
][1] = instance
.getModuleGuid();
770 saa
[i
][2] = instance
.getModuleVersion();
771 saa
[i
][3] = instance
.getPackageGuid();
772 saa
[i
][4] = instance
.getPackageVersion();
776 public void removeLibraryInstance(String key
, int i
) {
777 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
778 if (msa
== null || msa
.getLibraries() == null){
782 XmlCursor cursor
= msa
.getLibraries().newCursor();
783 if (cursor
.toFirstChild()) {
784 for (int j
= 0; j
< i
; ++j
) {
785 cursor
.toNextSibling();
788 while (cursor
.hasPrevToken()) {
789 cursor
.toPrevToken();
790 if (!cursor
.isText()) {
793 String s
= cursor
.getTextValue();
794 if (s
.matches(regExpNewLineAndSpaces
)) {
799 if (cursor
.isComment()) {
804 if (getLibraryInstancesCount(key
) == 0) {
813 public void genLibraryInstance(ModuleIdentification libMi
, String key
) {
814 ModuleSADocument
.ModuleSA msa
= getModuleSA(key
);
816 msa
= getfpdFrameworkModules().addNewModuleSA();
818 LibrariesDocument
.Libraries libs
= msa
.getLibraries();
820 libs
= msa
.addNewLibraries();
823 String mn
= libMi
.getName();
824 String mg
= libMi
.getGuid();
825 String mv
= libMi
.getVersion();
826 String pn
= libMi
.getPackageId().getName();
827 String pg
= libMi
.getPackageId().getGuid();
828 String pv
= libMi
.getPackageId().getVersion();
829 LibrariesDocument
.Libraries
.Instance instance
= libs
.addNewInstance();
830 XmlCursor cursor
= instance
.newCursor();
832 String comment
= "Pkg: " + pn
+ " Mod: " + mn
833 + " Path: " + libMi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
834 cursor
.insertComment(comment
);
843 instance
.setModuleGuid(mg
);
844 instance
.setModuleVersion(mv
);
845 instance
.setPackageGuid(pg
);
846 instance
.setPackageVersion(pv
);
850 public String
getFvBinding(String moduleKey
){
851 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
852 return getFvBinding (moduleSa
);
855 public String
getFvBinding (ModuleSADocument
.ModuleSA moduleSa
) {
856 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
859 return moduleSa
.getModuleSaBuildOptions().getFvBinding();
862 public void setFvBinding(ModuleSADocument
.ModuleSA moduleSa
, String fvBinding
) {
863 if (moduleSa
== null ) {
866 if (fvBinding
== null || fvBinding
.length() == 0) {
867 if(moduleSa
.getModuleSaBuildOptions() != null){
868 moduleSa
.getModuleSaBuildOptions().unsetFvBinding();
872 if(moduleSa
.getModuleSaBuildOptions() == null){
873 moduleSa
.addNewModuleSaBuildOptions().setFvBinding(fvBinding
);
876 moduleSa
.getModuleSaBuildOptions().setFvBinding(fvBinding
);
880 public void setFvBinding(String moduleKey
, String fvBinding
){
881 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
882 setFvBinding (moduleSa
, fvBinding
);
885 private int fvBindingForModuleSA (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
886 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
890 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
891 String
[] fvNamesArray
= fvNameList
.split(" ");
893 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
894 if (fvNamesArray
[i
].equals(fvName
)) {
902 public void removeFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
903 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
907 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
908 String
[] fvNamesArray
= fvNameList
.split(" ");
910 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
911 if (fvNamesArray
[i
].equals(fvName
)) {
916 // jump over where the input fvName occurs in the original Fv list.
917 if (occursAt
!= -1) {
918 String newFvNameList
= " ";
919 for (int i
= 0; i
< fvNamesArray
.length
; ++i
) {
923 newFvNameList
+= fvNamesArray
[i
];
925 setFvBinding (moduleSa
, newFvNameList
.trim());
931 * @param fvName The FV name that to be removed from FvBinding List.
933 public void removeFvBindingAll (String fvName
) {
934 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
935 removeElement(getfpdFrameworkModules());
936 fpdFrameworkModules
= null;
940 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
941 while (li
.hasNext()) {
942 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
943 removeFvBinding (moduleSa
, fvName
);
947 public void appendFvBindingAll (String fvName
) {
948 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
949 removeElement(getfpdFrameworkModules());
950 fpdFrameworkModules
= null;
954 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
955 while (li
.hasNext()) {
956 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
957 appendFvBinding (moduleSa
, fvName
);
961 public void appendFvBindingFor (String oldFvName
, String newFvName
) {
962 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
963 removeElement(getfpdFrameworkModules());
964 fpdFrameworkModules
= null;
968 Iterator
<ModuleSADocument
.ModuleSA
> li
= getfpdFrameworkModules().getModuleSAList().iterator();
969 while (li
.hasNext()) {
970 ModuleSADocument
.ModuleSA moduleSa
= li
.next();
971 String fvBinding
= getFvBinding (moduleSa
);
972 if (fvBinding
!= null && fvBindingForModuleSA (moduleSa
, oldFvName
) >= 0) {
973 appendFvBinding (moduleSa
, newFvName
);
978 public void appendFvBinding (String moduleKey
, String fvName
) {
979 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
980 appendFvBinding (moduleSa
, fvName
);
983 public void appendFvBinding (ModuleSADocument
.ModuleSA moduleSa
, String fvName
) {
984 if (moduleSa
== null) {
988 if (moduleSa
.getModuleSaBuildOptions() == null || moduleSa
.getModuleSaBuildOptions().getFvBinding() == null) {
989 setFvBinding(moduleSa
, fvName
);
993 String fvNameList
= moduleSa
.getModuleSaBuildOptions().getFvBinding();
994 String newFvNameList
= fvNameList
+ " " + fvName
;
995 setFvBinding (moduleSa
, newFvNameList
.trim());
998 public void updateFvBindingInModuleSA (String moduleKey
, String fvName
) {
1000 appendFvBinding (moduleKey
, fvName
);
1003 public String
getFfsFileNameGuid(String moduleKey
){
1004 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(moduleKey
);
1005 if (moduleSa
== null || moduleSa
.getModuleSaBuildOptions() == null) {
1008 return moduleSa
.getModuleSaBuildOptions().getFfsFileNameGuid();
1011 public void setFfsFileNameGuid(String moduleKey
, String fileGuid
){
1012 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1016 if(msa
.getModuleSaBuildOptions() == null){
1017 msa
.addNewModuleSaBuildOptions();
1020 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions msaBuildOpts
= msa
.getModuleSaBuildOptions();
1021 if (fileGuid
!= null) {
1022 msaBuildOpts
.setFfsFileNameGuid(fileGuid
);
1025 XmlCursor cursor
= msaBuildOpts
.newCursor();
1026 if (cursor
.toChild(xmlNs
, "FfsFileNameGuid")) {
1034 public String
getFfsFormatKey(String moduleKey
){
1035 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1036 if (msa
== null || msa
.getModuleSaBuildOptions() == null) {
1039 return msa
.getModuleSaBuildOptions().getFfsFormatKey();
1042 public void setFfsFormatKey(String moduleKey
, String ffsKey
){
1043 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1047 if(msa
.getModuleSaBuildOptions() == null){
1048 msa
.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1051 msa
.getModuleSaBuildOptions().setFfsFormatKey(ffsKey
);
1054 public void setModuleSAForceDebug(int i
, boolean dbgEnable
) {
1055 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1056 moduleSa
.setForceDebug(dbgEnable
);
1059 public boolean getModuleSAForceDebug (int i
) {
1060 ModuleSADocument
.ModuleSA moduleSa
= getModuleSA(i
);
1061 if (moduleSa
.getForceDebug() == true) {
1067 public void getModuleSAOptions(String moduleKey
, String
[][] saa
) {
1068 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1069 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1070 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1074 List
<OptionDocument
.Option
> lOpt
= msa
.getModuleSaBuildOptions().getOptions().getOptionList();
1075 ListIterator li
= lOpt
.listIterator();
1077 while(li
.hasNext()) {
1078 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
1079 if (opt
.getBuildTargets() != null) {
1080 saa
[i
][0] = listToString(opt
.getBuildTargets());
1082 saa
[i
][1] = opt
.getToolChainFamily();
1083 saa
[i
][2] = opt
.getTagName();
1084 saa
[i
][3] = opt
.getToolCode();
1086 if (opt
.getSupArchList() != null){
1087 saa
[i
][4] = listToString(opt
.getSupArchList());
1093 saa
[i
][5] = opt
.getStringValue();
1099 public int getModuleSAOptionsCount(String moduleKey
){
1100 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1101 if (msa
== null || msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null
1102 || msa
.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1105 return msa
.getModuleSaBuildOptions().getOptions().getOptionList().size();
1108 public void genModuleSAOptionsOpt(String moduleKey
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1109 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1110 if (msa
.getModuleSaBuildOptions() == null) {
1111 msa
.addNewModuleSaBuildOptions();
1113 if (msa
.getModuleSaBuildOptions().getOptions() == null){
1114 msa
.getModuleSaBuildOptions().addNewOptions();
1116 OptionDocument
.Option opt
= msa
.getModuleSaBuildOptions().getOptions().addNewOption();
1117 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1120 public void removeModuleSAOptionsOpt(String moduleKey
, int i
) {
1121 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1122 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1125 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1126 XmlCursor cursor
= opts
.newCursor();
1127 if (cursor
.toFirstChild()) {
1128 for (int j
= 0; j
< i
; ++j
){
1129 cursor
.toNextSibling();
1132 if (getModuleSAOptionsCount(moduleKey
) == 0) {
1140 public void updateModuleSAOptionsOpt(String moduleKey
, int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
1141 ModuleSADocument
.ModuleSA msa
= getModuleSA(moduleKey
);
1142 if (msa
.getModuleSaBuildOptions() == null || msa
.getModuleSaBuildOptions().getOptions() == null) {
1145 OptionsDocument
.Options opts
= msa
.getModuleSaBuildOptions().getOptions();
1146 XmlCursor cursor
= opts
.newCursor();
1147 if (cursor
.toFirstChild()) {
1148 for (int j
= 0; j
< i
; ++j
){
1149 cursor
.toNextSibling();
1151 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
1152 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
1157 /**add pcd information of module mi to a ModuleSA.
1159 * @param moduleSa if null, generate a new ModuleSA.
1161 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi
, String arch
, ModuleSADocument
.ModuleSA moduleSa
) throws Exception
{
1162 //ToDo add Arch filter
1164 if (moduleSa
== null) {
1165 moduleSa
= genModuleSA(mi
, arch
);
1168 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
1169 .getModuleXmlObject(mi
);
1170 if (msa
.getPcdCoded() == null) {
1174 PackageIdentification
[] depPkgs
= SurfaceAreaQuery
.getDependencePkg(null, mi
);
1176 // Implementing InitializePlatformPcdBuildDefinitions
1178 List
<PcdCodedDocument
.PcdCoded
.PcdEntry
> l
= msa
.getPcdCoded().getPcdEntryList();
1179 ListIterator li
= l
.listIterator();
1180 while (li
.hasNext()) {
1181 PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
= (PcdCodedDocument
.PcdCoded
.PcdEntry
) li
.next();
1182 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= LookupPcdDeclaration(msaPcd
, depPkgs
);
1183 if (spdPcd
== null) {
1187 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd
.getCName() + "\n used by Module "
1188 + mi
.getName() + " or its Library Instances.");
1191 // AddItem to ModuleSA PcdBuildDefinitions
1193 String defaultVal
= msaPcd
.getDefaultValue() == null ? spdPcd
.getDefaultValue() : msaPcd
.getDefaultValue();
1195 genPcdData(msaPcd
.getCName(), spdPcd
.getToken(), msaPcd
.getTokenSpaceGuidCName(), msaPcd
.getPcdItemType()
1197 spdPcd
.getDatumType() + "", defaultVal
, moduleSa
, spdPcd
);
1202 private PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
LookupPcdDeclaration (PcdCodedDocument
.PcdCoded
.PcdEntry msaPcd
, PackageIdentification
[] depPkgs
) {
1204 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
= null;
1205 for (int i
= 0; i
< depPkgs
.length
; ++i
) {
1207 XmlObject
[] xo
= SurfaceAreaQuery
.getSpdPcdDeclarations(depPkgs
[i
]);
1211 for (int j
= 0; j
< xo
.length
; ++j
) {
1212 spdPcd
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)xo
[j
];
1213 if (msaPcd
.getTokenSpaceGuidCName() == null) {
1214 if (spdPcd
.getCName().equals(msaPcd
.getCName())) {
1219 if (spdPcd
.getCName().equals(msaPcd
.getCName()) && spdPcd
.getTokenSpaceGuidCName().equals(msaPcd
.getTokenSpaceGuidCName())) {
1230 private ModuleSADocument
.ModuleSA
genModuleSA (ModuleIdentification mi
, String arch
) {
1231 PackageIdentification pi
= WorkspaceProfile
.getPackageForModule(mi
);
1232 ModuleSADocument
.ModuleSA msa
= getfpdFrameworkModules().addNewModuleSA();
1233 XmlCursor cursor
= msa
.newCursor();
1235 String comment
= "Mod: " + mi
.getName() + " Type: " + SurfaceAreaQuery
.getModuleType(mi
) + " Path: "
1236 + mi
.getPath().substring(Workspace
.getCurrentWorkspace().length() + 1);
1237 cursor
.insertComment(comment
);
1240 e
.printStackTrace();
1245 msa
.setModuleGuid(mi
.getGuid());
1246 msa
.setModuleVersion(mi
.getVersion());
1247 msa
.setPackageGuid(pi
.getGuid());
1248 msa
.setPackageVersion(pi
.getVersion());
1250 Vector
<String
> v
= new Vector
<String
>();
1252 msa
.setSupArchList(v
);
1258 private String
chooseDefaultPcdType (List validPcdTypes
) {
1259 String choosedType
= "";
1260 if (validPcdTypes
.contains("FIXED_AT_BUILD")) {
1261 choosedType
= "FIXED_AT_BUILD";
1263 else if (validPcdTypes
.contains("DYNAMIC")) {
1264 choosedType
= "DYNAMIC";
1266 else if (validPcdTypes
.contains("PATCHABLE_IN_MODULE")) {
1267 choosedType
= "PATCHABLE_IN_MODULE";
1269 else if (validPcdTypes
.contains("DYNAMIC_EX")) {
1270 choosedType
= "DYNAMIC_EX";
1275 private void genPcdData (String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
,
1276 ModuleSADocument
.ModuleSA moduleSa
, PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry spdPcd
)
1277 throws PcdItemTypeConflictException
, PcdValueMalFormed
{
1278 if (moduleSa
.getPcdBuildDefinition() == null){
1279 moduleSa
.addNewPcdBuildDefinition();
1282 // constructe pcd to modulesa mapping first.
1283 // Attention : for any error condition, remove from map this pcd.
1285 ArrayList
<String
> pcdConsumer
= LookupPlatformPcdData(cName
+ " " + tsGuid
);
1286 if (pcdConsumer
== null) {
1287 pcdConsumer
= new ArrayList
<String
>();
1290 // Check whether this PCD has already added to ModuleSA, if so, just return.
1292 String moduleInfo
= moduleSa
.getModuleGuid().toLowerCase() + " " + moduleSa
.getModuleVersion()
1293 + " " + moduleSa
.getPackageGuid().toLowerCase() + " " + moduleSa
.getPackageVersion() + " " + listToString(moduleSa
.getSupArchList());
1294 for (int i
= 0; i
< pcdConsumer
.size(); ++i
) {
1295 String pcdInfo
= pcdConsumer
.get(i
);
1296 if (moduleInfo
.equals(pcdInfo
.substring(0, pcdInfo
.lastIndexOf(" ")))){
1300 // if pcd type from MSA file is Dynamic
1301 // we must choose one default type from SPD file for it.
1303 List validPcdTypes
= spdPcd
.getValidUsage();
1305 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1307 if (pcdConsumer
.size() > 0) {
1309 // platform should only contain one type for each pcd.
1311 String existingItemType
= itemType (pcdConsumer
.get(0));
1312 for (int i
= 1; i
< pcdConsumer
.size(); ++i
) {
1313 if (!existingItemType
.equals(itemType(pcdConsumer
.get(i
)))) {
1314 throw new PcdItemTypeConflictException (cName
, pcdConsumer
.get(0), pcdConsumer
.get(i
));
1318 if (itemType
.equals("DYNAMIC")) {
1319 if (!validPcdTypes
.contains(existingItemType
)) {
1320 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1322 itemType
= existingItemType
;
1325 if (!itemType
.equals(existingItemType
)) {
1326 throw new PcdItemTypeConflictException(cName
, pcdConsumer
.get(0));
1331 // if this is the first occurence of this pcd.
1334 if (itemType
.equals("DYNAMIC")) {
1335 itemType
= chooseDefaultPcdType (validPcdTypes
);
1338 String listValue
= moduleInfo
+ " " + itemType
;
1339 pcdConsumer
.add(listValue
);
1340 dynPcdMap
.put(cName
+ " " + tsGuid
, pcdConsumer
);
1342 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData fpdPcd
= moduleSa
.getPcdBuildDefinition().addNewPcdData();
1343 fpdPcd
.setCName(cName
);
1344 fpdPcd
.setToken(token
);
1345 fpdPcd
.setTokenSpaceGuidCName(tsGuid
);
1346 fpdPcd
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1347 fpdPcd
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1349 if (defaultVal
!= null && defaultVal
.length() > 0){
1350 fpdPcd
.setValue(defaultVal
);
1353 if (dataType
.equals("UINT8") || dataType
.equals("UINT16") || dataType
.equals("UINT32") || dataType
.equals("UINT64")) {
1354 fpdPcd
.setValue("0");
1356 if (dataType
.equals("BOOLEAN")){
1357 fpdPcd
.setValue("FALSE");
1359 if (dataType
.equals("VOID*")) {
1360 fpdPcd
.setValue("L\"\"");
1364 // Using existing pcd value, if this pcd already exists in other moduleSa.
1366 if (defaultPcdValue
.get(cName
+ " " + tsGuid
) == null) {
1367 defaultPcdValue
.put(cName
+ " " + tsGuid
, fpdPcd
.getValue());
1370 fpdPcd
.setValue(defaultPcdValue
.get(cName
+ " " + tsGuid
));
1373 if (dataType
.equals("UINT8")){
1374 fpdPcd
.setMaxDatumSize(1);
1376 if (dataType
.equals("UINT16")) {
1377 fpdPcd
.setMaxDatumSize(2);
1379 if (dataType
.equals("UINT32")) {
1380 fpdPcd
.setMaxDatumSize(4);
1382 if (dataType
.equals("UINT64")){
1383 fpdPcd
.setMaxDatumSize(8);
1385 if (dataType
.equals("BOOLEAN")){
1386 fpdPcd
.setMaxDatumSize(1);
1388 if (dataType
.equals("VOID*")) {
1389 int maxSize
= setMaxSizeForPointer(fpdPcd
.getValue());
1390 fpdPcd
.setMaxDatumSize(maxSize
);
1394 if (itemType
.equals("DYNAMIC") || itemType
.equals("DYNAMIC_EX")) {
1395 ArrayList
<String
> al
= LookupDynamicPcdBuildDefinition(cName
+ " " + tsGuid
);
1397 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1398 // so need to add one dyn pcd.
1400 if (al
.size() == 1) {
1401 addDynamicPcdBuildData(cName
, token
, tsGuid
, itemType
, dataType
, defaultVal
);
1407 public int setMaxSizeForPointer(String datum
) throws PcdValueMalFormed
{
1408 if (datum
== null) {
1411 char ch
= datum
.charAt(0);
1415 // For void* type PCD, only three datum is support:
1416 // 1) Unicode: string with start char is "L"
1417 // 2) Ansci: String is ""
1418 // 3) byte array: String start char "{"
1421 start
= datum
.indexOf('\"');
1422 end
= datum
.lastIndexOf('\"');
1423 if ((start
> end
) ||
1424 (end
> datum
.length())||
1425 ((start
== end
) && (datum
.length() > 0))) {
1426 //ToDo Error handling here
1427 throw new PcdValueMalFormed (datum
);
1430 strValue
= datum
.substring(start
+ 1, end
);
1431 return strValue
.length() * 2;
1432 } else if (ch
== '\"'){
1433 start
= datum
.indexOf('\"');
1434 end
= datum
.lastIndexOf('\"');
1435 if ((start
> end
) ||
1436 (end
> datum
.length())||
1437 ((start
== end
) && (datum
.length() > 0))) {
1438 throw new PcdValueMalFormed (datum
);
1440 strValue
= datum
.substring(start
+ 1, end
);
1441 return strValue
.length();
1442 } else if (ch
=='{') {
1443 String
[] strValueArray
;
1445 start
= datum
.indexOf('{');
1446 end
= datum
.lastIndexOf('}');
1447 strValue
= datum
.substring(start
+ 1, end
);
1448 strValue
= strValue
.trim();
1449 if (strValue
.length() == 0) {
1452 strValueArray
= strValue
.split(",");
1453 for (int index
= 0; index
< strValueArray
.length
; index
++) {
1454 Integer value
= Integer
.decode(strValueArray
[index
].trim());
1457 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1458 // "it must be a byte array. But the element of %s exceed the byte range",
1459 throw new PcdValueMalFormed (datum
);
1462 return strValueArray
.length
;
1466 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1467 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1468 // "2) ANSIC string: like \"xxx\";\r\n"+
1469 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1470 // "but the datum in seems does not following above format!",
1471 throw new PcdValueMalFormed (datum
);
1476 private ArrayList
<String
> LookupDynamicPcdBuildDefinition(String dynPcdKey
) {
1477 ArrayList
<String
> al
= dynPcdMap
.get(dynPcdKey
);
1482 private ArrayList
<String
> LookupPlatformPcdData(String pcdKey
) {
1484 return dynPcdMap
.get(pcdKey
);
1487 public int getDynamicPcdBuildDataCount() {
1488 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1489 removeElement(getfpdDynPcdBuildDefs());
1490 fpdDynPcdBuildDefs
= null;
1493 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1496 public void getDynamicPcdBuildData(String
[][] saa
) {
1497 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1498 removeElement(getfpdDynPcdBuildDefs());
1499 fpdDynPcdBuildDefs
= null;
1502 List
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> l
= getfpdDynPcdBuildDefs().getPcdBuildDataList();
1503 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
> li
= l
.listIterator();
1505 while(li
.hasNext()) {
1506 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcd
= li
.next();
1507 saa
[i
][0] = dynPcd
.getCName();
1508 saa
[i
][1] = dynPcd
.getToken().toString();
1509 saa
[i
][2] = dynPcd
.getTokenSpaceGuidCName();
1510 saa
[i
][3] = dynPcd
.getMaxDatumSize()+"";
1511 saa
[i
][4] = dynPcd
.getDatumType()+"";
1517 public void addDynamicPcdBuildData(String cName
, Object token
, String tsGuid
, String itemType
, String dataType
, String defaultVal
)
1518 throws PcdValueMalFormed
{
1519 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData dynPcdData
= getfpdDynPcdBuildDefs().addNewPcdBuildData();
1520 dynPcdData
.setItemType(PcdItemTypes
.Enum
.forString(itemType
));
1521 dynPcdData
.setCName(cName
);
1522 dynPcdData
.setToken(token
);
1523 dynPcdData
.setTokenSpaceGuidCName(tsGuid
);
1524 dynPcdData
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1526 BigInteger bigInt
= new BigInteger("0");
1527 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= dynPcdData
.addNewSkuInfo();
1528 skuInfo
.setSkuId(bigInt
);
1529 if (defaultVal
!= null){
1530 skuInfo
.setValue(defaultVal
);
1533 if (dataType
.equals("UINT8")){
1534 skuInfo
.setValue("0");
1536 if (dataType
.equals("UINT16")) {
1537 skuInfo
.setValue("0");
1539 if (dataType
.equals("UINT32")) {
1540 skuInfo
.setValue("0");
1542 if (dataType
.equals("UINT64")){
1543 skuInfo
.setValue("0");
1545 if (dataType
.equals("BOOLEAN")){
1546 skuInfo
.setValue("false");
1548 if (dataType
.equals("VOID*")) {
1549 skuInfo
.setValue("");
1552 if (dataType
.equals("UINT8")){
1553 dynPcdData
.setMaxDatumSize(1);
1555 if (dataType
.equals("UINT16")) {
1556 dynPcdData
.setMaxDatumSize(2);
1558 if (dataType
.equals("UINT32")) {
1559 dynPcdData
.setMaxDatumSize(4);
1561 if (dataType
.equals("UINT64")){
1562 dynPcdData
.setMaxDatumSize(8);
1564 if (dataType
.equals("BOOLEAN")){
1565 dynPcdData
.setMaxDatumSize(1);
1567 if (dataType
.equals("VOID*")) {
1568 int maxSize
= setMaxSizeForPointer(defaultVal
);
1569 dynPcdData
.setMaxDatumSize(maxSize
);
1573 public void removeDynamicPcdBuildData(String cName
, String tsGuid
) {
1574 XmlObject o
= fpdRoot
.getDynamicPcdBuildDefinitions();
1579 XmlCursor cursor
= o
.newCursor();
1580 if (cursor
.toFirstChild()) {
1582 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdBuildData
=
1583 (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1584 if (pcdBuildData
.getCName().equals(cName
) && pcdBuildData
.getTokenSpaceGuidCName().equals(tsGuid
)) {
1586 if (getDynamicPcdBuildDataCount() == 1) {
1589 fpdDynPcdBuildDefs
= null;
1597 while (cursor
.toNextSibling());
1602 // Get the Sku Info count of ith dyn pcd element.
1604 public int getDynamicPcdSkuInfoCount(int i
){
1605 if (fpdRoot
.getDynamicPcdBuildDefinitions() == null || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1606 || fpdRoot
.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1607 removeElement(getfpdDynPcdBuildDefs());
1608 fpdDynPcdBuildDefs
= null;
1612 int skuInfoCount
= 0;
1613 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1614 if (cursor
.toFirstChild()) {
1615 for (int j
= 0; j
< i
; ++j
) {
1616 cursor
.toNextSibling();
1618 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1619 if (pcdData
.getSkuInfoList() == null) {
1623 skuInfoCount
= pcdData
.getSkuInfoList().size();
1627 return skuInfoCount
;
1630 public void getDynamicPcdSkuInfos(int i
, String
[][] saa
){
1631 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1632 removeElement(getfpdDynPcdBuildDefs());
1633 fpdDynPcdBuildDefs
= null;
1637 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1638 if (cursor
.toFirstChild()) {
1639 for (int j
= 0; j
< i
; ++j
) {
1640 cursor
.toNextSibling();
1642 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1643 if (pcdData
.getSkuInfoList() == null) {
1648 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1650 while (li
.hasNext()) {
1651 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1652 saa
[k
][0] = skuInfo
.getSkuId()+"";
1653 saa
[k
][1] = skuInfo
.getVariableName();
1654 saa
[k
][2] = skuInfo
.getVariableGuid();
1655 saa
[k
][3] = skuInfo
.getVariableOffset();
1656 saa
[k
][4] = skuInfo
.getHiiDefaultValue();
1657 saa
[k
][5] = skuInfo
.getVpdOffset();
1658 saa
[k
][6] = skuInfo
.getValue();
1668 public String
getDynamicPcdBuildDataValue(int i
){
1669 String value
= null;
1670 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1671 removeElement(getfpdDynPcdBuildDefs());
1672 fpdDynPcdBuildDefs
= null;
1676 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1677 if (cursor
.toFirstChild()) {
1678 for (int j
= 0; j
< i
; ++j
) {
1679 cursor
.toNextSibling();
1681 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1682 if (pcdData
.getSkuInfoList() == null) {
1686 value
= pcdData
.getSkuInfoArray(0).getValue();
1693 public String
getDynamicPcdBuildDataVpdOffset(int i
){
1694 String vpdOffset
= null;
1695 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1696 removeElement(getfpdDynPcdBuildDefs());
1697 fpdDynPcdBuildDefs
= null;
1701 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1702 if (cursor
.toFirstChild()) {
1703 for (int j
= 0; j
< i
; ++j
) {
1704 cursor
.toNextSibling();
1706 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1707 if (pcdData
.getSkuInfoList() == null) {
1711 vpdOffset
= pcdData
.getSkuInfoArray(0).getVpdOffset();
1718 public void removeDynamicPcdBuildDataSkuInfo(int i
) {
1719 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1720 removeElement(getfpdDynPcdBuildDefs());
1721 fpdDynPcdBuildDefs
= null;
1725 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1726 if (cursor
.toFirstChild()) {
1727 for (int j
= 0; j
< i
; ++j
) {
1728 cursor
.toNextSibling();
1730 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1731 if (pcdData
.getSkuInfoList() == null) {
1736 pcdData
.getSkuInfoList().clear();
1737 // QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1738 // cursor.toChild(qSkuInfo);
1739 // cursor.removeXml();
1745 // generate sku info for ith dyn pcd build data.
1747 public void genDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1748 String hiiDefault
, String vpdOffset
, String value
, int i
) {
1749 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1753 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1754 if (cursor
.toFirstChild()) {
1755 for (int j
= 0; j
< i
; ++j
) {
1756 cursor
.toNextSibling();
1758 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1759 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= pcdData
.addNewSkuInfo();
1760 skuInfo
.setSkuId(new BigInteger(id
));
1761 if (varName
!= null){
1762 skuInfo
.setVariableName(varName
);
1763 skuInfo
.setVariableGuid(varGuid
);
1764 skuInfo
.setVariableOffset(varOffset
);
1765 skuInfo
.setHiiDefaultValue(hiiDefault
);
1767 else if (vpdOffset
!= null){
1768 skuInfo
.setVpdOffset(vpdOffset
);
1771 skuInfo
.setValue(value
);
1776 public void updateDynamicPcdBuildDataSkuInfo(String id
, String varName
, String varGuid
, String varOffset
,
1777 String hiiDefault
, String vpdOffset
, String value
, int i
){
1778 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1779 removeElement(getfpdDynPcdBuildDefs());
1780 fpdDynPcdBuildDefs
= null;
1784 XmlCursor cursor
= getfpdDynPcdBuildDefs().newCursor();
1785 if (cursor
.toFirstChild()) {
1786 for (int j
= 0; j
< i
; ++j
) {
1787 cursor
.toNextSibling();
1789 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData pcdData
= (DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
)cursor
.getObject();
1790 ListIterator
<DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo
> li
= pcdData
.getSkuInfoList().listIterator();
1791 while (li
.hasNext()) {
1792 DynamicPcdBuildDefinitionsDocument
.DynamicPcdBuildDefinitions
.PcdBuildData
.SkuInfo skuInfo
= li
.next();
1793 if (skuInfo
.getSkuId().toString().equals(id
)){
1794 if (varName
!= null){
1795 skuInfo
.setVariableName(varName
);
1796 skuInfo
.setVariableGuid(varGuid
);
1797 skuInfo
.setVariableOffset(varOffset
);
1798 skuInfo
.setHiiDefaultValue(hiiDefault
);
1800 else if (vpdOffset
!= null){
1801 skuInfo
.setVpdOffset(vpdOffset
);
1804 skuInfo
.setValue(value
);
1812 public BuildOptionsDocument
.BuildOptions
getfpdBuildOpts() {
1813 if (fpdBuildOpts
== null) {
1814 fpdBuildOpts
= fpdRoot
.addNewBuildOptions();
1816 return fpdBuildOpts
;
1819 public void genBuildOptionsUserExtensions(String fvName
, String userId
, String id
, String outputFileName
, Vector
<String
[]> includeModules
) {
1820 QName elementFvName
= new QName (xmlNs
, "FvName");
1821 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1822 QName elementInfFileName
= new QName(xmlNs
, "InfFileName");
1823 QName elementModule
= new QName(xmlNs
, "Module");
1825 UserExtensionsDocument
.UserExtensions userExts
= getfpdBuildOpts().addNewUserExtensions();
1826 userExts
.setUserID(userId
);
1827 userExts
.setIdentifier(new BigInteger(id
));
1828 XmlCursor cursor
= userExts
.newCursor();
1829 cursor
.toEndToken();
1831 cursor
.beginElement(elementFvName
);
1832 cursor
.insertChars(fvName
);
1833 cursor
.toNextToken();
1835 cursor
.beginElement(elementInfFileName
);
1836 cursor
.insertChars(outputFileName
);
1837 cursor
.toNextToken();
1839 cursor
.beginElement(elementIncludeModules
);
1840 for (int i
= 0; i
< includeModules
.size(); ++i
) {
1841 cursor
.beginElement(elementModule
);
1842 cursor
.insertAttributeWithValue("ModuleGuid", includeModules
.get(i
)[0]);
1843 if (!includeModules
.get(i
)[1].equals("null") && includeModules
.get(i
)[1].length() != 0) {
1844 cursor
.insertAttributeWithValue("ModuleVersion", includeModules
.get(i
)[1]);
1846 cursor
.insertAttributeWithValue("PackageGuid", includeModules
.get(i
)[2]);
1847 if (!includeModules
.get(i
)[3].equals("null") && includeModules
.get(i
)[3].length() != 0) {
1848 cursor
.insertAttributeWithValue("PackageVersion", includeModules
.get(i
)[3]);
1851 cursor
.insertAttributeWithValue("Arch", includeModules
.get(i
)[4]);
1852 cursor
.toEndToken();
1853 cursor
.toNextToken();
1858 public int getUserExtsIncModCount (String fvName
, String userId
, int id
) {
1859 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1863 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1864 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1865 while (li
.hasNext()) {
1866 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1867 if (!ues
.getUserID().equals(userId
)) {
1870 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
1873 XmlCursor cursor
= ues
.newCursor();
1874 cursor
.toFirstChild();
1875 String elementName
= cursor
.getTextValue();
1876 if (elementName
.equals(fvName
)) {
1877 cursor
.toNextSibling(elementIncludeModules
);
1878 if (cursor
.toFirstChild()) {
1880 for (i
= 1; cursor
.toNextSibling(); ++i
);
1892 public void getUserExtsIncMods(String fvName
, String userId
, int id
, String
[][] saa
) {
1893 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1897 XmlCursor cursor
= getfpdBuildOpts().newCursor();
1898 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
1899 QName attribUserId
= new QName ("UserID");
1900 QName attribId
= new QName ("Identifier");
1901 QName elementFvName
= new QName (xmlNs
, "FvName");
1902 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
1903 QName attribModuleGuid
= new QName("ModuleGuid");
1904 QName attribModuleVersion
= new QName("ModuleVersion");
1905 QName attribPackageGuid
= new QName("PackageGuid");
1906 QName attribPackageVersion
= new QName("PackageVersion");
1907 QName attribArch
= new QName("Arch");
1909 if (cursor
.toChild(elementUserExts
)) {
1912 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
1913 cursor
.toChild(elementFvName
);
1914 String elementName
= cursor
.getTextValue();
1915 if (elementName
.equals(fvName
)) {
1916 cursor
.toNextSibling(elementIncludeModules
);
1917 if (cursor
.toFirstChild()) {
1920 saa
[i
][0] = cursor
.getAttributeText(attribModuleGuid
);
1921 saa
[i
][1] = cursor
.getAttributeText(attribModuleVersion
);
1922 saa
[i
][2] = cursor
.getAttributeText(attribPackageGuid
);
1923 saa
[i
][3] = cursor
.getAttributeText(attribPackageVersion
);
1924 saa
[i
][4] = cursor
.getAttributeText(attribArch
);
1926 }while (cursor
.toNextSibling());
1932 }while (cursor
.toNextSibling(elementUserExts
));
1938 public void updateBuildOptionsUserExtensions (String oldFvName
, String newFvName
) {
1939 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1942 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1943 while (li
.hasNext()) {
1944 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1945 if (!ues
.getUserID().equals("IMAGES")) {
1948 XmlCursor cursor
= ues
.newCursor();
1949 cursor
.toFirstChild();
1950 String elementName
= cursor
.getTextValue();
1951 if (elementName
.equals(oldFvName
)) {
1952 cursor
.setTextValue(newFvName
);
1959 public void removeBuildOptionsUserExtensions (String fvName
, String userId
, int id
) {
1960 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1964 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
1965 while (li
.hasNext()) {
1966 UserExtensionsDocument
.UserExtensions ues
= li
.next();
1967 if (!ues
.getUserID().equals(userId
)) {
1970 if (ues
.getIdentifier()== null || ues
.getIdentifier().intValue() != id
) {
1973 XmlCursor cursor
= ues
.newCursor();
1974 cursor
.toFirstChild();
1975 String elementName
= cursor
.getTextValue();
1976 if (elementName
.equals(fvName
)) {
1987 private boolean versionEqual (String v1
, String v2
) {
1989 if ((v1
== null || v1
.length() == 0 || v1
.equalsIgnoreCase("null"))
1990 && (v2
== null || v2
.length() == 0 || v2
.equalsIgnoreCase("null"))) {
1994 if (v1
!= null && v1
.equals(v2
)) {
2001 public boolean moduleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2002 boolean inList
= false;
2003 if (getUserExtsIncModCount(fvName
, userId
, id
) > 0) {
2004 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2005 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2006 QName attribUserId
= new QName ("UserID");
2007 QName attribId
= new QName ("Identifier");
2008 QName elementFvName
= new QName (xmlNs
, "FvName");
2009 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2010 QName attribModuleGuid
= new QName("ModuleGuid");
2011 QName attribModuleVersion
= new QName("ModuleVersion");
2012 QName attribPackageGuid
= new QName("PackageGuid");
2013 QName attribPackageVersion
= new QName("PackageVersion");
2014 QName attribArch
= new QName("Arch");
2016 if (cursor
.toChild(elementUserExts
)) {
2019 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2020 cursor
.toChild(elementFvName
);
2021 String elementName
= cursor
.getTextValue();
2022 if (elementName
.equals(fvName
)) {
2023 cursor
.toNextSibling(elementIncludeModules
);
2024 if (cursor
.toFirstChild()) {
2027 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2028 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2029 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2030 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2031 String ar
= cursor
.getAttributeText(attribArch
);
2032 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2035 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2038 if (!arch
.equalsIgnoreCase(ar
)) {
2041 if (!versionEqual(moduleVersion
, mv
)) {
2044 if (!versionEqual(packageVersion
, pv
)) {
2049 }while (cursor
.toNextSibling());
2055 }while (cursor
.toNextSibling(elementUserExts
));
2062 public void removeModuleInBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2064 // if there is only one module before remove operation, the whole user extension should be removed.
2066 int moduleAmount
= getUserExtsIncModCount(fvName
, userId
, id
);
2067 if (moduleAmount
== 1) {
2068 removeBuildOptionsUserExtensions(fvName
, userId
, id
);
2072 if (moduleAmount
> 1) {
2073 XmlCursor cursor
= getfpdBuildOpts().newCursor();
2074 QName elementUserExts
= new QName (xmlNs
, "UserExtensions");
2075 QName attribUserId
= new QName ("UserID");
2076 QName attribId
= new QName ("Identifier");
2077 QName elementFvName
= new QName (xmlNs
, "FvName");
2078 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2079 QName attribModuleGuid
= new QName("ModuleGuid");
2080 QName attribModuleVersion
= new QName("ModuleVersion");
2081 QName attribPackageGuid
= new QName("PackageGuid");
2082 QName attribPackageVersion
= new QName("PackageVersion");
2083 QName attribArch
= new QName("Arch");
2085 if (cursor
.toChild(elementUserExts
)) {
2088 if (cursor
.getAttributeText(attribUserId
).equals(userId
) && cursor
.getAttributeText(attribId
).equals(id
+"")) {
2089 cursor
.toChild(elementFvName
);
2090 String elementName
= cursor
.getTextValue();
2091 if (elementName
.equals(fvName
)) {
2092 cursor
.toNextSibling(elementIncludeModules
);
2093 if (cursor
.toFirstChild()) {
2096 String mg
= cursor
.getAttributeText(attribModuleGuid
);
2097 String mv
= cursor
.getAttributeText(attribModuleVersion
);
2098 String pg
= cursor
.getAttributeText(attribPackageGuid
);
2099 String pv
= cursor
.getAttributeText(attribPackageVersion
);
2100 String ar
= cursor
.getAttributeText(attribArch
);
2101 if (!moduleGuid
.equalsIgnoreCase(mg
)) {
2104 if (!packageGuid
.equalsIgnoreCase(pg
)) {
2107 if (!arch
.equalsIgnoreCase(ar
)) {
2110 if (!versionEqual(moduleVersion
, mv
)) {
2113 if (!versionEqual(packageVersion
, pv
)) {
2117 }while (cursor
.toNextSibling());
2123 }while (cursor
.toNextSibling(elementUserExts
));
2129 public void addModuleIntoBuildOptionsUserExtensions (String fvName
, String userId
, int id
, String moduleGuid
, String moduleVersion
, String packageGuid
, String packageVersion
, String arch
) {
2130 if (moduleInBuildOptionsUserExtensions (fvName
, userId
, id
, moduleGuid
, moduleVersion
, packageGuid
, packageVersion
, arch
)) {
2134 ListIterator
<UserExtensionsDocument
.UserExtensions
> li
= getfpdBuildOpts().getUserExtensionsList().listIterator();
2135 QName elementIncludeModules
= new QName(xmlNs
, "IncludeModules");
2136 QName elementModule
= new QName(xmlNs
, "Module");
2137 while (li
.hasNext()) {
2138 UserExtensionsDocument
.UserExtensions ues
= li
.next();
2139 if (!ues
.getUserID().equals(userId
)) {
2142 if (ues
.getIdentifier() == null || ues
.getIdentifier().intValue() != id
) {
2145 XmlCursor cursor
= ues
.newCursor();
2146 cursor
.toFirstChild();
2147 String elementName
= cursor
.getTextValue();
2148 if (elementName
.equals(fvName
)) {
2149 cursor
.toNextSibling(elementIncludeModules
);
2150 cursor
.toLastChild();
2151 cursor
.toEndToken();
2152 cursor
.toNextToken();
2153 cursor
.beginElement(elementModule
);
2154 cursor
.insertAttributeWithValue("ModuleGuid", moduleGuid
);
2155 if (!moduleVersion
.equals("null") && moduleVersion
.length() != 0) {
2156 cursor
.insertAttributeWithValue("ModuleVersion", moduleVersion
);
2158 cursor
.insertAttributeWithValue("PackageGuid", packageGuid
);
2159 if (!packageVersion
.equals("null") && packageVersion
.length() != 0) {
2160 cursor
.insertAttributeWithValue("PackageVersion", packageVersion
);
2163 cursor
.insertAttributeWithValue("Arch", arch
);
2172 public void genBuildOptionsUserDefAntTask (String id
, String fileName
, String execOrder
) {
2173 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2174 if (udats
== null) {
2175 udats
= getfpdBuildOpts().addNewUserDefinedAntTasks();
2178 AntTaskDocument
.AntTask at
= udats
.addNewAntTask();
2179 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2182 private void setBuildOptionsUserDefAntTask(String id
, String fileName
, String execOrder
, AntTaskDocument
.AntTask at
) {
2183 at
.setId(new Integer(id
));
2184 XmlCursor cursor
= at
.newCursor();
2185 if (fileName
!= null){
2186 at
.setFilename(fileName
);
2188 else if (cursor
.toChild(xmlNs
, "Filename")) {
2191 if (execOrder
!= null) {
2192 at
.setAntCmdOptions(execOrder
);
2194 else if (cursor
.toChild(xmlNs
, "AntCmdOptions")) {
2200 public void removeBuildOptionsUserDefAntTask(int i
) {
2201 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2205 XmlCursor cursor
= o
.newCursor();
2206 if (cursor
.toFirstChild()) {
2207 for (int j
= 0; j
< i
; ++j
) {
2208 cursor
.toNextSibling();
2211 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2219 public void updateBuildOptionsUserDefAntTask(int i
, String id
, String fileName
, String execOrder
){
2220 XmlObject o
= getfpdBuildOpts().getUserDefinedAntTasks();
2224 XmlCursor cursor
= o
.newCursor();
2225 if (cursor
.toFirstChild()) {
2226 for (int j
= 0; j
< i
; ++j
) {
2227 cursor
.toNextSibling();
2229 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)cursor
.getObject();
2230 setBuildOptionsUserDefAntTask(id
, fileName
, execOrder
, at
);
2235 public int getBuildOptionsUserDefAntTaskCount() {
2236 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2237 if (udats
== null || udats
.getAntTaskList() == null) {
2241 return udats
.getAntTaskList().size();
2244 public void getBuildOptionsUserDefAntTasks(String
[][] saa
) {
2245 UserDefinedAntTasksDocument
.UserDefinedAntTasks udats
= getfpdBuildOpts().getUserDefinedAntTasks();
2246 if (udats
== null || udats
.getAntTaskList() == null) {
2250 List
<AntTaskDocument
.AntTask
> l
= udats
.getAntTaskList();
2251 ListIterator li
= l
.listIterator();
2253 while (li
.hasNext()) {
2254 AntTaskDocument
.AntTask at
= (AntTaskDocument
.AntTask
)li
.next();
2255 saa
[i
][0] = at
.getId() + "";
2256 saa
[i
][1] = saa
[i
][2] = "";
2257 if (at
.getFilename() != null){
2258 saa
[i
][1] = at
.getFilename();
2260 if (at
.getAntCmdOptions() != null) {
2261 saa
[i
][2] = at
.getAntCmdOptions();
2266 public void genBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2267 OptionsDocument
.Options opts
= getfpdBuildOpts().getOptions();
2269 opts
= getfpdBuildOpts().addNewOptions();
2271 OptionDocument
.Option opt
= opts
.addNewOption();
2272 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2275 private void setBuildOptionsOpt(Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
, OptionDocument
.Option opt
){
2276 opt
.setStringValue(contents
);
2277 if (buildTargets
!= null) {
2278 opt
.setBuildTargets(buildTargets
);
2281 if (opt
.isSetBuildTargets()) {
2282 opt
.unsetBuildTargets();
2286 if (toolChain
!= null && toolChain
.length() > 0) {
2287 opt
.setToolChainFamily(toolChain
);
2290 if (opt
.isSetToolChainFamily()) {
2291 opt
.unsetToolChainFamily();
2295 if (tagName
!= null && tagName
.length() > 0) {
2296 opt
.setTagName(tagName
);
2299 if (opt
.isSetTagName()) {
2304 if (toolCmd
!= null && toolCmd
.length() > 0) {
2305 opt
.setToolCode(toolCmd
);
2308 if (opt
.isSetToolCode()) {
2309 opt
.unsetToolCode();
2314 if (archList
!= null) {
2315 opt
.setSupArchList(archList
);
2318 if (opt
.isSetSupArchList()) {
2319 opt
.unsetSupArchList();
2324 public void removeBuildOptionsOpt(int i
){
2326 XmlObject o
= getfpdBuildOpts().getOptions();
2331 XmlCursor cursor
= o
.newCursor();
2332 if (cursor
.toFirstChild()) {
2333 for (int j
= 0; j
< i
; ++j
) {
2334 cursor
.toNextSibling();
2337 if (getBuildOptionsOptCount() == 0) {
2345 public void updateBuildOptionsOpt(int i
, Vector
<Object
> buildTargets
, String toolChain
, String tagName
, String toolCmd
, Vector
<Object
> archList
, String contents
) {
2346 XmlObject o
= getfpdBuildOpts().getOptions();
2351 XmlCursor cursor
= o
.newCursor();
2352 if (cursor
.toFirstChild()) {
2353 for (int j
= 0; j
< i
; ++j
) {
2354 cursor
.toNextSibling();
2356 OptionDocument
.Option opt
= (OptionDocument
.Option
)cursor
.getObject();
2357 setBuildOptionsOpt(buildTargets
, toolChain
, tagName
, toolCmd
, archList
, contents
, opt
);
2362 public int getBuildOptionsOptCount(){
2363 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2366 return getfpdBuildOpts().getOptions().getOptionList().size();
2369 public void getBuildOptionsOpts(String
[][] saa
) {
2370 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2374 List
<OptionDocument
.Option
> lOpt
= getfpdBuildOpts().getOptions().getOptionList();
2375 ListIterator li
= lOpt
.listIterator();
2377 while(li
.hasNext()) {
2378 OptionDocument
.Option opt
= (OptionDocument
.Option
)li
.next();
2379 if (opt
.getBuildTargets() != null) {
2380 saa
[i
][0] = listToString(opt
.getBuildTargets());
2382 saa
[i
][1] = opt
.getToolChainFamily();
2383 if (opt
.getSupArchList() != null){
2384 saa
[i
][2] = listToString(opt
.getSupArchList());
2387 saa
[i
][3] = opt
.getToolCode();
2388 saa
[i
][4] = opt
.getTagName();
2389 saa
[i
][5] = opt
.getStringValue();
2395 public void genBuildOptionsFfs(String ffsKey
, String type
) {
2396 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getfpdBuildOpts().addNewFfs();
2397 ffs
.setFfsKey(ffsKey
);
2399 ffs
.addNewSections().setEncapsulationType(type
);
2403 public void updateBuildOptionsFfsSectionsType(int i
, String type
) {
2404 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2405 ffs
.getSections().setEncapsulationType(type
);
2408 public void genBuildOptionsFfsAttribute(int i
, String name
, String value
) {
2409 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2410 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= ffs
.addNewAttribute();
2411 attrib
.setName(name
);
2412 attrib
.setValue(value
);
2415 /**update jth attribute of ith ffs.
2419 public void updateBuildOptionsFfsAttribute(int i
, int j
, String name
, String value
){
2420 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2421 XmlCursor cursor
= ffs
.newCursor();
2422 QName qAttrib
= new QName(xmlNs
, "Attribute");
2423 if (cursor
.toChild(qAttrib
)) {
2424 for (int k
= 0; k
< j
; ++k
) {
2425 cursor
.toNextSibling(qAttrib
);
2427 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
)cursor
.getObject();
2428 attrib
.setName(name
);
2429 attrib
.setValue(value
);
2434 public void removeBuildOptionsFfsAttribute(int i
, int j
){
2435 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2436 XmlCursor cursor
= ffs
.newCursor();
2437 QName qAttrib
= new QName(xmlNs
, "Attribute");
2438 if (cursor
.toChild(qAttrib
)) {
2439 for (int k
= 0; k
< j
; ++k
) {
2440 cursor
.toNextSibling(qAttrib
);
2447 public void genBuildOptionsFfsSectionsSection(int i
, String sectionType
) {
2448 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2452 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2454 if (sections
== null){
2455 sections
= ffs
.addNewSections();
2457 sections
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(sectionType
));
2460 public void removeBuildOptionsFfsSectionsSection(int i
, int j
) {
2461 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2462 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2463 if (sections
== null) {
2466 XmlCursor cursor
= sections
.newCursor();
2467 QName qSection
= new QName(xmlNs
, "Section");
2468 if (cursor
.toChild(qSection
)) {
2469 for (int k
= 0; k
< j
; ++k
) {
2470 cursor
.toNextSibling(qSection
);
2477 public void updateBuildOptionsFfsSectionsSection(int i
, int j
, String type
){
2478 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2479 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2480 if (sections
== null) {
2483 XmlCursor cursor
= sections
.newCursor();
2484 QName qSection
= new QName(xmlNs
, "Section");
2485 if (cursor
.toChild(qSection
)) {
2486 for (int k
= 0; k
< j
; ++k
) {
2487 cursor
.toNextSibling(qSection
);
2489 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
)cursor
.getObject();
2490 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2495 public void genBuildOptionsFfsSectionsSections(int i
, String encapType
) {
2496 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2500 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2502 if (sections
== null){
2503 sections
= ffs
.addNewSections();
2505 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= sections
.addNewSections();
2506 sections2
.setEncapsulationType(encapType
);
2507 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString("EFI_SECTION_PE32"));
2510 public void removeBuildOptionsFfsSectionsSections(int i
, int j
) {
2511 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2512 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2513 if (sections
== null) {
2516 XmlCursor cursor
= sections
.newCursor();
2517 QName qSections
= new QName(xmlNs
, "Sections");
2518 if (cursor
.toChild(qSections
)) {
2519 for (int k
= 0; k
< j
; ++k
) {
2520 cursor
.toNextSibling(qSections
);
2527 public void updateBuildOptionsFfsSectionsSections(int i
, int j
, String type
) {
2528 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2529 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2530 if (sections
== null) {
2533 XmlCursor cursor
= sections
.newCursor();
2534 QName qSections
= new QName(xmlNs
, "Sections");
2535 if (cursor
.toChild(qSections
)) {
2536 for (int k
= 0; k
< j
; ++k
) {
2537 cursor
.toNextSibling(qSections
);
2539 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2540 sections2
.setEncapsulationType(type
);
2545 public void genBuildOptionsFfsSectionsSectionsSection(int i
, int j
, String type
) {
2546 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2550 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2551 XmlCursor cursor
= sections
.newCursor();
2552 QName qSections
= new QName(xmlNs
, "Sections");
2553 if (cursor
.toChild(qSections
)){
2554 for (int k
= 0; k
< j
; ++k
) {
2555 cursor
.toNextSibling(qSections
);
2557 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2558 sections2
.addNewSection().setSectionType(EfiSectionType
.Enum
.forString(type
));
2563 public void removeBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
) {
2564 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2565 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2566 if (sections
== null) {
2569 XmlCursor cursor
= sections
.newCursor();
2570 QName qSections
= new QName(xmlNs
, "Sections");
2571 if (cursor
.toChild(qSections
)) {
2572 for (int l
= 0; l
< j
; ++l
) {
2573 cursor
.toNextSibling(qSections
);
2575 if (cursor
.toFirstChild()) {
2577 for (; m
< k
; ++m
) {
2578 cursor
.toNextSibling();
2590 public void updateBuildOptionsFfsSectionsSectionsSection(int i
, int j
, int k
, String type
) {
2591 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2592 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2593 if (sections
== null) {
2596 XmlCursor cursor
= sections
.newCursor();
2597 QName qSections
= new QName(xmlNs
, "Sections");
2598 if (cursor
.toChild(qSections
)) {
2599 for (int l
= 0; l
< j
; ++l
) {
2600 cursor
.toNextSibling(qSections
);
2602 if (cursor
.toFirstChild()) {
2603 for (int m
= 0; m
< k
; ++m
) {
2604 cursor
.toNextSibling();
2606 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
)cursor
.getObject();
2607 section
.setSectionType(EfiSectionType
.Enum
.forString(type
));
2613 public void getBuildOptionsFfsSectionsSectionsSection(int i
, int j
, ArrayList
<String
> al
) {
2614 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2618 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections sections
= ffs
.getSections();
2619 XmlCursor cursor
= sections
.newCursor();
2620 QName qSections
= new QName(xmlNs
, "Sections");
2621 if (cursor
.toChild(qSections
)){
2622 for (int k
= 0; k
< j
; ++k
) {
2623 cursor
.toNextSibling(qSections
);
2625 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2 sections2
= (BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
)cursor
.getObject();
2626 if (sections2
.getSectionList() == null){
2630 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section
> li
= sections2
.getSectionList().listIterator();
2631 while(li
.hasNext()) {
2632 BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
.Section section
= li
.next();
2633 // if (section.isSetSectionType()) {
2634 al
.add(section
.getSectionType()+"");
2643 public int getBuildOptionsFfsCount(){
2644 if (getfpdBuildOpts().getFfsList() == null) {
2647 return getfpdBuildOpts().getFfsList().size();
2650 public void getBuildOptionsFfsKey(String
[][] saa
) {
2651 if (getfpdBuildOpts().getFfsList() == null) {
2654 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
> li
= getfpdBuildOpts().getFfsList().listIterator();
2656 while(li
.hasNext()){
2657 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= li
.next();
2658 saa
[i
][0] = ffs
.getFfsKey();
2663 public void updateBuildOptionsFfsKey(int i
, String key
) {
2664 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2668 /**Get ith FFS key and contents.
2671 public void getBuildOptionsFfs(int i
, String
[] sa
, LinkedHashMap
<String
, String
> ffsAttribMap
, ArrayList
<String
> firstLevelSections
, ArrayList
<String
> firstLevelSection
) {
2672 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2676 sa
[0] = ffs
.getFfsKey();
2677 if (ffs
.getSections() != null) {
2678 if(ffs
.getSections().getEncapsulationType() != null){
2679 sa
[1] = ffs
.getSections().getEncapsulationType();
2681 if (ffs
.getSections().getSectionList() != null){
2682 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Section
> li
= ffs
.getSections().getSectionList().listIterator();
2683 while (li
.hasNext()) {
2684 firstLevelSection
.add(li
.next().getSectionType()+"");
2687 if (ffs
.getSections().getSectionsList() != null) {
2688 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Sections
.Sections2
> li
= ffs
.getSections().getSectionsList().listIterator();
2689 while(li
.hasNext()) {
2690 firstLevelSections
.add(li
.next().getEncapsulationType());
2694 if (ffs
.getAttributeList() != null) {
2695 ListIterator
<BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute
> li
= ffs
.getAttributeList().listIterator();
2696 while(li
.hasNext()) {
2697 BuildOptionsDocument
.BuildOptions
.Ffs
.Attribute attrib
= li
.next();
2698 ffsAttribMap
.put(attrib
.getName(), attrib
.getValue());
2707 private BuildOptionsDocument
.BuildOptions
.Ffs
getFfs(int i
) {
2708 XmlObject o
= getfpdBuildOpts();
2709 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= null;
2711 XmlCursor cursor
= o
.newCursor();
2712 QName qFfs
= new QName(xmlNs
, "Ffs");
2713 if (cursor
.toChild(qFfs
)) {
2714 for (int j
= 0; j
< i
; ++j
) {
2715 cursor
.toNextSibling(qFfs
);
2717 ffs
= (BuildOptionsDocument
.BuildOptions
.Ffs
)cursor
.getObject();
2723 public void removeBuildOptionsFfs(int i
) {
2724 BuildOptionsDocument
.BuildOptions
.Ffs ffs
= getFfs(i
);
2729 XmlCursor cursor
= ffs
.newCursor();
2736 public PlatformDefinitionsDocument
.PlatformDefinitions
getfpdPlatformDefs(){
2737 if (fpdPlatformDefs
== null){
2738 fpdPlatformDefs
= fpdRoot
.addNewPlatformDefinitions();
2740 return fpdPlatformDefs
;
2743 public void getPlatformDefsSupportedArchs(Vector
<Object
> archs
){
2744 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2747 ListIterator li
= getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2748 while(li
.hasNext()) {
2749 archs
.add(li
.next());
2753 public void setPlatformDefsSupportedArchs(Vector
<Object
> archs
) {
2754 if (archs
!= null) {
2755 getfpdPlatformDefs().setSupportedArchitectures(archs
);
2758 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2759 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2760 // cursor.removeXml();
2762 // cursor.dispose();
2766 public void getPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2767 if (getfpdPlatformDefs().getBuildTargets() == null) {
2770 ListIterator li
= getfpdPlatformDefs().getBuildTargets().listIterator();
2771 while(li
.hasNext()) {
2772 targets
.add(li
.next());
2776 public void setPlatformDefsBuildTargets(Vector
<Object
> targets
) {
2777 getfpdPlatformDefs().setBuildTargets(targets
);
2780 public void genPlatformDefsSkuInfo(String id
, String name
) {
2781 SkuInfoDocument
.SkuInfo skuInfo
= null;
2782 if (getfpdPlatformDefs().getSkuInfo() == null) {
2783 skuInfo
= getfpdPlatformDefs().addNewSkuInfo();
2785 skuInfo
= getfpdPlatformDefs().getSkuInfo();
2786 if (skuInfo
.getUiSkuNameList() == null || skuInfo
.getUiSkuNameList().size() == 0) {
2787 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2788 skuName
.setSkuID(new BigInteger("0"));
2789 skuName
.setStringValue("DEFAULT");
2791 if (id
.equals("0")) {
2794 SkuInfoDocument
.SkuInfo
.UiSkuName skuName
= skuInfo
.addNewUiSkuName();
2795 skuName
.setSkuID(new BigInteger(id
));
2796 skuName
.setStringValue(name
);
2799 public int getPlatformDefsSkuInfoCount(){
2800 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2803 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2806 public void getPlatformDefsSkuInfos(String
[][] saa
){
2807 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2808 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2809 removeElement(getfpdDynPcdBuildDefs());
2810 fpdDynPcdBuildDefs
= null;
2815 List
<SkuInfoDocument
.SkuInfo
.UiSkuName
> l
= getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2816 ListIterator
<SkuInfoDocument
.SkuInfo
.UiSkuName
> li
= l
.listIterator();
2818 while(li
.hasNext()) {
2819 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= li
.next();
2820 saa
[i
][0] = sku
.getSkuID()+"";
2821 saa
[i
][1] = sku
.getStringValue();
2826 public void removePlatformDefsSkuInfo(int i
) {
2827 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2828 if (skuInfo
== null || i
== 0) {
2832 XmlCursor cursor
= skuInfo
.newCursor();
2833 if (cursor
.toFirstChild()) {
2834 for (int j
= 0; j
< i
; ++j
) {
2835 cursor
.toNextSibling();
2842 public void updatePlatformDefsSkuInfo(int i
, String id
, String name
) {
2843 SkuInfoDocument
.SkuInfo skuInfo
= getfpdPlatformDefs().getSkuInfo();
2844 if (skuInfo
== null || i
== 0) {
2848 XmlCursor cursor
= skuInfo
.newCursor();
2849 if (cursor
.toFirstChild()) {
2850 for (int j
= 0; j
< i
; ++j
) {
2851 cursor
.toNextSibling();
2853 SkuInfoDocument
.SkuInfo
.UiSkuName sku
= (SkuInfoDocument
.SkuInfo
.UiSkuName
)cursor
.getObject();
2854 sku
.setSkuID(new BigInteger(id
));
2855 sku
.setStringValue(name
);
2860 public String
getPlatformDefsInterDir(){
2861 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2864 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2867 public void setPlatformDefsInterDir(String interDir
){
2868 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType
.Enum
.forString(interDir
));
2871 public String
getPlatformDefsOutputDir() {
2872 return getfpdPlatformDefs().getOutputDirectory();
2875 public void setPlatformDefsOutputDir(String outputDir
) {
2876 if (outputDir
!= null && outputDir
.length() > 0) {
2877 getfpdPlatformDefs().setOutputDirectory(outputDir
);
2880 XmlCursor cursor
= getfpdPlatformDefs().newCursor();
2881 if (cursor
.toChild(new QName(xmlNs
, "OutputDirectory"))) {
2888 public FlashDocument
.Flash
getfpdFlash() {
2889 if (fpdFlash
== null) {
2890 fpdFlash
= fpdRoot
.addNewFlash();
2895 public void genFlashDefinitionFile(String file
) {
2896 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2898 fdf
= getfpdFlash().addNewFlashDefinitionFile();
2901 fdf
.setStringValue(file
);
2904 public String
getFlashDefinitionFile() {
2905 FlashDefinitionFileDocument
.FlashDefinitionFile fdf
= getfpdFlash().getFlashDefinitionFile();
2910 return fdf
.getStringValue();
2913 public void genFvImagesNameValue(String name
, String value
) {
2915 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2917 fi
= getfpdFlash().addNewFvImages();
2920 FvImagesDocument
.FvImages
.NameValue nv
= fi
.addNewNameValue();
2925 public void removeFvImagesNameValue(int i
){
2927 XmlObject o
= getfpdFlash().getFvImages();
2932 QName qNameValue
= new QName(xmlNs
, "NameValue");
2933 XmlCursor cursor
= o
.newCursor();
2934 if (cursor
.toChild(qNameValue
)) {
2935 for (int j
= 0; j
< i
; ++j
) {
2936 cursor
.toNextSibling(qNameValue
);
2943 public void updateFvImagesNameValue(int i
, String name
, String value
){
2945 XmlObject o
= getfpdFlash().getFvImages();
2950 QName qNameValue
= new QName(xmlNs
, "NameValue");
2951 XmlCursor cursor
= o
.newCursor();
2952 if (cursor
.toChild(qNameValue
)) {
2953 for (int j
= 0; j
< i
; ++j
) {
2954 cursor
.toNextSibling(qNameValue
);
2956 FvImagesDocument
.FvImages
.NameValue nv
= (FvImagesDocument
.FvImages
.NameValue
)cursor
.getObject();
2963 public int getFvImagesNameValueCount() {
2965 FvImagesDocument
.FvImages fi
= null;
2966 if ((fi
= getfpdFlash().getFvImages()) == null || fi
.getNameValueList() == null) {
2969 return fi
.getNameValueList().size();
2972 public void getFvImagesNameValues(String
[][] nv
) {
2974 FvImagesDocument
.FvImages fi
= getfpdFlash().getFvImages();
2978 List
<FvImagesDocument
.FvImages
.NameValue
> l
= fi
.getNameValueList();
2980 ListIterator li
= l
.listIterator();
2981 while (li
.hasNext()) {
2982 FvImagesDocument
.FvImages
.NameValue e
= (FvImagesDocument
.FvImages
.NameValue
) li
2984 nv
[i
][0] = e
.getName();
2985 nv
[i
][1] = e
.getValue();
2991 public void getFvImagesFvImageFvImageNames (Vector
<String
> vImageNames
) {
2992 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
2993 if (fis
== null || fis
.getFvImageList() == null) {
2997 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
2998 while (li
.hasNext()) {
2999 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3000 if (fi
.getType().toString().equals("ImageName")) {
3001 vImageNames
.addAll(fi
.getFvImageNamesList());
3007 public void addFvImageFvImageNames (String
[] fvNames
) {
3008 FvImagesDocument
.FvImages fis
= getfpdFlash().getFvImages();
3009 if (fis
== null || fis
.getFvImageList() == null) {
3010 genFvImagesFvImage (fvNames
, "ImageName", null);
3014 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= fis
.getFvImageList().listIterator();
3015 while (li
.hasNext()) {
3016 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3017 if (fi
.getType().toString().equals("ImageName")) {
3018 addFvImageNamesInFvImage (fi
, fvNames
);
3022 genFvImagesFvImage (fvNames
, "ImageName", null);
3025 public void addFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String
[] fvNames
) {
3027 for (int i
= 0; i
< fvNames
.length
; ++i
) {
3028 fi
.addFvImageNames(fvNames
[i
]);
3032 public void addFvImageNamesInFvImage (int i
, String
[] fvNames
) {
3033 XmlObject o
= getfpdFlash().getFvImages();
3037 XmlCursor cursor
= o
.newCursor();
3038 QName qFvImage
= new QName(xmlNs
, "FvImage");
3039 if (cursor
.toChild(qFvImage
)) {
3040 for (int j
= 0; j
< i
; ++j
) {
3041 cursor
.toNextSibling(qFvImage
);
3043 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3044 addFvImageNamesInFvImage(fi
, fvNames
);
3049 public void genFvImagesFvImage(String
[] names
, String types
, Map
<String
, String
> options
) {
3051 FvImagesDocument
.FvImages fis
= null;
3052 if ((fis
= getfpdFlash().getFvImages()) == null) {
3053 fis
= getfpdFlash().addNewFvImages();
3057 //gen FvImage with FvImageNames array
3059 FvImagesDocument
.FvImages
.FvImage fi
= fis
.addNewFvImage();
3060 for (int i
= 0; i
< names
.length
; ++i
) {
3061 fi
.addFvImageNames(names
[i
]);
3063 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3064 if (options
!= null){
3065 setFvImagesFvImageFvImageOptions(options
, fi
);
3069 private void setFvImagesFvImageFvImageOptions(Map
<String
, String
> options
, FvImagesDocument
.FvImages
.FvImage fi
){
3070 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions fio
= fi
.getFvImageOptions();
3072 fio
= fi
.addNewFvImageOptions();
3075 Set
<String
> key
= options
.keySet();
3076 Iterator
<String
> i
= key
.iterator();
3077 while (i
.hasNext()) {
3079 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fio
.addNewNameValue();
3080 String k
= (String
)i
.next();
3083 nv
.setValue((String
)options
.get(k
));
3090 public void removeFvImagesFvImage(int i
) {
3092 XmlObject o
= getfpdFlash().getFvImages();
3097 QName qFvImage
= new QName(xmlNs
, "FvImage");
3098 XmlCursor cursor
= o
.newCursor();
3099 if (cursor
.toChild(qFvImage
)) {
3100 for (int j
= 0; j
< i
; ++j
) {
3101 cursor
.toNextSibling(qFvImage
);
3110 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3112 public void updateFvImageNameAll (String oldFvName
, String newFvName
) {
3113 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3116 ListIterator
<FvImagesDocument
.FvImages
.FvImage
> li
= getfpdFlash().getFvImages().getFvImageList().listIterator();
3117 while (li
.hasNext()) {
3118 FvImagesDocument
.FvImages
.FvImage fi
= li
.next();
3119 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3120 if (fi
.getFvImageNamesList().size() == 0) {
3126 public void updateFvImageNamesInFvImage (int i
, String oldFvName
, String newFvName
) {
3127 XmlObject o
= getfpdFlash().getFvImages();
3131 XmlCursor cursor
= o
.newCursor();
3132 QName qFvImage
= new QName(xmlNs
, "FvImage");
3133 if (cursor
.toChild(qFvImage
)) {
3134 for (int j
= 0; j
< i
; ++j
) {
3135 cursor
.toNextSibling(qFvImage
);
3137 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3138 updateFvImageNamesInFvImage (fi
, oldFvName
, newFvName
);
3144 * @param oldFvName The FV Name to be replaced.
3145 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3147 public void updateFvImageNamesInFvImage (FvImagesDocument
.FvImages
.FvImage fi
, String oldFvName
, String newFvName
) {
3148 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3149 XmlCursor cursor
= fi
.newCursor();
3151 if (cursor
.toChild(qFvImageNames
)) {
3153 String xmlValue
= cursor
.getTextValue();
3154 if (xmlValue
.equals(oldFvName
)){
3155 if (newFvName
!= null) {
3156 cursor
.setTextValue(newFvName
);
3162 }while (cursor
.toNextSibling(qFvImageNames
));
3168 /**update the Type attribute of ith FvImage with new type.
3172 public void updateFvImagesFvImageType (int i
, String type
) {
3173 XmlObject o
= getfpdFlash().getFvImages();
3177 XmlCursor cursor
= o
.newCursor();
3178 QName qFvImage
= new QName(xmlNs
, "FvImage");
3179 if (cursor
.toChild(qFvImage
)) {
3180 for (int j
= 0; j
< i
; ++j
) {
3181 cursor
.toNextSibling(qFvImage
);
3183 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3184 fi
.setType(FvImageTypes
.Enum
.forString(type
));
3189 public void updateFvImagesFvImage(int i
, String
[] names
, String types
, Map
<String
, String
> options
){
3191 XmlObject o
= getfpdFlash().getFvImages();
3195 XmlCursor cursor
= o
.newCursor();
3196 QName qFvImage
= new QName(xmlNs
, "FvImage");
3197 if (cursor
.toChild(qFvImage
)) {
3198 for (int j
= 0; j
< i
; ++j
) {
3199 cursor
.toNextSibling(qFvImage
);
3201 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3202 fi
.setType(FvImageTypes
.Enum
.forString(types
));
3205 // remove old FvImageNames before adding new ones
3207 QName qFvImageNames
= new QName(xmlNs
, "FvImageNames");
3208 cursor
.toChild(qFvImageNames
);
3210 while (cursor
.toNextSibling(qFvImageNames
)) {
3214 for (int k
= 0; k
< names
.length
; ++k
) {
3215 fi
.addFvImageNames(names
[k
]);
3218 // remove old FvImageOptions before adding new options
3220 QName qFvImageOptions
= new QName(xmlNs
, "FvImageOptions");
3221 cursor
.toNextSibling(qFvImageOptions
);
3224 setFvImagesFvImageFvImageOptions(options
, fi
);
3229 public int getFvImagesFvImageCount(String type
) {
3231 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3234 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3235 ListIterator li
= l
.listIterator();
3237 while(li
.hasNext()) {
3238 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3239 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3249 public Vector
<FvImagesDocument
.FvImages
.FvImage
> getFvImagesFvImageWithName (String fvName
, String type
) {
3250 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= new Vector
<FvImagesDocument
.FvImages
.FvImage
>();
3251 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3254 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3255 ListIterator li
= l
.listIterator();
3256 while(li
.hasNext()) {
3257 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3258 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3261 if (fi
.getFvImageNamesList().contains(fvName
)) {
3270 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3272 public void getFvImagesFvImages(String
[][] saa
, String type
) {
3274 if (getfpdFlash().getFvImages() == null) {
3277 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3281 ListIterator li
= l
.listIterator();
3283 while(li
.hasNext()) {
3284 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3285 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3289 // get FvImageNames array, space separated
3291 List
<String
> lfn
= fi
.getFvImageNamesList();
3292 ListIterator lfni
= lfn
.listIterator();
3294 while (lfni
.hasNext()) {
3295 saa
[i
][0] += (String
)lfni
.next();
3298 saa
[i
][0] = saa
[i
][0].trim();
3300 saa
[i
][1] = fi
.getType()+"";
3306 public void removeFvImageNameValue (int i
, String attributeName
) {
3307 XmlObject o
= getfpdFlash().getFvImages();
3311 XmlCursor cursor
= o
.newCursor();
3312 QName qFvImage
= new QName(xmlNs
, "FvImage");
3313 if (cursor
.toChild(qFvImage
)) {
3314 for (int j
= 0; j
< i
; ++j
) {
3315 cursor
.toNextSibling(qFvImage
);
3317 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3318 removeFvImageNameValue (fi
, attributeName
);
3322 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3324 * @param attributeName
3326 public void removeFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String attributeName
) {
3327 if (fi
.getFvImageOptions() != null && fi
.getFvImageOptions().getNameValueList() != null) {
3328 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3329 while (li
.hasNext()) {
3330 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3331 if (nv
.getName().equals(attributeName
)) {
3338 public void removeTypedNamedFvImageNameValue (String fvName
, String type
, String optName
) {
3339 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName(fvName
, type
);
3340 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3341 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3342 removeFvImageNameValue (fi
, optName
);
3346 /**Add name-value pair to FvImage element with type.
3347 * @param fvName FV name to add name-value pair.
3348 * @param type FvImage attribute.
3352 public void setTypedNamedFvImageNameValue (String fvName
, String type
, String name
, String value
, String newName
) {
3353 boolean fvImageExists
= false;
3354 if (getfpdFlash().getFvImages() != null) {
3356 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3358 ListIterator li
= l
.listIterator();
3359 while (li
.hasNext()) {
3360 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
) li
.next();
3361 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3364 if (!fi
.getFvImageNamesList().contains(fvName
)) {
3367 fvImageExists
= true;
3368 setFvImagesFvImageNameValue(fi
, name
, value
, newName
);
3373 if (!fvImageExists
) {
3374 HashMap
<String
, String
> map
= new HashMap
<String
, String
>();
3375 map
.put(name
, value
);
3376 genFvImagesFvImage(new String
[] { fvName
}, type
, map
);
3380 /**Add to all FvImage elements with type, the name-value pair.
3385 public void setTypedFvImageNameValue (String type
, String name
, String value
) {
3386 if (getfpdFlash().getFvImages() == null) {
3389 List
<FvImagesDocument
.FvImages
.FvImage
> l
= getfpdFlash().getFvImages().getFvImageList();
3393 ListIterator li
= l
.listIterator();
3394 while(li
.hasNext()) {
3395 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)li
.next();
3396 if (!fi
.getType().toString().equals(type
) && !type
.equals("ALL")) {
3399 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3404 public void setFvImagesFvImageNameValue (int i
, String name
, String value
) {
3405 XmlObject o
= getfpdFlash().getFvImages();
3409 XmlCursor cursor
= o
.newCursor();
3410 QName qFvImage
= new QName(xmlNs
, "FvImage");
3411 if (cursor
.toChild(qFvImage
)) {
3412 for (int j
= 0; j
< i
; ++j
) {
3413 cursor
.toNextSibling(qFvImage
);
3415 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3416 setFvImagesFvImageNameValue (fi
, name
, value
, null);
3421 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3427 public void setFvImagesFvImageNameValue (FvImagesDocument
.FvImages
.FvImage fi
, String name
, String value
, String newName
) {
3428 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3429 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.addNewFvImageOptions().addNewNameValue();
3432 if (newName
!= null && !newName
.equals(name
)) {
3433 nv
.setName(newName
);
3438 XmlCursor cursor
= fi
.getFvImageOptions().newCursor();
3439 if (cursor
.toFirstChild()) {
3441 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
)cursor
.getObject();
3442 if (nv
.getName().equals(name
)) {
3444 if (newName
!= null && !newName
.equals(name
)) {
3445 nv
.setName(newName
);
3450 }while (cursor
.toNextSibling());
3453 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= fi
.getFvImageOptions().addNewNameValue();
3456 if (newName
!= null && !newName
.equals(name
)) {
3457 nv
.setName(newName
);
3462 public void getFvImagesFvImageOptions (String fvName
, Map
<String
, String
> m
) {
3463 Vector
<FvImagesDocument
.FvImages
.FvImage
> vFvImage
= getFvImagesFvImageWithName (fvName
, "Options");
3464 for (int i
= 0; i
< vFvImage
.size(); ++i
) {
3465 FvImagesDocument
.FvImages
.FvImage fi
= vFvImage
.get(i
);
3466 if (fi
== null || fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null) {
3470 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions()
3473 while (li
.hasNext()) {
3474 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3475 m
.put(nv
.getName(), nv
.getValue());
3480 public int getFvImagePosInFvImages (String fvNameList
, String type
) {
3481 XmlObject o
= getfpdFlash().getFvImages();
3487 String
[] fvNameArray
= fvNameList
.trim().split(" ");
3488 Vector
<String
> vFvNames
= new Vector
<String
>();
3491 XmlCursor cursor
= o
.newCursor();
3492 QName qFvImage
= new QName(xmlNs
, "FvImage");
3493 if (cursor
.toChild(qFvImage
)) {
3496 vFvNames
.removeAllElements();
3497 for (int i
= 0; i
< fvNameArray
.length
; ++i
) {
3498 vFvNames
.add(fvNameArray
[i
]);
3500 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3501 if (!fi
.getType().toString().equals(type
)) {
3504 if (fi
.getFvImageNamesList() == null || fi
.getFvImageNamesList().size() != vFvNames
.size()) {
3507 ListIterator
<String
> li
= fi
.getFvImageNamesList().listIterator();
3508 while (li
.hasNext()) {
3509 String name
= li
.next();
3510 vFvNames
.remove(name
);
3512 if (vFvNames
.size() == 0) {
3517 }while (cursor
.toNextSibling(qFvImage
));
3523 /**Get FvImage Options for FvImage i
3524 * @param i the ith FvImage
3526 public void getFvImagesFvImageOptions(int i
, Map
<String
, String
> m
) {
3527 XmlObject o
= getfpdFlash().getFvImages();
3531 XmlCursor cursor
= o
.newCursor();
3532 QName qFvImage
= new QName(xmlNs
, "FvImage");
3533 if (cursor
.toChild(qFvImage
)) {
3534 for (int j
= 0; j
< i
; ++j
) {
3535 cursor
.toNextSibling(qFvImage
);
3537 FvImagesDocument
.FvImages
.FvImage fi
= (FvImagesDocument
.FvImages
.FvImage
)cursor
.getObject();
3538 if (fi
.getFvImageOptions() == null || fi
.getFvImageOptions().getNameValueList() == null){
3542 ListIterator
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> li
= fi
.getFvImageOptions().getNameValueList().listIterator();
3543 while(li
.hasNext()){
3544 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nv
= li
.next();
3545 m
.put(nv
.getName(), nv
.getValue());
3552 Get platform header element
3553 @return PlatformHeaderDocument.PlatformHeader
3555 public PlatformHeaderDocument
.PlatformHeader
getFpdHdr() {
3556 if (fpdHdr
== null) {
3557 fpdHdr
= fpdRoot
.addNewPlatformHeader();
3563 public String
getFpdHdrPlatformName() {
3564 return getFpdHdr().getPlatformName();
3567 public String
getFpdHdrGuidValue() {
3568 return getFpdHdr().getGuidValue();
3571 public String
getFpdHdrVer() {
3572 return getFpdHdr().getVersion();
3575 public String
getFpdHdrAbs() {
3576 return getFpdHdr().getAbstract();
3579 public String
getFpdHdrDescription() {
3580 return getFpdHdr().getDescription();
3583 public String
getFpdHdrCopyright() {
3584 return getFpdHdr().getCopyright();
3587 public String
getFpdHdrLicense() {
3588 LicenseDocument
.License l
= getFpdHdr().getLicense();
3592 return l
.getStringValue();
3595 public String
getFpdHdrUrl() {
3596 LicenseDocument
.License l
= getFpdHdr().getLicense();
3603 public String
getFpdHdrSpec() {
3605 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3606 // return getFpdHdr().getSpecification();
3609 public void setFpdHdrPlatformName(String name
){
3610 getFpdHdr().setPlatformName(name
);
3613 public void setFpdHdrGuidValue(String guid
){
3614 getFpdHdr().setGuidValue(guid
);
3617 public void setFpdHdrVer(String v
){
3618 getFpdHdr().setVersion(v
);
3621 public void setFpdHdrAbs(String abs
) {
3622 getFpdHdr().setAbstract(abs
);
3625 public void setFpdHdrDescription(String desc
){
3626 getFpdHdr().setDescription(desc
);
3629 public void setFpdHdrCopyright(String cr
) {
3630 getFpdHdr().setCopyright(cr
);
3633 public void setFpdHdrLicense(String license
){
3634 LicenseDocument
.License l
= getFpdHdr().getLicense();
3636 getFpdHdr().addNewLicense().setStringValue(license
);
3639 l
.setStringValue(license
);
3643 public void setFpdHdrUrl(String url
){
3644 LicenseDocument
.License l
= getFpdHdr().getLicense();
3650 public void setFpdHdrSpec(String s
){
3651 s
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3652 getFpdHdr().setSpecification(s
);
3655 Save the processed xml contents to file
3657 @param fpdFile The file to save xml contents
3658 @throws IOException Exceptions during file operation
3660 public void saveAs(File fpdFile
) throws IOException
{
3662 XmlOptions options
= new XmlOptions();
3664 options
.setCharacterEncoding("UTF-8");
3665 options
.setSavePrettyPrint();
3666 options
.setSavePrettyPrintIndent(2);
3668 fpdd
.save(fpdFile
, options
);
3669 } catch (IOException e
) {
3670 e
.printStackTrace();
3675 private String
listToString(List l
) {
3680 ListIterator li
= l
.listIterator();
3681 while(li
.hasNext()) {
3688 private void removeElement(XmlObject o
) {
3689 XmlCursor cursor
= o
.newCursor();
3695 class PcdItemTypeConflictException
extends Exception
{
3700 private static final long serialVersionUID
= 1L;
3701 private String details
= null;
3703 PcdItemTypeConflictException (String pcdName
, String info
) {
3704 ModuleIdentification mi
= WorkspaceProfile
.getModuleId(info
);
3706 details
= pcdName
+ " ItemType Conflicts with " + mi
.getName() + "\n in Pkg " + mi
.getPackageId().getName();
3709 details
= pcdName
+ " ItemType Conflicts with \n" + info
;
3713 PcdItemTypeConflictException (String pcdName
, String info1
, String info2
) {
3714 ModuleIdentification mi1
= WorkspaceProfile
.getModuleId(info1
);
3715 ModuleIdentification mi2
= WorkspaceProfile
.getModuleId(info2
);
3716 String moduleInfo1
= "";
3717 String moduleInfo2
= "";
3719 moduleInfo1
= mi1
.getName() + " in Pkg " + mi1
.getPackageId().getName();
3722 moduleInfo1
= info1
;
3726 moduleInfo2
= mi2
.getName() + " in Pkg " + mi2
.getPackageId().getName();
3729 moduleInfo2
= info2
;
3732 details
= pcdName
+ " ItemType Conflicts in \n" + moduleInfo1
+ "\n and " + moduleInfo2
;
3735 public String
getMessage() {
3740 class PcdDeclNotFound
extends Exception
{
3745 private static final long serialVersionUID
= 1L;
3746 private String details
= null;
3748 PcdDeclNotFound(String info
) {
3749 details
= "PcdDeclNotFound: " + info
;
3752 public String
getMessage() {
3757 class PcdValueMalFormed
extends Exception
{
3762 private static final long serialVersionUID
= 1L;
3763 private String details
= null;
3765 PcdValueMalFormed(String info
) {
3766 details
= "PcdValueMalFormed: " + info
;
3769 public String
getMessage() {