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