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