Source Code Cross Referenced for JdbcParametersElement.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » octopus » org.webdocwf.util.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.webdocwf.util.loader;
002:
003:        /**
004:         JdbcParametersElement - Element in parallel to importDefinitions and sql's.
005:
006:         Copyright (C) 2002-2003  Together
007:
008:         This library is free software; you can redistribute it and/or
009:         modify it under the terms of the GNU Lesser General Public
010:         License as published by the Free Software Foundation; either
011:         version 2.1 of the License, or (at your option) any later version.
012:
013:         This library is distributed in the hope that it will be useful,
014:         but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         Lesser General Public License for more details.
017:
018:         You should have received a copy of the GNU Lesser General Public
019:         License along with this library; if not, write to the Free Software
020:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:
022:         JdbcParametersElement.java
023:         Date: 20.5.2003.
024:         @version 1.0.0
025:         @author: Zoran Milakovic zoran@prozone.co.yu
026:         */
027:
028:        import java.io.*;
029:        import java.util.*;
030:
031:        import javax.xml.parsers.*;
032:
033:        import org.w3c.dom.*;
034:        import org.webdocwf.util.loader.logging.*;
035:
036:        /**
037:         *
038:         * JdbcParametersElement class sets the jdbc parameters
039:         * @author Radoslav Dutina
040:         * @version 1.0
041:         */
042:        public class JdbcParametersElement {
043:
044:            private String strJDBCSourceParameterDriver = "";
045:            private String strJDBCTargetParameterDriver = "";
046:            private String strJDBCSourceParameterConnection = "";
047:            private String strJDBCTargetParameterConnection = "";
048:            private String strJDBCSourceParameterUser = "";
049:            private String strJDBCTargetParameterUser = "";
050:            private String strJDBCSourceParameterPassword = "";
051:            private String strJDBCTargetParameterPassword = "";
052:
053:            private String strJDBCDefaultSourceParameterDriver = "";
054:            private String strJDBCDefaultTargetParameterDriver = "";
055:            private String strJDBCDefaultSourceParameterConnection = "";
056:            private String strJDBCDefaultTargetParameterConnection = "";
057:            private String strJDBCDefaultSourceParameterUser = "";
058:            private String strJDBCDefaultTargetParameterUser = "";
059:            private String strJDBCDefaultSourceParameterPassword = "";
060:            private String strJDBCDefaultTargetParameterPassword = "";
061:
062:            private String strDbVendor = "";
063:            private String strDriverName = "";
064:
065:            private String strTargetDbVendor = "";
066:            private String strTargetDriverName = "";
067:
068:            private String strDbVendorDefault = "";
069:            private String strDriverNameDefault = "";
070:
071:            private String strTargetDbVendorDefault = "";
072:            private String strTargetDriverNameDefault = "";
073:
074:            private Logger logger;
075:            private Vector targetConnections;
076:
077:            private String loaderJobFile = "";
078:            private ConfigReader configReaderSource;
079:
080:            /**
081:             * Method parseTargetJDBCParameters is used to analyse import XML file
082:             * @param inStream Data from inputXML file which is converted into InputStream.
083:             * @throws LoaderException
084:             */
085:            public void parseTargetJDBCParameters(InputStream inStream)
086:                    throws LoaderException {
087:                Document doc = null;
088:                targetConnections = new Vector();
089:                try {
090:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
091:                            .newInstance();
092:                    DocumentBuilder db = null;
093:                    db = dbf.newDocumentBuilder();
094:                    doc = db.parse(inStream);
095:                } catch (Exception e) {
096:                    this .logger.write("normal", "Sorry, an error occurred: "
097:                            + e);
098:                    LoaderException le = new LoaderException("Exception: ",
099:                            (Throwable) e);
100:                    throw le;
101:                }
102:                if (doc != null) {
103:                    NodeList targetList = doc
104:                            .getElementsByTagName("jdbcTargetParameters");
105:                    int position = 0;
106:                    if (targetList.getLength() != 0) {
107:                        for (int i = 0; i < targetList.getLength(); i++) {
108:
109:                            targetConnections.add(position, "");
110:                            targetConnections.add(position + 1, "");
111:                            targetConnections.add(position + 2, "");
112:                            targetConnections.add(position + 3, "");
113:
114:                            NodeList childs = targetList.item(i)
115:                                    .getChildNodes();
116:                            for (int k = 0; k < childs.getLength(); k++) {
117:                                if (childs.item(k).getNodeType() == 3) {
118:                                    //
119:                                } else {
120:                                    NamedNodeMap attributes = childs.item(k)
121:                                            .getAttributes();
122:                                    String name = attributes.getNamedItem(
123:                                            "name").getNodeValue();
124:                                    if (name.equalsIgnoreCase("JdbcDriver"))
125:                                        targetConnections.set(position,
126:                                                attributes
127:                                                        .getNamedItem("value")
128:                                                        .getNodeValue());
129:                                    else if (name
130:                                            .equalsIgnoreCase("Connection.Url")) {
131:                                        targetConnections.set(position + 1,
132:                                                attributes
133:                                                        .getNamedItem("value")
134:                                                        .getNodeValue());
135:                                    } else if (name.equalsIgnoreCase("User"))
136:                                        targetConnections.set(position + 2,
137:                                                attributes
138:                                                        .getNamedItem("value")
139:                                                        .getNodeValue());
140:                                    else if (name.equalsIgnoreCase("Password"))
141:                                        targetConnections.set(position + 3,
142:                                                attributes
143:                                                        .getNamedItem("value")
144:                                                        .getNodeValue());
145:
146:                                }
147:                            }
148:                            position = position + 4;
149:                        }
150:                    }
151:                }
152:                try {
153:                    inStream.reset();
154:                } catch (IOException e) {
155:                    this .logger.write("normal", "Sorry, an error occurred: "
156:                            + e);
157:                    LoaderException le = new LoaderException("IOException: ",
158:                            (Throwable) e);
159:                    throw le;
160:                }
161:            }
162:
163:            /**
164:             * This method read the value of targetConnections parameter
165:             * @return value of parameter
166:             */
167:            public Vector getTargetConnections() {
168:                return targetConnections;
169:            }
170:
171:            /**
172:             * Method parseImportJDBCParameters is used to analyse import XML file
173:             * about JDBC parameters tags. Puts values of first importDefinition's JDBC parameters in global variables.
174:             * @param inStream Data from inputXML file which is converted into InputStream.
175:             * @param number order number of importDefinition or sql tag which is proceeded.
176:             * @param tagName name of tag which is proceeded
177:             * @throws LoaderException
178:             */
179:            public void parseImportJDBCParameters(InputStream inStream,
180:                    int number, String tagName) throws LoaderException {
181:                this .strJDBCSourceParameterDriver = "";
182:                this .strJDBCTargetParameterDriver = "";
183:                this .strJDBCSourceParameterConnection = "";
184:                this .strJDBCTargetParameterConnection = "";
185:                this .strJDBCSourceParameterUser = "";
186:                this .strJDBCTargetParameterUser = "";
187:                this .strJDBCSourceParameterPassword = "";
188:                this .strJDBCTargetParameterPassword = "";
189:                this .strDbVendor = "";
190:                this .strDriverName = "";
191:                this .strTargetDbVendor = "";
192:                this .strTargetDriverName = "";
193:                number--;
194:                Document doc = null;
195:                Vector vecJDBCTargetValue = new Vector();
196:                Vector vecJDBCTargetName = new Vector();
197:                Vector vecJDBCSourceValue = new Vector();
198:                Vector vecJDBCSourceName = new Vector();
199:                boolean isOK = false;
200:
201:                this .logger.write("full",
202:                        "\tparseImportJDBCParameters method is started.");
203:                try {
204:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
205:                            .newInstance();
206:                    DocumentBuilder db = null;
207:                    db = dbf.newDocumentBuilder();
208:                    doc = db.parse(inStream);
209:                } catch (Exception e) {
210:                    this .logger.write("normal", "Sorry, an error occurred: "
211:                            + e);
212:                    LoaderException le = new LoaderException("Exception: ",
213:                            (Throwable) e);
214:                    throw le;
215:                    //            System.exit(1);
216:                }
217:                if (doc != null) {
218:                    NodeList tagDefault = doc.getElementsByTagName(tagName);
219:                    if (tagDefault.getLength() != 0) {
220:                        Element docFragment = (Element) tagDefault.item(number);
221:                        //source parameters
222:                        NodeList tag = docFragment
223:                                .getElementsByTagName("jdbcSourceParameters");
224:                        if (tag.getLength() != 0) {
225:                            NamedNodeMap jdbc = tag.item(0).getAttributes();
226:                            Node nodeJdbc = jdbc.getNamedItem("dbVendor");
227:                            if (nodeJdbc != null)
228:                                this .strDbVendor = nodeJdbc.getNodeValue();
229:                            nodeJdbc = jdbc.getNamedItem("driverName");
230:                            if (nodeJdbc != null)
231:                                this .strDriverName = nodeJdbc.getNodeValue();
232:                        }
233:                        //target parameters
234:                        tag = docFragment
235:                                .getElementsByTagName("jdbcTargetParameters");
236:                        if (tag.getLength() != 0) {
237:                            NamedNodeMap jdbc = tag.item(0).getAttributes();
238:                            Node nodeJdbc = jdbc.getNamedItem("dbVendor");
239:                            if (nodeJdbc != null)
240:                                this .strTargetDbVendor = nodeJdbc
241:                                        .getNodeValue();
242:                            nodeJdbc = jdbc.getNamedItem("driverName");
243:                            if (nodeJdbc != null)
244:                                this .strTargetDriverName = nodeJdbc
245:                                        .getNodeValue();
246:                        }
247:
248:                        tag = docFragment
249:                                .getElementsByTagName("jdbcSourceParameter");
250:                        for (int i = 0; i < tag.getLength(); i++) {
251:                            String nodeValueValue = "";
252:                            String nodeNameValue = "";
253:                            NamedNodeMap attrs = tag.item(i).getAttributes();
254:                            Node nodeValue = attrs.getNamedItem("value");
255:                            Node nodeName = attrs.getNamedItem("name");
256:                            if (nodeValue != null && nodeName != null) {
257:                                nodeValueValue = nodeValue.getNodeValue();
258:                                nodeNameValue = nodeName.getNodeValue();
259:                            }
260:                            vecJDBCSourceValue.addElement(nodeValueValue);
261:                            vecJDBCSourceName.addElement(nodeNameValue);
262:                        }
263:                        for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
264:                            if (vecJDBCSourceName.get(i).toString()
265:                                    .equalsIgnoreCase("JdbcDriver"))
266:                                this .strJDBCSourceParameterDriver = vecJDBCSourceValue
267:                                        .get(i).toString();
268:                            else if (vecJDBCSourceName.get(i).toString()
269:                                    .equalsIgnoreCase("Connection.Url")) {
270:                                //Testing SelectMethod parameter in microsoft MSSQL driver
271:                                if (vecJDBCSourceValue.get(i).toString()
272:                                        .indexOf("jdbc:microsoft:sqlserver") != -1) {
273:                                    if (vecJDBCSourceValue.get(i).toString()
274:                                            .indexOf("SelectMethod") == -1) {
275:                                        this .strJDBCSourceParameterConnection = vecJDBCSourceValue
276:                                                .get(i).toString()
277:                                                + ";SelectMethod=cursor";
278:                                    } else {
279:                                        if (vecJDBCSourceValue.get(i)
280:                                                .toString().indexOf("cursor") != -1) {
281:                                            this .strJDBCSourceParameterConnection = vecJDBCSourceValue
282:                                                    .get(i).toString();
283:                                        } else {
284:                                            this .logger
285:                                                    .write(
286:                                                            "normal",
287:                                                            "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor");
288:                                            LoaderException le = new LoaderException(
289:                                                    "Exception:",
290:                                                    new Exception(
291:                                                            "value of Connection.Url perameter SelectMethod has to be cursor"));
292:                                            throw le;
293:                                        }
294:                                    }
295:                                } else {
296:                                    this .strJDBCSourceParameterConnection = vecJDBCSourceValue
297:                                            .get(i).toString();
298:                                }
299:                            } else if (vecJDBCSourceName.get(i).toString()
300:                                    .equalsIgnoreCase("User"))
301:                                this .strJDBCSourceParameterUser = vecJDBCSourceValue
302:                                        .get(i).toString();
303:                            else if (vecJDBCSourceName.get(i).toString()
304:                                    .equalsIgnoreCase("Password"))
305:                                this .strJDBCSourceParameterPassword = vecJDBCSourceValue
306:                                        .get(i).toString();
307:                        }
308:                        tag = docFragment
309:                                .getElementsByTagName("jdbcTargetParameter");
310:                        for (int i = 0; i < tag.getLength(); i++) {
311:                            String nodeValueValue = "";
312:                            String nodeNameValue = "";
313:                            NamedNodeMap attrs = tag.item(i).getAttributes();
314:                            Node nodeValue = attrs.getNamedItem("value");
315:                            Node nodeName = attrs.getNamedItem("name");
316:                            if (nodeValueValue != null && nodeName != null) {
317:                                nodeValueValue = nodeValue.getNodeValue();
318:                                nodeNameValue = nodeName.getNodeValue();
319:                            }
320:                            vecJDBCTargetValue.addElement(nodeValueValue);
321:                            vecJDBCTargetName.addElement(nodeNameValue);
322:                        }
323:                        for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
324:                            if (vecJDBCTargetName.get(i).toString()
325:                                    .equalsIgnoreCase("JdbcDriver"))
326:                                this .strJDBCTargetParameterDriver = vecJDBCTargetValue
327:                                        .get(i).toString();
328:                            else if (vecJDBCTargetName.get(i).toString()
329:                                    .equalsIgnoreCase("Connection.Url")) {
330:                                //Testing SelectMethod parameter in microsoft MSSQL driver
331:                                if (vecJDBCTargetValue.get(i).toString()
332:                                        .indexOf("jdbc:microsoft:sqlserver") != -1) {
333:                                    if (vecJDBCTargetValue.get(i).toString()
334:                                            .indexOf("SelectMethod") == -1) {
335:                                        this .strJDBCTargetParameterConnection = vecJDBCTargetValue
336:                                                .get(i).toString()
337:                                                + ";SelectMethod=cursor";
338:                                    } else {
339:                                        if (vecJDBCTargetValue.get(i)
340:                                                .toString().indexOf("cursor") != -1) {
341:                                            this .strJDBCTargetParameterConnection = vecJDBCTargetValue
342:                                                    .get(i).toString();
343:                                        } else {
344:                                            this .logger
345:                                                    .write(
346:                                                            "normal",
347:                                                            "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor");
348:                                            LoaderException le = new LoaderException(
349:                                                    "Exception:",
350:                                                    new Exception(
351:                                                            "value of Connection.Url perameter SelectMethod has to be cursor"));
352:                                            throw le;
353:                                        }
354:                                    }
355:                                } else {
356:                                    this .strJDBCTargetParameterConnection = vecJDBCTargetValue
357:                                            .get(i).toString();
358:                                }
359:                            } else if (vecJDBCTargetName.get(i).toString()
360:                                    .equalsIgnoreCase("User"))
361:                                this .strJDBCTargetParameterUser = vecJDBCTargetValue
362:                                        .get(i).toString();
363:                            else if (vecJDBCTargetName.get(i).toString()
364:                                    .equalsIgnoreCase("Password"))
365:                                this .strJDBCTargetParameterPassword = vecJDBCTargetValue
366:                                        .get(i).toString();
367:                        }
368:                    }
369:                    isOK = true;
370:                }
371:                try {
372:                    inStream.reset();
373:                } catch (IOException e) {
374:                    this .logger.write("normal", "Sorry, an error occurred: "
375:                            + e);
376:                    LoaderException le = new LoaderException("IOException: ",
377:                            (Throwable) e);
378:                    throw le;
379:                }
380:                this .logger
381:                        .write("full",
382:                                "\tparseImportJDBCDefaultParameters method is finished.");
383:            }
384:
385:            /**
386:             * Method parseImportJDBCDefaultParameters is used to analyse import XML file
387:             * about Default JDBC parameters tags.
388:             * @param inStream Data from inputXML file which is converted into InputStream.
389:             * @return boolean - true default jdbc parameters exists, false otherwise
390:             * @throws LoaderException
391:             */
392:            public boolean parseImportJDBCDefaultParameters(InputStream inStream)
393:                    throws LoaderException {
394:                Document doc = null;
395:                Vector vecJDBCTargetValue = new Vector();
396:                Vector vecJDBCTargetName = new Vector();
397:                Vector vecJDBCSourceValue = new Vector();
398:                Vector vecJDBCSourceName = new Vector();
399:                boolean isOK = false;
400:
401:                this .logger
402:                        .write("full",
403:                                "\tparseImportJDBCDefaultParameters method is started.");
404:                try {
405:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
406:                            .newInstance();
407:                    DocumentBuilder db = null;
408:                    db = dbf.newDocumentBuilder();
409:                    doc = db.parse(inStream);
410:                } catch (Exception e) {
411:                    this .logger.write("normal", "Sorry, an error occurred: "
412:                            + e);
413:                    LoaderException le = new LoaderException("Exception: ",
414:                            (Throwable) e);
415:                    throw le;
416:                }
417:                if (doc != null) {
418:                    NodeList tagDefault = doc
419:                            .getElementsByTagName("jdbcDefaultParameters");
420:                    if (tagDefault.getLength() != 0) {
421:                        Element docFragment = (Element) tagDefault.item(0);
422:                        NodeList tag = docFragment
423:                                .getElementsByTagName("jdbcSourceParameters");
424:                        if (tag.getLength() != 0) {
425:                            NamedNodeMap jdbc = tag.item(0).getAttributes();
426:                            Node nodeJdbc = jdbc.getNamedItem("dbVendor");
427:                            if (nodeJdbc != null)
428:                                this .strDbVendorDefault = nodeJdbc
429:                                        .getNodeValue();
430:                            nodeJdbc = jdbc.getNamedItem("driverName");
431:                            if (nodeJdbc != null)
432:                                this .strDriverNameDefault = nodeJdbc
433:                                        .getNodeValue();
434:                        }
435:                        tag = docFragment
436:                                .getElementsByTagName("jdbcTargetParameters");
437:                        if (tag.getLength() != 0) {
438:                            NamedNodeMap jdbc = tag.item(0).getAttributes();
439:                            Node nodeJdbc = jdbc.getNamedItem("dbVendor");
440:                            if (nodeJdbc != null)
441:                                this .strTargetDbVendorDefault = nodeJdbc
442:                                        .getNodeValue();
443:                            nodeJdbc = jdbc.getNamedItem("driverName");
444:                            if (nodeJdbc != null)
445:                                this .strTargetDriverNameDefault = nodeJdbc
446:                                        .getNodeValue();
447:                        }
448:                        tag = docFragment
449:                                .getElementsByTagName("jdbcSourceParameter");
450:                        for (int i = 0; i < tag.getLength(); i++) {
451:                            String nodeValueValue = "";
452:                            String nodeNameValue = "";
453:                            NamedNodeMap attrs = tag.item(i).getAttributes();
454:                            Node nodeValue = attrs.getNamedItem("value");
455:                            Node nodeName = attrs.getNamedItem("name");
456:                            if (nodeValue != null && nodeName != null) {
457:                                nodeValueValue = nodeValue.getNodeValue();
458:                                nodeNameValue = nodeName.getNodeValue();
459:                            }
460:                            vecJDBCSourceValue.addElement(nodeValueValue);
461:                            vecJDBCSourceName.addElement(nodeNameValue);
462:                        }
463:                        for (int i = 0; i < vecJDBCSourceValue.size(); i++) {
464:                            if (vecJDBCSourceName.get(i).toString()
465:                                    .equalsIgnoreCase("JdbcDriver"))
466:                                this .strJDBCDefaultSourceParameterDriver = vecJDBCSourceValue
467:                                        .get(i).toString();
468:                            else if (vecJDBCSourceName.get(i).toString()
469:                                    .equalsIgnoreCase("Connection.Url")) {
470:                                //Testing SelectMethod parameter in microsoft MSSQL driver
471:                                if (vecJDBCSourceValue.get(i).toString()
472:                                        .indexOf("jdbc:microsoft:sqlserver") != -1) {
473:                                    if (vecJDBCSourceValue.get(i).toString()
474:                                            .indexOf("SelectMethod") == -1) {
475:                                        this .strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue
476:                                                .get(i).toString()
477:                                                + ";SelectMethod=cursor";
478:                                    } else {
479:                                        if (vecJDBCSourceValue.get(i)
480:                                                .toString().indexOf("cursor") != -1) {
481:                                            this .strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue
482:                                                    .get(i).toString();
483:                                        } else {
484:                                            this .logger
485:                                                    .write(
486:                                                            "normal",
487:                                                            "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor");
488:                                            LoaderException le = new LoaderException(
489:                                                    "Exception:",
490:                                                    new Exception(
491:                                                            "value of Connection.Url perameter SelectMethod has to be cursor"));
492:                                            throw le;
493:                                        }
494:                                    }
495:                                } else {
496:                                    this .strJDBCDefaultSourceParameterConnection = vecJDBCSourceValue
497:                                            .get(i).toString();
498:                                }
499:                            } else if (vecJDBCSourceName.get(i).toString()
500:                                    .equalsIgnoreCase("User"))
501:                                this .strJDBCDefaultSourceParameterUser = vecJDBCSourceValue
502:                                        .get(i).toString();
503:                            else if (vecJDBCSourceName.get(i).toString()
504:                                    .equalsIgnoreCase("Password"))
505:                                this .strJDBCDefaultSourceParameterPassword = vecJDBCSourceValue
506:                                        .get(i).toString();
507:                        }
508:                        tag = docFragment
509:                                .getElementsByTagName("jdbcTargetParameter");
510:                        for (int i = 0; i < tag.getLength(); i++) {
511:                            String nodeValueValue = "";
512:                            String nodeNameValue = "";
513:                            NamedNodeMap attrs = tag.item(i).getAttributes();
514:                            Node nodeValue = attrs.getNamedItem("value");
515:                            Node nodeName = attrs.getNamedItem("name");
516:                            if (nodeValueValue != null && nodeName != null) {
517:                                nodeValueValue = nodeValue.getNodeValue();
518:                                nodeNameValue = nodeName.getNodeValue();
519:                            }
520:                            vecJDBCTargetValue.addElement(nodeValueValue);
521:                            vecJDBCTargetName.addElement(nodeNameValue);
522:                        }
523:                        for (int i = 0; i < vecJDBCTargetValue.size(); i++) {
524:                            if (vecJDBCTargetName.get(i).toString()
525:                                    .equalsIgnoreCase("JdbcDriver"))
526:                                this .strJDBCDefaultTargetParameterDriver = vecJDBCTargetValue
527:                                        .get(i).toString();
528:                            else if (vecJDBCTargetName.get(i).toString()
529:                                    .equalsIgnoreCase("Connection.Url")) {
530:                                //Testing SelectMethod parameter in microsoft MSSQL driver
531:                                if (vecJDBCTargetValue.get(i).toString()
532:                                        .indexOf("jdbc:microsoft:sqlserver") != -1) {
533:                                    if (vecJDBCTargetValue.get(i).toString()
534:                                            .indexOf("SelectMethod") == -1) {
535:                                        this .strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue
536:                                                .get(i).toString()
537:                                                + ";SelectMethod=cursor";
538:                                    } else {
539:                                        if (vecJDBCTargetValue.get(i)
540:                                                .toString().indexOf("cursor") != -1) {
541:                                            this .strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue
542:                                                    .get(i).toString();
543:                                        } else {
544:                                            this .logger
545:                                                    .write(
546:                                                            "normal",
547:                                                            "Sorry, an error occurred: value of Connection.Url perameter SelectMethod has to be cursor");
548:                                            LoaderException le = new LoaderException(
549:                                                    "Exception:",
550:                                                    new Exception(
551:                                                            "value of Connection.Url perameter SelectMethod has to be cursor"));
552:                                            throw le;
553:                                        }
554:                                    }
555:                                } else {
556:                                    this .strJDBCDefaultTargetParameterConnection = vecJDBCTargetValue
557:                                            .get(i).toString();
558:                                }
559:                            } else if (vecJDBCTargetName.get(i).toString()
560:                                    .equalsIgnoreCase("User"))
561:                                this .strJDBCDefaultTargetParameterUser = vecJDBCTargetValue
562:                                        .get(i).toString();
563:                            else if (vecJDBCTargetName.get(i).toString()
564:                                    .equalsIgnoreCase("Password"))
565:                                this .strJDBCDefaultTargetParameterPassword = vecJDBCTargetValue
566:                                        .get(i).toString();
567:                        }
568:                    }
569:                    isOK = true;
570:                }
571:                try {
572:                    inStream.reset();
573:                } catch (IOException e) {
574:                    this .logger.write("normal", "Sorry, an error occurred: "
575:                            + e);
576:                    LoaderException le = new LoaderException("IOException: ",
577:                            (Throwable) e);
578:                    throw le;
579:                }
580:                this .logger
581:                        .write("full",
582:                                "\tparseImportJDBCDefaultParameters method is finished.");
583:                return isOK;
584:            }
585:
586:            //set and get methods
587:            /**
588:             * Set Logger of this class.
589:             * @param logger Logger object which is used to write to log and standard output.
590:             */
591:            public void setLogger(Logger logger) {
592:                this .logger = logger;
593:            }
594:
595:            /**
596:             * Set ConfigReader of this class.
597:             * @param configReader defines ConfigReader object which is used to store data
598:             * about source driver.
599:             */
600:            public void setConfigReaderSource(ConfigReader configReader) {
601:                this .configReaderSource = configReader;
602:            }
603:
604:            /**
605:             * This method set the absolute path to loader job file
606:             * @param loaderJobName is relativ path to loader job file
607:             */
608:            public void setLoaderJobPath(String loaderJobName) {
609:                File file = new File(loaderJobName);
610:                this .loaderJobFile = file.getAbsoluteFile().getParent()
611:                        + System.getProperty("file.separator");
612:            }
613:
614:            /**
615:             * This method make absoulte path from relative path
616:             * @param urlToDatabase relative path
617:             * @return absolute path
618:             * @throws LoaderException
619:             */
620:            public String getAbsolutePathFromDatabaseURL(String urlToDatabase)
621:                    throws LoaderException {
622:
623:                if (configReaderSource.getFileSystemDatabase() == true) {
624:                    String urlPrefix = configReaderSource.getConnectionPrefix();
625:                    String pathToDatabase = urlToDatabase.substring(urlPrefix
626:                            .length());
627:                    File file = new File(pathToDatabase);
628:                    if (!file.isAbsolute()) {
629:                        pathToDatabase = this .loaderJobFile + pathToDatabase;
630:                        File absolutePath = new File(pathToDatabase);
631:                        try {
632:                            pathToDatabase = absolutePath.getCanonicalPath();
633:                        } catch (Exception ex) {
634:                            this .logger.write("normal", ex.getMessage());
635:                            LoaderException le = new LoaderException(
636:                                    "Exception: ", (Throwable) ex);
637:                            throw le;
638:                        }
639:                        urlToDatabase = urlToDatabase.substring(0, (urlPrefix
640:                                .length()))
641:                                + pathToDatabase;
642:                    }
643:                }
644:                return urlToDatabase;
645:            }
646:
647:            //source parameters
648:            /**
649:             * Method return JDBCSourceParameterConnection,or if that
650:             * parameter is not defined method will return default value which is
651:             * strJDBCDefaultSourceParameterConnection
652:             * @return JDBCSourceParameterConnection
653:             * @throws LoaderException
654:             */
655:            public String getJDBCSourceParameterConnection()
656:                    throws LoaderException {
657:                String parseUrl = "";
658:                try {
659:                    if (!this .strJDBCSourceParameterConnection.equals("")) {
660:                        parseUrl = getAbsolutePathFromDatabaseURL(this .strJDBCSourceParameterConnection);
661:                    } else {
662:                        parseUrl = getAbsolutePathFromDatabaseURL(this .strJDBCDefaultSourceParameterConnection);
663:                    }
664:                } catch (LoaderException ex) {
665:                    throw ex;
666:                }
667:                return parseUrl;
668:            }
669:
670:            /**
671:             * This method set value of strJDBCSourceParameterConnection parameter
672:             * @param arg set JDBCSouceParameterConnection to value of arg
673:             */
674:            public void setJDBCSourceParameterConnection(String arg) {
675:                this .strJDBCSourceParameterConnection = arg;
676:            }
677:
678:            private String getJDBCDefaultSourceParameterConnection() {
679:                return this .strJDBCDefaultSourceParameterConnection;
680:            }
681:
682:            /**
683:             * Method return JDBCSourceParameterDriver,or if that
684:             * parameter is not defined method will return default value which is
685:             * strJDBCDefaultSourceParameterDriver
686:             * @return JDBCSourceParameterDriver
687:             */
688:            public String getJDBCSourceParameterDriver() {
689:                if (!this .strJDBCSourceParameterDriver.equals(""))
690:                    return this .strJDBCSourceParameterDriver;
691:                else
692:                    return this .strJDBCDefaultSourceParameterDriver;
693:            }
694:
695:            /**
696:             * This method set value of strJDBCSourceParameterDriver parameter
697:             * @param arg set JDBCSouceParameterDriver to value of arg
698:             */
699:            public void setJDBCSourceParameterDriver(String arg) {
700:                this .strJDBCSourceParameterDriver = arg;
701:            }
702:
703:            private String getJDBCDefaultSourceParameterDriver() {
704:                return this .strJDBCDefaultSourceParameterDriver;
705:            }
706:
707:            /**
708:             * Method return JDBCSourceParameterDriver,or if that
709:             * parameter is not defined method will return default value which is
710:             * strJDBCDefaultSourceParameterDriver
711:             * @return JDBCSourceParameterDriver
712:             */
713:            public String getJDBCSourceParameterPassword() {
714:                if (!this .strJDBCSourceParameterPassword.equals(""))
715:                    return this .strJDBCSourceParameterPassword;
716:                else
717:                    return this .strJDBCDefaultSourceParameterPassword;
718:            }
719:
720:            /**
721:             * This method set value of strJDBCSourceParameterPassword parameter
722:             * @param arg setJDBCSourceParameterPassword to value of arg
723:             */
724:            public void setJDBCSourceParameterPassword(String arg) {
725:                this .strJDBCSourceParameterPassword = arg;
726:            }
727:
728:            private String getJDBCDefaultSourceParameterPassword() {
729:                return this .strJDBCDefaultSourceParameterPassword;
730:            }
731:
732:            /**
733:             * Method return JDBCSourceParameterUser,or if that
734:             * parameter is not defined method will return default value which is
735:             * strJDBCDefaultSourceParameterUser
736:             * @return JDBCSourceParameterUser
737:             */
738:            public String getJDBCSourceParameterUser() {
739:                if (!this .strJDBCSourceParameterUser.equals(""))
740:                    return this .strJDBCSourceParameterUser;
741:                else
742:                    return this .strJDBCDefaultSourceParameterUser;
743:            }
744:
745:            /**
746:             * This method set value of strJDBCSourceParameterUser parameter
747:             * @param arg set JDBCSourceParameterUser to value of arg
748:             */
749:            public void setJDBCSourceParameterUser(String arg) {
750:                this .strJDBCSourceParameterUser = arg;
751:            }
752:
753:            private String getJDBCDefaultSourceParameterUser() {
754:                return this .strJDBCDefaultSourceParameterUser;
755:            }
756:
757:            //targets parameters
758:            /**
759:             * Method return JDBCTargetParameterConnection,or if that
760:             * parameter is not defined method will return default value which is
761:             * strJDBCTargetParameterConnection
762:             * @return JDBCTargetParameterConnection
763:             */
764:            public String getJDBCTargetParameterConnection() {
765:                if (!this .strJDBCTargetParameterConnection.equals(""))
766:                    return this .strJDBCTargetParameterConnection;
767:                else
768:                    return this .strJDBCDefaultTargetParameterConnection;
769:            }
770:
771:            /**
772:             * This method set value of strJDBCTargetParameterConnection parameter
773:             * @param arg set JDBCTargetParameterConnection to value of arg
774:             */
775:            public void setJDBCTargetParameterConnection(String arg) {
776:                this .strJDBCTargetParameterConnection = arg;
777:            }
778:
779:            private String getJDBCDefaultTargetParameterConnection() {
780:                return this .strJDBCDefaultTargetParameterConnection;
781:            }
782:
783:            /**
784:             * Method return JDBCTargetParameterDriver,or if that
785:             * parameter is not defined method will return default value which is
786:             * strJDBCDefaultTargetParameterDriver
787:             * @return JDBCTargetParameterDriver
788:             */
789:            public String getJDBCTargetParameterDriver() {
790:                if (!this .strJDBCTargetParameterDriver.equals(""))
791:                    return this .strJDBCTargetParameterDriver;
792:                else
793:                    return this .strJDBCDefaultTargetParameterDriver;
794:            }
795:
796:            /**
797:             * This method set value of strJDBCTargetParameterDriver parameter
798:             * @param arg set JDBCTargetParameterDriver to value of arg
799:             */
800:            public void setJDBCTargetParameterDriver(String arg) {
801:                this .strJDBCTargetParameterDriver = arg;
802:            }
803:
804:            private String getJDBCDefaultTargetParameterDriver() {
805:                return this .strJDBCDefaultTargetParameterDriver;
806:            }
807:
808:            /**
809:             * Method return JDBCTargetParameterPassword,or if that
810:             * parameter is not defined method will return default value which is
811:             * strJDBCDefaultTargetParameterPassword
812:             * @return JDBCTargetParameterPassword
813:             */
814:            public String getJDBCTargetParameterPassword() {
815:                if (!this .strJDBCTargetParameterPassword.equals(""))
816:                    return this .strJDBCTargetParameterPassword;
817:                else
818:                    return this .strJDBCDefaultTargetParameterPassword;
819:            }
820:
821:            /**
822:             * This method set value of strJDBCTargetParameterPassword parmeter
823:             * @param arg set JDBCTargetParameterPassword to value of arg
824:             */
825:            public void setJDBCTargetParameterPassword(String arg) {
826:                this .strJDBCTargetParameterPassword = arg;
827:            }
828:
829:            private String getJDBCDefaultTargetParameterPassword() {
830:                return this .strJDBCDefaultTargetParameterPassword;
831:            }
832:
833:            /**
834:             * Method return JDBCTargetParameterPassword,or if that
835:             * parameter is not defined method will return default value which is
836:             * strJDBCDefaultTargetParameterPassword
837:             * @return JDBCTargetParameterPassword
838:             */
839:            public String getJDBCTargetParameterUser() {
840:                if (!this .strJDBCTargetParameterUser.equals(""))
841:                    return this .strJDBCTargetParameterUser;
842:                else
843:                    return this .strJDBCDefaultTargetParameterUser;
844:            }
845:
846:            /**
847:             * This method set value of strJDBCTargetParameterUser parameter
848:             * @param arg set JDBCTargetParameterUser to value of arg
849:             */
850:            public void setJDBCTargetParameterUser(String arg) {
851:                this .strJDBCTargetParameterUser = arg;
852:            }
853:
854:            private String getJDBCDefaultTargetParameterUser() {
855:                return this .strJDBCDefaultTargetParameterUser;
856:            }
857:
858:            private String getDBVendorDefault() {
859:                return this .strDbVendorDefault;
860:            }
861:
862:            private String getDriverNameDefault() {
863:                return this .strDriverNameDefault;
864:            }
865:
866:            private String getTargetDbVendorDefault() {
867:                return this .strTargetDbVendorDefault;
868:            }
869:
870:            private String getTargetDriverNameDefault() {
871:                return this .strTargetDriverNameDefault;
872:            }
873:
874:            /**
875:             * Method return TargetDBVendor,or if that
876:             * parameter is not defined method will return default value which is
877:             * strTargetDBVendorDefault
878:             * @return TargetDBVendor
879:             */
880:            public String getTargetDBVendor() {
881:                if (!this .strTargetDbVendor.equals(""))
882:                    return this .strTargetDbVendor;
883:                else
884:                    return this .strTargetDbVendorDefault;
885:            }
886:
887:            /**
888:             * Method return TargetDriverName,or if that
889:             * parameter is not defined method will return default value which is
890:             * strTargetDriverNameDefault
891:             * @return TargetDriverName
892:             */
893:            public String getTargetDriverName() {
894:                if (!this .strTargetDriverName.equals(""))
895:                    return this .strTargetDriverName;
896:                else {
897:                    if (this .strTargetDbVendor.equalsIgnoreCase("")
898:                            && this .strTargetDriverName.equalsIgnoreCase("")) {
899:                        return this .strTargetDriverNameDefault;
900:                    } else
901:                        return "";
902:                }
903:            }
904:
905:            /**
906:             * Method return DriverName for source database,or if that
907:             * parameter is not defined method will return default value which is
908:             * strDriverNameDefault
909:             * @return DriverName
910:             */
911:            public String getDriverName() {
912:                if (!this .strDriverName.equals(""))
913:                    return this .strDriverName;
914:                else {
915:                    if (this .strDbVendor.equalsIgnoreCase("")
916:                            && this .strDriverName.equalsIgnoreCase("")) {
917:                        return this .strDriverNameDefault;
918:                    } else
919:                        return "";
920:                }
921:            }
922:
923:            /**
924:             * Method return DbVendor for source database,or if that
925:             * parameter is not defined method will return default value which is
926:             * strDbVendorDefault
927:             * @return DbVendor
928:             */
929:            public String getDbVendor() {
930:                if (!this .strDbVendor.equals(""))
931:                    return this.strDbVendor;
932:                else
933:                    return this.strDbVendorDefault;
934:            }
935:
936:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.