Commit f14e76be authored by R.W.M's avatar R.W.M

new preferences API with configuration injection

parent b1211885
package org.aktin;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;
/**
* Marker interface to allow automatic injection of configuration preferences
*
* @author R.W.Majeed
*
*/
public interface Configurable {
public default List<String> getPreferences(){
List<String> prefs = new LinkedList<>();
Method[] methods = getClass().getDeclaredMethods();
for( int i=0; i<methods.length; i++ ){
Preference pref = methods[i].getAnnotation(Preference.class);
if( pref != null ){
prefs.add(pref.id());
}
}
return prefs;
}
}
package org.aktin;
public interface ConfigurationTest {
}
package org.aktin;
public abstract class Module implements Configurable{
public String getVersion(){
return getClass().getPackage().getImplementationVersion();
}
}
package org.aktin;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* AKTIN preference. If the annotation is used, also implement the {@link Configurable} interface.
*
* TODO add annotation processor to verify at compile time that each preference id is unique and method types are void(SingleArg)
*
* @author R.W.Majeed
*
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Preference {
String id();
String example() default "";
}
package org.aktin;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Preferences {
String group();
// TODO add Class<?> validator() to validate preferences
}
\ No newline at end of file
package org.aktin.prefs;
/**
* Validates preference settings.
* A validator may work for one or more preferences,
* e.g for R executable (one preference) or email server settings (multiple)
* @author R.W.Majeed
*
*/
public interface Validator {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment