Home » Modeling » OCL » Ecore2OCLinEcore
Ecore2OCLinEcore [message #727104] |
Tue, 20 September 2011 08:25  |
Eclipse User |
|
|
|
Hi,
In my standalone application, i have created Ecore programmatically. I want to generate text from ecore model in my standalone appication. The same sort of text which appears in OCLinEcore Editor in Eclipse. I just want to generate text and i do not need any UI features.
Ecore2OCLinEcore oCLinEcore = Ecore2OCLinEcore.importDocument(resourceSet, resource);
OCLinEcoreDocumentCS document = oCLinEcore.getDocument();
document.eResource().save(null);
I am using above mentioned code. The saved resource contains XML stuff like mentioned below.
<packages name="temp" prefix="ABC" uri="http://www.eclipse.org/mdt/ocl/oclinecore/tutorial">
<classifiers xsi:type="oclinEcoreCST:OCLinEcoreClassCS" name="BehaviorElement">
<annotations xsi:type="oclinEcoreCST:AnnotationCS" stringSource="http://www.eclipse.org/emf/2002/Ecore">
<details idName="constraint">
<value>mostOneType</value>
</details>
but i would like to get the same sort of text which appears when user open Ecore model in OCLinEcore editor. e.g.
Class BehaviorElement {
attribute 1
attribute 2
}
i have asked this question on different groups but not sure which is the right group to ask this question. Sorry if i am duplicating.
Please help!
|
|
| |
Re: Ecore2OCLinEcore [message #727237 is a reply to message #727185] |
Tue, 20 September 2011 12:53   |
Eclipse User |
|
|
|
Hi,
Actually Ecore2OCLinEcore is available in org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore for Helios, but in Indigo this class is deleted.
I have tried to understand RoundTripTest Code which is given below:
public void doRoundTripFromOclInEcore(String stem) throws IOException, InterruptedException {
String inputName = stem + ".oclinecore";
String middleName = stem + ".converted.ecore";
String outputName = stem + ".regenerated.oclinecore";
String output2Name = stem + ".reconverted.ecore";
URI inputURI = getProjectFileURI(inputName);
URI middleURI = getProjectFileURI(middleName);
URI outputURI = getProjectFileURI(outputName);
URI output2URI = getProjectFileURI(output2Name);
Resource leftResource = resourceSet.getResource(inputURI, true);
assertNoResourceErrors("Load failed", leftResource);
// OCLinEcore2Ecore cs2e = new OCLinEcore2Ecore(resourceSet, leftResource, middleURI);
// Resource middleResource = cs2e.exportToEcore();
// assertEquals("To Ecore errors", 0, middleResource.getErrors().size());
// middleResource.save(null);
// resourceSet.getResources().add(middleResource);
RootPackageCS csDocument = null; // FIXME Ecore2OCLinEcore.importFromEcore(resourceSet, null, middleResource);
assertNoResourceErrors("From Ecore errors", csDocument.eResource());
Resource rightResource = resourceSet.createResource(outputURI);
// middleResource.getContents().addAll(csObjects);
rightResource.getContents().add(csDocument);
rightResource.save(null);
// OCLinEcore2Ecore cs2e2 = new OCLinEcore2Ecore(resourceSet, rightResource, output2URI);
// Resource right2Resource = cs2e2.exportToEcore();
assertNoResourceErrors("To Ecore errors", rightResource);
// right2Resource.save(null);
// resourceSet.getResources().add(right2Resource);
// assertSameModel(middleResource, right2Resource);
}
In the code, you have FIXME Ecore2OCLinEcore which is not part of Indigo. And here also XtextResource is not intialized/saved ? it conatins normal resource object. I am a bit confused. Sorry for being very demanding...
In my application i have object of EPackge which contains number of EClass, I am saving that ecore resource and i want to generate human friendly text. Can you please help me and guide me how to do that...
i really appreciate your help!
Regards
[Updated on: Tue, 20 September 2011 12:56] by Moderator
|
|
|
Re: Ecore2OCLinEcore [message #727253 is a reply to message #727237] |
Tue, 20 September 2011 13:40  |
Eclipse User |
|
|
|
Hi
Ah Helios; that was look time ago....
The Helios release has no pivot so indeed there is direct
Ecore2OCLinEcore, but none of the good things that come from the pivot.
The RoundTripTests suggestion is therefore a red herring.
However the problem is probably still that the serialized resource is
not an XtextResource since you presumably have not called
OCLinEcoreStandaloneSetup.doSetup().
Use the debugger to show the class and class hierarchy of the resource
and make sure you use *.oclinecore as the extension.
In Indigo, an EMF limitation was fixed, so you should just be able to
load a resource as Ecore then Save As *.oclinecore.
Regards
Ed Willink
On 20/09/2011 17:53, ModelGeek wrote:
> Hi,
>
> Actually Ecore2OCLinEcore is available in
> org.eclipse.ocl.examples.xtext.oclinecore.resource.Ecore2OCLinEcore
> for Helios.
>
> But in Indigo this class is deleted.
>
> I have tried to understand RoundTripTest Code which is given below:
> public void doRoundTripFromOclInEcore(String stem) throws
> IOException, InterruptedException {
> String inputName = stem + ".oclinecore";
> String middleName = stem + ".converted.ecore";
> String outputName = stem + ".regenerated.oclinecore";
> String output2Name = stem + ".reconverted.ecore";
> URI inputURI = getProjectFileURI(inputName);
> URI middleURI = getProjectFileURI(middleName);
> URI outputURI = getProjectFileURI(outputName);
> URI output2URI = getProjectFileURI(output2Name);
> Resource leftResource = resourceSet.getResource(inputURI, true);
> assertNoResourceErrors("Load failed", leftResource);
> // OCLinEcore2Ecore cs2e = new OCLinEcore2Ecore(resourceSet,
> leftResource, middleURI);
> // Resource middleResource = cs2e.exportToEcore();
> // assertEquals("To Ecore errors", 0,
> middleResource.getErrors().size());
> // middleResource.save(null);
> // resourceSet.getResources().add(middleResource);
> RootPackageCS csDocument = null; // FIXME
> Ecore2OCLinEcore.importFromEcore(resourceSet, null, middleResource);
> assertNoResourceErrors("From Ecore errors",
> csDocument.eResource());
> Resource rightResource = resourceSet.createResource(outputURI);
> // middleResource.getContents().addAll(csObjects);
> rightResource.getContents().add(csDocument);
> rightResource.save(null);
> // OCLinEcore2Ecore cs2e2 = new OCLinEcore2Ecore(resourceSet,
> rightResource, output2URI);
> // Resource right2Resource = cs2e2.exportToEcore();
> assertNoResourceErrors("To Ecore errors", rightResource);
> // right2Resource.save(null);
> // resourceSet.getResources().add(right2Resource);
> // assertSameModel(middleResource, right2Resource);
> }
>
> here you have FIXME Ecore2OCLinEcore which is not part of Indigo. And
> here also XtextResource is not intialized/saved ? it conatins normal
> resource object. I am a bit confused. Sorry for being very demanding...
>
> In my application i have object of EPackge which contains number of
> EClass, I am saving that ecore resource and i want to generate human
> friendly text. Can you please help me and guide me how to do that
|
|
|
Goto Forum:
Current Time: Tue Jul 22 19:34:40 EDT 2025
Powered by FUDForum. Page generated in 0.03142 seconds
|