Contents
Gen2J will generate all the standard "plumbing" for an application, leaving you free to concentrate on the specific business logic. This section describes how to add your own code to the generated application in order to implement your own specific requirements.
Gen2J allows you to
For any operation you have defined yourself in the one of the original classes in the input UML model, you can define the Java code which will be merged into the corresponding method of the class created by Gen2J.
For any method created by Gen2J, you can provide your own code to replace Gen2J's code.
The procedure is the same whether you are providing code for one of your own methods or one created by Gen2J.
Create an XML code file in your project directory for the code, for example code.xml
For each method for which you want to provide code, add a method element, with the appropriate elements to define which method it refers to - see the “Code file format” section.
Write the Java code as the content of each method element, as it would appear between the curly braces around the method body in a Java file.
Set the code.import.file property for the Ant build. You can do this on the Ant command line:
ant -Dcode.import.file=code.xml
or you can add a property element to the project build.xml (refer to the Ant documentation for instructions on how to do this).
Generate and build the application as described in the “Getting Started” section
The code import file is an XML file. Its elements are described informally below, in order from the highest level to the lowest. All attributes are required unless they are marked optional.
This is the top-level element for the code XML.
For each generated package in which there are classes where you want to provide code, there should be one of these elements.
Attribute: name - the fully qualified name of the package
For each generated class in which there are methods where you want to provide code, there should be one of these elements, nested within the Package element for the package to which the class belongs.
Attribute: name - the name of the class (not qualified)
For each method for which you want to provide code, there should be one of these elements, nested within the Class element for the class to which the method belongs.
Attribute: name - the name of the method
Attribute (optional): parmTypes - a space separated list of the parameter types. The names must be fully qualified class names.
The body of this element is the code for the method.
The example below is taken from the Ecomm2J sample application.
<?xml version="1.0" encoding="utf-8"?> <ImportCode> <Package name="com.ashridgetech.ecomm2j.customers.bean"> <Class name="CustomerBean"> <Method name="getTotalOrderValue"> return 23.0; </Method> </Class> </Package> </ImportCode>