]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java
e60426446fbe826b66cf251432da64e9b5db78e4
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFileContents.java
1 /** @file
2 Java class FpdFileContents is used to parse fpd xml file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.frameworkwizard.platform.ui;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.math.BigInteger;
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.Iterator;
21 import java.util.LinkedHashMap;
22 import java.util.List;
23 import java.util.ListIterator;
24 import java.util.Map;
25 import java.util.Set;
26 import java.util.Vector;
27
28 import javax.xml.namespace.QName;
29
30 import org.apache.xmlbeans.XmlCursor;
31 import org.apache.xmlbeans.XmlObject;
32 import org.apache.xmlbeans.XmlOptions;
33 import org.tianocore.AntTaskDocument;
34 import org.tianocore.BuildOptionsDocument;
35 import org.tianocore.DynamicPcdBuildDefinitionsDocument;
36 import org.tianocore.EfiSectionType;
37 import org.tianocore.FlashDefinitionFileDocument;
38 import org.tianocore.FlashDocument;
39 import org.tianocore.FrameworkModulesDocument;
40 import org.tianocore.IntermediateOutputType;
41 import org.tianocore.LibrariesDocument;
42 import org.tianocore.ModuleSADocument;
43 import org.tianocore.ModuleSaBuildOptionsDocument;
44 import org.tianocore.ModuleSurfaceAreaDocument;
45 import org.tianocore.OptionDocument;
46 import org.tianocore.OptionsDocument;
47 import org.tianocore.PcdBuildDefinitionDocument;
48 import org.tianocore.PcdCodedDocument;
49 import org.tianocore.PcdDataTypes;
50 import org.tianocore.PcdDeclarationsDocument;
51 import org.tianocore.PcdItemTypes;
52 import org.tianocore.PlatformDefinitionsDocument;
53 import org.tianocore.PlatformSurfaceAreaDocument;
54 import org.tianocore.FvImageTypes;
55 import org.tianocore.FvImagesDocument;
56 import org.tianocore.LicenseDocument;
57 import org.tianocore.PlatformHeaderDocument;
58 import org.tianocore.SkuInfoDocument;
59 import org.tianocore.UserDefinedAntTasksDocument;
60 import org.tianocore.UserExtensionsDocument;
61 import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
62 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
63 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
64 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
65
66 /**
67 This class processes fpd file contents such as add remove xml elements.
68 @since PackageEditor 1.0
69 **/
70 public class FpdFileContents {
71
72 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";
73
74 private PlatformSurfaceAreaDocument fpdd = null;
75
76 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;
77
78 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;
79
80 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;
81
82 private FlashDocument.Flash fpdFlash = null;
83
84 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;
85
86 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;
87
88 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;
89
90 private HashMap<String, ArrayList<String>> dynPcdMap = null;
91
92 private HashMap<String, String> defaultPcdValue = new HashMap<String, String>();
93
94 /**
95 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.
96 */
97 public void initDynPcdMap() {
98 if (dynPcdMap == null) {
99 dynPcdMap = new HashMap<String, ArrayList<String>>();
100 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();
101 if (l == null) {
102 removeElement(getfpdFrameworkModules());
103 fpdFrameworkModules = null;
104 return;
105 }
106 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();
107 while (li.hasNext()) {
108 ModuleSADocument.ModuleSA moduleSa = li.next();
109 if (moduleSa.getPcdBuildDefinition() == null || moduleSa.getPcdBuildDefinition().getPcdDataList() == null) {
110 continue;
111 }
112 String ModuleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() +
113 " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
114 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = moduleSa.getPcdBuildDefinition().getPcdDataList();
115 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();
116 while (lpi.hasNext()) {
117 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();
118 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();
119 if (dynPcdMap.get(pcdKey) == null) {
120 ArrayList<String> al = new ArrayList<String>();
121 al.add(ModuleInfo + " " + pcdData.getItemType().toString());
122 dynPcdMap.put(pcdKey, al);
123 }
124 else{
125 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());
126 }
127 }
128 }
129 }
130 }
131
132 public ArrayList<String> getDynPcdMapValue(String key) {
133 return dynPcdMap.get(key);
134 }
135 /**
136 Constructor to create a new spd file
137 **/
138 public FpdFileContents() {
139
140 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();
141 fpdRoot = fpdd.addNewPlatformSurfaceArea();
142
143 }
144
145 /**
146 Constructor for existing document object
147 @param psa
148 **/
149 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {
150 fpdRoot = fpd;
151 fpdHdr = fpdRoot.getPlatformHeader();
152 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();
153 fpdBuildOpts = fpdRoot.getBuildOptions();
154 fpdFrameworkModules = fpdRoot.getFrameworkModules();
155 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();
156 fpdFlash = fpdRoot.getFlash();
157 }
158
159 /**
160 Constructor based on an existing spd file
161
162 @param f Existing spd file
163 **/
164 public FpdFileContents(File f) {
165 try {
166 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);
167 fpdRoot = fpdd.getPlatformSurfaceArea();
168 } catch (Exception e) {
169 System.out.println(e.toString());
170 }
171 }
172
173 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {
174 if (fpdDynPcdBuildDefs == null){
175 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();
176 }
177 return fpdDynPcdBuildDefs;
178 }
179
180 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {
181 if (fpdFrameworkModules == null){
182 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();
183 }
184 return fpdFrameworkModules;
185 }
186
187 public void getFrameworkModuleGuid (String fvName, Vector<String> vGuid) {
188 if (getFrameworkModulesCount() == 0){
189 return;
190 }
191
192 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
193 while(li.hasNext()) {
194 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
195 if (moduleSa.getModuleSaBuildOptions() == null) {
196 continue;
197 }
198 String fvBinding = moduleSa.getModuleSaBuildOptions().getFvBinding();
199 if (fvBinding == null) {
200 continue;
201 }
202
203 String[] fvNames = fvBinding.split(" ");
204 for (int i = 0; i < fvNames.length; ++i) {
205 if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) {
206 vGuid.add(moduleSa.getModuleGuid());
207 break;
208 }
209 }
210 }
211 }
212
213 public int getFrameworkModulesCount() {
214 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0){
215 removeElement(getfpdFrameworkModules());
216 fpdFrameworkModules = null;
217 return 0;
218 }
219 return getfpdFrameworkModules().getModuleSAList().size();
220 }
221
222 public void getFrameworkModulesInfo(String[][] saa) {
223 if (getFrameworkModulesCount() == 0){
224 return;
225 }
226
227 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
228 int i = 0;
229 while(li.hasNext()) {
230 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
231 saa[i][0] = moduleSa.getModuleGuid();
232 saa[i][1] = moduleSa.getModuleVersion();
233
234 saa[i][2] = moduleSa.getPackageGuid();
235 saa[i][3] = moduleSa.getPackageVersion();
236 saa[i][4] = listToString(moduleSa.getSupArchList());
237 ++i;
238 }
239 }
240
241 public void getFrameworkModuleInfo(int i, String[] sa) {
242 ModuleSADocument.ModuleSA msa = getModuleSA(i);
243 if (msa == null) {
244 return;
245 }
246 sa[0] = msa.getModuleGuid();
247 sa[1] = msa.getModuleVersion();
248 sa[2] = msa.getPackageGuid();
249 sa[3] = msa.getPackageVersion();
250 sa[4] = listToString(msa.getSupArchList());
251 }
252
253 public ModuleSADocument.ModuleSA getModuleSA(String key) {
254 String[] s = key.split(" ");
255 if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) {
256 removeElement(getfpdFrameworkModules());
257 fpdFrameworkModules = null;
258 return null;
259 }
260 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();
261 while(li.hasNext()) {
262 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next();
263 if (moduleSa.getModuleGuid().equalsIgnoreCase(s[0]) && moduleSa.getPackageGuid().equalsIgnoreCase(s[2])) {
264 if (moduleSa.getModuleVersion() != null) {
265 if (!moduleSa.getModuleVersion().equals(s[1])) {
266 continue;
267 }
268 }
269 if (moduleSa.getPackageVersion() != null) {
270 if (!moduleSa.getPackageVersion().equals(s[3])) {
271 continue;
272 }
273 }
274 //ToDo add arch check for s[4]
275 if (moduleSa.getSupArchList() != null) {
276 if (!listToString(moduleSa.getSupArchList()).equals(s[4])) {
277 continue;
278 }
279 }
280 return moduleSa;
281 }
282 }
283 return null;
284 }
285
286 private ModuleSADocument.ModuleSA getModuleSA(int i) {
287 ModuleSADocument.ModuleSA moduleSa = null;
288 if (fpdRoot.getFrameworkModules() == null) {
289 return null;
290 }
291 XmlCursor cursor = fpdRoot.getFrameworkModules().newCursor();
292 if (cursor.toFirstChild()) {
293 for (int j = 0; j < i; ++j) {
294 cursor.toNextSibling();
295 }
296 moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
297 }
298 cursor.dispose();
299 return moduleSa;
300 }
301
302 public void removeModuleSA(int i) {
303 XmlObject o = fpdRoot.getFrameworkModules();
304 if (o == null) {
305 return;
306 }
307
308 XmlCursor cursor = o.newCursor();
309 if (cursor.toFirstChild()) {
310 for (int j = 0; j < i; ++j) {
311 cursor.toNextSibling();
312 }
313 //
314 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.
315 //
316 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();
317 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +
318 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList());
319 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();
320 if (pcdBuildDef != null && pcdBuildDef.getPcdDataList() != null) {
321 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> li = pcdBuildDef.getPcdDataList().listIterator();
322 while(li.hasNext()) {
323 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
324 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleInfo);
325 }
326 }
327
328 cursor.push();
329 cursor.toPrevToken();
330 if (cursor.isComment()) {
331 cursor.removeXml();
332 }
333 cursor.pop();
334 cursor.removeXml();
335 if (getFrameworkModulesCount() == 0) {
336 cursor.toParent();
337 cursor.removeXml();
338 }
339 }
340 cursor.dispose();
341 }
342
343 public boolean adjustPcd (int seqModuleSa) throws Exception {
344 boolean dataModified = false;
345 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
346 int pcdCount = getPcdDataCount(seqModuleSa);
347 String[][] saaModuleSaPcd = new String[pcdCount][7];
348 getPcdData(seqModuleSa, saaModuleSaPcd);
349 String mg = moduleSa.getModuleGuid();
350 String mv = moduleSa.getModuleVersion();
351 String pg = moduleSa.getPackageGuid();
352 String pv = moduleSa.getPackageVersion();
353 String arch = listToString(moduleSa.getSupArchList());
354 //
355 // delete pcd in ModuleSA but not in MSA files any longer.
356 //
357 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
358 int libCount = getLibraryInstancesCount(moduleKey);
359 String[][] saaLib = new String[libCount][5];
360 getLibraryInstances(moduleKey, saaLib);
361 ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);
362 Vector<ModuleIdentification> vMi = new Vector<ModuleIdentification>();
363 vMi.add(mi);
364 try {
365 nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) {
366 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], mi)){
367 continue;
368 }
369 for (int j = 0; j < saaLib.length; ++j) {
370 String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4];
371 ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey);
372 vMi.add(libMi);
373 if (WorkspaceProfile.pcdInMsa(saaModuleSaPcd[i][0], saaModuleSaPcd[i][1], libMi)) {
374 continue nextPcd;
375 }
376 }
377 removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]);
378 dataModified = true;
379 }
380 }
381 catch (Exception e) {
382
383 }
384 //
385 // add new Pcd from MSA file to ModuleSA.
386 //
387 try {
388
389 for (int i = 0; i < vMi.size(); ++i) {
390 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile
391 .getModuleXmlObject(vMi
392 .get(i));
393 if (msa.getPcdCoded() == null || msa.getPcdCoded().getPcdEntryList() == null) {
394 continue;
395 }
396 ListIterator li = msa.getPcdCoded().getPcdEntryList().listIterator();
397 msaPcdIter:while (li.hasNext()) {
398 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry) li.next();
399 ArrayList<String> al = getDynPcdMapValue(msaPcd.getCName() + " " + msaPcd.getTokenSpaceGuidCName());
400 if (al != null) {
401 for (int j = 0; j < al.size(); ++j) {
402 if (al.get(j).contains(moduleKey)) {
403 continue msaPcdIter;
404 }
405 }
406 }
407
408 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
409 m.put("ModuleSurfaceArea", msa);
410 SurfaceAreaQuery.setDoc(m);
411 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, vMi.get(i));
412 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
413 if (spdPcd == null) {
414 //
415 // ToDo Error
416 //
417 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module "
418 + mi.getName());
419 }
420 //
421 // AddItem to ModuleSA PcdBuildDefinitions
422 //
423 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue()
424 : msaPcd.getDefaultValue();
425
426 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(),
427 msaPcd.getPcdItemType().toString(), spdPcd.getDatumType() + "", defaultVal, moduleSa);
428 dataModified = true;
429 }
430
431 }
432 }
433 catch (Exception e){
434 throw e;
435 }
436
437 return dataModified;
438 }
439
440 private void maintainDynPcdMap(String pcdKey, String moduleInfo) {
441
442 ArrayList<String> al = dynPcdMap.get(pcdKey);
443 if (al == null) {
444 return;
445 }
446 String[] s = moduleInfo.split(" ");
447 for(int i = 0; i < al.size(); ++i){
448 String consumer = al.get(i);
449 if (consumer.contains(s[0]) && consumer.contains(s[2])){
450 String[] consumerPart = consumer.split(" ");
451 if (!consumerPart[4].equals(s[4])) {
452 continue;
453 }
454 al.remove(consumer);
455 break;
456 }
457 }
458
459 if (al.size() == 0) {
460 defaultPcdValue.remove(pcdKey);
461 dynPcdMap.remove(pcdKey);
462 String[] s1 = pcdKey.split(" ");
463 removeDynamicPcdBuildData(s1[0], s1[1]);
464 }
465
466 }
467 //
468 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
469 //
470 public int getPcdDataCount (int i){
471 ModuleSADocument.ModuleSA msa = getModuleSA(i);
472
473 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
474 return 0;
475 }
476 return msa.getPcdBuildDefinition().getPcdDataList().size();
477
478 }
479
480 public void getPcdData (int i, String[][] saa) {
481 ModuleSADocument.ModuleSA msa = getModuleSA(i);
482
483 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){
484 return;
485 }
486 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();
487 for (int k = 0; k < saa.length; ++k) {
488 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();
489 saa[k][0] = pcdData.getCName();
490 saa[k][1] = pcdData.getTokenSpaceGuidCName();
491 saa[k][2] = pcdData.getItemType()+"";
492 saa[k][3] = pcdData.getToken().toString();
493 saa[k][4] = pcdData.getMaxDatumSize()+"";
494 saa[k][5] = pcdData.getDatumType()+"";
495 saa[k][6] = pcdData.getValue();
496
497 }
498 }
499
500 public void removePcdData (int seqModuleSa, String cName, String tsGuid) {
501 ModuleSADocument.ModuleSA moduleSa = getModuleSA(seqModuleSa);
502 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
503 return;
504 }
505
506 String mg = moduleSa.getModuleGuid();
507 String mv = moduleSa.getModuleVersion();
508 String pg = moduleSa.getPackageGuid();
509 String pv = moduleSa.getPackageVersion();
510 String arch = listToString(moduleSa.getSupArchList());
511 String moduleKey = mg + " " + mv + " " + pg + " " + pv + " " + arch;
512
513 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
514 if (cursor.toFirstChild()){
515
516 do {
517 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
518 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
519 maintainDynPcdMap(cName + " " + tsGuid, moduleKey);
520 if (getPcdDataCount(seqModuleSa) == 1) {
521 cursor.toParent();
522 }
523 cursor.removeXml();
524 break;
525 }
526 }
527 while(cursor.toNextSibling());
528
529 }
530 cursor.dispose();
531 }
532
533 public void updatePcdData (String key, String cName, String tsGuid, String itemType, String maxSize, String value){
534 ModuleSADocument.ModuleSA moduleSa = getModuleSA(key);
535 if (moduleSa == null || moduleSa.getPcdBuildDefinition() == null){
536 return;
537 }
538
539 XmlCursor cursor = moduleSa.getPcdBuildDefinition().newCursor();
540 if (cursor.toFirstChild()){
541 do {
542 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();
543 if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) {
544 pcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
545 if(pcdData.getDatumType().equals("VOID*")) {
546 pcdData.setMaxDatumSize(new Integer(maxSize));
547 }
548 pcdData.setValue(value);
549 defaultPcdValue.put(cName + " " + tsGuid, value);
550 break;
551 }
552 }
553 while(cursor.toNextSibling());
554 }
555 cursor.dispose();
556 }
557
558 /**Get original Pcd info from MSA & SPD files.
559 * @param mi ModuleIdentification from which MSA & SPD come
560 * @param cName PCD cName
561 * @param sa Results: HelpText, Original item type.
562 * @return
563 */
564 public boolean getPcdBuildDataInfo(ModuleIdentification mi, String cName, String tsGuid, String[] sa) throws Exception{
565 try {
566
567 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
568 if (msa.getPcdCoded() == null) {
569 return false;
570 }
571
572 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
573 m.put("ModuleSurfaceArea", msa);
574 SurfaceAreaQuery.setDoc(m);
575 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
576 //
577 // First look through MSA pcd entries.
578 //
579 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
580 ListIterator li = l.listIterator();
581 while(li.hasNext()) {
582 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
583 if (!msaPcd.getCName().equals(cName)) {
584 continue;
585 }
586 if (!msaPcd.getTokenSpaceGuidCName().equals(tsGuid)) {
587 continue;
588 }
589 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
590 if (spdPcd == null) {
591 //
592 // ToDo Error
593 //
594 throw new PcdDeclNotFound(mi.getName() + " " + msaPcd.getCName());
595 }
596 //
597 // Get Pcd help text and original item type.
598 //
599 sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText();
600 sa[1] = msaPcd.getPcdItemType()+"";
601 return true;
602 }
603
604
605 }
606 catch (Exception e){
607 e.printStackTrace();
608 throw e;
609 }
610
611 return false;
612 }
613
614 /**Remove PCDBuildDefinition entries from ModuleSA
615 * @param moduleKey identifier of ModuleSA.
616 * @param consumer where these entries come from.
617 */
618 public void removePcdData(String moduleKey, ModuleIdentification consumer) {
619 try {
620 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer);
621 if (msa.getPcdCoded() == null) {
622 return;
623 }
624
625 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
626 ListIterator li = l.listIterator();
627
628 while(li.hasNext()) {
629 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
630 ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey);
631 if (moduleSA.getPcdBuildDefinition() != null) {
632 XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor();
633 if (cursor.toFirstChild()) {
634 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor
635 .getObject();
636 if (msaPcd.getCName().equals(pcdData.getCName())
637 && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {
638
639 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey);
640 cursor.removeXml();
641 break;
642 }
643 while (cursor.toNextSibling()) {
644 pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor.getObject();
645 if (msaPcd.getCName().equals(pcdData.getCName())
646 && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) {
647 maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(),
648 moduleKey);
649 cursor.removeXml();
650 break;
651 }
652 }
653 }
654 cursor.dispose();
655 }
656 }
657
658 }
659 catch (Exception e){
660 e.printStackTrace();
661
662 }
663 }
664 //
665 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch"
666 //
667 public int getLibraryInstancesCount(String key) {
668 ModuleSADocument.ModuleSA msa = getModuleSA(key);
669 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
670 return 0;
671 }
672 return msa.getLibraries().getInstanceList().size();
673 }
674
675 public void getLibraryInstances(String key, String[][] saa){
676 ModuleSADocument.ModuleSA msa = getModuleSA(key);
677 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){
678 return ;
679 }
680
681 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();
682 for (int i = 0; i < saa.length; ++i) {
683 LibrariesDocument.Libraries.Instance instance = li.next();
684 saa[i][1] = instance.getModuleGuid();
685 saa[i][2] = instance.getModuleVersion();
686 saa[i][3] = instance.getPackageGuid();
687 saa[i][4] = instance.getPackageVersion();
688 }
689 }
690
691 public void removeLibraryInstance(String key, int i) {
692 ModuleSADocument.ModuleSA msa = getModuleSA(key);
693 if (msa == null || msa.getLibraries() == null){
694 return ;
695 }
696
697 XmlCursor cursor = msa.getLibraries().newCursor();
698 if (cursor.toFirstChild()) {
699 for (int j = 0; j < i; ++j) {
700 cursor.toNextSibling();
701 }
702 cursor.push();
703 cursor.toPrevToken();
704 if (cursor.isComment()) {
705 cursor.removeXml();
706 }
707 cursor.pop();
708 cursor.removeXml();
709 if (getLibraryInstancesCount(key) == 0) {
710 cursor.toParent();
711 cursor.removeXml();
712 }
713 }
714
715 cursor.dispose();
716 }
717
718 public void genLibraryInstance(ModuleIdentification libMi, String key) {
719 ModuleSADocument.ModuleSA msa = getModuleSA(key);
720 if (msa == null){
721 msa = getfpdFrameworkModules().addNewModuleSA();
722 }
723 LibrariesDocument.Libraries libs = msa.getLibraries();
724 if(libs == null){
725 libs = msa.addNewLibraries();
726 }
727
728 String mn = libMi.getName();
729 String mg = libMi.getGuid();
730 String mv = libMi.getVersion();
731 String pn = libMi.getPackageId().getName();
732 String pg = libMi.getPackageId().getGuid();
733 String pv = libMi.getPackageId().getVersion();
734 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();
735 XmlCursor cursor = instance.newCursor();
736 try{
737 String comment = "Pkg: " + pn + " Mod: " + mn
738 + " Path: " + libMi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
739 cursor.insertComment(comment);
740 }
741 catch (Exception e){
742 e.printStackTrace();
743 }
744 finally {
745 cursor.dispose();
746 }
747
748 instance.setModuleGuid(mg);
749 instance.setModuleVersion(mv);
750 instance.setPackageGuid(pg);
751 instance.setPackageVersion(pv);
752
753 }
754
755 public String getFvBinding(String moduleKey){
756 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
757 if (msa == null || msa.getModuleSaBuildOptions() == null) {
758 return null;
759 }
760 return msa.getModuleSaBuildOptions().getFvBinding();
761 }
762
763 public void setFvBinding(String moduleKey, String fvBinding){
764 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
765 if (msa == null ) {
766 return;
767 }
768 if (fvBinding == null || fvBinding.length() == 0) {
769 if(msa.getModuleSaBuildOptions() != null){
770 msa.getModuleSaBuildOptions().unsetFvBinding();
771 }
772 }
773 else {
774 if(msa.getModuleSaBuildOptions() == null){
775 msa.addNewModuleSaBuildOptions().setFvBinding(fvBinding);
776 return;
777 }
778 msa.getModuleSaBuildOptions().setFvBinding(fvBinding);
779 }
780 }
781
782 public String getFfsFileNameGuid(String moduleKey){
783 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
784 if (msa == null || msa.getModuleSaBuildOptions() == null) {
785 return null;
786 }
787 return msa.getModuleSaBuildOptions().getFfsFileNameGuid();
788 }
789
790 public void setFfsFileNameGuid(String moduleKey, String fileGuid){
791 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
792 if (msa == null ) {
793 return;
794 }
795 if(msa.getModuleSaBuildOptions() == null){
796 msa.addNewModuleSaBuildOptions();
797
798 }
799 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions msaBuildOpts= msa.getModuleSaBuildOptions();
800 if (fileGuid != null) {
801 msaBuildOpts.setFfsFileNameGuid(fileGuid);
802 }
803 else{
804 XmlCursor cursor = msaBuildOpts.newCursor();
805 if (cursor.toChild(xmlNs, "FfsFileNameGuid")) {
806 cursor.removeXml();
807 }
808 cursor.dispose();
809 }
810
811 }
812
813 public String getFfsFormatKey(String moduleKey){
814 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
815 if (msa == null || msa.getModuleSaBuildOptions() == null) {
816 return null;
817 }
818 return msa.getModuleSaBuildOptions().getFfsFormatKey();
819 }
820
821 public void setFfsFormatKey(String moduleKey, String ffsKey){
822 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
823 if (msa == null ) {
824 return;
825 }
826 if(msa.getModuleSaBuildOptions() == null){
827 msa.addNewModuleSaBuildOptions().setFfsFormatKey(ffsKey);
828 return;
829 }
830 msa.getModuleSaBuildOptions().setFfsFormatKey(ffsKey);
831 }
832
833 public void setModuleSAForceDebug(int i, boolean dbgEnable) {
834 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
835 moduleSa.setForceDebug(dbgEnable);
836 }
837
838 public boolean getModuleSAForceDebug (int i) {
839 ModuleSADocument.ModuleSA moduleSa = getModuleSA(i);
840 if (moduleSa.getForceDebug() == true) {
841 return true;
842 }
843 return false;
844 }
845
846 public void getModuleSAOptions(String moduleKey, String[][] saa) {
847 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
848 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
849 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
850 return ;
851 }
852
853 List<OptionDocument.Option> lOpt = msa.getModuleSaBuildOptions().getOptions().getOptionList();
854 ListIterator li = lOpt.listIterator();
855 int i = 0;
856 while(li.hasNext()) {
857 OptionDocument.Option opt = (OptionDocument.Option)li.next();
858 if (opt.getBuildTargets() != null) {
859 saa[i][0] = listToString(opt.getBuildTargets());
860 }
861 saa[i][1] = opt.getToolChainFamily();
862 saa[i][2] = opt.getTagName();
863 saa[i][3] = opt.getToolCode();
864
865 if (opt.getSupArchList() != null){
866 saa[i][4] = listToString(opt.getSupArchList());
867
868 }
869
870 saa[i][5] = opt.getStringValue();
871
872 ++i;
873 }
874 }
875
876 public int getModuleSAOptionsCount(String moduleKey){
877 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
878 if (msa == null || msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null
879 || msa.getModuleSaBuildOptions().getOptions().getOptionList() == null) {
880 return 0;
881 }
882 return msa.getModuleSaBuildOptions().getOptions().getOptionList().size();
883 }
884
885 public void genModuleSAOptionsOpt(String moduleKey, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
886 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
887 if (msa.getModuleSaBuildOptions() == null) {
888 msa.addNewModuleSaBuildOptions();
889 }
890 if (msa.getModuleSaBuildOptions().getOptions() == null){
891 msa.getModuleSaBuildOptions().addNewOptions();
892 }
893 OptionDocument.Option opt = msa.getModuleSaBuildOptions().getOptions().addNewOption();
894 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
895 }
896
897 public void removeModuleSAOptionsOpt(String moduleKey, int i) {
898 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
899 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
900 return ;
901 }
902 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
903 XmlCursor cursor = opts.newCursor();
904 if (cursor.toFirstChild()) {
905 for (int j = 0; j < i; ++j){
906 cursor.toNextSibling();
907 }
908 cursor.removeXml();
909 }
910 cursor.dispose();
911 }
912
913 public void updateModuleSAOptionsOpt(String moduleKey, int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
914 ModuleSADocument.ModuleSA msa = getModuleSA(moduleKey);
915 if (msa.getModuleSaBuildOptions() == null || msa.getModuleSaBuildOptions().getOptions() == null) {
916 return ;
917 }
918 OptionsDocument.Options opts = msa.getModuleSaBuildOptions().getOptions();
919 XmlCursor cursor = opts.newCursor();
920 if (cursor.toFirstChild()) {
921 for (int j = 0; j < i; ++j){
922 cursor.toNextSibling();
923 }
924 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
925 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
926 }
927 cursor.dispose();
928 }
929
930 /**add pcd information of module mi to a ModuleSA.
931 * @param mi
932 * @param moduleSa if null, generate a new ModuleSA.
933 */
934 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, String arch, ModuleSADocument.ModuleSA moduleSa) throws Exception {
935 //ToDo add Arch filter
936
937 try {
938 if (moduleSa == null) {
939 moduleSa = genModuleSA(mi, arch);
940 }
941
942 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(mi);
943 if (msa.getPcdCoded() == null) {
944 return;
945 }
946
947 Map<String, XmlObject> m = new HashMap<String, XmlObject>();
948 m.put("ModuleSurfaceArea", msa);
949 SurfaceAreaQuery.setDoc(m);
950 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null, mi);
951 //
952 // Implementing InitializePlatformPcdBuildDefinitions
953 //
954 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();
955 ListIterator li = l.listIterator();
956 while(li.hasNext()) {
957 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();
958 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);
959 if (spdPcd == null) {
960 //
961 // ToDo Error
962 //
963 throw new PcdDeclNotFound("No Declaration for PCD Entry " + msaPcd.getCName() + " in Module " + mi.getName());
964 }
965 //
966 // AddItem to ModuleSA PcdBuildDefinitions
967 //
968 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();
969
970 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);
971 }
972
973 }
974 catch (Exception e){
975
976 throw e;
977 }
978
979 }
980
981 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {
982
983 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;
984 for (int i = 0; i < depPkgs.length; ++i) {
985
986 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations(depPkgs[i]);
987 if (xo == null) {
988 continue;
989 }
990 for (int j = 0; j < xo.length; ++j) {
991 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];
992 if (msaPcd.getTokenSpaceGuidCName() == null) {
993 if (spdPcd.getCName().equals(msaPcd.getCName())) {
994 return spdPcd;
995 }
996 }
997 else{
998 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {
999 return spdPcd;
1000 }
1001 }
1002
1003 }
1004
1005 }
1006 return null;
1007 }
1008
1009 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi, String arch) {
1010 PackageIdentification pi = WorkspaceProfile.getPackageForModule(mi);
1011 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();
1012 XmlCursor cursor = msa.newCursor();
1013 try{
1014 String comment = "Mod: " + mi.getName() + " Type: " + SurfaceAreaQuery.getModuleType(mi) + " Path: "
1015 + mi.getPath().substring(System.getenv("WORKSPACE").length() + 1);
1016 cursor.insertComment(comment);
1017 }
1018 catch(Exception e){
1019 e.printStackTrace();
1020 }
1021 finally {
1022 cursor.dispose();
1023 }
1024 msa.setModuleGuid(mi.getGuid());
1025 msa.setModuleVersion(mi.getVersion());
1026 msa.setPackageGuid(pi.getGuid());
1027 msa.setPackageVersion(pi.getVersion());
1028 if (arch != null) {
1029 Vector<String> v = new Vector<String>();
1030 v.add(arch);
1031 msa.setSupArchList(v);
1032 }
1033
1034 return msa;
1035 }
1036
1037 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa)
1038 throws PcdItemTypeConflictException, PcdValueMalFormed{
1039 if (moduleSa.getPcdBuildDefinition() == null){
1040 moduleSa.addNewPcdBuildDefinition();
1041 }
1042 //
1043 // constructe pcd to modulesa mapping first.
1044 // Attention : for any error condition, remove from map this pcd.
1045 //
1046 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);
1047 if (pcdConsumer == null) {
1048 pcdConsumer = new ArrayList<String>();
1049 }
1050 //
1051 // Using existing Pcd type, if this pcd already exists in other ModuleSA
1052 //
1053 if (pcdConsumer.size() > 0) {
1054 String[] valPart = pcdConsumer.get(0).split(" ");
1055 itemType = valPart[5];
1056 }
1057 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion()
1058 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList())
1059 + " " + itemType;
1060 pcdConsumer.add(listValue);
1061 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);
1062
1063 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();
1064 fpdPcd.setCName(cName);
1065 fpdPcd.setToken(token);
1066 fpdPcd.setTokenSpaceGuidCName(tsGuid);
1067 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));
1068 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));
1069
1070 if (defaultVal != null){
1071 fpdPcd.setValue(defaultVal);
1072 }
1073 else {
1074 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
1075 fpdPcd.setValue("0");
1076 }
1077 if (dataType.equals("BOOLEAN")){
1078 fpdPcd.setValue("false");
1079 }
1080 if (dataType.equals("VOID*")) {
1081 fpdPcd.setValue("");
1082 }
1083 }
1084 //
1085 // Using existing pcd value, if this pcd already exists in other moduleSa.
1086 //
1087 if (defaultPcdValue.get(cName + " " + tsGuid) == null) {
1088 defaultPcdValue.put(cName + " " + tsGuid, fpdPcd.getValue());
1089 }
1090 else {
1091 fpdPcd.setValue(defaultPcdValue.get(cName + " " + tsGuid));
1092 }
1093
1094 if (dataType.equals("UINT8")){
1095 fpdPcd.setMaxDatumSize(1);
1096 }
1097 if (dataType.equals("UINT16")) {
1098 fpdPcd.setMaxDatumSize(2);
1099 }
1100 if (dataType.equals("UINT32")) {
1101 fpdPcd.setMaxDatumSize(4);
1102 }
1103 if (dataType.equals("UINT64")){
1104 fpdPcd.setMaxDatumSize(8);
1105 }
1106 if (dataType.equals("BOOLEAN")){
1107 fpdPcd.setMaxDatumSize(1);
1108 }
1109 if (dataType.equals("VOID*")) {
1110 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());
1111 fpdPcd.setMaxDatumSize(maxSize);
1112 }
1113
1114
1115 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {
1116 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);
1117 //
1118 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.
1119 // so need to add one dyn pcd.
1120 //
1121 if (al.size() == 1) {
1122 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);
1123 }
1124 }
1125
1126 }
1127
1128 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{
1129 if (datum == null) {
1130 return 0;
1131 }
1132 char ch = datum.charAt(0);
1133 int start, end;
1134 String strValue;
1135 //
1136 // For void* type PCD, only three datum is support:
1137 // 1) Unicode: string with start char is "L"
1138 // 2) Ansci: String is ""
1139 // 3) byte array: String start char "{"
1140 //
1141 if (ch == 'L') {
1142 start = datum.indexOf('\"');
1143 end = datum.lastIndexOf('\"');
1144 if ((start > end) ||
1145 (end > datum.length())||
1146 ((start == end) && (datum.length() > 0))) {
1147 //ToDo Error handling here
1148 throw new PcdValueMalFormed (datum);
1149 }
1150
1151 strValue = datum.substring(start + 1, end);
1152 return strValue.length() * 2;
1153 } else if (ch == '\"'){
1154 start = datum.indexOf('\"');
1155 end = datum.lastIndexOf('\"');
1156 if ((start > end) ||
1157 (end > datum.length())||
1158 ((start == end) && (datum.length() > 0))) {
1159 throw new PcdValueMalFormed (datum);
1160 }
1161 strValue = datum.substring(start + 1, end);
1162 return strValue.length();
1163 } else if (ch =='{') {
1164 String[] strValueArray;
1165
1166 start = datum.indexOf('{');
1167 end = datum.lastIndexOf('}');
1168 strValue = datum.substring(start + 1, end);
1169 strValue = strValue.trim();
1170 if (strValue.length() == 0) {
1171 return 0;
1172 }
1173 strValueArray = strValue.split(",");
1174 for (int index = 0; index < strValueArray.length; index ++) {
1175 Integer value = Integer.decode(strValueArray[index].trim());
1176
1177 if (value > 0xFF) {
1178 // "[FPD file error] The datum type of PCD %s in %s is VOID*, "+
1179 // "it must be a byte array. But the element of %s exceed the byte range",
1180 throw new PcdValueMalFormed (datum);
1181 }
1182 }
1183 return strValueArray.length;
1184
1185
1186 } else {
1187 // "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
1188 // "1) UNICODE string: like L\"xxxx\";\r\n"+
1189 // "2) ANSIC string: like \"xxx\";\r\n"+
1190 // "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
1191 // "but the datum in seems does not following above format!",
1192 throw new PcdValueMalFormed (datum);
1193
1194 }
1195 }
1196
1197 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {
1198 ArrayList<String> al = dynPcdMap.get(dynPcdKey);
1199
1200 return al;
1201 }
1202
1203 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {
1204
1205 return dynPcdMap.get(pcdKey);
1206 }
1207
1208 public int getDynamicPcdBuildDataCount() {
1209 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1210 removeElement(getfpdDynPcdBuildDefs());
1211 fpdDynPcdBuildDefs = null;
1212 return 0;
1213 }
1214 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();
1215 }
1216
1217 public void getDynamicPcdBuildData(String[][] saa) {
1218 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1219 removeElement(getfpdDynPcdBuildDefs());
1220 fpdDynPcdBuildDefs = null;
1221 return ;
1222 }
1223 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();
1224 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();
1225 int i = 0;
1226 while(li.hasNext()) {
1227 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();
1228 saa[i][0] = dynPcd.getCName();
1229 saa[i][1] = dynPcd.getToken().toString();
1230 saa[i][2] = dynPcd.getTokenSpaceGuidCName();
1231 saa[i][3] = dynPcd.getMaxDatumSize()+"";
1232 saa[i][4] = dynPcd.getDatumType().toString();
1233
1234 ++i;
1235 }
1236 }
1237
1238 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal)
1239 throws PcdValueMalFormed{
1240 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();
1241 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));
1242 dynPcdData.setCName(cName);
1243 dynPcdData.setToken(token);
1244 dynPcdData.setTokenSpaceGuidCName(tsGuid);
1245 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));
1246
1247 BigInteger bigInt = new BigInteger("0");
1248 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();
1249 skuInfo.setSkuId(bigInt);
1250 if (defaultVal != null){
1251 skuInfo.setValue(defaultVal);
1252 }
1253 else {
1254 if (dataType.equals("UINT8")){
1255 skuInfo.setValue("0");
1256 }
1257 if (dataType.equals("UINT16")) {
1258 skuInfo.setValue("0");
1259 }
1260 if (dataType.equals("UINT32")) {
1261 skuInfo.setValue("0");
1262 }
1263 if (dataType.equals("UINT64")){
1264 skuInfo.setValue("0");
1265 }
1266 if (dataType.equals("BOOLEAN")){
1267 skuInfo.setValue("false");
1268 }
1269 if (dataType.equals("VOID*")) {
1270 skuInfo.setValue("");
1271 }
1272 }
1273 if (dataType.equals("UINT8")){
1274 dynPcdData.setMaxDatumSize(1);
1275 }
1276 if (dataType.equals("UINT16")) {
1277 dynPcdData.setMaxDatumSize(2);
1278 }
1279 if (dataType.equals("UINT32")) {
1280 dynPcdData.setMaxDatumSize(4);
1281 }
1282 if (dataType.equals("UINT64")){
1283 dynPcdData.setMaxDatumSize(8);
1284 }
1285 if (dataType.equals("BOOLEAN")){
1286 dynPcdData.setMaxDatumSize(1);
1287 }
1288 if (dataType.equals("VOID*")) {
1289 int maxSize = setMaxSizeForPointer(defaultVal);
1290 dynPcdData.setMaxDatumSize(maxSize);
1291 }
1292 }
1293
1294 public void removeDynamicPcdBuildData(String cName, String tsGuid) {
1295 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();
1296 if (o == null) {
1297 return;
1298 }
1299
1300 XmlCursor cursor = o.newCursor();
1301 if (cursor.toFirstChild()) {
1302 do {
1303 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData =
1304 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1305 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {
1306
1307 if (getDynamicPcdBuildDataCount() == 1) {
1308 cursor.toParent();
1309 }
1310 cursor.removeXml();
1311 cursor.dispose();
1312 return;
1313 }
1314 }
1315 while (cursor.toNextSibling());
1316 }
1317 cursor.dispose();
1318 }
1319 //
1320 // Get the Sku Info count of ith dyn pcd element.
1321 //
1322 public int getDynamicPcdSkuInfoCount(int i){
1323 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null
1324 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {
1325 return 0;
1326 }
1327
1328 int skuInfoCount = 0;
1329 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1330 if (cursor.toFirstChild()) {
1331 for (int j = 0; j < i; ++j) {
1332 cursor.toNextSibling();
1333 }
1334 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1335 if (pcdData.getSkuInfoList() == null) {
1336 skuInfoCount = 0;
1337 }
1338 else {
1339 skuInfoCount = pcdData.getSkuInfoList().size();
1340 }
1341 }
1342 cursor.dispose();
1343 return skuInfoCount;
1344 }
1345
1346 public void getDynamicPcdSkuInfos(int i, String[][] saa){
1347 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1348 removeElement(getfpdDynPcdBuildDefs());
1349 fpdDynPcdBuildDefs = null;
1350 return;
1351 }
1352
1353 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1354 if (cursor.toFirstChild()) {
1355 for (int j = 0; j < i; ++j) {
1356 cursor.toNextSibling();
1357 }
1358 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1359 if (pcdData.getSkuInfoList() == null) {
1360 cursor.dispose();
1361 return;
1362 }
1363 else {
1364 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1365 int k = 0;
1366 while (li.hasNext()) {
1367 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1368 saa[k][0] = skuInfo.getSkuId()+"";
1369 saa[k][1] = skuInfo.getVariableName();
1370 saa[k][2] = skuInfo.getVariableGuid();
1371 saa[k][3] = skuInfo.getVariableOffset();
1372 saa[k][4] = skuInfo.getHiiDefaultValue();
1373 saa[k][5] = skuInfo.getVpdOffset();
1374 saa[k][6] = skuInfo.getValue();
1375 ++k;
1376 }
1377
1378 }
1379 }
1380 cursor.dispose();
1381
1382 }
1383
1384 public String getDynamicPcdBuildDataValue(int i){
1385 String value = null;
1386 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1387 removeElement(getfpdDynPcdBuildDefs());
1388 fpdDynPcdBuildDefs = null;
1389 return value;
1390 }
1391
1392 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1393 if (cursor.toFirstChild()) {
1394 for (int j = 0; j < i; ++j) {
1395 cursor.toNextSibling();
1396 }
1397 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1398 if (pcdData.getSkuInfoList() == null) {
1399 value = null;
1400 }
1401 else {
1402 value = pcdData.getSkuInfoArray(0).getValue();
1403 }
1404 }
1405 cursor.dispose();
1406 return value;
1407 }
1408
1409 public String getDynamicPcdBuildDataVpdOffset(int i){
1410 String vpdOffset = null;
1411 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1412 removeElement(getfpdDynPcdBuildDefs());
1413 fpdDynPcdBuildDefs = null;
1414 return vpdOffset;
1415 }
1416
1417 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1418 if (cursor.toFirstChild()) {
1419 for (int j = 0; j < i; ++j) {
1420 cursor.toNextSibling();
1421 }
1422 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1423 if (pcdData.getSkuInfoList() == null) {
1424 vpdOffset = null;
1425 }
1426 else {
1427 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();
1428 }
1429 }
1430 cursor.dispose();
1431 return vpdOffset;
1432 }
1433
1434 public void removeDynamicPcdBuildDataSkuInfo(int i) {
1435 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1436 removeElement(getfpdDynPcdBuildDefs());
1437 fpdDynPcdBuildDefs = null;
1438 return;
1439 }
1440
1441 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1442 if (cursor.toFirstChild()) {
1443 for (int j = 0; j < i; ++j) {
1444 cursor.toNextSibling();
1445 }
1446 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1447 if (pcdData.getSkuInfoList() == null) {
1448 cursor.dispose();
1449 return;
1450 }
1451 else {
1452 QName qSkuInfo = new QName(xmlNs, "SkuInfo");
1453 cursor.toChild(qSkuInfo);
1454 cursor.removeXml();
1455 }
1456 }
1457 cursor.dispose();
1458 }
1459 //
1460 // generate sku info for ith dyn pcd build data.
1461 //
1462 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1463 String hiiDefault, String vpdOffset, String value, int i) {
1464 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1465 // return;
1466 // }
1467
1468 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1469 if (cursor.toFirstChild()) {
1470 for (int j = 0; j < i; ++j) {
1471 cursor.toNextSibling();
1472 }
1473 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1474 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();
1475 skuInfo.setSkuId(new BigInteger(id));
1476 if (varName != null){
1477 skuInfo.setVariableName(varName);
1478 skuInfo.setVariableGuid(varGuid);
1479 skuInfo.setVariableOffset(varOffset);
1480 skuInfo.setHiiDefaultValue(hiiDefault);
1481 }
1482 else if (vpdOffset != null){
1483 skuInfo.setVpdOffset(vpdOffset);
1484 }
1485 else{
1486 skuInfo.setValue(value);
1487 }
1488 }
1489 }
1490
1491 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset,
1492 String hiiDefault, String vpdOffset, String value, int i){
1493 // if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {
1494 // return;
1495 // }
1496
1497 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();
1498 if (cursor.toFirstChild()) {
1499 for (int j = 0; j < i; ++j) {
1500 cursor.toNextSibling();
1501 }
1502 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();
1503 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();
1504 while (li.hasNext()) {
1505 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();
1506 if (skuInfo.getSkuId().toString().equals(id)){
1507 if (varName != null){
1508 skuInfo.setVariableName(varName);
1509 skuInfo.setVariableGuid(varGuid);
1510 skuInfo.setVariableOffset(varOffset);
1511 skuInfo.setHiiDefaultValue(hiiDefault);
1512 }
1513 else if (vpdOffset != null){
1514 skuInfo.setVpdOffset(vpdOffset);
1515 }
1516 else{
1517 skuInfo.setValue(value);
1518 }
1519 break;
1520 }
1521 }
1522 }
1523 }
1524
1525 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {
1526 if (fpdBuildOpts == null) {
1527 fpdBuildOpts = fpdRoot.addNewBuildOptions();
1528 }
1529 return fpdBuildOpts;
1530 }
1531
1532 public void genBuildOptionsUserExtensions(String fvName, String outputFileName, String[][] includeModules) {
1533 UserExtensionsDocument.UserExtensions userExts = getfpdBuildOpts().addNewUserExtensions();
1534 userExts.setUserID("IMAGES");
1535 userExts.setIdentifier(new BigInteger("1"));
1536 XmlCursor cursor = userExts.newCursor();
1537 cursor.toEndToken();
1538
1539 cursor.beginElement("FvName");
1540 cursor.insertChars(fvName);
1541 cursor.toNextToken();
1542
1543 cursor.beginElement("InfFileName");
1544 cursor.insertChars(fvName + ".inf");
1545 cursor.toNextToken();
1546
1547 cursor.beginElement("IncludeModules");
1548 for (int i = 0; i < includeModules.length; ++i) {
1549 cursor.beginElement("Module");
1550 cursor.insertAttributeWithValue("ModuleGuid", includeModules[i][0]);
1551 cursor.insertAttributeWithValue("BaseName", includeModules[i][1]);
1552 cursor.toEndToken();
1553 cursor.toNextToken();
1554 }
1555 cursor.dispose();
1556 }
1557
1558 public int getUserExtsIncModCount (String fvName) {
1559 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1560 return -1;
1561 }
1562 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1563 while (li.hasNext()) {
1564 UserExtensionsDocument.UserExtensions ues = li.next();
1565 if (!ues.getUserID().equals("IMAGES")) {
1566 continue;
1567 }
1568 XmlCursor cursor = ues.newCursor();
1569 cursor.toFirstChild();
1570 String elementName = cursor.getTextValue();
1571 if (elementName.equals(fvName)) {
1572 cursor.toNextSibling(new QName("", "IncludeModules"));
1573 if (cursor.toFirstChild()) {
1574 int i = 1;
1575 for (i = 1; cursor.toNextSibling(); ++i);
1576 cursor.dispose();
1577 return i;
1578 }
1579 cursor.dispose();
1580 return 0;
1581 }
1582 cursor.dispose();
1583 }
1584 return -1;
1585 }
1586
1587 public void getUserExtsIncMods(String fvName, String[][] saa) {
1588 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1589 return;
1590 }
1591 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1592 while (li.hasNext()) {
1593 UserExtensionsDocument.UserExtensions ues = li.next();
1594 if (!ues.getUserID().equals("IMAGES")) {
1595 continue;
1596 }
1597 XmlCursor cursor = ues.newCursor();
1598 cursor.toFirstChild();
1599 String elementName = cursor.getTextValue();
1600 if (elementName.equals(fvName)) {
1601 cursor.toNextSibling(new QName("", "IncludeModules"));
1602 if (cursor.toFirstChild()) {
1603 int i = 0;
1604 do {
1605 saa[i][0] = cursor.getAttributeText(new QName("ModuleGuid"));
1606 saa[i][1] = cursor.getAttributeText(new QName("BaseName"));
1607 ++i;
1608 }while (cursor.toNextSibling());
1609 }
1610 cursor.dispose();
1611 return;
1612 }
1613 cursor.dispose();
1614 }
1615
1616 }
1617
1618 public void removeBuildOptionsUserExtensions (String fvName) {
1619 if (getfpdBuildOpts().getUserExtensionsList() == null) {
1620 return;
1621 }
1622
1623 ListIterator<UserExtensionsDocument.UserExtensions> li = getfpdBuildOpts().getUserExtensionsList().listIterator();
1624 while (li.hasNext()) {
1625 UserExtensionsDocument.UserExtensions ues = li.next();
1626 if (!ues.getUserID().equals("IMAGES")) {
1627 continue;
1628 }
1629 XmlCursor cursor = ues.newCursor();
1630 cursor.toFirstChild();
1631 String elementName = cursor.getTextValue();
1632 if (elementName.equals(fvName)) {
1633 cursor.toParent();
1634 cursor.removeXml();
1635 cursor.dispose();
1636 return;
1637 }
1638 cursor.dispose();
1639 }
1640
1641 }
1642
1643
1644 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {
1645 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1646 if (udats == null) {
1647 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();
1648 }
1649
1650 AntTaskDocument.AntTask at = udats.addNewAntTask();
1651 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1652 }
1653
1654 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {
1655 at.setId(new Integer(id));
1656 XmlCursor cursor = at.newCursor();
1657 if (fileName != null){
1658 at.setFilename(fileName);
1659 }
1660 else if (cursor.toChild(xmlNs, "Filename")) {
1661 cursor.removeXml();
1662 }
1663 if (execOrder != null) {
1664 at.setAntCmdOptions(execOrder);
1665 }
1666 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {
1667 cursor.removeXml();
1668 }
1669 cursor.dispose();
1670 }
1671
1672 public void removeBuildOptionsUserDefAntTask(int i) {
1673 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1674 if (o == null) {
1675 return;
1676 }
1677 XmlCursor cursor = o.newCursor();
1678 if (cursor.toFirstChild()) {
1679 for (int j = 0; j < i; ++j) {
1680 cursor.toNextSibling();
1681 }
1682 cursor.removeXml();
1683 if (getBuildOptionsUserDefAntTaskCount() == 0) {
1684 cursor.toParent();
1685 cursor.removeXml();
1686 }
1687 }
1688 cursor.dispose();
1689 }
1690
1691 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){
1692 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();
1693 if (o == null) {
1694 return;
1695 }
1696 XmlCursor cursor = o.newCursor();
1697 if (cursor.toFirstChild()) {
1698 for (int j = 0; j < i; ++j) {
1699 cursor.toNextSibling();
1700 }
1701 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();
1702 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);
1703 }
1704 cursor.dispose();
1705 }
1706
1707 public int getBuildOptionsUserDefAntTaskCount() {
1708 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1709 if (udats == null || udats.getAntTaskList() == null) {
1710 return 0;
1711 }
1712
1713 return udats.getAntTaskList().size();
1714 }
1715
1716 public void getBuildOptionsUserDefAntTasks(String[][] saa) {
1717 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();
1718 if (udats == null || udats.getAntTaskList() == null) {
1719 return ;
1720 }
1721
1722 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();
1723 ListIterator li = l.listIterator();
1724 int i = 0;
1725 while (li.hasNext()) {
1726 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();
1727 saa[i][0] = at.getId() + "";
1728 saa[i][1] = saa[i][2] = "";
1729 if (at.getFilename() != null){
1730 saa[i][1] = at.getFilename();
1731 }
1732 if (at.getAntCmdOptions() != null) {
1733 saa[i][2] = at.getAntCmdOptions();
1734 }
1735 ++i;
1736 }
1737 }
1738 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1739 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();
1740 if (opts == null) {
1741 opts = getfpdBuildOpts().addNewOptions();
1742 }
1743 OptionDocument.Option opt = opts.addNewOption();
1744 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1745 }
1746
1747 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){
1748 opt.setStringValue(contents);
1749
1750 opt.setBuildTargets(buildTargets);
1751 opt.setToolChainFamily(toolChain);
1752 opt.setTagName(tagName);
1753 opt.setToolCode(toolCmd);
1754
1755 if (archList != null) {
1756 opt.setSupArchList(archList);
1757 }
1758 else {
1759 if (opt.isSetSupArchList()) {
1760 opt.unsetSupArchList();
1761 }
1762 }
1763 }
1764
1765 public void removeBuildOptionsOpt(int i){
1766
1767 XmlObject o = getfpdBuildOpts().getOptions();
1768 if (o == null) {
1769 return;
1770 }
1771
1772 XmlCursor cursor = o.newCursor();
1773 if (cursor.toFirstChild()) {
1774 for (int j = 0; j < i; ++j) {
1775 cursor.toNextSibling();
1776 }
1777 cursor.removeXml();
1778 if (getBuildOptionsOptCount() == 0) {
1779 cursor.toParent();
1780 cursor.removeXml();
1781 }
1782 }
1783 cursor.dispose();
1784 }
1785
1786 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {
1787 XmlObject o = getfpdBuildOpts().getOptions();
1788 if (o == null) {
1789 return;
1790 }
1791
1792 XmlCursor cursor = o.newCursor();
1793 if (cursor.toFirstChild()) {
1794 for (int j = 0; j < i; ++j) {
1795 cursor.toNextSibling();
1796 }
1797 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();
1798 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);
1799 }
1800 cursor.dispose();
1801 }
1802
1803 public int getBuildOptionsOptCount(){
1804 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1805 return 0;
1806 }
1807 return getfpdBuildOpts().getOptions().getOptionList().size();
1808 }
1809
1810 public void getBuildOptionsOpts(String[][] saa) {
1811 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {
1812 return ;
1813 }
1814
1815 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();
1816 ListIterator li = lOpt.listIterator();
1817 int i = 0;
1818 while(li.hasNext()) {
1819 OptionDocument.Option opt = (OptionDocument.Option)li.next();
1820 if (opt.getBuildTargets() != null) {
1821 saa[i][0] = listToString(opt.getBuildTargets());
1822 }
1823 saa[i][1] = opt.getToolChainFamily();
1824 if (opt.getSupArchList() != null){
1825 saa[i][2] = listToString(opt.getSupArchList());
1826
1827 }
1828 saa[i][3] = opt.getToolCode();
1829 saa[i][4] = opt.getTagName();
1830 saa[i][5] = opt.getStringValue();
1831
1832 ++i;
1833 }
1834 }
1835
1836 public void genBuildOptionsFfs(String ffsKey, String type) {
1837 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1838 ffs.setFfsKey(ffsKey);
1839 if (type != null) {
1840 ffs.addNewSections().setEncapsulationType(type);
1841 }
1842 }
1843
1844 public void updateBuildOptionsFfsSectionsType(int i, String type) {
1845 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();
1846 if (type != null) {
1847 ffs.addNewSections().setEncapsulationType(type);
1848 }
1849 }
1850
1851 public void genBuildOptionsFfsAttribute(int i, String name, String value) {
1852 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1853 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();
1854 attrib.setName(name);
1855 attrib.setValue(value);
1856 }
1857
1858 /**update jth attribute of ith ffs.
1859 * @param i
1860 * @param j
1861 */
1862 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){
1863 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1864 XmlCursor cursor = ffs.newCursor();
1865 QName qAttrib = new QName(xmlNs, "Attribute");
1866 if (cursor.toChild(qAttrib)) {
1867 for (int k = 0; k < j; ++k) {
1868 cursor.toNextSibling(qAttrib);
1869 }
1870 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();
1871 attrib.setName(name);
1872 attrib.setValue(value);
1873 }
1874 cursor.dispose();
1875 }
1876
1877 public void removeBuildOptionsFfsAttribute(int i, int j){
1878 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1879 XmlCursor cursor = ffs.newCursor();
1880 QName qAttrib = new QName(xmlNs, "Attribute");
1881 if (cursor.toChild(qAttrib)) {
1882 for (int k = 0; k < j; ++k) {
1883 cursor.toNextSibling(qAttrib);
1884 }
1885 cursor.removeXml();
1886 }
1887 cursor.dispose();
1888 }
1889
1890 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {
1891 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1892 if (ffs == null) {
1893 return;
1894 }
1895 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1896
1897 if (sections == null){
1898 sections = ffs.addNewSections();
1899 }
1900 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));
1901 }
1902
1903 public void removeBuildOptionsFfsSectionsSection(int i, int j) {
1904 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1905 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1906 if (sections == null) {
1907 return;
1908 }
1909 XmlCursor cursor = sections.newCursor();
1910 QName qSection = new QName(xmlNs, "Section");
1911 if (cursor.toChild(qSection)) {
1912 for (int k = 0; k < j; ++k) {
1913 cursor.toNextSibling(qSection);
1914 }
1915 cursor.removeXml();
1916 }
1917 cursor.dispose();
1918 }
1919
1920 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){
1921 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1922 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1923 if (sections == null) {
1924 return;
1925 }
1926 XmlCursor cursor = sections.newCursor();
1927 QName qSection = new QName(xmlNs, "Section");
1928 if (cursor.toChild(qSection)) {
1929 for (int k = 0; k < j; ++k) {
1930 cursor.toNextSibling(qSection);
1931 }
1932 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();
1933 section.setSectionType(EfiSectionType.Enum.forString(type));
1934 }
1935 cursor.dispose();
1936 }
1937
1938 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {
1939 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1940 if (ffs == null) {
1941 return;
1942 }
1943 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1944
1945 if (sections == null){
1946 sections = ffs.addNewSections();
1947 }
1948 sections.addNewSections().setEncapsulationType(encapType);
1949 }
1950
1951 public void removeBuildOptionsFfsSectionsSections(int i, int j) {
1952 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1953 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1954 if (sections == null) {
1955 return;
1956 }
1957 XmlCursor cursor = sections.newCursor();
1958 QName qSections = new QName(xmlNs, "Sections");
1959 if (cursor.toChild(qSections)) {
1960 for (int k = 0; k < j; ++k) {
1961 cursor.toNextSibling(qSections);
1962 }
1963 cursor.removeXml();
1964 }
1965 cursor.dispose();
1966 }
1967
1968 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {
1969 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1970 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1971 if (sections == null) {
1972 return;
1973 }
1974 XmlCursor cursor = sections.newCursor();
1975 QName qSections = new QName(xmlNs, "Sections");
1976 if (cursor.toChild(qSections)) {
1977 for (int k = 0; k < j; ++k) {
1978 cursor.toNextSibling(qSections);
1979 }
1980 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1981 sections2.setEncapsulationType(type);
1982 }
1983 cursor.dispose();
1984 }
1985
1986 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {
1987 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
1988 if (ffs == null) {
1989 return;
1990 }
1991 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
1992 XmlCursor cursor = sections.newCursor();
1993 QName qSections = new QName(xmlNs, "Sections");
1994 if (cursor.toChild(qSections)){
1995 for (int k = 0; k < j; ++k) {
1996 cursor.toNextSibling(qSections);
1997 }
1998 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
1999 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));
2000 }
2001 cursor.dispose();
2002 }
2003
2004 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {
2005 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2006 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2007 if (sections == null) {
2008 return;
2009 }
2010 XmlCursor cursor = sections.newCursor();
2011 QName qSections = new QName(xmlNs, "Sections");
2012 if (cursor.toChild(qSections)) {
2013 for (int l = 0; l < j; ++l) {
2014 cursor.toNextSibling(qSections);
2015 }
2016 if (cursor.toFirstChild()) {
2017 int m = 0;
2018 for (; m < k; ++m) {
2019 cursor.toNextSibling();
2020 }
2021 cursor.removeXml();
2022 if (m == 0) {
2023 cursor.toParent();
2024 cursor.removeXml();
2025 }
2026 }
2027 }
2028 cursor.dispose();
2029 }
2030
2031 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {
2032 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2033 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2034 if (sections == null) {
2035 return;
2036 }
2037 XmlCursor cursor = sections.newCursor();
2038 QName qSections = new QName(xmlNs, "Sections");
2039 if (cursor.toChild(qSections)) {
2040 for (int l = 0; l < j; ++l) {
2041 cursor.toNextSibling(qSections);
2042 }
2043 if (cursor.toFirstChild()) {
2044 for (int m = 0; m < k; ++m) {
2045 cursor.toNextSibling();
2046 }
2047 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();
2048 section.setSectionType(EfiSectionType.Enum.forString(type));
2049 }
2050 }
2051 cursor.dispose();
2052 }
2053
2054 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {
2055 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2056 if (ffs == null) {
2057 return;
2058 }
2059 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();
2060 XmlCursor cursor = sections.newCursor();
2061 QName qSections = new QName(xmlNs, "Sections");
2062 if (cursor.toChild(qSections)){
2063 for (int k = 0; k < j; ++k) {
2064 cursor.toNextSibling(qSections);
2065 }
2066 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();
2067 if (sections2.getSectionList() == null){
2068 cursor.dispose();
2069 return;
2070 }
2071 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();
2072 while(li.hasNext()) {
2073 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();
2074 if (section.isSetSectionType()) {
2075 al.add(section.getSectionType().toString());
2076 }
2077
2078 }
2079 }
2080 cursor.dispose();
2081
2082 }
2083
2084 public int getBuildOptionsFfsCount(){
2085 if (getfpdBuildOpts().getFfsList() == null) {
2086 return 0;
2087 }
2088 return getfpdBuildOpts().getFfsList().size();
2089 }
2090
2091 public void getBuildOptionsFfsKey(String[][] saa) {
2092 if (getfpdBuildOpts().getFfsList() == null) {
2093 return;
2094 }
2095 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();
2096 int i = 0;
2097 while(li.hasNext()){
2098 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();
2099 saa[i][0] = ffs.getFfsKey();
2100 ++i;
2101 }
2102 }
2103
2104 public void updateBuildOptionsFfsKey(int i, String key) {
2105 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2106 ffs.setFfsKey(key);
2107 }
2108
2109 /**Get ith FFS key and contents.
2110 * @param saa
2111 */
2112 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {
2113 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2114
2115 if (ffs != null) {
2116
2117 sa[0] = ffs.getFfsKey();
2118 if (ffs.getSections() != null) {
2119 if(ffs.getSections().getEncapsulationType() != null){
2120 sa[1] = ffs.getSections().getEncapsulationType();
2121 }
2122 if (ffs.getSections().getSectionList() != null){
2123 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();
2124 while (li.hasNext()) {
2125 firstLevelSection.add(li.next().getSectionType().toString());
2126 }
2127 }
2128 if (ffs.getSections().getSectionsList() != null) {
2129 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();
2130 while(li.hasNext()) {
2131 firstLevelSections.add(li.next().getEncapsulationType());
2132 }
2133 }
2134 }
2135 if (ffs.getAttributeList() != null) {
2136 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();
2137 while(li.hasNext()) {
2138 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();
2139 ffsAttribMap.put(attrib.getName(), attrib.getValue());
2140 }
2141
2142 }
2143 }
2144
2145
2146 }
2147
2148 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {
2149 XmlObject o = getfpdBuildOpts();
2150 BuildOptionsDocument.BuildOptions.Ffs ffs = null;
2151
2152 XmlCursor cursor = o.newCursor();
2153 QName qFfs = new QName(xmlNs, "Ffs");
2154 if (cursor.toChild(qFfs)) {
2155 for (int j = 0; j < i; ++j) {
2156 cursor.toNextSibling(qFfs);
2157 }
2158 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();
2159 }
2160 cursor.dispose();
2161 return ffs;
2162 }
2163
2164 public void removeBuildOptionsFfs(int i) {
2165 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);
2166 if (ffs == null){
2167 return;
2168 }
2169
2170 XmlCursor cursor = ffs.newCursor();
2171 cursor.removeXml();
2172 cursor.dispose();
2173 }
2174
2175
2176
2177 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){
2178 if (fpdPlatformDefs == null){
2179 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();
2180 }
2181 return fpdPlatformDefs;
2182 }
2183
2184 public void getPlatformDefsSupportedArchs(Vector<Object> archs){
2185 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {
2186 return;
2187 }
2188 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();
2189 while(li.hasNext()) {
2190 archs.add(li.next());
2191 }
2192 }
2193
2194 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {
2195 if (archs != null) {
2196 getfpdPlatformDefs().setSupportedArchitectures(archs);
2197 }
2198 // else {
2199 // XmlCursor cursor = getfpdPlatformDefs().newCursor();
2200 // if (cursor.toChild(xmlNs, "SupportedArchitectures")) {
2201 // cursor.removeXml();
2202 // }
2203 // cursor.dispose();
2204 // }
2205 }
2206
2207 public void getPlatformDefsBuildTargets(Vector<Object> targets) {
2208 if (getfpdPlatformDefs().getBuildTargets() == null) {
2209 return;
2210 }
2211 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();
2212 while(li.hasNext()) {
2213 targets.add(li.next());
2214 }
2215 }
2216
2217 public void setPlatformDefsBuildTargets(Vector<Object> targets) {
2218 getfpdPlatformDefs().setBuildTargets(targets);
2219 }
2220
2221 public void genPlatformDefsSkuInfo(String id, String name) {
2222 SkuInfoDocument.SkuInfo skuInfo = null;
2223 if (getfpdPlatformDefs().getSkuInfo() == null) {
2224 skuInfo = getfpdPlatformDefs().addNewSkuInfo();
2225 }
2226 skuInfo = getfpdPlatformDefs().getSkuInfo();
2227 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {
2228 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2229 skuName.setSkuID(new BigInteger("0"));
2230 skuName.setStringValue("DEFAULT");
2231 }
2232 if (id.equals("0")) {
2233 return;
2234 }
2235 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();
2236 skuName.setSkuID(new BigInteger(id));
2237 skuName.setStringValue(name);
2238 }
2239
2240 public int getPlatformDefsSkuInfoCount(){
2241 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2242 return 0;
2243 }
2244 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();
2245 }
2246
2247 public void getPlatformDefsSkuInfos(String[][] saa){
2248 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {
2249 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {
2250 removeElement(getfpdDynPcdBuildDefs());
2251 fpdDynPcdBuildDefs = null;
2252 }
2253 return ;
2254 }
2255
2256 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();
2257 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();
2258 int i = 0;
2259 while(li.hasNext()) {
2260 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();
2261 saa[i][0] = sku.getSkuID()+"";
2262 saa[i][1] = sku.getStringValue();
2263 ++i;
2264 }
2265 }
2266
2267 public void removePlatformDefsSkuInfo(int i) {
2268 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2269 if (skuInfo == null || i == 0) {
2270 return ;
2271 }
2272
2273 XmlCursor cursor = skuInfo.newCursor();
2274 if (cursor.toFirstChild()) {
2275 for (int j = 0; j < i; ++j) {
2276 cursor.toNextSibling();
2277 }
2278 cursor.removeXml();
2279 }
2280 cursor.dispose();
2281 }
2282
2283 public void updatePlatformDefsSkuInfo(int i, String id, String name) {
2284 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();
2285 if (skuInfo == null || i == 0) {
2286 return ;
2287 }
2288
2289 XmlCursor cursor = skuInfo.newCursor();
2290 if (cursor.toFirstChild()) {
2291 for (int j = 0; j < i; ++j) {
2292 cursor.toNextSibling();
2293 }
2294 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();
2295 sku.setSkuID(new BigInteger(id));
2296 sku.setStringValue(name);
2297 }
2298 cursor.dispose();
2299 }
2300
2301 public String getPlatformDefsInterDir(){
2302 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {
2303 return null;
2304 }
2305 return getfpdPlatformDefs().getIntermediateDirectories().toString();
2306 }
2307
2308 public void setPlatformDefsInterDir(String interDir){
2309 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));
2310 }
2311
2312 public String getPlatformDefsOutputDir() {
2313 return getfpdPlatformDefs().getOutputDirectory();
2314 }
2315
2316 public void setPlatformDefsOutputDir(String outputDir) {
2317 if (outputDir != null && outputDir.length() > 0) {
2318 getfpdPlatformDefs().setOutputDirectory(outputDir);
2319 }
2320 else{
2321 XmlCursor cursor = getfpdPlatformDefs().newCursor();
2322 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {
2323 cursor.removeXml();
2324 }
2325 cursor.dispose();
2326 }
2327 }
2328
2329 public FlashDocument.Flash getfpdFlash() {
2330 if (fpdFlash == null) {
2331 fpdFlash = fpdRoot.addNewFlash();
2332 }
2333 return fpdFlash;
2334 }
2335
2336 public void genFlashDefinitionFile(String file) {
2337 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2338 if (fdf == null) {
2339 fdf = getfpdFlash().addNewFlashDefinitionFile();
2340 }
2341
2342 fdf.setStringValue(file);
2343 }
2344
2345 public String getFlashDefinitionFile() {
2346 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();
2347 if (fdf == null) {
2348 return "";
2349 }
2350
2351 return fdf.getStringValue();
2352 }
2353
2354 public void genFvImagesNameValue(String name, String value) {
2355
2356 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2357 if (fi == null) {
2358 fi = getfpdFlash().addNewFvImages();
2359 }
2360
2361 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();
2362 nv.setName(name);
2363 nv.setValue(value);
2364 }
2365
2366 public void removeFvImagesNameValue(int i){
2367
2368 XmlObject o = getfpdFlash().getFvImages();
2369 if (o == null) {
2370 return;
2371 }
2372
2373 QName qNameValue = new QName(xmlNs, "NameValue");
2374 XmlCursor cursor = o.newCursor();
2375 if (cursor.toChild(qNameValue)) {
2376 for (int j = 0; j < i; ++j) {
2377 cursor.toNextSibling(qNameValue);
2378 }
2379 cursor.removeXml();
2380 }
2381 cursor.dispose();
2382 }
2383
2384 public void updateFvImagesNameValue(int i, String name, String value){
2385
2386 XmlObject o = getfpdFlash().getFvImages();
2387 if (o == null) {
2388 return;
2389 }
2390
2391 QName qNameValue = new QName(xmlNs, "NameValue");
2392 XmlCursor cursor = o.newCursor();
2393 if (cursor.toChild(qNameValue)) {
2394 for (int j = 0; j < i; ++j) {
2395 cursor.toNextSibling(qNameValue);
2396 }
2397 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();
2398 nv.setName(name);
2399 nv.setValue(value);
2400 }
2401 cursor.dispose();
2402 }
2403
2404 public int getFvImagesNameValueCount() {
2405
2406 FvImagesDocument.FvImages fi = null;
2407 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {
2408 return 0;
2409 }
2410 return fi.getNameValueList().size();
2411 }
2412
2413 public void getFvImagesNameValues(String[][] nv) {
2414
2415 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();
2416 if (fi == null){
2417 return;
2418 }
2419 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();
2420 int i = 0;
2421 ListIterator li = l.listIterator();
2422 while (li.hasNext()) {
2423 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li
2424 .next();
2425 nv[i][0] = e.getName();
2426 nv[i][1] = e.getValue();
2427
2428 i++;
2429 }
2430 }
2431
2432 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {
2433
2434 FvImagesDocument.FvImages fis = null;
2435 if ((fis = getfpdFlash().getFvImages()) == null) {
2436 fis = getfpdFlash().addNewFvImages();
2437 }
2438
2439 //
2440 //gen FvImage with FvImageNames array
2441 //
2442 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();
2443 for (int i = 0; i < names.length; ++i) {
2444 fi.addFvImageNames(names[i]);
2445 }
2446 fi.setType(FvImageTypes.Enum.forString(types));
2447 if (options != null){
2448 setFvImagesFvImageFvImageOptions(options, fi);
2449 }
2450 }
2451
2452 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){
2453 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();
2454 if (fio == null){
2455 fio = fi.addNewFvImageOptions();
2456 }
2457
2458 Set<String> key = options.keySet();
2459 Iterator<String> i = key.iterator();
2460 while (i.hasNext()) {
2461
2462 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();
2463 String k = (String)i.next();
2464
2465 nv.setName(k);
2466 nv.setValue((String)options.get(k));
2467
2468 }
2469
2470 }
2471
2472
2473 public void removeFvImagesFvImage(int i) {
2474
2475 XmlObject o = getfpdFlash().getFvImages();
2476 if (o == null) {
2477 return;
2478 }
2479
2480 QName qFvImage = new QName(xmlNs, "FvImage");
2481 XmlCursor cursor = o.newCursor();
2482 if (cursor.toChild(qFvImage)) {
2483 for (int j = 0; j < i; ++j) {
2484 cursor.toNextSibling(qFvImage);
2485 }
2486 cursor.removeXml();
2487 }
2488 cursor.dispose();
2489 }
2490
2491 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){
2492
2493 XmlObject o = getfpdFlash().getFvImages();
2494 if (o == null) {
2495 return;
2496 }
2497 XmlCursor cursor = o.newCursor();
2498 QName qFvImage = new QName(xmlNs, "FvImage");
2499 if (cursor.toChild(qFvImage)) {
2500 for (int j = 0; j < i; ++j) {
2501 cursor.toNextSibling(qFvImage);
2502 }
2503 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2504 fi.setType(FvImageTypes.Enum.forString(types));
2505
2506 //
2507 // remove old FvImageNames before adding new ones
2508 //
2509 QName qFvImageNames = new QName(xmlNs, "FvImageNames");
2510 cursor.toChild(qFvImageNames);
2511 cursor.removeXml();
2512 while (cursor.toNextSibling(qFvImageNames)) {
2513 cursor.removeXml();
2514 }
2515
2516 for (int k = 0; k < names.length; ++k) {
2517 fi.addFvImageNames(names[k]);
2518 }
2519 //
2520 // remove old FvImageOptions before adding new options
2521 //
2522 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");
2523 cursor.toNextSibling(qFvImageOptions);
2524 cursor.removeXml();
2525
2526 setFvImagesFvImageFvImageOptions(options, fi);
2527 }
2528 cursor.dispose();
2529 }
2530
2531 public int getFvImagesFvImageCount() {
2532
2533 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {
2534 return 0;
2535 }
2536 return getfpdFlash().getFvImages().getFvImageList().size();
2537 }
2538
2539 /**Only Get Fv image setting - name and type.
2540 * @param saa
2541 */
2542 public void getFvImagesFvImages(String[][] saa) {
2543
2544 if (getfpdFlash().getFvImages() == null) {
2545 return;
2546 }
2547 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();
2548 if (l == null) {
2549 return;
2550 }
2551 ListIterator li = l.listIterator();
2552 int i = 0;
2553 while(li.hasNext()) {
2554 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();
2555 //
2556 // get FvImageNames array, space separated
2557 //
2558 List<String> lfn = fi.getFvImageNamesList();
2559 ListIterator lfni = lfn.listIterator();
2560 saa[i][0] = " ";
2561 while (lfni.hasNext()) {
2562 saa[i][0] += (String)lfni.next();
2563 saa[i][0] += " ";
2564 }
2565 saa[i][0] = saa[i][0].trim();
2566
2567 saa[i][1] = fi.getType()+"";
2568
2569 ++i;
2570 }
2571 }
2572
2573 /**Get FvImage Options for FvImage i
2574 * @param i the ith FvImage
2575 */
2576 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {
2577 XmlObject o = getfpdFlash().getFvImages();
2578 if (o == null) {
2579 return;
2580 }
2581 XmlCursor cursor = o.newCursor();
2582 QName qFvImage = new QName(xmlNs, "FvImage");
2583 if (cursor.toChild(qFvImage)) {
2584 for (int j = 0; j < i; ++j) {
2585 cursor.toNextSibling(qFvImage);
2586 }
2587 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();
2588 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){
2589 return;
2590 }
2591 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();
2592 while(li.hasNext()){
2593 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();
2594 m.put(nv.getName(), nv.getValue());
2595 }
2596 }
2597 }
2598
2599 /**
2600 Get platform header element
2601 @return PlatformHeaderDocument.PlatformHeader
2602 **/
2603 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {
2604 if (fpdHdr == null) {
2605 fpdHdr = fpdRoot.addNewPlatformHeader();
2606 }
2607
2608 return fpdHdr;
2609 }
2610
2611 public String getFpdHdrPlatformName() {
2612 return getFpdHdr().getPlatformName();
2613 }
2614
2615 public String getFpdHdrGuidValue() {
2616 return getFpdHdr().getGuidValue();
2617 }
2618
2619 public String getFpdHdrVer() {
2620 return getFpdHdr().getVersion();
2621 }
2622
2623 public String getFpdHdrAbs() {
2624 return getFpdHdr().getAbstract();
2625 }
2626
2627 public String getFpdHdrDescription() {
2628 return getFpdHdr().getDescription();
2629 }
2630
2631 public String getFpdHdrCopyright() {
2632 return getFpdHdr().getCopyright();
2633 }
2634
2635 public String getFpdHdrLicense() {
2636 LicenseDocument.License l = getFpdHdr().getLicense();
2637 if (l == null) {
2638 return null;
2639 }
2640 return l.getStringValue();
2641 }
2642
2643 public String getFpdHdrUrl() {
2644 LicenseDocument.License l = getFpdHdr().getLicense();
2645 if (l == null) {
2646 return null;
2647 }
2648 return l.getURL();
2649 }
2650
2651 public String getFpdHdrSpec() {
2652
2653 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2654 // return getFpdHdr().getSpecification();
2655 }
2656
2657 public void setFpdHdrPlatformName(String name){
2658 getFpdHdr().setPlatformName(name);
2659 }
2660
2661 public void setFpdHdrGuidValue(String guid){
2662 getFpdHdr().setGuidValue(guid);
2663 }
2664
2665 public void setFpdHdrVer(String v){
2666 getFpdHdr().setVersion(v);
2667 }
2668
2669 public void setFpdHdrAbs(String abs) {
2670 getFpdHdr().setAbstract(abs);
2671 }
2672
2673 public void setFpdHdrDescription(String desc){
2674 getFpdHdr().setDescription(desc);
2675 }
2676
2677 public void setFpdHdrCopyright(String cr) {
2678 getFpdHdr().setCopyright(cr);
2679 }
2680
2681 public void setFpdHdrLicense(String license){
2682 LicenseDocument.License l = getFpdHdr().getLicense();
2683 if (l == null) {
2684 getFpdHdr().addNewLicense().setStringValue(license);
2685 }
2686 else {
2687 l.setStringValue(license);
2688 }
2689 }
2690
2691 public void setFpdHdrUrl(String url){
2692 LicenseDocument.License l = getFpdHdr().getLicense();
2693
2694 l.setURL(url);
2695
2696 }
2697
2698 public void setFpdHdrSpec(String s){
2699 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
2700 getFpdHdr().setSpecification(s);
2701 }
2702 /**
2703 Save the processed xml contents to file
2704
2705 @param fpdFile The file to save xml contents
2706 @throws IOException Exceptions during file operation
2707 **/
2708 public void saveAs(File fpdFile) throws IOException {
2709
2710 XmlOptions options = new XmlOptions();
2711
2712 options.setCharacterEncoding("UTF-8");
2713 options.setSavePrettyPrint();
2714 options.setSavePrettyPrintIndent(2);
2715 try {
2716 fpdd.save(fpdFile, options);
2717 } catch (IOException e) {
2718 e.printStackTrace();
2719 }
2720
2721 }
2722
2723 private String listToString(List l) {
2724 if (l == null) {
2725 return null;
2726 }
2727 String s = " ";
2728 ListIterator li = l.listIterator();
2729 while(li.hasNext()) {
2730 s += li.next();
2731 s += " ";
2732 }
2733 return s.trim();
2734 }
2735
2736 private void removeElement(XmlObject o) {
2737 XmlCursor cursor = o.newCursor();
2738 cursor.removeXml();
2739 cursor.dispose();
2740 }
2741 }
2742
2743 class PcdItemTypeConflictException extends Exception {
2744
2745 /**
2746 *
2747 */
2748 private static final long serialVersionUID = 1L;
2749 private String details = null;
2750
2751 PcdItemTypeConflictException(String pcdName, String info){
2752 ModuleIdentification mi = WorkspaceProfile.getModuleId(info);
2753 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackageId().getName();
2754 }
2755
2756 public String getMessage() {
2757 return details;
2758 }
2759 }
2760
2761 class PcdDeclNotFound extends Exception {
2762
2763 /**
2764 *
2765 */
2766 private static final long serialVersionUID = 1L;
2767 private String details = null;
2768
2769 PcdDeclNotFound(String info) {
2770 details = "PcdDeclNotFound: " + info;
2771 }
2772
2773 public String getMessage() {
2774 return details;
2775 }
2776 }
2777
2778 class PcdValueMalFormed extends Exception {
2779
2780 /**
2781 *
2782 */
2783 private static final long serialVersionUID = 1L;
2784 private String details = null;
2785
2786 PcdValueMalFormed(String info) {
2787 details = "PcdValueMalFormed: " + info;
2788 }
2789
2790 public String getMessage() {
2791 return details;
2792 }
2793 }