]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/SaveFile.java
Adjusted locations and sizes of boxes for Windows, Linux and iMac GUI, no other funct...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / SaveFile.java
1 /** @file
2
3 The file provides interface to save xml file.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 package org.tianocore.frameworkwizard.common;
16
17 import java.io.File;
18
19 import org.apache.xmlbeans.XmlCursor;
20 import org.apache.xmlbeans.XmlObject;
21 import org.apache.xmlbeans.XmlOptions;
22 import org.tianocore.FrameworkDatabaseDocument;
23 import org.tianocore.ModuleSurfaceAreaDocument;
24 import org.tianocore.PackageSurfaceAreaDocument;
25 import org.tianocore.PlatformSurfaceAreaDocument;
26 import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
27 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
28 import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
29 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
30
31 public class SaveFile {
32
33 /**
34
35 @param args
36
37 **/
38 public static void main(String[] args) {
39
40 }
41
42 private static void createDirectory(String path) throws Exception {
43 File f = new File(path);
44 path = f.getParent();
45 FileOperation.newFolder(path);
46 }
47
48 /**
49 Save file as msa
50
51 **/
52 public static void saveMsaFile(String path, ModuleSurfaceArea msa) throws Exception {
53 //
54 // Create the file's directory first
55 //
56 createDirectory(path);
57
58 //
59 // Remove all empty top level elements
60 //
61 XmlObject o = msa.getLibraryClassDefinitions();
62 if (o != null) {
63 if (msa.getLibraryClassDefinitions().getLibraryClassList().size() <= 0) {
64 XmlCursor xmlCursor = o.newCursor();
65 xmlCursor.removeXml();
66 xmlCursor.dispose();
67 }
68 }
69
70 o = msa.getSourceFiles();
71 if (o != null) {
72 if (msa.getSourceFiles().getFilenameList().size() <= 0) {
73 XmlCursor xmlCursor = o.newCursor();
74 xmlCursor.removeXml();
75 xmlCursor.dispose();
76 }
77 }
78
79 o = msa.getPackageDependencies();
80 if (o != null) {
81 if (msa.getPackageDependencies().getPackageList().size() <= 0) {
82 XmlCursor xmlCursor = o.newCursor();
83 xmlCursor.removeXml();
84 xmlCursor.dispose();
85 }
86 }
87
88 o = msa.getProtocols();
89 if (o != null) {
90 if (msa.getProtocols().getProtocolList().size() <= 0
91 && msa.getProtocols().getProtocolNotifyList().size() <= 0) {
92 XmlCursor xmlCursor = o.newCursor();
93 xmlCursor.removeXml();
94 xmlCursor.dispose();
95 }
96 }
97
98 o = msa.getEvents();
99 if (o != null) {
100 if (msa.getEvents().getCreateEvents() != null || msa.getEvents().getSignalEvents() != null) {
101 if (msa.getEvents().getCreateEvents() != null && msa.getEvents().getCreateEvents().getEventTypesList().size() <= 0) {
102 XmlCursor xmlCursor = o.newCursor();
103 xmlCursor.removeXml();
104 xmlCursor.dispose();
105 }
106 if (msa.getEvents().getSignalEvents() != null && msa.getEvents().getSignalEvents().getEventTypesList().size() <= 0) {
107 XmlCursor xmlCursor = o.newCursor();
108 xmlCursor.removeXml();
109 xmlCursor.dispose();
110 }
111 } else {
112 XmlCursor xmlCursor = o.newCursor();
113 xmlCursor.removeXml();
114 xmlCursor.dispose();
115 }
116 }
117
118 o = msa.getHobs();
119 if (o != null) {
120 if (msa.getHobs().getHobTypesList().size() <= 0) {
121 XmlCursor xmlCursor = o.newCursor();
122 xmlCursor.removeXml();
123 xmlCursor.dispose();
124 }
125 }
126
127 o = msa.getPPIs();
128 if (o != null) {
129 if (msa.getPPIs().getPpiList().size() <= 0 && msa.getPPIs().getPpiNotifyList().size() <= 0) {
130 XmlCursor xmlCursor = o.newCursor();
131 xmlCursor.removeXml();
132 xmlCursor.dispose();
133 }
134 }
135
136 o = msa.getVariables();
137 if (o != null) {
138 if (msa.getVariables().getVariableList().size() <= 0) {
139 XmlCursor xmlCursor = o.newCursor();
140 xmlCursor.removeXml();
141 xmlCursor.dispose();
142 }
143 }
144
145 o = msa.getBootModes();
146 if (o != null) {
147 if (msa.getBootModes().getBootModeList().size() <= 0) {
148 XmlCursor xmlCursor = o.newCursor();
149 xmlCursor.removeXml();
150 xmlCursor.dispose();
151 }
152 }
153
154 o = msa.getSystemTables();
155 if (o != null) {
156 if (msa.getSystemTables().getSystemTableCNamesList().size() <= 0) {
157 XmlCursor xmlCursor = o.newCursor();
158 xmlCursor.removeXml();
159 xmlCursor.dispose();
160 }
161 }
162
163 o = msa.getDataHubs();
164 if (o != null) {
165 if (msa.getDataHubs().getDataHubRecordList().size() <= 0) {
166 XmlCursor xmlCursor = o.newCursor();
167 xmlCursor.removeXml();
168 xmlCursor.dispose();
169 }
170 }
171
172 o = msa.getHiiPackages();
173 if (o != null) {
174 if (msa.getHiiPackages().getHiiPackageList().size() <= 0) {
175 XmlCursor xmlCursor = o.newCursor();
176 xmlCursor.removeXml();
177 xmlCursor.dispose();
178 }
179 }
180
181 o = msa.getGuids();
182 if (o != null) {
183 if (msa.getGuids().getGuidCNamesList().size() <= 0) {
184 XmlCursor xmlCursor = o.newCursor();
185 xmlCursor.removeXml();
186 xmlCursor.dispose();
187 }
188 }
189
190 o = msa.getExterns();
191 if (o != null) {
192 if (msa.getExterns().getExternList().size() <= 0 && msa.getExterns().getSpecificationList().size() <= 0
193 && msa.getExterns().getPcdIsDriver() == null) {
194 XmlCursor xmlCursor = o.newCursor();
195 xmlCursor.removeXml();
196 xmlCursor.dispose();
197 }
198 }
199
200 o = msa.getPcdCoded();
201 if (o != null) {
202 if (msa.getPcdCoded().getPcdEntryList().size() <= 0) {
203 XmlCursor xmlCursor = o.newCursor();
204 xmlCursor.removeXml();
205 xmlCursor.dispose();
206 }
207 }
208
209 ModuleSurfaceAreaDocument msaDoc = ModuleSurfaceAreaDocument.Factory.newInstance();
210 File f = new File(path);
211
212 //
213 //Init namespace
214 //
215 XmlCursor cursor = XmlConfig.setupXmlCursor(msa.newCursor());
216
217 //
218 //Config file format
219 //
220 XmlOptions options = XmlConfig.setupXmlOptions();
221
222 //
223 //Create finial doc
224 //
225 msaDoc.addNewModuleSurfaceArea();
226 msaDoc.setModuleSurfaceArea((ModuleSurfaceArea) cursor.getObject());
227 //
228 //Save the file
229 //
230 msaDoc.save(f, options);
231 }
232
233 /**
234 Save file as spd
235
236 **/
237 public static void saveSpdFile(String path, PackageSurfaceArea spd) throws Exception {
238 //
239 // Create the file's directory first
240 //
241 createDirectory(path);
242
243 PackageSurfaceAreaDocument spdDoc = PackageSurfaceAreaDocument.Factory.newInstance();
244 File f = new File(path);
245
246 //
247 //Init namespace
248 //
249 XmlCursor cursor = XmlConfig.setupXmlCursor(spd.newCursor());
250
251 //
252 //Config file format
253 //
254 XmlOptions options = XmlConfig.setupXmlOptions();
255
256 //
257 //Create finial doc
258 //
259 spdDoc.addNewPackageSurfaceArea();
260 spdDoc.setPackageSurfaceArea((PackageSurfaceArea) cursor.getObject());
261 //
262 //Save the file
263 //
264 spdDoc.save(f, options);
265 }
266
267 /**
268 Save file as fpd
269
270 **/
271 public static void saveFpdFile(String path, PlatformSurfaceArea fpd) throws Exception {
272 //
273 // Create the file's directory first
274 //
275 createDirectory(path);
276
277 PlatformSurfaceAreaDocument fpdDoc = PlatformSurfaceAreaDocument.Factory.newInstance();
278 File f = new File(path);
279
280 //
281 //Init namespace
282 //
283 XmlCursor cursor = XmlConfig.setupXmlCursor(fpd.newCursor());
284
285 //
286 //Config file format
287 //
288 XmlOptions options = XmlConfig.setupXmlOptions();
289
290 //
291 //Create finial doc
292 //
293 fpdDoc.addNewPlatformSurfaceArea();
294 fpdDoc.setPlatformSurfaceArea((PlatformSurfaceArea) cursor.getObject());
295 //
296 //Save the file
297 //
298 fpdDoc.save(f, options);
299 }
300
301 /**
302 Save file as framework db
303
304 **/
305 public static void saveDbFile(String path, FrameworkDatabase db) throws Exception {
306 FrameworkDatabaseDocument dbDoc = FrameworkDatabaseDocument.Factory.newInstance();
307 File f = new File(path);
308
309 //
310 //Init namespace
311 //
312 XmlCursor cursor = XmlConfig.setupXmlCursor(db.newCursor());
313
314 //
315 //Config file format
316 //
317 XmlOptions options = XmlConfig.setupXmlOptions();
318
319 //
320 //Create finial doc
321 //
322 dbDoc.addNewFrameworkDatabase();
323 dbDoc.setFrameworkDatabase((FrameworkDatabase) cursor.getObject());
324
325 //
326 //Save the file
327 //
328 dbDoc.save(f, options);
329 }
330 }