package org.jboss.mx.remoting.event;
import javax.management.*;
import java.io.Serializable;
public class ClassQueryExp implements QueryExp, Serializable
{
private static final long serialVersionUID = -4099952623687795850L;
public static final int AND = 1;
public static final int OR = 2;
String classes[];
int operator;
transient MBeanServer mBeanServer;
public ClassQueryExp (Class cl[])
{
this(cl,OR);
}
public ClassQueryExp (Class cl)
{
this(new Class[]{cl},AND);
}
public ClassQueryExp (Class cl, int operator)
{
this(new Class[]{cl},operator);
}
public ClassQueryExp (Class cl[], int operator)
{
this.classes = new String[cl.length];
for (int c=0;c<cl.length;c++)
{
this.classes[c]=cl[c].getName();
}
this.operator = operator;
}
public boolean apply(ObjectName objectName) throws BadStringOperationException, BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException
{
try
{
for (int c=0;c<classes.length;c++)
{
boolean value=mBeanServer.isInstanceOf(objectName,classes[c]);
if (value && operator==OR)
{
return true;
}
else if (!value && operator==AND)
{
return false;
}
}
return (operator==OR?false:true);
}
catch (Exception ex)
{
return false;
}
}
public void setMBeanServer(MBeanServer mBeanServer)
{
this.mBeanServer=mBeanServer;
}
}