public class PropertyFieldCollection extends Object implements PropertyCollection, Serializable
Property
's from a class. Property
is added to the collection. LoggingPropertyChangeListener
is automatically a added to all the Properties.PropertyIO
will be validated using [PropertyCollectionFactory.initializeIO(io,logger,validationHandler)
], and the validationHandler will be called both if it is valid or invalid.Property
and parse the "PropertyFieldFilter.accept" method. Using [PropertyCollectionFactory.initializeFieldCollection(class,propertyIO,logger,validationHandler,propertyFieldFilter)
]PropertyIO
to all the Property
's.Property
's, and the validationHandler will be called both if they are is valid or invalid.LoggingPropertyChangeListener
is added to all identified Property's. [NEW in version 1.6]postValidation
where custom activation/crossvalidation of Properties can be performed.
Property
's to the collection.PropertyCollectionFactory.initializeFieldCollection(Object, Class, PropertyIO, Log, PropertyValidationHandler, PropertyFieldFilter)
,
PropertyFieldFilter
,
PropertyFieldFilterFactory
,
Serialized FormPROPERTY_REGISTRY_DO_NOT_REGISTER, PROPERTY_REGISTRY_NO_TIMEOUT
Constructor and Description |
---|
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter)
Default Constructor, where the class from where detection of static members of class type
Property will be performed is this class,
and the logger is a new instance of Log for this class,
and the PropertyValidationHandler is an instance of LoggingPropertyValidationHandler ,
and the PropertyIO is a instance of ResourceStreamPropertyIO with this class as input. |
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter,
PropertyIO io)
Constructor, where the class from where detection of static members of class type
Property will be performed is this class,
and the PropertyValidationHandler is an instance of LoggingPropertyValidationHandler ,
and the logger is a new instance of Log for this class. |
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter,
PropertyIO io,
Class<?> clazz,
org.apache.commons.logging.Log logger,
PropertyValidationHandler propertyValidationHandler)
Constructor.
|
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter,
PropertyIO io,
org.apache.commons.logging.Log logger)
Constructor, where the class from where detection of static members of class type
Property will be performed is this class,
and the PropertyValidationHandler is an instance of LoggingPropertyValidationHandler . |
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter,
PropertyIO io,
org.apache.commons.logging.Log logger,
PropertyValidationHandler propertyValidationHandler)
Constructor, where the class from where detection of static members of class type
Property will be performed is this class. |
PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter,
PropertyIO io,
PropertyValidationHandler propertyValidationHandler)
Constructor, where the class from where detection of static members of class type
Property will be performed is this class,
and the logger is a new instance of Log for this class. |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a
PropertyChangeListener to all registrered Property's in the PropertyCollection. |
PropertyIO |
getIo()
The PropertyIO.
|
Iterator<Property<?>> |
getIterator()
Property Iterator.
|
List<Property<?>> |
getList()
Property list sorted by name, as a
Collections.unmodifiableList . |
org.apache.commons.logging.Log |
getLogger()
The
org.apache.commons.logging.Log used. |
String |
getName()
Gets the name of the collection, default is getClass().getName();.
|
protected List<Property<?>> |
getProperties()
Gets the properties for the PropertyFieldCollection.
|
Property<?> |
getPropertyByName(String propertyName)
Get a Property by name.
|
PropertyFieldFilter |
getPropertyFieldFilter()
The instance of a
PropertyFieldFilter . |
PropertyValidationHandler |
getPropertyValidationHandler()
When a property collection validates all the properties it contains, then this handler defines what happens
in case the a property is valid or invalid.
|
long |
getRegistryTimeout()
The number of milliseconds before a PropertyCollection is automatically remove from PropertyCollectionRegistry.
|
static void |
initialize(PropertyFieldCollection collection)
Initialize the PropertyFieldCollection when the Property in the class is declared as non-static fields.
|
void |
postValidation()
After the PropertyCollection has validation the PropertyIO and all the Properties, it calls this method.
|
void |
preValidation()
This method is called before any validation of PropertyIO and Properties is performed, this is where you typically can setup global configurations.
|
void |
reload()
Resets the cache typed values for all the
Property 's in the PropertyIO for this collection which forces a reload from the property IO. |
void |
removeAllPropertyChangeListeners()
Remove all PropertyChangeListener's from the Property's in the Collection.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a
PropertyChangeListener from all registered Property's in the collection. |
protected void |
setProperties(List<Property<?>> properties) |
void |
setPropertyValidationHandler(PropertyValidationHandler propertyValidationHandler)
Here you can set your PropertyValidationHandler instance.
|
int |
size()
Number of properties.
|
void |
validate()
Validates all the
Property 's in the collection an throws an
PropertyException for the first that failsvalidation. |
List<PropertyValidationVO> |
validation()
Validates all the
Property 's in the collection, stores the result in
a java.util.List of PropertyValidationVO . |
public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter, PropertyIO io, Class<?> clazz, org.apache.commons.logging.Log logger, PropertyValidationHandler propertyValidationHandler)
propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedio
- the PropertyIO
instance from where the Property
's will be loaded.clazz
- the class from where detection of static members of class type Property
will be performed.logger
- the loggerpropertyValidationHandler
- the validation handler, used to perform operations on initialization when a Property
is either valid or invalid, or a PropertyIO
is either valid or invalid.public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter, PropertyIO io, org.apache.commons.logging.Log logger)
Property
will be performed is this class,
and the PropertyValidationHandler
is an instance of LoggingPropertyValidationHandler
. propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedio
- the PropertyIO
instance from where the Property
's will be loaded.logger
- the loggerLoggingPropertyValidationHandler
public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter, PropertyIO io, org.apache.commons.logging.Log logger, PropertyValidationHandler propertyValidationHandler)
Property
will be performed is this class. propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedio
- the PropertyIO
instance from where the Property
's will be loaded.logger
- the loggerpropertyValidationHandler
- the validation handler, used to perform operations on initialization when a Property
is either valid or invalid, or a PropertyIO
is either valid or invalid.public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter, PropertyIO io)
Property
will be performed is this class,
and the PropertyValidationHandler
is an instance of LoggingPropertyValidationHandler
,
and the logger is a new instance of Log for this class. propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedio
- the PropertyIO
instance from where the Property
's will be loaded.LoggingPropertyValidationHandler
public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter, PropertyIO io, PropertyValidationHandler propertyValidationHandler)
Property
will be performed is this class,
and the logger is a new instance of Log for this class. propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedio
- the PropertyIO
instance from where the Property
's will be loaded.propertyValidationHandler
- the validation handler, used to perform operations on initialization when a Property
is either valid or invalid, or a PropertyIO
is either valid or invalid.public PropertyFieldCollection(PropertyFieldFilter propertyFieldFilter)
Property
will be performed is this class,
and the logger is a new instance of Log for this class,
and the PropertyValidationHandler
is an instance of LoggingPropertyValidationHandler
,
and the PropertyIO
is a instance of ResourceStreamPropertyIO
with this class as input. propertyFieldFilter
- the filter which select the fields from classes and interfaces above which should be initializedLoggingPropertyValidationHandler
,
ResourceStreamPropertyIO.ResourceStreamPropertyIO(Class)
public String getName()
PropertyCollection
getName
in interface PropertyCollection
public long getRegistryTimeout()
PropertyCollection
getRegistryTimeout
in interface PropertyCollection
PropertyCollectionRegistry
public PropertyFieldFilter getPropertyFieldFilter()
PropertyFieldFilter
.public final void reload()
PropertyCollection
Property
's in the PropertyIO for this collection which forces a reload from the property IO.reload
in interface PropertyCollection
public final int size()
PropertyCollection
size
in interface PropertyCollection
Property
's in the collection.public final void validate() throws PropertyException
PropertyCollection
Property
's in the collection an throws an
PropertyException
for the first that failsvalidation.validate
in interface PropertyCollection
PropertyException
- if any of the Property
's fails validation.public final List<PropertyValidationVO> validation()
PropertyCollection
Property
's in the collection, stores the result in
a java.util.List
of PropertyValidationVO
.
The purpose is for the client to have a list to show in any user interface the state of
properties.validation
in interface PropertyCollection
PropertyValidationVO
public final Property<?> getPropertyByName(String propertyName)
PropertyCollection
getPropertyByName
in interface PropertyCollection
propertyName
- the name of the propertyProperty
if found, otherwise null
.public final Iterator<Property<?>> getIterator()
PropertyCollection
getIterator
in interface PropertyCollection
Property
's in the collection.Iterator
public final List<Property<?>> getList()
PropertyCollection
Collections.unmodifiableList
.
Remember to sort before turning it in to a unmodifiableList list.getList
in interface PropertyCollection
Collections.unmodifiableList(List)
public org.apache.commons.logging.Log getLogger()
PropertyCollection
org.apache.commons.logging.Log
used.getLogger
in interface PropertyCollection
public final PropertyIO getIo()
PropertyCollection
getIo
in interface PropertyCollection
Property
's has been initialized with.PropertyIO
public final PropertyValidationHandler getPropertyValidationHandler()
PropertyCollection
getPropertyValidationHandler
in interface PropertyCollection
PropertyValidationHandler
of none is defined than LoggingPropertyValidationHandler
is used.PropertyValidationHandler
,
LoggingPropertyValidationHandler
public final void setPropertyValidationHandler(PropertyValidationHandler propertyValidationHandler)
PropertyCollection
setPropertyValidationHandler
in interface PropertyCollection
propertyValidationHandler
- your instance of a PropertyValidationHandler.PropertyValidationHandler
public void preValidation()
PropertyCollection
preValidation
in interface PropertyCollection
public void postValidation() throws PropertyException
PropertyCollection
public class MyPropertiesDemo extends PropertyStaticCollection implements MyProperties { public MyPropertiesDemo(FilePropertyIO io) { super(io); } public void postValidation() throws PropertyException { ActivationValidator activator = new ActivationValidator(); activator.given(MyProperties.PORT_NUMBER.getTypedValue()==443,MyProperties.A_SSL_CONFIG); activator.given(MyProperties.MY_STRING,MyProperties.MY_NUMBER_A,MyProperties.MY_NUMBER_B,MyProperties.MY_NUMBER_C,MyProperties.MY_NUMBER_D); } }It throws an exception
postValidation
in interface PropertyCollection
PropertyException
public void addPropertyChangeListener(PropertyChangeListener listener) throws NullPointerException
PropertyCollection
PropertyChangeListener
to all registrered Property's in the PropertyCollection. addPropertyChangeListener
in interface PropertyCollection
listener
- the listener to be added to all Property's.NullPointerException
- if listener was null
or the PropertyIO of the collection is null
.Property.addPropertyChangeListener(PropertyChangeListener)
,
LoggingPropertyValidationHandler
public void removePropertyChangeListener(PropertyChangeListener listener) throws NullPointerException
PropertyCollection
PropertyChangeListener
from all registered Property's in the collection. removePropertyChangeListener
in interface PropertyCollection
listener
- the listener to be removed.NullPointerException
- if listener was null
or the PropertyIO of the collection is null
.Property.removePropertyChangeListener(PropertyChangeListener)
public static void initialize(PropertyFieldCollection collection)
collection
- the instance of the PropertyFieldCollection.public void removeAllPropertyChangeListeners()
PropertyCollection
removeAllPropertyChangeListeners
in interface PropertyCollection
protected final List<Property<?>> getProperties()