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