org.omegahat.Environment.Databases
Class TypedDatabase
java.lang.Object
|
+--org.omegahat.Environment.Databases.ObjectDatabase
|
+--org.omegahat.Environment.Databases.ReadWriteDatabase
|
+--org.omegahat.Environment.Databases.TypedDatabase
- All Implemented Interfaces:
- Activable, Database, DatabaseNotifier, DynamicFieldAccessInt, MergableInt, Named, ReadWriteDatabaseInt, java.io.Serializable, Subsettable, TypedDatabaseInt
- Direct Known Subclasses:
- EvaluationFrame, LazyFunctionDatabase
- public class TypedDatabase
- extends ReadWriteDatabase
- implements TypedDatabaseInt, java.io.Serializable
Extension of the basic ObjectDatabase that can optionall store
information for an entry about its declared type. When an
assignment takes place on an object that has this type information
associated with it, the potential new value is compared to the
declared type. If they are ``consistent'', the assignment
proceeds. Otherwise, an exceptionIncorrectTypeException is thrown indicating an error.
This class provides the optional type-checking in
omegahat.
- See Also:
- Serialized Form
|
Field Summary |
protected java.util.Hashtable |
typeTable
|
|
Method Summary |
boolean |
assign(java.lang.String name,
java.lang.Object obj)
assigns obj to the database under name. |
protected boolean |
checkType(java.lang.String name,
java.lang.Object obj)
Determines whether the object obj
matches the type declared for the given entry in the database. |
java.lang.Object |
remove(java.lang.String name)
remove the object from the database |
java.lang.Class |
setType(Name name,
java.lang.Class type)
Register the specified class type
for the variable identified by name |
java.lang.Class |
setType(java.lang.String name,
java.lang.Class type)
|
java.lang.Class |
setType(java.lang.String name,
Name type)
Register the given class as the type for the specified variable. |
java.lang.Class |
setType(java.lang.String name,
Type type)
Register the class identified by the Type
(by converting to Name)
for the specified variable. |
java.lang.Class |
type(java.lang.String name)
returns the declared type registered for the specified
variable name. |
| Methods inherited from class org.omegahat.Environment.Databases.ObjectDatabase |
addAssignListener, addAttachListener, addDetachListener, addListener, addRemoveListener, assign, attach, clear, detach, exists, get, getDynamicField, getName, getState, getTable, merge, merge, notify, objects, put, readOnly, readOnly, readSerialized, readSerialized, readSerialized, remove, setDynamicField, setName, setState, setTable, size, subset, table, table |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
typeTable
protected java.util.Hashtable typeTable
TypedDatabase
public TypedDatabase(java.lang.String name)
TypedDatabase
public TypedDatabase(int size)
TypedDatabase
public TypedDatabase()
setType
public java.lang.Class setType(Name name,
java.lang.Class type)
- Register the specified class
type
for the variable identified by name
setType
public java.lang.Class setType(java.lang.String name,
java.lang.Class type)
- Specified by:
setType in interface TypedDatabaseInt
setType
public java.lang.Class setType(java.lang.String name,
Name type)
throws java.lang.ClassNotFoundException
- Register the given class as the type for the specified variable.
- Parameters:
type - a "one or more"-component name identifying a class
that is resolved via the default evaluator.name - name of the variable whose class/type is being registered.
setType
public java.lang.Class setType(java.lang.String name,
Type type)
throws java.lang.ClassNotFoundException
- Register the class identified by the
Type
(by converting to Name)
for the specified variable.
- See Also:
setType(java.lang.String, org.omegahat.Environment.Parser.Parse.Name)
assign
public boolean assign(java.lang.String name,
java.lang.Object obj)
throws java.lang.Exception
- Description copied from interface:
Database
- assigns
obj to the database under name.
- Specified by:
assign in interface Database- Overrides:
assign in class ReadWriteDatabase
- Following copied from interface:
org.omegahat.Environment.Databases.Database
- Parameters:
obj - any object, including nullname - a string (preferably non-empty) to locate the object in
the database.
remove
public java.lang.Object remove(java.lang.String name)
- Description copied from interface:
Database
- remove the object from the database
- Specified by:
remove in interface Database- Overrides:
remove in class ReadWriteDatabase
- Following copied from interface:
org.omegahat.Environment.Databases.Database
- Parameters:
name - any string, matching the one used in a previous
assignment.
checkType
protected boolean checkType(java.lang.String name,
java.lang.Object obj)
throws java.lang.Exception
- Determines whether the object
obj
matches the type declared for the given entry in the database.
- Parameters:
name - name of variable in database whose type is being
comparedobj - object which is to be assigned to the specified
variable if the types match.
type
public java.lang.Class type(java.lang.String name)
- returns the declared type registered for the specified
variable name.
- Parameters:
name - name of the variable whose declared type
is being sought.