]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
Change to new XML Schema.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / SurfaceAreaQuery.java
... / ...
CommitLineData
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.build.global;\r
15\r
16import java.util.ArrayList;\r
17import java.util.Iterator;\r
18import java.util.List;\r
19import java.util.Map;\r
20import java.util.Stack;\r
21import java.util.regex.Matcher;\r
22import java.util.regex.Pattern;\r
23\r
24import org.apache.xmlbeans.XmlNormalizedString;\r
25import org.apache.xmlbeans.XmlObject;\r
26import org.apache.xmlbeans.XmlString;\r
27import org.tianocore.BuildOptionsDocument;\r
28import org.tianocore.CName;\r
29import org.tianocore.ExternsDocument;\r
30import org.tianocore.FfsDocument;\r
31import org.tianocore.FileNameConvention;\r
32import org.tianocore.FrameworkComponentTypes;\r
33import org.tianocore.FvImageOptionsDocument;\r
34import org.tianocore.GuidDocument;\r
35import org.tianocore.GuidsDocument;\r
36import org.tianocore.LibrariesDocument;\r
37import org.tianocore.LibraryClassDocument;\r
38import org.tianocore.LibraryUsage;\r
39import org.tianocore.ModuleSADocument;\r
40import org.tianocore.ModuleTypeDef;\r
41import org.tianocore.NameValueDocument;\r
42import org.tianocore.OutputDirectoryDocument;\r
43import org.tianocore.PPIsDocument;\r
44import org.tianocore.PackageNameDocument;\r
45import org.tianocore.ProtocolsDocument;\r
46import org.tianocore.PcdCodedDocument.PcdCoded;\r
47import org.tianocore.MsaHeaderDocument;\r
48import org.tianocore.MsaHeaderDocument.MsaHeader;\r
49\r
50/**\r
51 SurfaceAreaQuery class is used to query Surface Area information from msa, mbd,\r
52 spd and fpd files. \r
53 \r
54 This class should not instantiated. All the public interfaces is static.\r
55 \r
56 @since GenBuild 1.0\r
57 **/\r
58public class SurfaceAreaQuery {\r
59 /// \r
60 /// Contains name/value pairs of Surface Area document object. The name is\r
61 /// always the top level element name.\r
62 /// \r
63 private static Map<String, XmlObject> map = null;\r
64 \r
65 ///\r
66 /// mapStack is used to do nested query\r
67 ///\r
68 private static Stack< Map<String, XmlObject> > mapStack = new Stack< Map<String, XmlObject> >();\r
69 \r
70 /// \r
71 /// prefix of name space\r
72 /// \r
73 private static String nsPrefix = "sans";\r
74 \r
75 ///\r
76 /// xmlbeans needs a name space for each Xpath element \r
77 ///\r
78 private static String ns = null;\r
79 \r
80 ///\r
81 /// keep the namep declaration for xmlbeans Xpath query\r
82 ///\r
83 private static String queryDeclaration = null;\r
84\r
85 /**\r
86 Set a Surface Area document for query later\r
87 \r
88 @param map A Surface Area document in TopLevelElementName/XmlObject format.\r
89 **/\r
90 public static void setDoc(Map<String, XmlObject> map) {\r
91 ns = OverrideProcess.prefix;\r
92 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";\r
93 SurfaceAreaQuery.map = map;\r
94 }\r
95\r
96 /**\r
97 Push current used Surface Area document into query stack. The given new \r
98 document will be used for any immediately followed getXXX() callings, \r
99 untill pop() is called.\r
100 \r
101 @param newMap The TopLevelElementName/XmlObject format of a Surface Area document.\r
102 **/\r
103 public static void push(Map<String, XmlObject> newMap) {\r
104 mapStack.push(SurfaceAreaQuery.map);\r
105 SurfaceAreaQuery.map = newMap;\r
106 }\r
107 \r
108 /**\r
109 Discard current used Surface Area document and use the top document in stack\r
110 instead.\r
111 **/\r
112 public static void pop() {\r
113 SurfaceAreaQuery.map = mapStack.pop();\r
114 }\r
115 \r
116 ///\r
117 /// Convert xPath to be namespace qualified, which is necessary for XmlBeans\r
118 /// selectPath(). For example, converting /MsaHeader/ModuleType to\r
119 /// /ns:MsaHeader/ns:ModuleType\r
120 /// \r
121 private static String normalizeQueryString(String[] exp, String from) {\r
122 StringBuffer normQueryString = new StringBuffer(4096);\r
123\r
124 int i = 0;\r
125 while (i < exp.length) {\r
126 String newExp = from + exp[i];\r
127 Pattern pattern = Pattern.compile("([^/]*)(/|//)([^/]+)");\r
128 Matcher matcher = pattern.matcher(newExp);\r
129\r
130 while (matcher.find()) {\r
131 String starter = newExp.substring(matcher.start(1), matcher.end(1));\r
132 String seperator = newExp.substring(matcher.start(2), matcher.end(2));\r
133 String token = newExp.substring(matcher.start(3), matcher.end(3));\r
134 \r
135 normQueryString.append(starter);\r
136 normQueryString.append(seperator);\r
137 normQueryString.append(nsPrefix);\r
138 normQueryString.append(":");\r
139 normQueryString.append(token);\r
140 }\r
141\r
142 ++i;\r
143 if (i < exp.length) {\r
144 normQueryString.append(" | ");\r
145 }\r
146 }\r
147\r
148 return normQueryString.toString();\r
149 }\r
150\r
151 /**\r
152 Search all XML documents stored in "map" for the specified xPath, using\r
153 relative path (starting with '$this')\r
154 \r
155 @param xPath xpath query string array\r
156 @returns An array of XmlObject if elements are found at the specified xpath\r
157 @returns NULL if nothing is at the specified xpath\r
158 **/\r
159 public static XmlObject[] get(String[] xPath) {\r
160 if (map == null) {\r
161 return null;\r
162 }\r
163 \r
164 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);\r
165 List<XmlObject> result = new ArrayList<XmlObject>();\r
166 for (int i = 0; i < keys.length; ++i) {\r
167 XmlObject rootNode = (XmlObject) map.get(keys[i]);\r
168 if (rootNode == null) {\r
169 continue;\r
170 }\r
171 \r
172 String query = queryDeclaration + normalizeQueryString(xPath, "$this/" + keys[i]);\r
173 XmlObject[] tmp = rootNode.selectPath(query);\r
174 for (int j = 0; j < tmp.length; ++j) {\r
175 result.add(tmp[j]);\r
176 }\r
177 }\r
178 \r
179 int size = result.size();\r
180 if (size <= 0) {\r
181 return null;\r
182 }\r
183 \r
184 return (XmlObject[]) result.toArray(new XmlObject[size]);\r
185 }\r
186\r
187 /**\r
188 Search XML documents named by "rootName" for the given xPath, using\r
189 relative path (starting with '$this')\r
190 \r
191 @param rootName The top level element name \r
192 @param xPath The xpath query string array\r
193 @returns An array of XmlObject if elements are found at the given xpath\r
194 @returns NULL if nothing is found at the given xpath\r
195 **/\r
196 public static XmlObject[] get(String rootName, String[] xPath) {\r
197 if (map == null) {\r
198 return null;\r
199 }\r
200 \r
201 XmlObject root = (XmlObject) map.get(rootName);\r
202 if (root == null) {\r
203 return null;\r
204 }\r
205\r
206 String query = queryDeclaration + normalizeQueryString(xPath, "$this/" + rootName);\r
207 XmlObject[] result = root.selectPath(query);\r
208 if (result.length > 0) {\r
209 return result;\r
210 }\r
211\r
212 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);\r
213 result = root.selectPath(query);\r
214 if (result.length > 0) {\r
215 return result;\r
216 }\r
217\r
218 return null;\r
219 }\r
220\r
221 /**\r
222 Retrieve SourceFiles/Filename for specified ARCH type\r
223 \r
224 @param arch architecture name\r
225 @returns An array of XmlObject if elements are found at the known xpath\r
226 @returns NULL if nothing is found at the known xpath\r
227 **/\r
228 public static XmlObject[] getSourceFiles(String arch) {\r
229 String[] xPath;\r
230\r
231 if (arch == null || arch.equals("")) {\r
232 xPath = new String[] {\r
233 "/Filename",\r
234 "/Arch/Filename"\r
235 };\r
236 } else {\r
237 xPath = new String[] {\r
238 "/Filename[not(@SupArchList) and not(@ArchType) or @SupArchList='ALL' or @SupArchList='" + arch + "' or @ArchType='ALL' or @ArchType='" + arch + "']",\r
239 "/Filename[not(@SupArchList) and not(@ArchType) or @ArchType='ALL' or @ArchType='" + arch + "']",\r
240 "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/Filename"\r
241 };\r
242 }\r
243\r
244 return get("SourceFiles", xPath);\r
245 }\r
246\r
247 /**\r
248 Retrieve BuildOptions/Ffs\r
249\r
250 @returns FfsDocument.Ffs object if elements are found at the known xpath\r
251 @returns NULL if nothing is found at the known xpath\r
252 **/\r
253 public static FfsDocument.Ffs getFfs() {\r
254 String[] xPath = new String[] { "/Ffs" };\r
255\r
256 XmlObject[] returns = get("BuildOptions", xPath);\r
257 if (returns != null && returns.length > 0) {\r
258 return (FfsDocument.Ffs) returns[0];\r
259 }\r
260\r
261 return null;\r
262 }\r
263\r
264 /**\r
265 Retrieve BuildOptions/OutputDirectory\r
266\r
267 @returns Directory names array if elements are found at the known xpath\r
268 @returns Empty if nothing is found at the known xpath\r
269 **/\r
270 public static String[] getOutputDirectory() {\r
271 String[] xPath = new String[] { "/OutputDirectory" };\r
272\r
273 XmlObject[] returns = get("BuildOptions", xPath);\r
274 if (returns != null && returns.length > 0) {\r
275 String[] dirString = new String[2];\r
276\r
277 OutputDirectoryDocument.OutputDirectory[] dir = (OutputDirectoryDocument.OutputDirectory[]) returns;\r
278 dirString[0] = dir[0].getIntermediateDirectories().toString();\r
279 dirString[1] = dir[0].getStringValue();\r
280\r
281 return dirString;\r
282 }\r
283\r
284 return new String[] { "UNIFIED", null };\r
285 }\r
286\r
287 /**\r
288 Retrieve BuildOptions/Option or Arch/Option\r
289\r
290 @param arch architecture name\r
291\r
292 @returns name/value pairs of options if elements are found at the known xpath\r
293 @returns Empty array if nothing is there\r
294 **/\r
295 public static String[][] getOptions(String arch){\r
296 String[] xPath;\r
297\r
298 if (arch == null || arch.equals("")) {\r
299 xPath = new String[] {\r
300 "/Option",\r
301 "/Arch/Option"\r
302 };\r
303 } else {\r
304 xPath = new String[] {\r
305 "/Option",\r
306 "/Option[@SupArchList='ALL' or @SupArchList='" + arch + "']",\r
307 "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/Option"\r
308 };\r
309 }\r
310\r
311 XmlObject[] returns = get("BuildOptions", xPath);\r
312 if (returns == null){\r
313 return new String[0][2];\r
314 }\r
315 \r
316 String[][] result = new String[returns.length][2];\r
317 for (int i = 0; i < returns.length; i ++){\r
318 String str;\r
319 String name = null;\r
320 String value = null;\r
321\r
322 if (returns[i] instanceof BuildOptionsDocument.BuildOptions.Option) {\r
323 BuildOptionsDocument.BuildOptions.Option option = (BuildOptionsDocument.BuildOptions.Option)returns[i];\r
324 str = option.getStringValue();\r
325 } else if (returns[i] instanceof BuildOptionsDocument.BuildOptions.Arch.Option) {\r
326 BuildOptionsDocument.BuildOptions.Arch.Option archOption = (BuildOptionsDocument.BuildOptions.Arch.Option)returns[i];\r
327 str = archOption.getStringValue();\r
328 } else {\r
329 continue;\r
330 }\r
331 \r
332 int equalIndex = str.indexOf('=');\r
333 if ( equalIndex > 0) {\r
334 name = str.substring(0, equalIndex).trim();\r
335 value = str.substring(equalIndex + 1).trim();\r
336 // TBD remove some forbidden name: BASE_NAME, ARCH and so on\r
337 if (name.length() == 0){\r
338 name = null;\r
339 }\r
340 }\r
341 result[i][0] = name;\r
342 result[i][1] = value;\r
343 }\r
344\r
345 return result;\r
346 }\r
347 \r
348 public static String getModuleName() {\r
349 String[] xPath = new String[] { "/ModuleName", "/BaseName" };\r
350\r
351 XmlObject[] returns = get(xPath);\r
352 if (returns != null && returns.length > 0) {\r
353 return returns[0].toString();\r
354 }\r
355\r
356 return null;\r
357 }\r
358\r
359 /**\r
360 Retrieve <xxxHeader>/ModuleType\r
361\r
362 @returns The module type name if elements are found at the known xpath\r
363 @returns null if nothing is there\r
364 **/\r
365 public static String getModuleType() {\r
366 String[] xPath = new String[] { "/ModuleType" };\r
367\r
368 XmlObject[] returns = get(xPath);\r
369 if (returns != null && returns.length > 0) {\r
370 ModuleTypeDef type = (ModuleTypeDef) returns[0];\r
371 return type.enumValue().toString();\r
372 }\r
373\r
374 return null;\r
375 }\r
376\r
377 /**\r
378 Retrieve <xxxHeader>/ComponentType\r
379 \r
380 @returns The component type name if elements are found at the known xpath\r
381 @returns null if nothing is there\r
382 **/\r
383 public static String getComponentType() {\r
384 String[] xPath = new String[] { "/ComponentType" };\r
385\r
386 XmlObject[] returns = get(xPath);\r
387 if (returns != null && returns.length > 0) {\r
388 FrameworkComponentTypes type = (FrameworkComponentTypes) returns[0];\r
389 return type.enumValue().toString();\r
390 }\r
391\r
392 return null;\r
393 }\r
394\r
395 /**\r
396 Retrieve Includes/PackageName\r
397\r
398 @param arch Architecture name\r
399\r
400 @returns package name list if elements are found at the known xpath\r
401 @returns null if nothing is there\r
402 **/\r
403 public static List<String> getIncludePackageName(String arch) {\r
404 String[] xPath;\r
405\r
406 if (arch == null || arch.equals("")) {\r
407 xPath = new String[] {\r
408 "/PackageName",\r
409 "/Arch/PackageName"\r
410 };\r
411 } else {\r
412 xPath = new String[] {\r
413 "/PackageName",\r
414 "/PackageName[@SupArchList='ALL' or @SupArchList='" + arch + "']",\r
415 "/PackageName[@Arch='ALL' or @Arch='" + arch + "']",\r
416 "/Arch[@ArchType='ALL' or @ArchType='" + arch + "']/PackageName"\r
417 };\r
418 }\r
419 \r
420 XmlObject[] returns = get("Includes", xPath);\r
421 if (returns == null || returns.length == 0) {\r
422 returns = get("PackageDependencies", xPath);\r
423 if (returns == null || returns.length == 0) {\r
424 return null;\r
425 }\r
426 }\r
427\r
428 List<String> packageNames = new ArrayList<String>();\r
429 PackageNameDocument.PackageName[] nameObj = (PackageNameDocument.PackageName[])returns;\r
430 for (int i = 0; i < returns.length; ++i) {\r
431 packageNames.add(nameObj[i].getStringValue());\r
432 }\r
433 \r
434 return packageNames;\r
435 }\r
436\r
437 /**\r
438 Retrieve LibraryClassDefinitions/LibraryClass for specified usage\r
439\r
440 @param usage Library class usage\r
441\r
442 @returns LibraryClass objects list if elements are found at the known xpath\r
443 @returns null if nothing is there\r
444 **/\r
445 public static LibraryClassDocument.LibraryClass[] getLibraryClassArray(String usage) {\r
446 String[] xPath;\r
447\r
448 if (usage == null || usage.equals("")) {\r
449 xPath = new String[] {"/LibraryClass"};\r
450 } else {\r
451 xPath = new String[] {"/LibraryClass[@Usage='" + usage + "']"};\r
452 }\r
453\r
454 XmlObject[] returns = get("LibraryClassDefinitions", xPath);\r
455 if (returns != null && returns.length > 0) {\r
456 return (LibraryClassDocument.LibraryClass[]) returns;\r
457 }\r
458\r
459 return null;\r
460 }\r
461\r
462 /**\r
463 Retrieve ModuleEntryPoint names\r
464\r
465 @returns ModuleEntryPoint name list if elements are found at the known xpath\r
466 @returns null if nothing is there\r
467 **/\r
468 public static String[] getModuleEntryPointArray() {\r
469 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };\r
470\r
471 XmlObject[] returns = get("Externs", xPath);\r
472\r
473 if (returns != null && returns.length > 0) {\r
474 String[] entryPoints = new String[returns.length];\r
475\r
476 for (int i = 0; i < returns.length; ++i) {\r
477 entryPoints[i] = ((XmlNormalizedString) returns[i])\r
478 .getStringValue();\r
479 }\r
480\r
481 return entryPoints;\r
482 }\r
483\r
484 return null;\r
485 }\r
486\r
487 /**\r
488 Retrieve module Guid string\r
489 \r
490 @returns GUILD string if elements are found at the known xpath\r
491 @returns null if nothing is there\r
492 **/\r
493 public static String getModuleGuid() {\r
494 String[] xPath = new String[] { "" };\r
495\r
496 XmlObject[] returns = get("MsaHeader", xPath);\r
497 if (returns != null && returns.length > 0) {\r
498 MsaHeaderDocument.MsaHeader moduleHeader = (MsaHeaderDocument.MsaHeader) returns[0];\r
499 if (moduleHeader.isSetGuid()) {\r
500 return moduleHeader.getGuid().getStringValue();\r
501 } else if (moduleHeader.isSetGuidValue()) {\r
502 return moduleHeader.getGuidValue();\r
503 }\r
504 }\r
505\r
506 return null;\r
507 }\r
508\r
509 /**\r
510 Retrieve module Guid string\r
511 \r
512 @returns GUILD string if elements are found at the known xpath\r
513 @returns null if nothing is there\r
514 **/\r
515 public static String getModuleGuidValue() {\r
516 String[] xPath = new String[] { "" };\r
517\r
518 XmlObject[] returns = get("MsaHeader", xPath);\r
519 if (returns != null && returns.length > 0) { \r
520 MsaHeaderDocument.MsaHeader moduleHeader = (MsaHeaderDocument.MsaHeader) returns[0];\r
521 return moduleHeader.getGuidValue();\r
522 }\r
523\r
524 return null;\r
525 }\r
526\r
527 /**\r
528 retrieve Protocol for specified usage\r
529\r
530 @param usage Protocol usage\r
531\r
532 @returns Protocol objects list if elements are found at the known xpath\r
533 @returns null if nothing is there\r
534 **/\r
535 public static ProtocolsDocument.Protocols.Protocol[] getProtocolArray(String usage) {\r
536 String[] xPath;\r
537\r
538 if (usage == null || usage.equals("")) {\r
539 xPath = new String[] {"/Protocol"};\r
540 } else {\r
541 xPath = new String[] {"/Protocol[@Usage='" + usage + "']"};\r
542 }\r
543\r
544 XmlObject[] returns = get("Protocols", xPath);\r
545 if (returns != null && returns.length > 0) {\r
546 return (ProtocolsDocument.Protocols.Protocol[]) returns;\r
547 }\r
548\r
549 return null;\r
550 }\r
551\r
552 /**\r
553 Retrieve ProtocolNotify for specified usage\r
554 \r
555 @param usage ProtocolNotify usage\r
556\r
557 @returns ProtocolNotify objects list if elements are found at the known xpath\r
558 @returns null if nothing is there\r
559 **/\r
560 public static ProtocolsDocument.Protocols.ProtocolNotify[] getProtocolNotifyArray(String usage) {\r
561 String[] xPath;\r
562\r
563 if (usage == null || usage.equals("")) {\r
564 xPath = new String[] {"/ProtocolNotify"};\r
565 } else {\r
566 xPath = new String[] {"/ProtocolNotify[@Usage='" + usage + "']"};\r
567 }\r
568\r
569 XmlObject[] returns = get("Protocols", xPath);\r
570 if (returns != null && returns.length > 0) {\r
571 return (ProtocolsDocument.Protocols.ProtocolNotify[]) returns;\r
572 }\r
573\r
574 return null;\r
575 }\r
576\r
577 /**\r
578 Retrieve ModuleUnloadImage names\r
579\r
580 @returns ModuleUnloadImage name list if elements are found at the known xpath\r
581 @returns null if nothing is there\r
582 **/\r
583 public static String[] getModuleUnloadImageArray() {\r
584 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };\r
585\r
586 XmlObject[] returns = get("Externs", xPath);\r
587 if (returns != null && returns.length > 0) {\r
588 String[] stringArray = new String[returns.length];\r
589 XmlNormalizedString[] doc = (XmlNormalizedString[])returns;\r
590\r
591 for (int i = 0; i < returns.length; ++i) {\r
592 stringArray[i] = doc[i].getStringValue();\r
593 }\r
594\r
595 return stringArray;\r
596 }\r
597\r
598 return null;\r
599 }\r
600\r
601 /**\r
602 Retrieve Extern\r
603\r
604 @returns Extern objects list if elements are found at the known xpath\r
605 @returns null if nothing is there\r
606 **/\r
607 public static ExternsDocument.Externs.Extern[] getExternArray() {\r
608 String[] xPath = new String[] { "/Extern" };\r
609\r
610 XmlObject[] returns = get("Externs", xPath);\r
611 if (returns != null && returns.length > 0) {\r
612 return (ExternsDocument.Externs.Extern[]) returns;\r
613 }\r
614\r
615 return null;\r
616 }\r
617\r
618 /**\r
619 Retrieve Ppi information\r
620\r
621 @param usage Ppi usage\r
622\r
623 @returns Ppi objects list if elements are found at the known xpath\r
624 @returns null if nothing is there\r
625 **/\r
626 public static PPIsDocument.PPIs.Ppi[] getPpiArray(String usage) {\r
627 String[] xPath;\r
628\r
629 if (usage == null || usage.equals("")) {\r
630 xPath = new String[] { "/Ppi" };\r
631 } else {\r
632 xPath = new String[] { "/Ppi[@Usage='" + usage + "']" };\r
633 }\r
634\r
635 XmlObject[] returns = get("PPIs", xPath);\r
636 if (returns != null && returns.length > 0) {\r
637 return (PPIsDocument.PPIs.Ppi[])returns;\r
638 }\r
639\r
640 return null;\r
641 }\r
642\r
643 /**\r
644 Retrive PpiNotify information\r
645 \r
646 @param usage\r
647\r
648 @returns PpiNotify objects list if elements are found at the known xpath\r
649 @returns null if nothing is there\r
650 **/\r
651 public static PPIsDocument.PPIs.PpiNotify[] getPpiNotifyArray(String usage) {\r
652 String[] xPath;\r
653\r
654 if (usage == null || usage.equals("")) {\r
655 xPath = new String[] { "/PpiNotify" };\r
656 } else {\r
657 xPath = new String[] { "/PpiNotify[@Usage='" + usage + "']" };\r
658 }\r
659\r
660 XmlObject[] returns = get("PPIs", xPath);\r
661 if (returns != null && returns.length > 0) {\r
662 return (PPIsDocument.PPIs.PpiNotify[])returns;\r
663 }\r
664\r
665 return null;\r
666 }\r
667\r
668 /**\r
669 Retrieve GuidEntry information for specified usage\r
670\r
671 @param usage GuidEntry usage\r
672\r
673 @returns GuidEntry objects list if elements are found at the known xpath\r
674 @returns null if nothing is there\r
675 **/\r
676 public static GuidsDocument.Guids.GuidEntry[] getGuidEntryArray(String usage) {\r
677 String[] xPath;\r
678\r
679 if (usage == null || usage.equals("")) {\r
680 xPath = new String[] { "/GuidEntry" };\r
681 } else {\r
682 xPath = new String[] { "/GuidEntry[@Usage='" + usage + "']" };\r
683 }\r
684\r
685 XmlObject[] returns = get("Guids", xPath);\r
686 if (returns != null && returns.length > 0) {\r
687 return (GuidsDocument.Guids.GuidEntry[])returns;\r
688 }\r
689\r
690 return null;\r
691 }\r
692\r
693 /**\r
694 Retrieve Library instance information\r
695\r
696 @param arch Architecture name\r
697 @param usage Library instance usage\r
698\r
699 @returns library instance name list if elements are found at the known xpath\r
700 @returns null if nothing is there\r
701 **/\r
702 public static List<String> getLibraryInstance(String arch, String usage) {\r
703 String[] xPath;\r
704 String archAttribute = "";\r
705 String usageAttribute = "";\r
706\r
707 if ((arch != null) || (!arch.equals(""))) {\r
708 archAttribute = "[@ArchType='ALL' or @ArchType='" + arch + "']";\r
709 }\r
710 \r
711 if ((usage != null) || (!usage.equals(""))) {\r
712 // if no Usage attribute specified, default to ALWAYS_CONSUMED\r
713 if (usage.equals(LibraryUsage.ALWAYS_CONSUMED.toString())) {\r
714 usageAttribute = "[not(@Usage) or @Usage='" + usage + "']";\r
715 } else {\r
716 usageAttribute = "[@Usage='" + usage + "']";\r
717 }\r
718 }\r
719 \r
720 xPath = new String[] {\r
721 "/Library" + archAttribute, //usageAttribute,\r
722 "/Library[not(@SupArchList) or @SupArchList='" + arch + "']",\r
723 "/Arch" + archAttribute + "/Library" + usageAttribute\r
724 };\r
725\r
726 XmlObject[] returns = get("Libraries", xPath);\r
727 if (returns == null || returns.length == 0) {\r
728 return null;\r
729 }\r
730 \r
731 List<String> instances = new ArrayList<String>();\r
732 for (int i = 0; i < returns.length; ++i) {\r
733 if (returns[i] instanceof LibrariesDocument.Libraries.Library) {\r
734 LibrariesDocument.Libraries.Library lib = (LibrariesDocument.Libraries.Library)returns[i];\r
735 instances.add(lib.getStringValue());\r
736 } else if (returns[i] instanceof LibrariesDocument.Libraries.Arch.Library) {\r
737 LibrariesDocument.Libraries.Arch.Library lib = (LibrariesDocument.Libraries.Arch.Library)returns[i];\r
738 instances.add(lib.getStringValue());\r
739 }\r
740 }\r
741\r
742 return instances;\r
743 }\r
744\r
745 ///\r
746 /// This method is used for retrieving the elements information which has \r
747 /// CName sub-element\r
748 ///\r
749 private static String[] getCNames(String from, String xPath[]) {\r
750 XmlObject[] returns = get(from, xPath);\r
751 if (returns == null || returns.length == 0) {\r
752 return null;\r
753 }\r
754 \r
755 String[] strings = new String[returns.length];\r
756 for (int i = 0; i < returns.length; ++i) {\r
757 strings[i] = ((CName)returns[i]).getStringValue(); \r
758 }\r
759 \r
760 return strings; \r
761 }\r
762 \r
763 /**\r
764 Retrive library's constructor name\r
765\r
766 @returns constructor name list if elements are found at the known xpath\r
767 @returns null if nothing is there\r
768 **/\r
769 public static String getLibConstructorName() {\r
770 String[] xPath = new String[] {"/Extern/Constructor"};\r
771\r
772 XmlObject[] returns = get("Externs", xPath);\r
773 if (returns != null && returns.length > 0) {\r
774 CName constructor = (CName)returns[0]; \r
775 return constructor.getStringValue(); \r
776 }\r
777\r
778 return null;\r
779 }\r
780\r
781 /**\r
782 Retrive library's destructor name\r
783\r
784 @returns destructor name list if elements are found at the known xpath\r
785 @returns null if nothing is there\r
786 **/\r
787 public static String getLibDestructorName() {\r
788 String[] xPath = new String[] {"/Extern/Destructor"};\r
789\r
790 XmlObject[] returns = get("Externs", xPath);\r
791 if (returns != null && returns.length > 0) {\r
792 CName destructor = (CName)returns[0]; \r
793 return destructor.getStringValue(); \r
794 }\r
795\r
796 return null;\r
797 }\r
798 \r
799 /**\r
800 Retrive DriverBinding names\r
801\r
802 @returns DriverBinding name list if elements are found at the known xpath\r
803 @returns null if nothing is there\r
804 **/\r
805 public static String[] getDriverBindingArray() {\r
806 String[] xPath = new String[] {"/Extern/DriverBinding"};\r
807 return getCNames("Externs", xPath);\r
808 }\r
809 \r
810 /**\r
811 Retrive ComponentName names\r
812\r
813 @returns ComponentName name list if elements are found at the known xpath\r
814 @returns null if nothing is there\r
815 **/\r
816 public static String[] getComponentNameArray() {\r
817 String[] xPath = new String[] {"/Extern/ComponentName"};\r
818 return getCNames("Externs", xPath);\r
819 }\r
820 \r
821 /**\r
822 Retrive DriverConfig names\r
823\r
824 @returns DriverConfig name list if elements are found at the known xpath\r
825 @returns null if nothing is there\r
826 **/\r
827 public static String[] getDriverConfigArray() {\r
828 String[] xPath = new String[] {"/Extern/DriverConfig"};\r
829 return getCNames("Externs", xPath);\r
830 }\r
831 \r
832 /**\r
833 Retrive DriverDiag names\r
834\r
835 @returns DriverDiag name list if elements are found at the known xpath\r
836 @returns null if nothing is there\r
837 **/\r
838 public static String[] getDriverDiagArray() {\r
839 String[] xPath = new String[] {"/Extern/DriverDiag"};\r
840 return getCNames("Externs", xPath);\r
841 }\r
842\r
843 /**\r
844 Retrive SetVirtualAddressMapCallBack names\r
845\r
846 @returns SetVirtualAddressMapCallBack name list \r
847 if elements are found at the known xpath\r
848 @returns null if nothing is there\r
849 **/\r
850 public static String[] getSetVirtualAddressMapCallBackArray() {\r
851 String[] xPath = new String[] {"/Extern/SetVirtualAddressMapCallBack"};\r
852 return getCNames("Externs", xPath);\r
853 }\r
854 \r
855 /**\r
856 Retrive ExitBootServicesCallBack names\r
857\r
858 @returns ExitBootServicesCallBack name list \r
859 if elements are found at the known xpath\r
860 @returns null if nothing is there\r
861 **/\r
862 public static String[] getExitBootServicesCallBackArray() {\r
863 String[] xPath = new String[] {"/Extern/ExitBootServicesCallBack"};\r
864 return getCNames("Externs", xPath);\r
865 }\r
866\r
867 /**\r
868 Retrieve module surface area file information\r
869\r
870 @returns ModuleSA objects list if elements are found at the known xpath\r
871 @returns Empty ModuleSA list if nothing is there\r
872 **/\r
873 public static ModuleSADocument.ModuleSA[] getFpdModules() {\r
874 String[] xPath = new String[] { "/TianoImage/*/ModuleSA" };\r
875\r
876 XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
877 if (result == null) {\r
878 xPath = new String[] { "/FrameworkModules/*/ModuleSA" };\r
879 result = get("FrameworkPlatformDescription", xPath);\r
880 if (result != null) {\r
881 return (ModuleSADocument.ModuleSA[]) result;\r
882 }\r
883 return new ModuleSADocument.ModuleSA[0];\r
884 }\r
885\r
886 return (ModuleSADocument.ModuleSA[]) result;\r
887 }\r
888\r
889 /**\r
890 Retrieve all <ModuleSA> documents from FPD file.\r
891\r
892 @returns ModuleSA objects list if elements are found at the known xpath\r
893 @returns Empty ModuleSA list if nothing is there\r
894 **/\r
895 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {\r
896 String[] xPath = new String[] { "/FrameworkModules/*/ModuleSA" };\r
897\r
898 XmlObject[] result = get("FrameworkPlatformDescription", xPath);\r
899 if (result != null) {\r
900 return (ModuleSADocument.ModuleSA[]) result;\r
901 }\r
902 return new ModuleSADocument.ModuleSA[0];\r
903 }\r
904\r
905 /**\r
906 Retrieve variables for FV images\r
907\r
908 @returns name/value list if elements are found at the known xpath\r
909 @returns empty list if nothing is there\r
910 **/\r
911 public static String[][] getFpdGlobalVariable() {\r
912 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };\r
913\r
914 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
915 if (queryResult == null) {\r
916 return new String[0][];\r
917 }\r
918\r
919 String[][] result = new String[queryResult.length][2];\r
920 for (int i = 0; i < queryResult.length; i++){\r
921 result[i][0] = ((NameValueDocument.NameValue)queryResult[i]).getName();\r
922 result[i][1] = ((NameValueDocument.NameValue)queryResult[i]).getValue();\r
923 }\r
924\r
925 return result;\r
926 }\r
927 \r
928 /**\r
929 Retrieve valid image names\r
930\r
931 @returns valid iamges name list if elements are found at the known xpath\r
932 @returns empty list if nothing is there\r
933 **/\r
934 public static String[] getFpdValidImageNames(){\r
935 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };\r
936\r
937 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
938 if (queryResult == null) {\r
939 return new String[0];\r
940 }\r
941\r
942 String[] result = new String[queryResult.length];\r
943 for (int i = 0; i < queryResult.length; i++){\r
944 result[i] = ((XmlString)queryResult[i]).getStringValue();\r
945 }\r
946\r
947 return result;\r
948 }\r
949\r
950 /**\r
951 Retrieve FV image option information\r
952\r
953 @param fvName FV image name\r
954\r
955 @returns option name/value list if elements are found at the known xpath\r
956 @returns empty list if nothing is there\r
957 **/\r
958 public static String[][] getFpdOptions(String fvName){\r
959 String[] xPath = new String[] {"/Flash/FvImages/FvImageName[@Name='" + fvName.toUpperCase() + "']/FvImageOptions/NameValue" };\r
960\r
961 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
962 if (queryResult == null) {\r
963 return new String[0][];\r
964 }\r
965\r
966 String[][] result = new String[queryResult.length][2];\r
967 for (int i = 0; i < queryResult.length; i++){\r
968 result[i][0] = ((NameValueDocument.NameValue)queryResult[i]).getName();\r
969 result[i][1] = ((NameValueDocument.NameValue)queryResult[i]).getValue();\r
970 }\r
971\r
972 return result;\r
973 }\r
974 \r
975 /**\r
976 Retrieve FV image attributes information\r
977\r
978 @param fvName FV image name\r
979\r
980 @returns attribute name/value list if elements are found at the known xpath\r
981 @returns empty list if nothing is there\r
982 **/\r
983 public static String[][] getFpdAttributes(String fvName){\r
984 String[] xPath = new String[] {"/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='" + fvName.toUpperCase() + "']/FvImageOptions" };\r
985\r
986 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
987 if (queryResult == null) {\r
988 return new String[0][];\r
989 }\r
990\r
991 ArrayList<String[]> list = new ArrayList<String[]>();\r
992 for (int i = 0 ; i < queryResult.length; i++){\r
993 FvImageOptionsDocument.FvImageOptions item = (FvImageOptionsDocument.FvImageOptions)queryResult[i];\r
994\r
995 List<NameValueDocument.NameValue> namevalues = item.getNameValueList();\r
996 Iterator iter = namevalues.iterator();\r
997 while (iter.hasNext()) {\r
998 NameValueDocument.NameValue nvItem = (NameValueDocument.NameValue)iter.next();\r
999 list.add(new String[]{nvItem.getName(), nvItem.getValue()});\r
1000 }\r
1001\r
1002 List<String> enables = item.getEnableList();\r
1003 iter = enables.iterator();\r
1004 while (iter.hasNext()) {\r
1005 String enableItem = (String)iter.next();\r
1006 list.add(new String[]{enableItem, "TRUE"});\r
1007 }\r
1008\r
1009 List<String> disables = item.getDisableList();\r
1010 iter = disables.iterator();\r
1011 while (iter.hasNext()) {\r
1012 String disableItem = (String)iter.next();\r
1013 list.add(new String[]{disableItem, "FALSE"});\r
1014 }\r
1015 }\r
1016\r
1017 String[][] result = new String[list.size()][2];\r
1018 for (int i = 0; i < list.size(); i++){\r
1019 result[i][0] = list.get(i)[0];\r
1020 result[i][1] = list.get(i)[1];\r
1021 }\r
1022\r
1023 return result;\r
1024 }\r
1025 \r
1026 /**\r
1027 Retrieve flash definition file name\r
1028\r
1029 @returns file name if elements are found at the known xpath\r
1030 @returns null if nothing is there\r
1031 **/\r
1032 public static String getFlashDefinitionFile(){\r
1033 String[] xPath = new String[] {"/Flash/FlashDefinitionFile" };\r
1034\r
1035 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
1036 if (queryResult == null || queryResult.length == 0) {\r
1037 return null;\r
1038 }\r
1039\r
1040 FileNameConvention filename = (FileNameConvention)queryResult[queryResult.length - 1];\r
1041 return filename.getStringValue();\r
1042 }\r
1043 \r
1044 /**\r
1045 Retrieve FV image component options\r
1046\r
1047 @param fvName FV image name\r
1048\r
1049 @returns name/value pairs list if elements are found at the known xpath\r
1050 @returns empty list if nothing is there\r
1051 **/\r
1052 public static String[][] getFpdComponents(String fvName){\r
1053 String[] xPath = new String[] {"/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='" + fvName.toUpperCase() + "']/FvImageOptions" };\r
1054\r
1055 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);\r
1056 if (queryResult == null) {\r
1057 return new String[0][];\r
1058 }\r
1059\r
1060 ArrayList<String[]> list = new ArrayList<String[]>();\r
1061 for (int i = 0 ; i < queryResult.length; i++){\r
1062 FvImageOptionsDocument.FvImageOptions item = (FvImageOptionsDocument.FvImageOptions)queryResult[i];\r
1063\r
1064 List<NameValueDocument.NameValue> namevalues = item.getNameValueList();\r
1065 Iterator iter = namevalues.iterator();\r
1066 while (iter.hasNext()) {\r
1067 NameValueDocument.NameValue nvItem = (NameValueDocument.NameValue)iter.next();\r
1068 list.add(new String[]{nvItem.getName(), nvItem.getValue()});\r
1069 }\r
1070\r
1071 List<String> enables = item.getEnableList();\r
1072 iter = enables.iterator();\r
1073 while (iter.hasNext()) {\r
1074 String enableItem = (String)iter.next();\r
1075 list.add(new String[]{enableItem, "TRUE"});\r
1076 }\r
1077\r
1078 List<String> disables = item.getDisableList();\r
1079 iter = disables.iterator();\r
1080 while (iter.hasNext()) {\r
1081 String disableItem = (String)iter.next();\r
1082 list.add(new String[]{disableItem, "FALSE"});\r
1083 }\r
1084 }\r
1085\r
1086 String[][] result = new String[list.size()][2];\r
1087 for (int i = 0; i < list.size(); i++){\r
1088 result[i][0] = list.get(i)[0];\r
1089 result[i][1] = list.get(i)[1];\r
1090 }\r
1091\r
1092 return result;\r
1093 }\r
1094 \r
1095 /**\r
1096 Get name array of PCD in a module. In one module, token space\r
1097 is same, and token name should not be conflicted.\r
1098 \r
1099 @return String[]\r
1100 **/\r
1101 public static String[] getModulePcdEntryNameArray() {\r
1102 PcdCoded.PcdEntry[] pcdEntries = null;\r
1103 String[] results;\r
1104 int index;\r
1105 String[] xPath = new String[] {"/PcdEntry"};\r
1106 XmlObject[] returns = get ("PcdCoded", xPath);\r
1107 if (returns == null) {\r
1108 return null;\r
1109 }\r
1110\r
1111 pcdEntries = (PcdCoded.PcdEntry[])returns;\r
1112 results = new String[pcdEntries.length];\r
1113 \r
1114 for (index = 0; index < pcdEntries.length; index ++) {\r
1115 results[index] = pcdEntries[index].getCName();\r
1116 }\r
1117 return results;\r
1118 }\r
1119}\r