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.SerializableThe 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.StringCURRENCYstatic java.lang.StringCURRENTDATEstatic java.lang.StringCURRENTDATE_VALID_TOstatic java.lang.StringLANGUAGEstatic java.lang.StringLOCALEstatic java.lang.StringPRICEFACTORYstatic java.lang.StringTIMEOFFSETThe name of the attribute which stores the time offset in milliseconds.static java.lang.StringTIMEZONEstatic java.lang.StringTRANSACTION_4_ALLATTRIBUTESstatic java.lang.StringTRANSACTION_IN_CREATE_DISABLEDSetting this attribute to 'TRUE' will DISABLE the execution of Item#newInstance( SessionContext, JaloSession, ComposedType, Map ) inside a transaction.static java.lang.StringUSERstatic java.lang.LongZERO_TIME_OFFSET
-
Constructor Summary
Constructors Modifier Constructor Description SessionContext()SessionContext(SessionContext context)protectedSessionContext(SessionContext context, boolean asLocal)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAllAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)booleanequals(java.lang.Object object)protected voidfixStaleItemsInContext()protected <T> TfixStaleItemsInValue(java.lang.String name, T currentValue)java.util.DategetAdjustedCurrentDate()Returns the current time ( seegetAdjustedCurrentTime()) with hours, minutes, seconds and milliseconds normalized to zero.protected longgetAdjustedCurrentDateMillis()java.util.DategetAdjustedCurrentTime()Returns the adjusted current time relative to time set by callingsetCurrentTime(Date)early.protected longgetAdjustedCurrentTimeMillis()java.util.Collection<java.lang.String>getAllAttributeNames()<T> TgetAttribute(java.lang.String name)Returns the attribute mapped to key 'name'java.util.EnumerationgetAttributeNames()Deprecated.since agesjava.util.Map<java.lang.String,java.lang.Object>getAttributes()Returns a unmodifiable copy of the session attributesCurrencygetCurrency()Method getCurrencyprotected longgetCurrentTimeMillis()Override for testing only !LanguagegetLanguage()Returns the language currently associated with this session context.java.util.LocalegetLocale()Returns theLocalewhich matches the current language settings best.PriceFactorygetPriceFactory()Method getPriceFactorylonggetTimeOffset()Returns the time offset in milliseconds.java.util.TimeZonegetTimeZone()Returns theTimeZonewhich is currently associated with this session context.UsergetUser()Method getUserinthashCode()protected voidinitializeOnSessionStartup(User user, Language language, Currency currency, java.util.TimeZone timeZone, PriceFactory injectedPriceFactory)java.lang.ObjectremoveAttribute(java.lang.String name)Method removeAttributejava.lang.ObjectsetAttribute(java.lang.String name, java.lang.Object value)Method setAttributevoidsetAttributes(java.util.Map<java.lang.String,? extends java.lang.Object> attributes)Method setAttributesvoidsetCurrency(Currency currency)Method setCurrencyvoidsetCurrentTime(java.util.Date timeInstance)Set the given timeInstance as the current time.voidsetCurrentTimeSystem()Set the current time back to system timevoidsetLanguage(Language language)Method setLanguagevoidsetLocale(java.util.Locale loc)Changes theLocalewhich should be associated with this session context.voidsetPriceFactory(PriceFactory pricefactory)Method setPriceFactoryprotected voidsetSession(JaloSession session)voidsetSessionContextValues(SessionContext ctx)voidsetTimeZome(java.util.TimeZone timezone)Deprecated.since ages - usesetTimeZone(TimeZone)insteadvoidsetTimeZone(java.util.TimeZone timezone)Changes the time zone which is associated with this session context.voidsetUser(User user)Method setUserjava.lang.StringtoString()
-
-
-
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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein 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:
toStringin 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 theLocalewhich 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 theLocalewhich 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 theTimeZonewhich 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()
-
-