Home » Modeling » OCL » OCL AuditRule Constraining a String Property
OCL AuditRule Constraining a String Property [message #53030] |
Fri, 21 March 2008 07:41  |
Eclipse User |
|
|
|
Originally posted by: martin.baus.web.de
Hi,
I'm new to OCL and can't get it right.
I'm trying to define an AuditRule Constraint for a Property with Type String
in my GMF Project.
But all the variants I tried with context, inv, post are not working.
What I need is a Constraint that defines that the String can only hold the
Characters
'0','1','2','3','4','5','6','7','8','9','[',']','{','}'
Can anyone show me how to define a constraint like this? Or maybe can give
me a link with informations on how to write OCL Constraints in Eclipse?
Thanks for your help.
Martin Baus
|
|
|
Re: OCL AuditRule Constraining a String Property [message #53136 is a reply to message #53030] |
Mon, 24 March 2008 11:32  |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Martin,
It sounds like you are defining OCL constraints in a GMF context. I have
included that newsgroup in this reply.
To my knowledge, GMF's Audit constraints don't use the concrete syntax for
constraint context, so you don't want the "context MyClass inv:" preamble
on your constraint. The GMF Wiki page has some pretty good documentation
about Audits for more information.
Concerning the OCL that you need to implement this particular constraint,
something like this might do:
let allowed : Set(String) =
Set{'0','1','2','3','4','5','6','7','8','9','[',']','{','}'} in
Sequence{1..self.name.size()}->forAll(i : Integer |
allowed->includes(self.name.substring(i, i)))
assuming that it is "self.name" that you want to constrain.
HTH,
Christian
Martin Baus wrote:
> Hi,
>
> I'm new to OCL and can't get it right.
>
> I'm trying to define an AuditRule Constraint for a Property with Type
> String in my GMF Project.
>
> But all the variants I tried with context, inv, post are not working.
>
> What I need is a Constraint that defines that the String can only hold the
> Characters
>
> '0','1','2','3','4','5','6','7','8','9','[',']','{','}'
>
> Can anyone show me how to define a constraint like this? Or maybe can give
> me a link with informations on how to write OCL Constraints in Eclipse?
>
> Thanks for your help.
>
>
> Martin Baus
|
|
|
Goto Forum:
Current Time: Fri May 02 14:36:22 EDT 2025
Powered by FUDForum. Page generated in 0.03451 seconds
|