com.miginfocom.property
Class Property<T>

java.lang.Object
  extended by com.miginfocom.property.Property<T>
All Implemented Interfaces:
FieldProperty<T>, java.io.Serializable, PropertyI<T>
Direct Known Subclasses:
CollectionProperty, MapProperty, PropertyBean

public class Property<T>
extends java.lang.Object
implements FieldProperty<T>, java.io.Serializable

See Also:
Serialized Form

Field Summary
protected static java.lang.Object UNINITIALIZED
           
 
Constructor Summary
Property()
           
Property(T value)
           
 
Method Summary
 void addPropertyListener(PropertyListener<T> l)
          Adds a listener to this property with a string reference.
 void addPropertyListener(java.lang.ref.WeakReference<PropertyListener<T>> wl)
          Adds a listener to this property with a WeakReference.
protected  void checkInit()
           
protected  T cloneObject(T value)
          Clones the object.
protected  T create()
          Lazily creates the value at first use if it was not set in the constructor.
protected  FieldPropertyInfo<T> createInfo()
          Should create a FieldPropertyInfo every time.
 T get()
          Returns the value of this property.
 java.lang.Object getBean()
          Returns the bean that this property has at "parent".
 FieldPropertyInfo<T> getInfo()
          Returns the PropertyInfo object that contains the metadata for this property.
protected  T getInternal()
          This should be used to access the value internally as it will call create() if the value is uninitialized.
 java.lang.String getName()
           
 void init(java.lang.Object bean)
          Sets the bean that this property is a field in.
protected  void initNotify()
          Called when the property has been properly initialized.
 boolean isNull()
           
protected  T makeUnmodifiable(T value)
          Makes the value unmodifiable, usually by wrapping it.
 void removePropertyListener(PropertyListener<T> l)
          Removes the listener to this property.
 Result<T> set(T value)
          Set the value of this property.
protected  void setInternal(T value)
          This should be used to access the value internally.
 java.lang.String toString()
           
protected  java.lang.Object writeReplace()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNINITIALIZED

protected static final java.lang.Object UNINITIALIZED
Constructor Detail

Property

public Property()

Property

public Property(T value)
Method Detail

writeReplace

protected java.lang.Object writeReplace()
                                 throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

getInternal

protected T getInternal()
This should be used to access the value internally as it will call create() if the value is uninitialized.

To override this method means overriding the getting of the actualy value. Every access to the value will go through this method.

Returns:
The value of this property.

setInternal

protected void setInternal(T value)
This should be used to access the value internally.

To override this method means overriding the setting of the actualy value. Every access to the value will go through this method.

Parameters:
value - The raw value that will be set. Can be set to UNINITIALIZED to unset the value where it will be recreated the next time it is needed.

create

protected T create()
Lazily creates the value at first use if it was not set in the constructor. Default implementation returns null.

Should be overridden by sub classes to return default values.

It is a requirement that this method is only called a maximum of one time for an object instance.

Returns:
null by default.

getBean

public final java.lang.Object getBean()
Description copied from interface: FieldProperty
Returns the bean that this property has at "parent".

Any use of this property's value before the bean is set is illegal and will result in an exception.

Specified by:
getBean in interface FieldProperty<T>
Returns:
The bean that this property has at "parent. May only return null if the bean has not been set yet (i.e. it is not initialized).

init

public final void init(java.lang.Object bean)
Description copied from interface: FieldProperty
Sets the bean that this property is a field in. This method will only be called once and an attempt to either send in null or change an already set bean should result in an exception.

Any use of the property before the bean is set is illegal and will result in an exception.

Specified by:
init in interface FieldProperty<T>
Parameters:
bean - The bean. Never null.

initNotify

protected void initNotify()
Called when the property has been properly initialized. Default implementation is empty.

Can be overridden to do property specific initialization.


getInfo

public FieldPropertyInfo<T> getInfo()
Returns the PropertyInfo object that contains the metadata for this property. It should normally be the same object that is cached since this method will be called often.

Specified by:
getInfo in interface FieldProperty<T>
Returns:
The info. Never null.

getName

public java.lang.String getName()

createInfo

protected FieldPropertyInfo<T> createInfo()
Should create a FieldPropertyInfo every time. It is cached in getInfo(). getBean() will return a non-null value at the time of this call.

PropertyHandler.getValidators(java.lang.reflect.Field) should probably be used to get the standard set of Validators.

Override this method to create a custom FieldPropertyInfo.

Returns:
A property info. Never null.

addPropertyListener

public void addPropertyListener(PropertyListener<T> l)
Adds a listener to this property with a string reference.

Parameters:
l - The listener. Never null.
Throws:
java.lang.UnsupportedOperationException - if PropertyInfo.isObservable() returns false.

addPropertyListener

public void addPropertyListener(java.lang.ref.WeakReference<PropertyListener<T>> wl)
Adds a listener to this property with a WeakReference. This means that the listener will be unregistered when there is no other references to it. It also means that the caller must keep a reference to the listener or it will be garbage collected, and thus unregistered, rights away. This means that inline annonymous inner classes can not be used with this method.

Parameters:
wl - The listener. Never null.
Throws:
java.lang.UnsupportedOperationException - if PropertyInfo.isObservable() returns false.

removePropertyListener

public void removePropertyListener(PropertyListener<T> l)
Removes the listener to this property.

Parameters:
l - The listener. Never null.
Throws:
java.lang.UnsupportedOperationException - if PropertyInfo.isObservable() returns false.

get

public T get()
Description copied from interface: PropertyI
Returns the value of this property. The base interface makes no assuptions on this value at all. It might or might not be editable without side effects and it might or might not be null.

Specified by:
get in interface PropertyI<T>
Returns:
The value of this property.

set

public Result<T> set(T value)
Description copied from interface: PropertyI
Set the value of this property. The base interface makes no assuptions on this value at all. It might or might not be cloned for storage and it might or might not be null.

Specified by:
set in interface PropertyI<T>
Parameters:
value - The value.
Returns:
The result of the set. Should default to Result.ok() if not special logic for value checking is made.

makeUnmodifiable

protected T makeUnmodifiable(T value)
Makes the value unmodifiable, usually by wrapping it. This is what should be done when the get/set policy is Transfer.UNMODIFIABLE. Should be overridden by collection and map properties to wrap. Other property type can also overrider this to make the value unmidifiable.

Parameters:
value - The value. May be null in which canse null should be returned.
Returns:
The unmodifiable value.
Throws:
java.lang.IllegalStateException - if the property does not support unmodifiable. This is also the default.

cloneObject

protected T cloneObject(T value)
Clones the object. Should be overridden if custom cloning should be done for a property. Default is to call PropertyHandler.cloneObject(Object) which does a reflective lookup for .clone() on the object.

Parameters:
value - The value to clone. May be null.
Returns:
The cloned object. Never the same object as value.
Throws:
java.lang.IllegalStateException - if the property does not support cloning.

checkInit

protected final void checkInit()

isNull

public boolean isNull()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2007 MiG InfoCom AB. All Rights Reserved.