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