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