Developing utility generating applications from the CA Gen model

Overview

This blog entry focuses on explaining some hidden possibilities to activate the generation process using the CA Gen JMMI API. Selecting generation dialog from the Gen Toolset or Gen Studio is commonly known as the only way to trigger generation process, but CA Gen JMMI API allows controlling generation process outside the Toolset by developing your own utilities that can run online or in batch mode depending on your needs.

It makes sense to mention that historically the CA Gen Toolset was designed allowing the full cycle of the development, starting from the designing model, generating code in a number of the programming languages, allows building applications for some hardware and software platforms. This also includes dispatching packaged applications to the various operating systems and build them using native tools available on the target platform.

An integral part of the development cycle includes generating source code that can later be delivered and built in many different various target environments. Also, the CA Gen Toolset running on the Windows platform is not the only place where source code can be generated from the Gen Model. Please consult the CA Gen documentation to discover many possibilities that this software offers.

Standard generation process starts by selecting toolset dialog offering selection of the generation choices. This offers a selection of the operating system, programming language, transaction processing environment and database to mention few options. The whole process is under control of the toolset and strictly regulated and it has to be triggered manually from the workstation.

The generation process is implemented internally by a number of utilities that are triggered by the CA Gen Toolset transparently to the developer. Usually, the Gen Build Tools is activated later to start building application or performs packaging of the deliverables so packages of the generated source code can be transferred to one of many target platforms to complete building process. Those utilities are considered by the CA as internal and they are not documented so should not be used by the inexperienced developer.

The CA Gen JMMI API is quite elaborate and complex solution. We are going to focus only on the specific fragment of the API that deals with the generation process.

We are going to walk thru the sample utility built using JMMI API. Our simple utility will open selected local model and will generate code in Java and use JDBC as an access method to the database for the selected action block. Utility stores generated code at the location provided by the user.

The utility will be developed in Java and run from the command line taking a number of parameters. We are using Eclipse project for the development and project you can download from the Github here.

JMMI API

The CA Gen JMMI API is a hidden treasure. You will not find any part of the official documentation manual explaining how JMMI API works and how it can be used. There is a dedicated manual called Encyclopedia API Reference, but the JMMI API is not mentioned there. It is strange because the whole CA Gen Studio which is an Eclipse-based Java application is using JMMI API as the main way to access local model kept on the workstation.  Fortunately, you will find basic Java type of documentation in one of the CA Gen Toolset installation directories. There are not too many rich explanatory comments, but nicely crafted name for classes and methods allows to be familiar with the API very quickly.

Here is where you find your JMMI API.

Zrzut ekranu 2017-06-16 o 19.21.00

The CA Gen JMMI API is a really clever number of classes and methods are mostly native and implemented in C++ that can be executed only on the workstation running Window operating system, so you cannot port an application using JMMI API to any other platform. The CA Gen JMMI API can only access local models, but it looks like is designed to provide remote access to CA Gen encyclopaedias (Client Server Encyclopedia and Host Encyclopedia)in the future as well.

The JMMI provides a lot of classes, but we focus on only few of them. They are as follows:

  • com.ca.gen.jmmi.Generation
  • com.ca.gen.jmmi.GenerationData
  • com.ca.gen.jmmi.GenerationData

Soample utility explained

Our utility is very simple. This is a Java class run from the command line and accepting a number arguments. In its simplest form you can start application as follows:

java ABGenerate -j "C:\jgen.notes.models\sample.ief" "c:\temp" "FILE_FUNCTIONS_READ"

You specify location of your local model, location for generated source code and name of the action block to be generated.

The below snapshot of the code shows processing of the input arguments and what part of the application is responsible for the executing requests.

	public static void main(String[] args) {
		ABGenerate utility = new ABGenerate();
		try {
			System.out.println("Action Block Generaion Utility, Version 1.0");
			if(args.length == 0) {
				displayHelp();
			}
			if(args.length == 1 && args[0].equals("-h")) {
				displayHelp();
				return;
			}
			if(args.length == 4 && args[0].equals("-j")) {
				utility.start(args[1], args[2], args[3]);
				System.out.println("Completed.");
				return;
			}
		if(args.length == 2 && args[0].equals("-o")) {
			utility.options(args[1]);
			System.out.println("Completed.");
			return;
		}			
			displayHelp();
		} catch (EncyException e) {
			e.printStackTrace();
		} catch (ModelNotFoundException e) {
			e.printStackTrace();
		}
	}

	private static void displayHelp() {
		System.out.println("Usage: java ABGenerate [  ]");
		System.out.println("\toptions:");
		System.out.println("\t\t-h help");
		System.out.println("\t\t-j to generate for Java and   ");
		System.out.println("\t\t-o to display generation choices for ");
	}

The main function of the application starts here and will be explain step-by-step.

	private void start(String modelpath, String sourcepath, String abname)
			throws EncyException, ModelNotFoundException {
		openModel(modelpath);
		System.out.println("Generating action block " + abname + " into " + sourcepath + "\\" + JAVA_SUBDIRECTORY);
		generate(findActionBlock(abname), sourcepath, abname);
		closeModel();
	}	
	private void openModel(String modelpath) throws EncyException, ModelNotFoundException {
		ency = EncyManager.connectLocal(modelpath);
		model = ModelManager.open(ency, ency.getModelIds().get(0));
		System.out.println("Openning " + model.getName());
	}

	private void generate(long id, String sourcepath, String abname) {
		generation = GenerationManager.getInstance(model);
		generateActionBlock(id, sourcepath);
	}

	private void generateActionBlock(long id, String sourcepath) {
		generation.generateActionBlock(generation.getModelContext(), id, sourcepath, JAVA_SUBDIRECTORY, "ABC", "JVM",
				"JDBC", "INTERNET", "JAVA", "NO", "JAVAC", "YES");
	}

	private long findActionBlock(String abname) {
		ObjId objId = model.getObjIdByName(ObjTypeCode.ACBLKBSD, PrpTypeCode.NAME, abname);
		return objId.getValue();
	}

	private void closeModel() {
		model.close();
		ency.disconnect();
	}

  1. The first task is to open model. Class EncyManager has a static method connectLocal()allowing to connect to the encyclopedia. It is a little bit misleading because we are really connecting to the single local model which is not kept in the encyclopedia.
  2. Class ModelManager has the static method open()allowing to open selected model. An instance of the class Model is now available and represent a real model. Again, there is only one model at the chosen connection so we are going to pick the first one.
  3. We can start generation process once the model is selected and opened. We need to obtain an instance of the generator first.
  4. Class Generation has dedicated methods to perform a specific type of generation. We are going to use generateActionBlock().

These methods performing generation takes a number of parameters representing generation choices. You can display possible choices for the type of generation using this utility by starting it as follows:

java ABGenerate -j "C:\jgen.notes.models\sample.ief"
Here is the code printing possible generation choices.
	private void displayGenerationOptions() {
		generation =  GenerationManager.getInstance(model);
		operatingSystemsChoices();
		languagesChoices();
		databaseChoices();
		tpmonChoices();
		compilerChoices();
		communicationChoices();
	}

	private void operatingSystemsChoices() {
		System.out.println("Operating System  Choices:");
		for (GenerationData generationData : generation.getOperatingSystemsChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}
	
	private void databaseChoices() {
		System.out.println("Database Choices:");
		for (GenerationData generationData : generation.getDatabaseChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}
	
	private void tpmonChoices() {
		System.out.println("Tpmon Choices:");
		for (GenerationData generationData : generation.getTpmonChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}

	private void compilerChoices() {
		System.out.println("Compiler Choices:");
		for (GenerationData generationData : generation.getCompilerChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}
	
	private void communicationChoices() {
		System.out.println("Communication Choices:");
		for (GenerationData generationData : generation.getCommunicationChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}
	
	private void languagesChoices() {
		System.out.println("Language Choices:");
		for (GenerationData generationData : generation.getLanguageChoices()) {
			System.out.println("\t" +generationData.getGenerationDataKey() + "= " + generationData.getGenerationDataValue());
		}
	}

Our simple utility produces a couple messages at the completion of the job.

Action Block Generaion Utility, Version 1.0
Openning GEN SAMPLE MODEL 8 6
Generating action block FILE_FUNCTIONS_READ into c:\temp\sources
Completed.

You will find also a text file cgdebug.err created and summarizing what has been generated.

abg.exe, c:\temp\sources\java, JVM, JDBC, INTERNET, JAVA, JAVAC, OFF, *, *, ABC, *, *, *, *, YES.
ABG generating Encyid: 22020096
os       JVM
lang     JAVA
dbms     JDBC
compiler JAVAC
tpmon    INTERNET
MBCS set code page ID: 1252.
Starting Action Block Generator
Generated 1136 lines of Java.
Writing output file: c:\temp\sources\java\com/ca FILEFUNC.java
Wrote 548 lines.
Writing output file: c:\temp\sources\java\com/ca FILEFUNC_IA.java
Wrote 211 lines.
Writing output file: c:\temp\sources\java\com/ca FILEFUNC_OA.java
Wrote 177 lines.
Writing output file: c:\temp\sources\java\com/ca FILEFUNC_LA.java
Wrote 114 lines.

Summary

The sample application has been developed using the following software:

  • Windows 10
  • CA Gen 8.6 (Free)
  • Java Version 8 (Update 20)
  • Eclipse Neon.3 Release (4.6.3)

You can find project files here.

Changing images in the CA Gen generated web application during runtime

Introduction

Users converting their existing CA Gen Windows GUI clients to the new Web Generation features as provided with the CA Gen are facing many unsupported or having partial support for many features that they are free to use in the GUI Windows environment. This is because of a lot of functionality is provided using third party solutions based on the OLE technology that is not supported by many browsers.

Building a simple web application allows displaying different images on the page depending on the current transaction context becomes a challenge and requires using external logic. The CA Gen provides two web page design features allowing provide external logic. They are HTMLText and HTMLControl.

This post provides tips how to implement external logic using JavaScript and external frameworks. A simple application will be used as an example explaining how step by step achieves the desired result.

Example application

Web example application is very simple.

Zrzut ekranu 2017-04-24 o 09.53.16

There is a drop down list box with a list of names. Picture of the person is displayed whenever a new name is selected.

Design

Design requires the creation of a single window with the mode set to HTML. Windows has two controls. One is drop-down list box and picture control.

Zrzut ekranu 2017-04-24 o 11.04.18

External logic will be provided by the HTML Text located in the page header.

Zrzut ekranu 2017-04-24 o 11.05.25

HTMLTextHeader is not visible on the page and will be executed once by the browser when a page is loaded.

Zrzut ekranu 2017-04-24 o 11.06.13

Action block implementing procedure step displaying window does not have any logic of its own.

Zrzut ekranu 2017-04-24 o 11.07.35

It has one statement and it is just to prevent error messages. Developers will provide a number of statements in normal circumstances.

Package, Generate, Build and Deploy

The application is ready to be generated once packaging of the application is completed. Build Tool will compile all required code and Assembly function will produce ear file with all what is required to run after deployment to the target application server. URL address to invoke the application from the browser will be something like below:

http://youraddress:7001/dynimg/disimage.jsp

The sample application has been developed using the following software:

  • Windows 10
  • CA Gen 8.6 (Free)
  • Java Version 8 (Update 20)
  • JQuery 3.2.0
  • Weblogic Server Version 12.2.1.2.0

External logic explained

Writing handwritten JavaScript scripts is the main way to deliver external logic to the web pages generated from the CA Gen model when existing version of the software does not offer a suitable solution. Additionally, we are going to use jQuery library. The purpose of jQuery is to make much easier to use JavaScript when developing web pages and the jQuery is easy to learn.

Let us look first on HTML page that has been generated from the CA Gen model. The file name of the page is DISPLAY_IMAGE.html.

Code for drop-down list box look as follows:

<SELECT CLASS='DFGUICMG DropDownList' NAME='DropDownList' ID='DropDownList'
 style="dir:ltr; position:absolute; left:56; top:18; width:316; " >
 <OPTION VALUE=' ' ></OPTION>
 <OPTION VALUE='Kowalski' >Kowalski</OPTION>
 <OPTION VALUE='Skipper' >Skipper</OPTION>
 <OPTION VALUE='Private' >Private</OPTION>
 <OPTION VALUE='Rico' >Rico</OPTION>
 </SELECT>

Code for picture control looks as follows:

<IMG NAME='Picture' ID='Picture' CLASS='DFGUILIT Picture' TABINDEX=0 style=" position:absolute; left:56; top:88; width:315; height:322; "
 SRC='images/any.jpg' BORDER=0 WIDTH=315 HEIGHT=322 ALT='ANY' TITLE='ANY' >

Picture control generated above has SRC parameter set once during generation and cannot be changed inside action block. This is why we need a JavaScript to do it for us.
Part of the header section of the HTML page you will see included the following code:

<!-- HTMLTextHeader -->
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
 <script>
 $(document).ready(function(){
 $("#DropDownList").change(function(){
 $("#Picture").attr("src", "images/" + $("#DropDownList").val() + ".JPG");
 });
 });

You will notice that CA Gen generator included contents of the HTML Text control into the header section of the generated HTML. First <script> statement refers to the website with the jQuery library. The second <script> statement defines a function that will execute each time another value from the drop-down list box is selected. It listens to the change event and executes statement changing SRC parameter in the picture control. This action causes refresh and a new picture from another file is displayed in the browser.

This solution pickups images from the images subdirectory which is uploaded during deployment stage. It is important to remember to place all required images before deployment in the correct subdirectory of the model.

You can learn more about jQuery and how it works here.

Possibile modifications

This blog provides very simple example just to explain the main mechanism used creating external logic. More complicated modifications can be introduced using a similar approach. It could be more sophisticated image controls including video or images are stored in the database rather that in the file system and extracted dynamically when required. This will require to develop and implement external logic in Java using the CA Gen External Action Blocks mechanism. This can be a topic for another blog.

Links

Here you will find sample CA Gen model with the example used in this blog. Need to generate code, build web client application, assembly and deploy into one of the supported web servers.

Free Version of CA Gen 8.6 Now Available

A free version of CA Gen 8.6 is available on the CA Gen EDGE community. There are certain limitations in using of the free version of the software.  Here is how the CA Technologies comments decision allowing free download of the product:

The free version of Gen is being published to allow new users to try out Gen w/o incurring any cost, for use in training, for proof-of-concept opportunities and for long time users who are using earlier releases of Gen to check out the latest and greatest version of the product.

 

Note that the free version may only be used to create new models and will not work with existing models.  Also note that the installation of the free version does not allow models to be exchanged with an encyclopedia.

This is a very interesting product to learn. There are many ways to extend functionality of the product and use it to generate powerful software applications. A huge part of the JGen Notes will be devoted to discuss various possibilities offered by the free version of the CA Gen.

Please visit CA Gen EDGE community to learn more. You will need to join community before you can benefit from the free version of the software.

 

This website uses cookies. By continuing to use this site, you accept our use of cookies.