2 This file is for surface area information retrieval.
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.
14 package org
.tianocore
.frameworkwizard
.platform
.ui
.global
;
16 import java
.util
.ArrayList
;
17 import java
.util
.HashMap
;
18 import java
.util
.Iterator
;
19 import java
.util
.LinkedHashMap
;
20 import java
.util
.List
;
23 import java
.util
.Stack
;
24 import java
.util
.regex
.Matcher
;
25 import java
.util
.regex
.Pattern
;
27 import org
.apache
.xmlbeans
.XmlNormalizedString
;
28 import org
.apache
.xmlbeans
.XmlObject
;
29 import org
.apache
.xmlbeans
.XmlString
;
30 import org
.tianocore
.BuildTargetList
;
31 import org
.tianocore
.DataIdDocument
;
32 import org
.tianocore
.ExternsDocument
;
33 import org
.tianocore
.FileNameConvention
;
34 //import org.tianocore.FvImageDocument;
35 import org
.tianocore
.GuidDeclarationsDocument
;
36 import org
.tianocore
.LibrariesDocument
;
37 import org
.tianocore
.LibraryClassDeclarationsDocument
;
38 import org
.tianocore
.LibraryClassDocument
;
39 import org
.tianocore
.ModuleSADocument
;
40 import org
.tianocore
.ModuleTypeDef
;
41 import org
.tianocore
.MsaFilesDocument
;
42 import org
.tianocore
.MsaHeaderDocument
;
43 import org
.tianocore
.PackageDependenciesDocument
;
44 import org
.tianocore
.PackageHeadersDocument
;
45 import org
.tianocore
.PpiDeclarationsDocument
;
46 import org
.tianocore
.ProtocolDeclarationsDocument
;
47 import org
.tianocore
.SpdHeaderDocument
;
48 import org
.tianocore
.FilenameDocument
.Filename
;
49 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
50 import org
.tianocore
.PlatformHeaderDocument
;
51 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.FpdModuleIdentification
;
52 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
53 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
54 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PlatformIdentification
;
57 * SurfaceAreaQuery class is used to query Surface Area information from msa,
58 * mbd, spd and fpd files.
60 * This class should not instantiated. All the public interfaces is static.
64 public class SurfaceAreaQuery
{
66 public static String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
69 // / Contains name/value pairs of Surface Area document object. The name is
70 // / always the top level element name.
72 private static Map
<String
, XmlObject
> map
= null;
75 // / mapStack is used to do nested query
77 private static Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
80 // / prefix of name space
82 private static String nsPrefix
= "sans";
85 // / xmlbeans needs a name space for each Xpath element
87 private static String ns
= null;
90 // / keep the namep declaration for xmlbeans Xpath query
92 private static String queryDeclaration
= null;
95 * Set a Surface Area document for query later
98 * A Surface Area document in TopLevelElementName/XmlObject
101 public static void setDoc(Map
<String
, XmlObject
> map
) {
103 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
104 SurfaceAreaQuery
.map
= map
;
108 * Push current used Surface Area document into query stack. The given new
109 * document will be used for any immediately followed getXXX() callings,
110 * untill pop() is called.
113 * The TopLevelElementName/XmlObject format of a Surface Area
116 public static void push(Map
<String
, XmlObject
> newMap
) {
117 mapStack
.push(SurfaceAreaQuery
.map
);
118 SurfaceAreaQuery
.map
= newMap
;
122 * Discard current used Surface Area document and use the top document in
125 public static void pop() {
126 SurfaceAreaQuery
.map
= mapStack
.pop();
130 // / Convert xPath to be namespace qualified, which is necessary for
132 // / selectPath(). For example, converting /MsaHeader/ModuleType to
133 // / /ns:MsaHeader/ns:ModuleType
135 private static String
normalizeQueryString(String
[] exp
, String from
) {
136 StringBuffer normQueryString
= new StringBuffer(4096);
139 while (i
< exp
.length
) {
140 String newExp
= from
+ exp
[i
];
141 Pattern pattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
142 Matcher matcher
= pattern
.matcher(newExp
);
144 while (matcher
.find()) {
145 String starter
= newExp
.substring(matcher
.start(1), matcher
147 String seperator
= newExp
.substring(matcher
.start(2), matcher
149 String token
= newExp
.substring(matcher
.start(3), matcher
152 normQueryString
.append(starter
);
153 normQueryString
.append(seperator
);
154 normQueryString
.append(nsPrefix
);
155 normQueryString
.append(":");
156 normQueryString
.append(token
);
160 if (i
< exp
.length
) {
161 normQueryString
.append(" | ");
165 return normQueryString
.toString();
169 * Search all XML documents stored in "map" for the specified xPath, using
170 * relative path (starting with '$this')
173 * xpath query string array
174 * @returns An array of XmlObject if elements are found at the specified
176 * @returns NULL if nothing is at the specified xpath
178 public static XmlObject
[] get(String
[] xPath
) {
183 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
184 List
<XmlObject
> result
= new ArrayList
<XmlObject
>();
185 for (int i
= 0; i
< keys
.length
; ++i
) {
186 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
187 if (rootNode
== null) {
191 String query
= queryDeclaration
192 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
193 XmlObject
[] tmp
= rootNode
.selectPath(query
);
194 for (int j
= 0; j
< tmp
.length
; ++j
) {
199 int size
= result
.size();
204 return (XmlObject
[]) result
.toArray(new XmlObject
[size
]);
208 * Search XML documents named by "rootName" for the given xPath, using
209 * relative path (starting with '$this')
212 * The top level element name
214 * The xpath query string array
215 * @returns An array of XmlObject if elements are found at the given xpath
216 * @returns NULL if nothing is found at the given xpath
218 public static XmlObject
[] get(String rootName
, String
[] xPath
) {
223 XmlObject root
= (XmlObject
) map
.get(rootName
);
228 String query
= queryDeclaration
229 + normalizeQueryString(xPath
, "$this/" + rootName
);
230 XmlObject
[] result
= root
.selectPath(query
);
231 if (result
.length
> 0) {
235 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
236 result
= root
.selectPath(query
);
237 if (result
.length
> 0) {
245 * Retrieve SourceFiles/Filename for specified ARCH type
249 * @returns An 2 dimension string array if elements are found at the known
251 * @returns NULL if nothing is found at the known xpath
253 public static String
[][] getSourceFiles(String arch
) {
257 if (arch
== null || arch
.equals("")) {
258 xPath
= new String
[] { "/Filename" };
260 xPath
= new String
[] { "/Filename[not(@SupArchList) or @SupArchList='"
264 returns
= get("SourceFiles", xPath
);
266 if (returns
== null || returns
.length
== 0) {
270 Filename
[] sourceFileNames
= (Filename
[]) returns
;
271 String
[][] outputString
= new String
[sourceFileNames
.length
][2];
272 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
273 outputString
[i
][0] = sourceFileNames
[i
].getToolCode();
274 outputString
[i
][1] = sourceFileNames
[i
].getStringValue();
280 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
282 * @returns Directory names array if elements are found at the known xpath
283 * @returns Empty if nothing is found at the known xpath
285 public static String
getFpdOutputDirectory() {
286 String
[] xPath
= new String
[] { "/PlatformDefinitions/OutputDirectory" };
288 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
289 if (returns
!= null && returns
.length
> 0) {
296 public static String
getFpdIntermediateDirectories() {
297 String
[] xPath
= new String
[] { "/PlatformDefinitions/IntermediateDirectories" };
299 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
300 if (returns
!= null && returns
.length
> 0) {
306 public static String
getBuildTarget() {
307 String
[] xPath
= new String
[] { "/PlatformDefinitions/BuildTargets" };
309 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
310 if (returns
!= null && returns
.length
> 0) {
311 return ((BuildTargetList
) returns
[0]).getStringValue();
318 * Retrieve <xxxHeader>/ModuleType
320 * @returns The module type name if elements are found at the known xpath
321 * @returns null if nothing is there
323 public static String
getModuleType() {
324 String
[] xPath
= new String
[] { "/ModuleType" };
326 XmlObject
[] returns
= get(xPath
);
327 if (returns
!= null && returns
.length
> 0) {
328 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
329 return type
.enumValue().toString();
336 * Retrieve PackageDependencies/Package
341 * @returns package name list if elements are found at the known xpath
342 * @returns null if nothing is there
344 public static PackageIdentification
[] getDependencePkg(String arch
) {
346 String packageGuid
= null;
347 String packageVersion
= null;
349 if (arch
== null || arch
.equals("")) {
350 xPath
= new String
[] { "/PackageDependencies/Package" };
352 xPath
= new String
[] { "/PackageDependencies/Package[not(@SupArchList) or @SupArchList='"
356 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
357 if (returns
== null) {
358 return new PackageIdentification
[0];
360 PackageIdentification
[] packageIdList
= new PackageIdentification
[returns
.length
];
361 for (int i
= 0; i
< returns
.length
; i
++) {
362 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
363 packageGuid
= item
.getPackageGuid();
364 packageVersion
= item
.getPackageVersion();
366 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
367 Iterator
<PackageIdentification
> ispi
= spi
.iterator();
369 while(ispi
.hasNext()) {
370 PackageIdentification pi
= ispi
.next();
371 if (packageVersion
!= null) {
372 if (pi
.getGuid().equals(packageGuid
) && pi
.getVersion().equals(packageVersion
)) {
373 packageIdList
[i
] = pi
;
378 if (pi
.getGuid().equals(packageGuid
)) {
379 if (pi
.getVersion() != null && pi
.getVersion().compareTo(ver
) > 0){
380 ver
= pi
.getVersion();
381 packageIdList
[i
] = pi
;
383 else if (packageIdList
[i
] == null){
384 packageIdList
[i
] = pi
;
391 return packageIdList
;
395 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
398 * Library class usage
400 * @returns LibraryClass objects list if elements are found at the known
402 * @returns null if nothing is there
404 public static String
[] getLibraryClasses(String usage
) {
407 if (usage
== null || usage
.equals("")) {
408 xPath
= new String
[] { "/LibraryClass" };
410 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
413 XmlObject
[] returns
= get("LibraryClassDefinitions", xPath
);
414 if (returns
== null || returns
.length
== 0) {
415 return new String
[0];
418 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
419 String
[] libraryClassName
= new String
[libraryClassList
.length
];
420 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
421 libraryClassName
[i
] = libraryClassList
[i
].getKeyword();
423 return libraryClassName
;
427 * Retrieve ModuleEntryPoint names
429 * @returns ModuleEntryPoint name list if elements are found at the known
431 * @returns null if nothing is there
433 public static String
[] getModuleEntryPointArray() {
434 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
436 XmlObject
[] returns
= get("Externs", xPath
);
438 if (returns
!= null && returns
.length
> 0) {
439 String
[] entryPoints
= new String
[returns
.length
];
441 for (int i
= 0; i
< returns
.length
; ++i
) {
442 entryPoints
[i
] = ((XmlNormalizedString
) returns
[i
])
456 * Retrieve ModuleUnloadImage names
458 * @returns ModuleUnloadImage name list if elements are found at the known
460 * @returns null if nothing is there
462 public static String
[] getModuleUnloadImageArray() {
463 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
465 XmlObject
[] returns
= get("Externs", xPath
);
466 if (returns
!= null && returns
.length
> 0) {
467 String
[] stringArray
= new String
[returns
.length
];
468 XmlNormalizedString
[] doc
= (XmlNormalizedString
[]) returns
;
470 for (int i
= 0; i
< returns
.length
; ++i
) {
471 stringArray
[i
] = doc
[i
].getStringValue();
483 * @returns Extern objects list if elements are found at the known xpath
484 * @returns null if nothing is there
486 public static ExternsDocument
.Externs
.Extern
[] getExternArray() {
487 String
[] xPath
= new String
[] { "/Extern" };
489 XmlObject
[] returns
= get("Externs", xPath
);
490 if (returns
!= null && returns
.length
> 0) {
491 return (ExternsDocument
.Externs
.Extern
[]) returns
;
498 * Retrieve Library instance information
503 * Library instance usage
505 * @returns library instance name list if elements are found at the known
507 * @returns null if nothing is there
509 public static ModuleIdentification
[] getLibraryInstance(String arch
) {
511 String saGuid
= null;
512 String saVersion
= null;
513 String pkgGuid
= null;
514 String pkgVersion
= null;
516 if (arch
== null || arch
.equalsIgnoreCase("")) {
517 xPath
= new String
[] { "/Instance" };
519 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
523 XmlObject
[] returns
= get("Libraries", xPath
);
524 if (returns
== null || returns
.length
== 0) {
525 return new ModuleIdentification
[0];
528 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
529 for (int i
= 0; i
< returns
.length
; i
++) {
530 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
531 saGuid
= library
.getModuleGuid();
532 saVersion
= library
.getModuleVersion();
534 pkgGuid
= library
.getPackageGuid();
535 pkgVersion
= library
.getPackageVersion();
537 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
539 PackageIdentification pkgId
= new PackageIdentification(null,
540 pkgGuid
, pkgVersion
);
541 saId
.setPackage(pkgId
);
550 // / This method is used for retrieving the elements information which has
551 // / CName sub-element
553 private static String
[] getCNames(String from
, String xPath
[]) {
554 XmlObject
[] returns
= get(from
, xPath
);
555 if (returns
== null || returns
.length
== 0) {
559 String
[] strings
= new String
[returns
.length
];
560 for (int i
= 0; i
< returns
.length
; ++i
) {
562 // strings[i] = ((CName) returns[i]).getStringValue();
569 * Retrive library's constructor name
571 * @returns constructor name list if elements are found at the known xpath
572 * @returns null if nothing is there
574 public static String
getLibConstructorName() {
575 String
[] xPath
= new String
[] { "/Extern/Constructor" };
577 XmlObject
[] returns
= get("Externs", xPath
);
578 if (returns
!= null && returns
.length
> 0) {
579 // CName constructor = (CName) returns[0];
580 // return constructor.getStringValue();
587 * Retrive library's destructor name
589 * @returns destructor name list if elements are found at the known xpath
590 * @returns null if nothing is there
592 public static String
getLibDestructorName() {
593 String
[] xPath
= new String
[] { "/Extern/Destructor" };
595 XmlObject
[] returns
= get("Externs", xPath
);
596 if (returns
!= null && returns
.length
> 0) {
597 // CName destructor = (CName) returns[0];
598 // return destructor.getStringValue();
605 * Retrive DriverBinding names
607 * @returns DriverBinding name list if elements are found at the known xpath
608 * @returns null if nothing is there
610 public static String
[] getDriverBindingArray() {
611 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
612 return getCNames("Externs", xPath
);
616 * Retrive ComponentName names
618 * @returns ComponentName name list if elements are found at the known xpath
619 * @returns null if nothing is there
621 public static String
[] getComponentNameArray() {
622 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
623 return getCNames("Externs", xPath
);
627 * Retrive DriverConfig names
629 * @returns DriverConfig name list if elements are found at the known xpath
630 * @returns null if nothing is there
632 public static String
[] getDriverConfigArray() {
633 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
634 return getCNames("Externs", xPath
);
638 * Retrive DriverDiag names
640 * @returns DriverDiag name list if elements are found at the known xpath
641 * @returns null if nothing is there
643 public static String
[] getDriverDiagArray() {
644 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
645 return getCNames("Externs", xPath
);
649 * Retrive SetVirtualAddressMapCallBack names
651 * @returns SetVirtualAddressMapCallBack name list if elements are found at
653 * @returns null if nothing is there
655 public static String
[] getSetVirtualAddressMapCallBackArray() {
656 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
657 return getCNames("Externs", xPath
);
661 * Retrive ExitBootServicesCallBack names
663 * @returns ExitBootServicesCallBack name list if elements are found at the
665 * @returns null if nothing is there
667 public static String
[] getExitBootServicesCallBackArray() {
668 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
669 return getCNames("Externs", xPath
);
673 * Retrieve module surface area file information
675 * @returns ModuleSA objects list if elements are found at the known xpath
676 * @returns Empty ModuleSA list if nothing is there
678 public static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() {
679 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
680 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
682 String fvBinding
= null;
683 String saGuid
= null;
684 String saVersion
= null;
685 String pkgGuid
= null;
686 String pkgVersion
= null;
688 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
690 if (result
== null) {
694 for (int i
= 0; i
< result
.length
; i
++) {
696 // Get Fpd SA Module element node and add to xmlObjectMap.
698 Map
<String
, XmlObject
> xmlObjectMap
= new HashMap
<String
, XmlObject
>();
699 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
700 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
701 xmlObjectMap
.put("Libraries", moduleSA
.getLibraries());
703 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
704 xmlObjectMap
.put("PcdBuildDefinition", moduleSA
705 .getPcdBuildDefinition());
707 if (((ModuleSADocument
.ModuleSA
) result
[i
])
708 .getModuleSaBuildOptions() != null) {
709 xmlObjectMap
.put("ModuleSaBuildOptions", moduleSA
710 .getModuleSaBuildOptions());
714 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
716 arch
= moduleSA
.getSupArchList().toString();
720 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
])
723 saGuid
= moduleSA
.getModuleGuid();
724 pkgGuid
= moduleSA
.getPackageGuid();
725 pkgVersion
= moduleSA
.getPackageVersion();
728 // Create Module Identification which have class member of package
731 PackageIdentification pkgId
= new PackageIdentification(null,
732 pkgGuid
, pkgVersion
);
733 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
736 saId
.setPackage(pkgId
);
739 // Create FpdModule Identification which have class member of module
742 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
,
745 fpdSaId
.setArch(arch
);
747 if (fvBinding
!= null) {
748 fpdSaId
.setFvBinding(fvBinding
);
752 // Put element to Map<FpdModuleIdentification, Map<String,
755 fpdModuleMap
.put(fpdSaId
, xmlObjectMap
);
761 * Retrieve valid image names
763 * @returns valid iamges name list if elements are found at the known xpath
764 * @returns empty list if nothing is there
766 public static String
[] getFpdValidImageNames() {
767 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };
769 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
770 if (queryResult
== null) {
771 return new String
[0];
774 String
[] result
= new String
[queryResult
.length
];
775 for (int i
= 0; i
< queryResult
.length
; i
++) {
776 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
784 public static XmlObject
getFpdBuildOptions() {
785 String
[] xPath
= new String
[] { "/BuildOptions" };
787 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
789 if (queryResult
== null || queryResult
.length
== 0) {
792 return queryResult
[0];
795 public static PlatformIdentification
getFpdHeader() {
796 String
[] xPath
= new String
[] { "/PlatformHeader" };
798 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
800 if (returns
== null || returns
.length
== 0) {
803 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
805 String name
= header
.getPlatformName();
807 String guid
= header
.getGuidValue();
809 String version
= header
.getVersion();
811 return new PlatformIdentification(name
, guid
, version
);
815 * Retrieve flash definition file name
817 * @returns file name if elements are found at the known xpath
818 * @returns null if nothing is there
820 public static String
getFlashDefinitionFile() {
821 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
823 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
824 if (queryResult
== null || queryResult
.length
== 0) {
828 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
829 return filename
.getStringValue();
833 * Retrieve FV image component options
838 * @returns name/value pairs list if elements are found at the known xpath
839 * @returns empty list if nothing is there
841 public static String
[][] getFpdComponents(String fvName
) {
842 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"
843 + fvName
.toUpperCase() + "']/DataId" };
845 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
846 if (queryResult
== null) {
847 return new String
[0][];
850 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
851 for (int i
= 0; i
< queryResult
.length
; i
++) {
852 DataIdDocument
.DataId item
= (DataIdDocument
.DataId
) queryResult
[i
];
854 .add(new String
[] { item
.getStringValue(),
855 item
.getDataSize() });
858 String
[][] result
= new String
[list
.size()][2];
859 for (int i
= 0; i
< list
.size(); i
++) {
860 result
[i
][0] = list
.get(i
)[0];
861 result
[i
][1] = list
.get(i
)[1];
868 * Retrieve PCD tokens
870 * @returns CName/ItemType pairs list if elements are found at the known
872 * @returns null if nothing is there
874 public static String
[][] getPcdTokenArray() {
875 String
[] xPath
= new String
[] { "/PcdData" };
877 XmlObject
[] returns
= get("PCDs", xPath
);
878 if (returns
== null || returns
.length
== 0) {
882 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
883 // String[][] result = new String[pcds.length][2];
884 // for (int i = 0; i < returns.length; ++i) {
885 // if (pcds[i].getItemType() != null) {
886 // result[i][1] = pcds[i].getItemType().toString();
888 // result[i][1] = null;
890 // result[i][0] = pcds[i].getCName();
899 * Retrieve MSA header
904 public static ModuleIdentification
getMsaHeader() {
905 String
[] xPath
= new String
[] { "/" };
906 XmlObject
[] returns
= get("MsaHeader", xPath
);
908 if (returns
== null || returns
.length
== 0) {
912 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
914 // Get BaseName, ModuleType, GuidValue, Version
915 // which in MsaHeader.
917 String name
= msaHeader
.getModuleName();
918 String moduleType
= "";
919 if (msaHeader
.getModuleType() != null) {
920 moduleType
= msaHeader
.getModuleType().toString();
923 String guid
= msaHeader
.getGuidValue();
924 String version
= msaHeader
.getVersion();
926 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
929 moduleId
.setModuleType(moduleType
);
935 * Retrieve Extern Specification
939 * @return String[] If have specification element in the <extern> String[0]
940 * If no specification element in the <extern>
944 public static String
[] getExternSpecificaiton() {
945 String
[] xPath
= new String
[] { "/Specification" };
947 XmlObject
[] queryResult
= get("Externs", xPath
);
948 if (queryResult
== null) {
949 return new String
[0];
952 String
[] specificationList
= new String
[queryResult
.length
];
953 for (int i
= 0; i
< queryResult
.length
; i
++) {
954 // specificationList[i] = ((SpecificationDocument.Specification)
956 // .getStringValue();
958 return specificationList
;
962 * Retreive MsaFile which in SPD
965 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
966 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
968 public static String
[] getSpdMsaFile() {
969 String
[] xPath
= new String
[] { "/MsaFiles" };
971 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
972 if (returns
== null) {
973 return new String
[0];
976 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
978 return filenameList
.toArray(new String
[filenameList
.size()]);
984 public static Map
<String
, String
[]> getSpdLibraryClasses() {
985 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
987 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
990 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
992 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
994 if (returns
== null) {
995 return libClassHeaderMap
;
998 for (int i
= 0; i
< returns
.length
; i
++) {
999 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1000 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1001 .getIncludeHeader() });
1003 return libClassHeaderMap
;
1009 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1010 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1012 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1015 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1017 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1019 if (returns
== null) {
1020 return packageIncludeMap
;
1022 GlobalData
.log
.info("" + returns
[0].getClass().getName());
1023 for (int i
= 0; i
< returns
.length
; i
++) {
1024 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1025 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1026 includeHeader
.getStringValue());
1028 return packageIncludeMap
;
1031 public static PackageIdentification
getSpdHeader() {
1032 String
[] xPath
= new String
[] { "/SpdHeader" };
1034 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1036 if (returns
== null || returns
.length
== 0) {
1040 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1042 String name
= header
.getPackageName();
1044 String guid
= header
.getGuidValue();
1046 String version
= header
.getVersion();
1048 return new PackageIdentification(name
, guid
, version
);
1054 public static Map
<String
, String
[]> getSpdGuid() {
1055 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1057 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1060 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1062 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1063 if (returns
== null) {
1067 for (int i
= 0; i
< returns
.length
; i
++) {
1068 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1069 String
[] guidPair
= new String
[2];
1070 guidPair
[0] = entry
.getCName();
1071 guidPair
[1] = entry
.getGuidValue();
1072 guidDeclMap
.put(entry
.getName(), guidPair
);
1080 public static Map
<String
, String
[]> getSpdProtocol() {
1081 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1083 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1086 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1088 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1090 if (returns
== null) {
1094 for (int i
= 0; i
< returns
.length
; i
++) {
1095 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1096 String
[] protocolPair
= new String
[2];
1098 protocolPair
[0] = entry
.getCName();
1099 protocolPair
[1] = entry
.getGuidValue();
1100 protoclMap
.put(entry
.getName(), protocolPair
);
1106 * getSpdPpi() Retrieve the SPD PPI Entry
1109 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1110 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1113 public static Map
<String
, String
[]> getSpdPpi() {
1114 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1116 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1119 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1121 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1123 if (returns
== null) {
1127 for (int i
= 0; i
< returns
.length
; i
++) {
1128 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1129 String
[] ppiPair
= new String
[2];
1130 ppiPair
[0] = entry
.getCName();
1131 ppiPair
[1] = entry
.getGuidValue();
1132 ppiMap
.put(entry
.getName(), ppiPair
);
1138 * getModuleSupportedArchs()
1140 * This function is to Retrieve Archs one module supported.
1143 * @return supportArch String of supporting archs. null No arch specified in
1144 * <MouduleSupport> element.
1146 public static List
<String
> getModuleSupportedArchs() {
1147 String
[] xPath
= new String
[] { "/ModuleDefinitions/SupportedArchitectures" };
1149 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
1151 if (returns
== null) {
1155 return (List
<String
>)returns
[0];
1158 public static XmlObject
[] getSpdPcdDeclarations() {
1159 String
[] xPath
= null;
1160 // if (tsGuid != null){
1161 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1164 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1166 xPath
= new String
[] { "/PcdDeclarations/PcdEntry"};
1167 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1172 public static XmlObject
[] getFpdPcdBuildDefinitions(String cName
, String tsGuid
, String type
) {
1173 String
[] xPath
= new String
[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName
+ "' and TokenSpaceGuid='"
1174 + tsGuid
+ "' and DatumType!='" + type
+ "']" };
1176 XmlObject
[] returns
= get("ModuleSA", xPath
);
1181 * getToolChainFamily
1183 * This function is to retrieve ToolChainFamily attribute of FPD
1187 * @return toolChainFamily If find toolChainFamily attribute in
1188 * <BuildOptions> Null If don't have toolChainFamily in
1191 public String
getToolChainFamily() {
1192 String
[] xPath
= new String
[] { "/BuildOptions" };
1194 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1195 if (result
== null) {
1198 // toolChainFamily =
1199 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1200 // return toolChainFamily;
1205 * Retrieve module Guid string
1207 * @returns GUILD string if elements are found at the known xpath
1208 * @returns null if nothing is there
1210 public static String
getModuleGuid() {
1211 String
[] xPath
= new String
[] { "" };
1213 XmlObject
[] returns
= get("MsaHeader", xPath
);
1214 if (returns
!= null && returns
.length
> 0) {
1215 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1226 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1227 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1228 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1229 if (result
!= null) {
1230 return (ModuleSADocument
.ModuleSA
[]) result
;
1232 return new ModuleSADocument
.ModuleSA
[0];