Package org.jivesoftware.smack.filter
Interface StanzaFilter
- All Known Implementing Classes:
AbstractExactJidTypeFilter,AbstractFromToMatchesFilter,AbstractJidTypeFilter,AbstractJidTypeFilter,AbstractListFilter,AbstractPossibleJidTypeFilter,AndFilter,EmptyToMatcher,ExtensionElementFilter,FlexibleStanzaTypeFilter,FromJidTypeFilter,FromMatchesFilter,FromTypeFilter,IQReplyFilter,IQResultReplyFilter,IQTypeFilter,MessageTypeFilter,MessageWithBodiesFilter,MessageWithSubjectFilter,MessageWithThreadFilter,NotFilter,OrFilter,PossibleFromTypeFilter,PossibleToTypeFilter,PresenceTypeFilter,StanzaExtensionFilter,StanzaIdFilter,StanzaTypeFilter,ThreadFilter,ToMatchesFilter,ToTypeFilter
Defines a way to filter stanzas for particular attributes. Stanza filters are used when
constructing stanza listeners or collectors -- the filter defines what stanzas match the criteria
of the collector or listener for further stanza processing.
Several simple filters are pre-defined. These filters can be logically combined for more complex
stanza filtering by using the AndFilter and
OrFilter filters. It's also possible to define
your own filters by implementing this interface. The code example below creates a trivial filter
for stanzas with a specific ID (real code should use StanzaIdFilter instead).
// Use an anonymous inner class to define a stanza filter that returns
// all stanzas that have a stanza ID of "RS145".
StanzaFilter myFilter = new StanzaFilter() {
public boolean accept(Stanza stanza) {
return "RS145".equals(stanza.getStanzaId());
}
};
// Create a new stanza collector using the filter we created.
StanzaCollector myCollector = connection.createStanzaCollector(myFilter);
As a rule of thumb: If you have a predicate method, that is, a method which takes a single Stanza as argument, is pure
(side effect free) and returns only a boolean, then it is a good indicator that the logic should be put into a
StanzaFilter (and be referenced in StanzaListener).
- See Also:
-
Method Summary