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