Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » EMF Plugin(OCL setting extend map)
EMF Plugin [message #531622] Wed, 05 May 2010 15:43 Go to next message
Esin Karabacakoglu is currently offline Esin KarabacakogluFriend
Messages: 11
Registered: May 2010
Location: Turkey
Junior Member
Hi there,
I am beginner at OCL on EMF. I am trying to test my OCL constraints. I have a trouble with the code below. I used "allInstances()" function in OCL constraint. I succeeded to run it by creating an extent map. But in the code below, I am using two "allInstances()" functions in my OCL code. For this reason, i think, i need to add two mapping to my ocl environment. But, it doesn't work when I put two entries into the ocl extend map.

Do you have any idea?

Here is my code:

		org.eclipse.ocl.expressions.OCLExpression query = helper
				.createQuery("RefinementNode.allInstances()->exists(rn|rn.refinementGoals->includes(self)) or     Role.allInstances()->exists(ro|ro.goals->includes(self))");

		// sets the perform goal as a role goal...
		role.getGoals().add(performGoal);
		// create an extent map
		Map extents = new HashMap();
		Set environmentSet = new HashSet();
		environmentSet.add(role);
		extents.put(role.eClass(), environmentSet);
		
		environmentSet = new HashSet();		
		environmentSet.add(refinementNode);
		extents.put(refinementNode.eClass(), environmentSet);
		
		ocl.setExtentMap(extents);

		// use the query expression parsed before to create a Query
		eval = ocl.createQuery(query);
		result = eval.check(performGoal);

		// Assert the constraint...
		assertTrue(result);

[Updated on: Wed, 05 May 2010 15:44]

Report message to a moderator

Re: EMF Plugin [message #531654 is a reply to message #531622] Wed, 05 May 2010 17:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: philipp.berger.student.hpi.uni-potsdam.de

Hi,
I assume that you have to that the context for the OCL to bind it to the
Role class.

Regards
Phil
Am 05.05.2010 17:44, schrieb esin:
> Hi there, I am beginner at OCL on EMF. I am trying to test my OCL
> constraints. I have a trouble with the code below. I used
> "allInstances()" function in OCL constraint. I succeeded to run it by
> creating an extent map. But in the code below, I am using two
> "allInstances()" functions in my OCL code. For this reason, i think, i
> need to add two mapping to my ocl environment. But, it doesn't work when
> I put two entries into the ocl extend map.
>
> Do you have any idea?
>
> Here is my code:
>
> org.eclipse.ocl.expressions.OCLExpression query = helper
> .createQuery("RefinementNode.allInstances()->exists(rn|rn.refinementGoals- >includes(self))
> or Role.allInstances()->exists(ro|ro.goals->includes(self))");
>
> // sets the perform goal as a role goal...
> role.getGoals().add(performGoal);
> // create an extent map
> Map extents = new HashMap();
> Set environmentSet = new HashSet();
> environmentSet.add(role);
> extents.put(role.eClass(), environmentSet);
>
> environmentSet = new HashSet();
> environmentSet.add(refinementNode);
> extents.put(refinementNode.eClass(), environmentSet);
>
> ocl.setExtentMap(extents);
>
> // use the query expression parsed before to create a Query
> eval = ocl.createQuery(query);
> result = eval.check(performGoal);
>
> // Assert the constraint...
> assertTrue(result);
>
>
> Any help will be appreciated.
Re: EMF Plugin [message #531812 is a reply to message #531622] Thu, 06 May 2010 09:22 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi esin

I don't understand what you mean by "add two mapping".

Your code looks reasonable. Two usages of allInstnaces _should_ not be a
problem.

You need to be much clearer about "it doesn't work"

does the parser crash
is it a syntax error
does the evaluator crash
does the evaluator give an unexpected result
?

Regards

Ed Willink


On 05/05/2010 16:44, esin wrote:
> Hi there, I am beginner at OCL on EMF. I am trying to test my OCL
> constraints. I have a trouble with the code below. I used
> "allInstances()" function in OCL constraint. I succeeded to run it by
> creating an extent map. But in the code below, I am using two
> "allInstances()" functions in my OCL code. For this reason, i think, i
> need to add two mapping to my ocl environment. But, it doesn't work when
> I put two entries into the ocl extend map.
>
> Do you have any idea?
>
> Here is my code:
>
> org.eclipse.ocl.expressions.OCLExpression query = helper
> .createQuery("RefinementNode.allInstances()->exists(rn|rn.refinementGoals- >includes(self))
> or Role.allInstances()->exists(ro|ro.goals->includes(self))");
>
> // sets the perform goal as a role goal...
> role.getGoals().add(performGoal);
> // create an extent map
> Map extents = new HashMap();
> Set environmentSet = new HashSet();
> environmentSet.add(role);
> extents.put(role.eClass(), environmentSet);
>
> environmentSet = new HashSet();
> environmentSet.add(refinementNode);
> extents.put(refinementNode.eClass(), environmentSet);
>
> ocl.setExtentMap(extents);
>
> // use the query expression parsed before to create a Query
> eval = ocl.createQuery(query);
> result = eval.check(performGoal);
>
> // Assert the constraint...
> assertTrue(result);
>
>
> Any help will be appreciated.
Re: EMF Plugin [message #531838 is a reply to message #531812] Thu, 06 May 2010 10:51 Go to previous messageGo to next message
Esin Karabacakoglu is currently offline Esin KarabacakogluFriend
Messages: 11
Registered: May 2010
Location: Turkey
Junior Member
Hi everybody,
Thanks for your replies. After asking my previous question, I realized that, my problem is about the "adding mappings into the ocl's extent map containing the environment( through setExtentMap() function)". For that reason, the evaluator gives an unexpected result. I expect the "eval.check(performGoal)" function's result as TRUE, however it gives as a result FALSE. Fortunatelly, i noticed that, if I use OR (which is the subclass of the RefinementNode) instead of using RefinementNode ( which is abstract class) in the OCL constraint, the check function's result comes TRUE.

Now my new question is how can I map these whole environment items in an easiest way?

Here is my working code:
public void danglingPerformGoalConstraintTest() throws Exception {
		// Creates an organization diagram that contains dangling perform
		// goal...
		// creates Perform Goal instance...
		PerformGoal performGoal = OrganizationFactory.eINSTANCE
				.createPerformGoal();

		// creates an Organization diagram instance...
		Organization organization = OrganizationFactory.eINSTANCE
				.createOrganization();

		// creates a Role instance...
		Role role = OrganizationFactory.eINSTANCE.createRole();

		// crates a Refinement node instance...
		OR refinementNode = OrganizationFactory.eINSTANCE.createOR();

		// add elements..
		organization.getRoles().add(role);
		organization.getGoals().add(performGoal);
		organization.getRefinementNodes().add(refinementNode);

		// sets the perform goal as a role goal...
		refinementNode.getRefinementGoals().add(performGoal);

		// mapping...
		Map extents = new HashMap();
		Set environmentSet = new HashSet();
		environmentSet.add(role);
		Set environmentSet2 = new HashSet();
		environmentSet2.add(refinementNode);
		extents.put(role.eClass(), environmentSet);
		extents.put(refinementNode.eClass(), environmentSet2);

		// create an OCL instance for Ecore
		OCL ocl;
		ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
		// create an OCL helper object
		OCLHelper helper = ocl.createOCLHelper();
		// set the OCL context classifier
		helper.setContext(OrganizationPackage.eINSTANCE.getPerformGoal());
		org.eclipse.ocl.expressions.OCLExpression query = helper
				.createQuery("(OR.allInstances()->exists(rn|rn.refinementGoals->includes(self))) or (Role.allInstances()->exists(ro|ro.goals->includes(self)))");

		ocl.setExtentMap(extents);
		// use the query expression parsed before to create a Query
		org.eclipse.ocl.Query eval = ocl.createQuery(query);
		boolean result = eval.check(performGoal);
		assertTrue(result);
	} 


And my new question's part is below, mapping it in an easier way:

// mapping...
		Map extents = new HashMap();
		Set environmentSet = new HashSet();
		environmentSet.add(role);
		Set environmentSet2 = new HashSet();
		environmentSet2.add(refinementNode);
		extents.put(role.eClass(), environmentSet);
		extents.put(refinementNode.eClass(), environmentSet2);
Re: EMF Plugin [message #532012 is a reply to message #531838] Thu, 06 May 2010 18:23 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi esin

It is far from clear what needs to be made easier.

Your hard code is only 7 line including one-off initialisation and
one-line per addition.

A helper function for the initialisation will just trade lines.

A helper function for the addition will be mode that one line.

At a complete guess, you might choose to an Extents class that
encapsulates your interactions.

Regards

Ed Willink

On 06/05/2010 11:51, esin wrote:
> Hi everybody,
> Thanks for your replies. After asking my previous question, I realized
> that, my problem is about the "adding mappings into the ocl's extent map
> containing the environment( through setExtentMap() function)". For that
> reason, the evaluator gives an unexpected result. I expect the
> "eval.check(performGoal)" function's result as TRUE, however it gives as
> a result FALSE. Fortunatelly, i noticed that, if I use OR (which is the
> subclass of the RefinementNode) instead of using RefinementNode ( which
> is abstract class) in the OCL constraint, the check function's result
> comes TRUE.
> Now my new question is how can I map these whole environment items in an
> easiest way?
>
> Here is my working code:
>
> public void danglingPerformGoalConstraintTest() throws Exception {
> // Creates an organization diagram that contains dangling perform
> // goal...
> // creates Perform Goal instance...
> PerformGoal performGoal = OrganizationFactory.eINSTANCE
> .createPerformGoal();
>
> // creates an Organization diagram instance...
> Organization organization = OrganizationFactory.eINSTANCE
> .createOrganization();
>
> // creates a Role instance...
> Role role = OrganizationFactory.eINSTANCE.createRole();
>
> // crates a Refinement node instance...
> OR refinementNode = OrganizationFactory.eINSTANCE.createOR();
>
> // add elements..
> organization.getRoles().add(role);
> organization.getGoals().add(performGoal);
> organization.getRefinementNodes().add(refinementNode);
>
> // sets the perform goal as a role goal...
> refinementNode.getRefinementGoals().add(performGoal);
>
> // mapping...
> Map extents = new HashMap();
> Set environmentSet = new HashSet();
> environmentSet.add(role);
> Set environmentSet2 = new HashSet();
> environmentSet2.add(refinementNode);
> extents.put(role.eClass(), environmentSet);
> extents.put(refinementNode.eClass(), environmentSet2);
>
> // create an OCL instance for Ecore
> OCL ocl;
> ocl = OCL.newInstance(EcoreEnvironmentFactory.INSTANCE);
> // create an OCL helper object
> OCLHelper helper = ocl.createOCLHelper();
> // set the OCL context classifier
> helper.setContext(OrganizationPackage.eINSTANCE.getPerformGo al());
> org.eclipse.ocl.expressions.OCLExpression query = helper
> .createQuery("(OR.allInstances()->exists(rn|rn.refinementGoals- >includes(self)))
> or (Role.allInstances()->exists(ro|ro.goals->includes(self))) ");
>
> ocl.setExtentMap(extents);
> // use the query expression parsed before to create a Query
> org.eclipse.ocl.Query eval = ocl.createQuery(query);
> boolean result = eval.check(performGoal);
> assertTrue(result);
> }
> And my new question's part is below, mapping it in an easier way:
>
>
> // mapping...
> Map extents = new HashMap();
> Set environmentSet = new HashSet();
> environmentSet.add(role);
> Set environmentSet2 = new HashSet();
> environmentSet2.add(refinementNode);
> extents.put(role.eClass(), environmentSet);
> extents.put(refinementNode.eClass(), environmentSet2);
>
Previous Topic:integration the OCL validation in EMF generated editor
Next Topic:Cannot find operation alloOwnedElements()
Goto Forum:
  


Current Time: Thu Apr 18 14:44:35 GMT 2024

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

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

Back to the top