[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.mdt.ocl] Re: How to check the types of containment?

Hi, Gilbert,

See some replies in-line, below.

HTH,

Christian


On Tue, 2009-09-15 at 18:04 +0200, Gilbert Mirenque wrote:
Sorry Christian,
I don't understand what you mean.
> Update the interpreter example code to set the "implicit root class"
> parser option to EcorePackage.Literals.EObject in the initialization of
> the M1 environment.  This is required to access the EObject features in
> models that do not explicitly extend EObject.
I meant that I found the posted link and wanted to create some ocl
expressions with at least a little kind of editor. I don't use the
example described in the link. What is the "implicit root class" parser

But, you said in your post that you were getting error messages from expressions and "activated level M1" etc.  If you weren't doing this in the OCL interpreter example (the "interactive console") then I don't know what you were using.  AFAIK, the only UI that uses labels like "M2" and "M1" is that example.

The MDT OCL SDK provides a "New Example" wizard that creates the interpreter/console example as a source project in your workspace.  You can edit the code to customize the parser behaviour, if you need to, as in this case.

The implicit root class option is a customization option for the parser:  the details of the API escape me now, it's been so long since I've worked with the OCL code.  Look for the ParserOptions type in the OCL source.  This option is used to tell the parser to assume that all classes in your model that don't have an explicit superclass have the given class (in this case, EObject) as a superclass.  This covers the case in Ecore models where on a Java level all generated classes extend EObject whether your Ecore model makes it explicit or not.


option? I have a meta model based on ecore. What do I have to change
that I can invent some ocl expressions?

You don't necessarily have to do anything special to work with Ecore models.  It's just that, in your case, you need to do reflection on the meta-model level of a sort that OCL (the language) does not support, so we need to pull a trick to work around it in the MDT implementation.


Another question: Under [1] I found in the last snippet the following line:

self.allOwnedElements()

But allOwnedElements() can't be found here. Is this an old snippet? I

No, this snippet pertains to the UML metamodel.  In UML models you can use allOwnedElements because it is defined by the uml::Element metaclass.  The only thing similar in the Ecore metamodel is eAllContents(), but it returns a data type (an iterator) which isn't of any use in OCL.


want to check if all referenced events of a model element are contained
in its own hierarchy are and not events of model elements outside its
own hierarchy. That means the referenced events mustn't be events of
sibling model elements. So I tried to do something like this:

self.exportedEvents ->forAll(ev| 	
	self.allOwnedElements()
	->select(x|
	x.oclIsTypeOf(MyMetaModel::Event))
	->includes(ev)
)

Try this:

  self.exportedEvents ->forAll(ev |
      ev->closure(eContainer())->contains(self))

Unfortunately, this again requires that either you explicitly extend EObject in your model or you use the implicit root class option, in order to access the eContainer()) operation.  Alternatively, perhaps your model already has some feature that generically returns the containing element?

Sorry for the annoying questions but for a novice it's just an ocl
jungle. A central documentation with what is possible in MDT OCL and how
would be nice. Hope you can help.

best regards,
Gilbert

[http://wiki.eclipse.org/OCLSnippets#Finding_all_classifiers_that_specialize_an_arbitrary_classifier_named_.27foo::Bar.27]