]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/ModuleEditor/src/org/tianocore/packaging/workspace/common/Workspace.java
Initial import.
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / workspace / common / Workspace.java
CommitLineData
878ddf1f 1/** @file\r
2 \r
3 The file is used to init workspace and get basic information of workspace\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\r
16package org.tianocore.packaging.workspace.common;\r
17\r
18import java.io.File;\r
19\r
20import org.apache.xmlbeans.XmlException;\r
21import org.apache.xmlbeans.XmlObject;\r
22import org.tianocore.FrameworkDatabaseDocument;\r
23import org.tianocore.common.Log;\r
24\r
25/**\r
26 The file is used to init workspace and get basic information of workspace\r
27 \r
28 @since ModuleEditor 1.0\r
29\r
30 **/\r
31public class Workspace {\r
32\r
33 //\r
34 // Define class members\r
35 //\r
36 private String currentWorkspace = null;\r
37\r
38 private FrameworkDatabaseDocument xmlFrameworkDbDoc = null;\r
39\r
40 private String strWorkspaceDatabaseFile = System.getProperty("file.separator") + "Tools"\r
41 + System.getProperty("file.separator") + "Conf"\r
42 + System.getProperty("file.separator") + "FrameworkDatabase.db";\r
43\r
44 public static void main(String[] args) {\r
45\r
46 }\r
47\r
48 /**\r
49 This is the default constructor\r
50 Get current WORKSPACE from system environment variable\r
51 \r
52 **/\r
53 public Workspace() {\r
54 this.currentWorkspace = System.getenv("WORKSPACE");\r
55 }\r
56\r
57 /**\r
58 Check if current workspace exists of not\r
59 \r
60 @retval true - The current WORKSPACE exists\r
61 @retval false - The current WORKSPACE doesn't exist\r
62 \r
63 **/\r
64 public boolean checkCurrentWorkspace() {\r
65 return checkCurrentWorkspace(getCurrentWorkspace());\r
66 }\r
67\r
68 /**\r
69 Check if current workspace exists or not via input workspace path\r
70 \r
71 @param strWorkspace The input data of WORKSPACE path\r
72 @retval true - The current WORKSPACE exists\r
73 @retval false - The current WORKSPACE doesn't exist\r
74 \r
75 **/\r
76 public boolean checkCurrentWorkspace(String strWorkspace) {\r
77 if (strWorkspace == null || strWorkspace == "") {\r
78 return false;\r
79 }\r
80 File f = new File(strWorkspace);\r
81 if (!f.isDirectory()) {\r
82 return false;\r
83 }\r
84 if (!f.exists()) {\r
85 return false;\r
86 }\r
87 return true;\r
88 }\r
89\r
90 /**\r
91 Get Current Workspace\r
92 \r
93 @return currentWorkspace\r
94 \r
95 **/\r
96 public String getCurrentWorkspace() {\r
97 return currentWorkspace;\r
98 }\r
99\r
100 /**\r
101 Set Current Workspace\r
102 \r
103 @param currentWorkspace The input data of currentWorkspace\r
104 \r
105 **/\r
106 public void setCurrentWorkspace(String currentWorkspace) {\r
107 this.currentWorkspace = currentWorkspace;\r
108 }\r
109\r
110 /**\r
111 Open Framework Database file\r
112 \r
113 **/\r
114 private void openFrameworkDb() {\r
115 String strFrameworkDbFilePath = this.getCurrentWorkspace() + strWorkspaceDatabaseFile;\r
116 try {\r
117 xmlFrameworkDbDoc = (FrameworkDatabaseDocument) XmlObject.Factory.parse(strFrameworkDbFilePath);\r
118 } catch (XmlException e) {\r
119 Log.err("Open Framework Database " + strFrameworkDbFilePath, e.getMessage());\r
120 return;\r
121 } catch (Exception e) {\r
122 Log.err("Open Framework Database " + strFrameworkDbFilePath, "Invalid file type");\r
123 return;\r
124 }\r
125 }\r
126\r
127 /**\r
128 Get FrameworkDatabaseDocument\r
129 \r
130 @return FrameworkDatabaseDocument\r
131 \r
132 **/\r
133 public FrameworkDatabaseDocument getXmlFrameworkDbDoc() {\r
134 openFrameworkDb();\r
135 return xmlFrameworkDbDoc;\r
136 }\r
137\r
138 /**\r
139 Set FrameworkDatabaseDocument\r
140 \r
141 @param xmlFrameworkDbDoc The input data of FrameworkDatabaseDocument\r
142 \r
143 **/\r
144 public void setXmlFrameworkDbDoc(FrameworkDatabaseDocument xmlFrameworkDbDoc) {\r
145 this.xmlFrameworkDbDoc = xmlFrameworkDbDoc;\r
146 }\r
147}\r