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