]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[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
27 import javax.xml.namespace.QName;
28
29 import org.apache.xmlbeans.XmlCursor;
30 import org.apache.xmlbeans.XmlObject;
31 import org.apache.xmlbeans.XmlOptions;
32 import org.tianocore.AntTaskDocument;
33 import org.tianocore.BuildOptionsDocument;
34 import org.tianocore.DynamicPcdBuildDefinitionsDocument;
35 import org.tianocore.FlashDefinitionFileDocument;
36 import org.tianocore.FlashDeviceDefinitionsDocument;
37 import org.tianocore.FlashDocument;
38 import org.tianocore.FrameworkModulesDocument;
39 import org.tianocore.FvRegionNameDocument;
40 import org.tianocore.LibrariesDocument;
41 import org.tianocore.ModuleSADocument;
42 import org.tianocore.ModuleSurfaceAreaDocument;
43 import org.tianocore.OptionDocument;
44 import org.tianocore.OptionsDocument;
45 import org.tianocore.PcdBuildDefinitionDocument;
46 import org.tianocore.PcdCodedDocument;
47 import org.tianocore.PcdDataTypes;
48 import org.tianocore.PcdDeclarationsDocument;
49 import org.tianocore.PcdItemTypes;
50 import org.tianocore.PlatformDefinitionsDocument;
51 import org.tianocore.PlatformSurfaceAreaDocument;
52 import org.tianocore.FvImageTypes;
53 import org.tianocore.FvImagesDocument;
54 import org.tianocore.LicenseDocument;
55 import org.tianocore.PlatformHeaderDocument;
56 import org.tianocore.SkuInfoDocument;
57 import org.tianocore.UserDefinedAntTasksDocument;
58 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
59 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
60 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
61 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
62
63 /**
64 This class processes fpd file contents such as add remove xml elements.
65 @since PackageEditor 1.0
66 **/
67 public class FpdFileContents {
68
69 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
70
71 private PlatformSurfaceAreaDocument fpdd = null;
72
73 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
74
75 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
76
77 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
78
79 private FlashDocument.Flash fpdFlash = null;
80
81 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
82
83 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
84
85 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
86
87 public static HashMap<String, ArrayList<String>> dynPcdMap = null;
88
89 /**
90 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
91 */
92 public void initDynPcdMap() {
93 if (dynPcdMap == null) {
94 dynPcdMap = new HashMap<String, ArrayList<String>>();
95 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
96 if (l == null) {
97 return;
98 }
99 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
100 while (li.hasNext()) {
101 ModuleSADocument.ModuleSA msa = li.next();
102 if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {
103 continue;
104 }
105 String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +
106 " " + msa.getPackageGuid() + " " + msa.getPackageVersion();
107 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();
108 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
109 while (lpi.hasNext()) {
110 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
111 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
112 if (dynPcdMap.get(pcdKey) == null) {
113 ArrayList<String> al = new ArrayList<String>();
114 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
115 dynPcdMap.put(pcdKey, al);
116 }
117 else{
118 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
119 }
120 }
121 }
122 }
123 }
124 /**
125 Constructor to create a new spd file
126 **/
127 public FpdFileContents() {
128
129 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
130 fpdRoot = fpdd.addNewPlatformSurfaceArea();
131
132 }
133
134 /**
135 Constructor for existing document object
136 @param psa
137 **/
138 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
139 fpdRoot = fpd;
140 fpdHdr = fpdRoot.getPlatformHeader();
141 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
142 fpdBuildOpts = fpdRoot.getBuildOptions();
143 fpdFrameworkModules = fpdRoot.getFrameworkModules();
144 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
145 fpdFlash = fpdRoot.getFlash();
146 }
147
148 /**
149 Constructor based on an existing spd file
150
151 @param f Existing spd file
152 **/
153 public FpdFileContents(File f) {
154 try {
155 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
156 fpdRoot = fpdd.getPlatformSurfaceArea();
157 } catch (Exception e) {
158 System.out.println(e.toString());
159 }
160 }
161
162 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
163 if (fpdDynPcdBuildDefs == null){
164 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
165 }
166 return fpdDynPcdBuildDefs;
167 }
168
169 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
170 if (fpdFrameworkModules == null){
171 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
172 }
173 return fpdFrameworkModules;
174 }
175
176 public int getPlatformDefsSkuInfoCount(){
177 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
178 return 0;
179 }
180 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
181 }
182
183 public void getPlatformDefsSkuInfos(String[][] saa){
184 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
185 return ;
186 }
187
188 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
189 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
190 int i = 0;
191 while(li.hasNext()) {
192 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
193 saa[i][0] = sku.getSkuID()+"";
194 saa[i][1] = sku.getStringValue();
195 ++i;
196 }
197 }
198
199 public int getFrameworkModulesCount() {
200 if (getfpdFrameworkModules().getModuleSAList() == null){
201 return 0;
202 }
203 return getfpdFrameworkModules().getModuleSAList().size();
204 }
205
206 public void getFrameworkModulesInfo(String[][] saa) {
207 if (getFrameworkModulesCount() == 0){
208 return;
209 }
210
211 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
212 int i = 0;
213 while(li.hasNext()) {
214 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();
215 saa[i][1] = msa.getModuleGuid();
216 saa[i][2] = msa.getModuleVersion();
217
218 saa[i][3] = msa.getPackageGuid();
219 saa[i][4] = msa.getPackageVersion();
220 // saa[i][4] = listToString(msa.getSupArchList());
221 ++i;
222 }
223 }
224
225 public ModuleSADocument.ModuleSA getModuleSA(String key) {
226 String[] s = key.split(" ");
227 if (getfpdFrameworkModules().getModuleSAList() == null) {
228 return null;
229 }
230 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
231 while(li.hasNext()) {
232 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();
233 if (msa.getModuleGuid().equals(s[0]) && msa.getModuleVersion().equals(s[1])
234 && msa.getPackageGuid().equals(s[2]) && msa.getPackageVersion().equals(s[3])) {
235
236 return msa;
237 }
238 }
239 return null;
240 }
241 public void removeModuleSA(int i) {
242 XmlObject o = getfpdFrameworkModules();
243 if (o == null) {
244 return;
245 }
246
247 XmlCursor cursor = o.newCursor();
248 if (cursor.toFirstChild()) {
249 for (int j = 0; j < i; ++j) {
250 cursor.toNextSibling();
251 }
252 //
253 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
254 //
255 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
256 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
257 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion();
258 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
259 if (pcdBuildDef != null) {
260 maintainDynPcdMap(pcdBuildDef, moduleInfo);
261 }
262 cursor.removeXml();
263 }
264 cursor.dispose();
265 }
266
267 private void maintainDynPcdMap(PcdBuildDefinitionDocument.PcdBuildDefinition o, String moduleInfo) {
268 XmlCursor cursor = o.newCursor();
269 boolean fromLibInstance = false;
270 if (!cursor.toFirstChild()){
271 return;
272 }
273 //
274 // deal with first child, same process in the while loop below for siblings.
275 //
276 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
277 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
278 ArrayList<String> al = dynPcdMap.get(pcdKey);
279 for(int i = 0; i < al.size(); ++i){
280 if (al.get(i).startsWith(moduleInfo)){
281 fromLibInstance = true;
282 break;
283 }
284 }
285 al.remove(moduleInfo + " " + pcdData.getItemType().toString());
286 if (al.size() == 0) {
287 dynPcdMap.remove(pcdKey);
288 }
289
290 if (pcdData.getItemType().toString().equals("DYNAMIC")) {
291 if (dynPcdMap.get(pcdKey) == null) {
292 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());
293 }
294 }
295 if (fromLibInstance){
296 cursor.removeXml();
297 }
298 while(cursor.toNextSibling()) {
299 fromLibInstance = false;
300 pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
301 //
302 // remove each pcd record from dynPcdMap
303 //
304 pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
305 al = dynPcdMap.get(pcdKey);
306 for(int i = 0; i < al.size(); ++i){
307 if (al.get(i).startsWith(moduleInfo)){
308 fromLibInstance = true;
309 break;
310 }
311 }
312 al.remove(moduleInfo + " " + pcdData.getItemType().toString());
313 if (al.size() == 0) {
314 dynPcdMap.remove(pcdKey);
315 }
316
317 if (pcdData.getItemType().toString().equals("DYNAMIC")) {
318 //
319 // First check whether this is the only consumer of this dyn pcd.
320 //
321 if (dynPcdMap.get(pcdKey) == null) {
322 //
323 // delete corresponding entry in DynamicPcdBuildData
324 //
325 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());
326 }
327 }
328 if (fromLibInstance){
329 cursor.removeXml();
330 }
331 }
332 }
333 //
334 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
335 //
336 public int getPcdDataCount(String key){
337 ModuleSADocument.ModuleSA msa = getModuleSA(key);
338 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
339 return 0;
340 }
341 return msa.getPcdBuildDefinition().getPcdDataList().size();
342 }
343
344 public void getPcdData(String key, String[][] saa) {
345 ModuleSADocument.ModuleSA msa = getModuleSA(key);
346 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
347 return;
348 }
349 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
350 for (int i = 0; i < saa.length; ++i) {
351 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
352 saa[i][0] = pcdData.getCName();
353 saa[i][1] = pcdData.getTokenSpaceGuidCName();
354 saa[i][2] = pcdData.getItemType().toString();
355 saa[i][3] = pcdData.getToken().toString();
356 saa[i][4] = pcdData.getDatumType().toString();
357 saa[i][5] = pcdData.getValue();
358
359 }
360 }
361 //
362 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"
363 //
364 public int getLibraryInstancesCount(String key) {
365 ModuleSADocument.ModuleSA msa = getModuleSA(key);
366 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
367 return 0;
368 }
369 return msa.getLibraries().getInstanceList().size();
370 }
371
372 public void getLibraryInstances(String key, String[][] saa){
373 ModuleSADocument.ModuleSA msa = getModuleSA(key);
374 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
375 return ;
376 }
377
378 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
379 for (int i = 0; i < saa.length; ++i) {
380 LibrariesDocument.Libraries.Instance instance = li.next();
381 saa[i][1] = instance.getModuleGuid();
382 saa[i][2] = instance.getModuleVersion();
383 saa[i][3] = instance.getPackageGuid();
384 saa[i][4] = instance.getPackageVersion();
385 }
386 }
387
388 public void removeLibraryInstances(String key) {
389 ModuleSADocument.ModuleSA msa = getModuleSA(key);
390 if (msa == null || msa.getLibraries() == null){
391 return ;
392 }
393
394 XmlCursor cursor = msa.getLibraries().newCursor();
395 cursor.removeXml();
396 cursor.dispose();
397 }
398
399 public void genLibraryInstance(String mg, String mv, String pg, String pv, String key) {
400 ModuleSADocument.ModuleSA msa = getModuleSA(key);
401 if (msa == null){
402 msa = getfpdFrameworkModules().addNewModuleSA();
403 }
404 LibrariesDocument.Libraries libs = msa.getLibraries();
405 if(libs == null){
406 libs = msa.addNewLibraries();
407 }
408
409 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
410 instance.setModuleGuid(mg);
411 instance.setModuleVersion(mv);
412 instance.setPackageGuid(pg);
413 instance.setPackageVersion(pv);
414
415 }
416 /**add pcd information of module mi to a ModuleSA.
417 * @param mi
418 * @param moduleSa if null, generate a new ModuleSA.
419 */
420 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, ModuleSADocument.ModuleSA moduleSa){
421 //ToDo add Arch filter
422
423 try {
424 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);
425 if (msa.getPcdCoded() == null) {
426 return;
427 }
428 if (moduleSa == null) {
429 moduleSa = genModuleSA(mi);
430 }
431 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
432 m.put("ModuleSurfaceArea", msa);
433 SurfaceAreaQuery.setDoc(m);
434 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);
435 //
436 // Implementing InitializePlatformPcdBuildDefinitions
437 //
438 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
439 ListIterator li = l.listIterator();
440 while(li.hasNext()) {
441 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
442 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
443 if (spdPcd == null) {
444 //
445 // ToDo Error
446 //
447 break;
448 }
449 //
450 // AddItem to ModuleSA PcdBuildDefinitions
451 //
452 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
453 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
454 }
455
456 }
457 catch (Exception e){
458 e.printStackTrace();
459 }
460
461 }
462
463 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
464
465 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
466 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
467 for (int i = 0; i < depPkgs.length; ++i) {
468 m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));
469 SurfaceAreaQuery.setDoc(m);
470 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();
471 if (xo == null) {
472 continue;
473 }
474 for (int j = 0; j < xo.length; ++j) {
475 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
476 if (msaPcd.getTokenSpaceGuidCName() == null) {
477 if (spdPcd.getCName().equals(msaPcd.getCName())) {
478 return spdPcd;
479 }
480 }
481 else{
482 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
483 return spdPcd;
484 }
485 }
486
487 }
488
489 }
490 return null;
491 }
492
493 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi) {
494 PackageIdentification pi = GlobalData.getPackageForModule(mi);
495 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
496 msa.setModuleGuid(mi.getGuid());
497 msa.setModuleVersion(mi.getVersion());
498 msa.setPackageGuid(pi.getGuid());
499 msa.setPackageVersion(pi.getVersion());
500
501 return msa;
502 }
503
504 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) {
505 if (moduleSa.getPcdBuildDefinition() == null){
506 moduleSa.addNewPcdBuildDefinition();
507 }
508 //
509 // constructe pcd to modulesa mapping first.
510 // Attention : for any error condition, remove from map this pcd.
511 //
512 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
513 if (pcdConsumer == null) {
514 pcdConsumer = new ArrayList<String>();
515 }
516 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
517 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion()
518 + " " + itemType;
519 pcdConsumer.add(listValue);
520 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
521 //
522 // Special dynamic type, if this pcd already exists in other ModuleSA
523 //
524 if (itemType.equals("DYNAMIC")) {
525
526 ListIterator li = pcdConsumer.listIterator();
527 while(li.hasNext()) {
528 String value = li.next().toString();
529 String[] valuePart= value.split(" ");
530 if (!valuePart[4].equals("DYNAMIC")) {
531 //ToDo error for same pcd, other type than dynamic
532 pcdConsumer.remove(listValue);
533 return;
534 }
535 }
536 }
537 else {
538 ListIterator li = pcdConsumer.listIterator();
539 while(li.hasNext()) {
540 String value = li.next().toString();
541 String[] valuePart= value.split(" ");
542 if (valuePart[4].equals("DYNAMIC")) {
543 //ToDo error for same pcd, other type than non-dynamic
544 pcdConsumer.remove(listValue);
545 return;
546 }
547 }
548 }
549
550 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
551 fpdPcd.setCName(cName);
552 fpdPcd.setToken(token);
553 fpdPcd.setTokenSpaceGuidCName(tsGuid);
554 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
555 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
556
557 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
558 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
559 //
560 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
561 // so need to add one dyn pcd.
562 //
563 if (al.size() == 1) {
564 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
565 }
566 }
567 else {
568 if (defaultVal != null){
569 fpdPcd.setValue(defaultVal);
570 }
571 else {
572 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
573 fpdPcd.setValue("0");
574 }
575 if (dataType.equals("BOOLEAN")){
576 fpdPcd.setValue("false");
577 }
578 if (dataType.equals("VOID*")) {
579 fpdPcd.setValue("");
580 }
581 }
582 if (dataType.equals("UINT8")){
583 fpdPcd.setMaxDatumSize(1);
584 }
585 if (dataType.equals("UINT16")) {
586 fpdPcd.setMaxDatumSize(2);
587 }
588 if (dataType.equals("UINT32")) {
589 fpdPcd.setMaxDatumSize(4);
590 }
591 if (dataType.equals("UINT64")){
592 fpdPcd.setMaxDatumSize(8);
593 }
594 if (dataType.equals("BOOLEAN")){
595 fpdPcd.setMaxDatumSize(1);
596 }
597 if (dataType.equals("VOID*")) {
598 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
599 fpdPcd.setMaxDatumSize(maxSize);
600 }
601 }
602 }
603
604 private int setMaxSizeForPointer(String datum) {
605 if (datum == null) {
606 return 0;
607 }
608 char ch = datum.charAt(0);
609 int start, end;
610 String strValue;
611 //
612 // For void* type PCD, only three datum is support:
613 // 1) Unicode: string with start char is "L"
614 // 2) Ansci: String is ""
615 // 3) byte array: String start char "{"
616 //
617 if (ch == 'L') {
618 start = datum.indexOf('\"');
619 end = datum.lastIndexOf('\"');
620 if ((start > end) ||
621 (end > datum.length())||
622 ((start == end) && (datum.length() > 0))) {
623 //ToDo Error handling here
624 }
625
626 strValue = datum.substring(start + 1, end);
627 return strValue.length() * 2;
628 } else if (ch == '\"'){
629 start = datum.indexOf('\"');
630 end = datum.lastIndexOf('\"');
631 if ((start > end) ||
632 (end > datum.length())||
633 ((start == end) && (datum.length() > 0))) {
634
635 }
636 strValue = datum.substring(start + 1, end);
637 return strValue.length();
638 } else if (ch =='{') {
639 String[] strValueArray;
640
641 start = datum.indexOf('{');
642 end = datum.lastIndexOf('}');
643 strValue = datum.substring(start + 1, end);
644 strValue = strValue.trim();
645 if (strValue.length() == 0) {
646 return 0;
647 }
648 strValueArray = strValue.split(",");
649 for (int index = 0; index < strValueArray.length; index ++) {
650 Integer value = Integer.decode(strValueArray[index].trim());
651
652 if (value > 0xFF) {
653 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
654 // "it is byte array in fact. But the element of %s exceed the byte range",
655
656 }
657 }
658 return strValueArray.length;
659
660
661 } else {
662 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
663 // "1) UNICODE string: like L\"xxxx\";\r\n"+
664 // "2) ANSIC string: like \"xxx\";\r\n"+
665 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
666 // "but the datum in seems does not following above format!",
667 return -1;
668
669 }
670 }
671
672 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
673 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
674
675 return al;
676 }
677
678 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
679
680 return dynPcdMap.get("pcdKey");
681 }
682
683 public int getDynamicPcdBuildDataCount() {
684 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
685 return 0;
686 }
687 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
688 }
689
690 public void getDynamicPcdBuildData(String[][] saa) {
691 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
692 return ;
693 }
694 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
695 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
696 int i = 0;
697 while(li.hasNext()) {
698 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
699 saa[i][0] = dynPcd.getCName();
700 saa[i][1] = dynPcd.getToken().toString();
701 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
702 saa[i][3] = dynPcd.getMaxDatumSize()+"";
703 saa[i][4] = dynPcd.getDatumType().toString();
704
705 ++i;
706 }
707 }
708
709 private void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) {
710 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
711 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
712 dynPcdData.setCName(cName);
713 dynPcdData.setToken(token);
714 dynPcdData.setTokenSpaceGuidCName(tsGuid);
715 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
716
717 BigInteger bigInt = new BigInteger("0");
718 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
719 skuInfo.setSkuId(bigInt);
720 if (defaultVal != null){
721 skuInfo.setValue(defaultVal);
722 }
723 else {
724 if (dataType.equals("UINT8")){
725 skuInfo.setValue("0");
726 }
727 if (dataType.equals("UINT16")) {
728 skuInfo.setValue("0");
729 }
730 if (dataType.equals("UINT32")) {
731 skuInfo.setValue("0");
732 }
733 if (dataType.equals("UINT64")){
734 skuInfo.setValue("0");
735 }
736 if (dataType.equals("BOOLEAN")){
737 skuInfo.setValue("false");
738 }
739 if (dataType.equals("VOID*")) {
740 skuInfo.setValue("");
741 }
742 }
743 if (dataType.equals("UINT8")){
744 dynPcdData.setMaxDatumSize(1);
745 }
746 if (dataType.equals("UINT16")) {
747 dynPcdData.setMaxDatumSize(2);
748 }
749 if (dataType.equals("UINT32")) {
750 dynPcdData.setMaxDatumSize(4);
751 }
752 if (dataType.equals("UINT64")){
753 dynPcdData.setMaxDatumSize(8);
754 }
755 if (dataType.equals("BOOLEAN")){
756 dynPcdData.setMaxDatumSize(1);
757 }
758 if (dataType.equals("VOID*")) {
759 int maxSize = setMaxSizeForPointer(defaultVal);
760 dynPcdData.setMaxDatumSize(maxSize);
761 }
762 }
763
764 private void removeDynamicPcdBuildData(String cName, String tsGuid) {
765 XmlObject o = getfpdDynPcdBuildDefs();
766
767 XmlCursor cursor = o.newCursor();
768 if (cursor.toFirstChild()) {
769 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
770 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
771 while (!(pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid))) {
772 cursor.toNextSibling();
773 pcdBuildData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
774 }
775
776 cursor.removeXml();
777 }
778 cursor.dispose();
779 }
780 //
781 // Get the Sku Info count of ith dyn pcd element.
782 //
783 public int getDynamicPcdSkuInfoCount(int i){
784 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
785 return 0;
786 }
787
788 int skuInfoCount = 0;
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 skuInfoCount = 0;
797 }
798 else {
799 skuInfoCount = pcdData.getSkuInfoList().size();
800 }
801 }
802 cursor.dispose();
803 return skuInfoCount;
804 }
805
806 public void getDynamicPcdSkuInfos(int i, String[][] saa){
807 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
808 return;
809 }
810
811 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
812 if (cursor.toFirstChild()) {
813 for (int j = 0; j < i; ++j) {
814 cursor.toNextSibling();
815 }
816 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
817 if (pcdData.getSkuInfoList() == null) {
818 cursor.dispose();
819 return;
820 }
821 else {
822 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
823 int k = 0;
824 while (li.hasNext()) {
825 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
826 saa[k][0] = skuInfo.getSkuId()+"";
827 saa[k][1] = skuInfo.getVariableName();
828 saa[k][2] = skuInfo.getVariableGuid();
829 saa[k][3] = skuInfo.getVariableOffset();
830 saa[k][4] = skuInfo.getHiiDefaultValue();
831 saa[k][5] = skuInfo.getVpdOffset();
832 saa[k][6] = skuInfo.getValue();
833 ++k;
834 }
835
836 }
837 }
838 cursor.dispose();
839
840 }
841
842 public String getDynamicPcdBuildDataValue(int i){
843 String value = null;
844 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
845 return value;
846 }
847
848 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
849 if (cursor.toFirstChild()) {
850 for (int j = 0; j < i; ++j) {
851 cursor.toNextSibling();
852 }
853 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
854 if (pcdData.getSkuInfoList() == null) {
855 value = null;
856 }
857 else {
858 value = pcdData.getSkuInfoArray(0).getValue();
859 }
860 }
861 cursor.dispose();
862 return value;
863 }
864
865 public String getDynamicPcdBuildDataVpdOffset(int i){
866 String vpdOffset = null;
867 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
868 return vpdOffset;
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 vpdOffset = null;
879 }
880 else {
881 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
882 }
883 }
884 cursor.dispose();
885 return vpdOffset;
886 }
887
888 public void removeDynamicPcdBuildDataSkuInfo(int i) {
889 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
890 return;
891 }
892
893 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
894 if (cursor.toFirstChild()) {
895 for (int j = 0; j < i; ++j) {
896 cursor.toNextSibling();
897 }
898 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
899 if (pcdData.getSkuInfoList() == null) {
900 cursor.dispose();
901 return;
902 }
903 else {
904 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
905 cursor.toChild(qSkuInfo);
906 cursor.removeXml();
907 }
908 }
909 cursor.dispose();
910 }
911 //
912 // generate sku info for ith dyn pcd build data.
913 //
914 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
915 String hiiDefault, String vpdOffset, String value, int i) {
916 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
917 return;
918 }
919
920 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
921 if (cursor.toFirstChild()) {
922 for (int j = 0; j < i; ++j) {
923 cursor.toNextSibling();
924 }
925 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
926 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
927 skuInfo.setSkuId(new BigInteger(id));
928 if (varName != null){
929 skuInfo.setVariableName(varName);
930 skuInfo.setVariableGuid(varGuid);
931 skuInfo.setVariableOffset(varOffset);
932 skuInfo.setHiiDefaultValue(hiiDefault);
933 }
934 else if (vpdOffset != null){
935 skuInfo.setVpdOffset(vpdOffset);
936 }
937 else{
938 skuInfo.setValue(value);
939 }
940 }
941 }
942
943 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
944 String hiiDefault, String vpdOffset, String value, int i){
945 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
946 return;
947 }
948
949 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
950 if (cursor.toFirstChild()) {
951 for (int j = 0; j < i; ++j) {
952 cursor.toNextSibling();
953 }
954 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
955 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
956 while (li.hasNext()) {
957 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
958 if (skuInfo.getSkuId().toString().equals(id)){
959 if (varName != null){
960 skuInfo.setVariableName(varName);
961 skuInfo.setVariableGuid(varGuid);
962 skuInfo.setVariableOffset(varOffset);
963 skuInfo.setHiiDefaultValue(hiiDefault);
964 }
965 else if (vpdOffset != null){
966 skuInfo.setVpdOffset(vpdOffset);
967 }
968 else{
969 skuInfo.setValue(value);
970 }
971 break;
972 }
973 }
974 }
975 }
976
977 public void removePcdDataFromLibraryInstance(String moduleKey, String libInstanceKey){
978 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);
979 //
980 // should better maintain pcd from lib instance only, but maintain all is acceptable now.
981 //
982 maintainDynPcdMap(moduleSa.getPcdBuildDefinition(), libInstanceKey);
983
984 }
985
986 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
987 if (fpdBuildOpts == null) {
988 fpdBuildOpts = fpdRoot.addNewBuildOptions();
989 }
990 return fpdBuildOpts;
991 }
992
993 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
994 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
995 if (udats == null) {
996 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
997 }
998
999 AntTaskDocument.AntTask at = udats.addNewAntTask();
1000 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1001 }
1002
1003 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1004 at.setId(new Integer(id));
1005 if (fileName != null){
1006 at.setFilename(fileName);
1007 }
1008 else {
1009 at.setAntCmdOptions(execOrder);
1010 }
1011 }
1012
1013 public void removeBuildOptionsUserDefAntTask(int i) {
1014 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1015 if (o == null) {
1016 return;
1017 }
1018 XmlCursor cursor = o.newCursor();
1019 if (cursor.toFirstChild()) {
1020 for (int j = 0; j < i; ++j) {
1021 cursor.toNextSibling();
1022 }
1023 cursor.removeXml();
1024 }
1025 cursor.dispose();
1026 }
1027
1028 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1029 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1030 if (o == null) {
1031 return;
1032 }
1033 XmlCursor cursor = o.newCursor();
1034 if (cursor.toFirstChild()) {
1035 for (int j = 0; j < i; ++j) {
1036 cursor.toNextSibling();
1037 }
1038 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1039 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1040 }
1041 cursor.dispose();
1042 }
1043
1044 public int getBuildOptionsUserDefAntTaskCount() {
1045 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1046 if (udats == null || udats.getAntTaskList() == null) {
1047 return 0;
1048 }
1049
1050 return udats.getAntTaskList().size();
1051 }
1052
1053 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1054 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1055 if (udats == null || udats.getAntTaskList() == null) {
1056 return ;
1057 }
1058
1059 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1060 ListIterator li = l.listIterator();
1061 int i = 0;
1062 while (li.hasNext()) {
1063 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1064 saa[i][0] = at.getId() + "";
1065 saa[i][1] = saa[i][2] = "";
1066 if (at.getFilename() != null){
1067 saa[i][1] = at.getFilename();
1068 }
1069 if (at.getAntCmdOptions() != null) {
1070 saa[i][2] = at.getAntCmdOptions();
1071 }
1072 ++i;
1073 }
1074 }
1075 public void genBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {
1076 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1077 if (opts == null) {
1078 opts = getfpdBuildOpts().addNewOptions();
1079 }
1080 OptionDocument.Option opt = opts.addNewOption();
1081 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1082 }
1083
1084 private void setBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents, OptionDocument.Option opt){
1085 opt.setStringValue(contents);
1086 // opt.setBuildTargets(buildTargets);
1087 opt.setToolChainFamily(toolChain);
1088 opt.setTagName(tagName);
1089 opt.setToolCode(toolCmd);
1090 String[] s = archList.split(" ");
1091 ArrayList<String> al = new ArrayList<String>();
1092 for (int i = 0; i < s.length; ++i) {
1093 al.add(s[i]);
1094 }
1095 opt.setSupArchList(al);
1096 }
1097
1098 public void removeBuildOptionsOpt(int i){
1099
1100 XmlObject o = getfpdBuildOpts().getOptions();
1101 if (o == null) {
1102 return;
1103 }
1104
1105 XmlCursor cursor = o.newCursor();
1106 if (cursor.toFirstChild()) {
1107 for (int j = 0; j < i; ++j) {
1108 cursor.toNextSibling();
1109 }
1110 cursor.removeXml();
1111 }
1112 cursor.dispose();
1113 }
1114
1115 public void updateBuildOptionsOpt(int i, String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {
1116 XmlObject o = getfpdBuildOpts().getOptions();
1117 if (o == null) {
1118 return;
1119 }
1120
1121 XmlCursor cursor = o.newCursor();
1122 if (cursor.toFirstChild()) {
1123 for (int j = 0; j < i; ++j) {
1124 cursor.toNextSibling();
1125 }
1126 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1127 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1128 }
1129 cursor.dispose();
1130 }
1131
1132 public int getBuildOptionsOptCount(){
1133 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1134 return 0;
1135 }
1136 return getfpdBuildOpts().getOptions().getOptionList().size();
1137 }
1138
1139 public void getBuildOptionsOpts(String[][] saa) {
1140 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1141 return ;
1142 }
1143
1144 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1145 ListIterator li = lOpt.listIterator();
1146 int i = 0;
1147 while(li.hasNext()) {
1148 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1149 // saa[i][0] = opt.getBuildTargets();
1150 saa[i][1] = opt.getToolChainFamily();
1151 if (opt.getSupArchList() != null){
1152 Object[] archs = opt.getSupArchList().toArray();
1153 saa[i][2] = " ";
1154 for (int j = 0; j < archs.length; ++j){
1155 saa[i][2] += archs[j];
1156 saa[i][2] += " ";
1157 }
1158 saa[i][2] = saa[i][2].trim();
1159 }
1160 saa[i][3] = opt.getToolCode();
1161 saa[i][4] = opt.getTagName();
1162 saa[i][5] = opt.getStringValue();
1163
1164 ++i;
1165 }
1166 }
1167
1168 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
1169 if (fpdPlatformDefs == null){
1170 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
1171 }
1172 return fpdPlatformDefs;
1173 }
1174
1175 public FlashDocument.Flash getfpdFlash() {
1176 if (fpdFlash == null) {
1177 fpdFlash = fpdRoot.addNewFlash();
1178 }
1179 return fpdFlash;
1180 }
1181
1182 public void genFlashDefinitionFile(String file) {
1183 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1184 if (fdf == null) {
1185 fdf = getfpdFlash().addNewFlashDefinitionFile();
1186 }
1187
1188 fdf.setStringValue(file);
1189 }
1190
1191 public String getFlashDefinitionFile() {
1192 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
1193 if (fdf == null) {
1194 return "";
1195 }
1196
1197 return fdf.getStringValue();
1198 }
1199
1200
1201
1202 public void genFvImagesNameValue(String name, String value) {
1203
1204 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1205 if (fi == null) {
1206 fi = getfpdFlash().addNewFvImages();
1207 }
1208
1209 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
1210 nv.setName(name);
1211 nv.setValue(value);
1212 }
1213
1214 public void removeFvImagesNameValue(int i){
1215
1216 XmlObject o = getfpdFlash().getFvImages();
1217 if (o == null) {
1218 return;
1219 }
1220
1221 QName qNameValue = new QName(xmlNs, "NameValue");
1222 XmlCursor cursor = o.newCursor();
1223 if (cursor.toChild(qNameValue)) {
1224 for (int j = 0; j < i; ++j) {
1225 cursor.toNextSibling(qNameValue);
1226 }
1227 cursor.removeXml();
1228 }
1229 cursor.dispose();
1230 }
1231
1232 public void updateFvImagesNameValue(int i, String name, String value){
1233
1234 XmlObject o = getfpdFlash().getFvImages();
1235 if (o == null) {
1236 return;
1237 }
1238
1239 QName qNameValue = new QName(xmlNs, "NameValue");
1240 XmlCursor cursor = o.newCursor();
1241 if (cursor.toChild(qNameValue)) {
1242 for (int j = 0; j < i; ++j) {
1243 cursor.toNextSibling(qNameValue);
1244 }
1245 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
1246 nv.setName(name);
1247 nv.setValue(value);
1248 }
1249 cursor.dispose();
1250 }
1251
1252 public int getFvImagesNameValueCount() {
1253
1254 FvImagesDocument.FvImages fi = null;
1255 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
1256 return 0;
1257 }
1258 return fi.getNameValueList().size();
1259 }
1260
1261 public void getFvImagesNameValues(String[][] nv) {
1262
1263 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
1264 if (fi == null){
1265 return;
1266 }
1267 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
1268 int i = 0;
1269 ListIterator li = l.listIterator();
1270 while (li.hasNext()) {
1271 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
1272 .next();
1273 nv[i][0] = e.getName();
1274 nv[i][1] = e.getValue();
1275
1276 i++;
1277 }
1278 }
1279
1280 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
1281
1282 FvImagesDocument.FvImages fis = null;
1283 if ((fis = getfpdFlash().getFvImages()) == null) {
1284 fis = getfpdFlash().addNewFvImages();
1285 }
1286
1287 //
1288 //gen FvImage with FvImageNames array
1289 //
1290 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
1291 for (int i = 0; i < names.length; ++i) {
1292 fi.addFvImageNames(names[i]);
1293 }
1294 fi.setType(FvImageTypes.Enum.forString(types));
1295 if (options != null){
1296 setFvImagesFvImageFvImageOptions(options, fi);
1297 }
1298 }
1299
1300 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
1301 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
1302 if (fio == null){
1303 fio = fi.addNewFvImageOptions();
1304 }
1305
1306 Set<String> key = options.keySet();
1307 Iterator<String> i = key.iterator();
1308 while (i.hasNext()) {
1309 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
1310 String k = (String)i.next();
1311 nv.setName(k);
1312 nv.setValue((String)options.get(k));
1313
1314 }
1315
1316 }
1317
1318 public void removeFvImagesFvImage(int i) {
1319
1320 XmlObject o = getfpdFlash().getFvImages();
1321 if (o == null) {
1322 return;
1323 }
1324
1325 QName qFvImage = new QName(xmlNs, "FvImage");
1326 XmlCursor cursor = o.newCursor();
1327 if (cursor.toChild(qFvImage)) {
1328 for (int j = 0; j < i; ++j) {
1329 cursor.toNextSibling(qFvImage);
1330 }
1331 cursor.removeXml();
1332 }
1333 cursor.dispose();
1334 }
1335
1336 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
1337
1338 XmlObject o = getfpdFlash().getFvImages();
1339 if (o == null) {
1340 return;
1341 }
1342 XmlCursor cursor = o.newCursor();
1343 QName qFvImage = new QName(xmlNs, "FvImage");
1344 if (cursor.toChild(qFvImage)) {
1345 for (int j = 0; j < i; ++j) {
1346 cursor.toNextSibling(qFvImage);
1347 }
1348 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
1349 fi.setType(FvImageTypes.Enum.forString(types));
1350
1351 //
1352 // remove old FvImageNames before adding new ones
1353 //
1354 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
1355 cursor.toChild(qFvImageNames);
1356 cursor.removeXml();
1357 while (cursor.toNextSibling(qFvImageNames)) {
1358 cursor.removeXml();
1359 }
1360
1361 for (int k = 0; k < names.length; ++k) {
1362 fi.addFvImageNames(names[k]);
1363 }
1364 //
1365 // remove old FvImageOptions before adding new options
1366 //
1367 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
1368 cursor.toNextSibling(qFvImageOptions);
1369 cursor.removeXml();
1370
1371 setFvImagesFvImageFvImageOptions(options, fi);
1372 }
1373 cursor.dispose();
1374 }
1375
1376 public int getFvImagesFvImageCount() {
1377
1378 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
1379 return 0;
1380 }
1381 return getfpdFlash().getFvImages().getFvImageList().size();
1382 }
1383
1384 public void getFvImagesFvImages(String[][] saa, ArrayList<LinkedHashMap<String, String>> options) {
1385
1386 if (getfpdFlash().getFvImages() == null) {
1387 return;
1388 }
1389 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
1390 if (l == null) {
1391 return;
1392 }
1393 ListIterator li = l.listIterator();
1394 int i = 0;
1395 while(li.hasNext()) {
1396 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
1397 //
1398 // get FvImageNames array, space separated
1399 //
1400 List<String> lfn = fi.getFvImageNamesList();
1401 ListIterator lfni = lfn.listIterator();
1402 saa[i][0] = " ";
1403 while (lfni.hasNext()) {
1404 saa[i][0] += (String)lfni.next();
1405 saa[i][0] += " ";
1406 }
1407 saa[i][0] = saa[i][0].trim();
1408
1409 saa[i][1] = fi.getType()+"";
1410
1411 //
1412 // get FvImageOptions into Map[i]
1413 //
1414 FvImagesDocument.FvImages.FvImage.FvImageOptions fo = fi.getFvImageOptions();
1415 if (fo == null) {
1416 ++i;
1417 continue;
1418 }
1419 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> lnv = fo.getNameValueList();
1420 if (lnv == null || lnv.isEmpty()) {
1421 ++i;
1422 continue;
1423 }
1424 ListIterator lnvi = lnv.listIterator();
1425 while (lnvi.hasNext()) {
1426 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)lnvi.next();
1427 Map<String, String> m = options.get(i);
1428 m.put(nv.getName(), nv.getValue());
1429 }
1430
1431 ++i;
1432 }
1433 }
1434
1435 /**
1436 Get platform header element
1437 @return PlatformHeaderDocument.PlatformHeader
1438 **/
1439 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
1440 if (fpdHdr == null) {
1441 fpdHdr = fpdRoot.addNewPlatformHeader();
1442 }
1443 genPlatformDefsSkuInfo("0", "DEFAULT");
1444 return fpdHdr;
1445 }
1446
1447 public void genPlatformDefsSkuInfo(String id, String name) {
1448 SkuInfoDocument.SkuInfo skuInfo = null;
1449 if (getfpdPlatformDefs().getSkuInfo() == null) {
1450 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
1451 }
1452 skuInfo = getfpdPlatformDefs().getSkuInfo();
1453 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
1454 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1455 skuName.setSkuID(new BigInteger("0"));
1456 skuName.setStringValue("DEFAULT");
1457 }
1458 if (id.equals("0")) {
1459 return;
1460 }
1461 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
1462 skuName.setSkuID(new BigInteger(id));
1463 skuName.setStringValue(name);
1464
1465
1466 }
1467 public String getFpdHdrPlatformName() {
1468 return getFpdHdr().getPlatformName();
1469 }
1470
1471 public String getFpdHdrGuidValue() {
1472 return getFpdHdr().getGuidValue();
1473 }
1474
1475 public String getFpdHdrVer() {
1476 return getFpdHdr().getVersion();
1477 }
1478
1479 public String getFpdHdrAbs() {
1480 return getFpdHdr().getAbstract();
1481 }
1482
1483 public String getFpdHdrDescription() {
1484 return getFpdHdr().getDescription();
1485 }
1486
1487 public String getFpdHdrCopyright() {
1488 return getFpdHdr().getCopyright();
1489 }
1490
1491 public String getFpdHdrLicense() {
1492 LicenseDocument.License l = getFpdHdr().getLicense();
1493 if (l == null) {
1494 return null;
1495 }
1496 return l.getStringValue();
1497 }
1498
1499 public String getFpdHdrUrl() {
1500 LicenseDocument.License l = getFpdHdr().getLicense();
1501 if (l == null) {
1502 return null;
1503 }
1504 return l.getURL();
1505 }
1506
1507 public String getFpdHdrSpec() {
1508
1509 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1510 // return getFpdHdr().getSpecification();
1511 }
1512
1513 public void setFpdHdrPlatformName(String name){
1514 getFpdHdr().setPlatformName(name);
1515 }
1516
1517 public void setFpdHdrGuidValue(String guid){
1518 getFpdHdr().setGuidValue(guid);
1519 }
1520
1521 public void setFpdHdrVer(String v){
1522 getFpdHdr().setVersion(v);
1523 }
1524
1525 public void setFpdHdrAbs(String abs) {
1526 getFpdHdr().setAbstract(abs);
1527 }
1528
1529 public void setFpdHdrDescription(String desc){
1530 getFpdHdr().setDescription(desc);
1531 }
1532
1533 public void setFpdHdrCopyright(String cr) {
1534 getFpdHdr().setCopyright(cr);
1535 }
1536
1537 public void setFpdHdrLicense(String license){
1538 LicenseDocument.License l = getFpdHdr().getLicense();
1539 if (l == null) {
1540 getFpdHdr().addNewLicense().setStringValue(license);
1541 }
1542 else {
1543 l.setStringValue(license);
1544 }
1545 }
1546
1547 public void setFpdHdrUrl(String url){
1548 LicenseDocument.License l = getFpdHdr().getLicense();
1549
1550 l.setURL(url);
1551
1552 }
1553
1554 public void setFpdHdrSpec(String s){
1555 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1556 getFpdHdr().setSpecification(s);
1557 }
1558 /**
1559 Save the processed xml contents to file
1560
1561 @param fpdFile The file to save xml contents
1562 @throws IOException Exceptions during file operation
1563 **/
1564 public void saveAs(File fpdFile) throws IOException {
1565
1566 XmlOptions options = new XmlOptions();
1567
1568 options.setCharacterEncoding("UTF-8");
1569 options.setSavePrettyPrint();
1570 options.setSavePrettyPrintIndent(2);
1571 try {
1572 fpdd.save(fpdFile, options);
1573 } catch (IOException e) {
1574 e.printStackTrace();
1575 }
1576
1577 }
1578
1579 private String listToString(List<String> l) {
1580 if (l == null) {
1581 return null;
1582 }
1583 String s = " ";
1584 ListIterator li = l.listIterator();
1585 while(li.hasNext()) {
1586 s += li.next();
1587 s += " ";
1588 }
1589 return s.trim();
1590 }
1591 }