blob: d288456ce793886fb52c3707ac3075f448f46d3b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008-2010, 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.frameworkgui.views.console.commands.xform;
import java.util.List;
import org.eclipse.viatra2.framework.IFramework;
import org.eclipse.viatra2.frameworkgui.views.console.commands.IVIATRAConsoleCommandProvider;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Machine;
import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Rule;
/**
* VIATRA2 console command to facilitate the execution of a GTASM machine.
* @author istvan rath
*
*/
public class RunRule extends AbstractRunnerCommand implements IVIATRAConsoleCommandProvider {
public void executeCommand(IFramework fw, List<String> parameters) {
// 0. check if we have exactly two parameters
if (parameters.size()!=2) {
fw.getLogger().error("[RunRule] Wrong number of parameters supplied.");
return;
}
// 1. check if machine exists in the framework and is runnable
String ruleFQN = parameters.get(0);
// try to get the machine's FQN
// rule's name is the last segment
if (ruleFQN.indexOf(".")<0) {
fw.getLogger().error("[RunRule] rule FQN does not contain at least one dot (.)");
return;
}
String ruleName = ruleFQN.substring(ruleFQN.lastIndexOf(".")+1);
if (ruleName.length()<1) {
fw.getLogger().error("[RunRule] rule name empty.");
return;
}
String machineFQN = ruleFQN.substring(0, ruleFQN.lastIndexOf("."));
Machine m = (Machine)fw.getMachineByFQN(machineFQN);
if (m==null) {
fw.getLogger().error("[RunRule] machine "+machineFQN+" not found.");
return;
}
Object entrypoint = null;
for (Rule r : m.getAsmRuleDefinitions())
{
if (r.getName().equals(ruleName)) {
entrypoint = r;
break;
}
}
if (entrypoint==null) {
fw.getLogger().error("[RunRule] rule "+ruleName+" not found.");
return;
}
commenceRunning(fw, entrypoint, parameters.get(1), ruleName, false);
}
public String getCommandSignature() {
return "runrule(ruleFQN,parameterMappings)";
}
public String getDescription() {
return "Executes a GTASM Rule in a normal VIATRA2 transaction.";
}
public String getHelpText() {
return "Use runrule(<<rule fqn>>,<<parametermapping>>) to execute a GTASM rule in a normal transaction.\n"+
"Parameter mappings take the following syntax: <<parametername=value>> and are separated by ; characters.\n"+
"Example: runrule(helloworld.sayhello, target=John;message=Hello)";
}
}