com.groiss.util
Class ThreadContext

java.lang.Object
  extended by com.groiss.util.ThreadContext

public class ThreadContext
extends java.lang.Object

This class is designed to hold thread specific information which can then be requested anywhere in the code.


Field Summary
static short HTTP_SESSION
          session types
static short INTERNAL_SESSION
           
static short RMI_SESSION
           
static short WEBDAV_SESSION
           
static short WEBSERVICE_SESSION
           
 
Constructor Summary
ThreadContext()
           
 
Method Summary
static void addThreadLocale(java.lang.ThreadLocal<?> local)
           
static void clean()
          Clean the thread context.
static java.lang.Object getAttribute(java.lang.Object key)
          Gets the value identified by the passed key
 java.util.Iterator<java.lang.Object> getAttributeKeys()
          Returns an iterator over all keys which were added via method setAttribute(Object, Object)
static java.lang.String getSessionId()
          Get the thread sessionId.
static ThreadLocal2<java.lang.String> getSessions()
          Get the sessions.
static short getSessionType()
          Get the type of the Session
static java.util.Locale getThreadLocale()
          Get the thread locale.
static
<T extends java.security.Principal>
T
getThreadPrincipal()
          Get the thread princiapl, the user who performs the action.
static javax.servlet.http.HttpServletRequest getThreadRequest()
          Get the HttpServletRequest of this thread.
static java.util.TimeZone getThreadTimeZone()
          Get the thread TimeZone
static void internalClean()
          Clean the thread context of internal sessions if configuration param is set to true
static boolean isPrivileged()
          Is the thread privileged.
static void removeAttribute(java.lang.Object key)
          Removes the key-value pair identified by the passed key
static void setAttribute(java.lang.Object key, java.lang.Object value)
          Adds a key-value pair to the thread's context.
static void setPrivileged()
          Set the thread privileged.
static void setSessionId(java.lang.String s)
          Set the session id of the thread.
static void setSessionType(short s)
          Set the type of this thread.
static void setThreadLocale(java.util.Locale l)
          Set the locale of the thread.
static void setThreadPrincipal(java.security.Principal p)
          Set the principal of the thread.
static void setThreadRequest(javax.servlet.http.HttpServletRequest req)
          Set the HttpServletRequest of the thread.
static void setThreadTimeZone(java.util.TimeZone t)
          Set the TimeZone of the thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_SESSION

public static final short HTTP_SESSION
session types

See Also:
Constant Field Values

RMI_SESSION

public static final short RMI_SESSION
See Also:
Constant Field Values

INTERNAL_SESSION

public static final short INTERNAL_SESSION
See Also:
Constant Field Values

WEBDAV_SESSION

public static final short WEBDAV_SESSION
See Also:
Constant Field Values

WEBSERVICE_SESSION

public static final short WEBSERVICE_SESSION
See Also:
Constant Field Values
Constructor Detail

ThreadContext

public ThreadContext()
Method Detail

setThreadLocale

public static void setThreadLocale(java.util.Locale l)
Set the locale of the thread.

Parameters:
l - a locale object

getThreadLocale

public static java.util.Locale getThreadLocale()
Get the thread locale. If the thread has no locale set, the method returns the default locale.

Returns:
a Locale object

setThreadPrincipal

public static void setThreadPrincipal(java.security.Principal p)
Set the principal of the thread.

Parameters:
p - a Principal object

getThreadPrincipal

public static <T extends java.security.Principal> T getThreadPrincipal()
Get the thread princiapl, the user who performs the action.

Returns:
a Principal object

setSessionId

public static void setSessionId(java.lang.String s)
Set the session id of the thread.

Parameters:
s - a string object

getSessionId

public static java.lang.String getSessionId()
Get the thread sessionId.

Returns:
a String object

setThreadTimeZone

public static void setThreadTimeZone(java.util.TimeZone t)
Set the TimeZone of the thread.

Parameters:
t - a TimeZone object

getThreadTimeZone

public static java.util.TimeZone getThreadTimeZone()
Get the thread TimeZone

Returns:
a TimeZone object

getSessions

public static ThreadLocal2<java.lang.String> getSessions()
Get the sessions.

Returns:
a ThreadLocal2 object

setPrivileged

public static void setPrivileged()
Set the thread privileged.


isPrivileged

public static boolean isPrivileged()
Is the thread privileged.

Returns:
true if user of this thread is sysadm

setThreadRequest

public static void setThreadRequest(javax.servlet.http.HttpServletRequest req)
Set the HttpServletRequest of the thread.

Parameters:
req - a HttpServletRequest object

getThreadRequest

public static javax.servlet.http.HttpServletRequest getThreadRequest()
Get the HttpServletRequest of this thread.

Returns:
a HttpServletRequest object

getSessionType

public static short getSessionType()
Get the type of the Session

Returns:
the Session type.

setSessionType

public static void setSessionType(short s)
Set the type of this thread.

Parameters:
s - either HTTP_SESSION, RMI_SESSION or INTERNAL_SESSION

setAttribute

public static void setAttribute(java.lang.Object key,
                                java.lang.Object value)
Adds a key-value pair to the thread's context. If the key is already contained, the old value is replaced.

Parameters:
key - key with which the specified value is to be associated
value - value to be associated with the specified key

getAttribute

public static java.lang.Object getAttribute(java.lang.Object key)
Gets the value identified by the passed key

Parameters:
key - key whose value should be retrieved
Returns:
the value object

removeAttribute

public static void removeAttribute(java.lang.Object key)
Removes the key-value pair identified by the passed key

Parameters:
key - key whose value should be removed

getAttributeKeys

public java.util.Iterator<java.lang.Object> getAttributeKeys()
Returns an iterator over all keys which were added via method setAttribute(Object, Object)

Returns:
iterator containing the key objects

clean

public static void clean()
Clean the thread context.


internalClean

public static void internalClean()
Clean the thread context of internal sessions if configuration param is set to true


addThreadLocale

public static void addThreadLocale(java.lang.ThreadLocal<?> local)


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.