/******************************************************************************* | |
* Copyright (c) 2004-2008 Andras Okros, Istvan Rath and Daniel Varro | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* Andras Okros - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.viatra2.gtasm.trigger.natives; | |
import org.eclipse.viatra2.gtasm.trigger.engine.TriggerEngineManager; | |
import org.eclipse.viatra2.gtasm.trigger.engine.TriggerExecutionEngine; | |
import org.eclipse.viatra2.gtasm.trigger.model.Trigger; | |
import org.eclipse.viatra2.core.IModelSpace; | |
import org.eclipse.viatra2.errors.VPMRuntimeException; | |
import org.eclipse.viatra2.natives.ASMNativeFunction; | |
/** | |
* A Viatra native function for starting triggers from VTCL code. | |
* @author Andr�s �kr�s | |
*/ | |
public class StartTriggerFunction implements ASMNativeFunction { | |
public Object evaluate(IModelSpace msp, Object[] params) throws VPMRuntimeException | |
{ | |
String name = (String) params[0]; // The name of the gtrule | |
boolean founded = false; | |
//Trigger output = new Trigger(name); | |
//TriggerExecutionEngine single = TriggerEngineManager.getInstance().getTriggerEngine(msp.getFramework()); | |
//single.initTrigger(output); | |
//return "The " + name + " trigger started."; | |
TriggerExecutionEngine single = TriggerEngineManager.getInstance().getTriggerEngine(msp.getFramework()); | |
for (Trigger trigger : single.getTriggers()) | |
{ | |
if (trigger.getName().equals(name)) { | |
founded = true; | |
single.startTrigger(trigger); | |
} | |
} | |
if (founded) | |
return "startTrigger: the " + name + " trigger started."; | |
else | |
return "startTrigger: the " + name + " trigger cannot be found."; | |
} | |
public String getDescription() | |
{ | |
return "Starts a trigger in the trigger execution engine"; | |
} | |
public String getID() | |
{ | |
return "org.eclipse.viatra2.gtasm.trigger.natives.StartTriggerFunction"; | |
} | |
public String getName() | |
{ | |
return "startTrigger"; // VTCL command name | |
} | |
} |