]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/SaveFile.java
Fixed Enumeration ModuleType was suppose to be TOOL, not TOOLS.
[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.XmlOptions;
21 import org.tianocore.FrameworkDatabaseDocument;
22 import org.tianocore.ModuleSurfaceAreaDocument;
23 import org.tianocore.PackageSurfaceAreaDocument;
24 import org.tianocore.PlatformSurfaceAreaDocument;
25 import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;
26 import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;
27 import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;
28 import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;
29
30 public class SaveFile {
31
32 /**
33
34 @param args
35
36 **/
37 public static void main(String[] args) {
38 // TODO Auto-generated method stub
39
40 }
41
42 /**
43 Save file as msa
44
45 **/
46 public static void saveMsaFile(String path, ModuleSurfaceArea msa) throws Exception {
47 ModuleSurfaceAreaDocument msaDoc = ModuleSurfaceAreaDocument.Factory.newInstance();
48 File f = new File(path);
49
50 //
51 //Init namespace
52 //
53 XmlCursor cursor = XmlConfig.setupXmlCursor(msa.newCursor());
54
55 //
56 //Config file format
57 //
58 XmlOptions options = XmlConfig.setupXmlOptions();
59
60 //
61 //Create finial doc
62 //
63 msaDoc.addNewModuleSurfaceArea();
64 msaDoc.setModuleSurfaceArea((ModuleSurfaceArea) cursor.getObject());
65 //
66 //Save the file
67 //
68 msaDoc.save(f, options);
69 }
70
71 /**
72 Save file as spd
73
74 **/
75 public static void saveSpdFile(String path, PackageSurfaceArea spd) throws Exception {
76 PackageSurfaceAreaDocument spdDoc = PackageSurfaceAreaDocument.Factory.newInstance();
77 File f = new File(path);
78
79 //
80 //Init namespace
81 //
82 XmlCursor cursor = XmlConfig.setupXmlCursor(spd.newCursor());
83
84 //
85 //Config file format
86 //
87 XmlOptions options = XmlConfig.setupXmlOptions();
88
89 //
90 //Create finial doc
91 //
92 spdDoc.addNewPackageSurfaceArea();
93 spdDoc.setPackageSurfaceArea((PackageSurfaceArea) cursor.getObject());
94 //
95 //Save the file
96 //
97 spdDoc.save(f, options);
98 }
99
100 /**
101 Save file as fpd
102
103 **/
104 public static void saveFpdFile(String path, PlatformSurfaceArea fpd) throws Exception {
105 PlatformSurfaceAreaDocument fpdDoc = PlatformSurfaceAreaDocument.Factory.newInstance();
106 File f = new File(path);
107
108 //
109 //Init namespace
110 //
111 XmlCursor cursor = XmlConfig.setupXmlCursor(fpd.newCursor());
112
113 //
114 //Config file format
115 //
116 XmlOptions options = XmlConfig.setupXmlOptions();
117
118 //
119 //Create finial doc
120 //
121 fpdDoc.addNewPlatformSurfaceArea();
122 fpdDoc.setPlatformSurfaceArea((PlatformSurfaceArea) cursor.getObject());
123 //
124 //Save the file
125 //
126 fpdDoc.save(f, options);
127 }
128
129 /**
130 Save file as framework db
131
132 **/
133 public static void saveDbFile(String path, FrameworkDatabase db) throws Exception {
134 FrameworkDatabaseDocument dbDoc = FrameworkDatabaseDocument.Factory.newInstance();
135 File f = new File(path);
136
137 //
138 //Init namespace
139 //
140 XmlCursor cursor = XmlConfig.setupXmlCursor(db.newCursor());
141
142 //
143 //Config file format
144 //
145 XmlOptions options = XmlConfig.setupXmlOptions();
146
147 //
148 //Create finial doc
149 //
150 dbDoc.addNewFrameworkDatabase();
151 dbDoc.setFrameworkDatabase((FrameworkDatabase) cursor.getObject());
152
153 //
154 //Save the file
155 //
156 dbDoc.save(f, options);
157 }
158 }