Source Code Cross Referenced for SearchXmlFile.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » generator » 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.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
0003:
0004:
0005:         Copyright (C) 2003  Together
0006:
0007:         This library is free software; you can redistribute it and/or
0008:         modify it under the terms of the GNU Lesser General Public
0009:         License as published by the Free Software Foundation; either
0010:         version 2.1 of the License, or (at your option) any later version.
0011:
0012:         This library is distributed in the hope that it will be useful,
0013:         but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015:         Lesser General Public License for more details.
0016:
0017:         You should have received a copy of the GNU Lesser General Public
0018:         License along with this library; if not, write to the Free Software
0019:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0020:         */
0021:
0022:        package org.webdocwf.util.loader.generator;
0023:
0024:        import javax.xml.parsers.DocumentBuilder;
0025:        import javax.xml.parsers.DocumentBuilderFactory;
0026:
0027:        import org.w3c.dom.Document;
0028:        import org.w3c.dom.Element;
0029:        import org.w3c.dom.NodeList;
0030:        import java.io.File;
0031:
0032:        import java.io.*;
0033:        import java.util.*;
0034:
0035:        import org.enhydra.xml.*;
0036:        import org.webdocwf.util.loader.ConfigReader;
0037:        import org.webdocwf.util.loader.LoaderException;
0038:        import org.webdocwf.util.loader.logging.Logger;
0039:        import org.webdocwf.util.loader.logging.StandardLogger;
0040:
0041:        /**
0042:         *
0043:         * SearchXmlFile class search the named xml document.
0044:         * @author Radoslav Dutina
0045:         * @version 1.0
0046:         */
0047:        public class SearchXmlFile {
0048:
0049:            private SearchElement searchDocument;
0050:            private Document document;
0051:            private String fileName;
0052:            private String jdbcType = null;
0053:            private String sqlType = null;
0054:            private String javaType = null;
0055:            private String oidDbType = null;
0056:            private String versionDbType = null;
0057:            private String oidDbColumnName = null;
0058:            private String versionDbColumnName = null;
0059:            private InputStream is = null;
0060:            private File file = null;
0061:            private String octopusPath = null;
0062:            private String msg = null;
0063:            private Vector allVendors = new Vector();
0064:            private Logger logger = null;
0065:
0066:            /**
0067:             * Construct object SearchXmlFile with associated parameters.
0068:             * @param typePath defines the type of the path. Path can be relative, absolute and jar.
0069:             * If the parameter has value jar, then the xml file is placed in jar file.
0070:             * @param path is the path to named xml file.
0071:             * @throws LoaderException
0072:             */
0073:            public SearchXmlFile(String typePath, String path,
0074:                    String confJarStructure) throws LoaderException {
0075:
0076:                setLogger();
0077:                //				if (this.logger!=null){
0078:                //        	this.logger.write("full", "SearchXmlFile is started.");
0079:                //				}
0080:                DocumentBuilderFactory factory = DocumentBuilderFactory
0081:                        .newInstance();
0082:
0083:                try {
0084:                    octopusPath = System.getProperty("OCTOPUS_HOME");
0085:                    if (octopusPath == null) {
0086:                        if (confJarStructure != null
0087:                                && !confJarStructure.equalsIgnoreCase("")) {
0088:                            is = getClass().getClassLoader()
0089:                                    .getResourceAsStream(
0090:                                            confJarStructure + "/" + path);
0091:                        } else {
0092:                            is = getClass().getClassLoader()
0093:                                    .getResourceAsStream("xml/conf/" + path);
0094:                        }
0095:                    } else {
0096:                        //make the diference if the path is apsolute or relative!
0097:                        if (typePath.equalsIgnoreCase("relative")) {
0098:                            fileName = octopusPath + "/conf/" + path;
0099:                        } else if (typePath.equalsIgnoreCase("absolute")) {
0100:                            fileName = path;
0101:                            //                  check if absolute databaseConfigFile path exist,and if not try to find it in current directory
0102:                            if (!(new File(fileName).exists())) {
0103:                                fileName = octopusPath + "/conf/" + path;
0104:                            }
0105:                        }
0106:                    }
0107:                    if (fileName != null) {
0108:                        file = new File(fileName);
0109:                        if (!file.exists()) {
0110:                            msg = "This " + fileName + " file doesn't exists!!";
0111:                            LoaderException le = new LoaderException(
0112:                                    "Exception:",
0113:                                    (Throwable) new Exception(msg));
0114:                            if (this .logger != null) {
0115:                                this .logger.write("full",
0116:                                        "Exception in SearchXmlFile."
0117:                                                + le.getStackTraceAsString());
0118:                            }
0119:                            throw le;
0120:                        }
0121:                    }
0122:
0123:                    DocumentBuilder builder = factory.newDocumentBuilder();
0124:
0125:                    try {
0126:                        if (octopusPath != null)
0127:                            document = builder.parse(file);
0128:                        else
0129:                            document = builder.parse(is);
0130:
0131:                    } catch (Exception e) {
0132:                        if (fileName != null)
0133:                            msg = "Exception has occurred when application try to parse "
0134:                                    + fileName + " file." + "\n";
0135:                        else
0136:                            msg = "Exception has occurred when application try to parse "
0137:                                    + path + " file placed in jar file." + "\n";
0138:                        LoaderException le = new LoaderException("Exception:"
0139:                                + msg + e.getMessage(), (Throwable) e);
0140:                        if (this .logger != null) {
0141:                            this .logger.write("full",
0142:                                    "Exception in SearchXmlFile." + msg + "\n"
0143:                                            + le.getStackTraceAsString());
0144:                        }
0145:
0146:                        throw le;
0147:                    }
0148:
0149:                } catch (Exception e) {
0150:                    String msg = "Exception in SearchXmlFile.";
0151:                    LoaderException le = new LoaderException(msg + "\n"
0152:                            + e.getMessage(), (Throwable) e);
0153:                    if (this .logger != null) {
0154:                        this .logger.write("full", "Exception in SearchXmlFile."
0155:                                + "\n" + le.getStackTraceAsString());
0156:                    }
0157:                    throw le;
0158:                }
0159:                //				if (this.logger!=null){
0160:                //        	this.logger.write("full", "SearchXmlFile is finished.");
0161:                //				}
0162:
0163:            }
0164:
0165:            /**
0166:             * This method read value of allVendors parameter
0167:             * @return value of parameter
0168:             */
0169:            public Vector getAllVendors() {
0170:                setLogger();
0171:                //		if (this.logger!=null){
0172:                //        this.logger.write("full", "\tgetAllVendors is started.");
0173:                //		}
0174:                searchDocument = (SearchElement) SearchElement
0175:                        .newInstance(document);
0176:                NodeList databaseVendors = searchDocument
0177:                        .getSubElementsByTagName("Database/Vendor");
0178:                if (databaseVendors.getLength() != 0) {
0179:                    for (int i = 0; i < databaseVendors.getLength(); i++) {
0180:                        String vendorName = ((Element) databaseVendors.item(i))
0181:                                .getAttribute("name");
0182:                        String vendorPath = getPathToConf(vendorName);
0183:                        allVendors.add(vendorName);
0184:                    }
0185:                }
0186:                //		if (this.logger!=null){
0187:                //        this.logger.write("full", "\tgetAllVendors is finished.");
0188:                //		}
0189:                return allVendors;
0190:            }
0191:
0192:            /**
0193:             * This method read value of allVendorsPath parameter
0194:             * @return value of parameter
0195:             */
0196:            public Vector getAllVendorsPath() {
0197:                setLogger();
0198:                //		if (this.logger!=null){
0199:                //        this.logger.write("full", "\tgetAllVendorsPath is started.");
0200:                //		}
0201:                searchDocument = (SearchElement) SearchElement
0202:                        .newInstance(document);
0203:                Vector allVendorsPath = new Vector();
0204:                NodeList databaseVendors = searchDocument
0205:                        .getSubElementsByTagName("Database/Vendor");
0206:                if (databaseVendors.getLength() != 0) {
0207:                    for (int i = 0; i < databaseVendors.getLength(); i++) {
0208:                        String vendorName = ((Element) databaseVendors.item(i))
0209:                                .getAttribute("name");
0210:                        String vendorPath = getPathToConf(vendorName);
0211:                        allVendorsPath.add(vendorPath);
0212:                    }
0213:                }
0214:                //		if (this.logger!=null){
0215:                //        this.logger.write("full", "\tgetAllVendorsPath is finished.");
0216:                //		}
0217:                return allVendorsPath;
0218:            }
0219:
0220:            /**
0221:             * This method read value of drivers parameter
0222:             * @return value of parameter
0223:             */
0224:            public Vector getAllDriversForVendor() {
0225:                setLogger();
0226:                //		if (this.logger!=null){
0227:                //        this.logger.write("full", "\tgetAllDriversForVendor is started.");
0228:                //		}
0229:                Vector allDriversForVendor = new Vector();
0230:                Vector drivers = new Vector();
0231:                Vector metaDataDriver = new Vector();
0232:                String sourceVendor = "false";
0233:                searchDocument = (SearchElement) SearchElement
0234:                        .newInstance(document);
0235:                NodeList driverTag = searchDocument
0236:                        .getSubElementsByTagName("Driver");
0237:
0238:                for (int i = 0; i < driverTag.getLength(); i++) {
0239:                    String driverName = ((Element) driverTag.item(i))
0240:                            .getAttribute("name");
0241:                    allDriversForVendor.add(driverName);
0242:
0243:                    NodeList metaData = ((Element) driverTag.item(i))
0244:                            .getElementsByTagName("MetaData");
0245:                    String supportMetaData = ((Element) metaData.item(0))
0246:                            .getAttribute("value");
0247:
0248:                    if (supportMetaData.equalsIgnoreCase("true")) {
0249:                        metaDataDriver.add(driverName);
0250:                        sourceVendor = "true";
0251:                    }
0252:                }
0253:                drivers.add(allDriversForVendor);
0254:                drivers.add(metaDataDriver);
0255:                drivers.add(sourceVendor);
0256:                //		if (this.logger!=null){
0257:                //        this.logger.write("full", "\tgetAllDriversForVendor is finished.");
0258:                //		}
0259:                return drivers;
0260:
0261:            }
0262:
0263:            /**
0264:             * This method search the named xml document, and read the value of pathToConf parameter
0265:             * which represents the path of the conf file, for the named database.
0266:             * @param database_Type is the type of the database.
0267:             * @return value of paramter.
0268:             */
0269:            public String getPathToConf(String database_Type) {
0270:                setLogger();
0271:                //		if (this.logger!=null){
0272:                //				this.logger.write("full", "\tgetPathToConf is started.");
0273:                //		}
0274:                searchDocument = (SearchElement) SearchElement
0275:                        .newInstance(document);
0276:                //ZK 18.6 2004 commented this. It was problem with reading xml file from jar.
0277:                //if(octopusPath!=null){
0278:                NodeList databaseType = searchDocument
0279:                        .getSubElementsByCondition("Database/Vendor@name="
0280:                                + database_Type);
0281:                if (databaseType.getLength() != 0) {
0282:                    String pathToConf = databaseType.item(0).getFirstChild()
0283:                            .getNodeValue();
0284:                    //			if (this.logger!=null){
0285:                    //						this.logger.write("full", "\tgetPathToConf is finished.");
0286:                    //			}
0287:                    return pathToConf;
0288:                } else {
0289:                    //			if (this.logger!=null){
0290:                    //						this.logger.write("full", "\tgetPathToConf is finished.");
0291:                    //			}
0292:                    return null;
0293:                }
0294:
0295:            }
0296:
0297:            /**
0298:             * This method search the named xml document, and read the value of driverClassName parameter,
0299:             * which represents driver class for the named driver.
0300:             * @param driverName is the name of the driver.
0301:             * @param jdbcParameters is reference to JdbcParameters object.
0302:             * @param generatorParameters is object of InputParameters class
0303:             * @throws LoaderException
0304:             */
0305:            public void getClassName(String driverName,
0306:                    JdbcParameters jdbcParameters,
0307:                    InputParameters generatorParameters) throws LoaderException {
0308:                setLogger();
0309:                //		if (this.logger!=null){
0310:                //				this.logger.write("full", "\tgetClassName is started.");
0311:                //		}
0312:                searchDocument = (SearchElement) SearchElement
0313:                        .newInstance(document);
0314:                NodeList driverTag = null;
0315:                if (driverName.equalsIgnoreCase("")) {
0316:                    driverTag = searchDocument
0317:                            .getSubElementsByTagName("Driver");
0318:                } else {
0319:                    driverTag = searchDocument
0320:                            .getSubElementsByCondition("Driver@name="
0321:                                    + driverName);
0322:                }
0323:                if (driverTag.getLength() != 0) {
0324:                    NodeList classNameTag = ((Element) driverTag.item(0))
0325:                            .getElementsByTagName("ClassName");
0326:                    if (classNameTag.getLength() == 0) {
0327:                        if (fileName != null)
0328:                            msg = "In "
0329:                                    + fileName
0330:                                    + " file for this database, you don't have ClassName tag!";
0331:                        else
0332:                            msg = "In "
0333:                                    + octopusPath
0334:                                    + " ( in .jar) file for this database, you don't have ClassName tag!";
0335:
0336:                        LoaderException le = new LoaderException("Exception:",
0337:                                (Throwable) new Exception(msg));
0338:                        if (this .logger != null) {
0339:                            this .logger.write("full", "Exception:" + "\n"
0340:                                    + le.getStackTraceAsString());
0341:                        }
0342:
0343:                        throw le;
0344:                    }
0345:                    jdbcParameters.setDriverClassName(((Element) classNameTag
0346:                            .item(0)).getAttribute("value"));
0347:
0348:                    NodeList connectionTag = ((Element) driverTag.item(0))
0349:                            .getElementsByTagName("Connection");
0350:                    if (connectionTag.getLength() == 0) {
0351:                        if (fileName != null)
0352:                            msg = "In "
0353:                                    + fileName
0354:                                    + " file for this database, you don't have Connection tag!";
0355:                        else
0356:                            msg = "In "
0357:                                    + octopusPath
0358:                                    + " ( in .jar) file for this database, you don't have Connection tag!";
0359:                        LoaderException le = new LoaderException("Exception:",
0360:                                (Throwable) new Exception(msg));
0361:                        if (this .logger != null) {
0362:                            this .logger.write("full", "Exception:" + "\n"
0363:                                    + le.getStackTraceAsString());
0364:                        }
0365:                        throw le;
0366:                    }
0367:                    jdbcParameters.setConnection(((Element) connectionTag
0368:                            .item(0)).getAttribute("value"));
0369:                    //      NodeList alterTableTag= ((Element)driverTag.item(0)).getElementsByTagName("AlterTablePrimaryKey");
0370:                    //      if(alterTableTag.getLength()==0){
0371:                    //        if(fileName!=null)
0372:                    //          msg= "In "+fileName+" file for this database, you don't have AlterTablePrimaryKey tag!";
0373:                    //        else
0374:                    //          msg= "In "+octopusPath+" ( in .jar) file for this database, you don't have AlterTablePrimaryKey tag!";
0375:                    //        LoaderException le = new LoaderException(msg);
0376:                    //        throw le;
0377:                    //      }
0378:                    //      jdbcParameters.setAlterTablePrimaryKey(((Element)alterTableTag.item(0)).getAttribute("value"));
0379:                    //      generatorParameters.setAlterTablePrimaryKey(((Element)alterTableTag.item(0)).getAttribute("value"));
0380:                } else {
0381:                    if (fileName != null)
0382:                        msg = "In "
0383:                                + fileName
0384:                                + " file for this database, specified driver name ("
0385:                                + driverName + ") is not valid!";
0386:                    else
0387:                        msg = "In "
0388:                                + octopusPath
0389:                                + " ( in .jar) file for this database, specified driver name ("
0390:                                + driverName + ") is not valid!";
0391:                    LoaderException le = new LoaderException("Exception:",
0392:                            (Throwable) new Exception(msg));
0393:                    if (this .logger != null) {
0394:                        this .logger.write("full", "Exception:" + "\n"
0395:                                + le.getStackTraceAsString());
0396:                    }
0397:
0398:                    throw le;
0399:                }
0400:                //		if (this.logger!=null){
0401:                //				this.logger.write("full", "\tgetClassName is finished.");
0402:                //		}
0403:            }
0404:
0405:            public Vector getFileSystemDatabase(String driverName)
0406:                    throws LoaderException {
0407:                setLogger();
0408:                //		if (this.logger!=null){
0409:                //				this.logger.write("full", "\tgetFileSystemDatabase is started.");
0410:                //		}
0411:                Vector driverProperties = new Vector();
0412:                String strFileSystemDatabase = "";
0413:                String strConnection = "";
0414:
0415:                searchDocument = (SearchElement) SearchElement
0416:                        .newInstance(document);
0417:                NodeList driverTag = null;
0418:                if (driverName.equalsIgnoreCase("")) {
0419:                    driverTag = searchDocument
0420:                            .getSubElementsByTagName("Driver");
0421:                } else {
0422:                    driverTag = searchDocument
0423:                            .getSubElementsByCondition("Driver@name="
0424:                                    + driverName);
0425:                }
0426:                if (driverTag.getLength() != 0) {
0427:                    //FileSystemDatabase tag
0428:                    NodeList fileSystemDatabaseTag = ((Element) driverTag
0429:                            .item(0))
0430:                            .getElementsByTagName("FileSystemDatabase");
0431:                    if (fileSystemDatabaseTag.getLength() == 0) {
0432:                        if (fileName != null)
0433:                            msg = "In "
0434:                                    + fileName
0435:                                    + " file for this database, you don't have FileSystemDatabase tag!";
0436:                        else
0437:                            msg = "In "
0438:                                    + octopusPath
0439:                                    + " ( in .jar) file for this database, you don't have FileSystemDatabase tag!";
0440:                        LoaderException le = new LoaderException("Exception:",
0441:                                (Throwable) new Exception(msg));
0442:                        if (this .logger != null) {
0443:                            this .logger.write("full", "Exception:"
0444:                                    + le.getStackTraceAsString());
0445:                        }
0446:                        throw le;
0447:                    } else {
0448:                        strFileSystemDatabase = ((Element) fileSystemDatabaseTag
0449:                                .item(0)).getAttribute("value");
0450:                    }
0451:
0452:                    //Connection
0453:                    NodeList connectionTag = ((Element) driverTag.item(0))
0454:                            .getElementsByTagName("Connection");
0455:                    if (connectionTag.getLength() == 0) {
0456:                        if (fileName != null)
0457:                            msg = "In "
0458:                                    + fileName
0459:                                    + " file for this database, you don't have Connection tag!";
0460:                        else
0461:                            msg = "In "
0462:                                    + octopusPath
0463:                                    + " ( in .jar) file for this database, you don't have Connection tag!";
0464:                        LoaderException le = new LoaderException("Exception:",
0465:                                (Throwable) new Exception(msg));
0466:                        if (this .logger != null) {
0467:                            this .logger.write("full", "Exception:"
0468:                                    + le.getStackTraceAsString());
0469:                        }
0470:
0471:                        throw le;
0472:                    } else {
0473:                        strConnection = ((Element) connectionTag.item(0))
0474:                                .getAttribute("value");
0475:                    }
0476:
0477:                } else {
0478:                    if (fileName != null)
0479:                        msg = "In "
0480:                                + fileName
0481:                                + " file for this database, specified driver name ("
0482:                                + driverName + ") is not valid!";
0483:                    else
0484:                        msg = "In "
0485:                                + octopusPath
0486:                                + " ( in .jar) file for this database, specified driver name ("
0487:                                + driverName + ") is not valid!";
0488:                    LoaderException le = new LoaderException("Exception:",
0489:                            (Throwable) new Exception(msg));
0490:                    if (this .logger != null) {
0491:                        this .logger.write("full", "Exception:"
0492:                                + le.getStackTraceAsString());
0493:                    }
0494:                    throw le;
0495:                }
0496:                driverProperties.add(strFileSystemDatabase);
0497:                driverProperties.add(strConnection);
0498:                //		if (this.logger!=null){
0499:                //				this.logger.write("full", "\tgetFileSystemDatabase is finished.");
0500:                //		}
0501:                return driverProperties;
0502:            }
0503:
0504:            public String getMaxConstraintLength(String driverName)
0505:                    throws LoaderException {
0506:                setLogger();
0507:                //		if (this.logger!=null){
0508:                //				this.logger.write("full", "\tgetMaxConstraintLength is started.");
0509:                //		}
0510:                String maxConstraintLength = "-1";
0511:                searchDocument = (SearchElement) SearchElement
0512:                        .newInstance(document);
0513:                NodeList driverTag = null;
0514:                if (driverName.equalsIgnoreCase("")) {
0515:                    driverTag = searchDocument
0516:                            .getSubElementsByTagName("Driver");
0517:                } else {
0518:                    driverTag = searchDocument
0519:                            .getSubElementsByCondition("Driver@name="
0520:                                    + driverName);
0521:                }
0522:                if (driverTag.getLength() != 0) {
0523:                    try {
0524:                        NodeList maxConstraintLengthTag = ((Element) driverTag
0525:                                .item(0))
0526:                                .getElementsByTagName("MaxConstraintLength");
0527:
0528:                        maxConstraintLength = ((Element) maxConstraintLengthTag
0529:                                .item(0)).getAttribute("value");
0530:
0531:                    } catch (Exception ex) {
0532:                        if (fileName != null)
0533:                            msg = "In "
0534:                                    + fileName
0535:                                    + " file for this database, you don't have maxConstraintLenght tag!";
0536:                        else
0537:                            msg = "In "
0538:                                    + octopusPath
0539:                                    + " ( in .jar) file for this database, you don't have maxConstraintLenght tag!";
0540:                        LoaderException le = new LoaderException("Exception:",
0541:                                new Exception(msg));
0542:                        if (this .logger != null) {
0543:                            this .logger.write("full", "Exception:" + "\n"
0544:                                    + le.getStackTraceAsString());
0545:                        }
0546:
0547:                        throw le;
0548:                    }
0549:
0550:                }
0551:                //		if (this.logger!=null){
0552:                //				this.logger.write("full", "\tgetMaxConstraintLength is finished.");
0553:                //		}
0554:                return maxConstraintLength;
0555:            }
0556:
0557:            /**
0558:             * This method set value of alterTablePrimaryKey parameter
0559:             * @param driverName is name of the driver
0560:             * @return value of parameter
0561:             * @throws LoaderException
0562:             */
0563:            public String getAlterTablePrimaryKey(String driverName)
0564:                    throws LoaderException {
0565:                setLogger();
0566:                //		if (this.logger!=null){
0567:                //				this.logger.write("full", "\tgetAlterTablePrimaryKey is started.");
0568:                //		}
0569:                searchDocument = (SearchElement) SearchElement
0570:                        .newInstance(document);
0571:                NodeList driverTag = null;
0572:                if (driverName.equalsIgnoreCase("")) {
0573:                    driverTag = searchDocument
0574:                            .getSubElementsByTagName("Driver");
0575:                } else {
0576:                    driverTag = searchDocument
0577:                            .getSubElementsByCondition("Driver@name="
0578:                                    + driverName);
0579:                }
0580:                if (driverTag.getLength() != 0) {
0581:                    NodeList alterTableTag = ((Element) driverTag.item(0))
0582:                            .getElementsByTagName("AlterTablePrimaryKey");
0583:                    if (alterTableTag.getLength() == 0) {
0584:                        if (fileName != null)
0585:                            msg = "In "
0586:                                    + fileName
0587:                                    + " file for this database, you don't have AlterTablePrimaryKey tag!";
0588:                        else
0589:                            msg = "In "
0590:                                    + octopusPath
0591:                                    + " ( in .jar) file for this database, you don't have AlterTablePrimaryKey tag!";
0592:                        LoaderException le = new LoaderException("Exception:",
0593:                                (Throwable) new Exception(msg));
0594:                        if (this .logger != null) {
0595:                            this .logger.write("full", "Exception:"
0596:                                    + le.getStackTraceAsString());
0597:                        }
0598:                        throw le;
0599:                    } else {
0600:                        String ret = ((Element) alterTableTag.item(0))
0601:                                .getAttribute("value");
0602:                        //				if (this.logger!=null){
0603:                        //								this.logger.write("full", "\tgetAlterTablePrimaryKey is finished.");
0604:                        //				}
0605:                        return ret;
0606:                    }
0607:
0608:                } else {
0609:                    if (fileName != null)
0610:                        msg = "In "
0611:                                + fileName
0612:                                + " file for this database, specified driver name ("
0613:                                + driverName + ") is not valid!";
0614:                    else
0615:                        msg = "In "
0616:                                + octopusPath
0617:                                + " ( in .jar) file for this database, specified driver name ("
0618:                                + driverName + ") is not valid!";
0619:                    LoaderException le = new LoaderException("Exception:",
0620:                            (Throwable) new Exception(msg));
0621:                    if (this .logger != null) {
0622:                        this .logger.write("full", "Exception:"
0623:                                + le.getStackTraceAsString());
0624:                    }
0625:                    throw le;
0626:                }
0627:
0628:            }
0629:
0630:            /**
0631:             * This method search the named xml document, and read the value of jdbcType parameter,
0632:             * which represents the jdbc type of data of the named  sql type of data.
0633:             * @param sql_Type is the sql type of data.
0634:             * @return jdbc type of data.
0635:             * @throws LoaderException
0636:             */
0637:            public String getJDBCFromSQLType(String sql_Type)
0638:                    throws LoaderException {
0639:                setLogger();
0640:                //		if (this.logger!=null){
0641:                //				this.logger.write("full", "\tgetJDBCFromSQLType is started.");
0642:                //		}
0643:                searchDocument = (SearchElement) SearchElement
0644:                        .newInstance(document);
0645:                //TODO zoran added this line
0646:                sql_Type = Utils.replaceAll(sql_Type, " ",
0647:                        ConfigReader.SPACE_ESCAPE);
0648:                NodeList SQLTypeTag = searchDocument
0649:                        .getSubElementsByTagName("SQLType/"
0650:                                + sql_Type.toUpperCase());
0651:                if (SQLTypeTag.getLength() != 0) {
0652:                    jdbcType = SQLTypeTag.item(0).getFirstChild()
0653:                            .getNodeValue();
0654:                } else {
0655:                    String msg = "This type of data (" + sql_Type
0656:                            + ") doesn't exists in the source table conf file!";
0657:                    LoaderException le = new LoaderException("Exception:",
0658:                            new Exception(msg));
0659:                    if (this .logger != null) {
0660:                        this .logger.write("full", "Exception:"
0661:                                + le.getStackTraceAsString());
0662:                    }
0663:
0664:                    throw le;
0665:                }
0666:                //		if (this.logger!=null){
0667:                //				this.logger.write("full", "\tgetJDBCFromSQLType is finished.");
0668:                //		}
0669:                return jdbcType;
0670:            }
0671:
0672:            //ZK added this method 5.5 2004
0673:            /**
0674:             * This method search the named xml document, and read the value of hasSize parameter
0675:             * @return hasSize.
0676:             * @throws LoaderException
0677:             */
0678:            public Hashtable getHasSize() throws LoaderException {
0679:                setLogger();
0680:                //		if (this.logger!=null){
0681:                //				this.logger.write("full", "\tgetHasSize is started.");
0682:                //		}
0683:                Hashtable resHashtable = new Hashtable();
0684:                searchDocument = (SearchElement) SearchElement
0685:                        .newInstance(document);
0686:                NodeList SQLTypesTagX = searchDocument
0687:                        .getSubElementsByTagName("SQLType");
0688:                NodeList SQLTypesTag = SQLTypesTagX.item(0).getChildNodes();
0689:                if (SQLTypesTag.getLength() != 0) {
0690:                    for (int i = 0; i < SQLTypesTag.getLength(); i++) {
0691:                        if (!(SQLTypesTag.item(i) instanceof  org.enhydra.xml.SearchElement))
0692:                            continue;
0693:                        String hasSize = ((Element) SQLTypesTag.item(i))
0694:                                .getAttribute("hasSize");
0695:                        if (hasSize == null || hasSize.equalsIgnoreCase(""))
0696:                            hasSize = "false";
0697:                        String nodeName = ((Element) SQLTypesTag.item(i))
0698:                                .getNodeName();
0699:                        nodeName = Utils.replaceAll(nodeName,
0700:                                ConfigReader.SPACE_ESCAPE, " ");
0701:                        resHashtable.put(nodeName, hasSize);
0702:                    }
0703:                } else {
0704:                    String msg = "Exception in method getHasSize in class SearchXmlFile.";
0705:                    LoaderException le = new LoaderException("Exception:",
0706:                            (Throwable) new Exception(msg));
0707:                    if (this .logger != null) {
0708:                        this .logger.write("full", "Error:"
0709:                                + le.getStackTraceAsString());
0710:                    }
0711:                    throw le;
0712:                }
0713:                //		if (this.logger!=null){
0714:                //				this.logger.write("full", "\tgetHasSize is finished.");
0715:                //		}
0716:                return resHashtable;
0717:            }
0718:
0719:            /**
0720:             * This method search the named xml document, and read the value of isDecimal parameter
0721:             * @return hasSize.
0722:             * @throws LoaderException
0723:             */
0724:            public Hashtable getIsDecimal() throws LoaderException {
0725:                setLogger();
0726:                //		if (this.logger!=null){
0727:                //				this.logger.write("full", "\tgetIsDecimal is started.");
0728:                //		}
0729:                Hashtable resHashtable = new Hashtable();
0730:                searchDocument = (SearchElement) SearchElement
0731:                        .newInstance(document);
0732:                NodeList SQLTypesTagX = searchDocument
0733:                        .getSubElementsByTagName("SQLType");
0734:                NodeList SQLTypesTag = SQLTypesTagX.item(0).getChildNodes();
0735:                if (SQLTypesTag.getLength() != 0) {
0736:                    for (int i = 0; i < SQLTypesTag.getLength(); i++) {
0737:                        if (!(SQLTypesTag.item(i) instanceof  org.enhydra.xml.SearchElement))
0738:                            continue;
0739:                        String hasSize = ((Element) SQLTypesTag.item(i))
0740:                                .getAttribute("isDecimal");
0741:                        if (hasSize == null || hasSize.equalsIgnoreCase(""))
0742:                            hasSize = "false";
0743:                        String nodeName = ((Element) SQLTypesTag.item(i))
0744:                                .getNodeName();
0745:                        nodeName = Utils.replaceAll(nodeName,
0746:                                ConfigReader.SPACE_ESCAPE, " ");
0747:                        resHashtable.put(nodeName, hasSize);
0748:                    }
0749:                } else {
0750:                    String msg = "Exception in method getIsDecimal in class SearchXmlFile.";
0751:                    LoaderException le = new LoaderException("Exception:",
0752:                            new Exception(msg));
0753:                    if (this .logger != null) {
0754:                        this .logger.write("full", "Error:"
0755:                                + le.getStackTraceAsString());
0756:                    }
0757:                    throw le;
0758:                }
0759:                //		if (this.logger!=null){
0760:                //				this.logger.write("full", "\tgetIsDecimal is finished.");
0761:                //		}
0762:                return resHashtable;
0763:            }
0764:
0765:            /**
0766:             * This method search the named xml document, and read the value of sqlType parameter,
0767:             * which represents the sql type of data of the named jdbc type of data.
0768:             * @param jdbc_Type is the jdbc type of data.
0769:             * @return the sql type of data.
0770:             * @throws LoaderException
0771:             */
0772:            public String getSQLFromJDBCType(String jdbc_Type)
0773:                    throws LoaderException {
0774:                setLogger();
0775:                //		if (this.logger!=null){
0776:                //				this.logger.write("full", "\tgetSQLFromJDBCType is started.");
0777:                //		}
0778:                searchDocument = (SearchElement) SearchElement
0779:                        .newInstance(document);
0780:                NodeList JDBCTypeTag = searchDocument
0781:                        .getSubElementsByTagName("JDBCType/"
0782:                                + jdbc_Type.toUpperCase());
0783:                if (JDBCTypeTag.getLength() != 0) {
0784:                    sqlType = JDBCTypeTag.item(0).getFirstChild()
0785:                            .getNodeValue();
0786:                } else {
0787:                    String msg = "This type of data (" + jdbc_Type
0788:                            + ") doesn't exists on the target table conf file!";
0789:                    LoaderException le = new LoaderException("Exception:",
0790:                            new Exception(msg));
0791:                    if (this .logger != null) {
0792:                        this .logger.write("full", "Error:"
0793:                                + le.getStackTraceAsString());
0794:                    }
0795:                    throw le;
0796:                }
0797:                //		if (this.logger!=null){
0798:                //				this.logger.write("full", "\tgetSQLFromJDBCType is finished.");
0799:                //		}
0800:                return sqlType;
0801:            }
0802:
0803:            /**
0804:             * This method search the named xml document, and read the value of javaType parameter,
0805:             * which represents the java type of data of the named jdbc type of data.
0806:             * @param java_Type is the jdbc type of data.
0807:             * @return java type of data.
0808:             * @throws LoaderException
0809:             */
0810:            public String getJAVAType(String java_Type) throws LoaderException {
0811:                setLogger();
0812:                //		if (this.logger!=null){
0813:                //				this.logger.write("full", "\tgetJAVAType is started.");
0814:                //		}
0815:                searchDocument = (SearchElement) SearchElement
0816:                        .newInstance(document);
0817:                java_Type = Utils.replaceAll(java_Type, " ",
0818:                        ConfigReader.SPACE_ESCAPE);
0819:                NodeList JAVATypeTag = searchDocument
0820:                        .getSubElementsByTagName("JAVAType/"
0821:                                + java_Type.toUpperCase());
0822:                if (JAVATypeTag.getLength() != 0) {
0823:                    javaType = JAVATypeTag.item(0).getFirstChild()
0824:                            .getNodeValue();
0825:                } else {
0826:                    String msg = "This type of data (" + java_Type
0827:                            + ") doesn't exists in Java Type class!";
0828:                    LoaderException le = new LoaderException("Exception:",
0829:                            new Exception(msg));
0830:                    if (this .logger != null) {
0831:                        this .logger.write("full", "Error:"
0832:                                + le.getStackTraceAsString());
0833:                    }
0834:                    throw le;
0835:                }
0836:                //		if (this.logger!=null){
0837:                //				this.logger.write("full", "\tgetJAVAType is finished.");
0838:                //		}
0839:                return javaType;
0840:            }
0841:
0842:            /**
0843:             * This method search the named xml document, and read the value of oidDbType parameter, which
0844:             * represents the oid type for the named database.
0845:             * @return oid type.
0846:             * @throws LoaderException
0847:             */
0848:            public String getOidDB() throws LoaderException {
0849:                setLogger();
0850:                //		if (this.logger!=null){
0851:                //				this.logger.write("full", "\tgetOidDB is started.");
0852:                //		}
0853:                searchDocument = (SearchElement) SearchElement
0854:                        .newInstance(document);
0855:                NodeList OidDb = searchDocument
0856:                        .getSubElementsByTagName("OidDbType");
0857:                if (OidDb.getLength() != 0) {
0858:                    this .oidDbType = OidDb.item(0).getFirstChild()
0859:                            .getNodeValue();
0860:                } else {
0861:                    String msg = "You must cofigure your conf file for this Oid type!";
0862:                    LoaderException le = new LoaderException("Exception:",
0863:                            new Exception(msg));
0864:                    if (this .logger != null) {
0865:                        this .logger.write("full", "Error:"
0866:                                + le.getStackTraceAsString());
0867:                    }
0868:                    throw le;
0869:                }
0870:                //		if (this.logger!=null){
0871:                //				this.logger.write("full", "\tgetOidDB is finished.");
0872:                //		}
0873:                return oidDbType;
0874:            }
0875:
0876:            /**
0877:             * This method search the named xml document, and read the value of versionDbType parameter, which
0878:             * represents the version type of the named database.
0879:             * @return version type.
0880:             * @throws LoaderException
0881:             */
0882:            public String getVersionDb() throws LoaderException {
0883:                setLogger();
0884:                //		if (this.logger!=null){
0885:                //				this.logger.write("full", "\tgetVersionDb is started.");
0886:                //		}
0887:                searchDocument = (SearchElement) SearchElement
0888:                        .newInstance(document);
0889:                NodeList VersionDb = searchDocument
0890:                        .getSubElementsByTagName("VersionDbType");
0891:                if (VersionDb.getLength() != 0) {
0892:                    this .versionDbType = VersionDb.item(0).getFirstChild()
0893:                            .getNodeValue();
0894:                } else {
0895:                    String msg = "You must cofigure yoor conf file for this Version type!";
0896:                    LoaderException le = new LoaderException("Exception:",
0897:                            new Exception(msg));
0898:                    if (this .logger != null) {
0899:                        this .logger.write("full", "Error:"
0900:                                + le.getStackTraceAsString());
0901:                    }
0902:                    throw le;
0903:                }
0904:                //		if (this.logger!=null){
0905:                //				this.logger.write("full", "\tgetVersionDb is finished.");
0906:                //		}
0907:                return versionDbType;
0908:            }
0909:
0910:            /**
0911:             * This method search the named xml document, and read the value of oidDbColumnName parameter,
0912:             * which represents the oid name for the named database.
0913:             * @return oid name.
0914:             * @throws LoaderException
0915:             */
0916:            public String getOidDbColumn() throws LoaderException {
0917:                setLogger();
0918:                //		if (this.logger!=null){
0919:                //				this.logger.write("full", "\tgetOidDbColumn is started.");
0920:                //		}
0921:                searchDocument = (SearchElement) SearchElement
0922:                        .newInstance(document);
0923:                NodeList OidDbColumn = searchDocument
0924:                        .getSubElementsByTagName("OidDbColumnName");
0925:                if (OidDbColumn.getLength() != 0) {
0926:                    this .oidDbColumnName = OidDbColumn.item(0).getFirstChild()
0927:                            .getNodeValue();
0928:                } else {
0929:                    String msg = "You must cofigure yoor conf file for this Oid name!";
0930:                    LoaderException le = new LoaderException("Exception:",
0931:                            new Exception(msg));
0932:                    if (this .logger != null) {
0933:                        this .logger.write("full", "Error:"
0934:                                + le.getStackTraceAsString());
0935:                    }
0936:                    throw le;
0937:                }
0938:                //		if (this.logger!=null){
0939:                //				this.logger.write("full", "\tgetOidDbColumn is finished.");
0940:                //		}
0941:                return oidDbColumnName;
0942:            }
0943:
0944:            /**
0945:             * This method search the named xml document, and read the value of versionDbColumnName parameter,
0946:             * which represents the version name of the named database.
0947:             * @return version name.
0948:             * @throws LoaderException
0949:             */
0950:            public String getVersionDbColumn() throws LoaderException {
0951:                setLogger();
0952:                //		if (this.logger!=null){
0953:                //				this.logger.write("full", "\tgetVersionDbColumn is started.");
0954:                //		}
0955:                searchDocument = (SearchElement) SearchElement
0956:                        .newInstance(document);
0957:                NodeList VersionDbColumn = searchDocument
0958:                        .getSubElementsByTagName("VersionDbColumnName");
0959:                if (VersionDbColumn.getLength() != 0) {
0960:                    this .versionDbColumnName = VersionDbColumn.item(0)
0961:                            .getFirstChild().getNodeValue();
0962:                } else {
0963:                    String msg = "You must cofigure yoor conf file for this Version name!";
0964:                    LoaderException le = new LoaderException("Exception:",
0965:                            new Exception(msg));
0966:                    if (this .logger != null) {
0967:                        this .logger.write("full", "Error:"
0968:                                + le.getStackTraceAsString());
0969:                    }
0970:                    throw le;
0971:                }
0972:                //		if (this.logger!=null){
0973:                //				this.logger.write("full", "\tgetVersionDbColumn is finished.");
0974:                //		}
0975:                return versionDbColumnName;
0976:            }
0977:
0978:            /**
0979:             * This method search the named xml document, and read the value of name (Driver) parameter,
0980:             * which represents the driver name.
0981:             * @return value of parameter.
0982:             */
0983:            public String getDriverName() {
0984:                setLogger();
0985:                //		if (this.logger!=null){
0986:                //				this.logger.write("full", "\tgetDriverName is started.");
0987:                //		}
0988:                searchDocument = (SearchElement) SearchElement
0989:                        .newInstance(document);
0990:                NodeList driverTag = searchDocument
0991:                        .getSubElementsByTagName("Driver");
0992:                //		if (this.logger!=null){
0993:                //				this.logger.write("full", "\tgetDriverName is finished.");
0994:                //		}
0995:                return ((Element) driverTag.item(0)).getAttribute("name");
0996:
0997:            }
0998:
0999:            public String getExcludedTables() throws LoaderException {
1000:                setLogger();
1001:                //		if (this.logger!=null){
1002:                //				this.logger.write("full", "\tgetExcludedTables is started.");
1003:                //		}
1004:                String ret = "";
1005:                searchDocument = (SearchElement) SearchElement
1006:                        .newInstance(document);
1007:                NodeList excludeTableTag = searchDocument
1008:                        .getSubElementsByTagName("ExcludeTables");
1009:                if (excludeTableTag.getLength() != 0) {
1010:                    if (excludeTableTag.item(0).getFirstChild() != null)
1011:                        ret = excludeTableTag.item(0).getFirstChild()
1012:                                .getNodeValue();
1013:                    else
1014:                        ret = "";
1015:                } else {
1016:                    String msg = "ExcludeTables tag doesn't exist in source conf file!";
1017:                    LoaderException le = new LoaderException("Exception:",
1018:                            (Throwable) new Exception(msg));
1019:                    if (this .logger != null) {
1020:                        this .logger.write("full", "Error:"
1021:                                + le.getStackTraceAsString());
1022:                    }
1023:                    throw le;
1024:                }
1025:                //		if (this.logger!=null){
1026:                //				this.logger.write("full", "\tgetExcludedTables is finished.");
1027:                //		}
1028:                return ret;
1029:            }
1030:
1031:            /**
1032:             * This method will set logger object
1033:             * @param logger
1034:             */
1035:            private void setLogger() {
1036:                this.logger = StandardLogger.getCentralLogger();
1037:            }
1038:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.