All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.session.SimpleSession Maven / Gradle / Ivy

The newest version!
package com.enonic.xp.session;

import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.ImmutableMap;

@Deprecated
public final class SimpleSession
    implements Session
{
    private final SessionKey key;

    private final Map attributes;

    public SimpleSession( final SessionKey key )
    {
        this.key = key;
        this.attributes = new HashMap<>();
    }

    @Override
    public SessionKey getKey()
    {
        return this.key;
    }

    @Override
    public Object getAttribute( final String key )
    {
        return this.attributes.get( key );
    }

    @Override
    @SuppressWarnings("unchecked")
    public  T getAttribute( final Class type )
    {
        return (T) getAttribute( type.getName() );
    }

    @Override
    public void setAttribute( final String key, final Object value )
    {
        this.attributes.put( key, value );
    }

    @Override
    public  void setAttribute( final T value )
    {
        setAttribute( value.getClass().getName(), value );
    }

    @Override
    public Map getAttributes()
    {
        return ImmutableMap.copyOf( this.attributes );
    }

    @Override
    public void removeAttribute( final String key )
    {
        this.attributes.remove( key );
    }

    @Override
    public  void removeAttribute( final Class type )
    {
        removeAttribute( type.getName() );
    }

    @Override
    public void invalidate()
    {
        this.attributes.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy