public interface DataAdaptor
DataAdaptor
is a generic interface to an external data source.
A specific data adaptor (e.g. XmlDataAdaptor
) will implement this interface to
advertise its data in a generic way for reading and writing to a specific
data source (e.g. XML file). DataAdaptor
is intended to be a generic
wrapper for specific data sources and sinks. Data adaptors do not have any knowledge
about the objects that read and write data. Such data receivers and writers
should implement the
interface (or the
DataListener
interface for model persistence).
IArchive
A DataAdaptor
instance is generated for each node in a hierarchical data
tree and advertises information about the node and provides accessors
to its children. Information about a node is in the form of attributes
which represent key/value pairs of primitive data. The node also contains
a text string which represents the data node "content".
The general structure of the data should be tree based, analogous to that of
the XML DOM structure. Data is distributed by nodes in a tree, each node having
a data label (see
), attributes, and possibly some
type of string content (see name()
DataAdaptor#getContent()
- currently unimplimented).
There are potentially child data nodes of each node (see
and createChild(String)
).
childAdaptor(String)
Any object that is able to read and write from
DataAdaptor
interfaces
can implement the DataListener
interface. The idea is that such an
object should know, itself, how to load and save data from this interface, and expect
to receive the appropriate DataAdaptor
object for doing so. Finally,
note that the update(DataAdaptor)
and write(DataAdaptor)
methods of the
IDataAware
interface expect IDataAdaptors
in different
positions on the data tree. This must be the case for proper logistical implementation.
The update()
method expects to be synchronized to the current data node while
the write()
method expects to be given the parent of the data node it is to
populate. See the documentation for the DataListener
interface for more
information.Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
attributes()
return the array of all attributes
|
boolean |
booleanValue(java.lang.String attribute)
boolean value associated with the specified attribute
|
DataAdaptor |
childAdaptor(java.lang.String label)
Convenience method to get a single child adaptor when only one is expected
|
java.util.List<DataAdaptor> |
childAdaptors()
return all child adaptors
|
java.util.List<DataAdaptor> |
childAdaptors(java.lang.String label)
return all child adaptors of the specified node name
|
DataAdaptor |
createChild(java.lang.String label)
Create an new empty child adaptor with label
|
double[] |
doubleArray(java.lang.String attribute)
Returns the value of an attribute as an array of doubles.
|
double |
doubleValue(java.lang.String attribute)
double value associated with the specified attribute
|
boolean |
hasAttribute(java.lang.String attribute)
returns true iff the node has the specified attribute
|
int |
intValue(java.lang.String attribute)
integer value associated with the specified attribute
|
long |
longValue(java.lang.String attribute)
long value associated with the specified attribute
|
java.lang.String |
name()
name for the particular node in the data tree
|
void |
setValue(java.lang.String attribute,
boolean value)
set the value of the specified attribute to the specified value
|
void |
setValue(java.lang.String attribute,
double value)
set the value of the specified attribute to the specified value
|
void |
setValue(java.lang.String attribute,
double[] array)
Stores the value of the given
double[] object in the data adaptor backing store. |
void |
setValue(java.lang.String attribute,
int value)
set the value of the specified attribute to the specified value
|
void |
setValue(java.lang.String attribute,
long value)
set the value of the specified attribute to the specified value
|
void |
setValue(java.lang.String attribute,
java.lang.Object value)
set the value of the specified attribute to the specified value
|
void |
setValue(java.lang.String attribute,
java.lang.String value)
set the value of the specified attribute to the specified value
|
java.lang.String |
stringValue(java.lang.String attribute)
string value associated with the specified attribute
|
void |
writeNode(DataListener listener)
write the listener as a new node and append it to the data tree
|
void |
writeNodes(java.util.Collection<? extends DataListener> nodes)
Write the collection of listeners to new nodes and append them to the data tree.
|
java.lang.String name()
boolean hasAttribute(java.lang.String attribute)
java.lang.String stringValue(java.lang.String attribute)
double doubleValue(java.lang.String attribute)
long longValue(java.lang.String attribute)
int intValue(java.lang.String attribute)
boolean booleanValue(java.lang.String attribute)
double[] doubleArray(java.lang.String attribute)
attribute
- the attribute namenull
value is returned if the value string is empty.void setValue(java.lang.String attribute, java.lang.String value)
void setValue(java.lang.String attribute, double value)
void setValue(java.lang.String attribute, long value)
void setValue(java.lang.String attribute, int value)
void setValue(java.lang.String attribute, boolean value)
void setValue(java.lang.String attribute, java.lang.Object value)
void setValue(java.lang.String attribute, double[] array)
double[]
object in the data adaptor backing store.attribute
- attribute namearray
- attribute valuejava.lang.String[] attributes()
java.util.List<DataAdaptor> childAdaptors()
java.util.List<DataAdaptor> childAdaptors(java.lang.String label)
DataAdaptor childAdaptor(java.lang.String label)
DataAdaptor createChild(java.lang.String label)
void writeNode(DataListener listener)
void writeNodes(java.util.Collection<? extends DataListener> nodes)
nodes
- the nodes to write