001: /*
002: LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:
004:
005: Copyright (C) 2003 Together
006:
007: This library is free software; you can redistribute it and/or
008: modify it under the terms of the GNU Lesser General Public
009: License as published by the Free Software Foundation; either
010: version 2.1 of the License, or (at your option) any later version.
011:
012: This library is distributed in the hope that it will be useful,
013: but WITHOUT ANY WARRANTY; without even the implied warranty of
014: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: Lesser General Public License for more details.
016:
017: You should have received a copy of the GNU Lesser General Public
018: License along with this library; if not, write to the Free Software
019: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: package org.webdocwf.util.loader.generator;
023:
024: import java.util.Hashtable;
025:
026: import org.webdocwf.util.loader.LoaderException;
027: import org.webdocwf.util.loader.logging.Logger;
028: import org.webdocwf.util.loader.logging.StandardLogger;
029:
030: /**
031: * JdbcParameters class sets the value of jdbc drivers, which can be used in Octopus.
032: * @author Radoslav Dutina
033: * @version 1.0
034: */
035: public class JdbcParameters {
036:
037: //Creating an atribute for source tag
038: private Hashtable parameters;
039: private String dbVendorName = "default";
040: private String driverName = "default";
041:
042: private String strDriverClassName = null;
043: private String strConnection = null;
044: private String strUser = "default";
045: private String strPassword = "default";
046: // private String strAlterTablePrimaryKey="true";
047: private String strDbVendorsPath = null;
048: private String fileName;
049: private Logger logger;
050:
051: /**
052: *
053: * @param destination defines the type of the path. If destonation=absolute path is absolute,
054: * if destination=relative path is relative, and if destination=jar, application read from jar
055: * file.
056: * @param generatorParameters represents the references to InputParameter object.
057: * @throws LoaderException
058: */
059: public JdbcParameters(String destination,
060: InputParameters generatorParameters) throws LoaderException {
061: setLogger();
062: this .logger.write("full", "JdbcParameters is started.");
063: parameters = new Hashtable();
064:
065: try {
066: if (destination.equalsIgnoreCase("source")) {
067: this .dbVendorName = generatorParameters.getSourceType();
068: this .driverName = generatorParameters
069: .getSourceDriverName();
070:
071: SearchXmlFile searchXmlFile = new SearchXmlFile(
072: "absolute", generatorParameters
073: .getPathToSourceConf(),
074: generatorParameters.getConfJarStructure());
075:
076: generatorParameters.setExcludedTables(searchXmlFile
077: .getExcludedTables());
078:
079: if (driverName.equalsIgnoreCase("")) {
080: setDriverName(searchXmlFile.getDriverName());
081: }
082: searchXmlFile.getClassName(getDriverName(), this ,
083: generatorParameters);
084: setJdbcParameters("JdbcDriver", strDriverClassName);
085: setJdbcParameters("Connection.Url", strConnection
086: + generatorParameters.getSourceDataBase());
087: setJdbcParameters("User", generatorParameters
088: .getSourceUser());
089: setJdbcParameters("Password", generatorParameters
090: .getSourcePassword());
091: } else if (destination.equalsIgnoreCase("target")) {
092:
093: this .dbVendorName = generatorParameters.getTargetType();
094: this .driverName = generatorParameters
095: .getTargetDriverName();
096:
097: SearchXmlFile searchXmlFile = new SearchXmlFile(
098: "absolute", generatorParameters
099: .getPathToTargetConf(),
100: generatorParameters.getConfJarStructure());
101: if (driverName.equalsIgnoreCase("")) {
102: setDriverName(searchXmlFile.getDriverName());
103: }
104: searchXmlFile.getClassName(getDriverName(), this ,
105: generatorParameters);
106: setJdbcParameters("JdbcDriver", strDriverClassName);
107: setJdbcParameters("Connection.Url", strConnection
108: + generatorParameters.getTargetDataBase());
109: setJdbcParameters("User", generatorParameters
110: .getTargetUser());
111: setJdbcParameters("Password", generatorParameters
112: .getTargetPassword());
113: }
114: } catch (LoaderException e) {
115: LoaderException le = new LoaderException(
116: "Exception in class JdbcParameters.Error while set jdbc parameters.",
117: e);
118: this .logger.write("full",
119: "Exception in class JdbcParameters.Error while set jdbc parameters."
120: + le.getStackTraceAsString());
121: throw le;
122: }
123: this .logger.write("full", "JdbcParameters is finished.");
124: }
125:
126: /**
127: * This method sets the par (value, key) of jdbc parameters.
128: * @param key is the first jdbc parameter.
129: * @param value is the second jdbc parameter.
130: */
131: public void setJdbcParameters(String key, String value) {
132: this .parameters.put(key, value);
133: }
134:
135: /**
136: * This method read the value od jdbc parameters
137: * @param key is the first jdbc parameter.
138: * @return is the second jdbc parameter.
139: */
140: public String getJdbcParameters(String key) {
141: return (String) this .parameters.get(key);
142: }
143:
144: /**
145: * This method read the all jdbc parameters.
146: * @return value of all jdbc parameters.
147: */
148: public Hashtable getAllParameters() {
149: return this .parameters;
150: }
151:
152: /**
153: * This method sets the value of dbVendor parameter.
154: * @param db_VendorName is value of parameter.
155: */
156: public void setDbVendor(String db_VendorName) {
157: dbVendorName = db_VendorName;
158: }
159:
160: /**
161: * This method read the value of dbVendor parameter.
162: * @return value of parameter.
163: */
164: public String getDbVendor() {
165: return dbVendorName;
166: }
167:
168: /**
169: * This method sets the value of driverName parameter.
170: * @param driver_Name is value of parameter.
171: */
172: public void setDriverName(String driver_Name) {
173: driverName = driver_Name;
174: }
175:
176: /**
177: * This method read the value of driverName parameter.
178: * @return value od parameter.
179: */
180: public String getDriverName() {
181: return driverName;
182: }
183:
184: /**
185: * This method sets the value of strDriverClassName parameter.
186: * @param driver_ClassName is value of the parameter.
187: */
188: public void setDriverClassName(String driver_ClassName) {
189: strDriverClassName = driver_ClassName;
190: }
191:
192: /**
193: * This method sets the value of strConnection parameter.
194: * @param _connection is the value of the parameter.
195: */
196: public void setConnection(String _connection) {
197: strConnection = _connection;
198: }
199:
200: /**
201: * This method will set logger object
202: * @param logger
203: */
204: private void setLogger() {
205: this.logger = StandardLogger.getCentralLogger();
206: }
207: }
|