Altova MapForce 2024 Professional Edition

Modify Input/Output, Define Error Handling

Home Prev Top Next

This topic explains how to modify source and target files and define error handling for the mapping application in Java, C#, and C++ code. To illustrate these procedures, we use the MapForceExamples\CompletePO.mfd sample mapping. The mapping consists of three source components (ShortPO.xml, Customers.xml, and Articles.xml) and one target component (CompletePO.xml).

 

In the generated code, these sources and targets will translate to three input and one output parameters supplied to the Run method which executes the mapping. Note the following basic points about code generation:

 

The number of sources and targets in the mapping design corresponds to the number of mapping parameters to the Run method in the generated code.

If you change the number of sources or targets of the mapping, then you will need to re-generate the code accordingly.

If you make changes to the generated code and then re-generate the code at the same location, all changes will be overwritten.

 

Java

This example uses Eclipse as a Java IDE. To begin, generate Java code from the MapForceExamples\CompletePO.mfd sample mapping and then import the project into Eclipse. For information about generating Java code and importing it into Eclipse, see Generate, Build, and Run Code.

 

To edit the generated Java console application, locate the main method of your generated application in the Project Explorer of Eclipse (screenshot below). By default, this method is located in the MappingConsole class of the com.mapforce package. Otherwise, it is in the MappingConsole class of your custom defined package.

CG_Eclipse_CompletePO

To edit the generated Java dialog application, locate the place in the code where the run method is invoked from your generated application. By default, the run method is invoked from the class called MappingFrame.java of the com.mapforce package (screenshot above).

 

Modify sources and targets

The code listing below illustrates an extract from the main method in the generated Java console application. The paths to the sources and targets are shown below and are defined as parameters to the run method. If you need to change the sources and/or targets, change the values of the parameters shown below.

 

com.altova.io.Input Customers2Source = com.altova.io.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Customers.xml");

                 com.altova.io.Input Articles2Source = com.altova.io.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Articles.xml");

                 com.altova.io.Input ShortPO2Source = com.altova.io.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/ShortPO.xml");

                 com.altova.io.Output CompletePO2Target = new com.altova.io.FileOutput("CompletePO.xml");

 

Define custom error handling

If you need to add your custom error-handling code, modify the catch statement in the main method (console application) or in MappingFrame.java (GUI application).

 

C#

This example uses Microsoft Visual Studio as a C# IDE. To begin, generate C# code from the MapForceExamples\CompletePO.mfd sample mapping and then open the solution in Visual Studio. For information about generating code and importing it into Visual Studio, see Generate, Build, and Run Code.

 

To edit the generated C# application, navigate to the Main method of your generated application in the Solution Explorer of Visual Studio (screenshot below). By default, the solution file is called Mapping.sln and is located in the Mapping subdirectory relative to the directory where you saved the generated code.

CG_VS_CS_CompletePO

Modify sources and targets

The code listing below illustrates an extract from the Main method in the generated C# application. The paths to the sources and targets are shown below and are defined as parameters to the Run method. If you need to change the sources and/or targets, change the values of the parameters shown below.

 

Altova.IO.Input Customers2Source = Altova.IO.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Customers.xml");

                         Altova.IO.Input Articles2Source = Altova.IO.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Articles.xml");

                         Altova.IO.Input ShortPO2Source = Altova.IO.StreamInput.createInput("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/ShortPO.xml");

                         Altova.IO.Output CompletePO2Target = new Altova.IO.FileOutput("CompletePO.xml");

 

Define custom error handling

If you need to add your custom error-handling code, modify the catch statement in the Main method.

 

C++

This example uses Microsoft Visual Studio as a C++ IDE. To begin, generate C++ code from the MapForceExamples\CompletePO.mfd sample mapping and then open the solution in Visual Studio. For information about generating code and importing it into Visual Studio, see Generate, Build, and Run Code.

 

To edit the generated C++ application, navigate to the _tmain method of your generated application in the Solution Explorer of Visual Studio (screenshot below). By default, the solution file is called Mapping.sln and is located in the Mapping subdirectory relative to the directory where you saved the generated code.

CG_VS_CPP_CompletePO

Modify sources and targets

The code listing below illustrates an extract from the _tmain method in the generated C++ application. The paths to the sources and targets are shown below and are defined as parameters to the Run method. If you need to change the sources and/or targets, change the values of the parameters shown below.

 

MappingMapToCompletePO MappingMapToCompletePOObject;

                 MappingMapToCompletePOObject.Run(

                         _T("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Customers.xml"),

                                 _T("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/Articles.xml"),

                                 _T("C:/Users/<UserName>/Documents/Altova/MapForce2024/MapForceExamples/ShortPO.xml"),

         _T("CompletePO.xml"));

 

Define custom error handling

If you need to add your custom error-handling code, modify the catch statement in the _tmain method.

 

© 2018-2024 Altova GmbH