Class AbstractFilter<T>
- java.lang.Object
-
- org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter<T>
-
- All Implemented Interfaces:
Filter<T>
- Direct Known Subclasses:
AbstractPatternFilter
,FileFilterAdapter
public abstract class AbstractFilter<T> extends java.lang.Object implements Filter<T>
Abstract Filter implementation which handles separatingnull
candidate values from non-null ones, and delegates processing to concrete subclass implementations. Also, this AbstractFilter implementation provides a standard for emitting Filter debug statements (i.e. for toString() calls).- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
AbstractFilter.DelayedLogMessage
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<AbstractFilter.DelayedLogMessage>
delayedLogMessages
protected org.apache.maven.plugin.logging.Log
log
private boolean
processNullValues
protected static java.lang.String
TOSTRING_INDENT
Initial-line indent for human-readable toString() rendering.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFilter()
Convenience constructor which creates an AbstractFilter which does not process null values.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
accept(T candidate)
Method that is invoked to determine if a candidate instance should be accepted or not.protected void
addDelayedLogMessage(java.lang.String logLevel, java.lang.String message)
Adds a log message to be emitted when this AbstractFilter is initialized (and the Log is made available to it).void
initialize(org.apache.maven.plugin.logging.Log log)
Initializes this Filter, and assigns the supplied Log for use by this Filter.boolean
isInitialized()
protected abstract boolean
onCandidate(T nonNullCandidate)
Method that is invoked to determine if a candidate instance should be accepted or not.protected void
onInitialize()
Override this method to perform some custom action after standard initialization is complete.protected boolean
onNullCandidate()
Override this to perform an action other than debug logging whenever this AbstractFilter receives a null candidate.protected void
setProcessNullValues(boolean processNullValues)
Assigns theprocessNullValues
property which indicates if this AbstractFilter should process null values or not.java.lang.String
toString()
protected void
validateDiSetterCalledBeforeInitialization(java.lang.String setterPropertyName)
Validator method which should be called in a DI setter method to ensure that this AbstractFilter has not yet been initialized.
-
-
-
Field Detail
-
TOSTRING_INDENT
protected static final java.lang.String TOSTRING_INDENT
Initial-line indent for human-readable toString() rendering.- See Also:
- Constant Field Values
-
log
protected org.apache.maven.plugin.logging.Log log
-
delayedLogMessages
private java.util.List<AbstractFilter.DelayedLogMessage> delayedLogMessages
-
processNullValues
private boolean processNullValues
-
-
Method Detail
-
validateDiSetterCalledBeforeInitialization
protected final void validateDiSetterCalledBeforeInitialization(java.lang.String setterPropertyName)
Validator method which should be called in a DI setter method to ensure that this AbstractFilter has not yet been initialized.- Parameters:
setterPropertyName
- The name of the property to inject.
-
addDelayedLogMessage
protected final void addDelayedLogMessage(java.lang.String logLevel, java.lang.String message)
Adds a log message to be emitted when this AbstractFilter is initialized (and the Log is made available to it).- Parameters:
logLevel
- The logLevel of the message to emit.message
- The message to emit.
-
setProcessNullValues
protected final void setProcessNullValues(boolean processNullValues)
Assigns theprocessNullValues
property which indicates if this AbstractFilter should process null values or not.- Parameters:
processNullValues
-true
to indicate that this AbstractFilter should process null values.
-
initialize
public final void initialize(org.apache.maven.plugin.logging.Log log)
Initializes this Filter, and assigns the supplied Log for use by this Filter.- Specified by:
initialize
in interfaceFilter<T>
- Parameters:
log
- The non-null Log which should be used by this Filter to emit log messages.
-
isInitialized
public boolean isInitialized()
- Specified by:
isInitialized
in interfaceFilter<T>
- Returns:
true
if this Filter has been properly initialized (by a call to theinitialize
method).
-
onInitialize
protected void onInitialize()
Override this method to perform some custom action after standard initialization is complete. Default implementation does nothing, but the log is non-null and ready for use.
-
accept
public final boolean accept(T candidate) throws java.lang.IllegalStateException
Method that is invoked to determine if a candidate instance should be accepted or not. Implementing classes should be prepared to handle
null
candidate objects.- Specified by:
accept
in interfaceFilter<T>
- Parameters:
candidate
- The candidate that should be tested for acceptance by this Filter.- Returns:
true
if the candidate is accepted by this Filter andfalse
otherwise.- Throws:
java.lang.IllegalStateException
- if this Filter is not initialized by a call to the initialize method before calling this matchAtLeastOnce method.
-
onNullCandidate
protected boolean onNullCandidate()
Override this to perform an action other than debug logging whenever this AbstractFilter receives a null candidate. You also need to override this implementation if you want to return a value other thanfalse
. There is no point in callingsuper.onNullCandidate()
whenever this method is overridden.- Returns:
false
- implying that AbstractFilters will not matchAtLeastOncenull
s by default.
-
onCandidate
protected abstract boolean onCandidate(T nonNullCandidate)
Method that is invoked to determine if a candidate instance should be accepted or not.
- Parameters:
nonNullCandidate
- The candidate that should be tested for acceptance by this Filter. Never null.- Returns:
true
if the candidate is accepted by this Filter andfalse
otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-