diff --git a/processors/shacl-validator-kt/src/main/kotlin/SHACLValidator.kt b/processors/shacl-validator-kt/src/main/kotlin/SHACLValidator.kt index e9888c7..6165ff7 100644 --- a/processors/shacl-validator-kt/src/main/kotlin/SHACLValidator.kt +++ b/processors/shacl-validator-kt/src/main/kotlin/SHACLValidator.kt @@ -17,30 +17,30 @@ class SHACLValidator(args: Arguments) : Processor(args) { private val errorIsFatalDefault = false /** Arguments. */ - private val fatal: Boolean? = arguments["validation_is_fatal"] - private val incoming: ReceiveChannel = arguments["incoming"] - private val outgoing: SendChannel = arguments["outgoing"] - private val report: SendChannel? = arguments["report"] - private val path: String = arguments["shapes"] + private val fatal: Boolean? by args + private val incoming: ReceiveChannel by args + private val outgoing: SendChannel by args + private val report: SendChannel? by args + private val shapes: String by args /** Runtime fields. */ - private val shapes: Graph + private val shapesGraph: Graph private val validator = ShaclValidator.get() init { // Initialize the shape graph and validator. - Log.shared.debug { "Loading: $path" } + Log.shared.debug { "Loading: $shapes" } - // Create a new model with the SHACL shapes. + // Create a new model with the SHACL shapesGraph. val model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM) try { - model.read(path, "TURTLE") + model.read(shapes, "TURTLE") } catch (e: RiotException) { - Log.shared.fatal("Failed to read SHACL shapes from file://$path") + Log.shared.fatal("Failed to read SHACL shapesGraph from file://$shapes") } - // Assign its graph to the shapes field. - this.shapes = model.graph + // Assign its graph to the shapesGraph field. + this.shapesGraph = model.graph } /** Read incoming data, validate it, and output it. */ @@ -56,7 +56,7 @@ class SHACLValidator(args: Arguments) : Processor(args) { } // Validate the model. - val report = validator.validate(shapes, model.graph) + val report = validator.validate(shapesGraph, model.graph) if (report.conforms()) { Log.shared.debug { "Validation successful." } diff --git a/src/main/kotlin/runner/impl/jvm/Arguments.kt b/src/main/kotlin/runner/impl/jvm/Arguments.kt index b1daa2d..b073354 100644 --- a/src/main/kotlin/runner/impl/jvm/Arguments.kt +++ b/src/main/kotlin/runner/impl/jvm/Arguments.kt @@ -1,5 +1,6 @@ package technology.idlab.runner.impl.jvm +import kotlin.reflect.KProperty import kotlin.reflect.KType import kotlin.reflect.full.isSubclassOf import kotlin.reflect.full.isSuperclassOf @@ -105,6 +106,10 @@ data class Arguments( } } + inline operator fun getValue(thisRef: Any, property: KProperty<*>): T { + return this.get(property.name) + } + companion object { /** * Parse a (nested) map into type-safe arguments. This method calls itself recursively for all diff --git a/src/test/kotlin/runner/impl/jvm/ArgumentsTest.kt b/src/test/kotlin/runner/impl/jvm/ArgumentsTest.kt index 57f07c0..e556d86 100644 --- a/src/test/kotlin/runner/impl/jvm/ArgumentsTest.kt +++ b/src/test/kotlin/runner/impl/jvm/ArgumentsTest.kt @@ -14,6 +14,25 @@ class ArgumentsTest { Log.shared.setFatalMode(Log.FatalMode.EXCEPTION) } + @Test + fun delegation() { + val args = + Arguments( + mapOf( + "words" to listOf("the", "a"), + "present" to listOf(true), + )) + val obj = + object { + val words: List by args + val present: Boolean? by args + val nulled: Boolean? by args + } + assertEquals(listOf("the", "a"), obj.words) + assertEquals(true, obj.present) + assertEquals(null, obj.nulled) + } + @Test fun single() { val args = Arguments(mapOf("key" to listOf("value")))