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