cox.jmatt.java.MathTools.util
Class MathConsole

java.lang.Object
  extended by cox.jmatt.java.MathTools.util.MathConsole

public class MathConsole
extends java.lang.Object

This class exists to provide scripting languages access to the MathTools logging framework and Global Pizza. If subclassing, DO NOT implement the MathPrinter interface and set the subclass as either the Global Printer OR the subclass' MathPrinter. The universe will implode if this happens!


Field Summary
static java.lang.String AUTH_SIMPLE
          String constant for a SimpleAuthenticator.
static byte INSTRUCTOR
          Static constant for Instructor authentication codes.
static byte PROCTOR
          Static constant for Proctor codes.
static byte STUDENT
          Static constant for generating Student codes.
 
Constructor Summary
MathConsole()
          The basic MathConsole constructor.
MathConsole(MathPrinter pPrinter)
          Build a MathConsole around a MathPrinter instance.
MathConsole(MathPrinter pPrinter, java.util.Properties pPizza)
          Build a MathConsole completely separate from CapCom.
 
Method Summary
 void abort(java.lang.String pMesg)
          Sometimes a script needs to generate an error and terminate.
 boolean authenticateInstructor(java.lang.String pCode)
          Check an authentication code at Instructor level.
 boolean authenticateProctor(java.lang.String pCode)
          Check an authentication code at Proctor level.
 boolean authenticateStudent(java.lang.String pCode)
          Check an authentication code at Student level.
 void debug(java.lang.String pMesg)
           
 void debug(java.lang.String pMesg, java.lang.Throwable pThr)
           
 void error(java.lang.String pMesg)
           
 void error(java.lang.String pMesg, java.lang.Throwable pThr)
           
 java.lang.String[] generateCodes(byte pLevel, int pNumberOf, java.lang.Object... pParams)
          Generate a set of authentication codes, if access is permitted.
 java.lang.Object getObject(java.lang.String pKey)
          Get an Object from the CapCom shelf.
 java.lang.String getProperty(java.lang.String pKey)
          Convenience method for getProperty(pKey, null).
 java.lang.String getProperty(java.lang.String pKey, java.lang.String pDefault)
          Fetch a property from a Properties object.
 void info(java.lang.String pMesg)
           
 void info(java.lang.String pMesg, java.lang.Throwable pThr)
           
 void mathLog(byte pLevel, java.lang.String pMessage, java.lang.Throwable pThr)
          This method intercepts all logging calls made on this method directly OR on its convenience methods.
 void mathPrintln(java.lang.String pMessage)
          Print a message outside the logging framework.
 void println(java.lang.String pMessage)
          Laziness method aliasing mathPrintln().
 java.lang.Object processMathObject(java.lang.Object pData)
          Process an Object on a MathPrinter.
 java.lang.Object returns(java.lang.Object pRetObject)
          This method is used to explicitly store a return Object from a script.
 void setAuthenticator(java.lang.String pName, java.lang.Object pCtx)
          Install an Authenticator.
 void storeObject(java.lang.String pKey, java.lang.Object pData)
          Store something on the CapCom shelf.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STUDENT

public static final byte STUDENT
Static constant for generating Student codes.

See Also:
Constant Field Values

PROCTOR

public static final byte PROCTOR
Static constant for Proctor codes.

See Also:
Constant Field Values

INSTRUCTOR

public static final byte INSTRUCTOR
Static constant for Instructor authentication codes.

See Also:
Constant Field Values

AUTH_SIMPLE

public static final java.lang.String AUTH_SIMPLE
String constant for a SimpleAuthenticator.

See Also:
Constant Field Values
Constructor Detail

MathConsole

public MathConsole()
The basic MathConsole constructor. It reflects all method calls to CapCom and fetches all data from CapCom.


MathConsole

public MathConsole(MathPrinter pPrinter)
Build a MathConsole around a MathPrinter instance. This may be the one set in CapCom or it may be different, but it must be specified!


MathConsole

public MathConsole(MathPrinter pPrinter,
                   java.util.Properties pPizza)
Build a MathConsole completely separate from CapCom. The Properties object specified will be used for all getProperty() calls, which makes the Global Pizza inaccessible.

Parameters:
pPrinter - The MathPrinter to use for logging/printing calls. If null, CapCom is used.
pPizza - The Properties object to use for getProperty() calls. If null, the Global Pizza is used.
Method Detail

mathLog

public void mathLog(byte pLevel,
                    java.lang.String pMessage,
                    java.lang.Throwable pThr)

This method intercepts all logging calls made on this method directly OR on its convenience methods. If this console is built around a MathPrinter, that printer receives all calls. If not, this method reflects to the CapCom mathLog() method.

As with CapCom, MathConsole provides convenience methods for Debug, Info and Error: one method accepting a String and another that accepts a String and a Throwable.


error

public void error(java.lang.String pMesg)

error

public void error(java.lang.String pMesg,
                  java.lang.Throwable pThr)

debug

public void debug(java.lang.String pMesg)

debug

public void debug(java.lang.String pMesg,
                  java.lang.Throwable pThr)

info

public void info(java.lang.String pMesg)

info

public void info(java.lang.String pMesg,
                 java.lang.Throwable pThr)

mathPrintln

public void mathPrintln(java.lang.String pMessage)
Print a message outside the logging framework. If MathConsole has its own MathPrinter that is where the message goes. If not, it hits CapCom. The regular println() method echoes to this one.

Parameters:
pMessage - The message to be printed.

println

public void println(java.lang.String pMessage)
Laziness method aliasing mathPrintln().


processMathObject

public java.lang.Object processMathObject(java.lang.Object pData)
Process an Object on a MathPrinter. MathConsole's, if one is defined, CapCom's otherwise.


abort

public void abort(java.lang.String pMesg)
           throws java.lang.Exception

Sometimes a script needs to generate an error and terminate. This method does that. If the message is null or blank a default is supplied. When called, this method throws a generic Exception which will be caught by ScriptPanel. The message should always be specified and it should always be descriptive of the error condition.

Parameters:
pMesg - The message to include in the Exception.
Throws:
java.lang.Exception

getProperty

public java.lang.String getProperty(java.lang.String pKey,
                                    java.lang.String pDefault)
Fetch a property from a Properties object. The first time this method is called, it checks to see if MathConsole has a Properties object set. If so, that is the one asked for the property. If no internal Properties object is currently loaded it fetches a copy of the Global Pizza and checks that.

Parameters:
pKey - The key of the property to be fetched. If not valid, the default is returned.
pDefault - The String (or null) to return if the specified property can't be found.

getProperty

public java.lang.String getProperty(java.lang.String pKey)
Convenience method for getProperty(pKey, null).


getObject

public java.lang.Object getObject(java.lang.String pKey)
Get an Object from the CapCom shelf. If the required Object is present, it is returned. If not, null is returned. If the key value is null or empty, null is returned.

Parameters:
pKey - The String key under which the Object was stored.
Returns:
The Object if it is there, null if not.

storeObject

public void storeObject(java.lang.String pKey,
                        java.lang.Object pData)
Store something on the CapCom shelf. If the key is null or empty or the Object is null the request is silently ignored.

Parameters:
pKey - The String key under which the Object is to be shelved.
pData - The Object to be stored.

returns

public final java.lang.Object returns(java.lang.Object pRetObject)

This method is used to explicitly store a return Object from a script. When called it calls CapCom.setScriptReturnObject(java.lang.Object) and returns whatever value was sent in. This is done to facilitate the following:

Console.returns(someObject)

as the final statement in a script. This construct works regardless of whether or not the ScriptEngine.eval() method actually returns a value.

Parameters:
pRetObject - The return value from the script
Returns:
Whatever was sent in.

authenticateStudent

public final boolean authenticateStudent(java.lang.String pCode)
Check an authentication code at Student level.


authenticateProctor

public final boolean authenticateProctor(java.lang.String pCode)
Check an authentication code at Proctor level. This and all other Authenticator methods reflect to CapCom.


authenticateInstructor

public final boolean authenticateInstructor(java.lang.String pCode)
Check an authentication code at Instructor level.


setAuthenticator

public final void setAuthenticator(java.lang.String pName,
                                   java.lang.Object pCtx)
Install an Authenticator. By default this is allowed but setting CapCom.allowConsoleAuthenticatorAccess to false blocks it.

Parameters:
pName - The full name of the MAuthenticator to install.
pCtx - The context Object, if required.

generateCodes

public final java.lang.String[] generateCodes(byte pLevel,
                                              int pNumberOf,
                                              java.lang.Object... pParams)
Generate a set of authentication codes, if access is permitted. Parameters are per generateCodes() in the MAuthenticator interface. As with setting the authenticator, this method can be disabled from CapCom. If access is not allowed the return value is null. The authentication levels are reflected in static constants here for convenience.