2 Java class SpdFileContents is used to parse spd xml file.
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
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.
13 package org
.tianocore
.frameworkwizard
.packaging
.ui
;
16 import java
.io
.IOException
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
19 import java
.util
.ListIterator
;
20 import java
.util
.Vector
;
23 import org
.apache
.xmlbeans
.XmlObject
;
24 import org
.apache
.xmlbeans
.XmlOptions
;
25 import org
.apache
.xmlbeans
.XmlCursor
;
27 import org
.tianocore
.GuidDeclarationsDocument
;
29 import org
.tianocore
.LibraryClassDeclarationsDocument
;
31 import org
.tianocore
.ModuleTypeDef
;
32 import org
.tianocore
.MsaFilesDocument
;
33 import org
.tianocore
.PackageDefinitionsDocument
;
34 import org
.tianocore
.PackageHeadersDocument
;
35 import org
.tianocore
.PackageSurfaceAreaDocument
;
36 import org
.tianocore
.PcdDataTypes
;
37 import org
.tianocore
.PcdDeclarationsDocument
;
38 import org
.tianocore
.PpiDeclarationsDocument
;
39 import org
.tianocore
.ProtocolDeclarationsDocument
;
40 import org
.tianocore
.SpdHeaderDocument
;
41 import org
.tianocore
.GuidDeclarationsDocument
.GuidDeclarations
;
44 This class processes spd file contents such as add remove xml elements.
46 @since PackageEditor 1.0
49 public class SpdFileContents
{
51 private File file
= null;
53 private PackageSurfaceAreaDocument psad
= null;
55 private PackageSurfaceAreaDocument
.PackageSurfaceArea psaRoot
= null;
57 private SpdHeaderDocument
.SpdHeader spdHdr
= null;
59 private PackageDefinitionsDocument
.PackageDefinitions spdPkgDefs
= null;
61 private LibraryClassDeclarationsDocument
.LibraryClassDeclarations spdLibClassDeclarations
= null;
63 private MsaFilesDocument
.MsaFiles spdMsaFiles
= null;
65 private PackageHeadersDocument
.PackageHeaders spdModHdrs
= null;
67 private GuidDeclarationsDocument
.GuidDeclarations spdGuidDeclarations
= null;
69 private ProtocolDeclarationsDocument
.ProtocolDeclarations spdProtocolDeclarations
= null;
71 private PpiDeclarationsDocument
.PpiDeclarations spdPpiDeclarations
= null;
73 private PcdDeclarationsDocument
.PcdDeclarations spdPcdDefinitions
= null;
76 Constructor to create a new spd file
78 public SpdFileContents() {
80 psad
= PackageSurfaceAreaDocument
.Factory
.newInstance();
81 psaRoot
= psad
.addNewPackageSurfaceArea();
86 Constructor for existing document object
89 public SpdFileContents(PackageSurfaceAreaDocument
.PackageSurfaceArea psa
) {
91 spdHdr
= psaRoot
.getSpdHeader();
92 spdPkgDefs
= psaRoot
.getPackageDefinitions();
95 Constructor based on an existing spd file
97 @param f Existing spd file
99 public SpdFileContents(File f
) {
101 psad
= PackageSurfaceAreaDocument
.Factory
.parse(f
);
102 psaRoot
= psad
.getPackageSurfaceArea();
104 } catch (Exception e
) {
105 System
.out
.println(e
.toString());
110 Remove existing pcd definitions elements using XmlCursor
112 public void removeSpdPcdDefinition() {
113 XmlObject o
= psaRoot
.getPcdDeclarations();
116 XmlCursor cursor
= o
.newCursor();
118 spdPcdDefinitions
= null;
122 public void removeSpdPcdDefinition(int i
){
123 XmlObject o
= psaRoot
.getPcdDeclarations();
126 XmlCursor cursor
= o
.newCursor();
127 if (cursor
.toFirstChild()) {
128 for (int j
= 0; j
< i
; ++j
) {
129 cursor
.toNextSibling();
132 if (getSpdPcdDefinitionCount() == 0) {
141 Remove existing ppi declarations using XmlCursor
143 public void removeSpdPpiDeclaration() {
144 XmlObject o
= psaRoot
.getPpiDeclarations();
147 XmlCursor cursor
= o
.newCursor();
149 spdPpiDeclarations
= null;
153 public void removeSpdPpiDeclaration(int i
){
154 XmlObject o
= psaRoot
.getPpiDeclarations();
157 XmlCursor cursor
= o
.newCursor();
158 if (cursor
.toFirstChild()) {
159 for (int j
= 0; j
< i
; ++j
) {
160 cursor
.toNextSibling();
163 if (getSpdPpiDeclarationCount() == 0){
171 Remove existing protocols declarations using XmlCursor
173 public void removeSpdProtocolDeclaration() {
174 XmlObject o
= psaRoot
.getProtocolDeclarations();
177 XmlCursor cursor
= o
.newCursor();
179 spdProtocolDeclarations
= null;
183 public void removeSpdProtocolDeclaration(int i
) {
184 XmlObject o
= psaRoot
.getProtocolDeclarations();
187 XmlCursor cursor
= o
.newCursor();
188 if (cursor
.toFirstChild()) {
189 for (int j
= 0; j
< i
; ++j
) {
190 cursor
.toNextSibling();
193 if (getSpdProtocolDeclarationCount() == 0) {
201 Remove existing GUID declarations using XmlCursor
203 public void removeSpdGuidDeclaration() {
204 XmlObject o
= psaRoot
.getGuidDeclarations();
207 XmlCursor cursor
= o
.newCursor();
209 spdGuidDeclarations
= null;
213 public void removeSpdGuidDeclaration(int i
) {
214 XmlObject o
= psaRoot
.getGuidDeclarations();
217 XmlCursor cursor
= o
.newCursor();
218 if (cursor
.toFirstChild()) {
219 for (int j
= 0; j
< i
; ++j
) {
220 cursor
.toNextSibling();
223 if (getSpdGuidDeclarationCount() == 0) {
232 Remove existing spd package include files using XmlCursor
234 public void removeSpdPkgHeader() {
235 XmlObject o
= psaRoot
.getPackageHeaders();
238 XmlCursor cursor
= o
.newCursor();
244 public void removeSpdPkgHeader(int i
){
245 XmlObject o
= psaRoot
.getPackageHeaders();
248 XmlCursor cursor
= o
.newCursor();
249 if (cursor
.toFirstChild()) {
250 for (int j
= 0; j
< i
; ++j
) {
251 cursor
.toNextSibling();
254 if (getSpdPackageHeaderCount() == 0) {
263 Remove existing msa files using XmlCursor
265 public void removeSpdMsaFile() {
266 XmlObject o
= psaRoot
.getMsaFiles();
269 XmlCursor cursor
= o
.newCursor();
275 public void removeSpdMsaFile(int i
){
276 XmlObject o
= psaRoot
.getMsaFiles();
279 XmlCursor cursor
= o
.newCursor();
280 if (cursor
.toFirstChild()) {
281 for (int j
= 0; j
< i
; ++j
) {
282 cursor
.toNextSibling();
285 if (getSpdMsaFileCount() == 0) {
294 Remove existing library class declarations using XmlCursor
296 public void removeSpdLibClass() {
297 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
300 XmlCursor cursor
= o
.newCursor();
302 spdLibClassDeclarations
= null;
306 public void removeSpdLibClass(int i
) {
307 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
310 XmlCursor cursor
= o
.newCursor();
311 if (cursor
.toFirstChild()) {
312 for (int j
= 0; j
< i
; ++j
) {
313 cursor
.toNextSibling();
316 if (getSpdLibClassDeclarationCount() == 0) {
324 public void updateSpdLibClass(int i
, String lib
, String hdr
, String hlp
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
) {
325 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
329 XmlCursor cursor
= o
.newCursor();
330 if (cursor
.toFirstChild()) {
331 for (int j
= 0; j
< i
; ++j
) {
332 cursor
.toNextSibling();
334 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
)cursor
.getObject();
336 lc
.setIncludeHeader(hdr
);
338 if (clsUsage
!= null) {
339 lc
.setRecommendedInstanceGuid(clsUsage
);
341 if (instanceVer
!= null){
342 lc
.setRecommendedInstanceVersion(instanceVer
);
344 if (stringToList(hdrAttribArch
) != null){
345 lc
.setSupArchList(stringToList(hdrAttribArch
));
347 if (stringToList(hdrAttribModType
) != null){
348 lc
.setSupModuleList(stringToList(hdrAttribModType
));
355 public void updateSpdMsaFile(int i
, String msaFile
, String mName
, String v
, String g
){
356 XmlObject o
= psaRoot
.getMsaFiles();
360 XmlCursor cursor
= o
.newCursor();
361 if (cursor
.toFirstChild()) {
362 for (int j
= 0; j
< i
; ++j
) {
363 cursor
.toNextSibling();
365 cursor
.setTextValue(msaFile
);
372 public void updateSpdGuidDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
373 String modTypeList
, String guidTypeList
){
374 XmlObject o
= psaRoot
.getGuidDeclarations();
379 XmlCursor cursor
= o
.newCursor();
380 if (cursor
.toFirstChild()) {
381 for (int j
= 0; j
< i
; ++j
) {
382 cursor
.toNextSibling();
384 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
)cursor
.getObject();
387 e
.setGuidValue(guid
);
389 if (stringToList(guidTypeList
) != null) {
390 e
.setGuidTypeList(stringToList(guidTypeList
));
393 e
.setGuidTypeList(null);
395 if (stringToList(archList
) != null){
396 e
.setSupArchList(stringToList(archList
));
399 e
.setSupArchList(null);
401 if (stringToList(modTypeList
) != null) {
402 e
.setSupModuleList(stringToList(modTypeList
));
405 e
.setSupModuleList(null);
412 public void updateSpdPpiDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
414 XmlObject o
= psaRoot
.getPpiDeclarations();
419 XmlCursor cursor
= o
.newCursor();
420 if (cursor
.toFirstChild()) {
421 for (int j
= 0; j
< i
; ++j
) {
422 cursor
.toNextSibling();
424 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
)cursor
.getObject();
427 e
.setGuidValue(guid
);
429 if (stringToList(archList
) != null){
430 e
.setSupArchList(stringToList(archList
));
433 e
.setSupArchList(null);
435 if (stringToList(modTypeList
) != null) {
436 e
.setSupModuleList(stringToList(modTypeList
));
439 e
.setSupModuleList(null);
445 public void updateSpdProtocolDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
447 XmlObject o
= psaRoot
.getProtocolDeclarations();
452 XmlCursor cursor
= o
.newCursor();
453 if (cursor
.toFirstChild()) {
454 for (int j
= 0; j
< i
; ++j
) {
455 cursor
.toNextSibling();
457 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
)cursor
.getObject();
460 e
.setGuidValue(guid
);
462 if (stringToList(archList
) != null){
463 e
.setSupArchList(stringToList(archList
));
466 e
.setSupArchList(null);
468 if (stringToList(modTypeList
) != null) {
469 e
.setSupModuleList(stringToList(modTypeList
));
472 e
.setSupModuleList(null);
478 public void updateSpdPkgHdr(int i
, String pkgName
, String hdrName
){
479 XmlObject o
= psaRoot
.getPackageHeaders();
484 XmlCursor cursor
= o
.newCursor();
485 if (cursor
.toFirstChild()) {
486 for (int j
= 0; j
< i
; ++j
) {
487 cursor
.toNextSibling();
490 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader iph
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
)cursor
.getObject();
491 iph
.setModuleType(ModuleTypeDef
.Enum
.forString(pkgName
));
492 iph
.setStringValue(hdrName
);
497 public void updateSpdPcdDefinition(int i
, String cName
, String token
, String dataType
, String pcdItemTypes
,
498 String spaceGuid
, String defaultString
, String help
, String archList
, String modTypeList
){
499 XmlObject o
= psaRoot
.getPcdDeclarations();
502 XmlCursor cursor
= o
.newCursor();
503 if (cursor
.toFirstChild()) {
504 for (int j
= 0; j
< i
; ++j
) {
505 cursor
.toNextSibling();
507 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)cursor
.getObject();
510 e
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
511 if (pcdItemTypes
!= null && pcdItemTypes
.length() > 0) {
512 String usage
[] = pcdItemTypes
.split("( )+");
513 List
<String
> l
= new ArrayList
<String
>();
514 for (int k
= 0; k
< usage
.length
; ++k
) {
520 e
.setTokenSpaceGuidCName(spaceGuid
);
521 e
.setDefaultValue(defaultString
);
523 if (archList
!= null && archList
.length() > 0){
524 e
.setSupArchList(stringToList(archList
));
526 if (modTypeList
!= null && modTypeList
.length() > 0){
527 e
.setSupModuleList(stringToList(modTypeList
));
533 Get spd file header contents into String array
535 @param s Caller allocated String array
537 public void getSpdHdrDetails(String
[] s
) {
538 if (getSpdHdr() == null) {
539 spdHdr
= psaRoot
.addNewSpdHeader();
541 s
[0] = getSpdHdrPkgName();
542 s
[1] = getSpdHdr().getGuidValue();
543 s
[2] = getSpdHdrVer();
544 // s[3] = getSpdHdr().getAbstract();
545 s
[4] = getSpdHdr().getDescription();
546 s
[5] = getSpdHdr().getCopyright();
547 s
[6] = getSpdHdrLicense();
552 Get the number of library class declarations from the size of List
556 public int getSpdLibClassDeclarationCount() {
557 if (psaRoot
.getLibraryClassDeclarations() == null
558 || psaRoot
.getLibraryClassDeclarations().getLibraryClassList() == null) {
561 return psaRoot
.getLibraryClassDeclarations().getLibraryClassList().size();
565 Get available library class declaration into String array
566 @param libClass Caller allocated two-dimentional String array
568 public void getSpdLibClassDeclarations(String
[][] libClass
) {
569 if (psaRoot
.getLibraryClassDeclarations() == null){
573 List
<LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
> l
= psaRoot
.getLibraryClassDeclarations().getLibraryClassList();
575 ListIterator li
= l
.listIterator();
576 while (li
.hasNext()) {
577 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) li
.next();
579 libClass
[i
][0] = lc
.getName();
580 libClass
[i
][1] = lc
.getIncludeHeader();
581 libClass
[i
][2] = lc
.getHelpText();
582 libClass
[i
][3] = lc
.getRecommendedInstanceGuid();
583 libClass
[i
][4] = lc
.getRecommendedInstanceVersion();
584 if (lc
.getSupArchList() != null) {
585 libClass
[i
][5] = listToString(lc
.getSupArchList());
587 if (lc
.getSupModuleList() != null) {
588 libClass
[i
][6] = listToString(lc
.getSupModuleList());
599 Get the number of Msa files from the size of List
603 public int getSpdMsaFileCount() {
604 if (psaRoot
.getMsaFiles() == null || psaRoot
.getMsaFiles().getFilenameList() == null) {
607 return psaRoot
.getMsaFiles().getFilenameList().size();
611 Get available Msa file into String array
613 @param msaFile Caller allocated two-dimentional String array
615 public void getSpdMsaFiles(String
[][] msaFile
) {
616 if (psaRoot
.getMsaFiles() == null) {
619 List
<String
> l
= psaRoot
.getMsaFiles().getFilenameList();
621 ListIterator li
= l
.listIterator();
622 while (li
.hasNext()) {
623 msaFile
[i
][0] = (String
)li
.next();
630 Get the number of include header files in PackageHeaders from the size of List
634 public int getSpdPackageHeaderCount() {
635 if (psaRoot
.getPackageHeaders() == null || psaRoot
.getPackageHeaders().getIncludePkgHeaderList() == null) {
638 return psaRoot
.getPackageHeaders().getIncludePkgHeaderList().size();
642 Get available package header contents into String array
644 @param pkgHeader Caller allocated two-dimentional String array
646 public void getSpdPackageHeaders(String
[][] pkgHeader
) {
647 if (psaRoot
.getPackageHeaders() == null) {
651 List
<PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
> l
= psaRoot
.getPackageHeaders().getIncludePkgHeaderList();
653 ListIterator li
= l
.listIterator();
654 while (li
.hasNext()) {
655 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) li
.next();
656 if (ih
.getModuleType() != null) {
657 pkgHeader
[i
][0] = ih
.getModuleType().toString();
660 pkgHeader
[i
][1] = ih
.getStringValue();
666 Get the number of GUID declarations from the size of List
670 public int getSpdGuidDeclarationCount() {
671 if (psaRoot
.getGuidDeclarations() == null || psaRoot
.getGuidDeclarations().getEntryList() == null) {
674 return psaRoot
.getGuidDeclarations().getEntryList().size();
678 Get available Guid declaration contents into String array
680 @param guid Caller allocated two-dimentional String array
682 public void getSpdGuidDeclarations(String
[][] guid
) {
683 if (psaRoot
.getGuidDeclarations() == null) {
687 List
<GuidDeclarationsDocument
.GuidDeclarations
.Entry
> l
= psaRoot
.getGuidDeclarations().getEntryList();
689 ListIterator li
= l
.listIterator();
690 while (li
.hasNext()) {
691 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) li
693 guid
[i
][0] = e
.getName();
694 guid
[i
][1] = e
.getCName();
695 if (e
.getGuidValue() != null) {
696 guid
[i
][2] = e
.getGuidValue();
698 guid
[i
][3] = e
.getHelpText();
699 guid
[i
][4] = listToString(e
.getSupArchList());
700 guid
[i
][5] = listToString(e
.getSupModuleList());
701 guid
[i
][6] = listToString(e
.getGuidTypeList());
707 Get the number of protocol declarations from the size of List
711 public int getSpdProtocolDeclarationCount() {
712 if (psaRoot
.getProtocolDeclarations() == null || psaRoot
.getProtocolDeclarations().getEntryList() == null) {
715 return psaRoot
.getProtocolDeclarations().getEntryList().size();
719 Get available protocol declaration contents into String array
721 @param protocol Caller allocated two-dimentional String array
723 public void getSpdProtocolDeclarations(String
[][] protocol
) {
724 if (psaRoot
.getProtocolDeclarations() == null) {
728 List
<ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
> l
= psaRoot
.getProtocolDeclarations()
731 ListIterator li
= l
.listIterator();
732 while (li
.hasNext()) {
733 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) li
735 protocol
[i
][0] = e
.getName();
736 protocol
[i
][1] = e
.getCName();
737 if (e
.getGuidValue() != null) {
738 protocol
[i
][2] = e
.getGuidValue();
740 protocol
[i
][3] = e
.getHelpText();
741 protocol
[i
][4] = listToString(e
.getSupArchList());
742 protocol
[i
][5] = listToString(e
.getSupModuleList());
748 Get the number of Ppi declarations from the size of List
752 public int getSpdPpiDeclarationCount() {
753 if (psaRoot
.getPpiDeclarations() == null || psaRoot
.getPpiDeclarations().getEntryList() == null) {
756 return psaRoot
.getPpiDeclarations().getEntryList().size();
760 Get available Ppi declaration contents into String array
762 @param ppi Caller allocated two-dimentional String array
764 public void getSpdPpiDeclarations(String
[][] ppi
) {
765 if (psaRoot
.getPpiDeclarations() == null) {
769 List
<PpiDeclarationsDocument
.PpiDeclarations
.Entry
> l
= psaRoot
.getPpiDeclarations().getEntryList();
771 ListIterator li
= l
.listIterator();
772 while (li
.hasNext()) {
773 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) li
.next();
774 ppi
[i
][0] = e
.getName();
775 ppi
[i
][1] = e
.getCName();
776 if (e
.getGuidValue() != null) {
777 ppi
[i
][2] = e
.getGuidValue();
779 ppi
[i
][3] = e
.getHelpText();
780 ppi
[i
][4] = listToString(e
.getSupArchList());
781 ppi
[i
][5] = listToString(e
.getSupModuleList());
788 Get the number of Pcd definitions from the size of List
792 public int getSpdPcdDefinitionCount() {
793 if (psaRoot
.getPcdDeclarations() == null || psaRoot
.getPcdDeclarations().getPcdEntryList() == null) {
796 return psaRoot
.getPcdDeclarations().getPcdEntryList().size();
800 Get available Pcd definition contents into String array
802 @param pcd Caller allocated two-dimentional String array
804 public void getSpdPcdDefinitions(String
[][] pcd
, String pcdUsage
[][]) {
805 if (psaRoot
.getPcdDeclarations() == null) {
809 List
<PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
> l
= psaRoot
.getPcdDeclarations().getPcdEntryList();
811 while (i
< l
.size()) {
812 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)l
.get(i
);
813 pcd
[i
][0] = e
.getCName();
814 pcd
[i
][1] = e
.getToken() + "";
815 pcd
[i
][2] = e
.getTokenSpaceGuidCName();
816 if (e
.getDatumType() != null) {
817 pcd
[i
][3] = e
.getDatumType().toString();
819 pcd
[i
][4] = e
.getDefaultValue()+"";
820 pcd
[i
][5] = e
.getHelpText();
821 String archList
= listToString(e
.getSupArchList());
822 if (archList
!= null) {
823 pcd
[i
][6] = archList
;
825 String modTypeList
= listToString(e
.getSupModuleList());
826 if (modTypeList
!= null) {
827 pcd
[i
][7] = modTypeList
;
831 while (j
< e
.getValidUsage().size() && j
< 5) {
832 pcdUsage
[i
][j
] = (String
)e
.getValidUsage().get(j
);
840 Save the processed xml contents to file
842 @param spdFile The file to save xml contents
843 @throws IOException Exceptions during file operation
845 public void saveAs(File spdFile
) throws IOException
{
847 XmlOptions options
= new XmlOptions();
849 options
.setCharacterEncoding("UTF-8");
850 options
.setSavePrettyPrint();
851 options
.setSavePrettyPrintIndent(2);
853 psad
.save(spdFile
, options
);
854 } catch (IOException e
) {
861 Generate SpdHeader contents using parameters passed in.
863 @param pkgName PackageName
865 @param pkgVer Version
866 @param pkgAbs Abstract
867 @param pkgDes Description
868 @param pkgCpRight Copyright
869 @param pkgLicense License
870 @param pkgCreateDate Created
871 @param pkgUpdateDate Updated
873 @param pkgType PackageType
874 @param pkgRdOnly ReadOnly
875 @param pkgRePkg RePackage
876 @param pkgSpec Reserved
877 @param pkgOutDir Reserved
879 public void genSpdHeader(String pkgName
, String pkgGuid
, String pkgVer
, String pkgAbs
, String pkgDes
,
880 String pkgCpRight
, String pkgLicense
, String pkgCreateDate
, String pkgUpdateDate
,
881 String pkgURL
, String pkgType
, String pkgRdOnly
, String pkgRePkg
, String pkgSpec
,
883 if (getSpdHdr() == null) {
884 spdHdr
= psaRoot
.addNewSpdHeader();
887 setSpdHdrPkgName(pkgName
);
888 setSpdHdrGuidValue(pkgGuid
);
889 setSpdHdrVer(pkgVer
);
890 setSpdHdrAbs(pkgAbs
);
891 setSpdHdrDescription(pkgDes
);
892 setSpdHdrCopyright(pkgCpRight
);
893 setSpdHdrLicense(pkgLicense
);
896 setSpdHdrSpec(pkgSpec
);
900 Generate library class declaration element using parameters passed in
902 @param libClassBaseName LibraryClass element value
903 @param libClassUsage Reserved
904 @param incHdrFileName IncludeHeader element value
905 @param incHdrAttribGuid Reserved
906 @param incHdrAttribArch Reserved
907 @param incHdrAttribPath Reserved
908 @param incHdrAttribClass Reserved
909 @param incHdrAttribVer Reserved
910 @param incHdrAttribOverrideID Reserved
911 @param incHdrAttribModuleType Reserved
913 public void genSpdLibClassDeclarations(String libClassBaseName
, String instanceUsage
, String incHdrFileName
,
914 String help
, String incHdrAttribArch
, String incHdrAttribPath
,
915 String incHdrAttribClass
, String incHdrAttribVer
,
916 String incHdrAttribOverrideID
, String incHdrAttribModuleType
) {
917 if (getSpdLibClassDeclarations() == null) {
918 spdLibClassDeclarations
= psaRoot
.addNewLibraryClassDeclarations();
921 // add contents under LibraryClassDeclarations tag
923 setSpdLibClassDeclaration(libClassBaseName
, instanceUsage
, incHdrFileName
, help
, incHdrAttribArch
,
924 incHdrAttribPath
, incHdrAttribClass
, incHdrAttribVer
, incHdrAttribOverrideID
,
925 incHdrAttribModuleType
, spdLibClassDeclarations
);
929 Set library class declaration contents under parent tag
931 @param clsName LibraryClass element value
932 @param clsUsage Reserved
933 @param hdrFile IncludeHeader element value
934 @param hdrAttribGuid Reserved
935 @param hdrAttribArch Reserved
936 @param hdrAttribPath Reserved
937 @param hdrAttribClass Reserved
938 @param hdrAttribVer Reserved
939 @param hdrAttribOverID Reserved
940 @param hdrAttribModType Reserved
941 @param parent The tag under which library class declaration goes to
943 public void setSpdLibClassDeclaration(String clsName
, String clsUsage
, String hdrFile
, String help
,
944 String hdrAttribArch
, String hdrAttribPath
, String hdrAttribClass
,
945 String instanceVer
, String hdrAttribOverID
, String hdrAttribModType
,
948 setSpdLibraryClass(clsName
, hdrFile
, help
, clsUsage
, instanceVer
, hdrAttribArch
, hdrAttribModType
, parent
);
953 Set the contents of LibraryClass under parent element
955 @param clsName LibraryClass element value
956 @param clsUsage Reserved
957 @param parent The tag under which library class declaration goes to
959 public void setSpdLibraryClass(String clsName
, String clsIncludeFile
, String help
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
, XmlObject parent
) {
960 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= ((LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) parent
).addNewLibraryClass();
962 lc
.setIncludeHeader(clsIncludeFile
);
963 lc
.setHelpText(help
);
964 lc
.setRecommendedInstanceGuid(clsUsage
);
965 lc
.setRecommendedInstanceVersion(instanceVer
);
966 if (hdrAttribArch
!= null) {
967 lc
.setSupArchList(stringToList(hdrAttribArch
));
969 if (hdrAttribModType
!= null) {
970 lc
.setSupModuleList(stringToList(hdrAttribModType
));
976 Set contents of IncludeHeader under parent element
978 @param modType Reserved
979 @param hdrFile IncludeHeader element value
980 @param hdrAttribGuid Reserved
981 @param hdrAttribArch Reserved
982 @param hdrAttribPath Reserved
983 @param hdrAttribClass Reserved
984 @param hdrAttribVer Reserved
985 @param hdrAttribOverID Reserved
986 @param parent The tag under which library class declaration goes to
988 public void setSpdIncludeHeader(String modType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
989 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
990 String hdrAttribOverID
, XmlObject parent
) {
992 if (parent
instanceof LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) {
993 } else if (parent
instanceof PackageHeadersDocument
.PackageHeaders
) {
994 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= null;
995 ih
= ((PackageHeadersDocument
.PackageHeaders
) parent
).addNewIncludePkgHeader();
996 ih
.setStringValue(hdrFile
);
997 ih
.setModuleType(ModuleTypeDef
.Enum
.forString(modType
));
1002 if (hdrAttribGuid
!= null) {
1004 if (hdrAttribPath
!= null) {
1006 if (hdrAttribClass
!= null) {
1008 if (hdrAttribVer
!= null) {
1010 if (hdrAttribOverID
!= null) {
1016 Generate MsaFile element.
1018 @param msaFileName MsaFile element value
1019 @param archType Reserved
1021 public void genSpdMsaFiles(String msaFileName
, String moduleName
, String ver
, String guid
) {
1022 if (getSpdMsaFiles() == null) {
1023 spdMsaFiles
= psaRoot
.addNewMsaFiles();
1025 setSpdMsaFile(msaFileName
, moduleName
, ver
, guid
, spdMsaFiles
);
1030 Set MsaFile contents under parent element.
1032 @param msaFileName MsaFile element value
1033 @param parent Element under which MsaFile goes to
1035 public void setSpdMsaFile(String msaFileName
, String moduleName
, String ver
, String guid
, XmlObject parent
) {
1036 MsaFilesDocument
.MsaFiles f
= (MsaFilesDocument
.MsaFiles
)parent
;
1037 f
.addNewFilename().setStringValue(msaFileName
);
1038 // f.setFilename(msaFileName);
1039 // f.setModuleName(moduleName);
1040 // f.setModuleVersion(ver);
1041 // f.setModuleGuid(guid);
1045 Generate PackageHeader element using parameters passed in.
1047 @param ModHdrModType ModuleType attribute of IncludeHeader element
1048 @param hdrFile IncludeHeader element value
1049 @param hdrAttribGuid Reserved
1050 @param hdrAttribArch Reserved
1051 @param hdrAttribPath Reserved
1052 @param hdrAttribClass Reserved
1053 @param hdrAttribVer Reserved
1054 @param hdrAttribOverID Reserved
1056 public void genSpdModuleHeaders(String ModHdrModType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
1057 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
1058 String hdrAttribOverID
) {
1059 if (getSpdModHdrs() == null) {
1060 spdModHdrs
= psaRoot
.addNewPackageHeaders();
1064 // add IncludeHeader under PackageHeaders element
1066 setSpdIncludeHeader(ModHdrModType
, hdrFile
, hdrAttribGuid
, hdrAttribArch
, hdrAttribPath
, hdrAttribClass
,
1067 hdrAttribVer
, hdrAttribOverID
, spdModHdrs
);
1071 Generate GUID declaration element using parameters passed in.
1073 @param guidDeclEntryName Name attribute of Entry element
1074 @param guidDeclCName CName element value
1075 @param guidDeclGuid Guid element value
1076 @param guidDeclFeatureFlag Reserved
1078 public void genSpdGuidDeclarations(String guidDeclEntryName
, String guidDeclCName
, String guidDeclGuid
,
1079 String guidDeclHelp
, Vector
<String
> archList
, Vector
<String
> modTypeList
,
1080 Vector
<String
> guidTypeList
) {
1081 if (getSpdGuidDeclarations() == null) {
1082 spdGuidDeclarations
= psaRoot
.addNewGuidDeclarations();
1085 setSpdEntry(guidDeclEntryName
, guidDeclCName
, guidDeclGuid
, guidDeclHelp
, archList
, modTypeList
, guidTypeList
, spdGuidDeclarations
);
1089 Generate protocol declaration element using parameters passed in.
1091 @param protocolDeclEntryName Name attribute of Entry element
1092 @param protocolDeclCName CName element value
1093 @param protocolDeclGuid Guid element value
1094 @param protocolDeclFeatureFlag Reserved
1096 public void genSpdProtocolDeclarations(String protocolDeclEntryName
, String protocolDeclCName
,
1097 String protocolDeclGuid
, String protocolDeclFeatureFlag
,
1098 Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1099 if (getSpdProtocolDeclarations() == null) {
1100 spdProtocolDeclarations
= psaRoot
.addNewProtocolDeclarations();
1103 setSpdEntry(protocolDeclEntryName
, protocolDeclCName
, protocolDeclGuid
, protocolDeclFeatureFlag
,
1104 archList
, modTypeList
, null, spdProtocolDeclarations
);
1108 Generate PPI declaration element using parameters passed in.
1110 @param ppiDeclEntryName Name attribute of Entry element
1111 @param ppiDeclCName CName element value
1112 @param ppiDeclGuid Guid element value
1113 @param ppiDeclFeatureFlag Reserved
1115 public void genSpdPpiDeclarations(String ppiDeclEntryName
, String ppiDeclCName
, String ppiDeclGuid
,
1116 String ppiDeclFeatureFlag
, Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1117 if (getSpdPpiDeclarations() == null) {
1118 spdPpiDeclarations
= psaRoot
.addNewPpiDeclarations();
1121 setSpdEntry(ppiDeclEntryName
, ppiDeclCName
, ppiDeclGuid
, ppiDeclFeatureFlag
, archList
, modTypeList
, null, spdPpiDeclarations
);
1125 Set Entry contents using parameters passed in
1127 @param entryName Name attribute of Entry element
1128 @param cName CName element value
1129 @param guid Guid element value
1130 @param featureFlag Reserved
1131 @param parent The tag under which Entry element goes to
1133 public void setSpdEntry(String entryName
, String cName
, String guid
, String help
,
1134 Vector
<String
> archList
, Vector
<String
> modTypeList
,
1135 Vector
<String
> guidTypeList
, XmlObject parent
) {
1137 if (parent
instanceof GuidDeclarationsDocument
.GuidDeclarations
) {
1138 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= ((GuidDeclarations
) parent
).addNewEntry();
1139 e
.setName(entryName
);
1141 e
.setGuidValue(guid
);
1142 e
.setHelpText(help
);
1143 e
.setGuidTypeList(guidTypeList
);
1144 e
.setSupArchList(archList
);
1145 e
.setSupModuleList(modTypeList
);
1146 // if (guidTypeList != null && guidTypeList.size() > 0) {
1147 // e.setGuidTypeList(new ArrayList<String>(guidTypeList));
1149 // if (archList != null && archList.size() > 0){
1150 // e.setSupArchList(new ArrayList<String>(archList));
1152 // if (modTypeList != null && modTypeList.size() > 0) {
1153 // e.setSupModuleList(new ArrayList<String>(modTypeList));
1157 if (parent
instanceof ProtocolDeclarationsDocument
.ProtocolDeclarations
) {
1158 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry pe
= ((ProtocolDeclarationsDocument
.ProtocolDeclarations
) parent
)
1160 pe
.setName(entryName
);
1162 pe
.setGuidValue(guid
);
1163 pe
.setHelpText(help
);
1164 pe
.setSupArchList(archList
);
1165 pe
.setSupModuleList(modTypeList
);
1166 // if (archList != null && archList.size() > 0){
1167 // pe.setSupArchList(new ArrayList<String>(archList));
1169 // if (modTypeList != null && modTypeList.size() > 0) {
1170 // pe.setSupModuleList(new ArrayList<String>(modTypeList));
1174 if (parent
instanceof PpiDeclarationsDocument
.PpiDeclarations
) {
1175 PpiDeclarationsDocument
.PpiDeclarations
.Entry ppe
= ((PpiDeclarationsDocument
.PpiDeclarations
) parent
)
1177 ppe
.setName(entryName
);
1178 ppe
.setCName(cName
);
1179 ppe
.setGuidValue(guid
);
1180 ppe
.setHelpText(help
);
1181 ppe
.setSupArchList(archList
);
1182 ppe
.setSupModuleList(modTypeList
);
1183 // if (archList != null && archList.size() > 0){
1184 // ppe.setSupArchList(new ArrayList<String>(archList));
1186 // if (archList != null && modTypeList.size() > 0) {
1187 // ppe.setSupModuleList(new ArrayList<String>(modTypeList));
1197 Generate Pcd definition using parameters passed in
1199 @param pcdItemTypes ItemType attribute of PcdEntry element
1200 @param cName C_Name element value
1201 @param token Token element value
1202 @param dataType DatumType element value
1203 @param skuEnable Reserved
1205 @param maxSku Reserved
1206 @param hiiEnable Reserved
1207 @param varGuid Reserved
1208 @param varName Reserved
1209 @param defaultString DefaultString element value
1211 public void genSpdPcdDefinitions(String cName
, String token
, String dataType
, String pcdItemTypes
,
1212 String spaceGuid
, String defaultString
, String help
, String archList
,
1213 String modTypeList
) {
1214 if (getSpdPcdDefinitions() == null) {
1215 spdPcdDefinitions
= psaRoot
.addNewPcdDeclarations();
1218 setSpdPcdEntry(pcdItemTypes
, cName
, token
, dataType
, spaceGuid
, help
,
1219 defaultString
, archList
, modTypeList
, spdPcdDefinitions
);
1223 Set Pcd entry contents under parent tag
1225 @param pcdItemTypes ItemType attribute of PcdEntry element
1226 @param cName C_Name element value
1227 @param token Token element value
1228 @param dataType DatumType element value
1229 @param spaceGuid Reserved
1230 @param help Reserved
1231 @param defaultString DefaultString element value
1232 @param parent Tag under which PcdEntry goes to
1234 public void setSpdPcdEntry(String pcdItemTypes
, String cName
, String token
, String dataType
, String spaceGuid
, String help
,
1235 String defaultString
, String archList
, String modTypeList
, XmlObject parent
) {
1237 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry pe
= ((PcdDeclarationsDocument
.PcdDeclarations
) parent
).addNewPcdEntry();
1239 //ToDo: maybe multiple types in, need parse pcdItemTypes.
1240 String usage
[] = pcdItemTypes
.split("( )+");
1241 List
<String
> l
= new ArrayList
<String
>();
1242 for (int i
= 0; i
< usage
.length
; ++i
) {
1245 pe
.setValidUsage(l
);
1248 pe
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1249 pe
.setDefaultValue(defaultString
);
1250 pe
.setTokenSpaceGuidCName(spaceGuid
);
1251 pe
.setHelpText(help
);
1252 if (archList
!= null){
1253 pe
.setSupArchList(stringToList(archList
));
1255 if (modTypeList
!= null){
1256 pe
.setSupModuleList(stringToList(modTypeList
));
1261 Get PpiDeclarations element
1263 @return PpiDeclarationsDocument.PpiDeclarations
1265 public PpiDeclarationsDocument
.PpiDeclarations
getSpdPpiDeclarations() {
1266 if (spdPpiDeclarations
== null) {
1267 spdPpiDeclarations
= psaRoot
.getPpiDeclarations();
1269 return spdPpiDeclarations
;
1273 Get ProtocolDeclarations element
1275 @return ProtocolDeclarationsDocument.ProtocolDeclarations
1277 public ProtocolDeclarationsDocument
.ProtocolDeclarations
getSpdProtocolDeclarations() {
1278 if (spdProtocolDeclarations
== null) {
1279 spdProtocolDeclarations
= psaRoot
.getProtocolDeclarations();
1281 return spdProtocolDeclarations
;
1285 Get GuidDeclarations element
1287 @return GuidDeclarationsDocument.GuidDeclarations
1289 public GuidDeclarationsDocument
.GuidDeclarations
getSpdGuidDeclarations() {
1290 if (spdGuidDeclarations
== null) {
1291 spdGuidDeclarations
= psaRoot
.getGuidDeclarations();
1293 return spdGuidDeclarations
;
1297 Get PcdDefinitions element
1299 @return PcdDefinitionsDocument.PcdDefinitions
1301 public PcdDeclarationsDocument
.PcdDeclarations
getSpdPcdDefinitions() {
1302 if (spdPcdDefinitions
== null) {
1303 spdPcdDefinitions
= psaRoot
.getPcdDeclarations();
1305 return spdPcdDefinitions
;
1309 Get PackageHeaders element
1311 @return PackageHeadersDocument.PackageHeaders
1313 public PackageHeadersDocument
.PackageHeaders
getSpdModHdrs() {
1314 if (spdModHdrs
== null) {
1315 spdModHdrs
= psaRoot
.getPackageHeaders();
1321 Get MsaFiles element
1323 @return MsaFilesDocument.MsaFiles
1325 public MsaFilesDocument
.MsaFiles
getSpdMsaFiles() {
1326 if (spdMsaFiles
== null) {
1327 spdMsaFiles
= psaRoot
.getMsaFiles();
1333 Get LibraryClassDeclarations element
1335 @return LibraryClassDeclarationsDocument.LibraryClassDeclarations
1337 public LibraryClassDeclarationsDocument
.LibraryClassDeclarations
getSpdLibClassDeclarations() {
1338 if (spdLibClassDeclarations
== null) {
1339 spdLibClassDeclarations
= psaRoot
.getLibraryClassDeclarations();
1341 return spdLibClassDeclarations
;
1344 public PackageDefinitionsDocument
.PackageDefinitions
getSpdPkgDefs() {
1345 if (spdPkgDefs
== null) {
1346 spdPkgDefs
= psaRoot
.addNewPackageDefinitions();
1351 Get SpdHeader element
1353 @return SpdHeaderDocument.SpdHeader
1355 public SpdHeaderDocument
.SpdHeader
getSpdHdr() {
1356 if (spdHdr
== null) {
1357 spdHdr
= psaRoot
.addNewSpdHeader();
1363 Set value to Guid element
1365 @param guid The value set to Guid element
1367 public void setSpdHdrGuidValue(String guid
) {
1368 getSpdHdr().setGuidValue(guid
);
1372 Get Version element under SpdHdr
1376 public String
getSpdHdrVer() {
1377 return getSpdHdr().getVersion();
1381 Set value to Version element
1383 @param ver The value set to Version element
1385 public void setSpdHdrVer(String ver
) {
1386 getSpdHdr().setVersion(ver
);
1389 public String
getSpdHdrAbs(){
1390 return getSpdHdr().getAbstract();
1395 Set value to Abstract element
1397 @param abs The value set to Abstract element
1399 public void setSpdHdrAbs(String abs
) {
1401 getSpdHdr().setAbstract(abs
);
1404 public String
getSpdHdrDescription(){
1405 return getSpdHdr().getDescription();
1408 Set value to Description element
1410 @param des The value set to Description element
1412 public void setSpdHdrDescription(String des
) {
1413 getSpdHdr().setDescription(des
);
1416 public String
getSpdHdrCopyright(){
1417 return getSpdHdr().getCopyright();
1420 Set value to Copyright element
1422 @param cpRit The value set to Copyright element
1424 public void setSpdHdrCopyright(String cpRit
) {
1426 getSpdHdr().setCopyright(cpRit
);
1430 Get License element under SpdHdr
1434 public String
getSpdHdrLicense() {
1435 if (getSpdHdr().getLicense() != null) {
1436 return getSpdHdr().getLicense().getStringValue();
1442 Set value to License element
1444 @param license The value set to License element
1446 public void setSpdHdrLicense(String license
) {
1447 if (getSpdHdr().getLicense() == null){
1448 getSpdHdr().addNewLicense().setStringValue(license
);
1451 getSpdHdr().getLicense().setStringValue(license
);
1455 public String
getSpdHdrUrl(){
1456 if (getSpdHdr().getLicense() != null) {
1457 return getSpdHdr().getLicense().getURL();
1462 public void setSpdHdrUrl(String url
){
1463 getSpdHdr().getLicense().setURL(url
);
1467 Get PackageName element under SpdHdr
1471 public String
getSpdHdrPkgName() {
1473 return getSpdHdr().getPackageName();
1477 Set value to PackageName element
1479 @param pkgName The value set to PackageName element
1481 public void setSpdHdrPkgName(String pkgName
) {
1482 getSpdHdr().setPackageName(pkgName
);
1485 public String
getSpdHdrGuidValue(){
1486 return getSpdHdr().getGuidValue();
1492 @return SpecificationDocument.Specification
1494 public String
getSpdHdrSpec() {
1495 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1496 // return getSpdHdr().getSpecification();
1504 public void setSpdHdrSpec(String spec
) {
1505 spec
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1506 getSpdHdr().setSpecification(spec
);
1510 public String
getSpdPkgDefsRdOnly(){
1511 return getSpdPkgDefs().getReadOnly() + "";
1514 Set value to ReadOnly element
1516 @param rdOnly The value set to ReadOnly element
1518 public void setSpdPkgDefsRdOnly(String rdOnly
) {
1520 getSpdPkgDefs().setReadOnly(new Boolean(rdOnly
));
1523 public String
getSpdPkgDefsRePkg(){
1524 return getSpdPkgDefs().getRePackage() + "";
1527 Set value to RePackage element
1529 @param rePkg The value set to RePackage element
1531 public void setSpdPkgDefsRePkg(String rePkg
) {
1533 getSpdPkgDefs().setRePackage(new Boolean(rePkg
));
1537 Set value to URL element
1539 @param url The value set to URL element
1541 // public void setSpdHdrURL(String url) {
1542 // getSpdHdr().setURL(url);
1550 public File
getFile() {
1557 @param file File with xml format
1559 public void setFile(File file
) {
1563 private List
<String
> stringToList(String s
){
1564 if (s
== null || s
.length() == 0) {
1567 Vector
<String
> al
= new Vector
<String
>();
1568 String
[] sArray
= s
.split(" ");
1569 for(int i
= 0; i
< sArray
.length
; ++i
){
1575 private String
listToString(List l
) {
1580 ListIterator li
= l
.listIterator();
1581 while(li
.hasNext()) {