View Javadoc
1 2 /* 3 LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus. 4 5 6 Copyright (C) 2003 Together 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 */ 22 23 package org.webdocwf.util.loader.generator; 24 25 import javax.xml.parsers.DocumentBuilder; 26 import javax.xml.parsers.DocumentBuilderFactory; 27 28 import org.w3c.dom.Document; 29 import org.w3c.dom.Element; 30 import org.w3c.dom.NodeList; 31 import java.io.File; 32 33 import java.io.*; 34 import java.util.*; 35 36 import org.enhydra.xml.*; 37 import org.webdocwf.util.loader.ConfigReader; 38 import org.webdocwf.util.loader.LoaderException; 39 import org.webdocwf.util.loader.logging.Logger; 40 import org.webdocwf.util.loader.logging.StandardLogger; 41 42 /*** 43 * 44 * SearchXmlFile class search the named xml document. 45 * @author Radoslav Dutina 46 * @version 1.0 47 */ 48 public class SearchXmlFile { 49 50 private SearchElement searchDocument; 51 private Document document; 52 private String fileName; 53 private String jdbcType = null; 54 private String sqlType = null; 55 private String javaType = null; 56 private String oidDbType = null; 57 private String versionDbType = null; 58 private String oidDbColumnName = null; 59 private String versionDbColumnName = null; 60 private InputStream is = null; 61 private File file = null; 62 private String octopusPath = null; 63 private String msg = null; 64 private Vector allVendors = new Vector(); 65 private Logger logger = null; 66 /*** 67 * Construct object SearchXmlFile with associated parameters. 68 * @param typePath defines the type of the path. Path can be relative, absolute and jar. 69 * If the parameter has value jar, then the xml file is placed in jar file. 70 * @param path is the path to named xml file. 71 * @throws LoaderException 72 */ 73 public SearchXmlFile(String typePath, String path, String confJarStructure) throws LoaderException { 74 75 76 setLogger(); 77 // if (this.logger!=null){ 78 // this.logger.write("full", "SearchXmlFile is started."); 79 // } 80 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 81 82 try { 83 octopusPath = System.getProperty("OCTOPUS_HOME"); 84 if (octopusPath == null) { 85 if (confJarStructure != null && !confJarStructure.equalsIgnoreCase("")) { 86 is = getClass().getClassLoader().getResourceAsStream(confJarStructure + "/" + path); 87 } else { 88 is = getClass().getClassLoader().getResourceAsStream("xml/conf/" + path); 89 } 90 } else { 91 //make the diference if the path is apsolute or relative! 92 if (typePath.equalsIgnoreCase("relative")) { 93 fileName = octopusPath + "/conf/" + path; 94 } else if (typePath.equalsIgnoreCase("absolute")) { 95 fileName = path; 96 // check if absolute databaseConfigFile path exist,and if not try to find it in current directory 97 if(!(new File(fileName).exists())) { 98 fileName = octopusPath + "/conf/" + path; 99 } 100 } 101 } 102 if (fileName != null) { 103 file = new File(fileName); 104 if (!file.exists()) { 105 msg = "This " + fileName + " file doesn't exists!!"; 106 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 107 if (this.logger!=null){ 108 this.logger.write("full", "Exception in SearchXmlFile." + le.getStackTraceAsString()); 109 } 110 throw le; 111 } 112 } 113 114 DocumentBuilder builder = factory.newDocumentBuilder(); 115 116 try { 117 if (octopusPath != null) 118 document = builder.parse(file); 119 else 120 document = builder.parse(is); 121 122 } catch (Exception e) { 123 if (fileName != null) 124 msg = "Exception has occurred when application try to parse " + fileName + " file." + "\n"; 125 else 126 msg = "Exception has occurred when application try to parse " + path + " file placed in jar file." + "\n"; 127 LoaderException le = new LoaderException("Exception:" + msg + e.getMessage(), (Throwable) e); 128 if (this.logger!=null){ 129 this.logger.write("full", "Exception in SearchXmlFile." + msg +"\n" + le.getStackTraceAsString()); 130 } 131 132 throw le; 133 } 134 135 } catch (Exception e) { 136 String msg = "Exception in SearchXmlFile."; 137 LoaderException le = new LoaderException(msg + "\n" + e.getMessage(), (Throwable) e); 138 if (this.logger!=null){ 139 this.logger.write("full", "Exception in SearchXmlFile." + "\n" + le.getStackTraceAsString()); 140 } 141 throw le; 142 } 143 // if (this.logger!=null){ 144 // this.logger.write("full", "SearchXmlFile is finished."); 145 // } 146 147 } 148 149 /*** 150 * This method read value of allVendors parameter 151 * @return value of parameter 152 */ 153 public Vector getAllVendors() { 154 setLogger(); 155 // if (this.logger!=null){ 156 // this.logger.write("full", "\tgetAllVendors is started."); 157 // } 158 searchDocument = (SearchElement) SearchElement.newInstance(document); 159 NodeList databaseVendors = searchDocument.getSubElementsByTagName("Database/Vendor"); 160 if (databaseVendors.getLength() != 0) { 161 for (int i = 0; i < databaseVendors.getLength(); i++) { 162 String vendorName = ((Element) databaseVendors.item(i)).getAttribute("name"); 163 String vendorPath = getPathToConf(vendorName); 164 allVendors.add(vendorName); 165 } 166 } 167 // if (this.logger!=null){ 168 // this.logger.write("full", "\tgetAllVendors is finished."); 169 // } 170 return allVendors; 171 } 172 173 /*** 174 * This method read value of allVendorsPath parameter 175 * @return value of parameter 176 */ 177 public Vector getAllVendorsPath() { 178 setLogger(); 179 // if (this.logger!=null){ 180 // this.logger.write("full", "\tgetAllVendorsPath is started."); 181 // } 182 searchDocument = (SearchElement) SearchElement.newInstance(document); 183 Vector allVendorsPath = new Vector(); 184 NodeList databaseVendors = searchDocument.getSubElementsByTagName("Database/Vendor"); 185 if (databaseVendors.getLength() != 0) { 186 for (int i = 0; i < databaseVendors.getLength(); i++) { 187 String vendorName = ((Element) databaseVendors.item(i)).getAttribute("name"); 188 String vendorPath = getPathToConf(vendorName); 189 allVendorsPath.add(vendorPath); 190 } 191 } 192 // if (this.logger!=null){ 193 // this.logger.write("full", "\tgetAllVendorsPath is finished."); 194 // } 195 return allVendorsPath; 196 } 197 198 /*** 199 * This method read value of drivers parameter 200 * @return value of parameter 201 */ 202 public Vector getAllDriversForVendor() { 203 setLogger(); 204 // if (this.logger!=null){ 205 // this.logger.write("full", "\tgetAllDriversForVendor is started."); 206 // } 207 Vector allDriversForVendor = new Vector(); 208 Vector drivers = new Vector(); 209 Vector metaDataDriver = new Vector(); 210 String sourceVendor = "false"; 211 searchDocument = (SearchElement) SearchElement.newInstance(document); 212 NodeList driverTag = searchDocument.getSubElementsByTagName("Driver"); 213 214 for (int i = 0; i < driverTag.getLength(); i++) { 215 String driverName = ((Element) driverTag.item(i)).getAttribute("name"); 216 allDriversForVendor.add(driverName); 217 218 NodeList metaData = ((Element) driverTag.item(i)).getElementsByTagName("MetaData"); 219 String supportMetaData = ((Element) metaData.item(0)).getAttribute("value"); 220 221 if (supportMetaData.equalsIgnoreCase("true")) { 222 metaDataDriver.add(driverName); 223 sourceVendor = "true"; 224 } 225 } 226 drivers.add(allDriversForVendor); 227 drivers.add(metaDataDriver); 228 drivers.add(sourceVendor); 229 // if (this.logger!=null){ 230 // this.logger.write("full", "\tgetAllDriversForVendor is finished."); 231 // } 232 return drivers; 233 234 } 235 236 /*** 237 * This method search the named xml document, and read the value of pathToConf parameter 238 * which represents the path of the conf file, for the named database. 239 * @param database_Type is the type of the database. 240 * @return value of paramter. 241 */ 242 public String getPathToConf(String database_Type) { 243 setLogger(); 244 // if (this.logger!=null){ 245 // this.logger.write("full", "\tgetPathToConf is started."); 246 // } 247 searchDocument = (SearchElement) SearchElement.newInstance(document); 248 //ZK 18.6 2004 commented this. It was problem with reading xml file from jar. 249 //if(octopusPath!=null){ 250 NodeList databaseType = searchDocument.getSubElementsByCondition("Database/Vendor@name=" + database_Type); 251 if (databaseType.getLength() != 0) { 252 String pathToConf = databaseType.item(0).getFirstChild().getNodeValue(); 253 // if (this.logger!=null){ 254 // this.logger.write("full", "\tgetPathToConf is finished."); 255 // } 256 return pathToConf; 257 } else { 258 // if (this.logger!=null){ 259 // this.logger.write("full", "\tgetPathToConf is finished."); 260 // } 261 return null; 262 } 263 264 } 265 266 /*** 267 * This method search the named xml document, and read the value of driverClassName parameter, 268 * which represents driver class for the named driver. 269 * @param driverName is the name of the driver. 270 * @param jdbcParameters is reference to JdbcParameters object. 271 * @param generatorParameters is object of InputParameters class 272 * @throws LoaderException 273 */ 274 public void getClassName(String driverName, JdbcParameters jdbcParameters, InputParameters generatorParameters) throws LoaderException { 275 setLogger(); 276 // if (this.logger!=null){ 277 // this.logger.write("full", "\tgetClassName is started."); 278 // } 279 searchDocument = (SearchElement) SearchElement.newInstance(document); 280 NodeList driverTag = null; 281 if (driverName.equalsIgnoreCase("")) { 282 driverTag = searchDocument.getSubElementsByTagName("Driver"); 283 } else { 284 driverTag = searchDocument.getSubElementsByCondition("Driver@name=" + driverName); 285 } 286 if (driverTag.getLength() != 0) { 287 NodeList classNameTag = ((Element) driverTag.item(0)).getElementsByTagName("ClassName"); 288 if (classNameTag.getLength() == 0) { 289 if (fileName != null) 290 msg = "In " + fileName + " file for this database, you don't have ClassName tag!"; 291 else 292 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have ClassName tag!"; 293 294 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 295 if (this.logger!=null){ 296 this.logger.write("full", "Exception:"+"\n"+le.getStackTraceAsString()); 297 } 298 299 throw le; 300 } 301 jdbcParameters.setDriverClassName(((Element) classNameTag.item(0)).getAttribute("value")); 302 303 NodeList connectionTag = ((Element) driverTag.item(0)).getElementsByTagName("Connection"); 304 if (connectionTag.getLength() == 0) { 305 if (fileName != null) 306 msg = "In " + fileName + " file for this database, you don't have Connection tag!"; 307 else 308 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have Connection tag!"; 309 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 310 if (this.logger!=null){ 311 this.logger.write("full", "Exception:"+"\n"+le.getStackTraceAsString()); 312 } 313 throw le; 314 } 315 jdbcParameters.setConnection(((Element) connectionTag.item(0)).getAttribute("value")); 316 // NodeList alterTableTag= ((Element)driverTag.item(0)).getElementsByTagName("AlterTablePrimaryKey"); 317 // if(alterTableTag.getLength()==0){ 318 // if(fileName!=null) 319 // msg= "In "+fileName+" file for this database, you don't have AlterTablePrimaryKey tag!"; 320 // else 321 // msg= "In "+octopusPath+" ( in .jar) file for this database, you don't have AlterTablePrimaryKey tag!"; 322 // LoaderException le = new LoaderException(msg); 323 // throw le; 324 // } 325 // jdbcParameters.setAlterTablePrimaryKey(((Element)alterTableTag.item(0)).getAttribute("value")); 326 // generatorParameters.setAlterTablePrimaryKey(((Element)alterTableTag.item(0)).getAttribute("value")); 327 } else { 328 if (fileName != null) 329 msg = "In " + fileName + " file for this database, specified driver name (" + driverName + ") is not valid!"; 330 else 331 msg = "In " + octopusPath + " ( in .jar) file for this database, specified driver name (" + driverName + ") is not valid!"; 332 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 333 if (this.logger!=null){ 334 this.logger.write("full", "Exception:"+"\n"+le.getStackTraceAsString()); 335 } 336 337 throw le; 338 } 339 // if (this.logger!=null){ 340 // this.logger.write("full", "\tgetClassName is finished."); 341 // } 342 } 343 344 public Vector getFileSystemDatabase(String driverName) throws LoaderException { 345 setLogger(); 346 // if (this.logger!=null){ 347 // this.logger.write("full", "\tgetFileSystemDatabase is started."); 348 // } 349 Vector driverProperties = new Vector(); 350 String strFileSystemDatabase = ""; 351 String strConnection = ""; 352 353 searchDocument = (SearchElement) SearchElement.newInstance(document); 354 NodeList driverTag = null; 355 if (driverName.equalsIgnoreCase("")) { 356 driverTag = searchDocument.getSubElementsByTagName("Driver"); 357 } else { 358 driverTag = searchDocument.getSubElementsByCondition("Driver@name=" + driverName); 359 } 360 if (driverTag.getLength() != 0) { 361 //FileSystemDatabase tag 362 NodeList fileSystemDatabaseTag = ((Element) driverTag.item(0)).getElementsByTagName("FileSystemDatabase"); 363 if (fileSystemDatabaseTag.getLength() == 0) { 364 if (fileName != null) 365 msg = "In " + fileName + " file for this database, you don't have FileSystemDatabase tag!"; 366 else 367 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have FileSystemDatabase tag!"; 368 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 369 if (this.logger!=null){ 370 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 371 } 372 throw le; 373 } else { 374 strFileSystemDatabase = ((Element) fileSystemDatabaseTag.item(0)).getAttribute("value"); 375 } 376 377 //Connection 378 NodeList connectionTag = ((Element) driverTag.item(0)).getElementsByTagName("Connection"); 379 if (connectionTag.getLength() == 0) { 380 if (fileName != null) 381 msg = "In " + fileName + " file for this database, you don't have Connection tag!"; 382 else 383 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have Connection tag!"; 384 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 385 if (this.logger!=null){ 386 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 387 } 388 389 throw le; 390 } else { 391 strConnection = ((Element) connectionTag.item(0)).getAttribute("value"); 392 } 393 394 } else { 395 if (fileName != null) 396 msg = "In " + fileName + " file for this database, specified driver name (" + driverName + ") is not valid!"; 397 else 398 msg = "In " + octopusPath + " ( in .jar) file for this database, specified driver name (" + driverName + ") is not valid!"; 399 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 400 if (this.logger!=null){ 401 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 402 } 403 throw le; 404 } 405 driverProperties.add(strFileSystemDatabase); 406 driverProperties.add(strConnection); 407 // if (this.logger!=null){ 408 // this.logger.write("full", "\tgetFileSystemDatabase is finished."); 409 // } 410 return driverProperties; 411 } 412 413 public String getMaxConstraintLength(String driverName) throws LoaderException { 414 setLogger(); 415 // if (this.logger!=null){ 416 // this.logger.write("full", "\tgetMaxConstraintLength is started."); 417 // } 418 String maxConstraintLength = "-1"; 419 searchDocument = (SearchElement) SearchElement.newInstance(document); 420 NodeList driverTag = null; 421 if (driverName.equalsIgnoreCase("")) { 422 driverTag = searchDocument.getSubElementsByTagName("Driver"); 423 } else { 424 driverTag = searchDocument.getSubElementsByCondition("Driver@name=" + driverName); 425 } 426 if (driverTag.getLength() != 0) { 427 try { 428 NodeList maxConstraintLengthTag = ((Element) driverTag.item(0)).getElementsByTagName("MaxConstraintLength"); 429 430 maxConstraintLength = ((Element) maxConstraintLengthTag.item(0)).getAttribute("value"); 431 432 } catch (Exception ex) { 433 if (fileName != null) 434 msg = "In " + fileName + " file for this database, you don't have maxConstraintLenght tag!"; 435 else 436 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have maxConstraintLenght tag!"; 437 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 438 if (this.logger!=null){ 439 this.logger.write("full", "Exception:"+"\n"+le.getStackTraceAsString()); 440 } 441 442 throw le; 443 } 444 445 } 446 // if (this.logger!=null){ 447 // this.logger.write("full", "\tgetMaxConstraintLength is finished."); 448 // } 449 return maxConstraintLength; 450 } 451 452 /*** 453 * This method set value of alterTablePrimaryKey parameter 454 * @param driverName is name of the driver 455 * @return value of parameter 456 * @throws LoaderException 457 */ 458 public String getAlterTablePrimaryKey(String driverName) throws LoaderException { 459 setLogger(); 460 // if (this.logger!=null){ 461 // this.logger.write("full", "\tgetAlterTablePrimaryKey is started."); 462 // } 463 searchDocument = (SearchElement) SearchElement.newInstance(document); 464 NodeList driverTag = null; 465 if (driverName.equalsIgnoreCase("")) { 466 driverTag = searchDocument.getSubElementsByTagName("Driver"); 467 } else { 468 driverTag = searchDocument.getSubElementsByCondition("Driver@name=" + driverName); 469 } 470 if (driverTag.getLength() != 0) { 471 NodeList alterTableTag = ((Element) driverTag.item(0)).getElementsByTagName("AlterTablePrimaryKey"); 472 if (alterTableTag.getLength() == 0) { 473 if (fileName != null) 474 msg = "In " + fileName + " file for this database, you don't have AlterTablePrimaryKey tag!"; 475 else 476 msg = "In " + octopusPath + " ( in .jar) file for this database, you don't have AlterTablePrimaryKey tag!"; 477 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 478 if (this.logger!=null){ 479 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 480 } 481 throw le; 482 } else { 483 String ret = ((Element) alterTableTag.item(0)).getAttribute("value"); 484 // if (this.logger!=null){ 485 // this.logger.write("full", "\tgetAlterTablePrimaryKey is finished."); 486 // } 487 return ret; 488 } 489 490 } else { 491 if (fileName != null) 492 msg = "In " + fileName + " file for this database, specified driver name (" + driverName + ") is not valid!"; 493 else 494 msg = "In " + octopusPath + " ( in .jar) file for this database, specified driver name (" + driverName + ") is not valid!"; 495 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 496 if (this.logger!=null){ 497 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 498 } 499 throw le; 500 } 501 502 } 503 504 /*** 505 * This method search the named xml document, and read the value of jdbcType parameter, 506 * which represents the jdbc type of data of the named sql type of data. 507 * @param sql_Type is the sql type of data. 508 * @return jdbc type of data. 509 * @throws LoaderException 510 */ 511 public String getJDBCFromSQLType(String sql_Type) throws LoaderException { 512 setLogger(); 513 // if (this.logger!=null){ 514 // this.logger.write("full", "\tgetJDBCFromSQLType is started."); 515 // } 516 searchDocument = (SearchElement) SearchElement.newInstance(document); 517 //TODO zoran added this line 518 sql_Type = Utils.replaceAll(sql_Type, " ", ConfigReader.SPACE_ESCAPE); 519 NodeList SQLTypeTag = searchDocument.getSubElementsByTagName("SQLType/" + sql_Type.toUpperCase()); 520 if (SQLTypeTag.getLength() != 0) { 521 jdbcType = SQLTypeTag.item(0).getFirstChild().getNodeValue(); 522 } else { 523 String msg = "This type of data (" + sql_Type + ") doesn't exists in the source table conf file!"; 524 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 525 if (this.logger!=null){ 526 this.logger.write("full", "Exception:"+le.getStackTraceAsString()); 527 } 528 529 throw le; 530 } 531 // if (this.logger!=null){ 532 // this.logger.write("full", "\tgetJDBCFromSQLType is finished."); 533 // } 534 return jdbcType; 535 } 536 537 //ZK added this method 5.5 2004 538 /*** 539 * This method search the named xml document, and read the value of hasSize parameter 540 * @return hasSize. 541 * @throws LoaderException 542 */ 543 public Hashtable getHasSize() throws LoaderException { 544 setLogger(); 545 // if (this.logger!=null){ 546 // this.logger.write("full", "\tgetHasSize is started."); 547 // } 548 Hashtable resHashtable = new Hashtable(); 549 searchDocument = (SearchElement) SearchElement.newInstance(document); 550 NodeList SQLTypesTagX = searchDocument.getSubElementsByTagName("SQLType"); 551 NodeList SQLTypesTag = SQLTypesTagX.item(0).getChildNodes(); 552 if (SQLTypesTag.getLength() != 0) { 553 for (int i = 0; i < SQLTypesTag.getLength(); i++) { 554 if (!(SQLTypesTag.item(i) instanceof org.enhydra.xml.SearchElement)) 555 continue; 556 String hasSize = ((Element) SQLTypesTag.item(i)).getAttribute("hasSize"); 557 if (hasSize == null || hasSize.equalsIgnoreCase("")) 558 hasSize = "false"; 559 String nodeName = ((Element) SQLTypesTag.item(i)).getNodeName(); 560 nodeName = Utils.replaceAll(nodeName, ConfigReader.SPACE_ESCAPE, " "); 561 resHashtable.put(nodeName, hasSize); 562 } 563 } else { 564 String msg = "Exception in method getHasSize in class SearchXmlFile."; 565 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 566 if (this.logger!=null){ 567 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 568 } 569 throw le; 570 } 571 // if (this.logger!=null){ 572 // this.logger.write("full", "\tgetHasSize is finished."); 573 // } 574 return resHashtable; 575 } 576 /*** 577 * This method search the named xml document, and read the value of isDecimal parameter 578 * @return hasSize. 579 * @throws LoaderException 580 */ 581 public Hashtable getIsDecimal() throws LoaderException { 582 setLogger(); 583 // if (this.logger!=null){ 584 // this.logger.write("full", "\tgetIsDecimal is started."); 585 // } 586 Hashtable resHashtable = new Hashtable(); 587 searchDocument = (SearchElement) SearchElement.newInstance(document); 588 NodeList SQLTypesTagX = searchDocument.getSubElementsByTagName("SQLType"); 589 NodeList SQLTypesTag = SQLTypesTagX.item(0).getChildNodes(); 590 if (SQLTypesTag.getLength() != 0) { 591 for (int i = 0; i < SQLTypesTag.getLength(); i++) { 592 if (!(SQLTypesTag.item(i) instanceof org.enhydra.xml.SearchElement)) 593 continue; 594 String hasSize = ((Element) SQLTypesTag.item(i)).getAttribute("isDecimal"); 595 if (hasSize == null || hasSize.equalsIgnoreCase("")) 596 hasSize = "false"; 597 String nodeName = ((Element) SQLTypesTag.item(i)).getNodeName(); 598 nodeName = Utils.replaceAll(nodeName, ConfigReader.SPACE_ESCAPE, " "); 599 resHashtable.put(nodeName, hasSize); 600 } 601 } else { 602 String msg = "Exception in method getIsDecimal in class SearchXmlFile."; 603 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 604 if (this.logger!=null){ 605 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 606 } 607 throw le; 608 } 609 // if (this.logger!=null){ 610 // this.logger.write("full", "\tgetIsDecimal is finished."); 611 // } 612 return resHashtable; 613 } 614 /*** 615 * This method search the named xml document, and read the value of sqlType parameter, 616 * which represents the sql type of data of the named jdbc type of data. 617 * @param jdbc_Type is the jdbc type of data. 618 * @return the sql type of data. 619 * @throws LoaderException 620 */ 621 public String getSQLFromJDBCType(String jdbc_Type) throws LoaderException { 622 setLogger(); 623 // if (this.logger!=null){ 624 // this.logger.write("full", "\tgetSQLFromJDBCType is started."); 625 // } 626 searchDocument = (SearchElement) SearchElement.newInstance(document); 627 NodeList JDBCTypeTag = searchDocument.getSubElementsByTagName("JDBCType/" + jdbc_Type.toUpperCase()); 628 if (JDBCTypeTag.getLength() != 0) { 629 sqlType = JDBCTypeTag.item(0).getFirstChild().getNodeValue(); 630 } else { 631 String msg = "This type of data (" + jdbc_Type + ") doesn't exists on the target table conf file!"; 632 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 633 if (this.logger!=null){ 634 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 635 } 636 throw le; 637 } 638 // if (this.logger!=null){ 639 // this.logger.write("full", "\tgetSQLFromJDBCType is finished."); 640 // } 641 return sqlType; 642 } 643 644 /*** 645 * This method search the named xml document, and read the value of javaType parameter, 646 * which represents the java type of data of the named jdbc type of data. 647 * @param java_Type is the jdbc type of data. 648 * @return java type of data. 649 * @throws LoaderException 650 */ 651 public String getJAVAType(String java_Type) throws LoaderException { 652 setLogger(); 653 // if (this.logger!=null){ 654 // this.logger.write("full", "\tgetJAVAType is started."); 655 // } 656 searchDocument = (SearchElement) SearchElement.newInstance(document); 657 java_Type = Utils.replaceAll(java_Type, " ", ConfigReader.SPACE_ESCAPE); 658 NodeList JAVATypeTag = searchDocument.getSubElementsByTagName("JAVAType/" + java_Type.toUpperCase()); 659 if (JAVATypeTag.getLength() != 0) { 660 javaType = JAVATypeTag.item(0).getFirstChild().getNodeValue(); 661 } else { 662 String msg = "This type of data (" + java_Type + ") doesn't exists in Java Type class!"; 663 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 664 if (this.logger!=null){ 665 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 666 } 667 throw le; 668 } 669 // if (this.logger!=null){ 670 // this.logger.write("full", "\tgetJAVAType is finished."); 671 // } 672 return javaType; 673 } 674 675 /*** 676 * This method search the named xml document, and read the value of oidDbType parameter, which 677 * represents the oid type for the named database. 678 * @return oid type. 679 * @throws LoaderException 680 */ 681 public String getOidDB() throws LoaderException { 682 setLogger(); 683 // if (this.logger!=null){ 684 // this.logger.write("full", "\tgetOidDB is started."); 685 // } 686 searchDocument = (SearchElement) SearchElement.newInstance(document); 687 NodeList OidDb = searchDocument.getSubElementsByTagName("OidDbType"); 688 if (OidDb.getLength() != 0) { 689 this.oidDbType = OidDb.item(0).getFirstChild().getNodeValue(); 690 } else { 691 String msg = "You must cofigure your conf file for this Oid type!"; 692 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 693 if (this.logger!=null){ 694 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 695 } 696 throw le; 697 } 698 // if (this.logger!=null){ 699 // this.logger.write("full", "\tgetOidDB is finished."); 700 // } 701 return oidDbType; 702 } 703 704 /*** 705 * This method search the named xml document, and read the value of versionDbType parameter, which 706 * represents the version type of the named database. 707 * @return version type. 708 * @throws LoaderException 709 */ 710 public String getVersionDb() throws LoaderException { 711 setLogger(); 712 // if (this.logger!=null){ 713 // this.logger.write("full", "\tgetVersionDb is started."); 714 // } 715 searchDocument = (SearchElement) SearchElement.newInstance(document); 716 NodeList VersionDb = searchDocument.getSubElementsByTagName("VersionDbType"); 717 if (VersionDb.getLength() != 0) { 718 this.versionDbType = VersionDb.item(0).getFirstChild().getNodeValue(); 719 } else { 720 String msg = "You must cofigure yoor conf file for this Version type!"; 721 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 722 if (this.logger!=null){ 723 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 724 } 725 throw le; 726 } 727 // if (this.logger!=null){ 728 // this.logger.write("full", "\tgetVersionDb is finished."); 729 // } 730 return versionDbType; 731 } 732 733 /*** 734 * This method search the named xml document, and read the value of oidDbColumnName parameter, 735 * which represents the oid name for the named database. 736 * @return oid name. 737 * @throws LoaderException 738 */ 739 public String getOidDbColumn() throws LoaderException { 740 setLogger(); 741 // if (this.logger!=null){ 742 // this.logger.write("full", "\tgetOidDbColumn is started."); 743 // } 744 searchDocument = (SearchElement) SearchElement.newInstance(document); 745 NodeList OidDbColumn = searchDocument.getSubElementsByTagName("OidDbColumnName"); 746 if (OidDbColumn.getLength() != 0) { 747 this.oidDbColumnName = OidDbColumn.item(0).getFirstChild().getNodeValue(); 748 } else { 749 String msg = "You must cofigure yoor conf file for this Oid name!"; 750 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 751 if (this.logger!=null){ 752 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 753 } 754 throw le; 755 } 756 // if (this.logger!=null){ 757 // this.logger.write("full", "\tgetOidDbColumn is finished."); 758 // } 759 return oidDbColumnName; 760 } 761 762 /*** 763 * This method search the named xml document, and read the value of versionDbColumnName parameter, 764 * which represents the version name of the named database. 765 * @return version name. 766 * @throws LoaderException 767 */ 768 public String getVersionDbColumn() throws LoaderException { 769 setLogger(); 770 // if (this.logger!=null){ 771 // this.logger.write("full", "\tgetVersionDbColumn is started."); 772 // } 773 searchDocument = (SearchElement) SearchElement.newInstance(document); 774 NodeList VersionDbColumn = searchDocument.getSubElementsByTagName("VersionDbColumnName"); 775 if (VersionDbColumn.getLength() != 0) { 776 this.versionDbColumnName = VersionDbColumn.item(0).getFirstChild().getNodeValue(); 777 } else { 778 String msg = "You must cofigure yoor conf file for this Version name!"; 779 LoaderException le = new LoaderException("Exception:", new Exception(msg)); 780 if (this.logger!=null){ 781 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 782 } 783 throw le; 784 } 785 // if (this.logger!=null){ 786 // this.logger.write("full", "\tgetVersionDbColumn is finished."); 787 // } 788 return versionDbColumnName; 789 } 790 791 /*** 792 * This method search the named xml document, and read the value of name (Driver) parameter, 793 * which represents the driver name. 794 * @return value of parameter. 795 */ 796 public String getDriverName() { 797 setLogger(); 798 // if (this.logger!=null){ 799 // this.logger.write("full", "\tgetDriverName is started."); 800 // } 801 searchDocument = (SearchElement) SearchElement.newInstance(document); 802 NodeList driverTag = searchDocument.getSubElementsByTagName("Driver"); 803 // if (this.logger!=null){ 804 // this.logger.write("full", "\tgetDriverName is finished."); 805 // } 806 return ((Element) driverTag.item(0)).getAttribute("name"); 807 808 } 809 810 public String getExcludedTables() throws LoaderException { 811 setLogger(); 812 // if (this.logger!=null){ 813 // this.logger.write("full", "\tgetExcludedTables is started."); 814 // } 815 String ret = ""; 816 searchDocument = (SearchElement) SearchElement.newInstance(document); 817 NodeList excludeTableTag = searchDocument.getSubElementsByTagName("ExcludeTables"); 818 if (excludeTableTag.getLength() != 0) { 819 if (excludeTableTag.item(0).getFirstChild() != null) 820 ret = excludeTableTag.item(0).getFirstChild().getNodeValue(); 821 else 822 ret = ""; 823 } else { 824 String msg = "ExcludeTables tag doesn't exist in source conf file!"; 825 LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg)); 826 if (this.logger!=null){ 827 this.logger.write("full", "Error:"+le.getStackTraceAsString()); 828 } 829 throw le; 830 } 831 // if (this.logger!=null){ 832 // this.logger.write("full", "\tgetExcludedTables is finished."); 833 // } 834 return ret; 835 } 836 /*** 837 * This method will set logger object 838 * @param logger 839 */ 840 private void setLogger() { 841 this.logger = StandardLogger.getCentralLogger(); 842 } 843 }

This page was automatically generated by Maven