]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Adjust Platform Definition and Module SA operations in FPD editor.
[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.ModuleSurfaceAreaDocument;
44 import org.tianocore.OptionDocument;
45 import org.tianocore.OptionsDocument;
46 import org.tianocore.PcdBuildDefinitionDocument;
47 import org.tianocore.PcdCodedDocument;
48 import org.tianocore.PcdDataTypes;
49 import org.tianocore.PcdDeclarationsDocument;
50 import org.tianocore.PcdItemTypes;
51 import org.tianocore.PlatformDefinitionsDocument;
52 import org.tianocore.PlatformSurfaceAreaDocument;
53 import org.tianocore.FvImageTypes;
54 import org.tianocore.FvImagesDocument;
55 import org.tianocore.LicenseDocument;
56 import org.tianocore.PlatformHeaderDocument;
57 import org.tianocore.SkuInfoDocument;
58 import org.tianocore.UserDefinedAntTasksDocument;
59 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
60 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
61 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
62 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
63
64 /**
65 This class processes fpd file contents such as add remove xml elements.
66 @since PackageEditor 1.0
67 **/
68 public class FpdFileContents {
69
70 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
71
72 private PlatformSurfaceAreaDocument fpdd = null;
73
74 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
75
76 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
77
78 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
79
80 private FlashDocument.Flash fpdFlash = null;
81
82 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
83
84 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
85
86 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
87
88 public static HashMap<String, ArrayList<String>> dynPcdMap = null;
89
90 /**
91 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
92 */
93 public void initDynPcdMap() {
94 if (dynPcdMap == null) {
95 dynPcdMap = new HashMap<String, ArrayList<String>>();
96 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
97 if (l == null) {
98 return;
99 }
100 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
101 while (li.hasNext()) {
102 ModuleSADocument.ModuleSA msa = li.next();
103 if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {
104 continue;
105 }
106 String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +
107 " " + msa.getPackageGuid() + " " + msa.getPackageVersion();
108 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();
109 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
110 while (lpi.hasNext()) {
111 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
112 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
113 if (dynPcdMap.get(pcdKey) == null) {
114 ArrayList<String> al = new ArrayList<String>();
115 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
116 dynPcdMap.put(pcdKey, al);
117 }
118 else{
119 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
120 }
121 }
122 }
123 }
124 }
125 /**
126 Constructor to create a new spd file
127 **/
128 public FpdFileContents() {
129
130 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
131 fpdRoot = fpdd.addNewPlatformSurfaceArea();
132
133 }
134
135 /**
136 Constructor for existing document object
137 @param psa
138 **/
139 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
140 fpdRoot = fpd;
141 fpdHdr = fpdRoot.getPlatformHeader();
142 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
143 fpdBuildOpts = fpdRoot.getBuildOptions();
144 fpdFrameworkModules = fpdRoot.getFrameworkModules();
145 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
146 fpdFlash = fpdRoot.getFlash();
147 }
148
149 /**
150 Constructor based on an existing spd file
151
152 @param f Existing spd file
153 **/
154 public FpdFileContents(File f) {
155 try {
156 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
157 fpdRoot = fpdd.getPlatformSurfaceArea();
158 } catch (Exception e) {
159 System.out.println(e.toString());
160 }
161 }
162
163 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
164 if (fpdDynPcdBuildDefs == null){
165 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
166 }
167 return fpdDynPcdBuildDefs;
168 }
169
170 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
171 if (fpdFrameworkModules == null){
172 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
173 }
174 return fpdFrameworkModules;
175 }
176
177 public int getFrameworkModulesCount() {
178 if (getfpdFrameworkModules().getModuleSAList() == null){
179 return 0;
180 }
181 return getfpdFrameworkModules().getModuleSAList().size();
182 }
183
184 public void getFrameworkModulesInfo(String[][] saa) {
185 if (getFrameworkModulesCount() == 0){
186 return;
187 }
188
189 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
190 int i = 0;
191 while(li.hasNext()) {
192 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();
193 saa[i][1] = msa.getModuleGuid();
194 saa[i][2] = msa.getModuleVersion();
195
196 saa[i][3] = msa.getPackageGuid();
197 saa[i][4] = msa.getPackageVersion();
198 // saa[i][4] = listToString(msa.getSupArchList());
199 ++i;
200 }
201 }
202
203 public ModuleSADocument.ModuleSA getModuleSA(String key) {
204 String[] s = key.split(" ");
205 if (getfpdFrameworkModules().getModuleSAList() == null) {
206 return null;
207 }
208 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
209 while(li.hasNext()) {
210 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();
211 if (msa.getModuleGuid().equals(s[0]) && msa.getModuleVersion().equals(s[1])
212 && msa.getPackageGuid().equals(s[2]) && msa.getPackageVersion().equals(s[3])) {
213
214 return msa;
215 }
216 }
217 return null;
218 }
219 public void removeModuleSA(int i) {
220 XmlObject o = getfpdFrameworkModules();
221 if (o == null) {
222 return;
223 }
224
225 XmlCursor cursor = o.newCursor();
226 if (cursor.toFirstChild()) {
227 for (int j = 0; j < i; ++j) {
228 cursor.toNextSibling();
229 }
230 //
231 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
232 //
233 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
234 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
235 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion();
236 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
237 if (pcdBuildDef != null) {
238 maintainDynPcdMap(pcdBuildDef, moduleInfo);
239 }
240 cursor.removeXml();
241 }
242 cursor.dispose();
243 }
244
245 private void maintainDynPcdMap(PcdBuildDefinitionDocument.PcdBuildDefinition o, String moduleInfo) {
246 XmlCursor cursor = o.newCursor();
247 boolean fromLibInstance = false;
248 if (!cursor.toFirstChild()){
249 return;
250 }
251 //
252 // deal with first child, same process in the while loop below for siblings.
253 //
254 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
255 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
256 ArrayList<String> al = dynPcdMap.get(pcdKey);
257 for(int i = 0; i < al.size(); ++i){
258 if (al.get(i).startsWith(moduleInfo)){
259 fromLibInstance = true;
260 break;
261 }
262 }
263 al.remove(moduleInfo + " " + pcdData.getItemType().toString());
264 if (al.size() == 0) {
265 dynPcdMap.remove(pcdKey);
266 }
267
268 if (pcdData.getItemType().toString().equals("DYNAMIC")) {
269 if (dynPcdMap.get(pcdKey) == null) {
270 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());
271 }
272 }
273 if (fromLibInstance){
274 cursor.removeXml();
275 }
276 while(cursor.toNextSibling()) {
277 fromLibInstance = false;
278 pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
279 //
280 // remove each pcd record from dynPcdMap
281 //
282 pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
283 al = dynPcdMap.get(pcdKey);
284 for(int i = 0; i < al.size(); ++i){
285 if (al.get(i).startsWith(moduleInfo)){
286 fromLibInstance = true;
287 break;
288 }
289 }
290 al.remove(moduleInfo + " " + pcdData.getItemType().toString());
291 if (al.size() == 0) {
292 dynPcdMap.remove(pcdKey);
293 }
294
295 if (pcdData.getItemType().toString().equals("DYNAMIC")) {
296 //
297 // First check whether this is the only consumer of this dyn pcd.
298 //
299 if (dynPcdMap.get(pcdKey) == null) {
300 //
301 // delete corresponding entry in DynamicPcdBuildData
302 //
303 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());
304 }
305 }
306 if (fromLibInstance){
307 cursor.removeXml();
308 }
309 }
310 }
311 //
312 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
313 //
314 public int getPcdDataCount(String key){
315 ModuleSADocument.ModuleSA msa = getModuleSA(key);
316 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
317 return 0;
318 }
319 return msa.getPcdBuildDefinition().getPcdDataList().size();
320 }
321
322 public void getPcdData(String key, String[][] saa) {
323 ModuleSADocument.ModuleSA msa = getModuleSA(key);
324 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
325 return;
326 }
327 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
328 for (int i = 0; i < saa.length; ++i) {
329 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
330 saa[i][0] = pcdData.getCName();
331 saa[i][1] = pcdData.getTokenSpaceGuidCName();
332 saa[i][2] = pcdData.getItemType().toString();
333 saa[i][3] = pcdData.getToken().toString();
334 saa[i][4] = pcdData.getDatumType().toString();
335 saa[i][5] = pcdData.getValue();
336
337 }
338 }
339 //
340 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
341 //
342 public int getLibraryInstancesCount(String key) {
343 ModuleSADocument.ModuleSA msa = getModuleSA(key);
344 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
345 return 0;
346 }
347 return msa.getLibraries().getInstanceList().size();
348 }
349
350 public void getLibraryInstances(String key, String[][] saa){
351 ModuleSADocument.ModuleSA msa = getModuleSA(key);
352 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
353 return ;
354 }
355
356 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
357 for (int i = 0; i < saa.length; ++i) {
358 LibrariesDocument.Libraries.Instance instance = li.next();
359 saa[i][1] = instance.getModuleGuid();
360 saa[i][2] = instance.getModuleVersion();
361 saa[i][3] = instance.getPackageGuid();
362 saa[i][4] = instance.getPackageVersion();
363 }
364 }
365
366 public void removeLibraryInstances(String key) {
367 ModuleSADocument.ModuleSA msa = getModuleSA(key);
368 if (msa == null || msa.getLibraries() == null){
369 return ;
370 }
371
372 XmlCursor cursor = msa.getLibraries().newCursor();
373 cursor.removeXml();
374 cursor.dispose();
375 }
376
377 public void genLibraryInstance(String mg, String mv, String pg, String pv, String key) {
378 ModuleSADocument.ModuleSA msa = getModuleSA(key);
379 if (msa == null){
380 msa = getfpdFrameworkModules().addNewModuleSA();
381 }
382 LibrariesDocument.Libraries libs = msa.getLibraries();
383 if(libs == null){
384 libs = msa.addNewLibraries();
385 }
386
387 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
388 instance.setModuleGuid(mg);
389 instance.setModuleVersion(mv);
390 instance.setPackageGuid(pg);
391 instance.setPackageVersion(pv);
392
393 }
394 /**add pcd information of module mi to a ModuleSA.
395 * @param mi
396 * @param moduleSa if null, generate a new ModuleSA.
397 */
398 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, ModuleSADocument.ModuleSA moduleSa){
399 //ToDo add Arch filter
400
401 try {
402 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);
403 if (msa.getPcdCoded() == null) {
404 return;
405 }
406 if (moduleSa == null) {
407 moduleSa = genModuleSA(mi);
408 }
409 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
410 m.put("ModuleSurfaceArea", msa);
411 SurfaceAreaQuery.setDoc(m);
412 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);
413 //
414 // Implementing InitializePlatformPcdBuildDefinitions
415 //
416 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
417 ListIterator li = l.listIterator();
418 while(li.hasNext()) {
419 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
420 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
421 if (spdPcd == null) {
422 //
423 // ToDo Error
424 //
425 break;
426 }
427 //
428 // AddItem to ModuleSA PcdBuildDefinitions
429 //
430 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
431 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
432 }
433
434 }
435 catch (Exception e){
436 e.printStackTrace();
437 }
438
439 }
440
441 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
442
443 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
444 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
445 for (int i = 0; i < depPkgs.length; ++i) {
446 m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));
447 SurfaceAreaQuery.setDoc(m);
448 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();
449 if (xo == null) {
450 continue;
451 }
452 for (int j = 0; j < xo.length; ++j) {
453 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
454 if (msaPcd.getTokenSpaceGuidCName() == null) {
455 if (spdPcd.getCName().equals(msaPcd.getCName())) {
456 return spdPcd;
457 }
458 }
459 else{
460 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
461 return spdPcd;
462 }
463 }
464
465 }
466
467 }
468 return null;
469 }
470
471 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi) {
472 PackageIdentification pi = GlobalData.getPackageForModule(mi);
473 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
474 msa.setModuleGuid(mi.getGuid());
475 msa.setModuleVersion(mi.getVersion());
476 msa.setPackageGuid(pi.getGuid());
477 msa.setPackageVersion(pi.getVersion());
478
479 return msa;
480 }
481
482 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) {
483 if (moduleSa.getPcdBuildDefinition() == null){
484 moduleSa.addNewPcdBuildDefinition();
485 }
486 //
487 // constructe pcd to modulesa mapping first.
488 // Attention : for any error condition, remove from map this pcd.
489 //
490 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
491 if (pcdConsumer == null) {
492 pcdConsumer = new ArrayList<String>();
493 }
494 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
495 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion()
496 + " " + itemType;
497 pcdConsumer.add(listValue);
498 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
499 //
500 // Special dynamic type, if this pcd already exists in other ModuleSA
501 //
502 if (itemType.equals("DYNAMIC")) {
503
504 ListIterator li = pcdConsumer.listIterator();
505 while(li.hasNext()) {
506 String value = li.next().toString();
507 String[] valuePart= value.split(" ");
508 if (!valuePart[4].equals("DYNAMIC")) {
509 //ToDo error for same pcd, other type than dynamic
510 pcdConsumer.remove(listValue);
511 return;
512 }
513 }
514 }
515 else {
516 ListIterator li = pcdConsumer.listIterator();
517 while(li.hasNext()) {
518 String value = li.next().toString();
519 String[] valuePart= value.split(" ");
520 if (valuePart[4].equals("DYNAMIC")) {
521 //ToDo error for same pcd, other type than non-dynamic
522 pcdConsumer.remove(listValue);
523 return;
524 }
525 }
526 }
527
528 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
529 fpdPcd.setCName(cName);
530 fpdPcd.setToken(token);
531 fpdPcd.setTokenSpaceGuidCName(tsGuid);
532 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
533 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
534
535 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
536 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
537 //
538 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
539 // so need to add one dyn pcd.
540 //
541 if (al.size() == 1) {
542 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
543 }
544 }
545 else {
546 if (defaultVal != null){
547 fpdPcd.setValue(defaultVal);
548 }
549 else {
550 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
551 fpdPcd.setValue("0");
552 }
553 if (dataType.equals("BOOLEAN")){
554 fpdPcd.setValue("false");
555 }
556 if (dataType.equals("VOID*")) {
557 fpdPcd.setValue("");
558 }
559 }
560 if (dataType.equals("UINT8")){
561 fpdPcd.setMaxDatumSize(1);
562 }
563 if (dataType.equals("UINT16")) {
564 fpdPcd.setMaxDatumSize(2);
565 }
566 if (dataType.equals("UINT32")) {
567 fpdPcd.setMaxDatumSize(4);
568 }
569 if (dataType.equals("UINT64")){
570 fpdPcd.setMaxDatumSize(8);
571 }
572 if (dataType.equals("BOOLEAN")){
573 fpdPcd.setMaxDatumSize(1);
574 }
575 if (dataType.equals("VOID*")) {
576 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
577 fpdPcd.setMaxDatumSize(maxSize);
578 }
579 }
580 }
581
582 private int setMaxSizeForPointer(String datum) {
583 if (datum == null) {
584 return 0;
585 }
586 char ch = datum.charAt(0);
587 int start, end;
588 String strValue;
589 //
590 // For void* type PCD, only three datum is support:
591 // 1) Unicode: string with start char is "L"
592 // 2) Ansci: String is ""
593 // 3) byte array: String start char "{"
594 //
595 if (ch == 'L') {
596 start = datum.indexOf('\"');
597 end = datum.lastIndexOf('\"');
598 if ((start > end) ||
599 (end > datum.length())||
600 ((start == end) && (datum.length() > 0))) {
601 //ToDo Error handling here
602 }
603
604 strValue = datum.substring(start + 1, end);
605 return strValue.length() * 2;
606 } else if (ch == '\"'){
607 start = datum.indexOf('\"');
608 end = datum.lastIndexOf('\"');
609 if ((start > end) ||
610 (end > datum.length())||
611 ((start == end) && (datum.length() > 0))) {
612
613 }
614 strValue = datum.substring(start + 1, end);
615 return strValue.length();
616 } else if (ch =='{') {
617 String[] strValueArray;
618
619 start = datum.indexOf('{');
620 end = datum.lastIndexOf('}');
621 strValue = datum.substring(start + 1, end);
622 strValue = strValue.trim();
623 if (strValue.length() == 0) {
624 return 0;
625 }
626 strValueArray = strValue.split(",");
627 for (int index = 0; index < strValueArray.length; index ++) {
628 Integer value = Integer.decode(strValueArray[index].trim());
629
630 if (value > 0xFF) {
631 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
632 // "it is byte array in fact. But the element of %s exceed the byte range",
633
634 }
635 }
636 return strValueArray.length;
637
638
639 } else {
640 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
641 // "1) UNICODE string: like L\"xxxx\";\r\n"+
642 // "2) ANSIC string: like \"xxx\";\r\n"+
643 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
644 // "but the datum in seems does not following above format!",
645 return -1;
646
647 }
648 }
649
650 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
651 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
652
653 return al;
654 }
655
656 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
657
658 return dynPcdMap.get("pcdKey");
659 }
660
661 public int getDynamicPcdBuildDataCount() {
662 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
663 return 0;
664 }
665 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
666 }
667
668 public void getDynamicPcdBuildData(String[][] saa) {
669 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
670 return ;
671 }
672 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
673 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
674 int i = 0;
675 while(li.hasNext()) {
676 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
677 saa[i][0] = dynPcd.getCName();
678 saa[i][1] = dynPcd.getToken().toString();
679 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
680 saa[i][3] = dynPcd.getMaxDatumSize()+"";
681 saa[i][4] = dynPcd.getDatumType().toString();
682
683 ++i;
684 }
685 }
686
687 private void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) {
688 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
689 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
690 dynPcdData.setCName(cName);
691 dynPcdData.setToken(token);
692 dynPcdData.setTokenSpaceGuidCName(tsGuid);
693 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
694
695 BigInteger bigInt = new BigInteger("0");
696 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
697 skuInfo.setSkuId(bigInt);
698 if (defaultVal != null){
699 skuInfo.setValue(defaultVal);
700 }
701 else {
702 if (dataType.equals("UINT8")){
703 skuInfo.setValue("0");
704 }
705 if (dataType.equals("UINT16")) {
706 skuInfo.setValue("0");
707 }
708 if (dataType.equals("UINT32")) {
709 skuInfo.setValue("0");
710 }
711 if (dataType.equals("UINT64")){
712 skuInfo.setValue("0");
713 }
714 if (dataType.equals("BOOLEAN")){
715 skuInfo.setValue("false");
716 }
717 if (dataType.equals("VOID*")) {
718 skuInfo.setValue("");
719 }
720 }
721 if (dataType.equals("UINT8")){
722 dynPcdData.setMaxDatumSize(1);
723 }
724 if (dataType.equals("UINT16")) {
725 dynPcdData.setMaxDatumSize(2);
726 }
727 if (dataType.equals("UINT32")) {
728 dynPcdData.setMaxDatumSize(4);
729 }
730 if (dataType.equals("UINT64")){
731 dynPcdData.setMaxDatumSize(8);
732 }
733 if (dataType.equals("BOOLEAN")){
734 dynPcdData.setMaxDatumSize(1);
735 }
736 if (dataType.equals("VOID*")) {
737 int maxSize = setMaxSizeForPointer(defaultVal);
738 dynPcdData.setMaxDatumSize(maxSize);
739 }
740 }
741
742 private void removeDynamicPcdBuildData(String cName, String tsGuid) {
743 XmlObject o = getfpdDynPcdBuildDefs();
744
745 XmlCursor cursor = o.newCursor();
746 if (cursor.toFirstChild()) {
747 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
748 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
749 while (!(pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid))) {
750 cursor.toNextSibling();
751 pcdBuildData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
752 }
753
754 cursor.removeXml();
755 }
756 cursor.dispose();
757 }
758 //
759 // Get the Sku Info count of ith dyn pcd element.
760 //
761 public int getDynamicPcdSkuInfoCount(int i){
762 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
763 return 0;
764 }
765
766 int skuInfoCount = 0;
767 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
768 if (cursor.toFirstChild()) {
769 for (int j = 0; j < i; ++j) {
770 cursor.toNextSibling();
771 }
772 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
773 if (pcdData.getSkuInfoList() == null) {
774 skuInfoCount = 0;
775 }
776 else {
777 skuInfoCount = pcdData.getSkuInfoList().size();
778 }
779 }
780 cursor.dispose();
781 return skuInfoCount;
782 }
783
784 public void getDynamicPcdSkuInfos(int i, String[][] saa){
785 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
786 return;
787 }
788
789 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
790 if (cursor.toFirstChild()) {
791 for (int j = 0; j < i; ++j) {
792 cursor.toNextSibling();
793 }
794 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
795 if (pcdData.getSkuInfoList() == null) {
796 cursor.dispose();
797 return;
798 }
799 else {
800 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
801 int k = 0;
802 while (li.hasNext()) {
803 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
804 saa[k][0] = skuInfo.getSkuId()+"";
805 saa[k][1] = skuInfo.getVariableName();
806 saa[k][2] = skuInfo.getVariableGuid();
807 saa[k][3] = skuInfo.getVariableOffset();
808 saa[k][4] = skuInfo.getHiiDefaultValue();
809 saa[k][5] = skuInfo.getVpdOffset();
810 saa[k][6] = skuInfo.getValue();
811 ++k;
812 }
813
814 }
815 }
816 cursor.dispose();
817
818 }
819
820 public String getDynamicPcdBuildDataValue(int i){
821 String value = null;
822 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
823 return value;
824 }
825
826 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
827 if (cursor.toFirstChild()) {
828 for (int j = 0; j < i; ++j) {
829 cursor.toNextSibling();
830 }
831 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
832 if (pcdData.getSkuInfoList() == null) {
833 value = null;
834 }
835 else {
836 value = pcdData.getSkuInfoArray(0).getValue();
837 }
838 }
839 cursor.dispose();
840 return value;
841 }
842
843 public String getDynamicPcdBuildDataVpdOffset(int i){
844 String vpdOffset = null;
845 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
846 return vpdOffset;
847 }
848
849 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
850 if (cursor.toFirstChild()) {
851 for (int j = 0; j < i; ++j) {
852 cursor.toNextSibling();
853 }
854 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
855 if (pcdData.getSkuInfoList() == null) {
856 vpdOffset = null;
857 }
858 else {
859 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
860 }
861 }
862 cursor.dispose();
863 return vpdOffset;
864 }
865
866 public void removeDynamicPcdBuildDataSkuInfo(int i) {
867 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
868 return;
869 }
870
871 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
872 if (cursor.toFirstChild()) {
873 for (int j = 0; j < i; ++j) {
874 cursor.toNextSibling();
875 }
876 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
877 if (pcdData.getSkuInfoList() == null) {
878 cursor.dispose();
879 return;
880 }
881 else {
882 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
883 cursor.toChild(qSkuInfo);
884 cursor.removeXml();
885 }
886 }
887 cursor.dispose();
888 }
889 //
890 // generate sku info for ith dyn pcd build data.
891 //
892 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
893 String hiiDefault, String vpdOffset, String value, int i) {
894 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
895 return;
896 }
897
898 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
899 if (cursor.toFirstChild()) {
900 for (int j = 0; j < i; ++j) {
901 cursor.toNextSibling();
902 }
903 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
904 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
905 skuInfo.setSkuId(new BigInteger(id));
906 if (varName != null){
907 skuInfo.setVariableName(varName);
908 skuInfo.setVariableGuid(varGuid);
909 skuInfo.setVariableOffset(varOffset);
910 skuInfo.setHiiDefaultValue(hiiDefault);
911 }
912 else if (vpdOffset != null){
913 skuInfo.setVpdOffset(vpdOffset);
914 }
915 else{
916 skuInfo.setValue(value);
917 }
918 }
919 }
920
921 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
922 String hiiDefault, String vpdOffset, String value, int i){
923 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
924 return;
925 }
926
927 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
928 if (cursor.toFirstChild()) {
929 for (int j = 0; j < i; ++j) {
930 cursor.toNextSibling();
931 }
932 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
933 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
934 while (li.hasNext()) {
935 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
936 if (skuInfo.getSkuId().toString().equals(id)){
937 if (varName != null){
938 skuInfo.setVariableName(varName);
939 skuInfo.setVariableGuid(varGuid);
940 skuInfo.setVariableOffset(varOffset);
941 skuInfo.setHiiDefaultValue(hiiDefault);
942 }
943 else if (vpdOffset != null){
944 skuInfo.setVpdOffset(vpdOffset);
945 }
946 else{
947 skuInfo.setValue(value);
948 }
949 break;
950 }
951 }
952 }
953 }
954
955 public void removePcdDataFromLibraryInstance(String moduleKey, String libInstanceKey){
956 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
957 //
958 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
959 //
960 maintainDynPcdMap(moduleSa.getPcdBuildDefinition(), libInstanceKey);
961
962 }
963
964 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
965 if (fpdBuildOpts == null) {
966 fpdBuildOpts = fpdRoot.addNewBuildOptions();
967 }
968 return fpdBuildOpts;
969 }
970
971 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
972 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
973 if (udats == null) {
974 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
975 }
976
977 AntTaskDocument.AntTask at = udats.addNewAntTask();
978 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
979 }
980
981 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
982 at.setId(new Integer(id));
983 if (fileName != null){
984 at.setFilename(fileName);
985 }
986 if (execOrder != null) {
987 at.setAntCmdOptions(execOrder);
988 }
989 }
990
991 public void removeBuildOptionsUserDefAntTask(int i) {
992 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
993 if (o == null) {
994 return;
995 }
996 XmlCursor cursor = o.newCursor();
997 if (cursor.toFirstChild()) {
998 for (int j = 0; j < i; ++j) {
999 cursor.toNextSibling();
1000 }
1001 cursor.removeXml();
1002 }
1003 cursor.dispose();
1004 }
1005
1006 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1007 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1008 if (o == null) {
1009 return;
1010 }
1011 XmlCursor cursor = o.newCursor();
1012 if (cursor.toFirstChild()) {
1013 for (int j = 0; j < i; ++j) {
1014 cursor.toNextSibling();
1015 }
1016 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1017 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1018 }
1019 cursor.dispose();
1020 }
1021
1022 public int getBuildOptionsUserDefAntTaskCount() {
1023 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1024 if (udats == null || udats.getAntTaskList() == null) {
1025 return 0;
1026 }
1027
1028 return udats.getAntTaskList().size();
1029 }
1030
1031 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1032 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1033 if (udats == null || udats.getAntTaskList() == null) {
1034 return ;
1035 }
1036
1037 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1038 ListIterator li = l.listIterator();
1039 int i = 0;
1040 while (li.hasNext()) {
1041 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1042 saa[i][0] = at.getId() + "";
1043 saa[i][1] = saa[i][2] = "";
1044 if (at.getFilename() != null){
1045 saa[i][1] = at.getFilename();
1046 }
1047 if (at.getAntCmdOptions() != null) {
1048 saa[i][2] = at.getAntCmdOptions();
1049 }
1050 ++i;
1051 }
1052 }
1053 public void genBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {
1054 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1055 if (opts == null) {
1056 opts = getfpdBuildOpts().addNewOptions();
1057 }
1058 OptionDocument.Option opt = opts.addNewOption();
1059 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1060 }
1061
1062 private void setBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents, OptionDocument.Option opt){
1063 opt.setStringValue(contents);
1064 // opt.setBuildTargets(buildTargets);
1065 opt.setToolChainFamily(toolChain);
1066 opt.setTagName(tagName);
1067 opt.setToolCode(toolCmd);
1068 String[] s = archList.split(" ");
1069 ArrayList<String> al = new ArrayList<String>();
1070 for (int i = 0; i < s.length; ++i) {
1071 al.add(s[i]);
1072 }
1073 opt.setSupArchList(al);
1074 }
1075
1076 public void removeBuildOptionsOpt(int i){
1077
1078 XmlObject o = getfpdBuildOpts().getOptions();
1079 if (o == null) {
1080 return;
1081 }
1082
1083 XmlCursor cursor = o.newCursor();
1084 if (cursor.toFirstChild()) {
1085 for (int j = 0; j < i; ++j) {
1086 cursor.toNextSibling();
1087 }
1088 cursor.removeXml();
1089 }
1090 cursor.dispose();
1091 }
1092
1093 public void updateBuildOptionsOpt(int i, String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {
1094 XmlObject o = getfpdBuildOpts().getOptions();
1095 if (o == null) {
1096 return;
1097 }
1098
1099 XmlCursor cursor = o.newCursor();
1100 if (cursor.toFirstChild()) {
1101 for (int j = 0; j < i; ++j) {
1102 cursor.toNextSibling();
1103 }
1104 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1105 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1106 }
1107 cursor.dispose();
1108 }
1109
1110 public int getBuildOptionsOptCount(){
1111 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1112 return 0;
1113 }
1114 return getfpdBuildOpts().getOptions().getOptionList().size();
1115 }
1116
1117 public void getBuildOptionsOpts(String[][] saa) {
1118 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1119 return ;
1120 }
1121
1122 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1123 ListIterator li = lOpt.listIterator();
1124 int i = 0;
1125 while(li.hasNext()) {
1126 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1127 if (opt.getBuildTargets() != null) {
1128 saa[i][0] = listToString(opt.getBuildTargets());
1129 }
1130 saa[i][1] = opt.getToolChainFamily();
1131 if (opt.getSupArchList() != null){
1132 saa[i][2] = listToString(opt.getSupArchList());
1133
1134 }
1135 saa[i][3] = opt.getToolCode();
1136 saa[i][4] = opt.getTagName();
1137 saa[i][5] = opt.getStringValue();
1138
1139 ++i;
1140 }
1141 }
1142
1143 public void genBuildOptionsFfs(String ffsKey, String type) {
1144 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1145 ffs.setFfsKey(ffsKey);
1146 if (type != null) {
1147 ffs.addNewSections().setEncapsulationType(type);
1148 }
1149 }
1150
1151 public void updateBuildOptionsFfsSectionsType(int i, String type) {
1152 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1153 if (type != null) {
1154 ffs.addNewSections().setEncapsulationType(type);
1155 }
1156 }
1157
1158 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
1159 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1160 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
1161 attrib.setName(name);
1162 attrib.setValue(value);
1163 }
1164
1165 /**update jth attribute of ith ffs.
1166 * @param i
1167 * @param j
1168 */
1169 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
1170 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1171 XmlCursor cursor = ffs.newCursor();
1172 QName qAttrib = new QName(xmlNs, "Attribute");
1173 if (cursor.toChild(qAttrib)) {
1174 for (int k = 0; k < j; ++k) {
1175 cursor.toNextSibling(qAttrib);
1176 }
1177 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
1178 attrib.setName(name);
1179 attrib.setValue(value);
1180 }
1181 cursor.dispose();
1182 }
1183
1184 public void removeBuildOptionsFfsAttribute(int i, int j){
1185 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1186 XmlCursor cursor = ffs.newCursor();
1187 QName qAttrib = new QName(xmlNs, "Attribute");
1188 if (cursor.toChild(qAttrib)) {
1189 for (int k = 0; k < j; ++k) {
1190 cursor.toNextSibling(qAttrib);
1191 }
1192 cursor.removeXml();
1193 }
1194 cursor.dispose();
1195 }
1196
1197 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
1198 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1199 if (ffs == null) {
1200 return;
1201 }
1202 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1203
1204 if (sections == null){
1205 sections = ffs.addNewSections();
1206 }
1207 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
1208 }
1209
1210 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
1211 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1212 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1213 if (sections == null) {
1214 return;
1215 }
1216 XmlCursor cursor = sections.newCursor();
1217 QName qSection = new QName(xmlNs, "Section");
1218 if (cursor.toChild(qSection)) {
1219 for (int k = 0; k < j; ++k) {
1220 cursor.toNextSibling(qSection);
1221 }
1222 cursor.removeXml();
1223 }
1224 cursor.dispose();
1225 }
1226
1227 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
1228 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1229 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1230 if (sections == null) {
1231 return;
1232 }
1233 XmlCursor cursor = sections.newCursor();
1234 QName qSection = new QName(xmlNs, "Section");
1235 if (cursor.toChild(qSection)) {
1236 for (int k = 0; k < j; ++k) {
1237 cursor.toNextSibling(qSection);
1238 }
1239 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
1240 section.setSectionType(EfiSectionType.Enum.forString(type));
1241 }
1242 cursor.dispose();
1243 }
1244
1245 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
1246 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1247 if (ffs == null) {
1248 return;
1249 }
1250 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1251
1252 if (sections == null){
1253 sections = ffs.addNewSections();
1254 }
1255 sections.addNewSections().setEncapsulationType(encapType);
1256 }
1257
1258 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
1259 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1260 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1261 if (sections == null) {
1262 return;
1263 }
1264 XmlCursor cursor = sections.newCursor();
1265 QName qSections = new QName(xmlNs, "Sections");
1266 if (cursor.toChild(qSections)) {
1267 for (int k = 0; k < j; ++k) {
1268 cursor.toNextSibling(qSections);
1269 }
1270 cursor.removeXml();
1271 }
1272 cursor.dispose();
1273 }
1274
1275 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
1276 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1277 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1278 if (sections == null) {
1279 return;
1280 }
1281 XmlCursor cursor = sections.newCursor();
1282 QName qSections = new QName(xmlNs, "Sections");
1283 if (cursor.toChild(qSections)) {
1284 for (int k = 0; k < j; ++k) {
1285 cursor.toNextSibling(qSections);
1286 }
1287 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1288 sections2.setEncapsulationType(type);
1289 }
1290 cursor.dispose();
1291 }
1292
1293 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
1294 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1295 if (ffs == null) {
1296 return;
1297 }
1298 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1299 XmlCursor cursor = sections.newCursor();
1300 QName qSections = new QName(xmlNs, "Sections");
1301 if (cursor.toChild(qSections)){
1302 for (int k = 0; k < j; ++k) {
1303 cursor.toNextSibling(qSections);
1304 }
1305 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1306 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
1307 }
1308 cursor.dispose();
1309 }
1310
1311 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
1312 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1313 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1314 if (sections == null) {
1315 return;
1316 }
1317 XmlCursor cursor = sections.newCursor();
1318 QName qSections = new QName(xmlNs, "Sections");
1319 if (cursor.toChild(qSections)) {
1320 for (int l = 0; l < j; ++l) {
1321 cursor.toNextSibling(qSections);
1322 }
1323 if (cursor.toFirstChild()) {
1324 for (int m = 0; m < k; ++m) {
1325 cursor.toNextSibling();
1326 }
1327 cursor.removeXml();
1328 }
1329 }
1330 cursor.dispose();
1331 }
1332
1333 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
1334 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1335 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1336 if (sections == null) {
1337 return;
1338 }
1339 XmlCursor cursor = sections.newCursor();
1340 QName qSections = new QName(xmlNs, "Sections");
1341 if (cursor.toChild(qSections)) {
1342 for (int l = 0; l < j; ++l) {
1343 cursor.toNextSibling(qSections);
1344 }
1345 if (cursor.toFirstChild()) {
1346 for (int m = 0; m < k; ++m) {
1347 cursor.toNextSibling();
1348 }
1349 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
1350 section.setSectionType(EfiSectionType.Enum.forString(type));
1351 }
1352 }
1353 cursor.dispose();
1354 }
1355
1356 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
1357 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1358 if (ffs == null) {
1359 return;
1360 }
1361 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1362 XmlCursor cursor = sections.newCursor();
1363 QName qSections = new QName(xmlNs, "Sections");
1364 if (cursor.toChild(qSections)){
1365 for (int k = 0; k < j; ++k) {
1366 cursor.toNextSibling(qSections);
1367 }
1368 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1369 if (sections2.getSectionList() == null){
1370 cursor.dispose();
1371 return;
1372 }
1373 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
1374 while(li.hasNext()) {
1375 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
1376 if (section.isSetSectionType()) {
1377 al.add(section.getSectionType().toString());
1378 }
1379
1380 }
1381 }
1382 cursor.dispose();
1383
1384 }
1385
1386 public int getBuildOptionsFfsCount(){
1387 if (getfpdBuildOpts().getFfsList() == null) {
1388 return 0;
1389 }
1390 return getfpdBuildOpts().getFfsList().size();
1391 }
1392
1393 public void getBuildOptionsFfsKey(String[][] saa) {
1394 if (getfpdBuildOpts().getFfsList() == null) {
1395 return;
1396 }
1397 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
1398 int i = 0;
1399 while(li.hasNext()){
1400 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
1401 saa[i][0] = ffs.getFfsKey();
1402 ++i;
1403 }
1404 }
1405
1406 public void updateBuildOptionsFfsKey(int i, String key) {
1407 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1408 ffs.setFfsKey(key);
1409 }
1410
1411 /**Get ith FFS key and contents.
1412 * @param saa
1413 */
1414 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
1415 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1416
1417 if (ffs != null) {
1418
1419 sa[0] = ffs.getFfsKey();
1420 if (ffs.getSections() != null) {
1421 if(ffs.getSections().getEncapsulationType() != null){
1422 sa[1] = ffs.getSections().getEncapsulationType();
1423 }
1424 if (ffs.getSections().getSectionList() != null){
1425 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
1426 while (li.hasNext()) {
1427 firstLevelSection.add(li.next().getSectionType().toString());
1428 }
1429 }
1430 if (ffs.getSections().getSectionsList() != null) {
1431 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
1432 while(li.hasNext()) {
1433 firstLevelSections.add(li.next().getEncapsulationType());
1434 }
1435 }
1436 }
1437 if (ffs.getAttributeList() != null) {
1438 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
1439 while(li.hasNext()) {
1440 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
1441 ffsAttribMap.put(attrib.getName(), attrib.getValue());
1442 }
1443
1444 }
1445 }
1446
1447
1448 }
1449
1450 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
1451 XmlObject o = getfpdBuildOpts();
1452 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
1453
1454 XmlCursor cursor = o.newCursor();
1455 QName qFfs = new QName(xmlNs, "Ffs");
1456 if (cursor.toChild(qFfs)) {
1457 for (int j = 0; j < i; ++j) {
1458 cursor.toNextSibling(qFfs);
1459 }
1460 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
1461 }
1462 cursor.dispose();
1463 return ffs;
1464 }
1465
1466 public void removeBuildOptionsFfs(int i) {
1467 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1468 if (ffs == null){
1469 return;
1470 }
1471
1472 XmlCursor cursor = ffs.newCursor();
1473 cursor.removeXml();
1474 cursor.dispose();
1475 }
1476
1477
1478
1479 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
1480 if (fpdPlatformDefs == null){
1481 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
1482 }
1483 return fpdPlatformDefs;
1484 }
1485
1486 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
1487 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
1488 return;
1489 }
1490 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
1491 while(li.hasNext()) {
1492 archs.add(li.next());
1493 }
1494 }
1495
1496 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
1497 getfpdPlatformDefs().setSupportedArchitectures(archs);
1498 }
1499
1500 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
1501 if (getfpdPlatformDefs().getBuildTargets() == null) {
1502 return;
1503 }
1504 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
1505 while(li.hasNext()) {
1506 targets.add(li.next());
1507 }
1508 }
1509
1510 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
1511 getfpdPlatformDefs().setBuildTargets(targets);
1512 }
1513
1514 public void genPlatformDefsSkuInfo(String id, String name) {
1515 SkuInfoDocument.SkuInfo skuInfo = null;
1516 if (getfpdPlatformDefs().getSkuInfo() == null) {
1517 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
1518 }
1519 skuInfo = getfpdPlatformDefs().getSkuInfo();
1520 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
1521 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1522 skuName.setSkuID(new BigInteger("0"));
1523 skuName.setStringValue("DEFAULT");
1524 }
1525 if (id.equals("0")) {
1526 return;
1527 }
1528 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1529 skuName.setSkuID(new BigInteger(id));
1530 skuName.setStringValue(name);
1531 }
1532
1533 public int getPlatformDefsSkuInfoCount(){
1534 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1535 return 0;
1536 }
1537 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
1538 }
1539
1540 public void getPlatformDefsSkuInfos(String[][] saa){
1541 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1542 return ;
1543 }
1544
1545 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
1546 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
1547 int i = 0;
1548 while(li.hasNext()) {
1549 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
1550 saa[i][0] = sku.getSkuID()+"";
1551 saa[i][1] = sku.getStringValue();
1552 ++i;
1553 }
1554 }
1555
1556 public void removePlatformDefsSkuInfo(int i) {
1557 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
1558 if (skuInfo == null || i == 0) {
1559 return ;
1560 }
1561
1562 XmlCursor cursor = skuInfo.newCursor();
1563 if (cursor.toFirstChild()) {
1564 for (int j = 0; j < i; ++j) {
1565 cursor.toNextSibling();
1566 }
1567 cursor.removeXml();
1568 }
1569 cursor.dispose();
1570 }
1571
1572 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
1573 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
1574 if (skuInfo == null || i == 0) {
1575 return ;
1576 }
1577
1578 XmlCursor cursor = skuInfo.newCursor();
1579 if (cursor.toFirstChild()) {
1580 for (int j = 0; j < i; ++j) {
1581 cursor.toNextSibling();
1582 }
1583 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
1584 sku.setSkuID(new BigInteger(id));
1585 sku.setStringValue(name);
1586 }
1587 cursor.dispose();
1588 }
1589
1590 public String getPlatformDefsInterDir(){
1591 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
1592 return null;
1593 }
1594 return getfpdPlatformDefs().getIntermediateDirectories().toString();
1595 }
1596
1597 public void setPlatformDefsInterDir(String interDir){
1598 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
1599 }
1600
1601 public String getPlatformDefsOutputDir() {
1602 return getfpdPlatformDefs().getOutputDirectory();
1603 }
1604
1605 public void setPlatformDefsOutputDir(String outputDir) {
1606 getfpdPlatformDefs().setOutputDirectory(outputDir);
1607 }
1608
1609 public FlashDocument.Flash getfpdFlash() {
1610 if (fpdFlash == null) {
1611 fpdFlash = fpdRoot.addNewFlash();
1612 }
1613 return fpdFlash;
1614 }
1615
1616 public void genFlashDefinitionFile(String file) {
1617 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1618 if (fdf == null) {
1619 fdf = getfpdFlash().addNewFlashDefinitionFile();
1620 }
1621
1622 fdf.setStringValue(file);
1623 }
1624
1625 public String getFlashDefinitionFile() {
1626 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1627 if (fdf == null) {
1628 return "";
1629 }
1630
1631 return fdf.getStringValue();
1632 }
1633
1634
1635
1636 public void genFvImagesNameValue(String name, String value) {
1637
1638 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1639 if (fi == null) {
1640 fi = getfpdFlash().addNewFvImages();
1641 }
1642
1643 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
1644 nv.setName(name);
1645 nv.setValue(value);
1646 }
1647
1648 public void removeFvImagesNameValue(int i){
1649
1650 XmlObject o = getfpdFlash().getFvImages();
1651 if (o == null) {
1652 return;
1653 }
1654
1655 QName qNameValue = new QName(xmlNs, "NameValue");
1656 XmlCursor cursor = o.newCursor();
1657 if (cursor.toChild(qNameValue)) {
1658 for (int j = 0; j < i; ++j) {
1659 cursor.toNextSibling(qNameValue);
1660 }
1661 cursor.removeXml();
1662 }
1663 cursor.dispose();
1664 }
1665
1666 public void updateFvImagesNameValue(int i, String name, String value){
1667
1668 XmlObject o = getfpdFlash().getFvImages();
1669 if (o == null) {
1670 return;
1671 }
1672
1673 QName qNameValue = new QName(xmlNs, "NameValue");
1674 XmlCursor cursor = o.newCursor();
1675 if (cursor.toChild(qNameValue)) {
1676 for (int j = 0; j < i; ++j) {
1677 cursor.toNextSibling(qNameValue);
1678 }
1679 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
1680 nv.setName(name);
1681 nv.setValue(value);
1682 }
1683 cursor.dispose();
1684 }
1685
1686 public int getFvImagesNameValueCount() {
1687
1688 FvImagesDocument.FvImages fi = null;
1689 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
1690 return 0;
1691 }
1692 return fi.getNameValueList().size();
1693 }
1694
1695 public void getFvImagesNameValues(String[][] nv) {
1696
1697 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1698 if (fi == null){
1699 return;
1700 }
1701 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
1702 int i = 0;
1703 ListIterator li = l.listIterator();
1704 while (li.hasNext()) {
1705 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
1706 .next();
1707 nv[i][0] = e.getName();
1708 nv[i][1] = e.getValue();
1709
1710 i++;
1711 }
1712 }
1713
1714 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
1715
1716 FvImagesDocument.FvImages fis = null;
1717 if ((fis = getfpdFlash().getFvImages()) == null) {
1718 fis = getfpdFlash().addNewFvImages();
1719 }
1720
1721 //
1722 //gen FvImage with FvImageNames array
1723 //
1724 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
1725 for (int i = 0; i < names.length; ++i) {
1726 fi.addFvImageNames(names[i]);
1727 }
1728 fi.setType(FvImageTypes.Enum.forString(types));
1729 if (options != null){
1730 setFvImagesFvImageFvImageOptions(options, fi);
1731 }
1732 }
1733
1734 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
1735 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
1736 if (fio == null){
1737 fio = fi.addNewFvImageOptions();
1738 }
1739
1740 Set<String> key = options.keySet();
1741 Iterator<String> i = key.iterator();
1742 while (i.hasNext()) {
1743
1744 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
1745 String k = (String)i.next();
1746
1747 nv.setName(k);
1748 nv.setValue((String)options.get(k));
1749
1750 }
1751
1752 }
1753
1754
1755 public void removeFvImagesFvImage(int i) {
1756
1757 XmlObject o = getfpdFlash().getFvImages();
1758 if (o == null) {
1759 return;
1760 }
1761
1762 QName qFvImage = new QName(xmlNs, "FvImage");
1763 XmlCursor cursor = o.newCursor();
1764 if (cursor.toChild(qFvImage)) {
1765 for (int j = 0; j < i; ++j) {
1766 cursor.toNextSibling(qFvImage);
1767 }
1768 cursor.removeXml();
1769 }
1770 cursor.dispose();
1771 }
1772
1773 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
1774
1775 XmlObject o = getfpdFlash().getFvImages();
1776 if (o == null) {
1777 return;
1778 }
1779 XmlCursor cursor = o.newCursor();
1780 QName qFvImage = new QName(xmlNs, "FvImage");
1781 if (cursor.toChild(qFvImage)) {
1782 for (int j = 0; j < i; ++j) {
1783 cursor.toNextSibling(qFvImage);
1784 }
1785 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
1786 fi.setType(FvImageTypes.Enum.forString(types));
1787
1788 //
1789 // remove old FvImageNames before adding new ones
1790 //
1791 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
1792 cursor.toChild(qFvImageNames);
1793 cursor.removeXml();
1794 while (cursor.toNextSibling(qFvImageNames)) {
1795 cursor.removeXml();
1796 }
1797
1798 for (int k = 0; k < names.length; ++k) {
1799 fi.addFvImageNames(names[k]);
1800 }
1801 //
1802 // remove old FvImageOptions before adding new options
1803 //
1804 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
1805 cursor.toNextSibling(qFvImageOptions);
1806 cursor.removeXml();
1807
1808 setFvImagesFvImageFvImageOptions(options, fi);
1809 }
1810 cursor.dispose();
1811 }
1812
1813 public int getFvImagesFvImageCount() {
1814
1815 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1816 return 0;
1817 }
1818 return getfpdFlash().getFvImages().getFvImageList().size();
1819 }
1820
1821 /**Only Get Fv image setting - name and type.
1822 * @param saa
1823 */
1824 public void getFvImagesFvImages(String[][] saa) {
1825
1826 if (getfpdFlash().getFvImages() == null) {
1827 return;
1828 }
1829 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
1830 if (l == null) {
1831 return;
1832 }
1833 ListIterator li = l.listIterator();
1834 int i = 0;
1835 while(li.hasNext()) {
1836 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
1837 //
1838 // get FvImageNames array, space separated
1839 //
1840 List<String> lfn = fi.getFvImageNamesList();
1841 ListIterator lfni = lfn.listIterator();
1842 saa[i][0] = " ";
1843 while (lfni.hasNext()) {
1844 saa[i][0] += (String)lfni.next();
1845 saa[i][0] += " ";
1846 }
1847 saa[i][0] = saa[i][0].trim();
1848
1849 saa[i][1] = fi.getType()+"";
1850
1851 ++i;
1852 }
1853 }
1854
1855 /**Get FvImage Options for FvImage i
1856 * @param i the ith FvImage
1857 */
1858 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
1859 XmlObject o = getfpdFlash().getFvImages();
1860 if (o == null) {
1861 return;
1862 }
1863 XmlCursor cursor = o.newCursor();
1864 QName qFvImage = new QName(xmlNs, "FvImage");
1865 if (cursor.toChild(qFvImage)) {
1866 for (int j = 0; j < i; ++j) {
1867 cursor.toNextSibling(qFvImage);
1868 }
1869 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
1870 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
1871 return;
1872 }
1873 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
1874 while(li.hasNext()){
1875 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
1876 m.put(nv.getName(), nv.getValue());
1877 }
1878 }
1879 }
1880
1881 /**
1882 Get platform header element
1883 @return PlatformHeaderDocument.PlatformHeader
1884 **/
1885 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
1886 if (fpdHdr == null) {
1887 fpdHdr = fpdRoot.addNewPlatformHeader();
1888 }
1889 genPlatformDefsSkuInfo("0", "DEFAULT");
1890 return fpdHdr;
1891 }
1892
1893 public String getFpdHdrPlatformName() {
1894 return getFpdHdr().getPlatformName();
1895 }
1896
1897 public String getFpdHdrGuidValue() {
1898 return getFpdHdr().getGuidValue();
1899 }
1900
1901 public String getFpdHdrVer() {
1902 return getFpdHdr().getVersion();
1903 }
1904
1905 public String getFpdHdrAbs() {
1906 return getFpdHdr().getAbstract();
1907 }
1908
1909 public String getFpdHdrDescription() {
1910 return getFpdHdr().getDescription();
1911 }
1912
1913 public String getFpdHdrCopyright() {
1914 return getFpdHdr().getCopyright();
1915 }
1916
1917 public String getFpdHdrLicense() {
1918 LicenseDocument.License l = getFpdHdr().getLicense();
1919 if (l == null) {
1920 return null;
1921 }
1922 return l.getStringValue();
1923 }
1924
1925 public String getFpdHdrUrl() {
1926 LicenseDocument.License l = getFpdHdr().getLicense();
1927 if (l == null) {
1928 return null;
1929 }
1930 return l.getURL();
1931 }
1932
1933 public String getFpdHdrSpec() {
1934
1935 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1936 // return getFpdHdr().getSpecification();
1937 }
1938
1939 public void setFpdHdrPlatformName(String name){
1940 getFpdHdr().setPlatformName(name);
1941 }
1942
1943 public void setFpdHdrGuidValue(String guid){
1944 getFpdHdr().setGuidValue(guid);
1945 }
1946
1947 public void setFpdHdrVer(String v){
1948 getFpdHdr().setVersion(v);
1949 }
1950
1951 public void setFpdHdrAbs(String abs) {
1952 getFpdHdr().setAbstract(abs);
1953 }
1954
1955 public void setFpdHdrDescription(String desc){
1956 getFpdHdr().setDescription(desc);
1957 }
1958
1959 public void setFpdHdrCopyright(String cr) {
1960 getFpdHdr().setCopyright(cr);
1961 }
1962
1963 public void setFpdHdrLicense(String license){
1964 LicenseDocument.License l = getFpdHdr().getLicense();
1965 if (l == null) {
1966 getFpdHdr().addNewLicense().setStringValue(license);
1967 }
1968 else {
1969 l.setStringValue(license);
1970 }
1971 }
1972
1973 public void setFpdHdrUrl(String url){
1974 LicenseDocument.License l = getFpdHdr().getLicense();
1975
1976 l.setURL(url);
1977
1978 }
1979
1980 public void setFpdHdrSpec(String s){
1981 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1982 getFpdHdr().setSpecification(s);
1983 }
1984 /**
1985 Save the processed xml contents to file
1986
1987 @param fpdFile The file to save xml contents
1988 @throws IOException Exceptions during file operation
1989 **/
1990 public void saveAs(File fpdFile) throws IOException {
1991
1992 XmlOptions options = new XmlOptions();
1993
1994 options.setCharacterEncoding("UTF-8");
1995 options.setSavePrettyPrint();
1996 options.setSavePrettyPrintIndent(2);
1997 try {
1998 fpdd.save(fpdFile, options);
1999 } catch (IOException e) {
2000 e.printStackTrace();
2001 }
2002
2003 }
2004
2005 private String listToString(List<String> l) {
2006 if (l == null) {
2007 return null;
2008 }
2009 String s = " ";
2010 ListIterator li = l.listIterator();
2011 while(li.hasNext()) {
2012 s += li.next();
2013 s += " ";
2014 }
2015 return s.trim();
2016 }
2017 }