/* * Dassault Aviation confidential * Copyright (c) 2019 Dassault Aviation. All rights reserved. * * This file is part of the protoframework project. * * NOTICE: All information contained herein is, and remains the property of Dassault Aviation. * The intellectual and technical concepts contained herein are proprietary to Dassault Aviation, * and are protected by trade secret or copyright law. * Unauthorized copying of this file, via any medium, is strictly prohibited. * It can not be copied and/or distributed, in source or binary form, without the express permission of * Dassault Aviation. */ package org.da.testcustom.python; import java.net.URL; import java.util.HashMap; import java.util.Map; import org.da.protoframework.custom.CustomModuleDefinition; import org.da.protoframework.custom.CustomModuleFactory; import org.da.protoframework.model.core.Application; import org.da.protoframework.model.core.Module; import org.da.protoframework.model.def.ApplicationDefinition; /** * The CustomModuleFactory for the Custom Python Module. * * @since 0.6.12 */ public class CustomPythonModuleFactory implements CustomModuleFactory, CustomModuleParameters { private static final Map> MODULE_PARAMS_TYPES = new HashMap<>(); private static final Map> FRAMEWORK_PROPERTIES_TYPES = new HashMap<>(); private URL pythonRuntime = null; static { MODULE_PARAMS_TYPES.put(SENDING_PORT, Integer.class); MODULE_PARAMS_TYPES.put(RECEIVING_PORT, Integer.class); MODULE_PARAMS_TYPES.put(SENDING_SIZE, Integer.class); MODULE_PARAMS_TYPES.put(RECEIVING_SIZE, Integer.class); FRAMEWORK_PROPERTIES_TYPES.put(PYTHON_RUNTIME, URL.class); } /** * Return the framework properties supported by the factory and their associated property types. * * @return the framework properties supported by the factory and their associated property types */ @Override public Map> getFrameworkPropertiesTypes() { return FRAMEWORK_PROPERTIES_TYPES; } /** * Set a framework property value. The value is guaranteed to be consistent with the type defined in {@link #getFrameworkPropertiesTypes()}. * Do nothing by default. * * @param key the framework property key * @param value the framework property value */ @Override public void setFrameworkProperty(String key, Object value) { if (key.equals(PYTHON_RUNTIME)) { pythonRuntime = (URL) value; } } /** * Return a framework property value. The value is guaranteed to be consistent with the type defined in {@link #getFrameworkPropertiesTypes()}. * Return null by default. * * @param key the framework property key * @return the framework property value */ @Override public Object getFrameworkProperty(String key) { if (key.equals(PYTHON_RUNTIME)) { return pythonRuntime; } else { return null; } } @Override public CustomModuleDefinition createModuleDefinition(ApplicationDefinition appli, String name, long id) { CustomPythonModuleDefinition moduleDef = new CustomPythonModuleDefinition(this, appli, name, id); return moduleDef; } /** * Creates a custom module. * * @param appli the application definition * @param name the module name * @return the custom module */ @Override public Module createModule(Application appli, String name) { CustomPythonModule module = new CustomPythonModule(appli, name); return module; } /** * Return the module implementation properties supported by the custom module and their associated property types. * * @return the module implementation properties supported by the custom module and their associated property types */ @Override public Map> getModuleParameterTypes() { return MODULE_PARAMS_TYPES; } @Override public Class getModuleDefinitionClass() { return CustomPythonModuleDefinition.class; } }