]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Fix the problem of not sync. module order list in FVs when user change the FvBinding...
[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.toParent();
1535 }
1536 cursor.removeXml();
1537 cursor.dispose();
1538 return;
1539 }
1540 }
1541 while (cursor.toNextSibling());
1542 }
1543 cursor.dispose();
1544 }
1545 //
1546 // Get the Sku Info count of ith dyn pcd element.
1547 //
1548 public int getDynamicPcdSkuInfoCount(int i){
1549 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1550 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1551 return 0;
1552 }
1553
1554 int skuInfoCount = 0;
1555 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1556 if (cursor.toFirstChild()) {
1557 for (int j = 0; j < i; ++j) {
1558 cursor.toNextSibling();
1559 }
1560 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1561 if (pcdData.getSkuInfoList() == null) {
1562 skuInfoCount = 0;
1563 }
1564 else {
1565 skuInfoCount = pcdData.getSkuInfoList().size();
1566 }
1567 }
1568 cursor.dispose();
1569 return skuInfoCount;
1570 }
1571
1572 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1573 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1574 removeElement(getfpdDynPcdBuildDefs());
1575 fpdDynPcdBuildDefs = null;
1576 return;
1577 }
1578
1579 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1580 if (cursor.toFirstChild()) {
1581 for (int j = 0; j < i; ++j) {
1582 cursor.toNextSibling();
1583 }
1584 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1585 if (pcdData.getSkuInfoList() == null) {
1586 cursor.dispose();
1587 return;
1588 }
1589 else {
1590 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1591 int k = 0;
1592 while (li.hasNext()) {
1593 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1594 saa[k][0] = skuInfo.getSkuId()+"";
1595 saa[k][1] = skuInfo.getVariableName();
1596 saa[k][2] = skuInfo.getVariableGuid();
1597 saa[k][3] = skuInfo.getVariableOffset();
1598 saa[k][4] = skuInfo.getHiiDefaultValue();
1599 saa[k][5] = skuInfo.getVpdOffset();
1600 saa[k][6] = skuInfo.getValue();
1601 ++k;
1602 }
1603
1604 }
1605 }
1606 cursor.dispose();
1607
1608 }
1609
1610 public String getDynamicPcdBuildDataValue(int i){
1611 String value = null;
1612 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1613 removeElement(getfpdDynPcdBuildDefs());
1614 fpdDynPcdBuildDefs = null;
1615 return value;
1616 }
1617
1618 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1619 if (cursor.toFirstChild()) {
1620 for (int j = 0; j < i; ++j) {
1621 cursor.toNextSibling();
1622 }
1623 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1624 if (pcdData.getSkuInfoList() == null) {
1625 value = null;
1626 }
1627 else {
1628 value = pcdData.getSkuInfoArray(0).getValue();
1629 }
1630 }
1631 cursor.dispose();
1632 return value;
1633 }
1634
1635 public String getDynamicPcdBuildDataVpdOffset(int i){
1636 String vpdOffset = null;
1637 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1638 removeElement(getfpdDynPcdBuildDefs());
1639 fpdDynPcdBuildDefs = null;
1640 return vpdOffset;
1641 }
1642
1643 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1644 if (cursor.toFirstChild()) {
1645 for (int j = 0; j < i; ++j) {
1646 cursor.toNextSibling();
1647 }
1648 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1649 if (pcdData.getSkuInfoList() == null) {
1650 vpdOffset = null;
1651 }
1652 else {
1653 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1654 }
1655 }
1656 cursor.dispose();
1657 return vpdOffset;
1658 }
1659
1660 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1661 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1662 removeElement(getfpdDynPcdBuildDefs());
1663 fpdDynPcdBuildDefs = null;
1664 return;
1665 }
1666
1667 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1668 if (cursor.toFirstChild()) {
1669 for (int j = 0; j < i; ++j) {
1670 cursor.toNextSibling();
1671 }
1672 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1673 if (pcdData.getSkuInfoList() == null) {
1674 cursor.dispose();
1675 return;
1676 }
1677 else {
1678 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1679 cursor.toChild(qSkuInfo);
1680 cursor.removeXml();
1681 }
1682 }
1683 cursor.dispose();
1684 }
1685 //
1686 // generate sku info for ith dyn pcd build data.
1687 //
1688 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1689 String hiiDefault, String vpdOffset, String value, int i) {
1690 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1691 // return;
1692 // }
1693
1694 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1695 if (cursor.toFirstChild()) {
1696 for (int j = 0; j < i; ++j) {
1697 cursor.toNextSibling();
1698 }
1699 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1700 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1701 skuInfo.setSkuId(new BigInteger(id));
1702 if (varName != null){
1703 skuInfo.setVariableName(varName);
1704 skuInfo.setVariableGuid(varGuid);
1705 skuInfo.setVariableOffset(varOffset);
1706 skuInfo.setHiiDefaultValue(hiiDefault);
1707 }
1708 else if (vpdOffset != null){
1709 skuInfo.setVpdOffset(vpdOffset);
1710 }
1711 else{
1712 skuInfo.setValue(value);
1713 }
1714 }
1715 }
1716
1717 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1718 String hiiDefault, String vpdOffset, String value, int i){
1719 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1720 // return;
1721 // }
1722
1723 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1724 if (cursor.toFirstChild()) {
1725 for (int j = 0; j < i; ++j) {
1726 cursor.toNextSibling();
1727 }
1728 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1729 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1730 while (li.hasNext()) {
1731 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1732 if (skuInfo.getSkuId().toString().equals(id)){
1733 if (varName != null){
1734 skuInfo.setVariableName(varName);
1735 skuInfo.setVariableGuid(varGuid);
1736 skuInfo.setVariableOffset(varOffset);
1737 skuInfo.setHiiDefaultValue(hiiDefault);
1738 }
1739 else if (vpdOffset != null){
1740 skuInfo.setVpdOffset(vpdOffset);
1741 }
1742 else{
1743 skuInfo.setValue(value);
1744 }
1745 break;
1746 }
1747 }
1748 }
1749 }
1750
1751 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1752 if (fpdBuildOpts == null) {
1753 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1754 }
1755 return fpdBuildOpts;
1756 }
1757
1758 public void genBuildOptionsUserExtensions(String fvName, String outputFileName, Vector<String[]> includeModules) {
1759 QName elementFvName = new QName (xmlNs, "FvName");
1760 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1761 QName elementInfFileName = new QName(xmlNs, "InfFileName");
1762 QName elementModule = new QName(xmlNs, "Module");
1763
1764 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1765 userExts.setUserID("IMAGES");
1766 userExts.setIdentifier(new BigInteger("1"));
1767 XmlCursor cursor = userExts.newCursor();
1768 cursor.toEndToken();
1769
1770 cursor.beginElement(elementFvName);
1771 cursor.insertChars(fvName);
1772 cursor.toNextToken();
1773
1774 cursor.beginElement(elementInfFileName);
1775 cursor.insertChars(fvName + ".inf");
1776 cursor.toNextToken();
1777
1778 cursor.beginElement(elementIncludeModules);
1779 for (int i = 0; i < includeModules.size(); ++i) {
1780 cursor.beginElement(elementModule);
1781 cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]);
1782 if (!includeModules.get(i)[1].equals("null") && includeModules.get(i)[1].length() != 0) {
1783 cursor.insertAttributeWithValue("ModuleVersion", includeModules.get(i)[1]);
1784 }
1785 cursor.insertAttributeWithValue("PackageGuid", includeModules.get(i)[2]);
1786 if (!includeModules.get(i)[3].equals("null") && includeModules.get(i)[3].length() != 0) {
1787 cursor.insertAttributeWithValue("PackageVersion", includeModules.get(i)[3]);
1788 }
1789
1790 cursor.insertAttributeWithValue("Arch", includeModules.get(i)[4]);
1791 cursor.toEndToken();
1792 cursor.toNextToken();
1793 }
1794 cursor.dispose();
1795 }
1796
1797 public int getUserExtsIncModCount (String fvName) {
1798 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1799 return -1;
1800 }
1801 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1802 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1803 while (li.hasNext()) {
1804 UserExtensionsDocument.UserExtensions ues = li.next();
1805 if (!ues.getUserID().equals("IMAGES")) {
1806 continue;
1807 }
1808 XmlCursor cursor = ues.newCursor();
1809 cursor.toFirstChild();
1810 String elementName = cursor.getTextValue();
1811 if (elementName.equals(fvName)) {
1812 cursor.toNextSibling(elementIncludeModules);
1813 if (cursor.toFirstChild()) {
1814 int i = 1;
1815 for (i = 1; cursor.toNextSibling(); ++i);
1816 cursor.dispose();
1817 return i;
1818 }
1819 cursor.dispose();
1820 return 0;
1821 }
1822 cursor.dispose();
1823 }
1824 return -1;
1825 }
1826
1827 public void getUserExtsIncMods(String fvName, String[][] saa) {
1828 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1829 return;
1830 }
1831
1832 XmlCursor cursor = getfpdBuildOpts().newCursor();
1833 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1834 QName attribUserId = new QName ("UserID");
1835 QName elementFvName = new QName (xmlNs, "FvName");
1836 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1837 QName attribModuleGuid = new QName("ModuleGuid");
1838 QName attribModuleVersion = new QName("ModuleVersion");
1839 QName attribPackageGuid = new QName("PackageGuid");
1840 QName attribPackageVersion = new QName("PackageVersion");
1841 QName attribArch = new QName("Arch");
1842
1843 if (cursor.toChild(elementUserExts)) {
1844 do {
1845 cursor.push();
1846 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1847 cursor.toChild(elementFvName);
1848 String elementName = cursor.getTextValue();
1849 if (elementName.equals(fvName)) {
1850 cursor.toNextSibling(elementIncludeModules);
1851 if (cursor.toFirstChild()) {
1852 int i = 0;
1853 do {
1854 saa[i][0] = cursor.getAttributeText(attribModuleGuid);
1855 saa[i][1] = cursor.getAttributeText(attribModuleVersion);
1856 saa[i][2] = cursor.getAttributeText(attribPackageGuid);
1857 saa[i][3] = cursor.getAttributeText(attribPackageVersion);
1858 saa[i][4] = cursor.getAttributeText(attribArch);
1859 ++i;
1860 }while (cursor.toNextSibling());
1861 }
1862 break;
1863 }
1864 }
1865 cursor.pop();
1866 }while (cursor.toNextSibling(elementUserExts));
1867 }
1868 cursor.dispose();
1869
1870 }
1871
1872 public void updateBuildOptionsUserExtensions (String oldFvName, String newFvName) {
1873 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1874 return;
1875 }
1876 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1877 while (li.hasNext()) {
1878 UserExtensionsDocument.UserExtensions ues = li.next();
1879 if (!ues.getUserID().equals("IMAGES")) {
1880 continue;
1881 }
1882 XmlCursor cursor = ues.newCursor();
1883 cursor.toFirstChild();
1884 String elementName = cursor.getTextValue();
1885 if (elementName.equals(oldFvName)) {
1886 cursor.setTextValue(newFvName);
1887 }
1888 cursor.dispose();
1889 }
1890
1891 }
1892
1893 public void removeBuildOptionsUserExtensions (String fvName) {
1894 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1895 return;
1896 }
1897
1898 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1899 while (li.hasNext()) {
1900 UserExtensionsDocument.UserExtensions ues = li.next();
1901 if (!ues.getUserID().equals("IMAGES")) {
1902 continue;
1903 }
1904 XmlCursor cursor = ues.newCursor();
1905 cursor.toFirstChild();
1906 String elementName = cursor.getTextValue();
1907 if (elementName.equals(fvName)) {
1908 cursor.toParent();
1909 cursor.removeXml();
1910 cursor.dispose();
1911 return;
1912 }
1913 cursor.dispose();
1914 }
1915
1916 }
1917
1918 private boolean versionEqual (String v1, String v2) {
1919
1920 if ((v1 == null || v1.length() == 0 || v1.equalsIgnoreCase("null"))
1921 && (v2 == null || v2.length() == 0 || v2.equalsIgnoreCase("null"))) {
1922 return true;
1923 }
1924
1925 if (v1 != null && v1.equals(v2)) {
1926 return true;
1927 }
1928
1929 return false;
1930 }
1931
1932 public boolean moduleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
1933 boolean inList = false;
1934 if (getUserExtsIncModCount(fvName) > 0) {
1935
1936 XmlCursor cursor = getfpdBuildOpts().newCursor();
1937 QName elementUserExts = new QName (xmlNs, "UserExtensions");
1938 QName attribUserId = new QName ("UserID");
1939 QName elementFvName = new QName (xmlNs, "FvName");
1940 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
1941 QName attribModuleGuid = new QName("ModuleGuid");
1942 QName attribModuleVersion = new QName("ModuleVersion");
1943 QName attribPackageGuid = new QName("PackageGuid");
1944 QName attribPackageVersion = new QName("PackageVersion");
1945 QName attribArch = new QName("Arch");
1946
1947 if (cursor.toChild(elementUserExts)) {
1948 do {
1949 cursor.push();
1950 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
1951 cursor.toChild(elementFvName);
1952 String elementName = cursor.getTextValue();
1953 if (elementName.equals(fvName)) {
1954 cursor.toNextSibling(elementIncludeModules);
1955 if (cursor.toFirstChild()) {
1956
1957 do {
1958 String mg = cursor.getAttributeText(attribModuleGuid);
1959 String mv = cursor.getAttributeText(attribModuleVersion);
1960 String pg = cursor.getAttributeText(attribPackageGuid);
1961 String pv = cursor.getAttributeText(attribPackageVersion);
1962 String ar = cursor.getAttributeText(attribArch);
1963 if (!moduleGuid.equalsIgnoreCase(mg)) {
1964 continue;
1965 }
1966 if (!packageGuid.equalsIgnoreCase(pg)) {
1967 continue;
1968 }
1969 if (!arch.equalsIgnoreCase(ar)) {
1970 continue;
1971 }
1972 if (!versionEqual(moduleVersion, mv)) {
1973 continue;
1974 }
1975 if (!versionEqual(packageVersion, pv)) {
1976 continue;
1977 }
1978 inList = true;
1979 break;
1980 }while (cursor.toNextSibling());
1981 }
1982 break;
1983 }
1984 }
1985 cursor.pop();
1986 }while (cursor.toNextSibling(elementUserExts));
1987 }
1988 cursor.dispose();
1989 }
1990 return inList;
1991 }
1992
1993 public void removeModuleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
1994 //
1995 // if there is only one module before remove operation, the whole user extension should be removed.
1996 //
1997 int moduleAmount = getUserExtsIncModCount(fvName);
1998 if (moduleAmount == 1) {
1999 removeBuildOptionsUserExtensions(fvName);
2000 return;
2001 }
2002
2003 if (moduleAmount > 1) {
2004
2005 XmlCursor cursor = getfpdBuildOpts().newCursor();
2006 QName elementUserExts = new QName (xmlNs, "UserExtensions");
2007 QName attribUserId = new QName ("UserID");
2008 QName elementFvName = new QName (xmlNs, "FvName");
2009 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
2010 QName attribModuleGuid = new QName("ModuleGuid");
2011 QName attribModuleVersion = new QName("ModuleVersion");
2012 QName attribPackageGuid = new QName("PackageGuid");
2013 QName attribPackageVersion = new QName("PackageVersion");
2014 QName attribArch = new QName("Arch");
2015
2016 if (cursor.toChild(elementUserExts)) {
2017 do {
2018 cursor.push();
2019 if (cursor.getAttributeText(attribUserId).equals("IMAGES")) {
2020 cursor.toChild(elementFvName);
2021 String elementName = cursor.getTextValue();
2022 if (elementName.equals(fvName)) {
2023 cursor.toNextSibling(elementIncludeModules);
2024 if (cursor.toFirstChild()) {
2025
2026 do {
2027 String mg = cursor.getAttributeText(attribModuleGuid);
2028 String mv = cursor.getAttributeText(attribModuleVersion);
2029 String pg = cursor.getAttributeText(attribPackageGuid);
2030 String pv = cursor.getAttributeText(attribPackageVersion);
2031 String ar = cursor.getAttributeText(attribArch);
2032 if (!moduleGuid.equalsIgnoreCase(mg)) {
2033 continue;
2034 }
2035 if (!packageGuid.equalsIgnoreCase(pg)) {
2036 continue;
2037 }
2038 if (!arch.equalsIgnoreCase(ar)) {
2039 continue;
2040 }
2041 if (!versionEqual(moduleVersion, mv)) {
2042 continue;
2043 }
2044 if (!versionEqual(packageVersion, pv)) {
2045 continue;
2046 }
2047 cursor.removeXml();
2048 }while (cursor.toNextSibling());
2049 }
2050 break;
2051 }
2052 }
2053 cursor.pop();
2054 }while (cursor.toNextSibling(elementUserExts));
2055 }
2056 cursor.dispose();
2057 }
2058 }
2059
2060 public void addModuleIntoBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) {
2061 if (moduleInBuildOptionsUserExtensions (fvName, moduleGuid, moduleVersion, packageGuid, packageVersion, arch)) {
2062 return;
2063 }
2064 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
2065 QName elementIncludeModules = new QName(xmlNs, "IncludeModules");
2066 QName elementModule = new QName(xmlNs, "Module");
2067 while (li.hasNext()) {
2068 UserExtensionsDocument.UserExtensions ues = li.next();
2069 if (!ues.getUserID().equals("IMAGES")) {
2070 continue;
2071 }
2072 XmlCursor cursor = ues.newCursor();
2073 cursor.toFirstChild();
2074 String elementName = cursor.getTextValue();
2075 if (elementName.equals(fvName)) {
2076 cursor.toNextSibling(elementIncludeModules);
2077 cursor.toLastChild();
2078 cursor.toEndToken();
2079 cursor.toNextToken();
2080 cursor.beginElement(elementModule);
2081 cursor.insertAttributeWithValue("ModuleGuid", moduleGuid);
2082 if (!moduleVersion.equals("null") && moduleVersion.length() != 0) {
2083 cursor.insertAttributeWithValue("ModuleVersion", moduleVersion);
2084 }
2085 cursor.insertAttributeWithValue("PackageGuid", packageGuid);
2086 if (!packageVersion.equals("null") && packageVersion.length() != 0) {
2087 cursor.insertAttributeWithValue("PackageVersion", packageVersion);
2088 }
2089
2090 cursor.insertAttributeWithValue("Arch", arch);
2091 cursor.dispose();
2092 return;
2093 }
2094 cursor.dispose();
2095 }
2096
2097 }
2098
2099 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
2100 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2101 if (udats == null) {
2102 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
2103 }
2104
2105 AntTaskDocument.AntTask at = udats.addNewAntTask();
2106 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2107 }
2108
2109 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
2110 at.setId(new Integer(id));
2111 XmlCursor cursor = at.newCursor();
2112 if (fileName != null){
2113 at.setFilename(fileName);
2114 }
2115 else if (cursor.toChild(xmlNs, "Filename")) {
2116 cursor.removeXml();
2117 }
2118 if (execOrder != null) {
2119 at.setAntCmdOptions(execOrder);
2120 }
2121 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
2122 cursor.removeXml();
2123 }
2124 cursor.dispose();
2125 }
2126
2127 public void removeBuildOptionsUserDefAntTask(int i) {
2128 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2129 if (o == null) {
2130 return;
2131 }
2132 XmlCursor cursor = o.newCursor();
2133 if (cursor.toFirstChild()) {
2134 for (int j = 0; j < i; ++j) {
2135 cursor.toNextSibling();
2136 }
2137 cursor.removeXml();
2138 if (getBuildOptionsUserDefAntTaskCount() == 0) {
2139 cursor.toParent();
2140 cursor.removeXml();
2141 }
2142 }
2143 cursor.dispose();
2144 }
2145
2146 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
2147 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
2148 if (o == null) {
2149 return;
2150 }
2151 XmlCursor cursor = o.newCursor();
2152 if (cursor.toFirstChild()) {
2153 for (int j = 0; j < i; ++j) {
2154 cursor.toNextSibling();
2155 }
2156 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
2157 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
2158 }
2159 cursor.dispose();
2160 }
2161
2162 public int getBuildOptionsUserDefAntTaskCount() {
2163 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2164 if (udats == null || udats.getAntTaskList() == null) {
2165 return 0;
2166 }
2167
2168 return udats.getAntTaskList().size();
2169 }
2170
2171 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
2172 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
2173 if (udats == null || udats.getAntTaskList() == null) {
2174 return ;
2175 }
2176
2177 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
2178 ListIterator li = l.listIterator();
2179 int i = 0;
2180 while (li.hasNext()) {
2181 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
2182 saa[i][0] = at.getId() + "";
2183 saa[i][1] = saa[i][2] = "";
2184 if (at.getFilename() != null){
2185 saa[i][1] = at.getFilename();
2186 }
2187 if (at.getAntCmdOptions() != null) {
2188 saa[i][2] = at.getAntCmdOptions();
2189 }
2190 ++i;
2191 }
2192 }
2193 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2194 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
2195 if (opts == null) {
2196 opts = getfpdBuildOpts().addNewOptions();
2197 }
2198 OptionDocument.Option opt = opts.addNewOption();
2199 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2200 }
2201
2202 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
2203 opt.setStringValue(contents);
2204 if (buildTargets != null) {
2205 opt.setBuildTargets(buildTargets);
2206 }
2207 else {
2208 if (opt.isSetBuildTargets()) {
2209 opt.unsetBuildTargets();
2210 }
2211 }
2212
2213 if (toolChain != null && toolChain.length() > 0) {
2214 opt.setToolChainFamily(toolChain);
2215 }
2216 else {
2217 if (opt.isSetToolChainFamily()) {
2218 opt.unsetToolChainFamily();
2219 }
2220 }
2221
2222 if (tagName != null && tagName.length() > 0) {
2223 opt.setTagName(tagName);
2224 }
2225 else {
2226 if (opt.isSetTagName()) {
2227 opt.unsetTagName();
2228 }
2229 }
2230
2231 if (toolCmd != null && toolCmd.length() > 0) {
2232 opt.setToolCode(toolCmd);
2233 }
2234 else {
2235 if (opt.isSetToolCode()) {
2236 opt.unsetToolCode();
2237 }
2238 }
2239
2240
2241 if (archList != null) {
2242 opt.setSupArchList(archList);
2243 }
2244 else {
2245 if (opt.isSetSupArchList()) {
2246 opt.unsetSupArchList();
2247 }
2248 }
2249 }
2250
2251 public void removeBuildOptionsOpt(int i){
2252
2253 XmlObject o = getfpdBuildOpts().getOptions();
2254 if (o == null) {
2255 return;
2256 }
2257
2258 XmlCursor cursor = o.newCursor();
2259 if (cursor.toFirstChild()) {
2260 for (int j = 0; j < i; ++j) {
2261 cursor.toNextSibling();
2262 }
2263 cursor.removeXml();
2264 if (getBuildOptionsOptCount() == 0) {
2265 cursor.toParent();
2266 cursor.removeXml();
2267 }
2268 }
2269 cursor.dispose();
2270 }
2271
2272 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
2273 XmlObject o = getfpdBuildOpts().getOptions();
2274 if (o == null) {
2275 return;
2276 }
2277
2278 XmlCursor cursor = o.newCursor();
2279 if (cursor.toFirstChild()) {
2280 for (int j = 0; j < i; ++j) {
2281 cursor.toNextSibling();
2282 }
2283 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
2284 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
2285 }
2286 cursor.dispose();
2287 }
2288
2289 public int getBuildOptionsOptCount(){
2290 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2291 return 0;
2292 }
2293 return getfpdBuildOpts().getOptions().getOptionList().size();
2294 }
2295
2296 public void getBuildOptionsOpts(String[][] saa) {
2297 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
2298 return ;
2299 }
2300
2301 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
2302 ListIterator li = lOpt.listIterator();
2303 int i = 0;
2304 while(li.hasNext()) {
2305 OptionDocument.Option opt = (OptionDocument.Option)li.next();
2306 if (opt.getBuildTargets() != null) {
2307 saa[i][0] = listToString(opt.getBuildTargets());
2308 }
2309 saa[i][1] = opt.getToolChainFamily();
2310 if (opt.getSupArchList() != null){
2311 saa[i][2] = listToString(opt.getSupArchList());
2312
2313 }
2314 saa[i][3] = opt.getToolCode();
2315 saa[i][4] = opt.getTagName();
2316 saa[i][5] = opt.getStringValue();
2317
2318 ++i;
2319 }
2320 }
2321
2322 public void genBuildOptionsFfs(String ffsKey, String type) {
2323 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2324 ffs.setFfsKey(ffsKey);
2325 if (type != null) {
2326 ffs.addNewSections().setEncapsulationType(type);
2327 }
2328 }
2329
2330 public void updateBuildOptionsFfsSectionsType(int i, String type) {
2331 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
2332 if (type != null) {
2333 ffs.addNewSections().setEncapsulationType(type);
2334 }
2335 }
2336
2337 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2338 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2339 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2340 attrib.setName(name);
2341 attrib.setValue(value);
2342 }
2343
2344 /**update jth attribute of ith ffs.
2345 * @param i
2346 * @param j
2347 */
2348 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2349 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2350 XmlCursor cursor = ffs.newCursor();
2351 QName qAttrib = new QName(xmlNs, "Attribute");
2352 if (cursor.toChild(qAttrib)) {
2353 for (int k = 0; k < j; ++k) {
2354 cursor.toNextSibling(qAttrib);
2355 }
2356 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2357 attrib.setName(name);
2358 attrib.setValue(value);
2359 }
2360 cursor.dispose();
2361 }
2362
2363 public void removeBuildOptionsFfsAttribute(int i, int j){
2364 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2365 XmlCursor cursor = ffs.newCursor();
2366 QName qAttrib = new QName(xmlNs, "Attribute");
2367 if (cursor.toChild(qAttrib)) {
2368 for (int k = 0; k < j; ++k) {
2369 cursor.toNextSibling(qAttrib);
2370 }
2371 cursor.removeXml();
2372 }
2373 cursor.dispose();
2374 }
2375
2376 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2377 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2378 if (ffs == null) {
2379 return;
2380 }
2381 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2382
2383 if (sections == null){
2384 sections = ffs.addNewSections();
2385 }
2386 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2387 }
2388
2389 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2390 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2391 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2392 if (sections == null) {
2393 return;
2394 }
2395 XmlCursor cursor = sections.newCursor();
2396 QName qSection = new QName(xmlNs, "Section");
2397 if (cursor.toChild(qSection)) {
2398 for (int k = 0; k < j; ++k) {
2399 cursor.toNextSibling(qSection);
2400 }
2401 cursor.removeXml();
2402 }
2403 cursor.dispose();
2404 }
2405
2406 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2407 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2408 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2409 if (sections == null) {
2410 return;
2411 }
2412 XmlCursor cursor = sections.newCursor();
2413 QName qSection = new QName(xmlNs, "Section");
2414 if (cursor.toChild(qSection)) {
2415 for (int k = 0; k < j; ++k) {
2416 cursor.toNextSibling(qSection);
2417 }
2418 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2419 section.setSectionType(EfiSectionType.Enum.forString(type));
2420 }
2421 cursor.dispose();
2422 }
2423
2424 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2425 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2426 if (ffs == null) {
2427 return;
2428 }
2429 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2430
2431 if (sections == null){
2432 sections = ffs.addNewSections();
2433 }
2434 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections();
2435 sections2.setEncapsulationType(encapType);
2436 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32"));
2437 }
2438
2439 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2440 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2441 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2442 if (sections == null) {
2443 return;
2444 }
2445 XmlCursor cursor = sections.newCursor();
2446 QName qSections = new QName(xmlNs, "Sections");
2447 if (cursor.toChild(qSections)) {
2448 for (int k = 0; k < j; ++k) {
2449 cursor.toNextSibling(qSections);
2450 }
2451 cursor.removeXml();
2452 }
2453 cursor.dispose();
2454 }
2455
2456 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2457 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2458 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2459 if (sections == null) {
2460 return;
2461 }
2462 XmlCursor cursor = sections.newCursor();
2463 QName qSections = new QName(xmlNs, "Sections");
2464 if (cursor.toChild(qSections)) {
2465 for (int k = 0; k < j; ++k) {
2466 cursor.toNextSibling(qSections);
2467 }
2468 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2469 sections2.setEncapsulationType(type);
2470 }
2471 cursor.dispose();
2472 }
2473
2474 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2475 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2476 if (ffs == null) {
2477 return;
2478 }
2479 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2480 XmlCursor cursor = sections.newCursor();
2481 QName qSections = new QName(xmlNs, "Sections");
2482 if (cursor.toChild(qSections)){
2483 for (int k = 0; k < j; ++k) {
2484 cursor.toNextSibling(qSections);
2485 }
2486 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2487 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2488 }
2489 cursor.dispose();
2490 }
2491
2492 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2493 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2494 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2495 if (sections == null) {
2496 return;
2497 }
2498 XmlCursor cursor = sections.newCursor();
2499 QName qSections = new QName(xmlNs, "Sections");
2500 if (cursor.toChild(qSections)) {
2501 for (int l = 0; l < j; ++l) {
2502 cursor.toNextSibling(qSections);
2503 }
2504 if (cursor.toFirstChild()) {
2505 int m = 0;
2506 for (; m < k; ++m) {
2507 cursor.toNextSibling();
2508 }
2509 cursor.removeXml();
2510 if (m == 0) {
2511 cursor.toParent();
2512 cursor.removeXml();
2513 }
2514 }
2515 }
2516 cursor.dispose();
2517 }
2518
2519 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2520 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2521 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2522 if (sections == null) {
2523 return;
2524 }
2525 XmlCursor cursor = sections.newCursor();
2526 QName qSections = new QName(xmlNs, "Sections");
2527 if (cursor.toChild(qSections)) {
2528 for (int l = 0; l < j; ++l) {
2529 cursor.toNextSibling(qSections);
2530 }
2531 if (cursor.toFirstChild()) {
2532 for (int m = 0; m < k; ++m) {
2533 cursor.toNextSibling();
2534 }
2535 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2536 section.setSectionType(EfiSectionType.Enum.forString(type));
2537 }
2538 }
2539 cursor.dispose();
2540 }
2541
2542 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2543 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2544 if (ffs == null) {
2545 return;
2546 }
2547 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2548 XmlCursor cursor = sections.newCursor();
2549 QName qSections = new QName(xmlNs, "Sections");
2550 if (cursor.toChild(qSections)){
2551 for (int k = 0; k < j; ++k) {
2552 cursor.toNextSibling(qSections);
2553 }
2554 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2555 if (sections2.getSectionList() == null){
2556 cursor.dispose();
2557 return;
2558 }
2559 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2560 while(li.hasNext()) {
2561 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2562 // if (section.isSetSectionType()) {
2563 al.add(section.getSectionType()+"");
2564 // }
2565
2566 }
2567 }
2568 cursor.dispose();
2569
2570 }
2571
2572 public int getBuildOptionsFfsCount(){
2573 if (getfpdBuildOpts().getFfsList() == null) {
2574 return 0;
2575 }
2576 return getfpdBuildOpts().getFfsList().size();
2577 }
2578
2579 public void getBuildOptionsFfsKey(String[][] saa) {
2580 if (getfpdBuildOpts().getFfsList() == null) {
2581 return;
2582 }
2583 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2584 int i = 0;
2585 while(li.hasNext()){
2586 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2587 saa[i][0] = ffs.getFfsKey();
2588 ++i;
2589 }
2590 }
2591
2592 public void updateBuildOptionsFfsKey(int i, String key) {
2593 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2594 ffs.setFfsKey(key);
2595 }
2596
2597 /**Get ith FFS key and contents.
2598 * @param saa
2599 */
2600 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2601 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2602
2603 if (ffs != null) {
2604
2605 sa[0] = ffs.getFfsKey();
2606 if (ffs.getSections() != null) {
2607 if(ffs.getSections().getEncapsulationType() != null){
2608 sa[1] = ffs.getSections().getEncapsulationType();
2609 }
2610 if (ffs.getSections().getSectionList() != null){
2611 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2612 while (li.hasNext()) {
2613 firstLevelSection.add(li.next().getSectionType()+"");
2614 }
2615 }
2616 if (ffs.getSections().getSectionsList() != null) {
2617 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2618 while(li.hasNext()) {
2619 firstLevelSections.add(li.next().getEncapsulationType());
2620 }
2621 }
2622 }
2623 if (ffs.getAttributeList() != null) {
2624 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2625 while(li.hasNext()) {
2626 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2627 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2628 }
2629
2630 }
2631 }
2632
2633
2634 }
2635
2636 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2637 XmlObject o = getfpdBuildOpts();
2638 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2639
2640 XmlCursor cursor = o.newCursor();
2641 QName qFfs = new QName(xmlNs, "Ffs");
2642 if (cursor.toChild(qFfs)) {
2643 for (int j = 0; j < i; ++j) {
2644 cursor.toNextSibling(qFfs);
2645 }
2646 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2647 }
2648 cursor.dispose();
2649 return ffs;
2650 }
2651
2652 public void removeBuildOptionsFfs(int i) {
2653 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2654 if (ffs == null){
2655 return;
2656 }
2657
2658 XmlCursor cursor = ffs.newCursor();
2659 cursor.removeXml();
2660 cursor.dispose();
2661 }
2662
2663
2664
2665 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2666 if (fpdPlatformDefs == null){
2667 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2668 }
2669 return fpdPlatformDefs;
2670 }
2671
2672 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2673 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2674 return;
2675 }
2676 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2677 while(li.hasNext()) {
2678 archs.add(li.next());
2679 }
2680 }
2681
2682 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2683 if (archs != null) {
2684 getfpdPlatformDefs().setSupportedArchitectures(archs);
2685 }
2686 // else {
2687 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2688 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2689 // cursor.removeXml();
2690 // }
2691 // cursor.dispose();
2692 // }
2693 }
2694
2695 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2696 if (getfpdPlatformDefs().getBuildTargets() == null) {
2697 return;
2698 }
2699 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2700 while(li.hasNext()) {
2701 targets.add(li.next());
2702 }
2703 }
2704
2705 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2706 getfpdPlatformDefs().setBuildTargets(targets);
2707 }
2708
2709 public void genPlatformDefsSkuInfo(String id, String name) {
2710 SkuInfoDocument.SkuInfo skuInfo = null;
2711 if (getfpdPlatformDefs().getSkuInfo() == null) {
2712 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2713 }
2714 skuInfo = getfpdPlatformDefs().getSkuInfo();
2715 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2716 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2717 skuName.setSkuID(new BigInteger("0"));
2718 skuName.setStringValue("DEFAULT");
2719 }
2720 if (id.equals("0")) {
2721 return;
2722 }
2723 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2724 skuName.setSkuID(new BigInteger(id));
2725 skuName.setStringValue(name);
2726 }
2727
2728 public int getPlatformDefsSkuInfoCount(){
2729 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2730 return 0;
2731 }
2732 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2733 }
2734
2735 public void getPlatformDefsSkuInfos(String[][] saa){
2736 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2737 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2738 removeElement(getfpdDynPcdBuildDefs());
2739 fpdDynPcdBuildDefs = null;
2740 }
2741 return ;
2742 }
2743
2744 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2745 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2746 int i = 0;
2747 while(li.hasNext()) {
2748 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2749 saa[i][0] = sku.getSkuID()+"";
2750 saa[i][1] = sku.getStringValue();
2751 ++i;
2752 }
2753 }
2754
2755 public void removePlatformDefsSkuInfo(int i) {
2756 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2757 if (skuInfo == null || i == 0) {
2758 return ;
2759 }
2760
2761 XmlCursor cursor = skuInfo.newCursor();
2762 if (cursor.toFirstChild()) {
2763 for (int j = 0; j < i; ++j) {
2764 cursor.toNextSibling();
2765 }
2766 cursor.removeXml();
2767 }
2768 cursor.dispose();
2769 }
2770
2771 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2772 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2773 if (skuInfo == null || i == 0) {
2774 return ;
2775 }
2776
2777 XmlCursor cursor = skuInfo.newCursor();
2778 if (cursor.toFirstChild()) {
2779 for (int j = 0; j < i; ++j) {
2780 cursor.toNextSibling();
2781 }
2782 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2783 sku.setSkuID(new BigInteger(id));
2784 sku.setStringValue(name);
2785 }
2786 cursor.dispose();
2787 }
2788
2789 public String getPlatformDefsInterDir(){
2790 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2791 return null;
2792 }
2793 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2794 }
2795
2796 public void setPlatformDefsInterDir(String interDir){
2797 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2798 }
2799
2800 public String getPlatformDefsOutputDir() {
2801 return getfpdPlatformDefs().getOutputDirectory();
2802 }
2803
2804 public void setPlatformDefsOutputDir(String outputDir) {
2805 if (outputDir != null && outputDir.length() > 0) {
2806 getfpdPlatformDefs().setOutputDirectory(outputDir);
2807 }
2808 else{
2809 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2810 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2811 cursor.removeXml();
2812 }
2813 cursor.dispose();
2814 }
2815 }
2816
2817 public FlashDocument.Flash getfpdFlash() {
2818 if (fpdFlash == null) {
2819 fpdFlash = fpdRoot.addNewFlash();
2820 }
2821 return fpdFlash;
2822 }
2823
2824 public void genFlashDefinitionFile(String file) {
2825 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2826 if (fdf == null) {
2827 fdf = getfpdFlash().addNewFlashDefinitionFile();
2828 }
2829
2830 fdf.setStringValue(file);
2831 }
2832
2833 public String getFlashDefinitionFile() {
2834 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2835 if (fdf == null) {
2836 return "";
2837 }
2838
2839 return fdf.getStringValue();
2840 }
2841
2842 public void genFvImagesNameValue(String name, String value) {
2843
2844 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2845 if (fi == null) {
2846 fi = getfpdFlash().addNewFvImages();
2847 }
2848
2849 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2850 nv.setName(name);
2851 nv.setValue(value);
2852 }
2853
2854 public void removeFvImagesNameValue(int i){
2855
2856 XmlObject o = getfpdFlash().getFvImages();
2857 if (o == null) {
2858 return;
2859 }
2860
2861 QName qNameValue = new QName(xmlNs, "NameValue");
2862 XmlCursor cursor = o.newCursor();
2863 if (cursor.toChild(qNameValue)) {
2864 for (int j = 0; j < i; ++j) {
2865 cursor.toNextSibling(qNameValue);
2866 }
2867 cursor.removeXml();
2868 }
2869 cursor.dispose();
2870 }
2871
2872 public void updateFvImagesNameValue(int i, String name, String value){
2873
2874 XmlObject o = getfpdFlash().getFvImages();
2875 if (o == null) {
2876 return;
2877 }
2878
2879 QName qNameValue = new QName(xmlNs, "NameValue");
2880 XmlCursor cursor = o.newCursor();
2881 if (cursor.toChild(qNameValue)) {
2882 for (int j = 0; j < i; ++j) {
2883 cursor.toNextSibling(qNameValue);
2884 }
2885 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2886 nv.setName(name);
2887 nv.setValue(value);
2888 }
2889 cursor.dispose();
2890 }
2891
2892 public int getFvImagesNameValueCount() {
2893
2894 FvImagesDocument.FvImages fi = null;
2895 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2896 return 0;
2897 }
2898 return fi.getNameValueList().size();
2899 }
2900
2901 public void getFvImagesNameValues(String[][] nv) {
2902
2903 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2904 if (fi == null){
2905 return;
2906 }
2907 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2908 int i = 0;
2909 ListIterator li = l.listIterator();
2910 while (li.hasNext()) {
2911 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2912 .next();
2913 nv[i][0] = e.getName();
2914 nv[i][1] = e.getValue();
2915
2916 i++;
2917 }
2918 }
2919
2920 public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {
2921 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2922 if (fis == null || fis.getFvImageList() == null) {
2923 return;
2924 }
2925
2926 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2927 while (li.hasNext()) {
2928 FvImagesDocument.FvImages.FvImage fi = li.next();
2929 if (fi.getType().toString().equals("ImageName")) {
2930 vImageNames.addAll(fi.getFvImageNamesList());
2931 return;
2932 }
2933 }
2934 }
2935
2936 public void addFvImageFvImageNames (String[] fvNames) {
2937 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2938 if (fis == null || fis.getFvImageList() == null) {
2939 genFvImagesFvImage (fvNames, "ImageName", null);
2940 return;
2941 }
2942
2943 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2944 while (li.hasNext()) {
2945 FvImagesDocument.FvImages.FvImage fi = li.next();
2946 if (fi.getType().toString().equals("ImageName")) {
2947 addFvImageNamesInFvImage (fi, fvNames);
2948 return;
2949 }
2950 }
2951 genFvImagesFvImage (fvNames, "ImageName", null);
2952 }
2953
2954 public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) {
2955
2956 for (int i = 0; i < fvNames.length; ++i) {
2957 fi.addFvImageNames(fvNames[i]);
2958 }
2959 }
2960
2961 public void addFvImageNamesInFvImage (int i, String[] fvNames) {
2962 XmlObject o = getfpdFlash().getFvImages();
2963 if (o == null) {
2964 return;
2965 }
2966 XmlCursor cursor = o.newCursor();
2967 QName qFvImage = new QName(xmlNs, "FvImage");
2968 if (cursor.toChild(qFvImage)) {
2969 for (int j = 0; j < i; ++j) {
2970 cursor.toNextSibling(qFvImage);
2971 }
2972 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2973 addFvImageNamesInFvImage(fi, fvNames);
2974 }
2975 cursor.dispose();
2976 }
2977
2978 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2979
2980 FvImagesDocument.FvImages fis = null;
2981 if ((fis = getfpdFlash().getFvImages()) == null) {
2982 fis = getfpdFlash().addNewFvImages();
2983 }
2984
2985 //
2986 //gen FvImage with FvImageNames array
2987 //
2988 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2989 for (int i = 0; i < names.length; ++i) {
2990 fi.addFvImageNames(names[i]);
2991 }
2992 fi.setType(FvImageTypes.Enum.forString(types));
2993 if (options != null){
2994 setFvImagesFvImageFvImageOptions(options, fi);
2995 }
2996 }
2997
2998 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2999 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
3000 if (fio == null){
3001 fio = fi.addNewFvImageOptions();
3002 }
3003
3004 Set<String> key = options.keySet();
3005 Iterator<String> i = key.iterator();
3006 while (i.hasNext()) {
3007
3008 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
3009 String k = (String)i.next();
3010
3011 nv.setName(k);
3012 nv.setValue((String)options.get(k));
3013
3014 }
3015
3016 }
3017
3018
3019 public void removeFvImagesFvImage(int i) {
3020
3021 XmlObject o = getfpdFlash().getFvImages();
3022 if (o == null) {
3023 return;
3024 }
3025
3026 QName qFvImage = new QName(xmlNs, "FvImage");
3027 XmlCursor cursor = o.newCursor();
3028 if (cursor.toChild(qFvImage)) {
3029 for (int j = 0; j < i; ++j) {
3030 cursor.toNextSibling(qFvImage);
3031 }
3032 cursor.removeXml();
3033 }
3034 cursor.dispose();
3035 }
3036
3037 /**
3038 * @param oldFvName
3039 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3040 */
3041 public void updateFvImageNameAll (String oldFvName, String newFvName) {
3042 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3043 return;
3044 }
3045 ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();
3046 while (li.hasNext()) {
3047 FvImagesDocument.FvImages.FvImage fi = li.next();
3048 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
3049 if (fi.getFvImageNamesList().size() == 0) {
3050 li.remove();
3051 }
3052 }
3053 }
3054
3055 public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) {
3056 XmlObject o = getfpdFlash().getFvImages();
3057 if (o == null) {
3058 return;
3059 }
3060 XmlCursor cursor = o.newCursor();
3061 QName qFvImage = new QName(xmlNs, "FvImage");
3062 if (cursor.toChild(qFvImage)) {
3063 for (int j = 0; j < i; ++j) {
3064 cursor.toNextSibling(qFvImage);
3065 }
3066 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3067 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
3068 }
3069 cursor.dispose();
3070 }
3071 /**
3072 * @param fi
3073 * @param oldFvName The FV Name to be replaced.
3074 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3075 */
3076 public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {
3077 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3078 XmlCursor cursor = fi.newCursor();
3079
3080 if (cursor.toChild(qFvImageNames)) {
3081 do {
3082 String xmlValue = cursor.getTextValue();
3083 if (xmlValue.equals(oldFvName)){
3084 if (newFvName != null) {
3085 cursor.setTextValue(newFvName);
3086 }
3087 else {
3088 cursor.removeXml();
3089 }
3090 }
3091 }while (cursor.toNextSibling(qFvImageNames));
3092 }
3093
3094 cursor.dispose();
3095 }
3096
3097 /**update the Type attribute of ith FvImage with new type.
3098 * @param i
3099 * @param type
3100 */
3101 public void updateFvImagesFvImageType (int i, String type) {
3102 XmlObject o = getfpdFlash().getFvImages();
3103 if (o == null) {
3104 return;
3105 }
3106 XmlCursor cursor = o.newCursor();
3107 QName qFvImage = new QName(xmlNs, "FvImage");
3108 if (cursor.toChild(qFvImage)) {
3109 for (int j = 0; j < i; ++j) {
3110 cursor.toNextSibling(qFvImage);
3111 }
3112 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3113 fi.setType(FvImageTypes.Enum.forString(type));
3114 }
3115 cursor.dispose();
3116 }
3117
3118 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
3119
3120 XmlObject o = getfpdFlash().getFvImages();
3121 if (o == null) {
3122 return;
3123 }
3124 XmlCursor cursor = o.newCursor();
3125 QName qFvImage = new QName(xmlNs, "FvImage");
3126 if (cursor.toChild(qFvImage)) {
3127 for (int j = 0; j < i; ++j) {
3128 cursor.toNextSibling(qFvImage);
3129 }
3130 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3131 fi.setType(FvImageTypes.Enum.forString(types));
3132
3133 //
3134 // remove old FvImageNames before adding new ones
3135 //
3136 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3137 cursor.toChild(qFvImageNames);
3138 cursor.removeXml();
3139 while (cursor.toNextSibling(qFvImageNames)) {
3140 cursor.removeXml();
3141 }
3142
3143 for (int k = 0; k < names.length; ++k) {
3144 fi.addFvImageNames(names[k]);
3145 }
3146 //
3147 // remove old FvImageOptions before adding new options
3148 //
3149 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
3150 cursor.toNextSibling(qFvImageOptions);
3151 cursor.removeXml();
3152
3153 setFvImagesFvImageFvImageOptions(options, fi);
3154 }
3155 cursor.dispose();
3156 }
3157
3158 public int getFvImagesFvImageCount(String type) {
3159
3160 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3161 return 0;
3162 }
3163 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3164 ListIterator li = l.listIterator();
3165 int i = 0;
3166 while(li.hasNext()) {
3167 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3168 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3169 continue;
3170 }
3171
3172 ++i;
3173 }
3174
3175 return i;
3176 }
3177
3178 public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {
3179 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();
3180 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3181 return vFvImage;
3182 }
3183 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3184 ListIterator li = l.listIterator();
3185 while(li.hasNext()) {
3186 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3187 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3188 continue;
3189 }
3190 if (fi.getFvImageNamesList().contains(fvName)) {
3191 vFvImage.add(fi);
3192 }
3193 }
3194
3195 return vFvImage;
3196 }
3197 /**
3198 * @param saa
3199 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3200 */
3201 public void getFvImagesFvImages(String[][] saa, String type) {
3202
3203 if (getfpdFlash().getFvImages() == null) {
3204 return;
3205 }
3206 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3207 if (l == null) {
3208 return;
3209 }
3210 ListIterator li = l.listIterator();
3211 int i = 0;
3212 while(li.hasNext()) {
3213 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3214 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3215 continue;
3216 }
3217 //
3218 // get FvImageNames array, space separated
3219 //
3220 List<String> lfn = fi.getFvImageNamesList();
3221 ListIterator lfni = lfn.listIterator();
3222 saa[i][0] = " ";
3223 while (lfni.hasNext()) {
3224 saa[i][0] += (String)lfni.next();
3225 saa[i][0] += " ";
3226 }
3227 saa[i][0] = saa[i][0].trim();
3228
3229 saa[i][1] = fi.getType()+"";
3230
3231 ++i;
3232 }
3233 }
3234
3235 public void removeFvImageNameValue (int i, String attributeName) {
3236 XmlObject o = getfpdFlash().getFvImages();
3237 if (o == null) {
3238 return;
3239 }
3240 XmlCursor cursor = o.newCursor();
3241 QName qFvImage = new QName(xmlNs, "FvImage");
3242 if (cursor.toChild(qFvImage)) {
3243 for (int j = 0; j < i; ++j) {
3244 cursor.toNextSibling(qFvImage);
3245 }
3246 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3247 removeFvImageNameValue (fi, attributeName);
3248 }
3249 cursor.dispose();
3250 }
3251 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3252 * @param fi
3253 * @param attributeName
3254 */
3255 public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) {
3256 if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) {
3257 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3258 while (li.hasNext()) {
3259 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3260 if (nv.getName().equals(attributeName)) {
3261 li.remove();
3262 }
3263 }
3264 }
3265 }
3266
3267 public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) {
3268 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName(fvName, type);
3269 for (int i = 0; i < vFvImage.size(); ++i) {
3270 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3271 removeFvImageNameValue (fi, optName);
3272 }
3273 }
3274
3275 /**Add name-value pair to FvImage element with type.
3276 * @param fvName FV name to add name-value pair.
3277 * @param type FvImage attribute.
3278 * @param name
3279 * @param value
3280 */
3281 public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value) {
3282 boolean fvImageExists = false;
3283 if (getfpdFlash().getFvImages() == null) {
3284 return;
3285 }
3286 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3287 if (l == null) {
3288 return;
3289 }
3290 ListIterator li = l.listIterator();
3291 while(li.hasNext()) {
3292 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3293 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3294 continue;
3295 }
3296 if (!fi.getFvImageNamesList().contains(fvName)) {
3297 continue;
3298 }
3299 fvImageExists = true;
3300 setFvImagesFvImageNameValue (fi, name, value, null);
3301 }
3302
3303 if (!fvImageExists) {
3304 HashMap<String, String> map = new HashMap<String, String>();
3305 map.put(name, value);
3306 genFvImagesFvImage(new String[]{fvName}, type, map);
3307 }
3308 }
3309
3310 /**Add to all FvImage elements with type, the name-value pair.
3311 * @param type
3312 * @param name
3313 * @param value
3314 */
3315 public void setTypedFvImageNameValue (String type, String name, String value) {
3316 if (getfpdFlash().getFvImages() == null) {
3317 return;
3318 }
3319 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3320 if (l == null) {
3321 return;
3322 }
3323 ListIterator li = l.listIterator();
3324 while(li.hasNext()) {
3325 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3326 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3327 continue;
3328 }
3329 setFvImagesFvImageNameValue (fi, name, value, null);
3330 }
3331
3332 }
3333
3334 public void setFvImagesFvImageNameValue (int i, String name, String value) {
3335 XmlObject o = getfpdFlash().getFvImages();
3336 if (o == null) {
3337 return;
3338 }
3339 XmlCursor cursor = o.newCursor();
3340 QName qFvImage = new QName(xmlNs, "FvImage");
3341 if (cursor.toChild(qFvImage)) {
3342 for (int j = 0; j < i; ++j) {
3343 cursor.toNextSibling(qFvImage);
3344 }
3345 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3346 setFvImagesFvImageNameValue (fi, name, value, null);
3347 }
3348 cursor.dispose();
3349 }
3350
3351 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3352 * @param fi
3353 * @param name
3354 * @param value
3355 * @param newName
3356 */
3357 public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {
3358 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3359 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();
3360 nv.setName(name);
3361 nv.setValue(value);
3362 if (newName != null) {
3363 nv.setName(newName);
3364 }
3365 return;
3366 }
3367
3368 XmlCursor cursor = fi.getFvImageOptions().newCursor();
3369 if (cursor.toFirstChild()) {
3370 do {
3371 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();
3372 if (nv.getName().equals(name)) {
3373 nv.setValue(value);
3374 if (newName != null) {
3375 nv.setName(newName);
3376 }
3377 cursor.dispose();
3378 return;
3379 }
3380 }while (cursor.toNextSibling());
3381 }
3382
3383 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();
3384 nv.setName(name);
3385 nv.setValue(value);
3386 if (newName != null) {
3387 nv.setName(newName);
3388 }
3389 cursor.dispose();
3390 }
3391
3392 public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {
3393 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");
3394 for (int i = 0; i < vFvImage.size(); ++i) {
3395 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3396 if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3397 continue;
3398 }
3399
3400 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()
3401 .getNameValueList()
3402 .listIterator();
3403 while (li.hasNext()) {
3404 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3405 m.put(nv.getName(), nv.getValue());
3406 }
3407 }
3408 }
3409
3410 public int getFvImagePosInFvImages (String fvNameList, String type) {
3411 XmlObject o = getfpdFlash().getFvImages();
3412 if (o == null) {
3413 return -1;
3414 }
3415
3416 int pos = -1;
3417 String[] fvNameArray = fvNameList.trim().split(" ");
3418 Vector<String> vFvNames = new Vector<String>();
3419
3420
3421 XmlCursor cursor = o.newCursor();
3422 QName qFvImage = new QName(xmlNs, "FvImage");
3423 if (cursor.toChild(qFvImage)) {
3424 do {
3425 pos++;
3426 vFvNames.removeAllElements();
3427 for (int i = 0; i < fvNameArray.length; ++i) {
3428 vFvNames.add(fvNameArray[i]);
3429 }
3430 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3431 if (!fi.getType().toString().equals(type)) {
3432 continue;
3433 }
3434 if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) {
3435 continue;
3436 }
3437 ListIterator<String> li = fi.getFvImageNamesList().listIterator();
3438 while (li.hasNext()) {
3439 String name = li.next();
3440 vFvNames.remove(name);
3441 }
3442 if (vFvNames.size() == 0) {
3443 cursor.dispose();
3444 return pos;
3445 }
3446
3447 }while (cursor.toNextSibling(qFvImage));
3448
3449 }
3450 cursor.dispose();
3451 return -1;
3452 }
3453 /**Get FvImage Options for FvImage i
3454 * @param i the ith FvImage
3455 */
3456 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
3457 XmlObject o = getfpdFlash().getFvImages();
3458 if (o == null) {
3459 return;
3460 }
3461 XmlCursor cursor = o.newCursor();
3462 QName qFvImage = new QName(xmlNs, "FvImage");
3463 if (cursor.toChild(qFvImage)) {
3464 for (int j = 0; j < i; ++j) {
3465 cursor.toNextSibling(qFvImage);
3466 }
3467 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3468 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
3469 cursor.dispose();
3470 return;
3471 }
3472 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3473 while(li.hasNext()){
3474 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3475 m.put(nv.getName(), nv.getValue());
3476 }
3477 }
3478 cursor.dispose();
3479 }
3480
3481 /**
3482 Get platform header element
3483 @return PlatformHeaderDocument.PlatformHeader
3484 **/
3485 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
3486 if (fpdHdr == null) {
3487 fpdHdr = fpdRoot.addNewPlatformHeader();
3488 }
3489
3490 return fpdHdr;
3491 }
3492
3493 public String getFpdHdrPlatformName() {
3494 return getFpdHdr().getPlatformName();
3495 }
3496
3497 public String getFpdHdrGuidValue() {
3498 return getFpdHdr().getGuidValue();
3499 }
3500
3501 public String getFpdHdrVer() {
3502 return getFpdHdr().getVersion();
3503 }
3504
3505 public String getFpdHdrAbs() {
3506 return getFpdHdr().getAbstract();
3507 }
3508
3509 public String getFpdHdrDescription() {
3510 return getFpdHdr().getDescription();
3511 }
3512
3513 public String getFpdHdrCopyright() {
3514 return getFpdHdr().getCopyright();
3515 }
3516
3517 public String getFpdHdrLicense() {
3518 LicenseDocument.License l = getFpdHdr().getLicense();
3519 if (l == null) {
3520 return null;
3521 }
3522 return l.getStringValue();
3523 }
3524
3525 public String getFpdHdrUrl() {
3526 LicenseDocument.License l = getFpdHdr().getLicense();
3527 if (l == null) {
3528 return null;
3529 }
3530 return l.getURL();
3531 }
3532
3533 public String getFpdHdrSpec() {
3534
3535 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3536 // return getFpdHdr().getSpecification();
3537 }
3538
3539 public void setFpdHdrPlatformName(String name){
3540 getFpdHdr().setPlatformName(name);
3541 }
3542
3543 public void setFpdHdrGuidValue(String guid){
3544 getFpdHdr().setGuidValue(guid);
3545 }
3546
3547 public void setFpdHdrVer(String v){
3548 getFpdHdr().setVersion(v);
3549 }
3550
3551 public void setFpdHdrAbs(String abs) {
3552 getFpdHdr().setAbstract(abs);
3553 }
3554
3555 public void setFpdHdrDescription(String desc){
3556 getFpdHdr().setDescription(desc);
3557 }
3558
3559 public void setFpdHdrCopyright(String cr) {
3560 getFpdHdr().setCopyright(cr);
3561 }
3562
3563 public void setFpdHdrLicense(String license){
3564 LicenseDocument.License l = getFpdHdr().getLicense();
3565 if (l == null) {
3566 getFpdHdr().addNewLicense().setStringValue(license);
3567 }
3568 else {
3569 l.setStringValue(license);
3570 }
3571 }
3572
3573 public void setFpdHdrUrl(String url){
3574 LicenseDocument.License l = getFpdHdr().getLicense();
3575
3576 l.setURL(url);
3577
3578 }
3579
3580 public void setFpdHdrSpec(String s){
3581 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3582 getFpdHdr().setSpecification(s);
3583 }
3584 /**
3585 Save the processed xml contents to file
3586
3587 @param fpdFile The file to save xml contents
3588 @throws IOException Exceptions during file operation
3589 **/
3590 public void saveAs(File fpdFile) throws IOException {
3591
3592 XmlOptions options = new XmlOptions();
3593
3594 options.setCharacterEncoding("UTF-8");
3595 options.setSavePrettyPrint();
3596 options.setSavePrettyPrintIndent(2);
3597 try {
3598 fpdd.save(fpdFile, options);
3599 } catch (IOException e) {
3600 e.printStackTrace();
3601 }
3602
3603 }
3604
3605 private String listToString(List l) {
3606 if (l == null) {
3607 return null;
3608 }
3609 String s = " ";
3610 ListIterator li = l.listIterator();
3611 while(li.hasNext()) {
3612 s += li.next();
3613 s += " ";
3614 }
3615 return s.trim();
3616 }
3617
3618 private void removeElement(XmlObject o) {
3619 XmlCursor cursor = o.newCursor();
3620 cursor.removeXml();
3621 cursor.dispose();
3622 }
3623 }
3624
3625 class PcdItemTypeConflictException extends Exception {
3626
3627 /**
3628 *
3629 */
3630 private static final long serialVersionUID = 1L;
3631 private String details = null;
3632
3633 PcdItemTypeConflictException(String pcdName, String info){
3634 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
3635 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();
3636 }
3637
3638 public String getMessage() {
3639 return details;
3640 }
3641 }
3642
3643 class PcdDeclNotFound extends Exception {
3644
3645 /**
3646 *
3647 */
3648 private static final long serialVersionUID = 1L;
3649 private String details = null;
3650
3651 PcdDeclNotFound(String info) {
3652 details = "PcdDeclNotFound: " + info;
3653 }
3654
3655 public String getMessage() {
3656 return details;
3657 }
3658 }
3659
3660 class PcdValueMalFormed extends Exception {
3661
3662 /**
3663 *
3664 */
3665 private static final long serialVersionUID = 1L;
3666 private String details = null;
3667
3668 PcdValueMalFormed(String info) {
3669 details = "PcdValueMalFormed: " + info;
3670 }
3671
3672 public String getMessage() {
3673 return details;
3674 }
3675 }