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

Commit 74b9a5d

Browse files
authored
Merge pull request #20 from JensMueller2709/refactoring/aml-deserializer
Refactoring/aml deserializer
2 parents b529d2a + 5647c0e commit 74b9a5d

22 files changed

+173
-136
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.adminshell.aas.v3.dataformat.aml.common;
1717

18-
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.NamingStrategy;
18+
import io.adminshell.aas.v3.dataformat.aml.common.naming.NamingStrategy;
1919
import io.adminshell.aas.v3.dataformat.mapping.Mapper;
2020
import io.adminshell.aas.v3.dataformat.mapping.MappingContext;
2121
import io.adminshell.aas.v3.dataformat.mapping.MappingProvider;

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/AbstractClassNamingStrategy.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/common/naming/AbstractClassNamingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.adminshell.aas.v3.dataformat.aml.serialization.naming;
16+
package io.adminshell.aas.v3.dataformat.aml.common.naming;
1717

1818
import com.google.common.reflect.TypeToken;
1919
import io.adminshell.aas.v3.dataformat.core.util.MostSpecificTypeTokenComparator;

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/IdClassNamingStrategy.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/common/naming/IdClassNamingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.adminshell.aas.v3.dataformat.aml.serialization.naming;
16+
package io.adminshell.aas.v3.dataformat.aml.common.naming;
1717

1818
import java.util.UUID;
1919

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/NamingStrategy.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/common/naming/NamingStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.adminshell.aas.v3.dataformat.aml.serialization.naming;
16+
package io.adminshell.aas.v3.dataformat.aml.common.naming;
1717

1818
import java.lang.reflect.Type;
1919

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/NumberingClassNamingStrategy.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/common/naming/NumberingClassNamingStrategy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.adminshell.aas.v3.dataformat.aml.serialization.naming;
16+
package io.adminshell.aas.v3.dataformat.aml.common.naming;
1717

1818
import io.adminshell.aas.v3.dataformat.core.ReflectionHelper;
1919
import java.util.HashMap;
@@ -43,5 +43,4 @@ protected String generateName(Object obj) {
4343
counter.put(type, counter.get(type) + 1);
4444
return type.getSimpleName() + "_" + counter.get(type);
4545
}
46-
4746
}

dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/serialization/naming/PropertyNamingStrategy.java renamed to dataformat-aml/src/main/java/io/adminshell/aas/v3/dataformat/aml/common/naming/PropertyNamingStrategy.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package io.adminshell.aas.v3.dataformat.aml.serialization.naming;
16+
package io.adminshell.aas.v3.dataformat.aml.common.naming;
1717

1818
import com.google.common.reflect.TypeToken;
1919
import io.adminshell.aas.v3.dataformat.core.util.MostSpecificTypeTokenComparator;
20-
import io.adminshell.aas.v3.model.Qualifier;
20+
2121
import java.lang.reflect.Type;
2222
import java.util.ArrayList;
2323
import java.util.List;
@@ -32,14 +32,25 @@ public class PropertyNamingStrategy implements NamingStrategy {
3232

3333
protected class TypeSafeFunction<T> {
3434

35+
public TypeSafeFunction(Class<T> inputType, BiFunction<T, String, String> nameProvider, BiFunction<T, String, String> refSemanticProvider, String oldName, String newName) {
36+
this.inputType = TypeToken.of(inputType);
37+
this.nameProvider = nameProvider;
38+
this.refSemanticProvider = refSemanticProvider;
39+
this.oldName = oldName;
40+
this.newName = newName;
41+
}
42+
3543
public TypeSafeFunction(Class<T> inputType, BiFunction<T, String, String> nameProvider, BiFunction<T, String, String> refSemanticProvider) {
3644
this.inputType = TypeToken.of(inputType);
3745
this.nameProvider = nameProvider;
3846
this.refSemanticProvider = refSemanticProvider;
3947
}
48+
4049
TypeToken inputType;
4150
BiFunction<T, String, String> nameProvider;
4251
BiFunction<T, String, String> refSemanticProvider;
52+
String oldName;
53+
String newName;
4354
}
4455

4556
public <T> void registerCustomNaming(Class<T> type,
@@ -58,7 +69,8 @@ public void registerCustomNaming(Class<?> type,
5869
String newName) {
5970
customNamings.add(new TypeSafeFunction(type,
6071
(obj, property) -> Objects.equals(oldName, property) ? newName : null,
61-
(obj, property) -> Objects.equals(oldName, property) ? newName : null));
72+
(obj, property) -> Objects.equals(oldName, property) ? newName : null,
73+
oldName, newName));
6274
}
6375

6476
public void registerCustomNaming(Class<?> type,
@@ -67,7 +79,8 @@ public void registerCustomNaming(Class<?> type,
6779
String newRefSemantic) {
6880
customNamings.add(new TypeSafeFunction(type,
6981
(obj, property) -> Objects.equals(oldName, property) ? newName : null,
70-
(obj, property) -> Objects.equals(oldName, property) ? newRefSemantic : null));
82+
(obj, property) -> Objects.equals(oldName, property) ? newRefSemantic : null,
83+
oldName,newName));
7184
}
7285

7386
public <T> void registerCustomNaming(Class<T> type,
@@ -92,6 +105,15 @@ private List<TypeSafeFunction> getCustomNaming(Type type, String property) {
92105
.collect(Collectors.toList());
93106
}
94107

108+
public String getOldName(Type type, Object obj, String property){
109+
TypeSafeFunction typeSafeFunction = customNamings.stream()
110+
.filter(x -> x.inputType.isSupertypeOf(type) && x.newName.equalsIgnoreCase(property))
111+
.findFirst()
112+
.orElse(null);
113+
if(typeSafeFunction==null)return null;
114+
return typeSafeFunction.oldName;
115+
}
116+
95117
@Override
96118
public String getName(Type type, Object obj, String property) {
97119
for (TypeSafeFunction customNaming : getCustomNaming(type, property)) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import io.adminshell.aas.v3.dataformat.aml.AmlDeserializationConfig;
2020
import io.adminshell.aas.v3.dataformat.aml.AmlDocumentInfo;
2121
import io.adminshell.aas.v3.dataformat.aml.model.caex.CAEXFile;
22-
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.AbstractClassNamingStrategy;
23-
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.NumberingClassNamingStrategy;
24-
import io.adminshell.aas.v3.dataformat.aml.serialization.naming.PropertyNamingStrategy;
22+
import io.adminshell.aas.v3.dataformat.aml.common.naming.AbstractClassNamingStrategy;
23+
import io.adminshell.aas.v3.dataformat.aml.common.naming.NumberingClassNamingStrategy;
24+
import io.adminshell.aas.v3.dataformat.aml.common.naming.PropertyNamingStrategy;
2525
import io.adminshell.aas.v3.dataformat.mapping.MappingException;
2626
import io.adminshell.aas.v3.dataformat.mapping.MappingProvider;
2727
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
@@ -82,12 +82,11 @@ public AssetAdministrationShellEnvironment map(CAEXFile aml) throws MappingExcep
8282
PropertyNamingStrategy propertyNamingStrategy = new PropertyNamingStrategy();
8383
propertyNamingStrategy.registerCustomNaming(Referable.class, "descriptions", "description");
8484
propertyNamingStrategy.registerCustomNaming(MultiLanguageProperty.class, "values", "value");
85-
//propertyNamingStrategy.registerCustomNaming(Qualifier.class, x -> "qualifier:" + x.getType() + "=" + x.getValue(), false);
8685
propertyNamingStrategy.registerCustomNaming(Qualifiable.class, "qualifiers", "qualifier","qualifier");
8786
MappingContext context = new MappingContext(mappingProvider, classNamingStrategy, propertyNamingStrategy, config.getTypeFactory());
8887
context.setDocumentInfo(AmlDocumentInfo.fromFile(aml));
8988
AssetAdministrationShellEnvironment result = context.map(AssetAdministrationShellEnvironment.class, parser);
9089
parser.resolveIdsToReferences(result);
91-
return (AssetAdministrationShellEnvironment) result;
90+
return result;
9291
}
9392
}

0 commit comments

Comments
 (0)