public class Property<T> extends Object implements Comparable<Property<T>>, Serializable
PropertyChangeListener
's, which is fire before and after a property is changed.PropertyCollection
constructor or preValidation
method.PropertyChangeListener
have a ID this to ensure that a PropertyChangeListener
only can be fired once per Property
PropertyChangeListener
,
Serialized FormModifier and Type | Field and Description |
---|---|
static String |
I18N_DESCRIPTION_INDICATOR |
static String |
I18N_PREFIX |
Constructor and Description |
---|
Property(String name,
PropertyType<T> type)
The constructor.
|
Property(String name,
PropertyType<T> type,
boolean nullAllowed)
The constructor.
|
Property(String name,
PropertyType<T> type,
boolean nullAllowed,
boolean readonly)
The constructor.
|
Property(String name,
PropertyType<T> type,
boolean nullAllowed,
boolean readonly,
String description)
The constructor with all the different paramenters.
|
Property(String name,
PropertyType<T> type,
String description)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a
PropertyChangeListener to the Property changeListener list. |
int |
compareTo(Property o)
Compare on names
|
boolean |
equals(Object obj)
Two Property objects are equal if their names are equal.
|
Collection<PropertyChangeListener> |
getChangeListeners()
Get all the
PropertyChangeListeners in a Collections.unmodifiableCollection . |
String |
getDescription()
Gets the description of property if any is set, if description is
null
it will try to retrieved the description from the localizer. |
String |
getI18NName()
Getting the I18N name for the property description, if you choose not to enter a description but instead using a I18N framework.
|
PropertyIO |
getIo()
The io from where the property gets and set the value of the property.
|
org.apache.commons.logging.Log |
getLogger()
Gets the logger.
|
String |
getName()
Gets the name of property.
|
PropertyType<T> |
getType()
Gets the type of property.
|
T |
getTypedValue()
Get the typed value of the property value.
|
String |
getValue()
Gets the value of property through the PropertyIO.
|
int |
hashCode()
Hashcode of the name.
|
boolean |
isDefined()
Determines if the Property is defined in the PropertyIO source.
|
boolean |
isDescriptionI18NKey()
If the description starts with "$", then it is assume that the description is actual the key for ResouceBundle entry.
|
boolean |
isNullAllowed()
Is the property allowed to have a undefined value and/or return
null . |
boolean |
isReadonly()
Determines if this property is specific set to be read only.
|
boolean |
isValid()
A convenience method for just determining if a Property is valid or not.
|
void |
reload()
Resets the cache of value, which is stored in the instance of the PropertyType for this Property.
|
void |
removeAllPropertyChangeListeners()
Remove all PropertyChangeListeners from the Property.
|
boolean |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a
PropertyChangeListener from the Property changelist. |
void |
setDescription(String description)
Sets description of the Property.
|
void |
setIo(PropertyIO io)
Sets the PropertyIO for the property.
|
void |
setNullAllowed(boolean value)
Sets if
null is allowed as value for the Property. |
void |
setReadonly(boolean readonly)
Sets the property to be read only or not.
|
void |
setTypedValue(T value)
Sets the value (T) for the Property via the PropertyIO.
|
void |
setValue(String value)
Sets the value (String) for the Property via the PropertyIO.
|
String |
toString() |
void |
validate()
Validates the value through the PropertyType validation.
|
PropertyValidationVO |
validation()
Wrappeds the validate method into a PropertyValidationVO.
|
public static final String I18N_PREFIX
public static final String I18N_DESCRIPTION_INDICATOR
public Property(String name, PropertyType<T> type) throws NullPointerException
name
- the name of the propertytype
- the type of the property, which extends PropertyTypeNullPointerException
- if either name or type is null
.PropertyType
public Property(String name, PropertyType<T> type, boolean nullAllowed) throws NullPointerException
name
- the name of the propertytype
- the type of the property, which extends PropertyTypenullAllowed
- is the property allowed to have a undefined value and/or return null
.NullPointerException
- if either name or type is null
.PropertyType
public Property(String name, PropertyType<T> type, boolean nullAllowed, boolean readonly) throws NullPointerException
name
- the name of the propertytype
- the type of the property, which extends PropertyTypenullAllowed
- is the property allowed to have a undefined value and/or return null
.readonly
- is the property is read only or not.NullPointerException
- if either name or type is null
.PropertyType
public Property(String name, PropertyType<T> type, String description) throws NullPointerException
name
- the name of the propertytype
- the type of the property, which extends PropertyTypedescription
- the description of the Property.NullPointerException
- if either name or type is null
.PropertyType
public Property(String name, PropertyType<T> type, boolean nullAllowed, boolean readonly, String description) throws NullPointerException
name
- the name of the property.type
- the type of the property, which extends PropertyType.nullAllowed
- is the property allowed to have a undefined value and/or return null
.readonly
- is the property is read only or not.description
- the description of the Property.NullPointerException
- if either name or type is null
.PropertyType
public final String getName()
public final String getDescription()
null
it will try to retrieved the description from the localizer. null
is returned.getI18NName()
,
PropertyFrameworkGlobals.getPropertyDescriptionLocalizer()
,
Localizer
public final boolean isDescriptionI18NKey()
true
if the description starts with "$" (trimmed), otherwise false
.public final void setDescription(String description)
description
- the description.public final PropertyType<T> getType()
PropertyType
public final PropertyIO getIo()
PropertyIO
public final String getI18NName()
jhpt.property.i18n
".I18N_PREFIX
,
PropertyUtils.getI18NName(String, String)
public final void setIo(PropertyIO io)
io
- the IO.PropertyIO
public final String getValue()
StringUtils.replaceInlinedProperties(String)
method,
to replace ${name} where name can either be a System.getProperty(String) or System.getenv(String). StringUtils.removeValueQuotes(String)
method,
to replace ${name} where name can either be a System.getProperty(String) or System.getenv(String). null
is returned.NullPointerException
- if IO is null
.PropertyIO
,
StringUtils.replaceInlinedProperties(String)
,
StringUtils.removeValueQuotes(String)
,
PropertyType.postGetValueProcessing(String, String, boolean)
public final T getTypedValue()
null
, than the Property is undefined.null
is returned.null
, than the Property is defined.null
is returned.PropertyIO
,
PropertyType
,
PropertyType.toType(String, String)
,
getValue()
public final void setValue(String value) throws PropertyException
PropertyChangeListeners
is added to the Property, the call in this method.value
- of type stringPropertyException
- if value fails validation or PropertyIO fails the setting of the value.PropertyIO.setValue(String, String)
,
PropertyType.validate(String, String)
public final void setTypedValue(T value) throws PropertyException
PropertyChangeListeners
is added to the Property, the call in this method.value
- of type TPropertyException
- if value fails validation or PropertyIO fails the setting of the value.PropertyIO.setValue(String, String)
,
PropertyType.validate(String, String)
public final void validate() throws PropertyException
PropertyException
- if the value type isnt valid.PropertyType.validateConstraints(String)
public final PropertyValidationVO validation()
PropertyValidationVO
public final boolean isValid()
true
if property value/default is valid, otherwise false
.PropertyValidationVO.isValid()
public final void reload()
public final boolean equals(Object obj)
public final int compareTo(Property o)
compareTo
in interface Comparable<Property<T>>
public final boolean isReadonly()
false
, and normally handled by the PropertyIO
.true
if the PropertyIO
is not null
and PropertyIO.isReadonly()
is true
, otherwise return the property's own value of read only attribute which can be set individually.getIo()
,
PropertyIO.isReadonly()
public final boolean isNullAllowed()
null
.true
if null
is allowed as valid value.public final void setNullAllowed(boolean value)
null
is allowed as value for the Property.value
- if null
is allowed as value or not.public final void setReadonly(boolean readonly)
PropertyIO
, but provides the possibility to set individual property to be read only if so desired. readonly
- if the property should be read only or not.public final boolean isDefined()
true
if getValue() differs from null
, otherwise false
.public final org.apache.commons.logging.Log getLogger()
public final boolean addPropertyChangeListener(PropertyChangeListener listener) throws NullPointerException
PropertyChangeListener
to the Property changeListener list. listener
- the listener to be added.true
if the listener was added successfully, otherwise false
, if it listener is null
.NullPointerException
- if listener was null
.public final boolean removePropertyChangeListener(PropertyChangeListener listener) throws NullPointerException
PropertyChangeListener
from the Property changelist.listener
- the PropertyChangeListener
to be removed.NullPointerException
- if listener was null
.public final void removeAllPropertyChangeListeners()
public final Collection<PropertyChangeListener> getChangeListeners()
PropertyChangeListeners
in a Collections.unmodifiableCollection
.PropertyChangeListeners
.Collections.unmodifiableCollection(Collection)