Is it possible to generate real Java code with Dresden OCL Toolkit?

StackOverflow https://stackoverflow.com/questions/9901948

  •  27-05-2021
  •  | 
  •  

Pergunta

I tried using Dresden OCL to describe constraints for an UML class diagram. It looks like it can generate AspectJ code fine but I could not find a way to generate the Java code representing the modeled classes (and their attributes and methods). The examples provided with Dresden OCL Toolkit also show how to generate AspectJ code once the Java code is already present (OCL22Java tutorial).

Is it possible to generate the Java (not AspectJ) code with constraints embedded inside? And if it is, then how is it done?

Foi útil?

Solução

It is not possible to do that with Dresden OCL Toolkit, therefore some other tool must be used for that. I used Uml2Java for Acceleo.

Outras dicas

The standalone engine of DresdenOCL (StandaloneFacade) includes a function called generateJavaCode. I'm not sure though if this function is actually "complete" and generates correct Java Code for all possible OCL constraints. You also cannot find any info about that function on Google, it's just used in the standalone example.

Edit: As an example what Java code it generates:

For this OCL expression (on some simple UML model that I created)

context person
inv: self.age >= 0

you get this piece of Java code

(aClass.age >= new Integer(0))

And for this OCL expression

context person::havingBirthday()
post: self.age = self.age@pre+1

you get this:

((Object) aClass.age).equals((atPreValue1 + new Integer(1)))

So the generated Java code is not that usable atm, you need to modify it (or your Java functions) a bit to actually use it.

Eclipse OCL provides support for enriching the Java generated from Ecore models with complete inline Java code for OCL embedded within Ecore. Eclipse UML2 provides support for converting UML with embedded OCL to Ecore with embedded OCL. This now provides all that you ask for. It has been available for a couple of years. See the Code Generator tutorial in the Eclipse OCL documentation for an example and further information.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top