serialization of CompleteOCL document to XMI format [message #986595] |
Wed, 21 November 2012 06:55 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
Hi all,
I would like to know if it is possible to serialize an CompleteOCL document to xmi format? If yes, how exactly please?
I have an completeOCL document like this
import 'MyEcore.ecore'
package test
context TestClass
...
....
I would like to generate the xmi file which refers to the ecore elements (classes, packages, attributes, etc.)
Please help me
Best regards
[Updated on: Wed, 21 November 2012 06:56] Report message to a moderator
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #986630 is a reply to message #986595] |
Wed, 21 November 2012 09:17 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
The CST can be serialized by saving the CST Resource to an XMI file.
(This is currently only available programmatically.)
The AST can be serialized by saving the AST (Pivot) Resource to an XMI
file, but since Complete OCL complements an existing meta-model, this
also serialises the complemented meta-model.
(This might be available interactively by using Load Complete OCL
Resource to merge into the Sampkle Excore Editior, then doing SaveAs...)
Regards
Ed Willink
On 21/11/2012 06:55, Fy Za wrote:
> Hi all, I would like to know if it is possible to serialize an
> CompleteOCL document to xmi format? If yes, how exactly please?
>
> I have an completeOCL document like this
>
> import 'MyEcore.ecore'
> package test
>
> context TestClass
> ...
> ....
>
> I would like to generate the xmi file which refers to the ecore
> elements (classes, packages, attributes, etc.)
>
> Please help me
> Best regards
>
>
|
|
|
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990033 is a reply to message #990000] |
Mon, 10 December 2012 15:45 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
To be more precise,
I have an OCLDocument test.ocl with applied to Simple.ecore
I define this class:
package Parser;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
public class Parser {
public static void main(String[] args) throws IOException {
CompleteOCLStandaloneSetup.doSetup();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI(args[0]));
resource.load(null);
Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".generated.xmi"));
resourceAsXmi.getContents().addAll(resource.getContents());
resourceAsXmi.save(null);
}
}
It generates a file which named test.generated.xmi
I generate another xmi file with saveAs xmi command of test.ocl named test.saveas.xmi
test.generated.xmi doesn't resolve paths (like in this example test.ocl#xtextLink_::0.10.0.6.1.0::2::/1)
<ownedImport>
<pathName>
<path xsi:type="baseCST:PathElementWithURICS">
<element xsi:type="pivot:Annotation" href="/CompleteOCLParser/Case/test.ocl#xtextLink_::0.10.0.6.1.0::2::/1"/>
</path>
</pathName>
</ownedImport>
However the test.saveas.xmi resolve them (Simple.ecore#/)
<ownedImport>
<namespace xsi:type="pivot:Model" href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
</ownedImport>
So, What I should modify or add in the parser class to get the results of test.saveas.xmi programmaticly ?
Best regards,
Fy Za
[Updated on: Mon, 10 December 2012 15:46] Report message to a moderator
|
|
|
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990128 is a reply to message #990079] |
Tue, 11 December 2012 00:56 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
Hi Ed,
Thank you!
It is resolved!!
I add two lines
package Parser;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
public class Parser {
public static void main(String[] args) throws IOException {
CompleteOCLStandaloneSetup.doSetup();
OCLinEcoreStandaloneSetup.doSetup();
OCLstdlib.install();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI(args[0]));
resource.load(null);
EcoreUtil.resolveAll(resource);
Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
resourceAsXmi.getContents().addAll(resource.getContents());
resourceAsXmi.save(null);
}
}
However, two differences between test.saveas.xmi and test.generated.xmi still persists:
1-
In the "save as xmi" file named test.saveas.xmi, I have a the top
<?xml version="1.0" encoding="ASCII"?>
<completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST" xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST" xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST" xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
<ownedImport>
<namespace xsi:type="pivot:Model" href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
</ownedImport>
However, The parser generated file named test.generated.xmi, I have for the same part
<?xml version="1.0" encoding="ASCII"?>
<completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST" xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST" xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST" xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
<ownedImport>
<pathName>
<path xsi:type="baseCST:PathElementWithURICS">
<element xsi:type="pivot:Root" href="pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/Simple.ecore#/"/>
</path>
</pathName>
</ownedImport>
2-
In the "save as xmi" file named test.saveas.xmi, I have for example (/null/Users/fyza/Modeling/workspace_ocl/)
<name xsi:type="essentialOCLCST:NameExpCS">
<pathName>
<path>
<element xsi:type="pivot:Variable" href="pivot:/null/Users/fyza/Modeling/workspace_ocl/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.0/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
</path>
</pathName>
</name>
However, The parser generated file named test.generated.xmi, I have for the same part(/platform/resource/):
<name xsi:type="essentialOCLCST:NameExpCS">
<pathName>
<path>
<element xsi:type="pivot:Variable" href="pivot:/platform/resource/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.1/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
</path>
</pathName>
</name>
Do you know what I should modify or add in the parser in order to eliminate these differences.
Best regards,
Fy Za
[Updated on: Tue, 11 December 2012 07:38] Report message to a moderator
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990194 is a reply to message #990128] |
Tue, 11 December 2012 11:05 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore
indicates a file that was opened as
platform:/resource/CompleteOCLParser/Case/Simple.ecore
pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore
indicates a file that was opened as
file:/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore
if you want EMF to work consistently, you should avoid file: paths
wherever possible. Use URI.createPlatformResourceURI and
StandaloneProjectMap.
Regards
Ed Willink
On 11/12/2012 00:57, Fy Za wrote:
> Hi Ed,
> Thank you!
> I add two lines
>
> package Parser;
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
> import
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
> import
> org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
>
> public class Parser {
>
> public static void main(String[] args) throws IOException {
>
> CompleteOCLStandaloneSetup.doSetup();
> OCLinEcoreStandaloneSetup.doSetup();
> OCLstdlib.install();
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI(args[0]));
> resource.load(null);
> EcoreUtil.resolveAll(resource);
> Resource resourceAsXmi =
> resourceSet.createResource(URI.createURI(args[0]+".xmi"));
> resourceAsXmi.getContents().addAll(resource.getContents());
> resourceAsXmi.save(null);
>
> }
> }
>
> However, two differences still persists:
> 1-
> In the "save as xmi" file named test.saveas.xmi, I have a the top
> <?xml version="1.0" encoding="ASCII"?>
> <completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST"
> xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST"
> xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST"
> xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
> <ownedImport>
> <namespace xsi:type="pivot:Model"
> href="pivot:/platform/resource/CompleteOCLParser/Case/Simple.ecore#/"/>
> </ownedImport>
> However, The parser generated file named test.generated.xmi, I have
>
> <?xml version="1.0" encoding="ASCII"?>
> <completeOCLCST:CompleteOCLDocumentCS xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:baseCST="http://www.eclipse.org/ocl/3.1.0/BaseCST"
> xmlns:completeOCLCST="http://www.eclipse.org/ocl/3.1.0/CompleteOCLCST"
> xmlns:essentialOCLCST="http://www.eclipse.org/ocl/3.1.0/EssentialOCLCST"
> xmlns:pivot="http://www.eclipse.org/ocl/3.1.0/Pivot">
> <ownedImport>
> <pathName>
> <path xsi:type="baseCST:PathElementWithURICS">
> <element xsi:type="pivot:Root"
> href="pivot:/file/Users/faiez/Modeling/workspace_juno_02122012/CompleteOCLParser/Case/SimplePDL.ecore#/"/>
> </path>
> </pathName>
> </ownedImport>
>
>
> 2- In the "save as xmi" file named test.saveas.xmi, I have for example
>
> <name xsi:type="essentialOCLCST:NameExpCS">
> <pathName>
> <path>
> <element xsi:type="pivot:Variable"
> href="pivot:/null/Users/fyza/Modeling/workspace_ocl/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.0/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
> </path>
> </pathName>
> </name>
>
> However, The parser generated file named test.generated.xmi, I have
>
> <name xsi:type="essentialOCLCST:NameExpCS">
> <pathName>
> <path>
> <element xsi:type="pivot:Variable"
> href="pivot:/platform/resource/CompleteOCLParser/Case/test.ocl#//@nestedPackage.0/@ownedType.1/@ownedOperation.0/@ownedRule.0/@specification/@bodyExpression/@iterator.0"/>
> </path>
> </pathName>
> </name>
>
>
> Do you know what I should modify or add in the parser in order to
> eliminate these differences.
> Best regards,
> Fy Za
|
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990273 is a reply to message #990235] |
Tue, 11 December 2012 16:50 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
Users of Eclipse are expected to be able to show some initiative....
Have you looked at the javadoc?
Have you searched for references?
Regards
ed Willink
On 11/12/2012 14:22, Fy Za wrote:
> Hi, I add this line: URI uri =
> URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);
>
> However, for StandaloneProjectMap, I don't know what I should define,
> what method, what parameters!!!! etc.
> can you explain to me more, Please!
> because I don't find nothing in Google :(
>
> package Parser;
> import java.io.IOException;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
> import
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
> import
> org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
>
> public class Parser {
>
> public static void main(String[] args) throws IOException {
>
> CompleteOCLStandaloneSetup.doSetup();
>
> OCLinEcoreStandaloneSetup.doSetup();
> OCLstdlib.install();
>
> URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore",
> true);
> System.out.println(uri);
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createURI(args[0]));
> resource.load(null);
> EcoreUtil.resolveAll(resource);
> Resource resourceAsXmi =
> resourceSet.createResource(URI.createURI(args[0]+".xmi"));
> resourceAsXmi.getContents().addAll(resource.getContents());
> resourceAsXmi.save(null);
>
> }
> }
>
>
>
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990357 is a reply to message #990273] |
Wed, 12 December 2012 07:08 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
Hi Ed,
Yes, I look in javadoc.
There is no concrete code. There is just some discussions!
I edit the code, but no modifications in the generated xmi file.
Can you PLEASE edit this code!
at least, tell me, what I should do exactly with StandaloneProjectMap
and How relate it with the initial code?
regards!
Fy
package Parser;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup;
import org.eclipse.ocl.examples.xtext.oclinecore.OCLinEcoreStandaloneSetup;
import org.eclipse.ocl.examples.domain.utilities.ProjectMap;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IPackageDescriptor;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IProjectDescriptor;
import simplepdl.SimplepdlPackage;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap;
//import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.ProjectDescriptor;
public class Parser {
public static void main(String[] args) throws IOException {
CompleteOCLStandaloneSetup.doSetup();
OCLinEcoreStandaloneSetup.doSetup();
OCLstdlib.install();
URI uri = URI.createPlatformPluginURI("org.eclipse.emf.ecore", true);
System.out.println(uri);
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI(args[0]));
String project = SimplepdlPackage.class.getPackage().getName();
String modelPath = project + "/model/SimplePDL.ecore";
ProjectMap.getResourceFactoryRegistry(null).getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
URI nsURI = URI.createURI(SimplepdlPackage.eINSTANCE.getNsURI());
URI pluginURI = URI.createPlatformPluginURI(modelPath, true);
URI resourceURI = URI.createPlatformResourceURI(modelPath, true);
ProjectMap projectMap = new ProjectMap();
projectMap.initializeResourceSet(resourceSet);
IProjectDescriptor projectDescriptor = projectMap.getProjectDescriptor(project);
IPackageDescriptor packageDescriptor = projectDescriptor.getPackageDescriptor(URI.createURI(SimplepdlPackage.eINSTANCE.getNsURI()));
packageDescriptor.setUseModel(true, resourceSet.getPackageRegistry());
Resource registeredResource = resourceSet.getResource(nsURI, true);
resource.load(null);
EcoreUtil.resolveAll(resource);
Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
resourceAsXmi.getContents().addAll(resource.getContents());
resourceAsXmi.save(null);
}
}
[Updated on: Wed, 12 December 2012 07:20] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05556 seconds