Class 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 Detail

      • 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_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

        protected SessionContext​(SessionContext context,
                                 boolean asLocal)
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.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 class java.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 the Locale which matches the current language settings best. This affects all data formatting logic within the hybris platform ( like Currency.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
      • setLocale

        public void setLocale​(java.util.Locale loc)
        Changes the Locale which should be associated with this session context. This affects all data formatting logic within the hybris platform ( like Currency.formatPrice(double) ).
        Since:
        3.0 M2
      • getTimeZone

        public java.util.TimeZone getTimeZone()
        Returns the TimeZone which is currently associated with this session context. If no time zone has been set via setTimeZome(TimeZone) the default vm time zone is returned (see TimeZone.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 to setCurrentTime(Date), a value of zero is returned.
      • setTimeZome

        @Deprecated
        public void setTimeZome​(java.util.TimeZone timezone)
        Deprecated.
        since ages - usesetTimeZone(TimeZone) instead
        Changes 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 ages
        Returns an Enumeration of String objects containing the names of all the objects bound to this session. Use getAllAttributeNames() 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 calling setCurrentTime(Date) early. If setCurrentTime(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 ( see getAdjustedCurrentTime() ) with hours, minutes, seconds and milliseconds normalized to zero.
      • getAdjustedCurrentDateMillis

        protected long getAdjustedCurrentDateMillis()