Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Henshin] Invoke Henshin programmatically
[Henshin] Invoke Henshin programmatically [message #762577] Thu, 08 December 2011 10:33
st oehm is currently offline st oehmFriend
Messages: 79
Registered: October 2009
Member
Greetings,

I am currently working with Henshin on in-place UML transformations. I have adapted the example presented in this paper (pull up attributes from classes in a common superclass) for UML. Manual execution works just fine.

Now, I want to apply the transformation programmatically. I have looked up the 'metamodelevolution' and the 'sierpinski' examples from the Henshin source code to see how this works.
Unfortunately, the transformation is not executed (its boolean value is false). Could anybody tell me what's wrong? You can find my code below.

In the instance model, I have a class 'superclass' and two subclasses with the property 'property1', which should be pulled up into the superclass. The transformation expects two parameters, 'superclassname' and 'propertyname'.

I could also provide the model files if needed.

Best regards,
stoehm



public class InvokeHenshin {
	
	private static final String BASE = "src/model/";
	// Path to meta-model, instance model and rule files
	private static final String UML_MODEL_INSTANCE = BASE + "test.uml";
	private static final String UML_MODEL_META = BASE + "UML.ecore";
	private static final String HENSHIN = BASE + "uml-refactor.henshin";
	
	ResourceSet resourceSet = new ResourceSetImpl();
	
	public void start() {
		initializeResourceFactories();
		
		// Load the UML meta-model
		EPackage umlMeta = loadUMLMeta();
		
		TransformationSystem ts = loadUMLTrafoSystem();
		ts.getImports().add(umlMeta); 
		
		// Load the instance model to be changed
		EObject umlInst = loadUMLModel();
		
		// Instantiate Henshin interpreter objects
		EmfGraph graph = new EmfGraph();
		graph.addRoot(umlInst); 
		EmfEngine engine = new EmfEngine(graph);
		
		Rule rule = ts.findRuleByName("pullUpPropertyNew");
		
		UnitApplication unitApp = new UnitApplication(engine, rule);
		
		// set parameters of the transformation
		unitApp.setParameterValue("superclassname", "superclass");
		unitApp.setParameterValue("propertyname", "property1");
		
		boolean result = unitApp.execute();
		if(result == true) 
			System.out.println("Transformation successfully applied...");
		else
			System.out.println("Transformation failed >:-(");
		
	} // start
	
	/*
	 * Assigns to each needed file extension a resource factory
	 */
	private void initializeResourceFactories() {
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				"ecore", new EcoreResourceFactoryImpl());
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				"henshin", new HenshinResourceFactory());	
	} // initializeResourceFactories
	
	/*
	 * Loads the UML meta-model
	 */
	private EPackage loadUMLMeta() {
		URI modelUri = URI.createFileURI(new File(UML_MODEL_META).getAbsolutePath());
		Resource resourceModel = resourceSet.getResource(modelUri, true);
		return (EPackage) resourceModel.getContents().get(0);
	} // loadUMLMeta
	
	/*
	 * Loads the UML model instance
	 */
	private EObject loadUMLModel() {
		URI modelUri = URI.createFileURI(new File(UML_MODEL_INSTANCE).getAbsolutePath());
		Resource resourceModel = resourceSet.getResource(modelUri, true);
		return (EObject) resourceModel.getContents().get(0);
	} // load UMLModel
	
	private TransformationSystem loadUMLTrafoSystem() {
		HenshinPackageImpl.init();
		return (TransformationSystem) ModelHelper.loadFile(HENSHIN);
	} // loadUMLTrafoSystem
	
	public static void main(String[] args) {
		InvokeHenshin test = new InvokeHenshin();
		
		test.start();
	} // main

}

Previous Topic:[EMF Facet]
Next Topic:[TEXO] Unique constraints
Goto Forum:
  


Current Time: Fri Apr 19 11:55:59 GMT 2024

Powered by FUDForum. Page generated in 0.01763 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top