Replaced set*(null) with unset*() to clear empty attributes that were causing invalid...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / packaging / ui / SpdFileContents.java
CommitLineData
a13899c5 1/** @file\r
2 Java class SpdFileContents is used to parse spd xml file.\r
3 \r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13package org.tianocore.frameworkwizard.packaging.ui;\r
14\r
15import java.io.File;\r
16import java.io.IOException;\r
17import java.util.ArrayList;\r
18import java.util.List;\r
19import java.util.ListIterator;\r
20import java.util.Vector;\r
21\r
a13899c5 22\r
23import org.apache.xmlbeans.XmlObject;\r
24import org.apache.xmlbeans.XmlOptions;\r
25import org.apache.xmlbeans.XmlCursor;\r
26\r
a13899c5 27import org.tianocore.GuidDeclarationsDocument;\r
28\r
29import org.tianocore.LibraryClassDeclarationsDocument;\r
30\r
31import org.tianocore.ModuleTypeDef;\r
32import org.tianocore.MsaFilesDocument;\r
33import org.tianocore.PackageDefinitionsDocument;\r
34import org.tianocore.PackageHeadersDocument;\r
35import org.tianocore.PackageSurfaceAreaDocument;\r
36import org.tianocore.PcdDataTypes;\r
37import org.tianocore.PcdDeclarationsDocument;\r
a13899c5 38import org.tianocore.PpiDeclarationsDocument;\r
39import org.tianocore.ProtocolDeclarationsDocument;\r
40import org.tianocore.SpdHeaderDocument;\r
41import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r
a13899c5 42\r
43/**\r
44 This class processes spd file contents such as add remove xml elements.\r
45 \r
46 @since PackageEditor 1.0\r
47**/\r
48\r
49public class SpdFileContents {\r
50\r
51 private File file = null;\r
52\r
53 private PackageSurfaceAreaDocument psad = null;\r
54\r
55 private PackageSurfaceAreaDocument.PackageSurfaceArea psaRoot = null;\r
56\r
57 private SpdHeaderDocument.SpdHeader spdHdr = null;\r
58 \r
59 private PackageDefinitionsDocument.PackageDefinitions spdPkgDefs = null;\r
60 \r
61 private LibraryClassDeclarationsDocument.LibraryClassDeclarations spdLibClassDeclarations = null;\r
62\r
63 private MsaFilesDocument.MsaFiles spdMsaFiles = null;\r
64\r
65 private PackageHeadersDocument.PackageHeaders spdModHdrs = null;\r
66\r
67 private GuidDeclarationsDocument.GuidDeclarations spdGuidDeclarations = null;\r
68\r
69 private ProtocolDeclarationsDocument.ProtocolDeclarations spdProtocolDeclarations = null;\r
70\r
71 private PpiDeclarationsDocument.PpiDeclarations spdPpiDeclarations = null;\r
72\r
73 private PcdDeclarationsDocument.PcdDeclarations spdPcdDefinitions = null;\r
74\r
75 /**\r
76 Constructor to create a new spd file\r
77 **/\r
78 public SpdFileContents() {\r
79\r
80 psad = PackageSurfaceAreaDocument.Factory.newInstance();\r
81 psaRoot = psad.addNewPackageSurfaceArea();\r
82\r
83 }\r
84\r
85 /**\r
86 Constructor for existing document object\r
87 @param psa\r
88 **/\r
89 public SpdFileContents(PackageSurfaceAreaDocument.PackageSurfaceArea psa) {\r
90 psaRoot = psa;\r
91 spdHdr = psaRoot.getSpdHeader();\r
92 spdPkgDefs = psaRoot.getPackageDefinitions();\r
93 }\r
94 /**\r
95 Constructor based on an existing spd file\r
96 \r
97 @param f Existing spd file\r
98 **/\r
99 public SpdFileContents(File f) {\r
100 try {\r
101 psad = PackageSurfaceAreaDocument.Factory.parse(f);\r
102 psaRoot = psad.getPackageSurfaceArea();\r
103 file = f;\r
104 } catch (Exception e) {\r
105 System.out.println(e.toString());\r
106 }\r
107 }\r
108\r
109 /**\r
110 Remove existing pcd definitions elements using XmlCursor\r
111 **/\r
112 public void removeSpdPcdDefinition() {\r
113 XmlObject o = psaRoot.getPcdDeclarations();\r
114 if (o == null)\r
115 return;\r
116 XmlCursor cursor = o.newCursor();\r
117 cursor.removeXml();\r
118 spdPcdDefinitions = null;\r
119 cursor.dispose();\r
120 }\r
121 \r
122 public void removeSpdPcdDefinition(int i){\r
123 XmlObject o = psaRoot.getPcdDeclarations();\r
124 if (o == null)\r
125 return;\r
126 XmlCursor cursor = o.newCursor();\r
127 if (cursor.toFirstChild()) {\r
128 for (int j = 0; j < i; ++j) {\r
129 cursor.toNextSibling();\r
130 }\r
131 cursor.removeXml();\r
af25df16 132 if (getSpdPcdDefinitionCount() == 0) {\r
133 cursor.toParent();\r
134 cursor.removeXml();\r
135 }\r
a13899c5 136 } \r
137 cursor.dispose();\r
138 }\r
139\r
140 /**\r
141 Remove existing ppi declarations using XmlCursor\r
142 **/\r
143 public void removeSpdPpiDeclaration() {\r
144 XmlObject o = psaRoot.getPpiDeclarations();\r
145 if (o == null)\r
146 return;\r
147 XmlCursor cursor = o.newCursor();\r
148 cursor.removeXml();\r
149 spdPpiDeclarations = null;\r
150 cursor.dispose();\r
151 }\r
152\r
153 public void removeSpdPpiDeclaration(int i){\r
154 XmlObject o = psaRoot.getPpiDeclarations();\r
155 if (o == null)\r
156 return;\r
157 XmlCursor cursor = o.newCursor();\r
158 if (cursor.toFirstChild()) {\r
159 for (int j = 0; j < i; ++j) {\r
160 cursor.toNextSibling();\r
161 }\r
162 cursor.removeXml();\r
af25df16 163 if (getSpdPpiDeclarationCount() == 0){\r
164 cursor.toParent();\r
165 cursor.removeXml();\r
166 }\r
a13899c5 167 } \r
168 cursor.dispose();\r
169 }\r
170 /**\r
171 Remove existing protocols declarations using XmlCursor\r
172 **/\r
173 public void removeSpdProtocolDeclaration() {\r
174 XmlObject o = psaRoot.getProtocolDeclarations();\r
175 if (o == null)\r
176 return;\r
177 XmlCursor cursor = o.newCursor();\r
178 cursor.removeXml();\r
179 spdProtocolDeclarations = null;\r
180 cursor.dispose();\r
181 }\r
182 \r
183 public void removeSpdProtocolDeclaration(int i) {\r
184 XmlObject o = psaRoot.getProtocolDeclarations();\r
185 if (o == null)\r
186 return;\r
187 XmlCursor cursor = o.newCursor();\r
188 if (cursor.toFirstChild()) {\r
189 for (int j = 0; j < i; ++j) {\r
190 cursor.toNextSibling();\r
191 }\r
192 cursor.removeXml();\r
af25df16 193 if (getSpdProtocolDeclarationCount() == 0) {\r
194 cursor.toParent();\r
195 cursor.removeXml();\r
196 }\r
a13899c5 197 }\r
198 cursor.dispose();\r
199 }\r
200 /**\r
201 Remove existing GUID declarations using XmlCursor\r
202 **/\r
203 public void removeSpdGuidDeclaration() {\r
204 XmlObject o = psaRoot.getGuidDeclarations();\r
205 if (o == null)\r
206 return;\r
207 XmlCursor cursor = o.newCursor();\r
208 cursor.removeXml();\r
209 spdGuidDeclarations = null; \r
210 cursor.dispose();\r
211 }\r
212 \r
213 public void removeSpdGuidDeclaration(int i) {\r
214 XmlObject o = psaRoot.getGuidDeclarations();\r
215 if (o == null)\r
216 return;\r
217 XmlCursor cursor = o.newCursor();\r
218 if (cursor.toFirstChild()) {\r
219 for (int j = 0; j < i; ++j) {\r
220 cursor.toNextSibling();\r
221 }\r
222 cursor.removeXml();\r
af25df16 223 if (getSpdGuidDeclarationCount() == 0) {\r
224 cursor.toParent();\r
225 cursor.removeXml();\r
226 }\r
a13899c5 227 } \r
228 cursor.dispose();\r
229 }\r
230\r
231 /**\r
232 Remove existing spd package include files using XmlCursor\r
233 **/\r
234 public void removeSpdPkgHeader() {\r
235 XmlObject o = psaRoot.getPackageHeaders();\r
236 if (o == null)\r
237 return;\r
238 XmlCursor cursor = o.newCursor();\r
239 cursor.removeXml();\r
240 spdModHdrs = null;\r
241 cursor.dispose();\r
242 }\r
243 \r
244 public void removeSpdPkgHeader(int i){\r
245 XmlObject o = psaRoot.getPackageHeaders();\r
246 if (o == null)\r
247 return;\r
248 XmlCursor cursor = o.newCursor();\r
249 if (cursor.toFirstChild()) {\r
250 for (int j = 0; j < i; ++j) {\r
251 cursor.toNextSibling();\r
252 }\r
253 cursor.removeXml();\r
af25df16 254 if (getSpdPackageHeaderCount() == 0) {\r
255 cursor.toParent();\r
256 cursor.removeXml();\r
257 }\r
a13899c5 258 } \r
259 cursor.dispose();\r
260 }\r
261\r
262 /**\r
263 Remove existing msa files using XmlCursor\r
264 **/\r
265 public void removeSpdMsaFile() {\r
266 XmlObject o = psaRoot.getMsaFiles();\r
267 if (o == null)\r
268 return;\r
269 XmlCursor cursor = o.newCursor();\r
270 cursor.removeXml();\r
271 spdMsaFiles = null;\r
272 cursor.dispose();\r
273 }\r
274 \r
275 public void removeSpdMsaFile(int i){\r
276 XmlObject o = psaRoot.getMsaFiles();\r
277 if (o == null)\r
278 return;\r
279 XmlCursor cursor = o.newCursor();\r
280 if (cursor.toFirstChild()) {\r
281 for (int j = 0; j < i; ++j) {\r
282 cursor.toNextSibling();\r
283 }\r
284 cursor.removeXml();\r
af25df16 285 if (getSpdMsaFileCount() == 0) {\r
286 cursor.toParent();\r
287 cursor.removeXml();\r
288 }\r
a13899c5 289 }\r
290 cursor.dispose();\r
291 }\r
292\r
293 /**\r
294 Remove existing library class declarations using XmlCursor\r
295 **/\r
296 public void removeSpdLibClass() {\r
297 XmlObject o = psaRoot.getLibraryClassDeclarations();\r
298 if (o == null)\r
299 return;\r
300 XmlCursor cursor = o.newCursor();\r
301 cursor.removeXml();\r
302 spdLibClassDeclarations = null;\r
303 cursor.dispose();\r
304 }\r
305 \r
306 public void removeSpdLibClass(int i) {\r
307 XmlObject o = psaRoot.getLibraryClassDeclarations();\r
308 if (o == null)\r
309 return;\r
310 XmlCursor cursor = o.newCursor();\r
311 if (cursor.toFirstChild()) {\r
312 for (int j = 0; j < i; ++j) {\r
313 cursor.toNextSibling();\r
314 }\r
315 cursor.removeXml();\r
af25df16 316 if (getSpdLibClassDeclarationCount() == 0) {\r
317 cursor.toParent();\r
318 cursor.removeXml();\r
319 }\r
a13899c5 320 }\r
321 cursor.dispose();\r
322 }\r
323 \r
324 public void updateSpdLibClass(int i, String lib, String hdr, String hlp, String clsUsage, String instanceVer, String hdrAttribArch, String hdrAttribModType) {\r
325 XmlObject o = psaRoot.getLibraryClassDeclarations();\r
326 if (o == null)\r
327 return;\r
328 \r
329 XmlCursor cursor = o.newCursor();\r
330 if (cursor.toFirstChild()) {\r
331 for (int j = 0; j < i; ++j) {\r
332 cursor.toNextSibling();\r
333 }\r
334 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass lc = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass)cursor.getObject();\r
335 lc.setName(lib);\r
336 lc.setIncludeHeader(hdr);\r
337 lc.setHelpText(hlp);\r
338 if (clsUsage != null) {\r
97796eaa 339 lc.setRecommendedInstanceGuid(clsUsage);\r
340 if (instanceVer != null){\r
a13899c5 341 lc.setRecommendedInstanceVersion(instanceVer);\r
97796eaa 342 } else {\r
343 lc.unsetRecommendedInstanceVersion();\r
344 }\r
345 } else {\r
346 lc.unsetRecommendedInstanceGuid();\r
347 lc.unsetRecommendedInstanceVersion();\r
a13899c5 348 }\r
97796eaa 349\r
a13899c5 350 if (stringToList(hdrAttribArch) != null){\r
97796eaa 351 lc.setSupArchList(stringToList(hdrAttribArch));\r
352 } else {\r
353 lc.unsetSupArchList();\r
a13899c5 354 }\r
355 if (stringToList(hdrAttribModType) != null){\r
97796eaa 356 lc.setSupModuleList(stringToList(hdrAttribModType));\r
357 } else {\r
358 lc.unsetSupModuleList();\r
a13899c5 359 }\r
360 }\r
361 \r
362 cursor.dispose();\r
363 }\r
364 \r
365 public void updateSpdMsaFile(int i, String msaFile, String mName, String v, String g){\r
366 XmlObject o = psaRoot.getMsaFiles();\r
367 if (o == null)\r
368 return;\r
369 \r
370 XmlCursor cursor = o.newCursor();\r
371 if (cursor.toFirstChild()) {\r
372 for (int j = 0; j < i; ++j) {\r
373 cursor.toNextSibling();\r
374 }\r
375 cursor.setTextValue(msaFile);\r
376\r
377 }\r
378 \r
379 cursor.dispose();\r
380 }\r
381\r
382 public void updateSpdGuidDecl(int i, String name, String cName, String guid, String hlp, String archList, \r
383 String modTypeList, String guidTypeList){\r
384 XmlObject o = psaRoot.getGuidDeclarations();\r
385 if (o == null){\r
386 return;\r
387 }\r
388 \r
389 XmlCursor cursor = o.newCursor();\r
390 if (cursor.toFirstChild()) {\r
391 for (int j = 0; j < i; ++j) {\r
392 cursor.toNextSibling();\r
393 }\r
394 GuidDeclarationsDocument.GuidDeclarations.Entry e = (GuidDeclarationsDocument.GuidDeclarations.Entry)cursor.getObject();\r
395 e.setName(name);\r
396 e.setCName(cName);\r
397 e.setGuidValue(guid);\r
398 e.setHelpText(hlp);\r
ce73a791 399 if (stringToList(guidTypeList) != null) {\r
a13899c5 400 e.setGuidTypeList(stringToList(guidTypeList));\r
401 }\r
ce73a791 402 else{\r
97796eaa 403 e.unsetGuidTypeList();\r
ce73a791 404 }\r
a13899c5 405 if (stringToList(archList) != null){\r
406 e.setSupArchList(stringToList(archList));\r
407 }\r
ce73a791 408 else{\r
97796eaa 409 e.unsetSupArchList();\r
ce73a791 410 }\r
a13899c5 411 if (stringToList(modTypeList) != null) {\r
412 e.setSupModuleList(stringToList(modTypeList));\r
413 }\r
ce73a791 414 else{\r
97796eaa 415 e.unsetSupModuleList();\r
ce73a791 416 }\r
a13899c5 417 \r
418 }\r
419 cursor.dispose();\r
420 }\r
421 \r
422 public void updateSpdPpiDecl(int i, String name, String cName, String guid, String hlp, String archList, \r
423 String modTypeList){\r
424 XmlObject o = psaRoot.getPpiDeclarations();\r
425 if (o == null){\r
426 return;\r
427 }\r
428 \r
429 XmlCursor cursor = o.newCursor();\r
430 if (cursor.toFirstChild()) {\r
431 for (int j = 0; j < i; ++j) {\r
432 cursor.toNextSibling();\r
433 }\r
434 PpiDeclarationsDocument.PpiDeclarations.Entry e = (PpiDeclarationsDocument.PpiDeclarations.Entry)cursor.getObject();\r
435 e.setName(name);\r
436 e.setCName(cName);\r
437 e.setGuidValue(guid);\r
438 e.setHelpText(hlp);\r
439 if (stringToList(archList) != null){\r
440 e.setSupArchList(stringToList(archList));\r
441 }\r
ce73a791 442 else{\r
97796eaa 443 e.unsetSupArchList();\r
ce73a791 444 }\r
a13899c5 445 if (stringToList(modTypeList) != null) {\r
446 e.setSupModuleList(stringToList(modTypeList));\r
447 }\r
ce73a791 448 else{\r
97796eaa 449 e.unsetSupModuleList();\r
ce73a791 450 }\r
a13899c5 451 }\r
452 cursor.dispose();\r
453 }\r
454 \r
455 public void updateSpdProtocolDecl(int i, String name, String cName, String guid, String hlp, String archList, \r
456 String modTypeList){\r
457 XmlObject o = psaRoot.getProtocolDeclarations();\r
458 if (o == null){\r
459 return;\r
460 }\r
461 \r
462 XmlCursor cursor = o.newCursor();\r
463 if (cursor.toFirstChild()) {\r
464 for (int j = 0; j < i; ++j) {\r
465 cursor.toNextSibling();\r
466 }\r
467 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry e = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry)cursor.getObject();\r
468 e.setName(name);\r
469 e.setCName(cName);\r
470 e.setGuidValue(guid);\r
471 e.setHelpText(hlp);\r
472 if (stringToList(archList) != null){\r
473 e.setSupArchList(stringToList(archList));\r
474 }\r
ce73a791 475 else{\r
97796eaa 476 e.unsetSupArchList();\r
ce73a791 477 }\r
a13899c5 478 if (stringToList(modTypeList) != null) {\r
479 e.setSupModuleList(stringToList(modTypeList));\r
480 }\r
ce73a791 481 else{\r
97796eaa 482 e.unsetSupModuleList();\r
ce73a791 483 }\r
a13899c5 484 }\r
485 cursor.dispose();\r
486 }\r
487 \r
488 public void updateSpdPkgHdr(int i, String pkgName, String hdrName){\r
489 XmlObject o = psaRoot.getPackageHeaders();\r
490 if (o == null){\r
491 return;\r
492 }\r
493 \r
494 XmlCursor cursor = o.newCursor();\r
495 if (cursor.toFirstChild()) {\r
496 for (int j = 0; j < i; ++j) {\r
497 cursor.toNextSibling();\r
498 }\r
499 \r
500 PackageHeadersDocument.PackageHeaders.IncludePkgHeader iph = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader)cursor.getObject();\r
501 iph.setModuleType(ModuleTypeDef.Enum.forString(pkgName));\r
502 iph.setStringValue(hdrName);\r
503 }\r
504 cursor.dispose();\r
505 }\r
506 \r
507 public void updateSpdPcdDefinition(int i, String cName, String token, String dataType, String pcdItemTypes, \r
508 String spaceGuid, String defaultString, String help, String archList, String modTypeList){\r
509 XmlObject o = psaRoot.getPcdDeclarations();\r
510 if (o == null)\r
511 return;\r
512 XmlCursor cursor = o.newCursor();\r
513 if (cursor.toFirstChild()) {\r
514 for (int j = 0; j < i; ++j) {\r
515 cursor.toNextSibling();\r
516 }\r
517 PcdDeclarationsDocument.PcdDeclarations.PcdEntry e = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)cursor.getObject();\r
518 e.setCName(cName);\r
519 e.setToken(token);\r
520 e.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
521 if (pcdItemTypes != null && pcdItemTypes.length() > 0) {\r
522 String usage[] = pcdItemTypes.split("( )+");\r
523 List<String> l = new ArrayList<String>();\r
524 for (int k = 0; k < usage.length; ++k) {\r
525 l.add(usage[k]); \r
526 }\r
527 e.setValidUsage(l);\r
528 }\r
529 \r
530 e.setTokenSpaceGuidCName(spaceGuid);\r
531 e.setDefaultValue(defaultString);\r
532 e.setHelpText(help);\r
533 if (archList != null && archList.length() > 0){\r
534 e.setSupArchList(stringToList(archList));\r
535 }\r
536 if (modTypeList != null && modTypeList.length() > 0){\r
537 e.setSupModuleList(stringToList(modTypeList));\r
538 }\r
539 } \r
540 cursor.dispose();\r
541 }\r
542 /**\r
543 Get spd file header contents into String array\r
544 \r
545 @param s Caller allocated String array\r
546 **/\r
547 public void getSpdHdrDetails(String[] s) {\r
548 if (getSpdHdr() == null) {\r
549 spdHdr = psaRoot.addNewSpdHeader();\r
550 }\r
551 s[0] = getSpdHdrPkgName();\r
552 s[1] = getSpdHdr().getGuidValue();\r
553 s[2] = getSpdHdrVer();\r
554// s[3] = getSpdHdr().getAbstract();\r
555 s[4] = getSpdHdr().getDescription();\r
556 s[5] = getSpdHdr().getCopyright();\r
557 s[6] = getSpdHdrLicense();\r
558 \r
559 }\r
560\r
561 /**\r
562 Get the number of library class declarations from the size of List\r
563 \r
564 @return int\r
565 **/\r
566 public int getSpdLibClassDeclarationCount() {\r
567 if (psaRoot.getLibraryClassDeclarations() == null\r
568 || psaRoot.getLibraryClassDeclarations().getLibraryClassList() == null) {\r
569 return 0;\r
570 }\r
571 return psaRoot.getLibraryClassDeclarations().getLibraryClassList().size();\r
572 }\r
573\r
574 /**\r
575 Get available library class declaration into String array\r
576 @param libClass Caller allocated two-dimentional String array\r
577 **/\r
578 public void getSpdLibClassDeclarations(String[][] libClass) {\r
579 if (psaRoot.getLibraryClassDeclarations() == null){\r
580 return;\r
581 }\r
582 \r
583 List<LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass> l = psaRoot.getLibraryClassDeclarations().getLibraryClassList();\r
584 int i = 0;\r
585 ListIterator li = l.listIterator();\r
586 while (li.hasNext()) {\r
587 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass lc = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) li.next();\r
588 if (lc != null) {\r
589 libClass[i][0] = lc.getName();\r
590 libClass[i][1] = lc.getIncludeHeader();\r
591 libClass[i][2] = lc.getHelpText();\r
2f8a7517 592// LAH added logic so you cannot set the version unless the GUID is defined.\r
97796eaa 593/* LAH do not set now\r
2f8a7517 594 if (lc.getRecommendedInstanceGuid() != null) {\r
595 libClass[i][3] = lc.getRecommendedInstanceGuid();\r
596 if (lc.getRecommendedInstanceVersion() != null) {\r
597 libClass[i][4] = lc.getRecommendedInstanceVersion();\r
598 }\r
599 }\r
97796eaa 600*/\r
a13899c5 601 if (lc.getSupArchList() != null) {\r
602 libClass[i][5] = listToString(lc.getSupArchList());\r
603 }\r
604 if (lc.getSupModuleList() != null) {\r
605 libClass[i][6] = listToString(lc.getSupModuleList());\r
606 }\r
607 \r
608 }\r
609 \r
610 i++;\r
611 }\r
612\r
613 }\r
614 \r
615 /**\r
616 Get the number of Msa files from the size of List\r
617 \r
618 @return int\r
619 **/\r
620 public int getSpdMsaFileCount() {\r
621 if (psaRoot.getMsaFiles() == null || psaRoot.getMsaFiles().getFilenameList() == null) {\r
622 return 0;\r
623 }\r
624 return psaRoot.getMsaFiles().getFilenameList().size();\r
625 }\r
626 \r
627 /**\r
628 Get available Msa file into String array\r
629 \r
630 @param msaFile Caller allocated two-dimentional String array\r
631 **/\r
632 public void getSpdMsaFiles(String[][] msaFile) {\r
633 if (psaRoot.getMsaFiles() == null) {\r
634 return;\r
635 }\r
636 List<String> l = psaRoot.getMsaFiles().getFilenameList();\r
637 int i = 0;\r
638 ListIterator li = l.listIterator();\r
639 while (li.hasNext()) {\r
640 msaFile[i][0] = (String)li.next();\r
641\r
642 i++;\r
643 }\r
644 }\r
645\r
646 /**\r
647 Get the number of include header files in PackageHeaders from the size of List\r
648 \r
649 @return int\r
650 **/\r
651 public int getSpdPackageHeaderCount() {\r
652 if (psaRoot.getPackageHeaders() == null || psaRoot.getPackageHeaders().getIncludePkgHeaderList() == null) {\r
653 return 0;\r
654 }\r
655 return psaRoot.getPackageHeaders().getIncludePkgHeaderList().size();\r
656 }\r
657\r
658 /**\r
659 Get available package header contents into String array\r
660 \r
661 @param pkgHeader Caller allocated two-dimentional String array\r
662 **/\r
663 public void getSpdPackageHeaders(String[][] pkgHeader) {\r
664 if (psaRoot.getPackageHeaders() == null) {\r
665 return;\r
666 }\r
667 \r
668 List<PackageHeadersDocument.PackageHeaders.IncludePkgHeader> l = psaRoot.getPackageHeaders().getIncludePkgHeaderList();\r
669 int i = 0;\r
670 ListIterator li = l.listIterator();\r
671 while (li.hasNext()) {\r
672 PackageHeadersDocument.PackageHeaders.IncludePkgHeader ih = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) li.next();\r
673 if (ih.getModuleType() != null) {\r
674 pkgHeader[i][0] = ih.getModuleType().toString();\r
675 }\r
676\r
677 pkgHeader[i][1] = ih.getStringValue();\r
678 i++;\r
679 }\r
680 }\r
681\r
682 /**\r
683 Get the number of GUID declarations from the size of List\r
684 \r
685 @return int\r
686 **/\r
687 public int getSpdGuidDeclarationCount() {\r
688 if (psaRoot.getGuidDeclarations() == null || psaRoot.getGuidDeclarations().getEntryList() == null) {\r
689 return 0;\r
690 }\r
691 return psaRoot.getGuidDeclarations().getEntryList().size();\r
692 }\r
693\r
694 /**\r
695 Get available Guid declaration contents into String array\r
696 \r
697 @param guid Caller allocated two-dimentional String array\r
698 **/\r
699 public void getSpdGuidDeclarations(String[][] guid) {\r
700 if (psaRoot.getGuidDeclarations() == null) {\r
701 return;\r
702 }\r
703 \r
704 List<GuidDeclarationsDocument.GuidDeclarations.Entry> l = psaRoot.getGuidDeclarations().getEntryList();\r
705 int i = 0;\r
706 ListIterator li = l.listIterator();\r
707 while (li.hasNext()) {\r
708 GuidDeclarationsDocument.GuidDeclarations.Entry e = (GuidDeclarationsDocument.GuidDeclarations.Entry) li\r
709 .next();\r
710 guid[i][0] = e.getName();\r
711 guid[i][1] = e.getCName();\r
712 if (e.getGuidValue() != null) {\r
713 guid[i][2] = e.getGuidValue();\r
714 }\r
715 guid[i][3] = e.getHelpText();\r
716 guid[i][4] = listToString(e.getSupArchList());\r
717 guid[i][5] = listToString(e.getSupModuleList());\r
718 guid[i][6] = listToString(e.getGuidTypeList());\r
719 i++;\r
720 }\r
721 }\r
722\r
723 /**\r
724 Get the number of protocol declarations from the size of List\r
725 \r
726 @return int\r
727 **/\r
728 public int getSpdProtocolDeclarationCount() {\r
729 if (psaRoot.getProtocolDeclarations() == null || psaRoot.getProtocolDeclarations().getEntryList() == null) {\r
730 return 0;\r
731 }\r
732 return psaRoot.getProtocolDeclarations().getEntryList().size();\r
733 }\r
734\r
735 /**\r
736 Get available protocol declaration contents into String array\r
737 \r
738 @param protocol Caller allocated two-dimentional String array\r
739 **/\r
740 public void getSpdProtocolDeclarations(String[][] protocol) {\r
741 if (psaRoot.getProtocolDeclarations() == null) {\r
742 return;\r
743 }\r
744 \r
745 List<ProtocolDeclarationsDocument.ProtocolDeclarations.Entry> l = psaRoot.getProtocolDeclarations()\r
746 .getEntryList();\r
747 int i = 0;\r
748 ListIterator li = l.listIterator();\r
749 while (li.hasNext()) {\r
750 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry e = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) li\r
751 .next();\r
752 protocol[i][0] = e.getName();\r
753 protocol[i][1] = e.getCName();\r
754 if (e.getGuidValue() != null) {\r
755 protocol[i][2] = e.getGuidValue();\r
756 }\r
757 protocol[i][3] = e.getHelpText();\r
758 protocol[i][4] = listToString(e.getSupArchList());\r
759 protocol[i][5] = listToString(e.getSupModuleList());\r
760 i++;\r
761 }\r
762 }\r
763\r
764 /**\r
765 Get the number of Ppi declarations from the size of List\r
766 \r
767 @return int\r
768 **/\r
769 public int getSpdPpiDeclarationCount() {\r
770 if (psaRoot.getPpiDeclarations() == null || psaRoot.getPpiDeclarations().getEntryList() == null) {\r
771 return 0;\r
772 }\r
773 return psaRoot.getPpiDeclarations().getEntryList().size();\r
774 }\r
775\r
776 /**\r
777 Get available Ppi declaration contents into String array\r
778 \r
779 @param ppi Caller allocated two-dimentional String array\r
780 **/\r
781 public void getSpdPpiDeclarations(String[][] ppi) {\r
782 if (psaRoot.getPpiDeclarations() == null) {\r
783 return;\r
784 }\r
785 \r
786 List<PpiDeclarationsDocument.PpiDeclarations.Entry> l = psaRoot.getPpiDeclarations().getEntryList();\r
787 int i = 0;\r
788 ListIterator li = l.listIterator();\r
789 while (li.hasNext()) {\r
790 PpiDeclarationsDocument.PpiDeclarations.Entry e = (PpiDeclarationsDocument.PpiDeclarations.Entry) li.next();\r
791 ppi[i][0] = e.getName();\r
792 ppi[i][1] = e.getCName();\r
793 if (e.getGuidValue() != null) {\r
794 ppi[i][2] = e.getGuidValue();\r
795 }\r
796 ppi[i][3] = e.getHelpText();\r
797 ppi[i][4] = listToString(e.getSupArchList());\r
798 ppi[i][5] = listToString(e.getSupModuleList());\r
799\r
800 i++;\r
801 }\r
802 }\r
803\r
804 /**\r
805 Get the number of Pcd definitions from the size of List\r
806 \r
807 @return int\r
808 **/\r
809 public int getSpdPcdDefinitionCount() {\r
810 if (psaRoot.getPcdDeclarations() == null || psaRoot.getPcdDeclarations().getPcdEntryList() == null) {\r
811 return 0;\r
812 }\r
813 return psaRoot.getPcdDeclarations().getPcdEntryList().size();\r
814 }\r
815\r
816 /**\r
817 Get available Pcd definition contents into String array\r
818 \r
819 @param pcd Caller allocated two-dimentional String array\r
820 **/\r
821 public void getSpdPcdDefinitions(String[][] pcd, String pcdUsage[][]) {\r
822 if (psaRoot.getPcdDeclarations() == null) {\r
823 return;\r
824 }\r
825 \r
826 List<PcdDeclarationsDocument.PcdDeclarations.PcdEntry> l = psaRoot.getPcdDeclarations().getPcdEntryList();\r
827 int i = 0;\r
828 while (i < l.size()) {\r
829 PcdDeclarationsDocument.PcdDeclarations.PcdEntry e = (PcdDeclarationsDocument.PcdDeclarations.PcdEntry)l.get(i);\r
830 pcd[i][0] = e.getCName();\r
831 pcd[i][1] = e.getToken() + ""; \r
832 pcd[i][2] = e.getTokenSpaceGuidCName();\r
833 if (e.getDatumType() != null) {\r
834 pcd[i][3] = e.getDatumType().toString();\r
835 }\r
836 pcd[i][4] = e.getDefaultValue()+"";\r
837 pcd[i][5] = e.getHelpText();\r
838 String archList = listToString(e.getSupArchList());\r
839 if (archList != null) {\r
840 pcd[i][6] = archList;\r
841 }\r
842 String modTypeList = listToString(e.getSupModuleList());\r
843 if (modTypeList != null) {\r
844 pcd[i][7] = modTypeList;\r
845 }\r
846 \r
847 int j = 0;\r
848 while (j < e.getValidUsage().size() && j < 5) {\r
849 pcdUsage[i][j] = (String)e.getValidUsage().get(j);\r
850 ++j;\r
851 }\r
852 i++;\r
853 }\r
854 }\r
855\r
856 /**\r
857 Save the processed xml contents to file\r
858 \r
859 @param spdFile The file to save xml contents\r
860 @throws IOException Exceptions during file operation\r
861 **/\r
862 public void saveAs(File spdFile) throws IOException {\r
863\r
864 XmlOptions options = new XmlOptions();\r
865\r
866 options.setCharacterEncoding("UTF-8");\r
867 options.setSavePrettyPrint();\r
868 options.setSavePrettyPrintIndent(2);\r
869 try {\r
870 psad.save(spdFile, options);\r
871 } catch (IOException e) {\r
872 e.printStackTrace();\r
873 }\r
874\r
875 }\r
876\r
877 /**\r
878 Generate SpdHeader contents using parameters passed in.\r
879 \r
880 @param pkgName PackageName \r
881 @param pkgGuid Guid\r
882 @param pkgVer Version\r
883 @param pkgAbs Abstract\r
884 @param pkgDes Description\r
885 @param pkgCpRight Copyright\r
886 @param pkgLicense License\r
887 @param pkgCreateDate Created\r
888 @param pkgUpdateDate Updated\r
889 @param pkgURL URL\r
890 @param pkgType PackageType\r
891 @param pkgRdOnly ReadOnly\r
892 @param pkgRePkg RePackage\r
893 @param pkgSpec Reserved\r
894 @param pkgOutDir Reserved\r
895 **/\r
896 public void genSpdHeader(String pkgName, String pkgGuid, String pkgVer, String pkgAbs, String pkgDes,\r
897 String pkgCpRight, String pkgLicense, String pkgCreateDate, String pkgUpdateDate,\r
898 String pkgURL, String pkgType, String pkgRdOnly, String pkgRePkg, String pkgSpec,\r
899 String pkgOutDir) {\r
900 if (getSpdHdr() == null) {\r
901 spdHdr = psaRoot.addNewSpdHeader();\r
902 }\r
903\r
904 setSpdHdrPkgName(pkgName);\r
905 setSpdHdrGuidValue(pkgGuid);\r
906 setSpdHdrVer(pkgVer);\r
907 setSpdHdrAbs(pkgAbs);\r
908 setSpdHdrDescription(pkgDes);\r
909 setSpdHdrCopyright(pkgCpRight);\r
910 setSpdHdrLicense(pkgLicense);\r
911 \r
912\r
913 setSpdHdrSpec(pkgSpec);\r
914 }\r
915\r
916 /**\r
917 Generate library class declaration element using parameters passed in\r
918 \r
919 @param libClassBaseName LibraryClass element value\r
920 @param libClassUsage Reserved\r
921 @param incHdrFileName IncludeHeader element value\r
922 @param incHdrAttribGuid Reserved\r
923 @param incHdrAttribArch Reserved\r
924 @param incHdrAttribPath Reserved\r
925 @param incHdrAttribClass Reserved\r
926 @param incHdrAttribVer Reserved\r
927 @param incHdrAttribOverrideID Reserved\r
928 @param incHdrAttribModuleType Reserved\r
929 **/\r
930 public void genSpdLibClassDeclarations(String libClassBaseName, String instanceUsage, String incHdrFileName,\r
931 String help, String incHdrAttribArch, String incHdrAttribPath,\r
932 String incHdrAttribClass, String incHdrAttribVer,\r
933 String incHdrAttribOverrideID, String incHdrAttribModuleType) {\r
934 if (getSpdLibClassDeclarations() == null) {\r
935 spdLibClassDeclarations = psaRoot.addNewLibraryClassDeclarations();\r
936 }\r
937 //\r
938 // add contents under LibraryClassDeclarations tag \r
939 //\r
940 setSpdLibClassDeclaration(libClassBaseName, instanceUsage, incHdrFileName, help, incHdrAttribArch,\r
941 incHdrAttribPath, incHdrAttribClass, incHdrAttribVer, incHdrAttribOverrideID,\r
942 incHdrAttribModuleType, spdLibClassDeclarations);\r
943 }\r
944\r
945 /**\r
946 Set library class declaration contents under parent tag\r
947 \r
948 @param clsName LibraryClass element value\r
949 @param clsUsage Reserved\r
950 @param hdrFile IncludeHeader element value\r
951 @param hdrAttribGuid Reserved\r
952 @param hdrAttribArch Reserved\r
953 @param hdrAttribPath Reserved\r
954 @param hdrAttribClass Reserved\r
955 @param hdrAttribVer Reserved\r
956 @param hdrAttribOverID Reserved\r
957 @param hdrAttribModType Reserved\r
958 @param parent The tag under which library class declaration goes to\r
959 **/\r
960 public void setSpdLibClassDeclaration(String clsName, String clsUsage, String hdrFile, String help,\r
961 String hdrAttribArch, String hdrAttribPath, String hdrAttribClass,\r
962 String instanceVer, String hdrAttribOverID, String hdrAttribModType,\r
963 XmlObject parent) {\r
964\r
965 setSpdLibraryClass(clsName, hdrFile, help, clsUsage, instanceVer, hdrAttribArch, hdrAttribModType, parent);\r
966\r
967 }\r
968\r
969 /**\r
970 Set the contents of LibraryClass under parent element\r
971 \r
972 @param clsName LibraryClass element value \r
973 @param clsUsage Reserved\r
974 @param parent The tag under which library class declaration goes to\r
975 **/\r
976 public void setSpdLibraryClass(String clsName, String clsIncludeFile, String help, String clsUsage, String instanceVer, String hdrAttribArch, String hdrAttribModType, XmlObject parent) {\r
977 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass lc = ((LibraryClassDeclarationsDocument.LibraryClassDeclarations) parent).addNewLibraryClass();\r
978 lc.setName(clsName);\r
979 lc.setIncludeHeader(clsIncludeFile);\r
980 lc.setHelpText(help);\r
2f8a7517 981// LAH added logic so you cannot set the version unless the GUID is defined.\r
97796eaa 982/* LAH\r
2f8a7517 983 if (clsUsage != null) {\r
984 lc.setRecommendedInstanceGuid(clsUsage);\r
985 if (instanceVer != null) {\r
986 lc.setRecommendedInstanceVersion(instanceVer);\r
987 }\r
988 }\r
97796eaa 989*/\r
a13899c5 990 if (hdrAttribArch != null) {\r
991 lc.setSupArchList(stringToList(hdrAttribArch));\r
992 }\r
993 if (hdrAttribModType != null) {\r
97796eaa 994 lc.setSupModuleList(stringToList(hdrAttribModType));\r
995 } else {\r
996 lc.unsetSupModuleList();\r
a13899c5 997 }\r
998 \r
999 }\r
1000\r
1001 /**\r
1002 Set contents of IncludeHeader under parent element\r
1003 \r
1004 @param modType Reserved\r
1005 @param hdrFile IncludeHeader element value\r
1006 @param hdrAttribGuid Reserved\r
1007 @param hdrAttribArch Reserved\r
1008 @param hdrAttribPath Reserved\r
1009 @param hdrAttribClass Reserved\r
1010 @param hdrAttribVer Reserved\r
1011 @param hdrAttribOverID Reserved\r
1012 @param parent The tag under which library class declaration goes to\r
1013 **/\r
1014 public void setSpdIncludeHeader(String modType, String hdrFile, String hdrAttribGuid, String hdrAttribArch,\r
1015 String hdrAttribPath, String hdrAttribClass, String hdrAttribVer,\r
1016 String hdrAttribOverID, XmlObject parent) {\r
1017 \r
1018 if (parent instanceof LibraryClassDeclarationsDocument.LibraryClassDeclarations) {\r
1019 } else if (parent instanceof PackageHeadersDocument.PackageHeaders) {\r
1020 PackageHeadersDocument.PackageHeaders.IncludePkgHeader ih = null;\r
1021 ih = ((PackageHeadersDocument.PackageHeaders) parent).addNewIncludePkgHeader();\r
1022 ih.setStringValue(hdrFile);\r
1023 ih.setModuleType(ModuleTypeDef.Enum.forString(modType));\r
1024 } else {\r
1025 return;\r
1026 }\r
1027\r
1028 if (hdrAttribGuid != null) {\r
1029 }\r
1030 if (hdrAttribPath != null) {\r
1031 }\r
1032 if (hdrAttribClass != null) {\r
1033 }\r
1034 if (hdrAttribVer != null) {\r
1035 }\r
1036 if (hdrAttribOverID != null) {\r
1037 }\r
1038\r
1039 }\r
1040\r
1041 /**\r
1042 Generate MsaFile element.\r
1043 \r
1044 @param msaFileName MsaFile element value\r
1045 @param archType Reserved\r
1046 **/\r
1047 public void genSpdMsaFiles(String msaFileName, String moduleName, String ver, String guid) {\r
1048 if (getSpdMsaFiles() == null) {\r
1049 spdMsaFiles = psaRoot.addNewMsaFiles();\r
1050 }\r
1051 setSpdMsaFile(msaFileName, moduleName, ver, guid, spdMsaFiles);\r
1052 \r
1053 }\r
1054\r
1055 /**\r
1056 Set MsaFile contents under parent element.\r
1057 \r
1058 @param msaFileName MsaFile element value\r
1059 @param parent Element under which MsaFile goes to\r
1060 **/\r
1061 public void setSpdMsaFile(String msaFileName, String moduleName, String ver, String guid, XmlObject parent) {\r
1062 MsaFilesDocument.MsaFiles f = (MsaFilesDocument.MsaFiles)parent;\r
1063 f.addNewFilename().setStringValue(msaFileName);\r
1064// f.setFilename(msaFileName);\r
1065// f.setModuleName(moduleName);\r
1066// f.setModuleVersion(ver);\r
1067// f.setModuleGuid(guid);\r
1068 }\r
1069\r
1070 /**\r
1071 Generate PackageHeader element using parameters passed in.\r
1072 \r
1073 @param ModHdrModType ModuleType attribute of IncludeHeader element\r
1074 @param hdrFile IncludeHeader element value\r
1075 @param hdrAttribGuid Reserved\r
1076 @param hdrAttribArch Reserved\r
1077 @param hdrAttribPath Reserved\r
1078 @param hdrAttribClass Reserved\r
1079 @param hdrAttribVer Reserved\r
1080 @param hdrAttribOverID Reserved\r
1081 **/\r
1082 public void genSpdModuleHeaders(String ModHdrModType, String hdrFile, String hdrAttribGuid, String hdrAttribArch,\r
1083 String hdrAttribPath, String hdrAttribClass, String hdrAttribVer,\r
1084 String hdrAttribOverID) {\r
1085 if (getSpdModHdrs() == null) {\r
1086 spdModHdrs = psaRoot.addNewPackageHeaders();\r
1087 }\r
1088\r
1089 //\r
1090 // add IncludeHeader under PackageHeaders element\r
1091 //\r
1092 setSpdIncludeHeader(ModHdrModType, hdrFile, hdrAttribGuid, hdrAttribArch, hdrAttribPath, hdrAttribClass,\r
1093 hdrAttribVer, hdrAttribOverID, spdModHdrs);\r
1094 }\r
1095\r
1096 /**\r
1097 Generate GUID declaration element using parameters passed in.\r
1098 \r
1099 @param guidDeclEntryName Name attribute of Entry element\r
1100 @param guidDeclCName CName element value\r
1101 @param guidDeclGuid Guid element value\r
1102 @param guidDeclFeatureFlag Reserved\r
1103 **/\r
1104 public void genSpdGuidDeclarations(String guidDeclEntryName, String guidDeclCName, String guidDeclGuid,\r
1105 String guidDeclHelp, Vector<String> archList, Vector<String> modTypeList,\r
1106 Vector<String> guidTypeList) {\r
1107 if (getSpdGuidDeclarations() == null) {\r
1108 spdGuidDeclarations = psaRoot.addNewGuidDeclarations();\r
1109 }\r
1110\r
1111 setSpdEntry(guidDeclEntryName, guidDeclCName, guidDeclGuid, guidDeclHelp, archList, modTypeList, guidTypeList, spdGuidDeclarations);\r
1112 }\r
1113\r
1114 /**\r
1115 Generate protocol declaration element using parameters passed in.\r
1116 \r
1117 @param protocolDeclEntryName Name attribute of Entry element\r
1118 @param protocolDeclCName CName element value\r
1119 @param protocolDeclGuid Guid element value\r
1120 @param protocolDeclFeatureFlag Reserved\r
1121 **/\r
1122 public void genSpdProtocolDeclarations(String protocolDeclEntryName, String protocolDeclCName,\r
1123 String protocolDeclGuid, String protocolDeclFeatureFlag,\r
1124 Vector<String> archList, Vector<String> modTypeList) {\r
1125 if (getSpdProtocolDeclarations() == null) {\r
1126 spdProtocolDeclarations = psaRoot.addNewProtocolDeclarations();\r
1127 }\r
1128\r
1129 setSpdEntry(protocolDeclEntryName, protocolDeclCName, protocolDeclGuid, protocolDeclFeatureFlag,\r
1130 archList, modTypeList, null, spdProtocolDeclarations);\r
1131 }\r
1132\r
1133 /**\r
1134 Generate PPI declaration element using parameters passed in.\r
1135 \r
1136 @param ppiDeclEntryName Name attribute of Entry element\r
1137 @param ppiDeclCName CName element value\r
1138 @param ppiDeclGuid Guid element value\r
1139 @param ppiDeclFeatureFlag Reserved\r
1140 **/\r
1141 public void genSpdPpiDeclarations(String ppiDeclEntryName, String ppiDeclCName, String ppiDeclGuid,\r
1142 String ppiDeclFeatureFlag, Vector<String> archList, Vector<String> modTypeList) {\r
1143 if (getSpdPpiDeclarations() == null) {\r
1144 spdPpiDeclarations = psaRoot.addNewPpiDeclarations();\r
1145 }\r
1146\r
1147 setSpdEntry(ppiDeclEntryName, ppiDeclCName, ppiDeclGuid, ppiDeclFeatureFlag, archList, modTypeList, null, spdPpiDeclarations);\r
1148 }\r
1149\r
1150 /**\r
1151 Set Entry contents using parameters passed in\r
1152 \r
1153 @param entryName Name attribute of Entry element\r
1154 @param cName CName element value\r
1155 @param guid Guid element value\r
1156 @param featureFlag Reserved\r
1157 @param parent The tag under which Entry element goes to\r
1158 **/\r
1159 public void setSpdEntry(String entryName, String cName, String guid, String help, \r
1160 Vector<String> archList, Vector<String> modTypeList,\r
1161 Vector<String> guidTypeList, XmlObject parent) {\r
1162\r
1163 if (parent instanceof GuidDeclarationsDocument.GuidDeclarations) {\r
1164 GuidDeclarationsDocument.GuidDeclarations.Entry e = ((GuidDeclarations) parent).addNewEntry();\r
1165 e.setName(entryName);\r
1166 e.setCName(cName);\r
1167 e.setGuidValue(guid);\r
1168 e.setHelpText(help);\r
ce73a791 1169 e.setGuidTypeList(guidTypeList);\r
1170 e.setSupArchList(archList);\r
1171 e.setSupModuleList(modTypeList);\r
1172// if (guidTypeList != null && guidTypeList.size() > 0) {\r
1173// e.setGuidTypeList(new ArrayList<String>(guidTypeList));\r
1174// }\r
1175// if (archList != null && archList.size() > 0){\r
1176// e.setSupArchList(new ArrayList<String>(archList));\r
1177// }\r
1178// if (modTypeList != null && modTypeList.size() > 0) {\r
1179// e.setSupModuleList(new ArrayList<String>(modTypeList));\r
1180// }\r
a13899c5 1181 return;\r
1182 }\r
1183 if (parent instanceof ProtocolDeclarationsDocument.ProtocolDeclarations) {\r
1184 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry pe = ((ProtocolDeclarationsDocument.ProtocolDeclarations) parent)\r
1185 .addNewEntry();\r
1186 pe.setName(entryName);\r
1187 pe.setCName(cName);\r
1188 pe.setGuidValue(guid);\r
1189 pe.setHelpText(help);\r
ce73a791 1190 pe.setSupArchList(archList);\r
1191 pe.setSupModuleList(modTypeList);\r
1192// if (archList != null && archList.size() > 0){\r
1193// pe.setSupArchList(new ArrayList<String>(archList));\r
1194// }\r
1195// if (modTypeList != null && modTypeList.size() > 0) {\r
1196// pe.setSupModuleList(new ArrayList<String>(modTypeList));\r
1197// }\r
a13899c5 1198 return;\r
1199 }\r
1200 if (parent instanceof PpiDeclarationsDocument.PpiDeclarations) {\r
1201 PpiDeclarationsDocument.PpiDeclarations.Entry ppe = ((PpiDeclarationsDocument.PpiDeclarations) parent)\r
1202 .addNewEntry();\r
1203 ppe.setName(entryName);\r
1204 ppe.setCName(cName);\r
1205 ppe.setGuidValue(guid);\r
1206 ppe.setHelpText(help);\r
ce73a791 1207 ppe.setSupArchList(archList);\r
1208 ppe.setSupModuleList(modTypeList);\r
1209// if (archList != null && archList.size() > 0){\r
1210// ppe.setSupArchList(new ArrayList<String>(archList));\r
1211// }\r
1212// if (archList != null && modTypeList.size() > 0) {\r
1213// ppe.setSupModuleList(new ArrayList<String>(modTypeList));\r
1214// }\r
a13899c5 1215 return;\r
1216 }\r
1217\r
1218 return;\r
1219\r
1220 }\r
1221\r
1222 /**\r
1223 Generate Pcd definition using parameters passed in\r
1224 \r
1225 @param pcdItemTypes ItemType attribute of PcdEntry element\r
1226 @param cName C_Name element value\r
1227 @param token Token element value\r
1228 @param dataType DatumType element value\r
1229 @param skuEnable Reserved\r
1230 @param sku Reserved\r
1231 @param maxSku Reserved\r
1232 @param hiiEnable Reserved\r
1233 @param varGuid Reserved\r
1234 @param varName Reserved\r
1235 @param defaultString DefaultString element value\r
1236 **/\r
1237 public void genSpdPcdDefinitions(String cName, String token, String dataType, String pcdItemTypes, \r
1238 String spaceGuid, String defaultString, String help, String archList,\r
1239 String modTypeList) {\r
1240 if (getSpdPcdDefinitions() == null) {\r
1241 spdPcdDefinitions = psaRoot.addNewPcdDeclarations();\r
1242 }\r
1243\r
1244 setSpdPcdEntry(pcdItemTypes, cName, token, dataType, spaceGuid, help,\r
1245 defaultString, archList, modTypeList, spdPcdDefinitions);\r
1246 }\r
1247\r
1248 /**\r
1249 Set Pcd entry contents under parent tag\r
1250 \r
1251 @param pcdItemTypes ItemType attribute of PcdEntry element\r
1252 @param cName C_Name element value\r
1253 @param token Token element value\r
1254 @param dataType DatumType element value\r
1255 @param spaceGuid Reserved\r
1256 @param help Reserved\r
1257 @param defaultString DefaultString element value\r
1258 @param parent Tag under which PcdEntry goes to\r
1259 **/\r
1260 public void setSpdPcdEntry(String pcdItemTypes, String cName, String token, String dataType, String spaceGuid, String help,\r
1261 String defaultString, String archList, String modTypeList, XmlObject parent) {\r
1262\r
1263 PcdDeclarationsDocument.PcdDeclarations.PcdEntry pe = ((PcdDeclarationsDocument.PcdDeclarations) parent).addNewPcdEntry();\r
1264 \r
1265 //ToDo: maybe multiple types in, need parse pcdItemTypes.\r
1266 String usage[] = pcdItemTypes.split("( )+");\r
1267 List<String> l = new ArrayList<String>();\r
1268 for (int i = 0; i < usage.length; ++i) {\r
1269 l.add(usage[i]); \r
1270 }\r
1271 pe.setValidUsage(l);\r
1272 pe.setCName(cName);\r
1273 pe.setToken(token);\r
1274 pe.setDatumType(PcdDataTypes.Enum.forString(dataType));\r
1275 pe.setDefaultValue(defaultString);\r
1276 pe.setTokenSpaceGuidCName(spaceGuid);\r
1277 pe.setHelpText(help);\r
1278 if (archList != null){\r
97796eaa 1279 pe.setSupArchList(stringToList(archList));\r
1280 } else {\r
1281 pe.unsetSupArchList();\r
a13899c5 1282 }\r
1283 if (modTypeList != null){\r
97796eaa 1284 pe.setSupModuleList(stringToList(modTypeList));\r
1285 } else {\r
1286 pe.unsetSupModuleList();\r
a13899c5 1287 }\r
1288 }\r
1289\r
1290 /**\r
1291 Get PpiDeclarations element\r
1292 \r
1293 @return PpiDeclarationsDocument.PpiDeclarations\r
1294 **/\r
1295 public PpiDeclarationsDocument.PpiDeclarations getSpdPpiDeclarations() {\r
1296 if (spdPpiDeclarations == null) {\r
1297 spdPpiDeclarations = psaRoot.getPpiDeclarations();\r
1298 }\r
1299 return spdPpiDeclarations;\r
1300 }\r
1301\r
1302 /**\r
1303 Get ProtocolDeclarations element\r
1304 \r
1305 @return ProtocolDeclarationsDocument.ProtocolDeclarations\r
1306 **/\r
1307 public ProtocolDeclarationsDocument.ProtocolDeclarations getSpdProtocolDeclarations() {\r
1308 if (spdProtocolDeclarations == null) {\r
1309 spdProtocolDeclarations = psaRoot.getProtocolDeclarations();\r
1310 }\r
1311 return spdProtocolDeclarations;\r
1312 }\r
1313\r
1314 /**\r
1315 Get GuidDeclarations element\r
1316 \r
1317 @return GuidDeclarationsDocument.GuidDeclarations\r
1318 **/\r
1319 public GuidDeclarationsDocument.GuidDeclarations getSpdGuidDeclarations() {\r
1320 if (spdGuidDeclarations == null) {\r
1321 spdGuidDeclarations = psaRoot.getGuidDeclarations();\r
1322 }\r
1323 return spdGuidDeclarations;\r
1324 }\r
1325\r
1326 /**\r
1327 Get PcdDefinitions element\r
1328 \r
1329 @return PcdDefinitionsDocument.PcdDefinitions\r
1330 **/\r
1331 public PcdDeclarationsDocument.PcdDeclarations getSpdPcdDefinitions() {\r
1332 if (spdPcdDefinitions == null) {\r
1333 spdPcdDefinitions = psaRoot.getPcdDeclarations();\r
1334 }\r
1335 return spdPcdDefinitions;\r
1336 }\r
1337\r
1338 /**\r
1339 Get PackageHeaders element\r
1340 \r
1341 @return PackageHeadersDocument.PackageHeaders\r
1342 **/\r
1343 public PackageHeadersDocument.PackageHeaders getSpdModHdrs() {\r
1344 if (spdModHdrs == null) {\r
1345 spdModHdrs = psaRoot.getPackageHeaders();\r
1346 }\r
1347 return spdModHdrs;\r
1348 }\r
1349\r
1350 /**\r
1351 Get MsaFiles element\r
1352 \r
1353 @return MsaFilesDocument.MsaFiles\r
1354 **/\r
1355 public MsaFilesDocument.MsaFiles getSpdMsaFiles() {\r
1356 if (spdMsaFiles == null) {\r
1357 spdMsaFiles = psaRoot.getMsaFiles();\r
1358 }\r
1359 return spdMsaFiles;\r
1360 }\r
1361\r
1362 /**\r
1363 Get LibraryClassDeclarations element\r
1364 \r
1365 @return LibraryClassDeclarationsDocument.LibraryClassDeclarations\r
1366 **/\r
1367 public LibraryClassDeclarationsDocument.LibraryClassDeclarations getSpdLibClassDeclarations() {\r
1368 if (spdLibClassDeclarations == null) {\r
1369 spdLibClassDeclarations = psaRoot.getLibraryClassDeclarations();\r
1370 }\r
1371 return spdLibClassDeclarations;\r
1372 }\r
1373\r
1374 public PackageDefinitionsDocument.PackageDefinitions getSpdPkgDefs() {\r
1375 if (spdPkgDefs == null) {\r
1376 spdPkgDefs = psaRoot.addNewPackageDefinitions();\r
1377 }\r
1378 return spdPkgDefs;\r
1379 }\r
1380 /**\r
1381 Get SpdHeader element\r
1382 \r
1383 @return SpdHeaderDocument.SpdHeader\r
1384 **/\r
1385 public SpdHeaderDocument.SpdHeader getSpdHdr() {\r
1386 if (spdHdr == null) {\r
1387 spdHdr = psaRoot.addNewSpdHeader();\r
1388 }\r
1389 return spdHdr;\r
1390 }\r
1391\r
1392 /**\r
1393 Set value to Guid element\r
1394 \r
1395 @param guid The value set to Guid element\r
1396 **/\r
1397 public void setSpdHdrGuidValue(String guid) {\r
1398 getSpdHdr().setGuidValue(guid);\r
1399 }\r
1400\r
1401 /**\r
1402 Get Version element under SpdHdr\r
1403 \r
1404 @return String\r
1405 **/\r
1406 public String getSpdHdrVer() {\r
1407 return getSpdHdr().getVersion();\r
1408 }\r
1409\r
1410 /**\r
1411 Set value to Version element\r
1412 \r
1413 @param ver The value set to Version element\r
1414 **/\r
1415 public void setSpdHdrVer(String ver) {\r
1416 getSpdHdr().setVersion(ver);\r
1417 }\r
1418\r
1419 public String getSpdHdrAbs(){\r
1420 return getSpdHdr().getAbstract();\r
1421 \r
1422 }\r
1423 \r
1424 /**\r
1425 Set value to Abstract element\r
1426 \r
1427 @param abs The value set to Abstract element\r
1428 **/\r
1429 public void setSpdHdrAbs(String abs) {\r
1430\r
1431 getSpdHdr().setAbstract(abs);\r
1432 }\r
1433 \r
1434 public String getSpdHdrDescription(){\r
1435 return getSpdHdr().getDescription(); \r
1436 }\r
1437 /**\r
1438 Set value to Description element\r
1439 \r
1440 @param des The value set to Description element\r
1441 **/\r
1442 public void setSpdHdrDescription(String des) {\r
1443 getSpdHdr().setDescription(des);\r
1444 }\r
1445 \r
1446 public String getSpdHdrCopyright(){\r
1447 return getSpdHdr().getCopyright();\r
1448 }\r
1449 /**\r
1450 Set value to Copyright element\r
1451 \r
1452 @param cpRit The value set to Copyright element\r
1453 **/\r
1454 public void setSpdHdrCopyright(String cpRit) {\r
1455\r
1456 getSpdHdr().setCopyright(cpRit);\r
1457\r
1458 }\r
1459 /**\r
1460 Get License element under SpdHdr\r
1461 \r
1462 @return String\r
1463 **/\r
1464 public String getSpdHdrLicense() {\r
1465 if (getSpdHdr().getLicense() != null) {\r
1466 return getSpdHdr().getLicense().getStringValue();\r
1467 }\r
1468 return null;\r
1469 }\r
1470\r
1471 /**\r
1472 Set value to License element\r
1473 \r
1474 @param license The value set to License element\r
1475 **/\r
1476 public void setSpdHdrLicense(String license) {\r
1477 if (getSpdHdr().getLicense() == null){\r
1478 getSpdHdr().addNewLicense().setStringValue(license);\r
1479 }\r
1480 else {\r
1481 getSpdHdr().getLicense().setStringValue(license);\r
1482 }\r
1483 }\r
1484 \r
1485 public String getSpdHdrUrl(){\r
1486 if (getSpdHdr().getLicense() != null) {\r
1487 return getSpdHdr().getLicense().getURL();\r
1488 }\r
1489 return null;\r
1490 }\r
1491 \r
1492 public void setSpdHdrUrl(String url){\r
1493 getSpdHdr().getLicense().setURL(url);\r
1494 }\r
1495\r
1496 /**\r
1497 Get PackageName element under SpdHdr\r
1498 \r
1499 @return String\r
1500 **/\r
1501 public String getSpdHdrPkgName() {\r
1502 \r
1503 return getSpdHdr().getPackageName();\r
1504 }\r
1505\r
1506 /**\r
1507 Set value to PackageName element\r
1508 \r
1509 @param pkgName The value set to PackageName element\r
1510 **/\r
1511 public void setSpdHdrPkgName(String pkgName) {\r
1512 getSpdHdr().setPackageName(pkgName);\r
1513 }\r
1514\r
1515 public String getSpdHdrGuidValue(){\r
1516 return getSpdHdr().getGuidValue();\r
1517 }\r
1518 \r
1519 /**\r
1520 Reserved method\r
1521 \r
1522 @return SpecificationDocument.Specification\r
1523 **/\r
1524 public String getSpdHdrSpec() {\r
c06e8657 1525 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 1526// return getSpdHdr().getSpecification();\r
1527 }\r
1528\r
1529 /**\r
1530 Reserved method\r
1531 \r
1532 @param spec \r
1533 **/\r
1534 public void setSpdHdrSpec(String spec) {\r
c06e8657 1535 spec = "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";\r
a13899c5 1536 getSpdHdr().setSpecification(spec);\r
1537 \r
1538 }\r
1539\r
1540 public String getSpdPkgDefsRdOnly(){\r
1541 return getSpdPkgDefs().getReadOnly() + "";\r
1542 }\r
1543 /**\r
1544 Set value to ReadOnly element\r
1545 \r
1546 @param rdOnly The value set to ReadOnly element\r
1547 **/\r
1548 public void setSpdPkgDefsRdOnly(String rdOnly) {\r
1549\r
1550 getSpdPkgDefs().setReadOnly(new Boolean(rdOnly));\r
1551 }\r
1552\r
1553 public String getSpdPkgDefsRePkg(){\r
1554 return getSpdPkgDefs().getRePackage() + "";\r
1555 }\r
1556 /**\r
1557 Set value to RePackage element\r
1558 \r
1559 @param rePkg The value set to RePackage element\r
1560 **/\r
1561 public void setSpdPkgDefsRePkg(String rePkg) {\r
1562\r
1563 getSpdPkgDefs().setRePackage(new Boolean(rePkg));\r
1564 }\r
1565\r
1566 /**\r
1567 Set value to URL element\r
1568 \r
1569 @param url The value set to URL element\r
1570 **/\r
1571// public void setSpdHdrURL(String url) {\r
1572// getSpdHdr().setURL(url);\r
1573// }\r
1574\r
1575 /**\r
1576 Get xml file\r
1577 \r
1578 @return File\r
1579 **/\r
1580 public File getFile() {\r
1581 return file;\r
1582 }\r
1583\r
1584 /**\r
1585 Set file\r
1586 \r
1587 @param file File with xml format\r
1588 **/\r
1589 public void setFile(File file) {\r
1590 this.file = file;\r
1591 }\r
1592 \r
1593 private List<String> stringToList(String s){\r
ce73a791 1594 if (s == null || s.length() == 0) {\r
a13899c5 1595 return null;\r
1596 }\r
ce73a791 1597 Vector<String> al = new Vector<String>();\r
a13899c5 1598 String[] sArray = s.split(" ");\r
1599 for(int i = 0; i < sArray.length; ++i){\r
1600 al.add(sArray[i]);\r
1601 }\r
1602 return al; \r
1603 }\r
1604 \r
ce73a791 1605 private String listToString(List l) {\r
a13899c5 1606 if (l == null) {\r
1607 return null;\r
1608 }\r
1609 String s = " ";\r
1610 ListIterator li = l.listIterator();\r
1611 while(li.hasNext()) {\r
1612 s += li.next();\r
1613 s += " ";\r
1614 }\r
1615 return s.trim();\r
1616 }\r
1617\r
1618}\r