]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Add ModuleSA BuildOptions
[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
395 public String getFvBinding(String moduleKey){
396 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
397 if (msa == null || msa.getModuleSaBuildOptions() == null) {
398 return null;
399 }
400 return msa.getModuleSaBuildOptions().getFvBinding();
401 }
402
403 public void setFvBinding(String moduleKey, String fvBinding){
404 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
405 if (msa == null ) {
406 return;
407 }
408 if(msa.getModuleSaBuildOptions() == null){
409 msa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
410 return;
411 }
412 msa.getModuleSaBuildOptions().setFvBinding(fvBinding);
413 }
414
415 public String getFfsFileNameGuid(String moduleKey){
416 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
417 if (msa == null || msa.getModuleSaBuildOptions() == null) {
418 return null;
419 }
420 return msa.getModuleSaBuildOptions().getFfsFileNameGuid();
421 }
422
423 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
424 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
425 if (msa == null ) {
426 return;
427 }
428 if(msa.getModuleSaBuildOptions() == null){
429 msa.addNewModuleSaBuildOptions().setFfsFileNameGuid(fileGuid);
430 return;
431 }
432 msa.getModuleSaBuildOptions().setFfsFileNameGuid(fileGuid);
433 }
434
435 public String getFfsFormatKey(String moduleKey){
436 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
437 if (msa == null || msa.getModuleSaBuildOptions() == null) {
438 return null;
439 }
440 return msa.getModuleSaBuildOptions().getFfsFormatKey();
441 }
442
443 public void setFfsFormatKey(String moduleKey, String ffsKey){
444 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
445 if (msa == null ) {
446 return;
447 }
448 if(msa.getModuleSaBuildOptions() == null){
449 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
450 return;
451 }
452 msa.getModuleSaBuildOptions().setFvBinding(ffsKey);
453 }
454
455 public void getModuleSAOptions(String moduleKey, String[][] saa) {
456 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
457 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
458 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
459 return ;
460 }
461
462 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
463 ListIterator li = lOpt.listIterator();
464 int i = 0;
465 while(li.hasNext()) {
466 OptionDocument.Option opt = (OptionDocument.Option)li.next();
467 if (opt.getBuildTargets() != null) {
468 saa[i][0] = listToString(opt.getBuildTargets());
469 }
470 saa[i][1] = opt.getToolChainFamily();
471 if (opt.getSupArchList() != null){
472 saa[i][2] = listToString(opt.getSupArchList());
473
474 }
475 saa[i][3] = opt.getToolCode();
476 saa[i][4] = opt.getTagName();
477 saa[i][5] = opt.getStringValue();
478
479 ++i;
480 }
481 }
482
483 public int getModuleSAOptionsCount(String moduleKey){
484 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
485 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
486 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
487 return 0;
488 }
489 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
490 }
491
492 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
493 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
494 if (msa.getModuleSaBuildOptions() == null) {
495 msa.addNewModuleSaBuildOptions();
496 }
497 if (msa.getModuleSaBuildOptions().getOptions() == null){
498 msa.getModuleSaBuildOptions().addNewOptions();
499 }
500 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
501 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
502 }
503
504 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
505 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
506 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
507 return ;
508 }
509 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
510 XmlCursor cursor = opts.newCursor();
511 if (cursor.toFirstChild()) {
512 for (int j = 0; j < i; ++j){
513 cursor.toNextSibling();
514 }
515 cursor.removeXml();
516 }
517 cursor.dispose();
518 }
519
520 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
521 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
522 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
523 return ;
524 }
525 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
526 XmlCursor cursor = opts.newCursor();
527 if (cursor.toFirstChild()) {
528 for (int j = 0; j < i; ++j){
529 cursor.toNextSibling();
530 }
531 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
532 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
533 }
534 cursor.dispose();
535 }
536
537 /**add pcd information of module mi to a ModuleSA.
538 * @param mi
539 * @param moduleSa if null, generate a new ModuleSA.
540 */
541 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, ModuleSADocument.ModuleSA moduleSa){
542 //ToDo add Arch filter
543
544 try {
545 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);
546 if (msa.getPcdCoded() == null) {
547 return;
548 }
549 if (moduleSa == null) {
550 moduleSa = genModuleSA(mi);
551 }
552 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
553 m.put("ModuleSurfaceArea", msa);
554 SurfaceAreaQuery.setDoc(m);
555 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);
556 //
557 // Implementing InitializePlatformPcdBuildDefinitions
558 //
559 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
560 ListIterator li = l.listIterator();
561 while(li.hasNext()) {
562 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
563 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
564 if (spdPcd == null) {
565 //
566 // ToDo Error
567 //
568 break;
569 }
570 //
571 // AddItem to ModuleSA PcdBuildDefinitions
572 //
573 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
574 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
575 }
576
577 }
578 catch (Exception e){
579 e.printStackTrace();
580 }
581
582 }
583
584 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
585
586 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
587 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
588 for (int i = 0; i < depPkgs.length; ++i) {
589 m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));
590 SurfaceAreaQuery.setDoc(m);
591 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();
592 if (xo == null) {
593 continue;
594 }
595 for (int j = 0; j < xo.length; ++j) {
596 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
597 if (msaPcd.getTokenSpaceGuidCName() == null) {
598 if (spdPcd.getCName().equals(msaPcd.getCName())) {
599 return spdPcd;
600 }
601 }
602 else{
603 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
604 return spdPcd;
605 }
606 }
607
608 }
609
610 }
611 return null;
612 }
613
614 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi) {
615 PackageIdentification pi = GlobalData.getPackageForModule(mi);
616 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
617 msa.setModuleGuid(mi.getGuid());
618 msa.setModuleVersion(mi.getVersion());
619 msa.setPackageGuid(pi.getGuid());
620 msa.setPackageVersion(pi.getVersion());
621
622 return msa;
623 }
624
625 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) {
626 if (moduleSa.getPcdBuildDefinition() == null){
627 moduleSa.addNewPcdBuildDefinition();
628 }
629 //
630 // constructe pcd to modulesa mapping first.
631 // Attention : for any error condition, remove from map this pcd.
632 //
633 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
634 if (pcdConsumer == null) {
635 pcdConsumer = new ArrayList<String>();
636 }
637 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
638 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion()
639 + " " + itemType;
640 pcdConsumer.add(listValue);
641 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
642 //
643 // Special dynamic type, if this pcd already exists in other ModuleSA
644 //
645 if (itemType.equals("DYNAMIC")) {
646
647 ListIterator li = pcdConsumer.listIterator();
648 while(li.hasNext()) {
649 String value = li.next().toString();
650 String[] valuePart= value.split(" ");
651 if (!valuePart[4].equals("DYNAMIC")) {
652 //ToDo error for same pcd, other type than dynamic
653 pcdConsumer.remove(listValue);
654 return;
655 }
656 }
657 }
658 else {
659 ListIterator li = pcdConsumer.listIterator();
660 while(li.hasNext()) {
661 String value = li.next().toString();
662 String[] valuePart= value.split(" ");
663 if (valuePart[4].equals("DYNAMIC")) {
664 //ToDo error for same pcd, other type than non-dynamic
665 pcdConsumer.remove(listValue);
666 return;
667 }
668 }
669 }
670
671 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
672 fpdPcd.setCName(cName);
673 fpdPcd.setToken(token);
674 fpdPcd.setTokenSpaceGuidCName(tsGuid);
675 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
676 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
677
678 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
679 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
680 //
681 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
682 // so need to add one dyn pcd.
683 //
684 if (al.size() == 1) {
685 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
686 }
687 }
688 else {
689 if (defaultVal != null){
690 fpdPcd.setValue(defaultVal);
691 }
692 else {
693 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
694 fpdPcd.setValue("0");
695 }
696 if (dataType.equals("BOOLEAN")){
697 fpdPcd.setValue("false");
698 }
699 if (dataType.equals("VOID*")) {
700 fpdPcd.setValue("");
701 }
702 }
703 if (dataType.equals("UINT8")){
704 fpdPcd.setMaxDatumSize(1);
705 }
706 if (dataType.equals("UINT16")) {
707 fpdPcd.setMaxDatumSize(2);
708 }
709 if (dataType.equals("UINT32")) {
710 fpdPcd.setMaxDatumSize(4);
711 }
712 if (dataType.equals("UINT64")){
713 fpdPcd.setMaxDatumSize(8);
714 }
715 if (dataType.equals("BOOLEAN")){
716 fpdPcd.setMaxDatumSize(1);
717 }
718 if (dataType.equals("VOID*")) {
719 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
720 fpdPcd.setMaxDatumSize(maxSize);
721 }
722 }
723 }
724
725 private int setMaxSizeForPointer(String datum) {
726 if (datum == null) {
727 return 0;
728 }
729 char ch = datum.charAt(0);
730 int start, end;
731 String strValue;
732 //
733 // For void* type PCD, only three datum is support:
734 // 1) Unicode: string with start char is "L"
735 // 2) Ansci: String is ""
736 // 3) byte array: String start char "{"
737 //
738 if (ch == 'L') {
739 start = datum.indexOf('\"');
740 end = datum.lastIndexOf('\"');
741 if ((start > end) ||
742 (end > datum.length())||
743 ((start == end) && (datum.length() > 0))) {
744 //ToDo Error handling here
745 }
746
747 strValue = datum.substring(start + 1, end);
748 return strValue.length() * 2;
749 } else if (ch == '\"'){
750 start = datum.indexOf('\"');
751 end = datum.lastIndexOf('\"');
752 if ((start > end) ||
753 (end > datum.length())||
754 ((start == end) && (datum.length() > 0))) {
755
756 }
757 strValue = datum.substring(start + 1, end);
758 return strValue.length();
759 } else if (ch =='{') {
760 String[] strValueArray;
761
762 start = datum.indexOf('{');
763 end = datum.lastIndexOf('}');
764 strValue = datum.substring(start + 1, end);
765 strValue = strValue.trim();
766 if (strValue.length() == 0) {
767 return 0;
768 }
769 strValueArray = strValue.split(",");
770 for (int index = 0; index < strValueArray.length; index ++) {
771 Integer value = Integer.decode(strValueArray[index].trim());
772
773 if (value > 0xFF) {
774 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
775 // "it is byte array in fact. But the element of %s exceed the byte range",
776
777 }
778 }
779 return strValueArray.length;
780
781
782 } else {
783 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
784 // "1) UNICODE string: like L\"xxxx\";\r\n"+
785 // "2) ANSIC string: like \"xxx\";\r\n"+
786 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
787 // "but the datum in seems does not following above format!",
788 return -1;
789
790 }
791 }
792
793 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
794 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
795
796 return al;
797 }
798
799 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
800
801 return dynPcdMap.get("pcdKey");
802 }
803
804 public int getDynamicPcdBuildDataCount() {
805 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
806 return 0;
807 }
808 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
809 }
810
811 public void getDynamicPcdBuildData(String[][] saa) {
812 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
813 return ;
814 }
815 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
816 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
817 int i = 0;
818 while(li.hasNext()) {
819 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
820 saa[i][0] = dynPcd.getCName();
821 saa[i][1] = dynPcd.getToken().toString();
822 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
823 saa[i][3] = dynPcd.getMaxDatumSize()+"";
824 saa[i][4] = dynPcd.getDatumType().toString();
825
826 ++i;
827 }
828 }
829
830 private void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) {
831 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
832 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
833 dynPcdData.setCName(cName);
834 dynPcdData.setToken(token);
835 dynPcdData.setTokenSpaceGuidCName(tsGuid);
836 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
837
838 BigInteger bigInt = new BigInteger("0");
839 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
840 skuInfo.setSkuId(bigInt);
841 if (defaultVal != null){
842 skuInfo.setValue(defaultVal);
843 }
844 else {
845 if (dataType.equals("UINT8")){
846 skuInfo.setValue("0");
847 }
848 if (dataType.equals("UINT16")) {
849 skuInfo.setValue("0");
850 }
851 if (dataType.equals("UINT32")) {
852 skuInfo.setValue("0");
853 }
854 if (dataType.equals("UINT64")){
855 skuInfo.setValue("0");
856 }
857 if (dataType.equals("BOOLEAN")){
858 skuInfo.setValue("false");
859 }
860 if (dataType.equals("VOID*")) {
861 skuInfo.setValue("");
862 }
863 }
864 if (dataType.equals("UINT8")){
865 dynPcdData.setMaxDatumSize(1);
866 }
867 if (dataType.equals("UINT16")) {
868 dynPcdData.setMaxDatumSize(2);
869 }
870 if (dataType.equals("UINT32")) {
871 dynPcdData.setMaxDatumSize(4);
872 }
873 if (dataType.equals("UINT64")){
874 dynPcdData.setMaxDatumSize(8);
875 }
876 if (dataType.equals("BOOLEAN")){
877 dynPcdData.setMaxDatumSize(1);
878 }
879 if (dataType.equals("VOID*")) {
880 int maxSize = setMaxSizeForPointer(defaultVal);
881 dynPcdData.setMaxDatumSize(maxSize);
882 }
883 }
884
885 private void removeDynamicPcdBuildData(String cName, String tsGuid) {
886 XmlObject o = getfpdDynPcdBuildDefs();
887
888 XmlCursor cursor = o.newCursor();
889 if (cursor.toFirstChild()) {
890 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
891 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
892 while (!(pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid))) {
893 cursor.toNextSibling();
894 pcdBuildData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
895 }
896
897 cursor.removeXml();
898 }
899 cursor.dispose();
900 }
901 //
902 // Get the Sku Info count of ith dyn pcd element.
903 //
904 public int getDynamicPcdSkuInfoCount(int i){
905 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
906 return 0;
907 }
908
909 int skuInfoCount = 0;
910 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
911 if (cursor.toFirstChild()) {
912 for (int j = 0; j < i; ++j) {
913 cursor.toNextSibling();
914 }
915 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
916 if (pcdData.getSkuInfoList() == null) {
917 skuInfoCount = 0;
918 }
919 else {
920 skuInfoCount = pcdData.getSkuInfoList().size();
921 }
922 }
923 cursor.dispose();
924 return skuInfoCount;
925 }
926
927 public void getDynamicPcdSkuInfos(int i, String[][] saa){
928 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
929 return;
930 }
931
932 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
933 if (cursor.toFirstChild()) {
934 for (int j = 0; j < i; ++j) {
935 cursor.toNextSibling();
936 }
937 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
938 if (pcdData.getSkuInfoList() == null) {
939 cursor.dispose();
940 return;
941 }
942 else {
943 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
944 int k = 0;
945 while (li.hasNext()) {
946 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
947 saa[k][0] = skuInfo.getSkuId()+"";
948 saa[k][1] = skuInfo.getVariableName();
949 saa[k][2] = skuInfo.getVariableGuid();
950 saa[k][3] = skuInfo.getVariableOffset();
951 saa[k][4] = skuInfo.getHiiDefaultValue();
952 saa[k][5] = skuInfo.getVpdOffset();
953 saa[k][6] = skuInfo.getValue();
954 ++k;
955 }
956
957 }
958 }
959 cursor.dispose();
960
961 }
962
963 public String getDynamicPcdBuildDataValue(int i){
964 String value = null;
965 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
966 return value;
967 }
968
969 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
970 if (cursor.toFirstChild()) {
971 for (int j = 0; j < i; ++j) {
972 cursor.toNextSibling();
973 }
974 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
975 if (pcdData.getSkuInfoList() == null) {
976 value = null;
977 }
978 else {
979 value = pcdData.getSkuInfoArray(0).getValue();
980 }
981 }
982 cursor.dispose();
983 return value;
984 }
985
986 public String getDynamicPcdBuildDataVpdOffset(int i){
987 String vpdOffset = null;
988 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
989 return vpdOffset;
990 }
991
992 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
993 if (cursor.toFirstChild()) {
994 for (int j = 0; j < i; ++j) {
995 cursor.toNextSibling();
996 }
997 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
998 if (pcdData.getSkuInfoList() == null) {
999 vpdOffset = null;
1000 }
1001 else {
1002 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1003 }
1004 }
1005 cursor.dispose();
1006 return vpdOffset;
1007 }
1008
1009 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1010 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1011 return;
1012 }
1013
1014 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1015 if (cursor.toFirstChild()) {
1016 for (int j = 0; j < i; ++j) {
1017 cursor.toNextSibling();
1018 }
1019 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1020 if (pcdData.getSkuInfoList() == null) {
1021 cursor.dispose();
1022 return;
1023 }
1024 else {
1025 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1026 cursor.toChild(qSkuInfo);
1027 cursor.removeXml();
1028 }
1029 }
1030 cursor.dispose();
1031 }
1032 //
1033 // generate sku info for ith dyn pcd build data.
1034 //
1035 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1036 String hiiDefault, String vpdOffset, String value, int i) {
1037 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1038 return;
1039 }
1040
1041 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1042 if (cursor.toFirstChild()) {
1043 for (int j = 0; j < i; ++j) {
1044 cursor.toNextSibling();
1045 }
1046 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1047 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1048 skuInfo.setSkuId(new BigInteger(id));
1049 if (varName != null){
1050 skuInfo.setVariableName(varName);
1051 skuInfo.setVariableGuid(varGuid);
1052 skuInfo.setVariableOffset(varOffset);
1053 skuInfo.setHiiDefaultValue(hiiDefault);
1054 }
1055 else if (vpdOffset != null){
1056 skuInfo.setVpdOffset(vpdOffset);
1057 }
1058 else{
1059 skuInfo.setValue(value);
1060 }
1061 }
1062 }
1063
1064 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1065 String hiiDefault, String vpdOffset, String value, int i){
1066 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1067 return;
1068 }
1069
1070 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1071 if (cursor.toFirstChild()) {
1072 for (int j = 0; j < i; ++j) {
1073 cursor.toNextSibling();
1074 }
1075 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1076 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1077 while (li.hasNext()) {
1078 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1079 if (skuInfo.getSkuId().toString().equals(id)){
1080 if (varName != null){
1081 skuInfo.setVariableName(varName);
1082 skuInfo.setVariableGuid(varGuid);
1083 skuInfo.setVariableOffset(varOffset);
1084 skuInfo.setHiiDefaultValue(hiiDefault);
1085 }
1086 else if (vpdOffset != null){
1087 skuInfo.setVpdOffset(vpdOffset);
1088 }
1089 else{
1090 skuInfo.setValue(value);
1091 }
1092 break;
1093 }
1094 }
1095 }
1096 }
1097
1098 public void removePcdDataFromLibraryInstance(String moduleKey, String libInstanceKey){
1099 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
1100 //
1101 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
1102 //
1103 maintainDynPcdMap(moduleSa.getPcdBuildDefinition(), libInstanceKey);
1104
1105 }
1106
1107 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1108 if (fpdBuildOpts == null) {
1109 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1110 }
1111 return fpdBuildOpts;
1112 }
1113
1114 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1115 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1116 if (udats == null) {
1117 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1118 }
1119
1120 AntTaskDocument.AntTask at = udats.addNewAntTask();
1121 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1122 }
1123
1124 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1125 at.setId(new Integer(id));
1126 if (fileName != null){
1127 at.setFilename(fileName);
1128 }
1129 if (execOrder != null) {
1130 at.setAntCmdOptions(execOrder);
1131 }
1132 }
1133
1134 public void removeBuildOptionsUserDefAntTask(int i) {
1135 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1136 if (o == null) {
1137 return;
1138 }
1139 XmlCursor cursor = o.newCursor();
1140 if (cursor.toFirstChild()) {
1141 for (int j = 0; j < i; ++j) {
1142 cursor.toNextSibling();
1143 }
1144 cursor.removeXml();
1145 }
1146 cursor.dispose();
1147 }
1148
1149 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1150 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1151 if (o == null) {
1152 return;
1153 }
1154 XmlCursor cursor = o.newCursor();
1155 if (cursor.toFirstChild()) {
1156 for (int j = 0; j < i; ++j) {
1157 cursor.toNextSibling();
1158 }
1159 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1160 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1161 }
1162 cursor.dispose();
1163 }
1164
1165 public int getBuildOptionsUserDefAntTaskCount() {
1166 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1167 if (udats == null || udats.getAntTaskList() == null) {
1168 return 0;
1169 }
1170
1171 return udats.getAntTaskList().size();
1172 }
1173
1174 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1175 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1176 if (udats == null || udats.getAntTaskList() == null) {
1177 return ;
1178 }
1179
1180 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1181 ListIterator li = l.listIterator();
1182 int i = 0;
1183 while (li.hasNext()) {
1184 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1185 saa[i][0] = at.getId() + "";
1186 saa[i][1] = saa[i][2] = "";
1187 if (at.getFilename() != null){
1188 saa[i][1] = at.getFilename();
1189 }
1190 if (at.getAntCmdOptions() != null) {
1191 saa[i][2] = at.getAntCmdOptions();
1192 }
1193 ++i;
1194 }
1195 }
1196 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1197 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1198 if (opts == null) {
1199 opts = getfpdBuildOpts().addNewOptions();
1200 }
1201 OptionDocument.Option opt = opts.addNewOption();
1202 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1203 }
1204
1205 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1206 opt.setStringValue(contents);
1207
1208 opt.setBuildTargets(buildTargets);
1209 opt.setToolChainFamily(toolChain);
1210 opt.setTagName(tagName);
1211 opt.setToolCode(toolCmd);
1212
1213 opt.setSupArchList(archList);
1214 }
1215
1216 public void removeBuildOptionsOpt(int i){
1217
1218 XmlObject o = getfpdBuildOpts().getOptions();
1219 if (o == null) {
1220 return;
1221 }
1222
1223 XmlCursor cursor = o.newCursor();
1224 if (cursor.toFirstChild()) {
1225 for (int j = 0; j < i; ++j) {
1226 cursor.toNextSibling();
1227 }
1228 cursor.removeXml();
1229 }
1230 cursor.dispose();
1231 }
1232
1233 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1234 XmlObject o = getfpdBuildOpts().getOptions();
1235 if (o == null) {
1236 return;
1237 }
1238
1239 XmlCursor cursor = o.newCursor();
1240 if (cursor.toFirstChild()) {
1241 for (int j = 0; j < i; ++j) {
1242 cursor.toNextSibling();
1243 }
1244 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1245 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1246 }
1247 cursor.dispose();
1248 }
1249
1250 public int getBuildOptionsOptCount(){
1251 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1252 return 0;
1253 }
1254 return getfpdBuildOpts().getOptions().getOptionList().size();
1255 }
1256
1257 public void getBuildOptionsOpts(String[][] saa) {
1258 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1259 return ;
1260 }
1261
1262 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1263 ListIterator li = lOpt.listIterator();
1264 int i = 0;
1265 while(li.hasNext()) {
1266 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1267 if (opt.getBuildTargets() != null) {
1268 saa[i][0] = listToString(opt.getBuildTargets());
1269 }
1270 saa[i][1] = opt.getToolChainFamily();
1271 if (opt.getSupArchList() != null){
1272 saa[i][2] = listToString(opt.getSupArchList());
1273
1274 }
1275 saa[i][3] = opt.getToolCode();
1276 saa[i][4] = opt.getTagName();
1277 saa[i][5] = opt.getStringValue();
1278
1279 ++i;
1280 }
1281 }
1282
1283 public void genBuildOptionsFfs(String ffsKey, String type) {
1284 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1285 ffs.setFfsKey(ffsKey);
1286 if (type != null) {
1287 ffs.addNewSections().setEncapsulationType(type);
1288 }
1289 }
1290
1291 public void updateBuildOptionsFfsSectionsType(int i, String type) {
1292 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1293 if (type != null) {
1294 ffs.addNewSections().setEncapsulationType(type);
1295 }
1296 }
1297
1298 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
1299 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1300 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
1301 attrib.setName(name);
1302 attrib.setValue(value);
1303 }
1304
1305 /**update jth attribute of ith ffs.
1306 * @param i
1307 * @param j
1308 */
1309 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
1310 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1311 XmlCursor cursor = ffs.newCursor();
1312 QName qAttrib = new QName(xmlNs, "Attribute");
1313 if (cursor.toChild(qAttrib)) {
1314 for (int k = 0; k < j; ++k) {
1315 cursor.toNextSibling(qAttrib);
1316 }
1317 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
1318 attrib.setName(name);
1319 attrib.setValue(value);
1320 }
1321 cursor.dispose();
1322 }
1323
1324 public void removeBuildOptionsFfsAttribute(int i, int j){
1325 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1326 XmlCursor cursor = ffs.newCursor();
1327 QName qAttrib = new QName(xmlNs, "Attribute");
1328 if (cursor.toChild(qAttrib)) {
1329 for (int k = 0; k < j; ++k) {
1330 cursor.toNextSibling(qAttrib);
1331 }
1332 cursor.removeXml();
1333 }
1334 cursor.dispose();
1335 }
1336
1337 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
1338 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1339 if (ffs == null) {
1340 return;
1341 }
1342 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1343
1344 if (sections == null){
1345 sections = ffs.addNewSections();
1346 }
1347 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
1348 }
1349
1350 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
1351 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1352 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1353 if (sections == null) {
1354 return;
1355 }
1356 XmlCursor cursor = sections.newCursor();
1357 QName qSection = new QName(xmlNs, "Section");
1358 if (cursor.toChild(qSection)) {
1359 for (int k = 0; k < j; ++k) {
1360 cursor.toNextSibling(qSection);
1361 }
1362 cursor.removeXml();
1363 }
1364 cursor.dispose();
1365 }
1366
1367 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
1368 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1369 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1370 if (sections == null) {
1371 return;
1372 }
1373 XmlCursor cursor = sections.newCursor();
1374 QName qSection = new QName(xmlNs, "Section");
1375 if (cursor.toChild(qSection)) {
1376 for (int k = 0; k < j; ++k) {
1377 cursor.toNextSibling(qSection);
1378 }
1379 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
1380 section.setSectionType(EfiSectionType.Enum.forString(type));
1381 }
1382 cursor.dispose();
1383 }
1384
1385 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
1386 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1387 if (ffs == null) {
1388 return;
1389 }
1390 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1391
1392 if (sections == null){
1393 sections = ffs.addNewSections();
1394 }
1395 sections.addNewSections().setEncapsulationType(encapType);
1396 }
1397
1398 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
1399 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1400 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1401 if (sections == null) {
1402 return;
1403 }
1404 XmlCursor cursor = sections.newCursor();
1405 QName qSections = new QName(xmlNs, "Sections");
1406 if (cursor.toChild(qSections)) {
1407 for (int k = 0; k < j; ++k) {
1408 cursor.toNextSibling(qSections);
1409 }
1410 cursor.removeXml();
1411 }
1412 cursor.dispose();
1413 }
1414
1415 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
1416 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1417 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1418 if (sections == null) {
1419 return;
1420 }
1421 XmlCursor cursor = sections.newCursor();
1422 QName qSections = new QName(xmlNs, "Sections");
1423 if (cursor.toChild(qSections)) {
1424 for (int k = 0; k < j; ++k) {
1425 cursor.toNextSibling(qSections);
1426 }
1427 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1428 sections2.setEncapsulationType(type);
1429 }
1430 cursor.dispose();
1431 }
1432
1433 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
1434 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1435 if (ffs == null) {
1436 return;
1437 }
1438 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1439 XmlCursor cursor = sections.newCursor();
1440 QName qSections = new QName(xmlNs, "Sections");
1441 if (cursor.toChild(qSections)){
1442 for (int k = 0; k < j; ++k) {
1443 cursor.toNextSibling(qSections);
1444 }
1445 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1446 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
1447 }
1448 cursor.dispose();
1449 }
1450
1451 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
1452 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1453 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1454 if (sections == null) {
1455 return;
1456 }
1457 XmlCursor cursor = sections.newCursor();
1458 QName qSections = new QName(xmlNs, "Sections");
1459 if (cursor.toChild(qSections)) {
1460 for (int l = 0; l < j; ++l) {
1461 cursor.toNextSibling(qSections);
1462 }
1463 if (cursor.toFirstChild()) {
1464 for (int m = 0; m < k; ++m) {
1465 cursor.toNextSibling();
1466 }
1467 cursor.removeXml();
1468 }
1469 }
1470 cursor.dispose();
1471 }
1472
1473 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
1474 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1475 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1476 if (sections == null) {
1477 return;
1478 }
1479 XmlCursor cursor = sections.newCursor();
1480 QName qSections = new QName(xmlNs, "Sections");
1481 if (cursor.toChild(qSections)) {
1482 for (int l = 0; l < j; ++l) {
1483 cursor.toNextSibling(qSections);
1484 }
1485 if (cursor.toFirstChild()) {
1486 for (int m = 0; m < k; ++m) {
1487 cursor.toNextSibling();
1488 }
1489 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
1490 section.setSectionType(EfiSectionType.Enum.forString(type));
1491 }
1492 }
1493 cursor.dispose();
1494 }
1495
1496 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
1497 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1498 if (ffs == null) {
1499 return;
1500 }
1501 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1502 XmlCursor cursor = sections.newCursor();
1503 QName qSections = new QName(xmlNs, "Sections");
1504 if (cursor.toChild(qSections)){
1505 for (int k = 0; k < j; ++k) {
1506 cursor.toNextSibling(qSections);
1507 }
1508 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1509 if (sections2.getSectionList() == null){
1510 cursor.dispose();
1511 return;
1512 }
1513 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
1514 while(li.hasNext()) {
1515 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
1516 if (section.isSetSectionType()) {
1517 al.add(section.getSectionType().toString());
1518 }
1519
1520 }
1521 }
1522 cursor.dispose();
1523
1524 }
1525
1526 public int getBuildOptionsFfsCount(){
1527 if (getfpdBuildOpts().getFfsList() == null) {
1528 return 0;
1529 }
1530 return getfpdBuildOpts().getFfsList().size();
1531 }
1532
1533 public void getBuildOptionsFfsKey(String[][] saa) {
1534 if (getfpdBuildOpts().getFfsList() == null) {
1535 return;
1536 }
1537 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
1538 int i = 0;
1539 while(li.hasNext()){
1540 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
1541 saa[i][0] = ffs.getFfsKey();
1542 ++i;
1543 }
1544 }
1545
1546 public void updateBuildOptionsFfsKey(int i, String key) {
1547 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1548 ffs.setFfsKey(key);
1549 }
1550
1551 /**Get ith FFS key and contents.
1552 * @param saa
1553 */
1554 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
1555 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1556
1557 if (ffs != null) {
1558
1559 sa[0] = ffs.getFfsKey();
1560 if (ffs.getSections() != null) {
1561 if(ffs.getSections().getEncapsulationType() != null){
1562 sa[1] = ffs.getSections().getEncapsulationType();
1563 }
1564 if (ffs.getSections().getSectionList() != null){
1565 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
1566 while (li.hasNext()) {
1567 firstLevelSection.add(li.next().getSectionType().toString());
1568 }
1569 }
1570 if (ffs.getSections().getSectionsList() != null) {
1571 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
1572 while(li.hasNext()) {
1573 firstLevelSections.add(li.next().getEncapsulationType());
1574 }
1575 }
1576 }
1577 if (ffs.getAttributeList() != null) {
1578 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
1579 while(li.hasNext()) {
1580 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
1581 ffsAttribMap.put(attrib.getName(), attrib.getValue());
1582 }
1583
1584 }
1585 }
1586
1587
1588 }
1589
1590 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
1591 XmlObject o = getfpdBuildOpts();
1592 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
1593
1594 XmlCursor cursor = o.newCursor();
1595 QName qFfs = new QName(xmlNs, "Ffs");
1596 if (cursor.toChild(qFfs)) {
1597 for (int j = 0; j < i; ++j) {
1598 cursor.toNextSibling(qFfs);
1599 }
1600 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
1601 }
1602 cursor.dispose();
1603 return ffs;
1604 }
1605
1606 public void removeBuildOptionsFfs(int i) {
1607 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1608 if (ffs == null){
1609 return;
1610 }
1611
1612 XmlCursor cursor = ffs.newCursor();
1613 cursor.removeXml();
1614 cursor.dispose();
1615 }
1616
1617
1618
1619 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
1620 if (fpdPlatformDefs == null){
1621 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
1622 }
1623 return fpdPlatformDefs;
1624 }
1625
1626 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
1627 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
1628 return;
1629 }
1630 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
1631 while(li.hasNext()) {
1632 archs.add(li.next());
1633 }
1634 }
1635
1636 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
1637 getfpdPlatformDefs().setSupportedArchitectures(archs);
1638 }
1639
1640 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
1641 if (getfpdPlatformDefs().getBuildTargets() == null) {
1642 return;
1643 }
1644 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
1645 while(li.hasNext()) {
1646 targets.add(li.next());
1647 }
1648 }
1649
1650 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
1651 getfpdPlatformDefs().setBuildTargets(targets);
1652 }
1653
1654 public void genPlatformDefsSkuInfo(String id, String name) {
1655 SkuInfoDocument.SkuInfo skuInfo = null;
1656 if (getfpdPlatformDefs().getSkuInfo() == null) {
1657 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
1658 }
1659 skuInfo = getfpdPlatformDefs().getSkuInfo();
1660 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
1661 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1662 skuName.setSkuID(new BigInteger("0"));
1663 skuName.setStringValue("DEFAULT");
1664 }
1665 if (id.equals("0")) {
1666 return;
1667 }
1668 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1669 skuName.setSkuID(new BigInteger(id));
1670 skuName.setStringValue(name);
1671 }
1672
1673 public int getPlatformDefsSkuInfoCount(){
1674 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1675 return 0;
1676 }
1677 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
1678 }
1679
1680 public void getPlatformDefsSkuInfos(String[][] saa){
1681 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
1682 return ;
1683 }
1684
1685 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
1686 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
1687 int i = 0;
1688 while(li.hasNext()) {
1689 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
1690 saa[i][0] = sku.getSkuID()+"";
1691 saa[i][1] = sku.getStringValue();
1692 ++i;
1693 }
1694 }
1695
1696 public void removePlatformDefsSkuInfo(int i) {
1697 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
1698 if (skuInfo == null || i == 0) {
1699 return ;
1700 }
1701
1702 XmlCursor cursor = skuInfo.newCursor();
1703 if (cursor.toFirstChild()) {
1704 for (int j = 0; j < i; ++j) {
1705 cursor.toNextSibling();
1706 }
1707 cursor.removeXml();
1708 }
1709 cursor.dispose();
1710 }
1711
1712 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
1713 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
1714 if (skuInfo == null || i == 0) {
1715 return ;
1716 }
1717
1718 XmlCursor cursor = skuInfo.newCursor();
1719 if (cursor.toFirstChild()) {
1720 for (int j = 0; j < i; ++j) {
1721 cursor.toNextSibling();
1722 }
1723 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
1724 sku.setSkuID(new BigInteger(id));
1725 sku.setStringValue(name);
1726 }
1727 cursor.dispose();
1728 }
1729
1730 public String getPlatformDefsInterDir(){
1731 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
1732 return null;
1733 }
1734 return getfpdPlatformDefs().getIntermediateDirectories().toString();
1735 }
1736
1737 public void setPlatformDefsInterDir(String interDir){
1738 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
1739 }
1740
1741 public String getPlatformDefsOutputDir() {
1742 return getfpdPlatformDefs().getOutputDirectory();
1743 }
1744
1745 public void setPlatformDefsOutputDir(String outputDir) {
1746 getfpdPlatformDefs().setOutputDirectory(outputDir);
1747 }
1748
1749 public FlashDocument.Flash getfpdFlash() {
1750 if (fpdFlash == null) {
1751 fpdFlash = fpdRoot.addNewFlash();
1752 }
1753 return fpdFlash;
1754 }
1755
1756 public void genFlashDefinitionFile(String file) {
1757 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1758 if (fdf == null) {
1759 fdf = getfpdFlash().addNewFlashDefinitionFile();
1760 }
1761
1762 fdf.setStringValue(file);
1763 }
1764
1765 public String getFlashDefinitionFile() {
1766 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1767 if (fdf == null) {
1768 return "";
1769 }
1770
1771 return fdf.getStringValue();
1772 }
1773
1774
1775
1776 public void genFvImagesNameValue(String name, String value) {
1777
1778 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1779 if (fi == null) {
1780 fi = getfpdFlash().addNewFvImages();
1781 }
1782
1783 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
1784 nv.setName(name);
1785 nv.setValue(value);
1786 }
1787
1788 public void removeFvImagesNameValue(int i){
1789
1790 XmlObject o = getfpdFlash().getFvImages();
1791 if (o == null) {
1792 return;
1793 }
1794
1795 QName qNameValue = new QName(xmlNs, "NameValue");
1796 XmlCursor cursor = o.newCursor();
1797 if (cursor.toChild(qNameValue)) {
1798 for (int j = 0; j < i; ++j) {
1799 cursor.toNextSibling(qNameValue);
1800 }
1801 cursor.removeXml();
1802 }
1803 cursor.dispose();
1804 }
1805
1806 public void updateFvImagesNameValue(int i, String name, String value){
1807
1808 XmlObject o = getfpdFlash().getFvImages();
1809 if (o == null) {
1810 return;
1811 }
1812
1813 QName qNameValue = new QName(xmlNs, "NameValue");
1814 XmlCursor cursor = o.newCursor();
1815 if (cursor.toChild(qNameValue)) {
1816 for (int j = 0; j < i; ++j) {
1817 cursor.toNextSibling(qNameValue);
1818 }
1819 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
1820 nv.setName(name);
1821 nv.setValue(value);
1822 }
1823 cursor.dispose();
1824 }
1825
1826 public int getFvImagesNameValueCount() {
1827
1828 FvImagesDocument.FvImages fi = null;
1829 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
1830 return 0;
1831 }
1832 return fi.getNameValueList().size();
1833 }
1834
1835 public void getFvImagesNameValues(String[][] nv) {
1836
1837 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1838 if (fi == null){
1839 return;
1840 }
1841 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
1842 int i = 0;
1843 ListIterator li = l.listIterator();
1844 while (li.hasNext()) {
1845 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
1846 .next();
1847 nv[i][0] = e.getName();
1848 nv[i][1] = e.getValue();
1849
1850 i++;
1851 }
1852 }
1853
1854 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
1855
1856 FvImagesDocument.FvImages fis = null;
1857 if ((fis = getfpdFlash().getFvImages()) == null) {
1858 fis = getfpdFlash().addNewFvImages();
1859 }
1860
1861 //
1862 //gen FvImage with FvImageNames array
1863 //
1864 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
1865 for (int i = 0; i < names.length; ++i) {
1866 fi.addFvImageNames(names[i]);
1867 }
1868 fi.setType(FvImageTypes.Enum.forString(types));
1869 if (options != null){
1870 setFvImagesFvImageFvImageOptions(options, fi);
1871 }
1872 }
1873
1874 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
1875 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
1876 if (fio == null){
1877 fio = fi.addNewFvImageOptions();
1878 }
1879
1880 Set<String> key = options.keySet();
1881 Iterator<String> i = key.iterator();
1882 while (i.hasNext()) {
1883
1884 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
1885 String k = (String)i.next();
1886
1887 nv.setName(k);
1888 nv.setValue((String)options.get(k));
1889
1890 }
1891
1892 }
1893
1894
1895 public void removeFvImagesFvImage(int i) {
1896
1897 XmlObject o = getfpdFlash().getFvImages();
1898 if (o == null) {
1899 return;
1900 }
1901
1902 QName qFvImage = new QName(xmlNs, "FvImage");
1903 XmlCursor cursor = o.newCursor();
1904 if (cursor.toChild(qFvImage)) {
1905 for (int j = 0; j < i; ++j) {
1906 cursor.toNextSibling(qFvImage);
1907 }
1908 cursor.removeXml();
1909 }
1910 cursor.dispose();
1911 }
1912
1913 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
1914
1915 XmlObject o = getfpdFlash().getFvImages();
1916 if (o == null) {
1917 return;
1918 }
1919 XmlCursor cursor = o.newCursor();
1920 QName qFvImage = new QName(xmlNs, "FvImage");
1921 if (cursor.toChild(qFvImage)) {
1922 for (int j = 0; j < i; ++j) {
1923 cursor.toNextSibling(qFvImage);
1924 }
1925 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
1926 fi.setType(FvImageTypes.Enum.forString(types));
1927
1928 //
1929 // remove old FvImageNames before adding new ones
1930 //
1931 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
1932 cursor.toChild(qFvImageNames);
1933 cursor.removeXml();
1934 while (cursor.toNextSibling(qFvImageNames)) {
1935 cursor.removeXml();
1936 }
1937
1938 for (int k = 0; k < names.length; ++k) {
1939 fi.addFvImageNames(names[k]);
1940 }
1941 //
1942 // remove old FvImageOptions before adding new options
1943 //
1944 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
1945 cursor.toNextSibling(qFvImageOptions);
1946 cursor.removeXml();
1947
1948 setFvImagesFvImageFvImageOptions(options, fi);
1949 }
1950 cursor.dispose();
1951 }
1952
1953 public int getFvImagesFvImageCount() {
1954
1955 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1956 return 0;
1957 }
1958 return getfpdFlash().getFvImages().getFvImageList().size();
1959 }
1960
1961 /**Only Get Fv image setting - name and type.
1962 * @param saa
1963 */
1964 public void getFvImagesFvImages(String[][] saa) {
1965
1966 if (getfpdFlash().getFvImages() == null) {
1967 return;
1968 }
1969 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
1970 if (l == null) {
1971 return;
1972 }
1973 ListIterator li = l.listIterator();
1974 int i = 0;
1975 while(li.hasNext()) {
1976 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
1977 //
1978 // get FvImageNames array, space separated
1979 //
1980 List<String> lfn = fi.getFvImageNamesList();
1981 ListIterator lfni = lfn.listIterator();
1982 saa[i][0] = " ";
1983 while (lfni.hasNext()) {
1984 saa[i][0] += (String)lfni.next();
1985 saa[i][0] += " ";
1986 }
1987 saa[i][0] = saa[i][0].trim();
1988
1989 saa[i][1] = fi.getType()+"";
1990
1991 ++i;
1992 }
1993 }
1994
1995 /**Get FvImage Options for FvImage i
1996 * @param i the ith FvImage
1997 */
1998 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
1999 XmlObject o = getfpdFlash().getFvImages();
2000 if (o == null) {
2001 return;
2002 }
2003 XmlCursor cursor = o.newCursor();
2004 QName qFvImage = new QName(xmlNs, "FvImage");
2005 if (cursor.toChild(qFvImage)) {
2006 for (int j = 0; j < i; ++j) {
2007 cursor.toNextSibling(qFvImage);
2008 }
2009 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2010 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
2011 return;
2012 }
2013 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
2014 while(li.hasNext()){
2015 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
2016 m.put(nv.getName(), nv.getValue());
2017 }
2018 }
2019 }
2020
2021 /**
2022 Get platform header element
2023 @return PlatformHeaderDocument.PlatformHeader
2024 **/
2025 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
2026 if (fpdHdr == null) {
2027 fpdHdr = fpdRoot.addNewPlatformHeader();
2028 }
2029 genPlatformDefsSkuInfo("0", "DEFAULT");
2030 return fpdHdr;
2031 }
2032
2033 public String getFpdHdrPlatformName() {
2034 return getFpdHdr().getPlatformName();
2035 }
2036
2037 public String getFpdHdrGuidValue() {
2038 return getFpdHdr().getGuidValue();
2039 }
2040
2041 public String getFpdHdrVer() {
2042 return getFpdHdr().getVersion();
2043 }
2044
2045 public String getFpdHdrAbs() {
2046 return getFpdHdr().getAbstract();
2047 }
2048
2049 public String getFpdHdrDescription() {
2050 return getFpdHdr().getDescription();
2051 }
2052
2053 public String getFpdHdrCopyright() {
2054 return getFpdHdr().getCopyright();
2055 }
2056
2057 public String getFpdHdrLicense() {
2058 LicenseDocument.License l = getFpdHdr().getLicense();
2059 if (l == null) {
2060 return null;
2061 }
2062 return l.getStringValue();
2063 }
2064
2065 public String getFpdHdrUrl() {
2066 LicenseDocument.License l = getFpdHdr().getLicense();
2067 if (l == null) {
2068 return null;
2069 }
2070 return l.getURL();
2071 }
2072
2073 public String getFpdHdrSpec() {
2074
2075 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2076 // return getFpdHdr().getSpecification();
2077 }
2078
2079 public void setFpdHdrPlatformName(String name){
2080 getFpdHdr().setPlatformName(name);
2081 }
2082
2083 public void setFpdHdrGuidValue(String guid){
2084 getFpdHdr().setGuidValue(guid);
2085 }
2086
2087 public void setFpdHdrVer(String v){
2088 getFpdHdr().setVersion(v);
2089 }
2090
2091 public void setFpdHdrAbs(String abs) {
2092 getFpdHdr().setAbstract(abs);
2093 }
2094
2095 public void setFpdHdrDescription(String desc){
2096 getFpdHdr().setDescription(desc);
2097 }
2098
2099 public void setFpdHdrCopyright(String cr) {
2100 getFpdHdr().setCopyright(cr);
2101 }
2102
2103 public void setFpdHdrLicense(String license){
2104 LicenseDocument.License l = getFpdHdr().getLicense();
2105 if (l == null) {
2106 getFpdHdr().addNewLicense().setStringValue(license);
2107 }
2108 else {
2109 l.setStringValue(license);
2110 }
2111 }
2112
2113 public void setFpdHdrUrl(String url){
2114 LicenseDocument.License l = getFpdHdr().getLicense();
2115
2116 l.setURL(url);
2117
2118 }
2119
2120 public void setFpdHdrSpec(String s){
2121 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2122 getFpdHdr().setSpecification(s);
2123 }
2124 /**
2125 Save the processed xml contents to file
2126
2127 @param fpdFile The file to save xml contents
2128 @throws IOException Exceptions during file operation
2129 **/
2130 public void saveAs(File fpdFile) throws IOException {
2131
2132 XmlOptions options = new XmlOptions();
2133
2134 options.setCharacterEncoding("UTF-8");
2135 options.setSavePrettyPrint();
2136 options.setSavePrettyPrintIndent(2);
2137 try {
2138 fpdd.save(fpdFile, options);
2139 } catch (IOException e) {
2140 e.printStackTrace();
2141 }
2142
2143 }
2144
2145 private String listToString(List l) {
2146 if (l == null) {
2147 return null;
2148 }
2149 String s = " ";
2150 ListIterator li = l.listIterator();
2151 while(li.hasNext()) {
2152 s += li.next();
2153 s += " ";
2154 }
2155 return s.trim();
2156 }
2157 }