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