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