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