From 313ec433f8c612a1967510da4c599518da405df7 Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Sun, 15 Dec 2024 01:23:59 +0100 Subject: [PATCH] [Fix #286] Add CharacterHandler and ModeHandler and register them in HandlerRegistry --- .../modules/handlers/CharacterHandler.java | 17 +++++++++++++++++ .../modules/handlers/HandlerRegistry.java | 2 ++ .../spipes/modules/ModuleRegistration.java | 12 ++++++++++++ .../cz/cvut/spipes/modules/RDF2CSVModule.java | 2 +- .../cz/cvut/spipes/modules/TabularModule.java | 2 +- .../spipes/modules/handlers/ModeHandler.java | 18 ++++++++++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/CharacterHandler.java create mode 100644 s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/ModuleRegistration.java create mode 100644 s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/handlers/ModeHandler.java diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/CharacterHandler.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/CharacterHandler.java new file mode 100644 index 00000000..46439e1b --- /dev/null +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/CharacterHandler.java @@ -0,0 +1,17 @@ +package cz.cvut.spipes.modules.handlers; + +import cz.cvut.spipes.engine.ExecutionContext; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.Resource; + +public class CharacterHandler extends BaseRDFNodeHandler { + + public CharacterHandler(Resource resource, ExecutionContext executionContext, Setter setter) { + super(resource, executionContext, setter); + } + + @Override + Character getRDFNodeValue(RDFNode node) throws Exception { + return node.asLiteral().getChar(); + } +} diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/HandlerRegistry.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/HandlerRegistry.java index 7c8d952e..4df46f76 100644 --- a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/HandlerRegistry.java +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/handlers/HandlerRegistry.java @@ -53,6 +53,8 @@ private void initHandlers() { registerHandler(boolean.class, BooleanHandler.class); registerHandler(Integer.class, IntegerHandler.class); registerHandler(int.class, IntegerHandler.class); + registerHandler(char.class, CharacterHandler.class); + registerHandler(Character.class, CharacterHandler.class); registerHandler(String.class, StringHandler.class); registerHandler(RDFNode.class, RDFNodeHandler.class); registerHandler(Select.class, SelectHandler.class); diff --git a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/ModuleRegistration.java b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/ModuleRegistration.java new file mode 100644 index 00000000..600d2e97 --- /dev/null +++ b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/ModuleRegistration.java @@ -0,0 +1,12 @@ +package cz.cvut.spipes.modules; + +import cz.cvut.spipes.modules.handlers.HandlerRegistry; +import cz.cvut.spipes.modules.handlers.ModeHandler; + +public class ModuleRegistration { + + public static void register(){ + HandlerRegistry.getInstance().registerHandler(Mode.class, ModeHandler.class); + } + +} diff --git a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/RDF2CSVModule.java b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/RDF2CSVModule.java index 93a881c6..9e68bd66 100644 --- a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/RDF2CSVModule.java +++ b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/RDF2CSVModule.java @@ -29,7 +29,7 @@ "The table is constructed from column and row resources defined in TableSchema and saves it as a new CSV file.\n" + "

") public class RDF2CSVModule extends AnnotatedAbstractModule { - + static {ModuleRegistration.register();} public static final String TYPE_URI = KBSS_MODULE.uri + "RDF2CSV"; public static final String TYPE_PREFIX = TYPE_URI + "/"; diff --git a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java index e66342a0..1b7f396d 100644 --- a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java +++ b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/TabularModule.java @@ -97,7 +97,7 @@ */ @SPipesModule(label = "Tabular module", comment = "Module for converting tabular data (e.g. CSV or TSV) to RDF") public class TabularModule extends AnnotatedAbstractModule { - + static {ModuleRegistration.register();} public static final String TYPE_URI = KBSS_MODULE.uri + "tabular"; public static final String PARAM_URL_PREFIX = TYPE_URI + "/"; private static final Logger LOG = LoggerFactory.getLogger(TabularModule.class); diff --git a/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/handlers/ModeHandler.java b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/handlers/ModeHandler.java new file mode 100644 index 00000000..17097f65 --- /dev/null +++ b/s-pipes-modules/module-tabular/src/main/java/cz/cvut/spipes/modules/handlers/ModeHandler.java @@ -0,0 +1,18 @@ +package cz.cvut.spipes.modules.handlers; +import cz.cvut.spipes.engine.ExecutionContext; +import cz.cvut.spipes.modules.Mode; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.Resource; + +public class ModeHandler extends BaseRDFNodeHandler { + + public ModeHandler(Resource resource, ExecutionContext executionContext, Setter setter) { + super(resource, executionContext, setter); + + } + + @Override + Mode getRDFNodeValue(RDFNode node) throws Exception { + return Mode.fromResource(node.asResource()); + } +}