Easing the Transition from C++ to Java (Part 2)
Journal of Object Technology
In Part I of this article , we discussed how to address the problem of making Java and C++ co-exist in the same baseline. We introduced the Java Native Interface Simplified (JNIS) Framework as a simple mechanism that relies on common design idioms such as the Command and Observer patterns  . Instead of depending directly upon the JNI interface, we hide the details of JNI behind a set of C++ and Java wrappers for Commands, Events and Listeners shown in Figure 3 . JavaCommand execut e()
... mand execut e() realExecut e() JavaEvent attach() detach() JavaLis tener update() NativeCommand execute() preExecute() postExecute() nativeExecute() NativeEvent attach() detach() BatteryImpl: :Const ruct Battery BatteryImpl::Power ChangeEvent BatteryImpl::Power ChangeListener JBattery::Construct Battery JBattery::Power ChangeEvent JBatteryMonitor::Power ChangeListener NativeListener update() eventNo() Figure 3: Class Diagram for JNIS Framework NativeMessage put(key : St ring, value : ) get(key : St ring) : format MethodArgs() parseRet urnArgs() JavaMessage get(key : String) : put(key : String, value : ) parseMethodArgs() formatReturnArgs() JNI In Part II of this article, we will show specifically how C++ libraries service Java native commands. We will show how to use pluggable factories to map Java native calls to C++ objects. We will also show how to attach Java listeners to C++ events for notification of state changes in the C++ library.