Added ConfigurationActionListener to Configurator
This commit is contained in:
parent
606c3bb2df
commit
d7637da980
2 changed files with 17 additions and 0 deletions
BIN
Zutil.jar
BIN
Zutil.jar
Binary file not shown.
|
|
@ -106,6 +106,9 @@ public class Configurator<T> {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses a Map to assign all parameters of the Object
|
||||||
|
*/
|
||||||
public void setConfiguration(Map<String,String> parameters){
|
public void setConfiguration(Map<String,String> parameters){
|
||||||
for(ConfigurationParam param : this.params){
|
for(ConfigurationParam param : this.params){
|
||||||
if(parameters.containsKey(param.getName()))
|
if(parameters.containsKey(param.getName()))
|
||||||
|
|
@ -113,6 +116,12 @@ public class Configurator<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All configuration parameters that was set
|
||||||
|
* for each parameter will be applied to the object.
|
||||||
|
*
|
||||||
|
* If the target class implements the ConfigurationActionListener interface
|
||||||
|
*/
|
||||||
public void applyConfiguration(){
|
public void applyConfiguration(){
|
||||||
StringBuilder strParams = new StringBuilder();
|
StringBuilder strParams = new StringBuilder();
|
||||||
for(ConfigurationParam param : params){
|
for(ConfigurationParam param : params){
|
||||||
|
|
@ -129,12 +138,20 @@ public class Configurator<T> {
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
logger.log(Level.WARNING, null, e);
|
logger.log(Level.WARNING, null, e);
|
||||||
}
|
}
|
||||||
|
if(obj instanceof ConfigurationActionListener)
|
||||||
|
((ConfigurationActionListener) obj).postConfigurationAction();
|
||||||
}
|
}
|
||||||
if(logger.isLoggable(Level.FINE))
|
if(logger.isLoggable(Level.FINE))
|
||||||
logger.fine("Configured object: " + obj.getClass().getSimpleName() + "("+ strParams +")");
|
logger.fine("Configured object: " + obj.getClass().getSimpleName() + "("+ strParams +")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface ConfigurationActionListener{
|
||||||
|
void postConfigurationAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ConfigurationParam implements Comparable<ConfigurationParam>{
|
public static class ConfigurationParam implements Comparable<ConfigurationParam>{
|
||||||
protected Field field;
|
protected Field field;
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue