Altova MapForce 2025 Enterprise Edition

Generate Code (Alternative)

Home Prev Top Next

The following JScript example shows how to load an existing document and generate different kinds of mapping code for it.

 

// ------------------- begin JScript example ---------------------
// Generate Code for existing mapping.
// works with Windows scripting host.
 
// ----------------- helper function ------------------
function Exit(strErrorText)
{
  WScript.Echo(strErrorText);
  WScript.Quit(-1);
}
 
function ERROR(strText, objErr)
{
  if (objErr != null)
     Exit ("ERROR: (" + (objErr.number & 0xffff) + ")" + objErr.description + " - " + strText);
  else
     Exit ("ERROR: " + strText);
}
// ---------------------------------------------------
 
// ----------------- MAIN ------------------
 
// ----- create the Shell and FileSystemObject of the windows scripting
try
{
  objWshShell = WScript.CreateObject("WScript.Shell");
  objFSO = WScript.CreateObject("Scripting.FileSystemObject");
}
catch(err)
  { Exit("Can't create WScript.Shell object"); }
 
// ----- open MapForce or access running instance and make it visible
try
{
  objMapForce = WScript.GetObject ("", "MapForce.Application");
  objMapForce.Visible = true;     // remove this line to perform background processing
}
catch(err) { WScript.Echo ("Can't access or create MapForce.Application"); }
 
// ----- open an existing mapping. adapt this to your needs!
objMapForce.OpenDocument(objFSO.GetAbsolutePathName ("Test.mfd"));
 
// ----- access the mapping to have access to the code generation methods
var objDoc = objMapForce.ActiveDocument;
 
// ----- set the code generation output properties and call the code generation methods.
// ----- adapt the output directories to your needs
try
{
  // ----- code generation uses some of these options
  var objOptions = objMapForce.Options;
 
  // ----- generate XSLT -----
  objOptions.XSLTDefaultOutputDirectory = "C:\\test\\TestCOMServer\\XSLT";
  objDoc.GenerateXSLT();
 
  // ----- generate Java Code -----
  objOptions.CodeDefaultOutputDirectory = "C:\\test\\TestCOMServer\\Java";
  objDoc.GenerateJavaCode();
 
  // ----- generate CPP Code, use same cpp code options as the last time -----
  objOptions.CodeDefaultOutputDirectory = "C:\\test\\TestCOMServer\\CPP";
  objDoc.GenerateCppCode();
 
  // ----- generate C# Code, use options C# code options as the last time -----
  objOptions.CodeDefaultOutputDirectory = "C:\\test\\TestCOMServer\\CHash";
  objDoc.GenerateCHashCode();
}
catch (err)
  { ERROR ("while generating XSL or program code", err); }
 
 
// hide MapForce to allow it to shut down
objMapForce.Visible = false;
 
// -------------------- end example ---------------------

© 2018-2024 Altova GmbH