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