View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2009 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // DatabaseFolder.java
20  // Since: Nov 19, 2009
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.bean;
26  
27  import com.google.gwt.user.client.rpc.IsSerializable;
28  
29  public class DatabaseEntry implements IsSerializable {
30  
31  	public String path = "";
32  	public boolean isFile = false;
33  
34  	public DatabaseEntry() {
35  	}
36  
37  	private DatabaseEntry(String dbFolder, boolean isFile) {
38  		this.path = dbFolder;
39  		this.isFile = isFile;
40  	}
41  
42  	public static DatabaseEntry newFolder(String dbFolder) {
43  		return new DatabaseEntry(dbFolder == null ? "" : dbFolder, false);
44  	}
45  
46  	public static DatabaseEntry newFile(String dbFile) {
47  		return new DatabaseEntry(dbFile == null ? "" : dbFile, true);
48  	}
49  
50  	public String leaf() {
51  		int pos = path.lastIndexOf("/");
52  		if (pos == -1)
53  			return path;
54  		else
55  			return path.substring(pos + 1);
56  	}
57  
58  	public DatabaseEntry parent() {
59  		int pos = path.lastIndexOf("/");
60  
61  		if (pos == -1)
62  			return null;
63  
64  		return newFolder(path.substring(0, pos));
65  	}
66  
67  	public static String parent(String databaseFolder) {
68  		DatabaseEntry p = newFolder(databaseFolder).parent();
69  		if (p == null)
70  			return null;
71  		else
72  			return p.path;
73  	}
74  
75  	public static String leaf(String databaseFolder) {
76  		return newFolder(databaseFolder).leaf();
77  	}
78  
79  	/**
80  	 * Path to the specified database file in this database folder
81  	 * 
82  	 * @param dbName
83  	 * @return
84  	 */
85  	public String dbPath(String dbName) {
86  		return path + "/" + dbName;
87  	}
88  
89  	public boolean isFile() {
90  		return isFile;
91  	}
92  
93  	public boolean isFolder() {
94  		return !isFile;
95  	}
96  
97  }