Package org.silverpeas.kernel.util
Interface SystemWrapper
public interface SystemWrapper
This wrapper aims to allow to load additional and custom system properties without passing them
explicitly and directly to the JVM. Usually in Silverpeas, these custom system properties define
the context of its execution.
By default it wraps the System class; hence its name. The way those custom system
properties are loaded is at the discretion of the implementor. In opposite to the System
class in which all the methods are static, this class allowed to be instantiated so that
different context can be prepared for the tests without implying necessarily the System
class.
- Author:
- Yohann Chastagnier
- Implementation Requirements:
- The
SystemWrapperimplementation is loaded from the the Java SPI (Java Service Provider Interface) and its instance is kept in memory for further retrieval. - Implementation Note:
- Whatever the number of available implementations of this interface, only the first
found one is used. Nevertheless, by using the @
Priorityannotation, the implementation to use can be explicitly indicated.
-
Method Summary
Modifier and TypeMethodDescriptiongetenv()Gets all the environment variables.default StringGets the value of a environment variable.static SystemWrapperGets the wrapped singleSysteminstance of theSystemWrapper.default PropertiesGets the system properties.default StringgetProperty(String key) Gets a system property.default StringgetProperty(String key, String def) Gets a system property.default voidsetProperties(Properties props) Sets the specified properties in the system properties.default StringsetProperty(String key, String value) Sets a new system property.
-
Method Details
-
getInstance
Gets the wrapped singleSysteminstance of theSystemWrapper. If the implementation isn't yet loaded, then it is loaded and instantiated once time.- Returns:
- the instance of the System Wrapper.
- Implementation Note:
- The implementation is loaded and instantiated by Java SPI at first call. The single instance is then kept in memory so that it is returned at each next call.
-
getenv
Gets the value of a environment variable.- Parameters:
name- the name of the variable.- Returns:
- the value of the requested environment variable.
-
getenv
Gets all the environment variables.- Returns:
- the map of environment variables.
-
getProperties
Gets the system properties.- Returns:
- the system properties.
- See Also:
-
setProperties
Sets the specified properties in the system properties. Opposite to the methodSystem.setProperties(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:
-
setProperty
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
nullif it did not have one or if the property to set isn't valid. - See Also:
-
getProperty
Gets a system property.- Parameters:
key- the key of the system property.- Returns:
- the string value of the system property, or
nullif there is no property with that key.
-
getProperty
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.
-