JBI Component development (Part 4)

Java JNI Wrapper Library - JNIWrapper

1. The Java JNI Wrapper Library (JNIWrapper)

Java Native Interface (JNI) is a standard programming interface for writing Java native methods and embedding the Java virtual machine into native applications. The primary goal is binary compatibility of native method libraries across all Java virtual machine implementations on a given platform.

JNI Spec available at:
http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html

Components of the JNI library: MyLib:

- MyLib C. (MyLib.so or .dll)
- Java JNI Wrapper using native call to MyLib C. (JNIWrapper.jar)
- WSDL that describe the Java JNI Library interface. (MyLib.wsdl).


To create the JNIWrapper, use NetBeans and create a new Java project: JNIWrapper.
At the end of this topic the project will produce a JNIWrapper.jar file.

1.1.Build the JNIWrapper:

For this use case the native library is called MyLib and is written in C and provides 2 methods:






The parameter to define a rule in the getPolicyRule method is a C structure:





To wrap the C structure we use a Java class:





To map the two C methods with Java, we need to declare two java native methods:





Use the javah tool from the SDK to generate the .h that define the natice call:




Now you need to implement the source.c that include the .h generated by javah.
At the Java level we created the two methods that wrap the native call:





Our JNIWrapper is now ready, we need to create the WSDL file that define our JNIWrapper library.

1.2. Create the WSDL


The WSDL (MyLib.wsdl) will define two operations and a complex type as:

- getPolicyRule operation for the java method: getPolicyRule(String ruleName);
- setPolicyRule operation for the java method: setPolicyRule(PMRULE rule);
- Rule type for the java class PMRule.





See part 5 ...

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Christophe Vaille

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today