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
;
22 import javax
.xml
.namespace
.QName
;
24 import org
.apache
.xmlbeans
.XmlObject
;
25 import org
.apache
.xmlbeans
.XmlOptions
;
26 import org
.apache
.xmlbeans
.XmlCursor
;
28 import org
.tianocore
.FilenameDocument
;
29 import org
.tianocore
.GuidDeclarationsDocument
;
31 import org
.tianocore
.LibraryClassDeclarationsDocument
;
33 import org
.tianocore
.ModuleTypeDef
;
34 import org
.tianocore
.MsaFilesDocument
;
35 import org
.tianocore
.PackageDefinitionsDocument
;
36 import org
.tianocore
.PackageHeadersDocument
;
37 import org
.tianocore
.PackageSurfaceAreaDocument
;
38 import org
.tianocore
.PcdDataTypes
;
39 import org
.tianocore
.PcdDeclarationsDocument
;
40 import org
.tianocore
.PcdItemTypes
;
41 import org
.tianocore
.PpiDeclarationsDocument
;
42 import org
.tianocore
.ProtocolDeclarationsDocument
;
43 import org
.tianocore
.SpdHeaderDocument
;
44 import org
.tianocore
.GuidDeclarationsDocument
.GuidDeclarations
;
45 import org
.tianocore
.PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
;
48 This class processes spd file contents such as add remove xml elements.
50 @since PackageEditor 1.0
53 public class SpdFileContents
{
55 private File file
= null;
57 private PackageSurfaceAreaDocument psad
= null;
59 private PackageSurfaceAreaDocument
.PackageSurfaceArea psaRoot
= null;
61 private SpdHeaderDocument
.SpdHeader spdHdr
= null;
63 private PackageDefinitionsDocument
.PackageDefinitions spdPkgDefs
= null;
65 private LibraryClassDeclarationsDocument
.LibraryClassDeclarations spdLibClassDeclarations
= null;
67 private MsaFilesDocument
.MsaFiles spdMsaFiles
= null;
69 private PackageHeadersDocument
.PackageHeaders spdModHdrs
= null;
71 private GuidDeclarationsDocument
.GuidDeclarations spdGuidDeclarations
= null;
73 private ProtocolDeclarationsDocument
.ProtocolDeclarations spdProtocolDeclarations
= null;
75 private PpiDeclarationsDocument
.PpiDeclarations spdPpiDeclarations
= null;
77 private PcdDeclarationsDocument
.PcdDeclarations spdPcdDefinitions
= null;
80 Constructor to create a new spd file
82 public SpdFileContents() {
84 psad
= PackageSurfaceAreaDocument
.Factory
.newInstance();
85 psaRoot
= psad
.addNewPackageSurfaceArea();
90 Constructor for existing document object
93 public SpdFileContents(PackageSurfaceAreaDocument
.PackageSurfaceArea psa
) {
95 spdHdr
= psaRoot
.getSpdHeader();
96 spdPkgDefs
= psaRoot
.getPackageDefinitions();
99 Constructor based on an existing spd file
101 @param f Existing spd file
103 public SpdFileContents(File f
) {
105 psad
= PackageSurfaceAreaDocument
.Factory
.parse(f
);
106 psaRoot
= psad
.getPackageSurfaceArea();
108 } catch (Exception e
) {
109 System
.out
.println(e
.toString());
114 Remove existing pcd definitions elements using XmlCursor
116 public void removeSpdPcdDefinition() {
117 XmlObject o
= psaRoot
.getPcdDeclarations();
120 XmlCursor cursor
= o
.newCursor();
122 spdPcdDefinitions
= null;
126 public void removeSpdPcdDefinition(int i
){
127 XmlObject o
= psaRoot
.getPcdDeclarations();
130 XmlCursor cursor
= o
.newCursor();
131 if (cursor
.toFirstChild()) {
132 for (int j
= 0; j
< i
; ++j
) {
133 cursor
.toNextSibling();
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();
167 Remove existing protocols declarations using XmlCursor
169 public void removeSpdProtocolDeclaration() {
170 XmlObject o
= psaRoot
.getProtocolDeclarations();
173 XmlCursor cursor
= o
.newCursor();
175 spdProtocolDeclarations
= null;
179 public void removeSpdProtocolDeclaration(int i
) {
180 XmlObject o
= psaRoot
.getProtocolDeclarations();
183 XmlCursor cursor
= o
.newCursor();
184 if (cursor
.toFirstChild()) {
185 for (int j
= 0; j
< i
; ++j
) {
186 cursor
.toNextSibling();
193 Remove existing GUID declarations using XmlCursor
195 public void removeSpdGuidDeclaration() {
196 XmlObject o
= psaRoot
.getGuidDeclarations();
199 XmlCursor cursor
= o
.newCursor();
201 spdGuidDeclarations
= null;
205 public void removeSpdGuidDeclaration(int i
) {
206 XmlObject o
= psaRoot
.getGuidDeclarations();
209 XmlCursor cursor
= o
.newCursor();
210 if (cursor
.toFirstChild()) {
211 for (int j
= 0; j
< i
; ++j
) {
212 cursor
.toNextSibling();
221 Remove existing spd package include files using XmlCursor
223 public void removeSpdPkgHeader() {
224 XmlObject o
= psaRoot
.getPackageHeaders();
227 XmlCursor cursor
= o
.newCursor();
233 public void removeSpdPkgHeader(int i
){
234 XmlObject o
= psaRoot
.getPackageHeaders();
237 XmlCursor cursor
= o
.newCursor();
238 if (cursor
.toFirstChild()) {
239 for (int j
= 0; j
< i
; ++j
) {
240 cursor
.toNextSibling();
248 Remove existing msa files using XmlCursor
250 public void removeSpdMsaFile() {
251 XmlObject o
= psaRoot
.getMsaFiles();
254 XmlCursor cursor
= o
.newCursor();
260 public void removeSpdMsaFile(int i
){
261 XmlObject o
= psaRoot
.getMsaFiles();
264 XmlCursor cursor
= o
.newCursor();
265 if (cursor
.toFirstChild()) {
266 for (int j
= 0; j
< i
; ++j
) {
267 cursor
.toNextSibling();
275 Remove existing library class declarations using XmlCursor
277 public void removeSpdLibClass() {
278 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
281 XmlCursor cursor
= o
.newCursor();
283 spdLibClassDeclarations
= null;
287 public void removeSpdLibClass(int i
) {
288 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
291 XmlCursor cursor
= o
.newCursor();
292 if (cursor
.toFirstChild()) {
293 for (int j
= 0; j
< i
; ++j
) {
294 cursor
.toNextSibling();
301 public void updateSpdLibClass(int i
, String lib
, String hdr
, String hlp
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
) {
302 XmlObject o
= psaRoot
.getLibraryClassDeclarations();
306 XmlCursor cursor
= o
.newCursor();
307 if (cursor
.toFirstChild()) {
308 for (int j
= 0; j
< i
; ++j
) {
309 cursor
.toNextSibling();
311 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
)cursor
.getObject();
313 lc
.setIncludeHeader(hdr
);
315 if (clsUsage
!= null) {
316 lc
.setRecommendedInstanceGuid(clsUsage
);
318 if (instanceVer
!= null){
319 lc
.setRecommendedInstanceVersion(instanceVer
);
321 if (stringToList(hdrAttribArch
) != null){
322 lc
.setSupArchList(stringToList(hdrAttribArch
));
324 if (stringToList(hdrAttribModType
) != null){
325 lc
.setSupModuleList(stringToList(hdrAttribModType
));
332 public void updateSpdMsaFile(int i
, String msaFile
, String mName
, String v
, String g
){
333 XmlObject o
= psaRoot
.getMsaFiles();
337 XmlCursor cursor
= o
.newCursor();
338 if (cursor
.toFirstChild()) {
339 for (int j
= 0; j
< i
; ++j
) {
340 cursor
.toNextSibling();
342 cursor
.setTextValue(msaFile
);
349 public void updateSpdGuidDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
350 String modTypeList
, String guidTypeList
){
351 XmlObject o
= psaRoot
.getGuidDeclarations();
356 XmlCursor cursor
= o
.newCursor();
357 if (cursor
.toFirstChild()) {
358 for (int j
= 0; j
< i
; ++j
) {
359 cursor
.toNextSibling();
361 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
)cursor
.getObject();
364 e
.setGuidValue(guid
);
366 if (stringToList(guidTypeList
) != null && !guidTypeList
.equals("")) {
367 e
.setGuidTypeList(stringToList(guidTypeList
));
369 if (stringToList(archList
) != null){
370 e
.setSupArchList(stringToList(archList
));
372 if (stringToList(modTypeList
) != null) {
373 e
.setSupModuleList(stringToList(modTypeList
));
380 public void updateSpdPpiDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
382 XmlObject o
= psaRoot
.getPpiDeclarations();
387 XmlCursor cursor
= o
.newCursor();
388 if (cursor
.toFirstChild()) {
389 for (int j
= 0; j
< i
; ++j
) {
390 cursor
.toNextSibling();
392 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
)cursor
.getObject();
395 e
.setGuidValue(guid
);
397 if (stringToList(archList
) != null){
398 e
.setSupArchList(stringToList(archList
));
400 if (stringToList(modTypeList
) != null) {
401 e
.setSupModuleList(stringToList(modTypeList
));
407 public void updateSpdProtocolDecl(int i
, String name
, String cName
, String guid
, String hlp
, String archList
,
409 XmlObject o
= psaRoot
.getProtocolDeclarations();
414 XmlCursor cursor
= o
.newCursor();
415 if (cursor
.toFirstChild()) {
416 for (int j
= 0; j
< i
; ++j
) {
417 cursor
.toNextSibling();
419 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
)cursor
.getObject();
422 e
.setGuidValue(guid
);
424 if (stringToList(archList
) != null){
425 e
.setSupArchList(stringToList(archList
));
427 if (stringToList(modTypeList
) != null) {
428 e
.setSupModuleList(stringToList(modTypeList
));
434 public void updateSpdPkgHdr(int i
, String pkgName
, String hdrName
){
435 XmlObject o
= psaRoot
.getPackageHeaders();
440 XmlCursor cursor
= o
.newCursor();
441 if (cursor
.toFirstChild()) {
442 for (int j
= 0; j
< i
; ++j
) {
443 cursor
.toNextSibling();
446 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader iph
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
)cursor
.getObject();
447 iph
.setModuleType(ModuleTypeDef
.Enum
.forString(pkgName
));
448 iph
.setStringValue(hdrName
);
453 public void updateSpdPcdDefinition(int i
, String cName
, String token
, String dataType
, String pcdItemTypes
,
454 String spaceGuid
, String defaultString
, String help
, String archList
, String modTypeList
){
455 XmlObject o
= psaRoot
.getPcdDeclarations();
458 XmlCursor cursor
= o
.newCursor();
459 if (cursor
.toFirstChild()) {
460 for (int j
= 0; j
< i
; ++j
) {
461 cursor
.toNextSibling();
463 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)cursor
.getObject();
466 e
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
467 if (pcdItemTypes
!= null && pcdItemTypes
.length() > 0) {
468 String usage
[] = pcdItemTypes
.split("( )+");
469 List
<String
> l
= new ArrayList
<String
>();
470 for (int k
= 0; k
< usage
.length
; ++k
) {
476 e
.setTokenSpaceGuidCName(spaceGuid
);
477 e
.setDefaultValue(defaultString
);
479 if (archList
!= null && archList
.length() > 0){
480 e
.setSupArchList(stringToList(archList
));
482 if (modTypeList
!= null && modTypeList
.length() > 0){
483 e
.setSupModuleList(stringToList(modTypeList
));
489 Get spd file header contents into String array
491 @param s Caller allocated String array
493 public void getSpdHdrDetails(String
[] s
) {
494 if (getSpdHdr() == null) {
495 spdHdr
= psaRoot
.addNewSpdHeader();
497 s
[0] = getSpdHdrPkgName();
498 s
[1] = getSpdHdr().getGuidValue();
499 s
[2] = getSpdHdrVer();
500 // s[3] = getSpdHdr().getAbstract();
501 s
[4] = getSpdHdr().getDescription();
502 s
[5] = getSpdHdr().getCopyright();
503 s
[6] = getSpdHdrLicense();
508 Get the number of library class declarations from the size of List
512 public int getSpdLibClassDeclarationCount() {
513 if (psaRoot
.getLibraryClassDeclarations() == null
514 || psaRoot
.getLibraryClassDeclarations().getLibraryClassList() == null) {
517 return psaRoot
.getLibraryClassDeclarations().getLibraryClassList().size();
521 Get available library class declaration into String array
522 @param libClass Caller allocated two-dimentional String array
524 public void getSpdLibClassDeclarations(String
[][] libClass
) {
525 if (psaRoot
.getLibraryClassDeclarations() == null){
529 List
<LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
> l
= psaRoot
.getLibraryClassDeclarations().getLibraryClassList();
531 ListIterator li
= l
.listIterator();
532 while (li
.hasNext()) {
533 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) li
.next();
535 libClass
[i
][0] = lc
.getName();
536 libClass
[i
][1] = lc
.getIncludeHeader();
537 libClass
[i
][2] = lc
.getHelpText();
538 libClass
[i
][3] = lc
.getRecommendedInstanceGuid();
539 libClass
[i
][4] = lc
.getRecommendedInstanceVersion();
540 if (lc
.getSupArchList() != null) {
541 libClass
[i
][5] = listToString(lc
.getSupArchList());
543 if (lc
.getSupModuleList() != null) {
544 libClass
[i
][6] = listToString(lc
.getSupModuleList());
555 Get the number of Msa files from the size of List
559 public int getSpdMsaFileCount() {
560 if (psaRoot
.getMsaFiles() == null || psaRoot
.getMsaFiles().getFilenameList() == null) {
563 return psaRoot
.getMsaFiles().getFilenameList().size();
567 Get available Msa file into String array
569 @param msaFile Caller allocated two-dimentional String array
571 public void getSpdMsaFiles(String
[][] msaFile
) {
572 if (psaRoot
.getMsaFiles() == null) {
575 List
<String
> l
= psaRoot
.getMsaFiles().getFilenameList();
577 ListIterator li
= l
.listIterator();
578 while (li
.hasNext()) {
579 msaFile
[i
][0] = (String
)li
.next();
586 Get the number of include header files in PackageHeaders from the size of List
590 public int getSpdPackageHeaderCount() {
591 if (psaRoot
.getPackageHeaders() == null || psaRoot
.getPackageHeaders().getIncludePkgHeaderList() == null) {
594 return psaRoot
.getPackageHeaders().getIncludePkgHeaderList().size();
598 Get available package header contents into String array
600 @param pkgHeader Caller allocated two-dimentional String array
602 public void getSpdPackageHeaders(String
[][] pkgHeader
) {
603 if (psaRoot
.getPackageHeaders() == null) {
607 List
<PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
> l
= psaRoot
.getPackageHeaders().getIncludePkgHeaderList();
609 ListIterator li
= l
.listIterator();
610 while (li
.hasNext()) {
611 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) li
.next();
612 if (ih
.getModuleType() != null) {
613 pkgHeader
[i
][0] = ih
.getModuleType().toString();
616 pkgHeader
[i
][1] = ih
.getStringValue();
622 Get the number of GUID declarations from the size of List
626 public int getSpdGuidDeclarationCount() {
627 if (psaRoot
.getGuidDeclarations() == null || psaRoot
.getGuidDeclarations().getEntryList() == null) {
630 return psaRoot
.getGuidDeclarations().getEntryList().size();
634 Get available Guid declaration contents into String array
636 @param guid Caller allocated two-dimentional String array
638 public void getSpdGuidDeclarations(String
[][] guid
) {
639 if (psaRoot
.getGuidDeclarations() == null) {
643 List
<GuidDeclarationsDocument
.GuidDeclarations
.Entry
> l
= psaRoot
.getGuidDeclarations().getEntryList();
645 ListIterator li
= l
.listIterator();
646 while (li
.hasNext()) {
647 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) li
649 guid
[i
][0] = e
.getName();
650 guid
[i
][1] = e
.getCName();
651 if (e
.getGuidValue() != null) {
652 guid
[i
][2] = e
.getGuidValue();
654 guid
[i
][3] = e
.getHelpText();
655 guid
[i
][4] = listToString(e
.getSupArchList());
656 guid
[i
][5] = listToString(e
.getSupModuleList());
657 guid
[i
][6] = listToString(e
.getGuidTypeList());
663 Get the number of protocol declarations from the size of List
667 public int getSpdProtocolDeclarationCount() {
668 if (psaRoot
.getProtocolDeclarations() == null || psaRoot
.getProtocolDeclarations().getEntryList() == null) {
671 return psaRoot
.getProtocolDeclarations().getEntryList().size();
675 Get available protocol declaration contents into String array
677 @param protocol Caller allocated two-dimentional String array
679 public void getSpdProtocolDeclarations(String
[][] protocol
) {
680 if (psaRoot
.getProtocolDeclarations() == null) {
684 List
<ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
> l
= psaRoot
.getProtocolDeclarations()
687 ListIterator li
= l
.listIterator();
688 while (li
.hasNext()) {
689 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry e
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) li
691 protocol
[i
][0] = e
.getName();
692 protocol
[i
][1] = e
.getCName();
693 if (e
.getGuidValue() != null) {
694 protocol
[i
][2] = e
.getGuidValue();
696 protocol
[i
][3] = e
.getHelpText();
697 protocol
[i
][4] = listToString(e
.getSupArchList());
698 protocol
[i
][5] = listToString(e
.getSupModuleList());
704 Get the number of Ppi declarations from the size of List
708 public int getSpdPpiDeclarationCount() {
709 if (psaRoot
.getPpiDeclarations() == null || psaRoot
.getPpiDeclarations().getEntryList() == null) {
712 return psaRoot
.getPpiDeclarations().getEntryList().size();
716 Get available Ppi declaration contents into String array
718 @param ppi Caller allocated two-dimentional String array
720 public void getSpdPpiDeclarations(String
[][] ppi
) {
721 if (psaRoot
.getPpiDeclarations() == null) {
725 List
<PpiDeclarationsDocument
.PpiDeclarations
.Entry
> l
= psaRoot
.getPpiDeclarations().getEntryList();
727 ListIterator li
= l
.listIterator();
728 while (li
.hasNext()) {
729 PpiDeclarationsDocument
.PpiDeclarations
.Entry e
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) li
.next();
730 ppi
[i
][0] = e
.getName();
731 ppi
[i
][1] = e
.getCName();
732 if (e
.getGuidValue() != null) {
733 ppi
[i
][2] = e
.getGuidValue();
735 ppi
[i
][3] = e
.getHelpText();
736 ppi
[i
][4] = listToString(e
.getSupArchList());
737 ppi
[i
][5] = listToString(e
.getSupModuleList());
744 Get the number of Pcd definitions from the size of List
748 public int getSpdPcdDefinitionCount() {
749 if (psaRoot
.getPcdDeclarations() == null || psaRoot
.getPcdDeclarations().getPcdEntryList() == null) {
752 return psaRoot
.getPcdDeclarations().getPcdEntryList().size();
756 Get available Pcd definition contents into String array
758 @param pcd Caller allocated two-dimentional String array
760 public void getSpdPcdDefinitions(String
[][] pcd
, String pcdUsage
[][]) {
761 if (psaRoot
.getPcdDeclarations() == null) {
765 List
<PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
> l
= psaRoot
.getPcdDeclarations().getPcdEntryList();
767 while (i
< l
.size()) {
768 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry e
= (PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry
)l
.get(i
);
769 pcd
[i
][0] = e
.getCName();
770 pcd
[i
][1] = e
.getToken() + "";
771 pcd
[i
][2] = e
.getTokenSpaceGuidCName();
772 if (e
.getDatumType() != null) {
773 pcd
[i
][3] = e
.getDatumType().toString();
775 pcd
[i
][4] = e
.getDefaultValue()+"";
776 pcd
[i
][5] = e
.getHelpText();
777 String archList
= listToString(e
.getSupArchList());
778 if (archList
!= null) {
779 pcd
[i
][6] = archList
;
781 String modTypeList
= listToString(e
.getSupModuleList());
782 if (modTypeList
!= null) {
783 pcd
[i
][7] = modTypeList
;
787 while (j
< e
.getValidUsage().size() && j
< 5) {
788 pcdUsage
[i
][j
] = (String
)e
.getValidUsage().get(j
);
796 Save the processed xml contents to file
798 @param spdFile The file to save xml contents
799 @throws IOException Exceptions during file operation
801 public void saveAs(File spdFile
) throws IOException
{
803 XmlOptions options
= new XmlOptions();
805 options
.setCharacterEncoding("UTF-8");
806 options
.setSavePrettyPrint();
807 options
.setSavePrettyPrintIndent(2);
809 psad
.save(spdFile
, options
);
810 } catch (IOException e
) {
817 Generate SpdHeader contents using parameters passed in.
819 @param pkgName PackageName
821 @param pkgVer Version
822 @param pkgAbs Abstract
823 @param pkgDes Description
824 @param pkgCpRight Copyright
825 @param pkgLicense License
826 @param pkgCreateDate Created
827 @param pkgUpdateDate Updated
829 @param pkgType PackageType
830 @param pkgRdOnly ReadOnly
831 @param pkgRePkg RePackage
832 @param pkgSpec Reserved
833 @param pkgOutDir Reserved
835 public void genSpdHeader(String pkgName
, String pkgGuid
, String pkgVer
, String pkgAbs
, String pkgDes
,
836 String pkgCpRight
, String pkgLicense
, String pkgCreateDate
, String pkgUpdateDate
,
837 String pkgURL
, String pkgType
, String pkgRdOnly
, String pkgRePkg
, String pkgSpec
,
839 if (getSpdHdr() == null) {
840 spdHdr
= psaRoot
.addNewSpdHeader();
843 setSpdHdrPkgName(pkgName
);
844 setSpdHdrGuidValue(pkgGuid
);
845 setSpdHdrVer(pkgVer
);
846 setSpdHdrAbs(pkgAbs
);
847 setSpdHdrDescription(pkgDes
);
848 setSpdHdrCopyright(pkgCpRight
);
849 setSpdHdrLicense(pkgLicense
);
852 setSpdHdrSpec(pkgSpec
);
856 Generate library class declaration element using parameters passed in
858 @param libClassBaseName LibraryClass element value
859 @param libClassUsage Reserved
860 @param incHdrFileName IncludeHeader element value
861 @param incHdrAttribGuid Reserved
862 @param incHdrAttribArch Reserved
863 @param incHdrAttribPath Reserved
864 @param incHdrAttribClass Reserved
865 @param incHdrAttribVer Reserved
866 @param incHdrAttribOverrideID Reserved
867 @param incHdrAttribModuleType Reserved
869 public void genSpdLibClassDeclarations(String libClassBaseName
, String instanceUsage
, String incHdrFileName
,
870 String help
, String incHdrAttribArch
, String incHdrAttribPath
,
871 String incHdrAttribClass
, String incHdrAttribVer
,
872 String incHdrAttribOverrideID
, String incHdrAttribModuleType
) {
873 if (getSpdLibClassDeclarations() == null) {
874 spdLibClassDeclarations
= psaRoot
.addNewLibraryClassDeclarations();
877 // add contents under LibraryClassDeclarations tag
879 setSpdLibClassDeclaration(libClassBaseName
, instanceUsage
, incHdrFileName
, help
, incHdrAttribArch
,
880 incHdrAttribPath
, incHdrAttribClass
, incHdrAttribVer
, incHdrAttribOverrideID
,
881 incHdrAttribModuleType
, spdLibClassDeclarations
);
885 Set library class declaration contents under parent tag
887 @param clsName LibraryClass element value
888 @param clsUsage Reserved
889 @param hdrFile IncludeHeader element value
890 @param hdrAttribGuid Reserved
891 @param hdrAttribArch Reserved
892 @param hdrAttribPath Reserved
893 @param hdrAttribClass Reserved
894 @param hdrAttribVer Reserved
895 @param hdrAttribOverID Reserved
896 @param hdrAttribModType Reserved
897 @param parent The tag under which library class declaration goes to
899 public void setSpdLibClassDeclaration(String clsName
, String clsUsage
, String hdrFile
, String help
,
900 String hdrAttribArch
, String hdrAttribPath
, String hdrAttribClass
,
901 String instanceVer
, String hdrAttribOverID
, String hdrAttribModType
,
904 setSpdLibraryClass(clsName
, hdrFile
, help
, clsUsage
, instanceVer
, hdrAttribArch
, hdrAttribModType
, parent
);
909 Set the contents of LibraryClass under parent element
911 @param clsName LibraryClass element value
912 @param clsUsage Reserved
913 @param parent The tag under which library class declaration goes to
915 public void setSpdLibraryClass(String clsName
, String clsIncludeFile
, String help
, String clsUsage
, String instanceVer
, String hdrAttribArch
, String hdrAttribModType
, XmlObject parent
) {
916 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass lc
= ((LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) parent
).addNewLibraryClass();
918 lc
.setIncludeHeader(clsIncludeFile
);
919 lc
.setHelpText(help
);
920 lc
.setRecommendedInstanceGuid(clsUsage
);
921 lc
.setRecommendedInstanceVersion(instanceVer
);
922 if (hdrAttribArch
!= null) {
923 lc
.setSupArchList(stringToList(hdrAttribArch
));
925 if (hdrAttribModType
!= null) {
926 lc
.setSupModuleList(stringToList(hdrAttribModType
));
932 Set contents of IncludeHeader under parent element
934 @param modType Reserved
935 @param hdrFile IncludeHeader element value
936 @param hdrAttribGuid Reserved
937 @param hdrAttribArch Reserved
938 @param hdrAttribPath Reserved
939 @param hdrAttribClass Reserved
940 @param hdrAttribVer Reserved
941 @param hdrAttribOverID Reserved
942 @param parent The tag under which library class declaration goes to
944 public void setSpdIncludeHeader(String modType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
945 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
946 String hdrAttribOverID
, XmlObject parent
) {
948 if (parent
instanceof LibraryClassDeclarationsDocument
.LibraryClassDeclarations
) {
949 } else if (parent
instanceof PackageHeadersDocument
.PackageHeaders
) {
950 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader ih
= null;
951 ih
= ((PackageHeadersDocument
.PackageHeaders
) parent
).addNewIncludePkgHeader();
952 ih
.setStringValue(hdrFile
);
953 ih
.setModuleType(ModuleTypeDef
.Enum
.forString(modType
));
958 if (hdrAttribGuid
!= null) {
960 if (hdrAttribPath
!= null) {
962 if (hdrAttribClass
!= null) {
964 if (hdrAttribVer
!= null) {
966 if (hdrAttribOverID
!= null) {
972 Generate MsaFile element.
974 @param msaFileName MsaFile element value
975 @param archType Reserved
977 public void genSpdMsaFiles(String msaFileName
, String moduleName
, String ver
, String guid
) {
978 if (getSpdMsaFiles() == null) {
979 spdMsaFiles
= psaRoot
.addNewMsaFiles();
981 setSpdMsaFile(msaFileName
, moduleName
, ver
, guid
, spdMsaFiles
);
986 Set MsaFile contents under parent element.
988 @param msaFileName MsaFile element value
989 @param parent Element under which MsaFile goes to
991 public void setSpdMsaFile(String msaFileName
, String moduleName
, String ver
, String guid
, XmlObject parent
) {
992 MsaFilesDocument
.MsaFiles f
= (MsaFilesDocument
.MsaFiles
)parent
;
993 f
.addNewFilename().setStringValue(msaFileName
);
994 // f.setFilename(msaFileName);
995 // f.setModuleName(moduleName);
996 // f.setModuleVersion(ver);
997 // f.setModuleGuid(guid);
1001 Generate PackageHeader element using parameters passed in.
1003 @param ModHdrModType ModuleType attribute of IncludeHeader element
1004 @param hdrFile IncludeHeader element value
1005 @param hdrAttribGuid Reserved
1006 @param hdrAttribArch Reserved
1007 @param hdrAttribPath Reserved
1008 @param hdrAttribClass Reserved
1009 @param hdrAttribVer Reserved
1010 @param hdrAttribOverID Reserved
1012 public void genSpdModuleHeaders(String ModHdrModType
, String hdrFile
, String hdrAttribGuid
, String hdrAttribArch
,
1013 String hdrAttribPath
, String hdrAttribClass
, String hdrAttribVer
,
1014 String hdrAttribOverID
) {
1015 if (getSpdModHdrs() == null) {
1016 spdModHdrs
= psaRoot
.addNewPackageHeaders();
1020 // add IncludeHeader under PackageHeaders element
1022 setSpdIncludeHeader(ModHdrModType
, hdrFile
, hdrAttribGuid
, hdrAttribArch
, hdrAttribPath
, hdrAttribClass
,
1023 hdrAttribVer
, hdrAttribOverID
, spdModHdrs
);
1027 Generate GUID declaration element using parameters passed in.
1029 @param guidDeclEntryName Name attribute of Entry element
1030 @param guidDeclCName CName element value
1031 @param guidDeclGuid Guid element value
1032 @param guidDeclFeatureFlag Reserved
1034 public void genSpdGuidDeclarations(String guidDeclEntryName
, String guidDeclCName
, String guidDeclGuid
,
1035 String guidDeclHelp
, Vector
<String
> archList
, Vector
<String
> modTypeList
,
1036 Vector
<String
> guidTypeList
) {
1037 if (getSpdGuidDeclarations() == null) {
1038 spdGuidDeclarations
= psaRoot
.addNewGuidDeclarations();
1041 setSpdEntry(guidDeclEntryName
, guidDeclCName
, guidDeclGuid
, guidDeclHelp
, archList
, modTypeList
, guidTypeList
, spdGuidDeclarations
);
1045 Generate protocol declaration element using parameters passed in.
1047 @param protocolDeclEntryName Name attribute of Entry element
1048 @param protocolDeclCName CName element value
1049 @param protocolDeclGuid Guid element value
1050 @param protocolDeclFeatureFlag Reserved
1052 public void genSpdProtocolDeclarations(String protocolDeclEntryName
, String protocolDeclCName
,
1053 String protocolDeclGuid
, String protocolDeclFeatureFlag
,
1054 Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1055 if (getSpdProtocolDeclarations() == null) {
1056 spdProtocolDeclarations
= psaRoot
.addNewProtocolDeclarations();
1059 setSpdEntry(protocolDeclEntryName
, protocolDeclCName
, protocolDeclGuid
, protocolDeclFeatureFlag
,
1060 archList
, modTypeList
, null, spdProtocolDeclarations
);
1064 Generate PPI declaration element using parameters passed in.
1066 @param ppiDeclEntryName Name attribute of Entry element
1067 @param ppiDeclCName CName element value
1068 @param ppiDeclGuid Guid element value
1069 @param ppiDeclFeatureFlag Reserved
1071 public void genSpdPpiDeclarations(String ppiDeclEntryName
, String ppiDeclCName
, String ppiDeclGuid
,
1072 String ppiDeclFeatureFlag
, Vector
<String
> archList
, Vector
<String
> modTypeList
) {
1073 if (getSpdPpiDeclarations() == null) {
1074 spdPpiDeclarations
= psaRoot
.addNewPpiDeclarations();
1077 setSpdEntry(ppiDeclEntryName
, ppiDeclCName
, ppiDeclGuid
, ppiDeclFeatureFlag
, archList
, modTypeList
, null, spdPpiDeclarations
);
1081 Set Entry contents using parameters passed in
1083 @param entryName Name attribute of Entry element
1084 @param cName CName element value
1085 @param guid Guid element value
1086 @param featureFlag Reserved
1087 @param parent The tag under which Entry element goes to
1089 public void setSpdEntry(String entryName
, String cName
, String guid
, String help
,
1090 Vector
<String
> archList
, Vector
<String
> modTypeList
,
1091 Vector
<String
> guidTypeList
, XmlObject parent
) {
1093 if (parent
instanceof GuidDeclarationsDocument
.GuidDeclarations
) {
1094 GuidDeclarationsDocument
.GuidDeclarations
.Entry e
= ((GuidDeclarations
) parent
).addNewEntry();
1095 e
.setName(entryName
);
1097 e
.setGuidValue(guid
);
1098 e
.setHelpText(help
);
1099 if (guidTypeList
!= null && guidTypeList
.size() > 0) {
1100 e
.setGuidTypeList(new ArrayList
<String
>(guidTypeList
));
1102 if (archList
!= null && archList
.size() > 0){
1103 e
.setSupArchList(new ArrayList
<String
>(archList
));
1105 if (modTypeList
!= null && modTypeList
.size() > 0) {
1106 e
.setSupModuleList(new ArrayList
<String
>(modTypeList
));
1110 if (parent
instanceof ProtocolDeclarationsDocument
.ProtocolDeclarations
) {
1111 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry pe
= ((ProtocolDeclarationsDocument
.ProtocolDeclarations
) parent
)
1113 pe
.setName(entryName
);
1115 pe
.setGuidValue(guid
);
1116 pe
.setHelpText(help
);
1117 if (archList
!= null && archList
.size() > 0){
1118 pe
.setSupArchList(new ArrayList
<String
>(archList
));
1120 if (modTypeList
!= null && modTypeList
.size() > 0) {
1121 pe
.setSupModuleList(new ArrayList
<String
>(modTypeList
));
1125 if (parent
instanceof PpiDeclarationsDocument
.PpiDeclarations
) {
1126 PpiDeclarationsDocument
.PpiDeclarations
.Entry ppe
= ((PpiDeclarationsDocument
.PpiDeclarations
) parent
)
1128 ppe
.setName(entryName
);
1129 ppe
.setCName(cName
);
1130 ppe
.setGuidValue(guid
);
1131 ppe
.setHelpText(help
);
1132 if (archList
!= null && archList
.size() > 0){
1133 ppe
.setSupArchList(new ArrayList
<String
>(archList
));
1135 if (archList
!= null && modTypeList
.size() > 0) {
1136 ppe
.setSupModuleList(new ArrayList
<String
>(modTypeList
));
1146 Generate Pcd definition using parameters passed in
1148 @param pcdItemTypes ItemType attribute of PcdEntry element
1149 @param cName C_Name element value
1150 @param token Token element value
1151 @param dataType DatumType element value
1152 @param skuEnable Reserved
1154 @param maxSku Reserved
1155 @param hiiEnable Reserved
1156 @param varGuid Reserved
1157 @param varName Reserved
1158 @param defaultString DefaultString element value
1160 public void genSpdPcdDefinitions(String cName
, String token
, String dataType
, String pcdItemTypes
,
1161 String spaceGuid
, String defaultString
, String help
, String archList
,
1162 String modTypeList
) {
1163 if (getSpdPcdDefinitions() == null) {
1164 spdPcdDefinitions
= psaRoot
.addNewPcdDeclarations();
1167 setSpdPcdEntry(pcdItemTypes
, cName
, token
, dataType
, spaceGuid
, help
,
1168 defaultString
, archList
, modTypeList
, spdPcdDefinitions
);
1172 Set Pcd entry contents under parent tag
1174 @param pcdItemTypes ItemType attribute of PcdEntry element
1175 @param cName C_Name element value
1176 @param token Token element value
1177 @param dataType DatumType element value
1178 @param spaceGuid Reserved
1179 @param help Reserved
1180 @param defaultString DefaultString element value
1181 @param parent Tag under which PcdEntry goes to
1183 public void setSpdPcdEntry(String pcdItemTypes
, String cName
, String token
, String dataType
, String spaceGuid
, String help
,
1184 String defaultString
, String archList
, String modTypeList
, XmlObject parent
) {
1186 PcdDeclarationsDocument
.PcdDeclarations
.PcdEntry pe
= ((PcdDeclarationsDocument
.PcdDeclarations
) parent
).addNewPcdEntry();
1188 //ToDo: maybe multiple types in, need parse pcdItemTypes.
1189 String usage
[] = pcdItemTypes
.split("( )+");
1190 List
<String
> l
= new ArrayList
<String
>();
1191 for (int i
= 0; i
< usage
.length
; ++i
) {
1194 pe
.setValidUsage(l
);
1197 pe
.setDatumType(PcdDataTypes
.Enum
.forString(dataType
));
1198 pe
.setDefaultValue(defaultString
);
1199 pe
.setTokenSpaceGuidCName(spaceGuid
);
1200 pe
.setHelpText(help
);
1201 if (archList
!= null){
1202 pe
.setSupArchList(stringToList(archList
));
1204 if (modTypeList
!= null){
1205 pe
.setSupModuleList(stringToList(modTypeList
));
1210 Get PpiDeclarations element
1212 @return PpiDeclarationsDocument.PpiDeclarations
1214 public PpiDeclarationsDocument
.PpiDeclarations
getSpdPpiDeclarations() {
1215 if (spdPpiDeclarations
== null) {
1216 spdPpiDeclarations
= psaRoot
.getPpiDeclarations();
1218 return spdPpiDeclarations
;
1222 Get ProtocolDeclarations element
1224 @return ProtocolDeclarationsDocument.ProtocolDeclarations
1226 public ProtocolDeclarationsDocument
.ProtocolDeclarations
getSpdProtocolDeclarations() {
1227 if (spdProtocolDeclarations
== null) {
1228 spdProtocolDeclarations
= psaRoot
.getProtocolDeclarations();
1230 return spdProtocolDeclarations
;
1234 Get GuidDeclarations element
1236 @return GuidDeclarationsDocument.GuidDeclarations
1238 public GuidDeclarationsDocument
.GuidDeclarations
getSpdGuidDeclarations() {
1239 if (spdGuidDeclarations
== null) {
1240 spdGuidDeclarations
= psaRoot
.getGuidDeclarations();
1242 return spdGuidDeclarations
;
1246 Get PcdDefinitions element
1248 @return PcdDefinitionsDocument.PcdDefinitions
1250 public PcdDeclarationsDocument
.PcdDeclarations
getSpdPcdDefinitions() {
1251 if (spdPcdDefinitions
== null) {
1252 spdPcdDefinitions
= psaRoot
.getPcdDeclarations();
1254 return spdPcdDefinitions
;
1258 Get PackageHeaders element
1260 @return PackageHeadersDocument.PackageHeaders
1262 public PackageHeadersDocument
.PackageHeaders
getSpdModHdrs() {
1263 if (spdModHdrs
== null) {
1264 spdModHdrs
= psaRoot
.getPackageHeaders();
1270 Get MsaFiles element
1272 @return MsaFilesDocument.MsaFiles
1274 public MsaFilesDocument
.MsaFiles
getSpdMsaFiles() {
1275 if (spdMsaFiles
== null) {
1276 spdMsaFiles
= psaRoot
.getMsaFiles();
1282 Get LibraryClassDeclarations element
1284 @return LibraryClassDeclarationsDocument.LibraryClassDeclarations
1286 public LibraryClassDeclarationsDocument
.LibraryClassDeclarations
getSpdLibClassDeclarations() {
1287 if (spdLibClassDeclarations
== null) {
1288 spdLibClassDeclarations
= psaRoot
.getLibraryClassDeclarations();
1290 return spdLibClassDeclarations
;
1293 public PackageDefinitionsDocument
.PackageDefinitions
getSpdPkgDefs() {
1294 if (spdPkgDefs
== null) {
1295 spdPkgDefs
= psaRoot
.addNewPackageDefinitions();
1300 Get SpdHeader element
1302 @return SpdHeaderDocument.SpdHeader
1304 public SpdHeaderDocument
.SpdHeader
getSpdHdr() {
1305 if (spdHdr
== null) {
1306 spdHdr
= psaRoot
.addNewSpdHeader();
1312 Set value to Guid element
1314 @param guid The value set to Guid element
1316 public void setSpdHdrGuidValue(String guid
) {
1317 getSpdHdr().setGuidValue(guid
);
1321 Get Version element under SpdHdr
1325 public String
getSpdHdrVer() {
1326 return getSpdHdr().getVersion();
1330 Set value to Version element
1332 @param ver The value set to Version element
1334 public void setSpdHdrVer(String ver
) {
1335 getSpdHdr().setVersion(ver
);
1338 public String
getSpdHdrAbs(){
1339 return getSpdHdr().getAbstract();
1344 Set value to Abstract element
1346 @param abs The value set to Abstract element
1348 public void setSpdHdrAbs(String abs
) {
1350 getSpdHdr().setAbstract(abs
);
1353 public String
getSpdHdrDescription(){
1354 return getSpdHdr().getDescription();
1357 Set value to Description element
1359 @param des The value set to Description element
1361 public void setSpdHdrDescription(String des
) {
1362 getSpdHdr().setDescription(des
);
1365 public String
getSpdHdrCopyright(){
1366 return getSpdHdr().getCopyright();
1369 Set value to Copyright element
1371 @param cpRit The value set to Copyright element
1373 public void setSpdHdrCopyright(String cpRit
) {
1375 getSpdHdr().setCopyright(cpRit
);
1379 Get License element under SpdHdr
1383 public String
getSpdHdrLicense() {
1384 if (getSpdHdr().getLicense() != null) {
1385 return getSpdHdr().getLicense().getStringValue();
1391 Set value to License element
1393 @param license The value set to License element
1395 public void setSpdHdrLicense(String license
) {
1396 if (getSpdHdr().getLicense() == null){
1397 getSpdHdr().addNewLicense().setStringValue(license
);
1400 getSpdHdr().getLicense().setStringValue(license
);
1404 public String
getSpdHdrUrl(){
1405 if (getSpdHdr().getLicense() != null) {
1406 return getSpdHdr().getLicense().getURL();
1411 public void setSpdHdrUrl(String url
){
1412 getSpdHdr().getLicense().setURL(url
);
1416 Get PackageName element under SpdHdr
1420 public String
getSpdHdrPkgName() {
1422 return getSpdHdr().getPackageName();
1426 Set value to PackageName element
1428 @param pkgName The value set to PackageName element
1430 public void setSpdHdrPkgName(String pkgName
) {
1431 getSpdHdr().setPackageName(pkgName
);
1434 public String
getSpdHdrGuidValue(){
1435 return getSpdHdr().getGuidValue();
1441 @return SpecificationDocument.Specification
1443 public String
getSpdHdrSpec() {
1444 return "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1445 // return getSpdHdr().getSpecification();
1453 public void setSpdHdrSpec(String spec
) {
1454 spec
= "FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052";
1455 getSpdHdr().setSpecification(spec
);
1459 public String
getSpdPkgDefsRdOnly(){
1460 return getSpdPkgDefs().getReadOnly() + "";
1463 Set value to ReadOnly element
1465 @param rdOnly The value set to ReadOnly element
1467 public void setSpdPkgDefsRdOnly(String rdOnly
) {
1469 getSpdPkgDefs().setReadOnly(new Boolean(rdOnly
));
1472 public String
getSpdPkgDefsRePkg(){
1473 return getSpdPkgDefs().getRePackage() + "";
1476 Set value to RePackage element
1478 @param rePkg The value set to RePackage element
1480 public void setSpdPkgDefsRePkg(String rePkg
) {
1482 getSpdPkgDefs().setRePackage(new Boolean(rePkg
));
1486 Set value to URL element
1488 @param url The value set to URL element
1490 // public void setSpdHdrURL(String url) {
1491 // getSpdHdr().setURL(url);
1499 public File
getFile() {
1506 @param file File with xml format
1508 public void setFile(File file
) {
1512 private List
<String
> stringToList(String s
){
1516 ArrayList
<String
> al
= new ArrayList
<String
>();
1517 String
[] sArray
= s
.split(" ");
1518 for(int i
= 0; i
< sArray
.length
; ++i
){
1524 private String
listToString(List
<String
> l
) {
1529 ListIterator li
= l
.listIterator();
1530 while(li
.hasNext()) {