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