Class OxEngine
- java.lang.Object
-
- com.jstatcom.engine.ox.OxEngine
-
- All Implemented Interfaces:
- Engine
public final class OxEngine extends java.lang.Object implements Engine
Engine implementation to handle calls to the Ox program. Ox can be downloaded from http://www.nuff.ox.ac.uk/Users/Doornik/doc/ox/. It must be installed to run this engine. The exact location of the Ox dll must be set injox/engine_config.xml. A dialog will appear to ask for it, if it was not set before.The engine can create objects from Ox classes and invoke methods defined by those classes. Modules (.ox or .oxo files) must reside in the
joxsubfolder. Static methods cannot be called directly, but only member functions of Ox classes.This engine takes JSCData arrays as arguments and return types and automatically does the conversion to and from the corresponding Ox types. Input and return parameters of the respective Ox function have to be known and the correct
JSCTypeshave to be specified.Usage Example:
It is assumed, that there is a moduleoxmodule.ox(o)in thejoxsubfolder:#include <oxstd.h>
// more includes
class MyClass {
decl lags;
MyClass();
setLags(const p);
... // more declarations
}
MyClass::setLags(const p){
lags = p;
}
... // more member methods
The Java call to that module could look like this:
Engine ox = EngineTypes.OX.getEngine();
ox.load("oxmodule", OxLoadTypes.OXO, null);
ox.load("MyClass", OxLoadTypes.CLASS, new JSCData[]{new JSCInt("arg", 3)}); // new MyClass(3)
ox.call("setLags", new JSCData[]{new JSCInt("lags", 3), null) // myclass.setLags(3);
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidcall(java.lang.String procName, JSCData[] args, JSCData[] retData)Makes a call to a memberfunction of an Ox object.static OxEnginegetInstance()Returns an instance of theOxEnginethat is a Singleton.booleanisValid(JSCTypes type)Gets whethertypecan be handled by this engine.voidload(java.lang.String loadName, LoadTypes loadType, JSCData... args)Loads a module according to the load type.voidshutdown()Shuts down Ox workspace.voidstop()Always throws an exception, because Ox engine tasks cannot be stopped.
-
-
-
Method Detail
-
getInstance
public static OxEngine getInstance()
Returns an instance of theOxEnginethat is a Singleton.- Returns:
- an engine instance
- Throws:
java.lang.RuntimeException- if the native support libraries cannot be found
-
call
public void call(java.lang.String procName, JSCData[] args, JSCData[] retData)Makes a call to a memberfunction of an Ox object. The object has to be created before via theloadmethod with theOxLoadTypes.CLASSargument.Input objects must not be empty or
null. They are never changed by the Ox call. The following parameter conversion rules apply:JSCInt - OX_INTJSCNumber - OX_DOUBLEJSCNArray - OX_MATRIXJSCString - OX_STRINGJSCSArray- if cols == 1;
OX_ARRAY(rows x 1) filled withOX_STRINGvalues - else;
OX_ARRAY(rows x 1) withOX_ARRAY(cols x 1) values, each of them filled withOX_STRINGvalues
- if cols == 1;
Return types may be empty but not
null. They are overwritten by the return values from the Ox call. The following parameter conversion rules apply:- return is
JSCInt -takesOX_INT, OX_DOUBLEor 0:0 element ofOX_MATRIXif dimension is 1:1, ifOX_INT, OX_DOUBLE, OX_MATRIXis empty, then return type is cleared - return is
JSCNumber -takesOX_INT, OX_DOUBLEor 0:0 element ofOX_MATRIXif dimension is 1:1, ifOX_INT, OX_DOUBLE, OX_MATRIXis empty, then return type is cleared - return is
JSCNArray -takesOX_INT, OX_DOUBLEorOX_MATRIX, ifOX_INT, OX_DOUBLE, OX_MATRIXis empty, then return type is cleared - return is
JSCString -takesOX_STRINGor 0:0 element ofOX_ARRAYif dimension is 1:1, ifOX_STRING, OX_SARRAYis empty, then return type is cleared,OX_ARRAYcan contain one value or anotherOX_ARRAYwith just one value, higher array nesting is not allowed - return is
JSCSARRAY -takesOX_STRINGorOX_ARRAY(as vector of values or otherOX_ARRAYs) with elements that are eitherOX_STRING, OX_DOUBLE, OX_INT, ifOX_STRING, OX_ARRAYis empty, then return type is cleared, only up to 2 dimensional arrays with scalar values are supported
If none of the rules apply for the given return type, a
RuntimeExceptionis issued.- Specified by:
callin interfaceEngine- Parameters:
procName- name of the member function of the loaded classargs- arguments for function, number must match exactly with method signatureretData- return types from function, number must not match exactly with number of actually returned parameters, can benull- Throws:
java.lang.IllegalArgumentException-if (procName == null || procName.length() == 0)or ifargsorretDatacontainnullelements or unsupported types or if an element ofargsis empty but not BYREFjava.lang.RuntimeException- if the module to load could not be found or if the call to the Ox system library resulted in an error
-
isValid
public boolean isValid(JSCTypes type)
Gets whethertypecan be handled by this engine.
-
load
public void load(java.lang.String loadName, LoadTypes loadType, JSCData... args)Loads a module according to the load type.Usage Note:
OxLoadTypes.VIEWER -spawns the viewer withloadNameas file argument,argsis ignored. The file to view must be specified with the absolute path.OxLoadTypes.OXO -loads the ox file specified withloadNamein the workspace. The filename must not contain the .ox or .oxo suffix. IfJSCConstants.DEBUG == true, then the .ox file is searched first, otherwise the compiled object file .oxo. The argumentargsis ignored. All filenames must be specified relative to the resource directory for the Ox engine.OxLoadTypes.CLASS -creates an instance of the class with the nameloadNameand the constructor argumentsargs. The file containing the class must have been loaded before viaOxLoadTypes.OXO. The created object is then set to be the current object and all calls via thecallmethod assume, that this object is used.
- Specified by:
loadin interfaceEngine- Parameters:
loadName- the name of the module to loadloadType- the type of the load operation to invokeargs- ignored forOxLoadTypes.OXOandOxLoadTypes.VIEWER, but used forOxLoadTypes.CLASSas constructor arguments, can benull- Throws:
java.lang.IllegalArgumentException-if (loadName == null || loadType == null)orif (loadName.length() == 0)or ifargscontainsnullor empty elements or unsupported types when used withOxLoadTypes.CLASSjava.lang.RuntimeException- if the module to load could not be found or if the call to the Ox system library resulted in an error- See Also:
Engine
-
stop
public void stop()
Always throws an exception, because Ox engine tasks cannot be stopped.- Specified by:
stopin interfaceEngine- Throws:
java.lang.UnsupportedOperationException- See Also:
Engine.stop()
-
shutdown
public void shutdown()
Shuts down Ox workspace.- Specified by:
shutdownin interfaceEngine- See Also:
Engine.shutdown()
-
-
DMelt 3.0 © DataMelt by jWork.ORG