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