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 // LAH added logic so you cannot set the version unless the GUID is defined.
583 if (lc
.getRecommendedInstanceGuid() != null) {
584 libClass
[i
][3] = lc
.getRecommendedInstanceGuid();
585 if (lc
.getRecommendedInstanceVersion() != null) {
586 libClass
[i
][4] = lc
.getRecommendedInstanceVersion();
589 if (lc
.getSupArchList() != null) {
590 libClass
[i
][5] = listToString(lc
.getSupArchList());
592 if (lc
.getSupModuleList() != null) {
593 libClass
[i
][6] = listToString(lc
.getSupModuleList());
604 Get the number of Msa files from the size of List
608 public int getSpdMsaFileCount() {
609 if (psaRoot
.getMsaFiles() == null || psaRoot
.getMsaFiles().getFilenameList() == null) {
612 return psaRoot
.getMsaFiles().getFilenameList().size();
616 Get available Msa file into String array
618 @param msaFile Caller allocated two-dimentional String array
620 public void getSpdMsaFiles(String
[][] msaFile
) {
621 if (psaRoot
.getMsaFiles() == null) {
624 List
<String
> l
= psaRoot
.getMsaFiles().getFilenameList();
626 ListIterator li
= l
.listIterator();
627 while (li
.hasNext()) {
628 msaFile
[i
][0] = (String
)li
.next();
635 Get the number of include header files in PackageHeaders from the size of List
639 public int getSpdPackageHeaderCount() {
640 if (psaRoot
.getPackageHeaders() == null || psaRoot
.getPackageHeaders().getIncludePkgHeaderList() == null) {
643 return psaRoot
.getPackageHeaders().getIncludePkgHeaderList().size();
647 Get available package header contents into String array
649 @param pkgHeader Caller allocated two-dimentional String array
651 public void getSpdPackageHeaders(String
[][] pkgHeader
) {
652 if (psaRoot
.getPackageHeaders() == null) {
656 List
<PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
> l
= psaRoot
.getPackageHeaders().getIncludePkgHeaderList();
658 ListIterator li
= l
.listIterator();
659 while (li
.hasNext()) {
660 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) li
.next();
661 if (ih
.getModuleType() != null) {
662 pkgHeader
[i
][0] = ih
.getModuleType().toString();
665 pkgHeader
[i
][1] = ih
.getStringValue();
671 Get the number of GUID declarations from the size of List
675 public int getSpdGuidDeclarationCount() {
676 if (psaRoot
.getGuidDeclarations() == null || psaRoot
.getGuidDeclarations().getEntryList() == null) {
679 return psaRoot
.getGuidDeclarations().getEntryList().size();
683 Get available Guid declaration contents into String array
685 @param guid Caller allocated two-dimentional String array
687 public void getSpdGuidDeclarations(String
[][] guid
) {
688 if (psaRoot
.getGuidDeclarations() == null) {
692 List
<GuidDeclarationsDocument
.GuidDeclarations
.Entry
> l
= psaRoot
.getGuidDeclarations().getEntryList();
694 ListIterator li
= l
.listIterator();
695 while (li
.hasNext()) {
696 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) li
698 guid
[i
][0] = e
.getName();
699 guid
[i
][1] = e
.getCName();
700 if (e
.getGuidValue() != null) {
701 guid
[i
][2] = e
.getGuidValue();
703 guid
[i
][3] = e
.getHelpText();
704 guid
[i
][4] = listToString(e
.getSupArchList());
705 guid
[i
][5] = listToString(e
.getSupModuleList());
706 guid
[i
][6] = listToString(e
.getGuidTypeList());
712 Get the number of protocol declarations from the size of List
716 public int getSpdProtocolDeclarationCount() {
717 if (psaRoot
.getProtocolDeclarations() == null || psaRoot
.getProtocolDeclarations().getEntryList() == null) {
720 return psaRoot
.getProtocolDeclarations().getEntryList().size();
724 Get available protocol declaration contents into String array
726 @param protocol Caller allocated two-dimentional String array
728 public void getSpdProtocolDeclarations(String
[][] protocol
) {
729 if (psaRoot
.getProtocolDeclarations() == null) {
733 List
<ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
> l
= psaRoot
.getProtocolDeclarations()
736 ListIterator li
= l
.listIterator();
737 while (li
.hasNext()) {
738 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) li
740 protocol
[i
][0] = e
.getName();
741 protocol
[i
][1] = e
.getCName();
742 if (e
.getGuidValue() != null) {
743 protocol
[i
][2] = e
.getGuidValue();
745 protocol
[i
][3] = e
.getHelpText();
746 protocol
[i
][4] = listToString(e
.getSupArchList());
747 protocol
[i
][5] = listToString(e
.getSupModuleList());
753 Get the number of Ppi declarations from the size of List
757 public int getSpdPpiDeclarationCount() {
758 if (psaRoot
.getPpiDeclarations() == null || psaRoot
.getPpiDeclarations().getEntryList() == null) {
761 return psaRoot
.getPpiDeclarations().getEntryList().size();
765 Get available Ppi declaration contents into String array
767 @param ppi Caller allocated two-dimentional String array
769 public void getSpdPpiDeclarations(String
[][] ppi
) {
770 if (psaRoot
.getPpiDeclarations() == null) {
774 List
<PpiDeclarationsDocument
.PpiDeclarations
.Entry
> l
= psaRoot
.getPpiDeclarations().getEntryList();
776 ListIterator li
= l
.listIterator();
777 while (li
.hasNext()) {
778 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) li
.next();
779 ppi
[i
][0] = e
.getName();
780 ppi
[i
][1] = e
.getCName();
781 if (e
.getGuidValue() != null) {
782 ppi
[i
][2] = e
.getGuidValue();
784 ppi
[i
][3] = e
.getHelpText();
785 ppi
[i
][4] = listToString(e
.getSupArchList());
786 ppi
[i
][5] = listToString(e
.getSupModuleList());
793 Get the number of Pcd definitions from the size of List
797 public int getSpdPcdDefinitionCount() {
798 if (psaRoot
.getPcdDeclarations() == null || psaRoot
.getPcdDeclarations().getPcdEntryList() == null) {
801 return psaRoot
.getPcdDeclarations().getPcdEntryList().size();
805 Get available Pcd definition contents into String array
807 @param pcd Caller allocated two-dimentional String array
809 public void getSpdPcdDefinitions(String
[][] pcd
, String pcdUsage
[][]) {
810 if (psaRoot
.getPcdDeclarations() == null) {
814 List
<PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
> l
= psaRoot
.getPcdDeclarations().getPcdEntryList();
816 while (i
< l
.size()) {
817 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)l
.get(i
);
818 pcd
[i
][0] = e
.getCName();
819 pcd
[i
][1] = e
.getToken() + "";
820 pcd
[i
][2] = e
.getTokenSpaceGuidCName();
821 if (e
.getDatumType() != null) {
822 pcd
[i
][3] = e
.getDatumType().toString();
824 pcd
[i
][4] = e
.getDefaultValue()+"";
825 pcd
[i
][5] = e
.getHelpText();
826 String archList
= listToString(e
.getSupArchList());
827 if (archList
!= null) {
828 pcd
[i
][6] = archList
;
830 String modTypeList
= listToString(e
.getSupModuleList());
831 if (modTypeList
!= null) {
832 pcd
[i
][7] = modTypeList
;
836 while (j
< e
.getValidUsage().size() && j
< 5) {
837 pcdUsage
[i
][j
] = (String
)e
.getValidUsage().get(j
);
845 Save the processed xml contents to file
847 @param spdFile The file to save xml contents
848 @throws IOException Exceptions during file operation
850 public void saveAs(File spdFile
) throws IOException
{
852 XmlOptions options
= new XmlOptions();
854 options
.setCharacterEncoding("UTF-8");
855 options
.setSavePrettyPrint();
856 options
.setSavePrettyPrintIndent(2);
858 psad
.save(spdFile
, options
);
859 } catch (IOException e
) {
866 Generate SpdHeader contents using parameters passed in.
868 @param pkgName PackageName
870 @param pkgVer Version
871 @param pkgAbs Abstract
872 @param pkgDes Description
873 @param pkgCpRight Copyright
874 @param pkgLicense License
875 @param pkgCreateDate Created
876 @param pkgUpdateDate Updated
878 @param pkgType PackageType
879 @param pkgRdOnly ReadOnly
880 @param pkgRePkg RePackage
881 @param pkgSpec Reserved
882 @param pkgOutDir Reserved
884 public void genSpdHeader(String pkgName
, String pkgGuid
, String pkgVer
, String pkgAbs
, String pkgDes
,
885 String pkgCpRight
, String pkgLicense
, String pkgCreateDate
, String pkgUpdateDate
,
886 String pkgURL
, String pkgType
, String pkgRdOnly
, String pkgRePkg
, String pkgSpec
,
888 if (getSpdHdr() == null) {
889 spdHdr
= psaRoot
.addNewSpdHeader();
892 setSpdHdrPkgName(pkgName
);
893 setSpdHdrGuidValue(pkgGuid
);
894 setSpdHdrVer(pkgVer
);
895 setSpdHdrAbs(pkgAbs
);
896 setSpdHdrDescription(pkgDes
);
897 setSpdHdrCopyright(pkgCpRight
);
898 setSpdHdrLicense(pkgLicense
);
901 setSpdHdrSpec(pkgSpec
);
905 Generate library class declaration element using parameters passed in
907 @param libClassBaseName LibraryClass element value
908 @param libClassUsage Reserved
909 @param incHdrFileName IncludeHeader element value
910 @param incHdrAttribGuid Reserved
911 @param incHdrAttribArch Reserved
912 @param incHdrAttribPath Reserved
913 @param incHdrAttribClass Reserved
914 @param incHdrAttribVer Reserved
915 @param incHdrAttribOverrideID Reserved
916 @param incHdrAttribModuleType Reserved
918 public void genSpdLibClassDeclarations(String libClassBaseName
, String instanceUsage
, String incHdrFileName
,
919 String help
, String incHdrAttribArch
, String incHdrAttribPath
,
920 String incHdrAttribClass
, String incHdrAttribVer
,
921 String incHdrAttribOverrideID
, String incHdrAttribModuleType
) {
922 if (getSpdLibClassDeclarations() == null) {
923 spdLibClassDeclarations
= psaRoot
.addNewLibraryClassDeclarations();
926 // add contents under LibraryClassDeclarations tag
928 setSpdLibClassDeclaration(libClassBaseName
, instanceUsage
, incHdrFileName
, help
, incHdrAttribArch
,
929 incHdrAttribPath
, incHdrAttribClass
, incHdrAttribVer
, incHdrAttribOverrideID
,
930 incHdrAttribModuleType
, spdLibClassDeclarations
);
934 Set library class declaration contents under parent tag
936 @param clsName LibraryClass element value
937 @param clsUsage Reserved
938 @param hdrFile IncludeHeader element value
939 @param hdrAttribGuid Reserved
940 @param hdrAttribArch Reserved
941 @param hdrAttribPath Reserved
942 @param hdrAttribClass Reserved
943 @param hdrAttribVer Reserved
944 @param hdrAttribOverID Reserved
945 @param hdrAttribModType Reserved
946 @param parent The tag under which library class declaration goes to
948 public void setSpdLibClassDeclaration(String clsName
, String clsUsage
, String hdrFile
, String help
,
949 String hdrAttribArch
, String hdrAttribPath
, String hdrAttribClass
,
950 String instanceVer
, String hdrAttribOverID
, String hdrAttribModType
,
953 setSpdLibraryClass(clsName
, hdrFile
, help
, clsUsage
, instanceVer
, hdrAttribArch
, hdrAttribModType
, parent
);
958 Set the contents of LibraryClass under parent element
960 @param clsName LibraryClass element value
961 @param clsUsage Reserved
962 @param parent The tag under which library class declaration goes to
964 public void setSpdLibraryClass(String clsName
, String clsIncludeFile
, String help
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
, XmlObject parent
) {
965 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= ((LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) parent
).addNewLibraryClass();
967 lc
.setIncludeHeader(clsIncludeFile
);
968 lc
.setHelpText(help
);
969 // LAH added logic so you cannot set the version unless the GUID is defined.
970 if (clsUsage
!= null) {
971 lc
.setRecommendedInstanceGuid(clsUsage
);
972 if (instanceVer
!= null) {
973 lc
.setRecommendedInstanceVersion(instanceVer
);
976 if (hdrAttribArch
!= null) {
977 lc
.setSupArchList(stringToList(hdrAttribArch
));
979 if (hdrAttribModType
!= null) {
980 lc
.setSupModuleList(stringToList(hdrAttribModType
));
986 Set contents of IncludeHeader under parent element
988 @param modType Reserved
989 @param hdrFile IncludeHeader element value
990 @param hdrAttribGuid Reserved
991 @param hdrAttribArch Reserved
992 @param hdrAttribPath Reserved
993 @param hdrAttribClass Reserved
994 @param hdrAttribVer Reserved
995 @param hdrAttribOverID Reserved
996 @param parent The tag under which library class declaration goes to
998 public void setSpdIncludeHeader(String modType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
999 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
1000 String hdrAttribOverID
, XmlObject parent
) {
1002 if (parent
instanceof LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) {
1003 } else if (parent
instanceof PackageHeadersDocument
.PackageHeaders
) {
1004 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= null;
1005 ih
= ((PackageHeadersDocument
.PackageHeaders
) parent
).addNewIncludePkgHeader();
1006 ih
.setStringValue(hdrFile
);
1007 ih
.setModuleType(ModuleTypeDef
.Enum
.forString(modType
));
1012 if (hdrAttribGuid
!= null) {
1014 if (hdrAttribPath
!= null) {
1016 if (hdrAttribClass
!= null) {
1018 if (hdrAttribVer
!= null) {
1020 if (hdrAttribOverID
!= null) {
1026 Generate MsaFile element.
1028 @param msaFileName MsaFile element value
1029 @param archType Reserved
1031 public void genSpdMsaFiles(String msaFileName
, String moduleName
, String ver
, String guid
) {
1032 if (getSpdMsaFiles() == null) {
1033 spdMsaFiles
= psaRoot
.addNewMsaFiles();
1035 setSpdMsaFile(msaFileName
, moduleName
, ver
, guid
, spdMsaFiles
);
1040 Set MsaFile contents under parent element.
1042 @param msaFileName MsaFile element value
1043 @param parent Element under which MsaFile goes to
1045 public void setSpdMsaFile(String msaFileName
, String moduleName
, String ver
, String guid
, XmlObject parent
) {
1046 MsaFilesDocument
.MsaFiles f
= (MsaFilesDocument
.MsaFiles
)parent
;
1047 f
.addNewFilename().setStringValue(msaFileName
);
1048 // f.setFilename(msaFileName);
1049 // f.setModuleName(moduleName);
1050 // f.setModuleVersion(ver);
1051 // f.setModuleGuid(guid);
1055 Generate PackageHeader element using parameters passed in.
1057 @param ModHdrModType ModuleType attribute of IncludeHeader element
1058 @param hdrFile IncludeHeader element value
1059 @param hdrAttribGuid Reserved
1060 @param hdrAttribArch Reserved
1061 @param hdrAttribPath Reserved
1062 @param hdrAttribClass Reserved
1063 @param hdrAttribVer Reserved
1064 @param hdrAttribOverID Reserved
1066 public void genSpdModuleHeaders(String ModHdrModType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
1067 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
1068 String hdrAttribOverID
) {
1069 if (getSpdModHdrs() == null) {
1070 spdModHdrs
= psaRoot
.addNewPackageHeaders();
1074 // add IncludeHeader under PackageHeaders element
1076 setSpdIncludeHeader(ModHdrModType
, hdrFile
, hdrAttribGuid
, hdrAttribArch
, hdrAttribPath
, hdrAttribClass
,
1077 hdrAttribVer
, hdrAttribOverID
, spdModHdrs
);
1081 Generate GUID declaration element using parameters passed in.
1083 @param guidDeclEntryName Name attribute of Entry element
1084 @param guidDeclCName CName element value
1085 @param guidDeclGuid Guid element value
1086 @param guidDeclFeatureFlag Reserved
1088 public void genSpdGuidDeclarations(String guidDeclEntryName
, String guidDeclCName
, String guidDeclGuid
,
1089 String guidDeclHelp
, Vector
<String
> archList
, Vector
<String
> modTypeList
,
1090 Vector
<String
> guidTypeList
) {
1091 if (getSpdGuidDeclarations() == null) {
1092 spdGuidDeclarations
= psaRoot
.addNewGuidDeclarations();
1095 setSpdEntry(guidDeclEntryName
, guidDeclCName
, guidDeclGuid
, guidDeclHelp
, archList
, modTypeList
, guidTypeList
, spdGuidDeclarations
);
1099 Generate protocol declaration element using parameters passed in.
1101 @param protocolDeclEntryName Name attribute of Entry element
1102 @param protocolDeclCName CName element value
1103 @param protocolDeclGuid Guid element value
1104 @param protocolDeclFeatureFlag Reserved
1106 public void genSpdProtocolDeclarations(String protocolDeclEntryName
, String protocolDeclCName
,
1107 String protocolDeclGuid
, String protocolDeclFeatureFlag
,
1108 Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1109 if (getSpdProtocolDeclarations() == null) {
1110 spdProtocolDeclarations
= psaRoot
.addNewProtocolDeclarations();
1113 setSpdEntry(protocolDeclEntryName
, protocolDeclCName
, protocolDeclGuid
, protocolDeclFeatureFlag
,
1114 archList
, modTypeList
, null, spdProtocolDeclarations
);
1118 Generate PPI declaration element using parameters passed in.
1120 @param ppiDeclEntryName Name attribute of Entry element
1121 @param ppiDeclCName CName element value
1122 @param ppiDeclGuid Guid element value
1123 @param ppiDeclFeatureFlag Reserved
1125 public void genSpdPpiDeclarations(String ppiDeclEntryName
, String ppiDeclCName
, String ppiDeclGuid
,
1126 String ppiDeclFeatureFlag
, Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1127 if (getSpdPpiDeclarations() == null) {
1128 spdPpiDeclarations
= psaRoot
.addNewPpiDeclarations();
1131 setSpdEntry(ppiDeclEntryName
, ppiDeclCName
, ppiDeclGuid
, ppiDeclFeatureFlag
, archList
, modTypeList
, null, spdPpiDeclarations
);
1135 Set Entry contents using parameters passed in
1137 @param entryName Name attribute of Entry element
1138 @param cName CName element value
1139 @param guid Guid element value
1140 @param featureFlag Reserved
1141 @param parent The tag under which Entry element goes to
1143 public void setSpdEntry(String entryName
, String cName
, String guid
, String help
,
1144 Vector
<String
> archList
, Vector
<String
> modTypeList
,
1145 Vector
<String
> guidTypeList
, XmlObject parent
) {
1147 if (parent
instanceof GuidDeclarationsDocument
.GuidDeclarations
) {
1148 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= ((GuidDeclarations
) parent
).addNewEntry();
1149 e
.setName(entryName
);
1151 e
.setGuidValue(guid
);
1152 e
.setHelpText(help
);
1153 e
.setGuidTypeList(guidTypeList
);
1154 e
.setSupArchList(archList
);
1155 e
.setSupModuleList(modTypeList
);
1156 // if (guidTypeList != null && guidTypeList.size() > 0) {
1157 // e.setGuidTypeList(new ArrayList<String>(guidTypeList));
1159 // if (archList != null && archList.size() > 0){
1160 // e.setSupArchList(new ArrayList<String>(archList));
1162 // if (modTypeList != null && modTypeList.size() > 0) {
1163 // e.setSupModuleList(new ArrayList<String>(modTypeList));
1167 if (parent
instanceof ProtocolDeclarationsDocument
.ProtocolDeclarations
) {
1168 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry pe
= ((ProtocolDeclarationsDocument
.ProtocolDeclarations
) parent
)
1170 pe
.setName(entryName
);
1172 pe
.setGuidValue(guid
);
1173 pe
.setHelpText(help
);
1174 pe
.setSupArchList(archList
);
1175 pe
.setSupModuleList(modTypeList
);
1176 // if (archList != null && archList.size() > 0){
1177 // pe.setSupArchList(new ArrayList<String>(archList));
1179 // if (modTypeList != null && modTypeList.size() > 0) {
1180 // pe.setSupModuleList(new ArrayList<String>(modTypeList));
1184 if (parent
instanceof PpiDeclarationsDocument
.PpiDeclarations
) {
1185 PpiDeclarationsDocument
.PpiDeclarations
.Entry ppe
= ((PpiDeclarationsDocument
.PpiDeclarations
) parent
)
1187 ppe
.setName(entryName
);
1188 ppe
.setCName(cName
);
1189 ppe
.setGuidValue(guid
);
1190 ppe
.setHelpText(help
);
1191 ppe
.setSupArchList(archList
);
1192 ppe
.setSupModuleList(modTypeList
);
1193 // if (archList != null && archList.size() > 0){
1194 // ppe.setSupArchList(new ArrayList<String>(archList));
1196 // if (archList != null && modTypeList.size() > 0) {
1197 // ppe.setSupModuleList(new ArrayList<String>(modTypeList));
1207 Generate Pcd definition using parameters passed in
1209 @param pcdItemTypes ItemType attribute of PcdEntry element
1210 @param cName C_Name element value
1211 @param token Token element value
1212 @param dataType DatumType element value
1213 @param skuEnable Reserved
1215 @param maxSku Reserved
1216 @param hiiEnable Reserved
1217 @param varGuid Reserved
1218 @param varName Reserved
1219 @param defaultString DefaultString element value
1221 public void genSpdPcdDefinitions(String cName
, String token
, String dataType
, String pcdItemTypes
,
1222 String spaceGuid
, String defaultString
, String help
, String archList
,
1223 String modTypeList
) {
1224 if (getSpdPcdDefinitions() == null) {
1225 spdPcdDefinitions
= psaRoot
.addNewPcdDeclarations();
1228 setSpdPcdEntry(pcdItemTypes
, cName
, token
, dataType
, spaceGuid
, help
,
1229 defaultString
, archList
, modTypeList
, spdPcdDefinitions
);
1233 Set Pcd entry contents under parent tag
1235 @param pcdItemTypes ItemType attribute of PcdEntry element
1236 @param cName C_Name element value
1237 @param token Token element value
1238 @param dataType DatumType element value
1239 @param spaceGuid Reserved
1240 @param help Reserved
1241 @param defaultString DefaultString element value
1242 @param parent Tag under which PcdEntry goes to
1244 public void setSpdPcdEntry(String pcdItemTypes
, String cName
, String token
, String dataType
, String spaceGuid
, String help
,
1245 String defaultString
, String archList
, String modTypeList
, XmlObject parent
) {
1247 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry pe
= ((PcdDeclarationsDocument
.PcdDeclarations
) parent
).addNewPcdEntry();
1249 //ToDo: maybe multiple types in, need parse pcdItemTypes.
1250 String usage
[] = pcdItemTypes
.split("( )+");
1251 List
<String
> l
= new ArrayList
<String
>();
1252 for (int i
= 0; i
< usage
.length
; ++i
) {
1255 pe
.setValidUsage(l
);
1258 pe
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1259 pe
.setDefaultValue(defaultString
);
1260 pe
.setTokenSpaceGuidCName(spaceGuid
);
1261 pe
.setHelpText(help
);
1262 if (archList
!= null){
1263 pe
.setSupArchList(stringToList(archList
));
1265 if (modTypeList
!= null){
1266 pe
.setSupModuleList(stringToList(modTypeList
));
1271 Get PpiDeclarations element
1273 @return PpiDeclarationsDocument.PpiDeclarations
1275 public PpiDeclarationsDocument
.PpiDeclarations
getSpdPpiDeclarations() {
1276 if (spdPpiDeclarations
== null) {
1277 spdPpiDeclarations
= psaRoot
.getPpiDeclarations();
1279 return spdPpiDeclarations
;
1283 Get ProtocolDeclarations element
1285 @return ProtocolDeclarationsDocument.ProtocolDeclarations
1287 public ProtocolDeclarationsDocument
.ProtocolDeclarations
getSpdProtocolDeclarations() {
1288 if (spdProtocolDeclarations
== null) {
1289 spdProtocolDeclarations
= psaRoot
.getProtocolDeclarations();
1291 return spdProtocolDeclarations
;
1295 Get GuidDeclarations element
1297 @return GuidDeclarationsDocument.GuidDeclarations
1299 public GuidDeclarationsDocument
.GuidDeclarations
getSpdGuidDeclarations() {
1300 if (spdGuidDeclarations
== null) {
1301 spdGuidDeclarations
= psaRoot
.getGuidDeclarations();
1303 return spdGuidDeclarations
;
1307 Get PcdDefinitions element
1309 @return PcdDefinitionsDocument.PcdDefinitions
1311 public PcdDeclarationsDocument
.PcdDeclarations
getSpdPcdDefinitions() {
1312 if (spdPcdDefinitions
== null) {
1313 spdPcdDefinitions
= psaRoot
.getPcdDeclarations();
1315 return spdPcdDefinitions
;
1319 Get PackageHeaders element
1321 @return PackageHeadersDocument.PackageHeaders
1323 public PackageHeadersDocument
.PackageHeaders
getSpdModHdrs() {
1324 if (spdModHdrs
== null) {
1325 spdModHdrs
= psaRoot
.getPackageHeaders();
1331 Get MsaFiles element
1333 @return MsaFilesDocument.MsaFiles
1335 public MsaFilesDocument
.MsaFiles
getSpdMsaFiles() {
1336 if (spdMsaFiles
== null) {
1337 spdMsaFiles
= psaRoot
.getMsaFiles();
1343 Get LibraryClassDeclarations element
1345 @return LibraryClassDeclarationsDocument.LibraryClassDeclarations
1347 public LibraryClassDeclarationsDocument
.LibraryClassDeclarations
getSpdLibClassDeclarations() {
1348 if (spdLibClassDeclarations
== null) {
1349 spdLibClassDeclarations
= psaRoot
.getLibraryClassDeclarations();
1351 return spdLibClassDeclarations
;
1354 public PackageDefinitionsDocument
.PackageDefinitions
getSpdPkgDefs() {
1355 if (spdPkgDefs
== null) {
1356 spdPkgDefs
= psaRoot
.addNewPackageDefinitions();
1361 Get SpdHeader element
1363 @return SpdHeaderDocument.SpdHeader
1365 public SpdHeaderDocument
.SpdHeader
getSpdHdr() {
1366 if (spdHdr
== null) {
1367 spdHdr
= psaRoot
.addNewSpdHeader();
1373 Set value to Guid element
1375 @param guid The value set to Guid element
1377 public void setSpdHdrGuidValue(String guid
) {
1378 getSpdHdr().setGuidValue(guid
);
1382 Get Version element under SpdHdr
1386 public String
getSpdHdrVer() {
1387 return getSpdHdr().getVersion();
1391 Set value to Version element
1393 @param ver The value set to Version element
1395 public void setSpdHdrVer(String ver
) {
1396 getSpdHdr().setVersion(ver
);
1399 public String
getSpdHdrAbs(){
1400 return getSpdHdr().getAbstract();
1405 Set value to Abstract element
1407 @param abs The value set to Abstract element
1409 public void setSpdHdrAbs(String abs
) {
1411 getSpdHdr().setAbstract(abs
);
1414 public String
getSpdHdrDescription(){
1415 return getSpdHdr().getDescription();
1418 Set value to Description element
1420 @param des The value set to Description element
1422 public void setSpdHdrDescription(String des
) {
1423 getSpdHdr().setDescription(des
);
1426 public String
getSpdHdrCopyright(){
1427 return getSpdHdr().getCopyright();
1430 Set value to Copyright element
1432 @param cpRit The value set to Copyright element
1434 public void setSpdHdrCopyright(String cpRit
) {
1436 getSpdHdr().setCopyright(cpRit
);
1440 Get License element under SpdHdr
1444 public String
getSpdHdrLicense() {
1445 if (getSpdHdr().getLicense() != null) {
1446 return getSpdHdr().getLicense().getStringValue();
1452 Set value to License element
1454 @param license The value set to License element
1456 public void setSpdHdrLicense(String license
) {
1457 if (getSpdHdr().getLicense() == null){
1458 getSpdHdr().addNewLicense().setStringValue(license
);
1461 getSpdHdr().getLicense().setStringValue(license
);
1465 public String
getSpdHdrUrl(){
1466 if (getSpdHdr().getLicense() != null) {
1467 return getSpdHdr().getLicense().getURL();
1472 public void setSpdHdrUrl(String url
){
1473 getSpdHdr().getLicense().setURL(url
);
1477 Get PackageName element under SpdHdr
1481 public String
getSpdHdrPkgName() {
1483 return getSpdHdr().getPackageName();
1487 Set value to PackageName element
1489 @param pkgName The value set to PackageName element
1491 public void setSpdHdrPkgName(String pkgName
) {
1492 getSpdHdr().setPackageName(pkgName
);
1495 public String
getSpdHdrGuidValue(){
1496 return getSpdHdr().getGuidValue();
1502 @return SpecificationDocument.Specification
1504 public String
getSpdHdrSpec() {
1505 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1506 // return getSpdHdr().getSpecification();
1514 public void setSpdHdrSpec(String spec
) {
1515 spec
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1516 getSpdHdr().setSpecification(spec
);
1520 public String
getSpdPkgDefsRdOnly(){
1521 return getSpdPkgDefs().getReadOnly() + "";
1524 Set value to ReadOnly element
1526 @param rdOnly The value set to ReadOnly element
1528 public void setSpdPkgDefsRdOnly(String rdOnly
) {
1530 getSpdPkgDefs().setReadOnly(new Boolean(rdOnly
));
1533 public String
getSpdPkgDefsRePkg(){
1534 return getSpdPkgDefs().getRePackage() + "";
1537 Set value to RePackage element
1539 @param rePkg The value set to RePackage element
1541 public void setSpdPkgDefsRePkg(String rePkg
) {
1543 getSpdPkgDefs().setRePackage(new Boolean(rePkg
));
1547 Set value to URL element
1549 @param url The value set to URL element
1551 // public void setSpdHdrURL(String url) {
1552 // getSpdHdr().setURL(url);
1560 public File
getFile() {
1567 @param file File with xml format
1569 public void setFile(File file
) {
1573 private List
<String
> stringToList(String s
){
1574 if (s
== null || s
.length() == 0) {
1577 Vector
<String
> al
= new Vector
<String
>();
1578 String
[] sArray
= s
.split(" ");
1579 for(int i
= 0; i
< sArray
.length
; ++i
){
1585 private String
listToString(List l
) {
1590 ListIterator li
= l
.listIterator();
1591 while(li
.hasNext()) {