package javax.management;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.util.Set;
import java.util.HashSet;
import java.util.Vector;
public class AttributeChangeNotificationFilter
implements NotificationFilter, java.io.Serializable
{
private static final long serialVersionUID = -6347317584796410029L;
private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[]
{
new ObjectStreamField("enabledAttributes", Vector.class)
};
private Set attributes = new HashSet();
public AttributeChangeNotificationFilter()
{
}
public synchronized boolean isNotificationEnabled(Notification notification)
{
if (notification != null && notification instanceof AttributeChangeNotification)
{
AttributeChangeNotification notif = (AttributeChangeNotification)notification;
if (attributes.contains(notif.getAttributeName()))
return true;
}
return false;
}
public synchronized void enableAttribute(String name) throws IllegalArgumentException
{
if (name == null)
throw new IllegalArgumentException("Null attribute name");
attributes.add(name);
}
public synchronized void disableAttribute(String name)
{
attributes.remove(name);
}
public synchronized void disableAllAttributes()
{
attributes.clear();
}
public synchronized Vector getEnabledAttributes()
{
return new Vector(attributes);
}
public String toString()
{
StringBuffer buffer = new StringBuffer(100);
buffer.append(getClass().getName()).append(":");
buffer.append(" enabledAttributes=").append(getEnabledAttributes());
return buffer.toString();
}
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField getField = ois.readFields();
Vector enabled = (Vector) getField.get("enabledAttributes", null);
attributes = new HashSet(enabled);
}
private void writeObject(ObjectOutputStream oos)
throws IOException
{
ObjectOutputStream.PutField putField = oos.putFields();
putField.put("enabledAttributes", new Vector(attributes));
oos.writeFields();
}
}