Skip to content

Commit

Permalink
[#274] Move loadManualConfiguration to the AnnotatedAbstractModule
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Sep 26, 2024
1 parent 36eadf8 commit 80fab41
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public abstract class AbstractModule implements Module {
public ExecutionContext execute() {
loadModuleFlags();
loadConfiguration();
loadManualConfiguration();
loadModuleConstraints();
String inputModelFilePath = null;
if (AuditConfig.isEnabled() || isInDebugMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ 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 Map<String, Field> vars = new HashMap<>();
for (final Field f : this.getClass().getDeclaredFields()) {
final Parameter p = f.getAnnotation(Parameter.class);
if ( p == null ) {
if (p == null) {
continue;
} else if (vars.containsKey(p.iri())) {
throw new RuntimeException(String.format("Two parameters have same iri %s", p.iri()));
Expand All @@ -44,17 +44,33 @@ public void loadConfiguration() {
log.trace("Processing parameter {} ", f.getName());

Setter setter;
if(f.getType() == List.class){
if (f.getType() == List.class) {
setter = new ListSetter(f, this);
}else{
} 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()));
}
loadManualConfiguration();
}

@Override
public void loadManualConfiguration(){}
/**
* This abstract method is intended to be overridden by subclasses to manually load
* specific configurations that are not automatically processed by the
* {@link #loadConfiguration()} method.
* <p>
* The {@link #loadConfiguration()} method first handles automated configuration by
* scanning annotated fields and invoking handlers to set their values. Once that
* process is complete, {@code loadManualConfiguration} is called to allow subclasses
* to define any additional custom configuration logic that is required.
* <p>
* Subclasses can choose to override this method to provide custom configurations
* that cannot be handled automatically. If no manual configuration is necessary,
* the default implementation can be used without changes.
*/
public void loadManualConfiguration(){
// Default implementation: no manual configuration
};
}
2 changes: 0 additions & 2 deletions s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public interface Module {
*/
void loadConfiguration();

void loadManualConfiguration();

Resource getResource();

void setInputModules(List<Module> inputModules);
Expand Down

0 comments on commit 80fab41

Please sign in to comment.