XPRM
- java.lang.Object
-
- com.dashoptimization.XPRM
-
public class XPRM extends java.lang.Object
Methods for initialisation as well as model compilation and loading of compiled models into Mosel.
-
-
Field Summary
Modifier and Type Field and Description static int
F_ERROR
Code for error stream.static int
F_INPUT
Code for input stream.static int
F_LINBUF
Code for enabling line buffering (output stream).static int
F_OUTPUT
Code for output stream.
-
Constructor Summary
Constructor and Description XPRM()
Generate an XPRM object and initialise Mosel.XPRM(java.lang.String dsopath)
Generate an XPRM object and initialise Mosel with a default modules path.
-
Method Summary
Modifier and Type Method and Description static boolean
beginLicensing()
Begin the OEM licensing process.static void
bind(java.lang.String name, java.lang.Object obj)
Bind an object to a name.void
compile(java.lang.String src)
Compile a model source file.void
compile(java.lang.String options, java.lang.String src)
Compile a model source file.void
compile(java.lang.String options, java.lang.String src, java.lang.String dest)
Compile a model source file.void
compile(java.lang.String options, java.lang.String src, java.lang.String dest, java.lang.String comm)
Compile a model source file.void
compile(java.lang.String options, java.lang.String src, java.lang.String dest, java.lang.String comm, java.lang.String pass, java.lang.String privkey, java.lang.String pubkeys)
Compile a model source file.static void
endLicensing()
End the OEM licensing process.java.lang.String
expandPath(java.lang.String path)
Expand a path.void
finalize()
Finalize the Mosel instance.XPRMModule
findModule(java.lang.String moduleName)
Find a module by its name.void
flushModules()
Unload unused modules.java.lang.String
getDefaultWorkDir()
Get the default working directory.java.lang.String
getModulesPath()
Get the directory list where modules are searched for.XPRMVersion
getVersion()
Get Mosel version.XPRMVersion
getVersion(int whichone)
Get version information.XPRMIODrivers
IODrivers()
Get an iterator to enumerate all IO drivers.static XPRMLicense
license()
Generate a license object.static XPRMLicense
license(java.lang.String path)
Generate a license object.static void
license(XPRMLicense lic)
Check license.XPRMModel
loadModel(java.lang.String name)
Load a compiled model into memory.XPRMModel
loadModel(java.lang.String name, java.lang.String options, java.lang.String pass, java.lang.String privkey, java.lang.String pubkeys)
Load a compiled model into memory.XPRMModule
loadModule(java.lang.String moduleName)
Explicitly load a module.XPRMModules
modules()
Get an iterator to enumerate all loaded modules.boolean
removeTmpDir()
Remove the Mosel temporary directory.void
setAutoUnloadModules(boolean yesno)
Disable or enable automatic unloading of modules.void
setDefaultStream(int wmd, java.lang.String fileName)
Set default input/output streams.void
setDefaultWorkDir(java.lang.String dirName)
Set the default working directory.void
setLocaleDir(java.lang.String dirName)
Set the location of the translated messages.void
setModulesPath(java.lang.String paths)
Set the directory list where modules are stored.static void
unbind(java.lang.String name)
Delete an association name-object.static void
unbindAll()
Delete all associations name-object.
-
-
-
Field Detail
-
F_INPUT
public static final int F_INPUT
Code for input stream.
-
F_OUTPUT
public static final int F_OUTPUT
Code for output stream.
-
F_ERROR
public static final int F_ERROR
Code for error stream.
-
F_LINBUF
public static final int F_LINBUF
Code for enabling line buffering (output stream).
-
-
Constructor Detail
-
XPRM
public XPRM() throws XPRMLicenseError
Generate an XPRM object and initialise Mosel. This method must be called first in order to use the library.- Throws:
-
XPRMLicenseError
- If no valid license is available. -
java.lang.RuntimeException
- If module"mmjava"
cannot be loaded.
-
XPRM
public XPRM(java.lang.String dsopath) throws XPRMLicenseError
Generate an XPRM object and initialise Mosel with a default modules path. This method must be called first in order to use the library.- Parameters:
-
dsopath
- list of paths where modules are stored - Throws:
-
XPRMLicenseError
- If no valid license is available. -
java.lang.RuntimeException
- If module"mmjava"
cannot be loaded. - See Also:
-
setModulesPath(java.lang.String)
-
-
Method Detail
-
bind
public static void bind(java.lang.String name, java.lang.Object obj)
Bind an object to a name. This method is used to associate a string with an object. This name can then be used to locate the object from Mosel especially when using the 'java' IO driver. The association can be used by all models.- Parameters:
-
name
- name to be used as the reference -
obj
- object associated to the name - See Also:
-
unbind(java.lang.String)
-
unbind
public static void unbind(java.lang.String name)
Delete an association name-object. This method should be called once a name is not to be used again in Mosel so the object can be released.- Parameters:
-
name
- name of the association to be removed - See Also:
-
bind(java.lang.String, java.lang.Object)
-
unbindAll
public static void unbindAll()
Delete all associations name-object.
-
license
public static XPRMLicense license(java.lang.String path)
Generate a license object. This method initiates the OEM licensing procedure.- Parameters:
-
path
- path to the license file (may benull
) - Returns:
- A new license object.
- See Also:
-
license(XPRMLicense lic)
-
license
public static XPRMLicense license()
Generate a license object. This method initiates the OEM licensing procedure.- Returns:
- A new license object.
- See Also:
-
license(XPRMLicense lic)
,license(null)
-
license
public static void license(XPRMLicense lic) throws XPRMLicenseError
Check license. This method is used for checking an OEM License.- Parameters:
-
lic
- license object obtained from a call tolicense(String path)
- Throws:
-
XPRMLicenseError
- If the OEM license is not valid. - See Also:
-
license(String path)
-
loadModel
public XPRMModel loadModel(java.lang.String name, java.lang.String options, java.lang.String pass, java.lang.String privkey, java.lang.String pubkeys) throws java.io.IOException
Load a compiled model into memory. This method loads a compiled model (Binary Model file) into memory. While loading a model from a file, Mosel also automatically opens any additional modules that are required by this model.- Parameters:
-
name
- name of a binary model file -
options
- loader options (may benull
, options may be separated by spaces or'-'
symbols):"c"
check file signature (if the file is signed)"V"
if the file is signed, load it only if the signature is valid"T"
load only signed files with a valid signature"F"
if this flag is set, the argumentpass
is interpreted as a file containing the password. Otherwisepass
is the password itself
-
pass
- password or password file (may benull
) -
privkey
- private key file (may benull
) -
pubkeys
- file of public keys (may benull
): this file contains a list of public key file names. If the file is signed and signature has to be checked (optionsc
andV
above) verification will be performed against these public keys. The special public key file name"*"
refers to all installed keys (these keys are used when no list is provided). - Returns:
-
A new model instance of type
XPRMModel
created from a binary model file. - Throws:
-
java.io.IOException
- If the binary model file cannot be found.
-
loadModel
public XPRMModel loadModel(java.lang.String name) throws java.io.IOException
Load a compiled model into memory. This method loads a compiled model (Binary Model file) into memory. While loading a model from a file, Mosel also automatically opens any additional modules that are required by this model.- Parameters:
-
name
- name of a binary model file - Returns:
-
A new model instance of type
XPRMModel
created from a binary model file. - Throws:
-
java.io.IOException
- If the binary model file cannot be found.
-
compile
public void compile(java.lang.String options, java.lang.String src, java.lang.String dest, java.lang.String comm, java.lang.String pass, java.lang.String privkey, java.lang.String pubkeys) throws XPRMCompileException, XPRMLicenseError
Compile a model source file. This method compiles a given model source file into a binary model file (bim file) that is required as input to methodloadModel(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
for loading the model. The output file takes the same name as the source file with the extension.bim
. Note that the empty string ( i.e.""
) is interpreted as the standard input forsrc
.- Parameters:
-
options
- compilation options (may benull
, options may be separated by spaces or'-'
symbols):"g"
include debugging information: in the case of a run time error during the execution of the model the location of the error in the source file may be indicated"G"
include tracing information in addition to debugging information: this makes possible execution step by step of the model through a debugger"s"
strip symbols: secure the bim file by removing all private symbol names used in the source model"wi"
with this flag a warning is displayed whenever a symbol is implicitly declared"p"
parse only: stop after the syntax analysis of the source file, do not compile (no file generated)"bx=prefix"
package prefix (can be quoted with single or double quotes)"ix=prefix"
include source prefix (can be quoted with single or double quotes)"E"
encrypt the bim file: if no password is provided via thepass
parameter, a random key is generated. The encryption procedure requires a private key: if theprivkey
parameter is not provided, the default key is used. The filepubkeys
must contain a list of public key file names: the bim loader will require one of the corresponding private keys in order to decrypt the file (if the encryption uses a random key)"S"
sign the bim file: the generated bim file is signed with the private keyprivkey
(or the default one if this parameter isnull
). The bim loader will require the corresponding public key in order to verify this signature"F"
if this flag is set, the argumentpass
is interpreted as a file containing the password. Otherwisepass
is the password itself"V"
Loading of a signed package will fail if the signature cannot be verified"T"
accept to load only signed packages. Loading of a package will fail if the signature cannot be verified
-
src
- name of the source file -
dest
- name of the output (bim) file (may benull
) -
comm
- user comment that will be saved as is in the output file (may benull
) -
pass
- password or password file (may benull
) -
privkey
- private key file (may benull
) -
pubkeys
- file of public keys (may benull
) - Throws:
-
XPRMCompileException
- If compilation fails. -
XPRMLicenseError
- If no valid license is available.
-
compile
public void compile(java.lang.String options, java.lang.String src, java.lang.String dest, java.lang.String comm) throws XPRMCompileException, XPRMLicenseError
Compile a model source file. This method compiles a given model source file into a binary model file (bim file) that is required as input to methodloadModel(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
for loading the model. The output file takes the same name as the source file with the extension.bim
. Note that the empty string ( i.e.""
) is interpreted as the standard input forsrc
.- Parameters:
-
options
- compilation options (may benull
) -
src
- name of the source file -
dest
- name of the output (bim) file (may benull
) -
comm
- user comment that will be saved as is in the output file (may benull
) - Throws:
-
XPRMCompileException
- If compilation fails. -
XPRMLicenseError
- If no valid license is available.
-
compile
public void compile(java.lang.String src) throws XPRMCompileException, XPRMLicenseError
Compile a model source file.- Parameters:
-
src
- name of the source file - Throws:
-
XPRMCompileException
- If compilation fails. -
XPRMLicenseError
- If no valid license is available. - See Also:
-
compile(null,src,null,null)
-
compile
public void compile(java.lang.String options, java.lang.String src) throws XPRMCompileException, XPRMLicenseError
Compile a model source file.- Parameters:
-
options
- compilation options -
src
- name of the source file - Throws:
-
XPRMCompileException
- If compilation fails. -
XPRMLicenseError
- If no valid license is available. - See Also:
-
compile(options,src,null,null)
-
compile
public void compile(java.lang.String options, java.lang.String src, java.lang.String dest) throws XPRMCompileException, XPRMLicenseError
Compile a model source file.- Parameters:
-
options
- compilation options -
src
- name of the source file -
dest
- name of the output (bim) file - Throws:
-
XPRMCompileException
- If compilation fails. -
XPRMLicenseError
- If no valid license is available. - See Also:
-
compile(options,src,dest,null)
-
setAutoUnloadModules
public void setAutoUnloadModules(boolean yesno)
Disable or enable automatic unloading of modules. By default, each unused module is automatically unloaded after a fixed period of time. Using this function it is possible to disable this automatic unloading; in which case, unused modules have to be unloaded explicitly usingflushModules()
.- Parameters:
-
yesno
-true
to enable automatic unloading - See Also:
-
flushModules()
-
flushModules
public void flushModules()
Unload unused modules.- See Also:
-
setAutoUnloadModules(boolean)
-
setModulesPath
public void setModulesPath(java.lang.String paths)
Set the directory list where modules are stored. By default, Mosel looks for its modules in the directories defined by the environment variableMOSEL_DSO
, inMOSEL/dso
and then inXPRESSDIR/dso
. This function may be used to replace the directory list defined byMOSEL_DSO
. Note that the directory separator is':'
under Unix (e.g."/opt/Mosel/dso:/tmp"
) and';'
under Win32 (e.g."E:\Mosel\Dso;C:\Temp"
).- Parameters:
-
paths
- list of paths suitable for the operating system - See Also:
-
getModulesPath()
-
getModulesPath
public java.lang.String getModulesPath()
Get the directory list where modules are searched for. Note that the returned path includes both the default search path (MOSEL/dso,XPRESSDIR/dso
) and the path set up either via the environment variableMOSEL_DSO
or the methodsetModulesPath(java.lang.String)
.- Returns:
- Directory list
-
loadModule
public XPRMModule loadModule(java.lang.String moduleName) throws java.io.FileNotFoundException
Explicitly load a module. Mosel loads modules on demand when they are required by the models in core memory. However, it is possible to force the system to load a module using this function.- Parameters:
-
moduleName
- name of the module to load - Returns:
- The corresponding module object
- Throws:
-
java.io.FileNotFoundException
- If the module cannot be loaded.
-
modules
public XPRMModules modules()
Get an iterator to enumerate all loaded modules.- Returns:
- A module iterator
-
findModule
public XPRMModule findModule(java.lang.String moduleName) throws java.util.NoSuchElementException
Find a module by its name. This method searches for a module of the given name. The module must be loaded in memory.- Parameters:
-
moduleName
- name of the module to find - Returns:
- A module object
- Throws:
-
java.util.NoSuchElementException
- If the module cannot be found.
-
IODrivers
public XPRMIODrivers IODrivers()
Get an iterator to enumerate all IO drivers.- Returns:
- An IO driver iterator
-
setLocaleDir
public void setLocaleDir(java.lang.String dirName)
Set the location of the translated messages. This function can be used to specify the location of the translated messages (native language support) if they are not stored in the usual place.- Parameters:
-
dirName
- path to the messages directory
-
setDefaultWorkDir
public void setDefaultWorkDir(java.lang.String dirName)
Set the default working directory. This function changes the default working directory. A null or empty string revert to the default behaviour that is to use the system-defined current working directory- Parameters:
-
dirName
- new current working directory
-
getDefaultWorkDir
public java.lang.String getDefaultWorkDir()
Get the default working directory.- Returns:
- The current default working directory (may be null)
-
removeTmpDir
public boolean removeTmpDir()
Remove the Mosel temporary directory. The temporary directory cannot be removed while models are running or if the default working directory is under the temporary directory. This directory is anyway automatically removed when the XPRM object is finalized.- Returns:
-
true
if the operation succeeded
-
expandPath
public java.lang.String expandPath(java.lang.String path)
Expand a path. The expansion consists in replacing relative references (like"."
and".."
) and completing the path with missing components (like current directory). The string"tmp:"
starting a path name will be replaced by the path to the Mosel temporary directory.- Parameters:
-
path
- to expand - Returns:
-
the expanded file name or the argument
path
if the expansion fails
-
setDefaultStream
public void setDefaultStream(int wmd, java.lang.String fileName) throws java.io.IOException
Set default input/output streams. This method defines the default global streams: they are used as the default when a model is loaded and whenever no model information is available (e.g. compilation errors, error on modules, etc). The method can be used only if no model is currently loaded in memory.
Using an empty string as the file name implies resetting to the corresponding original default stream.- Parameters:
-
wmd
- stream to be set: -
fileName
- extended file name to be used for the stream. The default values are"mmjava.java:java.lang.System.in"
for input"mmjava.java:java.lang.System.out"
for output"mmjava.java:java.lang.System.err"
for error
- Throws:
-
java.io.IOException
- If the stream cannot be set. - See Also:
-
XPRMModel.setDefaultStream(int, java.lang.String)
-
getVersion
public XPRMVersion getVersion()
Get Mosel version.- Returns:
- Version information as a version object
- See Also:
-
getVersion(0)
-
getVersion
public XPRMVersion getVersion(int whichone)
Get version information. This function returns the version number of Mosel, the Native Interface or BIM file format.- Parameters:
-
whichone
- the version requested:0
version of Mosel1
version of BIM file format2
version of NI interface
- Returns:
- Version information as a version object
-
beginLicensing
public static boolean beginLicensing()
Begin the OEM licensing process.- Returns:
-
true
if no license has been obtained yet
-
endLicensing
public static void endLicensing()
End the OEM licensing process.
-
finalize
public void finalize()
Finalize the Mosel instance. This procedure is normally automatically called by the Java Garbage Collector.- Overrides:
-
finalize
in classjava.lang.Object
-
-