]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java
Fix EDKT191.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / global / SurfaceAreaQuery.java
CommitLineData
a13899c5 1/** @file\r
2 This file is for surface area information retrieval.\r
3\r
4 Copyright (c) 2006, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 **/\r
14package org.tianocore.frameworkwizard.platform.ui.global;\r
15\r
16import java.util.ArrayList;\r
17import java.util.HashMap;\r
18import java.util.Iterator;\r
19import java.util.LinkedHashMap;\r
20import java.util.List;\r
21import java.util.Map;\r
22import java.util.Set;\r
23import java.util.Stack;\r
daa4663b 24import java.util.Vector;\r
a13899c5 25import java.util.regex.Matcher;\r
26import java.util.regex.Pattern;\r
27\r
28import org.apache.xmlbeans.XmlNormalizedString;\r
29import org.apache.xmlbeans.XmlObject;\r
30import org.apache.xmlbeans.XmlString;\r
a13899c5 31import org.tianocore.BuildTargetList;\r
32import org.tianocore.DataIdDocument;\r
33import org.tianocore.ExternsDocument;\r
34import org.tianocore.FileNameConvention;\r
a13899c5 35//import org.tianocore.FvImageDocument;\r
a13899c5 36import org.tianocore.GuidDeclarationsDocument;\r
a13899c5 37import org.tianocore.LibrariesDocument;\r
38import org.tianocore.LibraryClassDeclarationsDocument;\r
39import org.tianocore.LibraryClassDocument;\r
40import org.tianocore.ModuleSADocument;\r
daa4663b 41import org.tianocore.ModuleSurfaceAreaDocument;\r
a13899c5 42import org.tianocore.ModuleTypeDef;\r
43import org.tianocore.MsaFilesDocument;\r
44import org.tianocore.MsaHeaderDocument;\r
a13899c5 45import org.tianocore.PackageDependenciesDocument;\r
46import org.tianocore.PackageHeadersDocument;\r
a13899c5 47import org.tianocore.PpiDeclarationsDocument;\r
48import org.tianocore.ProtocolDeclarationsDocument;\r
49import org.tianocore.SpdHeaderDocument;\r
50import org.tianocore.FilenameDocument.Filename;\r
51import org.tianocore.MsaHeaderDocument.MsaHeader;\r
a13899c5 52import org.tianocore.PlatformHeaderDocument;\r
53import org.tianocore.frameworkwizard.platform.ui.id.FpdModuleIdentification;\r
54import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;\r
55import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;\r
56import org.tianocore.frameworkwizard.platform.ui.id.PlatformIdentification;\r
57\r
58/**\r
59 * SurfaceAreaQuery class is used to query Surface Area information from msa,\r
60 * mbd, spd and fpd files.\r
61 * \r
62 * This class should not instantiated. All the public interfaces is static.\r
63 * \r
64 * @since GenBuild 1.0\r
65 */\r
66public class SurfaceAreaQuery {\r
67\r
68 public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";\r
69\r
70 // /\r
71 // / Contains name/value pairs of Surface Area document object. The name is\r
72 // / always the top level element name.\r
73 // /\r
74 private static Map<String, XmlObject> map = null;\r
75\r
76 // /\r
77 // / mapStack is used to do nested query\r
78 // /\r
79 private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();\r
80\r
81 // /\r
82 // / prefix of name space\r
83 // /\r
84 private static String nsPrefix = "sans";\r
85\r
86 // /\r
87 // / xmlbeans needs a name space for each Xpath element\r
88 // /\r
89 private static String ns = null;\r
90\r
91 // /\r
92 // / keep the namep declaration for xmlbeans Xpath query\r
93 // /\r
94 private static String queryDeclaration = null;\r
95\r
96 /**\r
97 * Set a Surface Area document for query later\r
98 * \r
99 * @param map\r
100 * A Surface Area document in TopLevelElementName/XmlObject\r
101 * format.\r
102 */\r
103 public static void setDoc(Map<String, XmlObject> map) {\r
104 ns = prefix;\r
105 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
106 SurfaceAreaQuery.map = map;\r
107 }\r
108\r
109 /**\r
110 * Push current used Surface Area document into query stack. The given new\r
111 * document will be used for any immediately followed getXXX() callings,\r
112 * untill pop() is called.\r
113 * \r
114 * @param newMap\r
115 * The TopLevelElementName/XmlObject format of a Surface Area\r
116 * document.\r
117 */\r
118 public static void push(Map<String, XmlObject> newMap) {\r
119 mapStack.push(SurfaceAreaQuery.map);\r
120 SurfaceAreaQuery.map = newMap;\r
121 }\r
122\r
123 /**\r
124 * Discard current used Surface Area document and use the top document in\r
125 * stack instead.\r
126 */\r
127 public static void pop() {\r
128 SurfaceAreaQuery.map = mapStack.pop();\r
129 }\r
130\r
131 // /\r
132 // / Convert xPath to be namespace qualified, which is necessary for\r
133 // XmlBeans\r
134 // / selectPath(). For example, converting /MsaHeader/ModuleType to\r
135 // / /ns:MsaHeader/ns:ModuleType\r
136 // /\r
137 private static String normalizeQueryString(String[] exp, String from) {\r
138 StringBuffer normQueryString = new StringBuffer(4096);\r
139\r
140 int i = 0;\r
141 while (i < exp.length) {\r
142 String newExp = from + exp[i];\r
143 Pattern pattern = Pattern.compile("([^/]*)(/|//)([^/]+)");\r
144 Matcher matcher = pattern.matcher(newExp);\r
145\r
146 while (matcher.find()) {\r
147 String starter = newExp.substring(matcher.start(1), matcher\r
148 .end(1));\r
149 String seperator = newExp.substring(matcher.start(2), matcher\r
150 .end(2));\r
151 String token = newExp.substring(matcher.start(3), matcher\r
152 .end(3));\r
153\r
154 normQueryString.append(starter);\r
155 normQueryString.append(seperator);\r
156 normQueryString.append(nsPrefix);\r
157 normQueryString.append(":");\r
158 normQueryString.append(token);\r
159 }\r
160\r
161 ++i;\r
162 if (i < exp.length) {\r
163 normQueryString.append(" | ");\r
164 }\r
165 }\r
166\r
167 return normQueryString.toString();\r
168 }\r
169\r
170 /**\r
171 * Search all XML documents stored in "map" for the specified xPath, using\r
172 * relative path (starting with '$this')\r
173 * \r
174 * @param xPath\r
175 * xpath query string array\r
176 * @returns An array of XmlObject if elements are found at the specified\r
177 * xpath\r
178 * @returns NULL if nothing is at the specified xpath\r
179 */\r
180 public static XmlObject[] get(String[] xPath) {\r
181 if (map == null) {\r
182 return null;\r
183 }\r
184\r
185 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
186 List<XmlObject> result = new ArrayList<XmlObject>();\r
187 for (int i = 0; i < keys.length; ++i) {\r
188 XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
189 if (rootNode == null) {\r
190 continue;\r
191 }\r
192\r
193 String query = queryDeclaration\r
194 + normalizeQueryString(xPath, "$this/" + keys[i]);\r
195 XmlObject[] tmp = rootNode.selectPath(query);\r
196 for (int j = 0; j < tmp.length; ++j) {\r
197 result.add(tmp[j]);\r
198 }\r
199 }\r
200\r
201 int size = result.size();\r
202 if (size <= 0) {\r
203 return null;\r
204 }\r
205\r
206 return (XmlObject[]) result.toArray(new XmlObject[size]);\r
207 }\r
208\r
209 /**\r
210 * Search XML documents named by "rootName" for the given xPath, using\r
211 * relative path (starting with '$this')\r
212 * \r
213 * @param rootName\r
214 * The top level element name\r
215 * @param xPath\r
216 * The xpath query string array\r
217 * @returns An array of XmlObject if elements are found at the given xpath\r
218 * @returns NULL if nothing is found at the given xpath\r
219 */\r
220 public static XmlObject[] get(String rootName, String[] xPath) {\r
221 if (map == null) {\r
222 return null;\r
223 }\r
224\r
225 XmlObject root = (XmlObject) map.get(rootName);\r
226 if (root == null) {\r
227 return null;\r
228 }\r
229\r
230 String query = queryDeclaration\r
231 + normalizeQueryString(xPath, "$this/" + rootName);\r
232 XmlObject[] result = root.selectPath(query);\r
233 if (result.length > 0) {\r
234 return result;\r
235 }\r
236\r
237 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
238 result = root.selectPath(query);\r
239 if (result.length > 0) {\r
240 return result;\r
241 }\r
242\r
243 return null;\r
244 }\r
245\r
246 /**\r
247 * Retrieve SourceFiles/Filename for specified ARCH type\r
248 * \r
249 * @param arch\r
250 * architecture name\r
251 * @returns An 2 dimension string array if elements are found at the known\r
252 * xpath\r
253 * @returns NULL if nothing is found at the known xpath\r
254 */\r
255 public static String[][] getSourceFiles(String arch) {\r
256 String[] xPath;\r
257 XmlObject[] returns;\r
258\r
259 if (arch == null || arch.equals("")) {\r
260 xPath = new String[] { "/Filename" };\r
261 } else {\r
262 xPath = new String[] { "/Filename[not(@SupArchList) or @SupArchList='"\r
263 + arch + "']" };\r
264 }\r
265\r
266 returns = get("SourceFiles", xPath);\r
267\r
268 if (returns == null || returns.length == 0) {\r
269 return null;\r
270 }\r
271\r
272 Filename[] sourceFileNames = (Filename[]) returns;\r
273 String[][] outputString = new String[sourceFileNames.length][2];\r
274 for (int i = 0; i < sourceFileNames.length; i++) {\r
275 outputString[i][0] = sourceFileNames[i].getToolCode();\r
276 outputString[i][1] = sourceFileNames[i].getStringValue();\r
277 }\r
278 return outputString;\r
279 }\r
280\r
281 /**\r
282 * Retrieve /PlatformDefinitions/OutputDirectory from FPD\r
283 * \r
284 * @returns Directory names array if elements are found at the known xpath\r
285 * @returns Empty if nothing is found at the known xpath\r
286 */\r
287 public static String getFpdOutputDirectory() {\r
288 String[] xPath = new String[] { "/PlatformDefinitions/OutputDirectory" };\r
289\r
290 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
291 if (returns != null && returns.length > 0) {\r
292 // String TBD\r
293 }\r
294\r
295 return null;\r
296 }\r
297\r
298 public static String getFpdIntermediateDirectories() {\r
299 String[] xPath = new String[] { "/PlatformDefinitions/IntermediateDirectories" };\r
300\r
301 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
302 if (returns != null && returns.length > 0) {\r
303 // TBD\r
304 }\r
305 return "UNIFIED";\r
306 }\r
307\r
a13899c5 308 public static String getBuildTarget() {\r
309 String[] xPath = new String[] { "/PlatformDefinitions/BuildTargets" };\r
310\r
311 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
312 if (returns != null && returns.length > 0) {\r
313 return ((BuildTargetList) returns[0]).getStringValue();\r
314 }\r
315\r
316 return null;\r
317 }\r
318\r
319 /**\r
320 * Retrieve <xxxHeader>/ModuleType\r
321 * \r
322 * @returns The module type name if elements are found at the known xpath\r
323 * @returns null if nothing is there\r
324 */\r
325 public static String getModuleType() {\r
326 String[] xPath = new String[] { "/ModuleType" };\r
327\r
328 XmlObject[] returns = get(xPath);\r
329 if (returns != null && returns.length > 0) {\r
330 ModuleTypeDef type = (ModuleTypeDef) returns[0];\r
331 return type.enumValue().toString();\r
332 }\r
333\r
334 return null;\r
335 }\r
336\r
337 /**\r
338 * Retrieve PackageDependencies/Package\r
339 * \r
340 * @param arch\r
341 * Architecture name\r
342 * \r
343 * @returns package name list if elements are found at the known xpath\r
344 * @returns null if nothing is there\r
345 */\r
daa4663b 346\r
347 public static PackageIdentification[] getDependencePkg(String arch, ModuleIdentification mi) throws Exception{\r
348 \r
a13899c5 349 String packageGuid = null;\r
350 String packageVersion = null;\r
351\r
daa4663b 352 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) GlobalData.getModuleXmlObject(mi);\r
353 if (msa.getPackageDependencies() == null) {\r
354 return new PackageIdentification[0];\r
355 }\r
356 int size = msa.getPackageDependencies().getPackageList().size();\r
357 XmlObject[] returns = new XmlObject[size];\r
358 for (int i = 0; i < size; ++i) {\r
359 returns[i] = msa.getPackageDependencies().getPackageList().get(i);\r
360 }\r
a13899c5 361\r
a13899c5 362 PackageIdentification[] packageIdList = new PackageIdentification[returns.length];\r
363 for (int i = 0; i < returns.length; i++) {\r
364 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];\r
365 packageGuid = item.getPackageGuid();\r
366 packageVersion = item.getPackageVersion();\r
367\r
368 Set<PackageIdentification> spi = GlobalData.getPackageList();\r
369 Iterator<PackageIdentification> ispi = spi.iterator();\r
370 String ver = "";\r
371 while(ispi.hasNext()) {\r
372 PackageIdentification pi = ispi.next();\r
373 if (packageVersion != null) {\r
93fd07b1 374 if (pi.getGuid().equalsIgnoreCase(packageGuid) && pi.getVersion().equals(packageVersion)) {\r
a13899c5 375 packageIdList[i] = pi;\r
376 break;\r
377 } \r
378 }\r
379 else {\r
93fd07b1 380 if (pi.getGuid().equalsIgnoreCase(packageGuid)) {\r
a13899c5 381 if (pi.getVersion() != null && pi.getVersion().compareTo(ver) > 0){\r
382 ver = pi.getVersion();\r
383 packageIdList[i] = pi;\r
384 }\r
385 else if (packageIdList[i] == null){\r
386 packageIdList[i] = pi;\r
387 }\r
388 }\r
389 }\r
390 \r
391 }\r
392 }\r
393 return packageIdList;\r
394 }\r
395\r
396 /**\r
397 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
398 * \r
399 * @param usage\r
400 * Library class usage\r
401 * \r
402 * @returns LibraryClass objects list if elements are found at the known\r
403 * xpath\r
404 * @returns null if nothing is there\r
405 */\r
daa4663b 406 public static Vector<String> getLibraryClasses(String usage, ModuleIdentification mi) throws Exception{\r
407 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)GlobalData.getModuleXmlObject(mi);\r
408 Vector<String> libraryClassName = new Vector<String>();\r
409 if (msa.getLibraryClassDefinitions() == null) {\r
410 return libraryClassName;\r
411 }\r
412 \r
413 int size = msa.getLibraryClassDefinitions().getLibraryClassList().size();\r
414 \r
415 for (int i = 0; i < size; i++) {\r
416 LibraryClassDocument.LibraryClass libClass = msa.getLibraryClassDefinitions().getLibraryClassList().get(i);\r
417 if (usage.equals(libClass.getUsage().toString())) {\r
418 libraryClassName.add(libClass.getKeyword());\r
419 }\r
a13899c5 420 }\r
daa4663b 421 \r
a13899c5 422 return libraryClassName;\r
423 }\r
424\r
425 /**\r
426 * Retrieve ModuleEntryPoint names\r
427 * \r
428 * @returns ModuleEntryPoint name list if elements are found at the known\r
429 * xpath\r
430 * @returns null if nothing is there\r
431 */\r
432 public static String[] getModuleEntryPointArray() {\r
433 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };\r
434\r
435 XmlObject[] returns = get("Externs", xPath);\r
436\r
437 if (returns != null && returns.length > 0) {\r
438 String[] entryPoints = new String[returns.length];\r
439\r
440 for (int i = 0; i < returns.length; ++i) {\r
441 entryPoints[i] = ((XmlNormalizedString) returns[i])\r
442 .getStringValue();\r
443 }\r
444\r
445 return entryPoints;\r
446 }\r
447\r
448 return null;\r
449 }\r
450\r
451 \r
452 \r
453\r
454 /**\r
455 * Retrieve ModuleUnloadImage names\r
456 * \r
457 * @returns ModuleUnloadImage name list if elements are found at the known\r
458 * xpath\r
459 * @returns null if nothing is there\r
460 */\r
461 public static String[] getModuleUnloadImageArray() {\r
462 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };\r
463\r
464 XmlObject[] returns = get("Externs", xPath);\r
465 if (returns != null && returns.length > 0) {\r
466 String[] stringArray = new String[returns.length];\r
467 XmlNormalizedString[] doc = (XmlNormalizedString[]) returns;\r
468\r
469 for (int i = 0; i < returns.length; ++i) {\r
470 stringArray[i] = doc[i].getStringValue();\r
471 }\r
472\r
473 return stringArray;\r
474 }\r
475\r
476 return null;\r
477 }\r
478\r
479 /**\r
480 * Retrieve Extern\r
481 * \r
482 * @returns Extern objects list if elements are found at the known xpath\r
483 * @returns null if nothing is there\r
484 */\r
485 public static ExternsDocument.Externs.Extern[] getExternArray() {\r
486 String[] xPath = new String[] { "/Extern" };\r
487\r
488 XmlObject[] returns = get("Externs", xPath);\r
489 if (returns != null && returns.length > 0) {\r
490 return (ExternsDocument.Externs.Extern[]) returns;\r
491 }\r
492\r
493 return null;\r
494 }\r
495 \r
496 /**\r
497 * Retrieve Library instance information\r
498 * \r
499 * @param arch\r
500 * Architecture name\r
501 * @param usage\r
502 * Library instance usage\r
503 * \r
504 * @returns library instance name list if elements are found at the known\r
505 * xpath\r
506 * @returns null if nothing is there\r
507 */\r
508 public static ModuleIdentification[] getLibraryInstance(String arch) {\r
509 String[] xPath;\r
510 String saGuid = null;\r
511 String saVersion = null;\r
512 String pkgGuid = null;\r
513 String pkgVersion = null;\r
514\r
515 if (arch == null || arch.equalsIgnoreCase("")) {\r
516 xPath = new String[] { "/Instance" };\r
517 } else {\r
518 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"\r
519 + arch + "']" };\r
520 }\r
521\r
522 XmlObject[] returns = get("Libraries", xPath);\r
523 if (returns == null || returns.length == 0) {\r
524 return new ModuleIdentification[0];\r
525 }\r
526\r
527 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];\r
528 for (int i = 0; i < returns.length; i++) {\r
529 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];\r
530 saGuid = library.getModuleGuid();\r
531 saVersion = library.getModuleVersion();\r
532\r
533 pkgGuid = library.getPackageGuid();\r
534 pkgVersion = library.getPackageVersion();\r
535\r
536 ModuleIdentification saId = new ModuleIdentification(null, saGuid,\r
537 saVersion);\r
538 PackageIdentification pkgId = new PackageIdentification(null,\r
539 pkgGuid, pkgVersion);\r
540 saId.setPackage(pkgId);\r
541\r
542 saIdList[i] = saId;\r
543\r
544 }\r
545 return saIdList;\r
546 }\r
547\r
548 // /\r
549 // / This method is used for retrieving the elements information which has\r
550 // / CName sub-element\r
551 // /\r
552 private static String[] getCNames(String from, String xPath[]) {\r
553 XmlObject[] returns = get(from, xPath);\r
554 if (returns == null || returns.length == 0) {\r
555 return null;\r
556 }\r
557\r
558 String[] strings = new String[returns.length];\r
559 for (int i = 0; i < returns.length; ++i) {\r
560 // TBD\r
561 // strings[i] = ((CName) returns[i]).getStringValue();\r
562 }\r
563\r
564 return strings;\r
565 }\r
566\r
567 /**\r
568 * Retrive library's constructor name\r
569 * \r
570 * @returns constructor name list if elements are found at the known xpath\r
571 * @returns null if nothing is there\r
572 */\r
573 public static String getLibConstructorName() {\r
574 String[] xPath = new String[] { "/Extern/Constructor" };\r
575\r
576 XmlObject[] returns = get("Externs", xPath);\r
577 if (returns != null && returns.length > 0) {\r
578 // CName constructor = (CName) returns[0];\r
579 // return constructor.getStringValue();\r
580 }\r
581\r
582 return null;\r
583 }\r
584\r
585 /**\r
586 * Retrive library's destructor name\r
587 * \r
588 * @returns destructor name list if elements are found at the known xpath\r
589 * @returns null if nothing is there\r
590 */\r
591 public static String getLibDestructorName() {\r
592 String[] xPath = new String[] { "/Extern/Destructor" };\r
593\r
594 XmlObject[] returns = get("Externs", xPath);\r
595 if (returns != null && returns.length > 0) {\r
596 // CName destructor = (CName) returns[0];\r
597 // return destructor.getStringValue();\r
598 }\r
599\r
600 return null;\r
601 }\r
602\r
603 /**\r
604 * Retrive DriverBinding names\r
605 * \r
606 * @returns DriverBinding name list if elements are found at the known xpath\r
607 * @returns null if nothing is there\r
608 */\r
609 public static String[] getDriverBindingArray() {\r
610 String[] xPath = new String[] { "/Extern/DriverBinding" };\r
611 return getCNames("Externs", xPath);\r
612 }\r
613\r
614 /**\r
615 * Retrive ComponentName names\r
616 * \r
617 * @returns ComponentName name list if elements are found at the known xpath\r
618 * @returns null if nothing is there\r
619 */\r
620 public static String[] getComponentNameArray() {\r
621 String[] xPath = new String[] { "/Extern/ComponentName" };\r
622 return getCNames("Externs", xPath);\r
623 }\r
624\r
625 /**\r
626 * Retrive DriverConfig names\r
627 * \r
628 * @returns DriverConfig name list if elements are found at the known xpath\r
629 * @returns null if nothing is there\r
630 */\r
631 public static String[] getDriverConfigArray() {\r
632 String[] xPath = new String[] { "/Extern/DriverConfig" };\r
633 return getCNames("Externs", xPath);\r
634 }\r
635\r
636 /**\r
637 * Retrive DriverDiag names\r
638 * \r
639 * @returns DriverDiag name list if elements are found at the known xpath\r
640 * @returns null if nothing is there\r
641 */\r
642 public static String[] getDriverDiagArray() {\r
643 String[] xPath = new String[] { "/Extern/DriverDiag" };\r
644 return getCNames("Externs", xPath);\r
645 }\r
646\r
647 /**\r
648 * Retrive SetVirtualAddressMapCallBack names\r
649 * \r
650 * @returns SetVirtualAddressMapCallBack name list if elements are found at\r
651 * the known xpath\r
652 * @returns null if nothing is there\r
653 */\r
654 public static String[] getSetVirtualAddressMapCallBackArray() {\r
655 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };\r
656 return getCNames("Externs", xPath);\r
657 }\r
658\r
659 /**\r
660 * Retrive ExitBootServicesCallBack names\r
661 * \r
662 * @returns ExitBootServicesCallBack name list if elements are found at the\r
663 * known xpath\r
664 * @returns null if nothing is there\r
665 */\r
666 public static String[] getExitBootServicesCallBackArray() {\r
667 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };\r
668 return getCNames("Externs", xPath);\r
669 }\r
670\r
671 /**\r
672 * Retrieve module surface area file information\r
673 * \r
674 * @returns ModuleSA objects list if elements are found at the known xpath\r
675 * @returns Empty ModuleSA list if nothing is there\r
676 */\r
677 public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {\r
678 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
679 XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
680 String arch = null;\r
681 String fvBinding = null;\r
682 String saGuid = null;\r
683 String saVersion = null;\r
684 String pkgGuid = null;\r
685 String pkgVersion = null;\r
686\r
687 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();\r
688\r
689 if (result == null) {\r
690 return fpdModuleMap;\r
691 }\r
692\r
693 for (int i = 0; i < result.length; i++) {\r
694 //\r
695 // Get Fpd SA Module element node and add to xmlObjectMap.\r
696 //\r
697 Map<String, XmlObject> xmlObjectMap = new HashMap<String, XmlObject>();\r
698 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];\r
699 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {\r
700 xmlObjectMap.put("Libraries", moduleSA.getLibraries());\r
701 }\r
702 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {\r
703 xmlObjectMap.put("PcdBuildDefinition", moduleSA\r
704 .getPcdBuildDefinition());\r
705 }\r
706 if (((ModuleSADocument.ModuleSA) result[i])\r
707 .getModuleSaBuildOptions() != null) {\r
708 xmlObjectMap.put("ModuleSaBuildOptions", moduleSA\r
709 .getModuleSaBuildOptions());\r
710 }\r
711\r
712 //\r
713 // Get Fpd SA Module attribute and create FpdMoudleIdentification.\r
714 //\r
715 arch = moduleSA.getSupArchList().toString();\r
716\r
717 // TBD\r
718 fvBinding = null;\r
719 saVersion = ((ModuleSADocument.ModuleSA) result[i])\r
720 .getModuleVersion();\r
721\r
722 saGuid = moduleSA.getModuleGuid();\r
723 pkgGuid = moduleSA.getPackageGuid();\r
724 pkgVersion = moduleSA.getPackageVersion();\r
725\r
726 //\r
727 // Create Module Identification which have class member of package\r
728 // identification.\r
729 //\r
730 PackageIdentification pkgId = new PackageIdentification(null,\r
731 pkgGuid, pkgVersion);\r
732 ModuleIdentification saId = new ModuleIdentification(null, saGuid,\r
733 saVersion);\r
734\r
735 saId.setPackage(pkgId);\r
736\r
737 //\r
738 // Create FpdModule Identification which have class member of module\r
739 // identification\r
740 //\r
741 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId,\r
742 arch);\r
743 if (arch != null) {\r
744 fpdSaId.setArch(arch);\r
745 }\r
746 if (fvBinding != null) {\r
747 fpdSaId.setFvBinding(fvBinding);\r
748 }\r
749\r
750 //\r
751 // Put element to Map<FpdModuleIdentification, Map<String,\r
752 // XmlObject>>.\r
753 //\r
754 fpdModuleMap.put(fpdSaId, xmlObjectMap);\r
755 }\r
756 return fpdModuleMap;\r
757 }\r
758\r
759 /**\r
760 * Retrieve valid image names\r
761 * \r
762 * @returns valid iamges name list if elements are found at the known xpath\r
763 * @returns empty list if nothing is there\r
764 */\r
765 public static String[] getFpdValidImageNames() {\r
766 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };\r
767\r
768 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
769 if (queryResult == null) {\r
770 return new String[0];\r
771 }\r
772\r
773 String[] result = new String[queryResult.length];\r
774 for (int i = 0; i < queryResult.length; i++) {\r
775 result[i] = ((XmlString) queryResult[i]).getStringValue();\r
776 }\r
777\r
778 return result;\r
779 }\r
780\r
f3b0ed9a 781 \r
a13899c5 782\r
783 public static XmlObject getFpdBuildOptions() {\r
784 String[] xPath = new String[] { "/BuildOptions" };\r
785\r
786 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
787\r
788 if (queryResult == null || queryResult.length == 0) {\r
789 return null;\r
790 }\r
791 return queryResult[0];\r
792 }\r
793\r
794 public static PlatformIdentification getFpdHeader() {\r
795 String[] xPath = new String[] { "/PlatformHeader" };\r
796\r
797 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);\r
798\r
799 if (returns == null || returns.length == 0) {\r
800 return null;\r
801 }\r
802 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];\r
803\r
804 String name = header.getPlatformName();\r
805\r
806 String guid = header.getGuidValue();\r
807\r
808 String version = header.getVersion();\r
809\r
810 return new PlatformIdentification(name, guid, version);\r
811 }\r
812\r
813 /**\r
814 * Retrieve flash definition file name\r
815 * \r
816 * @returns file name if elements are found at the known xpath\r
817 * @returns null if nothing is there\r
818 */\r
819 public static String getFlashDefinitionFile() {\r
820 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };\r
821\r
822 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
823 if (queryResult == null || queryResult.length == 0) {\r
824 return null;\r
825 }\r
826\r
827 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];\r
828 return filename.getStringValue();\r
829 }\r
830\r
831 /**\r
832 * Retrieve FV image component options\r
833 * \r
834 * @param fvName\r
835 * FV image name\r
836 * \r
837 * @returns name/value pairs list if elements are found at the known xpath\r
838 * @returns empty list if nothing is there\r
839 */\r
840 public static String[][] getFpdComponents(String fvName) {\r
841 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"\r
842 + fvName.toUpperCase() + "']/DataId" };\r
843\r
844 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
845 if (queryResult == null) {\r
846 return new String[0][];\r
847 }\r
848\r
849 ArrayList<String[]> list = new ArrayList<String[]>();\r
850 for (int i = 0; i < queryResult.length; i++) {\r
851 DataIdDocument.DataId item = (DataIdDocument.DataId) queryResult[i];\r
852 list\r
853 .add(new String[] { item.getStringValue(),\r
854 item.getDataSize() });\r
855 }\r
856\r
857 String[][] result = new String[list.size()][2];\r
858 for (int i = 0; i < list.size(); i++) {\r
859 result[i][0] = list.get(i)[0];\r
860 result[i][1] = list.get(i)[1];\r
861 }\r
862\r
863 return result;\r
864 }\r
865\r
866 /**\r
867 * Retrieve PCD tokens\r
868 * \r
869 * @returns CName/ItemType pairs list if elements are found at the known\r
870 * xpath\r
871 * @returns null if nothing is there\r
872 */\r
873 public static String[][] getPcdTokenArray() {\r
874 String[] xPath = new String[] { "/PcdData" };\r
875\r
876 XmlObject[] returns = get("PCDs", xPath);\r
877 if (returns == null || returns.length == 0) {\r
878 return null;\r
879 }\r
880\r
881 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;\r
882 // String[][] result = new String[pcds.length][2];\r
883 // for (int i = 0; i < returns.length; ++i) {\r
884 // if (pcds[i].getItemType() != null) {\r
885 // result[i][1] = pcds[i].getItemType().toString();\r
886 // } else {\r
887 // result[i][1] = null;\r
888 // }\r
889 // result[i][0] = pcds[i].getCName();\r
890 // }\r
891\r
892 return null;\r
893 }\r
894\r
1dac04ab 895 \r
a13899c5 896\r
897 /**\r
1dac04ab 898 * Retrieve MSA header\r
a13899c5 899 * \r
900 * @return\r
901 * @return\r
902 */\r
903 public static ModuleIdentification getMsaHeader() {\r
904 String[] xPath = new String[] { "/" };\r
905 XmlObject[] returns = get("MsaHeader", xPath);\r
906\r
907 if (returns == null || returns.length == 0) {\r
908 return null;\r
909 }\r
910\r
911 MsaHeader msaHeader = (MsaHeader) returns[0];\r
912 //\r
913 // Get BaseName, ModuleType, GuidValue, Version\r
914 // which in MsaHeader.\r
915 //\r
916 String name = msaHeader.getModuleName();\r
410e0e9f 917 String moduleType = "";\r
918 if (msaHeader.getModuleType() != null) {\r
919 moduleType = msaHeader.getModuleType().toString();\r
920 }\r
921 \r
a13899c5 922 String guid = msaHeader.getGuidValue();\r
923 String version = msaHeader.getVersion();\r
924\r
925 ModuleIdentification moduleId = new ModuleIdentification(name, guid,\r
926 version);\r
927\r
928 moduleId.setModuleType(moduleType);\r
929\r
930 return moduleId;\r
931 }\r
932\r
933 /**\r
934 * Retrieve Extern Specification\r
935 * \r
936 * @param\r
937 * \r
938 * @return String[] If have specification element in the <extern> String[0]\r
939 * If no specification element in the <extern>\r
940 * \r
941 */\r
942\r
943 public static String[] getExternSpecificaiton() {\r
944 String[] xPath = new String[] { "/Specification" };\r
945\r
946 XmlObject[] queryResult = get("Externs", xPath);\r
947 if (queryResult == null) {\r
948 return new String[0];\r
949 }\r
950\r
951 String[] specificationList = new String[queryResult.length];\r
952 for (int i = 0; i < queryResult.length; i++) {\r
953 // specificationList[i] = ((SpecificationDocument.Specification)\r
954 // queryResult[i])\r
955 // .getStringValue();\r
956 }\r
957 return specificationList;\r
958 }\r
959\r
960 /**\r
961 * Retreive MsaFile which in SPD\r
962 * \r
963 * @param\r
964 * @return String[][3] The string sequence is ModuleName, ModuleGuid,\r
965 * ModuleVersion, MsaFile String[0][] If no msafile in SPD\r
966 */\r
967 public static String[] getSpdMsaFile() {\r
968 String[] xPath = new String[] { "/MsaFiles" };\r
969\r
970 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
971 if (returns == null) {\r
972 return new String[0];\r
973 }\r
974\r
975 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])\r
976 .getFilenameList();\r
977 return filenameList.toArray(new String[filenameList.size()]);\r
978 }\r
979\r
980 /**\r
981 * Reteive\r
982 */\r
983 public static Map<String, String[]> getSpdLibraryClasses() {\r
984 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };\r
985\r
986 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
987\r
988 //\r
989 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.\r
990 //\r
991 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();\r
992\r
993 if (returns == null) {\r
994 return libClassHeaderMap;\r
995 }\r
996\r
997 for (int i = 0; i < returns.length; i++) {\r
998 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];\r
999 libClassHeaderMap.put(library.getName(), new String[] { library\r
1000 .getIncludeHeader() });\r
1001 }\r
1002 return libClassHeaderMap;\r
1003 }\r
1004\r
1005 /**\r
1006 * Reteive\r
1007 */\r
1008 public static Map<String, String> getSpdPackageHeaderFiles() {\r
1009 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };\r
1010\r
1011 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1012\r
1013 //\r
1014 // Create Map, Key - ModuleType, String - PackageInclude Header file.\r
1015 //\r
1016 Map<String, String> packageIncludeMap = new HashMap<String, String>();\r
1017\r
1018 if (returns == null) {\r
1019 return packageIncludeMap;\r
1020 }\r
1021 GlobalData.log.info("" + returns[0].getClass().getName());\r
1022 for (int i = 0; i < returns.length; i++) {\r
1023 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];\r
1024 packageIncludeMap.put(includeHeader.getModuleType().toString(),\r
1025 includeHeader.getStringValue());\r
1026 }\r
1027 return packageIncludeMap;\r
1028 }\r
1029\r
1030 public static PackageIdentification getSpdHeader() {\r
1031 String[] xPath = new String[] { "/SpdHeader" };\r
1032\r
1033 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1034\r
1035 if (returns == null || returns.length == 0) {\r
1036 return null;\r
1037 }\r
1038\r
1039 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];\r
1040\r
1041 String name = header.getPackageName();\r
1042\r
1043 String guid = header.getGuidValue();\r
1044\r
1045 String version = header.getVersion();\r
1046\r
1047 return new PackageIdentification(name, guid, version);\r
1048 }\r
1049\r
1050 /**\r
1051 * Reteive\r
1052 */\r
1053 public static Map<String, String[]> getSpdGuid() {\r
1054 String[] xPath = new String[] { "/GuidDeclarations/Entry" };\r
1055\r
1056 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1057\r
1058 //\r
1059 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.\r
1060 //\r
1061 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();\r
1062 if (returns == null) {\r
1063 return guidDeclMap;\r
1064 }\r
1065\r
1066 for (int i = 0; i < returns.length; i++) {\r
1067 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];\r
1068 String[] guidPair = new String[2];\r
1069 guidPair[0] = entry.getCName();\r
1070 guidPair[1] = entry.getGuidValue();\r
1071 guidDeclMap.put(entry.getName(), guidPair);\r
1072 }\r
1073 return guidDeclMap;\r
1074 }\r
1075\r
1076 /**\r
1077 * Reteive\r
1078 */\r
1079 public static Map<String, String[]> getSpdProtocol() {\r
1080 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };\r
1081\r
1082 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1083\r
1084 //\r
1085 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
1086 //\r
1087 Map<String, String[]> protoclMap = new HashMap<String, String[]>();\r
1088\r
1089 if (returns == null) {\r
1090 return protoclMap;\r
1091 }\r
1092\r
1093 for (int i = 0; i < returns.length; i++) {\r
1094 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];\r
1095 String[] protocolPair = new String[2];\r
1096\r
1097 protocolPair[0] = entry.getCName();\r
1098 protocolPair[1] = entry.getGuidValue();\r
1099 protoclMap.put(entry.getName(), protocolPair);\r
1100 }\r
1101 return protoclMap;\r
1102 }\r
1103\r
1104 /**\r
1105 * getSpdPpi() Retrieve the SPD PPI Entry\r
1106 * \r
1107 * @param\r
1108 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI\r
1109 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI\r
1110 * entry in SPD.\r
1111 */\r
1112 public static Map<String, String[]> getSpdPpi() {\r
1113 String[] xPath = new String[] { "/PpiDeclarations/Entry" };\r
1114\r
1115 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1116\r
1117 //\r
1118 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.\r
1119 //\r
1120 Map<String, String[]> ppiMap = new HashMap<String, String[]>();\r
1121\r
1122 if (returns == null) {\r
1123 return ppiMap;\r
1124 }\r
1125\r
1126 for (int i = 0; i < returns.length; i++) {\r
1127 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];\r
1128 String[] ppiPair = new String[2];\r
1129 ppiPair[0] = entry.getCName();\r
1130 ppiPair[1] = entry.getGuidValue();\r
1131 ppiMap.put(entry.getName(), ppiPair);\r
1132 }\r
1133 return ppiMap;\r
1134 }\r
1135\r
1136 /**\r
1137 * getModuleSupportedArchs()\r
1138 * \r
1139 * This function is to Retrieve Archs one module supported.\r
1140 * \r
1141 * @param\r
1142 * @return supportArch String of supporting archs. null No arch specified in\r
1143 * <MouduleSupport> element.\r
1144 */\r
1145 public static List<String> getModuleSupportedArchs() {\r
1146 String[] xPath = new String[] { "/ModuleDefinitions/SupportedArchitectures" };\r
1147\r
1148 XmlObject[] returns = get("ModuleSurfaceArea", xPath);\r
1149\r
1150 if (returns == null) {\r
1151 return null;\r
1152 }\r
1153\r
1154 return (List<String>)returns[0];\r
1155 }\r
1156\r
1157 public static XmlObject[] getSpdPcdDeclarations() {\r
1158 String[] xPath = null;\r
1159// if (tsGuid != null){\r
1160// xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };\r
1161// }\r
1162// else{\r
1163// xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };\r
1164// } \r
1165 xPath = new String[] { "/PcdDeclarations/PcdEntry"};\r
1166 XmlObject[] returns = get("PackageSurfaceArea", xPath);\r
1167 \r
1168 return returns;\r
1169 }\r
1170 \r
1171 public static XmlObject[] getFpdPcdBuildDefinitions(String cName, String tsGuid, String type) {\r
1172 String[] xPath = new String[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName + "' and TokenSpaceGuid='"\r
1173 + tsGuid + "' and DatumType!='" + type + "']" };\r
1174\r
1175 XmlObject[] returns = get("ModuleSA", xPath);\r
1176\r
1177 return returns;\r
1178 }\r
1179 /**\r
1180 * getToolChainFamily\r
1181 * \r
1182 * This function is to retrieve ToolChainFamily attribute of FPD\r
1183 * <BuildOptions>\r
1184 * \r
1185 * @param\r
1186 * @return toolChainFamily If find toolChainFamily attribute in\r
1187 * <BuildOptions> Null If don't have toolChainFamily in\r
1188 * <BuildOptions>.\r
1189 */\r
1190 public String getToolChainFamily() {\r
a13899c5 1191 String[] xPath = new String[] { "/BuildOptions" };\r
1192\r
1193 XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
1194 if (result == null) {\r
1195 return null;\r
1196 }\r
1197 // toolChainFamily =\r
1198 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();\r
1199 // return toolChainFamily;\r
1200 return null;\r
1201 }\r
1202\r
1203 /**\r
1204 * Retrieve module Guid string\r
1205 * \r
1206 * @returns GUILD string if elements are found at the known xpath\r
1207 * @returns null if nothing is there\r
1208 */\r
1209 public static String getModuleGuid() {\r
1210 String[] xPath = new String[] { "" };\r
1211\r
1212 XmlObject[] returns = get("MsaHeader", xPath);\r
1213 if (returns != null && returns.length > 0) {\r
1214 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])\r
1215 .getGuidValue();\r
1216 return guid;\r
1217 }\r
1218\r
1219 return null;\r
1220 }\r
1221\r
1222 //\r
1223 // For new Pcd\r
1224 //\r
1225 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {\r
1226 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };\r
1227 XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
1228 if (result != null) {\r
1229 return (ModuleSADocument.ModuleSA[]) result;\r
1230 }\r
1231 return new ModuleSADocument.ModuleSA[0];\r
1232\r
1233 }\r
1234}\r