CiaoJava
Class PLGoal

java.lang.Object
  |
  +--CiaoJava.PLGoal

public class PLGoal
extends java.lang.Object

This class Represents a Prolog goal to be evaluated on a given PLConnection. This class connects to the Prolog side of the interface to manage the evaluation of the goals launched from the Java side. Instances of this class should be generated with the launchGoal method of the PLConnection class.


Field Summary
private  PLTerm actualGoal
           
private static java.lang.String EXCEPTION
           
private static java.lang.String FAIL
           
private static int FINISHED
           
private static java.lang.String LAUNCH_GOAL
           
private static java.lang.String LAUNCH_GOAL_ON_THREAD
           
private static java.lang.String NEXT_SOLUTION
           
private static java.lang.String NEXT_SOLUTION_ON_THREAD
           
private static int NOT_LAUNCHED
           
private  PLTerm originalGoal
           
private  PLConnection prologSpace
           
private  int queryId
           
protected static java.lang.String SOLUTION
           
private static java.lang.String TERMINATE_QUERY
           
private static java.lang.String TERMINATE_QUERY_ON_THREAD
           
private static int TERMINATED
           
private static java.lang.String USE_MODULE
           
 
Constructor Summary
PLGoal(PLConnection where, PLTerm term)
          Goal constructor.
PLGoal(PLConnection where, java.lang.String term)
          Goal constructor.
 
Method Summary
protected  void finalize()
          Destructor.
 PLTerm nextSolution()
          Sends to Prolog process a request for the next query solution.
private  PLTerm parseTerm(java.lang.String termString)
          This method uses the Prolog process to parse a Prolog term received as a string.
 void query()
          Goal query.
private  void terminate_()
          This private method implements the common tasks related to goal termination.
 void terminate()
          Terminates this Prolog goal execution.
 java.lang.String toString()
          String representation of a Prolog goal.
 void useModule(PLTerm module)
          This method loads a module in the Prolog process.
 void useModule(java.lang.String module)
          This method loads a module in the Prolog process.
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

SOLUTION

protected static final java.lang.String SOLUTION

originalGoal

private PLTerm originalGoal

actualGoal

private PLTerm actualGoal

prologSpace

private PLConnection prologSpace

queryId

private int queryId

LAUNCH_GOAL

private static final java.lang.String LAUNCH_GOAL

NEXT_SOLUTION

private static final java.lang.String NEXT_SOLUTION

TERMINATE_QUERY

private static final java.lang.String TERMINATE_QUERY

FAIL

private static final java.lang.String FAIL

EXCEPTION

private static final java.lang.String EXCEPTION

LAUNCH_GOAL_ON_THREAD

private static final java.lang.String LAUNCH_GOAL_ON_THREAD

NEXT_SOLUTION_ON_THREAD

private static final java.lang.String NEXT_SOLUTION_ON_THREAD

TERMINATE_QUERY_ON_THREAD

private static final java.lang.String TERMINATE_QUERY_ON_THREAD

USE_MODULE

private static final java.lang.String USE_MODULE

NOT_LAUNCHED

private static final int NOT_LAUNCHED

TERMINATED

private static final int TERMINATED

FINISHED

private static final int FINISHED
Constructor Detail

PLGoal

public PLGoal(PLConnection where,
              PLTerm term)
Goal constructor. Creates a new goal on the where Prolog process, using the Prolog term represented with term.
Parameters:
where - Prolog process on which the goal must be evaluated.
term - Prolog term that represents the goal that will be evaluated.

PLGoal

public PLGoal(PLConnection where,
              java.lang.String term)
       throws java.io.IOException,
              PLException
Goal constructor. Creates a new goal on the where Prolog process, using the Prolog term represented with termString string. This string must be a well formed Prolog term; otherwise a PLException will be thrown. This method connects to Prolog to parse the string containing the goal.
Parameters:
where - Prolog process on which the goal must be evaluated.
term - String containing the representation of a well formed Prolog term that represents the goal that will be evaluated.
Method Detail

query

public void query()
           throws java.io.IOException,
                  PLException
Goal query. Evaluates on the PLConnection associated object the goal represented by this object. To obtain the solutions of this goal, the nextSolution() method must be called, once for each solution.
Throws:
IOException, - PLException if there is any problem communicating with the Prolog process, or in the Prolog side (e.g., the predicate to be launched does not exist, or the goal has been launched yet).

nextSolution

public PLTerm nextSolution()
                    throws java.io.IOException,
                           PLException
Sends to Prolog process a request for the next query solution. Returns a Prolog term that corresponds to the goal with the Prolog variables unified with the solution. Later use of this Prolog variable objects will refer the unification performed. If there is no more solutions, all the variables of the goal will be set to their original binding before calling this method.
Returns:
the term that corresponds to the query, with the variables unified with the solution.
Throws:
IOException - if there are any error on the sockets.
PLException - if there are any error on the Prolog process. If the Prolog goal raises an exception, it is propagated through the interface, and a PLException is raised in the user Java program.

terminate

public void terminate()
               throws java.io.IOException,
                      PLException
Terminates this Prolog goal execution.
Throws:
java.io.IOException - if there are any error on the socket communication
PLException - if there are any error on the Prolog process

useModule

public void useModule(PLTerm module)
               throws java.io.IOException,
                      PLException
This method loads a module in the Prolog process. This method brings the possibility of loading Prolog modules dynamically. The module to be loaded must be accesible to the Prolog server.
Parameters:
module - Prolog term that represents the name of the module to be loaded. Can be used the library(module) format.
Throws:
java.io.IOException - if there are any I/O error with the sockets
PLException - if there are any error in the Prolog process

useModule

public void useModule(java.lang.String module)
               throws java.io.IOException,
                      PLException
This method loads a module in the Prolog process. This method brings the possibility of loading Prolog modules dynamically. The module to be loaded must be accesible to the Prolog server.
Parameters:
module - String that contains a Prolog term with the name of the module to be loaded. Can be used the library(module) format. The path must be accesible to the Prolog server.
Throws:
java.io.IOException - if there are any I/O error with the sockets
PLException - if there are any error in the Prolog process

terminate_

private void terminate_()
                 throws java.io.IOException,
                        PLException
This private method implements the common tasks related to goal termination.

finalize

protected void finalize()
                 throws java.io.IOException,
                        PLException,
                        java.lang.Throwable
Destructor. Terminates the Prolog goal and finalizes itself.
Overrides:
finalize in class java.lang.Object

parseTerm

private PLTerm parseTerm(java.lang.String termString)
                  throws java.io.IOException,
                         PLException
This method uses the Prolog process to parse a Prolog term received as a string.
Parameters:
termString - String object that represents a well formed Prolog term.
Returns:
the PLTerm that represents this Prolog term.
Throws:
IOException - if the socket stream has been broken.
PLException - if there is a problem parsing the term on the Prolog side.

toString

public java.lang.String toString()
String representation of a Prolog goal.
Returns:
A String object representing this Prolog goal.
Overrides:
toString in class java.lang.Object