]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
1.change GlobalData to WorkspaceProfile.
[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.platform.ui.id.ModuleIdentification;
64 import org.tianocore.frameworkwizard.platform.ui.id.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.getPackage().getName();
706 String pg = libMi.getPackage().getGuid();
707 String pv = libMi.getPackage().getVersion();
708 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
709 XmlCursor cursor = instance.newCursor();
710 try{
711 String comment = "Pkg: " + pn + " Mod: " + mn
712 + " Path: " + WorkspaceProfile.getMsaFile(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 getModuleSAOptions(String moduleKey, String[][] saa) {
801 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
802 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
803 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
804 return ;
805 }
806
807 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
808 ListIterator li = lOpt.listIterator();
809 int i = 0;
810 while(li.hasNext()) {
811 OptionDocument.Option opt = (OptionDocument.Option)li.next();
812 if (opt.getBuildTargets() != null) {
813 saa[i][0] = listToString(opt.getBuildTargets());
814 }
815 saa[i][1] = opt.getToolChainFamily();
816 saa[i][2] = opt.getTagName();
817 saa[i][3] = opt.getToolCode();
818
819 if (opt.getSupArchList() != null){
820 saa[i][4] = listToString(opt.getSupArchList());
821
822 }
823
824 saa[i][5] = opt.getStringValue();
825
826 ++i;
827 }
828 }
829
830 public int getModuleSAOptionsCount(String moduleKey){
831 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
832 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
833 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
834 return 0;
835 }
836 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
837 }
838
839 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
840 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
841 if (msa.getModuleSaBuildOptions() == null) {
842 msa.addNewModuleSaBuildOptions();
843 }
844 if (msa.getModuleSaBuildOptions().getOptions() == null){
845 msa.getModuleSaBuildOptions().addNewOptions();
846 }
847 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
848 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
849 }
850
851 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
852 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
853 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
854 return ;
855 }
856 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
857 XmlCursor cursor = opts.newCursor();
858 if (cursor.toFirstChild()) {
859 for (int j = 0; j < i; ++j){
860 cursor.toNextSibling();
861 }
862 cursor.removeXml();
863 }
864 cursor.dispose();
865 }
866
867 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
868 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
869 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
870 return ;
871 }
872 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
873 XmlCursor cursor = opts.newCursor();
874 if (cursor.toFirstChild()) {
875 for (int j = 0; j < i; ++j){
876 cursor.toNextSibling();
877 }
878 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
879 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
880 }
881 cursor.dispose();
882 }
883
884 /**add pcd information of module mi to a ModuleSA.
885 * @param mi
886 * @param moduleSa if null, generate a new ModuleSA.
887 */
888 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
889 //ToDo add Arch filter
890
891 try {
892 if (moduleSa == null) {
893 moduleSa = genModuleSA(mi, arch);
894 }
895
896 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
897 if (msa.getPcdCoded() == null) {
898 return;
899 }
900
901 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
902 m.put("ModuleSurfaceArea", msa);
903 SurfaceAreaQuery.setDoc(m);
904 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
905 //
906 // Implementing InitializePlatformPcdBuildDefinitions
907 //
908 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
909 ListIterator li = l.listIterator();
910 while(li.hasNext()) {
911 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
912 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
913 if (spdPcd == null) {
914 //
915 // ToDo Error
916 //
917 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());
918 }
919 //
920 // AddItem to ModuleSA PcdBuildDefinitions
921 //
922 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
923
924 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
925 }
926
927 }
928 catch (Exception e){
929
930 throw e;
931 }
932
933 }
934
935 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
936
937 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
938 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
939 for (int i = 0; i < depPkgs.length; ++i) {
940 m.put("PackageSurfaceArea", WorkspaceProfile.getPackageXmlObject(depPkgs[i]));
941 SurfaceAreaQuery.setDoc(m);
942 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();
943 if (xo == null) {
944 continue;
945 }
946 for (int j = 0; j < xo.length; ++j) {
947 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
948 if (msaPcd.getTokenSpaceGuidCName() == null) {
949 if (spdPcd.getCName().equals(msaPcd.getCName())) {
950 return spdPcd;
951 }
952 }
953 else{
954 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
955 return spdPcd;
956 }
957 }
958
959 }
960
961 }
962 return null;
963 }
964
965 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
966 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
967 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
968 XmlCursor cursor = msa.newCursor();
969 try{
970 String comment = "Mod: " + mi.getName() + " Type: " + mi.getModuleType() + " Path: "
971 + WorkspaceProfile.getMsaFile(mi).getPath().substring(System.getenv("WORKSPACE").length() + 1);
972 cursor.insertComment(comment);
973 }
974 catch(Exception e){
975 e.printStackTrace();
976 }
977 finally {
978 cursor.dispose();
979 }
980 msa.setModuleGuid(mi.getGuid());
981 msa.setModuleVersion(mi.getVersion());
982 msa.setPackageGuid(pi.getGuid());
983 msa.setPackageVersion(pi.getVersion());
984 if (arch != null) {
985 Vector<String> v = new Vector<String>();
986 v.add(arch);
987 msa.setSupArchList(v);
988 }
989
990 return msa;
991 }
992
993 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa)
994 throws PcdItemTypeConflictException, PcdValueMalFormed{
995 if (moduleSa.getPcdBuildDefinition() == null){
996 moduleSa.addNewPcdBuildDefinition();
997 }
998 //
999 // constructe pcd to modulesa mapping first.
1000 // Attention : for any error condition, remove from map this pcd.
1001 //
1002 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1003 if (pcdConsumer == null) {
1004 pcdConsumer = new ArrayList<String>();
1005 }
1006 //
1007 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1008 //
1009 if (pcdConsumer.size() > 0) {
1010 String[] valPart = pcdConsumer.get(0).split(" ");
1011 itemType = valPart[5];
1012 }
1013 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
1014 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())
1015 + " " + itemType;
1016 pcdConsumer.add(listValue);
1017 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1018
1019 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1020 fpdPcd.setCName(cName);
1021 fpdPcd.setToken(token);
1022 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1023 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1024 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1025
1026 if (defaultVal != null){
1027 fpdPcd.setValue(defaultVal);
1028 }
1029 else {
1030 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1031 fpdPcd.setValue("0");
1032 }
1033 if (dataType.equals("BOOLEAN")){
1034 fpdPcd.setValue("false");
1035 }
1036 if (dataType.equals("VOID*")) {
1037 fpdPcd.setValue("");
1038 }
1039 }
1040 //
1041 // Using existing pcd value, if this pcd already exists in other moduleSa.
1042 //
1043 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1044 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1045 }
1046 else {
1047 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1048 }
1049
1050 if (dataType.equals("UINT8")){
1051 fpdPcd.setMaxDatumSize(1);
1052 }
1053 if (dataType.equals("UINT16")) {
1054 fpdPcd.setMaxDatumSize(2);
1055 }
1056 if (dataType.equals("UINT32")) {
1057 fpdPcd.setMaxDatumSize(4);
1058 }
1059 if (dataType.equals("UINT64")){
1060 fpdPcd.setMaxDatumSize(8);
1061 }
1062 if (dataType.equals("BOOLEAN")){
1063 fpdPcd.setMaxDatumSize(1);
1064 }
1065 if (dataType.equals("VOID*")) {
1066 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1067 fpdPcd.setMaxDatumSize(maxSize);
1068 }
1069
1070
1071 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1072 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1073 //
1074 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1075 // so need to add one dyn pcd.
1076 //
1077 if (al.size() == 1) {
1078 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1079 }
1080 }
1081
1082 }
1083
1084 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1085 if (datum == null) {
1086 return 0;
1087 }
1088 char ch = datum.charAt(0);
1089 int start, end;
1090 String strValue;
1091 //
1092 // For void* type PCD, only three datum is support:
1093 // 1) Unicode: string with start char is "L"
1094 // 2) Ansci: String is ""
1095 // 3) byte array: String start char "{"
1096 //
1097 if (ch == 'L') {
1098 start = datum.indexOf('\"');
1099 end = datum.lastIndexOf('\"');
1100 if ((start > end) ||
1101 (end > datum.length())||
1102 ((start == end) && (datum.length() > 0))) {
1103 //ToDo Error handling here
1104 throw new PcdValueMalFormed (datum);
1105 }
1106
1107 strValue = datum.substring(start + 1, end);
1108 return strValue.length() * 2;
1109 } else if (ch == '\"'){
1110 start = datum.indexOf('\"');
1111 end = datum.lastIndexOf('\"');
1112 if ((start > end) ||
1113 (end > datum.length())||
1114 ((start == end) && (datum.length() > 0))) {
1115 throw new PcdValueMalFormed (datum);
1116 }
1117 strValue = datum.substring(start + 1, end);
1118 return strValue.length();
1119 } else if (ch =='{') {
1120 String[] strValueArray;
1121
1122 start = datum.indexOf('{');
1123 end = datum.lastIndexOf('}');
1124 strValue = datum.substring(start + 1, end);
1125 strValue = strValue.trim();
1126 if (strValue.length() == 0) {
1127 return 0;
1128 }
1129 strValueArray = strValue.split(",");
1130 for (int index = 0; index < strValueArray.length; index ++) {
1131 Integer value = Integer.decode(strValueArray[index].trim());
1132
1133 if (value > 0xFF) {
1134 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1135 // "it is byte array in fact. But the element of %s exceed the byte range",
1136 throw new PcdValueMalFormed (datum);
1137 }
1138 }
1139 return strValueArray.length;
1140
1141
1142 } else {
1143 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1144 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1145 // "2) ANSIC string: like \"xxx\";\r\n"+
1146 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1147 // "but the datum in seems does not following above format!",
1148 throw new PcdValueMalFormed (datum);
1149
1150 }
1151 }
1152
1153 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1154 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1155
1156 return al;
1157 }
1158
1159 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1160
1161 return dynPcdMap.get(pcdKey);
1162 }
1163
1164 public int getDynamicPcdBuildDataCount() {
1165 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1166 removeElement(getfpdDynPcdBuildDefs());
1167 fpdDynPcdBuildDefs = null;
1168 return 0;
1169 }
1170 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1171 }
1172
1173 public void getDynamicPcdBuildData(String[][] saa) {
1174 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1175 removeElement(getfpdDynPcdBuildDefs());
1176 fpdDynPcdBuildDefs = null;
1177 return ;
1178 }
1179 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1180 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1181 int i = 0;
1182 while(li.hasNext()) {
1183 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1184 saa[i][0] = dynPcd.getCName();
1185 saa[i][1] = dynPcd.getToken().toString();
1186 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1187 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1188 saa[i][4] = dynPcd.getDatumType().toString();
1189
1190 ++i;
1191 }
1192 }
1193
1194 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1195 throws PcdValueMalFormed{
1196 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1197 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1198 dynPcdData.setCName(cName);
1199 dynPcdData.setToken(token);
1200 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1201 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1202
1203 BigInteger bigInt = new BigInteger("0");
1204 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1205 skuInfo.setSkuId(bigInt);
1206 if (defaultVal != null){
1207 skuInfo.setValue(defaultVal);
1208 }
1209 else {
1210 if (dataType.equals("UINT8")){
1211 skuInfo.setValue("0");
1212 }
1213 if (dataType.equals("UINT16")) {
1214 skuInfo.setValue("0");
1215 }
1216 if (dataType.equals("UINT32")) {
1217 skuInfo.setValue("0");
1218 }
1219 if (dataType.equals("UINT64")){
1220 skuInfo.setValue("0");
1221 }
1222 if (dataType.equals("BOOLEAN")){
1223 skuInfo.setValue("false");
1224 }
1225 if (dataType.equals("VOID*")) {
1226 skuInfo.setValue("");
1227 }
1228 }
1229 if (dataType.equals("UINT8")){
1230 dynPcdData.setMaxDatumSize(1);
1231 }
1232 if (dataType.equals("UINT16")) {
1233 dynPcdData.setMaxDatumSize(2);
1234 }
1235 if (dataType.equals("UINT32")) {
1236 dynPcdData.setMaxDatumSize(4);
1237 }
1238 if (dataType.equals("UINT64")){
1239 dynPcdData.setMaxDatumSize(8);
1240 }
1241 if (dataType.equals("BOOLEAN")){
1242 dynPcdData.setMaxDatumSize(1);
1243 }
1244 if (dataType.equals("VOID*")) {
1245 int maxSize = setMaxSizeForPointer(defaultVal);
1246 dynPcdData.setMaxDatumSize(maxSize);
1247 }
1248 }
1249
1250 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1251 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1252 if (o == null) {
1253 return;
1254 }
1255
1256 XmlCursor cursor = o.newCursor();
1257 if (cursor.toFirstChild()) {
1258 do {
1259 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1260 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1261 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1262
1263 if (getDynamicPcdBuildDataCount() == 1) {
1264 cursor.toParent();
1265 }
1266 cursor.removeXml();
1267 cursor.dispose();
1268 return;
1269 }
1270 }
1271 while (cursor.toNextSibling());
1272 }
1273 cursor.dispose();
1274 }
1275 //
1276 // Get the Sku Info count of ith dyn pcd element.
1277 //
1278 public int getDynamicPcdSkuInfoCount(int i){
1279 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1280 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1281 return 0;
1282 }
1283
1284 int skuInfoCount = 0;
1285 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1286 if (cursor.toFirstChild()) {
1287 for (int j = 0; j < i; ++j) {
1288 cursor.toNextSibling();
1289 }
1290 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1291 if (pcdData.getSkuInfoList() == null) {
1292 skuInfoCount = 0;
1293 }
1294 else {
1295 skuInfoCount = pcdData.getSkuInfoList().size();
1296 }
1297 }
1298 cursor.dispose();
1299 return skuInfoCount;
1300 }
1301
1302 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1303 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1304 removeElement(getfpdDynPcdBuildDefs());
1305 fpdDynPcdBuildDefs = null;
1306 return;
1307 }
1308
1309 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1310 if (cursor.toFirstChild()) {
1311 for (int j = 0; j < i; ++j) {
1312 cursor.toNextSibling();
1313 }
1314 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1315 if (pcdData.getSkuInfoList() == null) {
1316 cursor.dispose();
1317 return;
1318 }
1319 else {
1320 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1321 int k = 0;
1322 while (li.hasNext()) {
1323 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1324 saa[k][0] = skuInfo.getSkuId()+"";
1325 saa[k][1] = skuInfo.getVariableName();
1326 saa[k][2] = skuInfo.getVariableGuid();
1327 saa[k][3] = skuInfo.getVariableOffset();
1328 saa[k][4] = skuInfo.getHiiDefaultValue();
1329 saa[k][5] = skuInfo.getVpdOffset();
1330 saa[k][6] = skuInfo.getValue();
1331 ++k;
1332 }
1333
1334 }
1335 }
1336 cursor.dispose();
1337
1338 }
1339
1340 public String getDynamicPcdBuildDataValue(int i){
1341 String value = null;
1342 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1343 removeElement(getfpdDynPcdBuildDefs());
1344 fpdDynPcdBuildDefs = null;
1345 return value;
1346 }
1347
1348 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1349 if (cursor.toFirstChild()) {
1350 for (int j = 0; j < i; ++j) {
1351 cursor.toNextSibling();
1352 }
1353 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1354 if (pcdData.getSkuInfoList() == null) {
1355 value = null;
1356 }
1357 else {
1358 value = pcdData.getSkuInfoArray(0).getValue();
1359 }
1360 }
1361 cursor.dispose();
1362 return value;
1363 }
1364
1365 public String getDynamicPcdBuildDataVpdOffset(int i){
1366 String vpdOffset = null;
1367 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1368 removeElement(getfpdDynPcdBuildDefs());
1369 fpdDynPcdBuildDefs = null;
1370 return vpdOffset;
1371 }
1372
1373 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1374 if (cursor.toFirstChild()) {
1375 for (int j = 0; j < i; ++j) {
1376 cursor.toNextSibling();
1377 }
1378 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1379 if (pcdData.getSkuInfoList() == null) {
1380 vpdOffset = null;
1381 }
1382 else {
1383 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1384 }
1385 }
1386 cursor.dispose();
1387 return vpdOffset;
1388 }
1389
1390 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1391 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1392 removeElement(getfpdDynPcdBuildDefs());
1393 fpdDynPcdBuildDefs = null;
1394 return;
1395 }
1396
1397 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1398 if (cursor.toFirstChild()) {
1399 for (int j = 0; j < i; ++j) {
1400 cursor.toNextSibling();
1401 }
1402 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1403 if (pcdData.getSkuInfoList() == null) {
1404 cursor.dispose();
1405 return;
1406 }
1407 else {
1408 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1409 cursor.toChild(qSkuInfo);
1410 cursor.removeXml();
1411 }
1412 }
1413 cursor.dispose();
1414 }
1415 //
1416 // generate sku info for ith dyn pcd build data.
1417 //
1418 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1419 String hiiDefault, String vpdOffset, String value, int i) {
1420 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1421 // return;
1422 // }
1423
1424 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1425 if (cursor.toFirstChild()) {
1426 for (int j = 0; j < i; ++j) {
1427 cursor.toNextSibling();
1428 }
1429 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1430 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1431 skuInfo.setSkuId(new BigInteger(id));
1432 if (varName != null){
1433 skuInfo.setVariableName(varName);
1434 skuInfo.setVariableGuid(varGuid);
1435 skuInfo.setVariableOffset(varOffset);
1436 skuInfo.setHiiDefaultValue(hiiDefault);
1437 }
1438 else if (vpdOffset != null){
1439 skuInfo.setVpdOffset(vpdOffset);
1440 }
1441 else{
1442 skuInfo.setValue(value);
1443 }
1444 }
1445 }
1446
1447 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1448 String hiiDefault, String vpdOffset, String value, int i){
1449 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1450 // return;
1451 // }
1452
1453 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1454 if (cursor.toFirstChild()) {
1455 for (int j = 0; j < i; ++j) {
1456 cursor.toNextSibling();
1457 }
1458 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1459 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1460 while (li.hasNext()) {
1461 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1462 if (skuInfo.getSkuId().toString().equals(id)){
1463 if (varName != null){
1464 skuInfo.setVariableName(varName);
1465 skuInfo.setVariableGuid(varGuid);
1466 skuInfo.setVariableOffset(varOffset);
1467 skuInfo.setHiiDefaultValue(hiiDefault);
1468 }
1469 else if (vpdOffset != null){
1470 skuInfo.setVpdOffset(vpdOffset);
1471 }
1472 else{
1473 skuInfo.setValue(value);
1474 }
1475 break;
1476 }
1477 }
1478 }
1479 }
1480
1481 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1482 if (fpdBuildOpts == null) {
1483 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1484 }
1485 return fpdBuildOpts;
1486 }
1487
1488 public void genBuildOptionsUserExtensions(String fvName, String infName, String outputFileName, String[][] includeModules) {
1489 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1490 userExts.setUserID("IMAGES");
1491 userExts.setIdentifier(new BigInteger("1"));
1492 XmlCursor cursor = userExts.newCursor();
1493 cursor.toEndToken();
1494
1495 cursor.beginElement("FvName");
1496 cursor.insertChars(fvName);
1497 cursor.toNextToken();
1498
1499 cursor.beginElement("InfFileName");
1500 cursor.insertChars(infName);
1501 cursor.toNextToken();
1502
1503 cursor.beginElement("IncludeModules");
1504 for (int i = 0; i < includeModules.length; ++i) {
1505 cursor.beginElement("Module");
1506 cursor.insertAttributeWithValue("ModuleGuid", includeModules[i][0]);
1507 cursor.insertAttributeWithValue("BaseName", includeModules[i][1]);
1508 cursor.toEndToken();
1509 cursor.toNextToken();
1510 }
1511 cursor.dispose();
1512 }
1513
1514 public int getUserExtsIncModCount (String fvName) {
1515 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1516 return -1;
1517 }
1518 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1519 while (li.hasNext()) {
1520 UserExtensionsDocument.UserExtensions ues = li.next();
1521 if (!ues.getUserID().equals("IMAGES")) {
1522 continue;
1523 }
1524 XmlCursor cursor = ues.newCursor();
1525 cursor.toFirstChild();
1526 String elementName = cursor.getTextValue();
1527 if (elementName.equals(fvName)) {
1528 cursor.toNextSibling(new QName("", "IncludeModules"));
1529 if (cursor.toFirstChild()) {
1530 int i = 1;
1531 for (i = 1; cursor.toNextSibling(); ++i);
1532 cursor.dispose();
1533 return i;
1534 }
1535 cursor.dispose();
1536 return 0;
1537 }
1538 cursor.dispose();
1539 }
1540 return -1;
1541 }
1542
1543 public void getUserExtsIncMods(String fvName, String[][] saa) {
1544 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1545 return;
1546 }
1547 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1548 while (li.hasNext()) {
1549 UserExtensionsDocument.UserExtensions ues = li.next();
1550 if (!ues.getUserID().equals("IMAGES")) {
1551 continue;
1552 }
1553 XmlCursor cursor = ues.newCursor();
1554 cursor.toFirstChild();
1555 String elementName = cursor.getTextValue();
1556 if (elementName.equals(fvName)) {
1557 cursor.toNextSibling(new QName("", "IncludeModules"));
1558 if (cursor.toFirstChild()) {
1559 int i = 0;
1560 do {
1561 saa[i][0] = cursor.getAttributeText(new QName("ModuleGuid"));
1562 saa[i][1] = cursor.getAttributeText(new QName("BaseName"));
1563 ++i;
1564 }while (cursor.toNextSibling());
1565 }
1566 cursor.dispose();
1567 return;
1568 }
1569 cursor.dispose();
1570 }
1571
1572 }
1573
1574 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1575 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1576 if (udats == null) {
1577 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1578 }
1579
1580 AntTaskDocument.AntTask at = udats.addNewAntTask();
1581 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1582 }
1583
1584 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1585 at.setId(new Integer(id));
1586 XmlCursor cursor = at.newCursor();
1587 if (fileName != null){
1588 at.setFilename(fileName);
1589 }
1590 else if (cursor.toChild(xmlNs, "Filename")) {
1591 cursor.removeXml();
1592 }
1593 if (execOrder != null) {
1594 at.setAntCmdOptions(execOrder);
1595 }
1596 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
1597 cursor.removeXml();
1598 }
1599 cursor.dispose();
1600 }
1601
1602 public void removeBuildOptionsUserDefAntTask(int i) {
1603 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1604 if (o == null) {
1605 return;
1606 }
1607 XmlCursor cursor = o.newCursor();
1608 if (cursor.toFirstChild()) {
1609 for (int j = 0; j < i; ++j) {
1610 cursor.toNextSibling();
1611 }
1612 cursor.removeXml();
1613 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1614 cursor.toParent();
1615 cursor.removeXml();
1616 }
1617 }
1618 cursor.dispose();
1619 }
1620
1621 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1622 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1623 if (o == null) {
1624 return;
1625 }
1626 XmlCursor cursor = o.newCursor();
1627 if (cursor.toFirstChild()) {
1628 for (int j = 0; j < i; ++j) {
1629 cursor.toNextSibling();
1630 }
1631 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1632 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1633 }
1634 cursor.dispose();
1635 }
1636
1637 public int getBuildOptionsUserDefAntTaskCount() {
1638 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1639 if (udats == null || udats.getAntTaskList() == null) {
1640 return 0;
1641 }
1642
1643 return udats.getAntTaskList().size();
1644 }
1645
1646 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1647 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1648 if (udats == null || udats.getAntTaskList() == null) {
1649 return ;
1650 }
1651
1652 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1653 ListIterator li = l.listIterator();
1654 int i = 0;
1655 while (li.hasNext()) {
1656 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1657 saa[i][0] = at.getId() + "";
1658 saa[i][1] = saa[i][2] = "";
1659 if (at.getFilename() != null){
1660 saa[i][1] = at.getFilename();
1661 }
1662 if (at.getAntCmdOptions() != null) {
1663 saa[i][2] = at.getAntCmdOptions();
1664 }
1665 ++i;
1666 }
1667 }
1668 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1669 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1670 if (opts == null) {
1671 opts = getfpdBuildOpts().addNewOptions();
1672 }
1673 OptionDocument.Option opt = opts.addNewOption();
1674 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1675 }
1676
1677 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1678 opt.setStringValue(contents);
1679
1680 opt.setBuildTargets(buildTargets);
1681 opt.setToolChainFamily(toolChain);
1682 opt.setTagName(tagName);
1683 opt.setToolCode(toolCmd);
1684
1685 if (archList != null) {
1686 opt.setSupArchList(archList);
1687 }
1688 else {
1689 if (opt.isSetSupArchList()) {
1690 opt.unsetSupArchList();
1691 }
1692 }
1693 }
1694
1695 public void removeBuildOptionsOpt(int i){
1696
1697 XmlObject o = getfpdBuildOpts().getOptions();
1698 if (o == null) {
1699 return;
1700 }
1701
1702 XmlCursor cursor = o.newCursor();
1703 if (cursor.toFirstChild()) {
1704 for (int j = 0; j < i; ++j) {
1705 cursor.toNextSibling();
1706 }
1707 cursor.removeXml();
1708 if (getBuildOptionsOptCount() == 0) {
1709 cursor.toParent();
1710 cursor.removeXml();
1711 }
1712 }
1713 cursor.dispose();
1714 }
1715
1716 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1717 XmlObject o = getfpdBuildOpts().getOptions();
1718 if (o == null) {
1719 return;
1720 }
1721
1722 XmlCursor cursor = o.newCursor();
1723 if (cursor.toFirstChild()) {
1724 for (int j = 0; j < i; ++j) {
1725 cursor.toNextSibling();
1726 }
1727 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1728 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1729 }
1730 cursor.dispose();
1731 }
1732
1733 public int getBuildOptionsOptCount(){
1734 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1735 return 0;
1736 }
1737 return getfpdBuildOpts().getOptions().getOptionList().size();
1738 }
1739
1740 public void getBuildOptionsOpts(String[][] saa) {
1741 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1742 return ;
1743 }
1744
1745 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1746 ListIterator li = lOpt.listIterator();
1747 int i = 0;
1748 while(li.hasNext()) {
1749 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1750 if (opt.getBuildTargets() != null) {
1751 saa[i][0] = listToString(opt.getBuildTargets());
1752 }
1753 saa[i][1] = opt.getToolChainFamily();
1754 if (opt.getSupArchList() != null){
1755 saa[i][2] = listToString(opt.getSupArchList());
1756
1757 }
1758 saa[i][3] = opt.getToolCode();
1759 saa[i][4] = opt.getTagName();
1760 saa[i][5] = opt.getStringValue();
1761
1762 ++i;
1763 }
1764 }
1765
1766 public void genBuildOptionsFfs(String ffsKey, String type) {
1767 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1768 ffs.setFfsKey(ffsKey);
1769 if (type != null) {
1770 ffs.addNewSections().setEncapsulationType(type);
1771 }
1772 }
1773
1774 public void updateBuildOptionsFfsSectionsType(int i, String type) {
1775 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1776 if (type != null) {
1777 ffs.addNewSections().setEncapsulationType(type);
1778 }
1779 }
1780
1781 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
1782 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1783 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
1784 attrib.setName(name);
1785 attrib.setValue(value);
1786 }
1787
1788 /**update jth attribute of ith ffs.
1789 * @param i
1790 * @param j
1791 */
1792 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
1793 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1794 XmlCursor cursor = ffs.newCursor();
1795 QName qAttrib = new QName(xmlNs, "Attribute");
1796 if (cursor.toChild(qAttrib)) {
1797 for (int k = 0; k < j; ++k) {
1798 cursor.toNextSibling(qAttrib);
1799 }
1800 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
1801 attrib.setName(name);
1802 attrib.setValue(value);
1803 }
1804 cursor.dispose();
1805 }
1806
1807 public void removeBuildOptionsFfsAttribute(int i, int j){
1808 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1809 XmlCursor cursor = ffs.newCursor();
1810 QName qAttrib = new QName(xmlNs, "Attribute");
1811 if (cursor.toChild(qAttrib)) {
1812 for (int k = 0; k < j; ++k) {
1813 cursor.toNextSibling(qAttrib);
1814 }
1815 cursor.removeXml();
1816 }
1817 cursor.dispose();
1818 }
1819
1820 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
1821 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1822 if (ffs == null) {
1823 return;
1824 }
1825 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1826
1827 if (sections == null){
1828 sections = ffs.addNewSections();
1829 }
1830 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
1831 }
1832
1833 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
1834 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1835 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1836 if (sections == null) {
1837 return;
1838 }
1839 XmlCursor cursor = sections.newCursor();
1840 QName qSection = new QName(xmlNs, "Section");
1841 if (cursor.toChild(qSection)) {
1842 for (int k = 0; k < j; ++k) {
1843 cursor.toNextSibling(qSection);
1844 }
1845 cursor.removeXml();
1846 }
1847 cursor.dispose();
1848 }
1849
1850 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
1851 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1852 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1853 if (sections == null) {
1854 return;
1855 }
1856 XmlCursor cursor = sections.newCursor();
1857 QName qSection = new QName(xmlNs, "Section");
1858 if (cursor.toChild(qSection)) {
1859 for (int k = 0; k < j; ++k) {
1860 cursor.toNextSibling(qSection);
1861 }
1862 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
1863 section.setSectionType(EfiSectionType.Enum.forString(type));
1864 }
1865 cursor.dispose();
1866 }
1867
1868 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
1869 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1870 if (ffs == null) {
1871 return;
1872 }
1873 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1874
1875 if (sections == null){
1876 sections = ffs.addNewSections();
1877 }
1878 sections.addNewSections().setEncapsulationType(encapType);
1879 }
1880
1881 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
1882 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1883 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1884 if (sections == null) {
1885 return;
1886 }
1887 XmlCursor cursor = sections.newCursor();
1888 QName qSections = new QName(xmlNs, "Sections");
1889 if (cursor.toChild(qSections)) {
1890 for (int k = 0; k < j; ++k) {
1891 cursor.toNextSibling(qSections);
1892 }
1893 cursor.removeXml();
1894 }
1895 cursor.dispose();
1896 }
1897
1898 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
1899 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1900 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1901 if (sections == null) {
1902 return;
1903 }
1904 XmlCursor cursor = sections.newCursor();
1905 QName qSections = new QName(xmlNs, "Sections");
1906 if (cursor.toChild(qSections)) {
1907 for (int k = 0; k < j; ++k) {
1908 cursor.toNextSibling(qSections);
1909 }
1910 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1911 sections2.setEncapsulationType(type);
1912 }
1913 cursor.dispose();
1914 }
1915
1916 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
1917 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1918 if (ffs == null) {
1919 return;
1920 }
1921 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1922 XmlCursor cursor = sections.newCursor();
1923 QName qSections = new QName(xmlNs, "Sections");
1924 if (cursor.toChild(qSections)){
1925 for (int k = 0; k < j; ++k) {
1926 cursor.toNextSibling(qSections);
1927 }
1928 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1929 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
1930 }
1931 cursor.dispose();
1932 }
1933
1934 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
1935 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1936 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1937 if (sections == null) {
1938 return;
1939 }
1940 XmlCursor cursor = sections.newCursor();
1941 QName qSections = new QName(xmlNs, "Sections");
1942 if (cursor.toChild(qSections)) {
1943 for (int l = 0; l < j; ++l) {
1944 cursor.toNextSibling(qSections);
1945 }
1946 if (cursor.toFirstChild()) {
1947 int m = 0;
1948 for (; m < k; ++m) {
1949 cursor.toNextSibling();
1950 }
1951 cursor.removeXml();
1952 if (m == 0) {
1953 cursor.toParent();
1954 cursor.removeXml();
1955 }
1956 }
1957 }
1958 cursor.dispose();
1959 }
1960
1961 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
1962 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1963 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1964 if (sections == null) {
1965 return;
1966 }
1967 XmlCursor cursor = sections.newCursor();
1968 QName qSections = new QName(xmlNs, "Sections");
1969 if (cursor.toChild(qSections)) {
1970 for (int l = 0; l < j; ++l) {
1971 cursor.toNextSibling(qSections);
1972 }
1973 if (cursor.toFirstChild()) {
1974 for (int m = 0; m < k; ++m) {
1975 cursor.toNextSibling();
1976 }
1977 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
1978 section.setSectionType(EfiSectionType.Enum.forString(type));
1979 }
1980 }
1981 cursor.dispose();
1982 }
1983
1984 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
1985 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1986 if (ffs == null) {
1987 return;
1988 }
1989 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1990 XmlCursor cursor = sections.newCursor();
1991 QName qSections = new QName(xmlNs, "Sections");
1992 if (cursor.toChild(qSections)){
1993 for (int k = 0; k < j; ++k) {
1994 cursor.toNextSibling(qSections);
1995 }
1996 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1997 if (sections2.getSectionList() == null){
1998 cursor.dispose();
1999 return;
2000 }
2001 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2002 while(li.hasNext()) {
2003 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2004 if (section.isSetSectionType()) {
2005 al.add(section.getSectionType().toString());
2006 }
2007
2008 }
2009 }
2010 cursor.dispose();
2011
2012 }
2013
2014 public int getBuildOptionsFfsCount(){
2015 if (getfpdBuildOpts().getFfsList() == null) {
2016 return 0;
2017 }
2018 return getfpdBuildOpts().getFfsList().size();
2019 }
2020
2021 public void getBuildOptionsFfsKey(String[][] saa) {
2022 if (getfpdBuildOpts().getFfsList() == null) {
2023 return;
2024 }
2025 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2026 int i = 0;
2027 while(li.hasNext()){
2028 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2029 saa[i][0] = ffs.getFfsKey();
2030 ++i;
2031 }
2032 }
2033
2034 public void updateBuildOptionsFfsKey(int i, String key) {
2035 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2036 ffs.setFfsKey(key);
2037 }
2038
2039 /**Get ith FFS key and contents.
2040 * @param saa
2041 */
2042 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2043 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2044
2045 if (ffs != null) {
2046
2047 sa[0] = ffs.getFfsKey();
2048 if (ffs.getSections() != null) {
2049 if(ffs.getSections().getEncapsulationType() != null){
2050 sa[1] = ffs.getSections().getEncapsulationType();
2051 }
2052 if (ffs.getSections().getSectionList() != null){
2053 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2054 while (li.hasNext()) {
2055 firstLevelSection.add(li.next().getSectionType().toString());
2056 }
2057 }
2058 if (ffs.getSections().getSectionsList() != null) {
2059 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2060 while(li.hasNext()) {
2061 firstLevelSections.add(li.next().getEncapsulationType());
2062 }
2063 }
2064 }
2065 if (ffs.getAttributeList() != null) {
2066 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2067 while(li.hasNext()) {
2068 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2069 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2070 }
2071
2072 }
2073 }
2074
2075
2076 }
2077
2078 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2079 XmlObject o = getfpdBuildOpts();
2080 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2081
2082 XmlCursor cursor = o.newCursor();
2083 QName qFfs = new QName(xmlNs, "Ffs");
2084 if (cursor.toChild(qFfs)) {
2085 for (int j = 0; j < i; ++j) {
2086 cursor.toNextSibling(qFfs);
2087 }
2088 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2089 }
2090 cursor.dispose();
2091 return ffs;
2092 }
2093
2094 public void removeBuildOptionsFfs(int i) {
2095 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2096 if (ffs == null){
2097 return;
2098 }
2099
2100 XmlCursor cursor = ffs.newCursor();
2101 cursor.removeXml();
2102 cursor.dispose();
2103 }
2104
2105
2106
2107 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2108 if (fpdPlatformDefs == null){
2109 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2110 }
2111 return fpdPlatformDefs;
2112 }
2113
2114 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2115 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2116 return;
2117 }
2118 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2119 while(li.hasNext()) {
2120 archs.add(li.next());
2121 }
2122 }
2123
2124 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2125 if (archs != null) {
2126 getfpdPlatformDefs().setSupportedArchitectures(archs);
2127 }
2128 // else {
2129 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2130 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2131 // cursor.removeXml();
2132 // }
2133 // cursor.dispose();
2134 // }
2135 }
2136
2137 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2138 if (getfpdPlatformDefs().getBuildTargets() == null) {
2139 return;
2140 }
2141 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2142 while(li.hasNext()) {
2143 targets.add(li.next());
2144 }
2145 }
2146
2147 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2148 getfpdPlatformDefs().setBuildTargets(targets);
2149 }
2150
2151 public void genPlatformDefsSkuInfo(String id, String name) {
2152 SkuInfoDocument.SkuInfo skuInfo = null;
2153 if (getfpdPlatformDefs().getSkuInfo() == null) {
2154 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2155 }
2156 skuInfo = getfpdPlatformDefs().getSkuInfo();
2157 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2158 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2159 skuName.setSkuID(new BigInteger("0"));
2160 skuName.setStringValue("DEFAULT");
2161 }
2162 if (id.equals("0")) {
2163 return;
2164 }
2165 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2166 skuName.setSkuID(new BigInteger(id));
2167 skuName.setStringValue(name);
2168 }
2169
2170 public int getPlatformDefsSkuInfoCount(){
2171 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2172 return 0;
2173 }
2174 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2175 }
2176
2177 public void getPlatformDefsSkuInfos(String[][] saa){
2178 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2179 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2180 removeElement(getfpdDynPcdBuildDefs());
2181 fpdDynPcdBuildDefs = null;
2182 }
2183 return ;
2184 }
2185
2186 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2187 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2188 int i = 0;
2189 while(li.hasNext()) {
2190 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2191 saa[i][0] = sku.getSkuID()+"";
2192 saa[i][1] = sku.getStringValue();
2193 ++i;
2194 }
2195 }
2196
2197 public void removePlatformDefsSkuInfo(int i) {
2198 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2199 if (skuInfo == null || i == 0) {
2200 return ;
2201 }
2202
2203 XmlCursor cursor = skuInfo.newCursor();
2204 if (cursor.toFirstChild()) {
2205 for (int j = 0; j < i; ++j) {
2206 cursor.toNextSibling();
2207 }
2208 cursor.removeXml();
2209 }
2210 cursor.dispose();
2211 }
2212
2213 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2214 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2215 if (skuInfo == null || i == 0) {
2216 return ;
2217 }
2218
2219 XmlCursor cursor = skuInfo.newCursor();
2220 if (cursor.toFirstChild()) {
2221 for (int j = 0; j < i; ++j) {
2222 cursor.toNextSibling();
2223 }
2224 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2225 sku.setSkuID(new BigInteger(id));
2226 sku.setStringValue(name);
2227 }
2228 cursor.dispose();
2229 }
2230
2231 public String getPlatformDefsInterDir(){
2232 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2233 return null;
2234 }
2235 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2236 }
2237
2238 public void setPlatformDefsInterDir(String interDir){
2239 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2240 }
2241
2242 public String getPlatformDefsOutputDir() {
2243 return getfpdPlatformDefs().getOutputDirectory();
2244 }
2245
2246 public void setPlatformDefsOutputDir(String outputDir) {
2247 if (outputDir != null && outputDir.length() > 0) {
2248 getfpdPlatformDefs().setOutputDirectory(outputDir);
2249 }
2250 else{
2251 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2252 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2253 cursor.removeXml();
2254 }
2255 cursor.dispose();
2256 }
2257 }
2258
2259 public FlashDocument.Flash getfpdFlash() {
2260 if (fpdFlash == null) {
2261 fpdFlash = fpdRoot.addNewFlash();
2262 }
2263 return fpdFlash;
2264 }
2265
2266 public void genFlashDefinitionFile(String file) {
2267 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2268 if (fdf == null) {
2269 fdf = getfpdFlash().addNewFlashDefinitionFile();
2270 }
2271
2272 fdf.setStringValue(file);
2273 }
2274
2275 public String getFlashDefinitionFile() {
2276 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2277 if (fdf == null) {
2278 return "";
2279 }
2280
2281 return fdf.getStringValue();
2282 }
2283
2284 public void genFvImagesNameValue(String name, String value) {
2285
2286 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2287 if (fi == null) {
2288 fi = getfpdFlash().addNewFvImages();
2289 }
2290
2291 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2292 nv.setName(name);
2293 nv.setValue(value);
2294 }
2295
2296 public void removeFvImagesNameValue(int i){
2297
2298 XmlObject o = getfpdFlash().getFvImages();
2299 if (o == null) {
2300 return;
2301 }
2302
2303 QName qNameValue = new QName(xmlNs, "NameValue");
2304 XmlCursor cursor = o.newCursor();
2305 if (cursor.toChild(qNameValue)) {
2306 for (int j = 0; j < i; ++j) {
2307 cursor.toNextSibling(qNameValue);
2308 }
2309 cursor.removeXml();
2310 }
2311 cursor.dispose();
2312 }
2313
2314 public void updateFvImagesNameValue(int i, String name, String value){
2315
2316 XmlObject o = getfpdFlash().getFvImages();
2317 if (o == null) {
2318 return;
2319 }
2320
2321 QName qNameValue = new QName(xmlNs, "NameValue");
2322 XmlCursor cursor = o.newCursor();
2323 if (cursor.toChild(qNameValue)) {
2324 for (int j = 0; j < i; ++j) {
2325 cursor.toNextSibling(qNameValue);
2326 }
2327 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2328 nv.setName(name);
2329 nv.setValue(value);
2330 }
2331 cursor.dispose();
2332 }
2333
2334 public int getFvImagesNameValueCount() {
2335
2336 FvImagesDocument.FvImages fi = null;
2337 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2338 return 0;
2339 }
2340 return fi.getNameValueList().size();
2341 }
2342
2343 public void getFvImagesNameValues(String[][] nv) {
2344
2345 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2346 if (fi == null){
2347 return;
2348 }
2349 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2350 int i = 0;
2351 ListIterator li = l.listIterator();
2352 while (li.hasNext()) {
2353 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2354 .next();
2355 nv[i][0] = e.getName();
2356 nv[i][1] = e.getValue();
2357
2358 i++;
2359 }
2360 }
2361
2362 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2363
2364 FvImagesDocument.FvImages fis = null;
2365 if ((fis = getfpdFlash().getFvImages()) == null) {
2366 fis = getfpdFlash().addNewFvImages();
2367 }
2368
2369 //
2370 //gen FvImage with FvImageNames array
2371 //
2372 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2373 for (int i = 0; i < names.length; ++i) {
2374 fi.addFvImageNames(names[i]);
2375 }
2376 fi.setType(FvImageTypes.Enum.forString(types));
2377 if (options != null){
2378 setFvImagesFvImageFvImageOptions(options, fi);
2379 }
2380 }
2381
2382 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2383 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
2384 if (fio == null){
2385 fio = fi.addNewFvImageOptions();
2386 }
2387
2388 Set<String> key = options.keySet();
2389 Iterator<String> i = key.iterator();
2390 while (i.hasNext()) {
2391
2392 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
2393 String k = (String)i.next();
2394
2395 nv.setName(k);
2396 nv.setValue((String)options.get(k));
2397
2398 }
2399
2400 }
2401
2402
2403 public void removeFvImagesFvImage(int i) {
2404
2405 XmlObject o = getfpdFlash().getFvImages();
2406 if (o == null) {
2407 return;
2408 }
2409
2410 QName qFvImage = new QName(xmlNs, "FvImage");
2411 XmlCursor cursor = o.newCursor();
2412 if (cursor.toChild(qFvImage)) {
2413 for (int j = 0; j < i; ++j) {
2414 cursor.toNextSibling(qFvImage);
2415 }
2416 cursor.removeXml();
2417 }
2418 cursor.dispose();
2419 }
2420
2421 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
2422
2423 XmlObject o = getfpdFlash().getFvImages();
2424 if (o == null) {
2425 return;
2426 }
2427 XmlCursor cursor = o.newCursor();
2428 QName qFvImage = new QName(xmlNs, "FvImage");
2429 if (cursor.toChild(qFvImage)) {
2430 for (int j = 0; j < i; ++j) {
2431 cursor.toNextSibling(qFvImage);
2432 }
2433 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2434 fi.setType(FvImageTypes.Enum.forString(types));
2435
2436 //
2437 // remove old FvImageNames before adding new ones
2438 //
2439 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
2440 cursor.toChild(qFvImageNames);
2441 cursor.removeXml();
2442 while (cursor.toNextSibling(qFvImageNames)) {
2443 cursor.removeXml();
2444 }
2445
2446 for (int k = 0; k < names.length; ++k) {
2447 fi.addFvImageNames(names[k]);
2448 }
2449 //
2450 // remove old FvImageOptions before adding new options
2451 //
2452 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
2453 cursor.toNextSibling(qFvImageOptions);
2454 cursor.removeXml();
2455
2456 setFvImagesFvImageFvImageOptions(options, fi);
2457 }
2458 cursor.dispose();
2459 }
2460
2461 public int getFvImagesFvImageCount() {
2462
2463 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2464 return 0;
2465 }
2466 return getfpdFlash().getFvImages().getFvImageList().size();
2467 }
2468
2469 /**Only Get Fv image setting - name and type.
2470 * @param saa
2471 */
2472 public void getFvImagesFvImages(String[][] saa) {
2473
2474 if (getfpdFlash().getFvImages() == null) {
2475 return;
2476 }
2477 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2478 if (l == null) {
2479 return;
2480 }
2481 ListIterator li = l.listIterator();
2482 int i = 0;
2483 while(li.hasNext()) {
2484 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2485 //
2486 // get FvImageNames array, space separated
2487 //
2488 List<String> lfn = fi.getFvImageNamesList();
2489 ListIterator lfni = lfn.listIterator();
2490 saa[i][0] = " ";
2491 while (lfni.hasNext()) {
2492 saa[i][0] += (String)lfni.next();
2493 saa[i][0] += " ";
2494 }
2495 saa[i][0] = saa[i][0].trim();
2496
2497 saa[i][1] = fi.getType()+"";
2498
2499 ++i;
2500 }
2501 }
2502
2503 /**Get FvImage Options for FvImage i
2504 * @param i the ith FvImage
2505 */
2506 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
2507 XmlObject o = getfpdFlash().getFvImages();
2508 if (o == null) {
2509 return;
2510 }
2511 XmlCursor cursor = o.newCursor();
2512 QName qFvImage = new QName(xmlNs, "FvImage");
2513 if (cursor.toChild(qFvImage)) {
2514 for (int j = 0; j < i; ++j) {
2515 cursor.toNextSibling(qFvImage);
2516 }
2517 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2518 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
2519 return;
2520 }
2521 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
2522 while(li.hasNext()){
2523 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
2524 m.put(nv.getName(), nv.getValue());
2525 }
2526 }
2527 }
2528
2529 /**
2530 Get platform header element
2531 @return PlatformHeaderDocument.PlatformHeader
2532 **/
2533 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
2534 if (fpdHdr == null) {
2535 fpdHdr = fpdRoot.addNewPlatformHeader();
2536 }
2537
2538 return fpdHdr;
2539 }
2540
2541 public String getFpdHdrPlatformName() {
2542 return getFpdHdr().getPlatformName();
2543 }
2544
2545 public String getFpdHdrGuidValue() {
2546 return getFpdHdr().getGuidValue();
2547 }
2548
2549 public String getFpdHdrVer() {
2550 return getFpdHdr().getVersion();
2551 }
2552
2553 public String getFpdHdrAbs() {
2554 return getFpdHdr().getAbstract();
2555 }
2556
2557 public String getFpdHdrDescription() {
2558 return getFpdHdr().getDescription();
2559 }
2560
2561 public String getFpdHdrCopyright() {
2562 return getFpdHdr().getCopyright();
2563 }
2564
2565 public String getFpdHdrLicense() {
2566 LicenseDocument.License l = getFpdHdr().getLicense();
2567 if (l == null) {
2568 return null;
2569 }
2570 return l.getStringValue();
2571 }
2572
2573 public String getFpdHdrUrl() {
2574 LicenseDocument.License l = getFpdHdr().getLicense();
2575 if (l == null) {
2576 return null;
2577 }
2578 return l.getURL();
2579 }
2580
2581 public String getFpdHdrSpec() {
2582
2583 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2584 // return getFpdHdr().getSpecification();
2585 }
2586
2587 public void setFpdHdrPlatformName(String name){
2588 getFpdHdr().setPlatformName(name);
2589 }
2590
2591 public void setFpdHdrGuidValue(String guid){
2592 getFpdHdr().setGuidValue(guid);
2593 }
2594
2595 public void setFpdHdrVer(String v){
2596 getFpdHdr().setVersion(v);
2597 }
2598
2599 public void setFpdHdrAbs(String abs) {
2600 getFpdHdr().setAbstract(abs);
2601 }
2602
2603 public void setFpdHdrDescription(String desc){
2604 getFpdHdr().setDescription(desc);
2605 }
2606
2607 public void setFpdHdrCopyright(String cr) {
2608 getFpdHdr().setCopyright(cr);
2609 }
2610
2611 public void setFpdHdrLicense(String license){
2612 LicenseDocument.License l = getFpdHdr().getLicense();
2613 if (l == null) {
2614 getFpdHdr().addNewLicense().setStringValue(license);
2615 }
2616 else {
2617 l.setStringValue(license);
2618 }
2619 }
2620
2621 public void setFpdHdrUrl(String url){
2622 LicenseDocument.License l = getFpdHdr().getLicense();
2623
2624 l.setURL(url);
2625
2626 }
2627
2628 public void setFpdHdrSpec(String s){
2629 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2630 getFpdHdr().setSpecification(s);
2631 }
2632 /**
2633 Save the processed xml contents to file
2634
2635 @param fpdFile The file to save xml contents
2636 @throws IOException Exceptions during file operation
2637 **/
2638 public void saveAs(File fpdFile) throws IOException {
2639
2640 XmlOptions options = new XmlOptions();
2641
2642 options.setCharacterEncoding("UTF-8");
2643 options.setSavePrettyPrint();
2644 options.setSavePrettyPrintIndent(2);
2645 try {
2646 fpdd.save(fpdFile, options);
2647 } catch (IOException e) {
2648 e.printStackTrace();
2649 }
2650
2651 }
2652
2653 private String listToString(List l) {
2654 if (l == null) {
2655 return null;
2656 }
2657 String s = " ";
2658 ListIterator li = l.listIterator();
2659 while(li.hasNext()) {
2660 s += li.next();
2661 s += " ";
2662 }
2663 return s.trim();
2664 }
2665
2666 private void removeElement(XmlObject o) {
2667 XmlCursor cursor = o.newCursor();
2668 cursor.removeXml();
2669 cursor.dispose();
2670 }
2671 }
2672
2673 class PcdItemTypeConflictException extends Exception {
2674
2675 /**
2676 *
2677 */
2678 private static final long serialVersionUID = 1L;
2679 private String details = null;
2680
2681 PcdItemTypeConflictException(String pcdName, String info){
2682 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
2683 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackage().getName();
2684 }
2685
2686 public String getMessage() {
2687 return details;
2688 }
2689 }
2690
2691 class PcdDeclNotFound extends Exception {
2692
2693 /**
2694 *
2695 */
2696 private static final long serialVersionUID = 1L;
2697 private String details = null;
2698
2699 PcdDeclNotFound(String info) {
2700 details = "PcdDeclNotFound: " + info;
2701 }
2702
2703 public String getMessage() {
2704 return details;
2705 }
2706 }
2707
2708 class PcdValueMalFormed extends Exception {
2709
2710 /**
2711 *
2712 */
2713 private static final long serialVersionUID = 1L;
2714 private String details = null;
2715
2716 PcdValueMalFormed(String info) {
2717 details = "PcdValueMalFormed: " + info;
2718 }
2719
2720 public String getMessage() {
2721 return details;
2722 }
2723 }