]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/global/SurfaceAreaQuery.java
5f86217378e1fa021c0c4d09e7cd4b5834bad05b
[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.HashMap;
18 import java.util.Iterator;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Stack;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
25
26 import org.apache.xmlbeans.XmlNormalizedString;
27 import org.apache.xmlbeans.XmlObject;
28 import org.apache.xmlbeans.XmlString;
29 import org.tianocore.*;
30 import org.tianocore.FilenameDocument.Filename;
31 import org.tianocore.MsaHeaderDocument.MsaHeader;
32 import org.tianocore.ProtocolsDocument.Protocols.Protocol;
33 import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;
34 import org.tianocore.SupportedArchitectures.Enum;
35 import org.tianocore.build.id.FpdModuleIdentification;
36 import org.tianocore.build.id.ModuleIdentification;
37 import org.tianocore.build.id.PackageIdentification;
38 import org.tianocore.build.id.PlatformIdentification;
39 import org.tianocore.build.toolchain.ToolChainInfo;
40 import org.tianocore.logger.EdkLog;
41
42 /**
43 * SurfaceAreaQuery class is used to query Surface Area information from msa,
44 * mbd, spd and fpd files.
45 *
46 * This class should not instantiated. All the public interfaces is static.
47 *
48 * @since GenBuild 1.0
49 */
50 public class SurfaceAreaQuery {
51
52 public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";
53
54 // /
55 // / Contains name/value pairs of Surface Area document object. The name is
56 // / always the top level element name.
57 // /
58 private static Map<String, XmlObject> map = null;
59
60 // /
61 // / mapStack is used to do nested query
62 // /
63 private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();
64
65 // /
66 // / prefix of name space
67 // /
68 private static String nsPrefix = "sans";
69
70 // /
71 // / xmlbeans needs a name space for each Xpath element
72 // /
73 private static String ns = null;
74
75 // /
76 // / keep the namep declaration for xmlbeans Xpath query
77 // /
78 private static String queryDeclaration = null;
79
80 /**
81 * Set a Surface Area document for query later
82 *
83 * @param map
84 * A Surface Area document in TopLevelElementName/XmlObject
85 * format.
86 */
87 public static void setDoc(Map<String, XmlObject> map) {
88 ns = prefix;
89 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";
90 SurfaceAreaQuery.map = map;
91 }
92
93 /**
94 * Push current used Surface Area document into query stack. The given new
95 * document will be used for any immediately followed getXXX() callings,
96 * untill pop() is called.
97 *
98 * @param newMap
99 * The TopLevelElementName/XmlObject format of a Surface Area
100 * document.
101 */
102 public static void push(Map<String, XmlObject> newMap) {
103 mapStack.push(SurfaceAreaQuery.map);
104 SurfaceAreaQuery.map = newMap;
105 }
106
107 /**
108 * Discard current used Surface Area document and use the top document in
109 * stack instead.
110 */
111 public static void pop() {
112 SurfaceAreaQuery.map = mapStack.pop();
113 }
114
115 // /
116 // / Convert xPath to be namespace qualified, which is necessary for
117 // 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
132 .end(1));
133 String seperator = newExp.substring(matcher.start(2), matcher
134 .end(2));
135 String token = newExp.substring(matcher.start(3), matcher
136 .end(3));
137
138 normQueryString.append(starter);
139 normQueryString.append(seperator);
140 normQueryString.append(nsPrefix);
141 normQueryString.append(":");
142 normQueryString.append(token);
143 }
144
145 ++i;
146 if (i < exp.length) {
147 normQueryString.append(" | ");
148 }
149 }
150
151 return normQueryString.toString();
152 }
153
154 /**
155 * Search all XML documents stored in "map" for the specified xPath, using
156 * relative path (starting with '$this')
157 *
158 * @param xPath
159 * xpath query string array
160 * @returns An array of XmlObject if elements are found at the specified
161 * xpath
162 * @returns NULL if nothing is at the specified xpath
163 */
164 public static Object[] get(String[] xPath) {
165 if (map == null) {
166 return null;
167 }
168
169 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);
170 List<Object> result = new ArrayList<Object>();
171 for (int i = 0; i < keys.length; ++i) {
172 XmlObject rootNode = (XmlObject) map.get(keys[i]);
173 if (rootNode == null) {
174 continue;
175 }
176
177 String query = queryDeclaration
178 + normalizeQueryString(xPath, "$this/" + keys[i]);
179 XmlObject[] tmp = rootNode.selectPath(query);
180 for (int j = 0; j < tmp.length; ++j) {
181 result.add((Object)tmp[j]);
182 }
183 }
184
185 int size = result.size();
186 if (size <= 0) {
187 return null;
188 }
189
190 return (Object[]) result.toArray(new Object[size]);
191 }
192
193 /**
194 * Search XML documents named by "rootName" for the given xPath, using
195 * relative path (starting with '$this')
196 *
197 * @param rootName
198 * The top level element name
199 * @param xPath
200 * The xpath query string array
201 * @returns An array of XmlObject if elements are found at the given xpath
202 * @returns NULL if nothing is found at the given xpath
203 */
204 public static Object[] get(String rootName, String[] xPath) {
205 if (map == null) {
206 return null;
207 }
208
209 XmlObject root = (XmlObject) map.get(rootName);
210 if (root == null) {
211 return null;
212 }
213
214 String query = queryDeclaration
215 + normalizeQueryString(xPath, "$this/" + rootName);
216 XmlObject[] result = root.selectPath(query);
217 if (result.length > 0) {
218 return (Object[])result;
219 }
220
221 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);
222 result = root.selectPath(query);
223 if (result.length > 0) {
224 return (Object[])result;
225 }
226
227 return null;
228 }
229
230 /**
231 * Retrieve SourceFiles/Filename for specified ARCH type
232 *
233 * @param arch
234 * architecture name
235 * @returns An 2 dimension string array if elements are found at the known
236 * xpath
237 * @returns NULL if nothing is found at the known xpath
238 */
239 public static String[][] getSourceFiles(String arch) {
240 String[] xPath;
241 Object[] returns;
242
243 xPath = new String[] { "/Filename" };
244
245 returns = get("SourceFiles", xPath);
246
247 if (returns == null || returns.length == 0) {
248 return new String[0][0];
249 }
250
251 Filename[] sourceFileNames = (Filename[]) returns;
252 List<String[]> outputList = new ArrayList<String[]>();
253 for (int i = 0; i < sourceFileNames.length; i++) {
254 List<String> archList = sourceFileNames[i].getSupArchList();
255 if (arch == null || arch.equalsIgnoreCase("") || archList == null || archList.contains(arch)) {
256 outputList.add(new String[] {sourceFileNames[i].getToolCode(),sourceFileNames[i].getStringValue()});
257 }
258 }
259
260 String[][] outputString = new String[outputList.size()][2];
261 for (int index = 0; index < outputList.size(); index++) {
262 outputString[index][0] = outputList.get(index)[0];
263 outputString[index][1] = outputList.get(index)[1];
264 }
265 return outputString;
266 }
267
268 /**
269 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
270 *
271 * @returns Directory names array if elements are found at the known xpath
272 * @returns Empty if nothing is found at the known xpath
273 */
274 public static String getFpdOutputDirectory() {
275 String[] xPath = new String[] { "/PlatformDefinitions" };
276
277 Object[] returns = get("PlatformSurfaceArea", xPath);
278 if (returns == null || returns.length == 0) {
279 return null;
280 }
281 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];
282 return item.getOutputDirectory();
283 }
284
285 public static String getFpdIntermediateDirectories() {
286 String[] xPath = new String[] { "/PlatformDefinitions" };
287
288 Object[] returns = get("PlatformSurfaceArea", xPath);
289 if (returns == null || returns.length == 0) {
290 return "UNIFIED";
291 }
292 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];
293 if(item.getIntermediateDirectories() == null) {
294 return null;
295 }
296 else {
297 return item.getIntermediateDirectories().toString();
298 }
299 }
300
301 public static String getModuleFfsKeyword() {
302 String[] xPath = new String[] { "/" };
303
304 Object[] returns = get("ModuleSaBuildOptions", xPath);
305 if (returns == null || returns.length == 0) {
306 return null;
307 }
308 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];
309 return item.getFfsFormatKey();
310 }
311
312 public static String getModuleFvBindingKeyword() {
313 String[] xPath = new String[] { "/" };
314
315 Object[] returns = get("ModuleSaBuildOptions", xPath);
316 if (returns == null || returns.length == 0) {
317 return null;
318 }
319 ModuleSaBuildOptionsDocument.ModuleSaBuildOptions item = (ModuleSaBuildOptionsDocument.ModuleSaBuildOptions)returns[0];
320 return item.getFvBinding();
321 }
322
323 public static List getModuleSupportedArchs() {
324 String[] xPath = new String[] { "/" };
325
326 Object[] returns = get("ModuleDefinitions", xPath);
327 if (returns == null || returns.length == 0) {
328 return null;
329 }
330 ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];
331 return item.getSupportedArchitectures();
332 }
333
334 public static BuildOptionsDocument.BuildOptions.Ffs[] getFpdFfs() {
335 String[] xPath = new String[] {"/Ffs"};
336
337 Object[] returns = get("BuildOptions", xPath);
338 if (returns == null || returns.length == 0) {
339 return new BuildOptionsDocument.BuildOptions.Ffs[0];
340 }
341 return (BuildOptionsDocument.BuildOptions.Ffs[])returns;
342 }
343
344 public static String getModuleOutputFileBasename() {
345 String[] xPath = new String[] { "/" };
346
347 Object[] returns = get("ModuleDefinitions", xPath);
348 if (returns == null || returns.length == 0) {
349 return null;
350 }
351 ModuleDefinitionsDocument.ModuleDefinitions item = (ModuleDefinitionsDocument.ModuleDefinitions)returns[0];
352 return item.getOutputFileBasename();
353 }
354
355 /**
356 * Retrieve BuildOptions/Option or Arch/Option
357 *
358 * @param toolChainFamilyFlag
359 * if true, retrieve options for toolchain family; otherwise for
360 * toolchain
361 *
362 * @returns String[][5] name, target, toolchain, arch, coommand of options
363 * if elements are found at the known xpath. String[0][] if dont
364 * find element.
365 *
366 * @returns Empty array if nothing is there
367 */
368 public static String[][] getOptions(String from, String[] xPath, boolean toolChainFamilyFlag) {
369 String target = null;
370 String toolchain = null;
371 String toolchainFamily = null;
372 List<String> archList = null;
373 String cmd = null;
374 String targetName = null;
375 String optionName = null;
376
377 Object[] returns = get(from, xPath);
378 if (returns == null) {
379 return new String[0][5];
380 }
381
382 List<String[]> optionList = new ArrayList<String[]>();
383 OptionDocument.Option option;
384
385 for (int i = 0; i < returns.length; i++) {
386 option = (OptionDocument.Option) returns[i];
387
388 //
389 // Get Target, ToolChain(Family), Arch, Cmd, and Option from Option,
390 // then
391 // put to result[][5] array in above order.
392 //
393 String[] targetList;
394 if (option.getBuildTargets() == null) {
395 target = null;
396 }
397 else {
398 target = option.getBuildTargets().toString();
399 }
400 if (target != null) {
401 targetList = target.split(" ");
402 } else {
403 targetList = new String[1];
404 targetList[0] = null;
405 }
406
407 if (toolChainFamilyFlag) {
408 toolchainFamily = option.getToolChainFamily();
409 if (toolchainFamily != null) {
410 toolchain = toolchainFamily.toString();
411 } else {
412 toolchain = null;
413 }
414 } else {
415 toolchain = option.getTagName();
416 }
417
418 archList = new ArrayList<String>();
419 List<String> archEnumList = option.getSupArchList();
420 if (archEnumList == null) {
421 archList.add(null);
422 } else {
423 archList.addAll(archEnumList);
424 /*
425 Iterator it = archEnumList.iterator();
426 while (it.hasNext()) {
427 System.out.println(it.next().getClass().getName());
428 SupportedArchitectures.Enum archType = it.next();
429 archList.add(archType.toString());
430 }
431 */
432 }
433
434 cmd = option.getToolCode();
435
436 optionName = option.getStringValue();
437 for (int t = 0; t < targetList.length; t++) {
438 for (int j = 0; j < archList.size(); j++) {
439 optionList.add(new String[] { targetList[t],
440 toolchain, archList.get(j), cmd, optionName});
441 }
442 }
443 }
444
445 String[][] result = new String[optionList.size()][5];
446 for (int i = 0; i < optionList.size(); i++) {
447 result[i][0] = optionList.get(i)[0];
448 result[i][1] = optionList.get(i)[1];
449 result[i][2] = optionList.get(i)[2];
450 result[i][3] = optionList.get(i)[3];
451 result[i][4] = optionList.get(i)[4];
452 }
453 return result;
454 }
455
456 public static String[][] getModuleBuildOptions(boolean toolChainFamilyFlag) {
457 String[] xPath;
458
459 if (toolChainFamilyFlag == true) {
460 xPath = new String[] {
461 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
462 "/Options/Option[@ToolChainFamily]", };
463 } else {
464 xPath = new String[] {
465 "/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
466 "/Options/Option[@TagName]", };
467 }
468 return getOptions("ModuleSaBuildOptions", xPath, toolChainFamilyFlag);
469 }
470
471 public static String[][] getPlatformBuildOptions(boolean toolChainFamilyFlag) {
472 String[] xPath;
473
474 if (toolChainFamilyFlag == true) {
475 xPath = new String[] {
476 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
477 "/BuildOptions/Options/Option[@ToolChainFamily]", };
478 } else {
479 xPath = new String[] {
480 "/BuildOptions/Options/Option[not(@ToolChainFamily) and not(@TagName)]",
481 "/BuildOptions/Options/Option[@TagName]", };
482 }
483
484 return getOptions("PlatformSurfaceArea", xPath, toolChainFamilyFlag);
485 }
486
487 public static ToolChainInfo getFpdToolChainInfo() {
488 String[] xPath = new String[] { "/PlatformDefinitions" };
489
490 Object[] returns = get("PlatformSurfaceArea", xPath);
491 if (returns == null || returns.length == 0) {
492 return null;
493 }
494
495 PlatformDefinitionsDocument.PlatformDefinitions item = (PlatformDefinitionsDocument.PlatformDefinitions)returns[0];
496 ToolChainInfo toolChainInfo = new ToolChainInfo();
497 toolChainInfo.addTargets(item.getBuildTargets().toString());
498 toolChainInfo.addArchs(item.getSupportedArchitectures().toString());
499 toolChainInfo.addTagnames((String)null);
500 return toolChainInfo;
501 }
502
503 /**
504 * Retrieve <xxxHeader>/ModuleType
505 *
506 * @returns The module type name if elements are found at the known xpath
507 * @returns null if nothing is there
508 */
509 public static String getModuleType() {
510 String[] xPath = new String[] { "/ModuleType" };
511
512 Object[] returns = get(xPath);
513 if (returns != null && returns.length > 0) {
514 ModuleTypeDef type = (ModuleTypeDef) returns[0];
515 return type.enumValue().toString();
516 }
517
518 return null;
519 }
520
521 /**
522 * Retrieve PackageDependencies/Package
523 *
524 * @param arch
525 * Architecture name
526 *
527 * @returns package name list if elements are found at the known xpath
528 * @returns null if nothing is there
529 */
530 public static PackageIdentification[] getDependencePkg(String arch) {
531 String[] xPath;
532 String packageGuid = null;
533 String packageVersion = null;
534
535
536 xPath = new String[] { "/Package" };
537
538 Object[] returns = get("PackageDependencies", xPath);
539 if (returns == null) {
540 return new PackageIdentification[0];
541 }
542 PackageIdentification[] packageIdList = new PackageIdentification[returns.length];
543 for (int i = 0; i < returns.length; i++) {
544 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];
545 List<String> archList = item.getSupArchList();
546 if (arch == null || archList == null || archList.contains(arch)) {
547 packageGuid = item.getPackageGuid();
548 packageVersion = item.getPackageVersion();
549 packageIdList[i] = (new PackageIdentification(null, packageGuid,
550 packageVersion));
551 }
552 }
553 return packageIdList;
554 }
555
556 /**
557 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
558 *
559 * @param usage
560 * Library class usage
561 *
562 * @returns LibraryClass objects list if elements are found at the known
563 * xpath
564 * @returns null if nothing is there
565 */
566 public static String[] getLibraryClasses(String usage) {
567 String[] xPath;
568
569 if (usage == null || usage.equals("")) {
570 xPath = new String[] { "/LibraryClass" };
571 } else {
572 xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };
573 }
574
575 Object[] returns = get("LibraryClassDefinitions", xPath);
576 if (returns == null || returns.length == 0) {
577 return new String[0];
578 }
579
580 LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;
581 String[] libraryClassName = new String[libraryClassList.length];
582 for (int i = 0; i < libraryClassList.length; i++) {
583 libraryClassName[i] = libraryClassList[i].getKeyword();
584 }
585 return libraryClassName;
586 }
587
588 /**
589 * Retrieve ModuleEntryPoint names
590 *
591 * @returns ModuleEntryPoint name list if elements are found at the known
592 * xpath
593 * @returns null if nothing is there
594 */
595 public static String[] getModuleEntryPointArray() {
596 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };
597
598 Object[] returns = get("Externs", xPath);
599
600 if (returns != null && returns.length > 0) {
601 String[] entryPoints = new String[returns.length];
602
603 for (int i = 0; i < returns.length; ++i) {
604 entryPoints[i] = ((CNameType) returns[i]).getStringValue();
605 }
606
607 return entryPoints;
608 }
609
610 return null;
611 }
612
613 /**
614 * retrieve Protocol for specified usage
615 *
616 * @param usage
617 * Protocol usage arch Architecture
618 *
619 * @returns Protocol String list if elements are found at the known xpath
620 * @returns String[0] if nothing is there
621 */
622 public static String[] getProtocolArray(String arch, String usage) {
623 String[] xPath;
624 String usageXpath = "";
625 String archXpath = "";
626
627 if (arch == null || arch.equals("")) {
628 return new String[0];
629 } else {
630 archXpath = "/Protocol";
631 if (usage != null && !usage.equals("")) {
632 usageXpath = "/Protocol[@Usage='" + usage + "']";
633 xPath = new String[] { usageXpath, archXpath };
634 } else {
635 return getProtocolArray(arch);
636 }
637
638 }
639
640 Object[] returns = get("Protocols", xPath);
641 if (returns == null) {
642 return new String[0];
643 }
644 Protocol[] protocolList = (Protocol[]) returns;
645
646 String[] protocolArray = new String[returns.length];
647 for (int i = 0; i < returns.length; i++) {
648 protocolArray[i] = protocolList[i].getProtocolCName();
649 }
650 return protocolArray;
651 }
652
653 /**
654 * retrieve Protocol for specified usage
655 *
656 * @param arch
657 * Architecture
658 *
659 * @returns Protocol String list if elements are found at the known xpath
660 * @returns String[0] if nothing is there
661 */
662 public static String[] getProtocolArray(String arch) {
663 String[] xPath;
664
665 if (arch == null || arch.equals("")) {
666 return new String[0];
667 } else {
668 xPath = new String[] { "/Protocol" };
669 }
670
671 Object[] returns = get("Protocols", xPath);
672 if (returns == null) {
673 return new String[0];
674 }
675 Protocol[] returnlList = (Protocol[]) returns;
676
677 List<String> protocolList = new ArrayList<String>();
678
679 for (int i = 0; i < returns.length; i++) {
680 List<String> archList = returnlList[i].getSupArchList();
681 if (archList == null || archList.contains(arch)){
682 protocolList.add(returnlList[i].getProtocolCName());
683 }
684 }
685 String[] protocolArray = new String[protocolList.size()];
686 for (int i = 0; i < protocolList.size(); i++) {
687 protocolArray[i] = protocolList.get(i);
688 }
689 return protocolArray;
690 }
691
692 /**
693 * Retrieve ProtocolNotify for specified usage
694 *
695 * @param usage
696 * ProtocolNotify usage
697 *
698 * @returns String[] if elements are found at the known xpath
699 * @returns String[0] if nothing is there
700 */
701 public static String[] getProtocolNotifyArray(String arch) {
702 String[] xPath;
703
704 if (arch == null || arch.equals("")) {
705 return new String[0];
706 } else {
707 xPath = new String[] { "/ProtocolNotify" };
708 }
709
710 Object[] returns = get("Protocols", xPath);
711 if (returns == null) {
712 return new String[0];
713 }
714
715 List<String> protocolNotifyList = new ArrayList<String>();
716
717 for (int i = 0; i < returns.length; i++) {
718 List<String> archList = ((ProtocolNotify) returns[i]).getSupArchList();
719 if (archList == null || archList.contains(arch)){
720 protocolNotifyList.add(((ProtocolNotify) returns[i]).getProtocolNotifyCName());
721 }
722
723 }
724 String[] protocolNotifyArray = new String[protocolNotifyList.size()];
725 for (int i = 0; i < protocolNotifyList.size(); i++) {
726 protocolNotifyArray[i] = protocolNotifyList.get(i);
727 }
728 return protocolNotifyArray;
729 }
730
731 /**
732 * Retrieve ProtocolNotify for specified usage
733 *
734 * @param usage
735 * ProtocolNotify usage
736 *
737 * @returns String[] if elements are found at the known xpath
738 * @returns String[0] if nothing is there
739 */
740 public static String[] getProtocolNotifyArray(String arch, String usage) {
741
742 String[] xPath;
743 String usageXpath;
744 String archXpath;
745
746 if (arch == null || arch.equals("")) {
747 return new String[0];
748 } else {
749 archXpath = "/ProtocolNotify";
750 if (usage != null && !usage.equals("")) {
751 usageXpath = "/ProtocolNotify[@Usage='" + arch + "']";
752 xPath = new String[] { archXpath, usageXpath };
753 } else {
754 return getProtocolNotifyArray(arch);
755 }
756 }
757
758 Object[] returns = get("Protocols", xPath);
759 if (returns == null) {
760 return new String[0];
761 }
762
763 String[] protocolNotifyList = new String[returns.length];
764
765 for (int i = 0; i < returns.length; i++) {
766 protocolNotifyList[i] = ((ProtocolNotify) returns[i]).getProtocolNotifyCName();
767 }
768 return protocolNotifyList;
769 }
770
771 /**
772 * Retrieve ModuleUnloadImage names
773 *
774 * @returns ModuleUnloadImage name list if elements are found at the known
775 * xpath
776 * @returns null if nothing is there
777 */
778 public static String[] getModuleUnloadImageArray() {
779 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };
780
781 Object[] returns = get("Externs", xPath);
782 if (returns != null && returns.length > 0) {
783 String[] stringArray = new String[returns.length];
784 CNameType[] doc = (CNameType[]) returns;
785
786 for (int i = 0; i < returns.length; ++i) {
787 stringArray[i] = doc[i].getStringValue();
788 }
789
790 return stringArray;
791 }
792
793 return null;
794 }
795
796 /**
797 * Retrieve Extern
798 *
799 * @returns Extern objects list if elements are found at the known xpath
800 * @returns null if nothing is there
801 */
802 public static ExternsDocument.Externs.Extern[] getExternArray() {
803 String[] xPath = new String[] { "/Extern" };
804
805 Object[] returns = get("Externs", xPath);
806 if (returns != null && returns.length > 0) {
807 return (ExternsDocument.Externs.Extern[]) returns;
808 }
809
810 return null;
811 }
812
813 /**
814 * Retrieve PpiNotify for specified arch
815 *
816 * @param arch
817 * PpiNotify arch
818 *
819 * @returns String[] if elements are found at the known xpath
820 * @returns String[0] if nothing is there
821 */
822 public static String[] getPpiNotifyArray(String arch) {
823 String[] xPath;
824
825 if (arch == null || arch.equals("")) {
826 return new String[0];
827 } else {
828 xPath = new String[] { "/PpiNotify" };
829 }
830
831 Object[] returns = get("PPIs", xPath);
832 if (returns == null) {
833 return new String[0];
834 }
835
836
837 List<String> ppiNotifyList = new ArrayList<String>();
838 for (int i = 0; i < returns.length; i++) {
839 List<String> archList = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getSupArchList();
840 if (archList == null || archList.contains(arch)){
841 ppiNotifyList.add(((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName());
842 }
843
844 }
845 String[] ppiNotifyArray = new String[ppiNotifyList.size()];
846 for (int i = 0; i < ppiNotifyList.size(); i++) {
847 ppiNotifyArray[i] = ppiNotifyList.get(i);
848 }
849
850 return ppiNotifyArray;
851 }
852
853 /**
854 * Retrieve PpiNotify for specified usage and arch
855 *
856 * @param arch
857 * PpiNotify arch usage PpiNotify usage
858 *
859 *
860 * @returns String[] if elements are found at the known xpath
861 * @returns String[0] if nothing is there
862 */
863 public static String[] getPpiNotifyArray(String arch, String usage) {
864
865 String[] xPath;
866 String usageXpath;
867 String archXpath;
868
869 if (arch == null || arch.equals("")) {
870 return new String[0];
871 } else {
872 archXpath = "/PpiNotify";
873 if (usage != null && !usage.equals("")) {
874 usageXpath = "/PpiNotify[@Usage='" + arch + "']";
875 xPath = new String[] { archXpath, usageXpath };
876 } else {
877 return getProtocolNotifyArray(arch);
878 }
879 }
880
881 Object[] returns = get("PPIs", xPath);
882 if (returns == null) {
883 return new String[0];
884 }
885
886 String[] ppiNotifyList = new String[returns.length];
887
888 for (int i = 0; i < returns.length; i++) {
889 ppiNotifyList[i] = ((PPIsDocument.PPIs.PpiNotify) returns[i]).getPpiNotifyCName();
890 }
891 return ppiNotifyList;
892 }
893
894 /**
895 * Retrieve Ppi for specified arch
896 *
897 * @param arch
898 * Ppi arch
899 *
900 * @returns String[] if elements are found at the known xpath
901 * @returns String[0] if nothing is there
902 */
903 public static String[] getPpiArray(String arch) {
904 String[] xPath;
905
906 if (arch == null || arch.equals("")) {
907 return new String[0];
908 } else {
909 xPath = new String[] { "/Ppi" };
910 }
911
912 Object[] returns = get("PPIs", xPath);
913 if (returns == null) {
914 return new String[0];
915 }
916
917 List<String> ppiList = new ArrayList<String>();
918 for (int i = 0; i < returns.length; i++) {
919 List<String> archList = ((PPIsDocument.PPIs.Ppi) returns[i]).getSupArchList();
920 if (archList == null || archList.contains(arch)){
921 ppiList.add(((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName());
922 }
923
924 }
925 String[] ppiArray = new String[ppiList.size()];
926 for (int i = 0; i < ppiList.size(); i++) {
927 ppiArray[i] = ppiList.get(i);
928 }
929 return ppiArray;
930 }
931
932 /**
933 * Retrieve PpiNotify for specified usage and arch
934 *
935 * @param arch
936 * PpiNotify arch usage PpiNotify usage
937 *
938 *
939 * @returns String[] if elements are found at the known xpath
940 * @returns String[0] if nothing is there
941 */
942 public static String[] getPpiArray(String arch, String usage) {
943
944 String[] xPath;
945 String usageXpath;
946 String archXpath;
947
948 if (arch == null || arch.equals("")) {
949 return new String[0];
950 } else {
951 archXpath = "/Ppi";
952 if (usage != null && !usage.equals("")) {
953 usageXpath = "/Ppi[@Usage='" + arch + "']";
954 xPath = new String[] { archXpath, usageXpath };
955 } else {
956 return getProtocolNotifyArray(arch);
957 }
958 }
959
960 Object[] returns = get("PPIs", xPath);
961 if (returns == null) {
962 return new String[0];
963 }
964
965 String[] ppiList = new String[returns.length];
966
967 for (int i = 0; i < returns.length; i++) {
968 ppiList[i] = ((PPIsDocument.PPIs.Ppi) returns[i]).getPpiCName();
969 }
970 return ppiList;
971 }
972
973 /**
974 * Retrieve GuidEntry information for specified usage
975 *
976 * @param arch
977 * GuidEntry arch
978 *
979 * @returns GuidEntry objects list if elements are found at the known xpath
980 * @returns null if nothing is there
981 */
982 public static String[] getGuidEntryArray(String arch) {
983 String[] xPath;
984
985 if (arch == null || arch.equals("")) {
986 xPath = new String[] { "/GuidCNames" };
987 } else {
988 xPath = new String[] { "/GuidCNames" };
989 }
990
991 Object[] returns = get("Guids", xPath);
992 if (returns == null) {
993 return new String[0];
994 }
995
996 List<String> guidList = new ArrayList<String>();
997 for (int i = 0; i < returns.length; i++) {
998 List<String> archList = ((GuidsDocument.Guids.GuidCNames) returns[i]).getSupArchList();
999 if (archList == null || archList.contains(arch)){
1000 guidList.add(((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName());
1001 }
1002
1003 }
1004 String[] guidArray = new String[guidList.size()];
1005 for (int i = 0; i < guidList.size(); i++) {
1006 guidArray[i] = guidList.get(i);
1007 }
1008 return guidArray;
1009
1010 }
1011
1012 /**
1013 * Retrieve GuidEntry information for specified usage
1014 *
1015 * @param arch
1016 * GuidEntry arch usage GuidEntry usage
1017 *
1018 * @returns GuidEntry objects list if elements are found at the known xpath
1019 * @returns null if nothing is there
1020 */
1021 public static String[] getGuidEntryArray(String arch, String usage) {
1022 String[] xPath;
1023 String archXpath;
1024 String usageXpath;
1025
1026 if (arch == null || arch.equals("")) {
1027 return new String[0];
1028 } else {
1029 archXpath = "/GuidEntry";
1030 if (usage != null && !usage.equals("")) {
1031 usageXpath = "/GuidEntry[@Usage='" + arch + "']";
1032 xPath = new String[] { archXpath, usageXpath };
1033 } else {
1034 return getProtocolNotifyArray(arch);
1035 }
1036 }
1037
1038 Object[] returns = get("Guids", xPath);
1039 if (returns == null) {
1040 return new String[0];
1041 }
1042
1043 String[] guidList = new String[returns.length];
1044
1045 for (int i = 0; i < returns.length; i++) {
1046 guidList[i] = ((GuidsDocument.Guids.GuidCNames) returns[i]).getGuidCName();
1047 }
1048 return guidList;
1049 }
1050
1051 /**
1052 * Retrieve Library instance information
1053 *
1054 * @param arch
1055 * Architecture name
1056 * @param usage
1057 * Library instance usage
1058 *
1059 * @returns library instance name list if elements are found at the known
1060 * xpath
1061 * @returns null if nothing is there
1062 */
1063 public static ModuleIdentification[] getLibraryInstance(String arch) {
1064 String[] xPath;
1065 String saGuid = null;
1066 String saVersion = null;
1067 String pkgGuid = null;
1068 String pkgVersion = null;
1069
1070 if (arch == null || arch.equalsIgnoreCase("")) {
1071 xPath = new String[] { "/Instance" };
1072 } else {
1073 //
1074 // Since Schema don't have SupArchList now, so the follow Xpath is
1075 // equal to "/Instance" and [not(@SupArchList) or @SupArchList= arch]
1076 // don't have effect.
1077 //
1078 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"
1079 + arch + "']" };
1080 }
1081
1082 Object[] returns = get("Libraries", xPath);
1083 if (returns == null || returns.length == 0) {
1084 return new ModuleIdentification[0];
1085 }
1086
1087 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];
1088 for (int i = 0; i < returns.length; i++) {
1089 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];
1090 saGuid = library.getModuleGuid();
1091 saVersion = library.getModuleVersion();
1092
1093 pkgGuid = library.getPackageGuid();
1094 pkgVersion = library.getPackageVersion();
1095
1096 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
1097 saVersion);
1098 PackageIdentification pkgId = new PackageIdentification(null,
1099 pkgGuid, pkgVersion);
1100 saId.setPackage(pkgId);
1101
1102 saIdList[i] = saId;
1103
1104 }
1105 return saIdList;
1106 }
1107
1108 // /
1109 // / This method is used for retrieving the elements information which has
1110 // / CName sub-element
1111 // /
1112 private static String[] getCNames(String from, String xPath[]) {
1113 Object[] returns = get(from, xPath);
1114 if (returns == null || returns.length == 0) {
1115 return null;
1116 }
1117
1118 String[] strings = new String[returns.length];
1119 for (int i = 0; i < returns.length; ++i) {
1120 // TBD
1121 strings[i] = ((CNameType) returns[i]).getStringValue();
1122 }
1123
1124 return strings;
1125 }
1126
1127 /**
1128 * Retrive library's constructor name
1129 *
1130 * @returns constructor name list if elements are found at the known xpath
1131 * @returns null if nothing is there
1132 */
1133 public static String getLibConstructorName() {
1134 String[] xPath = new String[] { "/Extern/Constructor" };
1135
1136 Object[] returns = get("Externs", xPath);
1137 if (returns != null && returns.length > 0) {
1138 CNameType constructor = ((CNameType) returns[0]);
1139 return constructor.getStringValue();
1140 }
1141
1142 return null;
1143 }
1144
1145 /**
1146 * Retrive library's destructor name
1147 *
1148 * @returns destructor name list if elements are found at the known xpath
1149 * @returns null if nothing is there
1150 */
1151 public static String getLibDestructorName() {
1152 String[] xPath = new String[] { "/Extern/Destructor" };
1153
1154 Object[] returns = get("Externs", xPath);
1155 if (returns != null && returns.length > 0) {
1156 //
1157 // Only support one Destructor function.
1158 //
1159 CNameType destructor = (CNameType) returns[0];
1160 return destructor.getStringValue();
1161 }
1162
1163 return null;
1164 }
1165
1166 /**
1167 * Retrive DriverBinding names
1168 *
1169 * @returns DriverBinding name list if elements are found at the known xpath
1170 * @returns null if nothing is there
1171 */
1172 public static String[] getDriverBindingArray() {
1173 String[] xPath = new String[] { "/Extern/DriverBinding" };
1174 return getCNames("Externs", xPath);
1175 }
1176
1177 /**
1178 * Retrive ComponentName names
1179 *
1180 * @returns ComponentName name list if elements are found at the known xpath
1181 * @returns null if nothing is there
1182 */
1183 public static String[] getComponentNameArray() {
1184 String[] xPath = new String[] { "/Extern/ComponentName" };
1185 return getCNames("Externs", xPath);
1186 }
1187
1188 /**
1189 * Retrive DriverConfig names
1190 *
1191 * @returns DriverConfig name list if elements are found at the known xpath
1192 * @returns null if nothing is there
1193 */
1194 public static String[] getDriverConfigArray() {
1195 String[] xPath = new String[] { "/Extern/DriverConfig" };
1196 return getCNames("Externs", xPath);
1197 }
1198
1199 /**
1200 * Retrive DriverDiag names
1201 *
1202 * @returns DriverDiag name list if elements are found at the known xpath
1203 * @returns null if nothing is there
1204 */
1205 public static String[] getDriverDiagArray() {
1206 String[] xPath = new String[] { "/Extern/DriverDiag" };
1207 return getCNames("Externs", xPath);
1208 }
1209
1210 /**
1211 * Retrive SetVirtualAddressMapCallBack names
1212 *
1213 * @returns SetVirtualAddressMapCallBack name list if elements are found at
1214 * the known xpath
1215 * @returns null if nothing is there
1216 */
1217 public static String[] getSetVirtualAddressMapCallBackArray() {
1218 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };
1219 return getCNames("Externs", xPath);
1220 }
1221
1222 /**
1223 * Retrive ExitBootServicesCallBack names
1224 *
1225 * @returns ExitBootServicesCallBack name list if elements are found at the
1226 * known xpath
1227 * @returns null if nothing is there
1228 */
1229 public static String[] getExitBootServicesCallBackArray() {
1230 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };
1231 return getCNames("Externs", xPath);
1232 }
1233
1234 /**
1235 * Retrieve module surface area file information
1236 *
1237 * @returns ModuleSA objects list if elements are found at the known xpath
1238 * @returns Empty ModuleSA list if nothing is there
1239 */
1240 public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {
1241 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1242 Object[] result = get("PlatformSurfaceArea", xPath);
1243 String arch = null;
1244 String fvBinding = null;
1245 String saGuid = null;
1246 String saVersion = null;
1247 String pkgGuid = null;
1248 String pkgVersion = null;
1249
1250 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();
1251
1252 if (result == null) {
1253 return fpdModuleMap;
1254 }
1255
1256 for (int i = 0; i < result.length; i++) {
1257 //
1258 // Get Fpd SA Module element node and add to ObjectMap.
1259 //
1260 Map<String, XmlObject> ObjectMap = new HashMap<String, XmlObject>();
1261 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];
1262 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {
1263 ObjectMap.put("Libraries", moduleSA.getLibraries());
1264 }
1265 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {
1266 ObjectMap.put("PcdBuildDefinition", moduleSA
1267 .getPcdBuildDefinition());
1268 }
1269 if (((ModuleSADocument.ModuleSA) result[i])
1270 .getModuleSaBuildOptions() != null) {
1271 ObjectMap.put("ModuleSaBuildOptions", moduleSA
1272 .getModuleSaBuildOptions());
1273 }
1274
1275 //
1276 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
1277 //
1278 arch = moduleSA.getSupArchList().toString();
1279
1280 // TBD
1281 fvBinding = null;
1282 saVersion = ((ModuleSADocument.ModuleSA) result[i])
1283 .getModuleVersion();
1284
1285 saGuid = moduleSA.getModuleGuid();
1286 pkgGuid = moduleSA.getPackageGuid();
1287 pkgVersion = moduleSA.getPackageVersion();
1288
1289 //
1290 // Create Module Identification which have class member of package
1291 // identification.
1292 //
1293 PackageIdentification pkgId = new PackageIdentification(null,
1294 pkgGuid, pkgVersion);
1295 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
1296 saVersion);
1297
1298 saId.setPackage(pkgId);
1299
1300 //
1301 // Create FpdModule Identification which have class member of module
1302 // identification
1303 //
1304 if (arch != null) {
1305 String[] archList = arch.split(" ");
1306 for (int j = 0; j < archList.length; j++) {
1307 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId, archList[j]);
1308
1309 if (fvBinding != null) {
1310 fpdSaId.setFvBinding(fvBinding);
1311 }
1312
1313 //
1314 // Put element to Map<FpdModuleIdentification, Map<String,
1315 // Object>>.
1316 //
1317 fpdModuleMap.put(fpdSaId, ObjectMap);
1318 }
1319 }
1320 }
1321 return fpdModuleMap;
1322 }
1323
1324 /**
1325 * Retrieve valid image names
1326 *
1327 * @returns valid iamges name list if elements are found at the known xpath
1328 * @returns empty list if nothing is there
1329 */
1330 public static String[] getFpdValidImageNames() {
1331 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='ImageName']/FvImageNames" };
1332
1333 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1334 if (queryResult == null) {
1335 return new String[0];
1336 }
1337
1338 String[] result = new String[queryResult.length];
1339 for (int i = 0; i < queryResult.length; i++) {
1340 result[i] = ((XmlString) queryResult[i]).getStringValue();
1341 }
1342
1343 return result;
1344 }
1345
1346 public static XmlObject getFpdUserExtension() {
1347 String[] xPath = new String[] { "" };
1348
1349 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1350 if (queryResult == null) {
1351 return null;
1352 }
1353 return null;
1354 }
1355
1356 /**
1357 * Retrieve FV image option information
1358 *
1359 * @param fvName
1360 * FV image name
1361 *
1362 * @returns option name/value list if elements are found at the known xpath
1363 * @returns empty list if nothing is there
1364 */
1365 public static String[][] getFpdOptions(String fvName) {
1366 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Options' and ./FvImageNames='"
1367 + fvName.toUpperCase() + "']/FvImageOptions" };
1368 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1369 if (queryResult == null) {
1370 return new String[0][];
1371 }
1372 ArrayList<String[]> list = new ArrayList<String[]>();
1373 for (int i = 0; i < queryResult.length; i++) {
1374 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1375 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item
1376 .getNameValueList();
1377 Iterator iter = namevalues.iterator();
1378 while (iter.hasNext()) {
1379 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1380 .next();
1381 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1382 }
1383 }
1384 String[][] result = new String[list.size()][2];
1385 for (int i = 0; i < list.size(); i++) {
1386 result[i][0] = list.get(i)[0];
1387 result[i][1] = list.get(i)[1];
1388 }
1389 return result;
1390
1391 }
1392
1393 public static XmlObject getFpdBuildOptions() {
1394 String[] xPath = new String[] { "/BuildOptions" };
1395
1396 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1397
1398 if (queryResult == null || queryResult.length == 0) {
1399 return null;
1400 }
1401 return (XmlObject)queryResult[0];
1402 }
1403
1404 public static PlatformIdentification getFpdHeader() {
1405 String[] xPath = new String[] { "/PlatformHeader" };
1406
1407 Object[] returns = get("PlatformSurfaceArea", xPath);
1408
1409 if (returns == null || returns.length == 0) {
1410 return null;
1411 }
1412 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
1413
1414 String name = header.getPlatformName();
1415
1416 String guid = header.getGuidValue();
1417
1418 String version = header.getVersion();
1419
1420 return new PlatformIdentification(name, guid, version);
1421 }
1422
1423 /**
1424 * Retrieve FV image attributes information
1425 *
1426 * @param fvName
1427 * FV image name
1428 *
1429 * @returns attribute name/value list if elements are found at the known
1430 * xpath
1431 * @returns empty list if nothing is there
1432 */
1433 public static String[][] getFpdAttributes(String fvName) {
1434 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Attributes' and ./FvImageNames='"
1435 + fvName.toUpperCase() + "']/FvImageOptions" };
1436 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1437 if (queryResult == null) {
1438 return new String[0][];
1439 }
1440 ArrayList<String[]> list = new ArrayList<String[]>();
1441 for (int i = 0; i < queryResult.length; i++) {
1442
1443 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1444 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1445 Iterator iter = namevalues.iterator();
1446 while (iter.hasNext()) {
1447 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1448 .next();
1449 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1450 }
1451 }
1452 String[][] result = new String[list.size()][2];
1453 for (int i = 0; i < list.size(); i++) {
1454 result[i][0] = list.get(i)[0];
1455 result[i][1] = list.get(i)[1];
1456 }
1457 return result;
1458 }
1459
1460 /**
1461 * Retrieve flash definition file name
1462 *
1463 * @returns file name if elements are found at the known xpath
1464 * @returns null if nothing is there
1465 */
1466 public static String getFlashDefinitionFile() {
1467 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
1468
1469 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1470 if (queryResult == null || queryResult.length == 0) {
1471 return null;
1472 }
1473
1474 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
1475 return filename.getStringValue();
1476 }
1477
1478 public static String[][] getFpdGlobalVariable() {
1479 String[] xPath = new String[] { "/Flash/FvImages/NameValue" };
1480 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1481 if (queryResult == null) {
1482 return new String[0][];
1483 }
1484
1485 String[][] result = new String[queryResult.length][2];
1486
1487 for (int i = 0; i < queryResult.length; i++) {
1488 FvImagesDocument.FvImages.NameValue item = (FvImagesDocument.FvImages.NameValue)queryResult[i];
1489 result[i][0] = item.getName();
1490 result[i][1] = item.getValue();
1491 }
1492 return result;
1493 }
1494
1495 /**
1496 * Retrieve FV image component options
1497 *
1498 * @param fvName
1499 * FV image name
1500 *
1501 * @returns name/value pairs list if elements are found at the known xpath
1502 * @returns empty list if nothing is there
1503 */
1504 public static String[][] getFpdComponents(String fvName) {
1505 String[] xPath = new String[] { "/Flash/FvImages/FvImage[@Type='Components' and ./FvImageNames='"+ fvName.toUpperCase() + "']/FvImageOptions" };
1506 Object[] queryResult = get("PlatformSurfaceArea", xPath);
1507 if (queryResult == null) {
1508 return new String[0][];
1509 }
1510
1511 ArrayList<String[]> list = new ArrayList<String[]>();
1512 for (int i = 0; i < queryResult.length; i++) {
1513 FvImagesDocument.FvImages.FvImage.FvImageOptions item = (FvImagesDocument.FvImages.FvImage.FvImageOptions) queryResult[i];
1514 List<FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue> namevalues = item.getNameValueList();
1515 Iterator iter = namevalues.iterator();
1516 while (iter.hasNext()) {
1517 FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nvItem = (FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue) iter
1518 .next();
1519 list.add(new String[] { nvItem.getName(), nvItem.getValue() });
1520 }
1521 }
1522 String[][] result = new String[list.size()][2];
1523 for (int i = 0; i < list.size(); i++) {
1524 result[i][0] = list.get(i)[0];
1525 result[i][1] = list.get(i)[1];
1526 }
1527 return result;
1528 }
1529
1530 /**
1531 * Retrieve PCD tokens
1532 *
1533 * @returns CName/ItemType pairs list if elements are found at the known
1534 * xpath
1535 * @returns null if nothing is there
1536 */
1537 public static String[][] getPcdTokenArray() {
1538 String[] xPath = new String[] { "/PcdData" };
1539
1540 Object[] returns = get("PCDs", xPath);
1541 if (returns == null || returns.length == 0) {
1542 return null;
1543 }
1544
1545 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
1546 // String[][] result = new String[pcds.length][2];
1547 // for (int i = 0; i < returns.length; ++i) {
1548 // if (pcds[i].getItemType() != null) {
1549 // result[i][1] = pcds[i].getItemType().toString();
1550 // } else {
1551 // result[i][1] = null;
1552 // }
1553 // result[i][0] = pcds[i].getCName();
1554 // }
1555
1556 return null;
1557 }
1558
1559 /**
1560 * Get the PcdToken array from module's surface area document. The array
1561 * should contains following data:
1562 * <p>
1563 * -------------------------------------------------------------------
1564 * </p>
1565 * <p>
1566 * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText
1567 * </p>
1568 * <p>
1569 * -------------------------------------------------------------------
1570 * </p>
1571 * <p>
1572 * Note: Until new schema applying, now we can only get CName, ItemType,
1573 * </p>
1574 *
1575 * @return 2-array table contains all information of PCD token retrieved
1576 * from MSA.
1577 */
1578 public static Object[][] etModulePCDTokenArray() {
1579 return null;
1580 // int index;
1581 // Object[][] result;
1582 // PCDs.PcdData[] pcds;
1583 // String[] xPath = new String[] { "/PcdData" };
1584 // Object[] returns = get("PCDs", xPath);
1585 //
1586 // if ((returns == null) || (returns.length == 0)) {
1587 // return null;
1588 // }
1589 //
1590 // pcds = (PCDs.PcdData[]) returns;
1591 // result = new Object[pcds.length][6];
1592 // for (index = 0; index < pcds.length; index++) {
1593 // //
1594 // // Get CName
1595 // //
1596 // result[index][0] = pcds[index].getCName();
1597 // //
1598 // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE,
1599 // // DYNAMIC, DYNAMIC_EX
1600 // //
1601 // if (pcds[index].getItemType() != null) {
1602 // result[index][1] = pcds[index].getItemType().toString();
1603 // } else {
1604 // result[index][1] = null;
1605 // }
1606 //
1607 // //
1608 // // BUGBUG: following field can *not* be got from current MSA until
1609 // // schema changed.
1610 // //
1611 // // result [index][2] = pcds[index].getTokenSpaceName();
1612 // result[index][2] = null;
1613 // result[index][3] = pcds[index].getDefaultValue();
1614 // // result [index][4] = pcds[index].getUsage ();
1615 // result[index][4] = null;
1616 // // result [index][5] = pcds[index].getHelpText ();
1617 // result[index][5] = null;
1618 // }
1619 // return result;
1620 }
1621
1622 /**
1623 * Retrieve MAS header
1624 *
1625 * @return
1626 * @return
1627 */
1628 public static ModuleIdentification getMsaHeader() {
1629 String[] xPath = new String[] { "/" };
1630 Object[] returns = get("MsaHeader", xPath);
1631
1632 if (returns == null || returns.length == 0) {
1633 return null;
1634 }
1635
1636 MsaHeader msaHeader = (MsaHeader) returns[0];
1637 //
1638 // Get BaseName, ModuleType, GuidValue, Version
1639 // which in MsaHeader.
1640 //
1641 String name = msaHeader.getModuleName();
1642 String moduleType = msaHeader.getModuleType().toString();
1643 String guid = msaHeader.getGuidValue();
1644 String version = msaHeader.getVersion();
1645
1646 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
1647 version);
1648
1649 moduleId.setModuleType(moduleType);
1650
1651 return moduleId;
1652 }
1653
1654 /**
1655 * Retrieve Extern Specification
1656 *
1657 * @param
1658 *
1659 * @return String[] If have specification element in the <extern> String[0]
1660 * If no specification element in the <extern>
1661 *
1662 */
1663
1664 public static String[] getExternSpecificaiton() {
1665 String[] xPath = new String[] { "/Specification" };
1666
1667 Object[] queryResult = get("Externs", xPath);
1668 if (queryResult == null) {
1669 return new String[0];
1670 }
1671
1672 String[] specificationList = new String[queryResult.length];
1673 for (int i = 0; i < queryResult.length; i++) {
1674 specificationList[i] = ((Sentence)queryResult[i])
1675 .getStringValue();
1676 }
1677 return specificationList;
1678 }
1679
1680 /**
1681 * Retreive MsaFile which in SPD
1682 *
1683 * @param
1684 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1685 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1686 */
1687 public static String[] getSpdMsaFile() {
1688 String[] xPath = new String[] { "/MsaFiles" };
1689
1690 Object[] returns = get("PackageSurfaceArea", xPath);
1691 if (returns == null) {
1692 return new String[0];
1693 }
1694
1695 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
1696 .getFilenameList();
1697 return filenameList.toArray(new String[filenameList.size()]);
1698 }
1699
1700 /**
1701 * Reteive
1702 */
1703 public static Map<String, String[]> getSpdLibraryClasses() {
1704 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
1705
1706 Object[] returns = get("PackageSurfaceArea", xPath);
1707
1708 //
1709 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1710 //
1711 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
1712
1713 if (returns == null) {
1714 return libClassHeaderMap;
1715 }
1716
1717 for (int i = 0; i < returns.length; i++) {
1718 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1719 libClassHeaderMap.put(library.getName(), new String[] { library
1720 .getIncludeHeader() });
1721 }
1722 return libClassHeaderMap;
1723 }
1724
1725 /**
1726 * Reteive
1727 */
1728 public static Map<String, String> getSpdPackageHeaderFiles() {
1729 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1730
1731 Object[] returns = get("PackageSurfaceArea", xPath);
1732
1733 //
1734 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1735 //
1736 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1737
1738 if (returns == null) {
1739 return packageIncludeMap;
1740 }
1741 // GlobalData.log.info("" + returns[0].getClass().getName());
1742 for (int i = 0; i < returns.length; i++) {
1743 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1744 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1745 includeHeader.getStringValue());
1746 }
1747 return packageIncludeMap;
1748 }
1749
1750 public static PackageIdentification getSpdHeader() {
1751 String[] xPath = new String[] { "/SpdHeader" };
1752
1753 Object[] returns = get("PackageSurfaceArea", xPath);
1754
1755 if (returns == null || returns.length == 0) {
1756 return null;
1757 }
1758
1759 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1760
1761 String name = header.getPackageName();
1762
1763 String guid = header.getGuidValue();
1764
1765 String version = header.getVersion();
1766
1767 return new PackageIdentification(name, guid, version);
1768 }
1769
1770 /**
1771 * Reteive
1772 */
1773 public static Map<String, String[]> getSpdGuid() {
1774 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1775
1776 Object[] returns = get("PackageSurfaceArea", xPath);
1777
1778 //
1779 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1780 //
1781 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1782 if (returns == null) {
1783 return guidDeclMap;
1784 }
1785
1786 for (int i = 0; i < returns.length; i++) {
1787 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1788 String[] guidPair = new String[2];
1789 guidPair[0] = entry.getCName();
1790 guidPair[1] = entry.getGuidValue();
1791 guidDeclMap.put(entry.getName(), guidPair);
1792 EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());
1793 EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[0]);
1794 EdkLog.log(EdkLog.EDK_VERBOSE, guidPair[1]);
1795 }
1796 return guidDeclMap;
1797 }
1798
1799 /**
1800 * Reteive
1801 */
1802 public static Map<String, String[]> getSpdProtocol() {
1803 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1804
1805 Object[] returns = get("PackageSurfaceArea", xPath);
1806
1807 //
1808 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1809 //
1810 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1811
1812 if (returns == null) {
1813 return protoclMap;
1814 }
1815
1816 for (int i = 0; i < returns.length; i++) {
1817 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1818 String[] protocolPair = new String[2];
1819
1820 protocolPair[0] = entry.getCName();
1821 protocolPair[1] = entry.getGuidValue();
1822 protoclMap.put(entry.getName(), protocolPair);
1823 EdkLog.log(EdkLog.EDK_VERBOSE, entry.getName());
1824 EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[0]);
1825 EdkLog.log(EdkLog.EDK_VERBOSE, protocolPair[1]);
1826 }
1827 return protoclMap;
1828 }
1829
1830 /**
1831 * getSpdPpi() Retrieve the SPD PPI Entry
1832 *
1833 * @param
1834 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1835 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1836 * entry in SPD.
1837 */
1838 public static Map<String, String[]> getSpdPpi() {
1839 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1840
1841 Object[] returns = get("PackageSurfaceArea", xPath);
1842
1843 //
1844 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1845 //
1846 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1847
1848 if (returns == null) {
1849 return ppiMap;
1850 }
1851
1852 for (int i = 0; i < returns.length; i++) {
1853 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1854 String[] ppiPair = new String[2];
1855 ppiPair[0] = entry.getCName();
1856 ppiPair[1] = entry.getGuidValue();
1857 ppiMap.put(entry.getName(), ppiPair);
1858 }
1859 return ppiMap;
1860 }
1861
1862 /**
1863 * getToolChainFamily
1864 *
1865 * This function is to retrieve ToolChainFamily attribute of FPD
1866 * <BuildOptions>
1867 *
1868 * @param
1869 * @return toolChainFamily If find toolChainFamily attribute in
1870 * <BuildOptions> Null If don't have toolChainFamily in
1871 * <BuildOptions>.
1872 */
1873 public String getToolChainFamily() {
1874 String toolChainFamily;
1875 String[] xPath = new String[] { "/BuildOptions" };
1876
1877 Object[] result = get("PlatformSurfaceArea", xPath);
1878 if (result == null) {
1879 return null;
1880 }
1881 // toolChainFamily =
1882 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1883 // return toolChainFamily;
1884 return null;
1885 }
1886
1887 /**
1888 * Retrieve module Guid string
1889 *
1890 * @returns GUILD string if elements are found at the known xpath
1891 * @returns null if nothing is there
1892 */
1893 public static String getModuleGuid() {
1894 String[] xPath = new String[] { "" };
1895
1896 Object[] returns = get("MsaHeader", xPath);
1897 if (returns != null && returns.length > 0) {
1898 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1899 .getGuidValue();
1900 return guid;
1901 }
1902
1903 return null;
1904 }
1905
1906 //
1907 // For new Pcd
1908 //
1909 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1910 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1911 Object[] result = get("PlatformSurfaceArea", xPath);
1912 if (result != null) {
1913 return (ModuleSADocument.ModuleSA[]) result;
1914 }
1915 return new ModuleSADocument.ModuleSA[0];
1916
1917 }
1918 /**
1919 Get name array of PCD in a module. In one module, token space
1920 is same, and token name should not be conflicted.
1921
1922 @return String[]
1923 **/
1924 public static String[] getModulePcdEntryNameArray() {
1925 PcdCodedDocument.PcdCoded.PcdEntry[] pcdEntries = null;
1926 String[] results;
1927 int index;
1928 String[] xPath = new String[] {"/PcdEntry"};
1929 Object[] returns = get ("PcdCoded", xPath);
1930
1931 if (returns == null) {
1932 return new String[0];
1933 }
1934
1935 pcdEntries = (PcdCodedDocument.PcdCoded.PcdEntry[])returns;
1936 results = new String[pcdEntries.length];
1937
1938 for (index = 0; index < pcdEntries.length; index ++) {
1939 results[index] = pcdEntries[index].getCName();
1940 }
1941 return results;
1942 }
1943 }