Improved comments and added som methods to Obj DSO
This commit is contained in:
parent
84a3b13b76
commit
7484236292
3 changed files with 24 additions and 5 deletions
|
|
@ -27,6 +27,8 @@ package zutil;
|
||||||
/**
|
/**
|
||||||
* This class is a timer, it will track time and
|
* This class is a timer, it will track time and
|
||||||
* timeout after a specific amount of time.
|
* timeout after a specific amount of time.
|
||||||
|
* <br>
|
||||||
|
* Note that the {@link #start()} method needs to be called for the timer to start.
|
||||||
*
|
*
|
||||||
* Created by Ziver on 2015-07-15.
|
* Created by Ziver on 2015-07-15.
|
||||||
*/
|
*/
|
||||||
|
|
@ -37,6 +39,9 @@ public class Timer {
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new timer that in reset state.
|
||||||
|
*/
|
||||||
public Timer(long milisec){
|
public Timer(long milisec){
|
||||||
this.period = milisec;
|
this.period = milisec;
|
||||||
reset();
|
reset();
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config != null && !config.isEmpty()) {
|
if (config != null && !config.isEmpty()) {
|
||||||
Configurator<T> configurator = new Configurator<>(cachedObj);
|
Configurator<T> configurator = getObjectConfigurator();
|
||||||
configurator.setValues(JSONParser.read(config));
|
configurator.setValues(JSONParser.read(config));
|
||||||
configurator.applyConfiguration();
|
configurator.applyConfiguration();
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
|
||||||
if (cachedObj == null)
|
if (cachedObj == null)
|
||||||
this.config = null;
|
this.config = null;
|
||||||
else {
|
else {
|
||||||
Configurator<T> configurator = new Configurator<>(cachedObj);
|
Configurator<T> configurator = getObjectConfigurator();
|
||||||
this.config = JSONWriter.toString(configurator.getValuesAsNode());
|
this.config = JSONWriter.toString(configurator.getValuesAsNode());
|
||||||
}
|
}
|
||||||
super.save(db);
|
super.save(db);
|
||||||
|
|
@ -95,12 +95,16 @@ public abstract class DBBeanObjectDSO<T> extends DBBean{
|
||||||
setObjectClass(clazz.getName());
|
setObjectClass(clazz.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setObjectClass(String clazz){
|
public void setObjectClass(String clazz){
|
||||||
if (this.type == null || !this.type.equals(type)) {
|
if (this.type == null || !this.type.equals(type)) {
|
||||||
|
// TODO: check if clazz is subclass of T
|
||||||
setObject(null);
|
setObject(null);
|
||||||
this.type = clazz;
|
this.type = clazz;
|
||||||
|
postUpdateAction(); // instantiate cached object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Configurator<T> getObjectConfigurator(){
|
||||||
|
return new Configurator<>(cachedObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,11 @@ import java.util.logging.Logger;
|
||||||
* object the {@link Configurator#setValues(DataNode)} or {@link Configurator#setValues(Map)}
|
* object the {@link Configurator#setValues(DataNode)} or {@link Configurator#setValues(Map)}
|
||||||
* can be used to set the individual fields and finally call {@link Configurator#applyConfiguration()}
|
* can be used to set the individual fields and finally call {@link Configurator#applyConfiguration()}
|
||||||
* to configure the target object.
|
* to configure the target object.
|
||||||
|
* <br />
|
||||||
|
* External listener can be registered to be called before or after configuration changes
|
||||||
|
* by implementing {@link PreConfigurationActionListener} or {@link PostConfigurationActionListener}.
|
||||||
|
* The configured object will autmatically be registered as a listener if it also implements
|
||||||
|
* these interfaces.
|
||||||
*
|
*
|
||||||
* <br>
|
* <br>
|
||||||
* Supported field types: String, int, boolean, enum
|
* Supported field types: String, int, boolean, enum
|
||||||
|
|
@ -248,6 +253,7 @@ public class Configurator<T> {
|
||||||
|
|
||||||
if (f.getType() == String.class) type = ConfigType.STRING;
|
if (f.getType() == String.class) type = ConfigType.STRING;
|
||||||
else if(f.getType() == int.class) type = ConfigType.INT;
|
else if(f.getType() == int.class) type = ConfigType.INT;
|
||||||
|
else if(f.getType() == double.class) type = ConfigType.INT;
|
||||||
else if(f.getType() == boolean.class) type = ConfigType.BOOLEAN;
|
else if(f.getType() == boolean.class) type = ConfigType.BOOLEAN;
|
||||||
else if(f.getType().isEnum()) type = ConfigType.ENUM;
|
else if(f.getType().isEnum()) type = ConfigType.ENUM;
|
||||||
else
|
else
|
||||||
|
|
@ -298,7 +304,11 @@ public class Configurator<T> {
|
||||||
case STRING:
|
case STRING:
|
||||||
value = v; break;
|
value = v; break;
|
||||||
case INT:
|
case INT:
|
||||||
value = Integer.parseInt(v); break;
|
if (field.getType() == double.class)
|
||||||
|
value = Double.parseDouble(v);
|
||||||
|
else
|
||||||
|
value = Integer.parseInt(v);
|
||||||
|
break;
|
||||||
case BOOLEAN:
|
case BOOLEAN:
|
||||||
value = Boolean.parseBoolean(v); break;
|
value = Boolean.parseBoolean(v); break;
|
||||||
case ENUM:
|
case ENUM:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue