can ocl validate runtimeobjects against their classes [message #693471] |
Wed, 06 July 2011 10:23  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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] by Moderator
|
|
|
Re: can ocl validate runtimeobjects against their classes [message #693823 is a reply to message #693796] |
Thu, 07 July 2011 05:08   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.39814 seconds