ubc.cs.JLog.Foundation
Class jPrologServices

java.lang.Object
  extended by ubc.cs.JLog.Foundation.jPrologServices

public class jPrologServices
extends java.lang.Object

This class is the near complete environment for a Prolog environment. It contains the rules database, a registery of predicates and operators needed for parsing Prolog code, a connection to a graphical display environment, connections to text input and output consoles, several broadcasters to notify observers of several possible events, and some debugging attributes. It does not, however, contain the prover itself.

Author:
Glendon Holst

Field Summary
protected  java.lang.Object animation
           
protected  jPrologServiceBroadcaster beginConsult
           
protected  jPrologServiceBroadcaster beginQuery
           
protected  java.io.BufferedReader current_input
           
protected  java.io.PrintWriter current_output
           
protected  jKnowledgeBase database
           
protected  boolean debugging
           
protected  jPrologServiceBroadcaster debugMessages
           
protected  java.io.BufferedReader default_input
           
protected  java.io.PrintWriter default_output
           
protected  jPrologServiceBroadcaster endConsult
           
protected  jPrologServiceBroadcaster endQuery
           
protected  boolean fail_unknown_predicate
           
protected  iPrologFileServices fileservices
           
protected  pOperatorRegistry operators
           
protected  pPredicateRegistry predicates
           
protected  java.util.Random rand
           
protected  jPrologServiceBroadcaster retryQuery
           
protected  jPrologServiceBroadcaster stateChanged
           
protected  jPrologServiceThread thread
           
protected  jPrologServiceBroadcaster threadStopped
           
 
Constructor Summary
jPrologServices(jKnowledgeBase kb, pPredicateRegistry pr, pOperatorRegistry or)
           
 
Method Summary
 void addBeginConsultListener(jPrologServiceListener l)
           
 void addBeginQueryListener(jPrologServiceListener l)
           
 void addDebugMessagesListener(jPrologServiceListener l)
           
 void addEndConsultListener(jPrologServiceListener l)
           
 void addEndQueryListener(jPrologServiceListener l)
           
 void addRetryQueryListener(jPrologServiceListener l)
           
 void addStateChangedListener(jPrologServiceListener l)
           
 void addThreadStoppedListener(jPrologServiceListener l)
           
 java.lang.Object getAnimationEnvironment()
           
 boolean getDebugging()
           
 boolean getFailUnknownPredicate()
          Get the behaviour for unknown predicates.
 iPrologFileServices getFileServices()
          Gets the file services object.
 java.io.BufferedReader getInput()
           
 jKnowledgeBase getKnowledgeBase()
           
 pOperatorRegistry getOperatorRegistry()
           
 java.io.PrintWriter getOutput()
           
 pPredicateRegistry getPredicateRegistry()
           
 java.util.Random getRandomGenerator()
           
static java.lang.String getRequiredCreditInfo()
          This function returns the credit assignment and copyright informaiton string.
 boolean isAvailable()
          Returns whether the prolog services are busy or not.
 java.lang.Class loadClass(java.lang.String lib, java.lang.String classname)
           
 void loadLibrary(java.lang.String lib)
           
protected  void loadLibraryFromTOC(java.lang.String lib, java.io.InputStream toc_is)
           
protected  void loadLibraryTOCParseGenericOperator(java.lang.String lib, java.io.StreamTokenizer tokenizer)
           
protected  void loadLibraryTOCParseGenericPredicate(java.lang.String lib, java.io.StreamTokenizer tokenizer)
           
protected  void loadLibraryTOCParseLoadClass(java.lang.String lib, java.io.StreamTokenizer tokenizer)
           
 void printOutput(java.lang.String s)
           
protected  void registerPredefinedInstance(java.lang.String lib, java.lang.Object obj_inst)
           
protected  void registerPredicateOperatorEntryInstance(java.lang.String lib, java.lang.Object obj_inst)
           
 void release()
          Releases the current thread as a user of jPrologServices.
 void removeBeginConsultListener(jPrologServiceListener l)
           
 void removeBeginQueryListener(jPrologServiceListener l)
           
 void removeDebugMessagesListener(jPrologServiceListener l)
           
 void removeEndConsultListener(jPrologServiceListener l)
           
 void removeEndQueryListener(jPrologServiceListener l)
           
 void removeRetryQueryListener(jPrologServiceListener l)
           
 void removeStateChangedListener(jPrologServiceListener l)
           
 void removeThreadStoppedListener(jPrologServiceListener l)
           
 void resetInput()
           
 void resetKnowledgeBase()
           
 void resetOutput()
           
 void resume()
           
 void setAnimationEnvironment(java.lang.Object ae)
           
 void setDebugging(boolean dp)
           
 void setDefaultInput(java.io.BufferedReader i)
           
 void setDefaultOutput(java.io.PrintWriter o)
           
 void setFailUnknownPredicate(boolean fp)
          Set the behaviour for unknown predicates.
 void setFileServices(iPrologFileServices fs)
          Sets the file services object.
 void setInput(java.io.BufferedReader i)
           
 void setOutput(java.io.PrintWriter o)
           
 void start()
           
 boolean start(jPrologServiceThread t)
          Starts a prolog services of a given type.
 void stop()
          Forcefully terminates the current user thread.
 void suspend()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thread

protected jPrologServiceThread thread

database

protected jKnowledgeBase database

predicates

protected pPredicateRegistry predicates

operators

protected pOperatorRegistry operators

rand

protected java.util.Random rand

beginQuery

protected jPrologServiceBroadcaster beginQuery

retryQuery

protected jPrologServiceBroadcaster retryQuery

endQuery

protected jPrologServiceBroadcaster endQuery

beginConsult

protected jPrologServiceBroadcaster beginConsult

endConsult

protected jPrologServiceBroadcaster endConsult

threadStopped

protected jPrologServiceBroadcaster threadStopped

debugMessages

protected jPrologServiceBroadcaster debugMessages

stateChanged

protected jPrologServiceBroadcaster stateChanged

default_output

protected java.io.PrintWriter default_output

current_output

protected java.io.PrintWriter current_output

default_input

protected java.io.BufferedReader default_input

current_input

protected java.io.BufferedReader current_input

fileservices

protected iPrologFileServices fileservices

animation

protected java.lang.Object animation

debugging

protected boolean debugging

fail_unknown_predicate

protected boolean fail_unknown_predicate
Constructor Detail

jPrologServices

public jPrologServices(jKnowledgeBase kb,
                       pPredicateRegistry pr,
                       pOperatorRegistry or)
Method Detail

getRequiredCreditInfo

public static java.lang.String getRequiredCreditInfo()
This function returns the credit assignment and copyright informaiton string. It must be preserved by authors of derivative works.

Returns:
The credit and information string.

addBeginQueryListener

public void addBeginQueryListener(jPrologServiceListener l)

addRetryQueryListener

public void addRetryQueryListener(jPrologServiceListener l)

addEndQueryListener

public void addEndQueryListener(jPrologServiceListener l)

addBeginConsultListener

public void addBeginConsultListener(jPrologServiceListener l)

addEndConsultListener

public void addEndConsultListener(jPrologServiceListener l)

removeBeginQueryListener

public void removeBeginQueryListener(jPrologServiceListener l)

removeRetryQueryListener

public void removeRetryQueryListener(jPrologServiceListener l)

removeEndQueryListener

public void removeEndQueryListener(jPrologServiceListener l)

removeBeginConsultListener

public void removeBeginConsultListener(jPrologServiceListener l)

removeEndConsultListener

public void removeEndConsultListener(jPrologServiceListener l)

addThreadStoppedListener

public void addThreadStoppedListener(jPrologServiceListener l)

removeThreadStoppedListener

public void removeThreadStoppedListener(jPrologServiceListener l)

addDebugMessagesListener

public void addDebugMessagesListener(jPrologServiceListener l)

removeDebugMessagesListener

public void removeDebugMessagesListener(jPrologServiceListener l)

addStateChangedListener

public void addStateChangedListener(jPrologServiceListener l)

removeStateChangedListener

public void removeStateChangedListener(jPrologServiceListener l)

isAvailable

public boolean isAvailable()
Returns whether the prolog services are busy or not.

Returns:
true if there is not already a busy thread, false otherwise.

start

public boolean start(jPrologServiceThread t)
Starts a prolog services of a given type.

Parameters:
t - The thread which will use the prolog services.
Returns:
true if the thread is accepted.

start

public void start()

stop

public void stop()
Forcefully terminates the current user thread. The thread may broadcast a 'stopped' message.


release

public void release()
Releases the current thread as a user of jPrologServices. This should be done only by the threads themselves, after they have finished using the services provided by this instance.


suspend

public void suspend()

resume

public void resume()

resetKnowledgeBase

public void resetKnowledgeBase()

getKnowledgeBase

public jKnowledgeBase getKnowledgeBase()

getPredicateRegistry

public pPredicateRegistry getPredicateRegistry()

getOperatorRegistry

public pOperatorRegistry getOperatorRegistry()

setAnimationEnvironment

public void setAnimationEnvironment(java.lang.Object ae)

getAnimationEnvironment

public java.lang.Object getAnimationEnvironment()

loadLibrary

public void loadLibrary(java.lang.String lib)
                 throws java.io.IOException
Throws:
java.io.IOException

loadLibraryFromTOC

protected void loadLibraryFromTOC(java.lang.String lib,
                                  java.io.InputStream toc_is)
                           throws java.io.IOException
Throws:
java.io.IOException

loadLibraryTOCParseLoadClass

protected void loadLibraryTOCParseLoadClass(java.lang.String lib,
                                            java.io.StreamTokenizer tokenizer)
                                     throws java.io.IOException
Throws:
java.io.IOException

loadLibraryTOCParseGenericPredicate

protected void loadLibraryTOCParseGenericPredicate(java.lang.String lib,
                                                   java.io.StreamTokenizer tokenizer)
                                            throws java.io.IOException
Throws:
java.io.IOException

loadLibraryTOCParseGenericOperator

protected void loadLibraryTOCParseGenericOperator(java.lang.String lib,
                                                  java.io.StreamTokenizer tokenizer)
                                           throws java.io.IOException
Throws:
java.io.IOException

loadClass

public java.lang.Class loadClass(java.lang.String lib,
                                 java.lang.String classname)

registerPredicateOperatorEntryInstance

protected void registerPredicateOperatorEntryInstance(java.lang.String lib,
                                                      java.lang.Object obj_inst)

registerPredefinedInstance

protected void registerPredefinedInstance(java.lang.String lib,
                                          java.lang.Object obj_inst)

setDebugging

public void setDebugging(boolean dp)

getDebugging

public boolean getDebugging()

setFailUnknownPredicate

public void setFailUnknownPredicate(boolean fp)
Set the behaviour for unknown predicates. By default missing predicates throw an exception.

Parameters:
fp - If false (default), then missing predicates generate a failing exception (i.e., exception thrown), if true then the query for that predicate fails (i.e., no exception is thrown).

getFailUnknownPredicate

public boolean getFailUnknownPredicate()
Get the behaviour for unknown predicates.

Returns:
If false, then exceptions are thrown for missing predicates, otherwise the query for that predicate fails (no exception thrown).

getRandomGenerator

public java.util.Random getRandomGenerator()

setDefaultOutput

public void setDefaultOutput(java.io.PrintWriter o)

setOutput

public void setOutput(java.io.PrintWriter o)

getOutput

public java.io.PrintWriter getOutput()

resetOutput

public void resetOutput()

printOutput

public void printOutput(java.lang.String s)

setDefaultInput

public void setDefaultInput(java.io.BufferedReader i)

setInput

public void setInput(java.io.BufferedReader i)

getInput

public java.io.BufferedReader getInput()

resetInput

public void resetInput()

setFileServices

public void setFileServices(iPrologFileServices fs)
Sets the file services object. This object is used to access files (remotely or locally depending upon the type of object).

Parameters:
fs - The iPrologFileServices object to use.

getFileServices

public iPrologFileServices getFileServices()
Gets the file services object. This object is used to access files (remotely or locally depending upon the type of object). Since this object may change, any users of the file services object should acquire it once, and hold on to it until they are finished (i.e., separate calls to this method may return different file services).

Returns:
The iPrologFileServices object.