|
|||||||||
| Home >> All >> org >> jdaemon >> util >> [ data overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jdaemon.util.data
Class Type

java.lang.Objectorg.jdaemon.util.data.Type
- Direct Known Subclasses:
- AbstractType, ArrayType, QuickListType
- public abstract class Type
- extends java.lang.Object
Mechanism for persisting Java objects in a DataRepresentation.
The Type object allows Java objects to be both retrieved from and written to a DataRepresentation.
A single Type object provides a mapping between the element type stored in a DataRepresentation and the class of a java object. For instance a java object of class 'org.jdaemon.Polygon' might have an element type of 'POLYGON'.
In addition, Type has two abstract methods (read and write) which must be implemented in order to define the exact mapping between fields of a java class and attributes of an element representing that class in a DataRepresentation.
Trivially, then, if POLYGON is an instance of an appropriate type object, and polygon is an instance of the Polygon class, polygon could be written to a data representation using:
POLYGON.put(data_representation, "example", polygon)
and read from a data representation using:
polygon = (Polygon)POLYGON.get(data_representation, "example")
Type also provides for polymorphism, allowing an object to be retrieved from a DataRepresentation without knowing its exact class. A tree of Type objects is created that specifies a notional inheritance tree (or type hierarchy) for the elements stored in a DataRepresentation. This will generally be similar to the type hierarchy of the java objects to be stored in the DataRepresentation.
The tree of Type objects is created using the addSubtype method. For example, given three classes, Drawable, Polygon, and Rectangle, where Polygon and Rectangle are both subclasses of Drawable, it would be natural to create three Type objects, POLYGON, RECTANGLE, and DRAWABLE.
If POLYGON and RECTANGLE are both added as subtypes of DRAWABLE, then it will be possible to read and write both polygon and rectangle objects using the DRAWABLE type. So:
drawable = (Drawable)DRAWABLE.get(data_representation, "example")
would correctly instantiate either a Polygon or a Rectangle object depending on the element type stored in the data representation.
- Version:
- 0.1
| Field Summary | |
private java.lang.Class |
my_class
The java class represented by this type |
private java.util.LinkedList |
subtypes
A list of subtypes of this type |
private java.lang.String |
type
The name of this type. |
| Constructor Summary | |
Type(java.lang.String type,
java.lang.Class my_class)
Construct a Type object to map between objects of a given class and DataRepresentation elements of a given type. |
|
Type(Type parent,
java.lang.String type,
java.lang.Class my_class)
Construct a Type object to map between objects of a given class and DataRepresentation elements of a given type. |
|
| Method Summary | |
protected void |
addSubtype(Type type)
Add a subtype to this type. |
java.lang.Object |
get(DataRepresentation representation)
|
java.lang.Object |
get(DataRepresentation representation,
java.lang.Object key)
Reads an object from the specified element of a DataRepresentation |
java.lang.Class |
getJavaClass()
|
java.lang.String |
getName()
Get the element type for which this Type provides a mapping. |
Type |
getType(DataRepresentation representation)
Find the actual type of some DataRepresentation. |
Type |
getType(java.lang.Object object)
Find the actual type of some object. |
void |
put(DataRepresentation representation,
java.lang.Object key,
java.lang.Object object)
Writes an object as an element of a DataRepresentation |
abstract java.lang.Object |
read(DataRepresentation representation)
Reads an object of this exact type from some DataRepresentation. |
abstract void |
write(DataRepresentation representation,
java.lang.Object object)
Writes an object of this exact type to some DataRepresentation. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
type
private java.lang.String type
- The name of this type. Maps to the element type in a datarepresentation
my_class
private java.lang.Class my_class
- The java class represented by this type
subtypes
private java.util.LinkedList subtypes
- A list of subtypes of this type
| Constructor Detail |
Type
public Type(java.lang.String type, java.lang.Class my_class)
- Construct a Type object to map between objects of a given class and DataRepresentation elements of a given type.
Type
public Type(Type parent, java.lang.String type, java.lang.Class my_class)
- Construct a Type object to map between objects of a given class and DataRepresentation elements of a given type.
This constructor is equivalent to building an object with Type(type, my_class) and then adding
that object as a subtype of some parent Type with parent's addSubtype method.
| Method Detail |
getName
public java.lang.String getName()
- Get the element type for which this Type provides a mapping.
getJavaClass
public java.lang.Class getJavaClass()
addSubtype
protected void addSubtype(Type type)
- Add a subtype to this type.
read
public abstract java.lang.Object read(DataRepresentation representation) throws ReadError, ObjectInstantiationError
- Reads an object of this exact type from some DataRepresentation.
Implement this method in order to define the mapping from attributes/sub-elements
of a data representation to the fields of an object.
write
public abstract void write(DataRepresentation representation, java.lang.Object object) throws WriteError
- Writes an object of this exact type to some DataRepresentation.
Implement this method in order to define the mapping from the fields of an object
to attributes/sub-elements of a data representation
getType
public Type getType(DataRepresentation representation) throws ReadError
- Find the actual type of some DataRepresentation.
getType
public Type getType(java.lang.Object object)
- Find the actual type of some object.
get
public java.lang.Object get(DataRepresentation representation) throws ReadError, ObjectInstantiationError
get
public java.lang.Object get(DataRepresentation representation, java.lang.Object key) throws ReadError, ObjectInstantiationError
- Reads an object from the specified element of a DataRepresentation
put
public void put(DataRepresentation representation, java.lang.Object key, java.lang.Object object) throws WriteError
- Writes an object as an element of a DataRepresentation
|
|||||||||
| Home >> All >> org >> jdaemon >> util >> [ data overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.jdaemon.util.data.Type