org.aspectj.bridge
Class MessageHandler

java.lang.Object
  extended by org.aspectj.bridge.MessageHandler
All Implemented Interfaces:
IMessageHandler, IMessageHolder

public class MessageHandler
extends java.lang.Object
implements IMessageHolder

This handler accumulates messages. To control messages accumulated, clients can ignore messages of a given kind, or install a listener/interceptor. The interceptor handles all messages (even null) first, and can halt further processing/accumlation by returning true. Clients can obtain messages accumulated using the get... methods. XXX this does not permit messages to be removed.

Author:
PARC, Andy Clement

Field Summary
 
Fields inherited from interface org.aspectj.bridge.IMessageHolder
EQUAL, ORGREATER
 
Fields inherited from interface org.aspectj.bridge.IMessageHandler
SYSTEM_ERR, SYSTEM_OUT, THROW
 
Constructor Summary
MessageHandler()
          same as MessageHandler(false)
MessageHandler(boolean accumulateOnly)
           
 
Method Summary
 void clearMessages()
          Clear the messages without changing other behavior.
 void dontIgnore(IMessage.Kind kind)
          Remove a message kind from the list of those ignored from now on.
 IMessage[] getErrors()
           
 IMessage[] getMessages(IMessage.Kind kind, boolean orGreater)
          Get all messages or those of a specific kind.
 java.util.List<IMessage> getUnmodifiableListView()
           
 IMessage[] getWarnings()
           
 boolean handleMessage(IMessage message)
          This implementation accumulates message.
 boolean hasAnyMessage(IMessage.Kind kind, boolean orGreater)
          Tell whether this holder has any message of this kind (optionally or greater).
 void ignore(IMessage.Kind kind)
          Set a message kind to be ignored from now on
 void init()
          Initialize this, removing any messages accumulated, kinds being ignored, or interceptor.
 void init(boolean accumulateOnly)
          Initialize this, removing any messages accumulated, kinds being ignored, or interceptor.
 boolean isIgnoring(IMessage.Kind kind)
          Signal clients whether this will ignore messages of a given type.
 int numMessages(IMessage.Kind kind, boolean orGreater)
          Count the messages currently held by this holder.
 void setInterceptor(IMessageHandler interceptor)
          Set the interceptor which gets any message before we process it.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageHandler

public MessageHandler()
same as MessageHandler(false)


MessageHandler

public MessageHandler(boolean accumulateOnly)
Parameters:
accumulateOnly - the result of handleMessage (i.e., if true, then only accumulate messages - stop processing
Method Detail

init

public void init()
Initialize this, removing any messages accumulated, kinds being ignored, or interceptor. Assume that this should return false from handleMessage(..).


init

public void init(boolean accumulateOnly)
Initialize this, removing any messages accumulated, kinds being ignored, or interceptor.

Parameters:
accumulateOnly - boolean value returned from handleMessage after accumulating in list

clearMessages

public void clearMessages()
Clear the messages without changing other behavior.

Specified by:
clearMessages in interface IMessageHolder

handleMessage

public boolean handleMessage(IMessage message)
This implementation accumulates message. If an interceptor is installed and returns true (message handled), then processing halts and the message is not accumulated.

Specified by:
handleMessage in interface IMessageHandler
Parameters:
message - the IMessage to handle - never null
Returns:
true on interception or the constructor value otherwise
See Also:
IMessageHandler.handleMessage(IMessage)

isIgnoring

public boolean isIgnoring(IMessage.Kind kind)
Description copied from interface: IMessageHandler
Signal clients whether this will ignore messages of a given type. Clients may use this to avoid constructing or sending certain messages.

Specified by:
isIgnoring in interface IMessageHandler
Returns:
true if this kind has been flagged to be ignored.
See Also:
ignore(IMessage.Kind), org.aspectj.bridge.IMessageHandler#isIgnoring(Kind)

ignore

public void ignore(IMessage.Kind kind)
Set a message kind to be ignored from now on

Specified by:
ignore in interface IMessageHandler

dontIgnore

public void dontIgnore(IMessage.Kind kind)
Remove a message kind from the list of those ignored from now on.

Specified by:
dontIgnore in interface IMessageHandler

hasAnyMessage

public boolean hasAnyMessage(IMessage.Kind kind,
                             boolean orGreater)
Description copied from interface: IMessageHolder
Tell whether this holder has any message of this kind (optionally or greater).

Specified by:
hasAnyMessage in interface IMessageHolder
Parameters:
kind - the IMessage.Kind to check for - accept any if null
orGreater - if true, also any greater than the target kind as determined by IMessage.Kind.COMPARATOR
Returns:
true if this holder has any message of this kind, or if orGreater and any message has a greater kind, as determined by IMessage.Kind.COMPARATOR
See Also:
org.aspectj.bridge.IMessageHolder#hasAnyMessage(Kind, boolean)

numMessages

public int numMessages(IMessage.Kind kind,
                       boolean orGreater)
Description copied from interface: IMessageHolder
Count the messages currently held by this holder. Pass null to get all kinds.

Specified by:
numMessages in interface IMessageHolder
Parameters:
kind - the IMessage.Kind expected, or null for all messages
orGreater - if true, also any greater than the target kind as determined by IMessage.Kind.COMPARATOR
Returns:
number of messages accumulated of a given kind

getUnmodifiableListView

public java.util.List<IMessage> getUnmodifiableListView()
Specified by:
getUnmodifiableListView in interface IMessageHolder
Returns:
unmodifiable List view of underlying collection of IMessage
See Also:
IMessageHolder.getUnmodifiableListView()

getMessages

public IMessage[] getMessages(IMessage.Kind kind,
                              boolean orGreater)
Get all messages or those of a specific kind. Pass null to get all kinds.

Specified by:
getMessages in interface IMessageHolder
Parameters:
kind - the IMessage.Kind expected, or null for all messages
orGreater - if true, also get any greater than the target kind as determined by IMessage.Kind.COMPARATOR
Returns:
IMessage[] of messages of the right kind

getErrors

public IMessage[] getErrors()
Returns:
array of error messages, or IMessage.NONE

getWarnings

public IMessage[] getWarnings()
Returns:
array of warning messages, or IMessage.NONE

setInterceptor

public void setInterceptor(IMessageHandler interceptor)
Set the interceptor which gets any message before we process it.

Parameters:
interceptor - the IMessageHandler passed the message. Pass null to remove the old interceptor.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String containing list of messages