com.jstatcom.engine.ox
Class OxEngine

java.lang.Object
  extended by 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 in jox/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 jox subfolder. 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 JSCTypes have to be specified.

Usage Example:
It is assumed, that there is a module oxmodule.ox(o) in the jox subfolder:

#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);

Author:
Markus Kraetzig

Method Summary
 void call(java.lang.String procName, JSCData[] args, JSCData[] retData)
          Makes a call to a memberfunction of an Ox object.
static OxEngine getInstance()
          Returns an instance of the OxEngine that is a Singleton.
 boolean isValid(JSCTypes type)
          Gets whether type can be handled by this engine.
 void load(java.lang.String loadName, LoadTypes loadType, JSCData... args)
          Loads a module according to the load type.
 void shutdown()
          Shuts down Ox workspace.
 void stop()
          Always throws an exception, because Ox engine tasks cannot be stopped.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static OxEngine getInstance()
Returns an instance of the OxEngine that 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 the load method with the OxLoadTypes.CLASS argument.

Input objects must not be empty or null. They are never changed by the Ox call. The following parameter conversion rules apply:

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:

If none of the rules apply for the given return type, a RuntimeException is issued.

Specified by:
call in interface Engine
Parameters:
procName - name of the member function of the loaded class
args - arguments for function, number must match exactly with method signature
retData - return types from function, number must not match exactly with number of actually returned parameters, can be null
Throws:
java.lang.IllegalArgumentException - if (procName == null || procName.length() == 0) or if args or retData contain null elements or unsupported types or if an element of args is empty but not BYREF
java.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 whether type can be handled by this engine.

Specified by:
isValid in interface Engine
Parameters:
type - the type to check
Returns:
true if type is one of NARRAY, INT, NUMBER, SARRAY or STRING, false otherwise

load

public void load(java.lang.String loadName,
                 LoadTypes loadType,
                 JSCData... args)
Loads a module according to the load type.

Usage Note:

Specified by:
load in interface Engine
Parameters:
loadName - the name of the module to load
loadType - the type of the load operation to invoke
args - ignored for OxLoadTypes.OXO and OxLoadTypes.VIEWER, but used for OxLoadTypes.CLASS as constructor arguments, can be null
Throws:
java.lang.IllegalArgumentException - if (loadName == null || loadType == null) or if (loadName.length() == 0) or if args contains null or empty elements or unsupported types when used with OxLoadTypes.CLASS
java.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:
stop in interface Engine
Throws:
java.lang.UnsupportedOperationException
See Also:
Engine.stop()

shutdown

public void shutdown()
Shuts down Ox workspace.

Specified by:
shutdown in interface Engine
See Also:
Engine.shutdown()