KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > jdbc > typing > DBMSInfoLoader


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  * Copyright (C) 2003 XQuark Group.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
19  * You can also get it at http://www.gnu.org/licenses/lgpl.html
20  *
21  * For more information on this software, see http://www.xquark.org.
22  */

23
24 package org.xquark.jdbc.typing;
25
26 import org.xquark.util.AttributeTracker;
27 import org.xquark.util.SaxMapper;
28 import org.xquark.util.TagTracker;
29
30 /**
31  *
32  */

33 public class DBMSInfoLoader extends SaxMapper
34 {
35     private static final String JavaDoc RCSRevision = "$Revision: 1.3 $";
36     private static final String JavaDoc RCSName = "$Name: $";
37
38     
39     private DBMSInfo dbmsInfo;
40     private TypeMap.SQLType wType;
41     private SQLStatementCustomizer wStmtCustomizer;
42     private String JavaDoc wClause;
43     private boolean wIsPrincipal = false;
44     private String JavaDoc wCreateParams = null;
45     private boolean wUseGetString = false;
46     private boolean defaultUseGetString;
47     /**
48      * @see org.xquark.xml.util.SaxMapper#createTagTrackerNetwork()
49      */

50     public TagTracker createTagTrackerNetwork()
51     {
52         // create root
53
TagTracker root = new TagTracker() {
54             public void onDeactivate()
55             {
56                 dbmsInfo = new DBMSInfo();
57                 dbmsInfo.setTypeMap(new TypeMap());
58             }
59         };
60         
61         // create action for /dbmsInfo/limits/systemCollectionsDataLength
62
root.track
63             (
64             "/dbmsInfo/limits/systemCollectionsDataLength",
65             new TagTracker() {
66                 public void onEnd(
67                         String JavaDoc namespaceURI,
68                         String JavaDoc localName,
69                         Object JavaDoc actualValue)
70                 {
71                     dbmsInfo.setSystemCollectionsDataLength(((Number JavaDoc)actualValue).intValue());
72                 }
73             }
74             );
75         
76         // create action for /dbmsInfo/limits/userCollectionMaxDataLength
77
root.track
78             (
79             "/dbmsInfo/limits/userCollectionMaxDataLength",
80             new TagTracker() {
81                 public void onEnd(
82                         String JavaDoc namespaceURI,
83                         String JavaDoc localName,
84                         Object JavaDoc actualValue)
85                 {
86                     dbmsInfo.setMaxUserCollectionsDataLength(((Number JavaDoc)actualValue).intValue());
87                 }
88             }
89             );
90         
91         // create action for /dbmsInfo/SQLTokens/lockHint
92
TagTracker lockHint = new TagTracker() {
93             public void onEnd(
94                     String JavaDoc namespaceURI,
95                     String JavaDoc localName,
96                     Object JavaDoc actualValue)
97             {
98                 dbmsInfo.setSelectLockStatement(new SQLStatementCustomizer((String JavaDoc)actualValue));
99             }
100         };
101         root.track("/dbmsInfo/SQLTokens/selectLockStatement", lockHint);
102         
103         // create action for /dbmsInfo/SQLTokens/temporaryTableSpecification
104
TagTracker tmpTableHint = new TagTracker() {
105             public void onEnd(
106                     String JavaDoc namespaceURI,
107                     String JavaDoc localName,
108                     Object JavaDoc actualValue)
109             {
110                 dbmsInfo.setTemporaryTableStatement(new SQLStatementCustomizer((String JavaDoc)actualValue));
111             }
112         };
113         root.track("/dbmsInfo/SQLTokens/temporaryTableSpecification", tmpTableHint);
114
115         // create action for /dbmsInfo/SQLTokens/indexOrganizationSpecification
116
TagTracker indexOrgHint = new TagTracker() {
117             public void onEnd(
118                     String JavaDoc namespaceURI,
119                     String JavaDoc localName,
120                     Object JavaDoc actualValue)
121             {
122                 dbmsInfo.setIndexOrganizedStatement(new SQLStatementCustomizer((String JavaDoc)actualValue));
123             }
124         };
125         root.track("/dbmsInfo/SQLTokens/indexOrganizationSpecification", indexOrgHint);
126
127         // create action for /dbmsInfo/SQLTokens/rowID
128
root.track
129             (
130             "/dbmsInfo/SQLTokens/rowID",
131             new TagTracker() {
132                 public void onEnd(
133                         String JavaDoc namespaceURI,
134                         String JavaDoc localName,
135                         Object JavaDoc actualValue)
136                 {
137                     dbmsInfo.setRowId((String JavaDoc)actualValue);
138                 }
139             }
140             );
141         
142         // create action for /dbmsInfo/SQLTokens/useDoubleQuotesToPreserveDDLNamesCase
143
root.track
144             (
145             "/dbmsInfo/SQLTokens/useDoubleQuotesToPreserveDDLNamesCase",
146             new TagTracker() {
147                 public void onEnd(
148                         String JavaDoc namespaceURI,
149                         String JavaDoc localName,
150                         Object JavaDoc actualValue)
151                 {
152                     dbmsInfo.setUseDoubleQuotes4DDLNames(((Boolean JavaDoc)actualValue).booleanValue());
153                 }
154             }
155             );
156         
157         // create action for /dbmsInfo/typeMapping/@defaultUseGetString
158
root.trackAttribute(
159             "/dbmsInfo/typeMapping/@defaultUseGetString",
160             new AttributeTracker() {
161                 public void onAttributeEncountered
162                     (
163                     String JavaDoc namespaceURI,
164                     String JavaDoc localName,
165                     Object JavaDoc actualValue,
166                     boolean isDefault
167                     )
168                 {
169                     defaultUseGetString =((Boolean JavaDoc)actualValue).booleanValue();
170                 }
171             }
172             );
173         
174         // create action for /dbmsInfo/typeMapping/type
175
TagTracker type = new TagTracker() {
176             public void onStart(
177                         String JavaDoc namespaceURI,
178                         String JavaDoc localName)
179             {
180                 wType = dbmsInfo.getTypeMap().createType();
181             }
182             public void onEnd(
183                     String JavaDoc namespaceURI,
184                     String JavaDoc localName,
185                     Object JavaDoc actualValue)
186             {
187                 dbmsInfo.getTypeMap().addType(wType);
188             }
189         };
190         root.track("/dbmsInfo/typeMapping/type", type);
191         
192         // create action for /dbmsInfo/typeMapping/type/@name
193
type.trackAttribute(
194             "@name",
195             new AttributeTracker() {
196                 public void onAttributeEncountered
197                     (
198                     String JavaDoc namespaceURI,
199                     String JavaDoc localName,
200                     Object JavaDoc actualValue,
201                     boolean isDefault
202                     )
203                 {
204                     wType.setNativeTypeName((String JavaDoc)actualValue);
205                 }
206             }
207             );
208         
209         // create action for /dbmsInfo/typeMapping/type/@autoFill
210
type.trackAttribute(
211             "@autoFill",
212             new AttributeTracker() {
213                 public void onAttributeEncountered
214                     (
215                     String JavaDoc namespaceURI,
216                     String JavaDoc localName,
217                     Object JavaDoc actualValue,
218                     boolean isDefault
219                     )
220                 {
221                     wType.setAutoFill(((Boolean JavaDoc)actualValue).booleanValue());
222                 }
223             }
224             );
225         
226         // create action for /dbmsInfo/typeMapping/type/jdbcType
227
TagTracker jdbcType = new TagTracker() {
228             public void onEnd(
229                     String JavaDoc namespaceURI,
230                     String JavaDoc localName,
231                     Object JavaDoc actualValue)
232             {
233                 wType.addJDBCType((String JavaDoc)actualValue, wCreateParams, wIsPrincipal, wUseGetString);
234                 wIsPrincipal = false;
235                 wCreateParams = null;
236                 wUseGetString = defaultUseGetString;
237             }
238         };
239         type.track("jdbcType", jdbcType);
240         
241         // create action for /dbmsInfo/typeMapping/type/jdbcType/@principal
242
jdbcType.trackAttribute(
243             "@principal",
244             new AttributeTracker() {
245                 public void onAttributeEncountered
246                     (
247                     String JavaDoc namespaceURI,
248                     String JavaDoc localName,
249                     Object JavaDoc actualValue,
250                     boolean isDefault
251                     )
252                 {
253                     wIsPrincipal = ((Boolean JavaDoc)actualValue).booleanValue();
254                 }
255             }
256             );
257         
258         // create action for /dbmsInfo/typeMapping/type/jdbcType/@createParams
259
jdbcType.trackAttribute(
260             "@createParams",
261             new AttributeTracker() {
262                 public void onAttributeEncountered
263                     (
264                     String JavaDoc namespaceURI,
265                     String JavaDoc localName,
266                     Object JavaDoc actualValue,
267                     boolean isDefault
268                     )
269                 {
270                     wCreateParams = (String JavaDoc)actualValue;
271                 }
272             }
273             );
274         
275         // create action for /dbmsInfo/typeMapping/type/jdbcType/@useGetString
276
jdbcType.trackAttribute(
277             "@useGetString",
278             new AttributeTracker() {
279                 public void onAttributeEncountered
280                     (
281                     String JavaDoc namespaceURI,
282                     String JavaDoc localName,
283                     Object JavaDoc actualValue,
284                     boolean isDefault
285                     )
286                 {
287                     if (isDefault) // attribute was not specified
288
wUseGetString = defaultUseGetString;
289                     else
290                         wUseGetString = ((Boolean JavaDoc)actualValue).booleanValue();
291                 }
292             }
293             );
294         
295         // create action for /dbmsInfo/typeMapping/type/size
296
type.track(
297             "size",
298             new TagTracker() {
299                 public void onEnd(
300                         String JavaDoc namespaceURI,
301                         String JavaDoc localName,
302                         Object JavaDoc actualValue)
303                 {
304                     wType.setPrecision(((Number JavaDoc)actualValue).longValue());
305                 }
306             }
307             );
308         
309         // create action for /dbmsInfo/typeMapping/type/precision
310
type.track(
311             "precision",
312             new TagTracker() {
313                 public void onEnd(
314                         String JavaDoc namespaceURI,
315                         String JavaDoc localName,
316                         Object JavaDoc actualValue)
317                 {
318                     wType.setPrecision(((Number JavaDoc)actualValue).longValue());
319                 }
320             }
321             );
322         
323         // create action for /dbmsInfo/typeMapping/type/unsigned
324
type.track(
325             "unsigned",
326             new TagTracker() {
327                 public void onEnd(
328                         String JavaDoc namespaceURI,
329                         String JavaDoc localName,
330                         Object JavaDoc actualValue)
331                 {
332                     wType.setUnsigned(((Boolean JavaDoc)actualValue).booleanValue());
333                 }
334             }
335             );
336         
337         // create action for /dbmsInfo/typeMapping/type/indexable
338
type.track(
339             "indexable",
340             new TagTracker() {
341                 public void onEnd(
342                         String JavaDoc namespaceURI,
343                         String JavaDoc localName,
344                         Object JavaDoc actualValue)
345                 {
346                     wType.setIndexable(((Boolean JavaDoc)actualValue).booleanValue());
347                 }
348             }
349             );
350         
351         // create action for /dbmsInfo/typeMapping/type/storage
352
type.track(
353             "storage",
354             new TagTracker() {
355                 public void onEnd(
356                         String JavaDoc namespaceURI,
357                         String JavaDoc localName,
358                         Object JavaDoc actualValue)
359                 {
360                     wType.setStorage(((Boolean JavaDoc)actualValue).booleanValue());
361                 }
362             }
363             );
364         
365         // create action for /dbmsInfo/typeMapping/type/extraction
366
type.track(
367             "extraction",
368             new TagTracker() {
369                 public void onEnd(
370                         String JavaDoc namespaceURI,
371                         String JavaDoc localName,
372                         Object JavaDoc actualValue)
373                 {
374                     wType.setExtraction(((Boolean JavaDoc)actualValue).booleanValue());
375                 }
376             }
377             );
378         
379         return root;
380     }
381
382     /**
383      * @see org.xquark.xml.util.SaxMapper#getMappedObject()
384      */

385     public Object JavaDoc getMappedObject()
386     {
387         return dbmsInfo;
388     }
389 }
390
Popular Tags