Skip to content

Commit b43ef5e

Browse files
Koenig Johannes Dr. FRD DIMG6karstenroethig
authored andcommitted
Add support for additional model version identifiers in RexsVersion and update related functionality
1 parent 24d0648 commit b43ef5e

5 files changed

Lines changed: 68 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

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

14+
### Fixed
15+
16+
- RexsSchemaRegistry does now find REXS Versions also based on the additional model version strings
17+
1418

1519
## [0.14.0] - 2025-07-18
1620

api/src/main/java/info/rexs/schema/RexsSchemaRegistry.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public class RexsSchemaRegistry implements IRexsSchemaRegistry {
5050

5151
private static RexsSchemaRegistry instance = null;
5252

53-
private Map<String, RexsVersion> versions = new HashMap<>();
54-
private Map<RexsVersion, Map<String, RexsComponentType>> componentMap = new HashMap<>();
55-
private Map<RexsVersion, Map<String, RexsUnitId>> attributeUnits = new HashMap<>();
56-
private Map<RexsVersion, Map<String, RexsValueType>> attributeTypes = new HashMap<>();
57-
private Map<RexsVersion, Map<String, Attribute>> attributeMap = new HashMap<>();
58-
private Map<RexsVersion, Map<String, List<RexsComponentType>>> attributeToComponentMap = new HashMap<>();
59-
private Map<RexsVersion, Map<RexsComponentType, List<String>>> componentToAttributesMap = new HashMap<>();
60-
private Map<RexsVersion, Map<RexsRelationType, List<List<AllowedCombinationRole>>>> relationsToAllowedCombinationsMap = new HashMap<>();
53+
private final Map<String, RexsVersion> versions = new HashMap<>();
54+
private final Map<RexsVersion, Map<String, RexsComponentType>> componentMap = new HashMap<>();
55+
private final Map<RexsVersion, Map<String, RexsUnitId>> attributeUnits = new HashMap<>();
56+
private final Map<RexsVersion, Map<String, RexsValueType>> attributeTypes = new HashMap<>();
57+
private final Map<RexsVersion, Map<String, Attribute>> attributeMap = new HashMap<>();
58+
private final Map<RexsVersion, Map<String, List<RexsComponentType>>> attributeToComponentMap = new HashMap<>();
59+
private final Map<RexsVersion, Map<RexsComponentType, List<String>>> componentToAttributesMap = new HashMap<>();
60+
private final Map<RexsVersion, Map<RexsRelationType, List<List<AllowedCombinationRole>>>> relationsToAllowedCombinationsMap = new HashMap<>();
6161

6262
private RexsSchemaRegistry() {
6363
try {
@@ -92,7 +92,10 @@ public void registerRexsVersion(RexsVersion version) {
9292
if (rexsSchema == null)
9393
throw new IllegalStateException(String.format("rexs db model for version %s not found", version.getModelVersion()));
9494
registerRexsSchema(version, rexsSchema);
95+
// register primary version
9596
versions.put(version.getModelVersion(), version);
97+
// register additional versions
98+
version.getAdditionalModelVersions().forEach(additionalVersion -> versions.put(additionalVersion, version));
9699
}
97100

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

324327
@Override
325328
public RexsVersion getVersion(String version) {
326-
return versions.get(version);
329+
return versions.getOrDefault(version, RexsVersion.UNKNOWN);
327330
}
328331

329332
@Override

api/src/main/java/info/rexs/schema/RexsSchemaResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import java.util.HashMap;
2020
import java.util.Map;
2121

22-
import jakarta.xml.bind.JAXBContext;
23-
import jakarta.xml.bind.Unmarshaller;
24-
2522
import info.rexs.schema.constants.RexsVersion;
2623
import info.rexs.schema.jaxb.RexsSchema;
24+
import jakarta.xml.bind.JAXBContext;
25+
import jakarta.xml.bind.Unmarshaller;
2726

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

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

4140
private RexsSchemaResolver() {}
4241

api/src/main/java/info/rexs/schema/constants/RexsVersion.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,35 @@ public class RexsVersion {
4949
*/
5050
private final String modelVersion;
5151

52+
/**
53+
* Additional (case-insensitive) identifiers of the versions in the REXS model.
54+
*/
55+
private final List<String> additionalModelVersions = new ArrayList<>();
56+
57+
/**
58+
* Gets the additional model versions.
59+
*
60+
* @return A list of additional model versions.
61+
*/
62+
public List<String> getAdditionalModelVersions() {
63+
return new ArrayList<>(additionalModelVersions);
64+
}
65+
66+
/**
67+
* Creates a new REXS version with additional model versions.
68+
*
69+
* @param schemaVersion The (case-insensitive) identifier of the version in the REXS schema.
70+
* @param schemaProvider The (case-insensitive) identifier of the provider in the REXS schema.
71+
* @param modelVersion The (case-insensitive) identifier of the version in the REXS model.
72+
* @param additionalModelVersions Additional (case-insensitive) identifiers of the versions inthe REXS model.
73+
*/
74+
private RexsVersion(String schemaVersion, String schemaProvider, String modelVersion, List<String> additionalModelVersions) {
75+
this.schemaVersion = schemaVersion;
76+
this.schemaProvider = schemaProvider;
77+
this.modelVersion = modelVersion;
78+
this.additionalModelVersions.addAll(additionalModelVersions);
79+
}
80+
5281
/**
5382
* Creates a new REXS version.
5483
*
@@ -89,7 +118,7 @@ public static RexsVersion create(String schemaVersion, String schemaProvider, St
89118
throw new IllegalArgumentException("schemaVersion must follow the pattern X.X");
90119

91120
// create the primary version
92-
RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion);
121+
RexsVersion primaryVersion = new RexsVersion(schemaVersion, schemaProvider, primaryModelVersion, List.of(additionalModelVersions));
93122
allModelVersions.put(primaryVersion.getModelVersion(), primaryVersion);
94123

95124
// register additional versions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package info.rexs.schema;
2+
3+
import info.rexs.schema.constants.RexsVersion;
4+
import info.rexs.schema.constants.standard.RexsStandardVersions;
5+
import junit.framework.TestCase;
6+
7+
public class RexsSchemaRegistryTest extends TestCase {
8+
9+
public void testGetVersion() {
10+
// find version by primary model version
11+
assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("1.0"));
12+
13+
// find version by additional model version
14+
assertEquals(RexsStandardVersions.V1_0, RexsSchemaRegistry.getInstance().getVersion("0.90"));
15+
16+
// invalid version returns UNKNOWN
17+
assertEquals(RexsVersion.UNKNOWN, RexsSchemaRegistry.getInstance().getVersion("9.9"));
18+
}
19+
}

0 commit comments

Comments
 (0)