Package org.silverpeas.bridge

## Class SafeSessionManager

- java.lang.Object
- - org.silverpeas.bridge.SafeSessionManager

-     public class SafeSessionManager
      extends Object

  This class allows handling a session safely against the different request calls.

  Some synchronized access are performed around session creation and session attribute accesses.

  Author:
    silveryocha

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SafeSessionManager​(javax.servlet.http.HttpServletRequest request)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `<T> T` | `getAttribute​(String attributeName, Class<T> aClass)` | Gets the specified attribute value from the session.
    `<T> T` | `getAttribute​(String attributeName, Class<T> aClass, T defaultValue)` | Gets the specified attribute value from the session.
    `<T> T` | `removeAttribute​(String attributeName, Class<T> aClass)` | Removes from the session the specified attribute.
    `<T> void` | `setAttribute​(String attributeName, T value)` | Sets the specified attribute value into the session.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SafeSessionManager

          public SafeSessionManager​(javax.servlet.http.HttpServletRequest request)

  - ### Method Detail

    - #### getAttribute

          public <T> T getAttribute​(String attributeName,
                                    Class<T> aClass)

      Gets the specified attribute value from the session.

      If the session does not exists, it is not created.

      If no value exists, null is returned.

      Type Parameters:
        `T` - the type of the value.
      Parameters:
        `attributeName` - the name of the attribute to fetch.
        `aClass` - the class of the value fetched.
      Returns:
        the value if any, null otherwise.

    - #### getAttribute

          public <T> T getAttribute​(String attributeName,
                                    Class<T> aClass,
                                    T defaultValue)

      Gets the specified attribute value from the session.

      If the session does not exists, it is not created.

      If no value exists, default one is returned.

      Type Parameters:
        `T` - the type of the value.
      Parameters:
        `attributeName` - the name of the attribute to fetch.
        `aClass` - the class of the value fetched.
        `defaultValue` - default value of no value fetched from session.
      Returns:
        the value if any, default value otherwise.

    - #### setAttribute

          public <T> void setAttribute​(String attributeName,
                                       T value)

      Sets the specified attribute value into the session.

      If the session does not exist, it is created.

      Type Parameters:
        `T` - the type of the value.
      Parameters:
        `attributeName` - the name of the attribute to fetch.
        `value` - the value to put.

    - #### removeAttribute

          public <T> T removeAttribute​(String attributeName,
                                       Class<T> aClass)

      Removes from the session the specified attribute.

      If the session does not exist, nothing is performed.

      Type Parameters:
        `T` - the type of the value.
      Parameters:
        `attributeName` - the name of the attribute to fetch.
        `aClass` - the class of the value fetched.
      Returns:
        the removed value if any, null otherwise.