Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added equivalent untis to `RexsStandardUnitIds` (`deg`, `degree`)

### Fixed

- RexsSchemaRegistry does now find REXS Versions also based on the additional model version strings


## [0.14.0] - 2025-07-18

Expand Down
21 changes: 12 additions & 9 deletions api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public class RexsSchemaRegistry implements IRexsSchemaRegistry {

private static RexsSchemaRegistry instance = null;

private Map<String, RexsVersion> versions = new HashMap<>();
private Map<RexsVersion, Map<String, RexsComponentType>> componentMap = new HashMap<>();
private Map<RexsVersion, Map<String, RexsUnitId>> attributeUnits = new HashMap<>();
private Map<RexsVersion, Map<String, RexsValueType>> attributeTypes = new HashMap<>();
private Map<RexsVersion, Map<String, Attribute>> attributeMap = new HashMap<>();
private Map<RexsVersion, Map<String, List<RexsComponentType>>> attributeToComponentMap = new HashMap<>();
private Map<RexsVersion, Map<RexsComponentType, List<String>>> componentToAttributesMap = new HashMap<>();
private Map<RexsVersion, Map<RexsRelationType, List<List<AllowedCombinationRole>>>> relationsToAllowedCombinationsMap = new HashMap<>();
private final Map<String, RexsVersion> versions = new HashMap<>();
private final Map<RexsVersion, Map<String, RexsComponentType>> componentMap = new HashMap<>();
private final Map<RexsVersion, Map<String, RexsUnitId>> attributeUnits = new HashMap<>();
private final Map<RexsVersion, Map<String, RexsValueType>> attributeTypes = new HashMap<>();
private final Map<RexsVersion, Map<String, Attribute>> attributeMap = new HashMap<>();
private final Map<RexsVersion, Map<String, List<RexsComponentType>>> attributeToComponentMap = new HashMap<>();
private final Map<RexsVersion, Map<RexsComponentType, List<String>>> componentToAttributesMap = new HashMap<>();
private final Map<RexsVersion, Map<RexsRelationType, List<List<AllowedCombinationRole>>>> relationsToAllowedCombinationsMap = new HashMap<>();

private RexsSchemaRegistry() {
try {
Expand Down Expand Up @@ -92,7 +92,10 @@ public void registerRexsVersion(RexsVersion version) {
if (rexsSchema == null)
throw new IllegalStateException(String.format("rexs db model for version %s not found", version.getModelVersion()));
registerRexsSchema(version, rexsSchema);
// register primary version
versions.put(version.getModelVersion(), version);
// register additional versions
version.getAdditionalModelVersions().forEach(additionalVersion -> versions.put(additionalVersion, version));
}

private void registerRexsSchema(RexsVersion version, RexsSchema rexsSchema) {
Expand Down Expand Up @@ -323,7 +326,7 @@ public List<String> getAttributeIdsOfComponentType(RexsComponentType rexsCompone

@Override
public RexsVersion getVersion(String version) {
return versions.get(version);
return versions.getOrDefault(version, RexsVersion.UNKNOWN);
}

@Override
Expand Down
7 changes: 3 additions & 4 deletions api/src/main/java/info/rexs/schema/RexsSchemaResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import java.util.HashMap;
import java.util.Map;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Unmarshaller;

import info.rexs.schema.constants.RexsVersion;
import info.rexs.schema.jaxb.RexsSchema;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Unmarshaller;

/**
* This class provides the REXS schemas of all available REXS versions (REXS standard and own).
Expand All @@ -36,7 +35,7 @@ public class RexsSchemaResolver {
private static RexsSchemaResolver instance = null;

/** An internal index with all created REXS schemas (REXS standard and own) for quick access. */
private Map<RexsSchemaFile, RexsSchema> rexsSchemaFileCache = new HashMap<>();
private final Map<RexsSchemaFile, RexsSchema> rexsSchemaFileCache = new HashMap<>();

private RexsSchemaResolver() {}

Expand Down
31 changes: 30 additions & 1 deletion api/src/main/java/info/rexs/schema/constants/RexsVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ public class RexsVersion {
*/
private final String modelVersion;

/**
* Additional (case-insensitive) identifiers of the versions in the REXS model.
*/
private final List<String> additionalModelVersions = new ArrayList<>();

/**
* Gets the additional model versions.
*
* @return A list of additional model versions.
*/
public List<String> getAdditionalModelVersions() {
return new ArrayList<>(additionalModelVersions);
}

/**
* Creates a new REXS version with additional model versions.
*
* @param schemaVersion The (case-insensitive) identifier of the version in the REXS schema.
* @param schemaProvider The (case-insensitive) identifier of the provider in the REXS schema.
* @param modelVersion The (case-insensitive) identifier of the version in the REXS model.
* @param additionalModelVersions Additional (case-insensitive) identifiers of the versions inthe REXS model.
*/
private RexsVersion(String schemaVersion, String schemaProvider, String modelVersion, List<String> additionalModelVersions) {
this.schemaVersion = schemaVersion;
this.schemaProvider = schemaProvider;
this.modelVersion = modelVersion;
this.additionalModelVersions.addAll(additionalModelVersions);
}

/**
* Creates a new REXS version.
*
Expand Down Expand Up @@ -89,7 +118,7 @@ public static RexsVersion create(String schemaVersion, String schemaProvider, St
throw new IllegalArgumentException("schemaVersion must follow the pattern X.X");

// create the primary version
RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion);
RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion, List.of(additionalModelVersions));
allModelVersions.put(primaryVersion.getModelVersion(), primaryVersion);

// register additional versions
Expand Down
19 changes: 19 additions & 0 deletions api/src/test/java/info/rexs/schema/RexsSchemaRegistryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package info.rexs.schema;

import info.rexs.schema.constants.RexsVersion;
import info.rexs.schema.constants.standard.RexsStandardVersions;
import junit.framework.TestCase;

public class RexsSchemaRegistryTest extends TestCase {

public void testGetVersion() {
// find version by primary model version
assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("1.0"));

// find version by additional model version
assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("0.90"));

// invalid version returns UNKNOWN
assertEquals(RexsVersion.UNKNOWN, RexsSchemaRegistry.getInstance().getVersion("9.9"));
}
}