KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > server > framework > AceConfigTableRecord


1 package com.quikj.server.framework;
2
3 import java.io.*;
4 import java.util.*;
5
6 public class AceConfigTableRecord
7 {
8     public AceConfigTableRecord (String JavaDoc line) throws IOException
9     {
10     String JavaDoc cline = line.trim();
11     if (cline.length() == 0)
12         {
13         return;
14         }
15     
16     strTokenizer = new StreamTokenizer (new StringReader(cline));
17     strTokenizer.commentChar (AceConfigTableFileParser.COMMENT_CHAR.charAt(0));
18     strTokenizer.quoteChar (AceConfigTableFileParser.QUOTE_CHAR);
19     
20     int next;
21     do
22         {
23         next = strTokenizer.nextToken();
24         if (next != StreamTokenizer.TT_EOF)
25             {
26             if (next == StreamTokenizer.TT_WORD)
27                 {
28                 tokenList.addElement (strTokenizer.sval);
29                 numTokens++;
30                 }
31             else if (next == AceConfigTableFileParser.QUOTE_CHAR)
32                 {
33                 tokenList.addElement (strTokenizer.sval);
34                 numTokens++;
35                 }
36             else if (next == StreamTokenizer.TT_NUMBER)
37                 {
38                 // There appears to be a bug in Jdk where it
39
// does not store numeric values in sval, so here
40
// is a kludge to match that of jdk
41
int ival = (int)strTokenizer.nval * 10;
42                 int sval = (int)(strTokenizer.nval * 10.0);
43                 
44                 if (ival == sval)
45                     {
46                     tokenList.addElement (Integer.toString((int)strTokenizer.nval));
47                     }
48                 else
49                     {
50                     tokenList.addElement (Double.toString(strTokenizer.nval));
51                     }
52                 numTokens++;
53                 }
54             }
55         }
56     while (next != StreamTokenizer.TT_EOF);
57     }
58
59     public int numberOfTokens()
60     {
61     return numTokens;
62     }
63
64     public String JavaDoc getString( int index)
65     {
66     return (String JavaDoc)tokenList.elementAt (index);
67     }
68
69     public int getInt (int index) throws NumberFormatException JavaDoc
70     {
71     return Integer.parseInt((String JavaDoc)tokenList.elementAt (index));
72     }
73
74     public double getDouble (int index) throws NumberFormatException JavaDoc
75     {
76     return Double.valueOf ((String JavaDoc)tokenList.elementAt (index)).doubleValue();
77     }
78
79     public boolean getBoolean (int index) throws IllegalArgumentException JavaDoc
80     {
81     String JavaDoc value = (String JavaDoc)tokenList.elementAt (index);
82     if (value.equals ("true") == true)
83         {
84         return true;
85         }
86     else
87         {
88         if (value.equals ("false") == true)
89             {
90             return false;
91             }
92         else
93             {
94             throw new IllegalArgumentException JavaDoc (value);
95             }
96         }
97     }
98
99     public boolean getYesNo (int index) throws IllegalArgumentException JavaDoc
100     {
101     String JavaDoc value = (String JavaDoc)tokenList.elementAt (index);
102     if (value.equals ("yes") == true)
103         {
104         return true;
105         }
106     else
107         {
108         if (value.equals ("no") == true)
109             {
110             return false;
111             }
112         else
113             {
114             throw new IllegalArgumentException JavaDoc (value);
115             }
116         }
117     }
118
119     private Vector tokenList = new Vector();
120     private StreamTokenizer strTokenizer;
121     private int numTokens = 0;
122 }
123
124
125
126
Popular Tags