001/** 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smack.filter; 019 020import org.jivesoftware.smack.packet.Message; 021import org.jivesoftware.smack.packet.Stanza; 022import org.jivesoftware.smack.packet.Presence; 023 024/** 025 * Filters for packets of a particular type. The type is given as a Class object, so 026 * example types would: 027 * <ul> 028 * <li><tt>Message.class</tt> 029 * <li><tt>IQ.class</tt> 030 * <li><tt>Presence.class</tt> 031 * </ul> 032 * 033 * @author Matt Tucker 034 * @deprecated use {@link StanzaTypeFilter} instead. 035 */ 036@Deprecated 037public class PacketTypeFilter implements StanzaFilter { 038 039 public static final PacketTypeFilter PRESENCE = new PacketTypeFilter(Presence.class); 040 public static final PacketTypeFilter MESSAGE = new PacketTypeFilter(Message.class); 041 042 private final Class<? extends Stanza> packetType; 043 044 /** 045 * Creates a new stanza(/packet) type filter that will filter for packets that are the 046 * same type as <tt>packetType</tt>. 047 * 048 * @param packetType the Class type. 049 */ 050 public PacketTypeFilter(Class<? extends Stanza> packetType) { 051 this.packetType = packetType; 052 } 053 054 public boolean accept(Stanza packet) { 055 return packetType.isInstance(packet); 056 } 057 058 @Override 059 public String toString() { 060 return getClass().getSimpleName() + ": " + packetType.getName(); 061 } 062}