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