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