|
Project Information
Members
Featured
Downloads
Wiki pages
Links
|
objectify-led is a small Java library for binding object or class properties at runtime using annotations, reducing boilerplate code. Values can be taken from the System, from properties files, any arbitrary source in fact, and automatically set on properties. Instead of having chunks of code such as public class Foo
{
private static String BLAH = "default-value";
private String myString;
private int myInt = -1;
public static void main(String[] args)
{
if (System.getProperty("blah.value) != null)
{
BLAH = System.getProperty("blah.value");
}
Foo foo = new Foo();
if (System.getProperty("mystring.value) != null)
{
foo.myString = System.getProperty("mystring.value");
}
if (System.getProperty("myint.value) != null)
{
try
{
String intValue = System.getProperty("myint.value");
foo.myInt = Integer.parseInt(intValue;
}
catch (NumberFormatException e)
{
...
}
}
}
...
}you can instead use objectify-led to bind the properties for you : public class Foo
{
@Property("blah.value");
private static String BLAH = "default-value";
@Property("mystring.value");
private String myString;
@Property("myint.value");
private int myInt = -1;
public static void main(String[] args)
{
Foo foo = new Foo();
new PropertySetter().process(foo);
}
...
}By default, Strings and all primitive/wrapper classes are handled. If you wish to convert a property value into a specific class, you just need to plug in your own object factory. Additionally, the source of the properties is completely up to you. By default, properties are taken from the system environment and any Properties objects you may have plugged in; custom property contexts can be used to provide a facade to more complex value stores. Static values are handled in two ways. If an instance of a class is processed, both its instance and static members are populated if necessary. If a class is processed, just the static members are populated (what with the lack of an instance and everything…). |