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