Skip to content

Commit

Permalink
Check identity constraint refs don't have invalid attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
pdvrieze committed Jan 31, 2024
1 parent 2a1b83d commit 1892106
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023.
* Copyright (c) 2024.
*
* This file is part of xmlutil.
*
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023.
* Copyright (c) 2024.
*
* This file is part of xmlutil.
*
Expand All @@ -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(
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -30,6 +30,8 @@ class ResolvedIndirectUnique(
): ResolvedIndirectIdentityConstraint<ResolvedDirectUnique>(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
Expand Down

0 comments on commit 1892106

Please sign in to comment.