|
|
Re: can ocl validate runtimeobjects against their classes [message #693796 is a reply to message #693507] |
Thu, 07 July 2011 08:23 |
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 08: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 09:08 |
Ed Willink Messages: 7669 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04194 seconds