KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ConfigFileParser


1 ///*
2
// * @(#) ConfigFileParser.java 1.0 02/08/01
3
// */
4
//
5
//package org.smartlib.pool.core;
6
//
7
//import java.io.*;
8
//import java.util.*;
9
//
10
//import org.xml.sax.*;
11
//import org.xml.sax.helpers.DefaultHandler;
12
//
13
//import javax.xml.parsers.SAXParserFactory;
14
//import javax.xml.parsers.SAXParser;
15
//
16
///**
17
// * This Class parses the configuration file. The configuration file should be
18
// * as per the pool-config.dtd.
19
// *
20
// * @author Sachin Shekar Shetty
21
// * @version 1.0, 02/08/01
22
// * @deprecated No longer user, we use DOM parsers in ConfigFileParser
23
// *
24
// */
25
//
26
//// I am not very good at XML, if this is the way an XML file is
27
//// parsed than i think i guessed it right as usual, if not then as usual
28
//// I always defy conventional stuff.
29
//
30
//public class ConfigFileParser extends DefaultHandler {
31
//
32
// private ArrayList ar = new ArrayList();
33
// private static final String className = "ConfigFileParser";
34
// private HashMap hs = new HashMap();
35
// private boolean defaultPool = false;
36
// private static Debugger debug = null;
37
// private String lastElement = null;
38
// private Stack stack = new Stack();
39
// private String contents = null;
40
//
41
// /**
42
// * This method returns a collection of PoolConfig objects.
43
// *
44
// * @param fileName Absolute file path.
45
// *
46
// * @return Collection of PoolConfig objects
47
// */
48
// Collection getPoolConfig(String fileName)
49
// throws ConnectionPoolException {
50
//
51
// if (fileName == null || fileName.equals(""))
52
// throw new IllegalArgumentException("File Name cannot be null/empty");
53
// return getPoolConfig(new File(fileName));
54
//
55
// }
56
//
57
// /**
58
// * This method returns a collection of PoolConfig objects.
59
// *
60
// * @param file file object representing the file to be parsed.
61
// *
62
// * @return Collection of PoolConfig objects
63
// */
64
// Collection getPoolConfig(File file)
65
// throws ConnectionPoolException {
66
//
67
// SAXParserFactory factory = SAXParserFactory.newInstance();
68
// try {
69
// // Parse the input file
70
// SAXParser saxParser = factory.newSAXParser();
71
// saxParser.parse(file ,this);
72
// return ar;
73
// }
74
// catch (Exception t) {
75
// throw new ConnectionPoolException("Could not parse file:"+file,t);
76
// }
77
//
78
// }
79
//
80
// /**
81
// *Sax callback method for parsing
82
// */
83
// public void startElement(String namespaceURI,
84
// String lName, // local name
85
// String qName, // qualified name
86
// Attributes attrs) throws SAXException {
87
//
88
//
89
// stack.push(qName);
90
//
91
// if (!qName.equals("data-source")) return;
92
//
93
// // Checking for distint poolName
94
// String poolName = attrs.getValue("pool-name");
95
// if (hs.get(poolName) != null )
96
// throw new SAXException("Duplicate connection pool name:" +poolName);
97
// hs.put(poolName , "");
98
//
99
//
100
// // Checking for more than one default pools
101
// String temp =attrs.getValue("default-pool");
102
// boolean newDefaultPool = false;
103
// if (temp != null)
104
// newDefaultPool= temp.equals("true")?true:false;
105
// else
106
// newDefaultPool = false;
107
// if ( defaultPool && newDefaultPool)
108
// throw new SAXException("More than one pools with default-pool setting");
109
// if (newDefaultPool)
110
// defaultPool = newDefaultPool;
111
//
112
// // Checking for detect-leaks
113
// temp = attrs.getValue("detect-leaks");
114
// boolean detectLeaks = false;
115
// if (temp != null )
116
// detectLeaks = temp.equals("true")?true:false;
117
// else
118
// detectLeaks = false;
119
//
120
// // Checking for leak-time-out
121
// temp = attrs.getValue("leak-time-out");
122
// long leakTimeOut = 0;
123
// if (temp != null )
124
// leakTimeOut = Long.parseLong(temp) * 1000;
125
// else
126
// leakTimeOut = 300 * 1000 ; // leakTimeOut
127
//
128
// // Checking for poll-thread-time
129
// temp = attrs.getValue("poll-thread-time");
130
// long pollThreadTime = 0;
131
// if (temp != null )
132
// pollThreadTime = Long.parseLong(temp) * 1000;
133
// else
134
// pollThreadTime = 300 * 1000 ; // leakTimeOut
135
//
136
// // Checking for auto-close
137
// temp =attrs.getValue("auto-close");
138
// boolean autoClose = false;
139
// if (temp != null)
140
// autoClose = temp.equals("true")?true:false;
141
// else
142
// autoClose = false;
143
//
144
// // Getting default listener
145
// String defaultListener =attrs.getValue("default-listener");
146
//
147
// // Getting max-free-connections-for-release
148
// int maxConnectionsForRelease = -1;
149
// temp =attrs.getValue("max-free-connections-for-release");
150
// if (temp != null) {
151
// try {
152
// maxConnectionsForRelease = Integer.parseInt(temp);
153
// }
154
// catch (NumberFormatException ne) {
155
// throw new SAXException(
156
// "max-free-connections-for-release is non numeric" , ne);
157
// }
158
// }
159
//
160
// // Getting allow-annonymous connections
161
// temp =attrs.getValue("allow-anonymous-connections");
162
// boolean allowAnonymousConnections = false;
163
// if (temp != null)
164
// allowAnonymousConnections = temp.equals("true")?true:false;
165
// else
166
// allowAnonymousConnections = false;
167
//
168
// // Getting the connection loader class
169
// String connectionLoaderClass = null;
170
// temp =attrs.getValue("connection-loader-class");
171
// if (temp != null) {
172
// connectionLoaderClass = temp;
173
// }
174
//
175
// // Getting the connection-wait-time-out
176
// long connectionWaitTimeOut = 60*1000;
177
// temp =attrs.getValue("connection-wait-time-out");
178
// if (temp != null) {
179
// connectionWaitTimeOut = Long.parseLong(temp) * 1000;
180
// }
181
//
182
// // Getting the Validator Query
183
// String validatorQuery = "";
184
// temp =attrs.getValue("validator-query");
185
// if (temp != null) {
186
// validatorQuery = temp;
187
// }
188
//
189
// // Getting the max-connection-idle-time
190
// long maxConnectionIdleTime = -1;
191
// temp =attrs.getValue("max-connection-idle-time");
192
// if (temp != null) {
193
// maxConnectionIdleTime = Long.parseLong(temp) * 1000;
194
// }
195
//
196
// PoolConfig config = new PoolConfig (
197
// attrs.getValue("pool-name"),
198
// Integer.parseInt(attrs.getValue("max-connections")),
199
// Integer.parseInt(attrs.getValue("min-connections")),
200
// attrs.getValue("username"),
201
// attrs.getValue("password"),
202
// attrs.getValue("connect-string"),
203
// Integer.parseInt(attrs.getValue("increment-by")),
204
// attrs.getValue("connection-driver")
205
// );
206
// config.setValidatorQuery(validatorQuery);
207
// config.setDefaultPool(newDefaultPool);
208
// config.setDetectLeaks(detectLeaks);
209
// config.setLeakTimeOut(leakTimeOut);
210
// config.setDefaultListener(attrs.getValue("default-listener"));
211
// config.setPollThreadTime(pollThreadTime);
212
// config.setAutoClose(autoClose);
213
// if (defaultListener != null)
214
// config.setDefaultListener(defaultListener);
215
// config.setMaxConnectionsForRelease(maxConnectionsForRelease);
216
// config.setAllowAnonymousConnections(allowAnonymousConnections);
217
// config.setConnectionLoaderClass(connectionLoaderClass);
218
// config.setConnectionWaitTimeOut(connectionWaitTimeOut);
219
// config.setMaxConnectionIdleTime(maxConnectionIdleTime);
220
// ar.add(config);
221
//
222
// }
223
//
224
// /**
225
// *Sax Callback method for parsing
226
// */
227
// public void endElement(String namespaceURI,
228
// String sName, // simple name
229
// String qName // qualified name
230
// ) throws SAXException {
231
//
232
// if (qName.equals("log-file")) {
233
// String fileName = (String)stack.pop();
234
// debug = new Debugger(contents, className );
235
// }
236
//
237
// }
238
//
239
// // Main method, once upon a time this used to be the only method in
240
// // my java programs. That is how you do procedural programming in java.
241
// public static void main (String args[]) throws ConnectionPoolException {
242
//
243
// Collection s = new ConfigFileParser().
244
// getPoolConfig("/home/sssachin/org.smartlib.pool.test.xml");
245
// Iterator it = s.iterator();
246
// while (it.hasNext()){
247
//
248
// }
249
//
250
// }
251
//
252
// // Sax Method
253
// public void characters(char[] ch, int start, int length)
254
// throws SAXException {
255
//
256
// contents = new String(ch, start, length);
257
//
258
// }
259
//
260
//
261
//}
262
Popular Tags