3 The file provides interface to save xml file.
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
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.
15 package org
.tianocore
.frameworkwizard
.common
;
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
;
31 public class SaveFile
{
38 public static void main(String
[] args
) {
42 private static void createDirectory(String path
) throws Exception
{
43 File f
= new File(path
);
45 FileOperation
.newFolder(path
);
52 public static void saveMsaFile(String path
, ModuleSurfaceArea msa
) throws Exception
{
54 // Create the file's directory first
56 createDirectory(path
);
59 // Remove all empty top level elements
61 XmlObject o
= msa
.getLibraryClassDefinitions();
63 if (msa
.getLibraryClassDefinitions().getLibraryClassList().size() <= 0) {
64 XmlCursor xmlCursor
= o
.newCursor();
65 xmlCursor
.removeXml();
70 o
= msa
.getSourceFiles();
72 if (msa
.getSourceFiles().getFilenameList().size() <= 0) {
73 XmlCursor xmlCursor
= o
.newCursor();
74 xmlCursor
.removeXml();
79 o
= msa
.getPackageDependencies();
81 if (msa
.getPackageDependencies().getPackageList().size() <= 0) {
82 XmlCursor xmlCursor
= o
.newCursor();
83 xmlCursor
.removeXml();
88 o
= msa
.getProtocols();
90 if (msa
.getProtocols().getProtocolList().size() <= 0
91 && msa
.getProtocols().getProtocolNotifyList().size() <= 0) {
92 XmlCursor xmlCursor
= o
.newCursor();
93 xmlCursor
.removeXml();
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();
106 if (msa
.getEvents().getSignalEvents() != null && msa
.getEvents().getSignalEvents().getEventTypesList().size() <= 0) {
107 XmlCursor xmlCursor
= o
.newCursor();
108 xmlCursor
.removeXml();
112 XmlCursor xmlCursor
= o
.newCursor();
113 xmlCursor
.removeXml();
120 if (msa
.getHobs().getHobTypesList().size() <= 0) {
121 XmlCursor xmlCursor
= o
.newCursor();
122 xmlCursor
.removeXml();
129 if (msa
.getPPIs().getPpiList().size() <= 0 && msa
.getPPIs().getPpiNotifyList().size() <= 0) {
130 XmlCursor xmlCursor
= o
.newCursor();
131 xmlCursor
.removeXml();
136 o
= msa
.getVariables();
138 if (msa
.getVariables().getVariableList().size() <= 0) {
139 XmlCursor xmlCursor
= o
.newCursor();
140 xmlCursor
.removeXml();
145 o
= msa
.getBootModes();
147 if (msa
.getBootModes().getBootModeList().size() <= 0) {
148 XmlCursor xmlCursor
= o
.newCursor();
149 xmlCursor
.removeXml();
154 o
= msa
.getSystemTables();
156 if (msa
.getSystemTables().getSystemTableCNamesList().size() <= 0) {
157 XmlCursor xmlCursor
= o
.newCursor();
158 xmlCursor
.removeXml();
163 o
= msa
.getDataHubs();
165 if (msa
.getDataHubs().getDataHubRecordList().size() <= 0) {
166 XmlCursor xmlCursor
= o
.newCursor();
167 xmlCursor
.removeXml();
172 o
= msa
.getHiiPackages();
174 if (msa
.getHiiPackages().getHiiPackageList().size() <= 0) {
175 XmlCursor xmlCursor
= o
.newCursor();
176 xmlCursor
.removeXml();
183 if (msa
.getGuids().getGuidCNamesList().size() <= 0) {
184 XmlCursor xmlCursor
= o
.newCursor();
185 xmlCursor
.removeXml();
190 o
= msa
.getExterns();
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();
200 o
= msa
.getPcdCoded();
202 if (msa
.getPcdCoded().getPcdEntryList().size() <= 0) {
203 XmlCursor xmlCursor
= o
.newCursor();
204 xmlCursor
.removeXml();
209 ModuleSurfaceAreaDocument msaDoc
= ModuleSurfaceAreaDocument
.Factory
.newInstance();
210 File f
= new File(path
);
215 XmlCursor cursor
= XmlConfig
.setupXmlCursor(msa
.newCursor());
220 XmlOptions options
= XmlConfig
.setupXmlOptions();
225 msaDoc
.addNewModuleSurfaceArea();
226 msaDoc
.setModuleSurfaceArea((ModuleSurfaceArea
) cursor
.getObject());
230 msaDoc
.save(f
, options
);
237 public static void saveSpdFile(String path
, PackageSurfaceArea spd
) throws Exception
{
239 // Create the file's directory first
241 createDirectory(path
);
243 PackageSurfaceAreaDocument spdDoc
= PackageSurfaceAreaDocument
.Factory
.newInstance();
244 File f
= new File(path
);
249 XmlCursor cursor
= XmlConfig
.setupXmlCursor(spd
.newCursor());
254 XmlOptions options
= XmlConfig
.setupXmlOptions();
259 spdDoc
.addNewPackageSurfaceArea();
260 spdDoc
.setPackageSurfaceArea((PackageSurfaceArea
) cursor
.getObject());
264 spdDoc
.save(f
, options
);
271 public static void saveFpdFile(String path
, PlatformSurfaceArea fpd
) throws Exception
{
273 // Create the file's directory first
275 createDirectory(path
);
277 PlatformSurfaceAreaDocument fpdDoc
= PlatformSurfaceAreaDocument
.Factory
.newInstance();
278 File f
= new File(path
);
283 XmlCursor cursor
= XmlConfig
.setupXmlCursor(fpd
.newCursor());
288 XmlOptions options
= XmlConfig
.setupXmlOptions();
293 fpdDoc
.addNewPlatformSurfaceArea();
294 fpdDoc
.setPlatformSurfaceArea((PlatformSurfaceArea
) cursor
.getObject());
298 fpdDoc
.save(f
, options
);
302 Save file as framework db
305 public static void saveDbFile(String path
, FrameworkDatabase db
) throws Exception
{
306 FrameworkDatabaseDocument dbDoc
= FrameworkDatabaseDocument
.Factory
.newInstance();
307 File f
= new File(path
);
312 XmlCursor cursor
= XmlConfig
.setupXmlCursor(db
.newCursor());
317 XmlOptions options
= XmlConfig
.setupXmlOptions();
322 dbDoc
.addNewFrameworkDatabase();
323 dbDoc
.setFrameworkDatabase((FrameworkDatabase
) cursor
.getObject());
328 dbDoc
.save(f
, options
);