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