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