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