| /******************************************************************************* |
| * |
| * 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 app4mc.example.transform.m2t.configuration; |
| |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.amalthea.model.AmaltheaFactory; |
| import org.eclipse.app4mc.transformation.ServiceConstants; |
| import org.eclipse.app4mc.transformation.executiontype.IModelToTextConfig; |
| import org.eclipse.emf.ecore.resource.ResourceSet; |
| 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.m2t.loader.AmaltheaMultiFileLoader2; |
| |
| @Component( |
| configurationPid = ServiceConstants.SESSION_CONFIGURATION_PID, |
| configurationPolicy = ConfigurationPolicy.REQUIRE, |
| property = { "transformation=Amalthea2Text" }, |
| service = IModelToTextConfig.class) |
| public class M2TTransformationConfig implements IModelToTextConfig { |
| |
| private static final Logger LOG = LoggerFactory.getLogger(M2TTransformationConfig.class); |
| |
| private AmaltheaMultiFileLoader2 amaltheaMultiFileLoader = new AmaltheaMultiFileLoader2(); |
| |
| private String folderPath; |
| |
| @Activate |
| void activate(Map<String, ?> properties) { |
| folderPath = (String) properties.get("input_models_folder"); |
| } |
| |
| @Override |
| 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; |
| } |
| |
| } |