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