|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lapetus_ltd._2009.xml.types.XLptsDriverType
com.lapetus_ltd.api.db.xml.types.TLptsDriverType
public class TLptsDriverType
Class Description : Wrapper class for XLptsDriverType.
This class is a wrapper for XLptsDriverType and holds the driver information used to create a connection to a database.
Apart from the driver class information and the jar file location, this class also holds the default values for
putting into a connection function (connection string, password, etc).
There are some functions in this class for dealing with the interface, functions and parameters. Remember that the
interface, functions and parameters are dynamically loaded from a config file called driver.loader.xml.
There is therefore no fixed interface for the functions and parameters. The functions supplied allow for dealing with
this dynamic capability.
$LastChangedRevision: 1190 $
$LastChangedDate:: 2010-11-17 13:21:35#$
Field Summary | |
---|---|
static java.lang.String |
GET_CHARSET
Used internally in the connection string for connecting to the ODBC file. |
static java.lang.String |
GET_DATA_FILE
Used internally in the connection string for connecting to the ODBC file. |
static java.lang.String |
GET_DRIVER_TITLE
Used internally in the connection string for connecting to the ODBC file. |
Fields inherited from class com.lapetus_ltd._2009.xml.types.XLptsDriverType |
---|
annotation, connectionStringFormat, defaultCharSet, driverClass, guestPassword, guestUser, id, interfaceListItem, jdbcType, operatingSystemListItem, properties, rowSetClass, title, type |
Constructor Summary | |
---|---|
TLptsDriverType()
Constructs an empty driver type. |
|
TLptsDriverType(XLptsDriverType driverType)
Constructs a driver type from another XLptsDriverType. |
Method Summary | |
---|---|
void |
addInterfaceListItem(XLptsDriverInterfaceType interfaceType)
Adds an interface to the driver. |
void |
addOperatingSystemListItem(XLptsOperatingSystemType osType)
Adds an operating system name as being supported by this driver. |
boolean |
equals(java.lang.Object obj)
Check for equal TLptsDriverType objects. |
java.util.List<XLptsDriverInterfaceType> |
getInterfaceListItem()
Gets a synchronised copy of the interface list, which contains the functions and parameters of the driver. |
int |
getInterfaceListItemSize()
Returns the size of the actual list. |
java.util.List<XLptsOperatingSystemType> |
getOperatingSystemListItem()
Returns a list of the operating systems that this driver can run on. |
int |
getOperatingSystemListItemSize()
Returns the size of the actual list. |
void |
removeInterfaceListItem(XLptsDriverInterfaceType interfaceType)
Removes an interface from the driver. |
void |
removeOperatingSystemListItem(XLptsOperatingSystemType osType)
Removes an operating system name from the list of supported OSs for this driver. |
void |
setValueForInterfaceFunctionParameter(java.lang.String function,
java.lang.String parameter,
java.lang.String value)
Change the value for a dynamic parameter, declared in the xml interface configuration. |
java.lang.String |
zgCS(java.lang.String charset,
java.lang.String dataFile,
java.lang.String driverName)
|
Methods inherited from class com.lapetus_ltd._2009.xml.types.XLptsDriverType |
---|
getAnnotation, getConnectionStringFormat, getDefaultCharSet, getDriverClass, getGuestPassword, getGuestUser, getId, getJdbcType, getProperties, getRowSetClass, getTitle, getType, setAnnotation, setConnectionStringFormat, setDefaultCharSet, setDriverClass, setGuestPassword, setGuestUser, setId, setJdbcType, setProperties, setRowSetClass, setTitle, setType |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String GET_CHARSET
public static final java.lang.String GET_DATA_FILE
public static final java.lang.String GET_DRIVER_TITLE
Constructor Detail |
---|
public TLptsDriverType()
Constructs an empty driver type.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. Notes :private void connectToDB(String title, String driverClassName, String dbName, String username, String password) { TLptsDBConnectionType connectionType = new TLptsDBConnectionType(); connectionType.setTitle(title); XLptsDriverType driverType = TLptsDriverLoader.getDriverTypeByClassName(driverClassName); if (driverType==null) { System.out.println("Could not find driver for class : " + driverClassName); return; } TLptsDriverType dt = new TLptsDriverType(driverType); // changing values that are default in the driver.loader.xml file. // the DB is now set correctly and will filter through to the Datasource interface execution if(dbName!=null) dt.setValueForInterfaceFunctionParameter("setDatabaseName","Database Name",dbName); connectionType.setDriverType(dt); if(username==null || password==null) connectionType.setCredentials(TLptsCryptoUtil.defaultEncryptCredentialsRSA(driverType.getGuestUser(),driverType.getGuestPassword())); else connectionType.setCredentials(TLptsCryptoUtil.defaultEncryptCredentialsRSA(username,password)); TLptsConnectionFactory.initialiseConnection(connectionType); // This generates another thread!! }
public TLptsDriverType(XLptsDriverType driverType)
Constructs a driver type from another XLptsDriverType.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. Notes :private void connectToDB(String title, String driverClassName, String dbName, String username, String password) { TLptsDBConnectionType connectionType = new TLptsDBConnectionType(); connectionType.setTitle(title); XLptsDriverType driverType = TLptsDriverLoader.getDriverTypeByClassName(driverClassName); if (driverType==null) { System.out.println("Could not find driver for class : " + driverClassName); return; } TLptsDriverType dt = new TLptsDriverType(driverType); // changing values that are default in the driver.loader.xml file. // the DB is now set correctly and will filter through to the Datasource interface execution if(dbName!=null) dt.setValueForInterfaceFunctionParameter("setDatabaseName","Database Name",dbName); connectionType.setDriverType(dt); if(username==null || password==null) connectionType.setCredentials(TLptsCryptoUtil.defaultEncryptCredentialsRSA(driverType.getGuestUser(),driverType.getGuestPassword())); else connectionType.setCredentials(TLptsCryptoUtil.defaultEncryptCredentialsRSA(username,password)); TLptsConnectionFactory.initialiseConnection(connectionType); // This generates another thread!! }
driverType
- the XLptsDriverType to construct a TLptsDriverTypeMethod Detail |
---|
public void addInterfaceListItem(XLptsDriverInterfaceType interfaceType)
Adds an interface to the driver. This is normally done after reading it from the xml config file.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(); TLptsDriverType driverItem = new TLptsDriverType(); TLptsDriverInterfaceType driverInterfaceType = new TLptsDriverInterfaceType(); TLptsFunctionParameterType functionParameterType = new TLptsFunctionParameterType(); driverInterfaceType.setTitle("ServerName"); driverInterfaceType.setFunctionName("setServerName"); functionParameterType.setName("Server Name"); functionParameterType.setType(XLptsProgramParameterType.STRING); functionParameterType.setValue("192.168.1.2"); driverInterfaceType.addParameterListItem(functionParameterType); driverItem.addInterfaceListItem(driverInterfaceType); driverInterfaceType = new TLptsDriverInterfaceType(); driverInterfaceType.setTitle("DatabaseName"); driverInterfaceType.setFunctionName("setDatabaseName"); functionParameterType = new TLptsFunctionParameterType(); functionParameterType.setName("Database Name"); functionParameterType.setType(XLptsProgramParameterType.STRING); functionParameterType.setValue("E_shop"); driverInterfaceType.addParameterListItem(functionParameterType); driverItem.addInterfaceListItem(driverInterfaceType); ... driverLoaderType.addDriverListItem(driverItem); //Save driverLoader in file ObjectFactory of1 = new ObjectFactory(); TLptsXmlUtil.marshal("driver.loader.xml", XLptsDriverLoaderType.class, of1.createXLptsDriverLoaderType(driverLoaderType));
interfaceType
- The interface to add to this driver.public void addOperatingSystemListItem(XLptsOperatingSystemType osType)
Adds an operating system name as being supported by this driver.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(); TLptsDriverType driverItem = new TLptsDriverType(); driverItem.setTitle("MS SQL DataSource Driver"); driverItem.getDriverClass().setFullClassName("com.microsoft.sqlserver.jdbc.SQLServerDataSource"); driverItem.getDriverClass().setContextLookupName(""); driverItem.getDriverClass().setJarFilePath("drivers/sqljdbc4.jar"); ... driverItem.addOperatingSystemListItem(XLptsOperatingSystemType.WINDOWS); driverItem.addOperatingSystemListItem(XLptsOperatingSystemType.LINUX); driverItem.addOperatingSystemListItem(XLptsOperatingSystemType.SUNOS); driverItem.addOperatingSystemListItem(XLptsOperatingSystemType.MACINTOSH); ... driverLoaderType.addDriverListItem(driverItem);
osType
- The os that is now supported by this driver.public boolean equals(java.lang.Object obj)
Check for equal TLptsDriverType objects.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Use this to compare two TLptsDriverType objects. Example :
equals
in class java.lang.Object
obj
- the function name
public java.util.List<XLptsDriverInterfaceType> getInterfaceListItem()
Gets a synchronised copy of the interface list, which contains the functions and parameters of the driver.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. Only an empty list can be returned in the worst case. Notes : Use this to get list items only. Do not add to or delete from this list as it does not affect//load drivers from file XLptsDriverLoaderType dlt = (XLptsDriverLoaderType) TLptsXmlUtil.unmarshal("driver.loader.xml", XLptsDriverLoaderType.class); TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(dlt); TLptsFunctionParameterType functionParameterType = new TLptsFunctionParameterType(); if(driverLoaderType.getInterfaceListItemSize()>0) { for (XLptsDriverInterfaceType dit : driverLoaderType.getInterfaceListItem()) for (XLptsFunctionParameterType fpt : dit.getParameterListItem()) if(fpt.getValue().equlas("E_shop)) { functionParameterType = fpt; break } } else { TLptsLogger.logError("Driver list is empty",null); }
getInterfaceListItem
in class XLptsDriverType
public int getInterfaceListItemSize()
Returns the size of the actual list.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. The result may be an empty list. Notes : Do not use getInterfaceListItem().size() as it is not efficient. Example ://load drivers from file XLptsDriverLoaderType dlt = (XLptsDriverLoaderType) TLptsXmlUtil.unmarshal("driver.loader.xml", XLptsDriverLoaderType.class); TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(dlt); TLptsFunctionParameterType functionParameterType = new TLptsFunctionParameterType(); if(driverLoaderType.getInterfaceListItemSize()>0) { for (XLptsDriverInterfaceType dit : driverLoaderType.getInterfaceListItem()) for (XLptsFunctionParameterType fpt : dit.getParameterListItem()) if(fpt.getValue().equlas("E_shop)) { functionParameterType = fpt; break } } else { TLptsLogger.logError("Driver list is empty",null); }
public java.util.List<XLptsOperatingSystemType> getOperatingSystemListItem()
Returns a list of the operating systems that this driver can run on.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. Just an empty list in the worst case. Notes : It is normally all OSs or just Microsoft, when it is ODBC. Example ://load drivers from file XLptsDriverLoaderType dlt = (XLptsDriverLoaderType) TLptsXmlUtil.unmarshal("driver.loader.xml", XLptsDriverLoaderType.class); TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(dlt); for(XLptsDriverType dt : driverLoaderType.getDriverListItem()) if(dt.getOperatingSystemListItemSize()>0) { if(!dt.getOperatingSystemListItem().contains(XLptsOperatingSystemType.LINUX)); { driverLoaderType.removeDriverListItem(dt); TLptsLogger.logError("Driver does not support Linux",null); break; } else //Remove Solaris { dt.removeOperatingSystemListItem(XLptsOperatingSystemType.SUNOS) } }
getOperatingSystemListItem
in class XLptsDriverType
public int getOperatingSystemListItemSize()
Returns the size of the actual list.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : Never. The result may be an empty list. Notes : Do not use getOperatingSystemListItem().size() as it is not efficient. Example ://load drivers from file XLptsDriverLoaderType dlt = (XLptsDriverLoaderType) TLptsXmlUtil.unmarshal("driver.loader.xml", XLptsDriverLoaderType.class); TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(dlt); for(XLptsDriverType dt : driverLoaderType.getDriverListItem()) if(dt.getOperatingSystemListItemSize()>0) { if(!dt.getOperatingSystemListItem().contains(XLptsOperatingSystemType.LINUX)); { driverLoaderType.removeDriverListItem(dt); TLptsLogger.logError("Driver does not support Linux",null); break; } else //Remove Solaris { dt.removeOperatingSystemListItem(XLptsOperatingSystemType.SUNOS) } }
public void removeInterfaceListItem(XLptsDriverInterfaceType interfaceType)
Removes an interface from the driver. This is done by the driver loader when required.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example :String interfaceType = ""; TLptsDriverType dt = new TLptsDriverType(); for(XLptsDriverInterfaceType dit : dt.getInterfaceListItem()) if(interfaceType.equals(dit.getTitle())) { dt.removeInterfaceListItem(dit); break; }
interfaceType
- The interface to remove from this driver.public void removeOperatingSystemListItem(XLptsOperatingSystemType osType)
Removes an operating system name from the list of supported OSs for this driver.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Example ://load drivers from file XLptsDriverLoaderType dlt = (XLptsDriverLoaderType) TLptsXmlUtil.unmarshal("driver.loader.xml", XLptsDriverLoaderType.class); TLptsDriverLoaderType driverLoaderType = new TLptsDriverLoaderType(dlt); for(XLptsDriverType dt : driverLoaderType.getDriverListItem()) if(dt.getOperatingSystemListItemSize()>0) { if(!dt.getOperatingSystemListItem().contains(XLptsOperatingSystemType.LINUX)); { driverLoaderType.removeDriverListItem(dt); TLptsLogger.logError("Driver does not support Linux",null); break; } else //Remove Solaris { dt.removeOperatingSystemListItem(XLptsOperatingSystemType.SUNOS) } }
osType
- The os that is to be removed.public void setValueForInterfaceFunctionParameter(java.lang.String function, java.lang.String parameter, java.lang.String value)
Change the value for a dynamic parameter, declared in the xml interface configuration.
Thread Safe : Yes Spawns its own Thread : No May Return NULL : n/a Notes : Use this to change the value of a parameter that is to be passed to the driver (normally DataSource JDBC type). Example :String driverClassName = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"; String dbName = "Data Base Name"; String title = "Connection Title"; TLptsDBConnectionType connectionType = new TLptsDBConnectionType(); connectionType.setTitle(title); XLptsDriverType driverType = TLptsDriverLoader.getDriverTypeByClassName(driverClassName); if (driverType==null) { System.out.println("Could not find driver for class : " + driverClassName); return; } TLptsDriverType dt = new TLptsDriverType(driverType); dt.setValueForInterfaceFunctionParameter("setDatabaseName","Database Name",dbName); connectionType.setDriverType(dt);
function
- the function nameparameter
- the parameter name of the functionvalue
- the new valuepublic java.lang.String zgCS(java.lang.String charset, java.lang.String dataFile, java.lang.String driverName)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |