Class AbstractLocalConfiguration
- java.lang.Object
-
- org.codehaus.cargo.util.log.LoggedObject
-
- org.codehaus.cargo.container.spi.configuration.AbstractConfiguration
-
- org.codehaus.cargo.container.spi.configuration.AbstractLocalConfiguration
-
- All Implemented Interfaces:
Configuration
,LocalConfiguration
,ContainerConfiguration
,Loggable
- Direct Known Subclasses:
AbstractExistingLocalConfiguration
,AbstractStandaloneLocalConfiguration
public abstract class AbstractLocalConfiguration extends AbstractConfiguration implements LocalConfiguration
Base implementation ofContainerConfiguration
that can be specialized for standalone configuration, existing configuration or other local configurations.
-
-
Field Summary
Fields Modifier and Type Field Description static String
RESOURCE_PATH
The path under which the container resources are stored in the JAR.
-
Constructor Summary
Constructors Constructor Description AbstractLocalConfiguration(String home)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDataSource(DataSource dataSource)
Add data source the container can take advantage of.protected void
addDataSourcesFromProperties()
Parse properties and add any DataSources to pending configuration.void
addDeployable(Deployable newDeployable)
Deploy aDeployable
in the container.void
addResource(Resource resource)
Add resources the container can take advantage of.protected void
addResourcesFromProperties()
Parse properties and add any Resources to pending configuration.void
addUser(User user)
Add user to container.protected void
addUsersFromProperties()
Parse properties and add any users to pending configuration.void
applyPortOffset()
This method should only be called once all the properties has been set.protected void
applyPortOffset(String name)
Apply the port offset on the specified propertyvoid
collectUnsupportedDataSourcesAndThrowException()
Warn user and throw an Exception if any unsupportedDataSource
s are setup for this configuration.void
collectUnsupportedResourcesAndThrowException()
Warn user and throw an Exception if any unsupportedResource
s are setup for this configuration.void
configure(LocalContainer container)
Setup the container which means setting up a valid directory structure, setting up configuration files and deploying static deployables.protected void
configureFiles(Map<String,String> replacements, LocalContainer container)
Copy the customized configuration files into the cargo home directory.protected abstract void
doConfigure(LocalContainer container)
Implementation ofLocalConfiguration.configure(LocalContainer)
that all local configuration using this class must implement.protected void
flagOffsetApplied(String name, boolean offsetApplied)
Flags whether offset has been applied to a given property or not.List<DataSource>
getDataSources()
List<Deployable>
getDeployables()
protected String
getDestDirectoryLocation(String file, String toDir)
Determines the correct path for the destination directory.protected String
getDestFileLocation(String file, String toDir, String toFile)
Determines the correct path for the destination file.FileHandler
getFileHandler()
List<FileConfig>
getFileProperties()
Returns the file configurations.String
getHome()
String
getPropertyValue(String name)
protected Map<String,String>
getReplacements()
Returns (while, if necessary, creating) the default filter chain that should be applied while copying container configuration files to the working directory from which the container is started.List<Resource>
getResources()
protected ResourceUtils
getResourceUtils()
List<User>
getUsers()
boolean
isOffsetApplied()
Checks whether the offset is already applied or not.protected boolean
isOffsetApplied(String name)
Checks whether the offset is already applied or notvoid
parsePropertiesForPendingConfiguration()
Some configuration can be specified as encoded properties.void
revertPortOffset()
Revert the port offset on the configuration port properties.protected void
revertPortOffset(String name)
Revert the port offset on the specified propertyvoid
setConfigFileProperty(FileConfig fileConfig)
set the config file property for a configuration.void
setFileHandler(FileHandler fileHandler)
void
setFileProperty(FileConfig fileConfig)
set the file property for a configuration.void
setLogger(Logger logger)
Overriden in order to set the logger on ancillary components.void
verify()
Verify that the configuration is valid.-
Methods inherited from class org.codehaus.cargo.container.spi.configuration.AbstractConfiguration
getProperties, setProperty
-
Methods inherited from class org.codehaus.cargo.util.log.LoggedObject
getLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.codehaus.cargo.container.configuration.Configuration
getCapability, getProperties, getType, setProperty
-
-
-
-
Field Detail
-
RESOURCE_PATH
public static final String RESOURCE_PATH
The path under which the container resources are stored in the JAR.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractLocalConfiguration
public AbstractLocalConfiguration(String home)
- Parameters:
home
- the home directory where the container will be set up to start and where it will deploy its deployables. IMPORTANT: While some containers can deal with this parameter being set as a relative path, some others require this path to be set to an absolute directory. Please refer to the documentation of the server to ensure you give the path in the appropriate way. If in doubt, you can use absolute paths -that is known to work with all containers.
-
-
Method Detail
-
setLogger
public void setLogger(Logger logger)
Overriden in order to set the logger on ancillary components.- Specified by:
setLogger
in interfaceLoggable
- Overrides:
setLogger
in classLoggedObject
- Parameters:
logger
- the logger to set and set in the ancillary objects
-
getFileHandler
public FileHandler getFileHandler()
- Specified by:
getFileHandler
in interfaceLocalConfiguration
- Returns:
- the file utility class to use for performing all file I/O.
-
setFileHandler
public void setFileHandler(FileHandler fileHandler)
- Specified by:
setFileHandler
in interfaceLocalConfiguration
- Parameters:
fileHandler
- the file utility class to use for performing all file I/O.
-
getResourceUtils
protected final ResourceUtils getResourceUtils()
- Returns:
- the Resource utility class
-
setFileProperty
public void setFileProperty(FileConfig fileConfig)
set the file property for a configuration.- Specified by:
setFileProperty
in interfaceLocalConfiguration
- Parameters:
fileConfig
- The FileConfig to use
-
setConfigFileProperty
public void setConfigFileProperty(FileConfig fileConfig)
set the config file property for a configuration.- Specified by:
setConfigFileProperty
in interfaceLocalConfiguration
- Parameters:
fileConfig
- The FileConfig to use
-
getFileProperties
public List<FileConfig> getFileProperties()
Returns the file configurations.- Specified by:
getFileProperties
in interfaceLocalConfiguration
- Returns:
- The configuration file properies
-
addDeployable
public void addDeployable(Deployable newDeployable)
Deploy aDeployable
in the container. It installs theDeployable
in the container's configuration directory.- Specified by:
addDeployable
in interfaceLocalConfiguration
- Parameters:
newDeployable
- theDeployable
to deploy
-
getDeployables
public List<Deployable> getDeployables()
- Specified by:
getDeployables
in interfaceLocalConfiguration
- Returns:
- the list of
Deployable
s that are going to be deployed in the container when it is started
-
getHome
public String getHome()
- Specified by:
getHome
in interfaceLocalConfiguration
- Returns:
- the configuration home directory. Note that we're returning a String instead of a File because we want to leave the possibility of using URIs for specifying the home location.
-
getPropertyValue
public String getPropertyValue(String name)
Description copied from class:AbstractConfiguration
- Specified by:
getPropertyValue
in interfaceConfiguration
- Overrides:
getPropertyValue
in classAbstractConfiguration
- Parameters:
name
- the property name for which to return the value- Returns:
- the property's value
- See Also:
Configuration.setProperty(String, String)
-
configure
public void configure(LocalContainer container)
Setup the container which means setting up a valid directory structure, setting up configuration files and deploying static deployables.- Specified by:
configure
in interfaceLocalConfiguration
- Parameters:
container
- the container to configure
-
getReplacements
protected Map<String,String> getReplacements()
Returns (while, if necessary, creating) the default filter chain that should be applied while copying container configuration files to the working directory from which the container is started.- Returns:
- The default filter chain
-
configureFiles
protected void configureFiles(Map<String,String> replacements, LocalContainer container)
Copy the customized configuration files into the cargo home directory.- Parameters:
replacements
- the replacements to use during the copycontainer
- local container
-
getDestFileLocation
protected String getDestFileLocation(String file, String toDir, String toFile)
Determines the correct path for the destination file.- Parameters:
file
- The path of the original filetoDir
- The directory for the copied filetoFile
- The file name for the copied file- Returns:
- The path for the destination file
-
getDestDirectoryLocation
protected String getDestDirectoryLocation(String file, String toDir)
Determines the correct path for the destination directory.- Parameters:
file
- The path of the original filetoDir
- The directory for the copied file- Returns:
- The path for the destination file
-
verify
public void verify()
Verify that the configuration is valid. The checks to be performed may vay whether this is standalone or existing configuration. This method should also be used to verify that the configuration properties specified by the user are valid and that the required ones are set.- Specified by:
verify
in interfaceContainerConfiguration
- Overrides:
verify
in classAbstractConfiguration
-
collectUnsupportedResourcesAndThrowException
public void collectUnsupportedResourcesAndThrowException()
Warn user and throw an Exception if any unsupportedResource
s are setup for this configuration.
-
collectUnsupportedDataSourcesAndThrowException
public void collectUnsupportedDataSourcesAndThrowException()
Warn user and throw an Exception if any unsupportedDataSource
s are setup for this configuration.
-
parsePropertiesForPendingConfiguration
public void parsePropertiesForPendingConfiguration()
Some configuration can be specified as encoded properties. Parse properties and apply what is found to the appropriate pending configuration list.
-
addResourcesFromProperties
protected void addResourcesFromProperties()
Parse properties and add any Resources to pending configuration. Resources will be found if their property name starts with:ResourcePropertySet.RESOURCE
-
addDataSourcesFromProperties
protected void addDataSourcesFromProperties()
Parse properties and add any DataSources to pending configuration. DataSources will be found if their property name starts with:DatasourcePropertySet.DATASOURCE
-
addUsersFromProperties
protected void addUsersFromProperties()
Parse properties and add any users to pending configuration. Users will be retrieved from their property:ServletPropertySet.USERS
-
doConfigure
protected abstract void doConfigure(LocalContainer container) throws Exception
Implementation ofLocalConfiguration.configure(LocalContainer)
that all local configuration using this class must implement. This provides the ability to perform generic actions before and after the container-specific implementation. Another way would be to use AOP...- Parameters:
container
- the container to configure- Throws:
Exception
- if any error is raised during the configuration
-
addResource
public void addResource(Resource resource)
Add resources the container can take advantage of. I.e. datasources.- Specified by:
addResource
in interfaceLocalConfiguration
- Parameters:
resource
- theResource
to add.
-
getResources
public List<Resource> getResources()
- Specified by:
getResources
in interfaceLocalConfiguration
- Returns:
- the configured resources for this container.
-
addUser
public void addUser(User user)
Add user to container.- Specified by:
addUser
in interfaceLocalConfiguration
- Parameters:
user
- theUser
to add.
-
getUsers
public List<User> getUsers()
- Specified by:
getUsers
in interfaceLocalConfiguration
- Returns:
- the list of
User
s that are going to be added to the container.
-
addDataSource
public void addDataSource(DataSource dataSource)
Add data source the container can take advantage of.- Specified by:
addDataSource
in interfaceLocalConfiguration
- Parameters:
dataSource
- theDataSource
to add.
-
getDataSources
public List<DataSource> getDataSources()
- Specified by:
getDataSources
in interfaceLocalConfiguration
- Returns:
- the configured DataSources for this container.
-
applyPortOffset
public void applyPortOffset()
This method should only be called once all the properties has been set. Apply the port offset to the configuration port properties.- Specified by:
applyPortOffset
in interfaceLocalConfiguration
-
revertPortOffset
public void revertPortOffset()
Revert the port offset on the configuration port properties. This method should only be called once all the properties has been set.- Specified by:
revertPortOffset
in interfaceLocalConfiguration
-
applyPortOffset
protected void applyPortOffset(String name)
Apply the port offset on the specified property- Parameters:
name
- the property name
-
revertPortOffset
protected void revertPortOffset(String name)
Revert the port offset on the specified property- Parameters:
name
- the property name
-
isOffsetApplied
public boolean isOffsetApplied()
Checks whether the offset is already applied or not.- Specified by:
isOffsetApplied
in interfaceLocalConfiguration
- Returns:
true
if the offset is already applied
-
isOffsetApplied
protected boolean isOffsetApplied(String name)
Checks whether the offset is already applied or not- Parameters:
name
- the name of the property to be checked- Returns:
true
if the offset is already applied
-
flagOffsetApplied
protected void flagOffsetApplied(String name, boolean offsetApplied)
Flags whether offset has been applied to a given property or not.- Parameters:
name
- name of the property to be flagged.offsetApplied
-true
if the offset is applied, elsefalse
.
-
-