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
.w3c
.dom
.Node
;
28 import org
.apache
.xmlbeans
.XmlObject
;
29 import org
.apache
.xmlbeans
.XmlString
;
31 import org
.tianocore
.BuildOptionsDocument
;
32 import org
.tianocore
.CNameType
;
33 import org
.tianocore
.ExternsDocument
;
34 import org
.tianocore
.FileNameConvention
;
35 import org
.tianocore
.FvImagesDocument
;
36 import org
.tianocore
.GuidDeclarationsDocument
;
37 import org
.tianocore
.GuidsDocument
;
38 import org
.tianocore
.LibrariesDocument
;
39 import org
.tianocore
.LibraryClassDeclarationsDocument
;
40 import org
.tianocore
.LibraryClassDocument
;
41 import org
.tianocore
.ModuleDefinitionsDocument
;
42 import org
.tianocore
.ModuleSADocument
;
43 import org
.tianocore
.ModuleSaBuildOptionsDocument
;
44 import org
.tianocore
.ModuleTypeDef
;
45 import org
.tianocore
.MsaFilesDocument
;
46 import org
.tianocore
.MsaHeaderDocument
;
47 import org
.tianocore
.OptionDocument
;
48 import org
.tianocore
.PPIsDocument
;
49 import org
.tianocore
.PackageDependenciesDocument
;
50 import org
.tianocore
.PackageHeadersDocument
;
51 import org
.tianocore
.PcdCodedDocument
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PlatformHeaderDocument
;
54 import org
.tianocore
.PpiDeclarationsDocument
;
55 import org
.tianocore
.ProtocolDeclarationsDocument
;
56 import org
.tianocore
.Sentence
;
57 import org
.tianocore
.SpdHeaderDocument
;
58 import org
.tianocore
.UserExtensionsDocument
;
59 import org
.tianocore
.FilenameDocument
.Filename
;
60 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
61 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
62 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
64 import org
.tianocore
.common
.logger
.EdkLog
;
65 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
66 import org
.tianocore
.build
.id
.ModuleIdentification
;
67 import org
.tianocore
.build
.id
.PackageIdentification
;
68 import org
.tianocore
.build
.id
.PlatformIdentification
;
69 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
72 * SurfaceAreaQuery class is used to query Surface Area information from msa,
73 * mbd, spd and fpd files.
75 * This class should not instantiated. All the public interfaces is static.
79 public class SurfaceAreaQuery
{
81 public static String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
84 // / Contains name/value pairs of Surface Area document object. The name is
85 // / always the top level element name.
87 private static Map
<String
, XmlObject
> map
= null;
90 // / mapStack is used to do nested query
92 private static Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
95 // / prefix of name space
97 private static String nsPrefix
= "sans";
100 // / xmlbeans needs a name space for each Xpath element
102 private static String ns
= null;
105 // / keep the namep declaration for xmlbeans Xpath query
107 private static String queryDeclaration
= null;
110 * Set a Surface Area document for query later
113 * A Surface Area document in TopLevelElementName/XmlObject
116 public static void setDoc(Map
<String
, XmlObject
> map
) {
118 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
119 SurfaceAreaQuery
.map
= map
;
123 * Push current used Surface Area document into query stack. The given new
124 * document will be used for any immediately followed getXXX() callings,
125 * untill pop() is called.
128 * The TopLevelElementName/XmlObject format of a Surface Area
131 public static void push(Map
<String
, XmlObject
> newMap
) {
132 mapStack
.push(SurfaceAreaQuery
.map
);
133 SurfaceAreaQuery
.map
= newMap
;
137 * Discard current used Surface Area document and use the top document in
140 public static void pop() {
141 SurfaceAreaQuery
.map
= mapStack
.pop();
145 // / Convert xPath to be namespace qualified, which is necessary for
147 // / selectPath(). For example, converting /MsaHeader/ModuleType to
148 // / /ns:MsaHeader/ns:ModuleType
150 private static String
normalizeQueryString(String
[] exp
, String from
) {
151 StringBuffer normQueryString
= new StringBuffer(4096);
154 while (i
< exp
.length
) {
155 String newExp
= from
+ exp
[i
];
156 Pattern pattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
157 Matcher matcher
= pattern
.matcher(newExp
);
159 while (matcher
.find()) {
160 String starter
= newExp
.substring(matcher
.start(1), matcher
162 String seperator
= newExp
.substring(matcher
.start(2), matcher
164 String token
= newExp
.substring(matcher
.start(3), matcher
167 normQueryString
.append(starter
);
168 normQueryString
.append(seperator
);
169 normQueryString
.append(nsPrefix
);
170 normQueryString
.append(":");
171 normQueryString
.append(token
);
175 if (i
< exp
.length
) {
176 normQueryString
.append(" | ");
180 return normQueryString
.toString();
184 * Search all XML documents stored in "map" for the specified xPath, using
185 * relative path (starting with '$this')
188 * xpath query string array
189 * @returns An array of XmlObject if elements are found at the specified
191 * @returns NULL if nothing is at the specified xpath
193 public static Object
[] get(String
[] xPath
) {
198 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
199 List
<Object
> result
= new ArrayList
<Object
>();
200 for (int i
= 0; i
< keys
.length
; ++i
) {
201 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
202 if (rootNode
== null) {
206 String query
= queryDeclaration
207 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
208 XmlObject
[] tmp
= rootNode
.selectPath(query
);
209 for (int j
= 0; j
< tmp
.length
; ++j
) {
210 result
.add((Object
)tmp
[j
]);
214 int size
= result
.size();
219 return (Object
[]) result
.toArray(new Object
[size
]);
223 * Search XML documents named by "rootName" for the given xPath, using
224 * relative path (starting with '$this')
227 * The top level element name
229 * The xpath query string array
230 * @returns An array of XmlObject if elements are found at the given xpath
231 * @returns NULL if nothing is found at the given xpath
233 public static Object
[] get(String rootName
, String
[] xPath
) {
238 XmlObject root
= (XmlObject
) map
.get(rootName
);
243 String query
= queryDeclaration
244 + normalizeQueryString(xPath
, "$this/" + rootName
);
245 XmlObject
[] result
= root
.selectPath(query
);
246 if (result
.length
> 0) {
247 return (Object
[])result
;
250 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
251 result
= root
.selectPath(query
);
252 if (result
.length
> 0) {
253 return (Object
[])result
;
260 * Retrieve SourceFiles/Filename for specified ARCH type
264 * @returns An 2 dimension string array if elements are found at the known
266 * @returns NULL if nothing is found at the known xpath
268 public static String
[][] getSourceFiles(String arch
) {
272 xPath
= new String
[] { "/Filename" };
274 returns
= get("SourceFiles", xPath
);
276 if (returns
== null || returns
.length
== 0) {
277 return new String
[0][0];
280 Filename
[] sourceFileNames
= (Filename
[]) returns
;
281 List
<String
[]> outputList
= new ArrayList
<String
[]>();
282 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
283 List archList
= sourceFileNames
[i
].getSupArchList();
284 if (arch
== null || arch
.equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
285 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(),sourceFileNames
[i
].getStringValue()});
289 String
[][] outputString
= new String
[outputList
.size()][2];
290 for (int index
= 0; index
< outputList
.size(); index
++) {
291 outputString
[index
][0] = outputList
.get(index
)[0];
292 outputString
[index
][1] = outputList
.get(index
)[1];
298 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
300 * @returns Directory names array if elements are found at the known xpath
301 * @returns Empty if nothing is found at the known xpath
303 public static String
getFpdOutputDirectory() {
304 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
306 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
307 if (returns
== null || returns
.length
== 0) {
310 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
311 return item
.getOutputDirectory();
314 public static String
getFpdIntermediateDirectories() {
315 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
317 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
318 if (returns
== null || returns
.length
== 0) {
321 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
322 if(item
.getIntermediateDirectories() == null) {
326 return item
.getIntermediateDirectories().toString();
330 public static String
getModuleFfsKeyword() {
331 String
[] xPath
= new String
[] { "/" };
333 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
334 if (returns
== null || returns
.length
== 0) {
337 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
338 return item
.getFfsFormatKey();
341 public static String
getModuleFvBindingKeyword() {
342 String
[] xPath
= new String
[] { "/" };
344 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
345 if (returns
== null || returns
.length
== 0) {
348 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
349 return item
.getFvBinding();
352 public static List
getModuleSupportedArchs() {
353 String
[] xPath
= new String
[] { "/" };
355 Object
[] returns
= get("ModuleDefinitions", xPath
);
356 if (returns
== null || returns
.length
== 0) {
359 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
360 return item
.getSupportedArchitectures();
363 public static BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
364 String
[] xPath
= new String
[] {"/Ffs"};
366 Object
[] returns
= get("BuildOptions", xPath
);
367 if (returns
== null || returns
.length
== 0) {
368 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
370 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
373 public static String
getModuleOutputFileBasename() {
374 String
[] xPath
= new String
[] { "/" };
376 Object
[] returns
= get("ModuleDefinitions", xPath
);
377 if (returns
== null || returns
.length
== 0) {
380 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
381 return item
.getOutputFileBasename();
385 * Retrieve BuildOptions/Option or Arch/Option
387 * @param toolChainFamilyFlag
388 * if true, retrieve options for toolchain family; otherwise for
391 * @returns String[][5] name, target, toolchain, arch, coommand of options
392 * if elements are found at the known xpath. String[0][] if dont
395 * @returns Empty array if nothing is there
397 public static String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
398 String target
= null;
399 String toolchain
= null;
400 String toolchainFamily
= null;
401 List
<String
> archList
= null;
403 String optionName
= null;
405 Object
[] returns
= get(from
, xPath
);
406 if (returns
== null) {
407 return new String
[0][5];
410 List
<String
[]> optionList
= new ArrayList
<String
[]>();
411 OptionDocument
.Option option
;
413 for (int i
= 0; i
< returns
.length
; i
++) {
414 option
= (OptionDocument
.Option
) returns
[i
];
417 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
419 // put to result[][5] array in above order.
422 if (option
.getBuildTargets() == null) {
426 target
= option
.getBuildTargets().toString();
428 if (target
!= null) {
429 targetList
= target
.split(" ");
431 targetList
= new String
[1];
432 targetList
[0] = null;
435 if (toolChainFamilyFlag
) {
436 toolchainFamily
= option
.getToolChainFamily();
437 if (toolchainFamily
!= null) {
438 toolchain
= toolchainFamily
.toString();
443 toolchain
= option
.getTagName();
446 archList
= new ArrayList
<String
>();
447 List archEnumList
= option
.getSupArchList();
448 if (archEnumList
== null) {
451 //archList.addAll(archEnumList);
452 Iterator it
= archEnumList
.iterator();
453 while (it
.hasNext()) {
454 String archType
= (String
)it
.next();
455 archList
.add(archType
);
459 cmd
= option
.getToolCode();
461 optionName
= option
.getStringValue();
462 for (int t
= 0; t
< targetList
.length
; t
++) {
463 for (int j
= 0; j
< archList
.size(); j
++) {
464 optionList
.add(new String
[] { targetList
[t
],
465 toolchain
, archList
.get(j
), cmd
, optionName
});
470 String
[][] result
= new String
[optionList
.size()][5];
471 for (int i
= 0; i
< optionList
.size(); i
++) {
472 result
[i
][0] = optionList
.get(i
)[0];
473 result
[i
][1] = optionList
.get(i
)[1];
474 result
[i
][2] = optionList
.get(i
)[2];
475 result
[i
][3] = optionList
.get(i
)[3];
476 result
[i
][4] = optionList
.get(i
)[4];
481 public static String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
484 if (toolChainFamilyFlag
== true) {
485 xPath
= new String
[] {
486 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
487 "/Options/Option[@ToolChainFamily]", };
489 xPath
= new String
[] {
490 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
491 "/Options/Option[@TagName]", };
493 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
496 public static String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
499 if (toolChainFamilyFlag
== true) {
500 xPath
= new String
[] {
501 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
502 "/BuildOptions/Options/Option[@ToolChainFamily]", };
504 xPath
= new String
[] {
505 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
506 "/BuildOptions/Options/Option[@TagName]", };
509 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
512 public static ToolChainInfo
getFpdToolChainInfo() {
513 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
515 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
516 if (returns
== null || returns
.length
== 0) {
520 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
521 ToolChainInfo toolChainInfo
= new ToolChainInfo();
522 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
523 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
524 toolChainInfo
.addTagnames((String
)null);
525 return toolChainInfo
;
529 * Retrieve <xxxHeader>/ModuleType
531 * @returns The module type name if elements are found at the known xpath
532 * @returns null if nothing is there
534 public static String
getModuleType() {
535 String
[] xPath
= new String
[] { "/ModuleType" };
537 Object
[] returns
= get(xPath
);
538 if (returns
!= null && returns
.length
> 0) {
539 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
540 return type
.enumValue().toString();
547 * Retrieve PackageDependencies/Package
552 * @returns package name list if elements are found at the known xpath
553 * @returns null if nothing is there
555 public static PackageIdentification
[] getDependencePkg(String arch
) {
557 String packageGuid
= null;
558 String packageVersion
= null;
561 xPath
= new String
[] { "/Package" };
563 Object
[] returns
= get("PackageDependencies", xPath
);
564 if (returns
== null) {
565 return new PackageIdentification
[0];
569 // Get packageIdentification
571 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
572 for (int i
= 0; i
< returns
.length
; i
++) {
573 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
574 List archList
= item
.getSupArchList();
575 if (arch
== null || archList
== null || contains(archList
, arch
)) {
576 packageGuid
= item
.getPackageGuid();
577 packageVersion
= item
.getPackageVersion();
578 packageIdList
.add(new PackageIdentification(null, packageGuid
,
584 // transfer packageIdentification list to array.
586 PackageIdentification
[] packageIdArray
= new PackageIdentification
[packageIdList
.size()];
587 for (int i
= 0; i
< packageIdList
.size(); i
++) {
588 packageIdArray
[i
] = new PackageIdentification(null, packageIdList
.get(i
).getGuid(),packageIdList
.get(i
).getVersion());
590 return packageIdArray
;
594 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
597 * Library class usage
599 * @returns LibraryClass objects list if elements are found at the known
601 * @returns null if nothing is there
603 public static String
[] getLibraryClasses(String usage
, String arch
) {
605 if (usage
== null || usage
.equals("")) {
606 xPath
= new String
[] { "/LibraryClass" };
608 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
611 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
612 if (returns
== null || returns
.length
== 0) {
613 return new String
[0];
616 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
617 List
<String
> libraryClassName
= new ArrayList
<String
>();
618 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
619 List archList
= libraryClassList
[i
].getSupArchList();
621 if (arch
== null || contains(archList
, arch
)) {
622 libraryClassName
.add(libraryClassList
[i
].getKeyword());
625 String
[] libraryArray
= new String
[libraryClassName
.size()];
626 for (int i
= 0; i
< libraryClassName
.size(); i
++) {
627 libraryArray
[i
] = libraryClassName
.get(i
);
633 * Retrieve ModuleEntryPoint names
635 * @returns ModuleEntryPoint name list if elements are found at the known
637 * @returns null if nothing is there
639 public static String
[] getModuleEntryPointArray() {
640 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
642 Object
[] returns
= get("Externs", xPath
);
644 if (returns
!= null && returns
.length
> 0) {
645 String
[] entryPoints
= new String
[returns
.length
];
647 for (int i
= 0; i
< returns
.length
; ++i
) {
648 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
658 * retrieve Protocol for specified usage
661 * Protocol usage arch Architecture
663 * @returns Protocol String list if elements are found at the known xpath
664 * @returns String[0] if nothing is there
666 public static String
[] getProtocolArray(String arch
, String usage
) {
668 String usageXpath
= "";
669 String archXpath
= "";
671 if (arch
== null || arch
.equals("")) {
672 return new String
[0];
674 archXpath
= "/Protocol";
675 if (usage
!= null && !usage
.equals("")) {
676 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
677 xPath
= new String
[] { usageXpath
, archXpath
};
679 return getProtocolArray(arch
);
684 Object
[] returns
= get("Protocols", xPath
);
685 if (returns
== null) {
686 return new String
[0];
688 Protocol
[] protocolList
= (Protocol
[]) returns
;
690 String
[] protocolArray
= new String
[returns
.length
];
691 for (int i
= 0; i
< returns
.length
; i
++) {
692 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
694 return protocolArray
;
698 * retrieve Protocol for specified usage
703 * @returns Protocol String list if elements are found at the known xpath
704 * @returns String[0] if nothing is there
706 public static String
[] getProtocolArray(String arch
) {
709 if (arch
== null || arch
.equals("")) {
710 return new String
[0];
712 xPath
= new String
[] { "/Protocol" };
715 Object
[] returns
= get("Protocols", xPath
);
716 if (returns
== null) {
717 return new String
[0];
719 Protocol
[] returnlList
= (Protocol
[]) returns
;
721 List
<String
> protocolList
= new ArrayList
<String
>();
723 for (int i
= 0; i
< returns
.length
; i
++) {
724 List archList
= returnlList
[i
].getSupArchList();
725 if (archList
== null || contains(archList
, arch
)){
726 protocolList
.add(returnlList
[i
].getProtocolCName());
729 String
[] protocolArray
= new String
[protocolList
.size()];
730 for (int i
= 0; i
< protocolList
.size(); i
++) {
731 protocolArray
[i
] = protocolList
.get(i
);
733 return protocolArray
;
737 * Retrieve ProtocolNotify for specified usage
740 * ProtocolNotify usage
742 * @returns String[] if elements are found at the known xpath
743 * @returns String[0] if nothing is there
745 public static String
[] getProtocolNotifyArray(String arch
) {
748 if (arch
== null || arch
.equals("")) {
749 return new String
[0];
751 xPath
= new String
[] { "/ProtocolNotify" };
754 Object
[] returns
= get("Protocols", xPath
);
755 if (returns
== null) {
756 return new String
[0];
759 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
761 for (int i
= 0; i
< returns
.length
; i
++) {
762 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
763 if (archList
== null || contains(archList
, arch
)){
764 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
768 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
769 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
770 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
772 return protocolNotifyArray
;
776 * Retrieve ProtocolNotify for specified usage
779 * ProtocolNotify usage
781 * @returns String[] if elements are found at the known xpath
782 * @returns String[0] if nothing is there
784 public static String
[] getProtocolNotifyArray(String arch
, String usage
) {
790 if (arch
== null || arch
.equals("")) {
791 return new String
[0];
793 archXpath
= "/ProtocolNotify";
794 if (usage
!= null && !usage
.equals("")) {
795 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
796 xPath
= new String
[] { archXpath
, usageXpath
};
798 return getProtocolNotifyArray(arch
);
802 Object
[] returns
= get("Protocols", xPath
);
803 if (returns
== null) {
804 return new String
[0];
807 String
[] protocolNotifyList
= new String
[returns
.length
];
809 for (int i
= 0; i
< returns
.length
; i
++) {
810 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
812 return protocolNotifyList
;
816 * Retrieve ModuleUnloadImage names
818 * @returns ModuleUnloadImage name list if elements are found at the known
820 * @returns null if nothing is there
822 public static String
[] getModuleUnloadImageArray() {
823 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
825 Object
[] returns
= get("Externs", xPath
);
826 if (returns
!= null && returns
.length
> 0) {
827 String
[] stringArray
= new String
[returns
.length
];
828 CNameType
[] doc
= (CNameType
[]) returns
;
830 for (int i
= 0; i
< returns
.length
; ++i
) {
831 stringArray
[i
] = doc
[i
].getStringValue();
843 * @returns Extern objects list if elements are found at the known xpath
844 * @returns null if nothing is there
846 public static ExternsDocument
.Externs
.Extern
[] getExternArray() {
847 String
[] xPath
= new String
[] { "/Extern" };
849 Object
[] returns
= get("Externs", xPath
);
850 if (returns
!= null && returns
.length
> 0) {
851 return (ExternsDocument
.Externs
.Extern
[]) returns
;
858 * Retrieve PpiNotify for specified arch
863 * @returns String[] if elements are found at the known xpath
864 * @returns String[0] if nothing is there
866 public static String
[] getPpiNotifyArray(String arch
) {
869 if (arch
== null || arch
.equals("")) {
870 return new String
[0];
872 xPath
= new String
[] { "/PpiNotify" };
875 Object
[] returns
= get("PPIs", xPath
);
876 if (returns
== null) {
877 return new String
[0];
881 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
882 for (int i
= 0; i
< returns
.length
; i
++) {
883 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
884 if (archList
== null || contains(archList
, arch
)){
885 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
889 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
890 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
891 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
894 return ppiNotifyArray
;
898 * Retrieve PpiNotify for specified usage and arch
901 * PpiNotify arch usage PpiNotify usage
904 * @returns String[] if elements are found at the known xpath
905 * @returns String[0] if nothing is there
907 public static String
[] getPpiNotifyArray(String arch
, String usage
) {
913 if (arch
== null || arch
.equals("")) {
914 return new String
[0];
916 archXpath
= "/PpiNotify";
917 if (usage
!= null && !usage
.equals("")) {
918 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
919 xPath
= new String
[] { archXpath
, usageXpath
};
921 return getProtocolNotifyArray(arch
);
925 Object
[] returns
= get("PPIs", xPath
);
926 if (returns
== null) {
927 return new String
[0];
930 String
[] ppiNotifyList
= new String
[returns
.length
];
932 for (int i
= 0; i
< returns
.length
; i
++) {
933 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
935 return ppiNotifyList
;
939 * Retrieve Ppi for specified arch
944 * @returns String[] if elements are found at the known xpath
945 * @returns String[0] if nothing is there
947 public static String
[] getPpiArray(String arch
) {
950 if (arch
== null || arch
.equals("")) {
951 return new String
[0];
953 xPath
= new String
[] { "/Ppi" };
956 Object
[] returns
= get("PPIs", xPath
);
957 if (returns
== null) {
958 return new String
[0];
961 List
<String
> ppiList
= new ArrayList
<String
>();
962 for (int i
= 0; i
< returns
.length
; i
++) {
963 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
964 if (archList
== null || contains(archList
, arch
)){
965 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
969 String
[] ppiArray
= new String
[ppiList
.size()];
970 for (int i
= 0; i
< ppiList
.size(); i
++) {
971 ppiArray
[i
] = ppiList
.get(i
);
977 * Retrieve PpiNotify for specified usage and arch
980 * PpiNotify arch usage PpiNotify usage
983 * @returns String[] if elements are found at the known xpath
984 * @returns String[0] if nothing is there
986 public static String
[] getPpiArray(String arch
, String usage
) {
992 if (arch
== null || arch
.equals("")) {
993 return new String
[0];
996 if (usage
!= null && !usage
.equals("")) {
997 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
998 xPath
= new String
[] { archXpath
, usageXpath
};
1000 return getProtocolNotifyArray(arch
);
1004 Object
[] returns
= get("PPIs", xPath
);
1005 if (returns
== null) {
1006 return new String
[0];
1009 String
[] ppiList
= new String
[returns
.length
];
1011 for (int i
= 0; i
< returns
.length
; i
++) {
1012 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1018 * Retrieve GuidEntry information for specified usage
1023 * @returns GuidEntry objects list if elements are found at the known xpath
1024 * @returns null if nothing is there
1026 public static String
[] getGuidEntryArray(String arch
) {
1029 if (arch
== null || arch
.equals("")) {
1030 xPath
= new String
[] { "/GuidCNames" };
1032 xPath
= new String
[] { "/GuidCNames" };
1035 Object
[] returns
= get("Guids", xPath
);
1036 if (returns
== null) {
1037 return new String
[0];
1040 List
<String
> guidList
= new ArrayList
<String
>();
1041 for (int i
= 0; i
< returns
.length
; i
++) {
1042 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1043 if (archList
== null || contains(archList
, arch
)){
1044 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1048 String
[] guidArray
= new String
[guidList
.size()];
1049 for (int i
= 0; i
< guidList
.size(); i
++) {
1050 guidArray
[i
] = guidList
.get(i
);
1057 * Retrieve GuidEntry information for specified usage
1060 * GuidEntry arch usage GuidEntry usage
1062 * @returns GuidEntry objects list if elements are found at the known xpath
1063 * @returns null if nothing is there
1065 public static String
[] getGuidEntryArray(String arch
, String usage
) {
1070 if (arch
== null || arch
.equals("")) {
1071 return new String
[0];
1073 archXpath
= "/GuidEntry";
1074 if (usage
!= null && !usage
.equals("")) {
1075 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1076 xPath
= new String
[] { archXpath
, usageXpath
};
1078 return getProtocolNotifyArray(arch
);
1082 Object
[] returns
= get("Guids", xPath
);
1083 if (returns
== null) {
1084 return new String
[0];
1087 String
[] guidList
= new String
[returns
.length
];
1089 for (int i
= 0; i
< returns
.length
; i
++) {
1090 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1096 * Retrieve Library instance information
1101 * Library instance usage
1103 * @returns library instance name list if elements are found at the known
1105 * @returns null if nothing is there
1107 public static ModuleIdentification
[] getLibraryInstance(String arch
) {
1109 String saGuid
= null;
1110 String saVersion
= null;
1111 String pkgGuid
= null;
1112 String pkgVersion
= null;
1114 if (arch
== null || arch
.equalsIgnoreCase("")) {
1115 xPath
= new String
[] { "/Instance" };
1118 // Since Schema don't have SupArchList now, so the follow Xpath is
1119 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1120 // don't have effect.
1122 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1126 Object
[] returns
= get("Libraries", xPath
);
1127 if (returns
== null || returns
.length
== 0) {
1128 return new ModuleIdentification
[0];
1131 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1132 for (int i
= 0; i
< returns
.length
; i
++) {
1133 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1134 saGuid
= library
.getModuleGuid();
1135 saVersion
= library
.getModuleVersion();
1137 pkgGuid
= library
.getPackageGuid();
1138 pkgVersion
= library
.getPackageVersion();
1140 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1142 PackageIdentification pkgId
= new PackageIdentification(null,
1143 pkgGuid
, pkgVersion
);
1144 saId
.setPackage(pkgId
);
1153 // / This method is used for retrieving the elements information which has
1154 // / CName sub-element
1156 private static String
[] getCNames(String from
, String xPath
[]) {
1157 Object
[] returns
= get(from
, xPath
);
1158 if (returns
== null || returns
.length
== 0) {
1162 String
[] strings
= new String
[returns
.length
];
1163 for (int i
= 0; i
< returns
.length
; ++i
) {
1165 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1172 * Retrive library's constructor name
1174 * @returns constructor name list if elements are found at the known xpath
1175 * @returns null if nothing is there
1177 public static String
getLibConstructorName() {
1178 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1180 Object
[] returns
= get("Externs", xPath
);
1181 if (returns
!= null && returns
.length
> 0) {
1182 CNameType constructor
= ((CNameType
) returns
[0]);
1183 return constructor
.getStringValue();
1190 * Retrive library's destructor name
1192 * @returns destructor name list if elements are found at the known xpath
1193 * @returns null if nothing is there
1195 public static String
getLibDestructorName() {
1196 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1198 Object
[] returns
= get("Externs", xPath
);
1199 if (returns
!= null && returns
.length
> 0) {
1201 // Only support one Destructor function.
1203 CNameType destructor
= (CNameType
) returns
[0];
1204 return destructor
.getStringValue();
1211 * Retrive DriverBinding names
1213 * @returns DriverBinding name list if elements are found at the known xpath
1214 * @returns null if nothing is there
1216 public static String
[] getDriverBindingArray() {
1217 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1218 return getCNames("Externs", xPath
);
1222 * Retrive ComponentName names
1224 * @returns ComponentName name list if elements are found at the known xpath
1225 * @returns null if nothing is there
1227 public static String
[] getComponentNameArray() {
1228 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1229 return getCNames("Externs", xPath
);
1233 * Retrive DriverConfig names
1235 * @returns DriverConfig name list if elements are found at the known xpath
1236 * @returns null if nothing is there
1238 public static String
[] getDriverConfigArray() {
1239 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1240 return getCNames("Externs", xPath
);
1244 * Retrive DriverDiag names
1246 * @returns DriverDiag name list if elements are found at the known xpath
1247 * @returns null if nothing is there
1249 public static String
[] getDriverDiagArray() {
1250 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1251 return getCNames("Externs", xPath
);
1255 * Retrive SetVirtualAddressMapCallBack names
1257 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1259 * @returns null if nothing is there
1261 public static String
[] getSetVirtualAddressMapCallBackArray() {
1262 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1263 return getCNames("Externs", xPath
);
1267 * Retrive ExitBootServicesCallBack names
1269 * @returns ExitBootServicesCallBack name list if elements are found at the
1271 * @returns null if nothing is there
1273 public static String
[] getExitBootServicesCallBackArray() {
1274 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1275 return getCNames("Externs", xPath
);
1279 * Retrieve module surface area file information
1281 * @returns ModuleSA objects list if elements are found at the known xpath
1282 * @returns Empty ModuleSA list if nothing is there
1284 public static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() {
1285 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1286 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1288 String fvBinding
= null;
1289 String saGuid
= null;
1290 String saVersion
= null;
1291 String pkgGuid
= null;
1292 String pkgVersion
= null;
1294 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1296 if (result
== null) {
1297 return fpdModuleMap
;
1300 for (int i
= 0; i
< result
.length
; i
++) {
1302 // Get Fpd SA Module element node and add to ObjectMap.
1304 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1305 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1306 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1307 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1309 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1310 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1312 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1313 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1317 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1319 if (moduleSA
.isSetSupArchList()) {
1320 arch
= moduleSA
.getSupArchList().toString();
1327 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1329 saGuid
= moduleSA
.getModuleGuid();
1330 pkgGuid
= moduleSA
.getPackageGuid();
1331 pkgVersion
= moduleSA
.getPackageVersion();
1334 // Create Module Identification which have class member of package
1337 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1338 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1340 saId
.setPackage(pkgId
);
1343 // Create FpdModule Identification which have class member of module
1346 String
[] archList
= new String
[0];
1347 if (arch
== null || arch
.trim().length() == 0) {
1348 archList
= GlobalData
.getToolChainInfo().getArchs();
1350 archList
= arch
.split(" ");
1352 for (int j
= 0; j
< archList
.length
; j
++) {
1353 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1355 if (fvBinding
!= null) {
1356 fpdSaId
.setFvBinding(fvBinding
);
1360 // Put element to Map<FpdModuleIdentification, Map<String,
1363 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1366 return fpdModuleMap
;
1370 * Retrieve valid image names
1372 * @returns valid iamges name list if elements are found at the known xpath
1373 * @returns empty list if nothing is there
1375 public static String
[] getFpdValidImageNames() {
1376 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1378 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1379 if (queryResult
== null) {
1380 return new String
[0];
1383 String
[] result
= new String
[queryResult
.length
];
1384 for (int i
= 0; i
< queryResult
.length
; i
++) {
1385 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1391 public static Node
getFpdUserExtensionPreBuild() {
1392 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1394 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1395 if (queryResult
== null || queryResult
.length
== 0) {
1398 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1400 return a
.getDomNode();
1403 public static Node
getFpdUserExtensionPostBuild() {
1404 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1406 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1407 if (queryResult
== null || queryResult
.length
== 0) {
1410 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1412 return a
.getDomNode();
1416 * Retrieve FV image option information
1421 * @returns option name/value list if elements are found at the known xpath
1422 * @returns empty list if nothing is there
1424 public static String
[][] getFpdOptions(String fvName
) {
1425 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1426 + fvName
+ "']/FvImageOptions" };
1427 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1428 if (queryResult
== null) {
1429 return new String
[0][];
1431 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1432 for (int i
= 0; i
< queryResult
.length
; i
++) {
1433 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1434 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1435 .getNameValueList();
1436 Iterator iter
= namevalues
.iterator();
1437 while (iter
.hasNext()) {
1438 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1440 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1443 String
[][] result
= new String
[list
.size()][2];
1444 for (int i
= 0; i
< list
.size(); i
++) {
1445 result
[i
][0] = list
.get(i
)[0];
1446 result
[i
][1] = list
.get(i
)[1];
1452 public static XmlObject
getFpdBuildOptions() {
1453 String
[] xPath
= new String
[] { "/BuildOptions" };
1455 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1457 if (queryResult
== null || queryResult
.length
== 0) {
1460 return (XmlObject
)queryResult
[0];
1463 public static PlatformIdentification
getFpdHeader() {
1464 String
[] xPath
= new String
[] { "/PlatformHeader" };
1466 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1468 if (returns
== null || returns
.length
== 0) {
1471 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1473 String name
= header
.getPlatformName();
1475 String guid
= header
.getGuidValue();
1477 String version
= header
.getVersion();
1479 return new PlatformIdentification(name
, guid
, version
);
1483 * Retrieve FV image attributes information
1488 * @returns attribute name/value list if elements are found at the known
1490 * @returns empty list if nothing is there
1492 public static String
[][] getFpdAttributes(String fvName
) {
1493 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1494 + fvName
+ "']/FvImageOptions" };
1495 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1496 if (queryResult
== null) {
1497 return new String
[0][];
1499 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1500 for (int i
= 0; i
< queryResult
.length
; i
++) {
1502 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1503 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1504 Iterator iter
= namevalues
.iterator();
1505 while (iter
.hasNext()) {
1506 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1508 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1511 String
[][] result
= new String
[list
.size()][2];
1512 for (int i
= 0; i
< list
.size(); i
++) {
1513 result
[i
][0] = list
.get(i
)[0];
1514 result
[i
][1] = list
.get(i
)[1];
1520 * Retrieve flash definition file name
1522 * @returns file name if elements are found at the known xpath
1523 * @returns null if nothing is there
1525 public static String
getFlashDefinitionFile() {
1526 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1528 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1529 if (queryResult
== null || queryResult
.length
== 0) {
1533 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1534 return filename
.getStringValue();
1537 public static String
[][] getFpdGlobalVariable() {
1538 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1539 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1540 if (queryResult
== null) {
1541 return new String
[0][];
1544 String
[][] result
= new String
[queryResult
.length
][2];
1546 for (int i
= 0; i
< queryResult
.length
; i
++) {
1547 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1548 result
[i
][0] = item
.getName();
1549 result
[i
][1] = item
.getValue();
1555 * Retrieve FV image component options
1560 * @returns name/value pairs list if elements are found at the known xpath
1561 * @returns empty list if nothing is there
1563 public static String
[][] getFpdComponents(String fvName
) {
1564 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1565 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1566 if (queryResult
== null) {
1567 return new String
[0][];
1570 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1571 for (int i
= 0; i
< queryResult
.length
; i
++) {
1572 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1573 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1574 Iterator iter
= namevalues
.iterator();
1575 while (iter
.hasNext()) {
1576 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1578 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1581 String
[][] result
= new String
[list
.size()][2];
1582 for (int i
= 0; i
< list
.size(); i
++) {
1583 result
[i
][0] = list
.get(i
)[0];
1584 result
[i
][1] = list
.get(i
)[1];
1590 * Retrieve PCD tokens
1592 * @returns CName/ItemType pairs list if elements are found at the known
1594 * @returns null if nothing is there
1596 public static String
[][] getPcdTokenArray() {
1597 String
[] xPath
= new String
[] { "/PcdData" };
1599 Object
[] returns
= get("PCDs", xPath
);
1600 if (returns
== null || returns
.length
== 0) {
1608 * Retrieve MAS header
1613 public static ModuleIdentification
getMsaHeader() {
1614 String
[] xPath
= new String
[] { "/" };
1615 Object
[] returns
= get("MsaHeader", xPath
);
1617 if (returns
== null || returns
.length
== 0) {
1621 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1623 // Get BaseName, ModuleType, GuidValue, Version
1624 // which in MsaHeader.
1626 String name
= msaHeader
.getModuleName();
1627 String moduleType
= msaHeader
.getModuleType().toString();
1628 String guid
= msaHeader
.getGuidValue();
1629 String version
= msaHeader
.getVersion();
1631 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1634 moduleId
.setModuleType(moduleType
);
1640 * Retrieve Extern Specification
1644 * @return String[] If have specification element in the <extern> String[0]
1645 * If no specification element in the <extern>
1649 public static String
[] getExternSpecificaiton() {
1650 String
[] xPath
= new String
[] { "/Specification" };
1652 Object
[] queryResult
= get("Externs", xPath
);
1653 if (queryResult
== null) {
1654 return new String
[0];
1657 String
[] specificationList
= new String
[queryResult
.length
];
1658 for (int i
= 0; i
< queryResult
.length
; i
++) {
1659 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1662 return specificationList
;
1666 * Retreive MsaFile which in SPD
1669 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1670 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1672 public static String
[] getSpdMsaFile() {
1673 String
[] xPath
= new String
[] { "/MsaFiles" };
1675 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1676 if (returns
== null) {
1677 return new String
[0];
1680 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1682 return filenameList
.toArray(new String
[filenameList
.size()]);
1688 public static Map
<String
, String
[]> getSpdLibraryClasses() {
1689 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1691 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1694 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1696 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1698 if (returns
== null) {
1699 return libClassHeaderMap
;
1702 for (int i
= 0; i
< returns
.length
; i
++) {
1703 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1704 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1705 .getIncludeHeader() });
1707 return libClassHeaderMap
;
1713 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1714 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1716 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1719 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1721 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1723 if (returns
== null) {
1724 return packageIncludeMap
;
1727 for (int i
= 0; i
< returns
.length
; i
++) {
1728 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1729 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1730 includeHeader
.getStringValue());
1732 return packageIncludeMap
;
1735 public static PackageIdentification
getSpdHeader() {
1736 String
[] xPath
= new String
[] { "/SpdHeader" };
1738 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1740 if (returns
== null || returns
.length
== 0) {
1744 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1746 String name
= header
.getPackageName();
1748 String guid
= header
.getGuidValue();
1750 String version
= header
.getVersion();
1752 return new PackageIdentification(name
, guid
, version
);
1758 public static Map
<String
, String
[]> getSpdGuid() {
1759 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1761 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1764 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1766 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1767 if (returns
== null) {
1771 for (int i
= 0; i
< returns
.length
; i
++) {
1772 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1773 String
[] guidPair
= new String
[2];
1774 guidPair
[0] = entry
.getCName();
1775 guidPair
[1] = entry
.getGuidValue();
1776 guidDeclMap
.put(entry
.getCName(), guidPair
);
1777 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1778 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[0]);
1779 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[1]);
1787 public static Map
<String
, String
[]> getSpdProtocol() {
1788 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1790 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1793 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1795 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1797 if (returns
== null) {
1801 for (int i
= 0; i
< returns
.length
; i
++) {
1802 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1803 String
[] protocolPair
= new String
[2];
1805 protocolPair
[0] = entry
.getCName();
1806 protocolPair
[1] = entry
.getGuidValue();
1807 protoclMap
.put(entry
.getCName(), protocolPair
);
1808 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1809 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[0]);
1810 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[1]);
1816 * getSpdPpi() Retrieve the SPD PPI Entry
1819 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1820 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1823 public static Map
<String
, String
[]> getSpdPpi() {
1824 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1826 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1829 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1831 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1833 if (returns
== null) {
1837 for (int i
= 0; i
< returns
.length
; i
++) {
1838 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1839 String
[] ppiPair
= new String
[2];
1840 ppiPair
[0] = entry
.getCName();
1841 ppiPair
[1] = entry
.getGuidValue();
1842 ppiMap
.put(entry
.getCName(), ppiPair
);
1848 * Retrieve module Guid string
1850 * @returns GUILD string if elements are found at the known xpath
1851 * @returns null if nothing is there
1853 public static String
getModuleGuid() {
1854 String
[] xPath
= new String
[] { "" };
1856 Object
[] returns
= get("MsaHeader", xPath
);
1857 if (returns
!= null && returns
.length
> 0) {
1858 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1869 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1870 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1871 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1872 if (result
!= null) {
1873 return (ModuleSADocument
.ModuleSA
[]) result
;
1875 return new ModuleSADocument
.ModuleSA
[0];
1879 Get name array of PCD in a module. In one module, token space
1880 is same, and token name should not be conflicted.
1884 public static String
[] getModulePcdEntryNameArray() {
1885 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1888 String
[] xPath
= new String
[] {"/PcdEntry"};
1889 Object
[] returns
= get ("PcdCoded", xPath
);
1891 if (returns
== null) {
1892 return new String
[0];
1895 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1896 results
= new String
[pcdEntries
.length
];
1898 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1899 results
[index
] = pcdEntries
[index
].getCName();
1905 Search in a List for a given string
1909 public static boolean contains(List list
, String str
) {
1910 if (list
== null || list
.size()== 0) {
1913 Iterator it
= list
.iterator();
1914 while (it
.hasNext()) {
1915 String s
= (String
)it
.next();
1916 if (s
.equalsIgnoreCase(str
)) {
1924 public static boolean isHaveTianoR8FlashMap(){
1925 String
[] xPath
= new String
[] {"/"};
1926 Object
[] returns
= get ("Externs", xPath
);
1928 if (returns
== null) {
1932 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
1934 if (ext
.getTianoR8FlashMapH()){