Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [henshin-dev] API: how to use findMatches?

Am 18.07.2012 18:59, schrieb Christian Krause:
How can I make use of parameters? As far as I see, parameters are
applied to (in this case) a RuleApplication-object, but findMatches()
works directly on the engine?

Since Match extends Assignment you can use the methods in Assignment to
set parameter values. The methods in RuleApplication are just
convinience methods which delegate to the corresponding methods in
Assignment / Match.

So this means if I just want to find matches and do not want to really apply rules, it is sufficient to work on an AssignmentImpl-Object?


Based on the "Bank"-Example, I tried using an assignment but it does not get my any matches. I attached my sourcecode.

Thanks,

Jens

package org.eclipse.emf.henshin.examples.bank;


import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.henshin.interpreter.EGraph;
import org.eclipse.emf.henshin.interpreter.Engine;
import org.eclipse.emf.henshin.interpreter.Match;
import org.eclipse.emf.henshin.interpreter.RuleApplication;
import org.eclipse.emf.henshin.interpreter.impl.AssignmentImpl;
import org.eclipse.emf.henshin.interpreter.impl.EGraphImpl;
import org.eclipse.emf.henshin.interpreter.impl.EngineImpl;
import org.eclipse.emf.henshin.interpreter.impl.RuleApplicationImpl;
import org.eclipse.emf.henshin.model.Rule;
import org.eclipse.emf.henshin.model.TransformationSystem;
import org.eclipse.emf.henshin.model.resource.HenshinResourceSet;

public class Banktest {

	static EObject root;
	static TransformationSystem system;
	
	
	public static void transform(){
		
		// Prepare the engine:
		Engine engine = new EngineImpl();
		 
		// Initialize the graph:
		EGraph graph = new EGraphImpl();
		graph.addTree(root);
		 
		
		 
		RuleApplication application = new RuleApplicationImpl(engine);
		application.setRule(system.findRuleByName("createAccount"));
		
		// Apply the unit:
		/*
		application.setEGraph(graph);
		
		application.setParameterValue("client", "Alice");
		application.setParameterValue("accountId", "5");
		*/
		// Iterate over all matches and print them on the console:
	
		
		AssignmentImpl assignment=new AssignmentImpl(system.findRuleByName("createAccount"));
		assignment.setParameterValue((assignment.getUnit()).getParameterByName("client"), "Alice");
		assignment.setParameterValue((assignment.getUnit()).getParameterByName("accountId"), "5");
		
		for (Match match : engine.findMatches((Rule) assignment.getUnit(), graph, null)) {
		  System.out.println(match.toString());
		}
		
		//application.execute(null);
		
	/*	UnitApplication application = new UnitApplicationImpl(engine);
		application.setUnit(unit);
		application.setEGraph(graph);
		application.execute(null);*/
		
		
	}

	public static void run(){
	// Create a resource set for the working directory "my/working/directory"
	HenshinResourceSet resourceSet = new HenshinResourceSet("src/org/eclipse/emf/henshin/examples/bank");
	 
	// Load a model:
	root = resourceSet.getObject("example-bank.xmi");
	 
	// Load a transformation system:
	system = resourceSet.getTransformationSystem("bank.henshin");
	 
	transform();
	 
	// Save the result:
	resourceSet.saveObject(root, "example-bank_result.xmi");
	}
	
	public static void main(String[] args) {
		run();
	}
}

Back to the top