Section Interfaces
Config sections can also be accessed via interface proxies using
{@link oaj.config.Config#getSectionAsInterface(String,Class)}.
While section maps and beans retrieve copies of the configuration data at the time of the method
call, section interfaces can also be use to set values in the underlying configuration.
// Example config file
[MySection]
string = foo
int = 123
enum = ONE
bean = {foo:'bar',baz:123}
int3dArray = [[[123,null],null],null]
bean1d3dListMap = {key:[[[[{foo:'bar',baz:123}]]]]}
// Example interface.
// Setters are optional.
public interface MyConfigInterface {
String getString();
void setString(String value);
int getInt();
void setInt(int value);
MyEnum getEnum();
void setEnum(MyEnum value);
MyBean getBean();
void setBean(MyBean value);
int[][][] getInt3dArray();
void setInt3dArray(int[][][] value);
Map<String,List<MyBean[][][]>> getBean1d3dListMap();
void setBean1d3dListMap(Map<String,List<MyBean[][][]>> value);
}
// Example usage.
Config config = Config.create("MyConfig.cfg").build();
MyConfigInterface intf = config.getSectionAsInterface("MySection", MyConfigInterface.class);
// Read a value.
int myInt = intf.getInt();
// Write a value.
intf.setBean(new MyBean());
// Commit your changes to the store.
config.commit();