lp.wrap
Class SmodelsWrapper

java.lang.Object
  extended by lp.wrap.SmodelsWrapper

public class SmodelsWrapper
extends Object

A class responsible for executing smodels with the given command line arguments. Smodels can be executed by calling the exec() method. This method can be called multiple times and each time the current model limit is passed to the smodels binary.

Version:
1.0.0
Author:
Martin Slota

Field Summary
private  int modelLimit
          Maximum number of stable models that should be computed by smodels.
private  Process process
          The smodels process.
private  String smodelsPath
          The path to the smodels binary.
private static WrapperUtils WU
          The singleton WrapperUtils instance used in the implementation.
 
Constructor Summary
SmodelsWrapper()
          Creates a new instance of SmodelsWrapper.
 
Method Summary
 void closeStdin()
          Closes the standard output stream of the currently executed smodels process.
 void exec()
          Executes smodels and passes the current command line options (see setModelLimit(int)) to it.
 OutputStream getStdin()
          Returns the standard input stream of the currently executed smodels process.
 InputStream getStdout()
          Returns the standard output stream of the currently executed smodels process.
 SmodelsWrapper setModelLimit(int modelLimit)
          Sets the maximum number of stable models that should be computed by smodels.
 void setSmodelsPath(String smodelsPath)
          Sets the path to smodels binary that is used to invoke smodels.
 int waitFor()
          Waits for the currently executed smodels process to finish computation and returns its exit value (see Process.waitFor()).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WU

private static final WrapperUtils WU
The singleton WrapperUtils instance used in the implementation.


smodelsPath

private String smodelsPath
The path to the smodels binary.


modelLimit

private int modelLimit
Maximum number of stable models that should be computed by smodels. If it is zero, all stable models will be computed. This is also the default.


process

private Process process
The smodels process.

Constructor Detail

SmodelsWrapper

public SmodelsWrapper()
Creates a new instance of SmodelsWrapper. Initially the path to the smodels binary is set to "smodels", i.e. it is assumed that smodels can be executed by issuing the "smodels" command on the command line of the native operating system. This setting can be changed by calling the setSmodelsPath(String) method. The model limit is set to 0, i.e. all stable models will be computed. This setting can be changed by calling the setModelLimit(int) method.

Method Detail

setSmodelsPath

public void setSmodelsPath(String smodelsPath)
Sets the path to smodels binary that is used to invoke smodels.

Parameters:
smodelsPath - path to the smodels binary
Throws:
IllegalArgumentException - if smodelsPath is null or an empty string

setModelLimit

public SmodelsWrapper setModelLimit(int modelLimit)
Sets the maximum number of stable models that should be computed by smodels. If set to zero, all models will be computed.

Parameters:
modelLimit - the maximum number of stable models that should be computed by smodels.
Returns:
a reference to this SmodelsWrapper
Throws:
IllegalArgumentException - if modelLimit is negative

exec

public void exec()
Executes smodels and passes the current command line options (see setModelLimit(int)) to it.

Throws:
WrapperException - if an IOException occurs while creating the process

getStdin

public OutputStream getStdin()
Returns the standard input stream of the currently executed smodels process.

Returns:
as specified above

closeStdin

public void closeStdin()
Closes the standard output stream of the currently executed smodels process.

Throws:
WrapperException - if an I/O error occurs while closing the standard input stream of the smodels process

getStdout

public InputStream getStdout()
Returns the standard output stream of the currently executed smodels process.

Returns:
as specified above

waitFor

public int waitFor()
Waits for the currently executed smodels process to finish computation and returns its exit value (see Process.waitFor()).

Returns:
the return value of the smodels process
Throws:
WrapperException - if an InterruptedException occurs while waiting for the error stream thread or smodels process to finish their tasks