|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface RegistryValue
A RegistryValue object represents something that can be stored in a Registry.
In order to adapt to several implementations of Registry, a RegistryValue
should provide some serialization facilities :
- a serialize() method that produce a String representation of the instance.
- a constructor with a String argument (e.g MyRegistryValue(String s))
that can reconstruct an instance from the previous String.
Note: this is the responsability of the Registry implementation to manage
the serialization/deserialization process. The default Memory implementation
(MemRegistry) does not care at all about these methods since it will never
serialize/deserialize the objects. A typical SGBD or Disk based Registry
will store the key, the serialized String and the original class of the
object. Then, in the get() method, it will call the class constructor
with the stored String value to restore the original object.
A RegistryValue also implements a klone() method, to potentially clone the object.
This method is called, in particular, when the Registry is copied
thru the Registry.copy() method. The behavior of your klone() method depends upon
the mutability of the object. For immutable objects, there is no need to actually
duplicate the object. a typical implementation is therefore :
public RegistryValue klone() { return this }
For mutable objects, the klone() method should make a deep
copy of the instance if you want the copy to have its own life.
A simple way to do this is :
public RegistryValue klone() { return new MyRegistryValue(this.serialize()) }
note: the method is called klone() instead of clone() to avoir conflicts with
the strange Object.clone() method.
Finally, RegistryValue also implements several conversion to basic types
(String, int, float and boolean). This is mostly useful for basic types
RegistryValue e.g. :
registry.set("age", 123);
If your RegistryValue cannot be converted into a Basic type, just
throw the IllegalValueException Runtime exception.
Note: you may also redefine the hashCode() and equals() methods for use
of your RegistryValue in hashMaps. The AbstractRegistryValue provides a
good startpoint for your class.
registry.get("age").intValue();
registry.get("age").stringValue();
Method Summary | |
---|---|
RegistryValue |
klone()
Potentially clone this instance. |
String |
serialize()
get a String representation of this instance. |
boolean |
toBoolean()
|
float |
toFloat()
|
int |
toInt()
|
String |
toString()
Get a String representation of this instance value note: this representation may not be suitable as the constructor argument, use serialize() instead. |
Method Detail |
---|
String serialize()
RegistryValue klone()
String toString() throws IllegalValueException
toString
in class Object
IllegalValueException
int toInt() throws IllegalValueException
IllegalValueException
float toFloat() throws IllegalValueException
IllegalValueException
boolean toBoolean() throws IllegalValueException
IllegalValueException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |