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();
897 * Get the PcdToken array from module's surface area document. The array
898 * should contains following data:
900 * -------------------------------------------------------------------
903 * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText
906 * -------------------------------------------------------------------
909 * Note: Until new schema applying, now we can only get CName, ItemType,
912 * @return 2-array table contains all information of PCD token retrieved
915 public static Object
[][] etModulePCDTokenArray() {
918 // Object[][] result;
919 // PCDs.PcdData[] pcds;
920 // String[] xPath = new String[] { "/PcdData" };
921 // XmlObject[] returns = get("PCDs", xPath);
923 // if ((returns == null) || (returns.length == 0)) {
927 // pcds = (PCDs.PcdData[]) returns;
928 // result = new Object[pcds.length][6];
929 // for (index = 0; index < pcds.length; index++) {
933 // result[index][0] = pcds[index].getCName();
935 // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE,
936 // // DYNAMIC, DYNAMIC_EX
938 // if (pcds[index].getItemType() != null) {
939 // result[index][1] = pcds[index].getItemType().toString();
941 // result[index][1] = null;
945 // // BUGBUG: following field can *not* be got from current MSA until
946 // // schema changed.
948 // // result [index][2] = pcds[index].getTokenSpaceName();
949 // result[index][2] = null;
950 // result[index][3] = pcds[index].getDefaultValue();
951 // // result [index][4] = pcds[index].getUsage ();
952 // result[index][4] = null;
953 // // result [index][5] = pcds[index].getHelpText ();
954 // result[index][5] = null;
960 * Retrieve MAS header
965 public static ModuleIdentification
getMsaHeader() {
966 String
[] xPath
= new String
[] { "/" };
967 XmlObject
[] returns
= get("MsaHeader", xPath
);
969 if (returns
== null || returns
.length
== 0) {
973 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
975 // Get BaseName, ModuleType, GuidValue, Version
976 // which in MsaHeader.
978 String name
= msaHeader
.getModuleName();
979 String moduleType
= "";
980 if (msaHeader
.getModuleType() != null) {
981 moduleType
= msaHeader
.getModuleType().toString();
984 String guid
= msaHeader
.getGuidValue();
985 String version
= msaHeader
.getVersion();
987 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
990 moduleId
.setModuleType(moduleType
);
996 * Retrieve Extern Specification
1000 * @return String[] If have specification element in the <extern> String[0]
1001 * If no specification element in the <extern>
1005 public static String
[] getExternSpecificaiton() {
1006 String
[] xPath
= new String
[] { "/Specification" };
1008 XmlObject
[] queryResult
= get("Externs", xPath
);
1009 if (queryResult
== null) {
1010 return new String
[0];
1013 String
[] specificationList
= new String
[queryResult
.length
];
1014 for (int i
= 0; i
< queryResult
.length
; i
++) {
1015 // specificationList[i] = ((SpecificationDocument.Specification)
1017 // .getStringValue();
1019 return specificationList
;
1023 * Retreive MsaFile which in SPD
1026 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1027 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1029 public static String
[] getSpdMsaFile() {
1030 String
[] xPath
= new String
[] { "/MsaFiles" };
1032 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1033 if (returns
== null) {
1034 return new String
[0];
1037 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1039 return filenameList
.toArray(new String
[filenameList
.size()]);
1045 public static Map
<String
, String
[]> getSpdLibraryClasses() {
1046 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1048 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1051 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1053 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1055 if (returns
== null) {
1056 return libClassHeaderMap
;
1059 for (int i
= 0; i
< returns
.length
; i
++) {
1060 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1061 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1062 .getIncludeHeader() });
1064 return libClassHeaderMap
;
1070 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1071 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1073 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1076 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1078 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1080 if (returns
== null) {
1081 return packageIncludeMap
;
1083 GlobalData
.log
.info("" + returns
[0].getClass().getName());
1084 for (int i
= 0; i
< returns
.length
; i
++) {
1085 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1086 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1087 includeHeader
.getStringValue());
1089 return packageIncludeMap
;
1092 public static PackageIdentification
getSpdHeader() {
1093 String
[] xPath
= new String
[] { "/SpdHeader" };
1095 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1097 if (returns
== null || returns
.length
== 0) {
1101 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1103 String name
= header
.getPackageName();
1105 String guid
= header
.getGuidValue();
1107 String version
= header
.getVersion();
1109 return new PackageIdentification(name
, guid
, version
);
1115 public static Map
<String
, String
[]> getSpdGuid() {
1116 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1118 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1121 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1123 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1124 if (returns
== null) {
1128 for (int i
= 0; i
< returns
.length
; i
++) {
1129 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1130 String
[] guidPair
= new String
[2];
1131 guidPair
[0] = entry
.getCName();
1132 guidPair
[1] = entry
.getGuidValue();
1133 guidDeclMap
.put(entry
.getName(), guidPair
);
1141 public static Map
<String
, String
[]> getSpdProtocol() {
1142 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1144 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1147 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1149 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1151 if (returns
== null) {
1155 for (int i
= 0; i
< returns
.length
; i
++) {
1156 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1157 String
[] protocolPair
= new String
[2];
1159 protocolPair
[0] = entry
.getCName();
1160 protocolPair
[1] = entry
.getGuidValue();
1161 protoclMap
.put(entry
.getName(), protocolPair
);
1167 * getSpdPpi() Retrieve the SPD PPI Entry
1170 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1171 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1174 public static Map
<String
, String
[]> getSpdPpi() {
1175 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1177 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1180 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1182 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1184 if (returns
== null) {
1188 for (int i
= 0; i
< returns
.length
; i
++) {
1189 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1190 String
[] ppiPair
= new String
[2];
1191 ppiPair
[0] = entry
.getCName();
1192 ppiPair
[1] = entry
.getGuidValue();
1193 ppiMap
.put(entry
.getName(), ppiPair
);
1199 * getModuleSupportedArchs()
1201 * This function is to Retrieve Archs one module supported.
1204 * @return supportArch String of supporting archs. null No arch specified in
1205 * <MouduleSupport> element.
1207 public static List
<String
> getModuleSupportedArchs() {
1208 String
[] xPath
= new String
[] { "/ModuleDefinitions/SupportedArchitectures" };
1210 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
1212 if (returns
== null) {
1216 return (List
<String
>)returns
[0];
1219 public static XmlObject
[] getSpdPcdDeclarations() {
1220 String
[] xPath
= null;
1221 // if (tsGuid != null){
1222 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1225 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1227 xPath
= new String
[] { "/PcdDeclarations/PcdEntry"};
1228 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1233 public static XmlObject
[] getFpdPcdBuildDefinitions(String cName
, String tsGuid
, String type
) {
1234 String
[] xPath
= new String
[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName
+ "' and TokenSpaceGuid='"
1235 + tsGuid
+ "' and DatumType!='" + type
+ "']" };
1237 XmlObject
[] returns
= get("ModuleSA", xPath
);
1242 * getToolChainFamily
1244 * This function is to retrieve ToolChainFamily attribute of FPD
1248 * @return toolChainFamily If find toolChainFamily attribute in
1249 * <BuildOptions> Null If don't have toolChainFamily in
1252 public String
getToolChainFamily() {
1253 String
[] xPath
= new String
[] { "/BuildOptions" };
1255 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1256 if (result
== null) {
1259 // toolChainFamily =
1260 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1261 // return toolChainFamily;
1266 * Retrieve module Guid string
1268 * @returns GUILD string if elements are found at the known xpath
1269 * @returns null if nothing is there
1271 public static String
getModuleGuid() {
1272 String
[] xPath
= new String
[] { "" };
1274 XmlObject
[] returns
= get("MsaHeader", xPath
);
1275 if (returns
!= null && returns
.length
> 0) {
1276 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1287 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1288 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1289 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1290 if (result
!= null) {
1291 return (ModuleSADocument
.ModuleSA
[]) result
;
1293 return new ModuleSADocument
.ModuleSA
[0];