|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.adminshell.aas.v3.dataformat.aml.deserialization.mappers; |
| 17 | + |
| 18 | +import io.adminshell.aas.v3.dataformat.aml.deserialization.AmlParser; |
| 19 | +import io.adminshell.aas.v3.dataformat.aml.deserialization.DefaultMapper; |
| 20 | +import io.adminshell.aas.v3.dataformat.aml.deserialization.MappingContext; |
| 21 | +import io.adminshell.aas.v3.dataformat.aml.model.caex.InternalElementType; |
| 22 | +import io.adminshell.aas.v3.dataformat.core.util.AasUtils; |
| 23 | +import io.adminshell.aas.v3.dataformat.mapping.MappingException; |
| 24 | +import io.adminshell.aas.v3.model.View; |
| 25 | + |
| 26 | +import java.beans.PropertyDescriptor; |
| 27 | +import java.util.List; |
| 28 | + |
| 29 | +/** |
| 30 | + * |
| 31 | + */ |
| 32 | +public class ViewMapper extends DefaultMapper<View> { |
| 33 | + |
| 34 | + private static final String CONTAINED_ELEMENTS = "containedElements"; |
| 35 | + private static final PropertyDescriptor PROPERTY_VALUE_TYPE = AasUtils.getProperty(View.class, "idShort"); |
| 36 | + |
| 37 | + public ViewMapper() { |
| 38 | + super(PROPERTY_VALUE_TYPE.getName()); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + protected void mapProperties(Object parent, AmlParser parser, MappingContext context) throws MappingException { |
| 43 | + if (parent == null || context == null) { |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + if (!InternalElementType.class.isAssignableFrom(parser.getCurrent().getClass())) return; |
| 48 | + InternalElementType internalElementType_View = (InternalElementType) parser.getCurrent(); |
| 49 | + |
| 50 | + ((View) parent).setIdShort(internalElementType_View.getName()); |
| 51 | + |
| 52 | + List<InternalElementType> internalElementTypeList = internalElementType_View.getInternalElement(); |
| 53 | + internalElementTypeList.stream().forEach(x -> { |
| 54 | + String idToReference = x.getRefBaseSystemUnitPath(); |
| 55 | + if (idToReference != null) { |
| 56 | + parser.resolveIdToReferenceLater(parent, AasUtils.getProperty(View.class, CONTAINED_ELEMENTS), idToReference); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + super.mapProperties(parent, parser, context); |
| 61 | + } |
| 62 | +} |
0 commit comments