git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[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
26\r
27import javax.xml.namespace.QName;\r
28\r
29import org.apache.xmlbeans.XmlCursor;\r
30import org.apache.xmlbeans.XmlObject;\r
31import org.apache.xmlbeans.XmlOptions;\r
32import org.tianocore.AntTaskDocument;\r
33import org.tianocore.BuildOptionsDocument;\r
34import org.tianocore.DynamicPcdBuildDefinitionsDocument;\r
35import org.tianocore.FlashDefinitionFileDocument;\r
36import org.tianocore.FlashDeviceDefinitionsDocument;\r
37import org.tianocore.FlashDocument;\r
38import org.tianocore.FrameworkModulesDocument;\r
39import org.tianocore.FvRegionNameDocument;\r
40import org.tianocore.LibrariesDocument;\r
41import org.tianocore.ModuleSADocument;\r
42import org.tianocore.ModuleSurfaceAreaDocument;\r
43import org.tianocore.OptionDocument;\r
44import org.tianocore.OptionsDocument;\r
45import org.tianocore.PcdBuildDefinitionDocument;\r
46import org.tianocore.PcdCodedDocument;\r
47import org.tianocore.PcdDataTypes;\r
48import org.tianocore.PcdDeclarationsDocument;\r
49import org.tianocore.PcdItemTypes;\r
50import org.tianocore.PlatformDefinitionsDocument;\r
51import org.tianocore.PlatformSurfaceAreaDocument;\r
52import org.tianocore.FvImageTypes;\r
53import org.tianocore.FvImagesDocument;\r
54import org.tianocore.LicenseDocument;\r
55import org.tianocore.PlatformHeaderDocument;\r
56import org.tianocore.SkuInfoDocument;\r
57import org.tianocore.UserDefinedAntTasksDocument;\r
58import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;\r
59import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;\r
60import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r
61import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r
62\r
63/**\r
64 This class processes fpd file contents such as add remove xml elements. \r
65 @since PackageEditor 1.0\r
66**/\r
67public class FpdFileContents {\r
68\r
69 static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0";\r
70 \r
71 private PlatformSurfaceAreaDocument fpdd = null;\r
72 \r
73 private PlatformSurfaceAreaDocument.PlatformSurfaceArea fpdRoot = null;\r
74 \r
75 private PlatformHeaderDocument.PlatformHeader fpdHdr = null;\r
76 \r
77 private PlatformDefinitionsDocument.PlatformDefinitions fpdPlatformDefs = null;\r
78 \r
79 private FlashDocument.Flash fpdFlash = null;\r
80 \r
81 private BuildOptionsDocument.BuildOptions fpdBuildOpts = null;\r
82 \r
83 private FrameworkModulesDocument.FrameworkModules fpdFrameworkModules = null;\r
84 \r
85 private DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions fpdDynPcdBuildDefs = null;\r
86 \r
87 public static HashMap<String, ArrayList<String>> dynPcdMap = null;\r
88 \r
89 /**\r
90 * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings.\r
91 */\r
92 public void initDynPcdMap() {\r
93 if (dynPcdMap == null) {\r
94 dynPcdMap = new HashMap<String, ArrayList<String>>();\r
95 List<ModuleSADocument.ModuleSA> l = getfpdFrameworkModules().getModuleSAList();\r
96 if (l == null) {\r
97 return;\r
98 }\r
99 ListIterator<ModuleSADocument.ModuleSA> li = l.listIterator();\r
100 while (li.hasNext()) {\r
101 ModuleSADocument.ModuleSA msa = li.next();\r
102 if (msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null) {\r
103 continue;\r
104 }\r
105 String ModuleInfo = msa.getModuleGuid() + " " + msa.getModuleVersion() +\r
106 " " + msa.getPackageGuid() + " " + msa.getPackageVersion();\r
107 List<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lp = msa.getPcdBuildDefinition().getPcdDataList();\r
108 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData> lpi = lp.listIterator();\r
109 while (lpi.hasNext()) {\r
110 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = lpi.next();\r
111 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r
112 if (dynPcdMap.get(pcdKey) == null) {\r
113 ArrayList<String> al = new ArrayList<String>();\r
114 al.add(ModuleInfo + " " + pcdData.getItemType().toString());\r
115 dynPcdMap.put(pcdKey, al);\r
116 }\r
117 else{\r
118 dynPcdMap.get(pcdKey).add(ModuleInfo + " " + pcdData.getItemType().toString());\r
119 }\r
120 }\r
121 }\r
122 }\r
123 }\r
124 /**\r
125 Constructor to create a new spd file\r
126 **/\r
127 public FpdFileContents() {\r
128\r
129 fpdd = PlatformSurfaceAreaDocument.Factory.newInstance();\r
130 fpdRoot = fpdd.addNewPlatformSurfaceArea();\r
131\r
132 }\r
133\r
134 /**\r
135 Constructor for existing document object\r
136 @param psa\r
137 **/\r
138 public FpdFileContents(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd) {\r
139 fpdRoot = fpd;\r
140 fpdHdr = fpdRoot.getPlatformHeader();\r
141 fpdPlatformDefs = fpdRoot.getPlatformDefinitions();\r
142 fpdBuildOpts = fpdRoot.getBuildOptions();\r
143 fpdFrameworkModules = fpdRoot.getFrameworkModules();\r
144 fpdDynPcdBuildDefs = fpdRoot.getDynamicPcdBuildDefinitions();\r
145 fpdFlash = fpdRoot.getFlash();\r
146 }\r
147\r
148 /**\r
149 Constructor based on an existing spd file\r
150 \r
151 @param f Existing spd file\r
152 **/\r
153 public FpdFileContents(File f) {\r
154 try {\r
155 fpdd = PlatformSurfaceAreaDocument.Factory.parse(f);\r
156 fpdRoot = fpdd.getPlatformSurfaceArea();\r
157 } catch (Exception e) {\r
158 System.out.println(e.toString());\r
159 }\r
160 }\r
161 \r
162 public DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions getfpdDynPcdBuildDefs() {\r
163 if (fpdDynPcdBuildDefs == null){\r
164 fpdDynPcdBuildDefs = fpdRoot.addNewDynamicPcdBuildDefinitions();\r
165 }\r
166 return fpdDynPcdBuildDefs;\r
167 }\r
168 \r
169 public FrameworkModulesDocument.FrameworkModules getfpdFrameworkModules() {\r
170 if (fpdFrameworkModules == null){\r
171 fpdFrameworkModules = fpdRoot.addNewFrameworkModules();\r
172 }\r
173 return fpdFrameworkModules;\r
174 }\r
175 \r
176 public int getPlatformDefsSkuInfoCount(){\r
177 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
178 return 0;\r
179 }\r
180 return getfpdPlatformDefs().getSkuInfo().getUiSkuNameList().size();\r
181 }\r
182 \r
183 public void getPlatformDefsSkuInfos(String[][] saa){\r
184 if (getfpdPlatformDefs().getSkuInfo() == null || getfpdPlatformDefs().getSkuInfo().getUiSkuNameList() == null) {\r
185 return ;\r
186 }\r
187 \r
188 List<SkuInfoDocument.SkuInfo.UiSkuName> l = getfpdPlatformDefs().getSkuInfo().getUiSkuNameList();\r
189 ListIterator<SkuInfoDocument.SkuInfo.UiSkuName> li = l.listIterator();\r
190 int i = 0;\r
191 while(li.hasNext()) {\r
192 SkuInfoDocument.SkuInfo.UiSkuName sku = li.next();\r
193 saa[i][0] = sku.getSkuID()+"";\r
194 saa[i][1] = sku.getStringValue();\r
195 ++i;\r
196 }\r
197 }\r
198 \r
199 public int getFrameworkModulesCount() {\r
200 if (getfpdFrameworkModules().getModuleSAList() == null){\r
201 return 0;\r
202 }\r
203 return getfpdFrameworkModules().getModuleSAList().size();\r
204 }\r
205 \r
206 public void getFrameworkModulesInfo(String[][] saa) {\r
207 if (getFrameworkModulesCount() == 0){\r
208 return;\r
209 }\r
210 \r
211 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
212 int i = 0;\r
213 while(li.hasNext()) {\r
214 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
215 saa[i][1] = msa.getModuleGuid();\r
216 saa[i][2] = msa.getModuleVersion();\r
217 \r
218 saa[i][3] = msa.getPackageGuid();\r
219 saa[i][4] = msa.getPackageVersion();\r
220// saa[i][4] = listToString(msa.getSupArchList());\r
221 ++i;\r
222 }\r
223 }\r
224 \r
225 public ModuleSADocument.ModuleSA getModuleSA(String key) {\r
226 String[] s = key.split(" ");\r
227 if (getfpdFrameworkModules().getModuleSAList() == null) {\r
228 return null;\r
229 }\r
230 ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator();\r
231 while(li.hasNext()) {\r
232 ModuleSADocument.ModuleSA msa = (ModuleSADocument.ModuleSA)li.next();\r
233 if (msa.getModuleGuid().equals(s[0]) && msa.getModuleVersion().equals(s[1])\r
234 && msa.getPackageGuid().equals(s[2]) && msa.getPackageVersion().equals(s[3])) {\r
235 \r
236 return msa;\r
237 }\r
238 }\r
239 return null;\r
240 }\r
241 public void removeModuleSA(int i) {\r
242 XmlObject o = getfpdFrameworkModules();\r
243 if (o == null) {\r
244 return;\r
245 }\r
246 \r
247 XmlCursor cursor = o.newCursor();\r
248 if (cursor.toFirstChild()) {\r
249 for (int j = 0; j < i; ++j) {\r
250 cursor.toNextSibling();\r
251 }\r
252 //\r
253 // remove pcd from dynPcdMap, if DynamicPcdBuildData exists, remove them too.\r
254 //\r
255 ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)cursor.getObject();\r
256 String moduleInfo = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() + " " +\r
257 moduleSa.getPackageGuid()+ " " + moduleSa.getPackageVersion();\r
258 PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef = moduleSa.getPcdBuildDefinition();\r
259 if (pcdBuildDef != null) {\r
260 maintainDynPcdMap(pcdBuildDef, moduleInfo);\r
261 }\r
262 cursor.removeXml();\r
263 }\r
264 cursor.dispose();\r
265 }\r
266 \r
267 private void maintainDynPcdMap(PcdBuildDefinitionDocument.PcdBuildDefinition o, String moduleInfo) {\r
268 XmlCursor cursor = o.newCursor();\r
269 boolean fromLibInstance = false;\r
270 if (!cursor.toFirstChild()){\r
271 return;\r
272 }\r
273 //\r
274 // deal with first child, same process in the while loop below for siblings.\r
275 //\r
276 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
277 String pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r
278 ArrayList<String> al = dynPcdMap.get(pcdKey);\r
279 for(int i = 0; i < al.size(); ++i){\r
280 if (al.get(i).startsWith(moduleInfo)){\r
281 fromLibInstance = true;\r
282 break;\r
283 }\r
284 }\r
285 al.remove(moduleInfo + " " + pcdData.getItemType().toString());\r
286 if (al.size() == 0) {\r
287 dynPcdMap.remove(pcdKey);\r
288 }\r
289 \r
290 if (pcdData.getItemType().toString().equals("DYNAMIC")) {\r
291 if (dynPcdMap.get(pcdKey) == null) {\r
292 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());\r
293 }\r
294 }\r
295 if (fromLibInstance){\r
296 cursor.removeXml();\r
297 }\r
298 while(cursor.toNextSibling()) {\r
299 fromLibInstance = false;\r
300 pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject();\r
301 //\r
302 // remove each pcd record from dynPcdMap\r
303 //\r
304 pcdKey = pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName();\r
305 al = dynPcdMap.get(pcdKey);\r
306 for(int i = 0; i < al.size(); ++i){\r
307 if (al.get(i).startsWith(moduleInfo)){\r
308 fromLibInstance = true;\r
309 break;\r
310 }\r
311 }\r
312 al.remove(moduleInfo + " " + pcdData.getItemType().toString());\r
313 if (al.size() == 0) {\r
314 dynPcdMap.remove(pcdKey);\r
315 }\r
316 \r
317 if (pcdData.getItemType().toString().equals("DYNAMIC")) {\r
318 //\r
319 // First check whether this is the only consumer of this dyn pcd.\r
320 //\r
321 if (dynPcdMap.get(pcdKey) == null) {\r
322 //\r
323 // delete corresponding entry in DynamicPcdBuildData\r
324 //\r
325 removeDynamicPcdBuildData(pcdData.getCName(), pcdData.getTokenSpaceGuidCName());\r
326 }\r
327 }\r
328 if (fromLibInstance){\r
329 cursor.removeXml();\r
330 }\r
331 }\r
332 }\r
333 //\r
334 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"\r
335 //\r
336 public int getPcdDataCount(String key){\r
337 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
338 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
339 return 0;\r
340 }\r
341 return msa.getPcdBuildDefinition().getPcdDataList().size();\r
342 }\r
343 \r
344 public void getPcdData(String key, String[][] saa) {\r
345 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
346 if (msa == null || msa.getPcdBuildDefinition() == null || msa.getPcdBuildDefinition().getPcdDataList() == null){\r
347 return;\r
348 }\r
349 ListIterator<PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData>li = msa.getPcdBuildDefinition().getPcdDataList().listIterator();\r
350 for (int i = 0; i < saa.length; ++i) {\r
351 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = li.next();\r
352 saa[i][0] = pcdData.getCName();\r
353 saa[i][1] = pcdData.getTokenSpaceGuidCName();\r
354 saa[i][2] = pcdData.getItemType().toString();\r
355 saa[i][3] = pcdData.getToken().toString();\r
356 saa[i][4] = pcdData.getDatumType().toString();\r
357 saa[i][5] = pcdData.getValue();\r
358 \r
359 }\r
360 }\r
361 //\r
362 // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer"\r
363 //\r
364 public int getLibraryInstancesCount(String key) {\r
365 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
366 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r
367 return 0;\r
368 }\r
369 return msa.getLibraries().getInstanceList().size();\r
370 }\r
371 \r
372 public void getLibraryInstances(String key, String[][] saa){\r
373 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
374 if (msa == null || msa.getLibraries() == null || msa.getLibraries().getInstanceList() == null){\r
375 return ;\r
376 }\r
377 \r
378 ListIterator<LibrariesDocument.Libraries.Instance> li = msa.getLibraries().getInstanceList().listIterator();\r
379 for (int i = 0; i < saa.length; ++i) {\r
380 LibrariesDocument.Libraries.Instance instance = li.next();\r
381 saa[i][1] = instance.getModuleGuid();\r
382 saa[i][2] = instance.getModuleVersion();\r
383 saa[i][3] = instance.getPackageGuid();\r
384 saa[i][4] = instance.getPackageVersion();\r
385 }\r
386 }\r
387 \r
388 public void removeLibraryInstances(String key) {\r
389 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
390 if (msa == null || msa.getLibraries() == null){\r
391 return ;\r
392 }\r
393 \r
394 XmlCursor cursor = msa.getLibraries().newCursor();\r
395 cursor.removeXml();\r
396 cursor.dispose();\r
397 }\r
398 \r
399 public void genLibraryInstance(String mg, String mv, String pg, String pv, String key) {\r
400 ModuleSADocument.ModuleSA msa = getModuleSA(key);\r
401 if (msa == null){\r
402 msa = getfpdFrameworkModules().addNewModuleSA();\r
403 }\r
404 LibrariesDocument.Libraries libs = msa.getLibraries();\r
405 if(libs == null){\r
406 libs = msa.addNewLibraries();\r
407 }\r
408 \r
409 LibrariesDocument.Libraries.Instance instance = libs.addNewInstance();\r
410 instance.setModuleGuid(mg);\r
411 instance.setModuleVersion(mv);\r
412 instance.setPackageGuid(pg);\r
413 instance.setPackageVersion(pv);\r
414 \r
415 }\r
416 /**add pcd information of module mi to a ModuleSA. \r
417 * @param mi\r
418 * @param moduleSa if null, generate a new ModuleSA.\r
419 */\r
420 public void addFrameworkModulesPcdBuildDefs(ModuleIdentification mi, ModuleSADocument.ModuleSA moduleSa){\r
421 //ToDo add Arch filter\r
422 \r
423 try {\r
424 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
425 if (msa.getPcdCoded() == null) {\r
426 return;\r
427 }\r
428 if (moduleSa == null) {\r
429 moduleSa = genModuleSA(mi);\r
430 }\r
431 Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
432 m.put("ModuleSurfaceArea", msa);\r
433 SurfaceAreaQuery.setDoc(m);\r
434 PackageIdentification[] depPkgs = SurfaceAreaQuery.getDependencePkg(null);\r
435 //\r
436 // Implementing InitializePlatformPcdBuildDefinitions\r
437 //\r
438 List<PcdCodedDocument.PcdCoded.PcdEntry> l = msa.getPcdCoded().getPcdEntryList();\r
439 ListIterator li = l.listIterator();\r
440 while(li.hasNext()) {\r
441 PcdCodedDocument.PcdCoded.PcdEntry msaPcd = (PcdCodedDocument.PcdCoded.PcdEntry)li.next();\r
442 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = LookupPcdDeclaration(msaPcd, depPkgs);\r
443 if (spdPcd == null) {\r
444 //\r
445 // ToDo Error \r
446 //\r
447 break;\r
448 }\r
449 //\r
450 // AddItem to ModuleSA PcdBuildDefinitions\r
451 //\r
452 String defaultVal = msaPcd.getDefaultValue() == null ? spdPcd.getDefaultValue() : msaPcd.getDefaultValue();\r
453 genPcdData(msaPcd.getCName(), spdPcd.getToken(), msaPcd.getTokenSpaceGuidCName(), msaPcd.getPcdItemType().toString(), spdPcd.getDatumType()+"", defaultVal, moduleSa);\r
454 }\r
455 \r
456 }\r
457 catch (Exception e){\r
458 e.printStackTrace();\r
459 }\r
460 \r
461 }\r
462 \r
463 private PcdDeclarationsDocument.PcdDeclarations.PcdEntry LookupPcdDeclaration (PcdCodedDocument.PcdCoded.PcdEntry msaPcd, PackageIdentification[] depPkgs) {\r
464 \r
465 Map<String, XmlObject> m = new HashMap<String, XmlObject>();\r
466 PcdDeclarationsDocument.PcdDeclarations.PcdEntry spdPcd = null;\r
467 for (int i = 0; i < depPkgs.length; ++i) {\r
468 m.put("PackageSurfaceArea", GlobalData.getPackageXmlObject(depPkgs[i]));\r
469 SurfaceAreaQuery.setDoc(m);\r
470 XmlObject[] xo = SurfaceAreaQuery.getSpdPcdDeclarations();\r
471 if (xo == null) {\r
472 continue;\r
473 }\r
474 for (int j = 0; j < xo.length; ++j) {\r
475 spdPcd = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)xo[j];\r
476 if (msaPcd.getTokenSpaceGuidCName() == null) {\r
477 if (spdPcd.getCName().equals(msaPcd.getCName())) {\r
478 return spdPcd;\r
479 }\r
480 }\r
481 else{\r
482 if (spdPcd.getCName().equals(msaPcd.getCName()) && spdPcd.getTokenSpaceGuidCName().equals(msaPcd.getTokenSpaceGuidCName())) {\r
483 return spdPcd;\r
484 }\r
485 }\r
486 \r
487 }\r
488 \r
489 }\r
490 return null;\r
491 }\r
492 \r
493 private ModuleSADocument.ModuleSA genModuleSA (ModuleIdentification mi) {\r
494 PackageIdentification pi = GlobalData.getPackageForModule(mi);\r
495 ModuleSADocument.ModuleSA msa = getfpdFrameworkModules().addNewModuleSA();\r
496 msa.setModuleGuid(mi.getGuid());\r
497 msa.setModuleVersion(mi.getVersion());\r
498 msa.setPackageGuid(pi.getGuid());\r
499 msa.setPackageVersion(pi.getVersion());\r
500 \r
501 return msa;\r
502 }\r
503 \r
504 private void genPcdData (String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal, ModuleSADocument.ModuleSA moduleSa) {\r
505 if (moduleSa.getPcdBuildDefinition() == null){\r
506 moduleSa.addNewPcdBuildDefinition();\r
507 }\r
508 //\r
509 // constructe pcd to modulesa mapping first.\r
510 // Attention : for any error condition, remove from map this pcd.\r
511 //\r
512 ArrayList<String> pcdConsumer = LookupPlatformPcdData(cName + " " + tsGuid);\r
513 if (pcdConsumer == null) {\r
514 pcdConsumer = new ArrayList<String>();\r
515 }\r
516 String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() \r
517 + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() \r
518 + " " + itemType;\r
519 pcdConsumer.add(listValue);\r
520 dynPcdMap.put(cName + " " + tsGuid, pcdConsumer);\r
521 //\r
522 // Special dynamic type, if this pcd already exists in other ModuleSA\r
523 //\r
524 if (itemType.equals("DYNAMIC")) {\r
525 \r
526 ListIterator li = pcdConsumer.listIterator();\r
527 while(li.hasNext()) {\r
528 String value = li.next().toString();\r
529 String[] valuePart= value.split(" ");\r
530 if (!valuePart[4].equals("DYNAMIC")) {\r
531 //ToDo error for same pcd, other type than dynamic\r
532 pcdConsumer.remove(listValue);\r
533 return;\r
534 }\r
535 }\r
536 }\r
537 else {\r
538 ListIterator li = pcdConsumer.listIterator();\r
539 while(li.hasNext()) {\r
540 String value = li.next().toString();\r
541 String[] valuePart= value.split(" ");\r
542 if (valuePart[4].equals("DYNAMIC")) {\r
543 //ToDo error for same pcd, other type than non-dynamic\r
544 pcdConsumer.remove(listValue);\r
545 return;\r
546 }\r
547 }\r
548 }\r
549 \r
550 PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData fpdPcd = moduleSa.getPcdBuildDefinition().addNewPcdData();\r
551 fpdPcd.setCName(cName);\r
552 fpdPcd.setToken(token);\r
553 fpdPcd.setTokenSpaceGuidCName(tsGuid);\r
554 fpdPcd.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
555 fpdPcd.setItemType(PcdItemTypes.Enum.forString(itemType));\r
556 \r
557 if (itemType.equals("DYNAMIC") || itemType.equals("DYNAMIC_EX")) {\r
558 ArrayList<String> al = LookupDynamicPcdBuildDefinition(cName + " " + tsGuid);\r
559 //\r
560 // if only one module mapped to this pcd, then the one is myself. so no other module mapped.\r
561 // so need to add one dyn pcd.\r
562 //\r
563 if (al.size() == 1) {\r
564 addDynamicPcdBuildData(cName, token, tsGuid, itemType, dataType, defaultVal);\r
565 }\r
566 }\r
567 else {\r
568 if (defaultVal != null){\r
569 fpdPcd.setValue(defaultVal);\r
570 }\r
571 else {\r
572 if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {\r
573 fpdPcd.setValue("0");\r
574 }\r
575 if (dataType.equals("BOOLEAN")){\r
576 fpdPcd.setValue("false");\r
577 }\r
578 if (dataType.equals("VOID*")) {\r
579 fpdPcd.setValue("");\r
580 }\r
581 }\r
582 if (dataType.equals("UINT8")){\r
583 fpdPcd.setMaxDatumSize(1);\r
584 }\r
585 if (dataType.equals("UINT16")) {\r
586 fpdPcd.setMaxDatumSize(2);\r
587 }\r
588 if (dataType.equals("UINT32")) {\r
589 fpdPcd.setMaxDatumSize(4);\r
590 }\r
591 if (dataType.equals("UINT64")){\r
592 fpdPcd.setMaxDatumSize(8);\r
593 }\r
594 if (dataType.equals("BOOLEAN")){\r
595 fpdPcd.setMaxDatumSize(1);\r
596 }\r
597 if (dataType.equals("VOID*")) {\r
598 int maxSize = setMaxSizeForPointer(fpdPcd.getValue());\r
599 fpdPcd.setMaxDatumSize(maxSize);\r
600 }\r
601 }\r
602 }\r
603 \r
604 private int setMaxSizeForPointer(String datum) {\r
605 if (datum == null) {\r
606 return 0;\r
607 }\r
608 char ch = datum.charAt(0);\r
609 int start, end;\r
610 String strValue;\r
611 //\r
612 // For void* type PCD, only three datum is support:\r
613 // 1) Unicode: string with start char is "L"\r
614 // 2) Ansci: String is ""\r
615 // 3) byte array: String start char "{"\r
616 // \r
617 if (ch == 'L') {\r
618 start = datum.indexOf('\"');\r
619 end = datum.lastIndexOf('\"');\r
620 if ((start > end) || \r
621 (end > datum.length())||\r
622 ((start == end) && (datum.length() > 0))) {\r
623 //ToDo Error handling here\r
624 }\r
625\r
626 strValue = datum.substring(start + 1, end);\r
627 return strValue.length() * 2;\r
628 } else if (ch == '\"'){\r
629 start = datum.indexOf('\"');\r
630 end = datum.lastIndexOf('\"');\r
631 if ((start > end) || \r
632 (end > datum.length())||\r
633 ((start == end) && (datum.length() > 0))) {\r
634 \r
635 }\r
636 strValue = datum.substring(start + 1, end);\r
637 return strValue.length();\r
638 } else if (ch =='{') {\r
639 String[] strValueArray;\r
640\r
641 start = datum.indexOf('{');\r
642 end = datum.lastIndexOf('}');\r
643 strValue = datum.substring(start + 1, end);\r
644 strValue = strValue.trim();\r
645 if (strValue.length() == 0) {\r
646 return 0;\r
647 }\r
648 strValueArray = strValue.split(",");\r
649 for (int index = 0; index < strValueArray.length; index ++) {\r
650 Integer value = Integer.decode(strValueArray[index].trim());\r
651 \r
652 if (value > 0xFF) {\r
653// "[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
654// "it is byte array in fact. But the element of %s exceed the byte range",\r
655 \r
656 }\r
657 }\r
658 return strValueArray.length;\r
659\r
660\r
661 } else {\r
662// "[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
663// "1) UNICODE string: like L\"xxxx\";\r\n"+\r
664// "2) ANSIC string: like \"xxx\";\r\n"+\r
665// "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
666// "but the datum in seems does not following above format!",\r
667 return -1; \r
668 \r
669 }\r
670 }\r
671 \r
672 private ArrayList<String> LookupDynamicPcdBuildDefinition(String dynPcdKey) {\r
673 ArrayList<String> al = dynPcdMap.get(dynPcdKey);\r
674 \r
675 return al;\r
676 }\r
677 \r
678 private ArrayList<String> LookupPlatformPcdData(String pcdKey) {\r
679 \r
680 return dynPcdMap.get("pcdKey");\r
681 }\r
682 \r
683 public int getDynamicPcdBuildDataCount() {\r
684 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r
685 return 0;\r
686 }\r
687 return getfpdDynPcdBuildDefs().getPcdBuildDataList().size();\r
688 }\r
689 \r
690 public void getDynamicPcdBuildData(String[][] saa) {\r
691 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null) {\r
692 return ;\r
693 }\r
694 List<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> l = getfpdDynPcdBuildDefs().getPcdBuildDataList();\r
695 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData> li = l.listIterator();\r
696 int i = 0;\r
697 while(li.hasNext()) {\r
698 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcd = li.next();\r
699 saa[i][0] = dynPcd.getCName();\r
700 saa[i][1] = dynPcd.getToken().toString();\r
701 saa[i][2] = dynPcd.getTokenSpaceGuidCName();\r
702 saa[i][3] = dynPcd.getMaxDatumSize()+"";\r
703 saa[i][4] = dynPcd.getDatumType().toString();\r
704 \r
705 ++i;\r
706 }\r
707 }\r
708 \r
709 private void addDynamicPcdBuildData(String cName, Object token, String tsGuid, String itemType, String dataType, String defaultVal) {\r
710 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData dynPcdData = getfpdDynPcdBuildDefs().addNewPcdBuildData();\r
711 dynPcdData.setItemType(PcdItemTypes.Enum.forString(itemType));\r
712 dynPcdData.setCName(cName);\r
713 dynPcdData.setToken(token);\r
714 dynPcdData.setTokenSpaceGuidCName(tsGuid);\r
715 dynPcdData.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
716 \r
717 BigInteger bigInt = new BigInteger("0");\r
718 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = dynPcdData.addNewSkuInfo();\r
719 skuInfo.setSkuId(bigInt);\r
720 if (defaultVal != null){\r
721 skuInfo.setValue(defaultVal);\r
722 }\r
723 else {\r
724 if (dataType.equals("UINT8")){\r
725 skuInfo.setValue("0");\r
726 }\r
727 if (dataType.equals("UINT16")) {\r
728 skuInfo.setValue("0");\r
729 }\r
730 if (dataType.equals("UINT32")) {\r
731 skuInfo.setValue("0");\r
732 }\r
733 if (dataType.equals("UINT64")){\r
734 skuInfo.setValue("0");\r
735 }\r
736 if (dataType.equals("BOOLEAN")){\r
737 skuInfo.setValue("false");\r
738 }\r
739 if (dataType.equals("VOID*")) {\r
740 skuInfo.setValue("");\r
741 }\r
742 }\r
743 if (dataType.equals("UINT8")){\r
744 dynPcdData.setMaxDatumSize(1);\r
745 }\r
746 if (dataType.equals("UINT16")) {\r
747 dynPcdData.setMaxDatumSize(2);\r
748 }\r
749 if (dataType.equals("UINT32")) {\r
750 dynPcdData.setMaxDatumSize(4);\r
751 }\r
752 if (dataType.equals("UINT64")){\r
753 dynPcdData.setMaxDatumSize(8);\r
754 }\r
755 if (dataType.equals("BOOLEAN")){\r
756 dynPcdData.setMaxDatumSize(1);\r
757 }\r
758 if (dataType.equals("VOID*")) {\r
759 int maxSize = setMaxSizeForPointer(defaultVal);\r
760 dynPcdData.setMaxDatumSize(maxSize);\r
761 }\r
762 }\r
763 \r
764 private void removeDynamicPcdBuildData(String cName, String tsGuid) {\r
765 XmlObject o = getfpdDynPcdBuildDefs();\r
766 \r
767 XmlCursor cursor = o.newCursor();\r
768 if (cursor.toFirstChild()) {\r
769 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdBuildData = \r
770 (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
771 while (!(pcdBuildData.getCName().equals(cName) && pcdBuildData.getTokenSpaceGuidCName().equals(tsGuid))) {\r
772 cursor.toNextSibling();\r
773 pcdBuildData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
774 }\r
775 \r
776 cursor.removeXml();\r
777 }\r
778 cursor.dispose();\r
779 }\r
780 //\r
781 // Get the Sku Info count of ith dyn pcd element.\r
782 //\r
783 public int getDynamicPcdSkuInfoCount(int i){\r
784 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
785 return 0;\r
786 }\r
787 \r
788 int skuInfoCount = 0;\r
789 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
790 if (cursor.toFirstChild()) {\r
791 for (int j = 0; j < i; ++j) {\r
792 cursor.toNextSibling();\r
793 }\r
794 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
795 if (pcdData.getSkuInfoList() == null) {\r
796 skuInfoCount = 0;\r
797 }\r
798 else {\r
799 skuInfoCount = pcdData.getSkuInfoList().size();\r
800 }\r
801 }\r
802 cursor.dispose();\r
803 return skuInfoCount;\r
804 }\r
805 \r
806 public void getDynamicPcdSkuInfos(int i, String[][] saa){\r
807 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
808 return;\r
809 }\r
810 \r
811 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
812 if (cursor.toFirstChild()) {\r
813 for (int j = 0; j < i; ++j) {\r
814 cursor.toNextSibling();\r
815 }\r
816 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
817 if (pcdData.getSkuInfoList() == null) {\r
818 cursor.dispose();\r
819 return;\r
820 }\r
821 else {\r
822 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
823 int k = 0;\r
824 while (li.hasNext()) {\r
825 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
826 saa[k][0] = skuInfo.getSkuId()+"";\r
827 saa[k][1] = skuInfo.getVariableName();\r
828 saa[k][2] = skuInfo.getVariableGuid();\r
829 saa[k][3] = skuInfo.getVariableOffset();\r
830 saa[k][4] = skuInfo.getHiiDefaultValue();\r
831 saa[k][5] = skuInfo.getVpdOffset();\r
832 saa[k][6] = skuInfo.getValue();\r
833 ++k;\r
834 }\r
835 \r
836 }\r
837 }\r
838 cursor.dispose();\r
839 \r
840 }\r
841 \r
842 public String getDynamicPcdBuildDataValue(int i){\r
843 String value = null;\r
844 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
845 return value;\r
846 }\r
847 \r
848 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
849 if (cursor.toFirstChild()) {\r
850 for (int j = 0; j < i; ++j) {\r
851 cursor.toNextSibling();\r
852 }\r
853 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
854 if (pcdData.getSkuInfoList() == null) {\r
855 value = null;\r
856 }\r
857 else {\r
858 value = pcdData.getSkuInfoArray(0).getValue();\r
859 }\r
860 }\r
861 cursor.dispose();\r
862 return value;\r
863 }\r
864 \r
865 public String getDynamicPcdBuildDataVpdOffset(int i){\r
866 String vpdOffset = null;\r
867 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
868 return vpdOffset;\r
869 }\r
870 \r
871 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
872 if (cursor.toFirstChild()) {\r
873 for (int j = 0; j < i; ++j) {\r
874 cursor.toNextSibling();\r
875 }\r
876 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
877 if (pcdData.getSkuInfoList() == null) {\r
878 vpdOffset = null;\r
879 }\r
880 else {\r
881 vpdOffset = pcdData.getSkuInfoArray(0).getVpdOffset();\r
882 }\r
883 }\r
884 cursor.dispose();\r
885 return vpdOffset;\r
886 }\r
887 \r
888 public void removeDynamicPcdBuildDataSkuInfo(int i) {\r
889 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
890 return;\r
891 }\r
892 \r
893 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
894 if (cursor.toFirstChild()) {\r
895 for (int j = 0; j < i; ++j) {\r
896 cursor.toNextSibling();\r
897 }\r
898 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
899 if (pcdData.getSkuInfoList() == null) {\r
900 cursor.dispose();\r
901 return;\r
902 }\r
903 else {\r
904 QName qSkuInfo = new QName(xmlNs, "SkuInfo");\r
905 cursor.toChild(qSkuInfo);\r
906 cursor.removeXml();\r
907 }\r
908 }\r
909 cursor.dispose();\r
910 }\r
911 //\r
912 // generate sku info for ith dyn pcd build data.\r
913 //\r
914 public void genDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
915 String hiiDefault, String vpdOffset, String value, int i) {\r
916 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
917 return;\r
918 }\r
919 \r
920 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
921 if (cursor.toFirstChild()) {\r
922 for (int j = 0; j < i; ++j) {\r
923 cursor.toNextSibling();\r
924 }\r
925 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
926 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = pcdData.addNewSkuInfo();\r
927 skuInfo.setSkuId(new BigInteger(id));\r
928 if (varName != null){\r
929 skuInfo.setVariableName(varName);\r
930 skuInfo.setVariableGuid(varGuid);\r
931 skuInfo.setVariableOffset(varOffset);\r
932 skuInfo.setHiiDefaultValue(hiiDefault);\r
933 }\r
934 else if (vpdOffset != null){\r
935 skuInfo.setVpdOffset(vpdOffset);\r
936 }\r
937 else{\r
938 skuInfo.setValue(value);\r
939 }\r
940 }\r
941 }\r
942 \r
943 public void updateDynamicPcdBuildDataSkuInfo(String id, String varName, String varGuid, String varOffset, \r
944 String hiiDefault, String vpdOffset, String value, int i){\r
945 if (getfpdDynPcdBuildDefs().getPcdBuildDataList() == null || getfpdDynPcdBuildDefs().getPcdBuildDataList().size() == 0) {\r
946 return;\r
947 }\r
948 \r
949 XmlCursor cursor = getfpdDynPcdBuildDefs().newCursor();\r
950 if (cursor.toFirstChild()) {\r
951 for (int j = 0; j < i; ++j) {\r
952 cursor.toNextSibling();\r
953 }\r
954 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData pcdData = (DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData)cursor.getObject();\r
955 ListIterator<DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo> li = pcdData.getSkuInfoList().listIterator();\r
956 while (li.hasNext()) {\r
957 DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo skuInfo = li.next();\r
958 if (skuInfo.getSkuId().toString().equals(id)){\r
959 if (varName != null){\r
960 skuInfo.setVariableName(varName);\r
961 skuInfo.setVariableGuid(varGuid);\r
962 skuInfo.setVariableOffset(varOffset);\r
963 skuInfo.setHiiDefaultValue(hiiDefault);\r
964 }\r
965 else if (vpdOffset != null){\r
966 skuInfo.setVpdOffset(vpdOffset);\r
967 }\r
968 else{\r
969 skuInfo.setValue(value);\r
970 }\r
971 break;\r
972 }\r
973 }\r
974 }\r
975 }\r
976 \r
977 public void removePcdDataFromLibraryInstance(String moduleKey, String libInstanceKey){\r
978 ModuleSADocument.ModuleSA moduleSa = getModuleSA(moduleKey);\r
979 //\r
980 // should better maintain pcd from lib instance only, but maintain all is acceptable now. \r
981 //\r
982 maintainDynPcdMap(moduleSa.getPcdBuildDefinition(), libInstanceKey);\r
983 \r
984 }\r
985 \r
986 public BuildOptionsDocument.BuildOptions getfpdBuildOpts() {\r
987 if (fpdBuildOpts == null) {\r
988 fpdBuildOpts = fpdRoot.addNewBuildOptions();\r
989 }\r
990 return fpdBuildOpts;\r
991 }\r
992 \r
993 public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) {\r
994 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
995 if (udats == null) {\r
996 udats = getfpdBuildOpts().addNewUserDefinedAntTasks();\r
997 }\r
998 \r
999 AntTaskDocument.AntTask at = udats.addNewAntTask();\r
1000 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1001 }\r
1002 \r
1003 private void setBuildOptionsUserDefAntTask(String id, String fileName, String execOrder, AntTaskDocument.AntTask at) {\r
1004 at.setId(new Integer(id));\r
1005 if (fileName != null){\r
1006 at.setFilename(fileName);\r
1007 }\r
1008 else {\r
1009 at.setAntCmdOptions(execOrder);\r
1010 }\r
1011 }\r
1012 \r
1013 public void removeBuildOptionsUserDefAntTask(int i) {\r
1014 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1015 if (o == null) {\r
1016 return;\r
1017 }\r
1018 XmlCursor cursor = o.newCursor();\r
1019 if (cursor.toFirstChild()) {\r
1020 for (int j = 0; j < i; ++j) {\r
1021 cursor.toNextSibling();\r
1022 }\r
1023 cursor.removeXml();\r
1024 }\r
1025 cursor.dispose();\r
1026 }\r
1027 \r
1028 public void updateBuildOptionsUserDefAntTask(int i, String id, String fileName, String execOrder){\r
1029 XmlObject o = getfpdBuildOpts().getUserDefinedAntTasks();\r
1030 if (o == null) {\r
1031 return;\r
1032 }\r
1033 XmlCursor cursor = o.newCursor();\r
1034 if (cursor.toFirstChild()) {\r
1035 for (int j = 0; j < i; ++j) {\r
1036 cursor.toNextSibling();\r
1037 }\r
1038 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)cursor.getObject();\r
1039 setBuildOptionsUserDefAntTask(id, fileName, execOrder, at);\r
1040 }\r
1041 cursor.dispose();\r
1042 }\r
1043 \r
1044 public int getBuildOptionsUserDefAntTaskCount() {\r
1045 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1046 if (udats == null || udats.getAntTaskList() == null) {\r
1047 return 0;\r
1048 }\r
1049 \r
1050 return udats.getAntTaskList().size();\r
1051 }\r
1052 \r
1053 public void getBuildOptionsUserDefAntTasks(String[][] saa) {\r
1054 UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks();\r
1055 if (udats == null || udats.getAntTaskList() == null) {\r
1056 return ;\r
1057 }\r
1058 \r
1059 List<AntTaskDocument.AntTask> l = udats.getAntTaskList();\r
1060 ListIterator li = l.listIterator();\r
1061 int i = 0;\r
1062 while (li.hasNext()) {\r
1063 AntTaskDocument.AntTask at = (AntTaskDocument.AntTask)li.next();\r
1064 saa[i][0] = at.getId() + "";\r
1065 saa[i][1] = saa[i][2] = "";\r
1066 if (at.getFilename() != null){\r
1067 saa[i][1] = at.getFilename();\r
1068 }\r
1069 if (at.getAntCmdOptions() != null) {\r
1070 saa[i][2] = at.getAntCmdOptions();\r
1071 }\r
1072 ++i;\r
1073 }\r
1074 }\r
1075 public void genBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {\r
1076 OptionsDocument.Options opts = getfpdBuildOpts().getOptions();\r
1077 if (opts == null) {\r
1078 opts = getfpdBuildOpts().addNewOptions();\r
1079 }\r
1080 OptionDocument.Option opt = opts.addNewOption();\r
1081 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1082 }\r
1083 \r
1084 private void setBuildOptionsOpt(String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents, OptionDocument.Option opt){\r
1085 opt.setStringValue(contents);\r
1086// opt.setBuildTargets(buildTargets);\r
1087 opt.setToolChainFamily(toolChain);\r
1088 opt.setTagName(tagName);\r
1089 opt.setToolCode(toolCmd);\r
1090 String[] s = archList.split(" ");\r
1091 ArrayList<String> al = new ArrayList<String>();\r
1092 for (int i = 0; i < s.length; ++i) {\r
1093 al.add(s[i]);\r
1094 }\r
1095 opt.setSupArchList(al);\r
1096 }\r
1097 \r
1098 public void removeBuildOptionsOpt(int i){\r
1099 \r
1100 XmlObject o = getfpdBuildOpts().getOptions();\r
1101 if (o == null) {\r
1102 return;\r
1103 }\r
1104 \r
1105 XmlCursor cursor = o.newCursor();\r
1106 if (cursor.toFirstChild()) {\r
1107 for (int j = 0; j < i; ++j) {\r
1108 cursor.toNextSibling();\r
1109 }\r
1110 cursor.removeXml();\r
1111 }\r
1112 cursor.dispose();\r
1113 }\r
1114 \r
1115 public void updateBuildOptionsOpt(int i, String buildTargets, String toolChain, String tagName, String toolCmd, String archList, String contents) {\r
1116 XmlObject o = getfpdBuildOpts().getOptions();\r
1117 if (o == null) {\r
1118 return;\r
1119 }\r
1120 \r
1121 XmlCursor cursor = o.newCursor();\r
1122 if (cursor.toFirstChild()) {\r
1123 for (int j = 0; j < i; ++j) {\r
1124 cursor.toNextSibling();\r
1125 }\r
1126 OptionDocument.Option opt = (OptionDocument.Option)cursor.getObject();\r
1127 setBuildOptionsOpt(buildTargets, toolChain, tagName, toolCmd, archList, contents, opt);\r
1128 }\r
1129 cursor.dispose();\r
1130 }\r
1131 \r
1132 public int getBuildOptionsOptCount(){\r
1133 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1134 return 0;\r
1135 }\r
1136 return getfpdBuildOpts().getOptions().getOptionList().size();\r
1137 }\r
1138 \r
1139 public void getBuildOptionsOpts(String[][] saa) {\r
1140 if (getfpdBuildOpts().getOptions() == null || getfpdBuildOpts().getOptions().getOptionList() == null) {\r
1141 return ;\r
1142 }\r
1143 \r
1144 List<OptionDocument.Option> lOpt = getfpdBuildOpts().getOptions().getOptionList();\r
1145 ListIterator li = lOpt.listIterator();\r
1146 int i = 0;\r
1147 while(li.hasNext()) {\r
1148 OptionDocument.Option opt = (OptionDocument.Option)li.next();\r
1149// saa[i][0] = opt.getBuildTargets();\r
1150 saa[i][1] = opt.getToolChainFamily();\r
1151 if (opt.getSupArchList() != null){\r
1152 Object[] archs = opt.getSupArchList().toArray();\r
1153 saa[i][2] = " ";\r
1154 for (int j = 0; j < archs.length; ++j){\r
1155 saa[i][2] += archs[j];\r
1156 saa[i][2] += " ";\r
1157 }\r
1158 saa[i][2] = saa[i][2].trim();\r
1159 }\r
1160 saa[i][3] = opt.getToolCode();\r
1161 saa[i][4] = opt.getTagName();\r
1162 saa[i][5] = opt.getStringValue();\r
1163 \r
1164 ++i;\r
1165 }\r
1166 }\r
1167 \r
1168 public PlatformDefinitionsDocument.PlatformDefinitions getfpdPlatformDefs(){\r
1169 if (fpdPlatformDefs == null){\r
1170 fpdPlatformDefs = fpdRoot.addNewPlatformDefinitions();\r
1171 }\r
1172 return fpdPlatformDefs;\r
1173 }\r
1174 \r
1175 public FlashDocument.Flash getfpdFlash() {\r
1176 if (fpdFlash == null) {\r
1177 fpdFlash = fpdRoot.addNewFlash();\r
1178 }\r
1179 return fpdFlash;\r
1180 }\r
1181 \r
1182 public void genFlashDefinitionFile(String file) {\r
1183 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
1184 if (fdf == null) {\r
1185 fdf = getfpdFlash().addNewFlashDefinitionFile();\r
1186 }\r
1187 \r
1188 fdf.setStringValue(file);\r
1189 }\r
1190 \r
1191 public String getFlashDefinitionFile() {\r
1192 FlashDefinitionFileDocument.FlashDefinitionFile fdf = getfpdFlash().getFlashDefinitionFile();\r
1193 if (fdf == null) {\r
1194 return "";\r
1195 }\r
1196 \r
1197 return fdf.getStringValue();\r
1198 }\r
1199 \r
1200 \r
1201 \r
1202 public void genFvImagesNameValue(String name, String value) {\r
1203 \r
1204 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
1205 if (fi == null) {\r
1206 fi = getfpdFlash().addNewFvImages();\r
1207 }\r
1208 \r
1209 FvImagesDocument.FvImages.NameValue nv = fi.addNewNameValue();\r
1210 nv.setName(name);\r
1211 nv.setValue(value);\r
1212 }\r
1213 \r
1214 public void removeFvImagesNameValue(int i){\r
1215 \r
1216 XmlObject o = getfpdFlash().getFvImages();\r
1217 if (o == null) {\r
1218 return;\r
1219 }\r
1220 \r
1221 QName qNameValue = new QName(xmlNs, "NameValue");\r
1222 XmlCursor cursor = o.newCursor();\r
1223 if (cursor.toChild(qNameValue)) {\r
1224 for (int j = 0; j < i; ++j) {\r
1225 cursor.toNextSibling(qNameValue);\r
1226 }\r
1227 cursor.removeXml();\r
1228 }\r
1229 cursor.dispose();\r
1230 }\r
1231 \r
1232 public void updateFvImagesNameValue(int i, String name, String value){\r
1233 \r
1234 XmlObject o = getfpdFlash().getFvImages();\r
1235 if (o == null) {\r
1236 return;\r
1237 }\r
1238 \r
1239 QName qNameValue = new QName(xmlNs, "NameValue");\r
1240 XmlCursor cursor = o.newCursor();\r
1241 if (cursor.toChild(qNameValue)) {\r
1242 for (int j = 0; j < i; ++j) {\r
1243 cursor.toNextSibling(qNameValue);\r
1244 }\r
1245 FvImagesDocument.FvImages.NameValue nv = (FvImagesDocument.FvImages.NameValue)cursor.getObject();\r
1246 nv.setName(name);\r
1247 nv.setValue(value);\r
1248 }\r
1249 cursor.dispose();\r
1250 }\r
1251 \r
1252 public int getFvImagesNameValueCount() {\r
1253 \r
1254 FvImagesDocument.FvImages fi = null;\r
1255 if ((fi = getfpdFlash().getFvImages()) == null || fi.getNameValueList() == null) {\r
1256 return 0;\r
1257 }\r
1258 return fi.getNameValueList().size();\r
1259 }\r
1260 \r
1261 public void getFvImagesNameValues(String[][] nv) {\r
1262 \r
1263 FvImagesDocument.FvImages fi = getfpdFlash().getFvImages();\r
1264 if (fi == null){\r
1265 return;\r
1266 }\r
1267 List<FvImagesDocument.FvImages.NameValue> l = fi.getNameValueList();\r
1268 int i = 0;\r
1269 ListIterator li = l.listIterator();\r
1270 while (li.hasNext()) {\r
1271 FvImagesDocument.FvImages.NameValue e = (FvImagesDocument.FvImages.NameValue) li\r
1272 .next();\r
1273 nv[i][0] = e.getName();\r
1274 nv[i][1] = e.getValue();\r
1275 \r
1276 i++;\r
1277 }\r
1278 }\r
1279 \r
1280 public void genFvImagesFvImage(String[] names, String types, Map<String, String> options) {\r
1281 \r
1282 FvImagesDocument.FvImages fis = null;\r
1283 if ((fis = getfpdFlash().getFvImages()) == null) {\r
1284 fis = getfpdFlash().addNewFvImages();\r
1285 }\r
1286 \r
1287 //\r
1288 //gen FvImage with FvImageNames array\r
1289 //\r
1290 FvImagesDocument.FvImages.FvImage fi = fis.addNewFvImage();\r
1291 for (int i = 0; i < names.length; ++i) {\r
1292 fi.addFvImageNames(names[i]);\r
1293 }\r
1294 fi.setType(FvImageTypes.Enum.forString(types));\r
1295 if (options != null){\r
1296 setFvImagesFvImageFvImageOptions(options, fi);\r
1297 }\r
1298 }\r
1299 \r
1300 private void setFvImagesFvImageFvImageOptions(Map<String, String> options, FvImagesDocument.FvImages.FvImage fi){\r
1301 FvImagesDocument.FvImages.FvImage.FvImageOptions fio = fi.getFvImageOptions();\r
1302 if (fio == null){\r
1303 fio = fi.addNewFvImageOptions();\r
1304 }\r
1305 \r
1306 Set<String> key = options.keySet();\r
1307 Iterator<String> i = key.iterator();\r
1308 while (i.hasNext()) {\r
1309 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fio.addNewNameValue();\r
1310 String k = (String)i.next();\r
1311 nv.setName(k);\r
1312 nv.setValue((String)options.get(k));\r
1313 \r
1314 }\r
1315 \r
1316 }\r
1317 \r
1318 public void removeFvImagesFvImage(int i) {\r
1319 \r
1320 XmlObject o = getfpdFlash().getFvImages();\r
1321 if (o == null) {\r
1322 return;\r
1323 }\r
1324 \r
1325 QName qFvImage = new QName(xmlNs, "FvImage");\r
1326 XmlCursor cursor = o.newCursor();\r
1327 if (cursor.toChild(qFvImage)) {\r
1328 for (int j = 0; j < i; ++j) {\r
1329 cursor.toNextSibling(qFvImage);\r
1330 }\r
1331 cursor.removeXml();\r
1332 }\r
1333 cursor.dispose();\r
1334 }\r
1335 \r
1336 public void updateFvImagesFvImage(int i, String[] names, String types, Map<String, String> options){\r
1337 \r
1338 XmlObject o = getfpdFlash().getFvImages();\r
1339 if (o == null) {\r
1340 return;\r
1341 }\r
1342 XmlCursor cursor = o.newCursor();\r
1343 QName qFvImage = new QName(xmlNs, "FvImage");\r
1344 if (cursor.toChild(qFvImage)) {\r
1345 for (int j = 0; j < i; ++j) {\r
1346 cursor.toNextSibling(qFvImage);\r
1347 }\r
1348 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject();\r
1349 fi.setType(FvImageTypes.Enum.forString(types));\r
1350 \r
1351 //\r
1352 // remove old FvImageNames before adding new ones\r
1353 //\r
1354 QName qFvImageNames = new QName(xmlNs, "FvImageNames"); \r
1355 cursor.toChild(qFvImageNames);\r
1356 cursor.removeXml();\r
1357 while (cursor.toNextSibling(qFvImageNames)) {\r
1358 cursor.removeXml();\r
1359 }\r
1360 \r
1361 for (int k = 0; k < names.length; ++k) {\r
1362 fi.addFvImageNames(names[k]);\r
1363 }\r
1364 //\r
1365 // remove old FvImageOptions before adding new options\r
1366 //\r
1367 QName qFvImageOptions = new QName(xmlNs, "FvImageOptions");\r
1368 cursor.toNextSibling(qFvImageOptions);\r
1369 cursor.removeXml();\r
1370 \r
1371 setFvImagesFvImageFvImageOptions(options, fi);\r
1372 }\r
1373 cursor.dispose();\r
1374 }\r
1375 \r
1376 public int getFvImagesFvImageCount() {\r
1377 \r
1378 if (getfpdFlash().getFvImages() == null || getfpdFlash().getFvImages().getFvImageList() == null) {\r
1379 return 0;\r
1380 }\r
1381 return getfpdFlash().getFvImages().getFvImageList().size();\r
1382 }\r
1383 \r
1384 public void getFvImagesFvImages(String[][] saa, ArrayList<LinkedHashMap<String, String>> options) {\r
1385 \r
1386 if (getfpdFlash().getFvImages() == null) {\r
1387 return;\r
1388 }\r
1389 List<FvImagesDocument.FvImages.FvImage> l = getfpdFlash().getFvImages().getFvImageList();\r
1390 if (l == null) {\r
1391 return;\r
1392 }\r
1393 ListIterator li = l.listIterator();\r
1394 int i = 0;\r
1395 while(li.hasNext()) {\r
1396 FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)li.next();\r
1397 //\r
1398 // get FvImageNames array, space separated\r
1399 //\r
1400 List<String> lfn = fi.getFvImageNamesList();\r
1401 ListIterator lfni = lfn.listIterator();\r
1402 saa[i][0] = " ";\r
1403 while (lfni.hasNext()) {\r
1404 saa[i][0] += (String)lfni.next();\r
1405 saa[i][0] += " ";\r
1406 }\r
1407 saa[i][0] = saa[i][0].trim();\r
1408 \r
1409 saa[i][1] = fi.getType()+"";\r
1410 \r
1411 //\r
1412 // get FvImageOptions into Map[i]\r
1413 //\r
1414 FvImagesDocument.FvImages.FvImage.FvImageOptions fo = fi.getFvImageOptions();\r
1415 if (fo == null) {\r
1416 ++i;\r
1417 continue;\r
1418 }\r
1419 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> lnv = fo.getNameValueList();\r
1420 if (lnv == null || lnv.isEmpty()) {\r
1421 ++i;\r
1422 continue;\r
1423 }\r
1424 ListIterator lnvi = lnv.listIterator();\r
1425 while (lnvi.hasNext()) {\r
1426 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue)lnvi.next();\r
1427 Map<String, String> m = options.get(i);\r
1428 m.put(nv.getName(), nv.getValue());\r
1429 }\r
1430 \r
1431 ++i;\r
1432 }\r
1433 }\r
1434 \r
1435 /**\r
1436 Get platform header element\r
1437 @return PlatformHeaderDocument.PlatformHeader\r
1438 **/\r
1439 public PlatformHeaderDocument.PlatformHeader getFpdHdr() {\r
1440 if (fpdHdr == null) {\r
1441 fpdHdr = fpdRoot.addNewPlatformHeader();\r
1442 }\r
1443 genPlatformDefsSkuInfo("0", "DEFAULT");\r
1444 return fpdHdr;\r
1445 }\r
1446 \r
1447 public void genPlatformDefsSkuInfo(String id, String name) {\r
1448 SkuInfoDocument.SkuInfo skuInfo = null;\r
1449 if (getfpdPlatformDefs().getSkuInfo() == null) {\r
1450 skuInfo = getfpdPlatformDefs().addNewSkuInfo();\r
1451 }\r
1452 skuInfo = getfpdPlatformDefs().getSkuInfo();\r
1453 if (skuInfo.getUiSkuNameList() == null || skuInfo.getUiSkuNameList().size() == 0) {\r
1454 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1455 skuName.setSkuID(new BigInteger("0"));\r
1456 skuName.setStringValue("DEFAULT");\r
1457 }\r
1458 if (id.equals("0")) {\r
1459 return;\r
1460 }\r
1461 SkuInfoDocument.SkuInfo.UiSkuName skuName = skuInfo.addNewUiSkuName();\r
1462 skuName.setSkuID(new BigInteger(id));\r
1463 skuName.setStringValue(name);\r
1464 \r
1465 \r
1466 }\r
1467 public String getFpdHdrPlatformName() {\r
1468 return getFpdHdr().getPlatformName();\r
1469 }\r
1470 \r
1471 public String getFpdHdrGuidValue() {\r
1472 return getFpdHdr().getGuidValue();\r
1473 }\r
1474 \r
1475 public String getFpdHdrVer() {\r
1476 return getFpdHdr().getVersion();\r
1477 }\r
1478 \r
1479 public String getFpdHdrAbs() {\r
1480 return getFpdHdr().getAbstract();\r
1481 }\r
1482 \r
1483 public String getFpdHdrDescription() {\r
1484 return getFpdHdr().getDescription();\r
1485 }\r
1486 \r
1487 public String getFpdHdrCopyright() {\r
1488 return getFpdHdr().getCopyright();\r
1489 }\r
1490 \r
1491 public String getFpdHdrLicense() {\r
1492 LicenseDocument.License l = getFpdHdr().getLicense();\r
1493 if (l == null) {\r
1494 return null;\r
1495 }\r
1496 return l.getStringValue();\r
1497 }\r
1498 \r
1499 public String getFpdHdrUrl() {\r
1500 LicenseDocument.License l = getFpdHdr().getLicense();\r
1501 if (l == null) {\r
1502 return null;\r
1503 }\r
1504 return l.getURL();\r
1505 }\r
1506 \r
1507 public String getFpdHdrSpec() {\r
1508\r
1509 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
1510// return getFpdHdr().getSpecification();\r
1511 }\r
1512 \r
1513 public void setFpdHdrPlatformName(String name){\r
1514 getFpdHdr().setPlatformName(name);\r
1515 }\r
1516 \r
1517 public void setFpdHdrGuidValue(String guid){\r
1518 getFpdHdr().setGuidValue(guid);\r
1519 }\r
1520 \r
1521 public void setFpdHdrVer(String v){\r
1522 getFpdHdr().setVersion(v);\r
1523 }\r
1524 \r
1525 public void setFpdHdrAbs(String abs) {\r
1526 getFpdHdr().setAbstract(abs);\r
1527 }\r
1528 \r
1529 public void setFpdHdrDescription(String desc){\r
1530 getFpdHdr().setDescription(desc);\r
1531 }\r
1532 \r
1533 public void setFpdHdrCopyright(String cr) {\r
1534 getFpdHdr().setCopyright(cr);\r
1535 }\r
1536 \r
1537 public void setFpdHdrLicense(String license){\r
1538 LicenseDocument.License l = getFpdHdr().getLicense();\r
1539 if (l == null) {\r
1540 getFpdHdr().addNewLicense().setStringValue(license);\r
1541 }\r
1542 else {\r
1543 l.setStringValue(license);\r
1544 }\r
1545 }\r
1546\r
1547 public void setFpdHdrUrl(String url){\r
1548 LicenseDocument.License l = getFpdHdr().getLicense();\r
1549 \r
1550 l.setURL(url);\r
1551 \r
1552 }\r
1553 \r
1554 public void setFpdHdrSpec(String s){\r
1555 s = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
1556 getFpdHdr().setSpecification(s);\r
1557 }\r
1558 /**\r
1559 Save the processed xml contents to file\r
1560 \r
1561 @param fpdFile The file to save xml contents\r
1562 @throws IOException Exceptions during file operation\r
1563 **/\r
1564 public void saveAs(File fpdFile) throws IOException {\r
1565\r
1566 XmlOptions options = new XmlOptions();\r
1567\r
1568 options.setCharacterEncoding("UTF-8");\r
1569 options.setSavePrettyPrint();\r
1570 options.setSavePrettyPrintIndent(2);\r
1571 try {\r
1572 fpdd.save(fpdFile, options);\r
1573 } catch (IOException e) {\r
1574 e.printStackTrace();\r
1575 }\r
1576\r
1577 }\r
1578 \r
1579 private String listToString(List<String> l) {\r
1580 if (l == null) {\r
1581 return null;\r
1582 }\r
1583 String s = " ";\r
1584 ListIterator li = l.listIterator();\r
1585 while(li.hasNext()) {\r
1586 s += li.next();\r
1587 s += " ";\r
1588 }\r
1589 return s.trim();\r
1590 }\r
1591}\r