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