|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.io.FieldContainer
public class FieldContainer
A container of FieldMap
s. A container stores all
field maps added to itself and keeps a set of all keys found in the field
maps. This is an "append-only" container; field maps can only be added but
never removed.
Instances of this class are not thread-safe and must be synchronized externally, if required.
Constructor Summary | |
---|---|
FieldContainer()
Creates a new empty instance. |
|
FieldContainer(Element element)
Creates a new instance from an XML element, fulfilling the recommandation of the XMLStorable interface. |
Method Summary | |
---|---|
void |
add(FieldMap map)
Adds a field map to this container. |
protected void |
add(FieldMap map,
boolean checkKeys)
Helper method for adding a field map to this container. |
void |
add(List values,
int sectionNo)
Adds a field map created from the specified values, using the n-th key from the set of all keys for the n-th specified value. |
void |
add(Storable storable)
Adds the representation of a Storable to this container, by
calling its Storable.storeFields() method and adding the
resulting field map. |
void |
add(StorableContainer contents)
Adds the contents of a StorableContainer to this container, by
delegating to StorableContainer.storeEntries(FieldContainer) . |
protected boolean |
addKey(String key)
Helper method that adds a key to the set of all keys. |
FieldMap |
backgroundMap()
This map can be used to extend newly added field maps: at each add(FieldMap) operation, any key/value pairs from this map are
added to field map prior to storing it. |
static FieldContainer |
createFieldContainer(TiesConfiguration config)
Factory method that creates a field container in DelimSepValues
format. |
List<Object> |
createObjects(Class type)
Creates (deserializes) an list of objects of a specified type by calling FieldMap.createObject(Class) for each of the field maps contained
in this container. |
Iterator<FieldMap> |
entryIterator()
Returns an iterator over the FieldMap s in this container in the
order they were added. |
int |
keyCount()
Returns the number of keys in this container. |
Iterator<String> |
keyIterator()
Returns an iterator over the set of all keys used in contained field maps. |
void |
read(CharSequence input)
Subclasses can overwrite this method to deserialize their contents in a class-specific format. |
void |
read(InputStream in)
Read deserialized data. |
void |
read(Reader reader)
Read deserialized data. |
static String |
recommendedExtension()
Returns the file extension recommended for FieldContainer s. |
int |
size()
Returns the number of entries stored in this container. |
void |
store(OutputStream out)
Serializes contents by wrapping the stream in a Unicode writer and delegating to store(Writer) . |
void |
store(Writer writer)
Subclasses can overwrite this method to serialize their contents in a class-specific format. |
static File |
storeContainerInFile(StorableContainer sContainer,
File directory,
String baseName,
String extension,
TiesConfiguration config)
Convenience method that serializes the contents of a container in a file in standard format, delegating to createFieldContainer(TiesConfiguration) and
storeInFile(File, String, String, Configuration) . |
File |
storeInFile(File directory,
String baseName,
String extension,
Configuration config)
Convenience method for serializing the contents of this container in a file. |
ObjectElement |
toElement()
Stores all relevant fields of this object in an XML element for serialization. This implementation delegates to toElement(String) , setting the name of the main element to "list". |
ObjectElement |
toElement(QName name)
Stores all contents of this container in an XML element for serialization, without using a medium level. |
ObjectElement |
toElement(QName name,
QName level2Name)
Stores all contents of this container in an XML element for serialization. |
ObjectElement |
toElement(String localName)
Stores all contents of this container in an XML element for serialization. |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FieldContainer()
public FieldContainer(Element element)
XMLStorable
interface.
element
- the XML element containing the serialized representationMethod Detail |
---|
public static FieldContainer createFieldContainer(TiesConfiguration config)
DelimSepValues
format.
config
- used to configure the container
public static String recommendedExtension()
FieldContainer
s.
DelimSepValues.FILE_EXT
public static File storeContainerInFile(StorableContainer sContainer, File directory, String baseName, String extension, TiesConfiguration config) throws IOException
createFieldContainer(TiesConfiguration)
and
storeInFile(File, String, String, Configuration)
.
sContainer
- the container to serializedirectory
- the directory in which to store the databaseName
- the base name of the file using for storing the dataextension
- the file extension to use; if null
,
the recommended extension is usedconfig
- used to determine the container format and output character
set
IOException
- if an I/O error occursprotected boolean addKey(String key)
key
- the key to add
true
if the set did not already contain the
specified elementpublic void add(FieldMap map)
map
- the field map to addpublic void add(Storable storable)
Storable
to this container, by
calling its Storable.storeFields()
method and adding the
resulting field map.
storable
- the storable whose fields to addpublic void add(StorableContainer contents)
StorableContainer
to this container, by
delegating to StorableContainer.storeEntries(FieldContainer)
.
contents
- the contents to add by calling
StorableContainer.storeEntries(FieldContainer)
protected void add(FieldMap map, boolean checkKeys)
map
- the field map to addcheckKeys
- whether to check the keys of the field map and add any
missing keys to the set of all keys; subclasses calling this method can
set this to false
iff they know for sure that the map does
not contain any new keyspublic void add(List values, int sectionNo) throws IllegalArgumentException
null
values are omitted
(the corresponding key is skipped).
values
- the list of values to store in the field mapsectionNo
- the number of the current
section
IllegalArgumentException
- if the specified array contains more
elements than the set of all keyspublic FieldMap backgroundMap()
add(FieldMap)
operation, any key/value pairs from this map are
added to field map prior to storing it. The map is empty by default.
public List<Object> createObjects(Class type) throws InstantiationException, SecurityException
FieldMap.createObject(Class)
for each of the field maps contained
in this container. The contained field maps are deserialized in the order
they were added to this container.
type
- the class of the objects 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 Iterator<FieldMap> entryIterator()
FieldMap
s in this container in the
order they were added.
public int keyCount()
public Iterator<String> keyIterator()
public void read(CharSequence input)
UnsupportedOperationException
instead.
input
- the input data to processpublic final void read(InputStream in) throws IOException
read(Reader)
. Internally uses
IOUtils.openCompressableInStream(InputStream)
so
gzip
-compressed streams are also supported.
in
- the input stream to read from; not closed by this method
IOException
- if an I/O error occurs while reading the datapublic final void read(Reader reader) throws IOException
read(CharSequence)
.
reader
- the reader to read from; not closed by this method
IOException
- if an I/O error occurs while reading the datapublic int size()
public final void store(OutputStream out) throws IOException
store(Writer)
.
out
- the output stream to write to; flushed but not closed by this
method
IOException
- if an I/O error occurs while writing to the streampublic void store(Writer writer) throws IOException
UnsupportedOperationException
instead.
writer
- the writer to write to; not closed by this method
IOException
- if an I/O error occurs while serializing the datapublic File storeInFile(File directory, String baseName, String extension, Configuration config) throws IOException
directory
- the directory in which to store the databaseName
- the base name of the file using for storing the dataextension
- the file extension to use; if null
,
the recommended extension is usedconfig
- used to determine the output character set (by delegating
to IOUtils.openWriter(File, Configuration)
IOException
- if an I/O error occurspublic ObjectElement toElement()
ObjectElement.createObject(org.dom4j.Element,
Class)
on the created element. This implementation delegates to toElement(String)
, setting the name of the main element to "list".
toElement
in interface XMLStorable
public ObjectElement toElement(QName name)
name
- the qualified name to use for the main element
public ObjectElement toElement(QName name, QName level2Name)
level2Name
is given, an element of this
name is created for each non-empty section in this container; each field map is stored as child element of
section it is in. Otherwise (if level2Name
is
null
) all field maps are stored as direct child elements of
the main element, without using a medium level.
name
- the qualified name to use for the main elementlevel2Name
- the name of elements inserted as medium level;
or null
if no medium level should be used
public ObjectElement toElement(String localName)
localName
- the local name to use for the main element, will be
converted into a qualified name by calling
DOMUtils.defaultName(String)
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |