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