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