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