org.apache.shiro.util
Class MapContext

java.lang.Object
  extended by org.apache.shiro.util.MapContext
All Implemented Interfaces:
Serializable, Map<String,Object>
Direct Known Subclasses:
DefaultSessionContext, DefaultSubjectContext

public class MapContext
extends Object
implements Map<String,Object>, Serializable

A MapContext provides a common base for context-based data storage in a Map. Type-safe attribute retrieval is provided for subclasses with the getTypedValue(String, Class) method.

Since:
1.0
See Also:
SubjectContext, SessionContext, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
MapContext()
           
MapContext(Map<String,Object> map)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object o)
           
 boolean containsValue(Object o)
           
 Set<Map.Entry<String,Object>> entrySet()
           
 Object get(Object o)
           
protected
<E> E
getTypedValue(String key, Class<E> type)
          Performs a get operation but additionally ensures that the value returned is of the specified type.
 boolean isEmpty()
           
 Set<String> keySet()
           
protected  void nullSafePut(String key, Object value)
          Places a value in this context map under the given key only if the given value argument is not null.
 Object put(String s, Object o)
           
 void putAll(Map<? extends String,?> map)
           
 Object remove(Object o)
           
 int size()
           
 Collection<Object> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

MapContext

public MapContext()

MapContext

public MapContext(Map<String,Object> map)
Method Detail

getTypedValue

protected <E> E getTypedValue(String key,
                              Class<E> type)
Performs a get operation but additionally ensures that the value returned is of the specified type. If there is no value, null is returned.

Type Parameters:
E - the expected type of the value
Parameters:
key - the attribute key to look up a value
type - the expected type of the value
Returns:
the typed value or null if the attribute does not exist.

nullSafePut

protected void nullSafePut(String key,
                           Object value)
Places a value in this context map under the given key only if the given value argument is not null.

Parameters:
key - the attribute key under which the non-null value will be stored
value - the non-null value to store. If null, this method does nothing and returns immediately.

size

public int size()
Specified by:
size in interface Map<String,Object>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<String,Object>

containsKey

public boolean containsKey(Object o)
Specified by:
containsKey in interface Map<String,Object>

containsValue

public boolean containsValue(Object o)
Specified by:
containsValue in interface Map<String,Object>

get

public Object get(Object o)
Specified by:
get in interface Map<String,Object>

put

public Object put(String s,
                  Object o)
Specified by:
put in interface Map<String,Object>

remove

public Object remove(Object o)
Specified by:
remove in interface Map<String,Object>

putAll

public void putAll(Map<? extends String,?> map)
Specified by:
putAll in interface Map<String,Object>

clear

public void clear()
Specified by:
clear in interface Map<String,Object>

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,Object>

values

public Collection<Object> values()
Specified by:
values in interface Map<String,Object>

entrySet

public Set<Map.Entry<String,Object>> entrySet()
Specified by:
entrySet in interface Map<String,Object>


Copyright © 2004-2014 The Apache Software Foundation. All Rights Reserved.