📄 searchxmlfile.java
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
Copyright (C) 2003 Together
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.webdocwf.util.loader.generator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import java.io.File;
import java.io.*;
import java.util.*;
import org.enhydra.xml.*;
import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;
/**
*
* SearchXmlFile class search the named xml document.
* @author Radoslav Dutina
* @version 1.0
*/
public class SearchXmlFile {
private SearchElement searchDocument;
private Document document;
private String fileName;
private String jdbcType = null;
private String sqlType = null;
private String javaType = null;
private String oidDbType = null;
private String versionDbType = null;
private String oidDbColumnName = null;
private String versionDbColumnName = null;
private InputStream is = null;
private File file = null;
private String octopusPath = null;
private String msg = null;
private Vector allVendors = new Vector();
private Logger logger = null;
/**
* Construct object SearchXmlFile with associated parameters.
* @param typePath defines the type of the path. Path can be relative, absolute and jar.
* If the parameter has value jar, then the xml file is placed in jar file.
* @param path is the path to named xml file.
* @throws LoaderException
*/
public SearchXmlFile(String typePath, String path, String confJarStructure) throws LoaderException {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "SearchXmlFile is started.");
// }
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
octopusPath = System.getProperty("OCTOPUS_HOME");
if (octopusPath == null) {
if (confJarStructure != null && !confJarStructure.equalsIgnoreCase("")) {
is = getClass().getClassLoader().getResourceAsStream(confJarStructure + "/" + path);
} else {
is = getClass().getClassLoader().getResourceAsStream("xml/conf/" + path);
}
} else {
//make the diference if the path is apsolute or relative!
if (typePath.equalsIgnoreCase("relative")) {
fileName = octopusPath + "/conf/" + path;
} else if (typePath.equalsIgnoreCase("absolute")) {
fileName = path;
}
}
if (fileName != null) {
file = new File(fileName);
if (!file.exists()) {
msg = "This " + fileName + " file doesn't exists!!";
LoaderException le = new LoaderException("Exception:", (Throwable) new Exception(msg));
if (this.logger!=null){
this.logger.write("full", "Exception in SearchXmlFile." + le.getStackTraceAsString());
}
throw le;
}
}
DocumentBuilder builder = factory.newDocumentBuilder();
try {
if (octopusPath != null)
document = builder.parse(file);
else
document = builder.parse(is);
} catch (Exception e) {
if (fileName != null)
msg = "Exception has occurred when application try to parse " + fileName + " file." + "\n";
else
msg = "Exception has occurred when application try to parse " + path + " file placed in jar file." + "\n";
LoaderException le = new LoaderException("Exception:" + msg + e.getMessage(), (Throwable) e);
if (this.logger!=null){
this.logger.write("full", "Exception in SearchXmlFile." + msg +"\n" + le.getStackTraceAsString());
}
throw le;
}
} catch (Exception e) {
String msg = "Exception in SearchXmlFile.";
LoaderException le = new LoaderException(msg + "\n" + e.getMessage(), (Throwable) e);
if (this.logger!=null){
this.logger.write("full", "Exception in SearchXmlFile." + "\n" + le.getStackTraceAsString());
}
throw le;
}
// if (this.logger!=null){
// this.logger.write("full", "SearchXmlFile is finished.");
// }
}
/**
* This method read value of allVendors parameter
* @return value of parameter
*/
public Vector getAllVendors() {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllVendors is started.");
// }
searchDocument = (SearchElement) SearchElement.newInstance(document);
NodeList databaseVendors = searchDocument.getSubElementsByTagName("Database/Vendor");
if (databaseVendors.getLength() != 0) {
for (int i = 0; i < databaseVendors.getLength(); i++) {
String vendorName = ((Element) databaseVendors.item(i)).getAttribute("name");
String vendorPath = getPathToConf(vendorName);
allVendors.add(vendorName);
}
}
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllVendors is finished.");
// }
return allVendors;
}
/**
* This method read value of allVendorsPath parameter
* @return value of parameter
*/
public Vector getAllVendorsPath() {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllVendorsPath is started.");
// }
searchDocument = (SearchElement) SearchElement.newInstance(document);
Vector allVendorsPath = new Vector();
NodeList databaseVendors = searchDocument.getSubElementsByTagName("Database/Vendor");
if (databaseVendors.getLength() != 0) {
for (int i = 0; i < databaseVendors.getLength(); i++) {
String vendorName = ((Element) databaseVendors.item(i)).getAttribute("name");
String vendorPath = getPathToConf(vendorName);
allVendorsPath.add(vendorPath);
}
}
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllVendorsPath is finished.");
// }
return allVendorsPath;
}
/**
* This method read value of drivers parameter
* @return value of parameter
*/
public Vector getAllDriversForVendor() {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllDriversForVendor is started.");
// }
Vector allDriversForVendor = new Vector();
Vector drivers = new Vector();
Vector metaDataDriver = new Vector();
String sourceVendor = "false";
searchDocument = (SearchElement) SearchElement.newInstance(document);
NodeList driverTag = searchDocument.getSubElementsByTagName("Driver");
for (int i = 0; i < driverTag.getLength(); i++) {
String driverName = ((Element) driverTag.item(i)).getAttribute("name");
allDriversForVendor.add(driverName);
NodeList metaData = ((Element) driverTag.item(i)).getElementsByTagName("MetaData");
String supportMetaData = ((Element) metaData.item(0)).getAttribute("value");
if (supportMetaData.equalsIgnoreCase("true")) {
metaDataDriver.add(driverName);
sourceVendor = "true";
}
}
drivers.add(allDriversForVendor);
drivers.add(metaDataDriver);
drivers.add(sourceVendor);
// if (this.logger!=null){
// this.logger.write("full", "\tgetAllDriversForVendor is finished.");
// }
return drivers;
}
/**
* This method search the named xml document, and read the value of pathToConf parameter
* which represents the path of the conf file, for the named database.
* @param database_Type is the type of the database.
* @return value of paramter.
*/
public String getPathToConf(String database_Type) {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "\tgetPathToConf is started.");
// }
searchDocument = (SearchElement) SearchElement.newInstance(document);
//ZK 18.6 2004 commented this. It was problem with reading xml file from jar.
//if(octopusPath!=null){
NodeList databaseType = searchDocument.getSubElementsByCondition("Database/Vendor@name=" + database_Type);
if (databaseType.getLength() != 0) {
String pathToConf = databaseType.item(0).getFirstChild().getNodeValue();
// if (this.logger!=null){
// this.logger.write("full", "\tgetPathToConf is finished.");
// }
return pathToConf;
} else {
// if (this.logger!=null){
// this.logger.write("full", "\tgetPathToConf is finished.");
// }
return null;
}
}
/**
* This method search the named xml document, and read the value of driverClassName parameter,
* which represents driver class for the named driver.
* @param driverName is the name of the driver.
* @param jdbcParameters is reference to JdbcParameters object.
* @param generatorParameters is object of InputParameters class
* @throws LoaderException
*/
public void getClassName(String driverName, JdbcParameters jdbcParameters, InputParameters generatorParameters) throws LoaderException {
setLogger();
// if (this.logger!=null){
// this.logger.write("full", "\tgetClassName is started.");
// }
searchDocument = (SearchElement) SearchElement.newInstance(document);
NodeList driverTag = null;
if (driverName.equalsIgnoreCase("")) {
driverTag = searchDocument.getSubElementsByTagName("Driver");
} else {
driverTag = searchDocument.getSubElementsByCondition("Driver@name=" + driverName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -