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