From 1892106ae6f522bc2733442f319e82aa4d0ce66e Mon Sep 17 00:00:00 2001 From: Paul de Vrieze Date: Wed, 31 Jan 2024 22:30:11 +0000 Subject: [PATCH] Check identity constraint refs don't have invalid attributes --- .../formats/xmlschema/resolved/ResolvedDirectKey.kt | 6 +++++- .../formats/xmlschema/resolved/ResolvedDirectUnique.kt | 7 +++++-- .../formats/xmlschema/resolved/ResolvedIndirectKey.kt | 6 ++++-- .../formats/xmlschema/resolved/ResolvedIndirectKeyRef.kt | 7 +++++-- .../formats/xmlschema/resolved/ResolvedIndirectUnique.kt | 6 ++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectKey.kt b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectKey.kt index fd55c85ef..bd1e4ace5 100644 --- a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectKey.kt +++ b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectKey.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023. + * Copyright (c) 2024. * * This file is part of xmlutil. * @@ -31,6 +31,10 @@ class ResolvedDirectKey( owner: ResolvedElement, ): ResolvedDirectReferenceable(rawPart, schema, owner), ResolvedKey { + init { + require(rawPart.ref == null) { "A key can either have a name or ref" } + } + override val mdlQName: QName = checkNotNull(rawPart.name).toQname(schema.targetNamespace) override val selector: XSSelector = checkNotNull(rawPart.selector) diff --git a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectUnique.kt b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectUnique.kt index 12796e7f3..01681c38c 100644 --- a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectUnique.kt +++ b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedDirectUnique.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023. + * Copyright (c) 2024. * * This file is part of xmlutil. * @@ -23,7 +23,6 @@ package io.github.pdvrieze.formats.xmlschema.resolved import io.github.pdvrieze.formats.xmlschema.datatypes.serialization.XSField import io.github.pdvrieze.formats.xmlschema.datatypes.serialization.XSSelector import io.github.pdvrieze.formats.xmlschema.datatypes.serialization.XSUnique -import io.github.pdvrieze.formats.xmlschema.resolved.checking.CheckHelper import nl.adaptivity.xmlutil.QName class ResolvedDirectUnique( @@ -32,6 +31,10 @@ class ResolvedDirectUnique( owner: ResolvedElement, ): ResolvedDirectReferenceable(rawPart, schema, owner), ResolvedUnique { + init { + require(rawPart.ref == null) { "A unique can either have a name or ref" } + } + override val constraint: ResolvedDirectUnique get() = this diff --git a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKey.kt b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKey.kt index faf0d6617..049cdc2dd 100644 --- a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKey.kt +++ b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKey.kt @@ -1,7 +1,7 @@ /* - * Copyright (c) 2023. + * Copyright (c) 2024. * - * This file is part of XmlUtil. + * This file is part of xmlutil. * * This file is licenced to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance @@ -31,6 +31,8 @@ class ResolvedIndirectKey( init { check(rawPart.name == null) + check(rawPart.selector == null) { "When reference only id is valid member, not selector" } + check(rawPart.fields.isEmpty()) { "When reference only id is valid member, not fields" } } override val mdlIdentityConstraintCategory: ResolvedIdentityConstraint.Category get() = super.mdlIdentityConstraintCategory diff --git a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKeyRef.kt b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKeyRef.kt index 16c29789d..06ea9b064 100644 --- a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKeyRef.kt +++ b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectKeyRef.kt @@ -1,7 +1,7 @@ /* - * Copyright (c) 2023. + * Copyright (c) 2024. * - * This file is part of XmlUtil. + * This file is part of xmlutil. * * This file is licenced to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance @@ -29,6 +29,9 @@ class ResolvedIndirectKeyRef(rawPart: XSKeyRef, schema: ResolvedSchemaLike, owne init { check(rawPart.name == null) + check(rawPart.refer == null) { "When reference only id is valid member, not refer" } + check(rawPart.selector == null) { "When reference only id is valid member, not selector" } + check(rawPart.fields.isEmpty()) { "When reference only id is valid member, not fields" } } override val constraint: ResolvedIndirectKeyRef get() = this diff --git a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectUnique.kt b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectUnique.kt index f29450a64..ea7b212cc 100644 --- a/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectUnique.kt +++ b/xmlschema/src/commonMain/kotlin/io/github/pdvrieze/formats/xmlschema/resolved/ResolvedIndirectUnique.kt @@ -1,7 +1,7 @@ /* - * Copyright (c) 2023. + * Copyright (c) 2024. * - * This file is part of XmlUtil. + * This file is part of xmlutil. * * This file is licenced to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance @@ -30,6 +30,8 @@ class ResolvedIndirectUnique( ): ResolvedIndirectIdentityConstraint(rawPart, schema, owner), ResolvedUnique { init { check(rawPart.name == null) + check(rawPart.selector == null) { "When reference only id is valid member, not selector" } + check(rawPart.fields.isEmpty()) { "When reference only id is valid member, not fields" } } override val constraint: ResolvedIndirectUnique get() = this