Home » Modeling » GMF (Graphical Modeling Framework) » Re: OCL related
Re: OCL related [message #200157] |
Mon, 04 August 2008 15:07 |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Jiezi,
The problem with trying to test for circular routes in the TaiPan
example is that a Destination doesn't know the Routes that link to it.
If TaiPan were modeled with UML instead of Ecore, then OCL would be able
to use UML's Association elements to navigate from Ports to Routes, but
Ecore doesn't have the same capability.
So, this constraint in TaiPan would have to be defined using the
allInstances() operation:
context Port
def: incomingRoutes : Set(Route) =
Route.allInstances()->select(destination = self)
context Route
inv: self->closure(source.incomingRoutes)->excludes(self)
However, GMF doesn't support definitions in OCL-based validation, so you
could try an Audit on the Route EClass that looks like:
self->closure(r|
Route.allInstances()->select(destination = r.source))
->excludes(self)
I don't promise that this is correct, nor that it performs reasonably :-D
Cheers,
Christian
jiezi wrote:
> jiezi506@gmail.com 写道:
>
> I want to prevent the connection like "PortA--->PortB---->PortC--->PortA".
>
> I make a try in TaiPan example,but I don't know how to create the
> expression,because in TaiPan,all the "parent and child" informations are
> stored in Route,I can't make the expression like this
> "self->closure(port.source-Port)->excludes(self)" follow
> "self->closure(generalization.general)->excludes(self)",
>
> furthermore,one port may have more than one source port,like
> "PortD--->PorE<----PortF".
>
>
>
> The test code in TaiPan LinkConstraint is below:
> public static boolean canExistRoute_4002(Port source,
> Port target) {
> try {
> if (target == null) {
> return true;
> }
> if (Route_4002_TargetExpression == null) {
> Map env = Collections.singletonMap(OPPOSITE_END_VAR,
> TaiPanPackage.eINSTANCE.getPort());
> Route_4002_TargetExpression = TaiPanOCLFactory
> .getExpression(
>
> "self->closure(route.source)->excludes(self)",
> TaiPanPackage.eINSTANCE.getRoute(), env); //$NON-NLS-1$
> }
> Object targetVal =
> Route_4002_TargetExpression.evaluate(target,
> Collections.singletonMap(OPPOSITE_END_VAR, source));
> if (false == targetVal instanceof Boolean
> || !((Boolean) targetVal).booleanValue()) {
> return false;
> } // else fall-through
> return true;
> } catch (Exception e) {
> TaiPanDiagramEditorPlugin.getInstance().logError(
> "Link constraint evaluation error", e);
> //$NON-NLS-1$
> return false;
> }
> }
>
> How could I make the expression in TaiPan example?
>
> thx.
|
|
|
Re: OCL related [message #200224 is a reply to message #200157] |
Mon, 04 August 2008 18:42 |
Eclipse User |
|
|
|
Originally posted by: eclipse.[REMOVE]stefan-kuhn.eu
what about using a cross referencer or the notation model to help? :)
btw. the 'prefered' gmf way is a reference meta-class, like in uml.
-stefan
Christian W. Damus schrieb:
> Hi, Jiezi,
>
> The problem with trying to test for circular routes in the TaiPan
> example is that a Destination doesn't know the Routes that link to it.
> If TaiPan were modeled with UML instead of Ecore, then OCL would be able
> to use UML's Association elements to navigate from Ports to Routes, but
> Ecore doesn't have the same capability.
>
> So, this constraint in TaiPan would have to be defined using the
> allInstances() operation:
>
> context Port
> def: incomingRoutes : Set(Route) =
> Route.allInstances()->select(destination = self)
>
> context Route
> inv: self->closure(source.incomingRoutes)->excludes(self)
>
> However, GMF doesn't support definitions in OCL-based validation, so you
> could try an Audit on the Route EClass that looks like:
>
> self->closure(r|
> Route.allInstances()->select(destination = r.source))
> ->excludes(self)
>
> I don't promise that this is correct, nor that it performs reasonably :-D
>
> Cheers,
>
> Christian
>
>
> jiezi wrote:
>> jiezi506@gmail.com 写道:
>>
>> I want to prevent the connection like
>> "PortA--->PortB---->PortC--->PortA".
>>
>> I make a try in TaiPan example,but I don't know how to create the
>> expression,because in TaiPan,all the "parent and child" informations are
>> stored in Route,I can't make the expression like this
>> "self->closure(port.source-Port)->excludes(self)" follow
>> "self->closure(generalization.general)->excludes(self)",
>>
>> furthermore,one port may have more than one source port,like
>> "PortD--->PorE<----PortF".
>>
>>
>>
>> The test code in TaiPan LinkConstraint is below:
>> public static boolean canExistRoute_4002(Port source,
>> Port target) {
>> try {
>> if (target == null) {
>> return true;
>> }
>> if (Route_4002_TargetExpression == null) {
>> Map env = Collections.singletonMap(OPPOSITE_END_VAR,
>> TaiPanPackage.eINSTANCE.getPort());
>> Route_4002_TargetExpression = TaiPanOCLFactory
>> .getExpression(
>>
>> "self->closure(route.source)->excludes(self)",
>> TaiPanPackage.eINSTANCE.getRoute(), env); //$NON-NLS-1$
>> }
>> Object targetVal =
>> Route_4002_TargetExpression.evaluate(target,
>> Collections.singletonMap(OPPOSITE_END_VAR,
>> source));
>> if (false == targetVal instanceof Boolean
>> || !((Boolean) targetVal).booleanValue()) {
>> return false;
>> } // else fall-through
>> return true;
>> } catch (Exception e) {
>> TaiPanDiagramEditorPlugin.getInstance().logError(
>> "Link constraint evaluation error", e);
>> //$NON-NLS-1$
>> return false;
>> }
>> }
>>
>> How could I make the expression in TaiPan example?
>>
>> thx.
|
|
|
Re: OCL related [message #200231 is a reply to message #200224] |
Mon, 04 August 2008 18:57 |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Stefan,
That's precisely what the UML binding in MDT OCL uses: the
cross-referencing facility in the CacheAdapter. This allows us to
navigate non-navigable association ends, even when they don't have names.
The semantics of OCL in the Ecore binding tries to match the
EssentialOcl, in which navigation of non-navigable association ends is
excluded because EMOF does not have association ends (associations being
a CMOF/UML construct, available in the CompleteOcl). In EMOF, there are
only attributes. I suppose one might see EMOF attributes as always
having implicit unnamed opposites, but one can just as easily add an
inversion operation into one's model as MDT UML2 did with the
Element::getRelationships() query.
So, either we're being sticklers for OCL purity, or we're lazy. ;-)
Cheers,
Christian
Stefan Kuhn wrote:
> what about using a cross referencer or the notation model to help? :)
> btw. the 'prefered' gmf way is a reference meta-class, like in uml.
>
> -stefan
>
-----8<-----
|
|
|
Re: OCL related [message #200344 is a reply to message #200231] |
Wed, 06 August 2008 00:41 |
Eclipse User |
|
|
|
Originally posted by: jiezi506.gmail.com
Hi, Christian ,
Sorry,there was some problem in my thunderbird, and it brought about
last mail was deleted.I send it again.
I modifed the LinkConstraints class in TaiPanBaseItemSemanticEditPolicy
class like below:
public static boolean canExistRoute_4002(Port source,Port target) {
try {
if (source == null) {
return true;
}
if (Route_4002_SourceExpression == null) {
Map env = Collections.singletonMap(OPPOSITE_END_VAR,
TaiPanPackage.eINSTANCE.getPort());
Route_4002_SourceExpression = TaiPanOCLFactory
.getExpression(
"self->closure(r|Route.allInstances()->select(destination =
r.source))->excludes(self)",
TaiPanPackage.eINSTANCE.getPort(),
env); //$NON-NLS-1$
}
Object sourceVal = Route_4002_SourceExpression
..evaluate(source,Collections.singletonMap(OPPOSITE_END_VAR, target));
if (false == sourceVal instanceof Boolean
|| !((Boolean) sourceVal).booleanValue()) {
return false;
} // else fall-through
return true;
} catch (Exception e) {
TaiPanDiagramEditorPlugin.getInstance().logError(
"Link constraint evaluation error", e);
//$NON-NLS-1$
return false;
}
}
The TaiPanOCLFactory.getExpression() is below:
public static TaiPanAbstractExpression getExpression(String body,
EClassifier context, Map environment) {
return new Expression(body, context, environment);
}
but when I clicked a Reliable Route to a Port,an Exception was generated:
Message:Expression problem:Unrecognized variable:
(source)body:self->closure(r|Route.allInstances()->select(destination =
r.source))->excludes(self)
Exception Stack Trace:org.eclipse.ocl.SemanticException: Unrecognized
variable: (source)
at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:309 )
How may I solve this problem?or change the context to bigger container
Aquatory?
thx very much!
|
|
|
Re: OCL related [message #200498 is a reply to message #200344] |
Tue, 05 August 2008 13:38 |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Jiezi,
I was assuming that the context of the constraint was Route, which is
the type of the "r" variable in the closure expression. I think the
Route EClass defines a "source" property; I could be wrong.
I recommend using the Interactive OCL Console example to test OCL
expressions on your models to make sure that they work, before adding
them to your GMF mappings. It's easier, that way, to build up a working
expression in stages, one sub-expression at a time.
Install the example from the Examples ZIP on the MDT OCL downloads page.
Or, if you have the OCL SDK installed and want to learn more about the
OCL API anyway, you can install the example source project using the
"File -> New -> Example..." wizard and then export it using the
"Deployable Plug-ins and Fragments" wizard into your Eclipse installation.
HTH,
Christian
jiezi506@gmail.com wrote:
> Hi, Christian ,
>
> Sorry,there was some problem in my thunderbird, and it brought about
> last mail was deleted.I send it again.
>
> I modifed the LinkConstraints class in TaiPanBaseItemSemanticEditPolicy
> class like below:
>
> public static boolean canExistRoute_4002(Port source,Port target) {
> try {
> if (source == null) {
> return true;
> }
> if (Route_4002_SourceExpression == null) {
> Map env = Collections.singletonMap(OPPOSITE_END_VAR,
> TaiPanPackage.eINSTANCE.getPort());
> Route_4002_SourceExpression = TaiPanOCLFactory
> .getExpression(
>
> "self->closure(r|Route.allInstances()->select(destination =
> r.source))->excludes(self)",
> TaiPanPackage.eINSTANCE.getPort(),
> env); //$NON-NLS-1$
> }
>
> Object sourceVal = Route_4002_SourceExpression
>
> .evaluate(source,Collections.singletonMap(OPPOSITE_END_VAR, target));
> if (false == sourceVal instanceof Boolean
> || !((Boolean) sourceVal).booleanValue()) {
> return false;
>
> } // else fall-through
> return true;
> } catch (Exception e) {
> TaiPanDiagramEditorPlugin.getInstance().logError(
> "Link constraint evaluation error", e);
> //$NON-NLS-1$
> return false;
> }
> }
>
>
>
> The TaiPanOCLFactory.getExpression() is below:
>
> public static TaiPanAbstractExpression getExpression(String body,
> EClassifier context, Map environment) {
> return new Expression(body, context, environment);
> }
>
>
>
> but when I clicked a Reliable Route to a Port,an Exception was generated:
>
> Message:Expression problem:Unrecognized variable:
> (source)body:self->closure(r|Route.allInstances()->select(destination =
> r.source))->excludes(self)
>
> Exception Stack Trace:org.eclipse.ocl.SemanticException: Unrecognized
> variable: (source)
> at org.eclipse.ocl.util.OCLUtil.checkForErrors(OCLUtil.java:309 )
>
>
> How may I solve this problem?or change the context to bigger container
> Aquatory?
>
> thx very much!
>
>
>
|
|
|
Re: OCL related [message #200636 is a reply to message #200498] |
Wed, 06 August 2008 17:16 |
Eclipse User |
|
|
|
Originally posted by: jiezi506.gmail.com
Hi, Christian ,
I didn't understand how to use the Interactive OCL Console very much.
I just selected File--New--Examples--OCL(Object Constraint
Language)Plug-ins--OCL Interpreter,
then there were
org.eclipse.emf.examples.library
org.eclipse.emf.examples.library.edit
org.eclipse.emf.examples.library.editor
org.eclipse.emf.ocl.examples.interpreter
4 plugin projects were generated in workspace.
I added them to a Eclipse Application,then debug it,
there only was a "Example EMF Model Creation Wizards--EXTLibrary Model",
then I could open a Interactive OCL view,
but how to add my ecore,gmfgen,gmfmap to it to test?
thx.
|
|
|
Re: OCL related [message #200858 is a reply to message #200636] |
Wed, 06 August 2008 13:02 |
Eclipse User |
|
|
|
Originally posted by: cdamus.zeligsoft.com
Hi, Jiezi,
You can always open the OCL Console from the "New Console" menu in the
Console View's action bar. It's listed there with the CVS console and
others.
The console works with the selection in any Editor that provides a
selection containing either EObjects of some kind or IAdaptables that
provide adapters for the EObject interface.
The Examples Guide in the OCL Developer Guide should provide information
about how to use the console.
HTH,
Christian
jiezi506@gmail.com wrote:
> Hi, Christian ,
>
> I didn't understand how to use the Interactive OCL Console very much.
>
> I just selected File--New--Examples--OCL(Object Constraint
> Language)Plug-ins--OCL Interpreter,
> then there were
> org.eclipse.emf.examples.library
> org.eclipse.emf.examples.library.edit
> org.eclipse.emf.examples.library.editor
> org.eclipse.emf.ocl.examples.interpreter
> 4 plugin projects were generated in workspace.
>
> I added them to a Eclipse Application,then debug it,
> there only was a "Example EMF Model Creation Wizards--EXTLibrary Model",
> then I could open a Interactive OCL view,
> but how to add my ecore,gmfgen,gmfmap to it to test?
>
> thx.
|
|
|
Goto Forum:
Current Time: Thu Apr 25 17:16:46 GMT 2024
Powered by FUDForum. Page generated in 0.04438 seconds
|