|
Re: Xpand and GMF [message #1738889 is a reply to message #1738803] |
Mon, 25 July 2016 17:32 |
Wendy Wendy Messages: 21 Registered: July 2016 |
Junior Member |
|
|
My action class (src/ont.diagram.handlers/GenerateTurtleAction.java):
package ont.diagram.handlers;
import java.net.URI;
import java.net.URL;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.mwe.core.WorkflowRunner;
import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.typesystem.emf.EmfMetaModel;
import org.osgi.framework.Bundle;
import ont.OntPackage;
public class GenerateTurtleAction implements IObjectActionDelegate {
private Shell shell;
private IWorkbenchPart targetPart;
private IFile file;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
shell = targetPart.getSite().getShell();
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(false);
if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
return;
}
file = (IFile) ((IStructuredSelection) selection).getFirstElement();
action.setEnabled(true);
}
public void run(IAction action) {
try {
EObject source = getInput();
if (source == null) {
String title = "title";
String message = "message";
MessageDialog.openInformation(getShell(), title, NLS.bind(message, file.getFullPath()));
} else {
Bundle bundle = Platform.getBundle("ontology.diagram");
URL url = FileLocator.find(bundle, new Path("src/templates/Generator.mwe"), null);
url = FileLocator.toFileURL(url);
// URL url = FileLocator.toFileURL(new URL("platform:/resource/ontology.diagram/src/templates/Generator.mwe"));
Map<String, String> properties = new HashMap<String, String>();
properties.put("model", URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
properties.put("out", Platform.getLocation().toOSString() + file.getParent().getFullPath());
WorkflowRunner runner = new WorkflowRunner();
runner.run(url.getPath(), new NullProgressMonitor(), properties, null);
file.getParent().refreshLocal(IResource.DEPTH_ONE, new org.eclipse.core.runtime.NullProgressMonitor());
MessageDialog.openInformation(
shell,
"Generate Turtle",
"Successful!");
}
} catch (Exception ex) {
handleError(ex);
}
}
private EObject getInput() {
ResourceSetImpl rs = new ResourceSetImpl();
return rs.getEObject(URI.createPlatformResourceURI(file.getFullPath().toString(), true).appendFragment("/"), true);
}
private void handleError(Throwable ex) {
MessageDialog.openError(getShell(), "Transformation failed", MessageFormat.format("{0}: {1}", ex.getClass().getSimpleName(), ex.getMessage() == null ? "no message" : ex.getMessage()));
}
private Shell getShell() {
return targetPart.getSite().getShell();
}
}
My Xpand template (src/templates/TurtleTemplate.xpt):
«IMPORT http:///ont.ecore»
«DEFINE main FOR Ontology-»
«FILE ontologyDescription.ontLabel + ".txt"-»
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix base <«ontologyDescription.ontURI»#> .
#################################################################
#
# Classes
#
#################################################################
«EXPAND rdfclass FOREACH rDFClasses-»
#################################################################
#
# Properties
#
#################################################################
«EXPAND rdfproperty FOREACH rDFProperties-»
«ENDFILE»
«ENDDEFINE»
«DEFINE rdfclass FOR RDFSClass-»
«classLabel» rdf:type rdfs:Class «EXPAND subclass FOREACH subClassOf-».
«ENDDEFINE-»
«DEFINE subclass FOR RDFSClass-»
;
rdfs:subClassOf «classLabel-»
«ENDDEFINE-»
«DEFINE rdfproperty FOR RDFSProperty-»
«propertyLabel» rdf:type rdf:Property «EXPAND subproperty FOREACH subPropertyOf-» «EXPAND dom FOREACH domain-» «EXPAND ran FOREACH range-».
«ENDDEFINE-»
«DEFINE subproperty FOR RDFSProperty-»
;
rdfs:subPropertyOf «propertyLabel-»
«ENDDEFINE-»
«DEFINE dom FOR RDFSClass-»
;
rdfs:domain «classLabel-»
«ENDDEFINE-»
«DEFINE ran FOR RDFSClass-»
;
rdfs:range «classLabel-»
«ENDDEFINE-»
My workflow (Generator.mwe):
<?xml version="1.0"?>
<workflow>
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup">
<platformUri value="../" />
<RegisterEcoreFile value="http:///ont.ecore"/>
</bean>
<component class="org.eclipse.emf.mwe.utils.Reader">
<uri value="${model}" />
<modelSlot value="model" />
<firstElementOnly value="false" />
</component>
<component class="org.eclipse.xpand2.Generator">
<metaModel id="mm" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<expand value="templates::TurtleTemplate::main FOR model" />
<outlet path="${}">
<postprocessor class="org.eclipse.xpand2.output.XmlBeautifier" />
</outlet>
</component>
</workflow>
when i run it as eclipse application, the action only display the messaedialog. No file is generated. and no exception too.
|
|
|
|
|
Re: Xpand and GMF [message #1738926 is a reply to message #1738925] |
Tue, 26 July 2016 07:55 |
|
And is the workflow executed? Does the Reader component read files into slot 'model'?
Use the debugger and set a breakpoint in the Reader's load() method.
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
|
|
Re: Xpand and GMF [message #1738930 is a reply to message #1738928] |
Tue, 26 July 2016 08:10 |
|
Yes, you could debug into the WorkflowRunner to see if the workflow was successfully loaded and executed. The could set a breakpoint in WorkflowEngine#executeWorkflow. The process should stop at the breakpoint. Next indicator is Reader#load() to see if your model is actually loaded. If so, it should be placed into the 'model' slot of the WorkflowContext. Is that the case?
|
|
|
|
Re: Xpand and GMF [message #1738945 is a reply to message #1738936] |
Tue, 26 July 2016 09:16 |
Wendy Wendy Messages: 21 Registered: July 2016 |
Junior Member |
|
|
I think this part might be the problem, but not sure how to correct it
Map<String, String> properties = new HashMap<String, String>();
properties.put("model", URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString());
properties.put("out", Platform.getLocation().toOSString() + file.getParent().getFullPath());
WorkflowRunner runner = new WorkflowRunner();
runner.run(url.getPath(), new NullProgressMonitor(), properties, null)
|
|
|
Re: Xpand and GMF [message #1738962 is a reply to message #1738945] |
Tue, 26 July 2016 10:57 |
|
Without debugging into the process this is hard to tell. Did you enable debugging of the process and set a break point in class WorkflowEngine, method executeWorkflow? Does the debugger stop there?
|
|
|
Re: Xpand and GMF [message #1738966 is a reply to message #1738803] |
Tue, 26 July 2016 11:10 |
Wendy Wendy Messages: 21 Registered: July 2016 |
Junior Member |
|
|
Yes. It run and break there. But the engine return false.
I think its because
0 INFO WorkflowEngine - --------------------------------------------------------------------------------------
419 INFO WorkflowEngine - EMF Modeling Workflow Engine 1.3.13, Build v201512160556
423 INFO WorkflowEngine - (c) 2005-2009 openarchitectureware.org and contributors
428 INFO WorkflowEngine - --------------------------------------------------------------------------------------
435 INFO WorkflowEngine - running workflow: file:/C:/Users/User/workspace/ontology.diagram/src/templates/Generator.mwe
443 INFO WorkflowEngine -
1047 ERROR WorkflowEngine - [ERROR]: property model not specified. Dereferenced at in file:/C:/Users/User/workspace/ontology.diagram/src/templates/Generator.mwe:10(Element: -UNKNOWN-; Reported by: -UNKNOWN-)
1064 ERROR WorkflowEngine - Workflow interrupted because of configuration errors.
property model not specified? Isnt it already specified in the property?
[Updated on: Tue, 26 July 2016 12:38] Report message to a moderator
|
|
|
Re: Xpand and GMF [message #1738978 is a reply to message #1738966] |
Tue, 26 July 2016 13:27 |
|
With that message we can do something. It says 'property model not specified'. This property is used in the workflow:
You are putting this property in the param map:
properties.put("model", ...)
Please make sure that the 'model' param is passed properly to the engine. Set a breakpoint WorkflowFactory#parseInitAndCreate and see is 'params' contains 'model' key with the proper value.
If that's still a problem set a breakpoint in IssuesImpl and see when addError() is invoked and why.
|
|
|
|
Re: Xpand and GMF [message #1739000 is a reply to message #1738981] |
Tue, 26 July 2016 16:36 |
Wendy Wendy Messages: 21 Registered: July 2016 |
Junior Member |
|
|
I think this part might be the reason but not sure why
<outlet path="${out}">
<postprocessor class="org.eclipse.xpand2.output.XMLBeautifier" />
</outlet>
this part raise issues
[[ERROR]: Class not found: 'org.eclipse.xpand2.output.XMLBeautifier'(Element: bean postprocessor class='org.eclipse.xpand2.output.XMLBeautifier' in /C:/Users/User/eclipse/java-mars2/eclipse/../../../workspace/ontology.diagram/src/templates/Generator.mwe:18; Reported by: -UNKNOWN-)]
but when i remove this beautifier part, it is not responding when i try to debug
ok now this part is corrected by
<postprocessor class="org.eclipse.xtend.typesystem.xsd.XMLBeautifier" />
Thx, finally i got it running. I used the old template which use RDFSProperty instead of RDFProperty. thats where i go wrong.
When i debug i found there is this code that took long to run. Any idea what is the problem?
WorkflowEngine:
workflow = factory.parseInitAndCreate(workFlowFile, params, getConverters(), issues);
WorkflowEngine.executeWorkflow:
workflow.invoke(wfContext, monitor, issues);
[Updated on: Tue, 26 July 2016 19:21] Report message to a moderator
|
|
|
Re: Xpand and GMF [message #1739033 is a reply to message #1739000] |
Wed, 27 July 2016 06:31 |
|
parseInitAndCreate() cannot take long. It parses the Workflow file, and it is fast.
workflow.invoke() can take time, since this is your actual workflow executing.
<platformUri value="../" />
can take time. It goes one level up in the directory and from there it scans recursively for Eclipse project directories with a .project file. In your case "." should be enough. It is convenience to use ".." for multi-projects, e.g. if your Ecore file is in another project.
Also suspicious is that you use a http URL for the RegisterEcoreFile property. I would expect there "platform:/resource/PROJECTNAME_WITH_ECORE/PATH_TO_ECORE/ont.ecore".
Otherwise a HTTP connection is opened and might run into timeout, explaining the delay.
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
Re: Xpand and GMF [message #1739110 is a reply to message #1739033] |
Wed, 27 July 2016 14:53 |
Wendy Wendy Messages: 21 Registered: July 2016 |
Junior Member |
|
|
Karsten Thoms wrote on Wed, 27 July 2016 06:31parseInitAndCreate() cannot take long. It parses the Workflow file, and it is fast.
workflow.invoke() can take time, since this is your actual workflow executing.
<platformUri value="../" />
can take time. It goes one level up in the directory and from there it scans recursively for Eclipse project directories with a .project file. In your case "." should be enough. It is convenience to use ".." for multi-projects, e.g. if your Ecore file is in another project.
Also suspicious is that you use a http URL for the RegisterEcoreFile property. I would expect there "platform:/resource/PROJECTNAME_WITH_ECORE/PATH_TO_ECORE/ont.ecore".
Otherwise a HTTP connection is opened and might run into timeout, explaining the delay.
When i debug i still found that it took some second longer than other step in parseInitAndCreate() part. Took few seconds.
The I adjusted mwe as follow
<platformUri value="./" />
<RegisterEcoreFile value="platform:/resource/ontology/model/ont.ecore"/>
now i got this error:
[[ERROR]: Error creating instance of type 'org.eclipse.emf.mwe.utils.StandaloneSetup' : org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/ontology/model/ont.ecore' does not exist.(Element: bean bean class='org.eclipse.emf.mwe.utils.StandaloneSetup' in /C:/Users/User/eclipse/java-mars2/eclipse/../../../workspace/ontology.diagram/src/templates/Generator.mwe:4; Reported by: -UNKNOWN-), null, null, null, null, null, null, null, null, null]
I think its because the action run mwe from the eclipse instance while the ecore file is in the main eclipse. Is it? if that is the case, any idea how can i solve it? Thx.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07372 seconds