]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/SurfaceAreaQuery.java
8ecc71bcece7cb580dcbdafd0490f85fa02d4a7b
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / 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.frameworkwizard.platform.ui.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.Set;
23 import java.util.Stack;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 import org.apache.xmlbeans.XmlNormalizedString;
28 import org.apache.xmlbeans.XmlObject;
29 import org.apache.xmlbeans.XmlString;
30 import org.tianocore.BuildTargetList;
31 import org.tianocore.DataIdDocument;
32 import org.tianocore.ExternsDocument;
33 import org.tianocore.FileNameConvention;
34 //import org.tianocore.FvImageDocument;
35 import org.tianocore.GuidDeclarationsDocument;
36 import org.tianocore.LibrariesDocument;
37 import org.tianocore.LibraryClassDeclarationsDocument;
38 import org.tianocore.LibraryClassDocument;
39 import org.tianocore.ModuleSADocument;
40 import org.tianocore.ModuleTypeDef;
41 import org.tianocore.MsaFilesDocument;
42 import org.tianocore.MsaHeaderDocument;
43 import org.tianocore.PackageDependenciesDocument;
44 import org.tianocore.PackageHeadersDocument;
45 import org.tianocore.PpiDeclarationsDocument;
46 import org.tianocore.ProtocolDeclarationsDocument;
47 import org.tianocore.SpdHeaderDocument;
48 import org.tianocore.FilenameDocument.Filename;
49 import org.tianocore.MsaHeaderDocument.MsaHeader;
50 import org.tianocore.PlatformHeaderDocument;
51 import org.tianocore.frameworkwizard.platform.ui.id.FpdModuleIdentification;
52 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
53 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
54 import org.tianocore.frameworkwizard.platform.ui.id.PlatformIdentification;
55
56 /**
57 * SurfaceAreaQuery class is used to query Surface Area information from msa,
58 * mbd, spd and fpd files.
59 *
60 * This class should not instantiated. All the public interfaces is static.
61 *
62 * @since GenBuild 1.0
63 */
64 public class SurfaceAreaQuery {
65
66 public static String prefix = "http://www.TianoCore.org/2006/Edk2.0";
67
68 // /
69 // / Contains name/value pairs of Surface Area document object. The name is
70 // / always the top level element name.
71 // /
72 private static Map<String, XmlObject> map = null;
73
74 // /
75 // / mapStack is used to do nested query
76 // /
77 private static Stack<Map<String, XmlObject>> mapStack = new Stack<Map<String, XmlObject>>();
78
79 // /
80 // / prefix of name space
81 // /
82 private static String nsPrefix = "sans";
83
84 // /
85 // / xmlbeans needs a name space for each Xpath element
86 // /
87 private static String ns = null;
88
89 // /
90 // / keep the namep declaration for xmlbeans Xpath query
91 // /
92 private static String queryDeclaration = null;
93
94 /**
95 * Set a Surface Area document for query later
96 *
97 * @param map
98 * A Surface Area document in TopLevelElementName/XmlObject
99 * format.
100 */
101 public static void setDoc(Map<String, XmlObject> map) {
102 ns = prefix;
103 queryDeclaration = "declare namespace " + nsPrefix + "='" + ns + "'; ";
104 SurfaceAreaQuery.map = map;
105 }
106
107 /**
108 * Push current used Surface Area document into query stack. The given new
109 * document will be used for any immediately followed getXXX() callings,
110 * untill pop() is called.
111 *
112 * @param newMap
113 * The TopLevelElementName/XmlObject format of a Surface Area
114 * document.
115 */
116 public static void push(Map<String, XmlObject> newMap) {
117 mapStack.push(SurfaceAreaQuery.map);
118 SurfaceAreaQuery.map = newMap;
119 }
120
121 /**
122 * Discard current used Surface Area document and use the top document in
123 * stack instead.
124 */
125 public static void pop() {
126 SurfaceAreaQuery.map = mapStack.pop();
127 }
128
129 // /
130 // / Convert xPath to be namespace qualified, which is necessary for
131 // XmlBeans
132 // / selectPath(). For example, converting /MsaHeader/ModuleType to
133 // / /ns:MsaHeader/ns:ModuleType
134 // /
135 private static String normalizeQueryString(String[] exp, String from) {
136 StringBuffer normQueryString = new StringBuffer(4096);
137
138 int i = 0;
139 while (i < exp.length) {
140 String newExp = from + exp[i];
141 Pattern pattern = Pattern.compile("([^/]*)(/|//)([^/]+)");
142 Matcher matcher = pattern.matcher(newExp);
143
144 while (matcher.find()) {
145 String starter = newExp.substring(matcher.start(1), matcher
146 .end(1));
147 String seperator = newExp.substring(matcher.start(2), matcher
148 .end(2));
149 String token = newExp.substring(matcher.start(3), matcher
150 .end(3));
151
152 normQueryString.append(starter);
153 normQueryString.append(seperator);
154 normQueryString.append(nsPrefix);
155 normQueryString.append(":");
156 normQueryString.append(token);
157 }
158
159 ++i;
160 if (i < exp.length) {
161 normQueryString.append(" | ");
162 }
163 }
164
165 return normQueryString.toString();
166 }
167
168 /**
169 * Search all XML documents stored in "map" for the specified xPath, using
170 * relative path (starting with '$this')
171 *
172 * @param xPath
173 * xpath query string array
174 * @returns An array of XmlObject if elements are found at the specified
175 * xpath
176 * @returns NULL if nothing is at the specified xpath
177 */
178 public static XmlObject[] get(String[] xPath) {
179 if (map == null) {
180 return null;
181 }
182
183 String[] keys = (String[]) map.keySet().toArray(new String[map.size()]);
184 List<XmlObject> result = new ArrayList<XmlObject>();
185 for (int i = 0; i < keys.length; ++i) {
186 XmlObject rootNode = (XmlObject) map.get(keys[i]);
187 if (rootNode == null) {
188 continue;
189 }
190
191 String query = queryDeclaration
192 + normalizeQueryString(xPath, "$this/" + keys[i]);
193 XmlObject[] tmp = rootNode.selectPath(query);
194 for (int j = 0; j < tmp.length; ++j) {
195 result.add(tmp[j]);
196 }
197 }
198
199 int size = result.size();
200 if (size <= 0) {
201 return null;
202 }
203
204 return (XmlObject[]) result.toArray(new XmlObject[size]);
205 }
206
207 /**
208 * Search XML documents named by "rootName" for the given xPath, using
209 * relative path (starting with '$this')
210 *
211 * @param rootName
212 * The top level element name
213 * @param xPath
214 * The xpath query string array
215 * @returns An array of XmlObject if elements are found at the given xpath
216 * @returns NULL if nothing is found at the given xpath
217 */
218 public static XmlObject[] get(String rootName, String[] xPath) {
219 if (map == null) {
220 return null;
221 }
222
223 XmlObject root = (XmlObject) map.get(rootName);
224 if (root == null) {
225 return null;
226 }
227
228 String query = queryDeclaration
229 + normalizeQueryString(xPath, "$this/" + rootName);
230 XmlObject[] result = root.selectPath(query);
231 if (result.length > 0) {
232 return result;
233 }
234
235 query = queryDeclaration + normalizeQueryString(xPath, "/" + rootName);
236 result = root.selectPath(query);
237 if (result.length > 0) {
238 return result;
239 }
240
241 return null;
242 }
243
244 /**
245 * Retrieve SourceFiles/Filename for specified ARCH type
246 *
247 * @param arch
248 * architecture name
249 * @returns An 2 dimension string array if elements are found at the known
250 * xpath
251 * @returns NULL if nothing is found at the known xpath
252 */
253 public static String[][] getSourceFiles(String arch) {
254 String[] xPath;
255 XmlObject[] returns;
256
257 if (arch == null || arch.equals("")) {
258 xPath = new String[] { "/Filename" };
259 } else {
260 xPath = new String[] { "/Filename[not(@SupArchList) or @SupArchList='"
261 + arch + "']" };
262 }
263
264 returns = get("SourceFiles", xPath);
265
266 if (returns == null || returns.length == 0) {
267 return null;
268 }
269
270 Filename[] sourceFileNames = (Filename[]) returns;
271 String[][] outputString = new String[sourceFileNames.length][2];
272 for (int i = 0; i < sourceFileNames.length; i++) {
273 outputString[i][0] = sourceFileNames[i].getToolCode();
274 outputString[i][1] = sourceFileNames[i].getStringValue();
275 }
276 return outputString;
277 }
278
279 /**
280 * Retrieve /PlatformDefinitions/OutputDirectory from FPD
281 *
282 * @returns Directory names array if elements are found at the known xpath
283 * @returns Empty if nothing is found at the known xpath
284 */
285 public static String getFpdOutputDirectory() {
286 String[] xPath = new String[] { "/PlatformDefinitions/OutputDirectory" };
287
288 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
289 if (returns != null && returns.length > 0) {
290 // String TBD
291 }
292
293 return null;
294 }
295
296 public static String getFpdIntermediateDirectories() {
297 String[] xPath = new String[] { "/PlatformDefinitions/IntermediateDirectories" };
298
299 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
300 if (returns != null && returns.length > 0) {
301 // TBD
302 }
303 return "UNIFIED";
304 }
305
306 public static String getBuildTarget() {
307 String[] xPath = new String[] { "/PlatformDefinitions/BuildTargets" };
308
309 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
310 if (returns != null && returns.length > 0) {
311 return ((BuildTargetList) returns[0]).getStringValue();
312 }
313
314 return null;
315 }
316
317 /**
318 * Retrieve <xxxHeader>/ModuleType
319 *
320 * @returns The module type name if elements are found at the known xpath
321 * @returns null if nothing is there
322 */
323 public static String getModuleType() {
324 String[] xPath = new String[] { "/ModuleType" };
325
326 XmlObject[] returns = get(xPath);
327 if (returns != null && returns.length > 0) {
328 ModuleTypeDef type = (ModuleTypeDef) returns[0];
329 return type.enumValue().toString();
330 }
331
332 return null;
333 }
334
335 /**
336 * Retrieve PackageDependencies/Package
337 *
338 * @param arch
339 * Architecture name
340 *
341 * @returns package name list if elements are found at the known xpath
342 * @returns null if nothing is there
343 */
344 public static PackageIdentification[] getDependencePkg(String arch) {
345 String[] xPath;
346 String packageGuid = null;
347 String packageVersion = null;
348
349 if (arch == null || arch.equals("")) {
350 xPath = new String[] { "/PackageDependencies/Package" };
351 } else {
352 xPath = new String[] { "/PackageDependencies/Package[not(@SupArchList) or @SupArchList='"
353 + arch + "']" };
354 }
355
356 XmlObject[] returns = get("ModuleSurfaceArea", xPath);
357 if (returns == null) {
358 return new PackageIdentification[0];
359 }
360 PackageIdentification[] packageIdList = new PackageIdentification[returns.length];
361 for (int i = 0; i < returns.length; i++) {
362 PackageDependenciesDocument.PackageDependencies.Package item = (PackageDependenciesDocument.PackageDependencies.Package) returns[i];
363 packageGuid = item.getPackageGuid();
364 packageVersion = item.getPackageVersion();
365
366 Set<PackageIdentification> spi = GlobalData.getPackageList();
367 Iterator<PackageIdentification> ispi = spi.iterator();
368 String ver = "";
369 while(ispi.hasNext()) {
370 PackageIdentification pi = ispi.next();
371 if (packageVersion != null) {
372 if (pi.getGuid().equals(packageGuid) && pi.getVersion().equals(packageVersion)) {
373 packageIdList[i] = pi;
374 break;
375 }
376 }
377 else {
378 if (pi.getGuid().equals(packageGuid)) {
379 if (pi.getVersion() != null && pi.getVersion().compareTo(ver) > 0){
380 ver = pi.getVersion();
381 packageIdList[i] = pi;
382 }
383 else if (packageIdList[i] == null){
384 packageIdList[i] = pi;
385 }
386 }
387 }
388
389 }
390 }
391 return packageIdList;
392 }
393
394 /**
395 * Retrieve LibraryClassDefinitions/LibraryClass for specified usage
396 *
397 * @param usage
398 * Library class usage
399 *
400 * @returns LibraryClass objects list if elements are found at the known
401 * xpath
402 * @returns null if nothing is there
403 */
404 public static String[] getLibraryClasses(String usage) {
405 String[] xPath;
406
407 if (usage == null || usage.equals("")) {
408 xPath = new String[] { "/LibraryClass" };
409 } else {
410 xPath = new String[] { "/LibraryClass[@Usage='" + usage + "']" };
411 }
412
413 XmlObject[] returns = get("LibraryClassDefinitions", xPath);
414 if (returns == null || returns.length == 0) {
415 return new String[0];
416 }
417
418 LibraryClassDocument.LibraryClass[] libraryClassList = (LibraryClassDocument.LibraryClass[]) returns;
419 String[] libraryClassName = new String[libraryClassList.length];
420 for (int i = 0; i < libraryClassList.length; i++) {
421 libraryClassName[i] = libraryClassList[i].getKeyword();
422 }
423 return libraryClassName;
424 }
425
426 /**
427 * Retrieve ModuleEntryPoint names
428 *
429 * @returns ModuleEntryPoint name list if elements are found at the known
430 * xpath
431 * @returns null if nothing is there
432 */
433 public static String[] getModuleEntryPointArray() {
434 String[] xPath = new String[] { "/Extern/ModuleEntryPoint" };
435
436 XmlObject[] returns = get("Externs", xPath);
437
438 if (returns != null && returns.length > 0) {
439 String[] entryPoints = new String[returns.length];
440
441 for (int i = 0; i < returns.length; ++i) {
442 entryPoints[i] = ((XmlNormalizedString) returns[i])
443 .getStringValue();
444 }
445
446 return entryPoints;
447 }
448
449 return null;
450 }
451
452
453
454
455 /**
456 * Retrieve ModuleUnloadImage names
457 *
458 * @returns ModuleUnloadImage name list if elements are found at the known
459 * xpath
460 * @returns null if nothing is there
461 */
462 public static String[] getModuleUnloadImageArray() {
463 String[] xPath = new String[] { "/Extern/ModuleUnloadImage" };
464
465 XmlObject[] returns = get("Externs", xPath);
466 if (returns != null && returns.length > 0) {
467 String[] stringArray = new String[returns.length];
468 XmlNormalizedString[] doc = (XmlNormalizedString[]) returns;
469
470 for (int i = 0; i < returns.length; ++i) {
471 stringArray[i] = doc[i].getStringValue();
472 }
473
474 return stringArray;
475 }
476
477 return null;
478 }
479
480 /**
481 * Retrieve Extern
482 *
483 * @returns Extern objects list if elements are found at the known xpath
484 * @returns null if nothing is there
485 */
486 public static ExternsDocument.Externs.Extern[] getExternArray() {
487 String[] xPath = new String[] { "/Extern" };
488
489 XmlObject[] returns = get("Externs", xPath);
490 if (returns != null && returns.length > 0) {
491 return (ExternsDocument.Externs.Extern[]) returns;
492 }
493
494 return null;
495 }
496
497 /**
498 * Retrieve Library instance information
499 *
500 * @param arch
501 * Architecture name
502 * @param usage
503 * Library instance usage
504 *
505 * @returns library instance name list if elements are found at the known
506 * xpath
507 * @returns null if nothing is there
508 */
509 public static ModuleIdentification[] getLibraryInstance(String arch) {
510 String[] xPath;
511 String saGuid = null;
512 String saVersion = null;
513 String pkgGuid = null;
514 String pkgVersion = null;
515
516 if (arch == null || arch.equalsIgnoreCase("")) {
517 xPath = new String[] { "/Instance" };
518 } else {
519 xPath = new String[] { "/Instance[not(@SupArchList) or @SupArchList='"
520 + arch + "']" };
521 }
522
523 XmlObject[] returns = get("Libraries", xPath);
524 if (returns == null || returns.length == 0) {
525 return new ModuleIdentification[0];
526 }
527
528 ModuleIdentification[] saIdList = new ModuleIdentification[returns.length];
529 for (int i = 0; i < returns.length; i++) {
530 LibrariesDocument.Libraries.Instance library = (LibrariesDocument.Libraries.Instance) returns[i];
531 saGuid = library.getModuleGuid();
532 saVersion = library.getModuleVersion();
533
534 pkgGuid = library.getPackageGuid();
535 pkgVersion = library.getPackageVersion();
536
537 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
538 saVersion);
539 PackageIdentification pkgId = new PackageIdentification(null,
540 pkgGuid, pkgVersion);
541 saId.setPackage(pkgId);
542
543 saIdList[i] = saId;
544
545 }
546 return saIdList;
547 }
548
549 // /
550 // / This method is used for retrieving the elements information which has
551 // / CName sub-element
552 // /
553 private static String[] getCNames(String from, String xPath[]) {
554 XmlObject[] returns = get(from, xPath);
555 if (returns == null || returns.length == 0) {
556 return null;
557 }
558
559 String[] strings = new String[returns.length];
560 for (int i = 0; i < returns.length; ++i) {
561 // TBD
562 // strings[i] = ((CName) returns[i]).getStringValue();
563 }
564
565 return strings;
566 }
567
568 /**
569 * Retrive library's constructor name
570 *
571 * @returns constructor name list if elements are found at the known xpath
572 * @returns null if nothing is there
573 */
574 public static String getLibConstructorName() {
575 String[] xPath = new String[] { "/Extern/Constructor" };
576
577 XmlObject[] returns = get("Externs", xPath);
578 if (returns != null && returns.length > 0) {
579 // CName constructor = (CName) returns[0];
580 // return constructor.getStringValue();
581 }
582
583 return null;
584 }
585
586 /**
587 * Retrive library's destructor name
588 *
589 * @returns destructor name list if elements are found at the known xpath
590 * @returns null if nothing is there
591 */
592 public static String getLibDestructorName() {
593 String[] xPath = new String[] { "/Extern/Destructor" };
594
595 XmlObject[] returns = get("Externs", xPath);
596 if (returns != null && returns.length > 0) {
597 // CName destructor = (CName) returns[0];
598 // return destructor.getStringValue();
599 }
600
601 return null;
602 }
603
604 /**
605 * Retrive DriverBinding names
606 *
607 * @returns DriverBinding name list if elements are found at the known xpath
608 * @returns null if nothing is there
609 */
610 public static String[] getDriverBindingArray() {
611 String[] xPath = new String[] { "/Extern/DriverBinding" };
612 return getCNames("Externs", xPath);
613 }
614
615 /**
616 * Retrive ComponentName names
617 *
618 * @returns ComponentName name list if elements are found at the known xpath
619 * @returns null if nothing is there
620 */
621 public static String[] getComponentNameArray() {
622 String[] xPath = new String[] { "/Extern/ComponentName" };
623 return getCNames("Externs", xPath);
624 }
625
626 /**
627 * Retrive DriverConfig names
628 *
629 * @returns DriverConfig name list if elements are found at the known xpath
630 * @returns null if nothing is there
631 */
632 public static String[] getDriverConfigArray() {
633 String[] xPath = new String[] { "/Extern/DriverConfig" };
634 return getCNames("Externs", xPath);
635 }
636
637 /**
638 * Retrive DriverDiag names
639 *
640 * @returns DriverDiag name list if elements are found at the known xpath
641 * @returns null if nothing is there
642 */
643 public static String[] getDriverDiagArray() {
644 String[] xPath = new String[] { "/Extern/DriverDiag" };
645 return getCNames("Externs", xPath);
646 }
647
648 /**
649 * Retrive SetVirtualAddressMapCallBack names
650 *
651 * @returns SetVirtualAddressMapCallBack name list if elements are found at
652 * the known xpath
653 * @returns null if nothing is there
654 */
655 public static String[] getSetVirtualAddressMapCallBackArray() {
656 String[] xPath = new String[] { "/Extern/SetVirtualAddressMapCallBack" };
657 return getCNames("Externs", xPath);
658 }
659
660 /**
661 * Retrive ExitBootServicesCallBack names
662 *
663 * @returns ExitBootServicesCallBack name list if elements are found at the
664 * known xpath
665 * @returns null if nothing is there
666 */
667 public static String[] getExitBootServicesCallBackArray() {
668 String[] xPath = new String[] { "/Extern/ExitBootServicesCallBack" };
669 return getCNames("Externs", xPath);
670 }
671
672 /**
673 * Retrieve module surface area file information
674 *
675 * @returns ModuleSA objects list if elements are found at the known xpath
676 * @returns Empty ModuleSA list if nothing is there
677 */
678 public static Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() {
679 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
680 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
681 String arch = null;
682 String fvBinding = null;
683 String saGuid = null;
684 String saVersion = null;
685 String pkgGuid = null;
686 String pkgVersion = null;
687
688 Map<FpdModuleIdentification, Map<String, XmlObject>> fpdModuleMap = new LinkedHashMap<FpdModuleIdentification, Map<String, XmlObject>>();
689
690 if (result == null) {
691 return fpdModuleMap;
692 }
693
694 for (int i = 0; i < result.length; i++) {
695 //
696 // Get Fpd SA Module element node and add to xmlObjectMap.
697 //
698 Map<String, XmlObject> xmlObjectMap = new HashMap<String, XmlObject>();
699 ModuleSADocument.ModuleSA moduleSA = (ModuleSADocument.ModuleSA) result[i];
700 if (((ModuleSADocument.ModuleSA) result[i]).getLibraries() != null) {
701 xmlObjectMap.put("Libraries", moduleSA.getLibraries());
702 }
703 if (((ModuleSADocument.ModuleSA) result[i]).getPcdBuildDefinition() != null) {
704 xmlObjectMap.put("PcdBuildDefinition", moduleSA
705 .getPcdBuildDefinition());
706 }
707 if (((ModuleSADocument.ModuleSA) result[i])
708 .getModuleSaBuildOptions() != null) {
709 xmlObjectMap.put("ModuleSaBuildOptions", moduleSA
710 .getModuleSaBuildOptions());
711 }
712
713 //
714 // Get Fpd SA Module attribute and create FpdMoudleIdentification.
715 //
716 arch = moduleSA.getSupArchList().toString();
717
718 // TBD
719 fvBinding = null;
720 saVersion = ((ModuleSADocument.ModuleSA) result[i])
721 .getModuleVersion();
722
723 saGuid = moduleSA.getModuleGuid();
724 pkgGuid = moduleSA.getPackageGuid();
725 pkgVersion = moduleSA.getPackageVersion();
726
727 //
728 // Create Module Identification which have class member of package
729 // identification.
730 //
731 PackageIdentification pkgId = new PackageIdentification(null,
732 pkgGuid, pkgVersion);
733 ModuleIdentification saId = new ModuleIdentification(null, saGuid,
734 saVersion);
735
736 saId.setPackage(pkgId);
737
738 //
739 // Create FpdModule Identification which have class member of module
740 // identification
741 //
742 FpdModuleIdentification fpdSaId = new FpdModuleIdentification(saId,
743 arch);
744 if (arch != null) {
745 fpdSaId.setArch(arch);
746 }
747 if (fvBinding != null) {
748 fpdSaId.setFvBinding(fvBinding);
749 }
750
751 //
752 // Put element to Map<FpdModuleIdentification, Map<String,
753 // XmlObject>>.
754 //
755 fpdModuleMap.put(fpdSaId, xmlObjectMap);
756 }
757 return fpdModuleMap;
758 }
759
760 /**
761 * Retrieve valid image names
762 *
763 * @returns valid iamges name list if elements are found at the known xpath
764 * @returns empty list if nothing is there
765 */
766 public static String[] getFpdValidImageNames() {
767 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FvImages/FvImage[@Type='ValidImageNames']/FvImageNames" };
768
769 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
770 if (queryResult == null) {
771 return new String[0];
772 }
773
774 String[] result = new String[queryResult.length];
775 for (int i = 0; i < queryResult.length; i++) {
776 result[i] = ((XmlString) queryResult[i]).getStringValue();
777 }
778
779 return result;
780 }
781
782
783
784 public static XmlObject getFpdBuildOptions() {
785 String[] xPath = new String[] { "/BuildOptions" };
786
787 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
788
789 if (queryResult == null || queryResult.length == 0) {
790 return null;
791 }
792 return queryResult[0];
793 }
794
795 public static PlatformIdentification getFpdHeader() {
796 String[] xPath = new String[] { "/PlatformHeader" };
797
798 XmlObject[] returns = get("FrameworkPlatformDescription", xPath);
799
800 if (returns == null || returns.length == 0) {
801 return null;
802 }
803 PlatformHeaderDocument.PlatformHeader header = (PlatformHeaderDocument.PlatformHeader) returns[0];
804
805 String name = header.getPlatformName();
806
807 String guid = header.getGuidValue();
808
809 String version = header.getVersion();
810
811 return new PlatformIdentification(name, guid, version);
812 }
813
814 /**
815 * Retrieve flash definition file name
816 *
817 * @returns file name if elements are found at the known xpath
818 * @returns null if nothing is there
819 */
820 public static String getFlashDefinitionFile() {
821 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/FlashDefinitionFile" };
822
823 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
824 if (queryResult == null || queryResult.length == 0) {
825 return null;
826 }
827
828 FileNameConvention filename = (FileNameConvention) queryResult[queryResult.length - 1];
829 return filename.getStringValue();
830 }
831
832 /**
833 * Retrieve FV image component options
834 *
835 * @param fvName
836 * FV image name
837 *
838 * @returns name/value pairs list if elements are found at the known xpath
839 * @returns empty list if nothing is there
840 */
841 public static String[][] getFpdComponents(String fvName) {
842 String[] xPath = new String[] { "/PlatformDefinitions/FlashDeviceDefinitions/DataRegions/FvDataRegion[@Name='"
843 + fvName.toUpperCase() + "']/DataId" };
844
845 XmlObject[] queryResult = get("FrameworkPlatformDescription", xPath);
846 if (queryResult == null) {
847 return new String[0][];
848 }
849
850 ArrayList<String[]> list = new ArrayList<String[]>();
851 for (int i = 0; i < queryResult.length; i++) {
852 DataIdDocument.DataId item = (DataIdDocument.DataId) queryResult[i];
853 list
854 .add(new String[] { item.getStringValue(),
855 item.getDataSize() });
856 }
857
858 String[][] result = new String[list.size()][2];
859 for (int i = 0; i < list.size(); i++) {
860 result[i][0] = list.get(i)[0];
861 result[i][1] = list.get(i)[1];
862 }
863
864 return result;
865 }
866
867 /**
868 * Retrieve PCD tokens
869 *
870 * @returns CName/ItemType pairs list if elements are found at the known
871 * xpath
872 * @returns null if nothing is there
873 */
874 public static String[][] getPcdTokenArray() {
875 String[] xPath = new String[] { "/PcdData" };
876
877 XmlObject[] returns = get("PCDs", xPath);
878 if (returns == null || returns.length == 0) {
879 return null;
880 }
881
882 // PcdCoded.PcdData[] pcds = (PcdCoded.PcdData[]) returns;
883 // String[][] result = new String[pcds.length][2];
884 // for (int i = 0; i < returns.length; ++i) {
885 // if (pcds[i].getItemType() != null) {
886 // result[i][1] = pcds[i].getItemType().toString();
887 // } else {
888 // result[i][1] = null;
889 // }
890 // result[i][0] = pcds[i].getCName();
891 // }
892
893 return null;
894 }
895
896 /**
897 * Get the PcdToken array from module's surface area document. The array
898 * should contains following data:
899 * <p>
900 * -------------------------------------------------------------------
901 * </p>
902 * <p>
903 * CName | ItemType | TokenspaceName | DefaultValue | Usage | HelpText
904 * </p>
905 * <p>
906 * -------------------------------------------------------------------
907 * </p>
908 * <p>
909 * Note: Until new schema applying, now we can only get CName, ItemType,
910 * </p>
911 *
912 * @return 2-array table contains all information of PCD token retrieved
913 * from MSA.
914 */
915 public static Object[][] etModulePCDTokenArray() {
916 return null;
917 // int index;
918 // Object[][] result;
919 // PCDs.PcdData[] pcds;
920 // String[] xPath = new String[] { "/PcdData" };
921 // XmlObject[] returns = get("PCDs", xPath);
922 //
923 // if ((returns == null) || (returns.length == 0)) {
924 // return null;
925 // }
926 //
927 // pcds = (PCDs.PcdData[]) returns;
928 // result = new Object[pcds.length][6];
929 // for (index = 0; index < pcds.length; index++) {
930 // //
931 // // Get CName
932 // //
933 // result[index][0] = pcds[index].getCName();
934 // //
935 // // Get ItemType: FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODLE,
936 // // DYNAMIC, DYNAMIC_EX
937 // //
938 // if (pcds[index].getItemType() != null) {
939 // result[index][1] = pcds[index].getItemType().toString();
940 // } else {
941 // result[index][1] = null;
942 // }
943 //
944 // //
945 // // BUGBUG: following field can *not* be got from current MSA until
946 // // schema changed.
947 // //
948 // // result [index][2] = pcds[index].getTokenSpaceName();
949 // result[index][2] = null;
950 // result[index][3] = pcds[index].getDefaultValue();
951 // // result [index][4] = pcds[index].getUsage ();
952 // result[index][4] = null;
953 // // result [index][5] = pcds[index].getHelpText ();
954 // result[index][5] = null;
955 // }
956 // return result;
957 }
958
959 /**
960 * Retrieve MAS header
961 *
962 * @return
963 * @return
964 */
965 public static ModuleIdentification getMsaHeader() {
966 String[] xPath = new String[] { "/" };
967 XmlObject[] returns = get("MsaHeader", xPath);
968
969 if (returns == null || returns.length == 0) {
970 return null;
971 }
972
973 MsaHeader msaHeader = (MsaHeader) returns[0];
974 //
975 // Get BaseName, ModuleType, GuidValue, Version
976 // which in MsaHeader.
977 //
978 String name = msaHeader.getModuleName();
979 String moduleType = msaHeader.getModuleType().toString();
980 String guid = msaHeader.getGuidValue();
981 String version = msaHeader.getVersion();
982
983 ModuleIdentification moduleId = new ModuleIdentification(name, guid,
984 version);
985
986 moduleId.setModuleType(moduleType);
987
988 return moduleId;
989 }
990
991 /**
992 * Retrieve Extern Specification
993 *
994 * @param
995 *
996 * @return String[] If have specification element in the <extern> String[0]
997 * If no specification element in the <extern>
998 *
999 */
1000
1001 public static String[] getExternSpecificaiton() {
1002 String[] xPath = new String[] { "/Specification" };
1003
1004 XmlObject[] queryResult = get("Externs", xPath);
1005 if (queryResult == null) {
1006 return new String[0];
1007 }
1008
1009 String[] specificationList = new String[queryResult.length];
1010 for (int i = 0; i < queryResult.length; i++) {
1011 // specificationList[i] = ((SpecificationDocument.Specification)
1012 // queryResult[i])
1013 // .getStringValue();
1014 }
1015 return specificationList;
1016 }
1017
1018 /**
1019 * Retreive MsaFile which in SPD
1020 *
1021 * @param
1022 * @return String[][3] The string sequence is ModuleName, ModuleGuid,
1023 * ModuleVersion, MsaFile String[0][] If no msafile in SPD
1024 */
1025 public static String[] getSpdMsaFile() {
1026 String[] xPath = new String[] { "/MsaFiles" };
1027
1028 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1029 if (returns == null) {
1030 return new String[0];
1031 }
1032
1033 List<String> filenameList = ((MsaFilesDocument.MsaFiles) returns[0])
1034 .getFilenameList();
1035 return filenameList.toArray(new String[filenameList.size()]);
1036 }
1037
1038 /**
1039 * Reteive
1040 */
1041 public static Map<String, String[]> getSpdLibraryClasses() {
1042 String[] xPath = new String[] { "/LibraryClassDeclarations/LibraryClass" };
1043
1044 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1045
1046 //
1047 // Create Map, Key - LibraryClass, String[] - LibraryClass Header file.
1048 //
1049 Map<String, String[]> libClassHeaderMap = new HashMap<String, String[]>();
1050
1051 if (returns == null) {
1052 return libClassHeaderMap;
1053 }
1054
1055 for (int i = 0; i < returns.length; i++) {
1056 LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass library = (LibraryClassDeclarationsDocument.LibraryClassDeclarations.LibraryClass) returns[i];
1057 libClassHeaderMap.put(library.getName(), new String[] { library
1058 .getIncludeHeader() });
1059 }
1060 return libClassHeaderMap;
1061 }
1062
1063 /**
1064 * Reteive
1065 */
1066 public static Map<String, String> getSpdPackageHeaderFiles() {
1067 String[] xPath = new String[] { "/PackageHeaders/IncludePkgHeader" };
1068
1069 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1070
1071 //
1072 // Create Map, Key - ModuleType, String - PackageInclude Header file.
1073 //
1074 Map<String, String> packageIncludeMap = new HashMap<String, String>();
1075
1076 if (returns == null) {
1077 return packageIncludeMap;
1078 }
1079 GlobalData.log.info("" + returns[0].getClass().getName());
1080 for (int i = 0; i < returns.length; i++) {
1081 PackageHeadersDocument.PackageHeaders.IncludePkgHeader includeHeader = (PackageHeadersDocument.PackageHeaders.IncludePkgHeader) returns[i];
1082 packageIncludeMap.put(includeHeader.getModuleType().toString(),
1083 includeHeader.getStringValue());
1084 }
1085 return packageIncludeMap;
1086 }
1087
1088 public static PackageIdentification getSpdHeader() {
1089 String[] xPath = new String[] { "/SpdHeader" };
1090
1091 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1092
1093 if (returns == null || returns.length == 0) {
1094 return null;
1095 }
1096
1097 SpdHeaderDocument.SpdHeader header = (SpdHeaderDocument.SpdHeader) returns[0];
1098
1099 String name = header.getPackageName();
1100
1101 String guid = header.getGuidValue();
1102
1103 String version = header.getVersion();
1104
1105 return new PackageIdentification(name, guid, version);
1106 }
1107
1108 /**
1109 * Reteive
1110 */
1111 public static Map<String, String[]> getSpdGuid() {
1112 String[] xPath = new String[] { "/GuidDeclarations/Entry" };
1113
1114 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1115
1116 //
1117 // Create Map, Key - GuidName, String[] - C_NAME & GUID value.
1118 //
1119 Map<String, String[]> guidDeclMap = new HashMap<String, String[]>();
1120 if (returns == null) {
1121 return guidDeclMap;
1122 }
1123
1124 for (int i = 0; i < returns.length; i++) {
1125 GuidDeclarationsDocument.GuidDeclarations.Entry entry = (GuidDeclarationsDocument.GuidDeclarations.Entry) returns[i];
1126 String[] guidPair = new String[2];
1127 guidPair[0] = entry.getCName();
1128 guidPair[1] = entry.getGuidValue();
1129 guidDeclMap.put(entry.getName(), guidPair);
1130 }
1131 return guidDeclMap;
1132 }
1133
1134 /**
1135 * Reteive
1136 */
1137 public static Map<String, String[]> getSpdProtocol() {
1138 String[] xPath = new String[] { "/ProtocolDeclarations/Entry" };
1139
1140 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1141
1142 //
1143 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1144 //
1145 Map<String, String[]> protoclMap = new HashMap<String, String[]>();
1146
1147 if (returns == null) {
1148 return protoclMap;
1149 }
1150
1151 for (int i = 0; i < returns.length; i++) {
1152 ProtocolDeclarationsDocument.ProtocolDeclarations.Entry entry = (ProtocolDeclarationsDocument.ProtocolDeclarations.Entry) returns[i];
1153 String[] protocolPair = new String[2];
1154
1155 protocolPair[0] = entry.getCName();
1156 protocolPair[1] = entry.getGuidValue();
1157 protoclMap.put(entry.getName(), protocolPair);
1158 }
1159 return protoclMap;
1160 }
1161
1162 /**
1163 * getSpdPpi() Retrieve the SPD PPI Entry
1164 *
1165 * @param
1166 * @return Map<String, String[2]> if get the PPI entry from SPD. Key - PPI
1167 * Name String[0] - PPI CNAME String[1] - PPI Guid Null if no PPI
1168 * entry in SPD.
1169 */
1170 public static Map<String, String[]> getSpdPpi() {
1171 String[] xPath = new String[] { "/PpiDeclarations/Entry" };
1172
1173 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1174
1175 //
1176 // Create Map, Key - protocolName, String[] - C_NAME & GUID value.
1177 //
1178 Map<String, String[]> ppiMap = new HashMap<String, String[]>();
1179
1180 if (returns == null) {
1181 return ppiMap;
1182 }
1183
1184 for (int i = 0; i < returns.length; i++) {
1185 PpiDeclarationsDocument.PpiDeclarations.Entry entry = (PpiDeclarationsDocument.PpiDeclarations.Entry) returns[i];
1186 String[] ppiPair = new String[2];
1187 ppiPair[0] = entry.getCName();
1188 ppiPair[1] = entry.getGuidValue();
1189 ppiMap.put(entry.getName(), ppiPair);
1190 }
1191 return ppiMap;
1192 }
1193
1194 /**
1195 * getModuleSupportedArchs()
1196 *
1197 * This function is to Retrieve Archs one module supported.
1198 *
1199 * @param
1200 * @return supportArch String of supporting archs. null No arch specified in
1201 * <MouduleSupport> element.
1202 */
1203 public static List<String> getModuleSupportedArchs() {
1204 String[] xPath = new String[] { "/ModuleDefinitions/SupportedArchitectures" };
1205
1206 XmlObject[] returns = get("ModuleSurfaceArea", xPath);
1207
1208 if (returns == null) {
1209 return null;
1210 }
1211
1212 return (List<String>)returns[0];
1213 }
1214
1215 public static XmlObject[] getSpdPcdDeclarations() {
1216 String[] xPath = null;
1217 // if (tsGuid != null){
1218 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "' and TokenSpaceGuid='"+ tsGuid + "']" };
1219 // }
1220 // else{
1221 // xPath = new String[] { "/PcdDeclarations/PcdEntry[C_Name='" + cName + "']" };
1222 // }
1223 xPath = new String[] { "/PcdDeclarations/PcdEntry"};
1224 XmlObject[] returns = get("PackageSurfaceArea", xPath);
1225
1226 return returns;
1227 }
1228
1229 public static XmlObject[] getFpdPcdBuildDefinitions(String cName, String tsGuid, String type) {
1230 String[] xPath = new String[] { "/PcdBuildDefinition/PcdData[C_Name='" + cName + "' and TokenSpaceGuid='"
1231 + tsGuid + "' and DatumType!='" + type + "']" };
1232
1233 XmlObject[] returns = get("ModuleSA", xPath);
1234
1235 return returns;
1236 }
1237 /**
1238 * getToolChainFamily
1239 *
1240 * This function is to retrieve ToolChainFamily attribute of FPD
1241 * <BuildOptions>
1242 *
1243 * @param
1244 * @return toolChainFamily If find toolChainFamily attribute in
1245 * <BuildOptions> Null If don't have toolChainFamily in
1246 * <BuildOptions>.
1247 */
1248 public String getToolChainFamily() {
1249 String[] xPath = new String[] { "/BuildOptions" };
1250
1251 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
1252 if (result == null) {
1253 return null;
1254 }
1255 // toolChainFamily =
1256 // ((BuildOptionsDocument.BuildOptions)result[0]).getToolChainFamilies();
1257 // return toolChainFamily;
1258 return null;
1259 }
1260
1261 /**
1262 * Retrieve module Guid string
1263 *
1264 * @returns GUILD string if elements are found at the known xpath
1265 * @returns null if nothing is there
1266 */
1267 public static String getModuleGuid() {
1268 String[] xPath = new String[] { "" };
1269
1270 XmlObject[] returns = get("MsaHeader", xPath);
1271 if (returns != null && returns.length > 0) {
1272 String guid = ((MsaHeaderDocument.MsaHeader) returns[0])
1273 .getGuidValue();
1274 return guid;
1275 }
1276
1277 return null;
1278 }
1279
1280 //
1281 // For new Pcd
1282 //
1283 public static ModuleSADocument.ModuleSA[] getFpdModuleSAs() {
1284 String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
1285 XmlObject[] result = get("FrameworkPlatformDescription", xPath);
1286 if (result != null) {
1287 return (ModuleSADocument.ModuleSA[]) result;
1288 }
1289 return new ModuleSADocument.ModuleSA[0];
1290
1291 }
1292 }