Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » can ocl validate runtimeobjects against their classes
can ocl validate runtimeobjects against their classes [message #693471] Wed, 06 July 2011 10:23 Go to next message
st oehm is currently offline st oehm
Messages: 79
Registered: October 2009
Member
hi to all
i have a (maybe strange) question to the use of ocl
is it possible to use ocl without any models and metamodels, only for runtimeobjects, which are validated to their classes.
for example i have two classes (only as code nothing else) A and B with special constraints. now at runtime i have some instances of this classes A and B and i want to check, if they are validate for this constraints.
i guess that is not possible, but maybe somebody knows a way to reach this aim

best regards
stoehm
Re: can ocl validate runtimeobjects against their classes [message #693507 is a reply to message #693471] Wed, 06 July 2011 11:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4014
Registered: July 2009
Senior Member
Hi

This is most certainly possible, assuming that your runtime objects are
EObjects and so have an eClass() that return the correspomnding meta-class.

This is standard EMF functionality; no special action required.

Regards

Ed Willink

On 06/07/2011 15:23, stoehm wrote:
> hi to all
> i have a (maybe strange) question to the use of ocl
> is it possible to use ocl without any models and metamodels, only for
> runtimeobjects, which are validated to their classes.
> for example i have two classes (only as code nothing else) A and B
> with special constraints. now at runtime i have some instances of this
> classes A and B and i want to check, if they are validate for this
> constraints.
> i guess that is not possible, but maybe somebody knows a way to reach
> this aim
>
> best regards
> stoehm
Re: can ocl validate runtimeobjects against their classes [message #693796 is a reply to message #693507] Thu, 07 July 2011 04:23 Go to previous messageGo to next message
st oehm is currently offline st oehm
Messages: 79
Registered: October 2009
Member
hi ed
thanks for your reply
mhh maybe i was not too clear with my words
i want to use OCL just for plain old java far away from any models
maybe following example migth be helpful:

public class A{}

public class B {
private Set<A> linksToA;

//...getter and setter and further methods
}

Public class Test{
public static void main(String[] args){
A a1 = new A();
A a2 = new A();

B b = new B();
b.add(a1);
b.add(a2);
//here i want to check if a constarint is fullfilled e.g.
//b.linksToA->size()>=2
//so i want to call a method, which do that, sth. like this
Constraints.checkConstraints(b,"b.linksToA->size()>=2")
}

}

with other words my model is not a uml or xmi file, my "model" or "classdiagramm" i want to check against the runtimeobjects are the javaclasses.
so i highly assume, that is not possible
maybe it is possible, when the classdiagramm i check against is an uml-file (but still the objects are just normal javaobjects)

i need this, because i write a codegen from uml to java and i want to put constraints in this (for example for derived attributes or any other constraints). so i generate some code, this code are of course only "static". someone use it an has some runtimeobjects and it should be possible to validate this runtimeobjects against the classdiagramm (the classdiagramm can be the model or the java classes)
i hope now it is clearer what i'm looking for

best regards
stoehm

[Updated on: Thu, 07 July 2011 04:57]

Report message to a moderator

Re: can ocl validate runtimeobjects against their classes [message #693823 is a reply to message #693796] Thu, 07 July 2011 05:08 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4014
Registered: July 2009
Senior Member
Hi

If your A and B extend EObject then it's easy, you have EObject.eClass()
available to provide meta-data.

If you want to exploit OCL, and A and B do not extend EObject, you might
review whether that is a sensible design decision, because, today, for
full OCL support you would need to create an OCL<StoehmJava> to
correspond to the existing OCL<Ecore> and OCL<UML>; a very non-trivial
activity, that might only be difficult if you limit yourself to a
pragmatic subset of OCL.

In the next release, there will be direct Java code generation for Java
in which an Ecore model is converted to dispatch tables, so most of the
work to support a StoehmJava run-time representation may be in place. If
you don't add some kind of getMetaClass() method on your model
synthesis, a slightly slower dispatch might be possible automatically by
mapping Java's getClass().
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351406.

Regards

Ed Willink


On 07/07/2011 09:23, stoehm wrote:
> hi ed
> thanks for your reply
> mhh maybe i was not too clear with my words
> i want to use OCL just for plane old java far away from any models
> maybe following example migth be helpful:
>
> public class A{}
>
> public class B {
> private Set<A> linksToA;
>
> //...getter and setter and further methods
> }
>
> Public class Test{
> public static void main(String[] args){
> A a1 = new A();
> A a2 = new A();
>
> B b = new B();
> b.add(a1);
> b.add(a2);
> //here i want to check if a constarint is fullfilled e.g.
> //b.linksToA->size()>=2
> //so i want to call a method, which do that, sth. like this
> Constraints.checkConstraints(b,"b.linksToA->size()>=2")
> }
>
> }
>
> with other words my model is not a uml or xmi file, my "model" or
> "classdiagramm" i want to check against the runtimeobjects are the
> javaclasses.
> so i highly assume, that is not possible
> maybe it is possible, when the classdiagramm i check against is an
> uml-file (but still the objects are just normal javaobjects)
>
> i need this, because i write a codegen from uml to java and i want to
> put constraints in this (for example for derived attributes or any
> other constraints). so i generate some code, this code are of course
> only "static". someone use it an has some runtimeobjects and it should
> be possible to validate this runtimeobjects against the classdiagramm
> (the classdiagramm can be the model or the java classes)
> i hope now it is clearer what i'm looking for
>
> best regards
> stoehm
Re: can ocl validate runtimeobjects against their classes [message #693857 is a reply to message #693823] Thu, 07 July 2011 06:58 Go to previous message
st oehm is currently offline st oehm
Messages: 79
Registered: October 2009
Member
hi ed
thanks for your reply
you do a lot of work in these forums, what is very nice
for rigth now i think i have to omit this, because the time is limited, maybe the codegen can be adapted, when the OCL to java is supported by eclipse

best regards
stoehm
Previous Topic:using OCL from java
Next Topic:Unable to perform OCL validation outside eclipse
Goto Forum:
  


Current Time: Wed Jul 30 19:34:29 EDT 2014

Powered by FUDForum. Page generated in 0.04618 seconds