3 The file is used to init workspace and get basic information of workspace
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.
16 package org
.tianocore
.packaging
.workspace
.common
;
19 import java
.util
.Vector
;
21 import org
.apache
.xmlbeans
.XmlException
;
22 import org
.apache
.xmlbeans
.XmlObject
;
23 import org
.tianocore
.FrameworkDatabaseDocument
;
24 import org
.tianocore
.common
.Log
;
27 The file is used to init workspace and get basic information of workspace
29 @since ModuleEditor 1.0
32 public class Workspace
{
35 // Define class members
37 private String currentWorkspace
= null;
39 private FrameworkDatabaseDocument xmlFrameworkDbDoc
= null;
41 //private PackageDocument xmlPackage = null;
43 private String strWorkspaceDatabaseFile
= System
.getProperty("file.separator") + "Tools"
44 + System
.getProperty("file.separator") + "Conf"
45 + System
.getProperty("file.separator") + "FrameworkDatabase.db";
47 public static void main(String
[] args
) {
52 This is the default constructor
53 Get current WORKSPACE from system environment variable
57 this.currentWorkspace
= System
.getenv("WORKSPACE");
61 Check if current workspace exists of not
63 @retval true - The current WORKSPACE exists
64 @retval false - The current WORKSPACE doesn't exist
67 public boolean checkCurrentWorkspace() {
68 return checkCurrentWorkspace(getCurrentWorkspace());
72 Check if current workspace exists or not via input workspace path
74 @param strWorkspace The input data of WORKSPACE path
75 @retval true - The current WORKSPACE exists
76 @retval false - The current WORKSPACE doesn't exist
79 public boolean checkCurrentWorkspace(String strWorkspace
) {
80 if (strWorkspace
== null || strWorkspace
== "") {
83 File f
= new File(strWorkspace
);
84 if (!f
.isDirectory()) {
96 @return currentWorkspace
99 public String
getCurrentWorkspace() {
100 return currentWorkspace
;
104 Set Current Workspace
106 @param currentWorkspace The input data of currentWorkspace
109 public void setCurrentWorkspace(String currentWorkspace
) {
110 this.currentWorkspace
= currentWorkspace
;
114 Open Framework Database file
117 private void openFrameworkDb() {
118 String strFrameworkDbFilePath
= this.getCurrentWorkspace() + strWorkspaceDatabaseFile
;
119 File db
= new File(strFrameworkDbFilePath
);
121 xmlFrameworkDbDoc
= (FrameworkDatabaseDocument
) XmlObject
.Factory
.parse(db
);
122 } catch (XmlException e
) {
123 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, e
.getMessage());
125 } catch (Exception e
) {
126 Log
.err("Open Framework Database " + strFrameworkDbFilePath
, "Invalid file type");
132 Get FrameworkDatabaseDocument
134 @return FrameworkDatabaseDocument
137 public FrameworkDatabaseDocument
getXmlFrameworkDbDoc() {
139 return xmlFrameworkDbDoc
;
143 Set FrameworkDatabaseDocument
145 @param xmlFrameworkDbDoc The input data of FrameworkDatabaseDocument
148 public void setXmlFrameworkDbDoc(FrameworkDatabaseDocument xmlFrameworkDbDoc
) {
149 this.xmlFrameworkDbDoc
= xmlFrameworkDbDoc
;
153 Get all package name form the FrameworkDatabase.db file
155 @return vPackageName A vector includes all package names
158 public Vector
getAllPackageName() {
159 Vector
<String
> vPackageName
= new Vector
<String
>();
162 for (int index
= 0; index
< xmlFrameworkDbDoc
.getFrameworkDatabase().getPackageList().sizeOfPackageArray(); index
++) {
163 vPackageName
.addElement(xmlFrameworkDbDoc
.getFrameworkDatabase().getPackageList().getPackageArray(index
)
164 .getPackageNameArray(0).getStringValue());