IBM Support

Modeling Generalization to an Instance of Generic Class in UML to Java transformation

Question & Answer


Question

How do you model generalization to an Instance of Generic Class in UML to Java Transformation to get the generated code: Public class CustomerList extends ArrayList?

Answer

  • Attached is a model which illustrates how to model a generalization to an instance of a generic class for consumption by the Java transformations. A Java transformation profile is required.
  • Open the diagram FreeformDiagram1 to view how the classes and relationships are modeled.
  • After running the UML to Java transformation, the generated code will be:


    public class ArrayList<E> {                                

                public void add(E o) { }                                  

                public void remove(Integer index) { }                      

                public void get(Integer index) { }                        

        }                                                          

                public class Customer {                                    

                private String name;                                      

                private String address;                                    

                                       

          }                                                          

           public class CustomerList extends ArrayList<Customer> {    

           }


  • The following article titled Defining Generics with UML Templates describes how EMF/ecore translates Java generics to UML which is a basis for how it is done in the Java transformations.


Sample_Modeling_Project2.zip

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

[{"Product":{"code":"SS4JCV","label":"Rational Software Architect for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Java Development","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.1;7.5.2;7.5.3;7.5.4","Edition":"","Line of Business":{"code":"LOB15","label":"Integration"}}]

Document Information

Modified date:
23 June 2018

UID

swg21404919