FileDocCategorySizeDatePackage
InstanceOfQueryExp.javaAPI DocJava SE 6 API3433Tue Jun 10 00:26:12 BST 2008javax.management

InstanceOfQueryExp

public class InstanceOfQueryExp extends QueryEval implements QueryExp
This class is used by the query building mechanism for isInstanceOf expressions.
serial
include
since
1.6

Fields Summary
private static final long
serialVersionUID
private StringValueExp
classNameValue
Constructors Summary
public InstanceOfQueryExp(StringValueExp classNameValue)
Creates a new InstanceOfExp with a specific class name.

param
classNameValue The {@link StringValueExp} returning the name of the class of which selected MBeans should be instances.

    
                                            
    // We are using StringValueExp here to be consistent with other queries,
    // although we should actually either use a simple string (the classname)
    // or a ValueExp - which would allow more complex queries - like for 
    // instance evaluating the class name from an AttributeValueExp.
    // As it stands - using StringValueExp instead of a simple constant string
    // doesn't serve any useful purpose besides offering a consistent 
    // look & feel.
       
	if (classNameValue == null) {
	    throw new IllegalArgumentException("Null class name.");
	}
	
	this.classNameValue = classNameValue;
    
Methods Summary
public booleanapply(javax.management.ObjectName name)
Applies the InstanceOf on a MBean.

param
name The name of the MBean on which the InstanceOf will be applied.
return
True if the MBean specified by the name is instance of the class.
exception
BadAttributeValueExpException
exception
InvalidApplicationException
exception
BadStringOperationException
exception
BadBinaryOpValueExpException

        
        // Get the class name value 
        final StringValueExp val;
	try {
            val = (StringValueExp) classNameValue.apply(name);
	} catch (ClassCastException x) {
            // Should not happen - unless someone wrongly implemented
            // StringValueExp.apply().
            final BadStringOperationException y = 
                    new BadStringOperationException(x.toString());
            y.initCause(x);
            throw y;
	} 
        
        // Test whether the MBean is an instance of that class.
	try {            
	    return getMBeanServer().isInstanceOf(name, val.getValue());
	} catch (InstanceNotFoundException infe) {
	    return false;
        }
    
public javax.management.StringValueExpgetClassNameValue()
Returns the class name.

returns
The {@link StringValueExp} returning the name of the class of which selected MBeans should be instances.

 
	return classNameValue;
    
public java.lang.StringtoString()
Returns a string representation of this InstanceOfQueryExp.

return
a string representation of this InstanceOfQueryExp.

       return "InstanceOf " + classNameValue.toString();