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