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