Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Visiting OCL: Getting the Ecore element related to a Pivot typed element
Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1110181] Mon, 16 September 2013 13:49 Go to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi everyone,
In the context of visiting a pivot constraint (extending AbstractExtendingVisitor),
Is there a way to get the Ecore model element related to a pivot typed element?
More specifically, how can I get the Ecore element related to a context (Constraint.getContext():NamedElement)?
I guess there's probably a Map somewhere containing the mapping from Ecore to Pivot.
I already tried Ecore2Pivot.getAdapter() and then getCreated() but the Pivot elements seems to be different from those in the visitor.
Thanks a lot
John

[Updated on: Mon, 16 September 2013 14:02]

Report message to a moderator

Re: Visiting OCL: Get Ecore model element from a Pivot element [message #1110300 is a reply to message #1110181] Mon, 16 September 2013 17:30 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

If the pivot element was created from Ecore it is available at getETarget().

Using MetaModelManager.getEcoreOfPivot() is more controlled.

Regards

Ed Willink


On 16/09/2013 14:49, John Guerson wrote:
> Hi everyone,
> In the context of visiting a pivot constraint (extending
> AbstractExtendingVisitor),
> Is there a way to get the Ecore model element related to a pivot typed
> element?
> More specifically, how can I get the Ecore model element related to
> the context of a constraint which is resultant of the method
> Constraint.getContext():NamedElement ?
> Thanks in advance
> John
>
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1112593 is a reply to message #1110181] Thu, 19 September 2013 23:17 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi Edward,

The method getETarget() is returning null no matter what I do...
So if you could, please, take a look in my project (attached below) I would really appreciate.

The MetaModelManager.getEcoreOfPivot() doesn't exists in Juno (which is not the SR1 or SR2 version) (I need this running in Juno for the sake of compatibility with other custom libraries). So, I am trying with getETarget() in Juno.

I was also trying to run it in Kepler (using the getEcoreOfPivot()) but it seems that beacause getETarget() returns null, the method getEcoreOfPivot() creates another Ecore elements that are not the same as the original ecore ones. This is true?

I am probably doing something wrong, but so far I do not know what else I can do.

Thanks a lot,
John

[Updated on: Fri, 20 September 2013 20:11]

Report message to a moderator

Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1112869 is a reply to message #1112593] Fri, 20 September 2013 09:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

Have you tried loading the latest (or Kepler) OCL and Xtext on Juno?

Regards

Ed Willink


On 20/09/2013 00:17, John Guerson wrote:
> Hi Edward,
>
> The method getETarget() is returning null no matter what I do...
> So if you could, please, take a look in my project (attached below) I would really appreciate.
>
> The MetaModelManager.getEcoreOfPivot() doesn't exists in Juno (I need this running in Juno for the sake of compatibility with other custom libraries). So, I am trying with getETarget() in Juno.
>
> I was also trying to run it in Kepler (using the getEcoreOfPivot()) but it seems that beacause getETarget() returns null, the method getEcoreOfPivot() creates another Ecore elements that are not the same as the original ecore ones. This is true?
>
> I am probably doing something wrong, but so far I do not know what else I can do.
>
> Thanks a lot,
> John
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1113219 is a reply to message #1112869] Fri, 20 September 2013 20:33 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi,

I just tried with Kepler and Juno-SR2, using their plugins, and still got null's.
I also downloaded the OCL 4.2.0M1 and tried to replace them in Kepler, still didn't work.
The project attached above contains my code. To run it, you need only to import the project into your workspace. I know that you have little time to spend, so I really appreciate your attention.

I guess it could be something with the Ecore that I'm loading. My ecore model is generated by other custom library. I also ran tests with models from the sample ecore editor of eclipse and still got nulls.

Here is the main part of my code:


public PivotOCLTest (String oclPath, String ecorePath) throws IOException, ParserException
{
    OCLstdlib.install();				     
    org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();    	   
    org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup();    	
    org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();    	

    EPackage ecoreRoot = readEcore(ecorePath);
    OCL.initialize(ecoreRoot.eResource().getResourceSet());

    MetaModelManager metamodelManager = new MetaModelManager();
    PivotEnvironmentFactory pivotEnvFactory = new PivotEnvironmentFactory(
        ecoreRoot.eResource().getResourceSet().getPackageRegistry(),   
        metamodelManager);
    ocl = OCL.newInstance(pivotEnvFactory);	

    URI oclURI = URI.createFileURI(oclPath);	    
    Resource pivotResource = ocl.parse(oclURI);

    for (TreeIterator<EObject> tit = pivotResource.getAllContents(); tit.hasNext();){
        EObject next = tit.next();
        if (next instanceof Constraint){
         Constraint constraint = (Constraint)next;				
         System.out.println("ETarget = "+constraint.getContext().getETarget()); //null???				 
    }
}


and to read the ecore:

public static EPackage readEcore (String ecorePath)
{
    URI ecoreURI = URI.createFileURI(ecorePath);			
    ResourceSet ecoreResourceSet = new ResourceSetImpl();

    ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", 
    new EcoreResourceFactoryImpl());
    ecoreResourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
		    	
    Resource ecoreResource = ecoreResourceSet.getResource(ecoreURI,true);
    EPackage ecoremodel = (EPackage) ecoreResource.getContents().get(0);
    ecoreResource.getResourceSet().getPackageRegistry().put(null,ecoremodel);

    return ecoremodel;
}


and to run it:

/** Run a Test */
public static void main (String[] args)
{				
    String oclPath = "model/project.ocl";				
    String refPath = "model/project.ecore";
		
    try {
        new PivotOCLTest(oclPath,refPath);
	System.out.println("OCL parsed.");
			
    } catch (Exception e) {
        e.printStackTrace();
    }
}		


Regards,
John

[Updated on: Fri, 20 September 2013 20:39]

Report message to a moderator

Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1113542 is a reply to message #1113219] Sat, 21 September 2013 09:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
HI

You attachment expects all the libraries to be in the "juno" folder, so
I would have to do a lot of repair to make it work and might repair your
problem by mistake.

Does it work as a normal standalone application? If not please provide
an attachment for that.

You can set up launch configurations for non-Eclipse apps too; see
/org.eclipse.ocl.ecore.tests/launches/org.eclipse.ocl.ecore.tests
(Standalone Classpath).launch for how to get Eclipse to work out many of
the dependencies for you.

Regards

Ed Willink


On 20/09/2013 21:33, John Guerson wrote:
> Hi,
>
> I just tried with Kepler and Juno-SR2, using their plugins, and still
> got null's.
> I also downloaded the OCL 4.2.0M1 and tried to replace them in Kepler,
> still didn't work.
> The project attached above contains my code. To run it, you need only
> to import the project into your workspace. I know that you have little
> time to spend, so I really appreciate your attention.
>
> I guess it could be something with the Ecore that I'm loading. My
> ecore model is generated by other custom library. I also ran tests
> with models from the sample ecore editor of eclipse and still got nulls.
>
> Here is the main part of my code:
>
>
>
> public PivotOCLTest (String oclPath, String ecorePath) throws
> IOException, ParserException
> {
> OCLstdlib.install();
> org.eclipse.ocl.examples.xtext.completeocl.CompleteOCLStandaloneSetup.doSetup();
>
> org.eclipse.ocl.examples.xtext.essentialocl.EssentialOCLStandaloneSetup.doSetup();
>
>
> org.eclipse.ocl.examples.xtext.oclstdlib.OCLstdlibStandaloneSetup.doSetup();
>
>
> EPackage ecoreRoot = readEcore(ecorePath);
> OCL.initialize(ecoreRoot.eResource().getResourceSet());
>
> MetaModelManager metamodelManager = new MetaModelManager();
> PivotEnvironmentFactory pivotEnvFactory = new PivotEnvironmentFactory(
> ecoreRoot.eResource().getResourceSet().getPackageRegistry(),
> metamodelManager);
> ocl = OCL.newInstance(pivotEnvFactory);
>
> URI oclURI = URI.createFileURI(oclPath); Resource
> pivotResource = ocl.parse(oclURI);
>
> for (TreeIterator<EObject> tit = pivotResource.getAllContents();
> tit.hasNext();){
> EObject next = tit.next();
> if (next instanceof Constraint){
> Constraint constraint = (Constraint)next;
> System.out.println("ETarget = "+constraint.getETarget());
> //null??? }
> }
>
>
> and to read the ecore:
>
>
> public static EPackage readEcore (String ecorePath)
> {
> URI ecoreURI = URI.createFileURI(ecorePath);
> ResourceSet ecoreResourceSet = new ResourceSetImpl();
>
>
> ecoreResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
> ecoreResourceSet.getPackageRegistry().put(EcorePackage.eNS_URI,
> EcorePackage.eINSTANCE);
>
> Resource ecoreResource = ecoreResourceSet.getResource(ecoreURI,true);
> EPackage ecoremodel = (EPackage) ecoreResource.getContents().get(0);
>
> ecoreResource.getResourceSet().getPackageRegistry().put(null,ecoremodel);
>
> return ecoremodel;
> }
>
>
> and to run it:
>
>
> /** Run a Test */
> public static void main (String[] args)
> {
> String oclPath = "model/project.ocl";
> String refPath = "model/project.ecore";
>
> try {
> new PivotOCLTest(oclPath,refPath);
> System.out.println("OCL parsed.");
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
>
> Regards,
> John
Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1113710 is a reply to message #1113542] Sat, 21 September 2013 15:32 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi,

I updated the zip file attached in the previous reply. It's a plugin project.
It should work only importing the project into the workspace. I'm attaching it below.

I'll take a look on the launch configurations anyway.
Regards,
John

[Updated on: Sat, 21 September 2013 15:33]

Report message to a moderator

Re: Visiting OCL: Getting the Ecore element related to a Pivot typed element [message #1114296 is a reply to message #1113710] Sun, 22 September 2013 14:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

Your code is trying to get the 'EConstraint' for a pivot Constraint.
There is no such thing. If in the inner loop you do:

Constraint constraint = (Constraint)next;
Namespace context = constraint.getContext();
EClassifier eClassifier =
metamodelManager.getEcoreOfPivot(EClassifier.class, context);
System.out.println("ETarget = "+eClassifier);

You'll get

ETarget = org.eclipse.emf.ecore.impl.EClassImpl@c8c913 (name: Student)
(instanceClassName: null) (abstract: false, interface: false)
ETarget = org.eclipse.emf.ecore.impl.EClassImpl@91b85 (name: University)
(instanceClassName: null) (abstract: false, interface: false)
ETarget = org.eclipse.emf.ecore.impl.EClassImpl@1edbbdb (name:
University) (instanceClassName: null) (abstract: false, interface: false)
ETarget = org.eclipse.emf.ecore.impl.EClassImpl@c847a7 (name:
University) (instanceClassName: null) (abstract: false, interface: false)
OCL parsed.

Regards

Ed Willink

On 21/09/2013 16:32, John Guerson wrote:
> Hi,
>
> I updated the zip file attached in the previous reply. It's a plugin project.
> It should work only importing the project into the workspace.
> I'll take a look on the launch configurations anyway.
>
> Regards,
> John
Re: Ecore element related to a Pivot typed element [message #1114984 is a reply to message #1114296] Mon, 23 September 2013 13:58 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi,

I just forgot to add getContext() after the constraint, sorry for that. But, here is the doubt:

I transform a custom model into Ecore programatically saving a Map<CustomObject,EObject> which has all the mappings of my custom transformation.

These objects returned from getEcoreOfPivot() seems not to be those in the transformation Map above.
That's my real question. I thought that getETarget() and getEcoreOfPivot() would get me those exact same objects, but getETarget is returning null and the object returned by getEcoreOfPivot() seems to be different from those.

Regards
John

Re: Ecore element related to a Pivot typed element [message #1115274 is a reply to message #1114984] Mon, 23 September 2013 23:11 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi

Your comments make no sense to me. You seem to be confusing metalevels.
The Ecore/UML to Pivot conversions occur to normalize the metamodel
representations. Your models are a different issue.

Regards

Ed Willink




On 23/09/2013 09:58, John Guerson wrote:
> Hi,
>
> I just forgot to add getContext() after the constraint, sorry for
> that. But, here is the doubt:
>
> I transform a custom model into Ecore programatically saving a
> Map<CustomObject,EObject> which has all the mappings of my custom
> transformation.
> These objects returned from getEcoreOfPivot() seems not to be those in
> the transformation Map above. That's my real question. I thought that
> getETarget() and getEcoreOfPivot() would get me those exact same
> objects, but getETarget is returning null and the object returned by
> getEcoreOfPivot() seems to be different from those.
> Regards
> John
>
>
Previous Topic:Validating OCL in EMF - RCP
Next Topic:[Announce] Eclipse OCL 4.1.1 (Kepler SR1) is now available
Goto Forum:
  


Current Time: Fri Dec 19 14:39:07 GMT 2014

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

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