Package org.silverpeas.core.util.lang
Interface SystemWrapper
-
- All Known Implementing Classes:
DefaultSystemWrapper
,TestSystemWrapper
public interface SystemWrapper
This wrapper interface permits to bootstrap different System mechanism according to the context of execution. This interface ensures nothing of wrong is done with the System properties and as such it can use a security manager.- Author:
- Yohann Chastagnier
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static SystemWrapper
get()
Gets the wrappedSystem
instance.Map<String,String>
getenv()
Gets all the environment variables.String
getenv(String name)
Gets the value of a environment variable.Properties
getProperties()
Gets the system properties.String
getProperty(String key)
Gets a system property.String
getProperty(String key, String def)
Gets a system property.void
setProperties(Properties props)
Sets the specified properties in the system properties.String
setProperty(String key, String value)
Sets a new system property.
-
-
-
Method Detail
-
get
static SystemWrapper get()
Gets the wrappedSystem
instance.- Returns:
- the instance of the System Wrapper.
-
getenv
String getenv(String name)
Gets the value of a environment variable.- Parameters:
name
- the name of the variable.- Returns:
- the value of the requested environment variable.
-
getenv
Map<String,String> getenv()
Gets all the environment variables.- Returns:
- the map of environment variables.
-
getProperties
Properties getProperties()
Gets the system properties.- Returns:
- the system properties.
- See Also:
System.getProperties()
-
setProperties
void setProperties(Properties props)
Sets the specified properties in the system properties. Opposite to the methodSystem.setProperties(java.util.Properties)
that replace the system properties with the specified ones, this method adds the specified ones among the existing system properties.- Parameters:
props
- the system properties to add.- See Also:
Properties.putAll(java.util.Map)
-
setProperty
String setProperty(String key, String value)
Sets a new system property. If the property isn't valued, id est has a null or an empty value, then it is not set. Only non-null and not empty property can be set.- Parameters:
key
- the key of the property.value
- a non-null and non-empty value of the property.- Returns:
- the previous value of the system property,
or
null
if it did not have one or if the property to set isn't valid. - See Also:
System.setProperty(String, String)
-
getProperty
String getProperty(String key)
Gets a system property.- Parameters:
key
- the key of the system property.- Returns:
- the string value of the system property,
or
null
if there is no property with that key.
-
getProperty
String getProperty(String key, String def)
Gets a system property.- Parameters:
key
- the key of the system property.def
- the default value if there is no property value with the key.- Returns:
- the string value of the system property, or the default value if there is no property with that key.
-
-