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
.tianocore
.common
.definitions
.EdkDefinitions
;
42 import org
.w3c
.dom
.Node
;
45 * SurfaceAreaQuery class is used to query Surface Area information from msa,
46 * mbd, spd and fpd files.
48 * This class should not instantiated. All the public interfaces is static.
52 public class SurfaceAreaQuery
{
54 public String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
57 // Contains name/value pairs of Surface Area document object. The name is
58 // always the top level element name.
60 private Map
<String
, XmlObject
> map
= null;
63 // mapStack is used to do nested query
65 private Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
68 // prefix of name space
70 private String nsPrefix
= "sans";
73 // xmlbeans needs a name space for each Xpath element
75 private String ns
= null;
78 // keep the namep declaration for xmlbeans Xpath query
80 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
, String moduleType
) {
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();
614 List moduleTypeList
= libraryClassList
[i
].getSupModuleList();
615 if ((arch
== null || contains(archList
, arch
))
616 && (moduleType
== null || contains(moduleTypeList
, moduleType
))) {
617 libraryClassName
.add(libraryClassList
[i
].getKeyword());
621 String
[] libraryArray
= new String
[libraryClassName
.size()];
622 libraryClassName
.toArray(libraryArray
);
627 * Retrieve ModuleEntryPoint names
629 * @returns ModuleEntryPoint name list if elements are found at the known
631 * @returns null if nothing is there
633 public String
[] getModuleEntryPointArray() {
634 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
636 Object
[] returns
= get("Externs", xPath
);
638 if (returns
!= null && returns
.length
> 0) {
639 String
[] entryPoints
= new String
[returns
.length
];
641 for (int i
= 0; i
< returns
.length
; ++i
) {
642 entryPoints
[i
] = ((CNameType
) returns
[i
]).getStringValue();
652 * retrieve Protocol for specified usage
655 * Protocol usage arch Architecture
657 * @returns Protocol String list if elements are found at the known xpath
658 * @returns String[0] if nothing is there
660 public String
[] getProtocolArray(String arch
, String usage
) {
662 String usageXpath
= "";
663 String archXpath
= "";
665 if (arch
== null || arch
.equals("")) {
666 return new String
[0];
668 archXpath
= "/Protocol";
669 if (usage
!= null && !usage
.equals("")) {
670 usageXpath
= "/Protocol[@Usage='" + usage
+ "']";
671 xPath
= new String
[] { usageXpath
, archXpath
};
673 return getProtocolArray(arch
);
678 Object
[] returns
= get("Protocols", xPath
);
679 if (returns
== null) {
680 return new String
[0];
682 Protocol
[] protocolList
= (Protocol
[]) returns
;
684 String
[] protocolArray
= new String
[returns
.length
];
685 for (int i
= 0; i
< returns
.length
; i
++) {
686 protocolArray
[i
] = protocolList
[i
].getProtocolCName();
688 return protocolArray
;
692 * retrieve Protocol for specified usage
697 * @returns Protocol String list if elements are found at the known xpath
698 * @returns String[0] if nothing is there
700 public String
[] getProtocolArray(String arch
) {
703 if (arch
== null || arch
.equals("")) {
704 return new String
[0];
706 xPath
= new String
[] { "/Protocol" };
709 Object
[] returns
= get("Protocols", xPath
);
710 if (returns
== null) {
711 return new String
[0];
713 Protocol
[] returnlList
= (Protocol
[]) returns
;
715 List
<String
> protocolList
= new ArrayList
<String
>();
717 for (int i
= 0; i
< returns
.length
; i
++) {
718 List archList
= returnlList
[i
].getSupArchList();
719 if (archList
== null || contains(archList
, arch
)){
720 protocolList
.add(returnlList
[i
].getProtocolCName());
723 String
[] protocolArray
= new String
[protocolList
.size()];
724 for (int i
= 0; i
< protocolList
.size(); i
++) {
725 protocolArray
[i
] = protocolList
.get(i
);
727 return protocolArray
;
731 * Retrieve ProtocolNotify for specified usage
734 * ProtocolNotify usage
736 * @returns String[] if elements are found at the known xpath
737 * @returns String[0] if nothing is there
739 public String
[] getProtocolNotifyArray(String arch
) {
742 if (arch
== null || arch
.equals("")) {
743 return new String
[0];
745 xPath
= new String
[] { "/ProtocolNotify" };
748 Object
[] returns
= get("Protocols", xPath
);
749 if (returns
== null) {
750 return new String
[0];
753 List
<String
> protocolNotifyList
= new ArrayList
<String
>();
755 for (int i
= 0; i
< returns
.length
; i
++) {
756 List archList
= ((ProtocolNotify
) returns
[i
]).getSupArchList();
757 if (archList
== null || contains(archList
, arch
)){
758 protocolNotifyList
.add(((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName());
762 String
[] protocolNotifyArray
= new String
[protocolNotifyList
.size()];
763 for (int i
= 0; i
< protocolNotifyList
.size(); i
++) {
764 protocolNotifyArray
[i
] = protocolNotifyList
.get(i
);
766 return protocolNotifyArray
;
770 * Retrieve ProtocolNotify for specified usage
773 * ProtocolNotify usage
775 * @returns String[] if elements are found at the known xpath
776 * @returns String[0] if nothing is there
778 public String
[] getProtocolNotifyArray(String arch
, String usage
) {
784 if (arch
== null || arch
.equals("")) {
785 return new String
[0];
787 archXpath
= "/ProtocolNotify";
788 if (usage
!= null && !usage
.equals("")) {
789 usageXpath
= "/ProtocolNotify[@Usage='" + arch
+ "']";
790 xPath
= new String
[] { archXpath
, usageXpath
};
792 return getProtocolNotifyArray(arch
);
796 Object
[] returns
= get("Protocols", xPath
);
797 if (returns
== null) {
798 return new String
[0];
801 String
[] protocolNotifyList
= new String
[returns
.length
];
803 for (int i
= 0; i
< returns
.length
; i
++) {
804 protocolNotifyList
[i
] = ((ProtocolNotify
) returns
[i
]).getProtocolNotifyCName();
806 return protocolNotifyList
;
810 * Retrieve ModuleUnloadImage names
812 * @returns ModuleUnloadImage name list if elements are found at the known
814 * @returns null if nothing is there
816 public String
[] getModuleUnloadImageArray() {
817 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
819 Object
[] returns
= get("Externs", xPath
);
820 if (returns
!= null && returns
.length
> 0) {
821 String
[] stringArray
= new String
[returns
.length
];
822 CNameType
[] doc
= (CNameType
[]) returns
;
824 for (int i
= 0; i
< returns
.length
; ++i
) {
825 stringArray
[i
] = doc
[i
].getStringValue();
837 * @returns Extern objects list if elements are found at the known xpath
838 * @returns null if nothing is there
840 public ExternsDocument
.Externs
.Extern
[] getExternArray() {
841 String
[] xPath
= new String
[] { "/Extern" };
843 Object
[] returns
= get("Externs", xPath
);
844 if (returns
!= null && returns
.length
> 0) {
845 return (ExternsDocument
.Externs
.Extern
[]) returns
;
852 * Retrieve PpiNotify for specified arch
857 * @returns String[] if elements are found at the known xpath
858 * @returns String[0] if nothing is there
860 public String
[] getPpiNotifyArray(String arch
) {
863 if (arch
== null || arch
.equals("")) {
864 return new String
[0];
866 xPath
= new String
[] { "/PpiNotify" };
869 Object
[] returns
= get("PPIs", xPath
);
870 if (returns
== null) {
871 return new String
[0];
875 List
<String
> ppiNotifyList
= new ArrayList
<String
>();
876 for (int i
= 0; i
< returns
.length
; i
++) {
877 List archList
= ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getSupArchList();
878 if (archList
== null || contains(archList
, arch
)){
879 ppiNotifyList
.add(((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName());
883 String
[] ppiNotifyArray
= new String
[ppiNotifyList
.size()];
884 for (int i
= 0; i
< ppiNotifyList
.size(); i
++) {
885 ppiNotifyArray
[i
] = ppiNotifyList
.get(i
);
888 return ppiNotifyArray
;
892 * Retrieve PpiNotify for specified usage and arch
895 * PpiNotify arch usage PpiNotify usage
898 * @returns String[] if elements are found at the known xpath
899 * @returns String[0] if nothing is there
901 public String
[] getPpiNotifyArray(String arch
, String usage
) {
907 if (arch
== null || arch
.equals("")) {
908 return new String
[0];
910 archXpath
= "/PpiNotify";
911 if (usage
!= null && !usage
.equals("")) {
912 usageXpath
= "/PpiNotify[@Usage='" + arch
+ "']";
913 xPath
= new String
[] { archXpath
, usageXpath
};
915 return getProtocolNotifyArray(arch
);
919 Object
[] returns
= get("PPIs", xPath
);
920 if (returns
== null) {
921 return new String
[0];
924 String
[] ppiNotifyList
= new String
[returns
.length
];
926 for (int i
= 0; i
< returns
.length
; i
++) {
927 ppiNotifyList
[i
] = ((PPIsDocument
.PPIs
.PpiNotify
) returns
[i
]).getPpiNotifyCName();
929 return ppiNotifyList
;
933 * Retrieve Ppi for specified arch
938 * @returns String[] if elements are found at the known xpath
939 * @returns String[0] if nothing is there
941 public String
[] getPpiArray(String arch
) {
944 if (arch
== null || arch
.equals("")) {
945 return new String
[0];
947 xPath
= new String
[] { "/Ppi" };
950 Object
[] returns
= get("PPIs", xPath
);
951 if (returns
== null) {
952 return new String
[0];
955 List
<String
> ppiList
= new ArrayList
<String
>();
956 for (int i
= 0; i
< returns
.length
; i
++) {
957 List archList
= ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getSupArchList();
958 if (archList
== null || contains(archList
, arch
)){
959 ppiList
.add(((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName());
963 String
[] ppiArray
= new String
[ppiList
.size()];
964 for (int i
= 0; i
< ppiList
.size(); i
++) {
965 ppiArray
[i
] = ppiList
.get(i
);
971 * Retrieve PpiNotify for specified usage and arch
974 * PpiNotify arch usage PpiNotify usage
977 * @returns String[] if elements are found at the known xpath
978 * @returns String[0] if nothing is there
980 public String
[] getPpiArray(String arch
, String usage
) {
986 if (arch
== null || arch
.equals("")) {
987 return new String
[0];
990 if (usage
!= null && !usage
.equals("")) {
991 usageXpath
= "/Ppi[@Usage='" + arch
+ "']";
992 xPath
= new String
[] { archXpath
, usageXpath
};
994 return getProtocolNotifyArray(arch
);
998 Object
[] returns
= get("PPIs", xPath
);
999 if (returns
== null) {
1000 return new String
[0];
1003 String
[] ppiList
= new String
[returns
.length
];
1005 for (int i
= 0; i
< returns
.length
; i
++) {
1006 ppiList
[i
] = ((PPIsDocument
.PPIs
.Ppi
) returns
[i
]).getPpiCName();
1012 * Retrieve GuidEntry information for specified usage
1017 * @returns GuidEntry objects list if elements are found at the known xpath
1018 * @returns null if nothing is there
1020 public String
[] getGuidEntryArray(String arch
) {
1023 if (arch
== null || arch
.equals("")) {
1024 xPath
= new String
[] { "/GuidCNames" };
1026 xPath
= new String
[] { "/GuidCNames" };
1029 Object
[] returns
= get("Guids", xPath
);
1030 if (returns
== null) {
1031 return new String
[0];
1034 List
<String
> guidList
= new ArrayList
<String
>();
1035 for (int i
= 0; i
< returns
.length
; i
++) {
1036 List archList
= ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getSupArchList();
1037 if (archList
== null || contains(archList
, arch
)){
1038 guidList
.add(((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName());
1042 String
[] guidArray
= new String
[guidList
.size()];
1043 for (int i
= 0; i
< guidList
.size(); i
++) {
1044 guidArray
[i
] = guidList
.get(i
);
1051 * Retrieve GuidEntry information for specified usage
1054 * GuidEntry arch usage GuidEntry usage
1056 * @returns GuidEntry objects list if elements are found at the known xpath
1057 * @returns null if nothing is there
1059 public String
[] getGuidEntryArray(String arch
, String usage
) {
1064 if (arch
== null || arch
.equals("")) {
1065 return new String
[0];
1067 archXpath
= "/GuidEntry";
1068 if (usage
!= null && !usage
.equals("")) {
1069 usageXpath
= "/GuidEntry[@Usage='" + arch
+ "']";
1070 xPath
= new String
[] { archXpath
, usageXpath
};
1072 return getProtocolNotifyArray(arch
);
1076 Object
[] returns
= get("Guids", xPath
);
1077 if (returns
== null) {
1078 return new String
[0];
1081 String
[] guidList
= new String
[returns
.length
];
1083 for (int i
= 0; i
< returns
.length
; i
++) {
1084 guidList
[i
] = ((GuidsDocument
.Guids
.GuidCNames
) returns
[i
]).getGuidCName();
1090 * Retrieve Library instance information
1095 * Library instance usage
1097 * @returns library instance name list if elements are found at the known
1099 * @returns null if nothing is there
1101 public ModuleIdentification
[] getLibraryInstance(String arch
) throws EdkException
{
1103 String saGuid
= null;
1104 String saVersion
= null;
1105 String pkgGuid
= null;
1106 String pkgVersion
= null;
1108 if (arch
== null || arch
.equalsIgnoreCase("")) {
1109 xPath
= new String
[] { "/Instance" };
1112 // Since Schema don't have SupArchList now, so the follow Xpath is
1113 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1114 // don't have effect.
1116 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
1120 Object
[] returns
= get("Libraries", xPath
);
1121 if (returns
== null || returns
.length
== 0) {
1122 return new ModuleIdentification
[0];
1125 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
1126 for (int i
= 0; i
< returns
.length
; i
++) {
1127 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
1128 saGuid
= library
.getModuleGuid();
1129 saVersion
= library
.getModuleVersion();
1131 pkgGuid
= library
.getPackageGuid();
1132 pkgVersion
= library
.getPackageVersion();
1134 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
1136 PackageIdentification pkgId
= new PackageIdentification(null,
1137 pkgGuid
, pkgVersion
);
1138 GlobalData
.refreshPackageIdentification(pkgId
);
1139 saId
.setPackage(pkgId
);
1140 GlobalData
.refreshModuleIdentification(saId
);
1149 // / This method is used for retrieving the elements information which has
1150 // / CName sub-element
1152 private String
[] getCNames(String from
, String xPath
[]) {
1153 Object
[] returns
= get(from
, xPath
);
1154 if (returns
== null || returns
.length
== 0) {
1158 String
[] strings
= new String
[returns
.length
];
1159 for (int i
= 0; i
< returns
.length
; ++i
) {
1161 strings
[i
] = ((CNameType
) returns
[i
]).getStringValue();
1168 * Retrive library's constructor name
1170 * @returns constructor name list if elements are found at the known xpath
1171 * @returns null if nothing is there
1173 public String
getLibConstructorName() {
1174 String
[] xPath
= new String
[] { "/Extern/Constructor" };
1176 Object
[] returns
= get("Externs", xPath
);
1177 if (returns
!= null && returns
.length
> 0) {
1178 CNameType constructor
= ((CNameType
) returns
[0]);
1179 return constructor
.getStringValue();
1186 * Retrive library's destructor name
1188 * @returns destructor name list if elements are found at the known xpath
1189 * @returns null if nothing is there
1191 public String
getLibDestructorName() {
1192 String
[] xPath
= new String
[] { "/Extern/Destructor" };
1194 Object
[] returns
= get("Externs", xPath
);
1195 if (returns
!= null && returns
.length
> 0) {
1197 // Only support one Destructor function.
1199 CNameType destructor
= (CNameType
) returns
[0];
1200 return destructor
.getStringValue();
1207 * Retrive DriverBinding names
1209 * @returns DriverBinding name list if elements are found at the known xpath
1210 * @returns null if nothing is there
1212 public String
[] getDriverBindingArray() {
1213 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
1214 return getCNames("Externs", xPath
);
1218 * Retrive ComponentName names
1220 * @returns ComponentName name list if elements are found at the known xpath
1221 * @returns null if nothing is there
1223 public String
[] getComponentNameArray() {
1224 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
1225 return getCNames("Externs", xPath
);
1229 * Retrive DriverConfig names
1231 * @returns DriverConfig name list if elements are found at the known xpath
1232 * @returns null if nothing is there
1234 public String
[] getDriverConfigArray() {
1235 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
1236 return getCNames("Externs", xPath
);
1240 * Retrive DriverDiag names
1242 * @returns DriverDiag name list if elements are found at the known xpath
1243 * @returns null if nothing is there
1245 public String
[] getDriverDiagArray() {
1246 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
1247 return getCNames("Externs", xPath
);
1251 * Retrive DriverBinding, ComponentName, DriverConfig,
1252 * DriverDiag group array
1254 * @returns DriverBinding group name list if elements are found
1255 * at the known xpath
1256 * @returns null if nothing is there
1258 public String
[][] getExternProtocolGroup() {
1259 String
[] xPath
= new String
[] {"/Extern"};
1260 Object
[] returns
= get("Externs",xPath
);
1262 if (returns
== null) {
1263 return new String
[0][4];
1265 List
<Extern
> externList
= new ArrayList
<Extern
>();
1266 for (int i
= 0; i
< returns
.length
; i
++) {
1267 org
.tianocore
.ExternsDocument
.Externs
.Extern extern
= (org
.tianocore
.ExternsDocument
.Externs
.Extern
)returns
[i
];
1268 if (extern
.getDriverBinding() != null) {
1269 externList
.add(extern
);
1273 String
[][] externGroup
= new String
[externList
.size()][4];
1274 for (int i
= 0; i
< externList
.size(); i
++) {
1275 String driverBindingStr
= externList
.get(i
).getDriverBinding();
1276 if ( driverBindingStr
!= null){
1277 externGroup
[i
][0] = driverBindingStr
;
1279 externGroup
[i
][0] = null;
1282 String componentNameStr
= externList
.get(i
).getComponentName();
1283 if (componentNameStr
!= null) {
1284 externGroup
[i
][1] = componentNameStr
;
1286 externGroup
[i
][1] = null;
1289 String driverConfigStr
= externList
.get(i
).getDriverConfig();
1290 if (driverConfigStr
!= null) {
1291 externGroup
[i
][2] = driverConfigStr
;
1293 externGroup
[i
][2] = null;
1296 String driverDiagStr
= externList
.get(i
).getDriverDiag();
1297 if (driverDiagStr
!= null) {
1298 externGroup
[i
][3] = driverDiagStr
;
1300 externGroup
[i
][3] = null;
1307 * Retrive SetVirtualAddressMapCallBack names
1309 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1311 * @returns null if nothing is there
1313 public String
[] getSetVirtualAddressMapCallBackArray() {
1314 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
1315 return getCNames("Externs", xPath
);
1319 * Retrive ExitBootServicesCallBack names
1321 * @returns ExitBootServicesCallBack name list if elements are found at the
1323 * @returns null if nothing is there
1325 public String
[] getExitBootServicesCallBackArray() {
1326 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
1327 return getCNames("Externs", xPath
);
1331 Judge whether current driver is PEI_PCD_DRIVER or DXE_PCD_DRIVER or
1334 @return CommonDefinition.PCD_DRIVER_TYPE the type of current driver
1336 public CommonDefinition
.PCD_DRIVER_TYPE
getPcdDriverType() {
1337 String
[] xPath
= new String
[] {"/PcdIsDriver"};
1338 Object
[] results
= get ("Externs", xPath
);
1340 if (results
!= null && results
.length
!= 0) {
1341 PcdDriverTypes type
= (PcdDriverTypes
) results
[0];
1342 String typeStr
= type
.enumValue().toString();
1343 if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
.toString())) {
1344 return CommonDefinition
.PCD_DRIVER_TYPE
.PEI_PCD_DRIVER
;
1345 } else if (typeStr
.equals(CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
.toString())) {
1346 return CommonDefinition
.PCD_DRIVER_TYPE
.DXE_PCD_DRIVER
;
1348 return CommonDefinition
.PCD_DRIVER_TYPE
.UNKNOWN_PCD_DRIVER
;
1351 return CommonDefinition
.PCD_DRIVER_TYPE
.NOT_PCD_DRIVER
;
1355 * Retrieve module surface area file information
1357 * @returns ModuleSA objects list if elements are found at the known xpath
1358 * @returns Empty ModuleSA list if nothing is there
1360 public Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() throws EdkException
{
1361 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1362 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1364 String fvBinding
= null;
1365 String saGuid
= null;
1366 String saVersion
= null;
1367 String pkgGuid
= null;
1368 String pkgVersion
= null;
1370 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
1372 if (result
== null) {
1373 return fpdModuleMap
;
1376 for (int i
= 0; i
< result
.length
; i
++) {
1378 // Get Fpd SA Module element node and add to ObjectMap.
1380 Map
<String
, XmlObject
> ObjectMap
= new HashMap
<String
, XmlObject
>();
1381 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
1382 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
1383 ObjectMap
.put("Libraries", moduleSA
.getLibraries());
1385 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
1386 ObjectMap
.put("PcdBuildDefinition", moduleSA
.getPcdBuildDefinition());
1388 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleSaBuildOptions() != null) {
1389 ObjectMap
.put("ModuleSaBuildOptions", moduleSA
.getModuleSaBuildOptions());
1393 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1395 if (moduleSA
.isSetSupArchList()) {
1396 arch
= moduleSA
.getSupArchList().toString();
1403 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
]).getModuleVersion();
1405 saGuid
= moduleSA
.getModuleGuid();
1406 pkgGuid
= moduleSA
.getPackageGuid();
1407 pkgVersion
= moduleSA
.getPackageVersion();
1410 // Create Module Identification which have class member of package
1413 PackageIdentification pkgId
= new PackageIdentification(null, pkgGuid
, pkgVersion
);
1414 GlobalData
.refreshPackageIdentification(pkgId
);
1416 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
, saVersion
);
1417 saId
.setPackage(pkgId
);
1418 GlobalData
.refreshModuleIdentification(saId
);
1423 // Create FpdModule Identification which have class member of module
1426 String
[] archList
= new String
[0];
1427 if (arch
== null || arch
.trim().length() == 0) {
1428 archList
= GlobalData
.getToolChainInfo().getArchs();
1430 archList
= arch
.split(" ");
1432 for (int j
= 0; j
< archList
.length
; j
++) {
1433 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
, archList
[j
]);
1435 if (fvBinding
!= null) {
1436 fpdSaId
.setFvBinding(fvBinding
);
1440 // Put element to Map<FpdModuleIdentification, Map<String,
1443 fpdModuleMap
.put(fpdSaId
, ObjectMap
);
1446 return fpdModuleMap
;
1450 * Retrieve valid image names
1452 * @returns valid iamges name list if elements are found at the known xpath
1453 * @returns empty list if nothing is there
1455 public String
[] getFpdValidImageNames() {
1456 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1458 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1459 if (queryResult
== null) {
1460 return new String
[0];
1463 String
[] result
= new String
[queryResult
.length
];
1464 for (int i
= 0; i
< queryResult
.length
; i
++) {
1465 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
1471 public Node
getFpdUserExtensionPreBuild() {
1472 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='0']" };
1474 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1475 if (queryResult
== null || queryResult
.length
== 0) {
1478 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1480 return a
.getDomNode();
1483 public Node
getFpdUserExtensionPostBuild() {
1484 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and @Identifier='1']" };
1486 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1487 if (queryResult
== null || queryResult
.length
== 0) {
1490 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[0];
1492 return a
.getDomNode();
1495 public Node
[] getFpdUserExtensions() {
1496 String
[] xPath
= new String
[] { "/UserExtensions[@UserID='TianoCore' and not(@Identifier='1') and not(@Identifier='0')]" };
1498 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1499 if (queryResult
== null || queryResult
.length
== 0) {
1503 Node
[] nodeList
= new Node
[queryResult
.length
];
1504 for (int i
= 0; i
< queryResult
.length
; ++i
) {
1505 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)queryResult
[i
];
1506 nodeList
[i
] = a
.getDomNode();
1512 * Retrieve FV image option information
1517 * @returns option name/value list if elements are found at the known xpath
1518 * @returns empty list if nothing is there
1520 public String
[][] getFpdOptions(String fvName
) {
1521 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1522 + fvName
+ "']/FvImageOptions" };
1523 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1524 if (queryResult
== null) {
1525 return new String
[0][];
1527 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1528 for (int i
= 0; i
< queryResult
.length
; i
++) {
1529 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1530 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
1531 .getNameValueList();
1532 Iterator iter
= namevalues
.iterator();
1533 while (iter
.hasNext()) {
1534 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1536 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1539 String
[][] result
= new String
[list
.size()][2];
1540 for (int i
= 0; i
< list
.size(); i
++) {
1541 result
[i
][0] = list
.get(i
)[0];
1542 result
[i
][1] = list
.get(i
)[1];
1548 public XmlObject
getFpdBuildOptions() {
1549 String
[] xPath
= new String
[] { "/BuildOptions" };
1551 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1553 if (queryResult
== null || queryResult
.length
== 0) {
1556 return (XmlObject
)queryResult
[0];
1559 public PlatformIdentification
getFpdHeader() {
1560 String
[] xPath
= new String
[] { "/PlatformHeader" };
1562 Object
[] returns
= get("PlatformSurfaceArea", xPath
);
1564 if (returns
== null || returns
.length
== 0) {
1567 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
1569 String name
= header
.getPlatformName();
1571 String guid
= header
.getGuidValue();
1573 String version
= header
.getVersion();
1575 return new PlatformIdentification(name
, guid
, version
);
1579 * Retrieve FV image attributes information
1584 * @returns attribute name/value list if elements are found at the known
1586 * @returns empty list if nothing is there
1588 public String
[][] getFpdAttributes(String fvName
) {
1589 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1590 + fvName
+ "']/FvImageOptions" };
1591 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1592 if (queryResult
== null) {
1593 return new String
[0][];
1595 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1596 for (int i
= 0; i
< queryResult
.length
; i
++) {
1598 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1599 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1600 Iterator iter
= namevalues
.iterator();
1601 while (iter
.hasNext()) {
1602 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1604 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1607 String
[][] result
= new String
[list
.size()][2];
1608 for (int i
= 0; i
< list
.size(); i
++) {
1609 result
[i
][0] = list
.get(i
)[0];
1610 result
[i
][1] = list
.get(i
)[1];
1616 * Retrieve flash definition file name
1618 * @returns file name if elements are found at the known xpath
1619 * @returns null if nothing is there
1621 public String
getFlashDefinitionFile() {
1622 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1624 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1625 if (queryResult
== null || queryResult
.length
== 0) {
1629 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
1630 return filename
.getStringValue();
1633 public String
[][] getFpdGlobalVariable() {
1634 String
[] xPath
= new String
[] { "/Flash/FvImages/NameValue" };
1635 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1636 if (queryResult
== null) {
1637 return new String
[0][];
1640 String
[][] result
= new String
[queryResult
.length
][2];
1642 for (int i
= 0; i
< queryResult
.length
; i
++) {
1643 FvImagesDocument
.FvImages
.NameValue item
= (FvImagesDocument
.FvImages
.NameValue
)queryResult
[i
];
1644 result
[i
][0] = item
.getName();
1645 result
[i
][1] = item
.getValue();
1651 * Retrieve FV image component options
1656 * @returns name/value pairs list if elements are found at the known xpath
1657 * @returns empty list if nothing is there
1659 public String
[][] getFpdComponents(String fvName
) {
1660 String
[] xPath
= new String
[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName
+ "']/FvImageOptions" };
1661 Object
[] queryResult
= get("PlatformSurfaceArea", xPath
);
1662 if (queryResult
== null) {
1663 return new String
[0][];
1666 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
1667 for (int i
= 0; i
< queryResult
.length
; i
++) {
1668 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions item
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
) queryResult
[i
];
1669 List
<FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
> namevalues
= item
.getNameValueList();
1670 Iterator iter
= namevalues
.iterator();
1671 while (iter
.hasNext()) {
1672 FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue nvItem
= (FvImagesDocument
.FvImages
.FvImage
.FvImageOptions
.NameValue
) iter
1674 list
.add(new String
[] { nvItem
.getName(), nvItem
.getValue() });
1677 String
[][] result
= new String
[list
.size()][2];
1678 for (int i
= 0; i
< list
.size(); i
++) {
1679 result
[i
][0] = list
.get(i
)[0];
1680 result
[i
][1] = list
.get(i
)[1];
1686 * Retrieve PCD tokens
1688 * @returns CName/ItemType pairs list if elements are found at the known
1690 * @returns null if nothing is there
1692 public String
[][] getPcdTokenArray() {
1693 String
[] xPath
= new String
[] { "/PcdData" };
1695 Object
[] returns
= get("PCDs", xPath
);
1696 if (returns
== null || returns
.length
== 0) {
1704 * Retrieve MAS header
1709 public ModuleIdentification
getMsaHeader() {
1710 String
[] xPath
= new String
[] { "/" };
1711 Object
[] returns
= get("MsaHeader", xPath
);
1713 if (returns
== null || returns
.length
== 0) {
1717 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1719 // Get BaseName, ModuleType, GuidValue, Version
1720 // which in MsaHeader.
1722 String name
= msaHeader
.getModuleName();
1723 String moduleType
= msaHeader
.getModuleType().toString();
1724 String guid
= msaHeader
.getGuidValue();
1725 String version
= msaHeader
.getVersion();
1727 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1730 moduleId
.setModuleType(moduleType
);
1736 * Retrieve Extern Specification
1740 * @return String[] If have specification element in the <extern> String[0]
1741 * If no specification element in the <extern>
1745 public String
[] getExternSpecificaiton() {
1746 String
[] xPath
= new String
[] { "/Specification" };
1748 Object
[] queryResult
= get("Externs", xPath
);
1749 if (queryResult
== null) {
1750 return new String
[0];
1753 String
[] specificationList
= new String
[queryResult
.length
];
1754 for (int i
= 0; i
< queryResult
.length
; i
++) {
1755 specificationList
[i
] = ((Sentence
)queryResult
[i
])
1758 return specificationList
;
1762 * Retreive MsaFile which in SPD
1765 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1766 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1768 public String
[] getSpdMsaFile() {
1769 String
[] xPath
= new String
[] { "/MsaFiles" };
1771 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1772 if (returns
== null) {
1773 return new String
[0];
1776 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1778 return filenameList
.toArray(new String
[filenameList
.size()]);
1784 public Map
<String
, String
[]> getSpdLibraryClasses() {
1785 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1787 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1790 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1792 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1794 if (returns
== null) {
1795 return libClassHeaderMap
;
1798 for (int i
= 0; i
< returns
.length
; i
++) {
1799 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1800 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1801 .getIncludeHeader() });
1803 return libClassHeaderMap
;
1809 public Map
<String
, String
> getSpdPackageHeaderFiles() {
1810 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1812 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1815 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1817 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1819 if (returns
== null) {
1820 return packageIncludeMap
;
1823 for (int i
= 0; i
< returns
.length
; i
++) {
1824 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1825 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1826 includeHeader
.getStringValue());
1828 return packageIncludeMap
;
1831 public PackageIdentification
getSpdHeader() {
1832 String
[] xPath
= new String
[] { "/SpdHeader" };
1834 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1836 if (returns
== null || returns
.length
== 0) {
1840 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1842 String name
= header
.getPackageName();
1844 String guid
= header
.getGuidValue();
1846 String version
= header
.getVersion();
1848 return new PackageIdentification(name
, guid
, version
);
1854 public Map
<String
, String
[]> getSpdGuid() {
1855 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1857 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1860 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1862 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1863 if (returns
== null) {
1867 for (int i
= 0; i
< returns
.length
; i
++) {
1868 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1869 String
[] guidPair
= new String
[2];
1870 guidPair
[0] = entry
.getCName();
1871 guidPair
[1] = entry
.getGuidValue();
1872 guidDeclMap
.put(entry
.getCName(), guidPair
);
1880 public Map
<String
, String
[]> getSpdProtocol() {
1881 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1883 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1886 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1888 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1890 if (returns
== null) {
1894 for (int i
= 0; i
< returns
.length
; i
++) {
1895 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1896 String
[] protocolPair
= new String
[2];
1898 protocolPair
[0] = entry
.getCName();
1899 protocolPair
[1] = entry
.getGuidValue();
1900 protoclMap
.put(entry
.getCName(), protocolPair
);
1906 * getSpdPpi() Retrieve the SPD PPI Entry
1909 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1910 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1913 public Map
<String
, String
[]> getSpdPpi() {
1914 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1916 Object
[] returns
= get("PackageSurfaceArea", xPath
);
1919 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1921 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1923 if (returns
== null) {
1927 for (int i
= 0; i
< returns
.length
; i
++) {
1928 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1929 String
[] ppiPair
= new String
[2];
1930 ppiPair
[0] = entry
.getCName();
1931 ppiPair
[1] = entry
.getGuidValue();
1932 ppiMap
.put(entry
.getCName(), ppiPair
);
1938 * Retrieve module Guid string
1940 * @returns GUILD string if elements are found at the known xpath
1941 * @returns null if nothing is there
1943 public String
getModuleGuid() {
1944 String
[] xPath
= new String
[] { "" };
1946 Object
[] returns
= get("MsaHeader", xPath
);
1947 if (returns
!= null && returns
.length
> 0) {
1948 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1959 public ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1960 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1961 Object
[] result
= get("PlatformSurfaceArea", xPath
);
1962 if (result
!= null) {
1963 return (ModuleSADocument
.ModuleSA
[]) result
;
1965 return new ModuleSADocument
.ModuleSA
[0];
1970 Get name array who contains all PCDs in a module according to specified arch.
1972 @param arch The specified architecture type.
1974 @return String[] return all PCDs name into array, if no any PCD used by
1975 this module, a String[0] array is returned.
1977 public String
[] getModulePcdEntryNameArray(String arch
) {
1978 PcdCodedDocument
.PcdCoded
.PcdEntry
[] pcdEntries
= null;
1979 java
.util
.List archList
= null;
1980 java
.util
.List
<String
> results
= new java
.util
.ArrayList
<String
> ();
1982 String
[] xPath
= new String
[] {"/PcdEntry"};
1983 Object
[] returns
= get ("PcdCoded", xPath
);
1985 if (returns
== null) {
1986 return new String
[0];
1989 pcdEntries
= (PcdCodedDocument
.PcdCoded
.PcdEntry
[])returns
;
1991 for (index
= 0; index
< pcdEntries
.length
; index
++) {
1992 archList
= pcdEntries
[index
].getSupArchList();
1994 // If the ArchList is specified in MSA for this PCD, need check
1995 // current arch whether can support by this PCD.
1997 if (archList
!= null) {
1998 if (archList
.contains(arch
)) {
1999 results
.add(new String(pcdEntries
[index
].getCName()));
2003 // If no ArchList is specificied in MSA for this PCD, that means
2004 // this PCD support all architectures.
2006 results
.add(new String(pcdEntries
[index
].getCName()));
2010 if (results
.size() == 0) {
2011 return new String
[0];
2014 String
[] retArray
= new String
[results
.size()];
2015 results
.toArray(retArray
);
2021 Search in a List for a given string
2025 public boolean contains(List list
, String str
) {
2026 if (list
== null || list
.size()== 0) {
2030 return list
.contains(str
);
2033 public boolean isHaveTianoR8FlashMap(){
2034 String
[] xPath
= new String
[] {"/"};
2035 Object
[] returns
= get ("Externs", xPath
);
2037 if (returns
== null) {
2041 ExternsDocument
.Externs ext
= (ExternsDocument
.Externs
)returns
[0];
2043 if (ext
.getTianoR8FlashMapH()){
2050 public Node
getPeiApriori(String fvName
) {
2051 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='0' and ./FvName='" + fvName
+ "']" };
2052 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2054 if (result
== null || result
.length
== 0) {
2058 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2060 return a
.getDomNode();
2063 public Node
getDxeApriori(String fvName
) {
2064 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='APRIORI' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2065 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2067 if (result
== null || result
.length
== 0) {
2071 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2073 return a
.getDomNode();
2076 public Node
getFpdModuleSequence(String fvName
) {
2077 String
[] xPath
= new String
[] { "/BuildOptions/UserExtensions[@UserID='IMAGES' and @Identifier='1' and ./FvName='" + fvName
+ "']" };
2078 Object
[] result
= get("PlatformSurfaceArea", xPath
);
2080 if (result
== null || result
.length
== 0) {
2084 UserExtensionsDocument
.UserExtensions a
= (UserExtensionsDocument
.UserExtensions
)result
[0];
2086 return a
.getDomNode();
2090 Get the value of PCD by PCD cName
2092 @return PcdValue String of PcdComponentName
2093 null If don't find ComponentName Pcd
2095 public String
getPcdValueBycName(String cName
){
2096 String
[] xPath
= new String
[] { "/PcdData" };
2097 Object
[] returns
= get("PcdBuildDefinition", xPath
);
2098 if (returns
== null || returns
.length
== 0) {
2101 for (int i
= 0; i
< returns
.length
; i
++) {
2102 PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData pcdData
= (PcdBuildDefinitionDocument
.PcdBuildDefinition
.PcdData
)returns
[i
];
2103 if (pcdData
.getCName().equalsIgnoreCase(cName
)){
2104 return pcdData
.getValue();