Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » [CompleteOCL] Accessing the metamodel
[CompleteOCL] Accessing the metamodel [message #726044] Fri, 16 September 2011 13:17 Go to next message
Ambros Morscher is currently offline Ambros MorscherFriend
Messages: 28
Registered: June 2010
Junior Member
Hi all,

I am using CompleteOCL documents to enrich my UML model with OCL constraints. This works quite fine.

Now i want to have access to the OCL constraints packages and contexts in the CompleteOCL document. Therefore I instanceiated a CompleteOCL xtext resource and navigated through the content tree of the resource. I found all elements needed in the resource.
What i didn't manage was to access elements from my UML model. For example i want to get the name or element of my OCL context. I found no way to get it from the ClassifierContextDeclCS instance of the xText resource. Here an example of my ocl file

package packa::subpack
context ElementA
	inv checkName :
	let name :String = self.name in
	 	name.size()<=12 

endpackage


How can I retrieve the context "ElementA" from the CompleteOCL file. Has this something to do with the pivot model?
Can anyone please give me some hints how to retrieve this information ?

Thanks Ambros
Re: [CompleteOCL] Accessing the metamodel [message #726062 is a reply to message #726044] Fri, 16 September 2011 13:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Ambros

I think you want self.oclType()...

The specification of oclType() has changed editorially in every version
of OCL 2.x, although the narrow intent is clear. OCL 2.4 (and Eclipse
OCL 3.2) may have a fully reflective oclType(). Eclipse OCL 3.1's
implementation of oclType() for the pivot meta-model is well on the way
to being reflective, so self.oclType().ownedType may work. You may just
want self.oclType().name.

Regards

Ed Willink


On 16/09/2011 14:17, Ambros Morscher wrote:
> Hi all,
>
> I am using CompleteOCL documents to enrich my UML model with OCL
> constraints. This works quite fine.
>
> Now i want to have access to the OCL constraints packages and contexts
> in the CompleteOCL document. Therefore I instanceiated a CompleteOCL
> xtext resource and navigated through the content tree of the resource.
> I found all elements needed in the resource.
> What i didn't manage was to access elements from my UML model. For
> example i want to get the name or element of my OCL context. I found
> no way to get it from the ClassifierContextDeclCS instance of the
> xText resource. Here an example of my ocl file
>
> package packa::subpack
> context ElementA
> inv checkName :
> let name :String = self.name in
> name.size()<=12
> endpackage
>
>
> How can I retrieve the context "ElementA" from the CompleteOCL file.
> Has this something to do with the pivot model?
> Can anyone please give me some hints how to retrieve this information ?
>
> Thanks Ambros
Re: [CompleteOCL] Accessing the metamodel [message #726663 is a reply to message #726062] Mon, 19 September 2011 08:19 Go to previous messageGo to next message
Ambros Morscher is currently offline Ambros MorscherFriend
Messages: 28
Registered: June 2010
Junior Member
Hi Edward,

Thank you for your quick answer unfortunately this is not what I was looking for. In order to clarify here is the code how I access contraints from the Complete OCL resrouce.

CompleteOCLDocumentCS completeOCLDocument = (CompleteOCLDocumentCS)oclResource.getContents().get(0);
for(PackageDeclarationCS packageDecl :completeOCLDocument.getPackages()){
    for (org.eclipse.ocl.examples.xtext.completeocl.completeOCLCST.ContextDeclCS ctx:packageDecl.getContexts()){
        //get the name of the context
    }
}


In the second "FOR" loop I navigate through the contexts of my package declaration. How can I acces the name or type of the context using the ctx variable.

Thanks again.

Ambros Morscher
Re: [CompleteOCL] Accessing the metamodel [message #726846 is a reply to message #726663] Mon, 19 September 2011 17:00 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Ambros

You are navigating the the Concrete Syntax resource which is a
proprietary model. For Essential OCL, the OCL specification defines a
non-normative model, for Complete OCL the specification defines nothing.
The new Eclipse OCL Concrete Syntax models are designed for ease of use
with Xtext and so referenced nodes exist as references that Xtext
initialises with proxies and resolves to the required elements. You can
recover the text behind the CS elements using ElementUtil.getText(). It
is possible that the new CS models may influence the missing
non-normative specifications for OCL 2.4.

Navigating the proprietary CS is not recommended. You should navigate
the Abstract Syntax pivot model, which is close to the OCL
specification, and arguably beyond the OCL specification since the pivot
model prototypes UML-alignment and other solutions that may be approved
for OCL 2.4.

Most CS nodes have a 'pivot' property that identifies the corresponding
AST node. If you want to navigate this with type 'safety' you may use
PivotUtil.getPivot().

In the pivot model you should find one Package per PackageDeclarationCS
and merged Classes for multiple ClassifierContextDeclCSes. The Package
for the Complete OCL PackageDeclarationCS is not merged with an
equivalently named Package from perhaps OCLinEcore, rather it sits
alongside. Methods in the TypeManager facilitate treatment of multiple
merged contributions as a single coherent element.

If you really want to see multiple 'context Xyzzy' as multiple nodes you
do need to navigate the ClassifierContextDeclCS. However if you are
really more interested in the Xyzzy class, then the pivot is more useful.

If you invoke
C2Pivot.findAdapter(completeOCLDocument.eResource().getResourceSet())
you will get the CS 2 AS conversion controller that provides a variety
of useful facilities for interacting with the CS and AS.

Regards

Ed Willink

On 19/09/2011 09:19, Ambros Morscher wrote:
> Hi Edward,
>
> Thank you for your quick answer unfortunately this is not what I was
> looking for. In order to clarify here is the code how I access
> contraints from the Complete OCL resrouce.
>
>
> CompleteOCLDocumentCS completeOCLDocument =
> (CompleteOCLDocumentCS)oclResource.getContents().get(0);
> for(PackageDeclarationCS packageDecl :completeOCLDocument.getPackages()){
> for
> (org.eclipse.ocl.examples.xtext.completeocl.completeOCLCST.ContextDeclCS
> ctx:packageDecl.getContexts()){
> //get the name of the context
> }
> }
>
>
> In the second "FOR" loop I navigate through the contexts of my package
> declaration. How can I acces the name or type of the context using the
> ctx variable.
>
> Thanks again.
>
> Ambros Morscher
Previous Topic:OCL for InstanceSpecifications on M1
Next Topic:Ecore2OCLinEcore
Goto Forum:
  


Current Time: Thu Apr 18 11:39:36 GMT 2024

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

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

Back to the top