]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
946a6b64d9d8a4fea1d1d22d6eda493c4062bca6
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
1 /** @file
2 Java class FpdFileContents is used to parse fpd xml file.
3
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
9
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.
12 **/
13 package org.tianocore.frameworkwizard.platform.ui;
14
15 import java.io.File;
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;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Vector;
27
28 import javax.xml.namespace.QName;
29
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
66 /**
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
69 **/
70 public class FpdFileContents {
71
72 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
73
74 private PlatformSurfaceAreaDocument fpdd = null;
75
76 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
77
78 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
79
80 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
81
82 private FlashDocument.Flash fpdFlash = null;
83
84 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
85
86 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
87
88 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
89
90 private HashMap<String, ArrayList<String>> dynPcdMap = null;
91
92 private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();
93
94 private String itemType (String pcdInfo) {
95
96 return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1);
97 }
98
99 /**
100 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
101 */
102 public void initDynPcdMap() {
103 if (dynPcdMap == null) {
104 dynPcdMap = new HashMap<String, ArrayList<String>>();
105 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
106 if (l == null) {
107 removeElement(getfpdFrameworkModules());
108 fpdFrameworkModules = null;
109 return;
110 }
111 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
112 while (li.hasNext()) {
113 ModuleSADocument.ModuleSA moduleSa = li.next();
114 if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {
115 continue;
116 }
117 String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() +
118 " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
119 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();
120 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
121 while (lpi.hasNext()) {
122 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
123 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
124 if (dynPcdMap.get(pcdKey) == null) {
125 ArrayList<String> al = new ArrayList<String>();
126 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
127 dynPcdMap.put(pcdKey, al);
128 }
129 else{
130 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
131 }
132 }
133 }
134 }
135 }
136
137 public ArrayList<String> getDynPcdMapValue(String key) {
138 return dynPcdMap.get(key);
139 }
140 /**
141 Constructor to create a new spd file
142 **/
143 public FpdFileContents() {
144
145 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
146 fpdRoot = fpdd.addNewPlatformSurfaceArea();
147
148 }
149
150 /**
151 Constructor for existing document object
152 @param psa
153 **/
154 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
155 fpdRoot = fpd;
156 fpdHdr = fpdRoot.getPlatformHeader();
157 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
158 fpdBuildOpts = fpdRoot.getBuildOptions();
159 fpdFrameworkModules = fpdRoot.getFrameworkModules();
160 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
161 fpdFlash = fpdRoot.getFlash();
162 }
163
164 /**
165 Constructor based on an existing spd file
166
167 @param f Existing spd file
168 **/
169 public FpdFileContents(File f) {
170 try {
171 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
172 fpdRoot = fpdd.getPlatformSurfaceArea();
173 } catch (Exception e) {
174 System.out.println(e.toString());
175 }
176 }
177
178 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
179 if (fpdDynPcdBuildDefs == null){
180 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
181 }
182 return fpdDynPcdBuildDefs;
183 }
184
185 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
186 if (fpdFrameworkModules == null){
187 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
188 }
189 return fpdFrameworkModules;
190 }
191
192 public void getFrameworkModuleGuid (String fvName, Vector<String> vGuid) {
193 if (getFrameworkModulesCount() == 0){
194 return;
195 }
196
197 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
198 while(li.hasNext()) {
199 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
200 if (moduleSa.getModuleSaBuildOptions() == null) {
201 continue;
202 }
203 String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();
204 if (fvBinding == null) {
205 continue;
206 }
207
208 String[] fvNames = fvBinding.split(" ");
209 for (int i = 0; i < fvNames.length; ++i) {
210 if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {
211 vGuid.add(moduleSa.getModuleGuid());
212 break;
213 }
214 }
215 }
216 }
217
218 public int getFrameworkModulesCount() {
219 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
220 removeElement(getfpdFrameworkModules());
221 fpdFrameworkModules = null;
222 return 0;
223 }
224 return getfpdFrameworkModules().getModuleSAList().size();
225 }
226
227 public void getFrameworkModulesInfo(String[][] saa) {
228 if (getFrameworkModulesCount() == 0){
229 return;
230 }
231
232 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
233 int i = 0;
234 while(li.hasNext()) {
235 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
236 saa[i][0] = moduleSa.getModuleGuid();
237 saa[i][1] = moduleSa.getModuleVersion();
238
239 saa[i][2] = moduleSa.getPackageGuid();
240 saa[i][3] = moduleSa.getPackageVersion();
241 saa[i][4] = listToString(moduleSa.getSupArchList());
242 ++i;
243 }
244 }
245
246 public void getFrameworkModuleInfo(int i, String[] sa) {
247 ModuleSADocument.ModuleSA msa = getModuleSA(i);
248 if (msa == null) {
249 return;
250 }
251 sa[0] = msa.getModuleGuid();
252 sa[1] = msa.getModuleVersion();
253 sa[2] = msa.getPackageGuid();
254 sa[3] = msa.getPackageVersion();
255 sa[4] = listToString(msa.getSupArchList());
256 }
257
258 public ModuleSADocument.ModuleSA getModuleSA(String key) {
259
260 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
261 removeElement(getfpdFrameworkModules());
262 fpdFrameworkModules = null;
263 return null;
264 }
265 String[] s = key.split(" ");
266 String archsInKey = "";
267 if (s.length > 4) {
268 for (int i = 4; i < s.length; ++i) {
269 archsInKey += s[i];
270 archsInKey += " ";
271 }
272 archsInKey = archsInKey.trim();
273 }
274
275 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
276 while(li.hasNext()) {
277 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
278 if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {
279 if (moduleSa.getModuleVersion() != null) {
280 if (!moduleSa.getModuleVersion().equals(s[1])) {
281 continue;
282 }
283 }
284 if (moduleSa.getPackageVersion() != null) {
285 if (!moduleSa.getPackageVersion().equals(s[3])) {
286 continue;
287 }
288 }
289 //ToDo add arch check .
290 if (moduleSa.getSupArchList() != null) {
291 if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) {
292 return moduleSa;
293 }
294 }
295 else {
296 if (archsInKey.length() == 0) {
297 return moduleSa;
298 }
299 }
300 }
301 }
302 return null;
303 }
304
305 private ModuleSADocument.ModuleSA getModuleSA(int i) {
306 ModuleSADocument.ModuleSA moduleSa = null;
307 if (fpdRoot.getFrameworkModules() == null) {
308 return null;
309 }
310 XmlCursor cursor = fpdRoot.getFrameworkModules().newCursor();
311 if (cursor.toFirstChild()) {
312 for (int j = 0; j < i; ++j) {
313 cursor.toNextSibling();
314 }
315 moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
316 }
317 cursor.dispose();
318 return moduleSa;
319 }
320
321 public void removeModuleSA(int i) {
322 XmlObject o = fpdRoot.getFrameworkModules();
323 if (o == null) {
324 return;
325 }
326
327 XmlCursor cursor = o.newCursor();
328 if (cursor.toFirstChild()) {
329 for (int j = 0; j < i; ++j) {
330 cursor.toNextSibling();
331 }
332 //
333 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
334 //
335 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
336 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
337 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
338 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
339 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {
340 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();
341 while(li.hasNext()) {
342 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
343 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);
344 }
345 }
346
347 cursor.push();
348 cursor.toPrevToken();
349 if (cursor.isComment()) {
350 cursor.removeXml();
351 }
352 cursor.pop();
353 cursor.removeXml();
354 if (getFrameworkModulesCount() == 0) {
355 cursor.toParent();
356 cursor.removeXml();
357 }
358 }
359 cursor.dispose();
360 }
361
362 public boolean adjustPcd (int seqModuleSa) throws Exception {
363 boolean dataModified = false;
364 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
365 int pcdCount = getPcdDataCount(seqModuleSa);
366 String[][] saaModuleSaPcd = new String[pcdCount][7];
367 getPcdData(seqModuleSa, saaModuleSaPcd);
368 String mg = moduleSa.getModuleGuid();
369 String mv = moduleSa.getModuleVersion();
370 String pg = moduleSa.getPackageGuid();
371 String pv = moduleSa.getPackageVersion();
372 String arch = listToString(moduleSa.getSupArchList());
373 //
374 // delete pcd in ModuleSA but not in MSA files any longer.
375 //
376 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
377 int libCount = getLibraryInstancesCount(moduleKey);
378 String[][] saaLib = new String[libCount][5];
379 getLibraryInstances(moduleKey, saaLib);
380 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
381 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
382 //
383 // create vector for module & library instance MIs.
384 //
385 vMi.add(mi);
386 for (int j = 0; j < saaLib.length; ++j) {
387 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
388 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
389 vMi.add(libMi);
390 }
391
392 try {
393 nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {
394
395 for (int j = 0; j < vMi.size(); ++j) {
396 ModuleIdentification nextMi = vMi.get(j);
397 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], nextMi)) {
398 continue nextPcd;
399 }
400 }
401 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);
402 dataModified = true;
403 }
404 }
405 catch (Exception e) {
406 throw e;
407 }
408 //
409 // add new Pcd from MSA file to ModuleSA.
410 //
411 try {
412
413 for (int i = 0; i < vMi.size(); ++i) {
414 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
415 .getModuleXmlObject(vMi
416 .get(i));
417 if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {
418 continue;
419 }
420 ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();
421 msaPcdIter:while (li.hasNext()) {
422 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
423 ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());
424 if (al != null) {
425 for (int j = 0; j < al.size(); ++j) {
426 if (al.get(j).contains(moduleKey)) {
427 continue msaPcdIter;
428 }
429 }
430 }
431
432 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));
433 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
434 if (spdPcd == null) {
435 //
436 // ToDo Error
437 //
438 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "
439 + mi.getName());
440 }
441 //
442 // AddItem to ModuleSA PcdBuildDefinitions
443 //
444 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()
445 : msaPcd.getDefaultValue();
446
447 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),
448 msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);
449 dataModified = true;
450 }
451
452 }
453 }
454 catch (Exception e){
455 throw e;
456 }
457
458 return dataModified;
459 }
460
461 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {
462
463 ArrayList<String> al = dynPcdMap.get(pcdKey);
464 if (al == null) {
465 return;
466 }
467 String[] s = moduleInfo.split(" ");
468 for(int i = 0; i < al.size(); ++i){
469 String consumer = al.get(i);
470 if (consumer.contains(s[0]) && consumer.contains(s[2])){
471 String[] consumerPart = consumer.split(" ");
472 if (!consumerPart[4].equals(s[4])) {
473 continue;
474 }
475 al.remove(consumer);
476 break;
477 }
478 }
479
480 if (al.size() == 0) {
481 defaultPcdValue.remove(pcdKey);
482 dynPcdMap.remove(pcdKey);
483 String[] s1 = pcdKey.split(" ");
484 removeDynamicPcdBuildData(s1[0], s1[1]);
485 }
486
487 }
488 //
489 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
490 //
491 public int getPcdDataCount (int i){
492 ModuleSADocument.ModuleSA msa = getModuleSA(i);
493
494 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
495 return 0;
496 }
497 return msa.getPcdBuildDefinition().getPcdDataList().size();
498
499 }
500
501 public void getPcdData (int i, String[][] saa) {
502 ModuleSADocument.ModuleSA msa = getModuleSA(i);
503
504 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
505 return;
506 }
507 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
508 for (int k = 0; k < saa.length; ++k) {
509 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
510 saa[k][0] = pcdData.getCName();
511 saa[k][1] = pcdData.getTokenSpaceGuidCName();
512 saa[k][2] = pcdData.getItemType()+"";
513 saa[k][3] = pcdData.getToken().toString();
514 saa[k][4] = pcdData.getMaxDatumSize()+"";
515 saa[k][5] = pcdData.getDatumType()+"";
516 saa[k][6] = pcdData.getValue();
517
518 }
519 }
520
521 public void removePcdData (int seqModuleSa, String cName, String tsGuid) {
522 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
523 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
524 return;
525 }
526
527 String mg = moduleSa.getModuleGuid();
528 String mv = moduleSa.getModuleVersion();
529 String pg = moduleSa.getPackageGuid();
530 String pv = moduleSa.getPackageVersion();
531 String arch = listToString(moduleSa.getSupArchList());
532 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
533
534 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
535 if (cursor.toFirstChild()){
536
537 do {
538 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
539 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
540 maintainDynPcdMap(cName + " " + tsGuid, moduleKey);
541 if (getPcdDataCount(seqModuleSa) == 1) {
542 cursor.toParent();
543 }
544 cursor.removeXml();
545 break;
546 }
547 }
548 while(cursor.toNextSibling());
549
550 }
551 cursor.dispose();
552 }
553
554 public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){
555 ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);
556 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
557 return;
558 }
559
560 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
561 if (cursor.toFirstChild()){
562 do {
563 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
564 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
565 //
566 // change item type while not updating dynPcdData????
567 //
568 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
569 if(pcdData.getDatumType().equals("VOID*")) {
570 pcdData.setMaxDatumSize(new Integer(maxSize));
571 }
572 pcdData.setValue(value);
573 defaultPcdValue.put(cName + " " + tsGuid, value);
574 break;
575 }
576 }
577 while(cursor.toNextSibling());
578 }
579 cursor.dispose();
580 }
581
582 /**Get original Pcd info from MSA & SPD files.
583 * @param mi ModuleIdentification from which MSA & SPD come
584 * @param cName PCD cName
585 * @param sa Results: HelpText, Original item type.
586 * @return
587 */
588 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{
589 try {
590
591 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
592 if (msa.getPcdCoded() == null) {
593 return false;
594 }
595
596 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
597 m.put("ModuleSurfaceArea", msa);
598 SurfaceAreaQuery.setDoc(m);
599 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
600 //
601 // First look through MSA pcd entries.
602 //
603 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
604 ListIterator li = l.listIterator();
605 while(li.hasNext()) {
606 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
607 if (!msaPcd.getCName().equals(cName)) {
608 continue;
609 }
610 if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {
611 continue;
612 }
613 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
614 if (spdPcd == null) {
615 //
616 // ToDo Error
617 //
618 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());
619 }
620 //
621 // Get Pcd help text and original item type.
622 //
623 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();
624 sa[1] = msaPcd.getPcdItemType()+"";
625 sa[2] = msa.getModuleDefinitions().getBinaryModule()+"";
626 return true;
627 }
628
629
630 }
631 catch (Exception e){
632 e.printStackTrace();
633 throw e;
634 }
635
636 return false;
637 }
638
639 /**Remove PCDBuildDefinition entries from ModuleSA
640 * @param moduleKey identifier of ModuleSA.
641 * @param consumer where these entries come from.
642 */
643 public void removePcdData(String moduleKey, ModuleIdentification consumer) {
644 try {
645 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);
646 if (msa.getPcdCoded() == null) {
647 return;
648 }
649
650 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
651 ListIterator li = l.listIterator();
652
653 while(li.hasNext()) {
654 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
655 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);
656 if (moduleSA.getPcdBuildDefinition() != null) {
657 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();
658 if (cursor.toFirstChild()) {
659 do {
660 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor
661 .getObject();
662 if (msaPcd.getCName().equals(pcdData.getCName())
663 && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {
664
665 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),
666 moduleKey);
667 cursor.removeXml();
668 break;
669 }
670 } while (cursor.toNextSibling());
671 }
672 cursor.dispose();
673 }
674 }
675
676 }
677 catch (Exception e){
678 e.printStackTrace();
679
680 }
681 }
682 //
683 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
684 //
685 public int getLibraryInstancesCount(String key) {
686 ModuleSADocument.ModuleSA msa = getModuleSA(key);
687 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
688 return 0;
689 }
690 return msa.getLibraries().getInstanceList().size();
691 }
692
693 public void getLibraryInstances(String key, String[][] saa){
694 ModuleSADocument.ModuleSA msa = getModuleSA(key);
695 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
696 return ;
697 }
698
699 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
700 for (int i = 0; i < saa.length; ++i) {
701 LibrariesDocument.Libraries.Instance instance = li.next();
702 saa[i][1] = instance.getModuleGuid();
703 saa[i][2] = instance.getModuleVersion();
704 saa[i][3] = instance.getPackageGuid();
705 saa[i][4] = instance.getPackageVersion();
706 }
707 }
708
709 public void removeLibraryInstance(String key, int i) {
710 ModuleSADocument.ModuleSA msa = getModuleSA(key);
711 if (msa == null || msa.getLibraries() == null){
712 return ;
713 }
714
715 XmlCursor cursor = msa.getLibraries().newCursor();
716 if (cursor.toFirstChild()) {
717 for (int j = 0; j < i; ++j) {
718 cursor.toNextSibling();
719 }
720 cursor.push();
721 cursor.toPrevToken();
722 if (cursor.isComment()) {
723 cursor.removeXml();
724 }
725 cursor.pop();
726 cursor.removeXml();
727 if (getLibraryInstancesCount(key) == 0) {
728 cursor.toParent();
729 cursor.removeXml();
730 }
731 }
732
733 cursor.dispose();
734 }
735
736 public void genLibraryInstance(ModuleIdentification libMi, String key) {
737 ModuleSADocument.ModuleSA msa = getModuleSA(key);
738 if (msa == null){
739 msa = getfpdFrameworkModules().addNewModuleSA();
740 }
741 LibrariesDocument.Libraries libs = msa.getLibraries();
742 if(libs == null){
743 libs = msa.addNewLibraries();
744 }
745
746 String mn = libMi.getName();
747 String mg = libMi.getGuid();
748 String mv = libMi.getVersion();
749 String pn = libMi.getPackageId().getName();
750 String pg = libMi.getPackageId().getGuid();
751 String pv = libMi.getPackageId().getVersion();
752 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
753 XmlCursor cursor = instance.newCursor();
754 try{
755 String comment = "Pkg: " + pn + " Mod: " + mn
756 + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
757 cursor.insertComment(comment);
758 }
759 catch (Exception e){
760 e.printStackTrace();
761 }
762 finally {
763 cursor.dispose();
764 }
765
766 instance.setModuleGuid(mg);
767 instance.setModuleVersion(mv);
768 instance.setPackageGuid(pg);
769 instance.setPackageVersion(pv);
770
771 }
772
773 public String getFvBinding(String moduleKey){
774 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
775 return getFvBinding (moduleSa);
776 }
777
778 public String getFvBinding (ModuleSADocument.ModuleSA moduleSa) {
779 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
780 return null;
781 }
782 return moduleSa.getModuleSaBuildOptions().getFvBinding();
783 }
784
785 public void setFvBinding(ModuleSADocument.ModuleSA moduleSa, String fvBinding) {
786 if (moduleSa == null ) {
787 return;
788 }
789 if (fvBinding == null || fvBinding.length() == 0) {
790 if(moduleSa.getModuleSaBuildOptions() != null){
791 moduleSa.getModuleSaBuildOptions().unsetFvBinding();
792 }
793 }
794 else {
795 if(moduleSa.getModuleSaBuildOptions() == null){
796 moduleSa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
797 return;
798 }
799 moduleSa.getModuleSaBuildOptions().setFvBinding(fvBinding);
800 }
801 }
802
803 public void setFvBinding(String moduleKey, String fvBinding){
804 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
805 setFvBinding (moduleSa, fvBinding);
806 }
807
808 private int fvBindingForModuleSA (ModuleSADocument.ModuleSA moduleSa, String fvName) {
809 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
810 return -1;
811 }
812
813 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
814 String[] fvNamesArray = fvNameList.split(" ");
815 int occursAt = -1;
816 for (int i = 0; i < fvNamesArray.length; ++i) {
817 if (fvNamesArray[i].equals(fvName)) {
818 occursAt = i;
819 break;
820 }
821 }
822 return occursAt;
823 }
824
825 public void removeFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
826 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
827 return;
828 }
829
830 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
831 String[] fvNamesArray = fvNameList.split(" ");
832 int occursAt = -1;
833 for (int i = 0; i < fvNamesArray.length; ++i) {
834 if (fvNamesArray[i].equals(fvName)) {
835 occursAt = i;
836 break;
837 }
838 }
839 // jump over where the input fvName occurs in the original Fv list.
840 if (occursAt != -1) {
841 String newFvNameList = " ";
842 for (int i = 0; i < fvNamesArray.length; ++i) {
843 if (i == occursAt) {
844 continue;
845 }
846 newFvNameList += fvNamesArray[i];
847 }
848 setFvBinding (moduleSa, newFvNameList.trim());
849 }
850
851 }
852
853 /**
854 * @param fvName The FV name that to be removed from FvBinding List.
855 */
856 public void removeFvBindingAll (String fvName) {
857 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
858 removeElement(getfpdFrameworkModules());
859 fpdFrameworkModules = null;
860 return;
861 }
862
863 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
864 while (li.hasNext()) {
865 ModuleSADocument.ModuleSA moduleSa = li.next();
866 removeFvBinding (moduleSa, fvName);
867 }
868 }
869
870 public void appendFvBindingAll (String fvName) {
871 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
872 removeElement(getfpdFrameworkModules());
873 fpdFrameworkModules = null;
874 return;
875 }
876
877 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
878 while (li.hasNext()) {
879 ModuleSADocument.ModuleSA moduleSa = li.next();
880 appendFvBinding (moduleSa, fvName);
881 }
882 }
883
884 public void appendFvBindingFor (String oldFvName, String newFvName) {
885 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
886 removeElement(getfpdFrameworkModules());
887 fpdFrameworkModules = null;
888 return;
889 }
890
891 Iterator<ModuleSADocument.ModuleSA> li = getfpdFrameworkModules().getModuleSAList().iterator();
892 while (li.hasNext()) {
893 ModuleSADocument.ModuleSA moduleSa = li.next();
894 String fvBinding = getFvBinding (moduleSa);
895 if (fvBinding != null && fvBindingForModuleSA (moduleSa, oldFvName) >= 0) {
896 appendFvBinding (moduleSa, newFvName);
897 }
898 }
899 }
900
901 public void appendFvBinding (String moduleKey, String fvName) {
902 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
903 appendFvBinding (moduleSa, fvName);
904 }
905
906 public void appendFvBinding (ModuleSADocument.ModuleSA moduleSa, String fvName) {
907 if (moduleSa == null) {
908 return;
909 }
910
911 if (moduleSa.getModuleSaBuildOptions() == null || moduleSa.getModuleSaBuildOptions().getFvBinding() == null) {
912 setFvBinding(moduleSa, fvName);
913 return;
914 }
915
916 String fvNameList = moduleSa.getModuleSaBuildOptions().getFvBinding();
917 String newFvNameList = fvNameList + " " + fvName;
918 setFvBinding (moduleSa, newFvNameList.trim());
919 }
920
921 public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) {
922 Vector<Object> vSupArchs = new Vector<Object>();
923 getPlatformDefsSupportedArchs(vSupArchs);
924 String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion();
925 for (int i = 0; i < vSupArchs.size(); ++i) {
926 String moduleKey = moduleInfo + " " + vSupArchs.get(i);
927 appendFvBinding (moduleKey, fvName);
928 }
929 }
930
931 public String getFfsFileNameGuid(String moduleKey){
932 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
933 if (moduleSa == null || moduleSa.getModuleSaBuildOptions() == null) {
934 return null;
935 }
936 return moduleSa.getModuleSaBuildOptions().getFfsFileNameGuid();
937 }
938
939 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
940 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
941 if (msa == null ) {
942 return;
943 }
944 if(msa.getModuleSaBuildOptions() == null){
945 msa.addNewModuleSaBuildOptions();
946
947 }
948 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();
949 if (fileGuid != null) {
950 msaBuildOpts.setFfsFileNameGuid(fileGuid);
951 }
952 else{
953 XmlCursor cursor = msaBuildOpts.newCursor();
954 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {
955 cursor.removeXml();
956 }
957 cursor.dispose();
958 }
959
960 }
961
962 public String getFfsFormatKey(String moduleKey){
963 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
964 if (msa == null || msa.getModuleSaBuildOptions() == null) {
965 return null;
966 }
967 return msa.getModuleSaBuildOptions().getFfsFormatKey();
968 }
969
970 public void setFfsFormatKey(String moduleKey, String ffsKey){
971 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
972 if (msa == null ) {
973 return;
974 }
975 if(msa.getModuleSaBuildOptions() == null){
976 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
977 return;
978 }
979 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);
980 }
981
982 public void setModuleSAForceDebug(int i, boolean dbgEnable) {
983 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
984 moduleSa.setForceDebug(dbgEnable);
985 }
986
987 public boolean getModuleSAForceDebug (int i) {
988 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
989 if (moduleSa.getForceDebug() == true) {
990 return true;
991 }
992 return false;
993 }
994
995 public void getModuleSAOptions(String moduleKey, String[][] saa) {
996 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
997 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
998 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
999 return ;
1000 }
1001
1002 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
1003 ListIterator li = lOpt.listIterator();
1004 int i = 0;
1005 while(li.hasNext()) {
1006 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1007 if (opt.getBuildTargets() != null) {
1008 saa[i][0] = listToString(opt.getBuildTargets());
1009 }
1010 saa[i][1] = opt.getToolChainFamily();
1011 saa[i][2] = opt.getTagName();
1012 saa[i][3] = opt.getToolCode();
1013
1014 if (opt.getSupArchList() != null){
1015 saa[i][4] = listToString(opt.getSupArchList());
1016 }
1017 else {
1018 saa[i][4] = "";
1019 }
1020
1021 saa[i][5] = opt.getStringValue();
1022
1023 ++i;
1024 }
1025 }
1026
1027 public int getModuleSAOptionsCount(String moduleKey){
1028 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1029 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
1030 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
1031 return 0;
1032 }
1033 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
1034 }
1035
1036 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1037 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1038 if (msa.getModuleSaBuildOptions() == null) {
1039 msa.addNewModuleSaBuildOptions();
1040 }
1041 if (msa.getModuleSaBuildOptions().getOptions() == null){
1042 msa.getModuleSaBuildOptions().addNewOptions();
1043 }
1044 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
1045 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1046 }
1047
1048 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
1049 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1050 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1051 return ;
1052 }
1053 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1054 XmlCursor cursor = opts.newCursor();
1055 if (cursor.toFirstChild()) {
1056 for (int j = 0; j < i; ++j){
1057 cursor.toNextSibling();
1058 }
1059 cursor.removeXml();
1060 }
1061 cursor.dispose();
1062 }
1063
1064 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1065 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
1066 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
1067 return ;
1068 }
1069 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
1070 XmlCursor cursor = opts.newCursor();
1071 if (cursor.toFirstChild()) {
1072 for (int j = 0; j < i; ++j){
1073 cursor.toNextSibling();
1074 }
1075 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1076 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1077 }
1078 cursor.dispose();
1079 }
1080
1081 /**add pcd information of module mi to a ModuleSA.
1082 * @param mi
1083 * @param moduleSa if null, generate a new ModuleSA.
1084 */
1085 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
1086 //ToDo add Arch filter
1087
1088 try {
1089 if (moduleSa == null) {
1090 moduleSa = genModuleSA(mi, arch);
1091 }
1092
1093 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
1094 if (msa.getPcdCoded() == null) {
1095 return;
1096 }
1097
1098 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
1099 m.put("ModuleSurfaceArea", msa);
1100 SurfaceAreaQuery.setDoc(m);
1101 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
1102 //
1103 // Implementing InitializePlatformPcdBuildDefinitions
1104 //
1105 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
1106 ListIterator li = l.listIterator();
1107 while(li.hasNext()) {
1108 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
1109 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
1110 if (spdPcd == null) {
1111 //
1112 // ToDo Error
1113 //
1114 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());
1115 }
1116 //
1117 // AddItem to ModuleSA PcdBuildDefinitions
1118 //
1119 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
1120
1121 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
1122 }
1123
1124 }
1125 catch (Exception e){
1126
1127 throw e;
1128 }
1129
1130 }
1131
1132 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
1133
1134 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
1135 for (int i = 0; i < depPkgs.length; ++i) {
1136
1137 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);
1138 if (xo == null) {
1139 continue;
1140 }
1141 for (int j = 0; j < xo.length; ++j) {
1142 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
1143 if (msaPcd.getTokenSpaceGuidCName() == null) {
1144 if (spdPcd.getCName().equals(msaPcd.getCName())) {
1145 return spdPcd;
1146 }
1147 }
1148 else{
1149 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
1150 return spdPcd;
1151 }
1152 }
1153
1154 }
1155
1156 }
1157 return null;
1158 }
1159
1160 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
1161 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
1162 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
1163 XmlCursor cursor = msa.newCursor();
1164 try{
1165 String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "
1166 + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
1167 cursor.insertComment(comment);
1168 }
1169 catch(Exception e){
1170 e.printStackTrace();
1171 }
1172 finally {
1173 cursor.dispose();
1174 }
1175 msa.setModuleGuid(mi.getGuid());
1176 msa.setModuleVersion(mi.getVersion());
1177 msa.setPackageGuid(pi.getGuid());
1178 msa.setPackageVersion(pi.getVersion());
1179 if (arch != null) {
1180 Vector<String> v = new Vector<String>();
1181 v.add(arch);
1182 msa.setSupArchList(v);
1183 }
1184
1185 return msa;
1186 }
1187
1188 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa)
1189 throws PcdItemTypeConflictException, PcdValueMalFormed{
1190 if (moduleSa.getPcdBuildDefinition() == null){
1191 moduleSa.addNewPcdBuildDefinition();
1192 }
1193 //
1194 // constructe pcd to modulesa mapping first.
1195 // Attention : for any error condition, remove from map this pcd.
1196 //
1197 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1198 if (pcdConsumer == null) {
1199 pcdConsumer = new ArrayList<String>();
1200 }
1201 //
1202 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1203 //
1204 if (pcdConsumer.size() > 0) {
1205
1206 itemType = itemType (pcdConsumer.get(0));
1207 }
1208 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
1209 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())
1210 + " " + itemType;
1211 pcdConsumer.add(listValue);
1212 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1213
1214 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1215 fpdPcd.setCName(cName);
1216 fpdPcd.setToken(token);
1217 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1218 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1219 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1220
1221 if (defaultVal != null){
1222 fpdPcd.setValue(defaultVal);
1223 }
1224 else {
1225 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1226 fpdPcd.setValue("0");
1227 }
1228 if (dataType.equals("BOOLEAN")){
1229 fpdPcd.setValue("FALSE");
1230 }
1231 if (dataType.equals("VOID*")) {
1232 fpdPcd.setValue("");
1233 }
1234 }
1235 //
1236 // Using existing pcd value, if this pcd already exists in other moduleSa.
1237 //
1238 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1239 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1240 }
1241 else {
1242 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1243 }
1244
1245 if (dataType.equals("UINT8")){
1246 fpdPcd.setMaxDatumSize(1);
1247 }
1248 if (dataType.equals("UINT16")) {
1249 fpdPcd.setMaxDatumSize(2);
1250 }
1251 if (dataType.equals("UINT32")) {
1252 fpdPcd.setMaxDatumSize(4);
1253 }
1254 if (dataType.equals("UINT64")){
1255 fpdPcd.setMaxDatumSize(8);
1256 }
1257 if (dataType.equals("BOOLEAN")){
1258 fpdPcd.setMaxDatumSize(1);
1259 }
1260 if (dataType.equals("VOID*")) {
1261 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1262 fpdPcd.setMaxDatumSize(maxSize);
1263 }
1264
1265
1266 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1267 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1268 //
1269 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1270 // so need to add one dyn pcd.
1271 //
1272 if (al.size() == 1) {
1273 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1274 }
1275 }
1276
1277 }
1278
1279 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1280 if (datum == null) {
1281 return 0;
1282 }
1283 char ch = datum.charAt(0);
1284 int start, end;
1285 String strValue;
1286 //
1287 // For void* type PCD, only three datum is support:
1288 // 1) Unicode: string with start char is "L"
1289 // 2) Ansci: String is ""
1290 // 3) byte array: String start char "{"
1291 //
1292 if (ch == 'L') {
1293 start = datum.indexOf('\"');
1294 end = datum.lastIndexOf('\"');
1295 if ((start > end) ||
1296 (end > datum.length())||
1297 ((start == end) && (datum.length() > 0))) {
1298 //ToDo Error handling here
1299 throw new PcdValueMalFormed (datum);
1300 }
1301
1302 strValue = datum.substring(start + 1, end);
1303 return strValue.length() * 2;
1304 } else if (ch == '\"'){
1305 start = datum.indexOf('\"');
1306 end = datum.lastIndexOf('\"');
1307 if ((start > end) ||
1308 (end > datum.length())||
1309 ((start == end) && (datum.length() > 0))) {
1310 throw new PcdValueMalFormed (datum);
1311 }
1312 strValue = datum.substring(start + 1, end);
1313 return strValue.length();
1314 } else if (ch =='{') {
1315 String[] strValueArray;
1316
1317 start = datum.indexOf('{');
1318 end = datum.lastIndexOf('}');
1319 strValue = datum.substring(start + 1, end);
1320 strValue = strValue.trim();
1321 if (strValue.length() == 0) {
1322 return 0;
1323 }
1324 strValueArray = strValue.split(",");
1325 for (int index = 0; index < strValueArray.length; index ++) {
1326 Integer value = Integer.decode(strValueArray[index].trim());
1327
1328 if (value > 0xFF) {
1329 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1330 // "it must be a byte array. But the element of %s exceed the byte range",
1331 throw new PcdValueMalFormed (datum);
1332 }
1333 }
1334 return strValueArray.length;
1335
1336
1337 } else {
1338 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1339 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1340 // "2) ANSIC string: like \"xxx\";\r\n"+
1341 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1342 // "but the datum in seems does not following above format!",
1343 throw new PcdValueMalFormed (datum);
1344
1345 }
1346 }
1347
1348 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1349 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1350
1351 return al;
1352 }
1353
1354 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1355
1356 return dynPcdMap.get(pcdKey);
1357 }
1358
1359 public int getDynamicPcdBuildDataCount() {
1360 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1361 removeElement(getfpdDynPcdBuildDefs());
1362 fpdDynPcdBuildDefs = null;
1363 return 0;
1364 }
1365 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1366 }
1367
1368 public void getDynamicPcdBuildData(String[][] saa) {
1369 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1370 removeElement(getfpdDynPcdBuildDefs());
1371 fpdDynPcdBuildDefs = null;
1372 return ;
1373 }
1374 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1375 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1376 int i = 0;
1377 while(li.hasNext()) {
1378 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1379 saa[i][0] = dynPcd.getCName();
1380 saa[i][1] = dynPcd.getToken().toString();
1381 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1382 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1383 saa[i][4] = dynPcd.getDatumType().toString();
1384
1385 ++i;
1386 }
1387 }
1388
1389 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1390 throws PcdValueMalFormed{
1391 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1392 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1393 dynPcdData.setCName(cName);
1394 dynPcdData.setToken(token);
1395 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1396 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1397
1398 BigInteger bigInt = new BigInteger("0");
1399 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1400 skuInfo.setSkuId(bigInt);
1401 if (defaultVal != null){
1402 skuInfo.setValue(defaultVal);
1403 }
1404 else {
1405 if (dataType.equals("UINT8")){
1406 skuInfo.setValue("0");
1407 }
1408 if (dataType.equals("UINT16")) {
1409 skuInfo.setValue("0");
1410 }
1411 if (dataType.equals("UINT32")) {
1412 skuInfo.setValue("0");
1413 }
1414 if (dataType.equals("UINT64")){
1415 skuInfo.setValue("0");
1416 }
1417 if (dataType.equals("BOOLEAN")){
1418 skuInfo.setValue("false");
1419 }
1420 if (dataType.equals("VOID*")) {
1421 skuInfo.setValue("");
1422 }
1423 }
1424 if (dataType.equals("UINT8")){
1425 dynPcdData.setMaxDatumSize(1);
1426 }
1427 if (dataType.equals("UINT16")) {
1428 dynPcdData.setMaxDatumSize(2);
1429 }
1430 if (dataType.equals("UINT32")) {
1431 dynPcdData.setMaxDatumSize(4);
1432 }
1433 if (dataType.equals("UINT64")){
1434 dynPcdData.setMaxDatumSize(8);
1435 }
1436 if (dataType.equals("BOOLEAN")){
1437 dynPcdData.setMaxDatumSize(1);
1438 }
1439 if (dataType.equals("VOID*")) {
1440 int maxSize = setMaxSizeForPointer(defaultVal);
1441 dynPcdData.setMaxDatumSize(maxSize);
1442 }
1443 }
1444
1445 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1446 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1447 if (o == null) {
1448 return;
1449 }
1450
1451 XmlCursor cursor = o.newCursor();
1452 if (cursor.toFirstChild()) {
1453 do {
1454 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1455 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1456 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1457
1458 if (getDynamicPcdBuildDataCount() == 1) {
1459 cursor.toParent();
1460 }
1461 cursor.removeXml();
1462 cursor.dispose();
1463 return;
1464 }
1465 }
1466 while (cursor.toNextSibling());
1467 }
1468 cursor.dispose();
1469 }
1470 //
1471 // Get the Sku Info count of ith dyn pcd element.
1472 //
1473 public int getDynamicPcdSkuInfoCount(int i){
1474 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1475 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1476 return 0;
1477 }
1478
1479 int skuInfoCount = 0;
1480 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1481 if (cursor.toFirstChild()) {
1482 for (int j = 0; j < i; ++j) {
1483 cursor.toNextSibling();
1484 }
1485 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1486 if (pcdData.getSkuInfoList() == null) {
1487 skuInfoCount = 0;
1488 }
1489 else {
1490 skuInfoCount = pcdData.getSkuInfoList().size();
1491 }
1492 }
1493 cursor.dispose();
1494 return skuInfoCount;
1495 }
1496
1497 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1498 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1499 removeElement(getfpdDynPcdBuildDefs());
1500 fpdDynPcdBuildDefs = null;
1501 return;
1502 }
1503
1504 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1505 if (cursor.toFirstChild()) {
1506 for (int j = 0; j < i; ++j) {
1507 cursor.toNextSibling();
1508 }
1509 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1510 if (pcdData.getSkuInfoList() == null) {
1511 cursor.dispose();
1512 return;
1513 }
1514 else {
1515 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1516 int k = 0;
1517 while (li.hasNext()) {
1518 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1519 saa[k][0] = skuInfo.getSkuId()+"";
1520 saa[k][1] = skuInfo.getVariableName();
1521 saa[k][2] = skuInfo.getVariableGuid();
1522 saa[k][3] = skuInfo.getVariableOffset();
1523 saa[k][4] = skuInfo.getHiiDefaultValue();
1524 saa[k][5] = skuInfo.getVpdOffset();
1525 saa[k][6] = skuInfo.getValue();
1526 ++k;
1527 }
1528
1529 }
1530 }
1531 cursor.dispose();
1532
1533 }
1534
1535 public String getDynamicPcdBuildDataValue(int i){
1536 String value = null;
1537 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1538 removeElement(getfpdDynPcdBuildDefs());
1539 fpdDynPcdBuildDefs = null;
1540 return value;
1541 }
1542
1543 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1544 if (cursor.toFirstChild()) {
1545 for (int j = 0; j < i; ++j) {
1546 cursor.toNextSibling();
1547 }
1548 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1549 if (pcdData.getSkuInfoList() == null) {
1550 value = null;
1551 }
1552 else {
1553 value = pcdData.getSkuInfoArray(0).getValue();
1554 }
1555 }
1556 cursor.dispose();
1557 return value;
1558 }
1559
1560 public String getDynamicPcdBuildDataVpdOffset(int i){
1561 String vpdOffset = null;
1562 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1563 removeElement(getfpdDynPcdBuildDefs());
1564 fpdDynPcdBuildDefs = null;
1565 return vpdOffset;
1566 }
1567
1568 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1569 if (cursor.toFirstChild()) {
1570 for (int j = 0; j < i; ++j) {
1571 cursor.toNextSibling();
1572 }
1573 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1574 if (pcdData.getSkuInfoList() == null) {
1575 vpdOffset = null;
1576 }
1577 else {
1578 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1579 }
1580 }
1581 cursor.dispose();
1582 return vpdOffset;
1583 }
1584
1585 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1586 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1587 removeElement(getfpdDynPcdBuildDefs());
1588 fpdDynPcdBuildDefs = null;
1589 return;
1590 }
1591
1592 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1593 if (cursor.toFirstChild()) {
1594 for (int j = 0; j < i; ++j) {
1595 cursor.toNextSibling();
1596 }
1597 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1598 if (pcdData.getSkuInfoList() == null) {
1599 cursor.dispose();
1600 return;
1601 }
1602 else {
1603 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1604 cursor.toChild(qSkuInfo);
1605 cursor.removeXml();
1606 }
1607 }
1608 cursor.dispose();
1609 }
1610 //
1611 // generate sku info for ith dyn pcd build data.
1612 //
1613 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1614 String hiiDefault, String vpdOffset, String value, int i) {
1615 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1616 // return;
1617 // }
1618
1619 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1620 if (cursor.toFirstChild()) {
1621 for (int j = 0; j < i; ++j) {
1622 cursor.toNextSibling();
1623 }
1624 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1625 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1626 skuInfo.setSkuId(new BigInteger(id));
1627 if (varName != null){
1628 skuInfo.setVariableName(varName);
1629 skuInfo.setVariableGuid(varGuid);
1630 skuInfo.setVariableOffset(varOffset);
1631 skuInfo.setHiiDefaultValue(hiiDefault);
1632 }
1633 else if (vpdOffset != null){
1634 skuInfo.setVpdOffset(vpdOffset);
1635 }
1636 else{
1637 skuInfo.setValue(value);
1638 }
1639 }
1640 }
1641
1642 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1643 String hiiDefault, String vpdOffset, String value, int i){
1644 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1645 // return;
1646 // }
1647
1648 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1649 if (cursor.toFirstChild()) {
1650 for (int j = 0; j < i; ++j) {
1651 cursor.toNextSibling();
1652 }
1653 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1654 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1655 while (li.hasNext()) {
1656 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1657 if (skuInfo.getSkuId().toString().equals(id)){
1658 if (varName != null){
1659 skuInfo.setVariableName(varName);
1660 skuInfo.setVariableGuid(varGuid);
1661 skuInfo.setVariableOffset(varOffset);
1662 skuInfo.setHiiDefaultValue(hiiDefault);
1663 }
1664 else if (vpdOffset != null){
1665 skuInfo.setVpdOffset(vpdOffset);
1666 }
1667 else{
1668 skuInfo.setValue(value);
1669 }
1670 break;
1671 }
1672 }
1673 }
1674 }
1675
1676 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1677 if (fpdBuildOpts == null) {
1678 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1679 }
1680 return fpdBuildOpts;
1681 }
1682
1683 public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {
1684 QName elementFvName = new QName (xmlNs, "FvName");
1685 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1686 QName elementInfFileName = new QName(xmlNs, "InfFileName");
1687 QName elementModule = new QName(xmlNs, "Module");
1688
1689 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1690 userExts.setUserID("IMAGES");
1691 userExts.setIdentifier(new BigInteger("1"));
1692 XmlCursor cursor = userExts.newCursor();
1693 cursor.toEndToken();
1694
1695 cursor.beginElement(elementFvName);
1696 cursor.insertChars(fvName);
1697 cursor.toNextToken();
1698
1699 cursor.beginElement(elementInfFileName);
1700 cursor.insertChars(fvName + ".inf");
1701 cursor.toNextToken();
1702
1703 cursor.beginElement(elementIncludeModules);
1704 for (int i = 0; i < includeModules.size(); ++i) {
1705 cursor.beginElement(elementModule);
1706 cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);
1707 cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]);
1708 cursor.toEndToken();
1709 cursor.toNextToken();
1710 }
1711 cursor.dispose();
1712 }
1713
1714 public int getUserExtsIncModCount (String fvName) {
1715 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1716 return -1;
1717 }
1718 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1719 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1720 while (li.hasNext()) {
1721 UserExtensionsDocument.UserExtensions ues = li.next();
1722 if (!ues.getUserID().equals("IMAGES")) {
1723 continue;
1724 }
1725 XmlCursor cursor = ues.newCursor();
1726 cursor.toFirstChild();
1727 String elementName = cursor.getTextValue();
1728 if (elementName.equals(fvName)) {
1729 cursor.toNextSibling(elementIncludeModules);
1730 if (cursor.toFirstChild()) {
1731 int i = 1;
1732 for (i = 1; cursor.toNextSibling(); ++i);
1733 cursor.dispose();
1734 return i;
1735 }
1736 cursor.dispose();
1737 return 0;
1738 }
1739 cursor.dispose();
1740 }
1741 return -1;
1742 }
1743
1744 public void getUserExtsIncMods(String fvName, String[][] saa) {
1745 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1746 return;
1747 }
1748
1749 XmlCursor cursor = getfpdBuildOpts().newCursor();
1750 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1751 QName attribUserId = new QName ("UserID");
1752 QName elementFvName = new QName (xmlNs, "FvName");
1753 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1754 QName attribModuleGuid = new QName("ModuleGuid");
1755 QName attribBaseName = new QName("BaseName");
1756
1757 if (cursor.toChild(elementUserExts)) {
1758 do {
1759 cursor.push();
1760 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1761 cursor.toChild(elementFvName);
1762 String elementName = cursor.getTextValue();
1763 if (elementName.equals(fvName)) {
1764 cursor.toNextSibling(elementIncludeModules);
1765 if (cursor.toFirstChild()) {
1766 int i = 0;
1767 do {
1768 saa[i][0] = cursor.getAttributeText(attribModuleGuid);
1769 saa[i][1] = cursor.getAttributeText(attribBaseName);
1770 ++i;
1771 }while (cursor.toNextSibling());
1772 }
1773 break;
1774 }
1775 }
1776 cursor.pop();
1777 }while (cursor.toNextSibling(elementUserExts));
1778 }
1779 cursor.dispose();
1780
1781 }
1782
1783 public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {
1784 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1785 return;
1786 }
1787 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1788 while (li.hasNext()) {
1789 UserExtensionsDocument.UserExtensions ues = li.next();
1790 if (!ues.getUserID().equals("IMAGES")) {
1791 continue;
1792 }
1793 XmlCursor cursor = ues.newCursor();
1794 cursor.toFirstChild();
1795 String elementName = cursor.getTextValue();
1796 if (elementName.equals(oldFvName)) {
1797 cursor.setTextValue(newFvName);
1798 }
1799 cursor.dispose();
1800 }
1801
1802 }
1803
1804 public void removeBuildOptionsUserExtensions (String fvName) {
1805 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1806 return;
1807 }
1808
1809 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1810 while (li.hasNext()) {
1811 UserExtensionsDocument.UserExtensions ues = li.next();
1812 if (!ues.getUserID().equals("IMAGES")) {
1813 continue;
1814 }
1815 XmlCursor cursor = ues.newCursor();
1816 cursor.toFirstChild();
1817 String elementName = cursor.getTextValue();
1818 if (elementName.equals(fvName)) {
1819 cursor.toParent();
1820 cursor.removeXml();
1821 cursor.dispose();
1822 return;
1823 }
1824 cursor.dispose();
1825 }
1826
1827 }
1828
1829
1830 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1831 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1832 if (udats == null) {
1833 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1834 }
1835
1836 AntTaskDocument.AntTask at = udats.addNewAntTask();
1837 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1838 }
1839
1840 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1841 at.setId(new Integer(id));
1842 XmlCursor cursor = at.newCursor();
1843 if (fileName != null){
1844 at.setFilename(fileName);
1845 }
1846 else if (cursor.toChild(xmlNs, "Filename")) {
1847 cursor.removeXml();
1848 }
1849 if (execOrder != null) {
1850 at.setAntCmdOptions(execOrder);
1851 }
1852 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
1853 cursor.removeXml();
1854 }
1855 cursor.dispose();
1856 }
1857
1858 public void removeBuildOptionsUserDefAntTask(int i) {
1859 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1860 if (o == null) {
1861 return;
1862 }
1863 XmlCursor cursor = o.newCursor();
1864 if (cursor.toFirstChild()) {
1865 for (int j = 0; j < i; ++j) {
1866 cursor.toNextSibling();
1867 }
1868 cursor.removeXml();
1869 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1870 cursor.toParent();
1871 cursor.removeXml();
1872 }
1873 }
1874 cursor.dispose();
1875 }
1876
1877 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1878 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1879 if (o == null) {
1880 return;
1881 }
1882 XmlCursor cursor = o.newCursor();
1883 if (cursor.toFirstChild()) {
1884 for (int j = 0; j < i; ++j) {
1885 cursor.toNextSibling();
1886 }
1887 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1888 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1889 }
1890 cursor.dispose();
1891 }
1892
1893 public int getBuildOptionsUserDefAntTaskCount() {
1894 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1895 if (udats == null || udats.getAntTaskList() == null) {
1896 return 0;
1897 }
1898
1899 return udats.getAntTaskList().size();
1900 }
1901
1902 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1903 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1904 if (udats == null || udats.getAntTaskList() == null) {
1905 return ;
1906 }
1907
1908 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1909 ListIterator li = l.listIterator();
1910 int i = 0;
1911 while (li.hasNext()) {
1912 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1913 saa[i][0] = at.getId() + "";
1914 saa[i][1] = saa[i][2] = "";
1915 if (at.getFilename() != null){
1916 saa[i][1] = at.getFilename();
1917 }
1918 if (at.getAntCmdOptions() != null) {
1919 saa[i][2] = at.getAntCmdOptions();
1920 }
1921 ++i;
1922 }
1923 }
1924 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1925 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1926 if (opts == null) {
1927 opts = getfpdBuildOpts().addNewOptions();
1928 }
1929 OptionDocument.Option opt = opts.addNewOption();
1930 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1931 }
1932
1933 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1934 opt.setStringValue(contents);
1935
1936 opt.setBuildTargets(buildTargets);
1937 opt.setToolChainFamily(toolChain);
1938 opt.setTagName(tagName);
1939 opt.setToolCode(toolCmd);
1940
1941 if (archList != null) {
1942 opt.setSupArchList(archList);
1943 }
1944 else {
1945 if (opt.isSetSupArchList()) {
1946 opt.unsetSupArchList();
1947 }
1948 }
1949 }
1950
1951 public void removeBuildOptionsOpt(int i){
1952
1953 XmlObject o = getfpdBuildOpts().getOptions();
1954 if (o == null) {
1955 return;
1956 }
1957
1958 XmlCursor cursor = o.newCursor();
1959 if (cursor.toFirstChild()) {
1960 for (int j = 0; j < i; ++j) {
1961 cursor.toNextSibling();
1962 }
1963 cursor.removeXml();
1964 if (getBuildOptionsOptCount() == 0) {
1965 cursor.toParent();
1966 cursor.removeXml();
1967 }
1968 }
1969 cursor.dispose();
1970 }
1971
1972 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1973 XmlObject o = getfpdBuildOpts().getOptions();
1974 if (o == null) {
1975 return;
1976 }
1977
1978 XmlCursor cursor = o.newCursor();
1979 if (cursor.toFirstChild()) {
1980 for (int j = 0; j < i; ++j) {
1981 cursor.toNextSibling();
1982 }
1983 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1984 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1985 }
1986 cursor.dispose();
1987 }
1988
1989 public int getBuildOptionsOptCount(){
1990 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1991 return 0;
1992 }
1993 return getfpdBuildOpts().getOptions().getOptionList().size();
1994 }
1995
1996 public void getBuildOptionsOpts(String[][] saa) {
1997 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1998 return ;
1999 }
2000
2001 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
2002 ListIterator li = lOpt.listIterator();
2003 int i = 0;
2004 while(li.hasNext()) {
2005 OptionDocument.Option opt = (OptionDocument.Option)li.next();
2006 if (opt.getBuildTargets() != null) {
2007 saa[i][0] = listToString(opt.getBuildTargets());
2008 }
2009 saa[i][1] = opt.getToolChainFamily();
2010 if (opt.getSupArchList() != null){
2011 saa[i][2] = listToString(opt.getSupArchList());
2012
2013 }
2014 saa[i][3] = opt.getToolCode();
2015 saa[i][4] = opt.getTagName();
2016 saa[i][5] = opt.getStringValue();
2017
2018 ++i;
2019 }
2020 }
2021
2022 public void genBuildOptionsFfs(String ffsKey, String type) {
2023 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2024 ffs.setFfsKey(ffsKey);
2025 if (type != null) {
2026 ffs.addNewSections().setEncapsulationType(type);
2027 }
2028 }
2029
2030 public void updateBuildOptionsFfsSectionsType(int i, String type) {
2031 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2032 if (type != null) {
2033 ffs.addNewSections().setEncapsulationType(type);
2034 }
2035 }
2036
2037 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2038 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2039 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2040 attrib.setName(name);
2041 attrib.setValue(value);
2042 }
2043
2044 /**update jth attribute of ith ffs.
2045 * @param i
2046 * @param j
2047 */
2048 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2049 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2050 XmlCursor cursor = ffs.newCursor();
2051 QName qAttrib = new QName(xmlNs, "Attribute");
2052 if (cursor.toChild(qAttrib)) {
2053 for (int k = 0; k < j; ++k) {
2054 cursor.toNextSibling(qAttrib);
2055 }
2056 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2057 attrib.setName(name);
2058 attrib.setValue(value);
2059 }
2060 cursor.dispose();
2061 }
2062
2063 public void removeBuildOptionsFfsAttribute(int i, int j){
2064 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2065 XmlCursor cursor = ffs.newCursor();
2066 QName qAttrib = new QName(xmlNs, "Attribute");
2067 if (cursor.toChild(qAttrib)) {
2068 for (int k = 0; k < j; ++k) {
2069 cursor.toNextSibling(qAttrib);
2070 }
2071 cursor.removeXml();
2072 }
2073 cursor.dispose();
2074 }
2075
2076 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2077 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2078 if (ffs == null) {
2079 return;
2080 }
2081 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2082
2083 if (sections == null){
2084 sections = ffs.addNewSections();
2085 }
2086 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2087 }
2088
2089 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2090 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2091 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2092 if (sections == null) {
2093 return;
2094 }
2095 XmlCursor cursor = sections.newCursor();
2096 QName qSection = new QName(xmlNs, "Section");
2097 if (cursor.toChild(qSection)) {
2098 for (int k = 0; k < j; ++k) {
2099 cursor.toNextSibling(qSection);
2100 }
2101 cursor.removeXml();
2102 }
2103 cursor.dispose();
2104 }
2105
2106 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2107 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2108 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2109 if (sections == null) {
2110 return;
2111 }
2112 XmlCursor cursor = sections.newCursor();
2113 QName qSection = new QName(xmlNs, "Section");
2114 if (cursor.toChild(qSection)) {
2115 for (int k = 0; k < j; ++k) {
2116 cursor.toNextSibling(qSection);
2117 }
2118 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2119 section.setSectionType(EfiSectionType.Enum.forString(type));
2120 }
2121 cursor.dispose();
2122 }
2123
2124 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2125 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2126 if (ffs == null) {
2127 return;
2128 }
2129 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2130
2131 if (sections == null){
2132 sections = ffs.addNewSections();
2133 }
2134 sections.addNewSections().setEncapsulationType(encapType);
2135 }
2136
2137 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2138 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2139 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2140 if (sections == null) {
2141 return;
2142 }
2143 XmlCursor cursor = sections.newCursor();
2144 QName qSections = new QName(xmlNs, "Sections");
2145 if (cursor.toChild(qSections)) {
2146 for (int k = 0; k < j; ++k) {
2147 cursor.toNextSibling(qSections);
2148 }
2149 cursor.removeXml();
2150 }
2151 cursor.dispose();
2152 }
2153
2154 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2155 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2156 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2157 if (sections == null) {
2158 return;
2159 }
2160 XmlCursor cursor = sections.newCursor();
2161 QName qSections = new QName(xmlNs, "Sections");
2162 if (cursor.toChild(qSections)) {
2163 for (int k = 0; k < j; ++k) {
2164 cursor.toNextSibling(qSections);
2165 }
2166 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2167 sections2.setEncapsulationType(type);
2168 }
2169 cursor.dispose();
2170 }
2171
2172 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2173 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2174 if (ffs == null) {
2175 return;
2176 }
2177 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2178 XmlCursor cursor = sections.newCursor();
2179 QName qSections = new QName(xmlNs, "Sections");
2180 if (cursor.toChild(qSections)){
2181 for (int k = 0; k < j; ++k) {
2182 cursor.toNextSibling(qSections);
2183 }
2184 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2185 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2186 }
2187 cursor.dispose();
2188 }
2189
2190 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2191 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2192 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2193 if (sections == null) {
2194 return;
2195 }
2196 XmlCursor cursor = sections.newCursor();
2197 QName qSections = new QName(xmlNs, "Sections");
2198 if (cursor.toChild(qSections)) {
2199 for (int l = 0; l < j; ++l) {
2200 cursor.toNextSibling(qSections);
2201 }
2202 if (cursor.toFirstChild()) {
2203 int m = 0;
2204 for (; m < k; ++m) {
2205 cursor.toNextSibling();
2206 }
2207 cursor.removeXml();
2208 if (m == 0) {
2209 cursor.toParent();
2210 cursor.removeXml();
2211 }
2212 }
2213 }
2214 cursor.dispose();
2215 }
2216
2217 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2218 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2219 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2220 if (sections == null) {
2221 return;
2222 }
2223 XmlCursor cursor = sections.newCursor();
2224 QName qSections = new QName(xmlNs, "Sections");
2225 if (cursor.toChild(qSections)) {
2226 for (int l = 0; l < j; ++l) {
2227 cursor.toNextSibling(qSections);
2228 }
2229 if (cursor.toFirstChild()) {
2230 for (int m = 0; m < k; ++m) {
2231 cursor.toNextSibling();
2232 }
2233 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2234 section.setSectionType(EfiSectionType.Enum.forString(type));
2235 }
2236 }
2237 cursor.dispose();
2238 }
2239
2240 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2241 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2242 if (ffs == null) {
2243 return;
2244 }
2245 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2246 XmlCursor cursor = sections.newCursor();
2247 QName qSections = new QName(xmlNs, "Sections");
2248 if (cursor.toChild(qSections)){
2249 for (int k = 0; k < j; ++k) {
2250 cursor.toNextSibling(qSections);
2251 }
2252 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2253 if (sections2.getSectionList() == null){
2254 cursor.dispose();
2255 return;
2256 }
2257 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2258 while(li.hasNext()) {
2259 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2260 if (section.isSetSectionType()) {
2261 al.add(section.getSectionType().toString());
2262 }
2263
2264 }
2265 }
2266 cursor.dispose();
2267
2268 }
2269
2270 public int getBuildOptionsFfsCount(){
2271 if (getfpdBuildOpts().getFfsList() == null) {
2272 return 0;
2273 }
2274 return getfpdBuildOpts().getFfsList().size();
2275 }
2276
2277 public void getBuildOptionsFfsKey(String[][] saa) {
2278 if (getfpdBuildOpts().getFfsList() == null) {
2279 return;
2280 }
2281 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2282 int i = 0;
2283 while(li.hasNext()){
2284 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2285 saa[i][0] = ffs.getFfsKey();
2286 ++i;
2287 }
2288 }
2289
2290 public void updateBuildOptionsFfsKey(int i, String key) {
2291 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2292 ffs.setFfsKey(key);
2293 }
2294
2295 /**Get ith FFS key and contents.
2296 * @param saa
2297 */
2298 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2299 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2300
2301 if (ffs != null) {
2302
2303 sa[0] = ffs.getFfsKey();
2304 if (ffs.getSections() != null) {
2305 if(ffs.getSections().getEncapsulationType() != null){
2306 sa[1] = ffs.getSections().getEncapsulationType();
2307 }
2308 if (ffs.getSections().getSectionList() != null){
2309 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2310 while (li.hasNext()) {
2311 firstLevelSection.add(li.next().getSectionType().toString());
2312 }
2313 }
2314 if (ffs.getSections().getSectionsList() != null) {
2315 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2316 while(li.hasNext()) {
2317 firstLevelSections.add(li.next().getEncapsulationType());
2318 }
2319 }
2320 }
2321 if (ffs.getAttributeList() != null) {
2322 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2323 while(li.hasNext()) {
2324 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2325 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2326 }
2327
2328 }
2329 }
2330
2331
2332 }
2333
2334 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2335 XmlObject o = getfpdBuildOpts();
2336 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2337
2338 XmlCursor cursor = o.newCursor();
2339 QName qFfs = new QName(xmlNs, "Ffs");
2340 if (cursor.toChild(qFfs)) {
2341 for (int j = 0; j < i; ++j) {
2342 cursor.toNextSibling(qFfs);
2343 }
2344 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2345 }
2346 cursor.dispose();
2347 return ffs;
2348 }
2349
2350 public void removeBuildOptionsFfs(int i) {
2351 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2352 if (ffs == null){
2353 return;
2354 }
2355
2356 XmlCursor cursor = ffs.newCursor();
2357 cursor.removeXml();
2358 cursor.dispose();
2359 }
2360
2361
2362
2363 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2364 if (fpdPlatformDefs == null){
2365 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2366 }
2367 return fpdPlatformDefs;
2368 }
2369
2370 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2371 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2372 return;
2373 }
2374 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2375 while(li.hasNext()) {
2376 archs.add(li.next());
2377 }
2378 }
2379
2380 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2381 if (archs != null) {
2382 getfpdPlatformDefs().setSupportedArchitectures(archs);
2383 }
2384 // else {
2385 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2386 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2387 // cursor.removeXml();
2388 // }
2389 // cursor.dispose();
2390 // }
2391 }
2392
2393 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2394 if (getfpdPlatformDefs().getBuildTargets() == null) {
2395 return;
2396 }
2397 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2398 while(li.hasNext()) {
2399 targets.add(li.next());
2400 }
2401 }
2402
2403 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2404 getfpdPlatformDefs().setBuildTargets(targets);
2405 }
2406
2407 public void genPlatformDefsSkuInfo(String id, String name) {
2408 SkuInfoDocument.SkuInfo skuInfo = null;
2409 if (getfpdPlatformDefs().getSkuInfo() == null) {
2410 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2411 }
2412 skuInfo = getfpdPlatformDefs().getSkuInfo();
2413 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2414 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2415 skuName.setSkuID(new BigInteger("0"));
2416 skuName.setStringValue("DEFAULT");
2417 }
2418 if (id.equals("0")) {
2419 return;
2420 }
2421 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2422 skuName.setSkuID(new BigInteger(id));
2423 skuName.setStringValue(name);
2424 }
2425
2426 public int getPlatformDefsSkuInfoCount(){
2427 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2428 return 0;
2429 }
2430 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2431 }
2432
2433 public void getPlatformDefsSkuInfos(String[][] saa){
2434 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2435 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2436 removeElement(getfpdDynPcdBuildDefs());
2437 fpdDynPcdBuildDefs = null;
2438 }
2439 return ;
2440 }
2441
2442 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2443 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2444 int i = 0;
2445 while(li.hasNext()) {
2446 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2447 saa[i][0] = sku.getSkuID()+"";
2448 saa[i][1] = sku.getStringValue();
2449 ++i;
2450 }
2451 }
2452
2453 public void removePlatformDefsSkuInfo(int i) {
2454 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2455 if (skuInfo == null || i == 0) {
2456 return ;
2457 }
2458
2459 XmlCursor cursor = skuInfo.newCursor();
2460 if (cursor.toFirstChild()) {
2461 for (int j = 0; j < i; ++j) {
2462 cursor.toNextSibling();
2463 }
2464 cursor.removeXml();
2465 }
2466 cursor.dispose();
2467 }
2468
2469 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2470 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2471 if (skuInfo == null || i == 0) {
2472 return ;
2473 }
2474
2475 XmlCursor cursor = skuInfo.newCursor();
2476 if (cursor.toFirstChild()) {
2477 for (int j = 0; j < i; ++j) {
2478 cursor.toNextSibling();
2479 }
2480 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2481 sku.setSkuID(new BigInteger(id));
2482 sku.setStringValue(name);
2483 }
2484 cursor.dispose();
2485 }
2486
2487 public String getPlatformDefsInterDir(){
2488 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2489 return null;
2490 }
2491 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2492 }
2493
2494 public void setPlatformDefsInterDir(String interDir){
2495 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2496 }
2497
2498 public String getPlatformDefsOutputDir() {
2499 return getfpdPlatformDefs().getOutputDirectory();
2500 }
2501
2502 public void setPlatformDefsOutputDir(String outputDir) {
2503 if (outputDir != null && outputDir.length() > 0) {
2504 getfpdPlatformDefs().setOutputDirectory(outputDir);
2505 }
2506 else{
2507 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2508 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2509 cursor.removeXml();
2510 }
2511 cursor.dispose();
2512 }
2513 }
2514
2515 public FlashDocument.Flash getfpdFlash() {
2516 if (fpdFlash == null) {
2517 fpdFlash = fpdRoot.addNewFlash();
2518 }
2519 return fpdFlash;
2520 }
2521
2522 public void genFlashDefinitionFile(String file) {
2523 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2524 if (fdf == null) {
2525 fdf = getfpdFlash().addNewFlashDefinitionFile();
2526 }
2527
2528 fdf.setStringValue(file);
2529 }
2530
2531 public String getFlashDefinitionFile() {
2532 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2533 if (fdf == null) {
2534 return "";
2535 }
2536
2537 return fdf.getStringValue();
2538 }
2539
2540 public void genFvImagesNameValue(String name, String value) {
2541
2542 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2543 if (fi == null) {
2544 fi = getfpdFlash().addNewFvImages();
2545 }
2546
2547 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2548 nv.setName(name);
2549 nv.setValue(value);
2550 }
2551
2552 public void removeFvImagesNameValue(int i){
2553
2554 XmlObject o = getfpdFlash().getFvImages();
2555 if (o == null) {
2556 return;
2557 }
2558
2559 QName qNameValue = new QName(xmlNs, "NameValue");
2560 XmlCursor cursor = o.newCursor();
2561 if (cursor.toChild(qNameValue)) {
2562 for (int j = 0; j < i; ++j) {
2563 cursor.toNextSibling(qNameValue);
2564 }
2565 cursor.removeXml();
2566 }
2567 cursor.dispose();
2568 }
2569
2570 public void updateFvImagesNameValue(int i, String name, String value){
2571
2572 XmlObject o = getfpdFlash().getFvImages();
2573 if (o == null) {
2574 return;
2575 }
2576
2577 QName qNameValue = new QName(xmlNs, "NameValue");
2578 XmlCursor cursor = o.newCursor();
2579 if (cursor.toChild(qNameValue)) {
2580 for (int j = 0; j < i; ++j) {
2581 cursor.toNextSibling(qNameValue);
2582 }
2583 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2584 nv.setName(name);
2585 nv.setValue(value);
2586 }
2587 cursor.dispose();
2588 }
2589
2590 public int getFvImagesNameValueCount() {
2591
2592 FvImagesDocument.FvImages fi = null;
2593 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2594 return 0;
2595 }
2596 return fi.getNameValueList().size();
2597 }
2598
2599 public void getFvImagesNameValues(String[][] nv) {
2600
2601 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2602 if (fi == null){
2603 return;
2604 }
2605 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2606 int i = 0;
2607 ListIterator li = l.listIterator();
2608 while (li.hasNext()) {
2609 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2610 .next();
2611 nv[i][0] = e.getName();
2612 nv[i][1] = e.getValue();
2613
2614 i++;
2615 }
2616 }
2617
2618 public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {
2619 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2620 if (fis == null || fis.getFvImageList() == null) {
2621 return;
2622 }
2623
2624 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2625 while (li.hasNext()) {
2626 FvImagesDocument.FvImages.FvImage fi = li.next();
2627 if (fi.getType().toString().equals("ImageName")) {
2628 vImageNames.addAll(fi.getFvImageNamesList());
2629 return;
2630 }
2631 }
2632 }
2633
2634 public void addFvImageFvImageNames (String[] fvNames) {
2635 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2636 if (fis == null || fis.getFvImageList() == null) {
2637 genFvImagesFvImage (fvNames, "ImageName", null);
2638 return;
2639 }
2640
2641 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2642 while (li.hasNext()) {
2643 FvImagesDocument.FvImages.FvImage fi = li.next();
2644 if (fi.getType().toString().equals("ImageName")) {
2645 addFvImageNamesInFvImage (fi, fvNames);
2646 return;
2647 }
2648 }
2649 genFvImagesFvImage (fvNames, "ImageName", null);
2650 }
2651
2652 public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) {
2653
2654 for (int i = 0; i < fvNames.length; ++i) {
2655 fi.addFvImageNames(fvNames[i]);
2656 }
2657 }
2658
2659 public void addFvImageNamesInFvImage (int i, String[] fvNames) {
2660 XmlObject o = getfpdFlash().getFvImages();
2661 if (o == null) {
2662 return;
2663 }
2664 XmlCursor cursor = o.newCursor();
2665 QName qFvImage = new QName(xmlNs, "FvImage");
2666 if (cursor.toChild(qFvImage)) {
2667 for (int j = 0; j < i; ++j) {
2668 cursor.toNextSibling(qFvImage);
2669 }
2670 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2671 addFvImageNamesInFvImage(fi, fvNames);
2672 }
2673 cursor.dispose();
2674 }
2675
2676 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2677
2678 FvImagesDocument.FvImages fis = null;
2679 if ((fis = getfpdFlash().getFvImages()) == null) {
2680 fis = getfpdFlash().addNewFvImages();
2681 }
2682
2683 //
2684 //gen FvImage with FvImageNames array
2685 //
2686 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2687 for (int i = 0; i < names.length; ++i) {
2688 fi.addFvImageNames(names[i]);
2689 }
2690 fi.setType(FvImageTypes.Enum.forString(types));
2691 if (options != null){
2692 setFvImagesFvImageFvImageOptions(options, fi);
2693 }
2694 }
2695
2696 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2697 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
2698 if (fio == null){
2699 fio = fi.addNewFvImageOptions();
2700 }
2701
2702 Set<String> key = options.keySet();
2703 Iterator<String> i = key.iterator();
2704 while (i.hasNext()) {
2705
2706 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
2707 String k = (String)i.next();
2708
2709 nv.setName(k);
2710 nv.setValue((String)options.get(k));
2711
2712 }
2713
2714 }
2715
2716
2717 public void removeFvImagesFvImage(int i) {
2718
2719 XmlObject o = getfpdFlash().getFvImages();
2720 if (o == null) {
2721 return;
2722 }
2723
2724 QName qFvImage = new QName(xmlNs, "FvImage");
2725 XmlCursor cursor = o.newCursor();
2726 if (cursor.toChild(qFvImage)) {
2727 for (int j = 0; j < i; ++j) {
2728 cursor.toNextSibling(qFvImage);
2729 }
2730 cursor.removeXml();
2731 }
2732 cursor.dispose();
2733 }
2734
2735 /**
2736 * @param oldFvName
2737 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2738 */
2739 public void updateFvImageNameAll (String oldFvName, String newFvName) {
2740 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2741 return;
2742 }
2743 ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();
2744 while (li.hasNext()) {
2745 FvImagesDocument.FvImages.FvImage fi = li.next();
2746 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
2747 if (fi.getFvImageNamesList().size() == 0) {
2748 li.remove();
2749 }
2750 }
2751 }
2752
2753 public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) {
2754 XmlObject o = getfpdFlash().getFvImages();
2755 if (o == null) {
2756 return;
2757 }
2758 XmlCursor cursor = o.newCursor();
2759 QName qFvImage = new QName(xmlNs, "FvImage");
2760 if (cursor.toChild(qFvImage)) {
2761 for (int j = 0; j < i; ++j) {
2762 cursor.toNextSibling(qFvImage);
2763 }
2764 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2765 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
2766 }
2767 cursor.dispose();
2768 }
2769 /**
2770 * @param fi
2771 * @param oldFvName The FV Name to be replaced.
2772 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
2773 */
2774 public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {
2775 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
2776 XmlCursor cursor = fi.newCursor();
2777
2778 if (cursor.toChild(qFvImageNames)) {
2779 do {
2780 String xmlValue = cursor.getTextValue();
2781 if (xmlValue.equals(oldFvName)){
2782 if (newFvName != null) {
2783 cursor.setTextValue(newFvName);
2784 }
2785 else {
2786 cursor.removeXml();
2787 }
2788 }
2789 }while (cursor.toNextSibling(qFvImageNames));
2790 }
2791
2792 cursor.dispose();
2793 }
2794
2795 /**update the Type attribute of ith FvImage with new type.
2796 * @param i
2797 * @param type
2798 */
2799 public void updateFvImagesFvImageType (int i, String type) {
2800 XmlObject o = getfpdFlash().getFvImages();
2801 if (o == null) {
2802 return;
2803 }
2804 XmlCursor cursor = o.newCursor();
2805 QName qFvImage = new QName(xmlNs, "FvImage");
2806 if (cursor.toChild(qFvImage)) {
2807 for (int j = 0; j < i; ++j) {
2808 cursor.toNextSibling(qFvImage);
2809 }
2810 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2811 fi.setType(FvImageTypes.Enum.forString(type));
2812 }
2813 cursor.dispose();
2814 }
2815
2816 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
2817
2818 XmlObject o = getfpdFlash().getFvImages();
2819 if (o == null) {
2820 return;
2821 }
2822 XmlCursor cursor = o.newCursor();
2823 QName qFvImage = new QName(xmlNs, "FvImage");
2824 if (cursor.toChild(qFvImage)) {
2825 for (int j = 0; j < i; ++j) {
2826 cursor.toNextSibling(qFvImage);
2827 }
2828 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2829 fi.setType(FvImageTypes.Enum.forString(types));
2830
2831 //
2832 // remove old FvImageNames before adding new ones
2833 //
2834 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
2835 cursor.toChild(qFvImageNames);
2836 cursor.removeXml();
2837 while (cursor.toNextSibling(qFvImageNames)) {
2838 cursor.removeXml();
2839 }
2840
2841 for (int k = 0; k < names.length; ++k) {
2842 fi.addFvImageNames(names[k]);
2843 }
2844 //
2845 // remove old FvImageOptions before adding new options
2846 //
2847 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
2848 cursor.toNextSibling(qFvImageOptions);
2849 cursor.removeXml();
2850
2851 setFvImagesFvImageFvImageOptions(options, fi);
2852 }
2853 cursor.dispose();
2854 }
2855
2856 public int getFvImagesFvImageCount(String type) {
2857
2858 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2859 return 0;
2860 }
2861 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2862 ListIterator li = l.listIterator();
2863 int i = 0;
2864 while(li.hasNext()) {
2865 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2866 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
2867 continue;
2868 }
2869
2870 ++i;
2871 }
2872
2873 return i;
2874 }
2875
2876 public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {
2877 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();
2878 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2879 return vFvImage;
2880 }
2881 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2882 ListIterator li = l.listIterator();
2883 while(li.hasNext()) {
2884 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2885 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
2886 continue;
2887 }
2888 if (fi.getFvImageNamesList().contains(fvName)) {
2889 vFvImage.add(fi);
2890 }
2891 }
2892
2893 return vFvImage;
2894 }
2895 /**
2896 * @param saa
2897 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
2898 */
2899 public void getFvImagesFvImages(String[][] saa, String type) {
2900
2901 if (getfpdFlash().getFvImages() == null) {
2902 return;
2903 }
2904 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2905 if (l == null) {
2906 return;
2907 }
2908 ListIterator li = l.listIterator();
2909 int i = 0;
2910 while(li.hasNext()) {
2911 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2912 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
2913 continue;
2914 }
2915 //
2916 // get FvImageNames array, space separated
2917 //
2918 List<String> lfn = fi.getFvImageNamesList();
2919 ListIterator lfni = lfn.listIterator();
2920 saa[i][0] = " ";
2921 while (lfni.hasNext()) {
2922 saa[i][0] += (String)lfni.next();
2923 saa[i][0] += " ";
2924 }
2925 saa[i][0] = saa[i][0].trim();
2926
2927 saa[i][1] = fi.getType()+"";
2928
2929 ++i;
2930 }
2931 }
2932
2933 public void removeFvImageNameValue (int i, String attributeName) {
2934 XmlObject o = getfpdFlash().getFvImages();
2935 if (o == null) {
2936 return;
2937 }
2938 XmlCursor cursor = o.newCursor();
2939 QName qFvImage = new QName(xmlNs, "FvImage");
2940 if (cursor.toChild(qFvImage)) {
2941 for (int j = 0; j < i; ++j) {
2942 cursor.toNextSibling(qFvImage);
2943 }
2944 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2945 removeFvImageNameValue (fi, attributeName);
2946 }
2947 cursor.dispose();
2948 }
2949 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
2950 * @param fi
2951 * @param attributeName
2952 */
2953 public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) {
2954 if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) {
2955 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
2956 while (li.hasNext()) {
2957 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
2958 if (nv.getName().equals(attributeName)) {
2959 li.remove();
2960 }
2961 }
2962 }
2963 }
2964
2965 public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) {
2966 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName(fvName, type);
2967 for (int i = 0; i < vFvImage.size(); ++i) {
2968 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
2969 removeFvImageNameValue (fi, optName);
2970 }
2971 }
2972
2973 /**Add name-value pair to FvImage element with type.
2974 * @param fvName FV name to add name-value pair.
2975 * @param type FvImage attribute.
2976 * @param name
2977 * @param value
2978 */
2979 public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {
2980 boolean fvImageExists = false;
2981 if (getfpdFlash().getFvImages() == null) {
2982 return;
2983 }
2984 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2985 if (l == null) {
2986 return;
2987 }
2988 ListIterator li = l.listIterator();
2989 while(li.hasNext()) {
2990 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2991 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
2992 continue;
2993 }
2994 if (!fi.getFvImageNamesList().contains(fvName)) {
2995 continue;
2996 }
2997 fvImageExists = true;
2998 setFvImagesFvImageNameValue (fi, name, value, null);
2999 }
3000
3001 if (!fvImageExists) {
3002 HashMap<String, String> map = new HashMap<String, String>();
3003 map.put(name, value);
3004 genFvImagesFvImage(new String[]{fvName}, type, map);
3005 }
3006 }
3007
3008 /**Add to all FvImage elements with type, the name-value pair.
3009 * @param type
3010 * @param name
3011 * @param value
3012 */
3013 public void setTypedFvImageNameValue (String type, String name, String value) {
3014 if (getfpdFlash().getFvImages() == null) {
3015 return;
3016 }
3017 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3018 if (l == null) {
3019 return;
3020 }
3021 ListIterator li = l.listIterator();
3022 while(li.hasNext()) {
3023 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3024 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3025 continue;
3026 }
3027 setFvImagesFvImageNameValue (fi, name, value, null);
3028 }
3029
3030 }
3031
3032 public void setFvImagesFvImageNameValue (int i, String name, String value) {
3033 XmlObject o = getfpdFlash().getFvImages();
3034 if (o == null) {
3035 return;
3036 }
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);
3042 }
3043 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3044 setFvImagesFvImageNameValue (fi, name, value, null);
3045 }
3046 cursor.dispose();
3047 }
3048
3049 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3050 * @param fi
3051 * @param name
3052 * @param value
3053 * @param newName
3054 */
3055 public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {
3056 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3057 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();
3058 nv.setName(name);
3059 nv.setValue(value);
3060 if (newName != null) {
3061 nv.setName(newName);
3062 }
3063 return;
3064 }
3065
3066 XmlCursor cursor = fi.getFvImageOptions().newCursor();
3067 if (cursor.toFirstChild()) {
3068 do {
3069 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();
3070 if (nv.getName().equals(name)) {
3071 nv.setValue(value);
3072 if (newName != null) {
3073 nv.setName(newName);
3074 }
3075 cursor.dispose();
3076 return;
3077 }
3078 }while (cursor.toNextSibling());
3079 }
3080
3081 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();
3082 nv.setName(name);
3083 nv.setValue(value);
3084 if (newName != null) {
3085 nv.setName(newName);
3086 }
3087 cursor.dispose();
3088 }
3089
3090 public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {
3091 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");
3092 for (int i = 0; i < vFvImage.size(); ++i) {
3093 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3094 if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3095 continue;
3096 }
3097
3098 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()
3099 .getNameValueList()
3100 .listIterator();
3101 while (li.hasNext()) {
3102 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3103 m.put(nv.getName(), nv.getValue());
3104 }
3105 }
3106 }
3107
3108 public int getFvImagePosInFvImages (String fvNameList, String type) {
3109 XmlObject o = getfpdFlash().getFvImages();
3110 if (o == null) {
3111 return -1;
3112 }
3113
3114 int pos = -1;
3115 String[] fvNameArray = fvNameList.trim().split(" ");
3116 Vector<String> vFvNames = new Vector<String>();
3117
3118
3119 XmlCursor cursor = o.newCursor();
3120 QName qFvImage = new QName(xmlNs, "FvImage");
3121 if (cursor.toChild(qFvImage)) {
3122 do {
3123 pos++;
3124 vFvNames.removeAllElements();
3125 for (int i = 0; i < fvNameArray.length; ++i) {
3126 vFvNames.add(fvNameArray[i]);
3127 }
3128 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3129 if (!fi.getType().toString().equals(type)) {
3130 continue;
3131 }
3132 if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) {
3133 continue;
3134 }
3135 ListIterator<String> li = fi.getFvImageNamesList().listIterator();
3136 while (li.hasNext()) {
3137 String name = li.next();
3138 vFvNames.remove(name);
3139 }
3140 if (vFvNames.size() == 0) {
3141 cursor.dispose();
3142 return pos;
3143 }
3144
3145 }while (cursor.toNextSibling(qFvImage));
3146
3147 }
3148 cursor.dispose();
3149 return -1;
3150 }
3151 /**Get FvImage Options for FvImage i
3152 * @param i the ith FvImage
3153 */
3154 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
3155 XmlObject o = getfpdFlash().getFvImages();
3156 if (o == null) {
3157 return;
3158 }
3159 XmlCursor cursor = o.newCursor();
3160 QName qFvImage = new QName(xmlNs, "FvImage");
3161 if (cursor.toChild(qFvImage)) {
3162 for (int j = 0; j < i; ++j) {
3163 cursor.toNextSibling(qFvImage);
3164 }
3165 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3166 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
3167 cursor.dispose();
3168 return;
3169 }
3170 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3171 while(li.hasNext()){
3172 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3173 m.put(nv.getName(), nv.getValue());
3174 }
3175 }
3176 cursor.dispose();
3177 }
3178
3179 /**
3180 Get platform header element
3181 @return PlatformHeaderDocument.PlatformHeader
3182 **/
3183 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
3184 if (fpdHdr == null) {
3185 fpdHdr = fpdRoot.addNewPlatformHeader();
3186 }
3187
3188 return fpdHdr;
3189 }
3190
3191 public String getFpdHdrPlatformName() {
3192 return getFpdHdr().getPlatformName();
3193 }
3194
3195 public String getFpdHdrGuidValue() {
3196 return getFpdHdr().getGuidValue();
3197 }
3198
3199 public String getFpdHdrVer() {
3200 return getFpdHdr().getVersion();
3201 }
3202
3203 public String getFpdHdrAbs() {
3204 return getFpdHdr().getAbstract();
3205 }
3206
3207 public String getFpdHdrDescription() {
3208 return getFpdHdr().getDescription();
3209 }
3210
3211 public String getFpdHdrCopyright() {
3212 return getFpdHdr().getCopyright();
3213 }
3214
3215 public String getFpdHdrLicense() {
3216 LicenseDocument.License l = getFpdHdr().getLicense();
3217 if (l == null) {
3218 return null;
3219 }
3220 return l.getStringValue();
3221 }
3222
3223 public String getFpdHdrUrl() {
3224 LicenseDocument.License l = getFpdHdr().getLicense();
3225 if (l == null) {
3226 return null;
3227 }
3228 return l.getURL();
3229 }
3230
3231 public String getFpdHdrSpec() {
3232
3233 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3234 // return getFpdHdr().getSpecification();
3235 }
3236
3237 public void setFpdHdrPlatformName(String name){
3238 getFpdHdr().setPlatformName(name);
3239 }
3240
3241 public void setFpdHdrGuidValue(String guid){
3242 getFpdHdr().setGuidValue(guid);
3243 }
3244
3245 public void setFpdHdrVer(String v){
3246 getFpdHdr().setVersion(v);
3247 }
3248
3249 public void setFpdHdrAbs(String abs) {
3250 getFpdHdr().setAbstract(abs);
3251 }
3252
3253 public void setFpdHdrDescription(String desc){
3254 getFpdHdr().setDescription(desc);
3255 }
3256
3257 public void setFpdHdrCopyright(String cr) {
3258 getFpdHdr().setCopyright(cr);
3259 }
3260
3261 public void setFpdHdrLicense(String license){
3262 LicenseDocument.License l = getFpdHdr().getLicense();
3263 if (l == null) {
3264 getFpdHdr().addNewLicense().setStringValue(license);
3265 }
3266 else {
3267 l.setStringValue(license);
3268 }
3269 }
3270
3271 public void setFpdHdrUrl(String url){
3272 LicenseDocument.License l = getFpdHdr().getLicense();
3273
3274 l.setURL(url);
3275
3276 }
3277
3278 public void setFpdHdrSpec(String s){
3279 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3280 getFpdHdr().setSpecification(s);
3281 }
3282 /**
3283 Save the processed xml contents to file
3284
3285 @param fpdFile The file to save xml contents
3286 @throws IOException Exceptions during file operation
3287 **/
3288 public void saveAs(File fpdFile) throws IOException {
3289
3290 XmlOptions options = new XmlOptions();
3291
3292 options.setCharacterEncoding("UTF-8");
3293 options.setSavePrettyPrint();
3294 options.setSavePrettyPrintIndent(2);
3295 try {
3296 fpdd.save(fpdFile, options);
3297 } catch (IOException e) {
3298 e.printStackTrace();
3299 }
3300
3301 }
3302
3303 private String listToString(List l) {
3304 if (l == null) {
3305 return null;
3306 }
3307 String s = " ";
3308 ListIterator li = l.listIterator();
3309 while(li.hasNext()) {
3310 s += li.next();
3311 s += " ";
3312 }
3313 return s.trim();
3314 }
3315
3316 private void removeElement(XmlObject o) {
3317 XmlCursor cursor = o.newCursor();
3318 cursor.removeXml();
3319 cursor.dispose();
3320 }
3321 }
3322
3323 class PcdItemTypeConflictException extends Exception {
3324
3325 /**
3326 *
3327 */
3328 private static final long serialVersionUID = 1L;
3329 private String details = null;
3330
3331 PcdItemTypeConflictException(String pcdName, String info){
3332 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
3333 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();
3334 }
3335
3336 public String getMessage() {
3337 return details;
3338 }
3339 }
3340
3341 class PcdDeclNotFound extends Exception {
3342
3343 /**
3344 *
3345 */
3346 private static final long serialVersionUID = 1L;
3347 private String details = null;
3348
3349 PcdDeclNotFound(String info) {
3350 details = "PcdDeclNotFound: " + info;
3351 }
3352
3353 public String getMessage() {
3354 return details;
3355 }
3356 }
3357
3358 class PcdValueMalFormed extends Exception {
3359
3360 /**
3361 *
3362 */
3363 private static final long serialVersionUID = 1L;
3364 private String details = null;
3365
3366 PcdValueMalFormed(String info) {
3367 details = "PcdValueMalFormed: " + info;
3368 }
3369
3370 public String getMessage() {
3371 return details;
3372 }
3373 }