Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Ocl expressions
Ocl expressions [message #876004] Wed, 23 May 2012 18:11 Go to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Hi guys!


I'm working with OCL expressions and I need a expression that
validate a string in the context that it starter with a letter and not
with caracteres as !,?,*,&,^%,$.


Some idea how can I do that?

I tried to do with a regular expression, but I had no success.

Thank's for the help and sorry for the english!
Re: Ocl expressions [message #876027 is a reply to message #876004] Wed, 23 May 2012 19:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4090
Registered: July 2009
Senior Member
Hi

With the Ecore-binding in Indigo; you have only substring.

With the Pivot-binding in Indigo; you also have characters(), at() to
play with.

In Juno, you have characters(), startsWith(), at(), match() to play with.

Regards

Ed Willink

On 23/05/2012 19:11, Pablo Silva wrote:
> Hi guys!
>
>
> I'm working with OCL expressions and I need a expression that
> validate a string in the context that it starter with a letter and not
> with caracteres as !,?,*,&,^%,$.
>
>
> Some idea how can I do that?
>
> I tried to do with a regular expression, but I had no success.
>
> Thank's for the help and sorry for the english!
Re: Ocl expressions [message #876030 is a reply to message #876027] Wed, 23 May 2012 19:31 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

In my case, I'm trying validate a name of the a node on my Ecore Model.
I'm using the interactive OCL console for try validate these expressions.

For example, I should create a expression as: self.name.startsWith('[a-zA-Z]')
Is this possible? OCL expressions accept regular expressions?
Re: Ocl expressions [message #876038 is a reply to message #876030] Wed, 23 May 2012 19:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4090
Registered: July 2009
Senior Member
Hi

And why would you think that startsWith takes a regular expression argument?

You really should consult some documentation or at least common sense.
What does Java do?

Regards

Ed Willink



On 23/05/2012 20:31, Pablo Silva wrote:
> In my case, I'm trying validate a name of the a node on my Ecore Model.
> I'm using the interactive OCL console for try validate these expressions.
>
> For example, I should create a expression as:
> self.name.startsWith('[a-zA-Z]')
> Is this possible? OCL expressions accept regular expressions?
Re: Ocl expressions [message #876054 is a reply to message #876004] Wed, 23 May 2012 20:23 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Because I'm a new user in the OCL.
I'm learning about that.

Actually I am trying to place restrictions on a GMF graphical editor that I created. But I want these restrictions are implemented in EMF Ecore Model, because then it will be easier to manage them.

I've done to restrictions such as the name of a Node can not be empty, or that two nodes can not have the same name.
Take a look in my Ecore Model open in OCLinEcore editor:


package my : my = 'my'
{
	class Graph
	{
		invariant NoDuplicateEdgeNames: edges->forAll(e1, e2 | e1 <> e2 implies e1.name <> e2.name);
		invariant NoDuplicateNodeNames: nodes->forAll(n1, n2 | n1 <> n2 implies n1.name <> n2.name);
		invariant NoMultiGraphs: edges->forAll(e1, e2 | e1 <> e2 implies (e1.start <> e2.start) or (e1.end <> e2.end));
		invariant NoSameOneNodes: edges->forAll( e1, e2 | e1 = e2 implies e1.start<>e1.end);
		property nodes : Node[*] { composes };
		property edges : Edge[*] { composes };
		attribute name : String[?];
		annotation 'gmf.diagram'(onefile = 'true', 'diagram.extension' = 'Graph');
	}
	class Node
	{
		invariant noEmptyName: self.name->notEmpty();
		invariant noInvalidCaracter:;
		attribute name : String[?];
		attribute startNode : Boolean[?];
		annotation 'gmf.node'(label = 'name', figure = 'ellipse');
	}
	class Edge
	{
		property start : Node[1];
		property end : Node[1];
		attribute name : String[?];
		annotation 'gmf.link'(label = 'name', source = 'start', target = 'end', 'target.decoration' = 'arrow');
	}
}


All constraints are working, but I don't know how to do for to validate a name as I said before!

I can't find a document with all methods of OCL. If you could show me a link where
I can get this, I'll be grateful!

Pablo Silva
Re: Ocl expressions [message #876078 is a reply to message #876054] Wed, 23 May 2012 21:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4090
Registered: July 2009
Senior Member
Hi

Have you tried Help Contents OCL Documentation?

Have you tried the OCL specification?

Regards

Ed Willink


On 23/05/2012 21:23, Pablo Silva wrote:
> Because I'm a new user in the OCL.
> I'm learning about that.
>
> Actually I am trying to place restrictions on a GMF graphical editor
> that I created. But I want these restrictions are implemented in EMF
> Ecore Model, because then it will be easier to manage them.
>
> I've done to restrictions such as the name of a Node can not be empty,
> or that two nodes can not have the same name.
> Take a look in my Ecore Model open in OCLinEcore editor:
>
>
>
> package my : my = 'my'
> {
> class Graph
> {
> invariant NoDuplicateEdgeNames: edges->forAll(e1, e2 | e1 <>
> e2 implies e1.name <> e2.name);
> invariant NoDuplicateNodeNames: nodes->forAll(n1, n2 | n1 <>
> n2 implies n1.name <> n2.name);
> invariant NoMultiGraphs: edges->forAll(e1, e2 | e1 <> e2
> implies (e1.start <> e2.start) or (e1.end <> e2.end));
> invariant NoSameOneNodes: edges->forAll( e1, e2 | e1 = e2
> implies e1.start<>e1.end);
> property nodes : Node[*] { composes };
> property edges : Edge[*] { composes };
> attribute name : String[?];
> annotation 'gmf.diagram'(onefile = 'true', 'diagram.extension'
> = 'Graph');
> }
> class Node
> {
> invariant noEmptyName: self.name->notEmpty();
> invariant noInvalidCaracter:;
> attribute name : String[?];
> attribute startNode : Boolean[?];
> annotation 'gmf.node'(label = 'name', figure = 'ellipse');
> }
> class Edge
> {
> property start : Node[1];
> property end : Node[1];
> attribute name : String[?];
> annotation 'gmf.link'(label = 'name', source = 'start', target
> = 'end', 'target.decoration' = 'arrow');
> }
> }
>
> All constraints are working, but I don't know how to do for to
> validate a name as I said before!
>
> I can't find a document with all methods of OCL. If you could show me
> a link where
> I can get this, I'll be grateful!
>
> Pablo Silva
>
Re: Ocl expressions [message #878702 is a reply to message #876004] Tue, 29 May 2012 19:12 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

Thank's for the Help.
I gonna read the OCL specification.

Att.

Pablo Silva
Re: Ocl expressions [message #879340 is a reply to message #878702] Thu, 31 May 2012 02:26 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

I have a question!

Can I in a let expression in OCL applied recursively?

[Updated on: Thu, 31 May 2012 02:27]

Report message to a moderator

Re: Ocl expressions [message #879386 is a reply to message #879340] Thu, 31 May 2012 05:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4090
Registered: July 2009
Senior Member
Hi

Yes, you can do

let a : A = ... in let b: B = ... in ....

but beware of complex usages such as

y + z + let a : A = ... in let b: B = ... in a + b + x

that are challenging to the reader and also to the OCL parser. The above
should be treated as

y + z + (let a : A = ... in (let b: B = ... in (a + b + x)))

but use parentheses for portability and readability.

You may prefer a multi-variable let

let a : A = ... ,
b : B = ...
in ....

Regards

Ed Willink

On 31/05/2012 03:26, Pablo Silva wrote:
> I have a question!
>
> In a let expression in OCL can be applied recursively?
Re: Ocl expressions [message #879725 is a reply to message #879386] Thu, 31 May 2012 18:18 Go to previous messageGo to next message
Pablo Silva is currently offline Pablo Silva
Messages: 28
Registered: May 2012
Location: Brazil
Junior Member

I try to do this expression:

def:validate(n:Integer):Boolean =
(self.name.substring(n,n)<='@' or self.name.substring(n,n)>='[') and (self.name.substring(n,n)<='`' or self.name.substring(n,n)>='{')= true  
inv: let tam:Integer = self.name.size() in
validate(tam)


But is wrong. I would like to know if I can do that, i.e., use a def like a function?

Thank's for the help.
Re: Ocl expressions [message #879764 is a reply to message #879725] Thu, 31 May 2012 19:46 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4090
Registered: July 2009
Senior Member
Hi

You can certainly use def: to define an operation; that's what it is for.

But as in my answer on the other newsgroup you must use String not
'Character'.

Regards

Ed Willink

On 31/05/2012 19:18, Pablo Silva wrote:
> I try to do this expression:
>
> def:validate(n:Integer):Boolean =
> (self.name.substring(n,n)<='@' or self.name.substring(n,n)>='[') and
> (self.name.substring(n,n)<='`' or self.name.substring(n,n)>='{')=
> true inv: let tam:Integer = self.name.size() in
> validate(tam)
>
> But is wrong. I would like to know if I can do that, i.e., use a def
> like a function?
>
> Thank's for the help.
Previous Topic:Traversing from child to parent in derived relation
Next Topic:Problems parsing ocl query
Goto Forum:
  


Current Time: Wed Oct 22 08:10:59 GMT 2014

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

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