Class DefaultSignServiceContext

java.lang.Object
se.swedenconnect.signservice.context.DefaultSignServiceContext
All Implemented Interfaces:
Serializable, SignServiceContext

public class DefaultSignServiceContext extends Object implements SignServiceContext
Default implementation of the SignServiceContext interface.
See Also:
  • Constructor Details

    • DefaultSignServiceContext

      public DefaultSignServiceContext(@Nonnull String id)
      Constructor.
      Parameters:
      id - the context ID
  • Method Details

    • getId

      @Nonnull public String getId()
      Gets the unique ID for the current operation. This ID should be included in all logs (process- and audit logs).
      Specified by:
      getId in interface SignServiceContext
      Returns:
      the unique ID for the operation
    • put

      public <T extends Serializable> void put(@Nonnull String name, @Nullable T data)
      Stores a data element in the context.
      Specified by:
      put in interface SignServiceContext
      Type Parameters:
      T - the type of the element
      Parameters:
      name - the unique name of the element
      data - the element to store
    • get

      @Nullable public <T extends Serializable> T get(@Nonnull String name)
      Gets a named data element from the context.
      Specified by:
      get in interface SignServiceContext
      Type Parameters:
      T - the type of the element
      Parameters:
      name - the unique name of the element
      Returns:
      the element, or null if no matching element is available
    • get

      @Nonnull public <T extends Serializable> T get(@Nonnull String name, @Nonnull Class<T> type) throws ClassCastException
      Gets a named data element having a given type from the context.
      Specified by:
      get in interface SignServiceContext
      Type Parameters:
      T - the type of the element
      Parameters:
      name - the unique name of the element
      type - the type of the element
      Returns:
      the element, or null if no matching element is available
      Throws:
      ClassCastException - if the element exists but is not of the given type
    • remove

      public <T extends Serializable> void remove(@Nonnull String name)
      Removes the named element from the context.

      The rationale behind this method is that a module that writes a large data element to the context should be able to remove it when it os no longer needed. In this way, storing the context is cheaper.

      Specified by:
      remove in interface SignServiceContext
      Type Parameters:
      T - the type of the element
      Parameters:
      name - the unique name of the element
    • serialize

      @Nonnull public String serialize()
      Serializes the context to its string representation/encoding.
      Specified by:
      serialize in interface SignServiceContext
      Returns:
      the string encoding of the context object
    • deserialize

      @Nonnull public static DefaultSignServiceContext deserialize(@Nonnull String encoding)
      Deserializes an encoding to a DefaultSignServiceContext object.
      Parameters:
      encoding - the string encoding
      Returns:
      a DefaultSignServiceContext object