News About Us Support Bugs & Tasks Links
dklfgj dfgjmpsdklg dfgjdsklfg dfjglksdfjg sdfgjokdfjg dfgjoksdfjg sdfgjksdlfgjsdf gdgjopksdfgj

Incorporating Java Bean into APSIM

RSS
This is a brief guide for integrating a Java-written model into C# source code. For developing a model in C#, or rather the interface between the model and APSIM, see Developing Models for APSIM. Once you have the C# framework you'd need to do the following:


1. Convert the Java Bean into a COM object dll. See ActiveX Bridge


2. Use the COM object in the C# source code. See Invoking COM Components from C#



Tips from my personal experience:

• ActiveX Bridge - VCVARS32.bat contents (in case you don't have it)

echo off

rem Root of Visual Developer Studio Common files.

set VSCommonDir=C:\PROGRA~1\MICROS~3\Common

rem rem Root of Visual Developer Studio installed files. rem set MSDevDir=C:\PROGRA~1\MICROS~3\Common\msdev98

rem rem Root of Visual C++ installed files. rem set MSVCDir=C:\PROGRA~1\MICROS~3\VC98

rem rem VcOsDir is used to help create either a Windows 95 or Windows NT specific path. rem

set VcOsDir=WIN95

if "%OS%" == "Windows_NT" set VcOsDir=WINNT

rem echo Setting environment for using Microsoft Visual C++ tools. rem

if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\BIN;%MSVCDir%\BIN;%VSCommonDir%\TOOLS\%VcOsDir%;%VSCommonDir%\TOOLS;%PATH%

if "%OS%" == "" set PATH="%MSDevDir%\BIN";"%MSVCDir%\BIN";"%VSCommonDir%\TOOLS\%VcOsDir%";"%VSCommonDir%\TOOLS";"%windir%\SYSTEM";"%PATH%"

set INCLUDE=%MSVCDir%\ATL\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\MFC\INCLUDE;%INCLUDE%

set LIB=%MSVCDir%\LIB;%MSVCDir%\MFC\LIB;%LIB%

set VcOsDir=

set VSCommonDir=

• Invoking COM Components from C#

Early Bound Access to COM, as described in the article (2.) is great in the IDE. But when running it issued an error message which I couldn't sort out quickly. So eventually I reverted to the Late Bound Access to COM which looks a bit more complex to write but works perfectly in run-rime.

• Events - Haven't dealt yet with passing events generated by the Java Bean through the C# wrapper. I'm not sure there is an elegant way of doing this. I imagine the "last resort" solution would be to poll the Java Bean for any happenings in OnProcess() and generate required events in the C# code.



Hemda Levy
email: hemda.levy@dairynz.co.nz

SiteSearch, Login/Logout, Account Settings, Create a new Page