2

I created a UML class diagram im Modelio, now I need to implement this diagram in Java. Is there any possibility to generate Java code out of a class diagram? I just want to export the classes and prototypes of the methods. I have already tried tu use "java designer 3.1.00", but i could not figure out if/how i can generate class files with this extention.

blafoo
  • 23
  • 1
  • 4
  • 1
    you can export your model in XMI format and use it with another tool with the Java code generator already built-in. Many (even free) tools can generate class and method stubs (e.g. Sparx Systems Enterprise Architect can do it) – xmojmr Jun 16 '14 at 06:05

2 Answers2

1

Another way is write a macro using Modelio API. This is a very simple example for PHP (only for prepare class and methods):

if (selectedElements.size() > 0):
    for c in selectedElements:
        print "<?php"
        print ""
        print "class " + c.getName()
        print "{"

        child = c.getCompositionChildren()       
        for a in child:
            if (a.getMClass().getName() == "Operation"):             
                print " public function " + a.getName() + "()"
                print " {"
                print " }"
                print ""                     
        print "}"
        print ""
else:
    print "No element has been selected."

APIs for macros is here. API also allows you to save your generated code to files (for example you can use package names as directories and class names as file names).

zajonc
  • 1,935
  • 5
  • 20
  • 25
-1

Here is the Modelio Java Designer user manual where you will find all you need concerning Java code generation.

But for generating Java code you have to say, by adding stereotypes, that your UML element (package, Java, enumeration, etc.) can be used for Java code generation. For that please take a look at this post.

Red Beard
  • 3,436
  • 1
  • 14
  • 17