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 |
John Guerson 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 #731467 is a reply to message #731348] |
Sat, 01 October 2011 05:56 |
Ed Willink Messages: 7670 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 |
John Guerson 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 |
Ed Willink Messages: 7670 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 #754498 is a reply to message #753781] |
Wed, 02 November 2011 18:42 |
John Guerson 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
|
|
| | | |
Goto Forum:
Current Time: Tue Sep 24 14:46:24 GMT 2024
Powered by FUDForum. Page generated in 0.06274 seconds
|