]>
Commit | Line | Data |
---|---|---|
a13899c5 | 1 | /** @file\r |
2 | \r | |
3 | The file provides interface to save xml file.\r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | package org.tianocore.frameworkwizard.common;\r | |
16 | \r | |
17 | import java.io.File;\r | |
18 | \r | |
19 | import org.apache.xmlbeans.XmlCursor;\r | |
20 | import org.apache.xmlbeans.XmlOptions;\r | |
21 | import org.tianocore.FrameworkDatabaseDocument;\r | |
22 | import org.tianocore.ModuleSurfaceAreaDocument;\r | |
23 | import org.tianocore.PackageSurfaceAreaDocument;\r | |
24 | import org.tianocore.PlatformSurfaceAreaDocument;\r | |
25 | import org.tianocore.FrameworkDatabaseDocument.FrameworkDatabase;\r | |
26 | import org.tianocore.ModuleSurfaceAreaDocument.ModuleSurfaceArea;\r | |
27 | import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r | |
28 | import org.tianocore.PlatformSurfaceAreaDocument.PlatformSurfaceArea;\r | |
29 | \r | |
30 | public class SaveFile {\r | |
31 | \r | |
32 | /**\r | |
33 | \r | |
34 | @param args\r | |
35 | \r | |
36 | **/\r | |
37 | public static void main(String[] args) {\r | |
38 | // TODO Auto-generated method stub\r | |
39 | \r | |
40 | }\r | |
41 | \r | |
42 | /**\r | |
43 | Save file as msa\r | |
44 | \r | |
45 | **/\r | |
46 | public static void saveMsaFile(String path, ModuleSurfaceArea msa) throws Exception {\r | |
47 | ModuleSurfaceAreaDocument msaDoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r | |
48 | File f = new File(path);\r | |
49 | \r | |
50 | //\r | |
51 | //Init namespace\r | |
52 | //\r | |
53 | XmlCursor cursor = XmlConfig.setupXmlCursor(msa.newCursor());\r | |
54 | \r | |
55 | //\r | |
56 | //Config file format\r | |
57 | //\r | |
58 | XmlOptions options = XmlConfig.setupXmlOptions();\r | |
59 | \r | |
60 | //\r | |
61 | //Create finial doc\r | |
62 | //\r | |
63 | msaDoc.addNewModuleSurfaceArea();\r | |
64 | msaDoc.setModuleSurfaceArea((ModuleSurfaceArea) cursor.getObject());\r | |
65 | //\r | |
66 | //Save the file\r | |
67 | //\r | |
68 | msaDoc.save(f, options);\r | |
69 | }\r | |
70 | \r | |
71 | /**\r | |
72 | Save file as spd\r | |
73 | \r | |
74 | **/\r | |
75 | public static void saveSpdFile(String path, PackageSurfaceArea spd) throws Exception {\r | |
76 | PackageSurfaceAreaDocument spdDoc = PackageSurfaceAreaDocument.Factory.newInstance();\r | |
77 | File f = new File(path);\r | |
78 | \r | |
79 | //\r | |
80 | //Init namespace\r | |
81 | //\r | |
82 | XmlCursor cursor = XmlConfig.setupXmlCursor(spd.newCursor());\r | |
83 | \r | |
84 | //\r | |
85 | //Config file format\r | |
86 | //\r | |
87 | XmlOptions options = XmlConfig.setupXmlOptions();\r | |
88 | \r | |
89 | //\r | |
90 | //Create finial doc\r | |
91 | //\r | |
92 | spdDoc.addNewPackageSurfaceArea();\r | |
93 | spdDoc.setPackageSurfaceArea((PackageSurfaceArea) cursor.getObject());\r | |
94 | //\r | |
95 | //Save the file\r | |
96 | //\r | |
97 | spdDoc.save(f, options);\r | |
98 | }\r | |
99 | \r | |
100 | /**\r | |
101 | Save file as fpd\r | |
102 | \r | |
103 | **/\r | |
104 | public static void saveFpdFile(String path, PlatformSurfaceArea fpd) throws Exception {\r | |
105 | PlatformSurfaceAreaDocument fpdDoc = PlatformSurfaceAreaDocument.Factory.newInstance();\r | |
106 | File f = new File(path);\r | |
107 | \r | |
108 | //\r | |
109 | //Init namespace\r | |
110 | //\r | |
111 | XmlCursor cursor = XmlConfig.setupXmlCursor(fpd.newCursor());\r | |
112 | \r | |
113 | //\r | |
114 | //Config file format\r | |
115 | //\r | |
116 | XmlOptions options = XmlConfig.setupXmlOptions();\r | |
117 | \r | |
118 | //\r | |
119 | //Create finial doc\r | |
120 | //\r | |
121 | fpdDoc.addNewPlatformSurfaceArea();\r | |
122 | fpdDoc.setPlatformSurfaceArea((PlatformSurfaceArea) cursor.getObject());\r | |
123 | //\r | |
124 | //Save the file\r | |
125 | //\r | |
126 | fpdDoc.save(f, options);\r | |
127 | }\r | |
128 | \r | |
129 | /**\r | |
130 | Save file as framework db\r | |
131 | \r | |
132 | **/\r | |
133 | public static void saveDbFile(String path, FrameworkDatabase db) throws Exception {\r | |
134 | FrameworkDatabaseDocument dbDoc = FrameworkDatabaseDocument.Factory.newInstance();\r | |
135 | File f = new File(path);\r | |
136 | \r | |
137 | //\r | |
138 | //Init namespace\r | |
139 | //\r | |
140 | XmlCursor cursor = XmlConfig.setupXmlCursor(db.newCursor());\r | |
141 | \r | |
142 | //\r | |
143 | //Config file format\r | |
144 | //\r | |
145 | XmlOptions options = XmlConfig.setupXmlOptions();\r | |
146 | \r | |
147 | //\r | |
148 | //Create finial doc\r | |
149 | //\r | |
150 | dbDoc.addNewFrameworkDatabase();\r | |
151 | dbDoc.setFrameworkDatabase((FrameworkDatabase) cursor.getObject());\r | |
152 | \r | |
153 | //\r | |
154 | //Save the file\r | |
155 | //\r | |
156 | dbDoc.save(f, options);\r | |
157 | }\r | |
158 | }\r |