serialization of CompleteOCL document to XMI format [message #986595] |
Wed, 21 November 2012 01:55  |
Eclipse User |
|
|
|
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 01:56] by Moderator
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #986630 is a reply to message #986595] |
Wed, 21 November 2012 04:17   |
Eclipse User |
|
|
|
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 #990128 is a reply to message #990079] |
Mon, 10 December 2012 19:56   |
Eclipse User |
|
|
|
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 02:38] by Moderator
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990194 is a reply to message #990128] |
Tue, 11 December 2012 06:05   |
Eclipse User |
|
|
|
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 11:50   |
Eclipse User |
|
|
|
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 02:08   |
Eclipse User |
|
|
|
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 02:20] by Moderator
|
|
|
|
Re: serialization of CompleteOCL document to XMI format [message #990448 is a reply to message #990376] |
Wed, 12 December 2012 09:33  |
Eclipse User |
|
|
|
Hi Ed,
I read documentation,
I found the ProjectMapTest in org.eclipse.ocl.examples.test.ecore
I found also testProjectMap_Pivot_Local() method which can help me to resolve this problem.
I tryed to adopt it in my context, however, the problem still persists.
Best regards,
package Parser;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
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.IPackageDescriptor;
import org.eclipse.ocl.examples.domain.utilities.StandaloneProjectMap.IProjectDescriptor;
import simple.SimplePackage;
//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();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createURI(args[0]));
resource.load(null);
Resource resourceAsXmi = resourceSet.createResource(URI.createURI(args[0]+".xmi"));
String project = SimplePackage.class.getPackage().getName();
System.out.println(project);
ProjectMap.getResourceFactoryRegistry(null).getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
ProjectMap projectMap = new ProjectMap();
projectMap.initializeResourceSet(resourceSet);
IProjectDescriptor projectDescriptor = projectMap.getProjectDescriptor(project);
IPackageDescriptor packageDescriptor = projectDescriptor.getPackageDescriptor(URI.createURI(SimplePackage.eINSTANCE.getNsURI()));
packageDescriptor.setUseModel(true, resourceSet.getPackageRegistry());
EcoreUtil.resolveAll(resource);
resourceAsXmi.getContents().addAll(resource.getContents());
resourceAsXmi.save(null);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.06779 seconds