/maverick/tags/Sep20_2004/database/localdb/org/maverickdbms/database/localdb/ldbList.java
# · Java · 105 lines · 80 code · 4 blank · 21 comment · 0 complexity · eccfdfd03e8a659cff28f17eefa35467 MD5 · raw file
- /**
- Copyright (c) 1999 by Robert J Colquhoun, All Rights Reserved
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public
- License as published by the Free Software Foundation; either
- version 2 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA
-
- */
- package org.maverickdbms.database.localdb;
- import org.maverickdbms.basic.mvConstantString;
- import org.maverickdbms.basic.mvException;
- import org.maverickdbms.basic.List;
- import org.maverickdbms.basic.mvString;
- import java.io.*;
- public class ldbList implements List {
- private File fdir;
- private String[] selkeys;
- private int maxkeys;
- private int keyctr;
- private String iname;
- static final char[] ESCAPED_CHARS = {
- '/','?','"','%','*',':','<','|','>','\\'
- };
- static final String MANGLE_CHARS = new String(ESCAPED_CHARS);
- static final String REP_CHARS = "SQD%ACLVGB";
-
- ldbList() {
- fdir = null;
- selkeys = null;
- maxkeys = 0;
- keyctr = 0;
- }
- public void close() {
- selkeys = null;
- maxkeys = 0;
- keyctr = 0;
- }
- mvConstantString select(File pdir) {
-
- fdir = pdir;
- selkeys = fdir.list();
- maxkeys = selkeys.length;
- keyctr = 0;
- return RETURN_SUCCESS;
- }
- public boolean isAfterLast() {
- return (keyctr < maxkeys);
- }
- public mvConstantString READLIST(mvString result) throws mvException {
- throw new mvException(0, "Sorry READLIST is not yet implemented");
- }
-
- public mvConstantString READNEXT(mvString id, mvString val, mvString subval) {
- while (keyctr < maxkeys) {
- String temp = selkeys[keyctr++];
- demangle(temp);
- id.set(iname);
- return RETURN_SUCCESS;
- }
- return RETURN_ELSE;
- }
- public void demangle (String mname) {
- int len = mname.length();
- StringBuffer sb = new StringBuffer();
- for (int i = 1; i < len; i++) {
- char c = mname.charAt(i - 1);
- if (c == '%') {
- char c2 = mname.charAt(i);
- int tpos = REP_CHARS.indexOf(c2);
- if (tpos > -1) {
- sb.append(MANGLE_CHARS.charAt(tpos));
- i++;
- }
- } else {
- sb.append(c);
- }
- }
- sb.append(mname.charAt(len - 1));
- iname = sb.toString();
- }
- }