de.fu_berlin.ties.io
Class FieldMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<String,Object>
              extended by de.fu_berlin.ties.io.FieldMap
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>

public class FieldMap
extends LinkedHashMap<String,Object>

A map targeted at serialization and deserialiation of objects in human-readable formats. It that allows creating (deserializing) an object by passing itself to the constructor.

This class preserves the guarantees of LinkedHashMap: it allows both efficient retrieval of values by key/field name (due to the contained hash map) and iteration of key/value pairs in order of insertion (due to the contained linked list).

Note that this implementation is not synchronized. If multiple threads access a field map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap(java.util.Map) method.

Version:
$Revision: 1.2 $, $Date: 2004/09/06 17:23:31 $, $Author: siefkes $
Author:
Christian Siefkes
See Also:
Serialized Form

Constructor Summary
FieldMap()
          Creates a new instance.
FieldMap(Map<String,Object> map)
          Creates a new instance with the same mappings as the specified map.
 
Method Summary
 Object createObject(Class type)
          Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts a field map as single argument and passing itself as parameter.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

FieldMap

public FieldMap()
Creates a new instance.


FieldMap

public FieldMap(Map<String,Object> map)
         throws NullPointerException
Creates a new instance with the same mappings as the specified map.

Parameters:
map - the map whose mappings are to be placed in this map
Throws:
NullPointerException - if the specified map is null
Method Detail

createObject

public Object createObject(Class type)
                    throws InstantiationException,
                           SecurityException
Creates (deserializes) an object of a specified type by calling a constructor of the class that accepts a field map as single argument and passing itself as parameter. Only classes that provide a suitable constructor can be instantiated this way.

Parameters:
type - the class of the object to create; must have a constructor whose only argument is a FieldMap
Returns:
the created object; the returned object will be an instance of the specified class
Throws:
InstantiationException - if instantiation failed
SecurityException - if access to the required reflection information is denied


Copyright © 2003-2004 Christian Siefkes. All Rights Reserved.