org.jasen.core.engine
Class Jasen

java.lang.Object
  extended byorg.jasen.core.engine.Jasen

public class Jasen
extends Object

The core scanning class of the jASEN framework.

Jasen scans a MimeMessage using the internal logic and any registered plugins and returns a scan result object indicating the results of the scan

NOTE: You should not call this class directly. Use the JasenScanner singleton as it provides thread safety during updates

Author:
Jason Polites
See Also:
JasenScanner

Field Summary
static float NO_THRESHOLD
           
static int RESULT_INDEX_DISPLAY
          The index into the test results array for the plugin display name
static int RESULT_INDEX_NAME
          The index into the test results array for the plugin name
static int RESULT_INDEX_PROBABILITY
          The index into the test results array for the probability
static int RESULT_INDEX_TIME
          The index into the test results array for the plugin execution time
 
Constructor Summary
Jasen()
           
 
Method Summary
 void destroy()
          Calls destroy on any registered plugins.
 ProbabilityCalculator getCalculator()
          Gets the calculator used to calculate the combined probabilities of all the tests
 JasenConfiguration getConfig()
          Gets the configuration object defined for the engine
 ClassLoader getContextClassLoader()
          Gets the context classloader to use when loading plugins etc.
 DNSResolver getDnsResolver()
          Gets the resolver used to resolve DNS records
 JasenErrorHandler getErrorHandler()
          Gets the error handler used by the scanner
 Class getHeaderParserClass()
          Gets the mimeParser used to parse the "received" headers in the message
 InetAddressResolver getInetAddressResolver()
          Gets the resolver used to resolve InetAddresses
 MimeMessageParser getMimeParser()
          Gets the mimeParser used to parse the MimeMessage
 List getPlugins()
          Gets the list of plugins to be used when scanning a message
 Class getScanResultClass()
          Gets the class used to hold the results of a scan
 MimeMessageTokenizer getTokenizer()
          Gets the tokenizer used to extract meaningful text from the message
 void init()
          Initialises the engine with the default configuration
 void init(InputStream in)
          Deprecated. Use init(JasenConfigurationLoader loader)
 void init(JasenConfigurationLoader loader)
          Initialises the engine with the configuration loader provided
 void init(String config)
          Deprecated. Use init(JasenConfigurationLoader loader)
 void restart()
          Restarts the engine.
 JasenScanResult scan(javax.mail.internet.MimeMessage mm, float threshold, String[] ignored)
          Scans the given message.
 JasenScanResult scan(javax.mail.internet.MimeMessage mm, JasenMessage message, float threshold, String[] ignored)
          Scans the given mime message using the already mime-parsed JasenMessage.
 JasenScanResult scan(javax.mail.internet.MimeMessage mm, JasenMessage message, String[] ignored)
          Scans the message without a threshold specified
 JasenScanResult scan(javax.mail.internet.MimeMessage mm, String[] ignored)
          Scans the given message.
 void setCalculator(ProbabilityCalculator calculator)
          Sets the calculator used to calculate the combined probabilities of all the tests
 void setContextClassLoader(ClassLoader pluginClassLoader)
          Sets the class loader to use when loading plugins etc.
 void setDnsResolver(DNSResolver dnsResolver)
          Sets the resolver used to resolve DNS records
 void setErrorHandler(JasenErrorHandler errorHandler)
          Sets the error handler used by the scanner
 void setHeaderParserClass(Class headerParser)
          Sets the mimeParser used to parse the "received" headers in the message
 void setInetAddressResolver(InetAddressResolver inetAddressResolver)
          Sets the resolver used to resolve InetAddresses
 void setMimeParser(MimeMessageParser parser)
          Sets the mimeParser used to parse the MimeMessage
 void setPlugins(Vector plugins)
          Sets the list of plugins to be used when scanning a message
 void setScanResultClass(Class resultClass)
          Sets the class used to hold the results of a scan
 void setTokenizer(MimeMessageTokenizer tokenizer)
          Sets the tokenizer used to extract meaningful text from the message
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_THRESHOLD

public static final float NO_THRESHOLD
See Also:
Constant Field Values

RESULT_INDEX_PROBABILITY

public static final int RESULT_INDEX_PROBABILITY
The index into the test results array for the probability

See Also:
Constant Field Values

RESULT_INDEX_TIME

public static final int RESULT_INDEX_TIME
The index into the test results array for the plugin execution time

See Also:
Constant Field Values

RESULT_INDEX_NAME

public static final int RESULT_INDEX_NAME
The index into the test results array for the plugin name

See Also:
Constant Field Values

RESULT_INDEX_DISPLAY

public static final int RESULT_INDEX_DISPLAY
The index into the test results array for the plugin display name

See Also:
Constant Field Values
Constructor Detail

Jasen

public Jasen()
Method Detail

init

public void init()
          throws JasenException
Initialises the engine with the default configuration

Throws:
JasenException

init

public void init(String config)
          throws JasenException
Deprecated. Use init(JasenConfigurationLoader loader)

Initialises the engine with the configuration file specified

Parameters:
config - The absolute path to the configuration file
Throws:
JasenException

init

public void init(InputStream in)
          throws JasenException
Deprecated. Use init(JasenConfigurationLoader loader)

Initialises the engine with the configuration document passed as a stream

Parameters:
in - The input stream from which the configuration may be read
Throws:
JasenException

init

public void init(JasenConfigurationLoader loader)
          throws JasenException
Initialises the engine with the configuration loader provided

Parameters:
loader -
Throws:
JasenException

destroy

public void destroy()
Calls destroy on any registered plugins.
This should be called prior to any calling application exiting to ensure any resources obtained by plugins are closed or returned.


restart

public void restart()
             throws JasenException
Restarts the engine. This simply calls destroy() then init()
NOTE: This method will fail to produce accurate results if the engine was originally initialized with anything other than the default (parameterless) init() method.

Throws:
JasenException

scan

public JasenScanResult scan(javax.mail.internet.MimeMessage mm,
                            String[] ignored)
                     throws JasenException
Scans the given message.

All plugins will execute regardless of the probability (or computed total probability) discovered from any single plugin or combination thereof

Parameters:
mm - The MimeMessage to be scanned
ignored - A list of plugin names which will be ignored during the scan. May be null
Returns:
The results of the scan as a JasenScanResult
Throws:
JasenException

scan

public JasenScanResult scan(javax.mail.internet.MimeMessage mm,
                            JasenMessage message,
                            String[] ignored)
                     throws JasenException
Scans the message without a threshold specified

Parameters:
mm - The MimeMessage to be scanned
message - A pre-parsed JasenMessage
ignored - A list of plugin names which will be ignored during the scan. May be null
Returns:
The results of the scan as a JasenScanResult
Throws:
JasenException

scan

public JasenScanResult scan(javax.mail.internet.MimeMessage mm,
                            JasenMessage message,
                            float threshold,
                            String[] ignored)
                     throws JasenException
Scans the given mime message using the already mime-parsed JasenMessage.

This implementation allows calling applications to implement their own JasenMessage by passing it to the scan engine.

Parameters:
mm - The MimeMessage to be scanned
message - A pre-parsed JasenMessage
threshold - The thresholds. If any one plugin yields a result >= threshold, scanning is ceased and the result returned immediately
ignored - A list of plugin names which will be ignored during the scan. May be null
Returns:
The results of the scan as a JasenScanResult
Throws:
JasenException

scan

public JasenScanResult scan(javax.mail.internet.MimeMessage mm,
                            float threshold,
                            String[] ignored)
                     throws JasenException
Scans the given message.

The threshold value indicates the value at which we know the message is spam without continuing

If the engine computes this threshold prior to all plugins executing, tests are stopped and the result is returned immediately

Parameters:
mm - The MimeMessage to be scanned
threshold - The marker above which scanning ceases
ignored - A list of plugin names which will be ignored during the scan. May be null
Returns:
The results of the scan as a JasenScanResult
Throws:
JasenException

getCalculator

public ProbabilityCalculator getCalculator()
Gets the calculator used to calculate the combined probabilities of all the tests

Returns:
The calculator in use
See Also:
JasenConfiguration.getCalculator()

setCalculator

public void setCalculator(ProbabilityCalculator calculator)
Sets the calculator used to calculate the combined probabilities of all the tests

Parameters:
calculator -
See Also:
JasenConfiguration.setCalculator(String)

getHeaderParserClass

public Class getHeaderParserClass()
Gets the mimeParser used to parse the "received" headers in the message

Returns:
The Class object of the header parser in use
See Also:
JasenConfiguration.getHeaderParser()

setHeaderParserClass

public void setHeaderParserClass(Class headerParser)
Sets the mimeParser used to parse the "received" headers in the message

Parameters:
headerParser -
See Also:
JasenConfiguration.setHeaderParser(String)

getMimeParser

public MimeMessageParser getMimeParser()
Gets the mimeParser used to parse the MimeMessage

Returns:
The Mime parse in use
See Also:
JasenConfiguration.getMimeParser()

setMimeParser

public void setMimeParser(MimeMessageParser parser)
Sets the mimeParser used to parse the MimeMessage

Parameters:
parser - The mime parse to be used

getPlugins

public List getPlugins()
Gets the list of plugins to be used when scanning a message

Returns:
A list of PluginContainer objects
See Also:
PluginContainer

setPlugins

public void setPlugins(Vector plugins)
Sets the list of plugins to be used when scanning a message

Parameters:
plugins - A List of PluginContainer objects
See Also:
PluginContainer

getConfig

public JasenConfiguration getConfig()
Gets the configuration object defined for the engine

Returns:
The configuration object loaded from the XML config data

getTokenizer

public MimeMessageTokenizer getTokenizer()
Gets the tokenizer used to extract meaningful text from the message

Returns:
The message tokenizer in use
See Also:
JasenConfiguration.getTokenizer()

setTokenizer

public void setTokenizer(MimeMessageTokenizer tokenizer)
Sets the tokenizer used to extract meaningful text from the message

Parameters:
tokenizer - The tokenizer to use
See Also:
JasenConfiguration.setTokenizer(String)

getScanResultClass

public Class getScanResultClass()
Gets the class used to hold the results of a scan

Returns:
Returns the scanResultClass.
See Also:
JasenConfiguration.getResult()

setScanResultClass

public void setScanResultClass(Class resultClass)
Sets the class used to hold the results of a scan

Parameters:
resultClass -
See Also:
JasenConfiguration.setResult(String)

getInetAddressResolver

public InetAddressResolver getInetAddressResolver()
Gets the resolver used to resolve InetAddresses

Returns:
The InetAddressResolver in use
See Also:
JasenConfiguration.getInetResolver()

setInetAddressResolver

public void setInetAddressResolver(InetAddressResolver inetAddressResolver)
Sets the resolver used to resolve InetAddresses

Parameters:
inetAddressResolver -
See Also:
JasenConfiguration.setInetResolver(String)

getDnsResolver

public DNSResolver getDnsResolver()
Gets the resolver used to resolve DNS records

Returns:
The DNS resolver in use
See Also:
JasenConfiguration.getDnsResolver()

setDnsResolver

public void setDnsResolver(DNSResolver dnsResolver)
Sets the resolver used to resolve DNS records

Parameters:
dnsResolver -
See Also:
JasenConfiguration.setDnsResolver(String)

getErrorHandler

public JasenErrorHandler getErrorHandler()
Gets the error handler used by the scanner

Returns:
The current error handler in use
See Also:
JasenConfiguration.getErrorHandler()

setErrorHandler

public void setErrorHandler(JasenErrorHandler errorHandler)
Sets the error handler used by the scanner

Parameters:
errorHandler - The error handler to beused
See Also:
JasenConfiguration.setErrorHandler(String)

getContextClassLoader

public ClassLoader getContextClassLoader()
Gets the context classloader to use when loading plugins etc.

This should only EVERY be set by the auto update engine

Returns:
The class loader registered by the auto update engine. Or null if none has been set

setContextClassLoader

public void setContextClassLoader(ClassLoader pluginClassLoader)
Sets the class loader to use when loading plugins etc.

This should only EVERY be set by the auto update engine

Parameters:
pluginClassLoader - The class loader to use to load plugins for this session