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