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

Commit 645d08c

Browse files
committed
latest working version
1 parent ec3dabf commit 645d08c

44 files changed

Lines changed: 3387 additions & 2688 deletions

Some content is hidden

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

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/AmlSerializationConfig.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/Aas2AmlConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
import java.util.Arrays;
2222
import java.util.List;
2323

24-
public class AmlSerializationConfig {
24+
public class Aas2AmlConfig {
2525

2626
private final boolean includeLibraries;
2727
private final IdGenerator idGenerator;
2828
private final List<Object> additionalInformation;
29-
public static final AmlSerializationConfig DEFAULT = new Builder().build();
29+
public static final Aas2AmlConfig DEFAULT = new Builder().build();
3030

3131
public static Builder builder() {
3232
return new Builder();
3333
}
3434

35-
private AmlSerializationConfig(boolean includeLibraries, IdGenerator idGenerator, List<Object> additionalInformation) {
35+
private Aas2AmlConfig(boolean includeLibraries, IdGenerator idGenerator, List<Object> additionalInformation) {
3636
this.includeLibraries = includeLibraries;
3737
this.idGenerator = idGenerator;
3838
this.additionalInformation = additionalInformation;
@@ -56,8 +56,8 @@ public static class Builder {
5656
private IdGenerator idGenerator = new UuidGenerator();
5757
private List<Object> additionalInformation = new ArrayList<>();
5858

59-
public AmlSerializationConfig build() {
60-
return new AmlSerializationConfig(includeLibraries, idGenerator, additionalInformation);
59+
public Aas2AmlConfig build() {
60+
return new Aas2AmlConfig(includeLibraries, idGenerator, additionalInformation);
6161
}
6262

6363
public Builder includeLibraries() {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.adminshell.aas.v3.dataformat.aml;
2+
3+
public class Aml2AasConfig {
4+
5+
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/AmlDeserializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import io.adminshell.aas.v3.dataformat.DeserializationException;
1919
import io.adminshell.aas.v3.dataformat.Deserializer;
20+
import io.adminshell.aas.v3.dataformat.aml.aml2aas.Aml2AasObjectMapper;
2021
import io.adminshell.aas.v3.dataformat.aml.model.caex.CAEXFile;
22+
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
2123
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
2224
import java.io.StringReader;
2325
import javax.xml.bind.JAXBException;
@@ -29,17 +31,19 @@
2931
public class AmlDeserializer implements Deserializer {
3032

3133
private static final Logger log = LoggerFactory.getLogger(AmlDeserializer.class);
32-
private AmlToAasMapper mapper = new AmlToAasMapper();
3334

3435
@Override
3536
public AssetAdministrationShellEnvironment read(String value) throws DeserializationException {
3637
try {
3738
Unmarshaller unmarshaller = JAXBContextFactory.createContext(new Class[]{CAEXFile.class}, null).createUnmarshaller();
3839
StringReader reader = new StringReader(value);
3940
CAEXFile aml = (CAEXFile) unmarshaller.unmarshal(reader);
41+
Aml2AasObjectMapper mapper = new Aml2AasObjectMapper(new Aml2AasConfig());
4042
return mapper.map(aml);
4143
} catch (JAXBException ex) {
4244
throw new DeserializationException("error deserializing AssetAdministrationShellEnvironment", ex);
45+
} catch (MappingException ex) {
46+
throw new DeserializationException("error mapping AML document to AssetAdministrationShellEnvironment", ex);
4347
}
4448
}
4549

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/AmlGenerator.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@
2222
import io.adminshell.aas.v3.dataformat.aml.model.caex.InternalElementType;
2323
import io.adminshell.aas.v3.dataformat.aml.model.caex.RoleClassType;
2424
import io.adminshell.aas.v3.dataformat.aml.model.caex.SystemUnitClassType;
25+
import io.adminshell.aas.v3.dataformat.aml.util.AASUtils;
26+
import io.adminshell.aas.v3.model.Identifiable;
27+
import io.adminshell.aas.v3.model.KeyType;
2528
import io.adminshell.aas.v3.model.Referable;
29+
import io.adminshell.aas.v3.model.Reference;
30+
import io.adminshell.aas.v3.model.impl.DefaultKey;
31+
import io.adminshell.aas.v3.model.impl.DefaultReference;
2632
import java.beans.PropertyDescriptor;
33+
import java.util.Arrays;
2734
import java.util.List;
35+
import java.util.stream.Collectors;
2836
import org.slf4j.Logger;
2937
import org.slf4j.LoggerFactory;
3038

@@ -36,16 +44,32 @@ public class AmlGenerator {
3644
private CAEXObject.Builder current;
3745
private CAEXFile.Builder fileBuilder;
3846
private final AmlDocumentInfo documentInfo;
39-
40-
private AmlGenerator(AmlDocumentInfo documentInfo, String refSemanticPrefix, CAEXFile.Builder fileBuilder, CAEXObject.Builder current) {
47+
private final Reference reference;
48+
49+
private AmlGenerator(
50+
AmlDocumentInfo documentInfo,
51+
String refSemanticPrefix,
52+
CAEXFile.Builder fileBuilder,
53+
CAEXObject.Builder current,
54+
Reference reference) {
4155
this.documentInfo = documentInfo;
4256
this.refSemanticPrefix = refSemanticPrefix;
4357
this.fileBuilder = fileBuilder;
4458
this.current = current;
59+
this.reference = reference;
4560
}
4661

4762
public AmlGenerator with(CAEXObject.Builder current) {
48-
return new AmlGenerator(documentInfo, refSemanticPrefix, fileBuilder, current);
63+
return new AmlGenerator(documentInfo, refSemanticPrefix, fileBuilder, current, reference);
64+
}
65+
66+
public AmlGenerator with(Referable parent) {
67+
return new AmlGenerator(
68+
documentInfo,
69+
refSemanticPrefix,
70+
fileBuilder,
71+
current,
72+
AASUtils.asReference(reference, parent));
4973
}
5074

5175
public void addAdditionalInformation(List<Object> additionalInformation) {
@@ -64,7 +88,7 @@ public static class Builder {
6488
private AmlDocumentInfo documentInfo = new AmlDocumentInfo();
6589

6690
public AmlGenerator build() {
67-
return new AmlGenerator(documentInfo, refSemanticPrefix, fileBuilder, current);
91+
return new AmlGenerator(documentInfo, refSemanticPrefix, fileBuilder, current, new DefaultReference.Builder().build());
6892
}
6993

7094
public Builder refSemanticPrefix(String value) {
@@ -184,11 +208,12 @@ public RoleClassType.ExternalInterface getReferenceTargetInterface(Object obj, A
184208
RoleClassType.ExternalInterface result = null;
185209
if (obj != null && Referable.class.isAssignableFrom(obj.getClass())) {
186210
Referable referable = (Referable) obj;
187-
if (context.isTargetOfInternalLink(referable)) {
211+
Reference targetRef = AASUtils.asReference(reference, referable);
212+
if (context.isTargetOfInternalLink(targetRef)) {
188213
result = RoleClassType.ExternalInterface.builder()
189-
.withID(context.generateId())
190-
.withName("externalReferenceTarget")
191-
.withRefBaseClassPath("AutomationMLInterfaceClassLib/AutomationMLBaseInterface")
214+
.withID(context.newId())
215+
.withName("ReferableReference")
216+
.withRefBaseClassPath(documentInfo.getAssetAdministrationShellInterfaceClassLib() + "/ReferableReference")
192217
.build();
193218
}
194219
}
@@ -222,4 +247,8 @@ public String refBaseSystemUnitPath(Object value, Aas2AmlMappingContext context)
222247
public AmlDocumentInfo getDocumentInfo() {
223248
return documentInfo;
224249
}
250+
251+
public Reference getReference() {
252+
return reference;
253+
}
225254
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/AmlSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public AmlSerializer() {
4242

4343
@Override
4444
public String write(AssetAdministrationShellEnvironment aasEnvironment) throws SerializationException {
45-
return write(aasEnvironment, AmlSerializationConfig.DEFAULT);
45+
return write(aasEnvironment, Aas2AmlConfig.DEFAULT);
4646
}
4747

48-
public String write(AssetAdministrationShellEnvironment aasEnvironment, AmlSerializationConfig config) throws SerializationException {
48+
public String write(AssetAdministrationShellEnvironment aasEnvironment, Aas2AmlConfig config) throws SerializationException {
4949
AasToAmlMapper mapper = new AasToAmlMapper(config);
5050
try {
5151
CAEXFile aml = mapper.map(aasEnvironment);

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/aas2aml/Aas2AmlMappingContext.java

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import io.adminshell.aas.v3.dataformat.aml.AmlGenerator;
1919
import io.adminshell.aas.v3.dataformat.aml.id.IdGenerator;
2020
import io.adminshell.aas.v3.dataformat.aml.naming.NamingStrategy;
21+
import io.adminshell.aas.v3.dataformat.aml.util.AASUtils;
22+
import io.adminshell.aas.v3.dataformat.aml.util.ReferencedByViewCollector;
2123
import io.adminshell.aas.v3.dataformat.aml.util.ReferencedReferableCollector;
22-
import io.adminshell.aas.v3.dataformat.mapping.MappingContext;
2324
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
2425
import io.adminshell.aas.v3.dataformat.mapping.MappingProvider;
26+
import io.adminshell.aas.v3.dataformat.mapping.SourceBasedMappingContext;
2527
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
2628
import io.adminshell.aas.v3.model.Referable;
2729
import java.beans.PropertyDescriptor;
@@ -31,8 +33,11 @@
3133
import java.util.stream.Collectors;
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
36+
import io.adminshell.aas.v3.model.Reference;
37+
import java.util.Optional;
38+
import java.util.Set;
3439

35-
public class Aas2AmlMappingContext extends MappingContext {
40+
public class Aas2AmlMappingContext extends SourceBasedMappingContext {
3641

3742
private static final String EMPTY_STRING = "";
3843
private static final Logger log = LoggerFactory.getLogger(Aas2AmlMappingContext.class);
@@ -43,7 +48,7 @@ public class Aas2AmlMappingContext extends MappingContext {
4348
private final Map<Object, String> idCache;
4449

4550
private final PropertyDescriptor property;
46-
private final Map<Referable, String> referecedReferableIDs;
51+
private final Set<Reference> referencedReferables;
4752

4853
public Aas2AmlMappingContext(MappingProvider mappingProvider,
4954
IdGenerator idGenerator,
@@ -55,7 +60,10 @@ public Aas2AmlMappingContext(MappingProvider mappingProvider,
5560
internalElementNamingStrategy,
5661
attributeNamingStrategy,
5762
environment,
58-
null, null, null);
63+
null,
64+
null,
65+
null);
66+
5967
}
6068

6169
public NamingStrategy getInternalElementNamingStrategy() {
@@ -71,7 +79,7 @@ private Aas2AmlMappingContext(MappingProvider mappingProvider,
7179
NamingStrategy internalElementNamingStrategy,
7280
NamingStrategy attributeNamingStrategy,
7381
AssetAdministrationShellEnvironment environment,
74-
Map<Referable, String> referecedReferableIDs,
82+
Set<Reference> referencedReferables,
7583
Map<Object, String> idCache,
7684
PropertyDescriptor property) {
7785
super(mappingProvider);
@@ -80,41 +88,60 @@ private Aas2AmlMappingContext(MappingProvider mappingProvider,
8088
this.attributeNamingStrategy = attributeNamingStrategy;
8189
this.environment = environment;
8290
this.property = property;
83-
if (referecedReferableIDs == null) {
84-
this.referecedReferableIDs = new ReferencedReferableCollector(environment).collect().stream()
85-
.collect(Collectors.toMap(x -> x, x -> EMPTY_STRING));
91+
if (referencedReferables == null) {
92+
this.referencedReferables = new ReferencedReferableCollector(environment).collect();
8693
} else {
87-
this.referecedReferableIDs = referecedReferableIDs;
94+
this.referencedReferables = referencedReferables;
8895
}
8996
if (idCache == null) {
9097
this.idCache = new HashMap<>();
9198
} else {
9299
this.idCache = idCache;
93100
}
94101
}
102+
//
103+
// public String generateId() {
104+
// return idGenerator.generateId();
105+
// }
95106

96-
public String getInternalLinkTargetId(Referable target) {
97-
if (!isTargetOfInternalLink(target)) {
98-
referecedReferableIDs.put(target, getCachedId(target));
99-
}
100-
return referecedReferableIDs.get(target);
101-
}
102-
103-
public String generateId() {
107+
public String newId() {
104108
return idGenerator.generateId();
105109
}
106110

107-
public String getCachedId(Object obj) {
108-
if (idCache.containsKey(obj)) {
109-
return idCache.get(obj);
111+
public String getId(Reference reference) {
112+
if (reference == null) {
113+
return idGenerator.generateId();
114+
}
115+
Optional<Reference> cacheKey = findMatchingKey(reference);
116+
if (cacheKey.isPresent()) {
117+
return idCache.get(cacheKey.get());
110118
}
111119
String result = idGenerator.generateId();
112-
idCache.put(obj, result);
120+
idCache.put(reference, result);
113121
return result;
114122
}
115123

116-
public boolean isTargetOfInternalLink(Referable target) {
117-
return referecedReferableIDs.containsKey(target) && !referecedReferableIDs.get(target).equals(EMPTY_STRING);
124+
private Optional<Reference> findMatchingKey(Reference reference) {
125+
return idCache.keySet().stream()
126+
.filter(x -> Reference.class.isAssignableFrom(x.getClass()))
127+
.map(x -> (Reference) x)
128+
.filter(x -> AASUtils.equals(x, reference))
129+
.findFirst();
130+
}
131+
132+
// public String getCachedId(Object obj) {
133+
// if (elementsReferencedByViews.containsKey(obj)) {
134+
// return elementsReferencedByViews.get(obj);
135+
// }
136+
// if (idCache.containsKey(obj)) {
137+
// return idCache.get(obj);
138+
// }
139+
// String result = idGenerator.generateId();
140+
// idCache.put(obj, result);
141+
// return result;
142+
// }
143+
public boolean isTargetOfInternalLink(Reference targetRef) {
144+
return referencedReferables.stream().anyMatch(x -> AASUtils.equals(x, targetRef));
118145
}
119146

120147
public <T> void map(T value, AmlGenerator generator) throws MappingException {
@@ -127,36 +154,36 @@ public <T> void map(Type type, T value, AmlGenerator generator) throws MappingEx
127154

128155
public Aas2AmlMappingContext with(PropertyDescriptor property) {
129156
return new Aas2AmlMappingContext(
130-
mappingProvider,
157+
getMappingProvider(),
131158
idGenerator,
132159
internalElementNamingStrategy,
133160
attributeNamingStrategy,
134161
environment,
135-
referecedReferableIDs,
162+
referencedReferables,
136163
idCache,
137164
property);
138165
}
139166

140167
public Aas2AmlMappingContext withoutProperty() {
141168
return new Aas2AmlMappingContext(
142-
mappingProvider,
169+
getMappingProvider(),
143170
idGenerator,
144171
internalElementNamingStrategy,
145172
attributeNamingStrategy,
146173
environment,
147-
referecedReferableIDs,
174+
referencedReferables,
148175
idCache,
149176
null);
150177
}
151178

152179
public Aas2AmlMappingContext withoutIdCache() {
153180
return new Aas2AmlMappingContext(
154-
mappingProvider,
181+
getMappingProvider(),
155182
idGenerator,
156183
internalElementNamingStrategy,
157184
attributeNamingStrategy,
158185
environment,
159-
referecedReferableIDs,
186+
referencedReferables,
160187
null,
161188
property);
162189
}
@@ -168,13 +195,4 @@ public PropertyDescriptor getProperty() {
168195
public AssetAdministrationShellEnvironment getEnvironment() {
169196
return environment;
170197
}
171-
172-
public MappingProvider getMappingProvider() {
173-
return mappingProvider;
174-
}
175-
176-
public Map<Referable, String> getReferecedReferableIDs() {
177-
return referecedReferableIDs;
178-
}
179-
180198
}

0 commit comments

Comments
 (0)