Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] typeSelect()
[xtend] typeSelect() [message #759347] Mon, 28 November 2011 13:06 Go to next message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
Hi,

i have a simple transformation in which i only want to do example given typeSelect(uml::Property).

First the workflow file :

<workflow>
<!-- Properties -->


<!-- Initialize CompoSE workflow components -->
<bean class="org.eclipse.xtend.typesystem.uml2.Setup" standardUML2Setup="true"/>


<!-- Parse Model -->
<component id="xmiParser" class="org.eclipse.xtend.typesystem.emf.XmiReader">
<modelFile value="scenarios/indicators/model/test.uml"/>
<outputSlot value="test"/>
</component>

<!-- Run indicator -->
<component class="org.eclipse.xtend.XtendComponent">
<metaModel id='umlMetaModel' class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<metaModel id='indicatorCollectionResult' class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
<metaModelFile value="scenarios/indicators/indicatorOutput/CollectionResult.ecore" />
</metaModel>

<invoke value="scenarios::indicators::stepbystepIndicator::typeSelect::run(test)"/>
<outputSlot value="values"/>
</component>

<!-- Output result -->
<component class="org.eclipse.xtend.typesystem.emf.XmiWriter">
<modelFile value="scenarios/indicators/output/outputModel.xml"/>
<inputSlot value="values"/>
</component>




</workflow>




and here the extend file typeSelect

create result::CollectionResult run(result::CollectionResult in) :

result.addAll(in.result.typeSelect(uml::Property))->

;


Now my question. Is there any possibility to give the type from the workflow to the extend file. Something like

value="scenarios::indicators::stepbystepIndicator::typeSelect::run(test, uml::Property)"/>

create result::CollectionResult run(result::CollectionResult in, Type t)

To give a string its no problem, but i dont know how to do it with a type. Thanks in advance!
Re: [xtend] typeSelect() [message #759441 is a reply to message #759347] Mon, 28 November 2011 17:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

chaning it to create result::CollectionResult run(result::CollectionResult in, xpand2::Type t)

should do the trick

~Christian
Re: [xtend] typeSelect() [message #759446 is a reply to message #759347] Mon, 28 November 2011 17:21 Go to previous messageGo to next message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
I get following error message:

SCHWERWIEGEND: [ERROR]: Property 'invoke' not specified properly. AbstractExtension file 'scenarios::indicators::stepbystepIndicator::typeSelect::run(ownedElements, uml' not found.(Element: -UNKNOWN-; Reported by: -UNKNOWN-)
28.11.2011 18:18:51 org.eclipse.emf.mwe.core.WorkflowRunner prepare
SCHWERWIEGEND: Workflow interrupted because of configuration errors.

Because he thinks uml is a file or something. Any idea? thanks!
Re: [xtend] typeSelect() [message #759475 is a reply to message #759446] Mon, 28 November 2011 19:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
Hi,

indeed, the xtend component does not seem to like this notation, the xpand component does
here a workaround. please file a ticket into bugzilla

package workflow;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.emf.mwe.core.WorkflowContext;
import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory;
import org.eclipse.internal.xtend.util.ProfileCollector;
import org.eclipse.xtend.XtendComponent;
import org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent;
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.expression.ExpressionFacade;
import org.eclipse.xtend.expression.Resource;
import org.eclipse.xtend.expression.Variable;

public class FixedXtendComponent extends AbstractExpressionsUsingWorkflowComponent {

	private static final String COMPONENT_NAME = "Xtend Component";

	private final Log log = LogFactory.getLog(getClass());

	String extensionFile = null;

	private final List<String> extensionAdvices = new ArrayList<String>();

	/** Stores the value of the 'invoke' property. Needed for error analysis. */
	private String invokeExpression;

	private String expression = null;

	private String collectProfileSummary = null;

	private String verboseProfileFilename = null;

	private String outputSlot = WorkflowContext.DEFAULT_SLOT;

	/**
	 * Adds an extension advice.
	 * 
	 * @param extensionAdvice
	 *            the advice
	 */
	@Override
	public void addExtensionAdvice(final String extensionAdvice) {
		if (!extensionAdvices.contains(extensionAdvice)) {
			extensionAdvices.add(extensionAdvice);
		}
	}

	/**
	 * @see org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent#checkConfigurationInternal(org.eclipse.emf.mwe.core.issues.Issues)
	 */
	@Override
	public void checkConfigurationInternal(final Issues issues) {
		super.checkConfigurationInternal(issues);

		// Try to create detailed error message (see Bug#172567)
		final String compPrefix = getId() != null ? getId() + ": " : "";

		if (invokeExpression == null || invokeExpression.trim().length() == 0) {
			issues.addError(compPrefix + "Property 'invoke' not specified.");
			return;
		}
		if (extensionFile == null) {
			issues.addError(compPrefix
					+ "Error parsing property 'invoke': Could not extract name of the extension file.");
			return;
		}

		final InputStream in = getExtFileIS();
		if (in == null || expression == null) {
			issues.addError(compPrefix + "Property 'invoke' not specified properly. AbstractExtension file '"
					+ extensionFile + "' not found.");
			return;
		}

		try {
			in.close();
		}
		catch (final IOException e) {
			log.error("I/O exception", e);
		}

		if (expression == null) {
			issues.addError(compPrefix
					+ "Error parsing property 'invoke': Could not extract the expression to invoke in extension file '"
					+ extensionFile + "'.");
			return;
		}

	}

	/**
	 * @see org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent#getLogMessage()
	 */
	@Override
	public String getLogMessage() {
		return "executing '" + extensionFile + "'";
	}

	/**
	 * @see org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflowComponent#invokeInternal2(org.eclipse.emf.mwe.core.WorkflowContext,
	 *      org.eclipse.emf.mwe.core.monitor.ProgressMonitor,
	 *      org.eclipse.emf.mwe.core.issues.Issues)
	 */
	@Override
	public void invokeInternal2(final WorkflowContext ctx, final ProgressMonitor monitor, final Issues issues) {

		final InputStream in = getExtFileIS();
		if (in == null) {
			issues.addError("Cannot find extension file: " + extensionFile);
			return;
		}
		else {
			try {
				in.close();
			}
			catch (final IOException e) {
				log.error("I/O exception", e);
			}
		}

		OutputStream verboseProfileOutputStream = null;

		if (verboseProfileFilename != null) {
			try {
				verboseProfileOutputStream = new BufferedOutputStream(new FileOutputStream(verboseProfileFilename));
				ProfileCollector.getInstance().setDetailedLoggingWriter(verboseProfileOutputStream);
			}
			catch (final IOException exc) {
				log.warn("could not open profiling log file", exc);
			}
		}

		ExecutionContextImpl ec = getExecutionContext(ctx);

		for (final String advice : extensionAdvices) {
			final String[] allAdvices = advice.split(",");
			for (final String string : allAdvices) {
				ec.registerExtensionAdvices(string.trim());
			}
		}

		ec = (ExecutionContextImpl) ec.cloneWithResource(new Resource() {
			private String name = "noName";

			public String getFullyQualifiedName() {
				return name;
			}

			public String[] getImportedExtensions() {
				return new String[] { extensionFile };
			}

			public String[] getImportedNamespaces() {
				return new String[0];
			}

			public void setFullyQualifiedName(final String fqn) {
				name = fqn;
			}
		});
		final String[] slots = ctx.getSlotNames();
		for (final String slot : slots) {
			ec = (ExecutionContextImpl) ec.cloneWithVariable(new Variable(slot, ctx.get(slot)));
		}

		if (monitor != null) {
			ec.setMonitor(monitor);
		}

		final Object result = new ExpressionFacade(ec).evaluate(expression);
		ctx.set(outputSlot, result);

		ProfileCollector.getInstance().finish();
		if ("true".equalsIgnoreCase(this.collectProfileSummary)) {
			log.info("profiling info: \n" + ProfileCollector.getInstance().toString());
		}

		if (verboseProfileOutputStream != null) {
			try {
				verboseProfileOutputStream.close();
			}
			catch (final IOException exc) {
				log.warn("problem closing profile log file", exc);
			}
		}
	}

	/**
	 * Sets the collect profile summary.
	 * 
	 * @param summary
	 *            the summary
	 */
	public void setCollectProfileSummary(final String summary) {
		collectProfileSummary = summary;
	}

	/**
	 * Sets the invoke expression.
	 * 
	 * @param invokeExpr
	 *            the invoke expression
	 */
	public void setInvoke(final String invokeExpr) {
		invokeExpression = invokeExpr;
		final int i = invokeExpr.substring(0, invokeExpr.indexOf('(')).lastIndexOf("::");
		if (i != -1) {
			extensionFile = invokeExpr.substring(0, i);
			expression = invokeExpr.substring(i + 2);
		}
		else {
			expression = invokeExpr;
		}
	}

	/**
	 * Sets the output slot.
	 * 
	 * @param outputSlot
	 *            the output slot
	 */
	public void setOutputSlot(final String outputSlot) {
		this.outputSlot = outputSlot;
	}

	/**
	 * Sets the filename for the verbose profile.
	 * 
	 * @param fileName
	 *            the filename
	 */
	public void setVerboseProfileFilename(final String fileName) {
		verboseProfileFilename = fileName;
	}

	@Override
	public String getComponentName() {
		return COMPONENT_NAME;
	}

	private InputStream getExtFileIS() {
		final InputStream in = ResourceLoaderFactory.createResourceLoader().getResourceAsStream(
				extensionFile.replace("::", "/") + ".ext");
		return in;
	}

}



~Christian
Re: [xtend] typeSelect() [message #759478 is a reply to message #759475] Mon, 28 November 2011 19:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
P.S: this wont work anyway since the parser will only accect literals for the typeselect expression, so you would have to workaroud for this too. but this should not be the problem
Re: [xtend] typeSelect() [message #759480 is a reply to message #759478] Mon, 28 November 2011 19:25 Go to previous messageGo to next message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
so what is the best thing to do? rewrite the type select in java? i'm not well experienced Sad
Re: [xtend] typeSelect() [message #759481 is a reply to message #759480] Mon, 28 November 2011 19:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
either this or use something else (e.g. aop) to "configure" the workflow
Re: [xtend] typeSelect() [message #759483 is a reply to message #759481] Mon, 28 November 2011 19:32 Go to previous messageGo to next message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
is there a way to see how the type select is implemented?
Re: [xtend] typeSelect() [message #759486 is a reply to message #759478] Mon, 28 November 2011 19:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6388
Registered: July 2009
Senior Member
org.eclipse.internal.xtend.expression.ast.TypeSelectExpression
Re: [xtend] typeSelect() [message #759499 is a reply to message #759486] Mon, 28 November 2011 19:54 Go to previous messageGo to next message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
Sorry but where can i see this package? under my plugins it isn't included?
Re: [xtend] typeSelect() [message #759501 is a reply to message #759499] Mon, 28 November 2011 20:02 Go to previous message
majestic  is currently offline majestic
Messages: 11
Registered: September 2011
Junior Member
Got it. Thanks!
Previous Topic:[JET] Unable to retrieve stereotype list of a UML element in an XPath function
Next Topic:plug-in and IDE error, my acceleo UI launcher is not invoking all modules
Goto Forum:
  


Current Time: Sat Oct 25 08:02:26 GMT 2014

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

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