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