Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How to get the elements of OCL document (.ocl)
How to get the elements of OCL document (.ocl) [message #731348] Fri, 30 September 2011 17:31 Go to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi,

How can I access the elements [context, invariant, expressions, variables, operations and etc...] of the OCL document (OCLInput, ".ocl") that are related to my uml model?

I know that i need parse the document, something like this:

OCL myOCL = OCL.newInstance(myresourceSet)
myOCL.parse(OCLInput);

Until here, everything is fine. But after that, what i need to do?

Is the class Visitor used for this? How?

Is there some method with the parameter OCLInput to get the abstract sintax of the OCL document. How can i manipulate the constructs of the ocl expressions in the document?

ps: the ocl constraints are related to uml model. So: org.eclipse.ocl.uml is used.

Edward:

I had to transform my specific model in a UML model. So, now, my problem is how to get the elements in the document .ocl , that is related to the uml model.

Regards,
John

[Updated on: Tue, 18 October 2011 16:24]

Report message to a moderator

Re: How to get the elements of OCL document (.ocl) [message #731354 is a reply to message #731348] Fri, 30 September 2011 17:35 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member

This article is very confusing:

http://www.eclipse.org/articles/article.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html

IS there other source about this?

thanks
Re: How to get the elements of OCL document (.ocl) [message #731408 is a reply to message #731354] Fri, 30 September 2011 21:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi

It's certainly confusing. It's difficult/wrong to remove obsolete/old
material.

That article was part of preliminary work that led to the proposal for
an OCL Tools project. The project never materialized.

Similar, and I think distinctly superior, functionality is now available
in the OCL project; Xtext editors with overviews, and in Juno an
OCL2Java code generator.

See the OCLinEcore tutorial and other recent references from the project
summary/wiki documentation.

Regards

Ed Willink

On 30/09/2011 18:35, John wrote:
>
> This article is very confusing:
>
> http://www.eclipse.org/articles/article.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html
>
>
> IS there other source about this?
>
> thanks
Re: How to get the elements of OCL document (.ocl) [message #731467 is a reply to message #731348] Sat, 01 October 2011 05:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi John

The Complete OCL clause in the OMG specification is editorially and
technically incomplete. The Concrete Syntax classes are unmentioned and
the mechanism by which complementary declarations are merged into to the
complemented model is unspecified.

The traditional Eclipse OCL code for UML and Ecore bindings has a
proprietary CS which is converted to a list of Abstract Syntax
constraints returned from OCL.parse. I presume that you have looked at
these and found them to be unhelpful for your purpose; the constraints
are partially integrated into the complemented model by
additionalOperations and additionalProperties features in the classes.
If you want to get at the intermediate CS you should create a variant of
OCL.parse that stops before the analysis converts the CS to AS. I don't
recommend this since the underlying functionality is deficient and
should eventually be phased out in favour of the pivot model.

The new pivot-based Eclipse OCL code has an Xtext-based proprietary CS
which is converted to a (complementary) Package/Class/Feature hierarchy
that sits alongside the complemented Package/Class/Feature hierarchy.
This code is currently in examples plugins and of examples quality, but
may be more suitable for your purposes. You may either take the
Xtext-friendly CS model that closely resembles the source text, or the
complementary Packages, which should contain all the declarations, but
will lose some source information since all declarations for the same
context class appear in one class, rather than multiple contexts. This
should be possible but the external APIs have not yet been reviewed to
provide simple helpful facilities.

You may find some clues as to the rationale and operation of the pivot
model in http://gres.uoc.edu/OCL2011/pubs/ocl2011_submission_12.pdf.

Regards

Ed Willink


On 30/09/2011 18:31, John wrote:
> Hi,
>
> How can I access the elements [context, invariant, expressions,
> variables, operations and etc...] of the OCL document (OCLInput,
> ".ocl") that are related to my uml model?
>
> I know that i need parse the document, something like this:
> OCL myOCL = OCL.newInstance(myresourceSet)
> myOCL.parse(OCLInput);
>
> Until here, everything is fine. But after that, what i need to do?
> Is the class Visitor used for this? How?
>
> Is there some method with the parameter OCLInput to get the abstract
> sintax of the OCL document. How can i manipulate the constructs of the
> ocl expressions in the document?
>
> ps: the ocl constraints are related to uml model. So:
> org.eclipse.ocl.uml is used.
>
> Edward:
> I had to transform my specific OntoUML model in a UML model. So, now,
> my problem is how to get the elements in the document .ocl , that is
> related to the uml model.
>
> Regards,
> John
>
Re: How to get the elements of OCL document (.ocl) [message #753733 is a reply to message #731467] Fri, 28 October 2011 14:31 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi Edward,

Thanks for the replies.
About the parse () method, was my lack of attention.
Yes, I used the constraints returned by parse () method and by MyVisitor class that is extended by the class AbstractVisitor <...> I could traverse the abstract syntax tree of the restrictions.
The class ToStringVisitor helped me a lot. Instead of printing the syntax of OCL, I printed my transformation.

Now, maybe you can help me, I wanted to create a standalone editor for OCL related to the UML model that provides a syntax coloring and validation according to the UML model. I could use the editor CompleteOCL for this? I know this editor actually transform the UML model into an Ecore model to the validation, and it might not be so consistent. But still, it's better than nothing.

Remember that in fact my model is a specific model that I had to transform to a UML model in order to use the OCL constraints. And so, in fact, the restrictions contained in this editor OCL would be on my particular model.

You could give me some tips on how to do this OCL editor that is related to my UML model, outside of the Eclipse platform?

Regards,
John
Re: How to get the elements of OCL document (.ocl) [message #753757 is a reply to message #753733] Fri, 28 October 2011 15:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi John

ToStringVisitor is for debugging. PrettyPrint*Visitor is for pretty
printing.

Complete OCL edits a complementary model which is probably not what you
want; the syntax is also rather poor.

OCLinEcore edits a primary pivot model, currently readable and writeable
as an Ecore model, or readable as a UML model. It is my intention to
replace the UML2Ecore2Pivot conversion by a direct UML2Pivot conversion
so that the OCLinEcore editor could be renamed as a UnifiedOCL editor.
The code for UML2Pivot is there in very prototype form, but all profile
support is missing and no interesting UML model is profile-less.

If you really want to proceed in this direction then I would recommend
either renaming the OCLinEcore source as JohnsUML or defining JohnsUML
as an extension of OCLinEcore, in the same way that OCLinEcore extends
Essential OCL.

But be warned; the Xtext grammar facilities are very extensible, so you
may get the grammar working quite quickly; give up if you don't. However
the subsequent scope resolution is very hand coded, and now that I see
what it has to do, this is perhaps top list of targets for model-driven
automation; the need to manually maintain scopes is inhibiting many
other activities. So if you take OCLinEcore now you will have to adapt
when the APIs for automated scope resolution are defined.

If you have time/inclination/permission to work collaboratively, it
might be best to sort out the UML2Pivot loader so that it works for UML
and is extensible to JohnsUML. I will get the model-driven scoping in
place so that extending OCLinEcore is then a sensible activity.

Regards

Ed Willink


On 28/10/2011 15:31, John wrote:
> Hi Edward,
>
> Thanks for the replies.
> About the parse () method, was my lack of attention.
> Yes, I used the constraints returned by parse () method and by
> MyVisitor class that is extended by the class AbstractVisitor <...> I
> could traverse the abstract syntax tree of the restrictions.
> The class ToStringVisitor helped me a lot. Instead of printing the
> syntax of OCL, I printed my transformation.
>
> Now, maybe you can help me, I wanted to create a standalone editor for
> OCL related to the UML model that provides a syntax coloring and
> validation according to the UML model. I could use the editor
> CompleteOCL for this? I know this editor actually transform the UML
> model into an Ecore model to the validation, and it might not be so
> consistent. But still, it's better than nothing.
>
> Remember that in fact my model is a specific model that I had to
> transform to a UML model in order to use the OCL constraints. And so,
> in fact, the restrictions contained in this editor OCL would be on my
> particular model.
>
> You could give me some tips on how to do this OCL editor that is
> related to my UML model, outside of the Eclipse platform?
>
> Regards,
> John
Re: How to get the elements of OCL document (.ocl) [message #753765 is a reply to message #753757] Fri, 28 October 2011 16:23 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi Edward,

What do you mean by "prettyprint*Visitor is for pretty printing."

Well, I see... :
"Converts an OCL expression to a string for debugging. This is not Intended
* To be used by client applications to an AST-to-text transformation. "

Unlike the previously cited article:
http://www.eclipse.org/articles/article.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html

The class ToSTringVisitor helped me to understand how to process the elements of the AST.

I did something wrong? There is another way of doing this?
If there is, tell me what i have to do so...

I see no other way to make the transformation.

Regards,
John
Re: How to get the elements of OCL document (.ocl) [message #753776 is a reply to message #753765] Fri, 28 October 2011 17:13 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Another thing Edward:

Do you know if there is a transitive closure operator for OCL?
Something like allParents () or closure () ...
I read something about these methods, but not found in the OCL specification. I think allParents () is related to the UML and I read something recently about this closure method (), but found nothing in the OCL 2.2 specification ...
Is there any way to do this in OCL? (using org.eclipse.ocl and org.eclipse.ocl.uml)

Thanks for all your attention,

John
Re: How to get the elements of OCL document (.ocl) [message #753778 is a reply to message #753776] Fri, 28 October 2011 17:15 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi John

closure() has been in Eclipse OCL for at least 3 years (for Sets).

closure() was added to OMG OCL 2.3, (for Sets and OrderedSets) and the
new piviot implementation prototyped this.

Regards

Ed Willink



On 28/10/2011 18:13, John wrote:
> Another thing Edward:
>
> Do you know if there is a transitive closure operator for OCL?
> Something like allParents () or closure () ...
> I read something about these methods, but not found in the OCL
> specification. I think allParents () is related to the UML and I read
> something recently about this closure method (), but found nothing in
> the OCL 2.2 specification ...
> Is there any way to do this in OCL? (using org.eclipse.ocl and
> org.eclipse.ocl.uml)
>
> Thanks for all your attention,
>
> John
Re: How to get the elements of OCL document (.ocl) [message #753781 is a reply to message #753765] Fri, 28 October 2011 17:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
On 28/10/2011 17:23, John wrote:
> Hi Edward,
>
> What do you mean by "prettyprint*Visitor is for pretty printing."
/**
* The PrettyPrintExprVisitor supports pretty printing of OCL expressions.
* PrettyPrintOptions may be used to configure the printing.
*/
public class PrettyPrintExprVisitor extends PrettyPrintNameVisitor

>
> Well, I see... :
> "Converts an OCL expression to a string for debugging. This is not
> Intended
> * To be used by client applications to an AST-to-text transformation. "
>
> Unlike the previously cited article:
> http://www.eclipse.org/articles/article.php?file=Article-HowToProcessOCLAbstractSyntaxTrees/index.html
>
>
That article was written without any review by any member of the Eclipse
OCL team. It was not paerticularly accurate when written and has
obviously failed to track the evolution of Eclipse OCL in the many
intervening years.
> The class ToSTringVisitor helped me to understand how to process the
> elements of the AST.
ToStringVisitor is certainly a good example of tree-walking, but it's
formatting is targetted at debugging, in places deliberately creating
invalid OCL.

PrettyPrintVisitor is targetted at production of well formatted valid OCL.

Regards

Ed Willink
Re: How to get the elements of OCL document (.ocl) [message #754496 is a reply to message #753781] Wed, 02 November 2011 18:33 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member


[Updated on: Wed, 02 November 2011 18:43]

Report message to a moderator

Re: How to get the elements of OCL document (.ocl) [message #754498 is a reply to message #753781] Wed, 02 November 2011 18:42 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hi Edward,

To use the class PrittyPrintExpreVisitor I first need to make the parser to return the Constraints of the type: ocl.examples.pivot.Constraint, right?

Here is my old code:
InputStream in = new FileInputStream(oclPath);
OCLInput document = new OCLInput(in);
		
// initializae an ocl façade 
org.eclipse.ocl.uml.OCL.initialize(umlResource.getResourceSet());
		
// create a new instance of ocl façade
UMLEnvironmentFactory envFactory = new UMLEnvironmentFactory(umlResource.getResourceSet());
UMLEnvironment env = envFactory.createEnvironment();		
org.eclipse.ocl.uml.OCL myOCL = org.eclipse.ocl.uml.OCL.newInstance(env);		
	
// parse ocl against the uml model
List<Constraint> constraints = myOCL.parse(document);  
  
for (Constraint ct : constraints) {
    // Call PrittyPrintExprVisitor !
}


So how can I make the document parser using OCL org.eclipse.ocl.examples.pivot?
As far as I know, there is no UMLEnvironment...

Regards,
John

[Updated on: Wed, 02 November 2011 18:43]

Report message to a moderator

Re: How to get the elements of OCL document (.ocl) [message #754519 is a reply to message #754498] Wed, 02 November 2011 21:32 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi

I think you discovered the answer to your original question. The Old UML
binding has no PrettyPrintVisitor, which is part of the new Pivot binding.

Try org.eclipse.ocl.examples.pivot.utilities.PivotEnvironment.

For the most part the new code has similar APIs; justr change

org.eclipse.ocl, org.eclipse.ocl.ecore, or org.eclipse.ocl.uml to
org.eclipse.ocl.examples.pivot

Regards

Ed Willink



On 02/11/2011 19:42, John wrote:
> Hi Edward,
>
> Para usar a classe PrittyPrintExprVisitor eu primeiro preciso fazer o
> parser retornar as restrições do tipo : ocl.examples.pivot.Constraint
> , certo?
>
> Aqui está meu antigo código:
>
> InputStream in = new FileInputStream(oclPath);
> OCLInput document = new OCLInput(in);
>
> // initializae an ocl façade
> org.eclipse.ocl.uml.OCL.initialize(umlResource.getResourceSet());
>
> // create a new instance of ocl façade
> UMLEnvironmentFactory envFactory = new
> UMLEnvironmentFactory(umlResource.getResourceSet());
> UMLEnvironment env = envFactory.createEnvironment();
> org.eclipse.ocl.uml.OCL myOCL = org.eclipse.ocl.uml.OCL.newInstance(env);
>
> // parse ocl against the uml model
> List<Constraint> constraints = myOCL.parse(document);
> for (Constraint ct : constraints) {
> // Call PrittyPrintExprVisitor !
> }
>
>
> So how can I make the document parser using OCL
> org.eclipse.ocl.examples.pivot? As far as I know, there is no
> UMLEnvironment...
>
> Regards,
> John
>
Re: How to get the elements of OCL document (.ocl) [message #754603 is a reply to message #754519] Thu, 03 November 2011 13:25 Go to previous messageGo to next message
John Guerson is currently offline John GuersonFriend
Messages: 51
Registered: August 2011
Member
Hey Edward,

Is there any source or article that relates to this library?
Some examples ...

There is no parse () method in pivot.OCL nor pivot.OCLBase.
And what to do with OCLInput (my original document .ocl)?
how to get these contraints in the document ?
(Yeah, my original question... )

If I use ocl.examples.pivot, there is no connection with my model (UML or my specific model), as far as i know...

I'm a little confused ...

Thanks for your help ... I am very grateful!

Regards,
John
Re: How to get the elements of OCL document (.ocl) [message #754693 is a reply to message #754603] Thu, 03 November 2011 21:05 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4188
Registered: July 2009
Senior Member
Hi John

Hmm the documentation is a bit thin.

Traditionally documentation happens just before the release, in the
interval when code is frozen for final testing. For Indigo most of that
time went into migration to use textile and document libraries and
tutorials; then my enthusiasm for examples ran out; sorry. I'll have no
excuse when this code is non-examples in Juno.

Your best reference is the org.eclipse.ocl.examples.xtests plugin where
you will find all the JUnit tests and consequently many examples of usage.

If you look
org.eclipse.ocl.examples.pivot.tests.EvaluateBooleanOperationsTest you
can see how for instance

assertQueryFalse(null, "false and false")

evaluates "false and false" as input to generate a false result.

The pivot model uses either Ecore2Pivot or UML2Ecore2Pivot to load user
metamodels. See org.eclipse.ocl.examples.test.xtext.SerializeTests.

Regards

Ed Willink


On 03/11/2011 14:25, John wrote:
> Hey Edward,
>
> Is there any source or article that relates to this library? Some
> examples ...
>
> There is no parse () method in pivot.OCL nor pivot.OCLBase.
> And what to do with OCLInput (my original document .ocl)? how to get
> these contraints in the document ?
> (Yeah, my original question... )
>
> If I use ocl.examples.pivot, there is no connection with my model (UML
> or my specific model), as far as i know...
>
> I'm a little confused ...
>
> Thanks for your help ... I am very grateful!
>
> Regards,
> John
Previous Topic:real sum approximation problem
Next Topic:EEnumLiteral and Integer
Goto Forum:
  


Current Time: Mon Dec 22 00:41:29 GMT 2014

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

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