org.codehaus.cargo.container.property
Class DataSourceConverter

java.lang.Object
  extended by org.codehaus.cargo.container.property.DataSourceConverter

public class DataSourceConverter
extends Object

A DataSource is a representation of an database pool bound to JNDI. This converter will take a property and convert it to a DataSource and visa versa.

Version:
$Id: DataSource.java 1840 2008-12-09 00:26:10Z adriancole $

Constructor Summary
DataSourceConverter()
           
 
Method Summary
 Resource convertToResource(DataSource ds, String resourceType, String driverParameter)
          This method converts the DataSource to a Resource.
protected static String createIdFromJndiLocation(String jndiLocation)
          Get a string name for the configuration of this datasource.
 DataSource fromProperties(Properties properties)
          Construct a DataSource from a list of properties.
 DataSource fromPropertyString(String datasourceInformation)
          Construct a DataSource from a single String.
 String getConnectionPropertiesAsASemicolonDelimitedString(DataSource data)
          tests to see if the value is null before attempting to join the database properties on a semicolon.
 Properties toProperties(DataSource data)
          Get a properties object containing all of the members of this datasource object.
 String toPropertyString(DataSource data)
          Get a string representation of this datasource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceConverter

public DataSourceConverter()
Method Detail

fromPropertyString

public DataSource fromPropertyString(String datasourceInformation)
Construct a DataSource from a single String. Note that database driver properties can be nested as long as they are semicolon delimited Example: CreateDatabase=create;DatabaseName=TEST.

Parameters:
datasourceInformation - A string, really a list of properties, representing a datasource
Returns:
DataSource representing the string
See Also:
PropertyUtils.splitPropertiesOnPipe(String)

fromProperties

public DataSource fromProperties(Properties properties)
Construct a DataSource from a list of properties.

Parameters:
properties - A list of properties representing this datasource
Returns:
DataSource representing the properties
See Also:
PropertyUtils.splitPropertiesOnPipe(String)

createIdFromJndiLocation

protected static String createIdFromJndiLocation(String jndiLocation)
Get a string name for the configuration of this datasource. This should be XML and filesystem friendly. For example, the String returned will have no slashes or punctuation, and be as short as possible.

Parameters:
jndiLocation - used to construct the id
Returns:
a string that can be used to name this configuration

toPropertyString

public String toPropertyString(DataSource data)
Get a string representation of this datasource.

Parameters:
data - DataSource to serialize into a string.
Returns:
a string representation
See Also:
PropertyUtils#joinPropertiesOnPipe(java.util.Properties)

toProperties

public Properties toProperties(DataSource data)
Get a properties object containing all of the members of this datasource object. Note that driver properties will be nested and delimited by a semicolon.

Parameters:
data - DataSource to serialize into properties.
Returns:
a properties object corresponding to this datasource

getConnectionPropertiesAsASemicolonDelimitedString

public String getConnectionPropertiesAsASemicolonDelimitedString(DataSource data)
tests to see if the value is null before attempting to join the database properties on a semicolon.

Parameters:
data - DataSource to parse connection properties from.
Returns:
property string delimited by semicolon, or null, if they cannot be parsed because the input properties weren't set or empty

convertToResource

public Resource convertToResource(DataSource ds,
                                  String resourceType,
                                  String driverParameter)
This method converts the DataSource to a Resource.

Parameters:
ds - DataSource to convert to a resource.
resourceType - the type of the Resource to convert to. ex. javax.sql.DataSource
driverParameter - the name of the parameter to store driverClass.
Returns:
a Resource representing the assignable fields of the DataSource.


Copyright © 2004-2012 Codehaus. All Rights Reserved.