MapForce-generated code can be integrated, or adapted to your specific application, even though the result of code generation is a complete and fully-functioning application. Some typical scenarios where you might want to change the generated code are as follows:
•Define custom source or target files for the mapping application
•Add custom error handling code
•In C# or Java generated code, you can also change the data type of the mapping input programmatically (for example, from string to stream).
This section provides instructions on how to achieve these goals, based on the DB_CompletePO.mfd sample mapping available in the <マイ ドキュメント>\Altova\MapForce2020\MapForceExamples\ directory.
DB_CompletePO.mfd mapping sample in MapForce
As illustrated above, the sample mapping consists of two sources and one target:
•ShortPO.xml is a source XML file
•CustomersAndArticles.mdb is a source database
•CompletePO.xml is the target XML file.
In the generated code, these sources and targets will translate to two input and one output parameters supplied to the run method which executes the mapping (as described in the subsequent topics). For now, note the following basic points about code generation:
•The number of source 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.
If a mapping includes database components, the generated run method includes the database connection object at the appropriate location. For example, if the mapping uses three sources (text content, XML content and a database) to map to a single output file, MapForce generates the following run method:
void run(Input in1, Input in2, java.sql.Connection dbConn, Output out1);
The argument order is important. As you will see in the subsequent examples, you can modify dbConn parameters, or use the default parameters generated by MapForce when integrating your code.