JExternal
dv6.0E
JExternal is a 4D plug-in to execute Java methods from within 4D. JExternal enables you to use many useful Java libraries in 4D.
JExternal looks for Java files in "JavaClasses" folder and allows Java methods in those files to be used as if they were 4D plug-in methods. Besides JExternal allows the Java methods to callback 4D methods.
Create a "JavaClasses" folder and put Java files whose extensions are ".jar" into it. Java methods in the Jar files can be executed from within 4D.
Java methods called from within 4D are executed in a thread corresponding to a 4D process. If Java methods are called from two processes at the same time, they are executed in parallel.
JExternal requires JWorld which is another plug-in to launch a Java virtual machine for JExternal.
- The JavaClasses folder may be located in the following folders:
- (1) The Contens folder of JExternal_xxx.bundle
- (2) The parent folder of the structure file
- (3) The parent folder of the application file (4th Dimension or 4DServer)
- (4) 4D folder
The JavaClasses folder is searched in above order. Jar files in the JavaClasses folder found first are added to the classpath in Java.
If JExternal is used with 4D Server, the JavaClasses folder in the Contents folder of JExternal_xxx.bundle is automatically downloaded to the clients.
JExternal works with 4th Dimension / 4D Server v 6.0 or later in Mac OS and Windows. On Intel-based Macs, JExternal doesn't work with 4D v2004 or earlier, because it cannot run on Rosetta.
The current version (JExternal 6.0.0) requires 4D v11 or later, and Java 5 (JRE/JDK 1.5) or later on both platforms.
JEX Call
class method ( ClassName; MethodName; Params ) --> Status
[ C_LONGINT ]
Parameter
Type
Description
ClassName
C_TEXT
Java class name
MethodName
C_TEXT
Java method name
Params
ARRAY POINTER
Pointer array whose elements point to parameters to be passed to a Java method
JEX Call class method calls a Java class (static) method, whose class name is specified in ClassName and whose method name is specified in MethodName.
In Params, specify a pointer array whose elements point to parameters to be passed to the Java method. The results of the Java method are returned through Params. After the Java method is executed, the size of Params may be changed and its elements will point to the results returned by the Java method.
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
Refer to Type Conversion between 4D and Java and JEX Call object method.
`Script to call class method "TestMethod1" in "TestClass1" |
`Script to call class method "TestMethod2" in "TestClass1" |
`Script to call class method "TestMethod3" in "TestClass1" |
//Java Class |
JEX Call
object method ( ObjectID; MethodName; Params ) --> Status
[ C_LONGINT ]
Parameter
Type
Description
ObjectID
C_LONGINT
ID number by which a Java object is identified
MethodName
C_TEXT
Java method name
Params
ARRAY POINTER
Pointer array whose elements point to parameters to be passed to a Java method
JEX Call object method calls a Java object (instance) method, whose object ID is specified in ObjectID and whose method name is specified in MethodName.
An object ID is a positive number that identifies a Java object. Refer to Example Code below to know how to get an object ID.
In Params, specify a pointer array whose elements point to parameters to be passed to the Java method. The results of the Java method are returned through Params. After the Java method is executed, the size of Params may be changed and its elements will point to the results returned by the Java method.
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
Refer to Type Conversion between 4D and Java and JEX Call class method.
Script to call object method "TestMethod" in "TestClass2" |
//Java Class |
JEX Free
object ( ObjectID ) --> Status [ C_LONGINT ]
Parameter
Type
Description
ObjectID
C_LONGINT
ID number by which a Java object is identified
JEX Free object releases the memory for the Java object identified by ObjectID. After this method is executed, don't use this ID number again, because the Java object might be deallocated by the garbage collection.
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
Refer to Example Code for JEX Call object method.
JEX Set
environment ( JVM_ID; ProductType ) --> Status [ C_LONGINT ]
Parameter
Type
Description
JVM_ID
C_LONGINT
ID for a Java virtual machine JWD create java world returns
ProductType
C_TEXT
"PRODUCT" or "TRIAL"
JEX Set environment setups the environment for JExternal. This method has to be executed before executing any other JExternal plug-in methods. This method is usually called at "On Startup".
In JVM_ID, specify an ID number for a Java virtual machine which JWD create java world returns.
In ProductType, Specify "PRODUCT" normally. If you want to use your application with JExternal in trial mode, specify "TRIAL".
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
`Setup the environment for JExternal in "On Startup" method |
JWorld is a plug-in for 4D to launch a Java virtual machine (JVM). JExternal itself doesn't launch it. JWorld has following plug-in methods:
In Mac OS, Apple's built-in JVM is launched by JWorld. In Windows, if JWorld 6.0.0 or later is used, JWorld's built-in JVM is launched. If JWorld 5.x.x or earlier version is used in Windows, you have to install a JVM which is downloadable at the following URL:
JWD Create
java world ( JVM_Path )--> JVM_ID [ C_LONGINT ]
Parameter
Type
Description
JVM_Path
C_TEXT
"BUILT-IN", "" (blank) or a path to jvm.dll (wondows)
JWD Create java world launches a Java virtual machine (JVM) and returns its ID number.
In Mac OS, JVM_Path is always ignored and Apple's built-in JVM is launched. In Windows, specify "BUILT-IN", "" (blank) or a path to jvm.dll in JVM_Path.
If "BUILT-IN" is specified in JVM_Path using JWorld 6.0.0 or later in Windows, JWorld's built-in JVM is launched. This built-in JVM is "JRE version 6 Update 18" , which is located "Plugins/JWorld_xxx.bundle/Contents/Windows/JRE". If the built-in JVM is not found in the directory, it is considered that "" (blank) is specified in JVM_Path. If JWorld 5.x.x or earlier is used, it is also considered that "" (blank) is specified.
If "" (blank) is specified in JVM_Path in Windows, your installed JVM is launched referring to the Registry.
If a path to jvm.dll is specified in JVM_Path in Windows, the JVM identified by the path is launched.
Example of the path to jvm.dll in Windows JRE 1.6.0_02 "C:\Program Files\Java\jre1.6.0_02\bin\client\jvm.dll" JDK 1.6.0_02 "C:\Program Files\Java\jdk1.6.0_02\jre\bin\client\jvm.dll" This plug-in method should be called in "On Startup" or in a process started in "On Server Startup".
This method returns a positive number (JVM_ID), if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
C_LONGINT($JVM_ID) |
JWD Close
java world --> Status [ C_LONGINT ]
Parameter
Type
Description
(None)
JWD Close java world terminates JWorld. Call this method in "On Exit" or "On Server Shutdown".
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
C_LONGINT($Err) |
JWD Convert
line separator ( Switch ) --> Status [ C_LONGINT ]
Parameter
Type
Description
Switch
C_BOOLEAN
If Switch is True, Line separators are converted (CR <-> LF). If Switch is False, they are not converted.
If "True" is passed to JWD Convert line separator, all CRs (carriage return) are automatically converted to LFs (line feed) when 4D strings are sent to Java. And all LFs are automatically converted to CRs when Java strings are sent to 4D.
If "False" is passed to this method, any line separators are not converted.
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
C_LONGINT($Err) |
JWD Set JVM options ( Options ) --> Status [ C_LONGINT ]
Parameter
Type
Description
Options
ARRAY TEXT
Text array whose elements are JVM options.
JWD Set JVM options sets Java virtual machine options. Pass a text array whose elements are the options. Call this method before JWD Create java world is executed. Refer to the following web page about JVM options:
http://blogs.sun.com/watt/resource/jvm-options-list.html
If an option "-Djworld.stdout.redirect=true" is set, stdout and stderr can be redirected to a file whose name is "jworldout.txt" which is located in the same level as the structure file.
This method returns 0, if there is no error. If any error occurred, it returns a negative number. Refer to Error Number.
C_LONGINT($Err) C_LONGINT($JVM_ID) ` ARRAY TEXT($Options;3) $Options{1}:="-Xms128M" $Options{2}:="-Xmx128M" $Options{3}:="-Djworld.stdout.redirect=true" ` |
We provide Java developers with class libraries JExternal_xxx.jar and JWorld_xxx.jar to develop Java programs used in 4D. The class libraries is located in Plugins/JWorld_xxx.bundle/Contents/RonriKobo folder.
(JExternal_xxx.jar)
(JWorld_xxx.jar)
(JWorld_xxx.jar)
(JWorld_xxx.jar)
(JExternal_xxx.jar)
(JExternal_xxx.jar)
(JExternal_xxx.jar)
Class
com.ronri_kobo.JExternal.DBWorld
java.lang.Object
|
+----com.ronri_kobo.JExternal.DBWorld
public class DBWorld extends java.lang.Object
This class is a stub of 4D. This class has 1 constructor and 2 class methods 1 instance method as follows:
DBWorld
public DBWorld(int processNo) throws com.ronri_kobo.JExternal.InvalidProcessNoException
This constructor requires a 4D process number specified in processNo. In the process, callback methods will be executed.
Refor to call4Dmethod below.
public static synchronized int createObjectID(java.lang.Object obj)
This method returns the ID number of a object specified in obj, by which the object can be identified in 4D. This method prevents the garbage collection from deallocating the object.
The ID number is used in JEX Call object method and JEX Free object.
public static synchronized void alert(java.lang.String message)
This method displays a alert dialog box with message. This method corresponds with 4D command "ALERT".
public java.lang.Object call4DMethod(java.lang.String methodName,
java.lang.Object[] parameter)
throws com.ronri_kobo.JExternal.InvalidMethodNameException,
com.ronri_kobo.JExternal.InvalidParametersException
This method callbacks a 4D method, whose method name is specified in methodName. The 4D method is executed in a process whose number was passed to the constructor DBWorld. When the 4D method is called, JEX Call class method or JEX Call object method must be executed in the process. These plug-in methods can yield their process time to the callback method.
In parameter, specify an array of the Object class whose elements are parameters to be passed the 4D method. To pass primitive types (int, double...), the wrapper objects must be created for them.
This method always returns an object of the Object class, which corresponds with $0 in the 4D method. The object will be unwrapped or cast to use in your program.
If the 4D method returns a pointer to a ARRAY POINTER, this method returns an array of the Object class whose elements correspond with the elements of the ARRAY POINTER. The elements of the array will be unwrapped or cast to use in your program.
Refer to Type Mapping and demos for JExternal.
import java.lang.*; |
`4D Method "QueryAge" --- callback method |
java.lang.Object
|
+----com.ronri_kobo.Time
public class Time extends java.lang.Object implements java.io.Serializable
This class is in JWorld_xxx.jar in RonriKobo folder and corresponds with C_TIME in 4D.
Time
public Time(int hour, int min, int sec)
This method creates an object of the Time class and initializes its hour, minute and second with specified values.
public int getHours()
This method returns the hour of the Time object.
public int getMinutes()
This method returns the minute of the Time object.
public int getSeconds()
This method returns the second of the Time object.
public void setHours(int hour)
This method replaces the current hour of the Time object with a specified value.
public void setMinutes(int min)
This method replaces the current minute of the Time object with a specified value.
public void setSeconds(int sec)
This method replaces the current second of the Time object with a specified value.
java.lang.Object
|
+----com.ronri_kobo.Date
public class Date extends java.lang.Object implements java.io.Serializable
This class is in JWorld_xxx.jar in RonriKobo folder and corresponds with C_DATE in 4D.
Date
public Date(int year, int month, int date)
This method creates an object of the Date class and initializes its year, month and date with specified values.
public int getYear()
This method returns the year (0-32767) of the Date object.
public int getMonth()
This method returns the month (1-12) of the Date object.
public int getDate()
This method returns the day (1-31) of the Date object.
public void setYear(int year)
This method replaces the current year of the Date object with a specified value (0-32767).
public void setMonth(int month)
This method replaces the current month of a Date object with a specified value (1-12).
public void setDate(int date)
This method replaces the current date of the Date object with a specified value (1-31).
java.lang.Object
|
+----com.ronri_kobo.Picture
public class Picture extends java.lang.Object implements java.io.Serializable
This class is in JWorld_xxx.jar in RonriKobo folder. and corresponds with C_PICTURE in 4D.
Picture
public Picture(byte picture[])
This method creates an object of the Picture class and initializes it with the specified byte array.
public byte[] getBytes()
This method converts the Picture object into a byte array and returns it.
public void setBytes(byte picture[])
This method converts the specified byte array into a Picture object and replaces the current Picture object with it.
Class
com.ronri_kobo.JExternal.InvalidProcessNoException
java.lang.Object
|
+----java.lang.Throwable
|
+----java.lang.Exception
|
+----com.ronri_kobo.JExternal.InvalidProcessNoException
public class InvalidProcessNoException extends java.lang.Exception
This exception occurs when an invalid process number of 4D is passed to DBWorld.
![]()
InvalidProcessNoException
public InvalidProcessNoException()
Class
com.ronri_kobo.JExternal.InvalidMethodNameException
java.lang.Object
|
+----java.lang.Throwable
|
+----java.lang.Exception
|
+----com.ronri_kobo.JExternal.InvalidMethodNameException
public class InvalidMethodNameException extends java.lang.Exception
This exception occurs when an invalid method name is passed to call4DMethod.
![]()
InvalidMethodNameException
public InvalidMethodNameException()
Class
com.ronri_kobo.JExternal.InvalidParametersException
java.lang.Object
|
+----java.lang.Throwable
|
+----java.lang.Exception
|
+----com.ronri_kobo.JExternal.InvalidParametersException
public class InvalidParametersException extends java.lang.Exception
This exception occurs when invalid parameters are passed to call4DMethod.
![]()
InvalidParametersException
public InvalidParametersException()
When passing parameters to a Java method or receiving results from a Java method, their data types are converted as follows:
4D
<->
Java
C_BOOLEAN
<->
boolean
C_INTEGER
->
int
C_LONGINT
<->
int
C_REAL
<->
double
C_TIME
<->
com.ronri_kobo.Time
C_DATE
<->
com.ronri_kobo.Date
C_TEXT
<->
java.lang.String
C_PICTURE
<->
com.ronri_kobo.Picture
C_BLOB
<->
byte[]
ARRAY BOOLEAN
<->
boolean[]
ARRAY INTEGER
<->
short[]
ARRAY LONGINT
<->
int[]
ARRAY REAL
<->
double[]
ARRAY DATE
<->
com.ronri_kobo.Date[]
ARRAY TEXT
<->
java.lang.String[]
ARRAY PICTURE
<->
com.ronri_kobo.Picture[]
-15901
Java session could not be opened
-15902
Old version of 4D
-15903
68K Macintosh is used
-15904
Old version of Mac OS
-15905
Old version of MRJ
-15906
JWorld_xxx.jar was not found
-15920
Java session was not yet opened
-15922
Basic Java classes for JWorld were not found
-15923
Basic Java methods for JWorld were not found
-15924
libJWorld.jnilib was not found
-15925
java.security was not found
-15926
An error occurred when the classpath was set
-15927
Not enough memory for the classpath
-15928
An error occurred when the Java VM thread was created
-15929
Invalid Java VM DLL
-15930
jvm.dll was not found
-15931 Old version of Java VM (In Windows J2SE is required as a Java VM)
-17002
Invalid class name
-17003
Invalid method name
-17005
A pointer array was not specified
-17301
The Java method could not be executed
-17302
The Java object was not found
-18000
Trial is over
-18007
JExternal_xxx.jar was not found
-18010
Basic Java classes for JExternal were not found
-18011
Basic Java methods for JExternal were not found
-18012
Invalid JVM ID
-18021
The plug-in method tried to be executed before executing JEX Set environment
-18022
Invalid parameters
-18023
Not enough memory-1
-18024
Not enough memory-2
-18025
Not enough memory-3
-18029
Invalid return type(s)
1
A Java method cannot return over 99 results to 4D.
2
A Java method cannot pass over 99 parameters to a callback method.
3
Any two-dimensional array cannot be passed and returned between 4D and Java.
4
A Java method cannot be called in a callback method.
5
Any user interface components cannot be used in a Java method.
6 The plug-in names of JExternal_xxx.bundle and JWorld_xxx.bundle cannot be changed.
Copyright (C) Ronri Kobo, Inc. All rights reserved.