RDP Crystal EDI Controls opened for Java world with Javonet.io!

Tags

Lucas Berwid
Cross Platform Engineer at Javonet

We are pleased to introduce you the case study that presents the usage of our new unique cloud based solution powered by Javonet which enabled RDP Crystal company to generate instantly, the strongly typed wrappers from .NET DLLs as ready-to-use Java JAR packages. Using this new cloud service allowed our customer to distribute instantly their .NET UI and back-end controls product to the Java market within only few minutes and with the native performance and functionality.

The main products of RDP Crystal are libraries for handling EDI documents. EDI (short for Electronic Data Interchange) is an electronic message data format that unifies communication between companies. The major business value entails lowering costs, improving speed and accuracy, and increasing business efficiency. The RDP Crystal EDI Library is a suite of EDI components that can create and manipulate EDI files. Features include parsing, joining, splitting, validation, and loading. It works in both WPF and WinForms applications and supports any .NET language. The product is used by the US Department of Energy, Fortune 100 Companies, Fortune 500 Companies, and other enterprises all over the world.

To download the DLL, go to http://www.rdpcrystal.com. The suite consists of major components split into three separate DLL files.

RDP Crystal provides now the compiled Jar and Java samples within their official package but if would like to see how .NET DLLs can be converted into Jars you can create on on your own. To create a strongly typed wrapper with Javonet.io, you need to convert all of the files at once by dropping them on the Javonet.io website.

The output is shown on the screen below. After the generation is done you will get ready-to-use jar file and Github repository link where sources of wrapper with compiled binaries are stored. Compiled binaries will be in the target/ folder. The src/ folder contains all wrapper classes and is created only for your convenience. In order to guarantee a smooth Java experience, we wrap internal .NET classes and all external dependencies. To avoid Java and .NET class clashes, we renamed .NET System namespace to jio.System (we will talk more about resolving cross-language clashes in the future posts). All the types used in the RDP Crystal EDI Library were wrapped with all their .NET dependencies.

RDP Crystal has provided sample projects to show how to use the EDI Library:

In order to verify if everything had been wrapped correctly, we recreated all the .NET samples in Java as Swing applications. All samples are available on our GitHub repository (https://github.com/Javonet/RDPCrystal). You can download and test them yourself! Each sample replicates the functionality of the .NET counterpart proving that 100% of .NET functionality is now available for Java developers.

Let’s have a closer look at one of the sample projects and see how exactly was it created. We will look into the Create856EDIFile project (Create856EDIFile on GitHub) and explore the differences between the .NET and Java version.

First, let’s compare running applications. The .NET application was created using WinForms:

The Java version of above application was created using Swing:

When you compare both applications it becomes obvious that there are no differences between them despite the UI differences between .NET and Java frameworks.

This is because when using Javonet we can embed the .NET UI controls directly in the Java AWT, Swing or JavaFX application. Here the main elements of the application are the EDIFileLoader, EDIDocumentViewer, and EDIDocument, which all are the .NET controls and some back-end classes from RDP developers API. The project contains also some custom classes, such as Order, that were defined only for the purpose of this sample to present functionalities of the library. For this example, these classes were completely rewritten in Java the same way as they are implemented in .NET sample. It means the final experience of Java developers and ability to interact with RDP library is exactly the same as if they were using pure Java RDP library.

To write the project, we created an empty Java Swing application and combined Swing controls (such as JTextAreas and JButtons) with .NET controls (such as EDIFIleLoader). Using strongly typed wrappers, it is as easy as working with Java code which can change the state of .NET objects on actions originating from Java controls and Java back-end logic.

For example, to generate an EDI Document in .NET, the following code is used:

private void btnGenerate_Click
          (object sender, EventArgs e)
{
  try
  {
   sampleEDI856File=new EDIDocument();

   CreateEDIFile();

   rtbGeneratedFile.Text = 
      sampleEDI856File
         .GenerateEDIData();

   ediDocumentViewer1
     .LoadDocument(sampleEDI856File);
  }
  catch (Exception ex)
  {
    MessageBox
       .Show(ex.Message, 
       "RDPCrystal EDI Library");
  }
}

When converted to Java code with Javonet it looks as follows:

private void btnGenerate_Click()
{
 try
 {
   sampleEDI856File=new EDIDocument();

   CreateEDIFile();

   this.textArea
     .setText(sampleEDI856File
     .GenerateEDIData());

   this.ediDocumentViewer
     .LoadDocument(sampleEDI856File);
 }
 catch (Exception ex)
 {
   JOptionPane
       .showMessageDialog(this, 
            ex.toString());
 }
}

For a Java programmer familiar with the EDI Library, it would be clear that Java calls invoke underlying .NET methods but completely impossible to notice as the API is strongly typed and performance is native.

You can see that Java developers get the same access to EDI libraries as .NET developers have and can use all of the functionalities. From the usage syntax the only differences are those that differentiate Java and C# programming languages to stay aligned with standards to which developers are used to. In example the setters and getters of properties or subscribing events differs in terms of syntax but entire logic and interaction with library is exactly the same on both platforms!

In this article, we described a use case of Javonet.io for RDP Crystal. I hope you found this example helpful. Go ahead and try it yourself on your user controls or RDP package!

Read more about Javonet.io: