]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
Fix Ffs sections encapsulation type update problem.
[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 = getFfs(i);
2395 ffs.getSections().setEncapsulationType(type);
2396 }
2397
2398 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
2399 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2400 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
2401 attrib.setName(name);
2402 attrib.setValue(value);
2403 }
2404
2405 /**update jth attribute of ith ffs.
2406 * @param i
2407 * @param j
2408 */
2409 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
2410 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2411 XmlCursor cursor = ffs.newCursor();
2412 QName qAttrib = new QName(xmlNs, "Attribute");
2413 if (cursor.toChild(qAttrib)) {
2414 for (int k = 0; k < j; ++k) {
2415 cursor.toNextSibling(qAttrib);
2416 }
2417 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
2418 attrib.setName(name);
2419 attrib.setValue(value);
2420 }
2421 cursor.dispose();
2422 }
2423
2424 public void removeBuildOptionsFfsAttribute(int i, int j){
2425 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2426 XmlCursor cursor = ffs.newCursor();
2427 QName qAttrib = new QName(xmlNs, "Attribute");
2428 if (cursor.toChild(qAttrib)) {
2429 for (int k = 0; k < j; ++k) {
2430 cursor.toNextSibling(qAttrib);
2431 }
2432 cursor.removeXml();
2433 }
2434 cursor.dispose();
2435 }
2436
2437 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
2438 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2439 if (ffs == null) {
2440 return;
2441 }
2442 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2443
2444 if (sections == null){
2445 sections = ffs.addNewSections();
2446 }
2447 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
2448 }
2449
2450 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
2451 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2452 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2453 if (sections == null) {
2454 return;
2455 }
2456 XmlCursor cursor = sections.newCursor();
2457 QName qSection = new QName(xmlNs, "Section");
2458 if (cursor.toChild(qSection)) {
2459 for (int k = 0; k < j; ++k) {
2460 cursor.toNextSibling(qSection);
2461 }
2462 cursor.removeXml();
2463 }
2464 cursor.dispose();
2465 }
2466
2467 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
2468 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2469 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2470 if (sections == null) {
2471 return;
2472 }
2473 XmlCursor cursor = sections.newCursor();
2474 QName qSection = new QName(xmlNs, "Section");
2475 if (cursor.toChild(qSection)) {
2476 for (int k = 0; k < j; ++k) {
2477 cursor.toNextSibling(qSection);
2478 }
2479 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
2480 section.setSectionType(EfiSectionType.Enum.forString(type));
2481 }
2482 cursor.dispose();
2483 }
2484
2485 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
2486 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2487 if (ffs == null) {
2488 return;
2489 }
2490 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2491
2492 if (sections == null){
2493 sections = ffs.addNewSections();
2494 }
2495 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = sections.addNewSections();
2496 sections2.setEncapsulationType(encapType);
2497 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString("EFI_SECTION_PE32"));
2498 }
2499
2500 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
2501 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2502 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2503 if (sections == null) {
2504 return;
2505 }
2506 XmlCursor cursor = sections.newCursor();
2507 QName qSections = new QName(xmlNs, "Sections");
2508 if (cursor.toChild(qSections)) {
2509 for (int k = 0; k < j; ++k) {
2510 cursor.toNextSibling(qSections);
2511 }
2512 cursor.removeXml();
2513 }
2514 cursor.dispose();
2515 }
2516
2517 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
2518 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2519 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2520 if (sections == null) {
2521 return;
2522 }
2523 XmlCursor cursor = sections.newCursor();
2524 QName qSections = new QName(xmlNs, "Sections");
2525 if (cursor.toChild(qSections)) {
2526 for (int k = 0; k < j; ++k) {
2527 cursor.toNextSibling(qSections);
2528 }
2529 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2530 sections2.setEncapsulationType(type);
2531 }
2532 cursor.dispose();
2533 }
2534
2535 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
2536 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2537 if (ffs == null) {
2538 return;
2539 }
2540 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2541 XmlCursor cursor = sections.newCursor();
2542 QName qSections = new QName(xmlNs, "Sections");
2543 if (cursor.toChild(qSections)){
2544 for (int k = 0; k < j; ++k) {
2545 cursor.toNextSibling(qSections);
2546 }
2547 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2548 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2549 }
2550 cursor.dispose();
2551 }
2552
2553 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2554 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2555 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2556 if (sections == null) {
2557 return;
2558 }
2559 XmlCursor cursor = sections.newCursor();
2560 QName qSections = new QName(xmlNs, "Sections");
2561 if (cursor.toChild(qSections)) {
2562 for (int l = 0; l < j; ++l) {
2563 cursor.toNextSibling(qSections);
2564 }
2565 if (cursor.toFirstChild()) {
2566 int m = 0;
2567 for (; m < k; ++m) {
2568 cursor.toNextSibling();
2569 }
2570 cursor.removeXml();
2571 if (m == 0) {
2572 cursor.toParent();
2573 cursor.removeXml();
2574 }
2575 }
2576 }
2577 cursor.dispose();
2578 }
2579
2580 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2581 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2582 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2583 if (sections == null) {
2584 return;
2585 }
2586 XmlCursor cursor = sections.newCursor();
2587 QName qSections = new QName(xmlNs, "Sections");
2588 if (cursor.toChild(qSections)) {
2589 for (int l = 0; l < j; ++l) {
2590 cursor.toNextSibling(qSections);
2591 }
2592 if (cursor.toFirstChild()) {
2593 for (int m = 0; m < k; ++m) {
2594 cursor.toNextSibling();
2595 }
2596 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2597 section.setSectionType(EfiSectionType.Enum.forString(type));
2598 }
2599 }
2600 cursor.dispose();
2601 }
2602
2603 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2604 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2605 if (ffs == null) {
2606 return;
2607 }
2608 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2609 XmlCursor cursor = sections.newCursor();
2610 QName qSections = new QName(xmlNs, "Sections");
2611 if (cursor.toChild(qSections)){
2612 for (int k = 0; k < j; ++k) {
2613 cursor.toNextSibling(qSections);
2614 }
2615 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2616 if (sections2.getSectionList() == null){
2617 cursor.dispose();
2618 return;
2619 }
2620 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2621 while(li.hasNext()) {
2622 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2623 // if (section.isSetSectionType()) {
2624 al.add(section.getSectionType()+"");
2625 // }
2626
2627 }
2628 }
2629 cursor.dispose();
2630
2631 }
2632
2633 public int getBuildOptionsFfsCount(){
2634 if (getfpdBuildOpts().getFfsList() == null) {
2635 return 0;
2636 }
2637 return getfpdBuildOpts().getFfsList().size();
2638 }
2639
2640 public void getBuildOptionsFfsKey(String[][] saa) {
2641 if (getfpdBuildOpts().getFfsList() == null) {
2642 return;
2643 }
2644 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2645 int i = 0;
2646 while(li.hasNext()){
2647 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2648 saa[i][0] = ffs.getFfsKey();
2649 ++i;
2650 }
2651 }
2652
2653 public void updateBuildOptionsFfsKey(int i, String key) {
2654 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2655 ffs.setFfsKey(key);
2656 }
2657
2658 /**Get ith FFS key and contents.
2659 * @param saa
2660 */
2661 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2662 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2663
2664 if (ffs != null) {
2665
2666 sa[0] = ffs.getFfsKey();
2667 if (ffs.getSections() != null) {
2668 if(ffs.getSections().getEncapsulationType() != null){
2669 sa[1] = ffs.getSections().getEncapsulationType();
2670 }
2671 if (ffs.getSections().getSectionList() != null){
2672 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2673 while (li.hasNext()) {
2674 firstLevelSection.add(li.next().getSectionType()+"");
2675 }
2676 }
2677 if (ffs.getSections().getSectionsList() != null) {
2678 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2679 while(li.hasNext()) {
2680 firstLevelSections.add(li.next().getEncapsulationType());
2681 }
2682 }
2683 }
2684 if (ffs.getAttributeList() != null) {
2685 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2686 while(li.hasNext()) {
2687 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2688 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2689 }
2690
2691 }
2692 }
2693
2694
2695 }
2696
2697 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2698 XmlObject o = getfpdBuildOpts();
2699 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2700
2701 XmlCursor cursor = o.newCursor();
2702 QName qFfs = new QName(xmlNs, "Ffs");
2703 if (cursor.toChild(qFfs)) {
2704 for (int j = 0; j < i; ++j) {
2705 cursor.toNextSibling(qFfs);
2706 }
2707 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2708 }
2709 cursor.dispose();
2710 return ffs;
2711 }
2712
2713 public void removeBuildOptionsFfs(int i) {
2714 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2715 if (ffs == null){
2716 return;
2717 }
2718
2719 XmlCursor cursor = ffs.newCursor();
2720 cursor.removeXml();
2721 cursor.dispose();
2722 }
2723
2724
2725
2726 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2727 if (fpdPlatformDefs == null){
2728 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2729 }
2730 return fpdPlatformDefs;
2731 }
2732
2733 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2734 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2735 return;
2736 }
2737 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2738 while(li.hasNext()) {
2739 archs.add(li.next());
2740 }
2741 }
2742
2743 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2744 if (archs != null) {
2745 getfpdPlatformDefs().setSupportedArchitectures(archs);
2746 }
2747 // else {
2748 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2749 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2750 // cursor.removeXml();
2751 // }
2752 // cursor.dispose();
2753 // }
2754 }
2755
2756 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2757 if (getfpdPlatformDefs().getBuildTargets() == null) {
2758 return;
2759 }
2760 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2761 while(li.hasNext()) {
2762 targets.add(li.next());
2763 }
2764 }
2765
2766 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2767 getfpdPlatformDefs().setBuildTargets(targets);
2768 }
2769
2770 public void genPlatformDefsSkuInfo(String id, String name) {
2771 SkuInfoDocument.SkuInfo skuInfo = null;
2772 if (getfpdPlatformDefs().getSkuInfo() == null) {
2773 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2774 }
2775 skuInfo = getfpdPlatformDefs().getSkuInfo();
2776 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2777 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2778 skuName.setSkuID(new BigInteger("0"));
2779 skuName.setStringValue("DEFAULT");
2780 }
2781 if (id.equals("0")) {
2782 return;
2783 }
2784 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2785 skuName.setSkuID(new BigInteger(id));
2786 skuName.setStringValue(name);
2787 }
2788
2789 public int getPlatformDefsSkuInfoCount(){
2790 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2791 return 0;
2792 }
2793 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2794 }
2795
2796 public void getPlatformDefsSkuInfos(String[][] saa){
2797 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2798 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2799 removeElement(getfpdDynPcdBuildDefs());
2800 fpdDynPcdBuildDefs = null;
2801 }
2802 return ;
2803 }
2804
2805 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2806 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2807 int i = 0;
2808 while(li.hasNext()) {
2809 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2810 saa[i][0] = sku.getSkuID()+"";
2811 saa[i][1] = sku.getStringValue();
2812 ++i;
2813 }
2814 }
2815
2816 public void removePlatformDefsSkuInfo(int i) {
2817 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2818 if (skuInfo == null || i == 0) {
2819 return ;
2820 }
2821
2822 XmlCursor cursor = skuInfo.newCursor();
2823 if (cursor.toFirstChild()) {
2824 for (int j = 0; j < i; ++j) {
2825 cursor.toNextSibling();
2826 }
2827 cursor.removeXml();
2828 }
2829 cursor.dispose();
2830 }
2831
2832 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2833 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2834 if (skuInfo == null || i == 0) {
2835 return ;
2836 }
2837
2838 XmlCursor cursor = skuInfo.newCursor();
2839 if (cursor.toFirstChild()) {
2840 for (int j = 0; j < i; ++j) {
2841 cursor.toNextSibling();
2842 }
2843 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2844 sku.setSkuID(new BigInteger(id));
2845 sku.setStringValue(name);
2846 }
2847 cursor.dispose();
2848 }
2849
2850 public String getPlatformDefsInterDir(){
2851 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2852 return null;
2853 }
2854 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2855 }
2856
2857 public void setPlatformDefsInterDir(String interDir){
2858 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2859 }
2860
2861 public String getPlatformDefsOutputDir() {
2862 return getfpdPlatformDefs().getOutputDirectory();
2863 }
2864
2865 public void setPlatformDefsOutputDir(String outputDir) {
2866 if (outputDir != null && outputDir.length() > 0) {
2867 getfpdPlatformDefs().setOutputDirectory(outputDir);
2868 }
2869 else{
2870 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2871 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2872 cursor.removeXml();
2873 }
2874 cursor.dispose();
2875 }
2876 }
2877
2878 public FlashDocument.Flash getfpdFlash() {
2879 if (fpdFlash == null) {
2880 fpdFlash = fpdRoot.addNewFlash();
2881 }
2882 return fpdFlash;
2883 }
2884
2885 public void genFlashDefinitionFile(String file) {
2886 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2887 if (fdf == null) {
2888 fdf = getfpdFlash().addNewFlashDefinitionFile();
2889 }
2890
2891 fdf.setStringValue(file);
2892 }
2893
2894 public String getFlashDefinitionFile() {
2895 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2896 if (fdf == null) {
2897 return "";
2898 }
2899
2900 return fdf.getStringValue();
2901 }
2902
2903 public void genFvImagesNameValue(String name, String value) {
2904
2905 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2906 if (fi == null) {
2907 fi = getfpdFlash().addNewFvImages();
2908 }
2909
2910 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2911 nv.setName(name);
2912 nv.setValue(value);
2913 }
2914
2915 public void removeFvImagesNameValue(int i){
2916
2917 XmlObject o = getfpdFlash().getFvImages();
2918 if (o == null) {
2919 return;
2920 }
2921
2922 QName qNameValue = new QName(xmlNs, "NameValue");
2923 XmlCursor cursor = o.newCursor();
2924 if (cursor.toChild(qNameValue)) {
2925 for (int j = 0; j < i; ++j) {
2926 cursor.toNextSibling(qNameValue);
2927 }
2928 cursor.removeXml();
2929 }
2930 cursor.dispose();
2931 }
2932
2933 public void updateFvImagesNameValue(int i, String name, String value){
2934
2935 XmlObject o = getfpdFlash().getFvImages();
2936 if (o == null) {
2937 return;
2938 }
2939
2940 QName qNameValue = new QName(xmlNs, "NameValue");
2941 XmlCursor cursor = o.newCursor();
2942 if (cursor.toChild(qNameValue)) {
2943 for (int j = 0; j < i; ++j) {
2944 cursor.toNextSibling(qNameValue);
2945 }
2946 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2947 nv.setName(name);
2948 nv.setValue(value);
2949 }
2950 cursor.dispose();
2951 }
2952
2953 public int getFvImagesNameValueCount() {
2954
2955 FvImagesDocument.FvImages fi = null;
2956 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2957 return 0;
2958 }
2959 return fi.getNameValueList().size();
2960 }
2961
2962 public void getFvImagesNameValues(String[][] nv) {
2963
2964 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2965 if (fi == null){
2966 return;
2967 }
2968 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2969 int i = 0;
2970 ListIterator li = l.listIterator();
2971 while (li.hasNext()) {
2972 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2973 .next();
2974 nv[i][0] = e.getName();
2975 nv[i][1] = e.getValue();
2976
2977 i++;
2978 }
2979 }
2980
2981 public void getFvImagesFvImageFvImageNames (Vector<String> vImageNames) {
2982 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2983 if (fis == null || fis.getFvImageList() == null) {
2984 return;
2985 }
2986
2987 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
2988 while (li.hasNext()) {
2989 FvImagesDocument.FvImages.FvImage fi = li.next();
2990 if (fi.getType().toString().equals("ImageName")) {
2991 vImageNames.addAll(fi.getFvImageNamesList());
2992 return;
2993 }
2994 }
2995 }
2996
2997 public void addFvImageFvImageNames (String[] fvNames) {
2998 FvImagesDocument.FvImages fis = getfpdFlash().getFvImages();
2999 if (fis == null || fis.getFvImageList() == null) {
3000 genFvImagesFvImage (fvNames, "ImageName", null);
3001 return;
3002 }
3003
3004 ListIterator<FvImagesDocument.FvImages.FvImage> li = fis.getFvImageList().listIterator();
3005 while (li.hasNext()) {
3006 FvImagesDocument.FvImages.FvImage fi = li.next();
3007 if (fi.getType().toString().equals("ImageName")) {
3008 addFvImageNamesInFvImage (fi, fvNames);
3009 return;
3010 }
3011 }
3012 genFvImagesFvImage (fvNames, "ImageName", null);
3013 }
3014
3015 public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) {
3016
3017 for (int i = 0; i < fvNames.length; ++i) {
3018 fi.addFvImageNames(fvNames[i]);
3019 }
3020 }
3021
3022 public void addFvImageNamesInFvImage (int i, String[] fvNames) {
3023 XmlObject o = getfpdFlash().getFvImages();
3024 if (o == null) {
3025 return;
3026 }
3027 XmlCursor cursor = o.newCursor();
3028 QName qFvImage = new QName(xmlNs, "FvImage");
3029 if (cursor.toChild(qFvImage)) {
3030 for (int j = 0; j < i; ++j) {
3031 cursor.toNextSibling(qFvImage);
3032 }
3033 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3034 addFvImageNamesInFvImage(fi, fvNames);
3035 }
3036 cursor.dispose();
3037 }
3038
3039 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
3040
3041 FvImagesDocument.FvImages fis = null;
3042 if ((fis = getfpdFlash().getFvImages()) == null) {
3043 fis = getfpdFlash().addNewFvImages();
3044 }
3045
3046 //
3047 //gen FvImage with FvImageNames array
3048 //
3049 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
3050 for (int i = 0; i < names.length; ++i) {
3051 fi.addFvImageNames(names[i]);
3052 }
3053 fi.setType(FvImageTypes.Enum.forString(types));
3054 if (options != null){
3055 setFvImagesFvImageFvImageOptions(options, fi);
3056 }
3057 }
3058
3059 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
3060 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
3061 if (fio == null){
3062 fio = fi.addNewFvImageOptions();
3063 }
3064
3065 Set<String> key = options.keySet();
3066 Iterator<String> i = key.iterator();
3067 while (i.hasNext()) {
3068
3069 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
3070 String k = (String)i.next();
3071
3072 nv.setName(k);
3073 nv.setValue((String)options.get(k));
3074
3075 }
3076
3077 }
3078
3079
3080 public void removeFvImagesFvImage(int i) {
3081
3082 XmlObject o = getfpdFlash().getFvImages();
3083 if (o == null) {
3084 return;
3085 }
3086
3087 QName qFvImage = new QName(xmlNs, "FvImage");
3088 XmlCursor cursor = o.newCursor();
3089 if (cursor.toChild(qFvImage)) {
3090 for (int j = 0; j < i; ++j) {
3091 cursor.toNextSibling(qFvImage);
3092 }
3093 cursor.removeXml();
3094 }
3095 cursor.dispose();
3096 }
3097
3098 /**
3099 * @param oldFvName
3100 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3101 */
3102 public void updateFvImageNameAll (String oldFvName, String newFvName) {
3103 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3104 return;
3105 }
3106 ListIterator<FvImagesDocument.FvImages.FvImage> li = getfpdFlash().getFvImages().getFvImageList().listIterator();
3107 while (li.hasNext()) {
3108 FvImagesDocument.FvImages.FvImage fi = li.next();
3109 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
3110 if (fi.getFvImageNamesList().size() == 0) {
3111 li.remove();
3112 }
3113 }
3114 }
3115
3116 public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) {
3117 XmlObject o = getfpdFlash().getFvImages();
3118 if (o == null) {
3119 return;
3120 }
3121 XmlCursor cursor = o.newCursor();
3122 QName qFvImage = new QName(xmlNs, "FvImage");
3123 if (cursor.toChild(qFvImage)) {
3124 for (int j = 0; j < i; ++j) {
3125 cursor.toNextSibling(qFvImage);
3126 }
3127 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3128 updateFvImageNamesInFvImage (fi, oldFvName, newFvName);
3129 }
3130 cursor.dispose();
3131 }
3132 /**
3133 * @param fi
3134 * @param oldFvName The FV Name to be replaced.
3135 * @param newFvName The New FV Name. If null, remove the old FvImageNames entry.
3136 */
3137 public void updateFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String oldFvName, String newFvName) {
3138 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3139 XmlCursor cursor = fi.newCursor();
3140
3141 if (cursor.toChild(qFvImageNames)) {
3142 do {
3143 String xmlValue = cursor.getTextValue();
3144 if (xmlValue.equals(oldFvName)){
3145 if (newFvName != null) {
3146 cursor.setTextValue(newFvName);
3147 }
3148 else {
3149 cursor.removeXml();
3150 }
3151 }
3152 }while (cursor.toNextSibling(qFvImageNames));
3153 }
3154
3155 cursor.dispose();
3156 }
3157
3158 /**update the Type attribute of ith FvImage with new type.
3159 * @param i
3160 * @param type
3161 */
3162 public void updateFvImagesFvImageType (int i, String type) {
3163 XmlObject o = getfpdFlash().getFvImages();
3164 if (o == null) {
3165 return;
3166 }
3167 XmlCursor cursor = o.newCursor();
3168 QName qFvImage = new QName(xmlNs, "FvImage");
3169 if (cursor.toChild(qFvImage)) {
3170 for (int j = 0; j < i; ++j) {
3171 cursor.toNextSibling(qFvImage);
3172 }
3173 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3174 fi.setType(FvImageTypes.Enum.forString(type));
3175 }
3176 cursor.dispose();
3177 }
3178
3179 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
3180
3181 XmlObject o = getfpdFlash().getFvImages();
3182 if (o == null) {
3183 return;
3184 }
3185 XmlCursor cursor = o.newCursor();
3186 QName qFvImage = new QName(xmlNs, "FvImage");
3187 if (cursor.toChild(qFvImage)) {
3188 for (int j = 0; j < i; ++j) {
3189 cursor.toNextSibling(qFvImage);
3190 }
3191 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3192 fi.setType(FvImageTypes.Enum.forString(types));
3193
3194 //
3195 // remove old FvImageNames before adding new ones
3196 //
3197 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
3198 cursor.toChild(qFvImageNames);
3199 cursor.removeXml();
3200 while (cursor.toNextSibling(qFvImageNames)) {
3201 cursor.removeXml();
3202 }
3203
3204 for (int k = 0; k < names.length; ++k) {
3205 fi.addFvImageNames(names[k]);
3206 }
3207 //
3208 // remove old FvImageOptions before adding new options
3209 //
3210 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
3211 cursor.toNextSibling(qFvImageOptions);
3212 cursor.removeXml();
3213
3214 setFvImagesFvImageFvImageOptions(options, fi);
3215 }
3216 cursor.dispose();
3217 }
3218
3219 public int getFvImagesFvImageCount(String type) {
3220
3221 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3222 return 0;
3223 }
3224 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3225 ListIterator li = l.listIterator();
3226 int i = 0;
3227 while(li.hasNext()) {
3228 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3229 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3230 continue;
3231 }
3232
3233 ++i;
3234 }
3235
3236 return i;
3237 }
3238
3239 public Vector<FvImagesDocument.FvImages.FvImage> getFvImagesFvImageWithName (String fvName, String type) {
3240 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = new Vector<FvImagesDocument.FvImages.FvImage>();
3241 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
3242 return vFvImage;
3243 }
3244 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3245 ListIterator li = l.listIterator();
3246 while(li.hasNext()) {
3247 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3248 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3249 continue;
3250 }
3251 if (fi.getFvImageNamesList().contains(fvName)) {
3252 vFvImage.add(fi);
3253 }
3254 }
3255
3256 return vFvImage;
3257 }
3258 /**
3259 * @param saa
3260 * @param type "ALL" means all FvImage types: ImageName, Options, Attributes, Components.
3261 */
3262 public void getFvImagesFvImages(String[][] saa, String type) {
3263
3264 if (getfpdFlash().getFvImages() == null) {
3265 return;
3266 }
3267 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3268 if (l == null) {
3269 return;
3270 }
3271 ListIterator li = l.listIterator();
3272 int i = 0;
3273 while(li.hasNext()) {
3274 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3275 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3276 continue;
3277 }
3278 //
3279 // get FvImageNames array, space separated
3280 //
3281 List<String> lfn = fi.getFvImageNamesList();
3282 ListIterator lfni = lfn.listIterator();
3283 saa[i][0] = " ";
3284 while (lfni.hasNext()) {
3285 saa[i][0] += (String)lfni.next();
3286 saa[i][0] += " ";
3287 }
3288 saa[i][0] = saa[i][0].trim();
3289
3290 saa[i][1] = fi.getType()+"";
3291
3292 ++i;
3293 }
3294 }
3295
3296 public void removeFvImageNameValue (int i, String attributeName) {
3297 XmlObject o = getfpdFlash().getFvImages();
3298 if (o == null) {
3299 return;
3300 }
3301 XmlCursor cursor = o.newCursor();
3302 QName qFvImage = new QName(xmlNs, "FvImage");
3303 if (cursor.toChild(qFvImage)) {
3304 for (int j = 0; j < i; ++j) {
3305 cursor.toNextSibling(qFvImage);
3306 }
3307 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3308 removeFvImageNameValue (fi, attributeName);
3309 }
3310 cursor.dispose();
3311 }
3312 /**Remove from fi the attribute pair with attributeName in FvImageOptions.
3313 * @param fi
3314 * @param attributeName
3315 */
3316 public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) {
3317 if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) {
3318 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3319 while (li.hasNext()) {
3320 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3321 if (nv.getName().equals(attributeName)) {
3322 li.remove();
3323 }
3324 }
3325 }
3326 }
3327
3328 public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) {
3329 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName(fvName, type);
3330 for (int i = 0; i < vFvImage.size(); ++i) {
3331 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3332 removeFvImageNameValue (fi, optName);
3333 }
3334 }
3335
3336 /**Add name-value pair to FvImage element with type.
3337 * @param fvName FV name to add name-value pair.
3338 * @param type FvImage attribute.
3339 * @param name
3340 * @param value
3341 */
3342 public void setTypedNamedFvImageNameValue (String fvName, String type, String name, String value, String newName) {
3343 boolean fvImageExists = false;
3344 if (getfpdFlash().getFvImages() != null) {
3345
3346 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3347 if (l != null) {
3348 ListIterator li = l.listIterator();
3349 while (li.hasNext()) {
3350 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage) li.next();
3351 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3352 continue;
3353 }
3354 if (!fi.getFvImageNamesList().contains(fvName)) {
3355 continue;
3356 }
3357 fvImageExists = true;
3358 setFvImagesFvImageNameValue(fi, name, value, newName);
3359 }
3360 }
3361 }
3362
3363 if (!fvImageExists) {
3364 HashMap<String, String> map = new HashMap<String, String>();
3365 map.put(name, value);
3366 genFvImagesFvImage(new String[] { fvName }, type, map);
3367 }
3368 }
3369
3370 /**Add to all FvImage elements with type, the name-value pair.
3371 * @param type
3372 * @param name
3373 * @param value
3374 */
3375 public void setTypedFvImageNameValue (String type, String name, String value) {
3376 if (getfpdFlash().getFvImages() == null) {
3377 return;
3378 }
3379 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
3380 if (l == null) {
3381 return;
3382 }
3383 ListIterator li = l.listIterator();
3384 while(li.hasNext()) {
3385 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
3386 if (!fi.getType().toString().equals(type) && !type.equals("ALL")) {
3387 continue;
3388 }
3389 setFvImagesFvImageNameValue (fi, name, value, null);
3390 }
3391
3392 }
3393
3394 public void setFvImagesFvImageNameValue (int i, String name, String value) {
3395 XmlObject o = getfpdFlash().getFvImages();
3396 if (o == null) {
3397 return;
3398 }
3399 XmlCursor cursor = o.newCursor();
3400 QName qFvImage = new QName(xmlNs, "FvImage");
3401 if (cursor.toChild(qFvImage)) {
3402 for (int j = 0; j < i; ++j) {
3403 cursor.toNextSibling(qFvImage);
3404 }
3405 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3406 setFvImagesFvImageNameValue (fi, name, value, null);
3407 }
3408 cursor.dispose();
3409 }
3410
3411 /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before.
3412 * @param fi
3413 * @param name
3414 * @param value
3415 * @param newName
3416 */
3417 public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) {
3418 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3419 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue();
3420 nv.setName(name);
3421 nv.setValue(value);
3422 if (newName != null && !newName.equals(name)) {
3423 nv.setName(newName);
3424 }
3425 return;
3426 }
3427
3428 XmlCursor cursor = fi.getFvImageOptions().newCursor();
3429 if (cursor.toFirstChild()) {
3430 do {
3431 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)cursor.getObject();
3432 if (nv.getName().equals(name)) {
3433 nv.setValue(value);
3434 if (newName != null && !newName.equals(name)) {
3435 nv.setName(newName);
3436 }
3437 cursor.dispose();
3438 return;
3439 }
3440 }while (cursor.toNextSibling());
3441 }
3442
3443 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.getFvImageOptions().addNewNameValue();
3444 nv.setName(name);
3445 nv.setValue(value);
3446 if (newName != null && !newName.equals(name)) {
3447 nv.setName(newName);
3448 }
3449 cursor.dispose();
3450 }
3451
3452 public void getFvImagesFvImageOptions (String fvName, Map<String, String> m) {
3453 Vector<FvImagesDocument.FvImages.FvImage> vFvImage = getFvImagesFvImageWithName (fvName, "Options");
3454 for (int i = 0; i < vFvImage.size(); ++i) {
3455 FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i);
3456 if (fi == null || fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) {
3457 continue;
3458 }
3459
3460 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions()
3461 .getNameValueList()
3462 .listIterator();
3463 while (li.hasNext()) {
3464 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3465 m.put(nv.getName(), nv.getValue());
3466 }
3467 }
3468 }
3469
3470 public int getFvImagePosInFvImages (String fvNameList, String type) {
3471 XmlObject o = getfpdFlash().getFvImages();
3472 if (o == null) {
3473 return -1;
3474 }
3475
3476 int pos = -1;
3477 String[] fvNameArray = fvNameList.trim().split(" ");
3478 Vector<String> vFvNames = new Vector<String>();
3479
3480
3481 XmlCursor cursor = o.newCursor();
3482 QName qFvImage = new QName(xmlNs, "FvImage");
3483 if (cursor.toChild(qFvImage)) {
3484 do {
3485 pos++;
3486 vFvNames.removeAllElements();
3487 for (int i = 0; i < fvNameArray.length; ++i) {
3488 vFvNames.add(fvNameArray[i]);
3489 }
3490 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3491 if (!fi.getType().toString().equals(type)) {
3492 continue;
3493 }
3494 if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) {
3495 continue;
3496 }
3497 ListIterator<String> li = fi.getFvImageNamesList().listIterator();
3498 while (li.hasNext()) {
3499 String name = li.next();
3500 vFvNames.remove(name);
3501 }
3502 if (vFvNames.size() == 0) {
3503 cursor.dispose();
3504 return pos;
3505 }
3506
3507 }while (cursor.toNextSibling(qFvImage));
3508
3509 }
3510 cursor.dispose();
3511 return -1;
3512 }
3513 /**Get FvImage Options for FvImage i
3514 * @param i the ith FvImage
3515 */
3516 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
3517 XmlObject o = getfpdFlash().getFvImages();
3518 if (o == null) {
3519 return;
3520 }
3521 XmlCursor cursor = o.newCursor();
3522 QName qFvImage = new QName(xmlNs, "FvImage");
3523 if (cursor.toChild(qFvImage)) {
3524 for (int j = 0; j < i; ++j) {
3525 cursor.toNextSibling(qFvImage);
3526 }
3527 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
3528 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
3529 cursor.dispose();
3530 return;
3531 }
3532 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
3533 while(li.hasNext()){
3534 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
3535 m.put(nv.getName(), nv.getValue());
3536 }
3537 }
3538 cursor.dispose();
3539 }
3540
3541 /**
3542 Get platform header element
3543 @return PlatformHeaderDocument.PlatformHeader
3544 **/
3545 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
3546 if (fpdHdr == null) {
3547 fpdHdr = fpdRoot.addNewPlatformHeader();
3548 }
3549
3550 return fpdHdr;
3551 }
3552
3553 public String getFpdHdrPlatformName() {
3554 return getFpdHdr().getPlatformName();
3555 }
3556
3557 public String getFpdHdrGuidValue() {
3558 return getFpdHdr().getGuidValue();
3559 }
3560
3561 public String getFpdHdrVer() {
3562 return getFpdHdr().getVersion();
3563 }
3564
3565 public String getFpdHdrAbs() {
3566 return getFpdHdr().getAbstract();
3567 }
3568
3569 public String getFpdHdrDescription() {
3570 return getFpdHdr().getDescription();
3571 }
3572
3573 public String getFpdHdrCopyright() {
3574 return getFpdHdr().getCopyright();
3575 }
3576
3577 public String getFpdHdrLicense() {
3578 LicenseDocument.License l = getFpdHdr().getLicense();
3579 if (l == null) {
3580 return null;
3581 }
3582 return l.getStringValue();
3583 }
3584
3585 public String getFpdHdrUrl() {
3586 LicenseDocument.License l = getFpdHdr().getLicense();
3587 if (l == null) {
3588 return null;
3589 }
3590 return l.getURL();
3591 }
3592
3593 public String getFpdHdrSpec() {
3594
3595 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3596 // return getFpdHdr().getSpecification();
3597 }
3598
3599 public void setFpdHdrPlatformName(String name){
3600 getFpdHdr().setPlatformName(name);
3601 }
3602
3603 public void setFpdHdrGuidValue(String guid){
3604 getFpdHdr().setGuidValue(guid);
3605 }
3606
3607 public void setFpdHdrVer(String v){
3608 getFpdHdr().setVersion(v);
3609 }
3610
3611 public void setFpdHdrAbs(String abs) {
3612 getFpdHdr().setAbstract(abs);
3613 }
3614
3615 public void setFpdHdrDescription(String desc){
3616 getFpdHdr().setDescription(desc);
3617 }
3618
3619 public void setFpdHdrCopyright(String cr) {
3620 getFpdHdr().setCopyright(cr);
3621 }
3622
3623 public void setFpdHdrLicense(String license){
3624 LicenseDocument.License l = getFpdHdr().getLicense();
3625 if (l == null) {
3626 getFpdHdr().addNewLicense().setStringValue(license);
3627 }
3628 else {
3629 l.setStringValue(license);
3630 }
3631 }
3632
3633 public void setFpdHdrUrl(String url){
3634 LicenseDocument.License l = getFpdHdr().getLicense();
3635
3636 l.setURL(url);
3637
3638 }
3639
3640 public void setFpdHdrSpec(String s){
3641 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
3642 getFpdHdr().setSpecification(s);
3643 }
3644 /**
3645 Save the processed xml contents to file
3646
3647 @param fpdFile The file to save xml contents
3648 @throws IOException Exceptions during file operation
3649 **/
3650 public void saveAs(File fpdFile) throws IOException {
3651
3652 XmlOptions options = new XmlOptions();
3653
3654 options.setCharacterEncoding("UTF-8");
3655 options.setSavePrettyPrint();
3656 options.setSavePrettyPrintIndent(2);
3657 try {
3658 fpdd.save(fpdFile, options);
3659 } catch (IOException e) {
3660 e.printStackTrace();
3661 }
3662
3663 }
3664
3665 private String listToString(List l) {
3666 if (l == null) {
3667 return null;
3668 }
3669 String s = " ";
3670 ListIterator li = l.listIterator();
3671 while(li.hasNext()) {
3672 s += li.next();
3673 s += " ";
3674 }
3675 return s.trim();
3676 }
3677
3678 private void removeElement(XmlObject o) {
3679 XmlCursor cursor = o.newCursor();
3680 cursor.removeXml();
3681 cursor.dispose();
3682 }
3683 }
3684
3685 class PcdItemTypeConflictException extends Exception {
3686
3687 /**
3688 *
3689 */
3690 private static final long serialVersionUID = 1L;
3691 private String details = null;
3692
3693 PcdItemTypeConflictException (String pcdName, String info) {
3694 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
3695 if (mi != null) {
3696 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();
3697 }
3698 else {
3699 details = pcdName + " ItemType Conflicts with " + info;
3700 }
3701 }
3702
3703 PcdItemTypeConflictException (String pcdName, String info1, String info2) {
3704 ModuleIdentification mi1 = WorkspaceProfile.getModuleId(info1);
3705 ModuleIdentification mi2 = WorkspaceProfile.getModuleId(info2);
3706 String moduleInfo1 = "";
3707 String moduleInfo2 = "";
3708 if (mi1 != null) {
3709 moduleInfo1 = mi1.getName() + " in Pkg " + mi1.getPackageId().getName();
3710 }
3711 else {
3712 moduleInfo1 = info1;
3713 }
3714
3715 if (mi2 != null) {
3716 moduleInfo2 = mi2.getName() + " in Pkg " + mi2.getPackageId().getName();
3717 }
3718 else {
3719 moduleInfo2 = info2;
3720 }
3721
3722 details = pcdName + " ItemType Conflicts in " + moduleInfo1 + " and " + moduleInfo2;
3723 }
3724
3725 public String getMessage() {
3726 return details;
3727 }
3728 }
3729
3730 class PcdDeclNotFound extends Exception {
3731
3732 /**
3733 *
3734 */
3735 private static final long serialVersionUID = 1L;
3736 private String details = null;
3737
3738 PcdDeclNotFound(String info) {
3739 details = "PcdDeclNotFound: " + info;
3740 }
3741
3742 public String getMessage() {
3743 return details;
3744 }
3745 }
3746
3747 class PcdValueMalFormed extends Exception {
3748
3749 /**
3750 *
3751 */
3752 private static final long serialVersionUID = 1L;
3753 private String details = null;
3754
3755 PcdValueMalFormed(String info) {
3756 details = "PcdValueMalFormed: " + info;
3757 }
3758
3759 public String getMessage() {
3760 return details;
3761 }
3762 }