| /******************************************************************************* |
| * Copyright (c) 2004-2008 Peter Pasztor, Akos Horvath, Gergely Varro, 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: |
| * Peter Pasztor, Akos Horvath, Gergely Varro, Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.gtasm.interpreter.impl.interpreter; |
| |
| import java.util.Map; |
| import java.util.Vector; |
| |
| import org.eclipse.viatra2.errors.VPMRuntimeControlledException; |
| import org.eclipse.viatra2.errors.VPMRuntimeException; |
| import org.eclipse.viatra2.framework.IFramework; |
| import org.eclipse.viatra2.gtasm.interpreter.exception.ASMInterpreterErrorStrings; |
| import org.eclipse.viatra2.gtasm.interpreter.impl.machine.MachineInterpreter; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Machine; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Rule; |
| import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.SymbolicRuleParameter; |
| import org.eclipse.viatra2.interpreters.IProgressReport; |
| import org.eclipse.viatra2.interpreters.ModelInterpreter; |
| |
| |
| /** |
| * VIATRA2 GTASM model interpreter, based on the EMF-based GTASM metamodel |
| * representation (as encoded in the org.eclipse.viatra2.gtasm.model component). |
| * |
| * Able to interpret machines and rules. |
| * @author Istvan Rath |
| * |
| */ |
| public class EMFInterpreter implements ModelInterpreter { |
| |
| public String[] getParameters(IFramework fw, Object machineOrRule) |
| throws VPMRuntimeException { |
| Vector<String> ret = new Vector<String>(); |
| if (machineOrRule instanceof Machine) { |
| Machine m = (Machine) machineOrRule; |
| if(m.getMainRule() == null) |
| throw new VPMRuntimeControlledException(ASMInterpreterErrorStrings.MACHINE_WITHOUT_MAIN_RULE + m.getFqn()); |
| |
| for (Object p : m.getMainRule().getSymParameters()) { |
| SymbolicRuleParameter par = (SymbolicRuleParameter) p; |
| ret.add(par.getVariable().getName()); |
| } |
| } |
| else if (machineOrRule instanceof Rule) { |
| Rule r = (Rule) machineOrRule; |
| for (Object p : r.getSymParameters()) { |
| SymbolicRuleParameter par = (SymbolicRuleParameter) p; |
| ret.add(par.getVariable().getName()); |
| } |
| } |
| return ret.toArray(new String[] {}); |
| } |
| |
| public boolean isRunnable(Object machineOrRule, IFramework fw) { |
| return (machineOrRule instanceof Machine) || (machineOrRule instanceof Rule); |
| } |
| |
| public void run(IFramework fw, Object machineOrRule, Map<String, Object> parameters, IProgressReport pr) throws VPMRuntimeException |
| { |
| Machine m = null; |
| Rule ep = null; |
| |
| if (machineOrRule instanceof Machine) { |
| m = (Machine) machineOrRule; |
| ep = m.getMainRule(); |
| if (ep ==null) { |
| throw new VPMRuntimeControlledException(ASMInterpreterErrorStrings.MACHINE_WITHOUT_MAIN_RULE + m.getFqn()); |
| } |
| } |
| else if (machineOrRule instanceof Rule) { |
| ep = (Rule) machineOrRule; |
| m = ep.getNamespace(); |
| } |
| MachineInterpreter mi = new MachineInterpreter(fw, m); |
| mi.operate(parameters, pr, ep); |
| } |
| |
| } |