org.jboss.portal.common.util
Class TypedMap

java.lang.Object
  extended by org.jboss.portal.common.util.TypedMap
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
AbstractPropertyMap, ParameterMap, PersistentRegistration.Properties

public abstract class TypedMap
extends java.lang.Object
implements java.util.Map

A decorator that enforce the map content to be checked against a type. Null internal values are not supported.

Version:
$Revision: 7304 $
Author:
Julien Viet

Nested Class Summary
 class TypedMap.KeySet
           
 class TypedMap.TypedEntrySet
           
 class TypedMap.ValueCollection
           
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  MapAccessor accessor
          The map accessor.
 
Constructor Summary
protected TypedMap(java.util.Map delegate)
           
protected TypedMap(MapAccessor accessor)
           
 
Method Summary
protected  void assertKeyValidity(java.lang.Object key)
          Override to check the validity of the key, the default implementation is an empty method.
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
protected  java.util.Map convert(java.util.Map t)
          Validate the map and unwrap it if necessary.
 java.util.Set entrySet()
           
 boolean equals(java.lang.Object o)
          Compare to parameters objects.
 java.lang.Object get(java.lang.Object key)
           
protected  java.util.Map getDelegate(boolean requestWriteable)
          Return the map provided by the accessor.
protected  java.lang.Object getExternalKey(java.lang.Object key)
          Wrap the internal key into its external representation, by default returns the same key.
protected  java.lang.Object getExternalValue(java.lang.Object value)
          Wrap the internal value into its external representation.
protected  java.lang.Object getInternalKey(java.lang.Object key)
          Unwraps the key to the the internal key that will be stored in the map.
protected  java.lang.Object getInternalValue(java.lang.Object value)
          Unwrap the value to the the internal value that will be stored in the map.
protected  boolean internalValueEquals(java.lang.Object left, java.lang.Object right)
          Compare internal values, the default implementation delegates the operation to the equals method of the left argument.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 java.lang.Object remove(java.lang.Object key)
           
 void replace(java.util.Map t)
          Replace the content with the new map which is validated before replacement.
 int size()
           
 java.lang.String toString()
           
protected  java.lang.Object unwrapKey(java.lang.Object externalKey)
           
protected  java.lang.Object unwrapValue(java.lang.Object externalValue)
          Extract the internal value from an external value.
 void validate()
          Validate the content.
 java.util.Collection values()
           
protected  java.lang.Object wrapKey(java.lang.Object internalKey)
           
protected  java.lang.Object wrapValue(java.lang.Object internalValue)
          Convert an internal value into an external value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode
 

Field Detail

accessor

protected final MapAccessor accessor
The map accessor.

Constructor Detail

TypedMap

protected TypedMap(MapAccessor accessor)

TypedMap

protected TypedMap(java.util.Map delegate)
Method Detail

getDelegate

protected final java.util.Map getDelegate(boolean requestWriteable)
Return the map provided by the accessor.

Parameters:
requestWriteable -
Returns:
the delegate map

assertKeyValidity

protected void assertKeyValidity(java.lang.Object key)
                          throws java.lang.IllegalArgumentException,
                                 java.lang.ClassCastException
Override to check the validity of the key, the default implementation is an empty method.

Throws:
java.lang.ClassCastException - if the class of the specified key prevents it from being stored in this map
java.lang.IllegalArgumentException - if some aspect of this key prevents it from being stored in this map

getInternalKey

protected java.lang.Object getInternalKey(java.lang.Object key)
                                   throws java.lang.IllegalArgumentException,
                                          java.lang.ClassCastException
Unwraps the key to the the internal key that will be stored in the map. This method calls the assertKeyValidity(Object key) and returns the same key. It can be overriden to provide a customized key that will be used instead of the external key.

Parameters:
key - the key to unwrap
Returns:
the unwrapped key
Throws:
java.lang.ClassCastException - if the class of the specified key prevents it from being stored in this map
java.lang.IllegalArgumentException - if some aspect of this key prevents it from being stored in this map

getExternalKey

protected java.lang.Object getExternalKey(java.lang.Object key)
Wrap the internal key into its external representation, by default returns the same key. It can be overriden to provide a customized key that will be used instead of the internal key.


unwrapKey

protected final java.lang.Object unwrapKey(java.lang.Object externalKey)
                                    throws java.lang.IllegalArgumentException,
                                           java.lang.ClassCastException,
                                           java.lang.NullPointerException
Throws:
java.lang.IllegalArgumentException
java.lang.ClassCastException
java.lang.NullPointerException

wrapKey

protected final java.lang.Object wrapKey(java.lang.Object internalKey)
                                  throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

getInternalValue

protected java.lang.Object getInternalValue(java.lang.Object value)
                                     throws java.lang.IllegalArgumentException,
                                            java.lang.ClassCastException
Unwrap the value to the the internal value that will be stored in the map.

Parameters:
value - the value to unwrap
Returns:
the unwrapped value
Throws:
java.lang.ClassCastException - if the class of the specified value prevents it from being stored in this map
java.lang.IllegalArgumentException - if some aspect of this value prevents it from being stored in this map

getExternalValue

protected java.lang.Object getExternalValue(java.lang.Object value)
Wrap the internal value into its external representation. The external representation value should not be null. If it is not possible to obtain an external value representation of the internal value, then the the null value should be returned from this method.

Parameters:
value - the param value which will not be null
Returns:
the external value

unwrapValue

protected final java.lang.Object unwrapValue(java.lang.Object externalValue)
                                      throws java.lang.IllegalArgumentException,
                                             java.lang.ClassCastException,
                                             java.lang.NullPointerException
Extract the internal value from an external value.

Parameters:
externalValue - the external value to unwrap
Returns:
the non null internal value
Throws:
java.lang.IllegalArgumentException
java.lang.ClassCastException
java.lang.NullPointerException

wrapValue

protected final java.lang.Object wrapValue(java.lang.Object internalValue)
                                    throws java.lang.IllegalStateException
Convert an internal value into an external value.

Parameters:
internalValue - the internal value
Returns:
the non null external value
Throws:
java.lang.IllegalStateException - if the internal value was null or some aspect prevented it to be converted to an external representation

internalValueEquals

protected boolean internalValueEquals(java.lang.Object left,
                                      java.lang.Object right)
Compare internal values, the default implementation delegates the operation to the equals method of the left argument.

Parameters:
left -
right -
Returns:
true if the values are equals

size

public int size()
Specified by:
size in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

equals

public boolean equals(java.lang.Object o)
Compare to parameters objects.

Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

replace

public void replace(java.util.Map t)
             throws java.lang.ClassCastException,
                    java.lang.NullPointerException,
                    java.lang.IllegalArgumentException
Replace the content with the new map which is validated before replacement.

Parameters:
t - the replacement map
Throws:
java.lang.ClassCastException
java.lang.NullPointerException
java.lang.IllegalArgumentException

validate

public void validate()
              throws java.lang.ClassCastException,
                     java.lang.NullPointerException,
                     java.lang.IllegalArgumentException
Validate the content.

Throws:
java.lang.ClassCastException
java.lang.NullPointerException
java.lang.IllegalArgumentException

convert

protected final java.util.Map convert(java.util.Map t)
                               throws java.lang.IllegalArgumentException,
                                      java.lang.NullPointerException,
                                      java.lang.ClassCastException
Validate the map and unwrap it if necessary.

Throws:
java.lang.IllegalArgumentException
java.lang.NullPointerException
java.lang.ClassCastException