org.tm4j.topicmap.utils
Class HelperBase

java.lang.Object
  extended byorg.tm4j.topicmap.utils.HelperBase
Direct Known Subclasses:
TopicMapMerger, TopicMapSerializer

public abstract class HelperBase
extends java.lang.Object

Abstract base class for bean-like helper classes. Provides support for both vetoable and non-vetoable property change interaction, and for logging. When subclassing this class, it is highly recommended to put any initialization routines into the init(), method, rather than into the subclass constructor. See HelperBase() and init() for details.

This class and all its subclasses support at least one bound property, "logger", which represents the jakarta-commons Log that is to receive and dispatch logging messages. This may be set using setLogger(Log). Changes to this bound property are vetoable and may be rolled back by a registered VetoableChangeListener. For additional properties which a subclass may support, please refer to the subclass documentation.

Since:
0.8.4
Author:
Florian G. Haas

Constructor Summary
HelperBase()
          Default no-arg constructor.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a new listener for non-vetoable property changes.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a new listener for non-vetoable changes to a specific property.
 void addVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener listener)
          Adds a new listener for vetoable changes to a specific property.
 void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
          Adds a new listener for vetoable property changes.
protected  void debug(java.lang.Object message)
          Logs a message using a logging level of "debug".
protected  void error(java.lang.Object message)
          Logs a message using a logging level of "error".
protected  void error(java.lang.Object message, java.lang.Throwable t)
          Logs a message, and information concerning an error or exception, using a logging level of "error".
protected  void fatal(java.lang.Object message)
          Logs a message using a logging level of "fatal".
protected  void fatal(java.lang.Object message, java.lang.Throwable t)
          Logs a message, and information concerning an error or exception, using a logging level of "fatal".
protected  void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
          Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.
protected  void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
          Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.
protected  void fireVetoableChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
          Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred.
protected  void fireVetoableChange(java.lang.String propertyName, int oldValue, int newValue)
          Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred.
protected  void fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred.
protected  org.apache.commons.logging.Log getLogger()
          Retrieves the registered logger.
protected  boolean hasLogger()
          Determines if the current instance has a registered logger.
protected  void info(java.lang.Object message)
          Logs a message using a logging level of "info".
protected abstract  void init()
          Initializes the instance.
protected  void logVetoedChange(java.beans.PropertyVetoException exc)
          Logs a message about an attempted property change that has been vetoed by a registered VetoableChangeListener, and has therefore been rolled back.
 void removeLogger()
          Removes (unregisters) a registered logger.
 void setLogger(org.apache.commons.logging.Log newLogger)
          Registers a logger.
 void trace(java.lang.Object message)
          Logs a message using a logging level of "trace".
protected  void warn(java.lang.Object message)
          Logs a message using a logging level of "warn".
protected  void warn(java.lang.Object message, java.lang.Throwable t)
          Logs a message, and information concerning an error or exception, using a logging level of "warn".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelperBase

public HelperBase()
Default no-arg constructor. Sets up support for property change listeners and invokes init(). Any exceptions thrown by init() are caught and cause a RuntimeException to be thrown, with specific information about the exception being logged at the "fatal" level. Subclasses should ensure that their own no-arg constructors invoke super() to ensure proper initialization. However, it is a better idea to override init(), which is invoked by the default constructor, than to provide a subclass no-arg constructor.

Throws:
java.lang.RuntimeException - if the subclass-specific initialization fails.
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a new listener for non-vetoable property changes.

Parameters:
listener - the new listener to be registered.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Adds a new listener for non-vetoable changes to a specific property.

Parameters:
propertyName - the property which the listener monitors for changes.
listener - the new listener to be registered.

addVetoableChangeListener

public void addVetoableChangeListener(java.lang.String propertyName,
                                      java.beans.VetoableChangeListener listener)
Adds a new listener for vetoable changes to a specific property.

Parameters:
propertyName - the property which the listener monitors for changes.
listener - the new listener to be registered.

addVetoableChangeListener

public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a new listener for vetoable property changes.

Parameters:
listener - the new listener to be registered.

debug

protected void debug(java.lang.Object message)
Logs a message using a logging level of "debug". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

error

protected void error(java.lang.Object message)
Logs a message using a logging level of "error". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

error

protected void error(java.lang.Object message,
                     java.lang.Throwable t)
Logs a message, and information concerning an error or exception, using a logging level of "error". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged
t - the error condition being logged

fatal

protected void fatal(java.lang.Object message)
Logs a message using a logging level of "fatal". Fatal messages are never suppressed: if no logger is registered, the message is printed on System.err. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

fatal

protected void fatal(java.lang.Object message,
                     java.lang.Throwable t)
Logs a message, and information concerning an error or exception, using a logging level of "fatal". Fatal messages are never suppressed: if no logger is registered, the message (along with a stack trace) is printed on System.err. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged
t - the error condition being logged

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  boolean oldValue,
                                  boolean newValue)
Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  int oldValue,
                                  int newValue)
Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Notifies registered PropertyChangeListeners that a non-vetoable change to a property has occurred.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.

fireVetoableChange

protected void fireVetoableChange(java.lang.String propertyName,
                                  boolean oldValue,
                                  boolean newValue)
                           throws java.beans.PropertyVetoException
Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred. Note that if the change is not vetoed, any registered PropertyChangeListeners are notified of the property change as well.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.
Throws:
java.beans.PropertyVetoException - signifies that a registered VetoableChangeListener has requested that the change be rolled back.

fireVetoableChange

protected void fireVetoableChange(java.lang.String propertyName,
                                  int oldValue,
                                  int newValue)
                           throws java.beans.PropertyVetoException
Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred. Note that if the change is not vetoed, any registered PropertyChangeListeners are notified of the property change as well.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.
Throws:
java.beans.PropertyVetoException - signifies that a registered VetoableChangeListener has requested that the change be rolled back.

fireVetoableChange

protected void fireVetoableChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
                           throws java.beans.PropertyVetoException
Notifies registered VetoableChangeListeners that a vetoable change to a property has occurred. Note that if the change is not vetoed, any registered PropertyChangeListeners are notified of the property change as well.

Parameters:
propertyName - the string identifying the property.
oldValue - the original property value.
newValue - the new property value.
Throws:
java.beans.PropertyVetoException - signifies that a registered VetoableChangeListener has requested that the change be rolled back.

getLogger

protected org.apache.commons.logging.Log getLogger()
Retrieves the registered logger.

Returns:
the registered jakarta-commons Log, or null if no logger has been registered.

hasLogger

protected boolean hasLogger()
Determines if the current instance has a registered logger.

Returns:
true if the instance is currently configured for logging, false otherwise.

info

protected void info(java.lang.Object message)
Logs a message using a logging level of "info". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

init

protected abstract void init()
                      throws java.lang.Exception
Initializes the instance. This method is invoked by the default constructor, so subclasses should put their initialization routine in this method, rather than override the constructor.

Throws:
java.lang.Exception - if the initialization fails.

logVetoedChange

protected void logVetoedChange(java.beans.PropertyVetoException exc)
Logs a message about an attempted property change that has been vetoed by a registered VetoableChangeListener, and has therefore been rolled back. The message is logged at the "warn" level.

Parameters:
exc - the PropertyVetoException a VetoableChangeListener threw when it deemed a particular property change inappropriate or invalid.

removeLogger

public void removeLogger()
Removes (unregisters) a registered logger. Same as invoking setLogger(null).


setLogger

public void setLogger(org.apache.commons.logging.Log newLogger)
Registers a logger. Since changes to this property are vetoable, a registered VetoableChangeListener may determine that the property change is inappropriate or invalid, and ask for it to be rolled back. In that case, the property's original value is restored, and a warning is issued to the originally registered logger.

Parameters:
newLogger - the jakarta-commons Log to register.

trace

public void trace(java.lang.Object message)
Logs a message using a logging level of "trace". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

warn

protected void warn(java.lang.Object message)
Logs a message using a logging level of "warn". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged

warn

protected void warn(java.lang.Object message,
                    java.lang.Throwable t)
Logs a message, and information concerning an error or exception, using a logging level of "warn". This method does nothing if no logger has been registered. You can register a logger using the setLogger(Log) method.

Parameters:
message - the message being logged
t - the error condition being logged