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