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