|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<String,Object>
de.fu_berlin.ties.io.FieldMap
public class FieldMap
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.
Constructor Summary | |
---|---|
FieldMap()
Creates a new instance, setting the section number to 0. |
|
FieldMap(Element element)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface. |
|
FieldMap(Element element,
int sectionNo)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface. |
|
FieldMap(int sectionNo)
Creates a new instance. |
|
FieldMap(Map<String,Object> map)
Creates a new instance with the same mappings as the specified map, setting the section number to 0. |
|
FieldMap(Map<String,Object> map,
int sectionNo)
Creates a new instance with the same mappings as the specified map. |
|
FieldMap(String firstKey,
Object firstValue)
Convenience constructor that delegates to the standard
constructor and then puts a first key/value pair into the 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. |
int |
getSection()
Returns the number of the section this field map is in. |
ObjectElement |
toElement()
Stores all relevant fields of this object in an XML element for serialization. This implementation delegates to toElement(boolean) , setting the Java attribute. |
ObjectElement |
toElement(boolean setJavaAttrib)
Stores all relevant fields of this object in an XML element for serialization. |
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 |
---|
public FieldMap()
public FieldMap(Map<String,Object> map) throws NullPointerException
map
- the map whose mappings are to be placed in this map
NullPointerException
- if the specified map is nullpublic FieldMap(String firstKey, Object firstValue)
standard
constructor
and then puts a first key/value pair into the map.
firstKey
- the key of the first key/value pairfirstValue
- the value of the first key/value pairpublic FieldMap(int sectionNo)
sectionNo
- the number of the section
this field map is inpublic FieldMap(Map<String,Object> map, int sectionNo) throws NullPointerException
map
- the map whose mappings are to be placed in this mapsectionNo
- the number of the section
this field map is in
NullPointerException
- if the specified map is nullpublic FieldMap(Element element) throws IllegalArgumentException
XMLStorable
interface.
The section number is set to 0.
element
- the XML element containing the serialized representation
IllegalArgumentException
- if the element contains child elementspublic FieldMap(Element element, int sectionNo) throws IllegalArgumentException
XMLStorable
interface.
element
- the XML element containing the serialized representationsectionNo
- the number of the section
this field map is in
IllegalArgumentException
- if the element contains child elementsMethod Detail |
---|
public Object createObject(Class type) throws InstantiationException, SecurityException
type
- the class of the object to create; must have a constructor
whose only argument is a FieldMap
InstantiationException
- if instantiation failed
SecurityException
- if access to the required reflection
information is deniedpublic int getSection()
FieldContainer
s contains one or multiple sections which are
numbered sequentially starting from 0. In case of the
DSV format, sections are separated by
empty lines.
public ObjectElement toElement()
ObjectElement.createObject(org.dom4j.Element,
Class)
on the created element. This implementation delegates to
toElement(boolean)
, setting the Java attribute.
toElement
in interface XMLStorable
public ObjectElement toElement(boolean setJavaAttrib)
null
is returned.
setJavaAttrib
- whether to store the class of this object in the
ObjectElement.JAVA_CLASS_ATTRIBUTE
attribute; if
false
this attribute is not used
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |