| /******************************************************************************* |
| * |
| * Copyright (c) 2018, 2020 Robert Bosch GmbH. |
| * |
| * 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 configuration; |
| |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.model.AmaltheaFactory; |
| import org.eclipse.app4mc.transformation.ServiceConstants; |
| import org.eclipse.app4mc.transformation.executiontype.IModelToModelConfig; |
| import org.eclipse.emf.ecore.resource.Resource; |
| import org.eclipse.emf.ecore.resource.ResourceSet; |
| import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; |
| import org.osgi.service.component.annotations.Activate; |
| import org.osgi.service.component.annotations.Component; |
| import org.osgi.service.component.annotations.ConfigurationPolicy; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import app4mc.example.transform.samplemodel.SampleModelPackage; |
| import model.loader.AmaltheaMultiFileLoader; |
| import model.loader.IMultiFileLoader; |
| |
| @Component( |
| configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID, |
| configurationPolicy = ConfigurationPolicy.REQUIRE, |
| property = { "transformation=Amalthea2SampleModel" }, |
| service = IModelToModelConfig.class) |
| public class M2MTransformationConfig implements IModelToModelConfig { |
| |
| private static final Logger LOG = LoggerFactory.getLogger(M2MTransformationConfig.class); |
| |
| private IMultiFileLoader amaltheaMultiFileLoader = new AmaltheaMultiFileLoader(); |
| |
| private String folderPath; |
| |
| @Activate |
| void activate(Map<String, ?> properties) { |
| folderPath = (String) properties.get("input_models_folder"); |
| } |
| |
| public ResourceSet getInputResourceSet() { |
| |
| if (folderPath != null) { |
| |
| ResourceSet resourceSet = amaltheaMultiFileLoader.loadMultipleFiles(folderPath); |
| |
| if (resourceSet.getResources().isEmpty()) { |
| LOG.error("No Amalthea model files are loaded. Verify if the model version is : {}", |
| AmaltheaFactory.eINSTANCE.createAmalthea().getVersion()); |
| } |
| |
| return resourceSet; |
| } else { |
| LOG.error("Input_models_folder parameter not set", |
| new NullPointerException("input_models_folder property not set")); |
| } |
| |
| return null; |
| } |
| |
| public ResourceSet getOuputResourceSet() { |
| |
| ResourceSet outputRurceSet = new ResourceSetImpl(); |
| |
| outputRurceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() |
| .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); |
| |
| outputRurceSet.getPackageRegistry().put(SampleModelPackage.eNS_URI, SampleModelPackage.eINSTANCE); |
| |
| return outputRurceSet; |
| } |
| |
| } |