From 452efcc2279524ceb77fa27947630f0616670878 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Fri, 27 Sep 2024 12:47:04 +0200 Subject: [PATCH] [#274] Implement parent configuration via loadConfiguration method. --- .../modules/AnnotatedAbstractModule.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java index 744cd522..2a7efb66 100644 --- a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java @@ -30,28 +30,34 @@ public abstract class AnnotatedAbstractModule extends AbstractModule { @Override public void loadConfiguration() { - final Map 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 clazz = this.getClass(); + + while(clazz != AnnotatedAbstractModule.class){ + final Map 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) clazz.getSuperclass(); } loadManualConfiguration(); }