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