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