Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Adding new operation in OCL standard library
Adding new operation in OCL standard library [message #1085865] Tue, 13 August 2013 13:30 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
i want to add an operation in standard ocl library. The signature of operation is like

real operation(real, real)

I am uncertain about categorizing this operation. This is neither a collection operation nor operation for numeric types(x.floor(), x.abs(), etc)

i want to use it like

let x : Real = operation(20, 2)

Can you please guide me under which category i should define this operation? Should i define it under OclAny category?

Regards,

[Updated on: Tue, 13 August 2013 13:39]

Report message to a moderator

Re: Adding new operation in OCL standard library [message #1085884 is a reply to message #1085865] Tue, 13 August 2013 13:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

I don't know what a category is.

See my response on "Re: enabling OCL to parse user definded functions"

Regards

Ed Willink


On 13/08/2013 14:30, ModelGeek Mising name wrote:
> i want to add an operation in standard ocl library. The signature of
> operation is like
>
> real operation(real, real)
>
> I am uncertain about categorizing this operation. This is nor a
> collection operation neither operation for numeric types(x.floor(),
> x.abs(), etc)
> i want to use it like
>
> let x : Real = operation(20, 2)
>
> Can you please guide me under which category i should define this
> operation? Should i define it under OclAny category?
>
> Regards,
Re: Adding new operation in OCL standard library [message #1086511 is a reply to message #1085884] Wed, 14 August 2013 09:36 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
I meant context by category

like

real.abs() has Real as context and collection opertions have Collection context.

I do not want to have context like real.abs()

i want to use following OCL "let x : Real = myoperation(100,2) in x"

where i have defined operation in standard library under
type OclAny : AnyType {
annotation 'http://www.omg.org/ocl'(ClassGroup='OCL');

operation myoperation(a: Real, b: Real) : Real => 'path to implementation class';
.......
......
}

but i am getting following exceptions...

org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'let x : Real = myoperation(100,2) in x'
1: Unresolved Operation '::myoperation(UnlimitedNatural, UnlimitedNatural)'
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:171)
at org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:120)
at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:124)
at oclextplugin.ext.OCLStdLibTest.<init>(OCLStdLibTest.java:85)
at oclextplugin.View.createPartControl(View.java:71)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityView.createPartControl(CompatibilityView.java:174)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)


Do you have any idea why is that?

[Updated on: Wed, 14 August 2013 09:38]

Report message to a moderator

Re: Adding new operation in OCL standard library [message #1086521 is a reply to message #1086511] Wed, 14 August 2013 09:45 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
HI

Please attach a zipped project so that I can see what you're doing.

Regards

Ed Willink


On 14/08/2013 10:36, ModelGeek Mising name wrote:
> I meant context by category
>
> like
> real.abs() has Real as context and collection opertions have
> Collection context.
>
> I do not want to have context like real.abs()
>
> i want to use following OCL "let x : Real = myoperation(100,2) in x"
>
> where i have defined operation in standard library under type OclAny :
> AnyType {
> annotation 'http://www.omg.org/ocl'(ClassGroup='OCL');
>
> operation myoperation(mean: Real, sd: Real) : Real => 'path to
> implementation class';
> .......
> ......
> }
>
> but i am getting following exceptions...
>
> org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'let x :
> Real = myoperation(100,2) in x'
> 1: Unresolved Operation '::myoperation(UnlimitedNatural,
> UnlimitedNatural)'
> at
> org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:171)
> at
> org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:120)
> at
> org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:124)
> at oclextplugin.ext.OCLStdLibTest.<init>(OCLStdLibTest.java:85)
> at oclextplugin.View.createPartControl(View.java:71)
> at
> org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)
> at
> org.eclipse.ui.internal.e4.compatibility.CompatibilityView.createPartControl(CompatibilityView.java:174)
> at
> org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
>
>
> Do you have any idea why is that?
Re: Adding new operation in OCL standard library [message #1086568 is a reply to message #1086521] Wed, 14 August 2013 11:16 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
I have attached org.eclipse.ocl.examples.library plugin as zip and it contains OCL standard library. I have added following into it

AnyType {
annotation 'http://www.omg.org/ocl'(ClassGroup='OCL');
........
.........
operation myoperation(a: Real, b: Real) : Real => 'org.eclipse.ocl.examples.library.oclany.MyOperation';
}


and i am using following code to test newly added operation in OCL standard library.

org.eclipse.ocl.examples.pivot.OCL ocl = org.eclipse.ocl.examples.pivot.OCL.newInstance();
org.eclipse.ocl.examples.pivot.helper.OCLHelper helper = ocl.createOCLHelper();
ExpressionInOCL exp = helper.createQuery("let x : Real = myoperation(100,2) in x");
Query q = ocl.createQuery(exp);
System.out.println("result = " + q.evaluate());

i am getting following exception

org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'let x : Real = myoperation(100,2) in x'
1: Unresolved Operation '::myoperation(UnlimitedNatural, UnlimitedNatural)'
at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:171)
at org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:120)
at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:124)
at oclextplugin.ext.OCLStdLibTest.<init>(OCLStdLibTest.java:85)


Regards,
Re: Adding new operation in OCL standard library [message #1086756 is a reply to message #1086568] Wed, 14 August 2013 17:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are not adding to the OCL Standard Library, you are replacing it.
You therefore have to make sure that you use your artefacts rather than
those avialbale from the installed version. You haven't chnaged the
nsURI either.

You should extend the library not replace it. If you replace it use a
new nsURI.

Regards

Ed Willink




On 14/08/2013 12:16, ModelGeek Mising name wrote:
> I have attached org.eclipse.ocl.examples.library plugin as zip and it contains OCL standard library. I have added following into it
>
> AnyType {
> annotation 'http://www.omg.org/ocl'(ClassGroup='OCL');
> ........
> .........
> operation myoperation(a: Real, b: Real) : Real => 'org.eclipse.ocl.examples.library.oclany.MyOperation';
> }
>
>
> and i am using following code to test newly added operation in OCL standard library.
>
> org.eclipse.ocl.examples.pivot.OCL ocl = org.eclipse.ocl.examples.pivot.OCL.newInstance();
> org.eclipse.ocl.examples.pivot.helper.OCLHelper helper = ocl.createOCLHelper();
> ExpressionInOCL exp = helper.createQuery("let x : Real = myoperation(100,2) in x");
> Query q = ocl.createQuery(exp);
> System.out.println("result = " + q.evaluate());
>
> i am getting following exception
>
> org.eclipse.ocl.examples.pivot.SemanticException: Errors in 'let x : Real = myoperation(100,2) in x'
> 1: Unresolved Operation '::myoperation(UnlimitedNatural, UnlimitedNatural)'
> at org.eclipse.ocl.examples.pivot.utilities.PivotUtil.checkResourceErrors(PivotUtil.java:171)
> at org.eclipse.ocl.examples.pivot.context.AbstractParserContext.parse(AbstractParserContext.java:120)
> at org.eclipse.ocl.examples.pivot.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:124)
> at oclextplugin.ext.OCLStdLibTest.<init>(OCLStdLibTest.java:85)
>
>
> Regards,
Re: Adding new operation in OCL standard library [message #1087161 is a reply to message #1086756] Thu, 15 August 2013 08:07 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Hi,

I have added some other operation (some under collection context and some for primitive types like integer and real) and they are working fine. This is the first operation i tried to add under OCLAny context.

I have tried to change uri from http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib to http://www.eclipse.org/ocl/3.1.1/OCL.oclstdlib
After doing that when i try to run GenerateOCLstdlibModel.mwe2 then i get the following exception

0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Using resourceSet registry. The registered Packages will not be registered in the global EPackage.Registry.INSTANCE!
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'C:\Users\KhurramS\git\kepler\org.eclipse.ocl\examples'
2809 [main] INFO ld.utilities.OCLstdlibCodeGenerator - Loading OCL library 'platform:/resource/org.eclipse.ocl.examples.library/model/OCL-2.4.oclstdlib
17443 [main] INFO ld.utilities.OCLstdlibCodeGenerator - Generating to ' C:\Users\KhurramS\git\kepler\org.eclipse.ocl\examples\org.eclipse.ocl.examples.pivot\emf-gen\org\eclipse\ocl\examples\pivot\model'
20205 [main] INFO ild.utilities.Model2tablesGenerator - Loading Gen Model 'platform:/resource/org.eclipse.ocl.examples.library/model/oclstdlib.genmodel
22125 [main] INFO ild.utilities.Model2tablesGenerator - Generating to ' C:\Users\KhurramS\git\kepler\org.eclipse.ocl\examples\org.eclipse.ocl.examples.library\emf-gen'
23155 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems running workflow GenerateOCLstdlibModel: Problems running Model2tablesGenerator
java.lang.RuntimeException: Problems running workflow GenerateOCLstdlibModel: Problems running Model2tablesGenerator
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:104)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:62)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.lang.RuntimeException: Problems running Model2tablesGenerator
at org.eclipse.ocl.examples.build.utilities.Model2tablesGenerator.invokeInternal(Model2tablesGenerator.java:112)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:126)
at org.eclipse.emf.mwe.core.lib.Mwe2Bridge.invoke(Mwe2Bridge.java:34)
at org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent.invoke(AbstractWorkflowComponent.java:201)
at org.eclipse.emf.mwe2.runtime.workflow.AbstractCompositeWorkflowComponent.invoke(AbstractCompositeWorkflowComponent.java:35)
at org.eclipse.emf.mwe2.runtime.workflow.Workflow.run(Workflow.java:19)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:102)
... 4 more
Caused by: java.lang.UnsupportedOperationException
at org.eclipse.ocl.examples.pivot.manager.MetaModelManager.getType(MetaModelManager.java:2324)
at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTablesUtils.getAllSuperClasses(OCLinEcoreTablesUtils.java:648)
at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTablesUtils.getAllSupertypesSortedByName(OCLinEcoreTablesUtils.java:633)
at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTables.declareFragments(OCLinEcoreTables.java:216)
at org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTables.generateTablesClass(OCLinEcoreTables.java:902)
at org.eclipse.ocl.examples.build.utilities.Model2tablesGenerator.invokeInternal(Model2tablesGenerator.java:105)
... 10 more

I have also tried to extend OCL standard library, in that case GenerateOCLstdlibModel.mwe2 runs fine but it generate lot of problematic code in emf-gen folder of pivot plugin
Re: Adding new operation in OCL standard library [message #1087167 is a reply to message #1086756] Thu, 15 August 2013 08:17 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
I have also tried to extend like

import 'OCL-2.4.oclstdlib';
library ocl : ocl = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'{
type Integer : PrimitiveType conformsTo Real {
operation test() : Integer =>'org.eclipse.ocl.examples.library.numeric.TestNumericOperation';
}
}

and i changed the GenerateOCLstdlibModel.mwe2 to point to new ocl standard library file.

import org.eclipse.ocl.examples.build.utilities.*
import org.eclipse.emf.mwe.utils.*
import org.eclipse.emf.mwe.utils.*
import org.eclipse.emf.ecore.resource.impl.*

var sourceName = "org.eclipse.ocl.examples.library"
var targetName = "org.eclipse.ocl.examples.pivot"

/**
* Generate the OCLstdlib Model, by converting oclstdlib.oclstdlib to OCLstdlib.java.
*/
Workflow {
bean = ResourceSetImpl : resourceSet {}
bean = StandaloneSetup { resourceSet = resourceSet
platformUri = ".."
}
component = OCLstdlibCodeGenerator { resourceSet = resourceSet
uri = "http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib"
//libraryFile = "/${sourceName}/model/OCL-2.4.oclstdlib"
libraryFile = "/${sourceName}/model/extendedOCL.oclstdlib"
javaFolder = "/${targetName}/emf-gen"
javaPackageName = "${targetName}.model"
javaClassName = "OCLstdlib"
}
component = Model2tablesGenerator { resourceSet = resourceSet
genModelFile = "/${sourceName}/model/oclstdlib.genmodel"
genOCLstdlib = true
}
}


it gives me following error

7257 [main] ERROR .examples.build.acceleo.NameQueries - getPrefixedSymbolName for 'orphans'and null

process completes with out any exception but OCLstdlib.java file does not contains methods like installCollectionTypes, installMetaclasses etc and obviously this means compilation errors.

can you please identify the problem here.

thanks!
Re: Adding new operation in OCL standard library [message #1087182 is a reply to message #1087167] Thu, 15 August 2013 08:49 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You are using 'examples' code that has not been released and lacks
tutorials and in many cases going beyond what is supported.

I am afraid that at present I have very limited time and so can only
answer simple queries. Yours are not simple, so you'll have to help
yourself.

Sorry.

Regards

Ed Willink


On 15/08/2013 09:17, ModelGeek Mising name wrote:
> I have also tried to extend like
>
> import 'OCL-2.4.oclstdlib';
> library ocl : ocl = 'http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib'{
> type Integer : PrimitiveType conformsTo Real {
> operation test() : Integer
> =>'org.eclipse.ocl.examples.library.numeric.TestNumericOperation';
> }
> }
>
> and i changed the GenerateOCLstdlibModel.mwe2 to point to new ocl
> standard library file.
>
> import org.eclipse.ocl.examples.build.utilities.*
> import org.eclipse.emf.mwe.utils.*
> import org.eclipse.emf.mwe.utils.*
> import org.eclipse.emf.ecore.resource.impl.*
>
> var sourceName = "org.eclipse.ocl.examples.library"
> var targetName = "org.eclipse.ocl.examples.pivot"
>
> /**
> * Generate the OCLstdlib Model, by converting oclstdlib.oclstdlib
> to OCLstdlib.java.
> */
> Workflow {
> bean = ResourceSetImpl : resourceSet {}
> bean = StandaloneSetup { resourceSet = resourceSet
> platformUri = ".."
> }
> component = OCLstdlibCodeGenerator { resourceSet = resourceSet
> uri = "http://www.eclipse.org/ocl/3.1.0/OCL.oclstdlib"
> //libraryFile = "/${sourceName}/model/OCL-2.4.oclstdlib"
> libraryFile = "/${sourceName}/model/extendedOCL.oclstdlib"
> javaFolder = "/${targetName}/emf-gen"
> javaPackageName = "${targetName}.model"
> javaClassName = "OCLstdlib"
> }
> component = Model2tablesGenerator { resourceSet = resourceSet
> genModelFile = "/${sourceName}/model/oclstdlib.genmodel"
> genOCLstdlib = true
> }
> }
>
>
> it gives me following error
>
> 7257 [main] ERROR .examples.build.acceleo.NameQueries -
> getPrefixedSymbolName for 'orphans'and null
>
> process completes with out any exception but OCLstdlib.java file does
> not contains methods like installCollectionTypes, installMetaclasses
> etc and obviously this means compilation errors.
>
> can you please identify the problem here.
>
> thanks!
Re: Adding new operation in OCL standard library [message #1087199 is a reply to message #1087182] Thu, 15 August 2013 09:16 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Yes i can understand.

i would like to ask one simple question then

i have defined myoperation under OCLAny

"let x : Real = myoperation(100,2) in x" does not work and gives exception

but "let x : Real = 10 in x.myoperation(100,2)" works perfecly

and also "let x : Real = OclAny.myoperation(100,2) in x" works perfectly

do you have any clue why first ocl statement myoperation is not recognized?

thanks for your help!

regards,

[Updated on: Thu, 15 August 2013 09:29]

Report message to a moderator

Re: Adding new operation in OCL standard library [message #1087276 is a reply to message #1087199] Thu, 15 August 2013 11:55 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Because from what I have seen you have a very tangled mixture of
standard and extended functionality, it is impossible to give a quick
answer as to whether the problem is due to the tangle, a bug in your
code or a bug in the underlying code.

Regards

Ed Willink

On 15/08/2013 10:16, ModelGeek Mising name wrote:
> Yes i can understand.
>
> i would like to ask one simple question then
>
> i have defined myoperation under OCLAny
>
> let x : Real = myoperation(100,2) in x does not work and gives exception
> but let x : Real = 10 in x.myoperation(100,2) works perfecly
>
> do you have any clue why first ocl statement myoperation is not
> recognized?
>
> thanks for your help!
>
> regards,
Previous Topic:Error messages of the Audit Rule not shown!!!!
Next Topic:[Announce] Eclipse OCL 4.1.1 RC1 and OCL 4.2.0 M1 are available.
Goto Forum:
  


Current Time: Sat Apr 20 03:19:26 GMT 2024

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

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

Back to the top