Hello Simone,
We're just using something like
public abstract class MyConfigurationModule
extends org.nnsoft.guice.rocoto.configuration.ConfigurationModule {
protected final PropertyValueBindingBuilder bindProperty(final
String name) {
checkNotNull(name, "property name must not be null");
return new PropertyValueBindingBuilder() {
@Override
public void toValue(final String value) {
checkNotNull(value, "value for property '%s' must not
be null", name);
if (looksLikeAnnotationName(name)) {
bindConstant().annotatedWith(annotation(name)).to(value);
}
else {
bindConstant().annotatedWith(named(name)).to(value);
}
}
};
}
protected static final boolean looksLikeAnnotationName(final String name) {
return name.startsWith("com.mypackage") &&
Character.isUpperCase(name.charAt(name.lastIndexOf(".") + 1));
}
protected static final <A extends Annotation> Class<A>
annotation(final String annotationClassName) {
try {
return (Class<A>) Class.forName(annotationClassName);
}
catch (ClassNotFoundException e) {
throw new ProvisionException(format("could not create
annotation class '%s': %s", annotationClassName, e.getMessage()));
}
}
}
which is kind of hacky but works for our purposes. If such might be
included in Rocoto, it would be a good idea to make
looksLikeAnnotationName more robust, or alternatively try
annotation(name) and use named(name) on ClassNotFoundException.
I could send a pull request if you're interested.
michael