Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Ecore2OCLinEcore
Ecore2OCLinEcore [message #727104] Tue, 20 September 2011 12:25 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
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 #727185 is a reply to message #727104] Tue, 20 September 2011 15:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I'm not sure what your Ecore2OCLinEcore does, but assuming it combines
the two Ecore2Pivot and Pivot2CS steps, your problem is probably that
you have not registered the ".ocl" extension and so you have created an
XMIResource rather than an OCLinEcoreResource that extends an
XtextResource. The XtextResource ensures that a resource is saved in
human-friendly text rather than XMI. The registration is performed by
OCLinEcoreStandaloneSetup.doSetup().

You may find org.eclipse.ocl.examples.test.xtext.RoundTripTests has
some useful helpers to copy.

Regards

Ed Willink

On 20/09/2011 13:25, ModelGeek wrote:
> 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 16:53 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
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 16:56]

Report message to a moderator

Re: Ecore2OCLinEcore [message #727253 is a reply to message #727237] Tue, 20 September 2011 17:40 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
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
Previous Topic:[CompleteOCL] Accessing the metamodel
Next Topic:Query Evaluate method
Goto Forum:
  


Current Time: Thu Mar 28 22:34:06 GMT 2024

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

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

Back to the top