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
.frameworkwizard
.platform
.ui
.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
;
23 import java
.util
.Stack
;
24 import java
.util
.regex
.Matcher
;
25 import java
.util
.regex
.Pattern
;
27 import org
.apache
.xmlbeans
.XmlNormalizedString
;
28 import org
.apache
.xmlbeans
.XmlObject
;
29 import org
.apache
.xmlbeans
.XmlString
;
30 import org
.tianocore
.BuildOptionsDocument
;
31 import org
.tianocore
.BuildTargetList
;
32 import org
.tianocore
.DataIdDocument
;
33 import org
.tianocore
.ExternsDocument
;
34 import org
.tianocore
.FileNameConvention
;
35 import org
.tianocore
.FvAttributeDocument
;
36 //import org.tianocore.FvImageDocument;
37 import org
.tianocore
.FvImagesDocument
;
38 import org
.tianocore
.FvOptionDocument
;
39 import org
.tianocore
.GuidDeclarationsDocument
;
40 import org
.tianocore
.GuidsDocument
;
41 import org
.tianocore
.LibrariesDocument
;
42 import org
.tianocore
.LibraryClassDeclarationsDocument
;
43 import org
.tianocore
.LibraryClassDocument
;
44 import org
.tianocore
.ModuleSADocument
;
45 import org
.tianocore
.ModuleTypeDef
;
46 import org
.tianocore
.MsaFilesDocument
;
47 import org
.tianocore
.MsaHeaderDocument
;
48 import org
.tianocore
.OptionDocument
;
49 import org
.tianocore
.PPIsDocument
;
50 import org
.tianocore
.PackageDependenciesDocument
;
51 import org
.tianocore
.PackageHeadersDocument
;
52 import org
.tianocore
.PlatformDefinitionsDocument
;
53 import org
.tianocore
.PpiDeclarationsDocument
;
54 import org
.tianocore
.ProtocolDeclarationsDocument
;
55 import org
.tianocore
.SpdHeaderDocument
;
56 import org
.tianocore
.FilenameDocument
.Filename
;
57 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
58 import org
.tianocore
.ProtocolsDocument
.Protocols
.Protocol
;
59 import org
.tianocore
.ProtocolsDocument
.Protocols
.ProtocolNotify
;
60 import org
.tianocore
.PlatformHeaderDocument
;
61 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.FpdModuleIdentification
;
62 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
63 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
64 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PlatformIdentification
;
67 * SurfaceAreaQuery class is used to query Surface Area information from msa,
68 * mbd, spd and fpd files.
70 * This class should not instantiated. All the public interfaces is static.
74 public class SurfaceAreaQuery
{
76 public static String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
79 // / Contains name/value pairs of Surface Area document object. The name is
80 // / always the top level element name.
82 private static Map
<String
, XmlObject
> map
= null;
85 // / mapStack is used to do nested query
87 private static Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
90 // / prefix of name space
92 private static String nsPrefix
= "sans";
95 // / xmlbeans needs a name space for each Xpath element
97 private static String ns
= null;
100 // / keep the namep declaration for xmlbeans Xpath query
102 private static String queryDeclaration
= null;
105 * Set a Surface Area document for query later
108 * A Surface Area document in TopLevelElementName/XmlObject
111 public static void setDoc(Map
<String
, XmlObject
> map
) {
113 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
114 SurfaceAreaQuery
.map
= map
;
118 * Push current used Surface Area document into query stack. The given new
119 * document will be used for any immediately followed getXXX() callings,
120 * untill pop() is called.
123 * The TopLevelElementName/XmlObject format of a Surface Area
126 public static void push(Map
<String
, XmlObject
> newMap
) {
127 mapStack
.push(SurfaceAreaQuery
.map
);
128 SurfaceAreaQuery
.map
= newMap
;
132 * Discard current used Surface Area document and use the top document in
135 public static void pop() {
136 SurfaceAreaQuery
.map
= mapStack
.pop();
140 // / Convert xPath to be namespace qualified, which is necessary for
142 // / selectPath(). For example, converting /MsaHeader/ModuleType to
143 // / /ns:MsaHeader/ns:ModuleType
145 private static String
normalizeQueryString(String
[] exp
, String from
) {
146 StringBuffer normQueryString
= new StringBuffer(4096);
149 while (i
< exp
.length
) {
150 String newExp
= from
+ exp
[i
];
151 Pattern pattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
152 Matcher matcher
= pattern
.matcher(newExp
);
154 while (matcher
.find()) {
155 String starter
= newExp
.substring(matcher
.start(1), matcher
157 String seperator
= newExp
.substring(matcher
.start(2), matcher
159 String token
= newExp
.substring(matcher
.start(3), matcher
162 normQueryString
.append(starter
);
163 normQueryString
.append(seperator
);
164 normQueryString
.append(nsPrefix
);
165 normQueryString
.append(":");
166 normQueryString
.append(token
);
170 if (i
< exp
.length
) {
171 normQueryString
.append(" | ");
175 return normQueryString
.toString();
179 * Search all XML documents stored in "map" for the specified xPath, using
180 * relative path (starting with '$this')
183 * xpath query string array
184 * @returns An array of XmlObject if elements are found at the specified
186 * @returns NULL if nothing is at the specified xpath
188 public static XmlObject
[] get(String
[] xPath
) {
193 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
194 List
<XmlObject
> result
= new ArrayList
<XmlObject
>();
195 for (int i
= 0; i
< keys
.length
; ++i
) {
196 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
197 if (rootNode
== null) {
201 String query
= queryDeclaration
202 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
203 XmlObject
[] tmp
= rootNode
.selectPath(query
);
204 for (int j
= 0; j
< tmp
.length
; ++j
) {
209 int size
= result
.size();
214 return (XmlObject
[]) result
.toArray(new XmlObject
[size
]);
218 * Search XML documents named by "rootName" for the given xPath, using
219 * relative path (starting with '$this')
222 * The top level element name
224 * The xpath query string array
225 * @returns An array of XmlObject if elements are found at the given xpath
226 * @returns NULL if nothing is found at the given xpath
228 public static XmlObject
[] get(String rootName
, String
[] xPath
) {
233 XmlObject root
= (XmlObject
) map
.get(rootName
);
238 String query
= queryDeclaration
239 + normalizeQueryString(xPath
, "$this/" + rootName
);
240 XmlObject
[] result
= root
.selectPath(query
);
241 if (result
.length
> 0) {
245 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
246 result
= root
.selectPath(query
);
247 if (result
.length
> 0) {
255 * Retrieve SourceFiles/Filename for specified ARCH type
259 * @returns An 2 dimension string array if elements are found at the known
261 * @returns NULL if nothing is found at the known xpath
263 public static String
[][] getSourceFiles(String arch
) {
267 if (arch
== null || arch
.equals("")) {
268 xPath
= new String
[] { "/Filename" };
270 xPath
= new String
[] { "/Filename[not(@SupArchList) or @SupArchList='"
274 returns
= get("SourceFiles", xPath
);
276 if (returns
== null || returns
.length
== 0) {
280 Filename
[] sourceFileNames
= (Filename
[]) returns
;
281 String
[][] outputString
= new String
[sourceFileNames
.length
][2];
282 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
283 outputString
[i
][0] = sourceFileNames
[i
].getToolCode();
284 outputString
[i
][1] = sourceFileNames
[i
].getStringValue();
290 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
292 * @returns Directory names array if elements are found at the known xpath
293 * @returns Empty if nothing is found at the known xpath
295 public static String
getFpdOutputDirectory() {
296 String
[] xPath
= new String
[] { "/PlatformDefinitions/OutputDirectory" };
298 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
299 if (returns
!= null && returns
.length
> 0) {
306 public static String
getFpdIntermediateDirectories() {
307 String
[] xPath
= new String
[] { "/PlatformDefinitions/IntermediateDirectories" };
309 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
310 if (returns
!= null && returns
.length
> 0) {
317 * Retrieve BuildOptions/Option or Arch/Option
319 * @param toolChainFamilyFlag
320 * if true, retrieve options for toolchain family; otherwise for
323 * @returns String[][5] name, target, toolchain, arch, coommand of options
324 * if elements are found at the known xpath. String[0][] if dont
327 * @returns Empty array if nothing is there
329 public static String
[][] getOptions(boolean toolChainFamilyFlag
) {
331 String target
= null;
332 String toolchain
= null;
333 String toolchainFamily
= null;
334 List
<String
> archList
= null;
336 String targetName
= null;
337 String optionName
= null;
339 if (toolChainFamilyFlag
== true) {
340 xPath
= new String
[] {
341 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@ToolChainTag)]",
342 "/BuildOptions/Options/Option[@ToolChainFamily]", };
344 xPath
= new String
[] {
345 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@ToolChainTag)]",
346 "/BuildOptions/Options/Option[@TagName]", };
349 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
350 if (returns
== null) {
351 return new String
[0][5];
354 List
<String
[]> optionList
= new ArrayList
<String
[]>();
355 OptionDocument
.Option option
;
357 for (int i
= 0; i
< returns
.length
; i
++) {
358 option
= (OptionDocument
.Option
) returns
[i
];
361 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
363 // put to result[][5] array in above order.
366 target
= null;//Auber option.getBuildTargets();
367 if (target
!= null) {
368 targetList
= target
.split(" ");
370 targetList
= new String
[1];
371 targetList
[0] = null;
374 if (toolChainFamilyFlag
) {
375 toolchainFamily
= option
.getToolChainFamily();
376 if (toolchainFamily
!= null) {
377 toolchain
= toolchainFamily
.toString();
382 toolchain
= option
.getTagName();
385 archList
= option
.getSupArchList();
386 if (archList
== null) {
390 cmd
= option
.getToolCode();
392 optionName
= option
.getStringValue();
393 for (int t
= 0; t
< targetList
.length
; t
++) {
394 for (int j
= 0; j
< archList
.size(); j
++) {
395 optionList
.add(new String
[] { optionName
, targetList
[i
],
396 toolchain
, archList
.get(j
), cmd
});
401 String
[][] result
= new String
[optionList
.size()][5];
402 for (int i
= 0; i
< optionList
.size(); i
++) {
403 result
[i
][0] = optionList
.get(i
)[0];
404 result
[i
][1] = optionList
.get(i
)[1];
405 result
[i
][2] = optionList
.get(i
)[2];
406 result
[i
][3] = optionList
.get(i
)[3];
407 result
[i
][4] = optionList
.get(i
)[4];
412 public static String
getBuildTarget() {
413 String
[] xPath
= new String
[] { "/PlatformDefinitions/BuildTargets" };
415 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
416 if (returns
!= null && returns
.length
> 0) {
417 return ((BuildTargetList
) returns
[0]).getStringValue();
424 * Retrieve <xxxHeader>/ModuleType
426 * @returns The module type name if elements are found at the known xpath
427 * @returns null if nothing is there
429 public static String
getModuleType() {
430 String
[] xPath
= new String
[] { "/ModuleType" };
432 XmlObject
[] returns
= get(xPath
);
433 if (returns
!= null && returns
.length
> 0) {
434 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
435 return type
.enumValue().toString();
442 * Retrieve PackageDependencies/Package
447 * @returns package name list if elements are found at the known xpath
448 * @returns null if nothing is there
450 public static PackageIdentification
[] getDependencePkg(String arch
) {
452 String packageGuid
= null;
453 String packageVersion
= null;
455 if (arch
== null || arch
.equals("")) {
456 xPath
= new String
[] { "/PackageDependencies/Package" };
458 xPath
= new String
[] { "/PackageDependencies/Package[not(@SupArchList) or @SupArchList='"
462 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
463 if (returns
== null) {
464 return new PackageIdentification
[0];
466 PackageIdentification
[] packageIdList
= new PackageIdentification
[returns
.length
];
467 for (int i
= 0; i
< returns
.length
; i
++) {
468 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
469 packageGuid
= item
.getPackageGuid();
470 packageVersion
= item
.getPackageVersion();
472 Set
<PackageIdentification
> spi
= GlobalData
.getPackageList();
473 Iterator
<PackageIdentification
> ispi
= spi
.iterator();
475 while(ispi
.hasNext()) {
476 PackageIdentification pi
= ispi
.next();
477 if (packageVersion
!= null) {
478 if (pi
.getGuid().equals(packageGuid
) && pi
.getVersion().equals(packageVersion
)) {
479 packageIdList
[i
] = pi
;
484 if (pi
.getGuid().equals(packageGuid
)) {
485 if (pi
.getVersion() != null && pi
.getVersion().compareTo(ver
) > 0){
486 ver
= pi
.getVersion();
487 packageIdList
[i
] = pi
;
489 else if (packageIdList
[i
] == null){
490 packageIdList
[i
] = pi
;
497 return packageIdList
;
501 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
504 * Library class usage
506 * @returns LibraryClass objects list if elements are found at the known
508 * @returns null if nothing is there
510 public static String
[] getLibraryClasses(String usage
) {
513 if (usage
== null || usage
.equals("")) {
514 xPath
= new String
[] { "/LibraryClass" };
516 xPath
= new String
[] { "/LibraryClass[@Usage='" + usage
+ "']" };
519 XmlObject
[] returns
= get("LibraryClassDefinitions", xPath
);
520 if (returns
== null || returns
.length
== 0) {
521 return new String
[0];
524 LibraryClassDocument
.LibraryClass
[] libraryClassList
= (LibraryClassDocument
.LibraryClass
[]) returns
;
525 String
[] libraryClassName
= new String
[libraryClassList
.length
];
526 for (int i
= 0; i
< libraryClassList
.length
; i
++) {
527 libraryClassName
[i
] = libraryClassList
[i
].getKeyword();
529 return libraryClassName
;
533 * Retrieve ModuleEntryPoint names
535 * @returns ModuleEntryPoint name list if elements are found at the known
537 * @returns null if nothing is there
539 public static String
[] getModuleEntryPointArray() {
540 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
542 XmlObject
[] returns
= get("Externs", xPath
);
544 if (returns
!= null && returns
.length
> 0) {
545 String
[] entryPoints
= new String
[returns
.length
];
547 for (int i
= 0; i
< returns
.length
; ++i
) {
548 entryPoints
[i
] = ((XmlNormalizedString
) returns
[i
])
562 * Retrieve ModuleUnloadImage names
564 * @returns ModuleUnloadImage name list if elements are found at the known
566 * @returns null if nothing is there
568 public static String
[] getModuleUnloadImageArray() {
569 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
571 XmlObject
[] returns
= get("Externs", xPath
);
572 if (returns
!= null && returns
.length
> 0) {
573 String
[] stringArray
= new String
[returns
.length
];
574 XmlNormalizedString
[] doc
= (XmlNormalizedString
[]) returns
;
576 for (int i
= 0; i
< returns
.length
; ++i
) {
577 stringArray
[i
] = doc
[i
].getStringValue();
589 * @returns Extern objects list if elements are found at the known xpath
590 * @returns null if nothing is there
592 public static ExternsDocument
.Externs
.Extern
[] getExternArray() {
593 String
[] xPath
= new String
[] { "/Extern" };
595 XmlObject
[] returns
= get("Externs", xPath
);
596 if (returns
!= null && returns
.length
> 0) {
597 return (ExternsDocument
.Externs
.Extern
[]) returns
;
604 * Retrieve Library instance information
609 * Library instance usage
611 * @returns library instance name list if elements are found at the known
613 * @returns null if nothing is there
615 public static ModuleIdentification
[] getLibraryInstance(String arch
) {
617 String saGuid
= null;
618 String saVersion
= null;
619 String pkgGuid
= null;
620 String pkgVersion
= null;
622 if (arch
== null || arch
.equalsIgnoreCase("")) {
623 xPath
= new String
[] { "/Instance" };
625 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
629 XmlObject
[] returns
= get("Libraries", xPath
);
630 if (returns
== null || returns
.length
== 0) {
631 return new ModuleIdentification
[0];
634 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
635 for (int i
= 0; i
< returns
.length
; i
++) {
636 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
637 saGuid
= library
.getModuleGuid();
638 saVersion
= library
.getModuleVersion();
640 pkgGuid
= library
.getPackageGuid();
641 pkgVersion
= library
.getPackageVersion();
643 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
645 PackageIdentification pkgId
= new PackageIdentification(null,
646 pkgGuid
, pkgVersion
);
647 saId
.setPackage(pkgId
);
656 // / This method is used for retrieving the elements information which has
657 // / CName sub-element
659 private static String
[] getCNames(String from
, String xPath
[]) {
660 XmlObject
[] returns
= get(from
, xPath
);
661 if (returns
== null || returns
.length
== 0) {
665 String
[] strings
= new String
[returns
.length
];
666 for (int i
= 0; i
< returns
.length
; ++i
) {
668 // strings[i] = ((CName) returns[i]).getStringValue();
675 * Retrive library's constructor name
677 * @returns constructor name list if elements are found at the known xpath
678 * @returns null if nothing is there
680 public static String
getLibConstructorName() {
681 String
[] xPath
= new String
[] { "/Extern/Constructor" };
683 XmlObject
[] returns
= get("Externs", xPath
);
684 if (returns
!= null && returns
.length
> 0) {
685 // CName constructor = (CName) returns[0];
686 // return constructor.getStringValue();
693 * Retrive library's destructor name
695 * @returns destructor name list if elements are found at the known xpath
696 * @returns null if nothing is there
698 public static String
getLibDestructorName() {
699 String
[] xPath
= new String
[] { "/Extern/Destructor" };
701 XmlObject
[] returns
= get("Externs", xPath
);
702 if (returns
!= null && returns
.length
> 0) {
703 // CName destructor = (CName) returns[0];
704 // return destructor.getStringValue();
711 * Retrive DriverBinding names
713 * @returns DriverBinding name list if elements are found at the known xpath
714 * @returns null if nothing is there
716 public static String
[] getDriverBindingArray() {
717 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
718 return getCNames("Externs", xPath
);
722 * Retrive ComponentName names
724 * @returns ComponentName name list if elements are found at the known xpath
725 * @returns null if nothing is there
727 public static String
[] getComponentNameArray() {
728 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
729 return getCNames("Externs", xPath
);
733 * Retrive DriverConfig names
735 * @returns DriverConfig name list if elements are found at the known xpath
736 * @returns null if nothing is there
738 public static String
[] getDriverConfigArray() {
739 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
740 return getCNames("Externs", xPath
);
744 * Retrive DriverDiag names
746 * @returns DriverDiag name list if elements are found at the known xpath
747 * @returns null if nothing is there
749 public static String
[] getDriverDiagArray() {
750 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
751 return getCNames("Externs", xPath
);
755 * Retrive SetVirtualAddressMapCallBack names
757 * @returns SetVirtualAddressMapCallBack name list if elements are found at
759 * @returns null if nothing is there
761 public static String
[] getSetVirtualAddressMapCallBackArray() {
762 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
763 return getCNames("Externs", xPath
);
767 * Retrive ExitBootServicesCallBack names
769 * @returns ExitBootServicesCallBack name list if elements are found at the
771 * @returns null if nothing is there
773 public static String
[] getExitBootServicesCallBackArray() {
774 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
775 return getCNames("Externs", xPath
);
779 * Retrieve module surface area file information
781 * @returns ModuleSA objects list if elements are found at the known xpath
782 * @returns Empty ModuleSA list if nothing is there
784 public static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() {
785 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
786 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
788 String fvBinding
= null;
789 String saGuid
= null;
790 String saVersion
= null;
791 String pkgGuid
= null;
792 String pkgVersion
= null;
794 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
796 if (result
== null) {
800 for (int i
= 0; i
< result
.length
; i
++) {
802 // Get Fpd SA Module element node and add to xmlObjectMap.
804 Map
<String
, XmlObject
> xmlObjectMap
= new HashMap
<String
, XmlObject
>();
805 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
806 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
807 xmlObjectMap
.put("Libraries", moduleSA
.getLibraries());
809 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
810 xmlObjectMap
.put("PcdBuildDefinition", moduleSA
811 .getPcdBuildDefinition());
813 if (((ModuleSADocument
.ModuleSA
) result
[i
])
814 .getModuleSaBuildOptions() != null) {
815 xmlObjectMap
.put("ModuleSaBuildOptions", moduleSA
816 .getModuleSaBuildOptions());
820 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
822 arch
= moduleSA
.getSupArchList().toString();
826 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
])
829 saGuid
= moduleSA
.getModuleGuid();
830 pkgGuid
= moduleSA
.getPackageGuid();
831 pkgVersion
= moduleSA
.getPackageVersion();
834 // Create Module Identification which have class member of package
837 PackageIdentification pkgId
= new PackageIdentification(null,
838 pkgGuid
, pkgVersion
);
839 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
842 saId
.setPackage(pkgId
);
845 // Create FpdModule Identification which have class member of module
848 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
,
851 fpdSaId
.setArch(arch
);
853 if (fvBinding
!= null) {
854 fpdSaId
.setFvBinding(fvBinding
);
858 // Put element to Map<FpdModuleIdentification, Map<String,
861 fpdModuleMap
.put(fpdSaId
, xmlObjectMap
);
867 * Retrieve valid image names
869 * @returns valid iamges name list if elements are found at the known xpath
870 * @returns empty list if nothing is there
872 public static String
[] getFpdValidImageNames() {
873 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };
875 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
876 if (queryResult
== null) {
877 return new String
[0];
880 String
[] result
= new String
[queryResult
.length
];
881 for (int i
= 0; i
< queryResult
.length
; i
++) {
882 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
890 public static XmlObject
getFpdBuildOptions() {
891 String
[] xPath
= new String
[] { "/BuildOptions" };
893 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
895 if (queryResult
== null || queryResult
.length
== 0) {
898 return queryResult
[0];
901 public static PlatformIdentification
getFpdHeader() {
902 String
[] xPath
= new String
[] { "/PlatformHeader" };
904 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
906 if (returns
== null || returns
.length
== 0) {
909 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
911 String name
= header
.getPlatformName();
913 String guid
= header
.getGuidValue();
915 String version
= header
.getVersion();
917 return new PlatformIdentification(name
, guid
, version
);
921 * Retrieve flash definition file name
923 * @returns file name if elements are found at the known xpath
924 * @returns null if nothing is there
926 public static String
getFlashDefinitionFile() {
927 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
929 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
930 if (queryResult
== null || queryResult
.length
== 0) {
934 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
935 return filename
.getStringValue();
939 * Retrieve FV image component options
944 * @returns name/value pairs list if elements are found at the known xpath
945 * @returns empty list if nothing is there
947 public static String
[][] getFpdComponents(String fvName
) {
948 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"
949 + fvName
.toUpperCase() + "']/DataId" };
951 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
952 if (queryResult
== null) {
953 return new String
[0][];
956 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
957 for (int i
= 0; i
< queryResult
.length
; i
++) {
958 DataIdDocument
.DataId item
= (DataIdDocument
.DataId
) queryResult
[i
];
960 .add(new String
[] { item
.getStringValue(),
961 item
.getDataSize() });
964 String
[][] result
= new String
[list
.size()][2];
965 for (int i
= 0; i
< list
.size(); i
++) {
966 result
[i
][0] = list
.get(i
)[0];
967 result
[i
][1] = list
.get(i
)[1];
974 * Retrieve PCD tokens
976 * @returns CName/ItemType pairs list if elements are found at the known
978 * @returns null if nothing is there
980 public static String
[][] getPcdTokenArray() {
981 String
[] xPath
= new String
[] { "/PcdData" };
983 XmlObject
[] returns
= get("PCDs", xPath
);
984 if (returns
== null || returns
.length
== 0) {
988 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
989 // String[][] result = new String[pcds.length][2];
990 // for (int i = 0; i < returns.length; ++i) {
991 // if (pcds[i].getItemType() != null) {
992 // result[i][1] = pcds[i].getItemType().toString();
994 // result[i][1] = null;
996 // result[i][0] = pcds[i].getCName();
1003 * Get the PcdToken array from module's surface area document. The array
1004 * should contains following data:
1006 * -------------------------------------------------------------------
1009 * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText
1012 * -------------------------------------------------------------------
1015 * Note: Until new schema applying, now we can only get CName, ItemType,
1018 * @return 2-array table contains all information of PCD token retrieved
1021 public static Object
[][] etModulePCDTokenArray() {
1024 // Object[][] result;
1025 // PCDs.PcdData[] pcds;
1026 // String[] xPath = new String[] { "/PcdData" };
1027 // XmlObject[] returns = get("PCDs", xPath);
1029 // if ((returns == null) || (returns.length == 0)) {
1033 // pcds = (PCDs.PcdData[]) returns;
1034 // result = new Object[pcds.length][6];
1035 // for (index = 0; index < pcds.length; index++) {
1039 // result[index][0] = pcds[index].getCName();
1041 // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE,
1042 // // DYNAMIC, DYNAMIC_EX
1044 // if (pcds[index].getItemType() != null) {
1045 // result[index][1] = pcds[index].getItemType().toString();
1047 // result[index][1] = null;
1051 // // BUGBUG: following field can *not* be got from current MSA until
1052 // // schema changed.
1054 // // result [index][2] = pcds[index].getTokenSpaceName();
1055 // result[index][2] = null;
1056 // result[index][3] = pcds[index].getDefaultValue();
1057 // // result [index][4] = pcds[index].getUsage ();
1058 // result[index][4] = null;
1059 // // result [index][5] = pcds[index].getHelpText ();
1060 // result[index][5] = null;
1066 * Retrieve MAS header
1071 public static ModuleIdentification
getMsaHeader() {
1072 String
[] xPath
= new String
[] { "/" };
1073 XmlObject
[] returns
= get("MsaHeader", xPath
);
1075 if (returns
== null || returns
.length
== 0) {
1079 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
1081 // Get BaseName, ModuleType, GuidValue, Version
1082 // which in MsaHeader.
1084 String name
= msaHeader
.getModuleName();
1085 String moduleType
= msaHeader
.getModuleType().toString();
1086 String guid
= msaHeader
.getGuidValue();
1087 String version
= msaHeader
.getVersion();
1089 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
1092 moduleId
.setModuleType(moduleType
);
1098 * Retrieve Extern Specification
1102 * @return String[] If have specification element in the <extern> String[0]
1103 * If no specification element in the <extern>
1107 public static String
[] getExternSpecificaiton() {
1108 String
[] xPath
= new String
[] { "/Specification" };
1110 XmlObject
[] queryResult
= get("Externs", xPath
);
1111 if (queryResult
== null) {
1112 return new String
[0];
1115 String
[] specificationList
= new String
[queryResult
.length
];
1116 for (int i
= 0; i
< queryResult
.length
; i
++) {
1117 // specificationList[i] = ((SpecificationDocument.Specification)
1119 // .getStringValue();
1121 return specificationList
;
1125 * Retreive MsaFile which in SPD
1128 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1129 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1131 public static String
[] getSpdMsaFile() {
1132 String
[] xPath
= new String
[] { "/MsaFiles" };
1134 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1135 if (returns
== null) {
1136 return new String
[0];
1139 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
1141 return filenameList
.toArray(new String
[filenameList
.size()]);
1147 public static Map
<String
, String
[]> getSpdLibraryClasses() {
1148 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
1150 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1153 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1155 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
1157 if (returns
== null) {
1158 return libClassHeaderMap
;
1161 for (int i
= 0; i
< returns
.length
; i
++) {
1162 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
1163 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1164 .getIncludeHeader() });
1166 return libClassHeaderMap
;
1172 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1173 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1175 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1178 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1180 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1182 if (returns
== null) {
1183 return packageIncludeMap
;
1185 GlobalData
.log
.info("" + returns
[0].getClass().getName());
1186 for (int i
= 0; i
< returns
.length
; i
++) {
1187 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1188 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1189 includeHeader
.getStringValue());
1191 return packageIncludeMap
;
1194 public static PackageIdentification
getSpdHeader() {
1195 String
[] xPath
= new String
[] { "/SpdHeader" };
1197 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1199 if (returns
== null || returns
.length
== 0) {
1203 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1205 String name
= header
.getPackageName();
1207 String guid
= header
.getGuidValue();
1209 String version
= header
.getVersion();
1211 return new PackageIdentification(name
, guid
, version
);
1217 public static Map
<String
, String
[]> getSpdGuid() {
1218 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1220 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1223 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1225 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1226 if (returns
== null) {
1230 for (int i
= 0; i
< returns
.length
; i
++) {
1231 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1232 String
[] guidPair
= new String
[2];
1233 guidPair
[0] = entry
.getCName();
1234 guidPair
[1] = entry
.getGuidValue();
1235 guidDeclMap
.put(entry
.getName(), guidPair
);
1243 public static Map
<String
, String
[]> getSpdProtocol() {
1244 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1246 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1249 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1251 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1253 if (returns
== null) {
1257 for (int i
= 0; i
< returns
.length
; i
++) {
1258 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1259 String
[] protocolPair
= new String
[2];
1261 protocolPair
[0] = entry
.getCName();
1262 protocolPair
[1] = entry
.getGuidValue();
1263 protoclMap
.put(entry
.getName(), protocolPair
);
1269 * getSpdPpi() Retrieve the SPD PPI Entry
1272 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1273 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1276 public static Map
<String
, String
[]> getSpdPpi() {
1277 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1279 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1282 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1284 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1286 if (returns
== null) {
1290 for (int i
= 0; i
< returns
.length
; i
++) {
1291 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1292 String
[] ppiPair
= new String
[2];
1293 ppiPair
[0] = entry
.getCName();
1294 ppiPair
[1] = entry
.getGuidValue();
1295 ppiMap
.put(entry
.getName(), ppiPair
);
1301 * getModuleSupportedArchs()
1303 * This function is to Retrieve Archs one module supported.
1306 * @return supportArch String of supporting archs. null No arch specified in
1307 * <MouduleSupport> element.
1309 public static List
<String
> getModuleSupportedArchs() {
1310 String
[] xPath
= new String
[] { "/ModuleDefinitions/SupportedArchitectures" };
1312 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
1314 if (returns
== null) {
1318 return (List
<String
>)returns
[0];
1321 public static XmlObject
[] getSpdPcdDeclarations() {
1322 String
[] xPath
= null;
1323 // if (tsGuid != null){
1324 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1327 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1329 xPath
= new String
[] { "/PcdDeclarations/PcdEntry"};
1330 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1335 public static XmlObject
[] getFpdPcdBuildDefinitions(String cName
, String tsGuid
, String type
) {
1336 String
[] xPath
= new String
[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName
+ "' and TokenSpaceGuid='"
1337 + tsGuid
+ "' and DatumType!='" + type
+ "']" };
1339 XmlObject
[] returns
= get("ModuleSA", xPath
);
1344 * getToolChainFamily
1346 * This function is to retrieve ToolChainFamily attribute of FPD
1350 * @return toolChainFamily If find toolChainFamily attribute in
1351 * <BuildOptions> Null If don't have toolChainFamily in
1354 public String
getToolChainFamily() {
1355 String toolChainFamily
;
1356 String
[] xPath
= new String
[] { "/BuildOptions" };
1358 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1359 if (result
== null) {
1362 // toolChainFamily =
1363 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1364 // return toolChainFamily;
1369 * Retrieve module Guid string
1371 * @returns GUILD string if elements are found at the known xpath
1372 * @returns null if nothing is there
1374 public static String
getModuleGuid() {
1375 String
[] xPath
= new String
[] { "" };
1377 XmlObject
[] returns
= get("MsaHeader", xPath
);
1378 if (returns
!= null && returns
.length
> 0) {
1379 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1390 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1391 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1392 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1393 if (result
!= null) {
1394 return (ModuleSADocument
.ModuleSA
[]) result
;
1396 return new ModuleSADocument
.ModuleSA
[0];