| /** |
| ******************************************************************************** |
| * Copyright (c) 2018 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 org.eclipse.app4mc.amalthea.model.AmaltheaFactory; |
| import org.eclipse.app4mc.transformation.extensions.ICustomObjectsStore; |
| import org.eclipse.app4mc.transformation.extensions.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.Component; |
| import org.osgi.service.component.annotations.Reference; |
| import org.slf4j.Logger; |
| |
| import SampleModel.SampleModelPackage; |
| import model.loader.IMultiFileLoader; |
| |
| @Component( |
| property= { |
| // CommandProcessor.COMMAND_SCOPE + ":String=app4mc", |
| "transformation=Amalthea2SampleModel" |
| }, |
| service=IModelToModelConfig.class |
| ) |
| public class M2MTransformationConfig implements IModelToModelConfig { |
| |
| @Reference |
| private ICustomObjectsStore iCustomObjectsStore; |
| |
| @Reference |
| private IMultiFileLoader amaltheaMultiFileLoader; |
| |
| public ResourceSet getInputResourceSet() { |
| |
| Logger logger = iCustomObjectsStore.getInstance(Logger.class); |
| |
| String folderPath = iCustomObjectsStore.getData("input_models_folder"); |
| |
| if (folderPath != null) { |
| |
| ResourceSet resourceSet = amaltheaMultiFileLoader.loadMultipleFiles(folderPath); |
| |
| if(resourceSet.getResources().size()==0) { |
| logger.error("no Amalthea model files are loaded. Verify if the model version is : " + AmaltheaFactory.eINSTANCE.createAmalthea().getVersion()); |
| } |
| |
| return resourceSet; |
| } else { |
| logger.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; |
| } |
| |
| |
| } |