| package org.eclipse.basyx.submodel.factory.xml.converters.submodelelement.dataelement; |
| |
| import java.util.Map; |
| |
| import org.eclipse.basyx.submodel.factory.xml.converters.qualifier.LangStringsXMLConverter; |
| import org.eclipse.basyx.submodel.factory.xml.converters.reference.ReferenceXMLConverter; |
| import org.eclipse.basyx.submodel.factory.xml.converters.submodelelement.SubmodelElementXMLConverter; |
| import org.eclipse.basyx.submodel.metamodel.api.reference.IReference; |
| import org.eclipse.basyx.submodel.metamodel.api.submodelelement.dataelement.IMultiLanguageProperty; |
| import org.eclipse.basyx.submodel.metamodel.map.qualifier.LangStrings; |
| import org.eclipse.basyx.submodel.metamodel.map.reference.Reference; |
| import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.MultiLanguageProperty; |
| import org.w3c.dom.Document; |
| import org.w3c.dom.Element; |
| |
| /** |
| * Parses <aas:multiLanguageProperty> and builds the MultiLanguageProperty object from it <br> |
| * Builds <aas:multiLanguageProperty> form a given MultiLanguageProperty object |
| * |
| * @author conradi |
| * |
| */ |
| public class MultiLanguagePropertyXMLConverter extends SubmodelElementXMLConverter { |
| |
| public static final String MULTI_LANGUAGE_PROPERTY = "aas:multiLanguageProperty"; |
| public static final String VALUE_ID = "aas:valueId"; |
| |
| /** |
| * Parses a Map containing the content of XML tag <aas:multiLanguageProperty> |
| * |
| * @param xmlObject the Map with the content of XML tag <aas:multiLanguageProperty> |
| * @return the parsed MultiLanguageProperty |
| */ |
| @SuppressWarnings("unchecked") |
| public static MultiLanguageProperty parseMultiLanguageProperty(Map<String, Object> xmlObject) { |
| Map<String, Object> xmlValueId = (Map<String, Object>) xmlObject.get(VALUE_ID); |
| Reference valueId = ReferenceXMLConverter.parseReference(xmlValueId); |
| Map<String, Object> xmlLangStrings = (Map<String, Object>) xmlObject.get(VALUE); |
| LangStrings langStrings = LangStringsXMLConverter.parseLangStrings(xmlLangStrings); |
| MultiLanguageProperty mLProperty = new MultiLanguageProperty(valueId, langStrings); |
| populateSubmodelElement(xmlObject, mLProperty); |
| return mLProperty; |
| } |
| |
| |
| |
| /** |
| * Builds the <aas:multiLanguageProperty> XML tag for a MultiLanguageProperty |
| * |
| * @param document the XML document |
| * @param mLProperty the IMultiLanguageProperty to build the XML for |
| * @return the <aas:multiLanguageProperty> XML tag for the given MultiLanguageProperty |
| */ |
| public static Element buildMultiLanguageProperty(Document document, IMultiLanguageProperty mLProperty) { |
| Element mLPropertyRoot = document.createElement(MULTI_LANGUAGE_PROPERTY); |
| populateSubmodelElement(document, mLPropertyRoot, mLProperty); |
| |
| IReference valueId = mLProperty.getValueId(); |
| if(valueId != null) { |
| Element valueIdRoot = document.createElement(VALUE_ID); |
| valueIdRoot.appendChild(ReferenceXMLConverter.buildReferenceXML(document, valueId)); |
| mLPropertyRoot.appendChild(valueIdRoot); |
| } |
| |
| Element valueRoot = document.createElement(VALUE); |
| LangStringsXMLConverter.buildLangStringsXML(document, valueRoot, mLProperty.getValue()); |
| mLPropertyRoot.appendChild(valueRoot); |
| |
| return mLPropertyRoot; |
| } |
| } |