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