2 This file is for surface area information retrieval.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 package org
.tianocore
.build
.global
;
16 import java
.util
.ArrayList
;
17 import java
.util
.HashMap
;
18 import java
.util
.Iterator
;
19 import java
.util
.LinkedHashMap
;
20 import java
.util
.List
;
22 import java
.util
.Stack
;
23 import java
.util
.regex
.Matcher
;
24 import java
.util
.regex
.Pattern
;
26 import org
.apache
.xmlbeans
.XmlObject
;
27 import org
.apache
.xmlbeans
.XmlString
;
28 import org
.tianocore
.*;
29 import org
.tianocore
.ExternsDocument
.Externs
.Extern
;
30 import org
.tianocore
.FilenameDocument
.Filename
;
31 import org
.tianocore
.ModuleDefinitionsDocument
.ModuleDefinitions
;
32 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
33 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
34 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
35 import org
.tianocore
.build
.autogen
.CommonDefinition
;
36 import org
.tianocore
.build
.id
.FpdModuleIdentification
;
37 import org
.tianocore
.build
.id
.ModuleIdentification
;
38 import org
.tianocore
.build
.id
.PackageIdentification
;
39 import org
.tianocore
.build
.id
.PlatformIdentification
;
40 import org
.tianocore
.build
.toolchain
.ToolChainInfo
;
41 import org
.tianocore
.common
.definitions
.EdkDefinitions
;
42 import org
.tianocore
.common
.exception
.EdkException
;
43 import org
.w3c
.dom
.Node
;
46 * SurfaceAreaQuery class is used to query Surface Area information from msa,
47 * mbd, spd and fpd files.
49 * This class should not instantiated. All the public interfaces is static.
53 public class SurfaceAreaQuery
{
55 public String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
58 // Contains name/value pairs of Surface Area document object. The name is
59 // always the top level element name.
61 private Map
<String
, XmlObject
> map
= null;
64 // mapStack is used to do nested query
66 private Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
69 // prefix of name space
71 private String nsPrefix
= "sans";
74 // xmlbeans needs a name space for each Xpath element
76 private String ns
= null;
79 // keep the namep declaration for xmlbeans Xpath query
81 private String queryDeclaration
= null;
82 private StringBuffer normQueryString
= new StringBuffer(4096);
83 private Pattern xPathPattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
86 * Set a Surface Area document for query later
89 * A Surface Area document in TopLevelElementName/XmlObject
92 public SurfaceAreaQuery(Map
<String
, XmlObject
> map
) {
94 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
99 * Push current used Surface Area document into query stack. The given new
100 * document will be used for any immediately followed getXXX() callings,
101 * untill pop() is called.
104 * The TopLevelElementName/XmlObject format of a Surface Area
107 public void push(Map
<String
, XmlObject
> newMap
) {
108 mapStack
.push(this.map
);
113 * Discard current used Surface Area document and use the top document in
117 this.map
= mapStack
.pop();
121 // / Convert xPath to be namespace qualified, which is necessary for
123 // / selectPath(). For example, converting /MsaHeader/ModuleType to
124 // / /ns:MsaHeader/ns:ModuleType
126 private String
normalizeQueryString(String
[] exp
, String from
) {
127 normQueryString
.setLength(0);
130 while (i
< exp
.length
) {
131 String newExp
= from
+ exp
[i
];
132 Matcher matcher
= xPathPattern
.matcher(newExp
);
134 while (matcher
.find()) {
135 String starter
= newExp
.substring(matcher
.start(1), matcher
137 String seperator
= newExp
.substring(matcher
.start(2), matcher
139 String token
= newExp
.substring(matcher
.start(3), matcher
142 normQueryString
.append(starter
);
143 normQueryString
.append(seperator
);
144 normQueryString
.append(nsPrefix
);
145 normQueryString
.append(":");
146 normQueryString
.append(token
);
150 if (i
< exp
.length
) {
151 normQueryString
.append(" | ");
155 return normQueryString
.toString();
159 * Search all XML documents stored in "map" for the specified xPath, using
160 * relative path (starting with '$this')
163 * xpath query string array
164 * @returns An array of XmlObject if elements are found at the specified
166 * @returns NULL if nothing is at the specified xpath
168 public Object
[] get(String
[] xPath
) {
173 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
174 List
<Object
> result
= new ArrayList
<Object
>();
175 for (int i
= 0; i
< keys
.length
; ++i
) {
176 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
177 if (rootNode
== null) {
181 String query
= queryDeclaration
182 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
183 XmlObject
[] tmp
= rootNode
.selectPath(query
);
184 for (int j
= 0; j
< tmp
.length
; ++j
) {
185 result
.add((Object
)tmp
[j
]);
189 int size
= result
.size();
194 return (Object
[]) result
.toArray(new Object
[size
]);
198 * Search XML documents named by "rootName" for the given xPath, using
199 * relative path (starting with '$this')
202 * The top level element name
204 * The xpath query string array
205 * @returns An array of XmlObject if elements are found at the given xpath
206 * @returns NULL if nothing is found at the given xpath
208 public Object
[] get(String rootName
, String
[] xPath
) {
213 XmlObject root
= (XmlObject
) map
.get(rootName
);
218 String query
= queryDeclaration
219 + normalizeQueryString(xPath
, "$this/" + rootName
);
220 XmlObject
[] result
= root
.selectPath(query
);
221 if (result
.length
> 0) {
222 return (Object
[])result
;
225 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
226 result
= root
.selectPath(query
);
227 if (result
.length
> 0) {
228 return (Object
[])result
;
235 * Retrieve SourceFiles/Filename for specified ARCH type
239 * @returns An 2 dimension string array if elements are found at the known
241 * @returns NULL if nothing is found at the known xpath
243 public String
[][] getSourceFiles(String arch
) {
247 xPath
= new String
[] { "/Filename" };
249 returns
= get("SourceFiles", xPath
);
251 if (returns
== null || returns
.length
== 0) {
252 return new String
[0][3];
255 Filename
[] sourceFileNames
= (Filename
[]) returns
;
256 List
<String
[]> outputList
= new ArrayList
<String
[]>();
257 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
258 List archList
= sourceFileNames
[i
].getSupArchList();
259 if (arch
== null || arch
.trim().equalsIgnoreCase("") || archList
== null || contains(archList
, arch
)) {
260 outputList
.add(new String
[] {sourceFileNames
[i
].getToolCode(), sourceFileNames
[i
].getStringValue(), sourceFileNames
[i
].getToolChainFamily()});
264 String
[][] outputString
= new String
[outputList
.size()][3];
265 for (int index
= 0; index
< outputList
.size(); index
++) {
267 // ToolCode (FileType)
269 outputString
[index
][0] = outputList
.get(index
)[0];
271 // File name (relative to MODULE_DIR)
273 outputString
[index
][1] = outputList
.get(index
)[1];
277 outputString
[index
][2] = outputList
.get(index
)[2];
283 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
285 * @returns Directory names array if elements are found at the known xpath
286 * @returns Empty if nothing is found at the known xpath
288 public String
getFpdOutputDirectory() {
289 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
291 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
292 if (returns
== null || returns
.length
== 0) {
295 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
296 return item
.getOutputDirectory();
299 public String
getFpdIntermediateDirectories() {
300 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
302 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
303 if (returns
== null || returns
.length
== 0) {
306 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
307 if(item
.getIntermediateDirectories() == null) {
311 return item
.getIntermediateDirectories().toString();
315 public String
getModuleFfsKeyword() {
316 String
[] xPath
= new String
[] { "/" };
318 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
319 if (returns
== null || returns
.length
== 0) {
322 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
323 return item
.getFfsFormatKey();
326 public String
getModuleFvBindingKeyword() {
327 String
[] xPath
= new String
[] { "/" };
329 Object
[] returns
= get("ModuleSaBuildOptions", xPath
);
330 if (returns
== null || returns
.length
== 0) {
333 ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions item
= (ModuleSaBuildOptionsDocument
.ModuleSaBuildOptions
)returns
[0];
334 return item
.getFvBinding();
337 public List
getModuleSupportedArchs() {
338 String
[] xPath
= new String
[] { "/" };
340 Object
[] returns
= get("ModuleDefinitions", xPath
);
341 if (returns
== null || returns
.length
== 0) {
344 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
345 return item
.getSupportedArchitectures();
348 public BuildOptionsDocument
.BuildOptions
.Ffs
[] getFpdFfs() {
349 String
[] xPath
= new String
[] {"/Ffs"};
351 Object
[] returns
= get("BuildOptions", xPath
);
352 if (returns
== null || returns
.length
== 0) {
353 return new BuildOptionsDocument
.BuildOptions
.Ffs
[0];
355 return (BuildOptionsDocument
.BuildOptions
.Ffs
[])returns
;
358 public String
getModuleOutputFileBasename() {
359 String
[] xPath
= new String
[] { "/" };
361 Object
[] returns
= get("ModuleDefinitions", xPath
);
362 if (returns
== null || returns
.length
== 0) {
365 ModuleDefinitionsDocument
.ModuleDefinitions item
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
366 return item
.getOutputFileBasename();
370 * Retrieve BuildOptions/Option or Arch/Option
372 * @param toolChainFamilyFlag
373 * if true, retrieve options for toolchain family; otherwise for
376 * @returns String[][5] name, target, toolchain, arch, coommand of options
377 * if elements are found at the known xpath. String[0][] if dont
380 * @returns Empty array if nothing is there
382 public String
[][] getOptions(String from
, String
[] xPath
, boolean toolChainFamilyFlag
) {
383 String target
= null;
384 String toolchain
= null;
385 String toolchainFamily
= null;
386 List
<String
> archList
= null;
388 String optionName
= null;
390 Object
[] returns
= get(from
, xPath
);
391 if (returns
== null) {
392 return new String
[0][5];
395 List
<String
[]> optionList
= new ArrayList
<String
[]>();
396 OptionDocument
.Option option
;
398 for (int i
= 0; i
< returns
.length
; i
++) {
399 option
= (OptionDocument
.Option
) returns
[i
];
402 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
404 // put to result[][5] array in above order.
407 if (option
.getBuildTargets() == null) {
411 target
= option
.getBuildTargets().toString();
413 if (target
!= null) {
414 targetList
= target
.split(" ");
416 targetList
= new String
[1];
417 targetList
[0] = null;
420 if (toolChainFamilyFlag
) {
421 toolchainFamily
= option
.getToolChainFamily();
422 if (toolchainFamily
!= null) {
423 toolchain
= toolchainFamily
.toString();
428 toolchain
= option
.getTagName();
431 archList
= new ArrayList
<String
>();
432 List archEnumList
= option
.getSupArchList();
433 if (archEnumList
== null) {
436 //archList.addAll(archEnumList);
437 Iterator it
= archEnumList
.iterator();
438 while (it
.hasNext()) {
439 String archType
= (String
)it
.next();
440 archList
.add(archType
);
444 cmd
= option
.getToolCode();
446 optionName
= option
.getStringValue();
447 for (int t
= 0; t
< targetList
.length
; t
++) {
448 for (int j
= 0; j
< archList
.size(); j
++) {
449 optionList
.add(new String
[] { targetList
[t
],
450 toolchain
, archList
.get(j
), cmd
, optionName
});
455 String
[][] result
= new String
[optionList
.size()][5];
456 for (int i
= 0; i
< optionList
.size(); i
++) {
457 result
[i
][0] = optionList
.get(i
)[0];
458 result
[i
][1] = optionList
.get(i
)[1];
459 result
[i
][2] = optionList
.get(i
)[2];
460 result
[i
][3] = optionList
.get(i
)[3];
461 result
[i
][4] = optionList
.get(i
)[4];
466 public String
[][] getModuleBuildOptions(boolean toolChainFamilyFlag
) {
469 if (toolChainFamilyFlag
== true) {
470 xPath
= new String
[] {
471 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
472 "/Options/Option[@ToolChainFamily]", };
474 xPath
= new String
[] {
475 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
476 "/Options/Option[@TagName]", };
478 return getOptions("ModuleSaBuildOptions", xPath
, toolChainFamilyFlag
);
481 public String
[][] getPlatformBuildOptions(boolean toolChainFamilyFlag
) {
484 if (toolChainFamilyFlag
== true) {
485 xPath
= new String
[] {
486 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
487 "/BuildOptions/Options/Option[@ToolChainFamily]", };
489 xPath
= new String
[] {
490 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
491 "/BuildOptions/Options/Option[@TagName]", };
494 return getOptions("PlatformSurfaceArea", xPath
, toolChainFamilyFlag
);
497 public String
[][] getMsaBuildOptions(boolean toolChainFamilyFlag
) {
500 if (toolChainFamilyFlag
== true) {
501 xPath
= new String
[] {
502 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
503 "/Options/Option[@ToolChainFamily]", };
505 xPath
= new String
[] {
506 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
507 "/Options/Option[@TagName]", };
510 return getOptions("ModuleBuildOptions", xPath
, toolChainFamilyFlag
);
513 public ToolChainInfo
getFpdToolChainInfo() {
514 String
[] xPath
= new String
[] { "/PlatformDefinitions" };
516 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
517 if (returns
== null || returns
.length
== 0) {
521 PlatformDefinitionsDocument
.PlatformDefinitions item
= (PlatformDefinitionsDocument
.PlatformDefinitions
)returns
[0];
522 ToolChainInfo toolChainInfo
= new ToolChainInfo();
523 toolChainInfo
.addTargets(item
.getBuildTargets().toString());
524 toolChainInfo
.addArchs(item
.getSupportedArchitectures().toString());
525 toolChainInfo
.addTagnames((String
)null);
526 return toolChainInfo
;
530 * Retrieve <xxxHeader>/ModuleType
532 * @returns The module type name if elements are found at the known xpath
533 * @returns null if nothing is there
535 public String
getModuleType() {
536 String
[] xPath
= new String
[] { "/ModuleType" };
538 Object
[] returns
= get(xPath
);
539 if (returns
!= null && returns
.length
> 0) {
540 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
541 return type
.enumValue().toString();
548 * Retrieve <ModuleDefinitions>/<BinaryModule>
550 * @returns The module type name if elements are found at the known xpath
551 * @returns null if nothing is there
553 public boolean getBinaryModule() {
554 String
[] xPath
= new String
[] { "/" };
556 Object
[] returns
= get("ModuleDefinitions", xPath
);
557 if (returns
!= null && returns
.length
> 0) {
558 ModuleDefinitionsDocument
.ModuleDefinitions def
= (ModuleDefinitionsDocument
.ModuleDefinitions
)returns
[0];
559 return def
.getBinaryModule();
566 * Retrieve PackageDependencies/Package
571 * @returns package name list if elements are found at the known xpath
572 * @returns null if nothing is there
574 public PackageIdentification
[] getDependencePkg(String arch
) throws EdkException
{
576 String packageGuid
= null;
577 String packageVersion
= null;
580 xPath
= new String
[] { "/Package" };
582 Object
[] returns
= get("PackageDependencies", xPath
);
583 if (returns
== null) {
584 return new PackageIdentification
[0];
588 // Get packageIdentification
590 List
<PackageIdentification
> packageIdList
= new ArrayList
<PackageIdentification
>();
591 for (int i
= 0; i
< returns
.length
; i
++) {
592 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
593 List archList
= item
.getSupArchList();
594 if (arch
== null || archList
== null || contains(archList
, arch
)) {
595 packageGuid
= item
.getPackageGuid();
596 packageVersion
= item
.getPackageVersion();
597 PackageIdentification pkgId
= new PackageIdentification(null, packageGuid
, packageVersion
);
598 GlobalData
.refreshPackageIdentification(pkgId
);
599 packageIdList
.add(pkgId
);
603 return packageIdList
.toArray(new PackageIdentification
[packageIdList
.size()]);
607 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
610 * Library class usage
612 * @returns LibraryClass objects list if elements are found at the known
614 * @returns null if nothing is there
616 public String
[] getLibraryClasses(String usage
, String arch
, String moduleType
) {
618 if (usage
== null || usage
.equals("")) {
619 xPath
= new String
[] { "/LibraryClass" };
621 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
624 Object
[] returns
= get("LibraryClassDefinitions", xPath
);
625 if (returns
== null || returns
.length
== 0) {
626 return new String
[0];
629 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
630 List
<String
> libraryClassName
= new ArrayList
<String
>();
631 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
632 List archList
= libraryClassList
[i
].getSupArchList();
633 List moduleTypeList
= libraryClassList
[i
].getSupModuleList();
634 if ((arch
== null || contains(archList
, arch
))
635 && (moduleType
== null || contains(moduleTypeList
, moduleType
))) {
636 libraryClassName
.add(libraryClassList
[i
].getKeyword());
640 String
[] libraryArray
= new String
[libraryClassName
.size()];
641 libraryClassName
.toArray(libraryArray
);
646 * Retrieve ModuleEntryPoint names
648 * @returns ModuleEntryPoint name list if elements are found at the known
650 * @returns null if nothing is there
652 public String
[] getModuleEntryPointArray() {
653 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
655 Object
[] returns
= get("Externs", xPath
);
657 if (returns
!= null && returns
.length
> 0) {
658 String
[] entryPoints
= new String
[returns
.length
];
660 for (int i
= 0; i
< returns
.length
; ++i
) {
661 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
671 * retrieve Protocol for specified usage
674 * Protocol usage arch Architecture
676 * @returns Protocol String list if elements are found at the known xpath
677 * @returns String[0] if nothing is there
679 public String
[] getProtocolArray(String arch
, String usage
) {
681 String usageXpath
= "";
682 String archXpath
= "";
684 if (arch
== null || arch
.equals("")) {
685 return new String
[0];
687 archXpath
= "/Protocol";
688 if (usage
!= null && !usage
.equals("")) {
689 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
690 xPath
= new String
[] { usageXpath
, archXpath
};
692 return getProtocolArray(arch
);
697 Object
[] returns
= get("Protocols", xPath
);
698 if (returns
== null) {
699 return new String
[0];
701 Protocol
[] protocolList
= (Protocol
[]) returns
;
703 String
[] protocolArray
= new String
[returns
.length
];
704 for (int i
= 0; i
< returns
.length
; i
++) {
705 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
707 return protocolArray
;
711 * retrieve Protocol for specified usage
716 * @returns Protocol String list if elements are found at the known xpath
717 * @returns String[0] if nothing is there
719 public String
[] getProtocolArray(String arch
) {
722 if (arch
== null || arch
.equals("")) {
723 return new String
[0];
725 xPath
= new String
[] { "/Protocol" };
728 Object
[] returns
= get("Protocols", xPath
);
729 if (returns
== null) {
730 return new String
[0];
732 Protocol
[] returnlList
= (Protocol
[]) returns
;
734 List
<String
> protocolList
= new ArrayList
<String
>();
736 for (int i
= 0; i
< returns
.length
; i
++) {
737 List archList
= returnlList
[i
].getSupArchList();
738 if (archList
== null || contains(archList
, arch
)){
739 protocolList
.add(returnlList
[i
].getProtocolCName());
742 String
[] protocolArray
= new String
[protocolList
.size()];
743 for (int i
= 0; i
< protocolList
.size(); i
++) {
744 protocolArray
[i
] = protocolList
.get(i
);
746 return protocolArray
;
750 * Retrieve ProtocolNotify for specified usage
753 * ProtocolNotify usage
755 * @returns String[] if elements are found at the known xpath
756 * @returns String[0] if nothing is there
758 public String
[] getProtocolNotifyArray(String arch
) {
761 if (arch
== null || arch
.equals("")) {
762 return new String
[0];
764 xPath
= new String
[] { "/ProtocolNotify" };
767 Object
[] returns
= get("Protocols", xPath
);
768 if (returns
== null) {
769 return new String
[0];
772 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
774 for (int i
= 0; i
< returns
.length
; i
++) {
775 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
776 if (archList
== null || contains(archList
, arch
)){
777 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
781 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
782 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
783 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
785 return protocolNotifyArray
;
789 * Retrieve ProtocolNotify for specified usage
792 * ProtocolNotify usage
794 * @returns String[] if elements are found at the known xpath
795 * @returns String[0] if nothing is there
797 public String
[] getProtocolNotifyArray(String arch
, String usage
) {
803 if (arch
== null || arch
.equals("")) {
804 return new String
[0];
806 archXpath
= "/ProtocolNotify";
807 if (usage
!= null && !usage
.equals("")) {
808 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
809 xPath
= new String
[] { archXpath
, usageXpath
};
811 return getProtocolNotifyArray(arch
);
815 Object
[] returns
= get("Protocols", xPath
);
816 if (returns
== null) {
817 return new String
[0];
820 String
[] protocolNotifyList
= new String
[returns
.length
];
822 for (int i
= 0; i
< returns
.length
; i
++) {
823 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
825 return protocolNotifyList
;
829 * Retrieve ModuleUnloadImage names
831 * @returns ModuleUnloadImage name list if elements are found at the known
833 * @returns null if nothing is there
835 public String
[] getModuleUnloadImageArray() {
836 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
838 Object
[] returns
= get("Externs", xPath
);
839 if (returns
!= null && returns
.length
> 0) {
840 String
[] stringArray
= new String
[returns
.length
];
841 CNameType
[] doc
= (CNameType
[]) returns
;
843 for (int i
= 0; i
< returns
.length
; ++i
) {
844 stringArray
[i
] = doc
[i
].getStringValue();
856 * @returns Extern objects list if elements are found at the known xpath
857 * @returns null if nothing is there
859 public ExternsDocument
.Externs
.Extern
[] getExternArray() {
860 String
[] xPath
= new String
[] { "/Extern" };
862 Object
[] returns
= get("Externs", xPath
);
863 if (returns
!= null && returns
.length
> 0) {
864 return (ExternsDocument
.Externs
.Extern
[]) returns
;
871 * Retrieve PpiNotify for specified arch
876 * @returns String[] if elements are found at the known xpath
877 * @returns String[0] if nothing is there
879 public String
[] getPpiNotifyArray(String arch
) {
882 if (arch
== null || arch
.equals("")) {
883 return new String
[0];
885 xPath
= new String
[] { "/PpiNotify" };
888 Object
[] returns
= get("PPIs", xPath
);
889 if (returns
== null) {
890 return new String
[0];
894 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
895 for (int i
= 0; i
< returns
.length
; i
++) {
896 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
897 if (archList
== null || contains(archList
, arch
)){
898 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
902 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
903 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
904 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
907 return ppiNotifyArray
;
911 * Retrieve PpiNotify for specified usage and arch
914 * PpiNotify arch usage PpiNotify usage
917 * @returns String[] if elements are found at the known xpath
918 * @returns String[0] if nothing is there
920 public String
[] getPpiNotifyArray(String arch
, String usage
) {
926 if (arch
== null || arch
.equals("")) {
927 return new String
[0];
929 archXpath
= "/PpiNotify";
930 if (usage
!= null && !usage
.equals("")) {
931 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
932 xPath
= new String
[] { archXpath
, usageXpath
};
934 return getProtocolNotifyArray(arch
);
938 Object
[] returns
= get("PPIs", xPath
);
939 if (returns
== null) {
940 return new String
[0];
943 String
[] ppiNotifyList
= new String
[returns
.length
];
945 for (int i
= 0; i
< returns
.length
; i
++) {
946 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
948 return ppiNotifyList
;
952 * Retrieve Ppi for specified arch
957 * @returns String[] if elements are found at the known xpath
958 * @returns String[0] if nothing is there
960 public String
[] getPpiArray(String arch
) {
963 if (arch
== null || arch
.equals("")) {
964 return new String
[0];
966 xPath
= new String
[] { "/Ppi" };
969 Object
[] returns
= get("PPIs", xPath
);
970 if (returns
== null) {
971 return new String
[0];
974 List
<String
> ppiList
= new ArrayList
<String
>();
975 for (int i
= 0; i
< returns
.length
; i
++) {
976 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
977 if (archList
== null || contains(archList
, arch
)){
978 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
982 String
[] ppiArray
= new String
[ppiList
.size()];
983 for (int i
= 0; i
< ppiList
.size(); i
++) {
984 ppiArray
[i
] = ppiList
.get(i
);
990 * Retrieve PpiNotify for specified usage and arch
993 * PpiNotify arch usage PpiNotify usage
996 * @returns String[] if elements are found at the known xpath
997 * @returns String[0] if nothing is there
999 public String
[] getPpiArray(String arch
, String usage
) {
1005 if (arch
== null || arch
.equals("")) {
1006 return new String
[0];
1009 if (usage
!= null && !usage
.equals("")) {
1010 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
1011 xPath
= new String
[] { archXpath
, usageXpath
};
1013 return getProtocolNotifyArray(arch
);
1017 Object
[] returns
= get("PPIs", xPath
);
1018 if (returns
== null) {
1019 return new String
[0];
1022 String
[] ppiList
= new String
[returns
.length
];
1024 for (int i
= 0; i
< returns
.length
; i
++) {
1025 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1031 * Retrieve GuidEntry information for specified usage
1036 * @returns GuidEntry objects list if elements are found at the known xpath
1037 * @returns null if nothing is there
1039 public String
[] getGuidEntryArray(String arch
) {
1042 if (arch
== null || arch
.equals("")) {
1043 xPath
= new String
[] { "/GuidCNames" };
1045 xPath
= new String
[] { "/GuidCNames" };
1048 Object
[] returns
= get("Guids", xPath
);
1049 if (returns
== null) {
1050 return new String
[0];
1053 List
<String
> guidList
= new ArrayList
<String
>();
1054 for (int i
= 0; i
< returns
.length
; i
++) {
1055 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1056 if (archList
== null || contains(archList
, arch
)){
1057 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1061 String
[] guidArray
= new String
[guidList
.size()];
1062 for (int i
= 0; i
< guidList
.size(); i
++) {
1063 guidArray
[i
] = guidList
.get(i
);
1070 * Retrieve GuidEntry information for specified usage
1073 * GuidEntry arch usage GuidEntry usage
1075 * @returns GuidEntry objects list if elements are found at the known xpath
1076 * @returns null if nothing is there
1078 public String
[] getGuidEntryArray(String arch
, String usage
) {
1083 if (arch
== null || arch
.equals("")) {
1084 return new String
[0];
1086 archXpath
= "/GuidEntry";
1087 if (usage
!= null && !usage
.equals("")) {
1088 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1089 xPath
= new String
[] { archXpath
, usageXpath
};
1091 return getProtocolNotifyArray(arch
);
1095 Object
[] returns
= get("Guids", xPath
);
1096 if (returns
== null) {
1097 return new String
[0];
1100 String
[] guidList
= new String
[returns
.length
];
1102 for (int i
= 0; i
< returns
.length
; i
++) {
1103 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1109 * Retrieve Library instance information
1114 * Library instance usage
1116 * @returns library instance name list if elements are found at the known
1118 * @returns null if nothing is there
1120 public ModuleIdentification
[] getLibraryInstance(String arch
) throws EdkException
{
1122 String saGuid
= null;
1123 String saVersion
= null;
1124 String pkgGuid
= null;
1125 String pkgVersion
= null;
1127 if (arch
== null || arch
.equalsIgnoreCase("")) {
1128 xPath
= new String
[] { "/Instance" };
1131 // Since Schema don't have SupArchList now, so the follow Xpath is
1132 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1133 // don't have effect.
1135 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1139 Object
[] returns
= get("Libraries", xPath
);
1140 if (returns
== null || returns
.length
== 0) {
1141 return new ModuleIdentification
[0];
1144 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1145 for (int i
= 0; i
< returns
.length
; i
++) {
1146 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1147 saGuid
= library
.getModuleGuid();
1148 saVersion
= library
.getModuleVersion();
1150 pkgGuid
= library
.getPackageGuid();
1151 pkgVersion
= library
.getPackageVersion();
1153 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1155 PackageIdentification pkgId
= new PackageIdentification(null,
1156 pkgGuid
, pkgVersion
);
1157 GlobalData
.refreshPackageIdentification(pkgId
);
1158 saId
.setPackage(pkgId
);
1159 GlobalData
.refreshModuleIdentification(saId
);
1168 // / This method is used for retrieving the elements information which has
1169 // / CName sub-element
1171 private String
[] getCNames(String from
, String xPath
[]) {
1172 Object
[] returns
= get(from
, xPath
);
1173 if (returns
== null || returns
.length
== 0) {
1177 String
[] strings
= new String
[returns
.length
];
1178 for (int i
= 0; i
< returns
.length
; ++i
) {
1180 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1187 * Retrive library's constructor name
1189 * @returns constructor name list if elements are found at the known xpath
1190 * @returns null if nothing is there
1192 public String
getLibConstructorName() {
1193 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1195 Object
[] returns
= get("Externs", xPath
);
1196 if (returns
!= null && returns
.length
> 0) {
1197 CNameType constructor
= ((CNameType
) returns
[0]);
1198 return constructor
.getStringValue();
1205 * Retrive library's destructor name
1207 * @returns destructor name list if elements are found at the known xpath
1208 * @returns null if nothing is there
1210 public String
getLibDestructorName() {
1211 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1213 Object
[] returns
= get("Externs", xPath
);
1214 if (returns
!= null && returns
.length
> 0) {
1216 // Only support one Destructor function.
1218 CNameType destructor
= (CNameType
) returns
[0];
1219 return destructor
.getStringValue();
1226 * Retrive DriverBinding names
1228 * @returns DriverBinding name list if elements are found at the known xpath
1229 * @returns null if nothing is there
1231 public String
[] getDriverBindingArray() {
1232 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1233 return getCNames("Externs", xPath
);
1237 * Retrive ComponentName names
1239 * @returns ComponentName name list if elements are found at the known xpath
1240 * @returns null if nothing is there
1242 public String
[] getComponentNameArray() {
1243 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1244 return getCNames("Externs", xPath
);
1248 * Retrive DriverConfig names
1250 * @returns DriverConfig name list if elements are found at the known xpath
1251 * @returns null if nothing is there
1253 public String
[] getDriverConfigArray() {
1254 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1255 return getCNames("Externs", xPath
);
1259 * Retrive DriverDiag names
1261 * @returns DriverDiag name list if elements are found at the known xpath
1262 * @returns null if nothing is there
1264 public String
[] getDriverDiagArray() {
1265 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1266 return getCNames("Externs", xPath
);
1270 * Retrive DriverBinding, ComponentName, DriverConfig,
1271 * DriverDiag group array
1273 * @returns DriverBinding group name list if elements are found
1274 * at the known xpath
1275 * @returns null if nothing is there
1277 public String
[][] getExternProtocolGroup() {
1278 String
[] xPath
= new String
[] {"/Extern"};
1279 Object
[] returns
= get("Externs",xPath
);
1281 if (returns
== null) {
1282 return new String
[0][4];
1284 List
<Extern
> externList
= new ArrayList
<Extern
>();
1285 for (int i
= 0; i
< returns
.length
; i
++) {
1286 org
.tianocore
.ExternsDocument
.Externs
.Extern extern
= (org
.tianocore
.ExternsDocument
.Externs
.Extern
)returns
[i
];
1287 if (extern
.getDriverBinding() != null) {
1288 externList
.add(extern
);
1292 String
[][] externGroup
= new String
[externList
.size()][4];
1293 for (int i
= 0; i
< externList
.size(); i
++) {
1294 String driverBindingStr
= externList
.get(i
).getDriverBinding();
1295 if ( driverBindingStr
!= null){
1296 externGroup
[i
][0] = driverBindingStr
;
1298 externGroup
[i
][0] = null;
1301 String componentNameStr
= externList
.get(i
).getComponentName();
1302 if (componentNameStr
!= null) {
1303 externGroup
[i
][1] = componentNameStr
;
1305 externGroup
[i
][1] = null;
1308 String driverConfigStr
= externList
.get(i
).getDriverConfig();
1309 if (driverConfigStr
!= null) {
1310 externGroup
[i
][2] = driverConfigStr
;
1312 externGroup
[i
][2] = null;
1315 String driverDiagStr
= externList
.get(i
).getDriverDiag();
1316 if (driverDiagStr
!= null) {
1317 externGroup
[i
][3] = driverDiagStr
;
1319 externGroup
[i
][3] = null;
1326 * Retrive SetVirtualAddressMapCallBack names
1328 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1330 * @returns null if nothing is there
1332 public String
[] getSetVirtualAddressMapCallBackArray() {
1333 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1334 return getCNames("Externs", xPath
);
1338 * Retrive ExitBootServicesCallBack names
1340 * @returns ExitBootServicesCallBack name list if elements are found at the
1342 * @returns null if nothing is there
1344 public String
[] getExitBootServicesCallBackArray() {
1345 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1346 return getCNames("Externs", xPath
);
1350 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1353 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1355 public CommonDefinition
.PCD_DRIVER_TYPE
getPcdDriverType() {
1356 String
[] xPath
= new String
[] {"/PcdIsDriver"};
1357 Object
[] results
= get ("Externs", xPath
);
1359 if (results
!= null && results
.length
!= 0) {
1360 PcdDriverTypes type
= (PcdDriverTypes
) results
[0];
1361 String typeStr
= type
.enumValue().toString();
1362 if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
.toString())) {
1363 return CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
;
1364 } else if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
.toString())) {
1365 return CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
;
1367 return CommonDefinition
.PCD_DRIVER_TYPE
.UNKNOWN_PCD_DRIVER
;
1370 return CommonDefinition
.PCD_DRIVER_TYPE
.NOT_PCD_DRIVER
;
1374 * Retrieve module surface area file information
1376 * @returns ModuleSA objects list if elements are found at the known xpath
1377 * @returns Empty ModuleSA list if nothing is there
1379 public Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() throws EdkException
{
1380 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1381 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1383 String fvBinding
= null;
1384 String saGuid
= null;
1385 String saVersion
= null;
1386 String pkgGuid
= null;
1387 String pkgVersion
= null;
1389 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1391 if (result
== null) {
1392 return fpdModuleMap
;
1395 for (int i
= 0; i
< result
.length
; i
++) {
1397 // Get Fpd SA Module element node and add to ObjectMap.
1399 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1400 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1401 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1402 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1404 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1405 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1407 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1408 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1412 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1414 if (moduleSA
.isSetSupArchList()) {
1415 arch
= moduleSA
.getSupArchList().toString();
1422 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1424 saGuid
= moduleSA
.getModuleGuid();
1425 pkgGuid
= moduleSA
.getPackageGuid();
1426 pkgVersion
= moduleSA
.getPackageVersion();
1429 // Create Module Identification which have class member of package
1432 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1433 GlobalData
.refreshPackageIdentification(pkgId
);
1435 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1436 saId
.setPackage(pkgId
);
1437 GlobalData
.refreshModuleIdentification(saId
);
1442 // Create FpdModule Identification which have class member of module
1445 String
[] archList
= new String
[0];
1446 if (arch
== null || arch
.trim().length() == 0) {
1447 archList
= GlobalData
.getToolChainInfo().getArchs();
1449 archList
= arch
.split(" ");
1451 for (int j
= 0; j
< archList
.length
; j
++) {
1452 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1454 if (fvBinding
!= null) {
1455 fpdSaId
.setFvBinding(fvBinding
);
1459 // Put element to Map<FpdModuleIdentification, Map<String,
1462 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1465 return fpdModuleMap
;
1469 * Retrieve valid image names
1471 * @returns valid iamges name list if elements are found at the known xpath
1472 * @returns empty list if nothing is there
1474 public String
[] getFpdValidImageNames() {
1475 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1477 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1478 if (queryResult
== null) {
1479 return new String
[0];
1482 String
[] result
= new String
[queryResult
.length
];
1483 for (int i
= 0; i
< queryResult
.length
; i
++) {
1484 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1490 public Node
getFpdUserExtensionPreBuild() {
1491 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1493 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1494 if (queryResult
== null || queryResult
.length
== 0) {
1497 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1499 return a
.getDomNode();
1502 public Node
getFpdUserExtensionPostBuild() {
1503 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1505 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1506 if (queryResult
== null || queryResult
.length
== 0) {
1509 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1511 return a
.getDomNode();
1514 public Node
[] getFpdUserExtensions() {
1515 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and not(@Identifier='1') and not(@Identifier='0')]" };
1517 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1518 if (queryResult
== null || queryResult
.length
== 0) {
1522 Node
[] nodeList
= new Node
[queryResult
.length
];
1523 for (int i
= 0; i
< queryResult
.length
; ++i
) {
1524 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[i
];
1525 nodeList
[i
] = a
.getDomNode();
1531 * Retrieve FV image option information
1536 * @returns option name/value list if elements are found at the known xpath
1537 * @returns empty list if nothing is there
1539 public String
[][] getFpdOptions(String fvName
) {
1540 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1541 + fvName
+ "']/FvImageOptions" };
1542 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1543 if (queryResult
== null) {
1544 return new String
[0][];
1546 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1547 for (int i
= 0; i
< queryResult
.length
; i
++) {
1548 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1549 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1550 .getNameValueList();
1551 Iterator iter
= namevalues
.iterator();
1552 while (iter
.hasNext()) {
1553 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1555 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1558 String
[][] result
= new String
[list
.size()][2];
1559 for (int i
= 0; i
< list
.size(); i
++) {
1560 result
[i
][0] = list
.get(i
)[0];
1561 result
[i
][1] = list
.get(i
)[1];
1567 public XmlObject
getFpdBuildOptions() {
1568 String
[] xPath
= new String
[] { "/BuildOptions" };
1570 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1572 if (queryResult
== null || queryResult
.length
== 0) {
1575 return (XmlObject
)queryResult
[0];
1578 public PlatformIdentification
getFpdHeader() {
1579 String
[] xPath
= new String
[] { "/PlatformHeader" };
1581 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1583 if (returns
== null || returns
.length
== 0) {
1586 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1588 String name
= header
.getPlatformName();
1590 String guid
= header
.getGuidValue();
1592 String version
= header
.getVersion();
1594 return new PlatformIdentification(name
, guid
, version
);
1598 * Retrieve FV image attributes information
1603 * @returns attribute name/value list if elements are found at the known
1605 * @returns empty list if nothing is there
1607 public String
[][] getFpdAttributes(String fvName
) {
1608 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1609 + fvName
+ "']/FvImageOptions" };
1610 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1611 if (queryResult
== null) {
1612 return new String
[0][];
1614 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1615 for (int i
= 0; i
< queryResult
.length
; i
++) {
1617 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1618 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1619 Iterator iter
= namevalues
.iterator();
1620 while (iter
.hasNext()) {
1621 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1623 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1626 String
[][] result
= new String
[list
.size()][2];
1627 for (int i
= 0; i
< list
.size(); i
++) {
1628 result
[i
][0] = list
.get(i
)[0];
1629 result
[i
][1] = list
.get(i
)[1];
1635 * Retrieve flash definition file name
1637 * @returns file name if elements are found at the known xpath
1638 * @returns null if nothing is there
1640 public String
getFlashDefinitionFile() {
1641 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1643 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1644 if (queryResult
== null || queryResult
.length
== 0) {
1648 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1649 return filename
.getStringValue();
1652 public String
[][] getFpdGlobalVariable() {
1653 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1654 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1655 if (queryResult
== null) {
1656 return new String
[0][];
1659 String
[][] result
= new String
[queryResult
.length
][2];
1661 for (int i
= 0; i
< queryResult
.length
; i
++) {
1662 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1663 result
[i
][0] = item
.getName();
1664 result
[i
][1] = item
.getValue();
1670 * Retrieve FV image component options
1675 * @returns name/value pairs list if elements are found at the known xpath
1676 * @returns empty list if nothing is there
1678 public String
[][] getFpdComponents(String fvName
) {
1679 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1680 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1681 if (queryResult
== null) {
1682 return new String
[0][];
1685 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1686 for (int i
= 0; i
< queryResult
.length
; i
++) {
1687 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1688 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1689 Iterator iter
= namevalues
.iterator();
1690 while (iter
.hasNext()) {
1691 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1693 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1696 String
[][] result
= new String
[list
.size()][2];
1697 for (int i
= 0; i
< list
.size(); i
++) {
1698 result
[i
][0] = list
.get(i
)[0];
1699 result
[i
][1] = list
.get(i
)[1];
1705 * Retrieve PCD tokens
1707 * @returns CName/ItemType pairs list if elements are found at the known
1709 * @returns null if nothing is there
1711 public String
[][] getPcdTokenArray() {
1712 String
[] xPath
= new String
[] { "/PcdData" };
1714 Object
[] returns
= get("PCDs", xPath
);
1715 if (returns
== null || returns
.length
== 0) {
1723 * Retrieve MAS header
1728 public ModuleIdentification
getMsaHeader() {
1729 String
[] xPath
= new String
[] { "/" };
1730 Object
[] returns
= get("MsaHeader", xPath
);
1732 if (returns
== null || returns
.length
== 0) {
1736 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1738 // Get BaseName, ModuleType, GuidValue, Version
1739 // which in MsaHeader.
1741 String name
= msaHeader
.getModuleName();
1742 String moduleType
= msaHeader
.getModuleType().toString();
1743 String guid
= msaHeader
.getGuidValue();
1744 String version
= msaHeader
.getVersion();
1746 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1749 moduleId
.setModuleType(moduleType
);
1755 * Retrieve Extern Specification
1759 * @return String[] If have specification element in the <extern> String[0]
1760 * If no specification element in the <extern>
1764 public String
[] getExternSpecificaiton() {
1765 String
[] xPath
= new String
[] { "/Specification" };
1767 Object
[] queryResult
= get("Externs", xPath
);
1768 if (queryResult
== null) {
1769 return new String
[0];
1772 String
[] specificationList
= new String
[queryResult
.length
];
1773 for (int i
= 0; i
< queryResult
.length
; i
++) {
1774 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1777 return specificationList
;
1781 * Retreive MsaFile which in SPD
1784 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1785 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1787 public String
[] getSpdMsaFile() {
1788 String
[] xPath
= new String
[] { "/MsaFiles" };
1790 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1791 if (returns
== null) {
1792 return new String
[0];
1795 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1797 return filenameList
.toArray(new String
[filenameList
.size()]);
1803 public Map
<String
, String
[]> getSpdLibraryClasses() {
1804 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1806 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1809 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1811 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1813 if (returns
== null) {
1814 return libClassHeaderMap
;
1817 for (int i
= 0; i
< returns
.length
; i
++) {
1818 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1819 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1820 .getIncludeHeader() });
1822 return libClassHeaderMap
;
1828 public Map
<String
, String
> getSpdPackageHeaderFiles() {
1829 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1831 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1834 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1836 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1838 if (returns
== null) {
1839 return packageIncludeMap
;
1842 for (int i
= 0; i
< returns
.length
; i
++) {
1843 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1844 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1845 includeHeader
.getStringValue());
1847 return packageIncludeMap
;
1850 public PackageIdentification
getSpdHeader() {
1851 String
[] xPath
= new String
[] { "/SpdHeader" };
1853 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1855 if (returns
== null || returns
.length
== 0) {
1859 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1861 String name
= header
.getPackageName();
1863 String guid
= header
.getGuidValue();
1865 String version
= header
.getVersion();
1867 return new PackageIdentification(name
, guid
, version
);
1873 public Map
<String
, String
[]> getSpdGuid() {
1874 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1876 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1879 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1881 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1882 if (returns
== null) {
1886 for (int i
= 0; i
< returns
.length
; i
++) {
1887 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1888 String
[] guidPair
= new String
[2];
1889 guidPair
[0] = entry
.getCName();
1890 guidPair
[1] = entry
.getGuidValue();
1891 guidDeclMap
.put(entry
.getCName(), guidPair
);
1899 public Map
<String
, String
[]> getSpdProtocol() {
1900 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1902 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1905 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1907 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1909 if (returns
== null) {
1913 for (int i
= 0; i
< returns
.length
; i
++) {
1914 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1915 String
[] protocolPair
= new String
[2];
1917 protocolPair
[0] = entry
.getCName();
1918 protocolPair
[1] = entry
.getGuidValue();
1919 protoclMap
.put(entry
.getCName(), protocolPair
);
1925 * getSpdPpi() Retrieve the SPD PPI Entry
1928 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1929 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1932 public Map
<String
, String
[]> getSpdPpi() {
1933 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1935 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1938 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1940 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1942 if (returns
== null) {
1946 for (int i
= 0; i
< returns
.length
; i
++) {
1947 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1948 String
[] ppiPair
= new String
[2];
1949 ppiPair
[0] = entry
.getCName();
1950 ppiPair
[1] = entry
.getGuidValue();
1951 ppiMap
.put(entry
.getCName(), ppiPair
);
1957 * Retrieve module Guid string
1959 * @returns GUILD string if elements are found at the known xpath
1960 * @returns null if nothing is there
1962 public String
getModuleGuid() {
1963 String
[] xPath
= new String
[] { "" };
1965 Object
[] returns
= get("MsaHeader", xPath
);
1966 if (returns
!= null && returns
.length
> 0) {
1967 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1978 public ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1979 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1980 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1981 if (result
!= null) {
1982 return (ModuleSADocument
.ModuleSA
[]) result
;
1984 return new ModuleSADocument
.ModuleSA
[0];
1989 Get name array who contains all PCDs in a module according to specified arch.
1991 @param arch The specified architecture type.
1993 @return String[] return all PCDs name into array, if no any PCD used by
1994 this module, a String[0] array is returned.
1996 public String
[] getModulePcdEntryNameArray(String arch
) {
1997 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1998 java
.util
.List archList
= null;
1999 java
.util
.List
<String
> results
= new java
.util
.ArrayList
<String
> ();
2001 String
[] xPath
= new String
[] {"/PcdEntry"};
2002 Object
[] returns
= get ("PcdCoded", xPath
);
2004 if (returns
== null) {
2005 return new String
[0];
2008 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
2010 for (index
= 0; index
< pcdEntries
.length
; index
++) {
2011 archList
= pcdEntries
[index
].getSupArchList();
2013 // If the ArchList is specified in MSA for this PCD, need check
2014 // current arch whether can support by this PCD.
2016 if (archList
!= null) {
2017 if (archList
.contains(arch
)) {
2018 results
.add(new String(pcdEntries
[index
].getCName()));
2022 // If no ArchList is specificied in MSA for this PCD, that means
2023 // this PCD support all architectures.
2025 results
.add(new String(pcdEntries
[index
].getCName()));
2029 if (results
.size() == 0) {
2030 return new String
[0];
2033 String
[] retArray
= new String
[results
.size()];
2034 results
.toArray(retArray
);
2040 Search in a List for a given string
2044 public boolean contains(List list
, String str
) {
2045 if (list
== null || list
.size()== 0) {
2049 return list
.contains(str
);
2052 public boolean isHaveTianoR8FlashMap(){
2053 String
[] xPath
= new String
[] {"/"};
2054 Object
[] returns
= get ("Externs", xPath
);
2056 if (returns
== null) {
2060 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
2062 if (ext
.getTianoR8FlashMapH()){
2069 public Node
getPeiApriori(String fvName
) {
2070 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName
+ "']" };
2071 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2073 if (result
== null || result
.length
== 0) {
2077 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2079 return a
.getDomNode();
2082 public Node
getDxeApriori(String fvName
) {
2083 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2084 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2086 if (result
== null || result
.length
== 0) {
2090 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2092 return a
.getDomNode();
2095 public Node
getFpdModuleSequence(String fvName
) {
2096 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2097 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2099 if (result
== null || result
.length
== 0) {
2103 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2105 return a
.getDomNode();
2109 Get the value of PCD by PCD cName
2111 @return PcdValue String of PcdComponentName
2112 null If don't find ComponentName Pcd
2114 public String
getPcdValueBycName(String cName
){
2115 String
[] xPath
= new String
[] { "/PcdData" };
2116 Object
[] returns
= get("PcdBuildDefinition", xPath
);
2117 if (returns
== null || returns
.length
== 0) {
2120 for (int i
= 0; i
< returns
.length
; i
++) {
2121 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)returns
[i
];
2122 if (pcdData
.getCName().equalsIgnoreCase(cName
)){
2123 return pcdData
.getValue();