]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/global/Spd.java
Fixes:
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / global / Spd.java
1 /** @file
2 Spd class.
3
4 This class is to generate a global table for the content of spd file.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16 package org.tianocore.frameworkwizard.platform.ui.global;
17
18 import java.io.File;
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.apache.xmlbeans.XmlObject;
24 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
25 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
26
27 /**
28
29 This class is to generate a global table for the content of spd file.
30
31 **/
32 public class Spd {
33 ///
34 ///
35 ///
36 Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();
37
38 //
39 // Xml Doc of Spd file, Msa file
40 //
41 public Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();
42 public Map<ModuleIdentification, XmlObject> msaDocMap = new HashMap<ModuleIdentification, XmlObject>();
43 ///
44 /// Package path.
45 ///
46 PackageIdentification packageId;
47
48 /**
49 Constructor function
50
51 This function mainly initialize some member variables.
52 **/
53 Spd(File packageFile) throws Exception {
54 try {
55 XmlObject spdDoc = XmlObject.Factory.parse(packageFile);
56 //
57 // Verify SPD file, if is invalid, throw Exception
58 //
59 // if (! spdDoc.validate()) {
60 // throw new Exception("Package Surface Area file [" + packageFile.getPath() + "] is invalid. ");
61 // }
62 // We can change Map to XmlObject
63
64 spdDocMap.put("PackageSurfaceArea", spdDoc);
65 SurfaceAreaQuery.setDoc(spdDocMap);
66 //
67 //
68 //
69 packageId = SurfaceAreaQuery.getSpdHeader();
70 packageId.setSpdFile(packageFile);
71
72 //
73 // initialize Msa Files
74 // MSA file is absolute file path
75 //
76 String[] msaFilenames = SurfaceAreaQuery.getSpdMsaFile();
77 for (int i = 0; i < msaFilenames.length; i++){
78 File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);
79 if (!msaFile.exists()) {
80 continue;
81 }
82 Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );
83 SurfaceAreaQuery.push(msaDoc);
84 ModuleIdentification moduleId = SurfaceAreaQuery.getMsaHeader();
85 SurfaceAreaQuery.pop();
86 moduleId.setPackage(packageId);
87 msaInfo.put(moduleId, msaFile);
88 msaDocMap.put(moduleId, msaDoc.get("ModuleSurfaceArea"));
89 }
90
91 }
92 catch (Exception e) {
93
94 throw new Exception("Parse package description file [" + packageId.getSpdFile() + "] Error.\n"
95 + e.getMessage());
96 }
97 }
98
99 public PackageIdentification getPackageId() {
100 return packageId;
101 }
102
103 public File getModuleFile(ModuleIdentification moduleId) {
104 return msaInfo.get(moduleId);
105 }
106
107 public Set<ModuleIdentification> getModules(){
108 return msaInfo.keySet();
109 }
110
111 }