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();
137 Remove existing ppi declarations using XmlCursor
139 public void removeSpdPpiDeclaration() {
140 XmlObject o
= psaRoot
.getPpiDeclarations();
143 XmlCursor cursor
= o
.newCursor();
145 spdPpiDeclarations
= null;
149 public void removeSpdPpiDeclaration(int i
){
150 XmlObject o
= psaRoot
.getPpiDeclarations();
153 XmlCursor cursor
= o
.newCursor();
154 if (cursor
.toFirstChild()) {
155 for (int j
= 0; j
< i
; ++j
) {
156 cursor
.toNextSibling();
163 Remove existing protocols declarations using XmlCursor
165 public void removeSpdProtocolDeclaration() {
166 XmlObject o
= psaRoot
.getProtocolDeclarations();
169 XmlCursor cursor
= o
.newCursor();
171 spdProtocolDeclarations
= null;
175 public void removeSpdProtocolDeclaration(int i
) {
176 XmlObject o
= psaRoot
.getProtocolDeclarations();
179 XmlCursor cursor
= o
.newCursor();
180 if (cursor
.toFirstChild()) {
181 for (int j
= 0; j
< i
; ++j
) {
182 cursor
.toNextSibling();
189 Remove existing GUID declarations using XmlCursor
191 public void removeSpdGuidDeclaration() {
192 XmlObject o
= psaRoot
.getGuidDeclarations();
195 XmlCursor cursor
= o
.newCursor();
197 spdGuidDeclarations
= null;
201 public void removeSpdGuidDeclaration(int i
) {
202 XmlObject o
= psaRoot
.getGuidDeclarations();
205 XmlCursor cursor
= o
.newCursor();
206 if (cursor
.toFirstChild()) {
207 for (int j
= 0; j
< i
; ++j
) {
208 cursor
.toNextSibling();
217 Remove existing spd package include files using XmlCursor
219 public void removeSpdPkgHeader() {
220 XmlObject o
= psaRoot
.getPackageHeaders();
223 XmlCursor cursor
= o
.newCursor();
229 public void removeSpdPkgHeader(int i
){
230 XmlObject o
= psaRoot
.getPackageHeaders();
233 XmlCursor cursor
= o
.newCursor();
234 if (cursor
.toFirstChild()) {
235 for (int j
= 0; j
< i
; ++j
) {
236 cursor
.toNextSibling();
244 Remove existing msa files using XmlCursor
246 public void removeSpdMsaFile() {
247 XmlObject o
= psaRoot
.getMsaFiles();
250 XmlCursor cursor
= o
.newCursor();
256 public void removeSpdMsaFile(int i
){
257 XmlObject o
= psaRoot
.getMsaFiles();
260 XmlCursor cursor
= o
.newCursor();
261 if (cursor
.toFirstChild()) {
262 for (int j
= 0; j
< i
; ++j
) {
263 cursor
.toNextSibling();
271 Remove existing library class declarations using XmlCursor
273 public void removeSpdLibClass() {
274 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
277 XmlCursor cursor
= o
.newCursor();
279 spdLibClassDeclarations
= null;
283 public void removeSpdLibClass(int i
) {
284 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
287 XmlCursor cursor
= o
.newCursor();
288 if (cursor
.toFirstChild()) {
289 for (int j
= 0; j
< i
; ++j
) {
290 cursor
.toNextSibling();
297 public void updateSpdLibClass(int i
, String lib
, String hdr
, String hlp
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
) {
298 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
302 XmlCursor cursor
= o
.newCursor();
303 if (cursor
.toFirstChild()) {
304 for (int j
= 0; j
< i
; ++j
) {
305 cursor
.toNextSibling();
307 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
)cursor
.getObject();
309 lc
.setIncludeHeader(hdr
);
311 if (clsUsage
!= null) {
312 lc
.setRecommendedInstanceGuid(clsUsage
);
314 if (instanceVer
!= null){
315 lc
.setRecommendedInstanceVersion(instanceVer
);
317 if (stringToList(hdrAttribArch
) != null){
318 lc
.setSupArchList(stringToList(hdrAttribArch
));
320 if (stringToList(hdrAttribModType
) != null){
321 lc
.setSupModuleList(stringToList(hdrAttribModType
));
328 public void updateSpdMsaFile(int i
, String msaFile
, String mName
, String v
, String g
){
329 XmlObject o
= psaRoot
.getMsaFiles();
333 XmlCursor cursor
= o
.newCursor();
334 if (cursor
.toFirstChild()) {
335 for (int j
= 0; j
< i
; ++j
) {
336 cursor
.toNextSibling();
338 cursor
.setTextValue(msaFile
);
345 public void updateSpdGuidDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
346 String modTypeList
, String guidTypeList
){
347 XmlObject o
= psaRoot
.getGuidDeclarations();
352 XmlCursor cursor
= o
.newCursor();
353 if (cursor
.toFirstChild()) {
354 for (int j
= 0; j
< i
; ++j
) {
355 cursor
.toNextSibling();
357 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
)cursor
.getObject();
360 e
.setGuidValue(guid
);
362 if (stringToList(guidTypeList
) != null) {
363 e
.setGuidTypeList(stringToList(guidTypeList
));
366 e
.setGuidTypeList(null);
368 if (stringToList(archList
) != null){
369 e
.setSupArchList(stringToList(archList
));
372 e
.setSupArchList(null);
374 if (stringToList(modTypeList
) != null) {
375 e
.setSupModuleList(stringToList(modTypeList
));
378 e
.setSupModuleList(null);
385 public void updateSpdPpiDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
387 XmlObject o
= psaRoot
.getPpiDeclarations();
392 XmlCursor cursor
= o
.newCursor();
393 if (cursor
.toFirstChild()) {
394 for (int j
= 0; j
< i
; ++j
) {
395 cursor
.toNextSibling();
397 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
)cursor
.getObject();
400 e
.setGuidValue(guid
);
402 if (stringToList(archList
) != null){
403 e
.setSupArchList(stringToList(archList
));
406 e
.setSupArchList(null);
408 if (stringToList(modTypeList
) != null) {
409 e
.setSupModuleList(stringToList(modTypeList
));
412 e
.setSupModuleList(null);
418 public void updateSpdProtocolDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
420 XmlObject o
= psaRoot
.getProtocolDeclarations();
425 XmlCursor cursor
= o
.newCursor();
426 if (cursor
.toFirstChild()) {
427 for (int j
= 0; j
< i
; ++j
) {
428 cursor
.toNextSibling();
430 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
)cursor
.getObject();
433 e
.setGuidValue(guid
);
435 if (stringToList(archList
) != null){
436 e
.setSupArchList(stringToList(archList
));
439 e
.setSupArchList(null);
441 if (stringToList(modTypeList
) != null) {
442 e
.setSupModuleList(stringToList(modTypeList
));
445 e
.setSupModuleList(null);
451 public void updateSpdPkgHdr(int i
, String pkgName
, String hdrName
){
452 XmlObject o
= psaRoot
.getPackageHeaders();
457 XmlCursor cursor
= o
.newCursor();
458 if (cursor
.toFirstChild()) {
459 for (int j
= 0; j
< i
; ++j
) {
460 cursor
.toNextSibling();
463 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader iph
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
)cursor
.getObject();
464 iph
.setModuleType(ModuleTypeDef
.Enum
.forString(pkgName
));
465 iph
.setStringValue(hdrName
);
470 public void updateSpdPcdDefinition(int i
, String cName
, String token
, String dataType
, String pcdItemTypes
,
471 String spaceGuid
, String defaultString
, String help
, String archList
, String modTypeList
){
472 XmlObject o
= psaRoot
.getPcdDeclarations();
475 XmlCursor cursor
= o
.newCursor();
476 if (cursor
.toFirstChild()) {
477 for (int j
= 0; j
< i
; ++j
) {
478 cursor
.toNextSibling();
480 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)cursor
.getObject();
483 e
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
484 if (pcdItemTypes
!= null && pcdItemTypes
.length() > 0) {
485 String usage
[] = pcdItemTypes
.split("( )+");
486 List
<String
> l
= new ArrayList
<String
>();
487 for (int k
= 0; k
< usage
.length
; ++k
) {
493 e
.setTokenSpaceGuidCName(spaceGuid
);
494 e
.setDefaultValue(defaultString
);
496 if (archList
!= null && archList
.length() > 0){
497 e
.setSupArchList(stringToList(archList
));
499 if (modTypeList
!= null && modTypeList
.length() > 0){
500 e
.setSupModuleList(stringToList(modTypeList
));
506 Get spd file header contents into String array
508 @param s Caller allocated String array
510 public void getSpdHdrDetails(String
[] s
) {
511 if (getSpdHdr() == null) {
512 spdHdr
= psaRoot
.addNewSpdHeader();
514 s
[0] = getSpdHdrPkgName();
515 s
[1] = getSpdHdr().getGuidValue();
516 s
[2] = getSpdHdrVer();
517 // s[3] = getSpdHdr().getAbstract();
518 s
[4] = getSpdHdr().getDescription();
519 s
[5] = getSpdHdr().getCopyright();
520 s
[6] = getSpdHdrLicense();
525 Get the number of library class declarations from the size of List
529 public int getSpdLibClassDeclarationCount() {
530 if (psaRoot
.getLibraryClassDeclarations() == null
531 || psaRoot
.getLibraryClassDeclarations().getLibraryClassList() == null) {
534 return psaRoot
.getLibraryClassDeclarations().getLibraryClassList().size();
538 Get available library class declaration into String array
539 @param libClass Caller allocated two-dimentional String array
541 public void getSpdLibClassDeclarations(String
[][] libClass
) {
542 if (psaRoot
.getLibraryClassDeclarations() == null){
546 List
<LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
> l
= psaRoot
.getLibraryClassDeclarations().getLibraryClassList();
548 ListIterator li
= l
.listIterator();
549 while (li
.hasNext()) {
550 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) li
.next();
552 libClass
[i
][0] = lc
.getName();
553 libClass
[i
][1] = lc
.getIncludeHeader();
554 libClass
[i
][2] = lc
.getHelpText();
555 libClass
[i
][3] = lc
.getRecommendedInstanceGuid();
556 libClass
[i
][4] = lc
.getRecommendedInstanceVersion();
557 if (lc
.getSupArchList() != null) {
558 libClass
[i
][5] = listToString(lc
.getSupArchList());
560 if (lc
.getSupModuleList() != null) {
561 libClass
[i
][6] = listToString(lc
.getSupModuleList());
572 Get the number of Msa files from the size of List
576 public int getSpdMsaFileCount() {
577 if (psaRoot
.getMsaFiles() == null || psaRoot
.getMsaFiles().getFilenameList() == null) {
580 return psaRoot
.getMsaFiles().getFilenameList().size();
584 Get available Msa file into String array
586 @param msaFile Caller allocated two-dimentional String array
588 public void getSpdMsaFiles(String
[][] msaFile
) {
589 if (psaRoot
.getMsaFiles() == null) {
592 List
<String
> l
= psaRoot
.getMsaFiles().getFilenameList();
594 ListIterator li
= l
.listIterator();
595 while (li
.hasNext()) {
596 msaFile
[i
][0] = (String
)li
.next();
603 Get the number of include header files in PackageHeaders from the size of List
607 public int getSpdPackageHeaderCount() {
608 if (psaRoot
.getPackageHeaders() == null || psaRoot
.getPackageHeaders().getIncludePkgHeaderList() == null) {
611 return psaRoot
.getPackageHeaders().getIncludePkgHeaderList().size();
615 Get available package header contents into String array
617 @param pkgHeader Caller allocated two-dimentional String array
619 public void getSpdPackageHeaders(String
[][] pkgHeader
) {
620 if (psaRoot
.getPackageHeaders() == null) {
624 List
<PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
> l
= psaRoot
.getPackageHeaders().getIncludePkgHeaderList();
626 ListIterator li
= l
.listIterator();
627 while (li
.hasNext()) {
628 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) li
.next();
629 if (ih
.getModuleType() != null) {
630 pkgHeader
[i
][0] = ih
.getModuleType().toString();
633 pkgHeader
[i
][1] = ih
.getStringValue();
639 Get the number of GUID declarations from the size of List
643 public int getSpdGuidDeclarationCount() {
644 if (psaRoot
.getGuidDeclarations() == null || psaRoot
.getGuidDeclarations().getEntryList() == null) {
647 return psaRoot
.getGuidDeclarations().getEntryList().size();
651 Get available Guid declaration contents into String array
653 @param guid Caller allocated two-dimentional String array
655 public void getSpdGuidDeclarations(String
[][] guid
) {
656 if (psaRoot
.getGuidDeclarations() == null) {
660 List
<GuidDeclarationsDocument
.GuidDeclarations
.Entry
> l
= psaRoot
.getGuidDeclarations().getEntryList();
662 ListIterator li
= l
.listIterator();
663 while (li
.hasNext()) {
664 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) li
666 guid
[i
][0] = e
.getName();
667 guid
[i
][1] = e
.getCName();
668 if (e
.getGuidValue() != null) {
669 guid
[i
][2] = e
.getGuidValue();
671 guid
[i
][3] = e
.getHelpText();
672 guid
[i
][4] = listToString(e
.getSupArchList());
673 guid
[i
][5] = listToString(e
.getSupModuleList());
674 guid
[i
][6] = listToString(e
.getGuidTypeList());
680 Get the number of protocol declarations from the size of List
684 public int getSpdProtocolDeclarationCount() {
685 if (psaRoot
.getProtocolDeclarations() == null || psaRoot
.getProtocolDeclarations().getEntryList() == null) {
688 return psaRoot
.getProtocolDeclarations().getEntryList().size();
692 Get available protocol declaration contents into String array
694 @param protocol Caller allocated two-dimentional String array
696 public void getSpdProtocolDeclarations(String
[][] protocol
) {
697 if (psaRoot
.getProtocolDeclarations() == null) {
701 List
<ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
> l
= psaRoot
.getProtocolDeclarations()
704 ListIterator li
= l
.listIterator();
705 while (li
.hasNext()) {
706 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) li
708 protocol
[i
][0] = e
.getName();
709 protocol
[i
][1] = e
.getCName();
710 if (e
.getGuidValue() != null) {
711 protocol
[i
][2] = e
.getGuidValue();
713 protocol
[i
][3] = e
.getHelpText();
714 protocol
[i
][4] = listToString(e
.getSupArchList());
715 protocol
[i
][5] = listToString(e
.getSupModuleList());
721 Get the number of Ppi declarations from the size of List
725 public int getSpdPpiDeclarationCount() {
726 if (psaRoot
.getPpiDeclarations() == null || psaRoot
.getPpiDeclarations().getEntryList() == null) {
729 return psaRoot
.getPpiDeclarations().getEntryList().size();
733 Get available Ppi declaration contents into String array
735 @param ppi Caller allocated two-dimentional String array
737 public void getSpdPpiDeclarations(String
[][] ppi
) {
738 if (psaRoot
.getPpiDeclarations() == null) {
742 List
<PpiDeclarationsDocument
.PpiDeclarations
.Entry
> l
= psaRoot
.getPpiDeclarations().getEntryList();
744 ListIterator li
= l
.listIterator();
745 while (li
.hasNext()) {
746 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) li
.next();
747 ppi
[i
][0] = e
.getName();
748 ppi
[i
][1] = e
.getCName();
749 if (e
.getGuidValue() != null) {
750 ppi
[i
][2] = e
.getGuidValue();
752 ppi
[i
][3] = e
.getHelpText();
753 ppi
[i
][4] = listToString(e
.getSupArchList());
754 ppi
[i
][5] = listToString(e
.getSupModuleList());
761 Get the number of Pcd definitions from the size of List
765 public int getSpdPcdDefinitionCount() {
766 if (psaRoot
.getPcdDeclarations() == null || psaRoot
.getPcdDeclarations().getPcdEntryList() == null) {
769 return psaRoot
.getPcdDeclarations().getPcdEntryList().size();
773 Get available Pcd definition contents into String array
775 @param pcd Caller allocated two-dimentional String array
777 public void getSpdPcdDefinitions(String
[][] pcd
, String pcdUsage
[][]) {
778 if (psaRoot
.getPcdDeclarations() == null) {
782 List
<PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
> l
= psaRoot
.getPcdDeclarations().getPcdEntryList();
784 while (i
< l
.size()) {
785 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)l
.get(i
);
786 pcd
[i
][0] = e
.getCName();
787 pcd
[i
][1] = e
.getToken() + "";
788 pcd
[i
][2] = e
.getTokenSpaceGuidCName();
789 if (e
.getDatumType() != null) {
790 pcd
[i
][3] = e
.getDatumType().toString();
792 pcd
[i
][4] = e
.getDefaultValue()+"";
793 pcd
[i
][5] = e
.getHelpText();
794 String archList
= listToString(e
.getSupArchList());
795 if (archList
!= null) {
796 pcd
[i
][6] = archList
;
798 String modTypeList
= listToString(e
.getSupModuleList());
799 if (modTypeList
!= null) {
800 pcd
[i
][7] = modTypeList
;
804 while (j
< e
.getValidUsage().size() && j
< 5) {
805 pcdUsage
[i
][j
] = (String
)e
.getValidUsage().get(j
);
813 Save the processed xml contents to file
815 @param spdFile The file to save xml contents
816 @throws IOException Exceptions during file operation
818 public void saveAs(File spdFile
) throws IOException
{
820 XmlOptions options
= new XmlOptions();
822 options
.setCharacterEncoding("UTF-8");
823 options
.setSavePrettyPrint();
824 options
.setSavePrettyPrintIndent(2);
826 psad
.save(spdFile
, options
);
827 } catch (IOException e
) {
834 Generate SpdHeader contents using parameters passed in.
836 @param pkgName PackageName
838 @param pkgVer Version
839 @param pkgAbs Abstract
840 @param pkgDes Description
841 @param pkgCpRight Copyright
842 @param pkgLicense License
843 @param pkgCreateDate Created
844 @param pkgUpdateDate Updated
846 @param pkgType PackageType
847 @param pkgRdOnly ReadOnly
848 @param pkgRePkg RePackage
849 @param pkgSpec Reserved
850 @param pkgOutDir Reserved
852 public void genSpdHeader(String pkgName
, String pkgGuid
, String pkgVer
, String pkgAbs
, String pkgDes
,
853 String pkgCpRight
, String pkgLicense
, String pkgCreateDate
, String pkgUpdateDate
,
854 String pkgURL
, String pkgType
, String pkgRdOnly
, String pkgRePkg
, String pkgSpec
,
856 if (getSpdHdr() == null) {
857 spdHdr
= psaRoot
.addNewSpdHeader();
860 setSpdHdrPkgName(pkgName
);
861 setSpdHdrGuidValue(pkgGuid
);
862 setSpdHdrVer(pkgVer
);
863 setSpdHdrAbs(pkgAbs
);
864 setSpdHdrDescription(pkgDes
);
865 setSpdHdrCopyright(pkgCpRight
);
866 setSpdHdrLicense(pkgLicense
);
869 setSpdHdrSpec(pkgSpec
);
873 Generate library class declaration element using parameters passed in
875 @param libClassBaseName LibraryClass element value
876 @param libClassUsage Reserved
877 @param incHdrFileName IncludeHeader element value
878 @param incHdrAttribGuid Reserved
879 @param incHdrAttribArch Reserved
880 @param incHdrAttribPath Reserved
881 @param incHdrAttribClass Reserved
882 @param incHdrAttribVer Reserved
883 @param incHdrAttribOverrideID Reserved
884 @param incHdrAttribModuleType Reserved
886 public void genSpdLibClassDeclarations(String libClassBaseName
, String instanceUsage
, String incHdrFileName
,
887 String help
, String incHdrAttribArch
, String incHdrAttribPath
,
888 String incHdrAttribClass
, String incHdrAttribVer
,
889 String incHdrAttribOverrideID
, String incHdrAttribModuleType
) {
890 if (getSpdLibClassDeclarations() == null) {
891 spdLibClassDeclarations
= psaRoot
.addNewLibraryClassDeclarations();
894 // add contents under LibraryClassDeclarations tag
896 setSpdLibClassDeclaration(libClassBaseName
, instanceUsage
, incHdrFileName
, help
, incHdrAttribArch
,
897 incHdrAttribPath
, incHdrAttribClass
, incHdrAttribVer
, incHdrAttribOverrideID
,
898 incHdrAttribModuleType
, spdLibClassDeclarations
);
902 Set library class declaration contents under parent tag
904 @param clsName LibraryClass element value
905 @param clsUsage Reserved
906 @param hdrFile IncludeHeader element value
907 @param hdrAttribGuid Reserved
908 @param hdrAttribArch Reserved
909 @param hdrAttribPath Reserved
910 @param hdrAttribClass Reserved
911 @param hdrAttribVer Reserved
912 @param hdrAttribOverID Reserved
913 @param hdrAttribModType Reserved
914 @param parent The tag under which library class declaration goes to
916 public void setSpdLibClassDeclaration(String clsName
, String clsUsage
, String hdrFile
, String help
,
917 String hdrAttribArch
, String hdrAttribPath
, String hdrAttribClass
,
918 String instanceVer
, String hdrAttribOverID
, String hdrAttribModType
,
921 setSpdLibraryClass(clsName
, hdrFile
, help
, clsUsage
, instanceVer
, hdrAttribArch
, hdrAttribModType
, parent
);
926 Set the contents of LibraryClass under parent element
928 @param clsName LibraryClass element value
929 @param clsUsage Reserved
930 @param parent The tag under which library class declaration goes to
932 public void setSpdLibraryClass(String clsName
, String clsIncludeFile
, String help
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
, XmlObject parent
) {
933 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= ((LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) parent
).addNewLibraryClass();
935 lc
.setIncludeHeader(clsIncludeFile
);
936 lc
.setHelpText(help
);
937 lc
.setRecommendedInstanceGuid(clsUsage
);
938 lc
.setRecommendedInstanceVersion(instanceVer
);
939 if (hdrAttribArch
!= null) {
940 lc
.setSupArchList(stringToList(hdrAttribArch
));
942 if (hdrAttribModType
!= null) {
943 lc
.setSupModuleList(stringToList(hdrAttribModType
));
949 Set contents of IncludeHeader under parent element
951 @param modType Reserved
952 @param hdrFile IncludeHeader element value
953 @param hdrAttribGuid Reserved
954 @param hdrAttribArch Reserved
955 @param hdrAttribPath Reserved
956 @param hdrAttribClass Reserved
957 @param hdrAttribVer Reserved
958 @param hdrAttribOverID Reserved
959 @param parent The tag under which library class declaration goes to
961 public void setSpdIncludeHeader(String modType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
962 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
963 String hdrAttribOverID
, XmlObject parent
) {
965 if (parent
instanceof LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) {
966 } else if (parent
instanceof PackageHeadersDocument
.PackageHeaders
) {
967 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= null;
968 ih
= ((PackageHeadersDocument
.PackageHeaders
) parent
).addNewIncludePkgHeader();
969 ih
.setStringValue(hdrFile
);
970 ih
.setModuleType(ModuleTypeDef
.Enum
.forString(modType
));
975 if (hdrAttribGuid
!= null) {
977 if (hdrAttribPath
!= null) {
979 if (hdrAttribClass
!= null) {
981 if (hdrAttribVer
!= null) {
983 if (hdrAttribOverID
!= null) {
989 Generate MsaFile element.
991 @param msaFileName MsaFile element value
992 @param archType Reserved
994 public void genSpdMsaFiles(String msaFileName
, String moduleName
, String ver
, String guid
) {
995 if (getSpdMsaFiles() == null) {
996 spdMsaFiles
= psaRoot
.addNewMsaFiles();
998 setSpdMsaFile(msaFileName
, moduleName
, ver
, guid
, spdMsaFiles
);
1003 Set MsaFile contents under parent element.
1005 @param msaFileName MsaFile element value
1006 @param parent Element under which MsaFile goes to
1008 public void setSpdMsaFile(String msaFileName
, String moduleName
, String ver
, String guid
, XmlObject parent
) {
1009 MsaFilesDocument
.MsaFiles f
= (MsaFilesDocument
.MsaFiles
)parent
;
1010 f
.addNewFilename().setStringValue(msaFileName
);
1011 // f.setFilename(msaFileName);
1012 // f.setModuleName(moduleName);
1013 // f.setModuleVersion(ver);
1014 // f.setModuleGuid(guid);
1018 Generate PackageHeader element using parameters passed in.
1020 @param ModHdrModType ModuleType attribute of IncludeHeader element
1021 @param hdrFile IncludeHeader element value
1022 @param hdrAttribGuid Reserved
1023 @param hdrAttribArch Reserved
1024 @param hdrAttribPath Reserved
1025 @param hdrAttribClass Reserved
1026 @param hdrAttribVer Reserved
1027 @param hdrAttribOverID Reserved
1029 public void genSpdModuleHeaders(String ModHdrModType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
1030 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
1031 String hdrAttribOverID
) {
1032 if (getSpdModHdrs() == null) {
1033 spdModHdrs
= psaRoot
.addNewPackageHeaders();
1037 // add IncludeHeader under PackageHeaders element
1039 setSpdIncludeHeader(ModHdrModType
, hdrFile
, hdrAttribGuid
, hdrAttribArch
, hdrAttribPath
, hdrAttribClass
,
1040 hdrAttribVer
, hdrAttribOverID
, spdModHdrs
);
1044 Generate GUID declaration element using parameters passed in.
1046 @param guidDeclEntryName Name attribute of Entry element
1047 @param guidDeclCName CName element value
1048 @param guidDeclGuid Guid element value
1049 @param guidDeclFeatureFlag Reserved
1051 public void genSpdGuidDeclarations(String guidDeclEntryName
, String guidDeclCName
, String guidDeclGuid
,
1052 String guidDeclHelp
, Vector
<String
> archList
, Vector
<String
> modTypeList
,
1053 Vector
<String
> guidTypeList
) {
1054 if (getSpdGuidDeclarations() == null) {
1055 spdGuidDeclarations
= psaRoot
.addNewGuidDeclarations();
1058 setSpdEntry(guidDeclEntryName
, guidDeclCName
, guidDeclGuid
, guidDeclHelp
, archList
, modTypeList
, guidTypeList
, spdGuidDeclarations
);
1062 Generate protocol declaration element using parameters passed in.
1064 @param protocolDeclEntryName Name attribute of Entry element
1065 @param protocolDeclCName CName element value
1066 @param protocolDeclGuid Guid element value
1067 @param protocolDeclFeatureFlag Reserved
1069 public void genSpdProtocolDeclarations(String protocolDeclEntryName
, String protocolDeclCName
,
1070 String protocolDeclGuid
, String protocolDeclFeatureFlag
,
1071 Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1072 if (getSpdProtocolDeclarations() == null) {
1073 spdProtocolDeclarations
= psaRoot
.addNewProtocolDeclarations();
1076 setSpdEntry(protocolDeclEntryName
, protocolDeclCName
, protocolDeclGuid
, protocolDeclFeatureFlag
,
1077 archList
, modTypeList
, null, spdProtocolDeclarations
);
1081 Generate PPI declaration element using parameters passed in.
1083 @param ppiDeclEntryName Name attribute of Entry element
1084 @param ppiDeclCName CName element value
1085 @param ppiDeclGuid Guid element value
1086 @param ppiDeclFeatureFlag Reserved
1088 public void genSpdPpiDeclarations(String ppiDeclEntryName
, String ppiDeclCName
, String ppiDeclGuid
,
1089 String ppiDeclFeatureFlag
, Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1090 if (getSpdPpiDeclarations() == null) {
1091 spdPpiDeclarations
= psaRoot
.addNewPpiDeclarations();
1094 setSpdEntry(ppiDeclEntryName
, ppiDeclCName
, ppiDeclGuid
, ppiDeclFeatureFlag
, archList
, modTypeList
, null, spdPpiDeclarations
);
1098 Set Entry contents using parameters passed in
1100 @param entryName Name attribute of Entry element
1101 @param cName CName element value
1102 @param guid Guid element value
1103 @param featureFlag Reserved
1104 @param parent The tag under which Entry element goes to
1106 public void setSpdEntry(String entryName
, String cName
, String guid
, String help
,
1107 Vector
<String
> archList
, Vector
<String
> modTypeList
,
1108 Vector
<String
> guidTypeList
, XmlObject parent
) {
1110 if (parent
instanceof GuidDeclarationsDocument
.GuidDeclarations
) {
1111 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= ((GuidDeclarations
) parent
).addNewEntry();
1112 e
.setName(entryName
);
1114 e
.setGuidValue(guid
);
1115 e
.setHelpText(help
);
1116 e
.setGuidTypeList(guidTypeList
);
1117 e
.setSupArchList(archList
);
1118 e
.setSupModuleList(modTypeList
);
1119 // if (guidTypeList != null && guidTypeList.size() > 0) {
1120 // e.setGuidTypeList(new ArrayList<String>(guidTypeList));
1122 // if (archList != null && archList.size() > 0){
1123 // e.setSupArchList(new ArrayList<String>(archList));
1125 // if (modTypeList != null && modTypeList.size() > 0) {
1126 // e.setSupModuleList(new ArrayList<String>(modTypeList));
1130 if (parent
instanceof ProtocolDeclarationsDocument
.ProtocolDeclarations
) {
1131 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry pe
= ((ProtocolDeclarationsDocument
.ProtocolDeclarations
) parent
)
1133 pe
.setName(entryName
);
1135 pe
.setGuidValue(guid
);
1136 pe
.setHelpText(help
);
1137 pe
.setSupArchList(archList
);
1138 pe
.setSupModuleList(modTypeList
);
1139 // if (archList != null && archList.size() > 0){
1140 // pe.setSupArchList(new ArrayList<String>(archList));
1142 // if (modTypeList != null && modTypeList.size() > 0) {
1143 // pe.setSupModuleList(new ArrayList<String>(modTypeList));
1147 if (parent
instanceof PpiDeclarationsDocument
.PpiDeclarations
) {
1148 PpiDeclarationsDocument
.PpiDeclarations
.Entry ppe
= ((PpiDeclarationsDocument
.PpiDeclarations
) parent
)
1150 ppe
.setName(entryName
);
1151 ppe
.setCName(cName
);
1152 ppe
.setGuidValue(guid
);
1153 ppe
.setHelpText(help
);
1154 ppe
.setSupArchList(archList
);
1155 ppe
.setSupModuleList(modTypeList
);
1156 // if (archList != null && archList.size() > 0){
1157 // ppe.setSupArchList(new ArrayList<String>(archList));
1159 // if (archList != null && modTypeList.size() > 0) {
1160 // ppe.setSupModuleList(new ArrayList<String>(modTypeList));
1170 Generate Pcd definition using parameters passed in
1172 @param pcdItemTypes ItemType attribute of PcdEntry element
1173 @param cName C_Name element value
1174 @param token Token element value
1175 @param dataType DatumType element value
1176 @param skuEnable Reserved
1178 @param maxSku Reserved
1179 @param hiiEnable Reserved
1180 @param varGuid Reserved
1181 @param varName Reserved
1182 @param defaultString DefaultString element value
1184 public void genSpdPcdDefinitions(String cName
, String token
, String dataType
, String pcdItemTypes
,
1185 String spaceGuid
, String defaultString
, String help
, String archList
,
1186 String modTypeList
) {
1187 if (getSpdPcdDefinitions() == null) {
1188 spdPcdDefinitions
= psaRoot
.addNewPcdDeclarations();
1191 setSpdPcdEntry(pcdItemTypes
, cName
, token
, dataType
, spaceGuid
, help
,
1192 defaultString
, archList
, modTypeList
, spdPcdDefinitions
);
1196 Set Pcd entry contents under parent tag
1198 @param pcdItemTypes ItemType attribute of PcdEntry element
1199 @param cName C_Name element value
1200 @param token Token element value
1201 @param dataType DatumType element value
1202 @param spaceGuid Reserved
1203 @param help Reserved
1204 @param defaultString DefaultString element value
1205 @param parent Tag under which PcdEntry goes to
1207 public void setSpdPcdEntry(String pcdItemTypes
, String cName
, String token
, String dataType
, String spaceGuid
, String help
,
1208 String defaultString
, String archList
, String modTypeList
, XmlObject parent
) {
1210 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry pe
= ((PcdDeclarationsDocument
.PcdDeclarations
) parent
).addNewPcdEntry();
1212 //ToDo: maybe multiple types in, need parse pcdItemTypes.
1213 String usage
[] = pcdItemTypes
.split("( )+");
1214 List
<String
> l
= new ArrayList
<String
>();
1215 for (int i
= 0; i
< usage
.length
; ++i
) {
1218 pe
.setValidUsage(l
);
1221 pe
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1222 pe
.setDefaultValue(defaultString
);
1223 pe
.setTokenSpaceGuidCName(spaceGuid
);
1224 pe
.setHelpText(help
);
1225 if (archList
!= null){
1226 pe
.setSupArchList(stringToList(archList
));
1228 if (modTypeList
!= null){
1229 pe
.setSupModuleList(stringToList(modTypeList
));
1234 Get PpiDeclarations element
1236 @return PpiDeclarationsDocument.PpiDeclarations
1238 public PpiDeclarationsDocument
.PpiDeclarations
getSpdPpiDeclarations() {
1239 if (spdPpiDeclarations
== null) {
1240 spdPpiDeclarations
= psaRoot
.getPpiDeclarations();
1242 return spdPpiDeclarations
;
1246 Get ProtocolDeclarations element
1248 @return ProtocolDeclarationsDocument.ProtocolDeclarations
1250 public ProtocolDeclarationsDocument
.ProtocolDeclarations
getSpdProtocolDeclarations() {
1251 if (spdProtocolDeclarations
== null) {
1252 spdProtocolDeclarations
= psaRoot
.getProtocolDeclarations();
1254 return spdProtocolDeclarations
;
1258 Get GuidDeclarations element
1260 @return GuidDeclarationsDocument.GuidDeclarations
1262 public GuidDeclarationsDocument
.GuidDeclarations
getSpdGuidDeclarations() {
1263 if (spdGuidDeclarations
== null) {
1264 spdGuidDeclarations
= psaRoot
.getGuidDeclarations();
1266 return spdGuidDeclarations
;
1270 Get PcdDefinitions element
1272 @return PcdDefinitionsDocument.PcdDefinitions
1274 public PcdDeclarationsDocument
.PcdDeclarations
getSpdPcdDefinitions() {
1275 if (spdPcdDefinitions
== null) {
1276 spdPcdDefinitions
= psaRoot
.getPcdDeclarations();
1278 return spdPcdDefinitions
;
1282 Get PackageHeaders element
1284 @return PackageHeadersDocument.PackageHeaders
1286 public PackageHeadersDocument
.PackageHeaders
getSpdModHdrs() {
1287 if (spdModHdrs
== null) {
1288 spdModHdrs
= psaRoot
.getPackageHeaders();
1294 Get MsaFiles element
1296 @return MsaFilesDocument.MsaFiles
1298 public MsaFilesDocument
.MsaFiles
getSpdMsaFiles() {
1299 if (spdMsaFiles
== null) {
1300 spdMsaFiles
= psaRoot
.getMsaFiles();
1306 Get LibraryClassDeclarations element
1308 @return LibraryClassDeclarationsDocument.LibraryClassDeclarations
1310 public LibraryClassDeclarationsDocument
.LibraryClassDeclarations
getSpdLibClassDeclarations() {
1311 if (spdLibClassDeclarations
== null) {
1312 spdLibClassDeclarations
= psaRoot
.getLibraryClassDeclarations();
1314 return spdLibClassDeclarations
;
1317 public PackageDefinitionsDocument
.PackageDefinitions
getSpdPkgDefs() {
1318 if (spdPkgDefs
== null) {
1319 spdPkgDefs
= psaRoot
.addNewPackageDefinitions();
1324 Get SpdHeader element
1326 @return SpdHeaderDocument.SpdHeader
1328 public SpdHeaderDocument
.SpdHeader
getSpdHdr() {
1329 if (spdHdr
== null) {
1330 spdHdr
= psaRoot
.addNewSpdHeader();
1336 Set value to Guid element
1338 @param guid The value set to Guid element
1340 public void setSpdHdrGuidValue(String guid
) {
1341 getSpdHdr().setGuidValue(guid
);
1345 Get Version element under SpdHdr
1349 public String
getSpdHdrVer() {
1350 return getSpdHdr().getVersion();
1354 Set value to Version element
1356 @param ver The value set to Version element
1358 public void setSpdHdrVer(String ver
) {
1359 getSpdHdr().setVersion(ver
);
1362 public String
getSpdHdrAbs(){
1363 return getSpdHdr().getAbstract();
1368 Set value to Abstract element
1370 @param abs The value set to Abstract element
1372 public void setSpdHdrAbs(String abs
) {
1374 getSpdHdr().setAbstract(abs
);
1377 public String
getSpdHdrDescription(){
1378 return getSpdHdr().getDescription();
1381 Set value to Description element
1383 @param des The value set to Description element
1385 public void setSpdHdrDescription(String des
) {
1386 getSpdHdr().setDescription(des
);
1389 public String
getSpdHdrCopyright(){
1390 return getSpdHdr().getCopyright();
1393 Set value to Copyright element
1395 @param cpRit The value set to Copyright element
1397 public void setSpdHdrCopyright(String cpRit
) {
1399 getSpdHdr().setCopyright(cpRit
);
1403 Get License element under SpdHdr
1407 public String
getSpdHdrLicense() {
1408 if (getSpdHdr().getLicense() != null) {
1409 return getSpdHdr().getLicense().getStringValue();
1415 Set value to License element
1417 @param license The value set to License element
1419 public void setSpdHdrLicense(String license
) {
1420 if (getSpdHdr().getLicense() == null){
1421 getSpdHdr().addNewLicense().setStringValue(license
);
1424 getSpdHdr().getLicense().setStringValue(license
);
1428 public String
getSpdHdrUrl(){
1429 if (getSpdHdr().getLicense() != null) {
1430 return getSpdHdr().getLicense().getURL();
1435 public void setSpdHdrUrl(String url
){
1436 getSpdHdr().getLicense().setURL(url
);
1440 Get PackageName element under SpdHdr
1444 public String
getSpdHdrPkgName() {
1446 return getSpdHdr().getPackageName();
1450 Set value to PackageName element
1452 @param pkgName The value set to PackageName element
1454 public void setSpdHdrPkgName(String pkgName
) {
1455 getSpdHdr().setPackageName(pkgName
);
1458 public String
getSpdHdrGuidValue(){
1459 return getSpdHdr().getGuidValue();
1465 @return SpecificationDocument.Specification
1467 public String
getSpdHdrSpec() {
1468 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1469 // return getSpdHdr().getSpecification();
1477 public void setSpdHdrSpec(String spec
) {
1478 spec
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1479 getSpdHdr().setSpecification(spec
);
1483 public String
getSpdPkgDefsRdOnly(){
1484 return getSpdPkgDefs().getReadOnly() + "";
1487 Set value to ReadOnly element
1489 @param rdOnly The value set to ReadOnly element
1491 public void setSpdPkgDefsRdOnly(String rdOnly
) {
1493 getSpdPkgDefs().setReadOnly(new Boolean(rdOnly
));
1496 public String
getSpdPkgDefsRePkg(){
1497 return getSpdPkgDefs().getRePackage() + "";
1500 Set value to RePackage element
1502 @param rePkg The value set to RePackage element
1504 public void setSpdPkgDefsRePkg(String rePkg
) {
1506 getSpdPkgDefs().setRePackage(new Boolean(rePkg
));
1510 Set value to URL element
1512 @param url The value set to URL element
1514 // public void setSpdHdrURL(String url) {
1515 // getSpdHdr().setURL(url);
1523 public File
getFile() {
1530 @param file File with xml format
1532 public void setFile(File file
) {
1536 private List
<String
> stringToList(String s
){
1537 if (s
== null || s
.length() == 0) {
1540 Vector
<String
> al
= new Vector
<String
>();
1541 String
[] sArray
= s
.split(" ");
1542 for(int i
= 0; i
< sArray
.length
; ++i
){
1548 private String
listToString(List l
) {
1553 ListIterator li
= l
.listIterator();
1554 while(li
.hasNext()) {