KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > LoaderJobAttrReader


1 /**
2   LoaderJobAttrReader - Class used for reading attributes from tag.
3     Copyright (C) 2002-2003 Together
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License as published by the Free Software Foundation; either
7     version 2.1 of the License, or (at your option) any later version.
8     This library is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11     Lesser General Public License for more details.
12     You should have received a copy of the GNU Lesser General Public
13     License along with this library; if not, write to the Free Software
14     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  LoaderJobAttrReader.java
16  Date: 20.5.2003.
17  @version 1.0.0
18  @author: Zoran Milakovic zoran@prozone.co.yu
19  */

20
21 package org.webdocwf.util.loader;
22
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25
26 import javax.xml.parsers.DocumentBuilder JavaDoc;
27 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
28
29 import org.w3c.dom.Document JavaDoc;
30 import org.w3c.dom.NamedNodeMap JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32 import org.w3c.dom.NodeList JavaDoc;
33 import org.webdocwf.util.loader.logging.Logger;
34
35 /**
36  * Class used for reading attribute values from tags in XML file.
37  *
38  * @author Zoran Milakovic
39  * @version 1.1
40  */

41 public class LoaderJobAttrReader {
42
43     //parametri loaderJob elementa
44
boolean bDefaultOnErrorContinue = false;
45     boolean bDefaultCommit = true;
46     String JavaDoc strDefaultUserID = "";
47     String JavaDoc strDefaultLogDir = "";
48     String JavaDoc strDefaultLogFile = "default";
49     String JavaDoc strDefaultVendorConfig = "OctopusDBVendors.xml";
50     boolean bDefaultObjectIDAutoCreate = false;
51     int iDefaultObjectIDStartValue = 1;
52     int iDefaultCommitCount = 100;
53     int iLoaderJobCommitCount = 0;
54     boolean bDefaultOidLogic = true;
55
56     String JavaDoc strDefaultLogMode = "normal";
57     int iDefaultObjectIDIncrement = 20;
58     String JavaDoc strDefaultObjectIDTableName = "objectid";
59     String JavaDoc strDefaultObjectIDColumnName = "next";
60     String JavaDoc strDefaultObjectIDNameColumnName = "";
61     String JavaDoc strDefaultObjectIDNameColumnValue = "";
62     String JavaDoc strDefaultTableMode = "Query";
63
64     //rale
65
String JavaDoc strDefaultDataCutOff = "";
66     String JavaDoc strLogTableName = "";
67     String JavaDoc strLogTable = "";
68     String JavaDoc strLogColumnName = "";
69     String JavaDoc strLogRowNumber = "";
70     String JavaDoc strLogOriginalValue = "";
71     String JavaDoc strLogNewValue = "";
72     String JavaDoc strLogImportDefinitionName = "";
73     String JavaDoc strLogOperationName = "";
74     String JavaDoc strLogTypeName = "";
75     String JavaDoc strLogFailedStatemet = "";
76     String JavaDoc strLogTime = "";
77
78     private Logger logger;
79     String JavaDoc strLogClassName = "";
80     String JavaDoc strPathToLoggerConf = "";
81     String JavaDoc setFetchSize = "";
82     String JavaDoc setCursorName = "";
83
84     /**
85      * Method importLoaderJobAttributes is used to analyse import XML file
86          * about attributes of root element(loaderJob). Values of these attributes puts in global variables.
87      * @param inputStream Data from inputXML file which is converted into InputStream.
88      * @throws LoaderException
89      */

90     public void importLoaderJobAttributes(InputStream JavaDoc inputStream) throws LoaderException {
91         Document JavaDoc doc = null;
92         this.logger.write("full", "\timportLoaderJobAttributes method is started.");
93         try {
94             DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
95             DocumentBuilder JavaDoc db = null;
96             db = dbf.newDocumentBuilder();
97             doc = db.parse(inputStream);
98         } catch (Exception JavaDoc e) {
99             this.logger.write("normal", "Sorry, an error occurred: " + e);
100             LoaderException le = new LoaderException("Exception: ", (Throwable JavaDoc) e);
101             throw le;
102             // System.exit(1);
103
}
104         if (doc != null) {
105             NodeList JavaDoc tagRestartCounter = doc.getElementsByTagName("loaderJob");
106             if (tagRestartCounter.getLength() != 0) {
107                 NamedNodeMap JavaDoc attrs = tagRestartCounter.item(0).getAttributes();
108                 Node JavaDoc nodeResult = attrs.getNamedItem("logMode");
109                 if (nodeResult != null)
110                     this.strDefaultLogMode = nodeResult.getNodeValue();
111
112                 nodeResult = attrs.getNamedItem("objectIDIncrement");
113                 String JavaDoc strIncrement = "";
114                 if (nodeResult != null)
115                     strIncrement = nodeResult.getNodeValue();
116                 if (!strIncrement.equals(""))
117                     this.iDefaultObjectIDIncrement = Integer.parseInt(strIncrement);
118
119                 nodeResult = attrs.getNamedItem("objectIDTableName");
120                 if (nodeResult != null)
121                     this.strDefaultObjectIDTableName = nodeResult.getNodeValue();
122
123                 nodeResult = attrs.getNamedItem("objectIDColumnName");
124                 if (nodeResult != null)
125                     this.strDefaultObjectIDColumnName = nodeResult.getNodeValue();
126
127                 //log table
128
nodeResult = attrs.getNamedItem("dataCutOff");
129                 if (nodeResult != null)
130                     this.strDefaultDataCutOff = nodeResult.getNodeValue();
131
132                 nodeResult = attrs.getNamedItem("logTableName");
133                 if (nodeResult != null)
134                     this.strLogTableName = nodeResult.getNodeValue();
135
136                 nodeResult = attrs.getNamedItem("logTable");
137                 if (nodeResult != null)
138                     this.strLogTable = nodeResult.getNodeValue();
139
140                 nodeResult = attrs.getNamedItem("logColumnName");
141                 if (nodeResult != null)
142                     this.strLogColumnName = nodeResult.getNodeValue();
143
144                 nodeResult = attrs.getNamedItem("logRowNumber");
145                 if (nodeResult != null)
146                     this.strLogRowNumber = nodeResult.getNodeValue();
147
148                 nodeResult = attrs.getNamedItem("logOriginalValue");
149                 if (nodeResult != null)
150                     this.strLogOriginalValue = nodeResult.getNodeValue();
151
152                 nodeResult = attrs.getNamedItem("logNewValue");
153                 if (nodeResult != null)
154                     this.strLogNewValue = nodeResult.getNodeValue();
155
156                 nodeResult = attrs.getNamedItem("logImportDefinitionName");
157                 if (nodeResult != null)
158                     this.strLogImportDefinitionName = nodeResult.getNodeValue();
159
160                 nodeResult = attrs.getNamedItem("logOperationName");
161                 if (nodeResult != null)
162                     this.strLogOperationName = nodeResult.getNodeValue();
163
164                 nodeResult = attrs.getNamedItem("logTypeName");
165                 if (nodeResult != null)
166                     this.strLogTypeName = nodeResult.getNodeValue();
167                 //ZK added to support more information in logtable
168
nodeResult = attrs.getNamedItem("logTime");
169                 if (nodeResult != null)
170                     this.strLogTime = nodeResult.getNodeValue();
171
172                 nodeResult = attrs.getNamedItem("logPrimaryKeyValue");
173                 if (nodeResult != null)
174                     this.strLogFailedStatemet = nodeResult.getNodeValue();
175                 //end
176

177                 nodeResult = attrs.getNamedItem("objectIDNameColumnName");
178                 if (nodeResult != null)
179                     this.strDefaultObjectIDNameColumnName = nodeResult.getNodeValue();
180
181                 nodeResult = attrs.getNamedItem("objectIDNameColumnValue");
182                 if (nodeResult != null)
183                     this.strDefaultObjectIDNameColumnValue = nodeResult.getNodeValue();
184
185                 nodeResult = attrs.getNamedItem("onErrorContinue");
186                 if (nodeResult != null)
187                     this.bDefaultOnErrorContinue = (new Boolean JavaDoc(nodeResult.getNodeValue())).booleanValue();
188
189                 nodeResult = attrs.getNamedItem("commit");
190                 if (nodeResult != null)
191                     this.bDefaultCommit = (new Boolean JavaDoc(nodeResult.getNodeValue())).booleanValue();
192
193                 nodeResult = attrs.getNamedItem("userID");
194                 if (nodeResult != null)
195                     this.strDefaultUserID = nodeResult.getNodeValue();
196
197                 nodeResult = attrs.getNamedItem("logDir");
198                 if (nodeResult != null)
199                     this.strDefaultLogDir = nodeResult.getNodeValue();
200
201                 nodeResult = attrs.getNamedItem("logFile");
202                 if (nodeResult != null)
203                     this.strDefaultLogFile = nodeResult.getNodeValue();
204
205                 nodeResult = attrs.getNamedItem("vendorConfig");
206                 if (nodeResult != null)
207                     this.strDefaultVendorConfig = nodeResult.getNodeValue();
208
209                 nodeResult = attrs.getNamedItem("objectIDAutoCreate");
210                 if (nodeResult != null)
211                     this.bDefaultObjectIDAutoCreate = (new Boolean JavaDoc(nodeResult.getNodeValue())).booleanValue();
212
213                 nodeResult = attrs.getNamedItem("objectIDStartValue");
214                 if (nodeResult != null)
215                     this.iDefaultObjectIDStartValue = Integer.parseInt(nodeResult.getNodeValue());
216
217                 nodeResult = attrs.getNamedItem("commitCount");
218                 if (nodeResult != null)
219                     this.iLoaderJobCommitCount = Integer.parseInt(nodeResult.getNodeValue());
220
221                 nodeResult = attrs.getNamedItem("oidLogic");
222                 if (nodeResult != null)
223                     this.bDefaultOidLogic = (new Boolean JavaDoc(nodeResult.getNodeValue())).booleanValue();
224
225                 nodeResult = attrs.getNamedItem("tableMode");
226                 if (nodeResult != null)
227                     this.strDefaultTableMode = nodeResult.getNodeValue();
228
229                 // nodeResult = attrs.getNamedItem("logClassName");
230
// if (nodeResult != null)
231
// this.strLogClassName = nodeResult.getNodeValue();
232

233                 // nodeResult = attrs.getNamedItem("pathToLoggerConf");
234
// if (nodeResult != null)
235
// this.strPathToLoggerConf = nodeResult.getNodeValue();
236

237                 nodeResult = attrs.getNamedItem("returnCode");
238                 if (nodeResult != null) {
239                     if (!ReturnCode.isParameter)
240                         ReturnCode.setDefaultErrorReturnCode(Integer.parseInt(nodeResult.getNodeValue()));
241                 }
242
243                 nodeResult = attrs.getNamedItem("setFetchSize");
244                 if (nodeResult != null)
245                     this.setFetchSize = nodeResult.getNodeValue();
246
247                 nodeResult = attrs.getNamedItem("setCursorName");
248                 if (nodeResult != null)
249                     this.setCursorName = nodeResult.getNodeValue();
250
251             }
252         }
253         try {
254             inputStream.reset();
255         } catch (IOException JavaDoc e) {
256             this.logger.write("normal", "Sorry, an error occurred: " + e);
257             LoaderException le = new LoaderException("IOException: ", (Throwable JavaDoc) e);
258             throw le;
259         }
260         this.logger.write("full", "\timportLoaderJobAttributes method is finished.");
261     }
262
263     /**
264      * This method set setCursorName parameter
265      * @param setCursorName is value of parameter
266      */

267     public void setSetCursorName(String JavaDoc setCursorName) {
268         this.setCursorName = setCursorName;
269     }
270
271     /**
272      * This method read value from setCursorName parameter
273      * @return value attribute.
274      */

275     public String JavaDoc getSetCursorName() {
276         return this.setCursorName;
277     }
278
279     /**
280      * This method set setFetchSize parameter
281      * @param setFetchSize is value of parameter
282      */

283     public void setSetFetchSize(String JavaDoc setFetchSize) {
284         this.setFetchSize = setFetchSize;
285     }
286
287     /**
288      * This method read value from setFetchSize parameter
289      * @return value attribute.
290      */

291     public String JavaDoc getSetFetchSize() {
292         return this.setFetchSize;
293     }
294
295     /**
296      * Set Logger which is used for write in log file.
297      * @param logger Logger object.
298      */

299     public void setLogger(Logger logger) {
300         this.logger = logger;
301     }
302
303     /**
304      * This method read value from strDefaultTableMode parameter
305      * @return default value of TableMode attribute.
306      */

307     public String JavaDoc getDefaultTableMode() {
308         return this.strDefaultTableMode;
309     }
310
311     /**
312      * This method reads value from strDefaultDataCutOff parameter
313      * @return value of parameter
314      */

315     public String JavaDoc getDefaultDataCutOff() {
316         return this.strDefaultDataCutOff;
317     }
318
319     /**
320      * This method read value from strDefaultObjectIDNameColumnValue parameter
321      * @return default value of ObjectIDNameColumnValue attribute.
322      */

323     public String JavaDoc getDefaultObjectIDNameColumnValue() {
324         return this.strDefaultObjectIDNameColumnValue;
325     }
326
327     /**
328      * This method read value from strDefaultObjectIDNameColumnName parameter
329      * @return default value of ObjectIDNameColumnName attribute.
330      */

331     public String JavaDoc getDefaultObjectIDNameColumnName() {
332         return this.strDefaultObjectIDNameColumnName;
333     }
334
335     /**
336      * This method read value from strDefaultObjectIDColumnName parameter
337      * @return default value of ObjectIDColumnName attribute.
338      */

339     public String JavaDoc getDefaultObjectIDColumnName() {
340         return this.strDefaultObjectIDColumnName;
341     }
342
343     /**
344      * This method read value from strDefaultObjectIDTableName parameter
345      * @return default value of ObjectIDTableName attribute.
346      */

347     public String JavaDoc getDefaultObjectIDTableName() {
348         return this.strDefaultObjectIDTableName;
349     }
350
351     /**
352      * This method read value from iDefaultObjectIDIncrement parameter
353      * @return default value of ObectIDIncrement attribute.
354      */

355     public int getDefaultObjectIDIncrement() {
356         return this.iDefaultObjectIDIncrement;
357     }
358
359     /**
360      * This method read value from strDefaultLogMode parameter
361      * @return default value of LogMode attribute.
362      */

363     public String JavaDoc getDefaultLogMode() {
364         return this.strDefaultLogMode;
365     }
366     /**
367          * This method set value for strDefaultLogMode parameter
368          */

369     public void setDefaultLogMode(String JavaDoc logMode) {
370         this.strDefaultLogMode = logMode;
371     }
372
373     /**
374      * This method read value from bDefaultOidLogic parameter
375      * @return default value of OidLogic attribute.
376      */

377     public boolean getDefaultOidLogic() {
378         return this.bDefaultOidLogic;
379     }
380
381     /**
382      * This method read value from iDefaultCommitCount parameter
383      * @return default value of CommitCount attribute.
384      */

385     public int getDefaultCommitCount() {
386         return this.iDefaultCommitCount;
387     }
388
389     /**
390      * This method read value from iLoaderJobCommitCount parameter
391      * @return default value of iLoaderJobCommitCount attribute.
392      */

393     public int getLoaderJobCommitCount() {
394         return this.iLoaderJobCommitCount;
395     }
396
397     /**
398      * This method read value from iDefaultObjectIDStartValue parameter
399      * @return default value of ObjectIDStartValue attribute.
400      */

401     public int getDefaultObjectIDStartValue() {
402         return this.iDefaultObjectIDStartValue;
403     }
404
405     /**
406      * This method read value from bDefaultObjectIDAutoCreate parameter
407      * @return default value of ObjectIDAutoCreate attribute.
408      */

409     public boolean getDefaultObjectIDAutoCreate() {
410         return this.bDefaultObjectIDAutoCreate;
411     }
412
413     /**
414      * This method read value from strDefaultVendorConfig parameter
415      * @return default value of VendorConfig attribute.
416      */

417     public String JavaDoc getDefaultVendorConfig() {
418         return this.strDefaultVendorConfig;
419     }
420
421     /**
422      * This method read value from strDefaultLogFile parameter
423      * @return default value of LogFile attribute.
424      */

425     public String JavaDoc getDefaultLogFile() {
426         return this.strDefaultLogFile;
427     }
428
429     /**
430      * This method read value from strDefaultLogDir parameter
431      * @return default value of LogDir attribute.
432      */

433     public String JavaDoc getDefaultLogDir() {
434         return this.strDefaultLogDir;
435     }
436
437     /**
438      * This method read value from strDefaultUserID parameter
439      * @return default value of UserID attribute.
440      */

441     public String JavaDoc getDefaultUserID() {
442         return this.strDefaultUserID;
443     }
444
445     /**
446      * This method read value from bDefaultCommit parameter
447      * @return default value of Commit attribute.
448      */

449     public boolean getDefaultCommit() {
450         return this.bDefaultCommit;
451     }
452
453     /**
454      * This method read value from bDefaultOnErrorContinue parameter
455      * @return default value of OnErrorContinue attribute.
456      */

457     public boolean getDefaultOnErrorContinue() {
458         return this.bDefaultOnErrorContinue;
459     }
460
461     public void setDefaultOnErrorContinue(boolean value) {
462         this.bDefaultOnErrorContinue = value;
463     }
464
465     /**
466      * This method read value from parameter strLogTableName
467      * @return value of parameter
468      */

469     public String JavaDoc getLogTableName() {
470         return this.strLogTableName;
471     }
472
473     /**
474      * This method read value from parameter strLogTable
475      * @return value of parameter
476      */

477     public String JavaDoc getLogTable() {
478         return this.strLogTable;
479     }
480
481     /**
482      * This method read value from parameter strLogColumnName
483      * @return value of parameter
484      */

485     public String JavaDoc getLogColumnName() {
486         return this.strLogColumnName;
487     }
488
489     /**
490      * This method read value from parameter strLogRowNumber
491      * @return value of parameter
492      */

493     public String JavaDoc getLogRowNumber() {
494         return this.strLogRowNumber;
495     }
496
497     /**
498      * This method read value from parameter strLogOriginalValue
499      * @return value of parameter
500      */

501     public String JavaDoc getLogOriginalValue() {
502         return this.strLogOriginalValue;
503     }
504
505     /**
506      * This method read value from parameter strLogNewValue
507      * @return value of parameter
508      */

509     public String JavaDoc getLogNewValue() {
510         return this.strLogNewValue;
511     }
512
513     /**
514      * This method read value from parameter strLogImportDefinitionName
515      * @return value of parameter
516      */

517     public String JavaDoc getLogImportDefinitionName() {
518         return this.strLogImportDefinitionName;
519     }
520
521     /**
522      * This method read value from parameter strLogOperationName
523      * @return value of parameter
524      */

525     public String JavaDoc getLogOperationName() {
526         return this.strLogOperationName;
527     }
528
529     /**
530      * This method read value from parameter strLogTypeName
531      * @return value of parameter
532      */

533     public String JavaDoc getLogTypeName() {
534         return this.strLogTypeName;
535     }
536
537     /**
538      *This method read value from parameter strLogPrimaryKeyValue
539      * @return String column name
540      */

541     public String JavaDoc getLogFailedStatement() {
542         return this.strLogFailedStatemet;
543     }
544
545     /**
546      * This method read value from parameter strLogTime
547      * @return String column name
548      */

549     public String JavaDoc getLogTime() {
550         return this.strLogTime;
551     }
552
553 }
554
Popular Tags