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 ofContainerConfigurationthat can be specialized for standalone configuration, existing configuration or other local configurations.
-
-
Field Summary
Fields Modifier and Type Field Description static StringRESOURCE_PATHThe 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 voidaddDataSource(DataSource dataSource)Add data source the container can take advantage of.protected voidaddDataSourcesFromProperties()Parse properties and add any DataSources to pending configuration.voidaddDeployable(Deployable newDeployable)Deploy aDeployablein the container.voidaddResource(Resource resource)Add resources the container can take advantage of.protected voidaddResourcesFromProperties()Parse properties and add any Resources to pending configuration.voidaddUser(User user)Add user to container.protected voidaddUsersFromProperties()Parse properties and add any users to pending configuration.voidapplyPortOffset()This method should only be called once all the properties has been set.protected voidapplyPortOffset(String name)Apply the port offset on the specified propertyvoidcollectUnsupportedDataSourcesAndThrowException()Warn user and throw an Exception if any unsupportedDataSources are setup for this configuration.voidcollectUnsupportedResourcesAndThrowException()Warn user and throw an Exception if any unsupportedResources are setup for this configuration.voidconfigure(LocalContainer container)Setup the container which means setting up a valid directory structure, setting up configuration files and deploying static deployables.protected voidconfigureFiles(Map<String,String> replacements, LocalContainer container)Copy the customized configuration files into the cargo home directory.protected abstract voiddoConfigure(LocalContainer container)Implementation ofLocalConfiguration.configure(LocalContainer)that all local configuration using this class must implement.protected voidflagOffsetApplied(String name, boolean offsetApplied)Flags whether offset has been applied to a given property or not.List<DataSource>getDataSources()List<Deployable>getDeployables()protected StringgetDestDirectoryLocation(String file, String toDir)Determines the correct path for the destination directory.protected StringgetDestFileLocation(String file, String toDir, String toFile)Determines the correct path for the destination file.FileHandlergetFileHandler()List<FileConfig>getFileProperties()Returns the file configurations.StringgetHome()StringgetPropertyValue(String name)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 ResourceUtilsgetResourceUtils()List<User>getUsers()booleanisOffsetApplied()Checks whether the offset is already applied or not.protected booleanisOffsetApplied(String name)Checks whether the offset is already applied or notvoidparsePropertiesForPendingConfiguration()Some configuration can be specified as encoded properties.voidrevertPortOffset()Revert the port offset on the configuration port properties.protected voidrevertPortOffset(String name)Revert the port offset on the specified propertyvoidsetConfigFileProperty(FileConfig fileConfig)set the config file property for a configuration.voidsetFileHandler(FileHandler fileHandler)voidsetFileProperty(FileConfig fileConfig)set the file property for a configuration.voidsetLogger(Logger logger)Overriden in order to set the logger on ancillary components.voidverify()Verify that the configuration is valid.-
Methods inherited from class org.codehaus.cargo.container.spi.configuration.AbstractConfiguration
getProperties, getPropertyValueIgnoreSystemProperties, 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:
setLoggerin interfaceLoggable- Overrides:
setLoggerin classLoggedObject- Parameters:
logger- the logger to set and set in the ancillary objects
-
getFileHandler
public FileHandler getFileHandler()
- Specified by:
getFileHandlerin interfaceLocalConfiguration- Returns:
- the file utility class to use for performing all file I/O.
-
setFileHandler
public void setFileHandler(FileHandler fileHandler)
- Specified by:
setFileHandlerin 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:
setFilePropertyin interfaceLocalConfiguration- Parameters:
fileConfig- The FileConfig to use
-
setConfigFileProperty
public void setConfigFileProperty(FileConfig fileConfig)
set the config file property for a configuration.- Specified by:
setConfigFilePropertyin interfaceLocalConfiguration- Parameters:
fileConfig- The FileConfig to use
-
getFileProperties
public List<FileConfig> getFileProperties()
Returns the file configurations.- Specified by:
getFilePropertiesin interfaceLocalConfiguration- Returns:
- The configuration file properies
-
addDeployable
public void addDeployable(Deployable newDeployable)
Deploy aDeployablein the container. It installs theDeployablein the container's configuration directory.- Specified by:
addDeployablein interfaceLocalConfiguration- Parameters:
newDeployable- theDeployableto deploy
-
getDeployables
public List<Deployable> getDeployables()
- Specified by:
getDeployablesin interfaceLocalConfiguration- Returns:
- the list of
Deployables that are going to be deployed in the container when it is started
-
getHome
public String getHome()
- Specified by:
getHomein 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)
- Specified by:
getPropertyValuein interfaceConfiguration- Overrides:
getPropertyValuein 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:
configurein interfaceLocalConfiguration- Parameters:
container- the container to configure
-
getReplacements
public 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.- Specified by:
getReplacementsin interfaceLocalConfiguration- 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:
verifyin interfaceContainerConfiguration- Overrides:
verifyin classAbstractConfiguration
-
collectUnsupportedResourcesAndThrowException
public void collectUnsupportedResourcesAndThrowException()
Warn user and throw an Exception if any unsupportedResources are setup for this configuration.
-
collectUnsupportedDataSourcesAndThrowException
public void collectUnsupportedDataSourcesAndThrowException()
Warn user and throw an Exception if any unsupportedDataSources 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:
addResourcein interfaceLocalConfiguration- Parameters:
resource- theResourceto add.
-
getResources
public List<Resource> getResources()
- Specified by:
getResourcesin interfaceLocalConfiguration- Returns:
- the configured resources for this container.
-
addUser
public void addUser(User user)
Add user to container.- Specified by:
addUserin interfaceLocalConfiguration- Parameters:
user- theUserto add.
-
getUsers
public List<User> getUsers()
- Specified by:
getUsersin interfaceLocalConfiguration- Returns:
- the list of
Users 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:
addDataSourcein interfaceLocalConfiguration- Parameters:
dataSource- theDataSourceto add.
-
getDataSources
public List<DataSource> getDataSources()
- Specified by:
getDataSourcesin 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:
applyPortOffsetin 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:
revertPortOffsetin 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:
isOffsetAppliedin interfaceLocalConfiguration- Returns:
trueif 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:
trueif 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-trueif the offset is applied, elsefalse.
-
-