Package de.hybris.platform.jalo
Class SessionContext
- java.lang.Object
-
- de.hybris.platform.jalo.SessionContext
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
StandardSearchContext
public class SessionContext extends java.lang.Object implements java.io.Serializable
The Context-Object of a JaloSession.
This object is responsible for the current user, language, currency and custom session properties.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CURRENCY
static java.lang.String
CURRENTDATE
static java.lang.String
CURRENTDATE_VALID_TO
static java.lang.String
LANGUAGE
static java.lang.String
LOCALE
static java.lang.String
PRICEFACTORY
static java.lang.String
TIMEOFFSET
The name of the attribute which stores the time offset in milliseconds.static java.lang.String
TIMEZONE
static java.lang.String
TRANSACTION_4_ALLATTRIBUTES
static java.lang.String
TRANSACTION_IN_CREATE_DISABLED
Setting this attribute to 'TRUE' will DISABLE the execution of Item#newInstance( SessionContext, JaloSession, ComposedType, Map ) inside a transaction.static java.lang.String
USER
static java.lang.Long
ZERO_TIME_OFFSET
-
Constructor Summary
Constructors Modifier Constructor Description SessionContext()
SessionContext(SessionContext context)
protected
SessionContext(SessionContext context, boolean asLocal)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAllAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)
boolean
equals(java.lang.Object object)
protected void
fixStaleItemsInContext()
protected <T> T
fixStaleItemsInValue(java.lang.String name, T currentValue)
java.util.Date
getAdjustedCurrentDate()
Returns the current time ( seegetAdjustedCurrentTime()
) with hours, minutes, seconds and milliseconds normalized to zero.protected long
getAdjustedCurrentDateMillis()
java.util.Date
getAdjustedCurrentTime()
Returns the adjusted current time relative to time set by callingsetCurrentTime(Date)
early.protected long
getAdjustedCurrentTimeMillis()
java.util.Collection<java.lang.String>
getAllAttributeNames()
<T> T
getAttribute(java.lang.String name)
Returns the attribute mapped to key 'name'java.util.Enumeration
getAttributeNames()
Deprecated.since agesjava.util.Map<java.lang.String,java.lang.Object>
getAttributes()
Returns a unmodifiable copy of the session attributesCurrency
getCurrency()
Method getCurrencyprotected long
getCurrentTimeMillis()
Override for testing only !Language
getLanguage()
Returns the language currently associated with this session context.java.util.Locale
getLocale()
Returns theLocale
which matches the current language settings best.PriceFactory
getPriceFactory()
Method getPriceFactorylong
getTimeOffset()
Returns the time offset in milliseconds.java.util.TimeZone
getTimeZone()
Returns theTimeZone
which is currently associated with this session context.User
getUser()
Method getUserint
hashCode()
protected void
initializeOnSessionStartup(User user, Language language, Currency currency, java.util.TimeZone timeZone, PriceFactory injectedPriceFactory)
java.lang.Object
removeAttribute(java.lang.String name)
Method removeAttributejava.lang.Object
setAttribute(java.lang.String name, java.lang.Object value)
Method setAttributevoid
setAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)
Method setAttributesvoid
setCurrency(Currency currency)
Method setCurrencyvoid
setCurrentTime(java.util.Date timeInstance)
Set the given timeInstance as the current time.void
setCurrentTimeSystem()
Set the current time back to system timevoid
setLanguage(Language language)
Method setLanguagevoid
setLocale(java.util.Locale loc)
Changes theLocale
which should be associated with this session context.void
setPriceFactory(PriceFactory pricefactory)
Method setPriceFactoryprotected void
setSession(JaloSession session)
void
setSessionContextValues(SessionContext ctx)
void
setTimeZome(java.util.TimeZone timezone)
Deprecated.since ages - usesetTimeZone(TimeZone)
insteadvoid
setTimeZone(java.util.TimeZone timezone)
Changes the time zone which is associated with this session context.void
setUser(User user)
Method setUserjava.lang.String
toString()
-
-
-
Field Detail
-
USER
public static final java.lang.String USER
- See Also:
- Constant Field Values
-
LANGUAGE
public static final java.lang.String LANGUAGE
- See Also:
- Constant Field Values
-
CURRENCY
public static final java.lang.String CURRENCY
- See Also:
- Constant Field Values
-
PRICEFACTORY
public static final java.lang.String PRICEFACTORY
- See Also:
- Constant Field Values
-
LOCALE
public static final java.lang.String LOCALE
- See Also:
- Constant Field Values
-
TIMEZONE
public static final java.lang.String TIMEZONE
- See Also:
- Constant Field Values
-
ZERO_TIME_OFFSET
public static final java.lang.Long ZERO_TIME_OFFSET
-
TIMEOFFSET
public static final java.lang.String TIMEOFFSET
The name of the attribute which stores the time offset in milliseconds. This attribute allows adjusting time in a consistent way across the entire session.- See Also:
- Constant Field Values
-
CURRENTDATE
public static final java.lang.String CURRENTDATE
- See Also:
- Constant Field Values
-
CURRENTDATE_VALID_TO
public static final java.lang.String CURRENTDATE_VALID_TO
- See Also:
- Constant Field Values
-
TRANSACTION_IN_CREATE_DISABLED
public static final java.lang.String TRANSACTION_IN_CREATE_DISABLED
Setting this attribute to 'TRUE' will DISABLE the execution of Item#newInstance( SessionContext, JaloSession, ComposedType, Map ) inside a transaction.Sample:
ctx.setAttribute( SessionContext.TRANSACTION_IN_CREATE_DISABLED, Boolean.TRUE );
- See Also:
- Constant Field Values
-
TRANSACTION_4_ALLATTRIBUTES
public static final java.lang.String TRANSACTION_4_ALLATTRIBUTES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SessionContext
public SessionContext()
-
SessionContext
public SessionContext(SessionContext context)
-
SessionContext
protected SessionContext(SessionContext context, boolean asLocal)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
setSession
protected void setSession(JaloSession session)
-
initializeOnSessionStartup
protected void initializeOnSessionStartup(User user, Language language, Currency currency, java.util.TimeZone timeZone, PriceFactory injectedPriceFactory)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
setSessionContextValues
public void setSessionContextValues(SessionContext ctx)
-
setLanguage
public void setLanguage(Language language)
Method setLanguage- Parameters:
language
-
-
getLanguage
public Language getLanguage()
Returns the language currently associated with this session context. Please note that for some reasons the session context may hold no language at all ( e.g. when using the context to fetch all values of a localized attribute at once).
-
getLocale
public java.util.Locale getLocale()
Returns theLocale
which matches the current language settings best. This affects all data formatting logic within the hybris platform ( likeCurrency.formatPrice(double)
). The algorithm works as follows:- a locale has been set via
setLocale(Locale)
: return it directly - a language is present and its method
Language.getLocale()
returns a non-null locale: return this language dependent locale - otherwise simply return the vm default locale from
Locale.getDefault()
.
- Since:
- 3.0 M2
- a locale has been set via
-
setLocale
public void setLocale(java.util.Locale loc)
Changes theLocale
which should be associated with this session context. This affects all data formatting logic within the hybris platform ( likeCurrency.formatPrice(double)
).- Since:
- 3.0 M2
-
getTimeZone
public java.util.TimeZone getTimeZone()
Returns theTimeZone
which is currently associated with this session context. If no time zone has been set viasetTimeZome(TimeZone)
the default vm time zone is returned (seeTimeZone.getDefault()
. This affects all date formatting and parsing logic within the hybris platform.- Since:
- 3.0 M2
-
getTimeOffset
public long getTimeOffset()
Returns the time offset in milliseconds. If there has been no call tosetCurrentTime(Date)
, a value of zero is returned.
-
setTimeZome
@Deprecated public void setTimeZome(java.util.TimeZone timezone)
Deprecated.since ages - usesetTimeZone(TimeZone)
insteadChanges the time zone which is associated with this session context.- Since:
- 3.0 M2
-
setTimeZone
public void setTimeZone(java.util.TimeZone timezone)
Changes the time zone which is associated with this session context.- Since:
- 3.0 M2
-
setCurrency
public void setCurrency(Currency currency)
Method setCurrency- Parameters:
currency
-
-
getCurrency
public Currency getCurrency()
Method getCurrency
-
setUser
public void setUser(User user)
Method setUser- Parameters:
user
-
-
getUser
public User getUser()
Method getUser
-
setPriceFactory
public void setPriceFactory(PriceFactory pricefactory)
Method setPriceFactory- Parameters:
pricefactory
-
-
getPriceFactory
public PriceFactory getPriceFactory()
Method getPriceFactory
-
setAttributes
public void setAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)
Method setAttributes- Parameters:
attributes
-
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
Returns a unmodifiable copy of the session attributes- Returns:
- map
-
fixStaleItemsInContext
protected void fixStaleItemsInContext()
-
getAttribute
public <T> T getAttribute(java.lang.String name)
Returns the attribute mapped to key 'name'
-
fixStaleItemsInValue
protected <T> T fixStaleItemsInValue(java.lang.String name, T currentValue)
-
setAttribute
public java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
Method setAttribute
-
getAttributeNames
@Deprecated public java.util.Enumeration getAttributeNames()
Deprecated.since agesReturns an Enumeration of String objects containing the names of all the objects bound to this session. UsegetAllAttributeNames()
instead.
-
getAllAttributeNames
public java.util.Collection<java.lang.String> getAllAttributeNames()
-
addAllAttributes
public void addAllAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Method removeAttribute
-
setCurrentTime
public void setCurrentTime(java.util.Date timeInstance)
Set the given timeInstance as the current time. This method is used to adjust the current time to either a past or future instant.
-
getCurrentTimeMillis
protected long getCurrentTimeMillis()
Override for testing only !
-
getAdjustedCurrentTime
public java.util.Date getAdjustedCurrentTime()
Returns the adjusted current time relative to time set by callingsetCurrentTime(Date)
early. IfsetCurrentTime(Date)
was never called before, then current system time is returned.
-
getAdjustedCurrentTimeMillis
protected long getAdjustedCurrentTimeMillis()
-
setCurrentTimeSystem
public void setCurrentTimeSystem()
Set the current time back to system time
-
getAdjustedCurrentDate
public java.util.Date getAdjustedCurrentDate()
Returns the current time ( seegetAdjustedCurrentTime()
) with hours, minutes, seconds and milliseconds normalized to zero.
-
getAdjustedCurrentDateMillis
protected long getAdjustedCurrentDateMillis()
-
-