|
deegree 2.1 (2007/11/08 09:57 build-328-official) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.deegree.model.csct.resources.ClassChanger
public abstract class ClassChanger
Transforme un objet d'une classe vers une autre. Cette classe sert principalement � convertir en
Number des objets d'une autre classe, par exemple Date. Une m�thode statique,
toNumber(java.lang.Comparable), se charge d'effectuer ce genre de conversion en prenant en compte toutes les
classes qui auront �t� d�clar�es � ClassChanger.
Pour d�clarer une nouvelle classe, on peut proc�der comme suit. L'exemple ci-dessous inscrit une
classe qui convertira des objets Date en objets Long. Notez qu'il ne s'agit que
d'un exemple. Ce convertisseur n'a pas besoin d'�tre d�clar� car ClassChanger
comprend d�j� les objets Date par d�faut.
ClassChanger.register( new ClassChanger( Date.class, Long.class ) {
protected Number convert( final Comparable o ) {
return new Long( ( (Date) o ).getTime() );
}
protected Comparable inverseConvert( final Number number ) {
return new Date( number.longValue() );
}
} );
| Constructor Summary | |
|---|---|
protected |
ClassChanger(Class source,
Class target)
Construct a new class changer. |
| Method Summary | |
|---|---|
protected abstract Number |
convert(Comparable object)
Returns the numerical value for an object. |
static Class |
getTransformedClass(Class source)
Returns the target class for the specified source class, if a suitable transformation is known. |
protected abstract Comparable |
inverseConvert(Number value)
Returns an instance of the converted classe from a numerical value. |
static void |
register(ClassChanger converter)
Inscrit un nouvel objet ClassChanger. |
static Comparable |
toComparable(Number value,
Class classe)
Wrap the specified number as an instance of the specified classe. |
static Number |
toNumber(Comparable object)
Returns the numeric value for the specified object. |
String |
toString()
Returns a string representation for this class changer. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected ClassChanger(Class source,
Class target)
source - Parent class for convert(java.lang.Comparable)'s input objects.target - Parent class for convert(java.lang.Comparable)'s output objects.| Method Detail |
|---|
protected abstract Number convert(Comparable object)
throws ClassCastException
object - Object to convert (may be null).
ClassCastException - if object is not of the expected class.protected abstract Comparable inverseConvert(Number value)
value - The value to wrap.
public String toString()
toString in class Object
public static void register(ClassChanger converter)
throws IllegalStateException
ClassChanger. Les objets ClassChanger
inscrits ici seront pris en compte par la m�thode toNumber(java.lang.Comparable). Si un objet
ClassChanger existait d�j� pour une m�me classe, une exception sera lanc�e.
Cette sp�cification est justifi�e par le fait qu'on enregistre souvent un objet
ClassChanger lors de l'initialisation d'une classe qui vient d'�tre charg�e
pour la premi�re fois. En interdisant tout changements aux objets ClassChanger
apr�s l'initialisation d'une classe, on �vite que la fa�on de convertir des objets en nombres
r�els ne change au cours d'une ex�cution de la machine virtuelle. Notez que si
converter ne peut pas prendre en charge une m�me classe que celle d'un autre
objet ClassChanger, il peut toutefois prendre en charge une classe parente ou
une classe fille.
converter - Convertisseur � ajouter � la liste des convertisseurs d�j� existants.
IllegalStateException - si un autre objet ClassChanger prennait d�j� en charge la m�me
classe (l'argument classe d�clar� au constructeur) que
converter.public static Class getTransformedClass(Class source)
Comparable subclass that will be specified as input to
convert(java.lang.Comparable). The target class is a Number subclass that wimm be returned as
output by convert(java.lang.Comparable). If no suitable mapping is found, then source is
returned.
public static Number toNumber(Comparable object)
throws ClassNotFoundException
toNumber(new Date()) returns the Date.getTime() value of the
specified date object as a Long.
object - Object to convert (may be null).
null if object was null; otherwise object
if the supplied object is already an instance of Number; otherwise a new
number with the numerical value.
ClassNotFoundException - if object is not an instance of a registered class.
public static Comparable toComparable(Number value,
Class classe)
throws ClassNotFoundException
toComparable(Date.class, new Long(time)) is equivalent to
new Date(time). There is of course no point to use this method if the
destination class is know at compile time. This method is useful for creating instance of
classes choosen dynamically at run time.
value - The numerical value (may be null).classe - The desired classe for return value.
ClassNotFoundException - if classe is not a registered class.
|
deegree 2.1 (2007/11/08 09:57 build-328-official) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://deegree.sourceforge.net