Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » [OCLInEcore] Defining Helper Operations in Java
[OCLInEcore] Defining Helper Operations in Java [message #659393] Sun, 13 March 2011 15:21 Go to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hello all,

I would like to develop helper operations in java on type like string. I found the topic "Customizing the Environment" in the OCL Help. Is there a way to use this with OCLInEcore? If I understand right I would need to find the place where the template generates this line of code

OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject> ocl;
ocl = OCL.newInstance(new EnvironmentFactory());


and replace it with my EnvironmentFactory. Is this right? Is there a way to replace the used EnvironmentFactory by using an Annotation etc? Is there an completely alternative way to do this?

Thanks

Ralph
Re: [OCLInEcore] Defining Helper Operations in Java [message #659400 is a reply to message #659393] Sun, 13 March 2011 16:04 Go to previous messageGo to next message
Axel Uhl is currently offline Axel UhlFriend
Messages: 41
Registered: July 2009
Member
Adding operations to String AFAIK would require enhancing the stdlib including the stdlib model. If you just need a java-implemented operation with string arguments and return you may consider adding such operation on an score-modeled class, implement it in java and navigate to such an instance from you OCL expression, then invoke the helper method.
Hth,
-- Axel
Re: [OCLInEcore] Defining Helper Operations in Java [message #659404 is a reply to message #659393] Sun, 13 March 2011 16:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Ralph

Customizing the MDT/OCL 1.x, 3.0 releases is hard and one of the
motivations for the introduction of a true library model in the MDT/OCL
3.1 examples. Here you will find the Xtext concrete syntax of the
library model in OCLstdlib-2.4.oclstdlib is:

type String : PrimitiveType conformsTo OclAny {
operation "="(object2 : OclAny) : Boolean precedence=EQUALITY =>
'org.eclipse.ocl.examples.library.oclany.OclAnyEqualOperatio n';
operation "<>"(object2 : OclAny) : Boolean precedence=EQUALITY =>
'org.eclipse.ocl.examples.library.oclany.OclAnyNotEqualOpera tion';
operation "+"(s : String) : String precedence=ADDITIVE =>
'org.eclipse.ocl.examples.library.string.StringConcatOperati on';
operation at(i : Integer) : String =>
'org.eclipse.ocl.examples.library.string.StringAtOperation';
operation characters() : Sequence(String) =>
'org.eclipse.ocl.examples.library.string.StringCharactersOpe ration';
operation concat(s : String) : String =>
'org.eclipse.ocl.examples.library.string.StringConcatOperati on';
operation equalsIgnoreCase(s : String) : Boolean =>
'org.eclipse.ocl.examples.library.string.StringEqualsIgnoreC aseOperation';
operation indexOf(s : String) : Integer =>
'org.eclipse.ocl.examples.library.string.StringIndexOfOperat ion';
operation size() : Integer =>
'org.eclipse.ocl.examples.library.string.StringSizeOperation ';
operation substring(lower : Integer, upper : Integer) : String =>
'org.eclipse.ocl.examples.library.string.StringSubstringOper ation';
operation toBoolean() : Boolean =>
'org.eclipse.ocl.examples.library.string.StringToBooleanOper ation';
operation toInteger() : Integer =>
'org.eclipse.ocl.examples.library.string.StringToIntegerOper ation';
operation toLower() : String =>
'org.eclipse.ocl.examples.library.string.StringToLowerCaseOp eration';
operation toLowerCase() : String =>
'org.eclipse.ocl.examples.library.string.StringToLowerCaseOp eration';
operation toReal() : Real =>
'org.eclipse.ocl.examples.library.string.StringToRealOperati on';
operation toString() : String =>
'org.eclipse.ocl.examples.library.oclany.OclAnyToStringOpera tion';
operation toUpper() : String =>
'org.eclipse.ocl.examples.library.string.StringToUpperCaseOp eration';
operation toUpperCase() : String =>
'org.eclipse.ocl.examples.library.string.StringToUpperCaseOp eration';
operation ">"(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringGreaterThanOp eration';
operation "<"(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringLessThanOpera tion';
operation "<="(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringLessThanEqual Operation';
operation ">="(s : String) : Boolean precedence=RELATIONAL =>
'org.eclipse.ocl.examples.library.string.StringGreaterThanEq ualOperation';
}

and this is 100% of the definition. The =>
'org.eclipse.ocl.examples.library.string.StringToRealOperati on' is the
binding of the library signature to the Java class; one class per
feature. Custom libraries are supported, so you could just clone and add
a couple of lines for your extra functions. There is an import statement
but I've yet to activate it so that you can add your own code; might
happen for Indigo.

---

If you're imaginative enough you may manage to insert features in the
current code, but I dont' know how to and wouldn't recommend it; for
full addition you need to add functionality in perhaps 7 places.

Don't know if that helps.

Regards

Ed Willink



On 13/03/2011 15:21, ralph. wrote:
> Hello all,
>
> I would like to develop helper operations in java on type like string.
> I found the topic "Customizing the Environment" in the OCL Help. Is
> there a way to use this with OCLInEcore? If I understand right I would
> need to find the place where the template generates this line of code
>
>
> OCL<?, EClassifier, ?, ?, ?, ?, ?, ?, ?, Constraint, EClass, EObject>
> ocl;
> ocl = OCL.newInstance(new EnvironmentFactory());
>
>
> and replace it with my EnvironmentFactory. Is this right? Is there a
> way to replace the used EnvironmentFactory by using an Annotation etc?
> Is there an completely alternative way to do this?
>
> Thanks
>
> Ralph
Re: [OCLInEcore] Defining Helper Operations in Java [message #659968 is a reply to message #659404] Wed, 16 March 2011 12:32 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

is there any example for the library model in OCL 3.1?

Thanks,

Ralph
Re: [OCLInEcore] Defining Helper Operations in Java [message #660058 is a reply to message #659968] Wed, 16 March 2011 16:54 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Ralph

The library is its own example, in particular all the implementations in
the library plugin.

Extension of the library by the user is in principle very easy, but not
yet fully developed.

I need to do it just for a clean release, so that the MDT/OCL typos of
toUpper() and toLower()
appear by default without polluting the standard library.

Regards

Ed Willink


On 16/03/2011 12:32, ralph. wrote:
> Hi,
>
> is there any example for the library model in OCL 3.1?
>
> Thanks,
>
> Ralph
Previous Topic:[Announce] MDT/OCL 3.1.0 M6 is now available
Next Topic:Re: OCL and Xtext combination
Goto Forum:
  


Current Time: Thu Apr 25 00:31:55 GMT 2024

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

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

Back to the top