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
.FilenameDocument
.Filename
;
31 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
32 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
33 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
34 import org
.tianocore
.build
.autogen
.CommonDefinition
;
35 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
36 import org
.tianocore
.build
.id
.ModuleIdentification
;
37 import org
.tianocore
.build
.id
.PackageIdentification
;
38 import org
.tianocore
.build
.id
.PlatformIdentification
;
39 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
40 import org
.tianocore
.common
.exception
.EdkException
;
41 import org
.w3c
.dom
.Node
;
44 * SurfaceAreaQuery class is used to query Surface Area information from msa,
45 * mbd, spd and fpd files.
47 * This class should not instantiated. All the public interfaces is static.
51 public class SurfaceAreaQuery
{
53 public String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
56 // Contains name/value pairs of Surface Area document object. The name is
57 // always the top level element name.
59 private Map
<String
, XmlObject
> map
= null;
62 // mapStack is used to do nested query
64 private Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
67 // prefix of name space
69 private String nsPrefix
= "sans";
72 // xmlbeans needs a name space for each Xpath element
74 private String ns
= null;
77 // keep the namep declaration for xmlbeans Xpath query
79 private String queryDeclaration
= null;
80 private StringBuffer normQueryString
= new StringBuffer(4096);
81 private Pattern xPathPattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
84 * Set a Surface Area document for query later
87 * A Surface Area document in TopLevelElementName/XmlObject
90 public SurfaceAreaQuery(Map
<String
, XmlObject
> map
) {
92 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
97 * Push current used Surface Area document into query stack. The given new
98 * document will be used for any immediately followed getXXX() callings,
99 * untill pop() is called.
102 * The TopLevelElementName/XmlObject format of a Surface Area
105 public void push(Map
<String
, XmlObject
> newMap
) {
106 mapStack
.push(this.map
);
111 * Discard current used Surface Area document and use the top document in
115 this.map
= mapStack
.pop();
119 // / Convert xPath to be namespace qualified, which is necessary for
121 // / selectPath(). For example, converting /MsaHeader/ModuleType to
122 // / /ns:MsaHeader/ns:ModuleType
124 private String
normalizeQueryString(String
[] exp
, String from
) {
125 normQueryString
.setLength(0);
128 while (i
< exp
.length
) {
129 String newExp
= from
+ exp
[i
];
130 Matcher matcher
= xPathPattern
.matcher(newExp
);
132 while (matcher
.find()) {
133 String starter
= newExp
.substring(matcher
.start(1), matcher
135 String seperator
= newExp
.substring(matcher
.start(2), matcher
137 String token
= newExp
.substring(matcher
.start(3), matcher
140 normQueryString
.append(starter
);
141 normQueryString
.append(seperator
);
142 normQueryString
.append(nsPrefix
);
143 normQueryString
.append(":");
144 normQueryString
.append(token
);
148 if (i
< exp
.length
) {
149 normQueryString
.append(" | ");
153 return normQueryString
.toString();
157 * Search all XML documents stored in "map" for the specified xPath, using
158 * relative path (starting with '$this')
161 * xpath query string array
162 * @returns An array of XmlObject if elements are found at the specified
164 * @returns NULL if nothing is at the specified xpath
166 public Object
[] get(String
[] xPath
) {
171 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
172 List
<Object
> result
= new ArrayList
<Object
>();
173 for (int i
= 0; i
< keys
.length
; ++i
) {
174 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
175 if (rootNode
== null) {
179 String query
= queryDeclaration
180 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
181 XmlObject
[] tmp
= rootNode
.selectPath(query
);
182 for (int j
= 0; j
< tmp
.length
; ++j
) {
183 result
.add((Object
)tmp
[j
]);
187 int size
= result
.size();
192 return (Object
[]) result
.toArray(new Object
[size
]);
196 * Search XML documents named by "rootName" for the given xPath, using
197 * relative path (starting with '$this')
200 * The top level element name
202 * The xpath query string array
203 * @returns An array of XmlObject if elements are found at the given xpath
204 * @returns NULL if nothing is found at the given xpath
206 public Object
[] get(String rootName
, String
[] xPath
) {
211 XmlObject root
= (XmlObject
) map
.get(rootName
);
216 String query
= queryDeclaration
217 + normalizeQueryString(xPath
, "$this/" + rootName
);
218 XmlObject
[] result
= root
.selectPath(query
);
219 if (result
.length
> 0) {
220 return (Object
[])result
;
223 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
224 result
= root
.selectPath(query
);
225 if (result
.length
> 0) {
226 return (Object
[])result
;
233 * Retrieve SourceFiles/Filename for specified ARCH type
237 * @returns An 2 dimension string array if elements are found at the known
239 * @returns NULL if nothing is found at the known xpath
241 public String
[][] getSourceFiles(String arch
) {
245 xPath
= new String
[] { "/Filename" };
247 returns
= get("SourceFiles", xPath
);
249 if (returns
== null || returns
.length
== 0) {
250 return new String
[0][3];
253 Filename
[] sourceFileNames
= (Filename
[]) returns
;
254 List
<String
[]> outputList
= new ArrayList
<String
[]>();
255 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
256 List archList
= sourceFileNames
[i
].getSupArchList();
257 if (arch
== null || arch
.trim().equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
258 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(), sourceFileNames
[i
].getStringValue(), sourceFileNames
[i
].getToolChainFamily()});
262 String
[][] outputString
= new String
[outputList
.size()][3];
263 for (int index
= 0; index
< outputList
.size(); index
++) {
265 // ToolCode (FileType)
267 outputString
[index
][0] = outputList
.get(index
)[0];
269 // File name (relative to MODULE_DIR)
271 outputString
[index
][1] = outputList
.get(index
)[1];
275 outputString
[index
][2] = outputList
.get(index
)[2];
281 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
283 * @returns Directory names array if elements are found at the known xpath
284 * @returns Empty if nothing is found at the known xpath
286 public String
getFpdOutputDirectory() {
287 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
289 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
290 if (returns
== null || returns
.length
== 0) {
293 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
294 return item
.getOutputDirectory();
297 public String
getFpdIntermediateDirectories() {
298 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
300 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
301 if (returns
== null || returns
.length
== 0) {
304 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
305 if(item
.getIntermediateDirectories() == null) {
309 return item
.getIntermediateDirectories().toString();
313 public String
getModuleFfsKeyword() {
314 String
[] xPath
= new String
[] { "/" };
316 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
317 if (returns
== null || returns
.length
== 0) {
320 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
321 return item
.getFfsFormatKey();
324 public String
getModuleFvBindingKeyword() {
325 String
[] xPath
= new String
[] { "/" };
327 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
328 if (returns
== null || returns
.length
== 0) {
331 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
332 return item
.getFvBinding();
335 public List
getModuleSupportedArchs() {
336 String
[] xPath
= new String
[] { "/" };
338 Object
[] returns
= get("ModuleDefinitions", xPath
);
339 if (returns
== null || returns
.length
== 0) {
342 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
343 return item
.getSupportedArchitectures();
346 public BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
347 String
[] xPath
= new String
[] {"/Ffs"};
349 Object
[] returns
= get("BuildOptions", xPath
);
350 if (returns
== null || returns
.length
== 0) {
351 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
353 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
356 public String
getModuleOutputFileBasename() {
357 String
[] xPath
= new String
[] { "/" };
359 Object
[] returns
= get("ModuleDefinitions", xPath
);
360 if (returns
== null || returns
.length
== 0) {
363 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
364 return item
.getOutputFileBasename();
368 * Retrieve BuildOptions/Option or Arch/Option
370 * @param toolChainFamilyFlag
371 * if true, retrieve options for toolchain family; otherwise for
374 * @returns String[][5] name, target, toolchain, arch, coommand of options
375 * if elements are found at the known xpath. String[0][] if dont
378 * @returns Empty array if nothing is there
380 public String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
381 String target
= null;
382 String toolchain
= null;
383 String toolchainFamily
= null;
384 List
<String
> archList
= null;
386 String optionName
= null;
388 Object
[] returns
= get(from
, xPath
);
389 if (returns
== null) {
390 return new String
[0][5];
393 List
<String
[]> optionList
= new ArrayList
<String
[]>();
394 OptionDocument
.Option option
;
396 for (int i
= 0; i
< returns
.length
; i
++) {
397 option
= (OptionDocument
.Option
) returns
[i
];
400 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
402 // put to result[][5] array in above order.
405 if (option
.getBuildTargets() == null) {
409 target
= option
.getBuildTargets().toString();
411 if (target
!= null) {
412 targetList
= target
.split(" ");
414 targetList
= new String
[1];
415 targetList
[0] = null;
418 if (toolChainFamilyFlag
) {
419 toolchainFamily
= option
.getToolChainFamily();
420 if (toolchainFamily
!= null) {
421 toolchain
= toolchainFamily
.toString();
426 toolchain
= option
.getTagName();
429 archList
= new ArrayList
<String
>();
430 List archEnumList
= option
.getSupArchList();
431 if (archEnumList
== null) {
434 //archList.addAll(archEnumList);
435 Iterator it
= archEnumList
.iterator();
436 while (it
.hasNext()) {
437 String archType
= (String
)it
.next();
438 archList
.add(archType
);
442 cmd
= option
.getToolCode();
444 optionName
= option
.getStringValue();
445 for (int t
= 0; t
< targetList
.length
; t
++) {
446 for (int j
= 0; j
< archList
.size(); j
++) {
447 optionList
.add(new String
[] { targetList
[t
],
448 toolchain
, archList
.get(j
), cmd
, optionName
});
453 String
[][] result
= new String
[optionList
.size()][5];
454 for (int i
= 0; i
< optionList
.size(); i
++) {
455 result
[i
][0] = optionList
.get(i
)[0];
456 result
[i
][1] = optionList
.get(i
)[1];
457 result
[i
][2] = optionList
.get(i
)[2];
458 result
[i
][3] = optionList
.get(i
)[3];
459 result
[i
][4] = optionList
.get(i
)[4];
464 public String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
467 if (toolChainFamilyFlag
== true) {
468 xPath
= new String
[] {
469 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
470 "/Options/Option[@ToolChainFamily]", };
472 xPath
= new String
[] {
473 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
474 "/Options/Option[@TagName]", };
476 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
479 public String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
482 if (toolChainFamilyFlag
== true) {
483 xPath
= new String
[] {
484 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
485 "/BuildOptions/Options/Option[@ToolChainFamily]", };
487 xPath
= new String
[] {
488 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
489 "/BuildOptions/Options/Option[@TagName]", };
492 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
495 public String
[][] getMsaBuildOptions(boolean toolChainFamilyFlag
) {
498 if (toolChainFamilyFlag
== true) {
499 xPath
= new String
[] {
500 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
501 "/Options/Option[@ToolChainFamily]", };
503 xPath
= new String
[] {
504 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
505 "/Options/Option[@TagName]", };
508 return getOptions("ModuleBuildOptions", xPath
, toolChainFamilyFlag
);
511 public ToolChainInfo
getFpdToolChainInfo() {
512 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
514 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
515 if (returns
== null || returns
.length
== 0) {
519 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
520 ToolChainInfo toolChainInfo
= new ToolChainInfo();
521 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
522 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
523 toolChainInfo
.addTagnames((String
)null);
524 return toolChainInfo
;
528 * Retrieve <xxxHeader>/ModuleType
530 * @returns The module type name if elements are found at the known xpath
531 * @returns null if nothing is there
533 public String
getModuleType() {
534 String
[] xPath
= new String
[] { "/ModuleType" };
536 Object
[] returns
= get(xPath
);
537 if (returns
!= null && returns
.length
> 0) {
538 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
539 return type
.enumValue().toString();
546 * Retrieve PackageDependencies/Package
551 * @returns package name list if elements are found at the known xpath
552 * @returns null if nothing is there
554 public PackageIdentification
[] getDependencePkg(String arch
) throws EdkException
{
556 String packageGuid
= null;
557 String packageVersion
= null;
560 xPath
= new String
[] { "/Package" };
562 Object
[] returns
= get("PackageDependencies", xPath
);
563 if (returns
== null) {
564 return new PackageIdentification
[0];
568 // Get packageIdentification
570 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
571 for (int i
= 0; i
< returns
.length
; i
++) {
572 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
573 List archList
= item
.getSupArchList();
574 if (arch
== null || archList
== null || contains(archList
, arch
)) {
575 packageGuid
= item
.getPackageGuid();
576 packageVersion
= item
.getPackageVersion();
577 PackageIdentification pkgId
= new PackageIdentification(null, packageGuid
, packageVersion
);
578 GlobalData
.refreshPackageIdentification(pkgId
);
579 packageIdList
.add(pkgId
);
583 return packageIdList
.toArray(new PackageIdentification
[packageIdList
.size()]);
587 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
590 * Library class usage
592 * @returns LibraryClass objects list if elements are found at the known
594 * @returns null if nothing is there
596 public String
[] getLibraryClasses(String usage
, String arch
) {
598 if (usage
== null || usage
.equals("")) {
599 xPath
= new String
[] { "/LibraryClass" };
601 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
604 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
605 if (returns
== null || returns
.length
== 0) {
606 return new String
[0];
609 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
610 List
<String
> libraryClassName
= new ArrayList
<String
>();
611 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
612 List archList
= libraryClassList
[i
].getSupArchList();
614 if (arch
== null || contains(archList
, arch
)) {
615 libraryClassName
.add(libraryClassList
[i
].getKeyword());
619 String
[] libraryArray
= new String
[libraryClassName
.size()];
620 libraryClassName
.toArray(libraryArray
);
625 * Retrieve ModuleEntryPoint names
627 * @returns ModuleEntryPoint name list if elements are found at the known
629 * @returns null if nothing is there
631 public String
[] getModuleEntryPointArray() {
632 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
634 Object
[] returns
= get("Externs", xPath
);
636 if (returns
!= null && returns
.length
> 0) {
637 String
[] entryPoints
= new String
[returns
.length
];
639 for (int i
= 0; i
< returns
.length
; ++i
) {
640 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
650 * retrieve Protocol for specified usage
653 * Protocol usage arch Architecture
655 * @returns Protocol String list if elements are found at the known xpath
656 * @returns String[0] if nothing is there
658 public String
[] getProtocolArray(String arch
, String usage
) {
660 String usageXpath
= "";
661 String archXpath
= "";
663 if (arch
== null || arch
.equals("")) {
664 return new String
[0];
666 archXpath
= "/Protocol";
667 if (usage
!= null && !usage
.equals("")) {
668 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
669 xPath
= new String
[] { usageXpath
, archXpath
};
671 return getProtocolArray(arch
);
676 Object
[] returns
= get("Protocols", xPath
);
677 if (returns
== null) {
678 return new String
[0];
680 Protocol
[] protocolList
= (Protocol
[]) returns
;
682 String
[] protocolArray
= new String
[returns
.length
];
683 for (int i
= 0; i
< returns
.length
; i
++) {
684 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
686 return protocolArray
;
690 * retrieve Protocol for specified usage
695 * @returns Protocol String list if elements are found at the known xpath
696 * @returns String[0] if nothing is there
698 public String
[] getProtocolArray(String arch
) {
701 if (arch
== null || arch
.equals("")) {
702 return new String
[0];
704 xPath
= new String
[] { "/Protocol" };
707 Object
[] returns
= get("Protocols", xPath
);
708 if (returns
== null) {
709 return new String
[0];
711 Protocol
[] returnlList
= (Protocol
[]) returns
;
713 List
<String
> protocolList
= new ArrayList
<String
>();
715 for (int i
= 0; i
< returns
.length
; i
++) {
716 List archList
= returnlList
[i
].getSupArchList();
717 if (archList
== null || contains(archList
, arch
)){
718 protocolList
.add(returnlList
[i
].getProtocolCName());
721 String
[] protocolArray
= new String
[protocolList
.size()];
722 for (int i
= 0; i
< protocolList
.size(); i
++) {
723 protocolArray
[i
] = protocolList
.get(i
);
725 return protocolArray
;
729 * Retrieve ProtocolNotify for specified usage
732 * ProtocolNotify usage
734 * @returns String[] if elements are found at the known xpath
735 * @returns String[0] if nothing is there
737 public String
[] getProtocolNotifyArray(String arch
) {
740 if (arch
== null || arch
.equals("")) {
741 return new String
[0];
743 xPath
= new String
[] { "/ProtocolNotify" };
746 Object
[] returns
= get("Protocols", xPath
);
747 if (returns
== null) {
748 return new String
[0];
751 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
753 for (int i
= 0; i
< returns
.length
; i
++) {
754 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
755 if (archList
== null || contains(archList
, arch
)){
756 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
760 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
761 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
762 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
764 return protocolNotifyArray
;
768 * Retrieve ProtocolNotify for specified usage
771 * ProtocolNotify usage
773 * @returns String[] if elements are found at the known xpath
774 * @returns String[0] if nothing is there
776 public String
[] getProtocolNotifyArray(String arch
, String usage
) {
782 if (arch
== null || arch
.equals("")) {
783 return new String
[0];
785 archXpath
= "/ProtocolNotify";
786 if (usage
!= null && !usage
.equals("")) {
787 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
788 xPath
= new String
[] { archXpath
, usageXpath
};
790 return getProtocolNotifyArray(arch
);
794 Object
[] returns
= get("Protocols", xPath
);
795 if (returns
== null) {
796 return new String
[0];
799 String
[] protocolNotifyList
= new String
[returns
.length
];
801 for (int i
= 0; i
< returns
.length
; i
++) {
802 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
804 return protocolNotifyList
;
808 * Retrieve ModuleUnloadImage names
810 * @returns ModuleUnloadImage name list if elements are found at the known
812 * @returns null if nothing is there
814 public String
[] getModuleUnloadImageArray() {
815 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
817 Object
[] returns
= get("Externs", xPath
);
818 if (returns
!= null && returns
.length
> 0) {
819 String
[] stringArray
= new String
[returns
.length
];
820 CNameType
[] doc
= (CNameType
[]) returns
;
822 for (int i
= 0; i
< returns
.length
; ++i
) {
823 stringArray
[i
] = doc
[i
].getStringValue();
835 * @returns Extern objects list if elements are found at the known xpath
836 * @returns null if nothing is there
838 public ExternsDocument
.Externs
.Extern
[] getExternArray() {
839 String
[] xPath
= new String
[] { "/Extern" };
841 Object
[] returns
= get("Externs", xPath
);
842 if (returns
!= null && returns
.length
> 0) {
843 return (ExternsDocument
.Externs
.Extern
[]) returns
;
850 * Retrieve PpiNotify for specified arch
855 * @returns String[] if elements are found at the known xpath
856 * @returns String[0] if nothing is there
858 public String
[] getPpiNotifyArray(String arch
) {
861 if (arch
== null || arch
.equals("")) {
862 return new String
[0];
864 xPath
= new String
[] { "/PpiNotify" };
867 Object
[] returns
= get("PPIs", xPath
);
868 if (returns
== null) {
869 return new String
[0];
873 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
874 for (int i
= 0; i
< returns
.length
; i
++) {
875 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
876 if (archList
== null || contains(archList
, arch
)){
877 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
881 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
882 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
883 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
886 return ppiNotifyArray
;
890 * Retrieve PpiNotify for specified usage and arch
893 * PpiNotify arch usage PpiNotify usage
896 * @returns String[] if elements are found at the known xpath
897 * @returns String[0] if nothing is there
899 public String
[] getPpiNotifyArray(String arch
, String usage
) {
905 if (arch
== null || arch
.equals("")) {
906 return new String
[0];
908 archXpath
= "/PpiNotify";
909 if (usage
!= null && !usage
.equals("")) {
910 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
911 xPath
= new String
[] { archXpath
, usageXpath
};
913 return getProtocolNotifyArray(arch
);
917 Object
[] returns
= get("PPIs", xPath
);
918 if (returns
== null) {
919 return new String
[0];
922 String
[] ppiNotifyList
= new String
[returns
.length
];
924 for (int i
= 0; i
< returns
.length
; i
++) {
925 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
927 return ppiNotifyList
;
931 * Retrieve Ppi for specified arch
936 * @returns String[] if elements are found at the known xpath
937 * @returns String[0] if nothing is there
939 public String
[] getPpiArray(String arch
) {
942 if (arch
== null || arch
.equals("")) {
943 return new String
[0];
945 xPath
= new String
[] { "/Ppi" };
948 Object
[] returns
= get("PPIs", xPath
);
949 if (returns
== null) {
950 return new String
[0];
953 List
<String
> ppiList
= new ArrayList
<String
>();
954 for (int i
= 0; i
< returns
.length
; i
++) {
955 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
956 if (archList
== null || contains(archList
, arch
)){
957 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
961 String
[] ppiArray
= new String
[ppiList
.size()];
962 for (int i
= 0; i
< ppiList
.size(); i
++) {
963 ppiArray
[i
] = ppiList
.get(i
);
969 * Retrieve PpiNotify for specified usage and arch
972 * PpiNotify arch usage PpiNotify usage
975 * @returns String[] if elements are found at the known xpath
976 * @returns String[0] if nothing is there
978 public String
[] getPpiArray(String arch
, String usage
) {
984 if (arch
== null || arch
.equals("")) {
985 return new String
[0];
988 if (usage
!= null && !usage
.equals("")) {
989 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
990 xPath
= new String
[] { archXpath
, usageXpath
};
992 return getProtocolNotifyArray(arch
);
996 Object
[] returns
= get("PPIs", xPath
);
997 if (returns
== null) {
998 return new String
[0];
1001 String
[] ppiList
= new String
[returns
.length
];
1003 for (int i
= 0; i
< returns
.length
; i
++) {
1004 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1010 * Retrieve GuidEntry information for specified usage
1015 * @returns GuidEntry objects list if elements are found at the known xpath
1016 * @returns null if nothing is there
1018 public String
[] getGuidEntryArray(String arch
) {
1021 if (arch
== null || arch
.equals("")) {
1022 xPath
= new String
[] { "/GuidCNames" };
1024 xPath
= new String
[] { "/GuidCNames" };
1027 Object
[] returns
= get("Guids", xPath
);
1028 if (returns
== null) {
1029 return new String
[0];
1032 List
<String
> guidList
= new ArrayList
<String
>();
1033 for (int i
= 0; i
< returns
.length
; i
++) {
1034 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1035 if (archList
== null || contains(archList
, arch
)){
1036 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1040 String
[] guidArray
= new String
[guidList
.size()];
1041 for (int i
= 0; i
< guidList
.size(); i
++) {
1042 guidArray
[i
] = guidList
.get(i
);
1049 * Retrieve GuidEntry information for specified usage
1052 * GuidEntry arch usage GuidEntry usage
1054 * @returns GuidEntry objects list if elements are found at the known xpath
1055 * @returns null if nothing is there
1057 public String
[] getGuidEntryArray(String arch
, String usage
) {
1062 if (arch
== null || arch
.equals("")) {
1063 return new String
[0];
1065 archXpath
= "/GuidEntry";
1066 if (usage
!= null && !usage
.equals("")) {
1067 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1068 xPath
= new String
[] { archXpath
, usageXpath
};
1070 return getProtocolNotifyArray(arch
);
1074 Object
[] returns
= get("Guids", xPath
);
1075 if (returns
== null) {
1076 return new String
[0];
1079 String
[] guidList
= new String
[returns
.length
];
1081 for (int i
= 0; i
< returns
.length
; i
++) {
1082 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1088 * Retrieve Library instance information
1093 * Library instance usage
1095 * @returns library instance name list if elements are found at the known
1097 * @returns null if nothing is there
1099 public ModuleIdentification
[] getLibraryInstance(String arch
) throws EdkException
{
1101 String saGuid
= null;
1102 String saVersion
= null;
1103 String pkgGuid
= null;
1104 String pkgVersion
= null;
1106 if (arch
== null || arch
.equalsIgnoreCase("")) {
1107 xPath
= new String
[] { "/Instance" };
1110 // Since Schema don't have SupArchList now, so the follow Xpath is
1111 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1112 // don't have effect.
1114 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1118 Object
[] returns
= get("Libraries", xPath
);
1119 if (returns
== null || returns
.length
== 0) {
1120 return new ModuleIdentification
[0];
1123 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1124 for (int i
= 0; i
< returns
.length
; i
++) {
1125 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1126 saGuid
= library
.getModuleGuid();
1127 saVersion
= library
.getModuleVersion();
1129 pkgGuid
= library
.getPackageGuid();
1130 pkgVersion
= library
.getPackageVersion();
1132 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1134 PackageIdentification pkgId
= new PackageIdentification(null,
1135 pkgGuid
, pkgVersion
);
1136 GlobalData
.refreshPackageIdentification(pkgId
);
1137 saId
.setPackage(pkgId
);
1138 GlobalData
.refreshModuleIdentification(saId
);
1147 // / This method is used for retrieving the elements information which has
1148 // / CName sub-element
1150 private String
[] getCNames(String from
, String xPath
[]) {
1151 Object
[] returns
= get(from
, xPath
);
1152 if (returns
== null || returns
.length
== 0) {
1156 String
[] strings
= new String
[returns
.length
];
1157 for (int i
= 0; i
< returns
.length
; ++i
) {
1159 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1166 * Retrive library's constructor name
1168 * @returns constructor name list if elements are found at the known xpath
1169 * @returns null if nothing is there
1171 public String
getLibConstructorName() {
1172 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1174 Object
[] returns
= get("Externs", xPath
);
1175 if (returns
!= null && returns
.length
> 0) {
1176 CNameType constructor
= ((CNameType
) returns
[0]);
1177 return constructor
.getStringValue();
1184 * Retrive library's destructor name
1186 * @returns destructor name list if elements are found at the known xpath
1187 * @returns null if nothing is there
1189 public String
getLibDestructorName() {
1190 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1192 Object
[] returns
= get("Externs", xPath
);
1193 if (returns
!= null && returns
.length
> 0) {
1195 // Only support one Destructor function.
1197 CNameType destructor
= (CNameType
) returns
[0];
1198 return destructor
.getStringValue();
1205 * Retrive DriverBinding names
1207 * @returns DriverBinding name list if elements are found at the known xpath
1208 * @returns null if nothing is there
1210 public String
[] getDriverBindingArray() {
1211 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1212 return getCNames("Externs", xPath
);
1216 * Retrive ComponentName names
1218 * @returns ComponentName name list if elements are found at the known xpath
1219 * @returns null if nothing is there
1221 public String
[] getComponentNameArray() {
1222 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1223 return getCNames("Externs", xPath
);
1227 * Retrive DriverConfig names
1229 * @returns DriverConfig name list if elements are found at the known xpath
1230 * @returns null if nothing is there
1232 public String
[] getDriverConfigArray() {
1233 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1234 return getCNames("Externs", xPath
);
1238 * Retrive DriverDiag names
1240 * @returns DriverDiag name list if elements are found at the known xpath
1241 * @returns null if nothing is there
1243 public String
[] getDriverDiagArray() {
1244 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1245 return getCNames("Externs", xPath
);
1249 * Retrive DriverBinding, ComponentName, DriverConfig,
1250 * DriverDiag group array
1252 * @returns DriverBinding group name list if elements are found
1253 * at the known xpath
1254 * @returns null if nothing is there
1256 public String
[][] getExternProtocolGroup() {
1257 String
[] xPath
= new String
[] {"/Extern"};
1258 Object
[] returns
= get("Externs",xPath
);
1260 if (returns
== null) {
1261 return new String
[0][4];
1263 List
<Extern
> externList
= new ArrayList
<Extern
>();
1264 for (int i
= 0; i
< returns
.length
; i
++) {
1265 org
.tianocore
.ExternsDocument
.Externs
.Extern extern
= (org
.tianocore
.ExternsDocument
.Externs
.Extern
)returns
[i
];
1266 if (extern
.getDriverBinding() != null) {
1267 externList
.add(extern
);
1271 String
[][] externGroup
= new String
[externList
.size()][4];
1272 for (int i
= 0; i
< externList
.size(); i
++) {
1273 String driverBindingStr
= externList
.get(i
).getDriverBinding();
1274 if ( driverBindingStr
!= null){
1275 externGroup
[i
][0] = driverBindingStr
;
1277 externGroup
[i
][0] = null;
1280 String componentNameStr
= externList
.get(i
).getComponentName();
1281 if (componentNameStr
!= null) {
1282 externGroup
[i
][1] = componentNameStr
;
1284 externGroup
[i
][1] = null;
1287 String driverConfigStr
= externList
.get(i
).getDriverConfig();
1288 if (driverConfigStr
!= null) {
1289 externGroup
[i
][2] = driverConfigStr
;
1291 externGroup
[i
][2] = null;
1294 String driverDiagStr
= externList
.get(i
).getDriverDiag();
1295 if (driverDiagStr
!= null) {
1296 externGroup
[i
][3] = driverDiagStr
;
1298 externGroup
[i
][3] = null;
1305 * Retrive SetVirtualAddressMapCallBack names
1307 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1309 * @returns null if nothing is there
1311 public String
[] getSetVirtualAddressMapCallBackArray() {
1312 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1313 return getCNames("Externs", xPath
);
1317 * Retrive ExitBootServicesCallBack names
1319 * @returns ExitBootServicesCallBack name list if elements are found at the
1321 * @returns null if nothing is there
1323 public String
[] getExitBootServicesCallBackArray() {
1324 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1325 return getCNames("Externs", xPath
);
1329 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1332 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1334 public CommonDefinition
.PCD_DRIVER_TYPE
getPcdDriverType() {
1335 String
[] xPath
= new String
[] {"/PcdIsDriver"};
1336 Object
[] results
= get ("Externs", xPath
);
1338 if (results
!= null && results
.length
!= 0) {
1339 PcdDriverTypes type
= (PcdDriverTypes
) results
[0];
1340 String typeStr
= type
.enumValue().toString();
1341 if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
.toString())) {
1342 return CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
;
1343 } else if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
.toString())) {
1344 return CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
;
1346 return CommonDefinition
.PCD_DRIVER_TYPE
.UNKNOWN_PCD_DRIVER
;
1349 return CommonDefinition
.PCD_DRIVER_TYPE
.NOT_PCD_DRIVER
;
1353 * Retrieve module surface area file information
1355 * @returns ModuleSA objects list if elements are found at the known xpath
1356 * @returns Empty ModuleSA list if nothing is there
1358 public Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() throws EdkException
{
1359 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1360 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1362 String fvBinding
= null;
1363 String saGuid
= null;
1364 String saVersion
= null;
1365 String pkgGuid
= null;
1366 String pkgVersion
= null;
1368 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1370 if (result
== null) {
1371 return fpdModuleMap
;
1374 for (int i
= 0; i
< result
.length
; i
++) {
1376 // Get Fpd SA Module element node and add to ObjectMap.
1378 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1379 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1380 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1381 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1383 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1384 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1386 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1387 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1391 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1393 if (moduleSA
.isSetSupArchList()) {
1394 arch
= moduleSA
.getSupArchList().toString();
1401 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1403 saGuid
= moduleSA
.getModuleGuid();
1404 pkgGuid
= moduleSA
.getPackageGuid();
1405 pkgVersion
= moduleSA
.getPackageVersion();
1408 // Create Module Identification which have class member of package
1411 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1412 GlobalData
.refreshPackageIdentification(pkgId
);
1414 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1415 saId
.setPackage(pkgId
);
1416 GlobalData
.refreshModuleIdentification(saId
);
1421 // Create FpdModule Identification which have class member of module
1424 String
[] archList
= new String
[0];
1425 if (arch
== null || arch
.trim().length() == 0) {
1426 archList
= GlobalData
.getToolChainInfo().getArchs();
1428 archList
= arch
.split(" ");
1430 for (int j
= 0; j
< archList
.length
; j
++) {
1431 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1433 if (fvBinding
!= null) {
1434 fpdSaId
.setFvBinding(fvBinding
);
1438 // Put element to Map<FpdModuleIdentification, Map<String,
1441 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1444 return fpdModuleMap
;
1448 * Retrieve valid image names
1450 * @returns valid iamges name list if elements are found at the known xpath
1451 * @returns empty list if nothing is there
1453 public String
[] getFpdValidImageNames() {
1454 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1456 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1457 if (queryResult
== null) {
1458 return new String
[0];
1461 String
[] result
= new String
[queryResult
.length
];
1462 for (int i
= 0; i
< queryResult
.length
; i
++) {
1463 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1469 public Node
getFpdUserExtensionPreBuild() {
1470 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1472 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1473 if (queryResult
== null || queryResult
.length
== 0) {
1476 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1478 return a
.getDomNode();
1481 public Node
getFpdUserExtensionPostBuild() {
1482 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1484 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1485 if (queryResult
== null || queryResult
.length
== 0) {
1488 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1490 return a
.getDomNode();
1494 * Retrieve FV image option information
1499 * @returns option name/value list if elements are found at the known xpath
1500 * @returns empty list if nothing is there
1502 public String
[][] getFpdOptions(String fvName
) {
1503 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1504 + fvName
+ "']/FvImageOptions" };
1505 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1506 if (queryResult
== null) {
1507 return new String
[0][];
1509 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1510 for (int i
= 0; i
< queryResult
.length
; i
++) {
1511 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1512 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1513 .getNameValueList();
1514 Iterator iter
= namevalues
.iterator();
1515 while (iter
.hasNext()) {
1516 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1518 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1521 String
[][] result
= new String
[list
.size()][2];
1522 for (int i
= 0; i
< list
.size(); i
++) {
1523 result
[i
][0] = list
.get(i
)[0];
1524 result
[i
][1] = list
.get(i
)[1];
1530 public XmlObject
getFpdBuildOptions() {
1531 String
[] xPath
= new String
[] { "/BuildOptions" };
1533 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1535 if (queryResult
== null || queryResult
.length
== 0) {
1538 return (XmlObject
)queryResult
[0];
1541 public PlatformIdentification
getFpdHeader() {
1542 String
[] xPath
= new String
[] { "/PlatformHeader" };
1544 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1546 if (returns
== null || returns
.length
== 0) {
1549 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1551 String name
= header
.getPlatformName();
1553 String guid
= header
.getGuidValue();
1555 String version
= header
.getVersion();
1557 return new PlatformIdentification(name
, guid
, version
);
1561 * Retrieve FV image attributes information
1566 * @returns attribute name/value list if elements are found at the known
1568 * @returns empty list if nothing is there
1570 public String
[][] getFpdAttributes(String fvName
) {
1571 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1572 + fvName
+ "']/FvImageOptions" };
1573 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1574 if (queryResult
== null) {
1575 return new String
[0][];
1577 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1578 for (int i
= 0; i
< queryResult
.length
; i
++) {
1580 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1581 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1582 Iterator iter
= namevalues
.iterator();
1583 while (iter
.hasNext()) {
1584 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1586 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1589 String
[][] result
= new String
[list
.size()][2];
1590 for (int i
= 0; i
< list
.size(); i
++) {
1591 result
[i
][0] = list
.get(i
)[0];
1592 result
[i
][1] = list
.get(i
)[1];
1598 * Retrieve flash definition file name
1600 * @returns file name if elements are found at the known xpath
1601 * @returns null if nothing is there
1603 public String
getFlashDefinitionFile() {
1604 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1606 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1607 if (queryResult
== null || queryResult
.length
== 0) {
1611 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1612 return filename
.getStringValue();
1615 public String
[][] getFpdGlobalVariable() {
1616 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1617 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1618 if (queryResult
== null) {
1619 return new String
[0][];
1622 String
[][] result
= new String
[queryResult
.length
][2];
1624 for (int i
= 0; i
< queryResult
.length
; i
++) {
1625 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1626 result
[i
][0] = item
.getName();
1627 result
[i
][1] = item
.getValue();
1633 * Retrieve FV image component options
1638 * @returns name/value pairs list if elements are found at the known xpath
1639 * @returns empty list if nothing is there
1641 public String
[][] getFpdComponents(String fvName
) {
1642 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1643 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1644 if (queryResult
== null) {
1645 return new String
[0][];
1648 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1649 for (int i
= 0; i
< queryResult
.length
; i
++) {
1650 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1651 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1652 Iterator iter
= namevalues
.iterator();
1653 while (iter
.hasNext()) {
1654 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1656 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1659 String
[][] result
= new String
[list
.size()][2];
1660 for (int i
= 0; i
< list
.size(); i
++) {
1661 result
[i
][0] = list
.get(i
)[0];
1662 result
[i
][1] = list
.get(i
)[1];
1668 * Retrieve PCD tokens
1670 * @returns CName/ItemType pairs list if elements are found at the known
1672 * @returns null if nothing is there
1674 public String
[][] getPcdTokenArray() {
1675 String
[] xPath
= new String
[] { "/PcdData" };
1677 Object
[] returns
= get("PCDs", xPath
);
1678 if (returns
== null || returns
.length
== 0) {
1686 * Retrieve MAS header
1691 public ModuleIdentification
getMsaHeader() {
1692 String
[] xPath
= new String
[] { "/" };
1693 Object
[] returns
= get("MsaHeader", xPath
);
1695 if (returns
== null || returns
.length
== 0) {
1699 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1701 // Get BaseName, ModuleType, GuidValue, Version
1702 // which in MsaHeader.
1704 String name
= msaHeader
.getModuleName();
1705 String moduleType
= msaHeader
.getModuleType().toString();
1706 String guid
= msaHeader
.getGuidValue();
1707 String version
= msaHeader
.getVersion();
1709 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1712 moduleId
.setModuleType(moduleType
);
1718 * Retrieve Extern Specification
1722 * @return String[] If have specification element in the <extern> String[0]
1723 * If no specification element in the <extern>
1727 public String
[] getExternSpecificaiton() {
1728 String
[] xPath
= new String
[] { "/Specification" };
1730 Object
[] queryResult
= get("Externs", xPath
);
1731 if (queryResult
== null) {
1732 return new String
[0];
1735 String
[] specificationList
= new String
[queryResult
.length
];
1736 for (int i
= 0; i
< queryResult
.length
; i
++) {
1737 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1740 return specificationList
;
1744 * Retreive MsaFile which in SPD
1747 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1748 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1750 public String
[] getSpdMsaFile() {
1751 String
[] xPath
= new String
[] { "/MsaFiles" };
1753 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1754 if (returns
== null) {
1755 return new String
[0];
1758 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1760 return filenameList
.toArray(new String
[filenameList
.size()]);
1766 public Map
<String
, String
[]> getSpdLibraryClasses() {
1767 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1769 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1772 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1774 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1776 if (returns
== null) {
1777 return libClassHeaderMap
;
1780 for (int i
= 0; i
< returns
.length
; i
++) {
1781 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1782 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1783 .getIncludeHeader() });
1785 return libClassHeaderMap
;
1791 public Map
<String
, String
> getSpdPackageHeaderFiles() {
1792 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1794 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1797 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1799 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1801 if (returns
== null) {
1802 return packageIncludeMap
;
1805 for (int i
= 0; i
< returns
.length
; i
++) {
1806 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1807 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1808 includeHeader
.getStringValue());
1810 return packageIncludeMap
;
1813 public PackageIdentification
getSpdHeader() {
1814 String
[] xPath
= new String
[] { "/SpdHeader" };
1816 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1818 if (returns
== null || returns
.length
== 0) {
1822 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1824 String name
= header
.getPackageName();
1826 String guid
= header
.getGuidValue();
1828 String version
= header
.getVersion();
1830 return new PackageIdentification(name
, guid
, version
);
1836 public Map
<String
, String
[]> getSpdGuid() {
1837 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1839 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1842 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1844 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1845 if (returns
== null) {
1849 for (int i
= 0; i
< returns
.length
; i
++) {
1850 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1851 String
[] guidPair
= new String
[2];
1852 guidPair
[0] = entry
.getCName();
1853 guidPair
[1] = entry
.getGuidValue();
1854 guidDeclMap
.put(entry
.getCName(), guidPair
);
1862 public Map
<String
, String
[]> getSpdProtocol() {
1863 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1865 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1868 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1870 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1872 if (returns
== null) {
1876 for (int i
= 0; i
< returns
.length
; i
++) {
1877 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1878 String
[] protocolPair
= new String
[2];
1880 protocolPair
[0] = entry
.getCName();
1881 protocolPair
[1] = entry
.getGuidValue();
1882 protoclMap
.put(entry
.getCName(), protocolPair
);
1888 * getSpdPpi() Retrieve the SPD PPI Entry
1891 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1892 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1895 public Map
<String
, String
[]> getSpdPpi() {
1896 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1898 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1901 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1903 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1905 if (returns
== null) {
1909 for (int i
= 0; i
< returns
.length
; i
++) {
1910 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1911 String
[] ppiPair
= new String
[2];
1912 ppiPair
[0] = entry
.getCName();
1913 ppiPair
[1] = entry
.getGuidValue();
1914 ppiMap
.put(entry
.getCName(), ppiPair
);
1920 * Retrieve module Guid string
1922 * @returns GUILD string if elements are found at the known xpath
1923 * @returns null if nothing is there
1925 public String
getModuleGuid() {
1926 String
[] xPath
= new String
[] { "" };
1928 Object
[] returns
= get("MsaHeader", xPath
);
1929 if (returns
!= null && returns
.length
> 0) {
1930 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1941 public ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1942 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1943 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1944 if (result
!= null) {
1945 return (ModuleSADocument
.ModuleSA
[]) result
;
1947 return new ModuleSADocument
.ModuleSA
[0];
1951 Get name array of PCD in a module. In one module, token space
1952 is same, and token name should not be conflicted.
1956 public String
[] getModulePcdEntryNameArray() {
1957 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1960 String
[] xPath
= new String
[] {"/PcdEntry"};
1961 Object
[] returns
= get ("PcdCoded", xPath
);
1963 if (returns
== null) {
1964 return new String
[0];
1967 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1968 results
= new String
[pcdEntries
.length
];
1970 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1971 results
[index
] = pcdEntries
[index
].getCName();
1977 Search in a List for a given string
1981 public boolean contains(List list
, String str
) {
1982 if (list
== null || list
.size()== 0) {
1985 Iterator it
= list
.iterator();
1986 while (it
.hasNext()) {
1987 String s
= (String
)it
.next();
1988 if (s
.equalsIgnoreCase(str
)) {
1996 public boolean isHaveTianoR8FlashMap(){
1997 String
[] xPath
= new String
[] {"/"};
1998 Object
[] returns
= get ("Externs", xPath
);
2000 if (returns
== null) {
2004 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
2006 if (ext
.getTianoR8FlashMapH()){
2013 public Node
getPeiApriori(String fvName
) {
2014 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName
+ "']" };
2015 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2017 if (result
== null || result
.length
== 0) {
2021 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2023 return a
.getDomNode();
2026 public Node
getDxeApriori(String fvName
) {
2027 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2028 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2030 if (result
== null || result
.length
== 0) {
2034 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2036 return a
.getDomNode();
2039 public Node
getFpdModuleSequence(String fvName
) {
2040 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2041 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2043 if (result
== null || result
.length
== 0) {
2047 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2049 return a
.getDomNode();
2053 Get the value of PCD by PCD cName
2055 @return PcdValue String of PcdComponentName
2056 null If don't find ComponentName Pcd
2058 public String
getPcdValueBycName(String cName
){
2059 String
[] xPath
= new String
[] { "/PcdData" };
2060 Object
[] returns
= get("PcdBuildDefinition", xPath
);
2061 if (returns
== null || returns
.length
== 0) {
2064 for (int i
= 0; i
< returns
.length
; i
++) {
2065 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)returns
[i
];
2066 if (pcdData
.getCName().equalsIgnoreCase(cName
)){
2067 return pcdData
.getValue();