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