Java Custom Annotation
Hi members,
I am trying to create a custom annotation. The idea was very simple, it would set the data in a string field.
Here is the code I have done till now,
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface RunMode {
}
@8220494(service = Injector.class, immediate = true)
public class RunModeInjector implements Injector {
@3214626
private AppSettingService appSettingService;
@9944223
public String getName() {
return "runmode";
}
@9944223
public @3146596 Object getValue(@NotNull Object adaptable, String name, @126844 Type type,
@126844 AnnotatedElement annotatedElement,
@126844 DisposalCallbackRegistry disposalCallbackRegistry) {
if (annotatedElement.isAnnotationPresent(RunMode.class)) {
return appSettingService.getRunMode();
}
return null;
}
}
Usages,
// Sling Model
// value is assigned
// But I was supposed to it will work without the extra @586265 annotation.
@Inject @RunMode
private String runMode;
// OSGI Service/servlet
// value is null,
// The annotatedElement.isAnnotationPresent(RunMode.class) condition is not satisfied from injector class.
@RunMode
private String runMode;
What I missed, or how to make it work?
Thanks in advance.
