Package io.guise.framework.platform
Interface Environment
-
- All Known Implementing Classes:
AbstractEnvironment
,DefaultEnvironment
public interface Environment
Access to the platform user local environment. Properties stored in the environment should be persisted across sessions, using an appropriate platform storage mechanism such as cookies.- Author:
- Garret Wilson
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>
getProperties()
Returns the available environment properties as a read-only map of property names and values.<T> T
getProperty(java.lang.String name)
Retrieves an environment property by its name.<T> T
getProperty(java.lang.String name, T defaultValue)
Retrieves an environment property by its name, returning a default value if no value is available.<T> T
getRequiredProperty(java.lang.String name)
Retrieves a required environment property by its name, throwing an exception if the value is missing.boolean
hasProperty(java.lang.String name)
Determines if an environment property exists.void
removeProperty(java.lang.String name)
Removes the property specified by the given name.void
setProperties(java.util.Map<java.lang.String,java.lang.Object> map)
Sets multiple environment properties.void
setProperty(java.lang.String name, java.lang.Object value)
Sets an environment property.
-
-
-
Method Detail
-
hasProperty
boolean hasProperty(java.lang.String name)
Determines if an environment property exists.- Parameters:
name
- The name of the property to check.- Returns:
true
if the environment has the given property.
-
getProperty
<T> T getProperty(java.lang.String name)
Retrieves an environment property by its name. AClassCastException
will eventually be thrown if the given value is not the generic type requested.- Type Parameters:
T
- The type of property value expected.- Parameters:
name
- The name of the property to retrieve.- Returns:
- The property value, or
null
if there is no such property.
-
getProperty
<T> T getProperty(java.lang.String name, T defaultValue)
Retrieves an environment property by its name, returning a default value if no value is available. AClassCastException
will eventually be thrown if the given value is not the generic type requested.- Type Parameters:
T
- The type of property value expected.- Parameters:
name
- The name of the property to retrieve.defaultValue
- The value to return if no such property is available, ornull
if there is no default value.- Returns:
- The property value, or the provided default value if there is no such property.
-
getRequiredProperty
<T> T getRequiredProperty(java.lang.String name)
Retrieves a required environment property by its name, throwing an exception if the value is missing. AClassCastException
will eventually be thrown if the given value is not the generic type requested.- Type Parameters:
T
- The type of property value expected.- Parameters:
name
- The name of the property to retrieve.- Returns:
- The property value.
- Throws:
java.lang.IllegalStateException
- if no such property exists.
-
setProperty
void setProperty(java.lang.String name, java.lang.Object value)
Sets an environment property.- Parameters:
name
- The name of the property.value
- The value to associate with the name.- Throws:
java.lang.IllegalArgumentException
- if the given property cannot be set to the given value or cannot be changed.
-
setProperties
void setProperties(java.util.Map<java.lang.String,java.lang.Object> map)
Sets multiple environment properties.- Parameters:
map
- The map of property names and values to set.- Throws:
java.lang.IllegalArgumentException
- if the given property cannot be set to the given value or cannot be changed.
-
removeProperty
void removeProperty(java.lang.String name)
Removes the property specified by the given name.- Parameters:
name
- The name of the property to remove.- Throws:
java.lang.IllegalArgumentException
- if the given property cannot be removed.
-
getProperties
java.util.Map<java.lang.String,java.lang.Object> getProperties()
Returns the available environment properties as a read-only map of property names and values.- Returns:
- The available environment properties.
-
-