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