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
.Vector
;
25 import java
.util
.regex
.Matcher
;
26 import java
.util
.regex
.Pattern
;
28 import org
.apache
.xmlbeans
.XmlNormalizedString
;
29 import org
.apache
.xmlbeans
.XmlObject
;
30 import org
.apache
.xmlbeans
.XmlString
;
31 import org
.tianocore
.BuildTargetList
;
32 import org
.tianocore
.DataIdDocument
;
33 import org
.tianocore
.ExternsDocument
;
34 import org
.tianocore
.FileNameConvention
;
35 //import org.tianocore.FvImageDocument;
36 import org
.tianocore
.GuidDeclarationsDocument
;
37 import org
.tianocore
.LibrariesDocument
;
38 import org
.tianocore
.LibraryClassDeclarationsDocument
;
39 import org
.tianocore
.LibraryClassDocument
;
40 import org
.tianocore
.ModuleSADocument
;
41 import org
.tianocore
.ModuleSurfaceAreaDocument
;
42 import org
.tianocore
.ModuleTypeDef
;
43 import org
.tianocore
.MsaFilesDocument
;
44 import org
.tianocore
.MsaHeaderDocument
;
45 import org
.tianocore
.PackageDependenciesDocument
;
46 import org
.tianocore
.PackageHeadersDocument
;
47 import org
.tianocore
.PpiDeclarationsDocument
;
48 import org
.tianocore
.ProtocolDeclarationsDocument
;
49 import org
.tianocore
.SpdHeaderDocument
;
50 import org
.tianocore
.FilenameDocument
.Filename
;
51 import org
.tianocore
.MsaHeaderDocument
.MsaHeader
;
52 import org
.tianocore
.PlatformHeaderDocument
;
53 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.FpdModuleIdentification
;
54 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.ModuleIdentification
;
55 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PackageIdentification
;
56 import org
.tianocore
.frameworkwizard
.platform
.ui
.id
.PlatformIdentification
;
59 * SurfaceAreaQuery class is used to query Surface Area information from msa,
60 * mbd, spd and fpd files.
62 * This class should not instantiated. All the public interfaces is static.
66 public class SurfaceAreaQuery
{
68 public static String prefix
= "http://www.TianoCore.org/2006/Edk2.0";
71 // / Contains name/value pairs of Surface Area document object. The name is
72 // / always the top level element name.
74 private static Map
<String
, XmlObject
> map
= null;
77 // / mapStack is used to do nested query
79 private static Stack
<Map
<String
, XmlObject
>> mapStack
= new Stack
<Map
<String
, XmlObject
>>();
82 // / prefix of name space
84 private static String nsPrefix
= "sans";
87 // / xmlbeans needs a name space for each Xpath element
89 private static String ns
= null;
92 // / keep the namep declaration for xmlbeans Xpath query
94 private static String queryDeclaration
= null;
97 * Set a Surface Area document for query later
100 * A Surface Area document in TopLevelElementName/XmlObject
103 public static void setDoc(Map
<String
, XmlObject
> map
) {
105 queryDeclaration
= "declare namespace " + nsPrefix
+ "='" + ns
+ "'; ";
106 SurfaceAreaQuery
.map
= map
;
110 * Push current used Surface Area document into query stack. The given new
111 * document will be used for any immediately followed getXXX() callings,
112 * untill pop() is called.
115 * The TopLevelElementName/XmlObject format of a Surface Area
118 public static void push(Map
<String
, XmlObject
> newMap
) {
119 mapStack
.push(SurfaceAreaQuery
.map
);
120 SurfaceAreaQuery
.map
= newMap
;
124 * Discard current used Surface Area document and use the top document in
127 public static void pop() {
128 SurfaceAreaQuery
.map
= mapStack
.pop();
132 // / Convert xPath to be namespace qualified, which is necessary for
134 // / selectPath(). For example, converting /MsaHeader/ModuleType to
135 // / /ns:MsaHeader/ns:ModuleType
137 private static String
normalizeQueryString(String
[] exp
, String from
) {
138 StringBuffer normQueryString
= new StringBuffer(4096);
141 while (i
< exp
.length
) {
142 String newExp
= from
+ exp
[i
];
143 Pattern pattern
= Pattern
.compile("([^/]*)(/|//)([^/]+)");
144 Matcher matcher
= pattern
.matcher(newExp
);
146 while (matcher
.find()) {
147 String starter
= newExp
.substring(matcher
.start(1), matcher
149 String seperator
= newExp
.substring(matcher
.start(2), matcher
151 String token
= newExp
.substring(matcher
.start(3), matcher
154 normQueryString
.append(starter
);
155 normQueryString
.append(seperator
);
156 normQueryString
.append(nsPrefix
);
157 normQueryString
.append(":");
158 normQueryString
.append(token
);
162 if (i
< exp
.length
) {
163 normQueryString
.append(" | ");
167 return normQueryString
.toString();
171 * Search all XML documents stored in "map" for the specified xPath, using
172 * relative path (starting with '$this')
175 * xpath query string array
176 * @returns An array of XmlObject if elements are found at the specified
178 * @returns NULL if nothing is at the specified xpath
180 public static XmlObject
[] get(String
[] xPath
) {
185 String
[] keys
= (String
[]) map
.keySet().toArray(new String
[map
.size()]);
186 List
<XmlObject
> result
= new ArrayList
<XmlObject
>();
187 for (int i
= 0; i
< keys
.length
; ++i
) {
188 XmlObject rootNode
= (XmlObject
) map
.get(keys
[i
]);
189 if (rootNode
== null) {
193 String query
= queryDeclaration
194 + normalizeQueryString(xPath
, "$this/" + keys
[i
]);
195 XmlObject
[] tmp
= rootNode
.selectPath(query
);
196 for (int j
= 0; j
< tmp
.length
; ++j
) {
201 int size
= result
.size();
206 return (XmlObject
[]) result
.toArray(new XmlObject
[size
]);
210 * Search XML documents named by "rootName" for the given xPath, using
211 * relative path (starting with '$this')
214 * The top level element name
216 * The xpath query string array
217 * @returns An array of XmlObject if elements are found at the given xpath
218 * @returns NULL if nothing is found at the given xpath
220 public static XmlObject
[] get(String rootName
, String
[] xPath
) {
225 XmlObject root
= (XmlObject
) map
.get(rootName
);
230 String query
= queryDeclaration
231 + normalizeQueryString(xPath
, "$this/" + rootName
);
232 XmlObject
[] result
= root
.selectPath(query
);
233 if (result
.length
> 0) {
237 query
= queryDeclaration
+ normalizeQueryString(xPath
, "/" + rootName
);
238 result
= root
.selectPath(query
);
239 if (result
.length
> 0) {
247 * Retrieve SourceFiles/Filename for specified ARCH type
251 * @returns An 2 dimension string array if elements are found at the known
253 * @returns NULL if nothing is found at the known xpath
255 public static String
[][] getSourceFiles(String arch
) {
259 if (arch
== null || arch
.equals("")) {
260 xPath
= new String
[] { "/Filename" };
262 xPath
= new String
[] { "/Filename[not(@SupArchList) or @SupArchList='"
266 returns
= get("SourceFiles", xPath
);
268 if (returns
== null || returns
.length
== 0) {
272 Filename
[] sourceFileNames
= (Filename
[]) returns
;
273 String
[][] outputString
= new String
[sourceFileNames
.length
][2];
274 for (int i
= 0; i
< sourceFileNames
.length
; i
++) {
275 outputString
[i
][0] = sourceFileNames
[i
].getToolCode();
276 outputString
[i
][1] = sourceFileNames
[i
].getStringValue();
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 static String
getFpdOutputDirectory() {
288 String
[] xPath
= new String
[] { "/PlatformDefinitions/OutputDirectory" };
290 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
291 if (returns
!= null && returns
.length
> 0) {
298 public static String
getFpdIntermediateDirectories() {
299 String
[] xPath
= new String
[] { "/PlatformDefinitions/IntermediateDirectories" };
301 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
302 if (returns
!= null && returns
.length
> 0) {
308 public static String
getBuildTarget() {
309 String
[] xPath
= new String
[] { "/PlatformDefinitions/BuildTargets" };
311 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
312 if (returns
!= null && returns
.length
> 0) {
313 return ((BuildTargetList
) returns
[0]).getStringValue();
320 * Retrieve <xxxHeader>/ModuleType
322 * @returns The module type name if elements are found at the known xpath
323 * @returns null if nothing is there
325 public static String
getModuleType() {
326 String
[] xPath
= new String
[] { "/ModuleType" };
328 XmlObject
[] returns
= get(xPath
);
329 if (returns
!= null && returns
.length
> 0) {
330 ModuleTypeDef type
= (ModuleTypeDef
) returns
[0];
331 return type
.enumValue().toString();
338 * Retrieve PackageDependencies/Package
343 * @returns package name list if elements are found at the known xpath
344 * @returns null if nothing is there
347 public static PackageIdentification
[] getDependencePkg(String arch
, ModuleIdentification mi
) throws Exception
{
349 String packageGuid
= null;
350 String packageVersion
= null;
352 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
) WorkspaceProfile
.getModuleXmlObject(mi
);
353 if (msa
.getPackageDependencies() == null) {
354 return new PackageIdentification
[0];
356 int size
= msa
.getPackageDependencies().getPackageList().size();
357 XmlObject
[] returns
= new XmlObject
[size
];
358 for (int i
= 0; i
< size
; ++i
) {
359 returns
[i
] = msa
.getPackageDependencies().getPackageList().get(i
);
362 PackageIdentification
[] packageIdList
= new PackageIdentification
[returns
.length
];
363 for (int i
= 0; i
< returns
.length
; i
++) {
364 PackageDependenciesDocument
.PackageDependencies
.Package item
= (PackageDependenciesDocument
.PackageDependencies
.Package
) returns
[i
];
365 packageGuid
= item
.getPackageGuid();
366 packageVersion
= item
.getPackageVersion();
368 Set
<PackageIdentification
> spi
= WorkspaceProfile
.getPackageList();
369 Iterator
<PackageIdentification
> ispi
= spi
.iterator();
371 while(ispi
.hasNext()) {
372 PackageIdentification pi
= ispi
.next();
373 if (packageVersion
!= null) {
374 if (pi
.getGuid().equalsIgnoreCase(packageGuid
) && pi
.getVersion().equals(packageVersion
)) {
375 packageIdList
[i
] = pi
;
380 if (pi
.getGuid().equalsIgnoreCase(packageGuid
)) {
381 if (pi
.getVersion() != null && pi
.getVersion().compareTo(ver
) > 0){
382 ver
= pi
.getVersion();
383 packageIdList
[i
] = pi
;
385 else if (packageIdList
[i
] == null){
386 packageIdList
[i
] = pi
;
393 return packageIdList
;
397 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
400 * Library class usage
402 * @returns LibraryClass objects list if elements are found at the known
404 * @returns null if nothing is there
406 public static Vector
<String
> getLibraryClasses(String usage
, ModuleIdentification mi
) throws Exception
{
407 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= (ModuleSurfaceAreaDocument
.ModuleSurfaceArea
)WorkspaceProfile
.getModuleXmlObject(mi
);
408 Vector
<String
> libraryClassName
= new Vector
<String
>();
409 if (msa
.getLibraryClassDefinitions() == null) {
410 return libraryClassName
;
413 int size
= msa
.getLibraryClassDefinitions().getLibraryClassList().size();
415 for (int i
= 0; i
< size
; i
++) {
416 LibraryClassDocument
.LibraryClass libClass
= msa
.getLibraryClassDefinitions().getLibraryClassList().get(i
);
417 if (usage
.equals(libClass
.getUsage().toString())) {
418 libraryClassName
.add(libClass
.getKeyword());
422 return libraryClassName
;
426 * Retrieve ModuleEntryPoint names
428 * @returns ModuleEntryPoint name list if elements are found at the known
430 * @returns null if nothing is there
432 public static String
[] getModuleEntryPointArray() {
433 String
[] xPath
= new String
[] { "/Extern/ModuleEntryPoint" };
435 XmlObject
[] returns
= get("Externs", xPath
);
437 if (returns
!= null && returns
.length
> 0) {
438 String
[] entryPoints
= new String
[returns
.length
];
440 for (int i
= 0; i
< returns
.length
; ++i
) {
441 entryPoints
[i
] = ((XmlNormalizedString
) returns
[i
])
455 * Retrieve ModuleUnloadImage names
457 * @returns ModuleUnloadImage name list if elements are found at the known
459 * @returns null if nothing is there
461 public static String
[] getModuleUnloadImageArray() {
462 String
[] xPath
= new String
[] { "/Extern/ModuleUnloadImage" };
464 XmlObject
[] returns
= get("Externs", xPath
);
465 if (returns
!= null && returns
.length
> 0) {
466 String
[] stringArray
= new String
[returns
.length
];
467 XmlNormalizedString
[] doc
= (XmlNormalizedString
[]) returns
;
469 for (int i
= 0; i
< returns
.length
; ++i
) {
470 stringArray
[i
] = doc
[i
].getStringValue();
482 * @returns Extern objects list if elements are found at the known xpath
483 * @returns null if nothing is there
485 public static ExternsDocument
.Externs
.Extern
[] getExternArray() {
486 String
[] xPath
= new String
[] { "/Extern" };
488 XmlObject
[] returns
= get("Externs", xPath
);
489 if (returns
!= null && returns
.length
> 0) {
490 return (ExternsDocument
.Externs
.Extern
[]) returns
;
497 * Retrieve Library instance information
502 * Library instance usage
504 * @returns library instance name list if elements are found at the known
506 * @returns null if nothing is there
508 public static ModuleIdentification
[] getLibraryInstance(String arch
) {
510 String saGuid
= null;
511 String saVersion
= null;
512 String pkgGuid
= null;
513 String pkgVersion
= null;
515 if (arch
== null || arch
.equalsIgnoreCase("")) {
516 xPath
= new String
[] { "/Instance" };
518 xPath
= new String
[] { "/Instance[not(@SupArchList) or @SupArchList='"
522 XmlObject
[] returns
= get("Libraries", xPath
);
523 if (returns
== null || returns
.length
== 0) {
524 return new ModuleIdentification
[0];
527 ModuleIdentification
[] saIdList
= new ModuleIdentification
[returns
.length
];
528 for (int i
= 0; i
< returns
.length
; i
++) {
529 LibrariesDocument
.Libraries
.Instance library
= (LibrariesDocument
.Libraries
.Instance
) returns
[i
];
530 saGuid
= library
.getModuleGuid();
531 saVersion
= library
.getModuleVersion();
533 pkgGuid
= library
.getPackageGuid();
534 pkgVersion
= library
.getPackageVersion();
536 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
538 PackageIdentification pkgId
= new PackageIdentification(null,
539 pkgGuid
, pkgVersion
);
540 saId
.setPackage(pkgId
);
549 // / This method is used for retrieving the elements information which has
550 // / CName sub-element
552 private static String
[] getCNames(String from
, String xPath
[]) {
553 XmlObject
[] returns
= get(from
, xPath
);
554 if (returns
== null || returns
.length
== 0) {
558 String
[] strings
= new String
[returns
.length
];
559 for (int i
= 0; i
< returns
.length
; ++i
) {
561 // strings[i] = ((CName) returns[i]).getStringValue();
568 * Retrive library's constructor name
570 * @returns constructor name list if elements are found at the known xpath
571 * @returns null if nothing is there
573 public static String
getLibConstructorName() {
574 String
[] xPath
= new String
[] { "/Extern/Constructor" };
576 XmlObject
[] returns
= get("Externs", xPath
);
577 if (returns
!= null && returns
.length
> 0) {
578 // CName constructor = (CName) returns[0];
579 // return constructor.getStringValue();
586 * Retrive library's destructor name
588 * @returns destructor name list if elements are found at the known xpath
589 * @returns null if nothing is there
591 public static String
getLibDestructorName() {
592 String
[] xPath
= new String
[] { "/Extern/Destructor" };
594 XmlObject
[] returns
= get("Externs", xPath
);
595 if (returns
!= null && returns
.length
> 0) {
596 // CName destructor = (CName) returns[0];
597 // return destructor.getStringValue();
604 * Retrive DriverBinding names
606 * @returns DriverBinding name list if elements are found at the known xpath
607 * @returns null if nothing is there
609 public static String
[] getDriverBindingArray() {
610 String
[] xPath
= new String
[] { "/Extern/DriverBinding" };
611 return getCNames("Externs", xPath
);
615 * Retrive ComponentName names
617 * @returns ComponentName name list if elements are found at the known xpath
618 * @returns null if nothing is there
620 public static String
[] getComponentNameArray() {
621 String
[] xPath
= new String
[] { "/Extern/ComponentName" };
622 return getCNames("Externs", xPath
);
626 * Retrive DriverConfig names
628 * @returns DriverConfig name list if elements are found at the known xpath
629 * @returns null if nothing is there
631 public static String
[] getDriverConfigArray() {
632 String
[] xPath
= new String
[] { "/Extern/DriverConfig" };
633 return getCNames("Externs", xPath
);
637 * Retrive DriverDiag names
639 * @returns DriverDiag name list if elements are found at the known xpath
640 * @returns null if nothing is there
642 public static String
[] getDriverDiagArray() {
643 String
[] xPath
= new String
[] { "/Extern/DriverDiag" };
644 return getCNames("Externs", xPath
);
648 * Retrive SetVirtualAddressMapCallBack names
650 * @returns SetVirtualAddressMapCallBack name list if elements are found at
652 * @returns null if nothing is there
654 public static String
[] getSetVirtualAddressMapCallBackArray() {
655 String
[] xPath
= new String
[] { "/Extern/SetVirtualAddressMapCallBack" };
656 return getCNames("Externs", xPath
);
660 * Retrive ExitBootServicesCallBack names
662 * @returns ExitBootServicesCallBack name list if elements are found at the
664 * @returns null if nothing is there
666 public static String
[] getExitBootServicesCallBackArray() {
667 String
[] xPath
= new String
[] { "/Extern/ExitBootServicesCallBack" };
668 return getCNames("Externs", xPath
);
672 * Retrieve module surface area file information
674 * @returns ModuleSA objects list if elements are found at the known xpath
675 * @returns Empty ModuleSA list if nothing is there
677 public static Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> getFpdModules() {
678 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
679 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
681 String fvBinding
= null;
682 String saGuid
= null;
683 String saVersion
= null;
684 String pkgGuid
= null;
685 String pkgVersion
= null;
687 Map
<FpdModuleIdentification
, Map
<String
, XmlObject
>> fpdModuleMap
= new LinkedHashMap
<FpdModuleIdentification
, Map
<String
, XmlObject
>>();
689 if (result
== null) {
693 for (int i
= 0; i
< result
.length
; i
++) {
695 // Get Fpd SA Module element node and add to xmlObjectMap.
697 Map
<String
, XmlObject
> xmlObjectMap
= new HashMap
<String
, XmlObject
>();
698 ModuleSADocument
.ModuleSA moduleSA
= (ModuleSADocument
.ModuleSA
) result
[i
];
699 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getLibraries() != null) {
700 xmlObjectMap
.put("Libraries", moduleSA
.getLibraries());
702 if (((ModuleSADocument
.ModuleSA
) result
[i
]).getPcdBuildDefinition() != null) {
703 xmlObjectMap
.put("PcdBuildDefinition", moduleSA
704 .getPcdBuildDefinition());
706 if (((ModuleSADocument
.ModuleSA
) result
[i
])
707 .getModuleSaBuildOptions() != null) {
708 xmlObjectMap
.put("ModuleSaBuildOptions", moduleSA
709 .getModuleSaBuildOptions());
713 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
715 arch
= moduleSA
.getSupArchList().toString();
719 saVersion
= ((ModuleSADocument
.ModuleSA
) result
[i
])
722 saGuid
= moduleSA
.getModuleGuid();
723 pkgGuid
= moduleSA
.getPackageGuid();
724 pkgVersion
= moduleSA
.getPackageVersion();
727 // Create Module Identification which have class member of package
730 PackageIdentification pkgId
= new PackageIdentification(null,
731 pkgGuid
, pkgVersion
);
732 ModuleIdentification saId
= new ModuleIdentification(null, saGuid
,
735 saId
.setPackage(pkgId
);
738 // Create FpdModule Identification which have class member of module
741 FpdModuleIdentification fpdSaId
= new FpdModuleIdentification(saId
,
744 fpdSaId
.setArch(arch
);
746 if (fvBinding
!= null) {
747 fpdSaId
.setFvBinding(fvBinding
);
751 // Put element to Map<FpdModuleIdentification, Map<String,
754 fpdModuleMap
.put(fpdSaId
, xmlObjectMap
);
760 * Retrieve valid image names
762 * @returns valid iamges name list if elements are found at the known xpath
763 * @returns empty list if nothing is there
765 public static String
[] getFpdValidImageNames() {
766 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };
768 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
769 if (queryResult
== null) {
770 return new String
[0];
773 String
[] result
= new String
[queryResult
.length
];
774 for (int i
= 0; i
< queryResult
.length
; i
++) {
775 result
[i
] = ((XmlString
) queryResult
[i
]).getStringValue();
783 public static XmlObject
getFpdBuildOptions() {
784 String
[] xPath
= new String
[] { "/BuildOptions" };
786 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
788 if (queryResult
== null || queryResult
.length
== 0) {
791 return queryResult
[0];
794 public static PlatformIdentification
getFpdHeader() {
795 String
[] xPath
= new String
[] { "/PlatformHeader" };
797 XmlObject
[] returns
= get("FrameworkPlatformDescription", xPath
);
799 if (returns
== null || returns
.length
== 0) {
802 PlatformHeaderDocument
.PlatformHeader header
= (PlatformHeaderDocument
.PlatformHeader
) returns
[0];
804 String name
= header
.getPlatformName();
806 String guid
= header
.getGuidValue();
808 String version
= header
.getVersion();
810 return new PlatformIdentification(name
, guid
, version
);
814 * Retrieve flash definition file name
816 * @returns file name if elements are found at the known xpath
817 * @returns null if nothing is there
819 public static String
getFlashDefinitionFile() {
820 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
822 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
823 if (queryResult
== null || queryResult
.length
== 0) {
827 FileNameConvention filename
= (FileNameConvention
) queryResult
[queryResult
.length
- 1];
828 return filename
.getStringValue();
832 * Retrieve FV image component options
837 * @returns name/value pairs list if elements are found at the known xpath
838 * @returns empty list if nothing is there
840 public static String
[][] getFpdComponents(String fvName
) {
841 String
[] xPath
= new String
[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"
842 + fvName
.toUpperCase() + "']/DataId" };
844 XmlObject
[] queryResult
= get("FrameworkPlatformDescription", xPath
);
845 if (queryResult
== null) {
846 return new String
[0][];
849 ArrayList
<String
[]> list
= new ArrayList
<String
[]>();
850 for (int i
= 0; i
< queryResult
.length
; i
++) {
851 DataIdDocument
.DataId item
= (DataIdDocument
.DataId
) queryResult
[i
];
853 .add(new String
[] { item
.getStringValue(),
854 item
.getDataSize() });
857 String
[][] result
= new String
[list
.size()][2];
858 for (int i
= 0; i
< list
.size(); i
++) {
859 result
[i
][0] = list
.get(i
)[0];
860 result
[i
][1] = list
.get(i
)[1];
867 * Retrieve PCD tokens
869 * @returns CName/ItemType pairs list if elements are found at the known
871 * @returns null if nothing is there
873 public static String
[][] getPcdTokenArray() {
874 String
[] xPath
= new String
[] { "/PcdData" };
876 XmlObject
[] returns
= get("PCDs", xPath
);
877 if (returns
== null || returns
.length
== 0) {
881 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
882 // String[][] result = new String[pcds.length][2];
883 // for (int i = 0; i < returns.length; ++i) {
884 // if (pcds[i].getItemType() != null) {
885 // result[i][1] = pcds[i].getItemType().toString();
887 // result[i][1] = null;
889 // result[i][0] = pcds[i].getCName();
898 * Retrieve MSA header
903 public static ModuleIdentification
getMsaHeader() {
904 String
[] xPath
= new String
[] { "/" };
905 XmlObject
[] returns
= get("MsaHeader", xPath
);
907 if (returns
== null || returns
.length
== 0) {
911 MsaHeader msaHeader
= (MsaHeader
) returns
[0];
913 // Get BaseName, ModuleType, GuidValue, Version
914 // which in MsaHeader.
916 String name
= msaHeader
.getModuleName();
917 String moduleType
= "";
918 if (msaHeader
.getModuleType() != null) {
919 moduleType
= msaHeader
.getModuleType().toString();
922 String guid
= msaHeader
.getGuidValue();
923 String version
= msaHeader
.getVersion();
925 ModuleIdentification moduleId
= new ModuleIdentification(name
, guid
,
928 moduleId
.setModuleType(moduleType
);
934 * Retrieve Extern Specification
938 * @return String[] If have specification element in the <extern> String[0]
939 * If no specification element in the <extern>
943 public static String
[] getExternSpecificaiton() {
944 String
[] xPath
= new String
[] { "/Specification" };
946 XmlObject
[] queryResult
= get("Externs", xPath
);
947 if (queryResult
== null) {
948 return new String
[0];
951 String
[] specificationList
= new String
[queryResult
.length
];
952 for (int i
= 0; i
< queryResult
.length
; i
++) {
953 // specificationList[i] = ((SpecificationDocument.Specification)
955 // .getStringValue();
957 return specificationList
;
961 * Retreive MsaFile which in SPD
964 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
965 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
967 public static String
[] getSpdMsaFile() {
968 String
[] xPath
= new String
[] { "/MsaFiles" };
970 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
971 if (returns
== null) {
972 return new String
[0];
975 List
<String
> filenameList
= ((MsaFilesDocument
.MsaFiles
) returns
[0])
977 return filenameList
.toArray(new String
[filenameList
.size()]);
983 public static Map
<String
, String
[]> getSpdLibraryClasses() {
984 String
[] xPath
= new String
[] { "/LibraryClassDeclarations/LibraryClass" };
986 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
989 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
991 Map
<String
, String
[]> libClassHeaderMap
= new HashMap
<String
, String
[]>();
993 if (returns
== null) {
994 return libClassHeaderMap
;
997 for (int i
= 0; i
< returns
.length
; i
++) {
998 LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass library
= (LibraryClassDeclarationsDocument
.LibraryClassDeclarations
.LibraryClass
) returns
[i
];
999 libClassHeaderMap
.put(library
.getName(), new String
[] { library
1000 .getIncludeHeader() });
1002 return libClassHeaderMap
;
1008 public static Map
<String
, String
> getSpdPackageHeaderFiles() {
1009 String
[] xPath
= new String
[] { "/PackageHeaders/IncludePkgHeader" };
1011 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1014 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1016 Map
<String
, String
> packageIncludeMap
= new HashMap
<String
, String
>();
1018 if (returns
== null) {
1019 return packageIncludeMap
;
1021 WorkspaceProfile
.log
.info("" + returns
[0].getClass().getName());
1022 for (int i
= 0; i
< returns
.length
; i
++) {
1023 PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader includeHeader
= (PackageHeadersDocument
.PackageHeaders
.IncludePkgHeader
) returns
[i
];
1024 packageIncludeMap
.put(includeHeader
.getModuleType().toString(),
1025 includeHeader
.getStringValue());
1027 return packageIncludeMap
;
1030 public static PackageIdentification
getSpdHeader() {
1031 String
[] xPath
= new String
[] { "/SpdHeader" };
1033 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1035 if (returns
== null || returns
.length
== 0) {
1039 SpdHeaderDocument
.SpdHeader header
= (SpdHeaderDocument
.SpdHeader
) returns
[0];
1041 String name
= header
.getPackageName();
1043 String guid
= header
.getGuidValue();
1045 String version
= header
.getVersion();
1047 return new PackageIdentification(name
, guid
, version
);
1053 public static Map
<String
, String
[]> getSpdGuid() {
1054 String
[] xPath
= new String
[] { "/GuidDeclarations/Entry" };
1056 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1059 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1061 Map
<String
, String
[]> guidDeclMap
= new HashMap
<String
, String
[]>();
1062 if (returns
== null) {
1066 for (int i
= 0; i
< returns
.length
; i
++) {
1067 GuidDeclarationsDocument
.GuidDeclarations
.Entry entry
= (GuidDeclarationsDocument
.GuidDeclarations
.Entry
) returns
[i
];
1068 String
[] guidPair
= new String
[2];
1069 guidPair
[0] = entry
.getCName();
1070 guidPair
[1] = entry
.getGuidValue();
1071 guidDeclMap
.put(entry
.getName(), guidPair
);
1079 public static Map
<String
, String
[]> getSpdProtocol() {
1080 String
[] xPath
= new String
[] { "/ProtocolDeclarations/Entry" };
1082 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1085 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1087 Map
<String
, String
[]> protoclMap
= new HashMap
<String
, String
[]>();
1089 if (returns
== null) {
1093 for (int i
= 0; i
< returns
.length
; i
++) {
1094 ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry entry
= (ProtocolDeclarationsDocument
.ProtocolDeclarations
.Entry
) returns
[i
];
1095 String
[] protocolPair
= new String
[2];
1097 protocolPair
[0] = entry
.getCName();
1098 protocolPair
[1] = entry
.getGuidValue();
1099 protoclMap
.put(entry
.getName(), protocolPair
);
1105 * getSpdPpi() Retrieve the SPD PPI Entry
1108 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1109 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1112 public static Map
<String
, String
[]> getSpdPpi() {
1113 String
[] xPath
= new String
[] { "/PpiDeclarations/Entry" };
1115 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1118 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1120 Map
<String
, String
[]> ppiMap
= new HashMap
<String
, String
[]>();
1122 if (returns
== null) {
1126 for (int i
= 0; i
< returns
.length
; i
++) {
1127 PpiDeclarationsDocument
.PpiDeclarations
.Entry entry
= (PpiDeclarationsDocument
.PpiDeclarations
.Entry
) returns
[i
];
1128 String
[] ppiPair
= new String
[2];
1129 ppiPair
[0] = entry
.getCName();
1130 ppiPair
[1] = entry
.getGuidValue();
1131 ppiMap
.put(entry
.getName(), ppiPair
);
1137 * getModuleSupportedArchs()
1139 * This function is to Retrieve Archs one module supported.
1142 * @return supportArch String of supporting archs. null No arch specified in
1143 * <MouduleSupport> element.
1145 public static List
<String
> getModuleSupportedArchs() {
1146 String
[] xPath
= new String
[] { "/ModuleDefinitions/SupportedArchitectures" };
1148 XmlObject
[] returns
= get("ModuleSurfaceArea", xPath
);
1150 if (returns
== null) {
1154 return (List
<String
>)returns
[0];
1157 public static XmlObject
[] getSpdPcdDeclarations() {
1158 String
[] xPath
= null;
1159 // if (tsGuid != null){
1160 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1163 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1165 xPath
= new String
[] { "/PcdDeclarations/PcdEntry"};
1166 XmlObject
[] returns
= get("PackageSurfaceArea", xPath
);
1171 public static XmlObject
[] getFpdPcdBuildDefinitions(String cName
, String tsGuid
, String type
) {
1172 String
[] xPath
= new String
[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName
+ "' and TokenSpaceGuid='"
1173 + tsGuid
+ "' and DatumType!='" + type
+ "']" };
1175 XmlObject
[] returns
= get("ModuleSA", xPath
);
1180 * getToolChainFamily
1182 * This function is to retrieve ToolChainFamily attribute of FPD
1186 * @return toolChainFamily If find toolChainFamily attribute in
1187 * <BuildOptions> Null If don't have toolChainFamily in
1190 public String
getToolChainFamily() {
1191 String
[] xPath
= new String
[] { "/BuildOptions" };
1193 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1194 if (result
== null) {
1197 // toolChainFamily =
1198 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1199 // return toolChainFamily;
1204 * Retrieve module Guid string
1206 * @returns GUILD string if elements are found at the known xpath
1207 * @returns null if nothing is there
1209 public static String
getModuleGuid() {
1210 String
[] xPath
= new String
[] { "" };
1212 XmlObject
[] returns
= get("MsaHeader", xPath
);
1213 if (returns
!= null && returns
.length
> 0) {
1214 String guid
= ((MsaHeaderDocument
.MsaHeader
) returns
[0])
1225 public static ModuleSADocument
.ModuleSA
[] getFpdModuleSAs() {
1226 String
[] xPath
= new String
[] { "/FrameworkModules/ModuleSA" };
1227 XmlObject
[] result
= get("FrameworkPlatformDescription", xPath
);
1228 if (result
!= null) {
1229 return (ModuleSADocument
.ModuleSA
[]) result
;
1231 return new ModuleSADocument
.ModuleSA
[0];