Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit c436087

Browse files
committed
Adding the XML Serializer as a Maven module
1 parent 61194b4 commit c436087

84 files changed

Lines changed: 6463 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dataformat-json/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>io.adminshell.aas</groupId>
7+
<parent>
8+
<groupId>io.adminshell.aas</groupId>
9+
<artifactId>dataformat-parent</artifactId>
10+
<version>${revision}</version>
11+
</parent>
812
<artifactId>dataformat-json</artifactId>
9-
<version>${parent.version}</version>
13+
1014
<build>
1115
<plugins>
1216
<plugin>

dataformat-xml/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.idea/
2+
log/
3+
*.log
4+
bin/
5+
target/
6+
pom.xml.tag
7+
pom.xml.releaseBackup
8+
pom.xml.versionsBackup
9+
pom.xml.next
10+
release.properties
11+
dependency-reduced-pom.xml
12+
buildNumber.properties
13+
.mvn/timing.properties
14+
.mvn/wrapper/maven-wrapper.jar
15+
.metadata
16+
bin/
17+
tmp/
18+
*.tmp
19+
*.bak
20+
*.swp
21+
*~.nib
22+
local.properties
23+
.settings/
24+
.loadpath
25+
.recommenders
26+
27+
.classpath
28+
.project
29+
30+
testJsonSerialization.json
31+

dataformat-xml/pom.xml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.adminshell.aas</groupId>
9+
<artifactId>dataformat-parent</artifactId>
10+
<version>${revision}</version>
11+
</parent>
12+
<artifactId>dataformat-xml</artifactId>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<configuration>
20+
<source>11</source>
21+
<target>11</target>
22+
</configuration>
23+
</plugin>
24+
<plugin>
25+
<groupId>org.codehaus.mojo</groupId>
26+
<artifactId>flatten-maven-plugin</artifactId>
27+
<version>1.2.2</version>
28+
<configuration>
29+
<updatePomFile>true</updatePomFile>
30+
</configuration>
31+
<executions>
32+
<execution>
33+
<id>flatten</id>
34+
<phase>process-resources</phase>
35+
<goals>
36+
<goal>flatten</goal>
37+
</goals>
38+
</execution>
39+
<execution>
40+
<id>flatten.clean</id>
41+
<phase>clean</phase>
42+
<goals>
43+
<goal>clean</goal>
44+
</goals>
45+
</execution>
46+
</executions>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
51+
<dependencies>
52+
<dependency>
53+
<groupId>io.adminshell.aas</groupId>
54+
<artifactId>model</artifactId>
55+
<version>${model.version}</version>
56+
<scope>compile</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>com.fasterxml.jackson.core</groupId>
61+
<artifactId>jackson-annotations</artifactId>
62+
<version>2.12.3</version>
63+
<scope>compile</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>com.fasterxml.jackson.core</groupId>
67+
<artifactId>jackson-databind</artifactId>
68+
<version>2.12.3</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>com.fasterxml.jackson.dataformat</groupId>
72+
<artifactId>jackson-dataformat-xml</artifactId>
73+
<version>2.12.3</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.codehaus.woodstox</groupId>
77+
<artifactId>woodstox-core-asl</artifactId>
78+
<version>4.4.1</version>
79+
</dependency>
80+
81+
82+
<dependency>
83+
<groupId>org.slf4j</groupId>
84+
<artifactId>slf4j-api</artifactId>
85+
<version>1.7.30</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-simple</artifactId>
90+
<version>1.7.30</version>
91+
</dependency>
92+
93+
<dependency>
94+
<groupId>junit</groupId>
95+
<artifactId>junit</artifactId>
96+
<version>4.13</version>
97+
<scope>test</scope>
98+
</dependency>
99+
<dependency>
100+
<groupId>pl.pragmatists</groupId>
101+
<artifactId>JUnitParams</artifactId>
102+
<version>1.1.1</version>
103+
<scope>test</scope>
104+
</dependency>
105+
</dependencies>
106+
107+
<repositories>
108+
<repository>
109+
<id>eis-public-repo</id>
110+
<name>maven-public</name>
111+
<url>http://maven.iais.fraunhofer.de/artifactory/eis-ids-public</url>
112+
</repository>
113+
</repositories>
114+
115+
</project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.adminshell.aas.v3.dataformat.xml;
2+
3+
import java.util.Arrays;
4+
import java.util.Map;
5+
import java.util.Objects;
6+
import java.util.Optional;
7+
8+
import io.adminshell.aas.v3.model.DataSpecificationContent;
9+
import io.adminshell.aas.v3.model.DataSpecificationIEC61360;
10+
import io.adminshell.aas.v3.model.KeyElements;
11+
import io.adminshell.aas.v3.model.KeyType;
12+
import io.adminshell.aas.v3.model.Reference;
13+
import io.adminshell.aas.v3.model.impl.DefaultKey;
14+
import io.adminshell.aas.v3.model.impl.DefaultReference;
15+
16+
public class DataSpecificationManager {
17+
18+
public static final String PROP_DATA_SPECIFICATION = "dataSpecification";
19+
public static final String PROP_DATA_SPECIFICATION_CONTENT = "dataSpecificationContent";
20+
21+
private static final Map<Reference, Class<? extends DataSpecificationContent>> KNOWN_IMPLEMENTATIONS = Map.of(
22+
createGlobalIri("http://admin-shell.io/DataSpecificationTemplates/DataSpecificationIEC61360/2/0"),
23+
DataSpecificationIEC61360.class);
24+
25+
public static void register(Reference reference, Class<? extends DataSpecificationContent> implementation) {
26+
KNOWN_IMPLEMENTATIONS.put(reference, implementation);
27+
}
28+
29+
public static void registerGlobalIri(String iri, Class<? extends DataSpecificationContent> implementation) {
30+
KNOWN_IMPLEMENTATIONS.put(createGlobalIri(iri), implementation);
31+
}
32+
33+
private static Reference createGlobalIri(String iri) {
34+
return new DefaultReference.Builder().keys(Arrays.asList(
35+
new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.GLOBAL_REFERENCE).value(iri).build()))
36+
.build();
37+
}
38+
39+
public static Reference getReference(Class<? extends DataSpecificationContent> implementation) {
40+
Reference result = getReferenceSafe(implementation);
41+
if (result == null) {
42+
throw new IllegalArgumentException(
43+
String.format("unknown data specification implementation '%s'", implementation.getName()));
44+
}
45+
return result;
46+
}
47+
48+
private static Reference getReferenceSafe(Class<? extends DataSpecificationContent> implementation) {
49+
Optional<Reference> exactMatch = KNOWN_IMPLEMENTATIONS.entrySet().stream()
50+
.filter(x -> Objects.equals(x.getValue(), implementation)).map(x -> x.getKey()).findFirst();
51+
if (exactMatch.isPresent()) {
52+
return exactMatch.get();
53+
}
54+
Optional<Reference> inheritanceMatch = KNOWN_IMPLEMENTATIONS.entrySet().stream()
55+
.filter(x -> x.getValue().isAssignableFrom(implementation)).map(x -> x.getKey()).findFirst();
56+
if (inheritanceMatch.isPresent()) {
57+
return inheritanceMatch.get();
58+
}
59+
return null;
60+
}
61+
62+
public static Class<? extends DataSpecificationContent> getImplementation(Reference reference) {
63+
if (KNOWN_IMPLEMENTATIONS.containsKey(reference)) {
64+
return KNOWN_IMPLEMENTATIONS.get(reference);
65+
}
66+
throw new IllegalArgumentException(String.format("unknown data specification reference '%s'", reference));
67+
}
68+
}

0 commit comments

Comments
 (0)