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;
81 private StringBuffer normQueryString
= new StringBuffer(4096);
82 private Pattern xPathPattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
85 * Set a Surface Area document for query later
88 * A Surface Area document in TopLevelElementName/XmlObject
91 public SurfaceAreaQuery(Map
<String
, XmlObject
> map
) {
93 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
98 * Push current used Surface Area document into query stack. The given new
99 * document will be used for any immediately followed getXXX() callings,
100 * untill pop() is called.
103 * The TopLevelElementName/XmlObject format of a Surface Area
106 public void push(Map
<String
, XmlObject
> newMap
) {
107 mapStack
.push(this.map
);
112 * Discard current used Surface Area document and use the top document in
116 this.map
= mapStack
.pop();
120 // / Convert xPath to be namespace qualified, which is necessary for
122 // / selectPath(). For example, converting /MsaHeader/ModuleType to
123 // / /ns:MsaHeader/ns:ModuleType
125 private String
normalizeQueryString(String
[] exp
, String from
) {
126 normQueryString
.setLength(0);
129 while (i
< exp
.length
) {
130 String newExp
= from
+ exp
[i
];
131 Matcher matcher
= xPathPattern
.matcher(newExp
);
133 while (matcher
.find()) {
134 String starter
= newExp
.substring(matcher
.start(1), matcher
136 String seperator
= newExp
.substring(matcher
.start(2), matcher
138 String token
= newExp
.substring(matcher
.start(3), matcher
141 normQueryString
.append(starter
);
142 normQueryString
.append(seperator
);
143 normQueryString
.append(nsPrefix
);
144 normQueryString
.append(":");
145 normQueryString
.append(token
);
149 if (i
< exp
.length
) {
150 normQueryString
.append(" | ");
154 return normQueryString
.toString();
158 * Search all XML documents stored in "map" for the specified xPath, using
159 * relative path (starting with '$this')
162 * xpath query string array
163 * @returns An array of XmlObject if elements are found at the specified
165 * @returns NULL if nothing is at the specified xpath
167 public Object
[] get(String
[] xPath
) {
172 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
173 List
<Object
> result
= new ArrayList
<Object
>();
174 for (int i
= 0; i
< keys
.length
; ++i
) {
175 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
176 if (rootNode
== null) {
180 String query
= queryDeclaration
181 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
182 XmlObject
[] tmp
= rootNode
.selectPath(query
);
183 for (int j
= 0; j
< tmp
.length
; ++j
) {
184 result
.add((Object
)tmp
[j
]);
188 int size
= result
.size();
193 return (Object
[]) result
.toArray(new Object
[size
]);
197 * Search XML documents named by "rootName" for the given xPath, using
198 * relative path (starting with '$this')
201 * The top level element name
203 * The xpath query string array
204 * @returns An array of XmlObject if elements are found at the given xpath
205 * @returns NULL if nothing is found at the given xpath
207 public Object
[] get(String rootName
, String
[] xPath
) {
212 XmlObject root
= (XmlObject
) map
.get(rootName
);
217 String query
= queryDeclaration
218 + normalizeQueryString(xPath
, "$this/" + rootName
);
219 XmlObject
[] result
= root
.selectPath(query
);
220 if (result
.length
> 0) {
221 return (Object
[])result
;
224 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
225 result
= root
.selectPath(query
);
226 if (result
.length
> 0) {
227 return (Object
[])result
;
234 * Retrieve SourceFiles/Filename for specified ARCH type
238 * @returns An 2 dimension string array if elements are found at the known
240 * @returns NULL if nothing is found at the known xpath
242 public String
[][] getSourceFiles(String arch
) {
246 xPath
= new String
[] { "/Filename" };
248 returns
= get("SourceFiles", xPath
);
250 if (returns
== null || returns
.length
== 0) {
251 return new String
[0][3];
254 Filename
[] sourceFileNames
= (Filename
[]) returns
;
255 List
<String
[]> outputList
= new ArrayList
<String
[]>();
256 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
257 List archList
= sourceFileNames
[i
].getSupArchList();
258 if (arch
== null || arch
.trim().equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
259 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(), sourceFileNames
[i
].getStringValue(), sourceFileNames
[i
].getToolChainFamily()});
263 String
[][] outputString
= new String
[outputList
.size()][3];
264 for (int index
= 0; index
< outputList
.size(); index
++) {
266 // ToolCode (FileType)
268 outputString
[index
][0] = outputList
.get(index
)[0];
270 // File name (relative to MODULE_DIR)
272 outputString
[index
][1] = outputList
.get(index
)[1];
276 outputString
[index
][2] = outputList
.get(index
)[2];
282 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
284 * @returns Directory names array if elements are found at the known xpath
285 * @returns Empty if nothing is found at the known xpath
287 public String
getFpdOutputDirectory() {
288 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
290 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
291 if (returns
== null || returns
.length
== 0) {
294 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
295 return item
.getOutputDirectory();
298 public String
getFpdIntermediateDirectories() {
299 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
301 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
302 if (returns
== null || returns
.length
== 0) {
305 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
306 if(item
.getIntermediateDirectories() == null) {
310 return item
.getIntermediateDirectories().toString();
314 public String
getModuleFfsKeyword() {
315 String
[] xPath
= new String
[] { "/" };
317 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
318 if (returns
== null || returns
.length
== 0) {
321 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
322 return item
.getFfsFormatKey();
325 public String
getModuleFvBindingKeyword() {
326 String
[] xPath
= new String
[] { "/" };
328 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
329 if (returns
== null || returns
.length
== 0) {
332 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
333 return item
.getFvBinding();
336 public List
getModuleSupportedArchs() {
337 String
[] xPath
= new String
[] { "/" };
339 Object
[] returns
= get("ModuleDefinitions", xPath
);
340 if (returns
== null || returns
.length
== 0) {
343 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
344 return item
.getSupportedArchitectures();
347 public BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
348 String
[] xPath
= new String
[] {"/Ffs"};
350 Object
[] returns
= get("BuildOptions", xPath
);
351 if (returns
== null || returns
.length
== 0) {
352 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
354 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
357 public String
getModuleOutputFileBasename() {
358 String
[] xPath
= new String
[] { "/" };
360 Object
[] returns
= get("ModuleDefinitions", xPath
);
361 if (returns
== null || returns
.length
== 0) {
364 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
365 return item
.getOutputFileBasename();
369 * Retrieve BuildOptions/Option or Arch/Option
371 * @param toolChainFamilyFlag
372 * if true, retrieve options for toolchain family; otherwise for
375 * @returns String[][5] name, target, toolchain, arch, coommand of options
376 * if elements are found at the known xpath. String[0][] if dont
379 * @returns Empty array if nothing is there
381 public String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
382 String target
= null;
383 String toolchain
= null;
384 String toolchainFamily
= null;
385 List
<String
> archList
= null;
387 String optionName
= null;
389 Object
[] returns
= get(from
, xPath
);
390 if (returns
== null) {
391 return new String
[0][5];
394 List
<String
[]> optionList
= new ArrayList
<String
[]>();
395 OptionDocument
.Option option
;
397 for (int i
= 0; i
< returns
.length
; i
++) {
398 option
= (OptionDocument
.Option
) returns
[i
];
401 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
403 // put to result[][5] array in above order.
406 if (option
.getBuildTargets() == null) {
410 target
= option
.getBuildTargets().toString();
412 if (target
!= null) {
413 targetList
= target
.split(" ");
415 targetList
= new String
[1];
416 targetList
[0] = null;
419 if (toolChainFamilyFlag
) {
420 toolchainFamily
= option
.getToolChainFamily();
421 if (toolchainFamily
!= null) {
422 toolchain
= toolchainFamily
.toString();
427 toolchain
= option
.getTagName();
430 archList
= new ArrayList
<String
>();
431 List archEnumList
= option
.getSupArchList();
432 if (archEnumList
== null) {
435 //archList.addAll(archEnumList);
436 Iterator it
= archEnumList
.iterator();
437 while (it
.hasNext()) {
438 String archType
= (String
)it
.next();
439 archList
.add(archType
);
443 cmd
= option
.getToolCode();
445 optionName
= option
.getStringValue();
446 for (int t
= 0; t
< targetList
.length
; t
++) {
447 for (int j
= 0; j
< archList
.size(); j
++) {
448 optionList
.add(new String
[] { targetList
[t
],
449 toolchain
, archList
.get(j
), cmd
, optionName
});
454 String
[][] result
= new String
[optionList
.size()][5];
455 for (int i
= 0; i
< optionList
.size(); i
++) {
456 result
[i
][0] = optionList
.get(i
)[0];
457 result
[i
][1] = optionList
.get(i
)[1];
458 result
[i
][2] = optionList
.get(i
)[2];
459 result
[i
][3] = optionList
.get(i
)[3];
460 result
[i
][4] = optionList
.get(i
)[4];
465 public String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
468 if (toolChainFamilyFlag
== true) {
469 xPath
= new String
[] {
470 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
471 "/Options/Option[@ToolChainFamily]", };
473 xPath
= new String
[] {
474 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
475 "/Options/Option[@TagName]", };
477 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
480 public String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
483 if (toolChainFamilyFlag
== true) {
484 xPath
= new String
[] {
485 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
486 "/BuildOptions/Options/Option[@ToolChainFamily]", };
488 xPath
= new String
[] {
489 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
490 "/BuildOptions/Options/Option[@TagName]", };
493 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
496 public String
[][] getMsaBuildOptions(boolean toolChainFamilyFlag
) {
499 if (toolChainFamilyFlag
== true) {
500 xPath
= new String
[] {
501 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
502 "/Options/Option[@ToolChainFamily]", };
504 xPath
= new String
[] {
505 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
506 "/Options/Option[@TagName]", };
509 return getOptions("ModuleBuildOptions", xPath
, toolChainFamilyFlag
);
512 public ToolChainInfo
getFpdToolChainInfo() {
513 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
515 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
516 if (returns
== null || returns
.length
== 0) {
520 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
521 ToolChainInfo toolChainInfo
= new ToolChainInfo();
522 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
523 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
524 toolChainInfo
.addTagnames((String
)null);
525 return toolChainInfo
;
529 * Retrieve <xxxHeader>/ModuleType
531 * @returns The module type name if elements are found at the known xpath
532 * @returns null if nothing is there
534 public String
getModuleType() {
535 String
[] xPath
= new String
[] { "/ModuleType" };
537 Object
[] returns
= get(xPath
);
538 if (returns
!= null && returns
.length
> 0) {
539 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
540 return type
.enumValue().toString();
547 * Retrieve PackageDependencies/Package
552 * @returns package name list if elements are found at the known xpath
553 * @returns null if nothing is there
555 public PackageIdentification
[] getDependencePkg(String arch
) throws EdkException
{
557 String packageGuid
= null;
558 String packageVersion
= null;
561 xPath
= new String
[] { "/Package" };
563 Object
[] returns
= get("PackageDependencies", xPath
);
564 if (returns
== null) {
565 return new PackageIdentification
[0];
569 // Get packageIdentification
571 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
572 for (int i
= 0; i
< returns
.length
; i
++) {
573 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
574 List archList
= item
.getSupArchList();
575 if (arch
== null || archList
== null || contains(archList
, arch
)) {
576 packageGuid
= item
.getPackageGuid();
577 packageVersion
= item
.getPackageVersion();
578 PackageIdentification pkgId
= new PackageIdentification(null, packageGuid
, packageVersion
);
579 GlobalData
.refreshPackageIdentification(pkgId
);
580 packageIdList
.add(pkgId
);
584 return packageIdList
.toArray(new PackageIdentification
[packageIdList
.size()]);
588 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
591 * Library class usage
593 * @returns LibraryClass objects list if elements are found at the known
595 * @returns null if nothing is there
597 public String
[] getLibraryClasses(String usage
, String arch
) {
599 if (usage
== null || usage
.equals("")) {
600 xPath
= new String
[] { "/LibraryClass" };
602 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
605 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
606 if (returns
== null || returns
.length
== 0) {
607 return new String
[0];
610 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
611 List
<String
> libraryClassName
= new ArrayList
<String
>();
612 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
613 List archList
= libraryClassList
[i
].getSupArchList();
615 if (arch
== null || contains(archList
, arch
)) {
616 libraryClassName
.add(libraryClassList
[i
].getKeyword());
620 String
[] libraryArray
= new String
[libraryClassName
.size()];
621 libraryClassName
.toArray(libraryArray
);
626 * Retrieve ModuleEntryPoint names
628 * @returns ModuleEntryPoint name list if elements are found at the known
630 * @returns null if nothing is there
632 public String
[] getModuleEntryPointArray() {
633 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
635 Object
[] returns
= get("Externs", xPath
);
637 if (returns
!= null && returns
.length
> 0) {
638 String
[] entryPoints
= new String
[returns
.length
];
640 for (int i
= 0; i
< returns
.length
; ++i
) {
641 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
651 * retrieve Protocol for specified usage
654 * Protocol usage arch Architecture
656 * @returns Protocol String list if elements are found at the known xpath
657 * @returns String[0] if nothing is there
659 public String
[] getProtocolArray(String arch
, String usage
) {
661 String usageXpath
= "";
662 String archXpath
= "";
664 if (arch
== null || arch
.equals("")) {
665 return new String
[0];
667 archXpath
= "/Protocol";
668 if (usage
!= null && !usage
.equals("")) {
669 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
670 xPath
= new String
[] { usageXpath
, archXpath
};
672 return getProtocolArray(arch
);
677 Object
[] returns
= get("Protocols", xPath
);
678 if (returns
== null) {
679 return new String
[0];
681 Protocol
[] protocolList
= (Protocol
[]) returns
;
683 String
[] protocolArray
= new String
[returns
.length
];
684 for (int i
= 0; i
< returns
.length
; i
++) {
685 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
687 return protocolArray
;
691 * retrieve Protocol for specified usage
696 * @returns Protocol String list if elements are found at the known xpath
697 * @returns String[0] if nothing is there
699 public String
[] getProtocolArray(String arch
) {
702 if (arch
== null || arch
.equals("")) {
703 return new String
[0];
705 xPath
= new String
[] { "/Protocol" };
708 Object
[] returns
= get("Protocols", xPath
);
709 if (returns
== null) {
710 return new String
[0];
712 Protocol
[] returnlList
= (Protocol
[]) returns
;
714 List
<String
> protocolList
= new ArrayList
<String
>();
716 for (int i
= 0; i
< returns
.length
; i
++) {
717 List archList
= returnlList
[i
].getSupArchList();
718 if (archList
== null || contains(archList
, arch
)){
719 protocolList
.add(returnlList
[i
].getProtocolCName());
722 String
[] protocolArray
= new String
[protocolList
.size()];
723 for (int i
= 0; i
< protocolList
.size(); i
++) {
724 protocolArray
[i
] = protocolList
.get(i
);
726 return protocolArray
;
730 * Retrieve ProtocolNotify for specified usage
733 * ProtocolNotify usage
735 * @returns String[] if elements are found at the known xpath
736 * @returns String[0] if nothing is there
738 public String
[] getProtocolNotifyArray(String arch
) {
741 if (arch
== null || arch
.equals("")) {
742 return new String
[0];
744 xPath
= new String
[] { "/ProtocolNotify" };
747 Object
[] returns
= get("Protocols", xPath
);
748 if (returns
== null) {
749 return new String
[0];
752 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
754 for (int i
= 0; i
< returns
.length
; i
++) {
755 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
756 if (archList
== null || contains(archList
, arch
)){
757 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
761 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
762 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
763 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
765 return protocolNotifyArray
;
769 * Retrieve ProtocolNotify for specified usage
772 * ProtocolNotify usage
774 * @returns String[] if elements are found at the known xpath
775 * @returns String[0] if nothing is there
777 public String
[] getProtocolNotifyArray(String arch
, String usage
) {
783 if (arch
== null || arch
.equals("")) {
784 return new String
[0];
786 archXpath
= "/ProtocolNotify";
787 if (usage
!= null && !usage
.equals("")) {
788 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
789 xPath
= new String
[] { archXpath
, usageXpath
};
791 return getProtocolNotifyArray(arch
);
795 Object
[] returns
= get("Protocols", xPath
);
796 if (returns
== null) {
797 return new String
[0];
800 String
[] protocolNotifyList
= new String
[returns
.length
];
802 for (int i
= 0; i
< returns
.length
; i
++) {
803 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
805 return protocolNotifyList
;
809 * Retrieve ModuleUnloadImage names
811 * @returns ModuleUnloadImage name list if elements are found at the known
813 * @returns null if nothing is there
815 public String
[] getModuleUnloadImageArray() {
816 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
818 Object
[] returns
= get("Externs", xPath
);
819 if (returns
!= null && returns
.length
> 0) {
820 String
[] stringArray
= new String
[returns
.length
];
821 CNameType
[] doc
= (CNameType
[]) returns
;
823 for (int i
= 0; i
< returns
.length
; ++i
) {
824 stringArray
[i
] = doc
[i
].getStringValue();
836 * @returns Extern objects list if elements are found at the known xpath
837 * @returns null if nothing is there
839 public ExternsDocument
.Externs
.Extern
[] getExternArray() {
840 String
[] xPath
= new String
[] { "/Extern" };
842 Object
[] returns
= get("Externs", xPath
);
843 if (returns
!= null && returns
.length
> 0) {
844 return (ExternsDocument
.Externs
.Extern
[]) returns
;
851 * Retrieve PpiNotify for specified arch
856 * @returns String[] if elements are found at the known xpath
857 * @returns String[0] if nothing is there
859 public String
[] getPpiNotifyArray(String arch
) {
862 if (arch
== null || arch
.equals("")) {
863 return new String
[0];
865 xPath
= new String
[] { "/PpiNotify" };
868 Object
[] returns
= get("PPIs", xPath
);
869 if (returns
== null) {
870 return new String
[0];
874 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
875 for (int i
= 0; i
< returns
.length
; i
++) {
876 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
877 if (archList
== null || contains(archList
, arch
)){
878 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
882 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
883 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
884 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
887 return ppiNotifyArray
;
891 * Retrieve PpiNotify for specified usage and arch
894 * PpiNotify arch usage PpiNotify usage
897 * @returns String[] if elements are found at the known xpath
898 * @returns String[0] if nothing is there
900 public String
[] getPpiNotifyArray(String arch
, String usage
) {
906 if (arch
== null || arch
.equals("")) {
907 return new String
[0];
909 archXpath
= "/PpiNotify";
910 if (usage
!= null && !usage
.equals("")) {
911 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
912 xPath
= new String
[] { archXpath
, usageXpath
};
914 return getProtocolNotifyArray(arch
);
918 Object
[] returns
= get("PPIs", xPath
);
919 if (returns
== null) {
920 return new String
[0];
923 String
[] ppiNotifyList
= new String
[returns
.length
];
925 for (int i
= 0; i
< returns
.length
; i
++) {
926 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
928 return ppiNotifyList
;
932 * Retrieve Ppi for specified arch
937 * @returns String[] if elements are found at the known xpath
938 * @returns String[0] if nothing is there
940 public String
[] getPpiArray(String arch
) {
943 if (arch
== null || arch
.equals("")) {
944 return new String
[0];
946 xPath
= new String
[] { "/Ppi" };
949 Object
[] returns
= get("PPIs", xPath
);
950 if (returns
== null) {
951 return new String
[0];
954 List
<String
> ppiList
= new ArrayList
<String
>();
955 for (int i
= 0; i
< returns
.length
; i
++) {
956 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
957 if (archList
== null || contains(archList
, arch
)){
958 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
962 String
[] ppiArray
= new String
[ppiList
.size()];
963 for (int i
= 0; i
< ppiList
.size(); i
++) {
964 ppiArray
[i
] = ppiList
.get(i
);
970 * Retrieve PpiNotify for specified usage and arch
973 * PpiNotify arch usage PpiNotify usage
976 * @returns String[] if elements are found at the known xpath
977 * @returns String[0] if nothing is there
979 public String
[] getPpiArray(String arch
, String usage
) {
985 if (arch
== null || arch
.equals("")) {
986 return new String
[0];
989 if (usage
!= null && !usage
.equals("")) {
990 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
991 xPath
= new String
[] { archXpath
, usageXpath
};
993 return getProtocolNotifyArray(arch
);
997 Object
[] returns
= get("PPIs", xPath
);
998 if (returns
== null) {
999 return new String
[0];
1002 String
[] ppiList
= new String
[returns
.length
];
1004 for (int i
= 0; i
< returns
.length
; i
++) {
1005 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1011 * Retrieve GuidEntry information for specified usage
1016 * @returns GuidEntry objects list if elements are found at the known xpath
1017 * @returns null if nothing is there
1019 public String
[] getGuidEntryArray(String arch
) {
1022 if (arch
== null || arch
.equals("")) {
1023 xPath
= new String
[] { "/GuidCNames" };
1025 xPath
= new String
[] { "/GuidCNames" };
1028 Object
[] returns
= get("Guids", xPath
);
1029 if (returns
== null) {
1030 return new String
[0];
1033 List
<String
> guidList
= new ArrayList
<String
>();
1034 for (int i
= 0; i
< returns
.length
; i
++) {
1035 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1036 if (archList
== null || contains(archList
, arch
)){
1037 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1041 String
[] guidArray
= new String
[guidList
.size()];
1042 for (int i
= 0; i
< guidList
.size(); i
++) {
1043 guidArray
[i
] = guidList
.get(i
);
1050 * Retrieve GuidEntry information for specified usage
1053 * GuidEntry arch usage GuidEntry usage
1055 * @returns GuidEntry objects list if elements are found at the known xpath
1056 * @returns null if nothing is there
1058 public String
[] getGuidEntryArray(String arch
, String usage
) {
1063 if (arch
== null || arch
.equals("")) {
1064 return new String
[0];
1066 archXpath
= "/GuidEntry";
1067 if (usage
!= null && !usage
.equals("")) {
1068 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1069 xPath
= new String
[] { archXpath
, usageXpath
};
1071 return getProtocolNotifyArray(arch
);
1075 Object
[] returns
= get("Guids", xPath
);
1076 if (returns
== null) {
1077 return new String
[0];
1080 String
[] guidList
= new String
[returns
.length
];
1082 for (int i
= 0; i
< returns
.length
; i
++) {
1083 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1089 * Retrieve Library instance information
1094 * Library instance usage
1096 * @returns library instance name list if elements are found at the known
1098 * @returns null if nothing is there
1100 public ModuleIdentification
[] getLibraryInstance(String arch
) throws EdkException
{
1102 String saGuid
= null;
1103 String saVersion
= null;
1104 String pkgGuid
= null;
1105 String pkgVersion
= null;
1107 if (arch
== null || arch
.equalsIgnoreCase("")) {
1108 xPath
= new String
[] { "/Instance" };
1111 // Since Schema don't have SupArchList now, so the follow Xpath is
1112 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1113 // don't have effect.
1115 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1119 Object
[] returns
= get("Libraries", xPath
);
1120 if (returns
== null || returns
.length
== 0) {
1121 return new ModuleIdentification
[0];
1124 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1125 for (int i
= 0; i
< returns
.length
; i
++) {
1126 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1127 saGuid
= library
.getModuleGuid();
1128 saVersion
= library
.getModuleVersion();
1130 pkgGuid
= library
.getPackageGuid();
1131 pkgVersion
= library
.getPackageVersion();
1133 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1135 PackageIdentification pkgId
= new PackageIdentification(null,
1136 pkgGuid
, pkgVersion
);
1137 GlobalData
.refreshPackageIdentification(pkgId
);
1138 saId
.setPackage(pkgId
);
1139 GlobalData
.refreshModuleIdentification(saId
);
1148 // / This method is used for retrieving the elements information which has
1149 // / CName sub-element
1151 private String
[] getCNames(String from
, String xPath
[]) {
1152 Object
[] returns
= get(from
, xPath
);
1153 if (returns
== null || returns
.length
== 0) {
1157 String
[] strings
= new String
[returns
.length
];
1158 for (int i
= 0; i
< returns
.length
; ++i
) {
1160 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1167 * Retrive library's constructor name
1169 * @returns constructor name list if elements are found at the known xpath
1170 * @returns null if nothing is there
1172 public String
getLibConstructorName() {
1173 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1175 Object
[] returns
= get("Externs", xPath
);
1176 if (returns
!= null && returns
.length
> 0) {
1177 CNameType constructor
= ((CNameType
) returns
[0]);
1178 return constructor
.getStringValue();
1185 * Retrive library's destructor name
1187 * @returns destructor name list if elements are found at the known xpath
1188 * @returns null if nothing is there
1190 public String
getLibDestructorName() {
1191 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1193 Object
[] returns
= get("Externs", xPath
);
1194 if (returns
!= null && returns
.length
> 0) {
1196 // Only support one Destructor function.
1198 CNameType destructor
= (CNameType
) returns
[0];
1199 return destructor
.getStringValue();
1206 * Retrive DriverBinding names
1208 * @returns DriverBinding name list if elements are found at the known xpath
1209 * @returns null if nothing is there
1211 public String
[] getDriverBindingArray() {
1212 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1213 return getCNames("Externs", xPath
);
1217 * Retrive ComponentName names
1219 * @returns ComponentName name list if elements are found at the known xpath
1220 * @returns null if nothing is there
1222 public String
[] getComponentNameArray() {
1223 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1224 return getCNames("Externs", xPath
);
1228 * Retrive DriverConfig names
1230 * @returns DriverConfig name list if elements are found at the known xpath
1231 * @returns null if nothing is there
1233 public String
[] getDriverConfigArray() {
1234 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1235 return getCNames("Externs", xPath
);
1239 * Retrive DriverDiag names
1241 * @returns DriverDiag name list if elements are found at the known xpath
1242 * @returns null if nothing is there
1244 public String
[] getDriverDiagArray() {
1245 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1246 return getCNames("Externs", xPath
);
1250 * Retrive DriverBinding, ComponentName, DriverConfig,
1251 * DriverDiag group array
1253 * @returns DriverBinding group name list if elements are found
1254 * at the known xpath
1255 * @returns null if nothing is there
1257 public String
[][] getExternProtocolGroup() {
1258 String
[] xPath
= new String
[] {"/Extern"};
1259 Object
[] returns
= get("Externs",xPath
);
1261 if (returns
== null) {
1262 return new String
[0][4];
1264 List
<Extern
> externList
= new ArrayList
<Extern
>();
1265 for (int i
= 0; i
< returns
.length
; i
++) {
1266 org
.tianocore
.ExternsDocument
.Externs
.Extern extern
= (org
.tianocore
.ExternsDocument
.Externs
.Extern
)returns
[i
];
1267 if (extern
.getDriverBinding() != null) {
1268 externList
.add(extern
);
1272 String
[][] externGroup
= new String
[externList
.size()][4];
1273 for (int i
= 0; i
< externList
.size(); i
++) {
1274 String driverBindingStr
= externList
.get(i
).getDriverBinding();
1275 if ( driverBindingStr
!= null){
1276 externGroup
[i
][0] = driverBindingStr
;
1278 externGroup
[i
][0] = null;
1281 String componentNameStr
= externList
.get(i
).getComponentName();
1282 if (componentNameStr
!= null) {
1283 externGroup
[i
][1] = componentNameStr
;
1285 externGroup
[i
][1] = null;
1288 String driverConfigStr
= externList
.get(i
).getDriverConfig();
1289 if (driverConfigStr
!= null) {
1290 externGroup
[i
][2] = driverConfigStr
;
1292 externGroup
[i
][2] = null;
1295 String driverDiagStr
= externList
.get(i
).getDriverDiag();
1296 if (driverDiagStr
!= null) {
1297 externGroup
[i
][3] = driverDiagStr
;
1299 externGroup
[i
][3] = null;
1306 * Retrive SetVirtualAddressMapCallBack names
1308 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1310 * @returns null if nothing is there
1312 public String
[] getSetVirtualAddressMapCallBackArray() {
1313 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1314 return getCNames("Externs", xPath
);
1318 * Retrive ExitBootServicesCallBack names
1320 * @returns ExitBootServicesCallBack name list if elements are found at the
1322 * @returns null if nothing is there
1324 public String
[] getExitBootServicesCallBackArray() {
1325 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1326 return getCNames("Externs", xPath
);
1330 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1333 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1335 public CommonDefinition
.PCD_DRIVER_TYPE
getPcdDriverType() {
1336 String
[] xPath
= new String
[] {"/PcdIsDriver"};
1337 Object
[] results
= get ("Externs", xPath
);
1339 if (results
!= null && results
.length
!= 0) {
1340 PcdDriverTypes type
= (PcdDriverTypes
) results
[0];
1341 String typeStr
= type
.enumValue().toString();
1342 if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
.toString())) {
1343 return CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
;
1344 } else if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
.toString())) {
1345 return CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
;
1347 return CommonDefinition
.PCD_DRIVER_TYPE
.UNKNOWN_PCD_DRIVER
;
1350 return CommonDefinition
.PCD_DRIVER_TYPE
.NOT_PCD_DRIVER
;
1354 * Retrieve module surface area file information
1356 * @returns ModuleSA objects list if elements are found at the known xpath
1357 * @returns Empty ModuleSA list if nothing is there
1359 public Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() throws EdkException
{
1360 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1361 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1363 String fvBinding
= null;
1364 String saGuid
= null;
1365 String saVersion
= null;
1366 String pkgGuid
= null;
1367 String pkgVersion
= null;
1369 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1371 if (result
== null) {
1372 return fpdModuleMap
;
1375 for (int i
= 0; i
< result
.length
; i
++) {
1377 // Get Fpd SA Module element node and add to ObjectMap.
1379 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1380 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1381 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1382 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1384 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1385 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1387 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1388 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1392 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1394 if (moduleSA
.isSetSupArchList()) {
1395 arch
= moduleSA
.getSupArchList().toString();
1402 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1404 saGuid
= moduleSA
.getModuleGuid();
1405 pkgGuid
= moduleSA
.getPackageGuid();
1406 pkgVersion
= moduleSA
.getPackageVersion();
1409 // Create Module Identification which have class member of package
1412 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1413 GlobalData
.refreshPackageIdentification(pkgId
);
1415 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1416 saId
.setPackage(pkgId
);
1417 GlobalData
.refreshModuleIdentification(saId
);
1422 // Create FpdModule Identification which have class member of module
1425 String
[] archList
= new String
[0];
1426 if (arch
== null || arch
.trim().length() == 0) {
1427 archList
= GlobalData
.getToolChainInfo().getArchs();
1429 archList
= arch
.split(" ");
1431 for (int j
= 0; j
< archList
.length
; j
++) {
1432 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1434 if (fvBinding
!= null) {
1435 fpdSaId
.setFvBinding(fvBinding
);
1439 // Put element to Map<FpdModuleIdentification, Map<String,
1442 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1445 return fpdModuleMap
;
1449 * Retrieve valid image names
1451 * @returns valid iamges name list if elements are found at the known xpath
1452 * @returns empty list if nothing is there
1454 public String
[] getFpdValidImageNames() {
1455 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1457 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1458 if (queryResult
== null) {
1459 return new String
[0];
1462 String
[] result
= new String
[queryResult
.length
];
1463 for (int i
= 0; i
< queryResult
.length
; i
++) {
1464 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1470 public Node
getFpdUserExtensionPreBuild() {
1471 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1473 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1474 if (queryResult
== null || queryResult
.length
== 0) {
1477 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1479 return a
.getDomNode();
1482 public Node
getFpdUserExtensionPostBuild() {
1483 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1485 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1486 if (queryResult
== null || queryResult
.length
== 0) {
1489 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1491 return a
.getDomNode();
1495 * Retrieve FV image option information
1500 * @returns option name/value list if elements are found at the known xpath
1501 * @returns empty list if nothing is there
1503 public String
[][] getFpdOptions(String fvName
) {
1504 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1505 + fvName
+ "']/FvImageOptions" };
1506 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1507 if (queryResult
== null) {
1508 return new String
[0][];
1510 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1511 for (int i
= 0; i
< queryResult
.length
; i
++) {
1512 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1513 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1514 .getNameValueList();
1515 Iterator iter
= namevalues
.iterator();
1516 while (iter
.hasNext()) {
1517 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1519 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1522 String
[][] result
= new String
[list
.size()][2];
1523 for (int i
= 0; i
< list
.size(); i
++) {
1524 result
[i
][0] = list
.get(i
)[0];
1525 result
[i
][1] = list
.get(i
)[1];
1531 public XmlObject
getFpdBuildOptions() {
1532 String
[] xPath
= new String
[] { "/BuildOptions" };
1534 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1536 if (queryResult
== null || queryResult
.length
== 0) {
1539 return (XmlObject
)queryResult
[0];
1542 public PlatformIdentification
getFpdHeader() {
1543 String
[] xPath
= new String
[] { "/PlatformHeader" };
1545 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1547 if (returns
== null || returns
.length
== 0) {
1550 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1552 String name
= header
.getPlatformName();
1554 String guid
= header
.getGuidValue();
1556 String version
= header
.getVersion();
1558 return new PlatformIdentification(name
, guid
, version
);
1562 * Retrieve FV image attributes information
1567 * @returns attribute name/value list if elements are found at the known
1569 * @returns empty list if nothing is there
1571 public String
[][] getFpdAttributes(String fvName
) {
1572 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1573 + fvName
+ "']/FvImageOptions" };
1574 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1575 if (queryResult
== null) {
1576 return new String
[0][];
1578 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1579 for (int i
= 0; i
< queryResult
.length
; i
++) {
1581 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1582 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1583 Iterator iter
= namevalues
.iterator();
1584 while (iter
.hasNext()) {
1585 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1587 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1590 String
[][] result
= new String
[list
.size()][2];
1591 for (int i
= 0; i
< list
.size(); i
++) {
1592 result
[i
][0] = list
.get(i
)[0];
1593 result
[i
][1] = list
.get(i
)[1];
1599 * Retrieve flash definition file name
1601 * @returns file name if elements are found at the known xpath
1602 * @returns null if nothing is there
1604 public String
getFlashDefinitionFile() {
1605 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1607 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1608 if (queryResult
== null || queryResult
.length
== 0) {
1612 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1613 return filename
.getStringValue();
1616 public String
[][] getFpdGlobalVariable() {
1617 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1618 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1619 if (queryResult
== null) {
1620 return new String
[0][];
1623 String
[][] result
= new String
[queryResult
.length
][2];
1625 for (int i
= 0; i
< queryResult
.length
; i
++) {
1626 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1627 result
[i
][0] = item
.getName();
1628 result
[i
][1] = item
.getValue();
1634 * Retrieve FV image component options
1639 * @returns name/value pairs list if elements are found at the known xpath
1640 * @returns empty list if nothing is there
1642 public String
[][] getFpdComponents(String fvName
) {
1643 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1644 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1645 if (queryResult
== null) {
1646 return new String
[0][];
1649 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1650 for (int i
= 0; i
< queryResult
.length
; i
++) {
1651 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1652 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1653 Iterator iter
= namevalues
.iterator();
1654 while (iter
.hasNext()) {
1655 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1657 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1660 String
[][] result
= new String
[list
.size()][2];
1661 for (int i
= 0; i
< list
.size(); i
++) {
1662 result
[i
][0] = list
.get(i
)[0];
1663 result
[i
][1] = list
.get(i
)[1];
1669 * Retrieve PCD tokens
1671 * @returns CName/ItemType pairs list if elements are found at the known
1673 * @returns null if nothing is there
1675 public String
[][] getPcdTokenArray() {
1676 String
[] xPath
= new String
[] { "/PcdData" };
1678 Object
[] returns
= get("PCDs", xPath
);
1679 if (returns
== null || returns
.length
== 0) {
1687 * Retrieve MAS header
1692 public ModuleIdentification
getMsaHeader() {
1693 String
[] xPath
= new String
[] { "/" };
1694 Object
[] returns
= get("MsaHeader", xPath
);
1696 if (returns
== null || returns
.length
== 0) {
1700 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1702 // Get BaseName, ModuleType, GuidValue, Version
1703 // which in MsaHeader.
1705 String name
= msaHeader
.getModuleName();
1706 String moduleType
= msaHeader
.getModuleType().toString();
1707 String guid
= msaHeader
.getGuidValue();
1708 String version
= msaHeader
.getVersion();
1710 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1713 moduleId
.setModuleType(moduleType
);
1719 * Retrieve Extern Specification
1723 * @return String[] If have specification element in the <extern> String[0]
1724 * If no specification element in the <extern>
1728 public String
[] getExternSpecificaiton() {
1729 String
[] xPath
= new String
[] { "/Specification" };
1731 Object
[] queryResult
= get("Externs", xPath
);
1732 if (queryResult
== null) {
1733 return new String
[0];
1736 String
[] specificationList
= new String
[queryResult
.length
];
1737 for (int i
= 0; i
< queryResult
.length
; i
++) {
1738 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1741 return specificationList
;
1745 * Retreive MsaFile which in SPD
1748 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1749 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1751 public String
[] getSpdMsaFile() {
1752 String
[] xPath
= new String
[] { "/MsaFiles" };
1754 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1755 if (returns
== null) {
1756 return new String
[0];
1759 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1761 return filenameList
.toArray(new String
[filenameList
.size()]);
1767 public Map
<String
, String
[]> getSpdLibraryClasses() {
1768 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1770 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1773 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1775 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1777 if (returns
== null) {
1778 return libClassHeaderMap
;
1781 for (int i
= 0; i
< returns
.length
; i
++) {
1782 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1783 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1784 .getIncludeHeader() });
1786 return libClassHeaderMap
;
1792 public Map
<String
, String
> getSpdPackageHeaderFiles() {
1793 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1795 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1798 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1800 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1802 if (returns
== null) {
1803 return packageIncludeMap
;
1806 for (int i
= 0; i
< returns
.length
; i
++) {
1807 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1808 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1809 includeHeader
.getStringValue());
1811 return packageIncludeMap
;
1814 public PackageIdentification
getSpdHeader() {
1815 String
[] xPath
= new String
[] { "/SpdHeader" };
1817 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1819 if (returns
== null || returns
.length
== 0) {
1823 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1825 String name
= header
.getPackageName();
1827 String guid
= header
.getGuidValue();
1829 String version
= header
.getVersion();
1831 return new PackageIdentification(name
, guid
, version
);
1837 public Map
<String
, String
[]> getSpdGuid() {
1838 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1840 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1843 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1845 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1846 if (returns
== null) {
1850 for (int i
= 0; i
< returns
.length
; i
++) {
1851 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1852 String
[] guidPair
= new String
[2];
1853 guidPair
[0] = entry
.getCName();
1854 guidPair
[1] = entry
.getGuidValue();
1855 guidDeclMap
.put(entry
.getCName(), guidPair
);
1863 public Map
<String
, String
[]> getSpdProtocol() {
1864 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1866 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1869 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1871 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1873 if (returns
== null) {
1877 for (int i
= 0; i
< returns
.length
; i
++) {
1878 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1879 String
[] protocolPair
= new String
[2];
1881 protocolPair
[0] = entry
.getCName();
1882 protocolPair
[1] = entry
.getGuidValue();
1883 protoclMap
.put(entry
.getCName(), protocolPair
);
1889 * getSpdPpi() Retrieve the SPD PPI Entry
1892 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1893 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1896 public Map
<String
, String
[]> getSpdPpi() {
1897 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1899 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1902 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1904 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1906 if (returns
== null) {
1910 for (int i
= 0; i
< returns
.length
; i
++) {
1911 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1912 String
[] ppiPair
= new String
[2];
1913 ppiPair
[0] = entry
.getCName();
1914 ppiPair
[1] = entry
.getGuidValue();
1915 ppiMap
.put(entry
.getCName(), ppiPair
);
1921 * Retrieve module Guid string
1923 * @returns GUILD string if elements are found at the known xpath
1924 * @returns null if nothing is there
1926 public String
getModuleGuid() {
1927 String
[] xPath
= new String
[] { "" };
1929 Object
[] returns
= get("MsaHeader", xPath
);
1930 if (returns
!= null && returns
.length
> 0) {
1931 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1942 public ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1943 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1944 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1945 if (result
!= null) {
1946 return (ModuleSADocument
.ModuleSA
[]) result
;
1948 return new ModuleSADocument
.ModuleSA
[0];
1952 Get name array of PCD in a module. In one module, token space
1953 is same, and token name should not be conflicted.
1957 public String
[] getModulePcdEntryNameArray() {
1958 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1961 String
[] xPath
= new String
[] {"/PcdEntry"};
1962 Object
[] returns
= get ("PcdCoded", xPath
);
1964 if (returns
== null) {
1965 return new String
[0];
1968 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1969 results
= new String
[pcdEntries
.length
];
1971 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1972 results
[index
] = pcdEntries
[index
].getCName();
1978 Search in a List for a given string
1982 public boolean contains(List list
, String str
) {
1983 if (list
== null || list
.size()== 0) {
1986 Iterator it
= list
.iterator();
1987 while (it
.hasNext()) {
1988 String s
= (String
)it
.next();
1989 if (s
.equalsIgnoreCase(str
)) {
1997 public boolean isHaveTianoR8FlashMap(){
1998 String
[] xPath
= new String
[] {"/"};
1999 Object
[] returns
= get ("Externs", xPath
);
2001 if (returns
== null) {
2005 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
2007 if (ext
.getTianoR8FlashMapH()){
2014 public Node
getPeiApriori(String fvName
) {
2015 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName
+ "']" };
2016 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2018 if (result
== null || result
.length
== 0) {
2022 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2024 return a
.getDomNode();
2027 public Node
getDxeApriori(String fvName
) {
2028 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2029 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2031 if (result
== null || result
.length
== 0) {
2035 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2037 return a
.getDomNode();
2040 public Node
getFpdModuleSequence(String fvName
) {
2041 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2042 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2044 if (result
== null || result
.length
== 0) {
2048 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2050 return a
.getDomNode();
2054 Get the value of PCD by PCD cName
2056 @return PcdValue String of PcdComponentName
2057 null If don't find ComponentName Pcd
2059 public String
getPcdValueBycName(String cName
){
2060 String
[] xPath
= new String
[] { "/PcdData" };
2061 Object
[] returns
= get("PcdBuildDefinition", xPath
);
2062 if (returns
== null || returns
.length
== 0) {
2065 for (int i
= 0; i
< returns
.length
; i
++) {
2066 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)returns
[i
];
2067 if (pcdData
.getCName().equalsIgnoreCase(cName
)){
2068 return pcdData
.getValue();