Skip to content

Commit

Permalink
[#274] Implement parent configuration via loadConfiguration method.
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Sep 27, 2024
1 parent 80fab41 commit 452efcc
Showing 1 changed file with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,34 @@ public abstract class AnnotatedAbstractModule extends AbstractModule {

@Override
public void loadConfiguration() {
final Map<String, Field> vars = new HashMap<>();
for (final Field f : this.getClass().getDeclaredFields()) {
final Parameter p = f.getAnnotation(Parameter.class);
if (p == null) {
continue;
} else if (vars.containsKey(p.iri())) {
throw new RuntimeException(String.format("Two parameters have same iri %s", p.iri()));
} else {
vars.put(p.iri(), f);
}

log.trace("Processing parameter {} ", f.getName());
Class<? extends AnnotatedAbstractModule> clazz = this.getClass();

while(clazz != AnnotatedAbstractModule.class){
final Map<String, Field> vars = new HashMap<>();
for (final Field f : clazz.getDeclaredFields()) {
final Parameter p = f.getAnnotation(Parameter.class);
if (p == null) {
continue;
} else if (vars.containsKey(p.iri())) {
throw new RuntimeException(String.format("Two parameters have same iri %s", p.iri()));
} else {
vars.put(p.iri(), f);
}

log.trace("Processing parameter {} ", f.getName());

Setter setter;
if (f.getType() == List.class) {
setter = new ListSetter(f, this);
} else {
setter = new FieldSetter(f, this);
Setter setter;
if (f.getType() == List.class) {
setter = new ListSetter(f, this);
} else {
setter = new FieldSetter(f, this);
}
HandlerRegistry handlerRegistry = HandlerRegistry.getInstance();
Handler<?> handler = handlerRegistry.getHandler(f.getType(), resource, executionContext, setter);
handler.setValueByProperty(ResourceFactory.createProperty(p.iri()));
}
HandlerRegistry handlerRegistry = HandlerRegistry.getInstance();
Handler<?> handler = handlerRegistry.getHandler(f.getType(), resource, executionContext, setter);
handler.setValueByProperty(ResourceFactory.createProperty(p.iri()));
clazz = (Class<? extends AnnotatedAbstractModule>) clazz.getSuperclass();
}
loadManualConfiguration();
}
Expand Down

0 comments on commit 452efcc

Please sign in to comment.