content: /**
   * Copyright 2020 Alexander Herzog
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package simulator.elements;
  
  import scripting.java.ClientImpl;
  import scripting.java.DynamicFactory;
  import scripting.java.DynamicRunner;
  import scripting.java.InputValueImpl;
  import scripting.java.SystemImpl;
  import scripting.js.JSRunSimulationData;
  import simulator.coreelements.RunElement;
  import simulator.coreelements.RunElementData;
  import simulator.runmodel.SimulationData;
  import ui.modeleditor.elements.ModelElementInputJS;
  
  /**
   * Laufzeitdaten eines <code>RunElementInputJS</code>-Laufzeit-Objekts
   * @author Alexander Herzog
   * @see RunElementInputJS
   * @see RunElementData
   */
  public class RunElementInputJSData extends RunElementData {
  	/**
  	 * Aktuelle Position in der Liste der Eingabewerte
  	 */
  	public int position;
  
  	/**
  	 * Das auszufhrende Skript.
  	 */
  	public final String script;
  
  	/**
  	 * JS-Skript-Ausfhrungsumgebung
  	 */
  	public final JSRunSimulationData jsRunner;
  
  	/**
  	 * Java-Ausfhrungsumgebung
  	 */
  	public final DynamicRunner javaRunner;
  
  	/**
  	 * Konstruktor der Klasse <code>RunElementInputData</code>
  	 * @param station	Zu dem Datenobjekt zugehriges <code>RunElementInputJS</code>-Element
  	 * @param script	Auszufhrendes Skript
  	 * @param mode	Skriptsprache
  	 * @param jRunner	Im Falle von Java als Sprache kann hier optional ein bereits vorbereiteter Runner, der dann kopiert wird, angegeben werden
  	 * @param simData	Simulationsdatenobjekt
  	 */
  	public RunElementInputJSData(final RunElement station, final String script, final ModelElementInputJS.ScriptMode mode, final DynamicRunner jRunner, final SimulationData simData) {
  		super(station,simData);
  		this.script=script;
  
  		position=0;
  
  		switch (mode) {
  		case Java:
  			jsRunner=null;
  			if (jRunner==null) {
  				javaRunner=DynamicFactory.getFactory().load(script,simData.runModel.javaImports);
  			} else {
  				javaRunner=DynamicFactory.getFactory().load(jRunner,simData.runModel.javaImports);
  			}
  			javaRunner.parameter.system=new SystemImpl(simData,station.id);
  			javaRunner.parameter.client=new ClientImpl(simData);
  			javaRunner.parameter.inputValue=new InputValueImpl();
  			break;
  		case Javascript:
  			jsRunner=new JSRunSimulationData(false,false);
  			jsRunner.compile(script);
  			javaRunner=null;
  			break;
  		default:
  			jsRunner=null;
  			javaRunner=null;
  		}
  	}
  }
  