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
.build
.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
;
22 import java
.util
.Stack
;
23 import java
.util
.regex
.Matcher
;
24 import java
.util
.regex
.Pattern
;
26 import org
.apache
.xmlbeans
.XmlObject
;
27 import org
.apache
.xmlbeans
.XmlString
;
28 import org
.tianocore
.BuildOptionsDocument
;
29 import org
.tianocore
.CNameType
;
30 import org
.tianocore
.ExternsDocument
;
31 import org
.tianocore
.FileNameConvention
;
32 import org
.tianocore
.FvImagesDocument
;
33 import org
.tianocore
.GuidDeclarationsDocument
;
34 import org
.tianocore
.GuidsDocument
;
35 import org
.tianocore
.LibrariesDocument
;
36 import org
.tianocore
.LibraryClassDeclarationsDocument
;
37 import org
.tianocore
.LibraryClassDocument
;
38 import org
.tianocore
.ModuleDefinitionsDocument
;
39 import org
.tianocore
.ModuleSADocument
;
40 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
41 import org
.tianocore
.ModuleTypeDef
;
42 import org
.tianocore
.MsaFilesDocument
;
43 import org
.tianocore
.MsaHeaderDocument
;
44 import org
.tianocore
.OptionDocument
;
45 import org
.tianocore
.PPIsDocument
;
46 import org
.tianocore
.PackageDependenciesDocument
;
47 import org
.tianocore
.PackageHeadersDocument
;
48 import org
.tianocore
.PcdCodedDocument
;
49 import org
.tianocore
.PlatformDefinitionsDocument
;
50 import org
.tianocore
.PlatformHeaderDocument
;
51 import org
.tianocore
.PpiDeclarationsDocument
;
52 import org
.tianocore
.ProtocolDeclarationsDocument
;
53 import org
.tianocore
.Sentence
;
54 import org
.tianocore
.SpdHeaderDocument
;
55 import org
.tianocore
.UserExtensionsDocument
;
56 import org
.tianocore
.FilenameDocument
.Filename
;
57 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
58 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
59 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
60 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
61 import org
.tianocore
.build
.id
.ModuleIdentification
;
62 import org
.tianocore
.build
.id
.PackageIdentification
;
63 import org
.tianocore
.build
.id
.PlatformIdentification
;
64 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
65 import org
.tianocore
.logger
.EdkLog
;
66 import org
.w3c
.dom
.Node
;
69 * SurfaceAreaQuery class is used to query Surface Area information from msa,
70 * mbd, spd and fpd files.
72 * This class should not instantiated. All the public interfaces is static.
76 public class SurfaceAreaQuery
{
78 public static String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
81 // / Contains name/value pairs of Surface Area document object. The name is
82 // / always the top level element name.
84 private static Map
<String
, XmlObject
> map
= null;
87 // / mapStack is used to do nested query
89 private static Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
92 // / prefix of name space
94 private static String nsPrefix
= "sans";
97 // / xmlbeans needs a name space for each Xpath element
99 private static String ns
= null;
102 // / keep the namep declaration for xmlbeans Xpath query
104 private static String queryDeclaration
= null;
107 * Set a Surface Area document for query later
110 * A Surface Area document in TopLevelElementName/XmlObject
113 public static void setDoc(Map
<String
, XmlObject
> map
) {
115 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
116 SurfaceAreaQuery
.map
= map
;
120 * Push current used Surface Area document into query stack. The given new
121 * document will be used for any immediately followed getXXX() callings,
122 * untill pop() is called.
125 * The TopLevelElementName/XmlObject format of a Surface Area
128 public static void push(Map
<String
, XmlObject
> newMap
) {
129 mapStack
.push(SurfaceAreaQuery
.map
);
130 SurfaceAreaQuery
.map
= newMap
;
134 * Discard current used Surface Area document and use the top document in
137 public static void pop() {
138 SurfaceAreaQuery
.map
= mapStack
.pop();
142 // / Convert xPath to be namespace qualified, which is necessary for
144 // / selectPath(). For example, converting /MsaHeader/ModuleType to
145 // / /ns:MsaHeader/ns:ModuleType
147 private static String
normalizeQueryString(String
[] exp
, String from
) {
148 StringBuffer normQueryString
= new StringBuffer(4096);
151 while (i
< exp
.length
) {
152 String newExp
= from
+ exp
[i
];
153 Pattern pattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
154 Matcher matcher
= pattern
.matcher(newExp
);
156 while (matcher
.find()) {
157 String starter
= newExp
.substring(matcher
.start(1), matcher
159 String seperator
= newExp
.substring(matcher
.start(2), matcher
161 String token
= newExp
.substring(matcher
.start(3), matcher
164 normQueryString
.append(starter
);
165 normQueryString
.append(seperator
);
166 normQueryString
.append(nsPrefix
);
167 normQueryString
.append(":");
168 normQueryString
.append(token
);
172 if (i
< exp
.length
) {
173 normQueryString
.append(" | ");
177 return normQueryString
.toString();
181 * Search all XML documents stored in "map" for the specified xPath, using
182 * relative path (starting with '$this')
185 * xpath query string array
186 * @returns An array of XmlObject if elements are found at the specified
188 * @returns NULL if nothing is at the specified xpath
190 public static Object
[] get(String
[] xPath
) {
195 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
196 List
<Object
> result
= new ArrayList
<Object
>();
197 for (int i
= 0; i
< keys
.length
; ++i
) {
198 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
199 if (rootNode
== null) {
203 String query
= queryDeclaration
204 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
205 XmlObject
[] tmp
= rootNode
.selectPath(query
);
206 for (int j
= 0; j
< tmp
.length
; ++j
) {
207 result
.add((Object
)tmp
[j
]);
211 int size
= result
.size();
216 return (Object
[]) result
.toArray(new Object
[size
]);
220 * Search XML documents named by "rootName" for the given xPath, using
221 * relative path (starting with '$this')
224 * The top level element name
226 * The xpath query string array
227 * @returns An array of XmlObject if elements are found at the given xpath
228 * @returns NULL if nothing is found at the given xpath
230 public static Object
[] get(String rootName
, String
[] xPath
) {
235 XmlObject root
= (XmlObject
) map
.get(rootName
);
240 String query
= queryDeclaration
241 + normalizeQueryString(xPath
, "$this/" + rootName
);
242 XmlObject
[] result
= root
.selectPath(query
);
243 if (result
.length
> 0) {
244 return (Object
[])result
;
247 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
248 result
= root
.selectPath(query
);
249 if (result
.length
> 0) {
250 return (Object
[])result
;
257 * Retrieve SourceFiles/Filename for specified ARCH type
261 * @returns An 2 dimension string array if elements are found at the known
263 * @returns NULL if nothing is found at the known xpath
265 public static String
[][] getSourceFiles(String arch
) {
269 xPath
= new String
[] { "/Filename" };
271 returns
= get("SourceFiles", xPath
);
273 if (returns
== null || returns
.length
== 0) {
274 return new String
[0][0];
277 Filename
[] sourceFileNames
= (Filename
[]) returns
;
278 List
<String
[]> outputList
= new ArrayList
<String
[]>();
279 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
280 List archList
= sourceFileNames
[i
].getSupArchList();
281 if (arch
== null || arch
.equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
282 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(),sourceFileNames
[i
].getStringValue()});
286 String
[][] outputString
= new String
[outputList
.size()][2];
287 for (int index
= 0; index
< outputList
.size(); index
++) {
288 outputString
[index
][0] = outputList
.get(index
)[0];
289 outputString
[index
][1] = outputList
.get(index
)[1];
295 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
297 * @returns Directory names array if elements are found at the known xpath
298 * @returns Empty if nothing is found at the known xpath
300 public static String
getFpdOutputDirectory() {
301 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
303 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
304 if (returns
== null || returns
.length
== 0) {
307 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
308 return item
.getOutputDirectory();
311 public static String
getFpdIntermediateDirectories() {
312 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
314 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
315 if (returns
== null || returns
.length
== 0) {
318 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
319 if(item
.getIntermediateDirectories() == null) {
323 return item
.getIntermediateDirectories().toString();
327 public static String
getModuleFfsKeyword() {
328 String
[] xPath
= new String
[] { "/" };
330 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
331 if (returns
== null || returns
.length
== 0) {
334 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
335 return item
.getFfsFormatKey();
338 public static String
getModuleFvBindingKeyword() {
339 String
[] xPath
= new String
[] { "/" };
341 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
342 if (returns
== null || returns
.length
== 0) {
345 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
346 return item
.getFvBinding();
349 public static List
getModuleSupportedArchs() {
350 String
[] xPath
= new String
[] { "/" };
352 Object
[] returns
= get("ModuleDefinitions", xPath
);
353 if (returns
== null || returns
.length
== 0) {
356 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
357 return item
.getSupportedArchitectures();
360 public static BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
361 String
[] xPath
= new String
[] {"/Ffs"};
363 Object
[] returns
= get("BuildOptions", xPath
);
364 if (returns
== null || returns
.length
== 0) {
365 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
367 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
370 public static String
getModuleOutputFileBasename() {
371 String
[] xPath
= new String
[] { "/" };
373 Object
[] returns
= get("ModuleDefinitions", xPath
);
374 if (returns
== null || returns
.length
== 0) {
377 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
378 return item
.getOutputFileBasename();
382 * Retrieve BuildOptions/Option or Arch/Option
384 * @param toolChainFamilyFlag
385 * if true, retrieve options for toolchain family; otherwise for
388 * @returns String[][5] name, target, toolchain, arch, coommand of options
389 * if elements are found at the known xpath. String[0][] if dont
392 * @returns Empty array if nothing is there
394 public static String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
395 String target
= null;
396 String toolchain
= null;
397 String toolchainFamily
= null;
398 List
<String
> archList
= null;
400 String optionName
= null;
402 Object
[] returns
= get(from
, xPath
);
403 if (returns
== null) {
404 return new String
[0][5];
407 List
<String
[]> optionList
= new ArrayList
<String
[]>();
408 OptionDocument
.Option option
;
410 for (int i
= 0; i
< returns
.length
; i
++) {
411 option
= (OptionDocument
.Option
) returns
[i
];
414 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
416 // put to result[][5] array in above order.
419 if (option
.getBuildTargets() == null) {
423 target
= option
.getBuildTargets().toString();
425 if (target
!= null) {
426 targetList
= target
.split(" ");
428 targetList
= new String
[1];
429 targetList
[0] = null;
432 if (toolChainFamilyFlag
) {
433 toolchainFamily
= option
.getToolChainFamily();
434 if (toolchainFamily
!= null) {
435 toolchain
= toolchainFamily
.toString();
440 toolchain
= option
.getTagName();
443 archList
= new ArrayList
<String
>();
444 List archEnumList
= option
.getSupArchList();
445 if (archEnumList
== null) {
448 //archList.addAll(archEnumList);
449 Iterator it
= archEnumList
.iterator();
450 while (it
.hasNext()) {
451 String archType
= (String
)it
.next();
452 archList
.add(archType
);
456 cmd
= option
.getToolCode();
458 optionName
= option
.getStringValue();
459 for (int t
= 0; t
< targetList
.length
; t
++) {
460 for (int j
= 0; j
< archList
.size(); j
++) {
461 optionList
.add(new String
[] { targetList
[t
],
462 toolchain
, archList
.get(j
), cmd
, optionName
});
467 String
[][] result
= new String
[optionList
.size()][5];
468 for (int i
= 0; i
< optionList
.size(); i
++) {
469 result
[i
][0] = optionList
.get(i
)[0];
470 result
[i
][1] = optionList
.get(i
)[1];
471 result
[i
][2] = optionList
.get(i
)[2];
472 result
[i
][3] = optionList
.get(i
)[3];
473 result
[i
][4] = optionList
.get(i
)[4];
478 public static String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
481 if (toolChainFamilyFlag
== true) {
482 xPath
= new String
[] {
483 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
484 "/Options/Option[@ToolChainFamily]", };
486 xPath
= new String
[] {
487 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
488 "/Options/Option[@TagName]", };
490 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
493 public static String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
496 if (toolChainFamilyFlag
== true) {
497 xPath
= new String
[] {
498 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
499 "/BuildOptions/Options/Option[@ToolChainFamily]", };
501 xPath
= new String
[] {
502 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
503 "/BuildOptions/Options/Option[@TagName]", };
506 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
509 public static ToolChainInfo
getFpdToolChainInfo() {
510 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
512 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
513 if (returns
== null || returns
.length
== 0) {
517 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
518 ToolChainInfo toolChainInfo
= new ToolChainInfo();
519 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
520 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
521 toolChainInfo
.addTagnames((String
)null);
522 return toolChainInfo
;
526 * Retrieve <xxxHeader>/ModuleType
528 * @returns The module type name if elements are found at the known xpath
529 * @returns null if nothing is there
531 public static String
getModuleType() {
532 String
[] xPath
= new String
[] { "/ModuleType" };
534 Object
[] returns
= get(xPath
);
535 if (returns
!= null && returns
.length
> 0) {
536 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
537 return type
.enumValue().toString();
544 * Retrieve PackageDependencies/Package
549 * @returns package name list if elements are found at the known xpath
550 * @returns null if nothing is there
552 public static PackageIdentification
[] getDependencePkg(String arch
) {
554 String packageGuid
= null;
555 String packageVersion
= null;
558 xPath
= new String
[] { "/Package" };
560 Object
[] returns
= get("PackageDependencies", xPath
);
561 if (returns
== null) {
562 return new PackageIdentification
[0];
566 // Get packageIdentification
568 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
569 for (int i
= 0; i
< returns
.length
; i
++) {
570 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
571 List archList
= item
.getSupArchList();
572 if (arch
== null || archList
== null || contains(archList
, arch
)) {
573 packageGuid
= item
.getPackageGuid();
574 packageVersion
= item
.getPackageVersion();
575 packageIdList
.add(new PackageIdentification(null, packageGuid
,
581 // transfer packageIdentification list to array.
583 PackageIdentification
[] packageIdArray
= new PackageIdentification
[packageIdList
.size()];
584 for (int i
= 0; i
< packageIdList
.size(); i
++) {
585 packageIdArray
[i
] = new PackageIdentification(null, packageIdList
.get(i
).getGuid(),packageIdList
.get(i
).getVersion());
587 return packageIdArray
;
591 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
594 * Library class usage
596 * @returns LibraryClass objects list if elements are found at the known
598 * @returns null if nothing is there
600 public static String
[] getLibraryClasses(String usage
, String arch
) {
602 if (usage
== null || usage
.equals("")) {
603 xPath
= new String
[] { "/LibraryClass" };
605 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
608 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
609 if (returns
== null || returns
.length
== 0) {
610 return new String
[0];
613 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
614 List
<String
> libraryClassName
= new ArrayList
<String
>();
615 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
616 List archList
= libraryClassList
[i
].getSupArchList();
618 if (arch
== null || contains(archList
, arch
)) {
619 libraryClassName
.add(libraryClassList
[i
].getKeyword());
622 String
[] libraryArray
= new String
[libraryClassName
.size()];
623 for (int i
= 0; i
< libraryClassName
.size(); i
++) {
624 libraryArray
[i
] = libraryClassName
.get(i
);
630 * Retrieve ModuleEntryPoint names
632 * @returns ModuleEntryPoint name list if elements are found at the known
634 * @returns null if nothing is there
636 public static String
[] getModuleEntryPointArray() {
637 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
639 Object
[] returns
= get("Externs", xPath
);
641 if (returns
!= null && returns
.length
> 0) {
642 String
[] entryPoints
= new String
[returns
.length
];
644 for (int i
= 0; i
< returns
.length
; ++i
) {
645 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
655 * retrieve Protocol for specified usage
658 * Protocol usage arch Architecture
660 * @returns Protocol String list if elements are found at the known xpath
661 * @returns String[0] if nothing is there
663 public static String
[] getProtocolArray(String arch
, String usage
) {
665 String usageXpath
= "";
666 String archXpath
= "";
668 if (arch
== null || arch
.equals("")) {
669 return new String
[0];
671 archXpath
= "/Protocol";
672 if (usage
!= null && !usage
.equals("")) {
673 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
674 xPath
= new String
[] { usageXpath
, archXpath
};
676 return getProtocolArray(arch
);
681 Object
[] returns
= get("Protocols", xPath
);
682 if (returns
== null) {
683 return new String
[0];
685 Protocol
[] protocolList
= (Protocol
[]) returns
;
687 String
[] protocolArray
= new String
[returns
.length
];
688 for (int i
= 0; i
< returns
.length
; i
++) {
689 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
691 return protocolArray
;
695 * retrieve Protocol for specified usage
700 * @returns Protocol String list if elements are found at the known xpath
701 * @returns String[0] if nothing is there
703 public static String
[] getProtocolArray(String arch
) {
706 if (arch
== null || arch
.equals("")) {
707 return new String
[0];
709 xPath
= new String
[] { "/Protocol" };
712 Object
[] returns
= get("Protocols", xPath
);
713 if (returns
== null) {
714 return new String
[0];
716 Protocol
[] returnlList
= (Protocol
[]) returns
;
718 List
<String
> protocolList
= new ArrayList
<String
>();
720 for (int i
= 0; i
< returns
.length
; i
++) {
721 List archList
= returnlList
[i
].getSupArchList();
722 if (archList
== null || contains(archList
, arch
)){
723 protocolList
.add(returnlList
[i
].getProtocolCName());
726 String
[] protocolArray
= new String
[protocolList
.size()];
727 for (int i
= 0; i
< protocolList
.size(); i
++) {
728 protocolArray
[i
] = protocolList
.get(i
);
730 return protocolArray
;
734 * Retrieve ProtocolNotify for specified usage
737 * ProtocolNotify usage
739 * @returns String[] if elements are found at the known xpath
740 * @returns String[0] if nothing is there
742 public static String
[] getProtocolNotifyArray(String arch
) {
745 if (arch
== null || arch
.equals("")) {
746 return new String
[0];
748 xPath
= new String
[] { "/ProtocolNotify" };
751 Object
[] returns
= get("Protocols", xPath
);
752 if (returns
== null) {
753 return new String
[0];
756 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
758 for (int i
= 0; i
< returns
.length
; i
++) {
759 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
760 if (archList
== null || contains(archList
, arch
)){
761 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
765 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
766 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
767 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
769 return protocolNotifyArray
;
773 * Retrieve ProtocolNotify for specified usage
776 * ProtocolNotify usage
778 * @returns String[] if elements are found at the known xpath
779 * @returns String[0] if nothing is there
781 public static String
[] getProtocolNotifyArray(String arch
, String usage
) {
787 if (arch
== null || arch
.equals("")) {
788 return new String
[0];
790 archXpath
= "/ProtocolNotify";
791 if (usage
!= null && !usage
.equals("")) {
792 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
793 xPath
= new String
[] { archXpath
, usageXpath
};
795 return getProtocolNotifyArray(arch
);
799 Object
[] returns
= get("Protocols", xPath
);
800 if (returns
== null) {
801 return new String
[0];
804 String
[] protocolNotifyList
= new String
[returns
.length
];
806 for (int i
= 0; i
< returns
.length
; i
++) {
807 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
809 return protocolNotifyList
;
813 * Retrieve ModuleUnloadImage names
815 * @returns ModuleUnloadImage name list if elements are found at the known
817 * @returns null if nothing is there
819 public static String
[] getModuleUnloadImageArray() {
820 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
822 Object
[] returns
= get("Externs", xPath
);
823 if (returns
!= null && returns
.length
> 0) {
824 String
[] stringArray
= new String
[returns
.length
];
825 CNameType
[] doc
= (CNameType
[]) returns
;
827 for (int i
= 0; i
< returns
.length
; ++i
) {
828 stringArray
[i
] = doc
[i
].getStringValue();
840 * @returns Extern objects list if elements are found at the known xpath
841 * @returns null if nothing is there
843 public static ExternsDocument
.Externs
.Extern
[] getExternArray() {
844 String
[] xPath
= new String
[] { "/Extern" };
846 Object
[] returns
= get("Externs", xPath
);
847 if (returns
!= null && returns
.length
> 0) {
848 return (ExternsDocument
.Externs
.Extern
[]) returns
;
855 * Retrieve PpiNotify for specified arch
860 * @returns String[] if elements are found at the known xpath
861 * @returns String[0] if nothing is there
863 public static String
[] getPpiNotifyArray(String arch
) {
866 if (arch
== null || arch
.equals("")) {
867 return new String
[0];
869 xPath
= new String
[] { "/PpiNotify" };
872 Object
[] returns
= get("PPIs", xPath
);
873 if (returns
== null) {
874 return new String
[0];
878 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
879 for (int i
= 0; i
< returns
.length
; i
++) {
880 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
881 if (archList
== null || contains(archList
, arch
)){
882 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
886 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
887 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
888 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
891 return ppiNotifyArray
;
895 * Retrieve PpiNotify for specified usage and arch
898 * PpiNotify arch usage PpiNotify usage
901 * @returns String[] if elements are found at the known xpath
902 * @returns String[0] if nothing is there
904 public static String
[] getPpiNotifyArray(String arch
, String usage
) {
910 if (arch
== null || arch
.equals("")) {
911 return new String
[0];
913 archXpath
= "/PpiNotify";
914 if (usage
!= null && !usage
.equals("")) {
915 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
916 xPath
= new String
[] { archXpath
, usageXpath
};
918 return getProtocolNotifyArray(arch
);
922 Object
[] returns
= get("PPIs", xPath
);
923 if (returns
== null) {
924 return new String
[0];
927 String
[] ppiNotifyList
= new String
[returns
.length
];
929 for (int i
= 0; i
< returns
.length
; i
++) {
930 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
932 return ppiNotifyList
;
936 * Retrieve Ppi for specified arch
941 * @returns String[] if elements are found at the known xpath
942 * @returns String[0] if nothing is there
944 public static String
[] getPpiArray(String arch
) {
947 if (arch
== null || arch
.equals("")) {
948 return new String
[0];
950 xPath
= new String
[] { "/Ppi" };
953 Object
[] returns
= get("PPIs", xPath
);
954 if (returns
== null) {
955 return new String
[0];
958 List
<String
> ppiList
= new ArrayList
<String
>();
959 for (int i
= 0; i
< returns
.length
; i
++) {
960 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
961 if (archList
== null || contains(archList
, arch
)){
962 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
966 String
[] ppiArray
= new String
[ppiList
.size()];
967 for (int i
= 0; i
< ppiList
.size(); i
++) {
968 ppiArray
[i
] = ppiList
.get(i
);
974 * Retrieve PpiNotify for specified usage and arch
977 * PpiNotify arch usage PpiNotify usage
980 * @returns String[] if elements are found at the known xpath
981 * @returns String[0] if nothing is there
983 public static String
[] getPpiArray(String arch
, String usage
) {
989 if (arch
== null || arch
.equals("")) {
990 return new String
[0];
993 if (usage
!= null && !usage
.equals("")) {
994 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
995 xPath
= new String
[] { archXpath
, usageXpath
};
997 return getProtocolNotifyArray(arch
);
1001 Object
[] returns
= get("PPIs", xPath
);
1002 if (returns
== null) {
1003 return new String
[0];
1006 String
[] ppiList
= new String
[returns
.length
];
1008 for (int i
= 0; i
< returns
.length
; i
++) {
1009 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1015 * Retrieve GuidEntry information for specified usage
1020 * @returns GuidEntry objects list if elements are found at the known xpath
1021 * @returns null if nothing is there
1023 public static String
[] getGuidEntryArray(String arch
) {
1026 if (arch
== null || arch
.equals("")) {
1027 xPath
= new String
[] { "/GuidCNames" };
1029 xPath
= new String
[] { "/GuidCNames" };
1032 Object
[] returns
= get("Guids", xPath
);
1033 if (returns
== null) {
1034 return new String
[0];
1037 List
<String
> guidList
= new ArrayList
<String
>();
1038 for (int i
= 0; i
< returns
.length
; i
++) {
1039 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1040 if (archList
== null || contains(archList
, arch
)){
1041 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1045 String
[] guidArray
= new String
[guidList
.size()];
1046 for (int i
= 0; i
< guidList
.size(); i
++) {
1047 guidArray
[i
] = guidList
.get(i
);
1054 * Retrieve GuidEntry information for specified usage
1057 * GuidEntry arch usage GuidEntry usage
1059 * @returns GuidEntry objects list if elements are found at the known xpath
1060 * @returns null if nothing is there
1062 public static String
[] getGuidEntryArray(String arch
, String usage
) {
1067 if (arch
== null || arch
.equals("")) {
1068 return new String
[0];
1070 archXpath
= "/GuidEntry";
1071 if (usage
!= null && !usage
.equals("")) {
1072 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1073 xPath
= new String
[] { archXpath
, usageXpath
};
1075 return getProtocolNotifyArray(arch
);
1079 Object
[] returns
= get("Guids", xPath
);
1080 if (returns
== null) {
1081 return new String
[0];
1084 String
[] guidList
= new String
[returns
.length
];
1086 for (int i
= 0; i
< returns
.length
; i
++) {
1087 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1093 * Retrieve Library instance information
1098 * Library instance usage
1100 * @returns library instance name list if elements are found at the known
1102 * @returns null if nothing is there
1104 public static ModuleIdentification
[] getLibraryInstance(String arch
) {
1106 String saGuid
= null;
1107 String saVersion
= null;
1108 String pkgGuid
= null;
1109 String pkgVersion
= null;
1111 if (arch
== null || arch
.equalsIgnoreCase("")) {
1112 xPath
= new String
[] { "/Instance" };
1115 // Since Schema don't have SupArchList now, so the follow Xpath is
1116 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1117 // don't have effect.
1119 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1123 Object
[] returns
= get("Libraries", xPath
);
1124 if (returns
== null || returns
.length
== 0) {
1125 return new ModuleIdentification
[0];
1128 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1129 for (int i
= 0; i
< returns
.length
; i
++) {
1130 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1131 saGuid
= library
.getModuleGuid();
1132 saVersion
= library
.getModuleVersion();
1134 pkgGuid
= library
.getPackageGuid();
1135 pkgVersion
= library
.getPackageVersion();
1137 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1139 PackageIdentification pkgId
= new PackageIdentification(null,
1140 pkgGuid
, pkgVersion
);
1141 saId
.setPackage(pkgId
);
1150 // / This method is used for retrieving the elements information which has
1151 // / CName sub-element
1153 private static String
[] getCNames(String from
, String xPath
[]) {
1154 Object
[] returns
= get(from
, xPath
);
1155 if (returns
== null || returns
.length
== 0) {
1159 String
[] strings
= new String
[returns
.length
];
1160 for (int i
= 0; i
< returns
.length
; ++i
) {
1162 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1169 * Retrive library's constructor name
1171 * @returns constructor name list if elements are found at the known xpath
1172 * @returns null if nothing is there
1174 public static String
getLibConstructorName() {
1175 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1177 Object
[] returns
= get("Externs", xPath
);
1178 if (returns
!= null && returns
.length
> 0) {
1179 CNameType constructor
= ((CNameType
) returns
[0]);
1180 return constructor
.getStringValue();
1187 * Retrive library's destructor name
1189 * @returns destructor name list if elements are found at the known xpath
1190 * @returns null if nothing is there
1192 public static String
getLibDestructorName() {
1193 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1195 Object
[] returns
= get("Externs", xPath
);
1196 if (returns
!= null && returns
.length
> 0) {
1198 // Only support one Destructor function.
1200 CNameType destructor
= (CNameType
) returns
[0];
1201 return destructor
.getStringValue();
1208 * Retrive DriverBinding names
1210 * @returns DriverBinding name list if elements are found at the known xpath
1211 * @returns null if nothing is there
1213 public static String
[] getDriverBindingArray() {
1214 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1215 return getCNames("Externs", xPath
);
1219 * Retrive ComponentName names
1221 * @returns ComponentName name list if elements are found at the known xpath
1222 * @returns null if nothing is there
1224 public static String
[] getComponentNameArray() {
1225 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1226 return getCNames("Externs", xPath
);
1230 * Retrive DriverConfig names
1232 * @returns DriverConfig name list if elements are found at the known xpath
1233 * @returns null if nothing is there
1235 public static String
[] getDriverConfigArray() {
1236 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1237 return getCNames("Externs", xPath
);
1241 * Retrive DriverDiag names
1243 * @returns DriverDiag name list if elements are found at the known xpath
1244 * @returns null if nothing is there
1246 public static String
[] getDriverDiagArray() {
1247 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1248 return getCNames("Externs", xPath
);
1252 * Retrive SetVirtualAddressMapCallBack names
1254 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1256 * @returns null if nothing is there
1258 public static String
[] getSetVirtualAddressMapCallBackArray() {
1259 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1260 return getCNames("Externs", xPath
);
1264 * Retrive ExitBootServicesCallBack names
1266 * @returns ExitBootServicesCallBack name list if elements are found at the
1268 * @returns null if nothing is there
1270 public static String
[] getExitBootServicesCallBackArray() {
1271 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1272 return getCNames("Externs", xPath
);
1276 * Retrieve module surface area file information
1278 * @returns ModuleSA objects list if elements are found at the known xpath
1279 * @returns Empty ModuleSA list if nothing is there
1281 public static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() {
1282 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1283 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1285 String fvBinding
= null;
1286 String saGuid
= null;
1287 String saVersion
= null;
1288 String pkgGuid
= null;
1289 String pkgVersion
= null;
1291 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1293 if (result
== null) {
1294 return fpdModuleMap
;
1297 for (int i
= 0; i
< result
.length
; i
++) {
1299 // Get Fpd SA Module element node and add to ObjectMap.
1301 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1302 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1303 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1304 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1306 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1307 ObjectMap
.put("PcdBuildDefinition", moduleSA
1308 .getPcdBuildDefinition());
1310 if (((ModuleSADocument
.ModuleSA
) result
[i
])
1311 .getModuleSaBuildOptions() != null) {
1312 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
1313 .getModuleSaBuildOptions());
1317 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1319 arch
= moduleSA
.getSupArchList().toString();
1323 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
])
1324 .getModuleVersion();
1326 saGuid
= moduleSA
.getModuleGuid();
1327 pkgGuid
= moduleSA
.getPackageGuid();
1328 pkgVersion
= moduleSA
.getPackageVersion();
1331 // Create Module Identification which have class member of package
1334 PackageIdentification pkgId
= new PackageIdentification(null,
1335 pkgGuid
, pkgVersion
);
1336 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1339 saId
.setPackage(pkgId
);
1342 // Create FpdModule Identification which have class member of module
1346 String
[] archList
= arch
.split(" ");
1347 for (int j
= 0; j
< archList
.length
; j
++) {
1348 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1350 if (fvBinding
!= null) {
1351 fpdSaId
.setFvBinding(fvBinding
);
1355 // Put element to Map<FpdModuleIdentification, Map<String,
1358 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1362 return fpdModuleMap
;
1366 * Retrieve valid image names
1368 * @returns valid iamges name list if elements are found at the known xpath
1369 * @returns empty list if nothing is there
1371 public static String
[] getFpdValidImageNames() {
1372 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1374 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1375 if (queryResult
== null) {
1376 return new String
[0];
1379 String
[] result
= new String
[queryResult
.length
];
1380 for (int i
= 0; i
< queryResult
.length
; i
++) {
1381 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1387 public static Node
getFpdUserExtensionPreBuild() {
1388 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1390 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1391 if (queryResult
== null || queryResult
.length
== 0) {
1394 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1396 return a
.getDomNode();
1399 public static Node
getFpdUserExtensionPostBuild() {
1400 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1402 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1403 if (queryResult
== null || queryResult
.length
== 0) {
1406 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1408 return a
.getDomNode();
1412 * Retrieve FV image option information
1417 * @returns option name/value list if elements are found at the known xpath
1418 * @returns empty list if nothing is there
1420 public static String
[][] getFpdOptions(String fvName
) {
1421 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1422 + fvName
.toUpperCase() + "']/FvImageOptions" };
1423 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1424 if (queryResult
== null) {
1425 return new String
[0][];
1427 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1428 for (int i
= 0; i
< queryResult
.length
; i
++) {
1429 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1430 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1431 .getNameValueList();
1432 Iterator iter
= namevalues
.iterator();
1433 while (iter
.hasNext()) {
1434 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1436 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1439 String
[][] result
= new String
[list
.size()][2];
1440 for (int i
= 0; i
< list
.size(); i
++) {
1441 result
[i
][0] = list
.get(i
)[0];
1442 result
[i
][1] = list
.get(i
)[1];
1448 public static XmlObject
getFpdBuildOptions() {
1449 String
[] xPath
= new String
[] { "/BuildOptions" };
1451 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1453 if (queryResult
== null || queryResult
.length
== 0) {
1456 return (XmlObject
)queryResult
[0];
1459 public static PlatformIdentification
getFpdHeader() {
1460 String
[] xPath
= new String
[] { "/PlatformHeader" };
1462 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1464 if (returns
== null || returns
.length
== 0) {
1467 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1469 String name
= header
.getPlatformName();
1471 String guid
= header
.getGuidValue();
1473 String version
= header
.getVersion();
1475 return new PlatformIdentification(name
, guid
, version
);
1479 * Retrieve FV image attributes information
1484 * @returns attribute name/value list if elements are found at the known
1486 * @returns empty list if nothing is there
1488 public static String
[][] getFpdAttributes(String fvName
) {
1489 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1490 + fvName
.toUpperCase() + "']/FvImageOptions" };
1491 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1492 if (queryResult
== null) {
1493 return new String
[0][];
1495 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1496 for (int i
= 0; i
< queryResult
.length
; i
++) {
1498 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1499 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1500 Iterator iter
= namevalues
.iterator();
1501 while (iter
.hasNext()) {
1502 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1504 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1507 String
[][] result
= new String
[list
.size()][2];
1508 for (int i
= 0; i
< list
.size(); i
++) {
1509 result
[i
][0] = list
.get(i
)[0];
1510 result
[i
][1] = list
.get(i
)[1];
1516 * Retrieve flash definition file name
1518 * @returns file name if elements are found at the known xpath
1519 * @returns null if nothing is there
1521 public static String
getFlashDefinitionFile() {
1522 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1524 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1525 if (queryResult
== null || queryResult
.length
== 0) {
1529 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1530 return filename
.getStringValue();
1533 public static String
[][] getFpdGlobalVariable() {
1534 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1535 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1536 if (queryResult
== null) {
1537 return new String
[0][];
1540 String
[][] result
= new String
[queryResult
.length
][2];
1542 for (int i
= 0; i
< queryResult
.length
; i
++) {
1543 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1544 result
[i
][0] = item
.getName();
1545 result
[i
][1] = item
.getValue();
1551 * Retrieve FV image component options
1556 * @returns name/value pairs list if elements are found at the known xpath
1557 * @returns empty list if nothing is there
1559 public static String
[][] getFpdComponents(String fvName
) {
1560 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
.toUpperCase() + "']/FvImageOptions" };
1561 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1562 if (queryResult
== null) {
1563 return new String
[0][];
1566 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1567 for (int i
= 0; i
< queryResult
.length
; i
++) {
1568 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1569 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1570 Iterator iter
= namevalues
.iterator();
1571 while (iter
.hasNext()) {
1572 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1574 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1577 String
[][] result
= new String
[list
.size()][2];
1578 for (int i
= 0; i
< list
.size(); i
++) {
1579 result
[i
][0] = list
.get(i
)[0];
1580 result
[i
][1] = list
.get(i
)[1];
1586 * Retrieve PCD tokens
1588 * @returns CName/ItemType pairs list if elements are found at the known
1590 * @returns null if nothing is there
1592 public static String
[][] getPcdTokenArray() {
1593 String
[] xPath
= new String
[] { "/PcdData" };
1595 Object
[] returns
= get("PCDs", xPath
);
1596 if (returns
== null || returns
.length
== 0) {
1604 * Retrieve MAS header
1609 public static ModuleIdentification
getMsaHeader() {
1610 String
[] xPath
= new String
[] { "/" };
1611 Object
[] returns
= get("MsaHeader", xPath
);
1613 if (returns
== null || returns
.length
== 0) {
1617 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1619 // Get BaseName, ModuleType, GuidValue, Version
1620 // which in MsaHeader.
1622 String name
= msaHeader
.getModuleName();
1623 String moduleType
= msaHeader
.getModuleType().toString();
1624 String guid
= msaHeader
.getGuidValue();
1625 String version
= msaHeader
.getVersion();
1627 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1630 moduleId
.setModuleType(moduleType
);
1636 * Retrieve Extern Specification
1640 * @return String[] If have specification element in the <extern> String[0]
1641 * If no specification element in the <extern>
1645 public static String
[] getExternSpecificaiton() {
1646 String
[] xPath
= new String
[] { "/Specification" };
1648 Object
[] queryResult
= get("Externs", xPath
);
1649 if (queryResult
== null) {
1650 return new String
[0];
1653 String
[] specificationList
= new String
[queryResult
.length
];
1654 for (int i
= 0; i
< queryResult
.length
; i
++) {
1655 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1658 return specificationList
;
1662 * Retreive MsaFile which in SPD
1665 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1666 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1668 public static String
[] getSpdMsaFile() {
1669 String
[] xPath
= new String
[] { "/MsaFiles" };
1671 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1672 if (returns
== null) {
1673 return new String
[0];
1676 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1678 return filenameList
.toArray(new String
[filenameList
.size()]);
1684 public static Map
<String
, String
[]> getSpdLibraryClasses() {
1685 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1687 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1690 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1692 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1694 if (returns
== null) {
1695 return libClassHeaderMap
;
1698 for (int i
= 0; i
< returns
.length
; i
++) {
1699 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1700 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1701 .getIncludeHeader() });
1703 return libClassHeaderMap
;
1709 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1710 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1712 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1715 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1717 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1719 if (returns
== null) {
1720 return packageIncludeMap
;
1723 for (int i
= 0; i
< returns
.length
; i
++) {
1724 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1725 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1726 includeHeader
.getStringValue());
1728 return packageIncludeMap
;
1731 public static PackageIdentification
getSpdHeader() {
1732 String
[] xPath
= new String
[] { "/SpdHeader" };
1734 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1736 if (returns
== null || returns
.length
== 0) {
1740 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1742 String name
= header
.getPackageName();
1744 String guid
= header
.getGuidValue();
1746 String version
= header
.getVersion();
1748 return new PackageIdentification(name
, guid
, version
);
1754 public static Map
<String
, String
[]> getSpdGuid() {
1755 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1757 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1760 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1762 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1763 if (returns
== null) {
1767 for (int i
= 0; i
< returns
.length
; i
++) {
1768 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1769 String
[] guidPair
= new String
[2];
1770 guidPair
[0] = entry
.getCName();
1771 guidPair
[1] = entry
.getGuidValue();
1772 guidDeclMap
.put(entry
.getName(), guidPair
);
1773 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1774 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[0]);
1775 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[1]);
1783 public static Map
<String
, String
[]> getSpdProtocol() {
1784 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1786 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1789 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1791 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1793 if (returns
== null) {
1797 for (int i
= 0; i
< returns
.length
; i
++) {
1798 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1799 String
[] protocolPair
= new String
[2];
1801 protocolPair
[0] = entry
.getCName();
1802 protocolPair
[1] = entry
.getGuidValue();
1803 protoclMap
.put(entry
.getName(), protocolPair
);
1804 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1805 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[0]);
1806 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[1]);
1812 * getSpdPpi() Retrieve the SPD PPI Entry
1815 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1816 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1819 public static Map
<String
, String
[]> getSpdPpi() {
1820 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1822 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1825 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1827 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1829 if (returns
== null) {
1833 for (int i
= 0; i
< returns
.length
; i
++) {
1834 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1835 String
[] ppiPair
= new String
[2];
1836 ppiPair
[0] = entry
.getCName();
1837 ppiPair
[1] = entry
.getGuidValue();
1838 ppiMap
.put(entry
.getName(), ppiPair
);
1844 * Retrieve module Guid string
1846 * @returns GUILD string if elements are found at the known xpath
1847 * @returns null if nothing is there
1849 public static String
getModuleGuid() {
1850 String
[] xPath
= new String
[] { "" };
1852 Object
[] returns
= get("MsaHeader", xPath
);
1853 if (returns
!= null && returns
.length
> 0) {
1854 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1865 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1866 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1867 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1868 if (result
!= null) {
1869 return (ModuleSADocument
.ModuleSA
[]) result
;
1871 return new ModuleSADocument
.ModuleSA
[0];
1875 Get name array of PCD in a module. In one module, token space
1876 is same, and token name should not be conflicted.
1880 public static String
[] getModulePcdEntryNameArray() {
1881 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1884 String
[] xPath
= new String
[] {"/PcdEntry"};
1885 Object
[] returns
= get ("PcdCoded", xPath
);
1887 if (returns
== null) {
1888 return new String
[0];
1891 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1892 results
= new String
[pcdEntries
.length
];
1894 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1895 results
[index
] = pcdEntries
[index
].getCName();
1901 Search in a List for a given string
1905 public static boolean contains(List list
, String str
) {
1906 if (list
== null || list
.size()== 0) {
1909 Iterator it
= list
.iterator();
1910 while (it
.hasNext()) {
1911 String s
= (String
)it
.next();
1912 if (s
.equalsIgnoreCase(str
)) {