Bug 563666 - [Sonar] Reduced code duplication in RootElementConverters
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.071/src/org/eclipse/app4mc/amalthea/converters071/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.071/src/org/eclipse/app4mc/amalthea/converters071/impl/RootElementConverter.java index fac2009..68e9852 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.071/src/org/eclipse/app4mc/amalthea/converters071/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.071/src/org/eclipse/app4mc/amalthea/converters071/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,11 +22,9 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -34,9 +32,6 @@ /** * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,103 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - logger.info("Migration from 0.7.0 to 0.7.1 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.072/src/org/eclipse/app4mc/amalthea/converters072/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.072/src/org/eclipse/app4mc/amalthea/converters072/impl/RootElementConverter.java index 6f82f12..f936666 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.072/src/org/eclipse/app4mc/amalthea/converters072/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.072/src/org/eclipse/app4mc/amalthea/converters072/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,11 +22,9 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -34,9 +32,6 @@ /** * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,103 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.7.1 to 0.7.2 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.080/src/org/eclipse/app4mc/amalthea/converters080/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.080/src/org/eclipse/app4mc/amalthea/converters080/impl/RootElementConverter.java index e8fdb4c..c7888f9 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.080/src/org/eclipse/app4mc/amalthea/converters080/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.080/src/org/eclipse/app4mc/amalthea/converters080/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,11 +22,9 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -34,9 +32,6 @@ /** * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.7.2 to 0.8.0 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.081/src/org/eclipse/app4mc/amalthea/converters081/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.081/src/org/eclipse/app4mc/amalthea/converters081/impl/RootElementConverter.java index 13fec7d..894916e 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.081/src/org/eclipse/app4mc/amalthea/converters081/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.081/src/org/eclipse/app4mc/amalthea/converters081/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.8.0 to 0.8.1 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.082/src/org/eclipse/app4mc/amalthea/converters082/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.082/src/org/eclipse/app4mc/amalthea/converters082/impl/RootElementConverter.java index 96cb5ef..a823d3e 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.082/src/org/eclipse/app4mc/amalthea/converters082/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.082/src/org/eclipse/app4mc/amalthea/converters082/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.8.1 to 0.8.2 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.083/src/org/eclipse/app4mc/amalthea/converters083/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.083/src/org/eclipse/app4mc/amalthea/converters083/impl/RootElementConverter.java index ca9866d..14401f8 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.083/src/org/eclipse/app4mc/amalthea/converters083/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.083/src/org/eclipse/app4mc/amalthea/converters083/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2015-2021 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author mez2rng - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.8.2 to 0.8.3 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.090/src/org/eclipse/app4mc/amalthea/converters090/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.090/src/org/eclipse/app4mc/amalthea/converters090/impl/RootElementConverter.java index 0423c06..5403de2 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.090/src/org/eclipse/app4mc/amalthea/converters090/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.090/src/org/eclipse/app4mc/amalthea/converters090/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2018-2021 Robert Bosch GmbH and others. + * Copyright (c) 2018-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author Zakir Hussain - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.8.3 to 0.9.0 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.091/src/org/eclipse/app4mc/amalthea/converters091/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.091/src/org/eclipse/app4mc/amalthea/converters091/impl/RootElementConverter.java index 113ed62..b5eb3cf 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.091/src/org/eclipse/app4mc/amalthea/converters091/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.091/src/org/eclipse/app4mc/amalthea/converters091/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2018-2021 Robert Bosch GmbH and others. + * Copyright (c) 2018-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author Zakir Hussain - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,106 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.9.0 to 0.9.1 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = filename2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(filename2documentMap.get(targetFile)); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.092/src/org/eclipse/app4mc/amalthea/converters092/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.092/src/org/eclipse/app4mc/amalthea/converters092/impl/RootElementConverter.java index effdcbc..ade3246 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.092/src/org/eclipse/app4mc/amalthea/converters092/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.092/src/org/eclipse/app4mc/amalthea/converters092/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2018-2021 Robert Bosch GmbH and others. + * Copyright (c) 2018-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,21 +22,16 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author Zakir Hussain - * */ @Component( property = { @@ -45,7 +40,7 @@ "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,25 +54,6 @@ @Override public void convert(File targetFile, Map<File, Document> filename2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.9.1 to 0.9.2 : Executing Root Element Converter for model file : {0}", targetFile.getName()); @@ -86,79 +62,8 @@ if (document == null) { return; } - final Element rootElement = document.getRootElement(); - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } - } - - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } + doConvert(document); } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.093/src/org/eclipse/app4mc/amalthea/converters093/impl/RootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.093/src/org/eclipse/app4mc/amalthea/converters093/impl/RootElementConverter.java index ff7b7a0..a36ab5d 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.093/src/org/eclipse/app4mc/amalthea/converters093/impl/RootElementConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.093/src/org/eclipse/app4mc/amalthea/converters093/impl/RootElementConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2018-2021 Robert Bosch GmbH and others. + * Copyright (c) 2018-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -22,30 +22,25 @@ import org.eclipse.app4mc.amalthea.converters.common.ServiceConstants; import org.eclipse.app4mc.amalthea.converters.common.base.ICache; import org.eclipse.app4mc.amalthea.converters.common.base.IConverter; -import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractConverter; -import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.eclipse.app4mc.amalthea.converters.common.converter.AbstractRootElementConverter; import org.eclipse.app4mc.util.sessionlog.SessionLogger; import org.jdom2.Document; -import org.jdom2.Element; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** - * This class is responsible for converting the root element of the model file as : "Amalthea" (only if for the supplied + * This class is responsible for converting the root element of the model file as : AMALTHEA (only if for the supplied * model root element is other than "Amalthea" e.g: hwModel or swModel) - * - * @author Zakir Hussain - * */ @Component( property = { ServiceConstants.INPUT_MODEL_VERSION_PROPERTY + "=0.9.2", ServiceConstants.OUTPUT_MODEL_VERSION_PROPERTY + "=0.9.3", - "service.ranking:Integer=100" - }, + "service.ranking:Integer=100"}, service = IConverter.class) -public class RootElementConverter extends AbstractConverter { + +public class RootElementConverter extends AbstractRootElementConverter { @Reference SessionLogger logger; @@ -59,105 +54,10 @@ @Override public void convert(File targetFile, Map<File, Document> fileName2documentMap, List<ICache> caches) { - /*- - * ============== - *|| Input Model :|| - * ============== - * <am:MappingModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * </am:MappingModel> - * - * ============== - *|| Output Model :|| - * ============== - * - * <am:Amalthea xmlns:am="http://app4mc.eclipse.org/amalthea/0.7.2" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - * <mappingModel> - * - * </mappingModel> - </am:Amalthea> - */ - - logger.info("Migration from 0.9.2 to 0.9.3 : Executing Root Element Converter for model file : {0}", targetFile.getName()); - final Document document = fileName2documentMap.get(targetFile); - - if (document == null) { - return; - } - final Element rootElement = document.getRootElement(); - - final String rootTagName = rootElement.getName(); - - if (!rootTagName.equals("Amalthea")) { - - if (rootTagName.equals("SWModel") || rootTagName.equals("HWModel") || rootTagName.equals("OSModel") - || rootTagName.equals("StimuliModel") || rootTagName.equals("ConstraintsModel") - || rootTagName.equals("EventModel") || rootTagName.equals("PropertyConstraintsModel") - || rootTagName.equals("MappingModel") || rootTagName.equals("ConfigModel") - || rootTagName.equals("ComponentsModel") || rootTagName.equals("CommonElements")) { - - final Element newRootElement = new Element("Amalthea"); - - HelperUtil.copyAllNameSpaces(rootElement, newRootElement); - - updateCurrentRootTagProps(rootElement); - - document.removeContent(); - - newRootElement.addContent(rootElement); - - document.addContent(newRootElement); - } - } + doConvert(fileName2documentMap.get(targetFile)); } - /** - * This method is used to remove the default namespaces associated to the Root Element and also change the name of - * it -> so that it can be added as a sub-tag inside "Amalthea root element" - * - * @param rootElement - * Element This is the root element of the model file (where Amalthea is not root element) - */ - private void updateCurrentRootTagProps(final Element rootElement) { - - HelperUtil.removeDefaultAttribs(rootElement); - - final String name = rootElement.getName(); - - if (name.equals("SWModel")) { - rootElement.setName("swModel"); - } - else if (name.equals("HWModel")) { - rootElement.setName("hwModel"); - } - else if (name.equals("OSModel")) { - rootElement.setName("osModel"); - } - else if (name.equals("StimuliModel")) { - rootElement.setName("stimuliModel"); - } - else if (name.equals("ConstraintsModel")) { - rootElement.setName("constraintsModel"); - } - else if (name.equals("EventModel")) { - rootElement.setName("eventModel"); - } - else if (name.equals("PropertyConstraintsModel")) { - rootElement.setName("propertyConstraintsModel"); - } - else if (name.equals("MappingModel")) { - rootElement.setName("mappingModel"); - } - else if (name.equals("ConfigModel")) { - rootElement.setName("configModel"); - } - else if (name.equals("ComponentsModel")) { - rootElement.setName("componentsModel"); - } - else if (name.equals("CommonElements")) { - rootElement.setName("commonElements"); - } - } }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractConverter.java index 2b46057..f4b9804 100644 --- a/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractConverter.java +++ b/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractConverter.java
@@ -1,6 +1,6 @@ /** ******************************************************************************** - * Copyright (c) 2019 Robert Bosch GmbH and others. + * Copyright (c) 2019-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -25,6 +25,8 @@ */ public abstract class AbstractConverter implements IConverter { + public static final String AMALTHEA = "Amalthea"; + private String inputModelVersion; private String outputModelVersion; @@ -40,4 +42,5 @@ public String getOutputModelVersion() { return this.outputModelVersion; } + }
diff --git a/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractRootElementConverter.java b/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractRootElementConverter.java new file mode 100644 index 0000000..00d4179 --- /dev/null +++ b/plugins/org.eclipse.app4mc.amalthea.converters.common/src/org/eclipse/app4mc/amalthea/converters/common/converter/AbstractRootElementConverter.java
@@ -0,0 +1,85 @@ +/** + ******************************************************************************** + * Copyright (c) 2018-2022 Robert Bosch GmbH and others. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Robert Bosch GmbH - initial API and implementation + ******************************************************************************** + */ + +package org.eclipse.app4mc.amalthea.converters.common.converter; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.app4mc.amalthea.converters.common.utils.HelperUtil; +import org.jdom2.Document; +import org.jdom2.Element; + +public abstract class AbstractRootElementConverter extends AbstractConverter { + + protected static final Map<String, String> SUB_MODEL_REPLACEMENT_NAMES; + static { + Map<String, String> tmpMap = new HashMap<>(); + tmpMap.put("CommonElements", "commonElements"); + tmpMap.put("ComponentsModel", "componentsModel"); + tmpMap.put("ConfigModel", "configModel"); + tmpMap.put("ConstraintsModel", "constraintsModel"); + tmpMap.put("EventModel", "eventModel"); + tmpMap.put("HWModel", "hwModel"); + tmpMap.put("MappingModel", "mappingModel"); + tmpMap.put("OSModel", "osModel"); + tmpMap.put("PropertyConstraintsModel", "propertyConstraintsModel"); + tmpMap.put("StimuliModel", "stimuliModel"); + tmpMap.put("SWModel", "swModel"); + SUB_MODEL_REPLACEMENT_NAMES = Collections.unmodifiableMap(tmpMap); + } + + /** + * This method is used to remove the default namespaces associated to the Root + * Element and also change the name of it -> so that it can be added as a + * sub-tag inside "Amalthea root element" + * + * @param rootElement Element This is the root element of the model file (where + * Amalthea is not root element) + */ + protected void updateCurrentRootTagProps(final Element rootElement) { + + HelperUtil.removeDefaultAttribs(rootElement); + + final String oldName = rootElement.getName(); + final String newName = SUB_MODEL_REPLACEMENT_NAMES.get(oldName); + + if (newName != null) { + rootElement.setName(newName); + } + } + + protected void doConvert(final Document document) { + if (document == null) return; + + final Element rootElement = document.getRootElement(); + final String rootTagName = rootElement.getName(); + + if (!AMALTHEA.equals(rootTagName) && SUB_MODEL_REPLACEMENT_NAMES.containsKey(rootTagName)) { + + final Element newRootElement = new Element(AMALTHEA); + + HelperUtil.copyAllNameSpaces(rootElement, newRootElement); + updateCurrentRootTagProps(rootElement); + + document.removeContent(); + + newRootElement.addContent(rootElement); + document.addContent(newRootElement); + } + } + +}
diff --git a/tests/org.eclipse.app4mc.amalthea.converters.071.tests/src/org/eclipse/app4mc/amalthea/converters071/tests/RootElementConverterTest.java b/tests/org.eclipse.app4mc.amalthea.converters.071.tests/src/org/eclipse/app4mc/amalthea/converters071/tests/RootElementConverterTest.java index f347cda..d4c9456 100644 --- a/tests/org.eclipse.app4mc.amalthea.converters.071.tests/src/org/eclipse/app4mc/amalthea/converters071/tests/RootElementConverterTest.java +++ b/tests/org.eclipse.app4mc.amalthea.converters.071.tests/src/org/eclipse/app4mc/amalthea/converters071/tests/RootElementConverterTest.java
@@ -1,5 +1,5 @@ /********************************************************************************* - * Copyright (c) 2015-2020 Robert Bosch GmbH and others. + * Copyright (c) 2015-2022 Robert Bosch GmbH and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -15,7 +15,6 @@ package org.eclipse.app4mc.amalthea.converters071.tests; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Arrays;