2
* @(#)BtreeDictParameters.java 1.15 06/10/30
4
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
* This code is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License version 2 only, as
9
* published by the Free Software Foundation. Sun designates this
10
* particular file as subject to the "Classpath" exception as provided
11
* by Sun in the LICENSE file that accompanied this code.
13
* This code is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
* version 2 for more details (a copy is included in the LICENSE file that
17
* accompanied this code).
19
* You should have received a copy of the GNU General Public License version
20
* 2 along with this work; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24
* CA 95054 USA or visit www.sun.com if you need additional information or
29
* @(#) BtreeDictParameters.java 1.5 - last change made 04/01/98
32
package com.sun.java.help.search;
35
import java.net.URLConnection;
36
import java.util.StringTokenizer;
41
* @version 1.5 04/01/98
42
* @author Jacek R. Ambroziak
43
* @author Roger D. Brinkley
44
* @author Eduardo Pelegri-Llopart
47
class BtreeDictParameters extends BlockManagerParameters
50
private String dirName;
52
// some form of this is needed for starting new DBs
53
public BtreeDictParameters(URL fileName, int blockSize, int root,
56
super(fileName, blockSize, root);
60
public BtreeDictParameters(Schema schema, String partName)
63
super(schema, partName);
66
public boolean readState()
68
if (super.readState())
70
setFreeID(integerParameter("id1"));
77
public void writeState() {
80
public int getFreeID() {
84
public final void setFreeID(int id) {
88
private void setDirName(String dirName) {
89
this.dirName = dirName;
92
public static BtreeDictParameters create(URL dirName)
95
URL url = new URL(dirName, "TMAP");
96
BtreeDictParameters bdp = null;
97
// new BtreeDictParameters(url, 2048, 0, 1);
98
bdp.setDirName(dirName.getFile());
100
} catch (java.net.MalformedURLException e) {
101
System.out.println ("Couldn't create " + dirName + File.separator + "TMAP");
106
public static BtreeDictParameters read(String dir, URL hsBase)
109
URL baseURL=null, url, tmapURL=null;
110
URLConnection connect;
115
int rootPosition = -1;
118
if (hsBase == null) {
119
file = new File(dir);
121
// On Win32 we need to convert all "\" to "/"
122
if (File.separatorChar != '/') {
123
dir = dir.replace(File.separatorChar, '/');
125
// Make sure the last character is a file separator
126
if (dir.lastIndexOf(File.separatorChar)
127
!= dir.length() - 1) {
128
dir = dir.concat(File.separator);
130
debug ("file:" + dir);
131
// Use a file protocol
132
baseURL = new URL("file", "", dir);
134
// Assume that some protocol was specified and try it
135
baseURL = new URL(dir);
139
// Read the SCHEMA data
140
if (hsBase != null) {
141
url = new URL(hsBase, dir + "/SCHEMA");
143
url = new URL(baseURL, "SCHEMA");
145
connect = url.openConnection();
147
in = new BufferedReader
148
(new InputStreamReader(connect.getInputStream()));
150
// This needs to be replaced with our XML Parser
153
line = in.readLine();
155
while (!line.startsWith("TMAP"));
157
StringTokenizer tokens = new StringTokenizer(line, " =");
158
tokens.nextToken(); // skip over 'TMAP'
159
while (tokens.hasMoreTokens())
161
String token = tokens.nextToken();
162
if (token.equals("bs"))
163
blockSize = Integer.parseInt(tokens.nextToken());
164
else if (token.equals("rt"))
165
rootPosition = Integer.parseInt(tokens.nextToken());
166
else if (token.equals("id1"))
167
freeID = Integer.parseInt(tokens.nextToken());
170
if (hsBase != null) {
171
tmapURL = new URL(hsBase, dir + "/TMAP");
173
tmapURL = new URL(baseURL, "TMAP");
175
BtreeDictParameters bdp = null;
176
// new BtreeDictParameters(tmapURL, blockSize, rootPosition, freeID);
178
if (hsBase == null) {
179
bdp.setDirName(Utilities.URLDecoder(baseURL.getFile()));
184
public void updateSchema() {
185
super.updateSchema("id1="+id1+" id2=1");
188
public void write() throws java.io.IOException
190
FileWriter out = new FileWriter(dirName + "/SCHEMA");
191
out.write("JavaSearch 1.0\n");
192
out.write("TMAP bs=2048 rt="+root+" fl=-1 id1="+id1+" id2=1\n");
197
* For printf debugging.
199
private static boolean debugFlag = false;
200
private static void debug(String str) {
202
System.out.println("BtreeDictParamters: " + str);