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