/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

  1. /**
  2. Copyright (c) 1999 by Robert J Colquhoun, All Rights Reserved
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  14. MA 02111-1307, USA
  15. */
  16. package org.maverickdbms.database.localdb;
  17. import org.maverickdbms.basic.mvConstantString;
  18. import org.maverickdbms.basic.mvException;
  19. import org.maverickdbms.basic.List;
  20. import org.maverickdbms.basic.mvString;
  21. import java.io.*;
  22. public class ldbList implements List {
  23. private File fdir;
  24. private String[] selkeys;
  25. private int maxkeys;
  26. private int keyctr;
  27. private String iname;
  28. static final char[] ESCAPED_CHARS = {
  29. '/','?','"','%','*',':','<','|','>','\\'
  30. };
  31. static final String MANGLE_CHARS = new String(ESCAPED_CHARS);
  32. static final String REP_CHARS = "SQD%ACLVGB";
  33. ldbList() {
  34. fdir = null;
  35. selkeys = null;
  36. maxkeys = 0;
  37. keyctr = 0;
  38. }
  39. public void close() {
  40. selkeys = null;
  41. maxkeys = 0;
  42. keyctr = 0;
  43. }
  44. mvConstantString select(File pdir) {
  45. fdir = pdir;
  46. selkeys = fdir.list();
  47. maxkeys = selkeys.length;
  48. keyctr = 0;
  49. return RETURN_SUCCESS;
  50. }
  51. public boolean isAfterLast() {
  52. return (keyctr < maxkeys);
  53. }
  54. public mvConstantString READLIST(mvString result) throws mvException {
  55. throw new mvException(0, "Sorry READLIST is not yet implemented");
  56. }
  57. public mvConstantString READNEXT(mvString id, mvString val, mvString subval) {
  58. while (keyctr < maxkeys) {
  59. String temp = selkeys[keyctr++];
  60. demangle(temp);
  61. id.set(iname);
  62. return RETURN_SUCCESS;
  63. }
  64. return RETURN_ELSE;
  65. }
  66. public void demangle (String mname) {
  67. int len = mname.length();
  68. StringBuffer sb = new StringBuffer();
  69. for (int i = 1; i < len; i++) {
  70. char c = mname.charAt(i - 1);
  71. if (c == '%') {
  72. char c2 = mname.charAt(i);
  73. int tpos = REP_CHARS.indexOf(c2);
  74. if (tpos > -1) {
  75. sb.append(MANGLE_CHARS.charAt(tpos));
  76. i++;
  77. }
  78. } else {
  79. sb.append(c);
  80. }
  81. }
  82. sb.append(mname.charAt(len - 1));
  83. iname = sb.toString();
  84. }
  85. }