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
.tianocore
.ExternsDocument
.Externs
.Extern
;
27 import org
.apache
.xmlbeans
.XmlObject
;
28 import org
.apache
.xmlbeans
.XmlString
;
29 import org
.tianocore
.*;
30 import org
.tianocore
.ExternsDocument
.Externs
;
31 import org
.tianocore
.FilenameDocument
.Filename
;
32 import org
.tianocore
.ModuleSurfaceAreaDocument
.ModuleSurfaceArea
;
33 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
34 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
35 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
36 import org
.tianocore
.build
.autogen
.CommonDefinition
;
37 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
38 import org
.tianocore
.build
.id
.ModuleIdentification
;
39 import org
.tianocore
.build
.id
.PackageIdentification
;
40 import org
.tianocore
.build
.id
.PlatformIdentification
;
41 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
42 import org
.tianocore
.common
.exception
.EdkException
;
43 import org
.tianocore
.common
.logger
.EdkLog
;
44 import org
.w3c
.dom
.Node
;
47 * SurfaceAreaQuery class is used to query Surface Area information from msa,
48 * mbd, spd and fpd files.
50 * This class should not instantiated. All the public interfaces is static.
54 public class SurfaceAreaQuery
{
56 public String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
59 // Contains name/value pairs of Surface Area document object. The name is
60 // always the top level element name.
62 private Map
<String
, XmlObject
> map
= null;
65 // mapStack is used to do nested query
67 private Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
70 // prefix of name space
72 private String nsPrefix
= "sans";
75 // xmlbeans needs a name space for each Xpath element
77 private String ns
= null;
80 // keep the namep declaration for xmlbeans Xpath query
82 private String queryDeclaration
= null;
84 private StringBuffer normQueryString
= new StringBuffer(4096);
85 private Pattern xPathPattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
88 * Set a Surface Area document for query later
91 * A Surface Area document in TopLevelElementName/XmlObject
94 public SurfaceAreaQuery(Map
<String
, XmlObject
> map
) {
96 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
101 * Push current used Surface Area document into query stack. The given new
102 * document will be used for any immediately followed getXXX() callings,
103 * untill pop() is called.
106 * The TopLevelElementName/XmlObject format of a Surface Area
109 public void push(Map
<String
, XmlObject
> newMap
) {
110 mapStack
.push(this.map
);
115 * Discard current used Surface Area document and use the top document in
119 this.map
= mapStack
.pop();
123 // / Convert xPath to be namespace qualified, which is necessary for
125 // / selectPath(). For example, converting /MsaHeader/ModuleType to
126 // / /ns:MsaHeader/ns:ModuleType
128 private String
normalizeQueryString(String
[] exp
, String from
) {
129 normQueryString
.setLength(0);
132 while (i
< exp
.length
) {
133 String newExp
= from
+ exp
[i
];
134 Matcher matcher
= xPathPattern
.matcher(newExp
);
136 while (matcher
.find()) {
137 String starter
= newExp
.substring(matcher
.start(1), matcher
139 String seperator
= newExp
.substring(matcher
.start(2), matcher
141 String token
= newExp
.substring(matcher
.start(3), matcher
144 normQueryString
.append(starter
);
145 normQueryString
.append(seperator
);
146 normQueryString
.append(nsPrefix
);
147 normQueryString
.append(":");
148 normQueryString
.append(token
);
152 if (i
< exp
.length
) {
153 normQueryString
.append(" | ");
157 return normQueryString
.toString();
161 * Search all XML documents stored in "map" for the specified xPath, using
162 * relative path (starting with '$this')
165 * xpath query string array
166 * @returns An array of XmlObject if elements are found at the specified
168 * @returns NULL if nothing is at the specified xpath
170 public Object
[] get(String
[] xPath
) {
175 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
176 List
<Object
> result
= new ArrayList
<Object
>();
177 for (int i
= 0; i
< keys
.length
; ++i
) {
178 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
179 if (rootNode
== null) {
183 String query
= queryDeclaration
184 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
185 XmlObject
[] tmp
= rootNode
.selectPath(query
);
186 for (int j
= 0; j
< tmp
.length
; ++j
) {
187 result
.add((Object
)tmp
[j
]);
191 int size
= result
.size();
196 return (Object
[]) result
.toArray(new Object
[size
]);
200 * Search XML documents named by "rootName" for the given xPath, using
201 * relative path (starting with '$this')
204 * The top level element name
206 * The xpath query string array
207 * @returns An array of XmlObject if elements are found at the given xpath
208 * @returns NULL if nothing is found at the given xpath
210 public Object
[] get(String rootName
, String
[] xPath
) {
215 XmlObject root
= (XmlObject
) map
.get(rootName
);
220 String query
= queryDeclaration
221 + normalizeQueryString(xPath
, "$this/" + rootName
);
222 XmlObject
[] result
= root
.selectPath(query
);
223 if (result
.length
> 0) {
224 return (Object
[])result
;
227 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
228 result
= root
.selectPath(query
);
229 if (result
.length
> 0) {
230 return (Object
[])result
;
237 * Retrieve SourceFiles/Filename for specified ARCH type
241 * @returns An 2 dimension string array if elements are found at the known
243 * @returns NULL if nothing is found at the known xpath
245 public String
[][] getSourceFiles(String arch
) {
249 xPath
= new String
[] { "/Filename" };
251 returns
= get("SourceFiles", xPath
);
253 if (returns
== null || returns
.length
== 0) {
254 return new String
[0][0];
257 Filename
[] sourceFileNames
= (Filename
[]) returns
;
258 List
<String
[]> outputList
= new ArrayList
<String
[]>();
259 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
260 List archList
= sourceFileNames
[i
].getSupArchList();
261 if (arch
== null || arch
.equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
262 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(),sourceFileNames
[i
].getStringValue()});
266 String
[][] outputString
= new String
[outputList
.size()][2];
267 for (int index
= 0; index
< outputList
.size(); index
++) {
268 outputString
[index
][0] = outputList
.get(index
)[0];
269 outputString
[index
][1] = outputList
.get(index
)[1];
275 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
277 * @returns Directory names array if elements are found at the known xpath
278 * @returns Empty if nothing is found at the known xpath
280 public String
getFpdOutputDirectory() {
281 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
283 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
284 if (returns
== null || returns
.length
== 0) {
287 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
288 return item
.getOutputDirectory();
291 public String
getFpdIntermediateDirectories() {
292 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
294 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
295 if (returns
== null || returns
.length
== 0) {
298 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
299 if(item
.getIntermediateDirectories() == null) {
303 return item
.getIntermediateDirectories().toString();
307 public String
getModuleFfsKeyword() {
308 String
[] xPath
= new String
[] { "/" };
310 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
311 if (returns
== null || returns
.length
== 0) {
314 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
315 return item
.getFfsFormatKey();
318 public String
getModuleFvBindingKeyword() {
319 String
[] xPath
= new String
[] { "/" };
321 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
322 if (returns
== null || returns
.length
== 0) {
325 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
326 return item
.getFvBinding();
329 public List
getModuleSupportedArchs() {
330 String
[] xPath
= new String
[] { "/" };
332 Object
[] returns
= get("ModuleDefinitions", xPath
);
333 if (returns
== null || returns
.length
== 0) {
336 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
337 return item
.getSupportedArchitectures();
340 public BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
341 String
[] xPath
= new String
[] {"/Ffs"};
343 Object
[] returns
= get("BuildOptions", xPath
);
344 if (returns
== null || returns
.length
== 0) {
345 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
347 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
350 public String
getModuleOutputFileBasename() {
351 String
[] xPath
= new String
[] { "/" };
353 Object
[] returns
= get("ModuleDefinitions", xPath
);
354 if (returns
== null || returns
.length
== 0) {
357 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
358 return item
.getOutputFileBasename();
362 * Retrieve BuildOptions/Option or Arch/Option
364 * @param toolChainFamilyFlag
365 * if true, retrieve options for toolchain family; otherwise for
368 * @returns String[][5] name, target, toolchain, arch, coommand of options
369 * if elements are found at the known xpath. String[0][] if dont
372 * @returns Empty array if nothing is there
374 public String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
375 String target
= null;
376 String toolchain
= null;
377 String toolchainFamily
= null;
378 List
<String
> archList
= null;
380 String optionName
= null;
382 Object
[] returns
= get(from
, xPath
);
383 if (returns
== null) {
384 return new String
[0][5];
387 List
<String
[]> optionList
= new ArrayList
<String
[]>();
388 OptionDocument
.Option option
;
390 for (int i
= 0; i
< returns
.length
; i
++) {
391 option
= (OptionDocument
.Option
) returns
[i
];
394 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
396 // put to result[][5] array in above order.
399 if (option
.getBuildTargets() == null) {
403 target
= option
.getBuildTargets().toString();
405 if (target
!= null) {
406 targetList
= target
.split(" ");
408 targetList
= new String
[1];
409 targetList
[0] = null;
412 if (toolChainFamilyFlag
) {
413 toolchainFamily
= option
.getToolChainFamily();
414 if (toolchainFamily
!= null) {
415 toolchain
= toolchainFamily
.toString();
420 toolchain
= option
.getTagName();
423 archList
= new ArrayList
<String
>();
424 List archEnumList
= option
.getSupArchList();
425 if (archEnumList
== null) {
428 //archList.addAll(archEnumList);
429 Iterator it
= archEnumList
.iterator();
430 while (it
.hasNext()) {
431 String archType
= (String
)it
.next();
432 archList
.add(archType
);
436 cmd
= option
.getToolCode();
438 optionName
= option
.getStringValue();
439 for (int t
= 0; t
< targetList
.length
; t
++) {
440 for (int j
= 0; j
< archList
.size(); j
++) {
441 optionList
.add(new String
[] { targetList
[t
],
442 toolchain
, archList
.get(j
), cmd
, optionName
});
447 String
[][] result
= new String
[optionList
.size()][5];
448 for (int i
= 0; i
< optionList
.size(); i
++) {
449 result
[i
][0] = optionList
.get(i
)[0];
450 result
[i
][1] = optionList
.get(i
)[1];
451 result
[i
][2] = optionList
.get(i
)[2];
452 result
[i
][3] = optionList
.get(i
)[3];
453 result
[i
][4] = optionList
.get(i
)[4];
458 public String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
461 if (toolChainFamilyFlag
== true) {
462 xPath
= new String
[] {
463 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
464 "/Options/Option[@ToolChainFamily]", };
466 xPath
= new String
[] {
467 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
468 "/Options/Option[@TagName]", };
470 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
473 public String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
476 if (toolChainFamilyFlag
== true) {
477 xPath
= new String
[] {
478 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
479 "/BuildOptions/Options/Option[@ToolChainFamily]", };
481 xPath
= new String
[] {
482 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
483 "/BuildOptions/Options/Option[@TagName]", };
486 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
489 public ToolChainInfo
getFpdToolChainInfo() {
490 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
492 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
493 if (returns
== null || returns
.length
== 0) {
497 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
498 ToolChainInfo toolChainInfo
= new ToolChainInfo();
499 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
500 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
501 toolChainInfo
.addTagnames((String
)null);
502 return toolChainInfo
;
506 * Retrieve <xxxHeader>/ModuleType
508 * @returns The module type name if elements are found at the known xpath
509 * @returns null if nothing is there
511 public String
getModuleType() {
512 String
[] xPath
= new String
[] { "/ModuleType" };
514 Object
[] returns
= get(xPath
);
515 if (returns
!= null && returns
.length
> 0) {
516 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
517 return type
.enumValue().toString();
524 * Retrieve PackageDependencies/Package
529 * @returns package name list if elements are found at the known xpath
530 * @returns null if nothing is there
532 public PackageIdentification
[] getDependencePkg(String arch
) throws EdkException
{
534 String packageGuid
= null;
535 String packageVersion
= null;
538 xPath
= new String
[] { "/Package" };
540 Object
[] returns
= get("PackageDependencies", xPath
);
541 if (returns
== null) {
542 return new PackageIdentification
[0];
546 // Get packageIdentification
548 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
549 for (int i
= 0; i
< returns
.length
; i
++) {
550 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
551 List archList
= item
.getSupArchList();
552 if (arch
== null || archList
== null || contains(archList
, arch
)) {
553 packageGuid
= item
.getPackageGuid();
554 packageVersion
= item
.getPackageVersion();
555 PackageIdentification pkgId
= new PackageIdentification(null, packageGuid
, packageVersion
);
556 GlobalData
.refreshPackageIdentification(pkgId
);
557 packageIdList
.add(pkgId
);
561 return packageIdList
.toArray(new PackageIdentification
[packageIdList
.size()]);
565 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
568 * Library class usage
570 * @returns LibraryClass objects list if elements are found at the known
572 * @returns null if nothing is there
574 public String
[] getLibraryClasses(String usage
, String arch
) {
576 if (usage
== null || usage
.equals("")) {
577 xPath
= new String
[] { "/LibraryClass" };
579 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
582 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
583 if (returns
== null || returns
.length
== 0) {
584 return new String
[0];
587 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
588 List
<String
> libraryClassName
= new ArrayList
<String
>();
589 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
590 List archList
= libraryClassList
[i
].getSupArchList();
592 if (arch
== null || contains(archList
, arch
)) {
593 libraryClassName
.add(libraryClassList
[i
].getKeyword());
597 String
[] libraryArray
= new String
[libraryClassName
.size()];
598 libraryClassName
.toArray(libraryArray
);
603 * Retrieve ModuleEntryPoint names
605 * @returns ModuleEntryPoint name list if elements are found at the known
607 * @returns null if nothing is there
609 public String
[] getModuleEntryPointArray() {
610 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
612 Object
[] returns
= get("Externs", xPath
);
614 if (returns
!= null && returns
.length
> 0) {
615 String
[] entryPoints
= new String
[returns
.length
];
617 for (int i
= 0; i
< returns
.length
; ++i
) {
618 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
628 * retrieve Protocol for specified usage
631 * Protocol usage arch Architecture
633 * @returns Protocol String list if elements are found at the known xpath
634 * @returns String[0] if nothing is there
636 public String
[] getProtocolArray(String arch
, String usage
) {
638 String usageXpath
= "";
639 String archXpath
= "";
641 if (arch
== null || arch
.equals("")) {
642 return new String
[0];
644 archXpath
= "/Protocol";
645 if (usage
!= null && !usage
.equals("")) {
646 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
647 xPath
= new String
[] { usageXpath
, archXpath
};
649 return getProtocolArray(arch
);
654 Object
[] returns
= get("Protocols", xPath
);
655 if (returns
== null) {
656 return new String
[0];
658 Protocol
[] protocolList
= (Protocol
[]) returns
;
660 String
[] protocolArray
= new String
[returns
.length
];
661 for (int i
= 0; i
< returns
.length
; i
++) {
662 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
664 return protocolArray
;
668 * retrieve Protocol for specified usage
673 * @returns Protocol String list if elements are found at the known xpath
674 * @returns String[0] if nothing is there
676 public String
[] getProtocolArray(String arch
) {
679 if (arch
== null || arch
.equals("")) {
680 return new String
[0];
682 xPath
= new String
[] { "/Protocol" };
685 Object
[] returns
= get("Protocols", xPath
);
686 if (returns
== null) {
687 return new String
[0];
689 Protocol
[] returnlList
= (Protocol
[]) returns
;
691 List
<String
> protocolList
= new ArrayList
<String
>();
693 for (int i
= 0; i
< returns
.length
; i
++) {
694 List archList
= returnlList
[i
].getSupArchList();
695 if (archList
== null || contains(archList
, arch
)){
696 protocolList
.add(returnlList
[i
].getProtocolCName());
699 String
[] protocolArray
= new String
[protocolList
.size()];
700 for (int i
= 0; i
< protocolList
.size(); i
++) {
701 protocolArray
[i
] = protocolList
.get(i
);
703 return protocolArray
;
707 * Retrieve ProtocolNotify for specified usage
710 * ProtocolNotify usage
712 * @returns String[] if elements are found at the known xpath
713 * @returns String[0] if nothing is there
715 public String
[] getProtocolNotifyArray(String arch
) {
718 if (arch
== null || arch
.equals("")) {
719 return new String
[0];
721 xPath
= new String
[] { "/ProtocolNotify" };
724 Object
[] returns
= get("Protocols", xPath
);
725 if (returns
== null) {
726 return new String
[0];
729 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
731 for (int i
= 0; i
< returns
.length
; i
++) {
732 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
733 if (archList
== null || contains(archList
, arch
)){
734 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
738 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
739 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
740 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
742 return protocolNotifyArray
;
746 * Retrieve ProtocolNotify for specified usage
749 * ProtocolNotify usage
751 * @returns String[] if elements are found at the known xpath
752 * @returns String[0] if nothing is there
754 public String
[] getProtocolNotifyArray(String arch
, String usage
) {
760 if (arch
== null || arch
.equals("")) {
761 return new String
[0];
763 archXpath
= "/ProtocolNotify";
764 if (usage
!= null && !usage
.equals("")) {
765 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
766 xPath
= new String
[] { archXpath
, usageXpath
};
768 return getProtocolNotifyArray(arch
);
772 Object
[] returns
= get("Protocols", xPath
);
773 if (returns
== null) {
774 return new String
[0];
777 String
[] protocolNotifyList
= new String
[returns
.length
];
779 for (int i
= 0; i
< returns
.length
; i
++) {
780 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
782 return protocolNotifyList
;
786 * Retrieve ModuleUnloadImage names
788 * @returns ModuleUnloadImage name list if elements are found at the known
790 * @returns null if nothing is there
792 public String
[] getModuleUnloadImageArray() {
793 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
795 Object
[] returns
= get("Externs", xPath
);
796 if (returns
!= null && returns
.length
> 0) {
797 String
[] stringArray
= new String
[returns
.length
];
798 CNameType
[] doc
= (CNameType
[]) returns
;
800 for (int i
= 0; i
< returns
.length
; ++i
) {
801 stringArray
[i
] = doc
[i
].getStringValue();
813 * @returns Extern objects list if elements are found at the known xpath
814 * @returns null if nothing is there
816 public ExternsDocument
.Externs
.Extern
[] getExternArray() {
817 String
[] xPath
= new String
[] { "/Extern" };
819 Object
[] returns
= get("Externs", xPath
);
820 if (returns
!= null && returns
.length
> 0) {
821 return (ExternsDocument
.Externs
.Extern
[]) returns
;
828 * Retrieve PpiNotify for specified arch
833 * @returns String[] if elements are found at the known xpath
834 * @returns String[0] if nothing is there
836 public String
[] getPpiNotifyArray(String arch
) {
839 if (arch
== null || arch
.equals("")) {
840 return new String
[0];
842 xPath
= new String
[] { "/PpiNotify" };
845 Object
[] returns
= get("PPIs", xPath
);
846 if (returns
== null) {
847 return new String
[0];
851 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
852 for (int i
= 0; i
< returns
.length
; i
++) {
853 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
854 if (archList
== null || contains(archList
, arch
)){
855 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
859 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
860 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
861 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
864 return ppiNotifyArray
;
868 * Retrieve PpiNotify for specified usage and arch
871 * PpiNotify arch usage PpiNotify usage
874 * @returns String[] if elements are found at the known xpath
875 * @returns String[0] if nothing is there
877 public String
[] getPpiNotifyArray(String arch
, String usage
) {
883 if (arch
== null || arch
.equals("")) {
884 return new String
[0];
886 archXpath
= "/PpiNotify";
887 if (usage
!= null && !usage
.equals("")) {
888 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
889 xPath
= new String
[] { archXpath
, usageXpath
};
891 return getProtocolNotifyArray(arch
);
895 Object
[] returns
= get("PPIs", xPath
);
896 if (returns
== null) {
897 return new String
[0];
900 String
[] ppiNotifyList
= new String
[returns
.length
];
902 for (int i
= 0; i
< returns
.length
; i
++) {
903 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
905 return ppiNotifyList
;
909 * Retrieve Ppi for specified arch
914 * @returns String[] if elements are found at the known xpath
915 * @returns String[0] if nothing is there
917 public String
[] getPpiArray(String arch
) {
920 if (arch
== null || arch
.equals("")) {
921 return new String
[0];
923 xPath
= new String
[] { "/Ppi" };
926 Object
[] returns
= get("PPIs", xPath
);
927 if (returns
== null) {
928 return new String
[0];
931 List
<String
> ppiList
= new ArrayList
<String
>();
932 for (int i
= 0; i
< returns
.length
; i
++) {
933 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
934 if (archList
== null || contains(archList
, arch
)){
935 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
939 String
[] ppiArray
= new String
[ppiList
.size()];
940 for (int i
= 0; i
< ppiList
.size(); i
++) {
941 ppiArray
[i
] = ppiList
.get(i
);
947 * Retrieve PpiNotify for specified usage and arch
950 * PpiNotify arch usage PpiNotify usage
953 * @returns String[] if elements are found at the known xpath
954 * @returns String[0] if nothing is there
956 public String
[] getPpiArray(String arch
, String usage
) {
962 if (arch
== null || arch
.equals("")) {
963 return new String
[0];
966 if (usage
!= null && !usage
.equals("")) {
967 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
968 xPath
= new String
[] { archXpath
, usageXpath
};
970 return getProtocolNotifyArray(arch
);
974 Object
[] returns
= get("PPIs", xPath
);
975 if (returns
== null) {
976 return new String
[0];
979 String
[] ppiList
= new String
[returns
.length
];
981 for (int i
= 0; i
< returns
.length
; i
++) {
982 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
988 * Retrieve GuidEntry information for specified usage
993 * @returns GuidEntry objects list if elements are found at the known xpath
994 * @returns null if nothing is there
996 public String
[] getGuidEntryArray(String arch
) {
999 if (arch
== null || arch
.equals("")) {
1000 xPath
= new String
[] { "/GuidCNames" };
1002 xPath
= new String
[] { "/GuidCNames" };
1005 Object
[] returns
= get("Guids", xPath
);
1006 if (returns
== null) {
1007 return new String
[0];
1010 List
<String
> guidList
= new ArrayList
<String
>();
1011 for (int i
= 0; i
< returns
.length
; i
++) {
1012 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1013 if (archList
== null || contains(archList
, arch
)){
1014 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1018 String
[] guidArray
= new String
[guidList
.size()];
1019 for (int i
= 0; i
< guidList
.size(); i
++) {
1020 guidArray
[i
] = guidList
.get(i
);
1027 * Retrieve GuidEntry information for specified usage
1030 * GuidEntry arch usage GuidEntry usage
1032 * @returns GuidEntry objects list if elements are found at the known xpath
1033 * @returns null if nothing is there
1035 public String
[] getGuidEntryArray(String arch
, String usage
) {
1040 if (arch
== null || arch
.equals("")) {
1041 return new String
[0];
1043 archXpath
= "/GuidEntry";
1044 if (usage
!= null && !usage
.equals("")) {
1045 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1046 xPath
= new String
[] { archXpath
, usageXpath
};
1048 return getProtocolNotifyArray(arch
);
1052 Object
[] returns
= get("Guids", xPath
);
1053 if (returns
== null) {
1054 return new String
[0];
1057 String
[] guidList
= new String
[returns
.length
];
1059 for (int i
= 0; i
< returns
.length
; i
++) {
1060 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1066 * Retrieve Library instance information
1071 * Library instance usage
1073 * @returns library instance name list if elements are found at the known
1075 * @returns null if nothing is there
1077 public ModuleIdentification
[] getLibraryInstance(String arch
) throws EdkException
{
1079 String saGuid
= null;
1080 String saVersion
= null;
1081 String pkgGuid
= null;
1082 String pkgVersion
= null;
1084 if (arch
== null || arch
.equalsIgnoreCase("")) {
1085 xPath
= new String
[] { "/Instance" };
1088 // Since Schema don't have SupArchList now, so the follow Xpath is
1089 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1090 // don't have effect.
1092 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1096 Object
[] returns
= get("Libraries", xPath
);
1097 if (returns
== null || returns
.length
== 0) {
1098 return new ModuleIdentification
[0];
1101 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1102 for (int i
= 0; i
< returns
.length
; i
++) {
1103 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1104 saGuid
= library
.getModuleGuid();
1105 saVersion
= library
.getModuleVersion();
1107 pkgGuid
= library
.getPackageGuid();
1108 pkgVersion
= library
.getPackageVersion();
1110 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1112 PackageIdentification pkgId
= new PackageIdentification(null,
1113 pkgGuid
, pkgVersion
);
1114 GlobalData
.refreshPackageIdentification(pkgId
);
1115 saId
.setPackage(pkgId
);
1116 GlobalData
.refreshModuleIdentification(saId
);
1125 // / This method is used for retrieving the elements information which has
1126 // / CName sub-element
1128 private String
[] getCNames(String from
, String xPath
[]) {
1129 Object
[] returns
= get(from
, xPath
);
1130 if (returns
== null || returns
.length
== 0) {
1134 String
[] strings
= new String
[returns
.length
];
1135 for (int i
= 0; i
< returns
.length
; ++i
) {
1137 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1144 * Retrive library's constructor name
1146 * @returns constructor name list if elements are found at the known xpath
1147 * @returns null if nothing is there
1149 public String
getLibConstructorName() {
1150 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1152 Object
[] returns
= get("Externs", xPath
);
1153 if (returns
!= null && returns
.length
> 0) {
1154 CNameType constructor
= ((CNameType
) returns
[0]);
1155 return constructor
.getStringValue();
1162 * Retrive library's destructor name
1164 * @returns destructor name list if elements are found at the known xpath
1165 * @returns null if nothing is there
1167 public String
getLibDestructorName() {
1168 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1170 Object
[] returns
= get("Externs", xPath
);
1171 if (returns
!= null && returns
.length
> 0) {
1173 // Only support one Destructor function.
1175 CNameType destructor
= (CNameType
) returns
[0];
1176 return destructor
.getStringValue();
1183 * Retrive DriverBinding names
1185 * @returns DriverBinding name list if elements are found at the known xpath
1186 * @returns null if nothing is there
1188 public String
[] getDriverBindingArray() {
1189 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1190 return getCNames("Externs", xPath
);
1194 * Retrive ComponentName names
1196 * @returns ComponentName name list if elements are found at the known xpath
1197 * @returns null if nothing is there
1199 public String
[] getComponentNameArray() {
1200 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1201 return getCNames("Externs", xPath
);
1205 * Retrive DriverConfig names
1207 * @returns DriverConfig name list if elements are found at the known xpath
1208 * @returns null if nothing is there
1210 public String
[] getDriverConfigArray() {
1211 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1212 return getCNames("Externs", xPath
);
1216 * Retrive DriverDiag names
1218 * @returns DriverDiag name list if elements are found at the known xpath
1219 * @returns null if nothing is there
1221 public String
[] getDriverDiagArray() {
1222 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1223 return getCNames("Externs", xPath
);
1227 * Retrive DriverBinding, ComponentName, DriverConfig,
1228 * DriverDiag group array
1230 * @returns DriverBinding group name list if elements are found
1231 * at the known xpath
1232 * @returns null if nothing is there
1234 public String
[][] getExternProtocolGroup() {
1235 String
[] xPath
= new String
[] {"/Extern"};
1236 Object
[] returns
= get("Externs",xPath
);
1238 if (returns
== null) {
1239 return new String
[0][4];
1241 List
<Extern
> externList
= new ArrayList
<Extern
>();
1242 for (int i
= 0; i
< returns
.length
; i
++) {
1243 org
.tianocore
.ExternsDocument
.Externs
.Extern extern
= (org
.tianocore
.ExternsDocument
.Externs
.Extern
)returns
[i
];
1244 if (extern
.getDriverBinding() != null) {
1245 externList
.add(extern
);
1249 String
[][] externGroup
= new String
[externList
.size()][4];
1250 for (int i
= 0; i
< externList
.size(); i
++) {
1251 String driverBindingStr
= externList
.get(i
).getDriverBinding();
1252 if ( driverBindingStr
!= null){
1253 externGroup
[i
][0] = driverBindingStr
;
1255 externGroup
[i
][0] = null;
1258 String componentNameStr
= externList
.get(i
).getComponentName();
1259 if (componentNameStr
!= null) {
1260 externGroup
[i
][1] = componentNameStr
;
1262 externGroup
[i
][1] = null;
1265 String driverConfigStr
= externList
.get(i
).getDriverConfig();
1266 if (driverConfigStr
!= null) {
1267 externGroup
[i
][2] = driverConfigStr
;
1269 externGroup
[i
][2] = null;
1272 String driverDiagStr
= externList
.get(i
).getDriverDiag();
1273 if (driverDiagStr
!= null) {
1274 externGroup
[i
][3] = driverDiagStr
;
1276 externGroup
[i
][3] = null;
1283 * Retrive SetVirtualAddressMapCallBack names
1285 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1287 * @returns null if nothing is there
1289 public String
[] getSetVirtualAddressMapCallBackArray() {
1290 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1291 return getCNames("Externs", xPath
);
1295 * Retrive ExitBootServicesCallBack names
1297 * @returns ExitBootServicesCallBack name list if elements are found at the
1299 * @returns null if nothing is there
1301 public String
[] getExitBootServicesCallBackArray() {
1302 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1303 return getCNames("Externs", xPath
);
1307 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1310 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1312 public CommonDefinition
.PCD_DRIVER_TYPE
getPcdDriverType() {
1313 String
[] xPath
= new String
[] {"/PcdIsDriver"};
1314 Object
[] results
= get ("Externs", xPath
);
1316 if (results
!= null && results
.length
!= 0) {
1317 PcdDriverTypes type
= (PcdDriverTypes
) results
[0];
1318 String typeStr
= type
.enumValue().toString();
1319 if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
.toString())) {
1320 return CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
;
1321 } else if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
.toString())) {
1322 return CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
;
1324 return CommonDefinition
.PCD_DRIVER_TYPE
.UNKNOWN_PCD_DRIVER
;
1327 return CommonDefinition
.PCD_DRIVER_TYPE
.NOT_PCD_DRIVER
;
1331 * Retrieve module surface area file information
1333 * @returns ModuleSA objects list if elements are found at the known xpath
1334 * @returns Empty ModuleSA list if nothing is there
1336 public Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() throws EdkException
{
1337 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1338 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1340 String fvBinding
= null;
1341 String saGuid
= null;
1342 String saVersion
= null;
1343 String pkgGuid
= null;
1344 String pkgVersion
= null;
1346 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1348 if (result
== null) {
1349 return fpdModuleMap
;
1352 for (int i
= 0; i
< result
.length
; i
++) {
1354 // Get Fpd SA Module element node and add to ObjectMap.
1356 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1357 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1358 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1359 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1361 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1362 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1364 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1365 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1369 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1371 if (moduleSA
.isSetSupArchList()) {
1372 arch
= moduleSA
.getSupArchList().toString();
1379 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1381 saGuid
= moduleSA
.getModuleGuid();
1382 pkgGuid
= moduleSA
.getPackageGuid();
1383 pkgVersion
= moduleSA
.getPackageVersion();
1386 // Create Module Identification which have class member of package
1389 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1390 GlobalData
.refreshPackageIdentification(pkgId
);
1392 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1393 saId
.setPackage(pkgId
);
1394 GlobalData
.refreshModuleIdentification(saId
);
1399 // Create FpdModule Identification which have class member of module
1402 String
[] archList
= new String
[0];
1403 if (arch
== null || arch
.trim().length() == 0) {
1404 archList
= GlobalData
.getToolChainInfo().getArchs();
1406 archList
= arch
.split(" ");
1408 for (int j
= 0; j
< archList
.length
; j
++) {
1409 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1411 if (fvBinding
!= null) {
1412 fpdSaId
.setFvBinding(fvBinding
);
1416 // Put element to Map<FpdModuleIdentification, Map<String,
1419 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1422 return fpdModuleMap
;
1426 * Retrieve valid image names
1428 * @returns valid iamges name list if elements are found at the known xpath
1429 * @returns empty list if nothing is there
1431 public String
[] getFpdValidImageNames() {
1432 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1434 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1435 if (queryResult
== null) {
1436 return new String
[0];
1439 String
[] result
= new String
[queryResult
.length
];
1440 for (int i
= 0; i
< queryResult
.length
; i
++) {
1441 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1447 public Node
getFpdUserExtensionPreBuild() {
1448 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1450 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1451 if (queryResult
== null || queryResult
.length
== 0) {
1454 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1456 return a
.getDomNode();
1459 public Node
getFpdUserExtensionPostBuild() {
1460 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1462 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1463 if (queryResult
== null || queryResult
.length
== 0) {
1466 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1468 return a
.getDomNode();
1472 * Retrieve FV image option information
1477 * @returns option name/value list if elements are found at the known xpath
1478 * @returns empty list if nothing is there
1480 public String
[][] getFpdOptions(String fvName
) {
1481 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1482 + fvName
+ "']/FvImageOptions" };
1483 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1484 if (queryResult
== null) {
1485 return new String
[0][];
1487 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1488 for (int i
= 0; i
< queryResult
.length
; i
++) {
1489 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1490 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1491 .getNameValueList();
1492 Iterator iter
= namevalues
.iterator();
1493 while (iter
.hasNext()) {
1494 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1496 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1499 String
[][] result
= new String
[list
.size()][2];
1500 for (int i
= 0; i
< list
.size(); i
++) {
1501 result
[i
][0] = list
.get(i
)[0];
1502 result
[i
][1] = list
.get(i
)[1];
1508 public XmlObject
getFpdBuildOptions() {
1509 String
[] xPath
= new String
[] { "/BuildOptions" };
1511 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1513 if (queryResult
== null || queryResult
.length
== 0) {
1516 return (XmlObject
)queryResult
[0];
1519 public PlatformIdentification
getFpdHeader() {
1520 String
[] xPath
= new String
[] { "/PlatformHeader" };
1522 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1524 if (returns
== null || returns
.length
== 0) {
1527 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1529 String name
= header
.getPlatformName();
1531 String guid
= header
.getGuidValue();
1533 String version
= header
.getVersion();
1535 return new PlatformIdentification(name
, guid
, version
);
1539 * Retrieve FV image attributes information
1544 * @returns attribute name/value list if elements are found at the known
1546 * @returns empty list if nothing is there
1548 public String
[][] getFpdAttributes(String fvName
) {
1549 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1550 + fvName
+ "']/FvImageOptions" };
1551 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1552 if (queryResult
== null) {
1553 return new String
[0][];
1555 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1556 for (int i
= 0; i
< queryResult
.length
; i
++) {
1558 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1559 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1560 Iterator iter
= namevalues
.iterator();
1561 while (iter
.hasNext()) {
1562 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1564 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1567 String
[][] result
= new String
[list
.size()][2];
1568 for (int i
= 0; i
< list
.size(); i
++) {
1569 result
[i
][0] = list
.get(i
)[0];
1570 result
[i
][1] = list
.get(i
)[1];
1576 * Retrieve flash definition file name
1578 * @returns file name if elements are found at the known xpath
1579 * @returns null if nothing is there
1581 public String
getFlashDefinitionFile() {
1582 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1584 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1585 if (queryResult
== null || queryResult
.length
== 0) {
1589 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1590 return filename
.getStringValue();
1593 public String
[][] getFpdGlobalVariable() {
1594 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1595 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1596 if (queryResult
== null) {
1597 return new String
[0][];
1600 String
[][] result
= new String
[queryResult
.length
][2];
1602 for (int i
= 0; i
< queryResult
.length
; i
++) {
1603 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1604 result
[i
][0] = item
.getName();
1605 result
[i
][1] = item
.getValue();
1611 * Retrieve FV image component options
1616 * @returns name/value pairs list if elements are found at the known xpath
1617 * @returns empty list if nothing is there
1619 public String
[][] getFpdComponents(String fvName
) {
1620 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1621 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1622 if (queryResult
== null) {
1623 return new String
[0][];
1626 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1627 for (int i
= 0; i
< queryResult
.length
; i
++) {
1628 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1629 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1630 Iterator iter
= namevalues
.iterator();
1631 while (iter
.hasNext()) {
1632 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1634 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1637 String
[][] result
= new String
[list
.size()][2];
1638 for (int i
= 0; i
< list
.size(); i
++) {
1639 result
[i
][0] = list
.get(i
)[0];
1640 result
[i
][1] = list
.get(i
)[1];
1646 * Retrieve PCD tokens
1648 * @returns CName/ItemType pairs list if elements are found at the known
1650 * @returns null if nothing is there
1652 public String
[][] getPcdTokenArray() {
1653 String
[] xPath
= new String
[] { "/PcdData" };
1655 Object
[] returns
= get("PCDs", xPath
);
1656 if (returns
== null || returns
.length
== 0) {
1664 * Retrieve MAS header
1669 public ModuleIdentification
getMsaHeader() {
1670 String
[] xPath
= new String
[] { "/" };
1671 Object
[] returns
= get("MsaHeader", xPath
);
1673 if (returns
== null || returns
.length
== 0) {
1677 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1679 // Get BaseName, ModuleType, GuidValue, Version
1680 // which in MsaHeader.
1682 String name
= msaHeader
.getModuleName();
1683 String moduleType
= msaHeader
.getModuleType().toString();
1684 String guid
= msaHeader
.getGuidValue();
1685 String version
= msaHeader
.getVersion();
1687 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1690 moduleId
.setModuleType(moduleType
);
1696 * Retrieve Extern Specification
1700 * @return String[] If have specification element in the <extern> String[0]
1701 * If no specification element in the <extern>
1705 public String
[] getExternSpecificaiton() {
1706 String
[] xPath
= new String
[] { "/Specification" };
1708 Object
[] queryResult
= get("Externs", xPath
);
1709 if (queryResult
== null) {
1710 return new String
[0];
1713 String
[] specificationList
= new String
[queryResult
.length
];
1714 for (int i
= 0; i
< queryResult
.length
; i
++) {
1715 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1718 return specificationList
;
1722 * Retreive MsaFile which in SPD
1725 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1726 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1728 public String
[] getSpdMsaFile() {
1729 String
[] xPath
= new String
[] { "/MsaFiles" };
1731 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1732 if (returns
== null) {
1733 return new String
[0];
1736 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1738 return filenameList
.toArray(new String
[filenameList
.size()]);
1744 public Map
<String
, String
[]> getSpdLibraryClasses() {
1745 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1747 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1750 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1752 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1754 if (returns
== null) {
1755 return libClassHeaderMap
;
1758 for (int i
= 0; i
< returns
.length
; i
++) {
1759 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1760 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1761 .getIncludeHeader() });
1763 return libClassHeaderMap
;
1769 public Map
<String
, String
> getSpdPackageHeaderFiles() {
1770 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1772 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1775 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1777 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1779 if (returns
== null) {
1780 return packageIncludeMap
;
1783 for (int i
= 0; i
< returns
.length
; i
++) {
1784 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1785 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1786 includeHeader
.getStringValue());
1788 return packageIncludeMap
;
1791 public PackageIdentification
getSpdHeader() {
1792 String
[] xPath
= new String
[] { "/SpdHeader" };
1794 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1796 if (returns
== null || returns
.length
== 0) {
1800 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1802 String name
= header
.getPackageName();
1804 String guid
= header
.getGuidValue();
1806 String version
= header
.getVersion();
1808 return new PackageIdentification(name
, guid
, version
);
1814 public Map
<String
, String
[]> getSpdGuid() {
1815 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1817 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1820 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1822 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1823 if (returns
== null) {
1827 for (int i
= 0; i
< returns
.length
; i
++) {
1828 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1829 String
[] guidPair
= new String
[2];
1830 guidPair
[0] = entry
.getCName();
1831 guidPair
[1] = entry
.getGuidValue();
1832 guidDeclMap
.put(entry
.getCName(), guidPair
);
1833 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1834 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[0]);
1835 EdkLog
.log(EdkLog
.EDK_VERBOSE
, guidPair
[1]);
1843 public Map
<String
, String
[]> getSpdProtocol() {
1844 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1846 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1849 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1851 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1853 if (returns
== null) {
1857 for (int i
= 0; i
< returns
.length
; i
++) {
1858 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1859 String
[] protocolPair
= new String
[2];
1861 protocolPair
[0] = entry
.getCName();
1862 protocolPair
[1] = entry
.getGuidValue();
1863 protoclMap
.put(entry
.getCName(), protocolPair
);
1864 EdkLog
.log(EdkLog
.EDK_VERBOSE
, entry
.getName());
1865 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[0]);
1866 EdkLog
.log(EdkLog
.EDK_VERBOSE
, protocolPair
[1]);
1872 * getSpdPpi() Retrieve the SPD PPI Entry
1875 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1876 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1879 public Map
<String
, String
[]> getSpdPpi() {
1880 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1882 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1885 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1887 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1889 if (returns
== null) {
1893 for (int i
= 0; i
< returns
.length
; i
++) {
1894 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1895 String
[] ppiPair
= new String
[2];
1896 ppiPair
[0] = entry
.getCName();
1897 ppiPair
[1] = entry
.getGuidValue();
1898 ppiMap
.put(entry
.getCName(), ppiPair
);
1904 * Retrieve module Guid string
1906 * @returns GUILD string if elements are found at the known xpath
1907 * @returns null if nothing is there
1909 public String
getModuleGuid() {
1910 String
[] xPath
= new String
[] { "" };
1912 Object
[] returns
= get("MsaHeader", xPath
);
1913 if (returns
!= null && returns
.length
> 0) {
1914 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1925 public ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1926 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1927 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1928 if (result
!= null) {
1929 return (ModuleSADocument
.ModuleSA
[]) result
;
1931 return new ModuleSADocument
.ModuleSA
[0];
1935 Get name array of PCD in a module. In one module, token space
1936 is same, and token name should not be conflicted.
1940 public String
[] getModulePcdEntryNameArray() {
1941 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1944 String
[] xPath
= new String
[] {"/PcdEntry"};
1945 Object
[] returns
= get ("PcdCoded", xPath
);
1947 if (returns
== null) {
1948 return new String
[0];
1951 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1952 results
= new String
[pcdEntries
.length
];
1954 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1955 results
[index
] = pcdEntries
[index
].getCName();
1961 Search in a List for a given string
1965 public boolean contains(List list
, String str
) {
1966 if (list
== null || list
.size()== 0) {
1969 Iterator it
= list
.iterator();
1970 while (it
.hasNext()) {
1971 String s
= (String
)it
.next();
1972 if (s
.equalsIgnoreCase(str
)) {
1980 public boolean isHaveTianoR8FlashMap(){
1981 String
[] xPath
= new String
[] {"/"};
1982 Object
[] returns
= get ("Externs", xPath
);
1984 if (returns
== null) {
1988 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
1990 if (ext
.getTianoR8FlashMapH()){