comment out item type checking temporarily when adding module to fpd 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
909 \r
910 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {\r
911 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);\r
912 //\r
913 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.\r
914 // so need to add one dyn pcd.\r
915 //\r
916 if (al.size() == 1) {\r
917 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);\r
918 }\r
919 }\r
920 else {\r
921 if (defaultVal != null){\r
922 fpdPcd.setValue(defaultVal);\r
923 }\r
924 else {\r
925 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r
926 fpdPcd.setValue("0");\r
927 }\r
928 if (dataType.equals("BOOLEAN")){\r
929 fpdPcd.setValue("false");\r
930 }\r
931 if (dataType.equals("VOID*")) {\r
932 fpdPcd.setValue("");\r
933 }\r
934 }\r
935 if (dataType.equals("UINT8")){\r
936 fpdPcd.setMaxDatumSize(1);\r
937 }\r
938 if (dataType.equals("UINT16")) {\r
939 fpdPcd.setMaxDatumSize(2);\r
940 }\r
941 if (dataType.equals("UINT32")) {\r
942 fpdPcd.setMaxDatumSize(4);\r
943 }\r
944 if (dataType.equals("UINT64")){\r
945 fpdPcd.setMaxDatumSize(8);\r
946 }\r
947 if (dataType.equals("BOOLEAN")){\r
948 fpdPcd.setMaxDatumSize(1);\r
949 }\r
950 if (dataType.equals("VOID*")) {\r
951 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r
952 fpdPcd.setMaxDatumSize(maxSize);\r
953 }\r
954 }\r
955 }\r
956 \r
908b1c05 957 public int setMaxSizeForPointer(String datum) throws PcdValueMalFormed{\r
a13899c5 958 if (datum == null) {\r
959 return 0;\r
960 }\r
961 char ch = datum.charAt(0);\r
962 int start, end;\r
963 String strValue;\r
964 //\r
965 // For void* type PCD, only three datum is support:\r
966 // 1) Unicode: string with start char is "L"\r
967 // 2) Ansci: String is ""\r
968 // 3) byte array: String start char "{"\r
969 // \r
970 if (ch == 'L') {\r
971 start = datum.indexOf('\"');\r
972 end = datum.lastIndexOf('\"');\r
973 if ((start > end) || \r
974 (end > datum.length())||\r
975 ((start == end) && (datum.length() > 0))) {\r
976 //ToDo Error handling here\r
82961247 977 throw new PcdValueMalFormed (datum);\r
a13899c5 978 }\r
979\r
980 strValue = datum.substring(start + 1, end);\r
981 return strValue.length() * 2;\r
982 } else if (ch == '\"'){\r
983 start = datum.indexOf('\"');\r
984 end = datum.lastIndexOf('\"');\r
985 if ((start > end) || \r
986 (end > datum.length())||\r
987 ((start == end) && (datum.length() > 0))) {\r
82961247 988 throw new PcdValueMalFormed (datum);\r
a13899c5 989 }\r
990 strValue = datum.substring(start + 1, end);\r
991 return strValue.length();\r
992 } else if (ch =='{') {\r
993 String[] strValueArray;\r
994\r
995 start = datum.indexOf('{');\r
996 end = datum.lastIndexOf('}');\r
997 strValue = datum.substring(start + 1, end);\r
998 strValue = strValue.trim();\r
999 if (strValue.length() == 0) {\r
1000 return 0;\r
1001 }\r
1002 strValueArray = strValue.split(",");\r
1003 for (int index = 0; index < strValueArray.length; index ++) {\r
1004 Integer value = Integer.decode(strValueArray[index].trim());\r
1005 \r
1006 if (value > 0xFF) {\r
1007// "[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
1008// "it is byte array in fact. But the element of %s exceed the byte range",\r
82961247 1009 throw new PcdValueMalFormed (datum); \r
a13899c5 1010 }\r
1011 }\r
1012 return strValueArray.length;\r
1013\r
1014\r
1015 } else {\r
1016// "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
1017// "1) UNICODE string: like L\"xxxx\";\r\n"+\r
1018// "2) ANSIC string: like \"xxx\";\r\n"+\r
1019// "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
1020// "but the datum in seems does not following above format!",\r
82961247 1021 throw new PcdValueMalFormed (datum);\r
a13899c5 1022 \r
1023 }\r
1024 }\r
1025 \r
1026 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {\r
1027 ArrayList<String> al = dynPcdMap.get(dynPcdKey);\r
1028 \r
1029 return al;\r
1030 }\r
1031 \r
1032 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {\r
1033 \r
34c614e1 1034 return dynPcdMap.get(pcdKey);\r
a13899c5 1035 }\r
1036 \r
1037 public int getDynamicPcdBuildDataCount() {\r
5af6b67f 1038 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1039 removeElement(getfpdDynPcdBuildDefs());\r
1040 fpdDynPcdBuildDefs = null;\r
a13899c5 1041 return 0;\r
1042 }\r
1043 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();\r
1044 }\r
1045 \r
1046 public void getDynamicPcdBuildData(String[][] saa) {\r
5af6b67f 1047 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1048 removeElement(getfpdDynPcdBuildDefs());\r
1049 fpdDynPcdBuildDefs = null;\r
a13899c5 1050 return ;\r
1051 }\r
1052 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();\r
1053 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();\r
1054 int i = 0;\r
1055 while(li.hasNext()) {\r
1056 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();\r
1057 saa[i][0] = dynPcd.getCName();\r
1058 saa[i][1] = dynPcd.getToken().toString();\r
1059 saa[i][2] = dynPcd.getTokenSpaceGuidCName();\r
1060 saa[i][3] = dynPcd.getMaxDatumSize()+"";\r
1061 saa[i][4] = dynPcd.getDatumType().toString();\r
1062 \r
1063 ++i;\r
1064 }\r
1065 }\r
1066 \r
908b1c05 1067 public void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) \r
82961247 1068 throws PcdValueMalFormed{\r
a13899c5 1069 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();\r
1070 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
1071 dynPcdData.setCName(cName);\r
1072 dynPcdData.setToken(token);\r
1073 dynPcdData.setTokenSpaceGuidCName(tsGuid);\r
1074 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
1075 \r
1076 BigInteger bigInt = new BigInteger("0");\r
1077 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();\r
1078 skuInfo.setSkuId(bigInt);\r
1079 if (defaultVal != null){\r
1080 skuInfo.setValue(defaultVal);\r
1081 }\r
1082 else {\r
1083 if (dataType.equals("UINT8")){\r
1084 skuInfo.setValue("0");\r
1085 }\r
1086 if (dataType.equals("UINT16")) {\r
1087 skuInfo.setValue("0");\r
1088 }\r
1089 if (dataType.equals("UINT32")) {\r
1090 skuInfo.setValue("0");\r
1091 }\r
1092 if (dataType.equals("UINT64")){\r
1093 skuInfo.setValue("0");\r
1094 }\r
1095 if (dataType.equals("BOOLEAN")){\r
1096 skuInfo.setValue("false");\r
1097 }\r
1098 if (dataType.equals("VOID*")) {\r
1099 skuInfo.setValue("");\r
1100 }\r
1101 }\r
1102 if (dataType.equals("UINT8")){\r
1103 dynPcdData.setMaxDatumSize(1);\r
1104 }\r
1105 if (dataType.equals("UINT16")) {\r
1106 dynPcdData.setMaxDatumSize(2);\r
1107 }\r
1108 if (dataType.equals("UINT32")) {\r
1109 dynPcdData.setMaxDatumSize(4);\r
1110 }\r
1111 if (dataType.equals("UINT64")){\r
1112 dynPcdData.setMaxDatumSize(8);\r
1113 }\r
1114 if (dataType.equals("BOOLEAN")){\r
1115 dynPcdData.setMaxDatumSize(1);\r
1116 }\r
1117 if (dataType.equals("VOID*")) {\r
1118 int maxSize = setMaxSizeForPointer(defaultVal);\r
1119 dynPcdData.setMaxDatumSize(maxSize);\r
1120 }\r
1121 }\r
1122 \r
908b1c05 1123 public void removeDynamicPcdBuildData(String cName, String tsGuid) {\r
e232295e 1124 XmlObject o = fpdRoot.getDynamicPcdBuildDefinitions();\r
1125 if (o == null) {\r
1126 return;\r
1127 }\r
a13899c5 1128 \r
1129 XmlCursor cursor = o.newCursor();\r
1130 if (cursor.toFirstChild()) {\r
af25df16 1131 do {\r
1132 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = \r
1133 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
908b1c05 1134 if (pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid)) {\r
1135 cursor.removeXml();\r
af25df16 1136 if (getDynamicPcdBuildDataCount() == 0) {\r
1137 cursor.toParent();\r
1138 cursor.removeXml();\r
1139 }\r
908b1c05 1140 cursor.dispose();\r
1141 return;\r
1142 }\r
a13899c5 1143 }\r
af25df16 1144 while (cursor.toNextSibling());\r
a13899c5 1145 }\r
1146 cursor.dispose();\r
1147 }\r
1148 //\r
1149 // Get the Sku Info count of ith dyn pcd element.\r
1150 //\r
1151 public int getDynamicPcdSkuInfoCount(int i){\r
e232295e 1152 if (fpdRoot.getDynamicPcdBuildDefinitions() == null || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList() == null \r
1153 || fpdRoot.getDynamicPcdBuildDefinitions().getPcdBuildDataList().size() == 0) {\r
a13899c5 1154 return 0;\r
1155 }\r
1156 \r
1157 int skuInfoCount = 0;\r
1158 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1159 if (cursor.toFirstChild()) {\r
1160 for (int j = 0; j < i; ++j) {\r
1161 cursor.toNextSibling();\r
1162 }\r
1163 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1164 if (pcdData.getSkuInfoList() == null) {\r
1165 skuInfoCount = 0;\r
1166 }\r
1167 else {\r
1168 skuInfoCount = pcdData.getSkuInfoList().size();\r
1169 }\r
1170 }\r
1171 cursor.dispose();\r
1172 return skuInfoCount;\r
1173 }\r
1174 \r
1175 public void getDynamicPcdSkuInfos(int i, String[][] saa){\r
1176 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1177 removeElement(getfpdDynPcdBuildDefs());\r
1178 fpdDynPcdBuildDefs = null;\r
a13899c5 1179 return;\r
1180 }\r
1181 \r
1182 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1183 if (cursor.toFirstChild()) {\r
1184 for (int j = 0; j < i; ++j) {\r
1185 cursor.toNextSibling();\r
1186 }\r
1187 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1188 if (pcdData.getSkuInfoList() == null) {\r
1189 cursor.dispose();\r
1190 return;\r
1191 }\r
1192 else {\r
1193 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
1194 int k = 0;\r
1195 while (li.hasNext()) {\r
1196 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
1197 saa[k][0] = skuInfo.getSkuId()+"";\r
1198 saa[k][1] = skuInfo.getVariableName();\r
1199 saa[k][2] = skuInfo.getVariableGuid();\r
1200 saa[k][3] = skuInfo.getVariableOffset();\r
1201 saa[k][4] = skuInfo.getHiiDefaultValue();\r
1202 saa[k][5] = skuInfo.getVpdOffset();\r
1203 saa[k][6] = skuInfo.getValue();\r
1204 ++k;\r
1205 }\r
1206 \r
1207 }\r
1208 }\r
1209 cursor.dispose();\r
1210 \r
1211 }\r
1212 \r
1213 public String getDynamicPcdBuildDataValue(int i){\r
1214 String value = null;\r
1215 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1216 removeElement(getfpdDynPcdBuildDefs());\r
1217 fpdDynPcdBuildDefs = null;\r
a13899c5 1218 return value;\r
1219 }\r
1220 \r
1221 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1222 if (cursor.toFirstChild()) {\r
1223 for (int j = 0; j < i; ++j) {\r
1224 cursor.toNextSibling();\r
1225 }\r
1226 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1227 if (pcdData.getSkuInfoList() == null) {\r
1228 value = null;\r
1229 }\r
1230 else {\r
1231 value = pcdData.getSkuInfoArray(0).getValue();\r
1232 }\r
1233 }\r
1234 cursor.dispose();\r
1235 return value;\r
1236 }\r
1237 \r
1238 public String getDynamicPcdBuildDataVpdOffset(int i){\r
1239 String vpdOffset = null;\r
1240 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1241 removeElement(getfpdDynPcdBuildDefs());\r
1242 fpdDynPcdBuildDefs = null;\r
a13899c5 1243 return vpdOffset;\r
1244 }\r
1245 \r
1246 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1247 if (cursor.toFirstChild()) {\r
1248 for (int j = 0; j < i; ++j) {\r
1249 cursor.toNextSibling();\r
1250 }\r
1251 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1252 if (pcdData.getSkuInfoList() == null) {\r
1253 vpdOffset = null;\r
1254 }\r
1255 else {\r
1256 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();\r
1257 }\r
1258 }\r
1259 cursor.dispose();\r
1260 return vpdOffset;\r
1261 }\r
1262 \r
1263 public void removeDynamicPcdBuildDataSkuInfo(int i) {\r
1264 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
e232295e 1265 removeElement(getfpdDynPcdBuildDefs());\r
1266 fpdDynPcdBuildDefs = null;\r
a13899c5 1267 return;\r
1268 }\r
1269 \r
1270 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1271 if (cursor.toFirstChild()) {\r
1272 for (int j = 0; j < i; ++j) {\r
1273 cursor.toNextSibling();\r
1274 }\r
1275 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1276 if (pcdData.getSkuInfoList() == null) {\r
1277 cursor.dispose();\r
1278 return;\r
1279 }\r
1280 else {\r
1281 QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r
1282 cursor.toChild(qSkuInfo);\r
1283 cursor.removeXml();\r
1284 }\r
1285 }\r
1286 cursor.dispose();\r
1287 }\r
1288 //\r
1289 // generate sku info for ith dyn pcd build data.\r
1290 //\r
1291 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
1292 String hiiDefault, String vpdOffset, String value, int i) {\r
e232295e 1293// if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1294// return;\r
1295// }\r
a13899c5 1296 \r
1297 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1298 if (cursor.toFirstChild()) {\r
1299 for (int j = 0; j < i; ++j) {\r
1300 cursor.toNextSibling();\r
1301 }\r
1302 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1303 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();\r
1304 skuInfo.setSkuId(new BigInteger(id));\r
1305 if (varName != null){\r
1306 skuInfo.setVariableName(varName);\r
1307 skuInfo.setVariableGuid(varGuid);\r
1308 skuInfo.setVariableOffset(varOffset);\r
1309 skuInfo.setHiiDefaultValue(hiiDefault);\r
1310 }\r
1311 else if (vpdOffset != null){\r
1312 skuInfo.setVpdOffset(vpdOffset);\r
1313 }\r
1314 else{\r
1315 skuInfo.setValue(value);\r
1316 }\r
1317 }\r
1318 }\r
1319 \r
1320 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
1321 String hiiDefault, String vpdOffset, String value, int i){\r
e232295e 1322// if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
1323// return;\r
1324// }\r
a13899c5 1325 \r
1326 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
1327 if (cursor.toFirstChild()) {\r
1328 for (int j = 0; j < i; ++j) {\r
1329 cursor.toNextSibling();\r
1330 }\r
1331 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
1332 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
1333 while (li.hasNext()) {\r
1334 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
1335 if (skuInfo.getSkuId().toString().equals(id)){\r
1336 if (varName != null){\r
1337 skuInfo.setVariableName(varName);\r
1338 skuInfo.setVariableGuid(varGuid);\r
1339 skuInfo.setVariableOffset(varOffset);\r
1340 skuInfo.setHiiDefaultValue(hiiDefault);\r
1341 }\r
1342 else if (vpdOffset != null){\r
1343 skuInfo.setVpdOffset(vpdOffset);\r
1344 }\r
1345 else{\r
1346 skuInfo.setValue(value);\r
1347 }\r
1348 break;\r
1349 }\r
1350 }\r
1351 }\r
1352 }\r
1353 \r
a13899c5 1354 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {\r
1355 if (fpdBuildOpts == null) {\r
1356 fpdBuildOpts = fpdRoot.addNewBuildOptions();\r
1357 }\r
1358 return fpdBuildOpts;\r
1359 }\r
1360 \r
1361 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r
1362 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1363 if (udats == null) {\r
1364 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();\r
1365 }\r
1366 \r
1367 AntTaskDocument.AntTask at = udats.addNewAntTask();\r
1368 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1369 }\r
1370 \r
1371 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {\r
1372 at.setId(new Integer(id));\r
bf5abaff 1373 XmlCursor cursor = at.newCursor();\r
a13899c5 1374 if (fileName != null){\r
1375 at.setFilename(fileName);\r
1376 }\r
bf5abaff 1377 else if (cursor.toChild(xmlNs, "Filename")) {\r
1378 cursor.removeXml();\r
1379 }\r
202c4f38 1380 if (execOrder != null) {\r
a13899c5 1381 at.setAntCmdOptions(execOrder);\r
1382 }\r
bf5abaff 1383 else if (cursor.toChild(xmlNs, "AntCmdOptions")) {\r
1384 cursor.removeXml();\r
1385 }\r
1386 cursor.dispose();\r
a13899c5 1387 }\r
1388 \r
1389 public void removeBuildOptionsUserDefAntTask(int i) {\r
1390 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1391 if (o == null) {\r
1392 return;\r
1393 }\r
1394 XmlCursor cursor = o.newCursor();\r
1395 if (cursor.toFirstChild()) {\r
1396 for (int j = 0; j < i; ++j) {\r
1397 cursor.toNextSibling();\r
1398 }\r
1399 cursor.removeXml();\r
af25df16 1400 if (getBuildOptionsUserDefAntTaskCount() == 0) {\r
1401 cursor.toParent();\r
1402 cursor.removeXml();\r
1403 }\r
a13899c5 1404 }\r
1405 cursor.dispose();\r
1406 }\r
1407 \r
1408 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){\r
1409 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1410 if (o == null) {\r
1411 return;\r
1412 }\r
1413 XmlCursor cursor = o.newCursor();\r
1414 if (cursor.toFirstChild()) {\r
1415 for (int j = 0; j < i; ++j) {\r
1416 cursor.toNextSibling();\r
1417 }\r
1418 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();\r
1419 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1420 }\r
1421 cursor.dispose();\r
1422 }\r
1423 \r
1424 public int getBuildOptionsUserDefAntTaskCount() {\r
1425 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1426 if (udats == null || udats.getAntTaskList() == null) {\r
1427 return 0;\r
1428 }\r
1429 \r
1430 return udats.getAntTaskList().size();\r
1431 }\r
1432 \r
1433 public void getBuildOptionsUserDefAntTasks(String[][] saa) {\r
1434 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1435 if (udats == null || udats.getAntTaskList() == null) {\r
1436 return ;\r
1437 }\r
1438 \r
1439 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();\r
1440 ListIterator li = l.listIterator();\r
1441 int i = 0;\r
1442 while (li.hasNext()) {\r
1443 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();\r
1444 saa[i][0] = at.getId() + "";\r
1445 saa[i][1] = saa[i][2] = "";\r
1446 if (at.getFilename() != null){\r
1447 saa[i][1] = at.getFilename();\r
1448 }\r
1449 if (at.getAntCmdOptions() != null) {\r
1450 saa[i][2] = at.getAntCmdOptions();\r
1451 }\r
1452 ++i;\r
1453 }\r
1454 }\r
1800d80f 1455 public void genBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
a13899c5 1456 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();\r
1457 if (opts == null) {\r
1458 opts = getfpdBuildOpts().addNewOptions();\r
1459 }\r
1460 OptionDocument.Option opt = opts.addNewOption();\r
1461 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1462 }\r
1463 \r
1800d80f 1464 private void setBuildOptionsOpt(Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents, OptionDocument.Option opt){\r
a13899c5 1465 opt.setStringValue(contents);\r
1800d80f 1466 \r
1467 opt.setBuildTargets(buildTargets);\r
a13899c5 1468 opt.setToolChainFamily(toolChain);\r
1469 opt.setTagName(tagName);\r
1470 opt.setToolCode(toolCmd);\r
1800d80f 1471 \r
bf5abaff 1472 if (archList != null) {\r
1473 opt.setSupArchList(archList);\r
1474 }\r
1475 else {\r
1476 if (opt.isSetSupArchList()) {\r
1477 opt.unsetSupArchList();\r
1478 }\r
1479 }\r
a13899c5 1480 }\r
1481 \r
1482 public void removeBuildOptionsOpt(int i){\r
1483 \r
1484 XmlObject o = getfpdBuildOpts().getOptions();\r
1485 if (o == null) {\r
1486 return;\r
1487 }\r
1488 \r
1489 XmlCursor cursor = o.newCursor();\r
1490 if (cursor.toFirstChild()) {\r
1491 for (int j = 0; j < i; ++j) {\r
1492 cursor.toNextSibling();\r
1493 }\r
1494 cursor.removeXml();\r
af25df16 1495 if (getBuildOptionsOptCount() == 0) {\r
1496 cursor.toParent();\r
1497 cursor.removeXml();\r
1498 }\r
a13899c5 1499 }\r
1500 cursor.dispose();\r
1501 }\r
1502 \r
1800d80f 1503 public void updateBuildOptionsOpt(int i, Vector<Object> buildTargets, String toolChain, String tagName, String toolCmd, Vector<Object> archList, String contents) {\r
a13899c5 1504 XmlObject o = getfpdBuildOpts().getOptions();\r
1505 if (o == null) {\r
1506 return;\r
1507 }\r
1508 \r
1509 XmlCursor cursor = o.newCursor();\r
1510 if (cursor.toFirstChild()) {\r
1511 for (int j = 0; j < i; ++j) {\r
1512 cursor.toNextSibling();\r
1513 }\r
1514 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();\r
1515 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1516 }\r
1517 cursor.dispose();\r
1518 }\r
1519 \r
1520 public int getBuildOptionsOptCount(){\r
1521 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1522 return 0;\r
1523 }\r
1524 return getfpdBuildOpts().getOptions().getOptionList().size();\r
1525 }\r
1526 \r
1527 public void getBuildOptionsOpts(String[][] saa) {\r
1528 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1529 return ;\r
1530 }\r
1531 \r
1532 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();\r
1533 ListIterator li = lOpt.listIterator();\r
1534 int i = 0;\r
1535 while(li.hasNext()) {\r
1536 OptionDocument.Option opt = (OptionDocument.Option)li.next();\r
6cba26e8 1537 if (opt.getBuildTargets() != null) {\r
1538 saa[i][0] = listToString(opt.getBuildTargets());\r
1539 }\r
a13899c5 1540 saa[i][1] = opt.getToolChainFamily();\r
1541 if (opt.getSupArchList() != null){\r
6cba26e8 1542 saa[i][2] = listToString(opt.getSupArchList());\r
1543\r
a13899c5 1544 }\r
1545 saa[i][3] = opt.getToolCode();\r
1546 saa[i][4] = opt.getTagName();\r
1547 saa[i][5] = opt.getStringValue();\r
1548 \r
1549 ++i;\r
1550 }\r
1551 }\r
1552 \r
6cba26e8 1553 public void genBuildOptionsFfs(String ffsKey, String type) {\r
1554 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r
1555 ffs.setFfsKey(ffsKey);\r
1556 if (type != null) {\r
1557 ffs.addNewSections().setEncapsulationType(type);\r
1558 }\r
1559 }\r
1560 \r
3b405e9b 1561 public void updateBuildOptionsFfsSectionsType(int i, String type) {\r
1562 BuildOptionsDocument.BuildOptions.Ffs ffs = getfpdBuildOpts().addNewFfs();\r
1563 if (type != null) {\r
1564 ffs.addNewSections().setEncapsulationType(type);\r
1565 }\r
1566 }\r
1567 \r
6cba26e8 1568 public void genBuildOptionsFfsAttribute(int i, String name, String value) {\r
1569 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1570 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = ffs.addNewAttribute();\r
1571 attrib.setName(name);\r
1572 attrib.setValue(value);\r
1573 }\r
1574 \r
1575 /**update jth attribute of ith ffs.\r
1576 * @param i\r
1577 * @param j\r
1578 */\r
1579 public void updateBuildOptionsFfsAttribute(int i, int j, String name, String value){\r
1580 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1581 XmlCursor cursor = ffs.newCursor();\r
1582 QName qAttrib = new QName(xmlNs, "Attribute");\r
1583 if (cursor.toChild(qAttrib)) {\r
1584 for (int k = 0; k < j; ++k) {\r
1585 cursor.toNextSibling(qAttrib);\r
1586 }\r
1587 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = (BuildOptionsDocument.BuildOptions.Ffs.Attribute)cursor.getObject();\r
1588 attrib.setName(name);\r
1589 attrib.setValue(value);\r
1590 }\r
1591 cursor.dispose();\r
1592 }\r
1593 \r
1594 public void removeBuildOptionsFfsAttribute(int i, int j){\r
1595 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1596 XmlCursor cursor = ffs.newCursor();\r
1597 QName qAttrib = new QName(xmlNs, "Attribute");\r
1598 if (cursor.toChild(qAttrib)) {\r
1599 for (int k = 0; k < j; ++k) {\r
1600 cursor.toNextSibling(qAttrib);\r
1601 }\r
1602 cursor.removeXml();\r
1603 }\r
1604 cursor.dispose();\r
1605 }\r
1606 \r
1607 public void genBuildOptionsFfsSectionsSection(int i, String sectionType) {\r
1608 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1609 if (ffs == null) {\r
1610 return;\r
1611 }\r
1612 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1613 \r
1614 if (sections == null){\r
1615 sections = ffs.addNewSections();\r
1616 }\r
1617 sections.addNewSection().setSectionType(EfiSectionType.Enum.forString(sectionType));\r
1618 }\r
1619 \r
3b405e9b 1620 public void removeBuildOptionsFfsSectionsSection(int i, int j) {\r
1621 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1622 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1623 if (sections == null) {\r
1624 return;\r
1625 }\r
1626 XmlCursor cursor = sections.newCursor();\r
1627 QName qSection = new QName(xmlNs, "Section");\r
1628 if (cursor.toChild(qSection)) {\r
1629 for (int k = 0; k < j; ++k) {\r
1630 cursor.toNextSibling(qSection);\r
1631 }\r
1632 cursor.removeXml();\r
1633 }\r
1634 cursor.dispose();\r
1635 }\r
1636 \r
1637 public void updateBuildOptionsFfsSectionsSection(int i, int j, String type){\r
1638 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1639 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1640 if (sections == null) {\r
1641 return;\r
1642 }\r
1643 XmlCursor cursor = sections.newCursor();\r
1644 QName qSection = new QName(xmlNs, "Section");\r
1645 if (cursor.toChild(qSection)) {\r
1646 for (int k = 0; k < j; ++k) {\r
1647 cursor.toNextSibling(qSection);\r
1648 }\r
1649 BuildOptionsDocument.BuildOptions.Ffs.Sections.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Section)cursor.getObject();\r
1650 section.setSectionType(EfiSectionType.Enum.forString(type));\r
1651 }\r
1652 cursor.dispose();\r
1653 } \r
1654 \r
6cba26e8 1655 public void genBuildOptionsFfsSectionsSections(int i, String encapType) {\r
1656 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1657 if (ffs == null) {\r
1658 return;\r
1659 }\r
1660 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1661 \r
1662 if (sections == null){\r
1663 sections = ffs.addNewSections();\r
1664 }\r
1665 sections.addNewSections().setEncapsulationType(encapType);\r
1666 }\r
1667 \r
3b405e9b 1668 public void removeBuildOptionsFfsSectionsSections(int i, int j) {\r
1669 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1670 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1671 if (sections == null) {\r
1672 return;\r
1673 }\r
1674 XmlCursor cursor = sections.newCursor();\r
1675 QName qSections = new QName(xmlNs, "Sections");\r
1676 if (cursor.toChild(qSections)) {\r
1677 for (int k = 0; k < j; ++k) {\r
1678 cursor.toNextSibling(qSections);\r
1679 }\r
1680 cursor.removeXml();\r
1681 }\r
1682 cursor.dispose();\r
1683 }\r
1684 \r
1685 public void updateBuildOptionsFfsSectionsSections(int i, int j, String type) {\r
1686 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1687 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1688 if (sections == null) {\r
1689 return;\r
1690 }\r
1691 XmlCursor cursor = sections.newCursor();\r
1692 QName qSections = new QName(xmlNs, "Sections");\r
1693 if (cursor.toChild(qSections)) {\r
1694 for (int k = 0; k < j; ++k) {\r
1695 cursor.toNextSibling(qSections);\r
1696 }\r
1697 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1698 sections2.setEncapsulationType(type);\r
1699 }\r
1700 cursor.dispose();\r
1701 }\r
1702 \r
6cba26e8 1703 public void genBuildOptionsFfsSectionsSectionsSection(int i, int j, String type) {\r
1704 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1705 if (ffs == null) {\r
1706 return;\r
1707 }\r
1708 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1709 XmlCursor cursor = sections.newCursor();\r
1710 QName qSections = new QName(xmlNs, "Sections");\r
1711 if (cursor.toChild(qSections)){\r
1712 for (int k = 0; k < j; ++k) {\r
1713 cursor.toNextSibling(qSections);\r
1714 }\r
1715 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1716 sections2.addNewSection().setSectionType(EfiSectionType.Enum.forString(type));\r
1717 }\r
1718 cursor.dispose();\r
1719 }\r
1720 \r
3b405e9b 1721 public void removeBuildOptionsFfsSectionsSectionsSection(int i, int j, int k) {\r
1722 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1723 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1724 if (sections == null) {\r
1725 return;\r
1726 }\r
1727 XmlCursor cursor = sections.newCursor();\r
1728 QName qSections = new QName(xmlNs, "Sections");\r
1729 if (cursor.toChild(qSections)) {\r
1730 for (int l = 0; l < j; ++l) {\r
1731 cursor.toNextSibling(qSections);\r
1732 }\r
1733 if (cursor.toFirstChild()) {\r
af25df16 1734 int m = 0;\r
1735 for (; m < k; ++m) {\r
3b405e9b 1736 cursor.toNextSibling();\r
1737 }\r
1738 cursor.removeXml();\r
af25df16 1739 if (m == 0) {\r
1740 cursor.toParent();\r
1741 cursor.removeXml();\r
1742 }\r
3b405e9b 1743 }\r
1744 }\r
1745 cursor.dispose();\r
1746 }\r
1747 \r
1748 public void updateBuildOptionsFfsSectionsSectionsSection(int i, int j, int k, String type) {\r
1749 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1750 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1751 if (sections == null) {\r
1752 return;\r
1753 }\r
1754 XmlCursor cursor = sections.newCursor();\r
1755 QName qSections = new QName(xmlNs, "Sections");\r
1756 if (cursor.toChild(qSections)) {\r
1757 for (int l = 0; l < j; ++l) {\r
1758 cursor.toNextSibling(qSections);\r
1759 }\r
1760 if (cursor.toFirstChild()) {\r
1761 for (int m = 0; m < k; ++m) {\r
1762 cursor.toNextSibling();\r
1763 }\r
1764 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section)cursor.getObject();\r
1765 section.setSectionType(EfiSectionType.Enum.forString(type));\r
1766 }\r
1767 }\r
1768 cursor.dispose();\r
1769 }\r
1770 \r
6cba26e8 1771 public void getBuildOptionsFfsSectionsSectionsSection(int i, int j, ArrayList<String> al) {\r
1772 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1773 if (ffs == null) {\r
1774 return;\r
1775 }\r
1776 BuildOptionsDocument.BuildOptions.Ffs.Sections sections = ffs.getSections();\r
1777 XmlCursor cursor = sections.newCursor();\r
1778 QName qSections = new QName(xmlNs, "Sections");\r
1779 if (cursor.toChild(qSections)){\r
1780 for (int k = 0; k < j; ++k) {\r
1781 cursor.toNextSibling(qSections);\r
1782 }\r
1783 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2 sections2 = (BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2)cursor.getObject();\r
1784 if (sections2.getSectionList() == null){\r
1785 cursor.dispose();\r
1786 return;\r
1787 }\r
1788 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section> li = sections2.getSectionList().listIterator();\r
1789 while(li.hasNext()) {\r
1790 BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2.Section section = li.next();\r
3b405e9b 1791 if (section.isSetSectionType()) {\r
1800d80f 1792 al.add(section.getSectionType().toString());\r
1793 }\r
3b405e9b 1794 \r
1795 }\r
6cba26e8 1796 }\r
1797 cursor.dispose();\r
1798 \r
1799 }\r
1800 \r
1801 public int getBuildOptionsFfsCount(){\r
1802 if (getfpdBuildOpts().getFfsList() == null) {\r
1803 return 0;\r
1804 }\r
1805 return getfpdBuildOpts().getFfsList().size();\r
1806 }\r
1807 \r
1808 public void getBuildOptionsFfsKey(String[][] saa) {\r
1809 if (getfpdBuildOpts().getFfsList() == null) {\r
1810 return;\r
1811 }\r
1812 ListIterator<BuildOptionsDocument.BuildOptions.Ffs> li = getfpdBuildOpts().getFfsList().listIterator();\r
1813 int i = 0;\r
1814 while(li.hasNext()){\r
1815 BuildOptionsDocument.BuildOptions.Ffs ffs = li.next();\r
1816 saa[i][0] = ffs.getFfsKey();\r
1817 ++i;\r
1818 }\r
1819 }\r
1820 \r
3b405e9b 1821 public void updateBuildOptionsFfsKey(int i, String key) {\r
1822 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1823 ffs.setFfsKey(key);\r
1824 }\r
1825 \r
6cba26e8 1826 /**Get ith FFS key and contents.\r
1827 * @param saa\r
1828 */\r
1829 public void getBuildOptionsFfs(int i, String[] sa, LinkedHashMap<String, String> ffsAttribMap, ArrayList<String> firstLevelSections, ArrayList<String> firstLevelSection) {\r
1830 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1831 \r
1832 if (ffs != null) {\r
1833 \r
1834 sa[0] = ffs.getFfsKey();\r
1835 if (ffs.getSections() != null) {\r
1836 if(ffs.getSections().getEncapsulationType() != null){\r
1837 sa[1] = ffs.getSections().getEncapsulationType();\r
1838 }\r
1839 if (ffs.getSections().getSectionList() != null){\r
1840 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Section> li = ffs.getSections().getSectionList().listIterator();\r
1841 while (li.hasNext()) {\r
1842 firstLevelSection.add(li.next().getSectionType().toString());\r
1843 }\r
1844 }\r
1845 if (ffs.getSections().getSectionsList() != null) {\r
1846 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Sections.Sections2> li = ffs.getSections().getSectionsList().listIterator();\r
1847 while(li.hasNext()) {\r
1848 firstLevelSections.add(li.next().getEncapsulationType());\r
1849 }\r
1850 }\r
1851 }\r
1852 if (ffs.getAttributeList() != null) {\r
1853 ListIterator<BuildOptionsDocument.BuildOptions.Ffs.Attribute> li = ffs.getAttributeList().listIterator();\r
1854 while(li.hasNext()) {\r
1855 BuildOptionsDocument.BuildOptions.Ffs.Attribute attrib = li.next();\r
1856 ffsAttribMap.put(attrib.getName(), attrib.getValue());\r
1857 }\r
1858 \r
1859 }\r
1860 }\r
1861\r
1862 \r
1863 }\r
1864 \r
1865 private BuildOptionsDocument.BuildOptions.Ffs getFfs(int i) {\r
1866 XmlObject o = getfpdBuildOpts();\r
1867 BuildOptionsDocument.BuildOptions.Ffs ffs = null;\r
1868 \r
1869 XmlCursor cursor = o.newCursor();\r
1870 QName qFfs = new QName(xmlNs, "Ffs");\r
1871 if (cursor.toChild(qFfs)) {\r
1872 for (int j = 0; j < i; ++j) {\r
1873 cursor.toNextSibling(qFfs);\r
1874 }\r
1875 ffs = (BuildOptionsDocument.BuildOptions.Ffs)cursor.getObject();\r
1876 }\r
1877 cursor.dispose();\r
1878 return ffs;\r
1879 }\r
1880 \r
1881 public void removeBuildOptionsFfs(int i) {\r
1882 BuildOptionsDocument.BuildOptions.Ffs ffs = getFfs(i);\r
1883 if (ffs == null){\r
1884 return;\r
1885 }\r
1886 \r
1887 XmlCursor cursor = ffs.newCursor();\r
1888 cursor.removeXml();\r
1889 cursor.dispose();\r
1890 }\r
1891 \r
3b405e9b 1892 \r
1893 \r
a13899c5 1894 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){\r
1895 if (fpdPlatformDefs == null){\r
1896 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();\r
1897 }\r
1898 return fpdPlatformDefs;\r
1899 }\r
1900 \r
6a09eb19 1901 public void getPlatformDefsSupportedArchs(Vector<Object> archs){\r
1902 if (getfpdPlatformDefs().getSupportedArchitectures() == null) {\r
1903 return;\r
1904 }\r
1905 ListIterator li = getfpdPlatformDefs().getSupportedArchitectures().listIterator();\r
1906 while(li.hasNext()) {\r
1907 archs.add(li.next());\r
1908 }\r
1909 }\r
1910 \r
1911 public void setPlatformDefsSupportedArchs(Vector<Object> archs) {\r
bf5abaff 1912 if (archs != null) {\r
1913 getfpdPlatformDefs().setSupportedArchitectures(archs);\r
1914 }\r
1915// else {\r
1916// XmlCursor cursor = getfpdPlatformDefs().newCursor();\r
1917// if (cursor.toChild(xmlNs, "SupportedArchitectures")) {\r
1918// cursor.removeXml();\r
1919// }\r
1920// cursor.dispose();\r
1921// }\r
6a09eb19 1922 }\r
1923 \r
1924 public void getPlatformDefsBuildTargets(Vector<Object> targets) {\r
1925 if (getfpdPlatformDefs().getBuildTargets() == null) {\r
1926 return;\r
1927 }\r
1928 ListIterator li = getfpdPlatformDefs().getBuildTargets().listIterator();\r
1929 while(li.hasNext()) {\r
1930 targets.add(li.next());\r
1931 }\r
1932 }\r
1933 \r
1934 public void setPlatformDefsBuildTargets(Vector<Object> targets) {\r
1935 getfpdPlatformDefs().setBuildTargets(targets);\r
1936 }\r
1937 \r
1938 public void genPlatformDefsSkuInfo(String id, String name) {\r
1939 SkuInfoDocument.SkuInfo skuInfo = null;\r
1940 if (getfpdPlatformDefs().getSkuInfo() == null) {\r
1941 skuInfo = getfpdPlatformDefs().addNewSkuInfo();\r
1942 }\r
1943 skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1944 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {\r
1945 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1946 skuName.setSkuID(new BigInteger("0"));\r
1947 skuName.setStringValue("DEFAULT");\r
1948 }\r
1949 if (id.equals("0")) {\r
1950 return;\r
1951 }\r
1952 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1953 skuName.setSkuID(new BigInteger(id));\r
1954 skuName.setStringValue(name);\r
1955 }\r
1956 \r
1957 public int getPlatformDefsSkuInfoCount(){\r
1958 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
1959 return 0;\r
1960 }\r
1961 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();\r
1962 }\r
1963 \r
1964 public void getPlatformDefsSkuInfos(String[][] saa){\r
1965 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
5af6b67f 1966 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r
1967 removeElement(getfpdDynPcdBuildDefs());\r
1968 fpdDynPcdBuildDefs = null;\r
1969 }\r
6a09eb19 1970 return ;\r
1971 }\r
1972 \r
1973 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();\r
1974 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();\r
1975 int i = 0;\r
1976 while(li.hasNext()) {\r
1977 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();\r
1978 saa[i][0] = sku.getSkuID()+"";\r
1979 saa[i][1] = sku.getStringValue();\r
1980 ++i;\r
1981 }\r
1982 }\r
1983 \r
1984 public void removePlatformDefsSkuInfo(int i) {\r
1985 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1986 if (skuInfo == null || i == 0) {\r
1987 return ;\r
1988 }\r
1989 \r
1990 XmlCursor cursor = skuInfo.newCursor();\r
1991 if (cursor.toFirstChild()) {\r
1992 for (int j = 0; j < i; ++j) {\r
1993 cursor.toNextSibling();\r
1994 }\r
1995 cursor.removeXml();\r
1996 }\r
1997 cursor.dispose();\r
1998 }\r
1999 \r
2000 public void updatePlatformDefsSkuInfo(int i, String id, String name) {\r
2001 SkuInfoDocument.SkuInfo skuInfo = getfpdPlatformDefs().getSkuInfo();\r
2002 if (skuInfo == null || i == 0) {\r
2003 return ;\r
2004 }\r
2005 \r
2006 XmlCursor cursor = skuInfo.newCursor();\r
2007 if (cursor.toFirstChild()) {\r
2008 for (int j = 0; j < i; ++j) {\r
2009 cursor.toNextSibling();\r
2010 }\r
2011 SkuInfoDocument.SkuInfo.UiSkuName sku = (SkuInfoDocument.SkuInfo.UiSkuName)cursor.getObject();\r
2012 sku.setSkuID(new BigInteger(id));\r
2013 sku.setStringValue(name);\r
2014 }\r
2015 cursor.dispose();\r
2016 }\r
2017 \r
2018 public String getPlatformDefsInterDir(){\r
2019 if (getfpdPlatformDefs().getIntermediateDirectories() == null) {\r
2020 return null;\r
2021 }\r
2022 return getfpdPlatformDefs().getIntermediateDirectories().toString();\r
2023 }\r
2024 \r
2025 public void setPlatformDefsInterDir(String interDir){\r
2026 getfpdPlatformDefs().setIntermediateDirectories(IntermediateOutputType.Enum.forString(interDir));\r
2027 }\r
2028 \r
2029 public String getPlatformDefsOutputDir() {\r
2030 return getfpdPlatformDefs().getOutputDirectory();\r
2031 }\r
2032 \r
2033 public void setPlatformDefsOutputDir(String outputDir) {\r
af25df16 2034 if (outputDir != null && outputDir.length() > 0) {\r
2035 getfpdPlatformDefs().setOutputDirectory(outputDir);\r
2036 }\r
2037 else{\r
2038 XmlCursor cursor = getfpdPlatformDefs().newCursor();\r
2039 if (cursor.toChild(new QName(xmlNs, "OutputDirectory"))) {\r
2040 cursor.removeXml();\r
2041 }\r
2042 cursor.dispose();\r
2043 }\r
6a09eb19 2044 }\r
2045 \r
a13899c5 2046 public FlashDocument.Flash getfpdFlash() {\r
2047 if (fpdFlash == null) {\r
2048 fpdFlash = fpdRoot.addNewFlash();\r
2049 }\r
2050 return fpdFlash;\r
2051 }\r
2052 \r
2053 public void genFlashDefinitionFile(String file) {\r
2054 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
2055 if (fdf == null) {\r
2056 fdf = getfpdFlash().addNewFlashDefinitionFile();\r
2057 }\r
2058 \r
2059 fdf.setStringValue(file);\r
2060 }\r
2061 \r
2062 public String getFlashDefinitionFile() {\r
2063 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
2064 if (fdf == null) {\r
2065 return "";\r
2066 }\r
2067 \r
2068 return fdf.getStringValue();\r
2069 }\r
2070 \r
a13899c5 2071 public void genFvImagesNameValue(String name, String value) {\r
2072 \r
2073 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
2074 if (fi == null) {\r
2075 fi = getfpdFlash().addNewFvImages();\r
2076 }\r
2077 \r
2078 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();\r
2079 nv.setName(name);\r
2080 nv.setValue(value);\r
2081 }\r
2082 \r
2083 public void removeFvImagesNameValue(int i){\r
2084 \r
2085 XmlObject o = getfpdFlash().getFvImages();\r
2086 if (o == null) {\r
2087 return;\r
2088 }\r
2089 \r
2090 QName qNameValue = new QName(xmlNs, "NameValue");\r
2091 XmlCursor cursor = o.newCursor();\r
2092 if (cursor.toChild(qNameValue)) {\r
2093 for (int j = 0; j < i; ++j) {\r
2094 cursor.toNextSibling(qNameValue);\r
2095 }\r
2096 cursor.removeXml();\r
2097 }\r
2098 cursor.dispose();\r
2099 }\r
2100 \r
2101 public void updateFvImagesNameValue(int i, String name, String value){\r
2102 \r
2103 XmlObject o = getfpdFlash().getFvImages();\r
2104 if (o == null) {\r
2105 return;\r
2106 }\r
2107 \r
2108 QName qNameValue = new QName(xmlNs, "NameValue");\r
2109 XmlCursor cursor = o.newCursor();\r
2110 if (cursor.toChild(qNameValue)) {\r
2111 for (int j = 0; j < i; ++j) {\r
2112 cursor.toNextSibling(qNameValue);\r
2113 }\r
2114 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();\r
2115 nv.setName(name);\r
2116 nv.setValue(value);\r
2117 }\r
2118 cursor.dispose();\r
2119 }\r
2120 \r
2121 public int getFvImagesNameValueCount() {\r
2122 \r
2123 FvImagesDocument.FvImages fi = null;\r
2124 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {\r
2125 return 0;\r
2126 }\r
2127 return fi.getNameValueList().size();\r
2128 }\r
2129 \r
2130 public void getFvImagesNameValues(String[][] nv) {\r
2131 \r
2132 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
2133 if (fi == null){\r
2134 return;\r
2135 }\r
2136 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();\r
2137 int i = 0;\r
2138 ListIterator li = l.listIterator();\r
2139 while (li.hasNext()) {\r
2140 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li\r
2141 .next();\r
2142 nv[i][0] = e.getName();\r
2143 nv[i][1] = e.getValue();\r
2144 \r
2145 i++;\r
2146 }\r
2147 }\r
2148 \r
2149 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
2150 \r
2151 FvImagesDocument.FvImages fis = null;\r
2152 if ((fis = getfpdFlash().getFvImages()) == null) {\r
2153 fis = getfpdFlash().addNewFvImages();\r
2154 }\r
2155 \r
2156 //\r
2157 //gen FvImage with FvImageNames array\r
2158 //\r
2159 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();\r
2160 for (int i = 0; i < names.length; ++i) {\r
2161 fi.addFvImageNames(names[i]);\r
2162 }\r
2163 fi.setType(FvImageTypes.Enum.forString(types));\r
2164 if (options != null){\r
2165 setFvImagesFvImageFvImageOptions(options, fi);\r
2166 }\r
2167 }\r
2168 \r
2169 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){\r
2170 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();\r
2171 if (fio == null){\r
2172 fio = fi.addNewFvImageOptions();\r
2173 }\r
2174 \r
2175 Set<String> key = options.keySet();\r
2176 Iterator<String> i = key.iterator();\r
2177 while (i.hasNext()) {\r
44053733 2178 \r
a13899c5 2179 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();\r
2180 String k = (String)i.next();\r
ae0d4fd2 2181 \r
a13899c5 2182 nv.setName(k);\r
2183 nv.setValue((String)options.get(k));\r
2184 \r
2185 }\r
2186 \r
2187 }\r
2188 \r
44053733 2189 \r
a13899c5 2190 public void removeFvImagesFvImage(int i) {\r
2191 \r
2192 XmlObject o = getfpdFlash().getFvImages();\r
2193 if (o == null) {\r
2194 return;\r
2195 }\r
2196 \r
2197 QName qFvImage = new QName(xmlNs, "FvImage");\r
2198 XmlCursor cursor = o.newCursor();\r
2199 if (cursor.toChild(qFvImage)) {\r
2200 for (int j = 0; j < i; ++j) {\r
2201 cursor.toNextSibling(qFvImage);\r
2202 }\r
2203 cursor.removeXml();\r
2204 }\r
2205 cursor.dispose();\r
2206 }\r
2207 \r
2208 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
2209 \r
2210 XmlObject o = getfpdFlash().getFvImages();\r
2211 if (o == null) {\r
2212 return;\r
2213 }\r
2214 XmlCursor cursor = o.newCursor();\r
2215 QName qFvImage = new QName(xmlNs, "FvImage");\r
2216 if (cursor.toChild(qFvImage)) {\r
2217 for (int j = 0; j < i; ++j) {\r
2218 cursor.toNextSibling(qFvImage);\r
2219 }\r
2220 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
2221 fi.setType(FvImageTypes.Enum.forString(types));\r
2222 \r
2223 //\r
2224 // remove old FvImageNames before adding new ones\r
2225 //\r
2226 QName qFvImageNames = new QName(xmlNs, "FvImageNames"); \r
2227 cursor.toChild(qFvImageNames);\r
2228 cursor.removeXml();\r
2229 while (cursor.toNextSibling(qFvImageNames)) {\r
2230 cursor.removeXml();\r
2231 }\r
2232 \r
2233 for (int k = 0; k < names.length; ++k) {\r
2234 fi.addFvImageNames(names[k]);\r
2235 }\r
2236 //\r
2237 // remove old FvImageOptions before adding new options\r
2238 //\r
2239 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");\r
2240 cursor.toNextSibling(qFvImageOptions);\r
2241 cursor.removeXml();\r
2242 \r
2243 setFvImagesFvImageFvImageOptions(options, fi);\r
2244 }\r
2245 cursor.dispose();\r
2246 }\r
2247 \r
2248 public int getFvImagesFvImageCount() {\r
2249 \r
2250 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
2251 return 0;\r
2252 }\r
2253 return getfpdFlash().getFvImages().getFvImageList().size();\r
2254 }\r
2255 \r
ae0d4fd2 2256 /**Only Get Fv image setting - name and type.\r
2257 * @param saa\r
2258 */\r
2259 public void getFvImagesFvImages(String[][] saa) {\r
a13899c5 2260 \r
2261 if (getfpdFlash().getFvImages() == null) {\r
2262 return;\r
2263 }\r
2264 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
2265 if (l == null) {\r
2266 return;\r
2267 }\r
2268 ListIterator li = l.listIterator();\r
2269 int i = 0;\r
2270 while(li.hasNext()) {\r
2271 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
2272 //\r
2273 // get FvImageNames array, space separated\r
2274 //\r
2275 List<String> lfn = fi.getFvImageNamesList();\r
2276 ListIterator lfni = lfn.listIterator();\r
2277 saa[i][0] = " ";\r
2278 while (lfni.hasNext()) {\r
2279 saa[i][0] += (String)lfni.next();\r
2280 saa[i][0] += " ";\r
2281 }\r
2282 saa[i][0] = saa[i][0].trim();\r
2283 \r
2284 saa[i][1] = fi.getType()+"";\r
2285 \r
ae0d4fd2 2286 ++i;\r
2287 }\r
2288 }\r
2289 \r
2290 /**Get FvImage Options for FvImage i\r
2291 * @param i the ith FvImage\r
2292 */\r
2293 public void getFvImagesFvImageOptions(int i, Map<String, String> m) {\r
2294 XmlObject o = getfpdFlash().getFvImages();\r
2295 if (o == null) {\r
2296 return;\r
2297 }\r
2298 XmlCursor cursor = o.newCursor();\r
2299 QName qFvImage = new QName(xmlNs, "FvImage");\r
2300 if (cursor.toChild(qFvImage)) {\r
2301 for (int j = 0; j < i; ++j) {\r
2302 cursor.toNextSibling(qFvImage);\r
a13899c5 2303 }\r
ae0d4fd2 2304 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
2305 if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){\r
2306 return;\r
a13899c5 2307 }\r
ae0d4fd2 2308 ListIterator<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> li = fi.getFvImageOptions().getNameValueList().listIterator();\r
2309 while(li.hasNext()){\r
2310 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next();\r
a13899c5 2311 m.put(nv.getName(), nv.getValue());\r
2312 }\r
a13899c5 2313 }\r
2314 }\r
2315 \r
2316 /**\r
2317 Get platform header element\r
2318 @return PlatformHeaderDocument.PlatformHeader\r
2319 **/\r
2320 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {\r
2321 if (fpdHdr == null) {\r
2322 fpdHdr = fpdRoot.addNewPlatformHeader();\r
2323 }\r
1faac7b6 2324 \r
a13899c5 2325 return fpdHdr;\r
2326 }\r
2327 \r
a13899c5 2328 public String getFpdHdrPlatformName() {\r
2329 return getFpdHdr().getPlatformName();\r
2330 }\r
2331 \r
2332 public String getFpdHdrGuidValue() {\r
2333 return getFpdHdr().getGuidValue();\r
2334 }\r
2335 \r
2336 public String getFpdHdrVer() {\r
2337 return getFpdHdr().getVersion();\r
2338 }\r
2339 \r
2340 public String getFpdHdrAbs() {\r
2341 return getFpdHdr().getAbstract();\r
2342 }\r
2343 \r
2344 public String getFpdHdrDescription() {\r
2345 return getFpdHdr().getDescription();\r
2346 }\r
2347 \r
2348 public String getFpdHdrCopyright() {\r
2349 return getFpdHdr().getCopyright();\r
2350 }\r
2351 \r
2352 public String getFpdHdrLicense() {\r
2353 LicenseDocument.License l = getFpdHdr().getLicense();\r
2354 if (l == null) {\r
2355 return null;\r
2356 }\r
2357 return l.getStringValue();\r
2358 }\r
2359 \r
2360 public String getFpdHdrUrl() {\r
2361 LicenseDocument.License l = getFpdHdr().getLicense();\r
2362 if (l == null) {\r
2363 return null;\r
2364 }\r
2365 return l.getURL();\r
2366 }\r
2367 \r
2368 public String getFpdHdrSpec() {\r
2369\r
c06e8657 2370 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 2371// return getFpdHdr().getSpecification();\r
2372 }\r
2373 \r
2374 public void setFpdHdrPlatformName(String name){\r
2375 getFpdHdr().setPlatformName(name);\r
2376 }\r
2377 \r
2378 public void setFpdHdrGuidValue(String guid){\r
2379 getFpdHdr().setGuidValue(guid);\r
2380 }\r
2381 \r
2382 public void setFpdHdrVer(String v){\r
2383 getFpdHdr().setVersion(v);\r
2384 }\r
2385 \r
2386 public void setFpdHdrAbs(String abs) {\r
2387 getFpdHdr().setAbstract(abs);\r
2388 }\r
2389 \r
2390 public void setFpdHdrDescription(String desc){\r
2391 getFpdHdr().setDescription(desc);\r
2392 }\r
2393 \r
2394 public void setFpdHdrCopyright(String cr) {\r
2395 getFpdHdr().setCopyright(cr);\r
2396 }\r
2397 \r
2398 public void setFpdHdrLicense(String license){\r
2399 LicenseDocument.License l = getFpdHdr().getLicense();\r
2400 if (l == null) {\r
2401 getFpdHdr().addNewLicense().setStringValue(license);\r
2402 }\r
2403 else {\r
2404 l.setStringValue(license);\r
2405 }\r
2406 }\r
2407\r
2408 public void setFpdHdrUrl(String url){\r
2409 LicenseDocument.License l = getFpdHdr().getLicense();\r
2410 \r
2411 l.setURL(url);\r
2412 \r
2413 }\r
2414 \r
2415 public void setFpdHdrSpec(String s){\r
c06e8657 2416 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 2417 getFpdHdr().setSpecification(s);\r
2418 }\r
2419 /**\r
2420 Save the processed xml contents to file\r
2421 \r
2422 @param fpdFile The file to save xml contents\r
2423 @throws IOException Exceptions during file operation\r
2424 **/\r
2425 public void saveAs(File fpdFile) throws IOException {\r
2426\r
2427 XmlOptions options = new XmlOptions();\r
2428\r
2429 options.setCharacterEncoding("UTF-8");\r
2430 options.setSavePrettyPrint();\r
2431 options.setSavePrettyPrintIndent(2);\r
2432 try {\r
2433 fpdd.save(fpdFile, options);\r
2434 } catch (IOException e) {\r
2435 e.printStackTrace();\r
2436 }\r
2437\r
2438 }\r
2439 \r
1800d80f 2440 private String listToString(List l) {\r
a13899c5 2441 if (l == null) {\r
2442 return null;\r
2443 }\r
2444 String s = " ";\r
2445 ListIterator li = l.listIterator();\r
2446 while(li.hasNext()) {\r
2447 s += li.next();\r
2448 s += " ";\r
2449 }\r
2450 return s.trim();\r
2451 }\r
e232295e 2452 \r
2453 private void removeElement(XmlObject o) {\r
2454 XmlCursor cursor = o.newCursor();\r
2455 cursor.removeXml();\r
2456 cursor.dispose();\r
2457 }\r
a13899c5 2458}\r
82961247 2459\r
2460class PcdItemTypeConflictException extends Exception {\r
2461\r
2462 /**\r
2463 * \r
2464 */\r
2465 private static final long serialVersionUID = 1L;\r
2466 private String details = null;\r
2467 \r
34c614e1 2468 PcdItemTypeConflictException(String pcdName, String info){\r
2469 ModuleIdentification mi = GlobalData.getModuleId(info);\r
2470 details = pcdName + " ItemType Conflicts with " + mi.getName() + " in Pkg " + mi.getPackage().getName();\r
82961247 2471 }\r
2472 \r
2473 public String getMessage() {\r
2474 return details;\r
2475 }\r
2476}\r
2477\r
2478class PcdDeclNotFound extends Exception {\r
2479\r
2480 /**\r
2481 * \r
2482 */\r
2483 private static final long serialVersionUID = 1L;\r
2484 private String details = null;\r
2485 \r
2486 PcdDeclNotFound(String info) {\r
4da2e625 2487 details = "PcdDeclNotFound: " + info;\r
82961247 2488 }\r
2489 \r
2490 public String getMessage() {\r
2491 return details;\r
2492 }\r
2493}\r
2494\r
2495class PcdValueMalFormed extends Exception {\r
2496\r
2497 /**\r
2498 * \r
2499 */\r
2500 private static final long serialVersionUID = 1L;\r
2501 private String details = null;\r
2502 \r
2503 PcdValueMalFormed(String info) {\r
4da2e625 2504 details = "PcdValueMalFormed: " + info;\r
82961247 2505 }\r
2506 \r
2507 public String getMessage() {\r
2508 return details;\r
2509 }\r
2510}\r