MWE2

Aus SDQ-Wiki

The Modeling Workflow Engine 2 (MWE2) is the newly developed workflow engine used by the Xtext framework.

Examples

Experiences, Tips & Tricks

Solving org.eclipse.xtext.linking.lazy.LazyLinkingResource errors

The Caused by: java.lang.ArrayStoreException: org.eclipse.xtext.linking.lazy.LazyLinkingResource exception usually occurs when trying to persist a Xtext textual model to XMI using a MWE2 workflow. It is caused by an incompatibility between LazyLinkingResource and EList. Solution: Create a MWE2 workflow component that resolves the LazyLinkingResource

package edu.kit.ipd.sdq.mdsd.util.workflow;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent;
import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext;
import  org.eclipse.xtext.linking.lazy.LazyLinkingResource;

/**
 * Resolves lazy linking resources by replacing it with it content.
 * loads all resources not already being loaded.
 * 
 * @author Joerg Henss
 * 
 */
public class ResolveLazyComponent implements IWorkflowComponent {

	@Override
	public void invoke(IWorkflowContext ctx) {
		Set<String> names = ctx.getSlotNames();
		for (String slotName : names) {

			Object slotContent = ctx.get(slotName);
			if (slotContent instanceof Iterable) {
				Iterator<?> iter = ((Iterable<?>) slotContent).iterator();
				while (iter.hasNext()) {
					Object o = iter.next();
					if (o instanceof Resource) {
						Resource r = ((Resource) o);
						if(!r.isLoaded())
							try {
								r.load(null);
							} catch (IOException e) {
								throw new RuntimeException("Error loading slot "+ slotName, e);
							} 

						if(r instanceof LazyLinkingResource)
							ctx.put(slotName, r.getContents());
					}
				}
			}

		}

	}

	@Override
	public void postInvoke() {
		// TODO Auto-generated method stub

	}

	@Override
	public void preInvoke() {
		// TODO Auto-generated method stub

	}

}