FileDocCategorySizeDatePackage
DefaultMBeanServerInterceptor.javaAPI DocJava SE 5 API60250Fri Aug 26 14:54:58 BST 2005com.sun.jmx.interceptor

DefaultMBeanServerInterceptor

public class DefaultMBeanServerInterceptor extends Object implements MBeanServerInterceptor
This is the default class for MBean manipulation on the agent side. It contains the methods necessary for the creation, registration, and deletion of MBeans as well as the access methods for registered MBeans. This is the core component of the JMX infrastructure.

Every MBean which is added to the MBean server becomes manageable: its attributes and operations become remotely accessible through the connectors/adaptors connected to that MBean server. A Java object cannot be registered in the MBean server unless it is a JMX compliant MBean.

When an MBean is registered or unregistered in the MBean server an {@link javax.management.MBeanServerNotification MBeanServerNotification} Notification is emitted. To register an object as listener to MBeanServerNotifications you should call the MBean server method {@link #addNotificationListener addNotificationListener} with ObjectName the ObjectName of the {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. This ObjectName is:
JMImplementation:type=MBeanServerDelegate.

since
1.5
since.unbundled
JMX RI 1.2

Fields Summary
private static final ObjectName
_MBSDelegateObjectName
MBeanServerDelegate ObjectName shared ref
private final transient MBeanInstantiator
instantiator
The MBeanInstantiator object used by the DefaultMBeanServerInterceptor
private transient MBeanServer
server
The MBean server object that is associated to the DefaultMBeanServerInterceptor
private final transient MBeanServerDelegate
delegate
The MBean server object taht associated to the DefaultMBeanServerInterceptor
private final transient com.sun.jmx.mbeanserver.MetaData
meta
The Metadata object used by the DefaultMBeanServerInterceptor
private final transient Repository
repository
The Repository object used by the DefaultMBeanServerInterceptor
private final transient WeakHashMap
listenerWrappers
Wrappers for client listeners.
private final String
domain
The default domain of the object names
private boolean
queryByRepo
True if the repository perform queries, false otherwise
private static final String
dbgTag
The name of this class to be used for tracing
Constructors Summary
public DefaultMBeanServerInterceptor(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator)
Creates a DefaultMBeanServerInterceptor with the specified default domain name. The default domain name is used as the domain part in the ObjectName of MBeans if no domain is specified by the user.

Do not forget to call initialize(outer,delegate) before using this object.

param
domain The default domain name used by this MBeanServer.
param
outer A pointer to the MBeanServer object that must be passed to the MBeans when invoking their {@link javax.management.MBeanRegistration} interface.
param
delegate A pointer to the MBeanServerDelegate associated with the new MBeanServer. The new MBeanServer must register this MBean in its MBean repository.
param
instantiator The MBeanInstantiator that will be used to instantiate MBeans and take care of class loading issues.


                                                                                                                                                               
                   
					           
					  
					     
        this(outer, delegate, instantiator, null, 
	     new RepositorySupport((domain==null?ServiceName.DOMAIN:domain))); 
    
public DefaultMBeanServerInterceptor(MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, com.sun.jmx.mbeanserver.MetaData metadata, Repository repository)
Creates a DefaultMBeanServerInterceptor with the specified repository instance.

Do not forget to call initialize(outer,delegate) before using this object.

param
outer A pointer to the MBeanServer object that must be passed to the MBeans when invoking their {@link javax.management.MBeanRegistration} interface.
param
delegate A pointer to the MBeanServerDelegate associated with the new MBeanServer. The new MBeanServer must register this MBean in its MBean repository.
param
instantiator The MBeanInstantiator that will be used to instantiate MBeans and take care of class loading issues.
param
metadata The MetaData object that will be used by the MBean server in order to invoke the MBean interface of the registered MBeans.
param
repository The repository to use for this MBeanServer

	if (outer == null) throw new 
	    IllegalArgumentException("outer MBeanServer cannot be null");
	if (delegate == null) throw new 
	    IllegalArgumentException("MBeanServerDelegate cannot be null");
	if (instantiator == null) throw new 
	    IllegalArgumentException("MBeanInstantiator cannot be null");
	if (metadata == null)
	    metadata = new MetaDataImpl(instantiator);
	if (repository == null) 
	    repository = new RepositorySupport(ServiceName.DOMAIN);

	this.server   = outer;
	this.delegate = delegate; 
	this.instantiator = instantiator;
	this.meta         = metadata;
	this.repository   = repository;
	this.domain       = repository.getDefaultDomain();
    
Methods Summary
public voidaddNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)


	// ------------------------------
	// ------------------------------
        if (isTraceOn()) {
            trace("addNotificationListener", "obj= " + name);
        }

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, name, "addNotificationListener");

        NotificationBroadcaster broadcaster;

	if (!(instance instanceof NotificationBroadcaster)) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException(name.getCanonicalName() ),
                "The MBean " + name.getCanonicalName() +
                " does not implement the NotificationBroadcaster interface");
        }
	broadcaster = (NotificationBroadcaster) instance;

        // ------------------
        // Check listener
        // ------------------
        if (listener == null) {
	    throw new RuntimeOperationsException(new
		IllegalArgumentException("Null listener"),"Null listener");
	}

	NotificationListener listenerWrapper =
	    getListenerWrapper(listener, name, instance, true);
	broadcaster.addNotificationListener(listenerWrapper, filter, handback);
    
public voidaddNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener, javax.management.NotificationFilter filter, java.lang.Object handback)


	// ------------------------------
	// ------------------------------

        // ----------------
        // Get listener object
        // ----------------
        Object instance = getMBean(listener);
        if (!(instance instanceof NotificationListener)) {
	    throw new RuntimeOperationsException(new
		IllegalArgumentException(listener.getCanonicalName()),
		"The MBean " + listener.getCanonicalName() +
		"does not implement the NotificationListener interface") ;
        }

        // ----------------
        // Add a listener on an MBean
        // ----------------
        if (isTraceOn()) {
            trace("addNotificationListener", "obj= " + name + " listener= " +
		  listener);
        }
        server.addNotificationListener(name,(NotificationListener) instance,
				       filter, handback) ;
    
private static voidcheckMBeanPermission(java.lang.String classname, java.lang.String member, javax.management.ObjectName objectName, java.lang.String actions)

	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    Permission perm = new MBeanPermission(classname,
						  member,
						  objectName,
						  actions);
	    sm.checkPermission(perm);
	}
    
private static voidcheckMBeanTrustPermission(java.lang.Class theClass)

	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    Permission perm = new MBeanTrustPermission("register");
	    ProtectionDomain pd = (ProtectionDomain)
		AccessController.doPrivileged(new PrivilegedAction() {
		    public Object run() {
			return theClass.getProtectionDomain();
		    }
		});
	    AccessControlContext acc =
		new AccessControlContext(new ProtectionDomain[] { pd });
	    sm.checkPermission(perm, acc);
	}
    
public javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name)


	return createMBean(className, name, (Object[]) null, (String[]) null);

    
public javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.management.ObjectName loaderName)


	return createMBean(className, name, loaderName, (Object[]) null,
			   (String[]) null);
    
public javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, java.lang.Object[] params, java.lang.String[] signature)


	try {
	    return createMBean(className, name, null, true,
			       params, signature);
	} catch (InstanceNotFoundException e) {
	    /* Can only happen if loaderName doesn't exist, but we just
	       passed null, so we shouldn't get this exception.  */
	    throw new IllegalArgumentException("Unexpected exception: " + e);
	}
    
public javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.management.ObjectName loaderName, java.lang.Object[] params, java.lang.String[] signature)


	return createMBean(className, name, loaderName, false,
			   params, signature);
    
private javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.management.ObjectName loaderName, boolean withDefaultLoaderRepository, java.lang.Object[] params, java.lang.String[] signature)


        ObjectName logicalName = name;
        Class theClass;

	if (className == null) {
	    final RuntimeException wrapped =
		new IllegalArgumentException("The class name cannot be null");
	    throw new RuntimeOperationsException(wrapped,
                      "Exception occured during MBean creation");
	}

	if (name != null) {
	    if (name.isPattern()) {
		final RuntimeException wrapped =
		    new IllegalArgumentException("Invalid name->" +
						 name.toString());
		final String msg = "Exception occurred during MBean creation";
		throw new RuntimeOperationsException(wrapped, msg);
	    }

	    name = nonDefaultDomain(name);
	}

	/* Permission check */
	checkMBeanPermission(className, null, null, "instantiate");
	checkMBeanPermission(className, null, name, "registerMBean");

	/* Load the appropriate class. */
	if (withDefaultLoaderRepository) {
	    if (isTraceOn()) {
		trace(dbgTag, "createMBean", "ClassName = " + className +
		      ",ObjectName = " + name);
	    }
	    theClass =
		instantiator.findClassWithDefaultLoaderRepository(className);
	} else if (loaderName == null) {
	    if (isTraceOn()) {
		trace(dbgTag, "createMBean", "ClassName = " + className +
		      ",ObjectName = " + name + " Loader name = null");
	    }

	    theClass = instantiator.findClass(className,
				  server.getClass().getClassLoader());
	} else {
	    loaderName = nonDefaultDomain(loaderName);

	    if (isTraceOn()) {
                trace(dbgTag, "createMBean", "ClassName = " + className +
		      ",ObjectName = " + name + ",Loader name = "+
		      loaderName.toString());
            }

	    theClass = instantiator.findClass(className, loaderName);
	}

	/* Permission check */
	checkMBeanTrustPermission(theClass);

	// Check that the MBean can be instantiated by the MBeanServer.
	instantiator.testCreation(theClass);

	// Check the JMX compliance of the class
	meta.testCompliance(theClass);

	Object moi= instantiator.instantiate(theClass, params,  signature,
					     server.getClass().getClassLoader());

	final String infoClassName;
	try {
	    infoClassName = meta.getMBeanClassName(moi);
	} catch (IntrospectionException e) {
	    throw new NotCompliantMBeanException(e.getMessage());
	} 

	return registerCreatedObject(infoClassName, moi, name);
    
private static voiddebug(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info);
    
private static voiddebug(java.lang.String func, java.lang.String info)

        debug(dbgTag, func, info);
    
private static voiddebugX(java.lang.String func, java.lang.Throwable e)

	if (isDebugOn()) {
	    final StringWriter s = new StringWriter();
	    e.printStackTrace(new PrintWriter(s));
	    final String stack = s.toString();

	    debug(dbgTag,func,"Exception caught in "+ func+"(): "+e);
	    debug(dbgTag,func,stack);

	    // java.lang.System.err.println("**** Exception caught in "+
	    //				 func+"(): "+e);
	    // java.lang.System.err.println(stack);
	}
    
private static voiderror(java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_ERROR,Trace.INFO_MBEANSERVER,dbgTag,func,info);
    
private java.util.SetfilterListOfObjectInstances(java.util.Set list, javax.management.QueryExp query)
Applies the specified queries to the set of ObjectInstances.

        // Null query.
	//
        if (query == null) {
	    return list;
        } else {
	    Set result = new HashSet();
            // Access the filter.
	    //
            for (final Iterator i = list.iterator(); i.hasNext(); ) {
		final ObjectInstance oi = (ObjectInstance) i.next();
                boolean res = false;
		MBeanServer oldServer = QueryEval.getMBeanServer();
		query.setMBeanServer(server);
                try {
                    res = query.apply(oi.getObjectName());
                } catch (Exception e) {
                    res = false;
                } finally {
		    /*
		     * query.setMBeanServer is probably
		     * QueryEval.setMBeanServer so put back the old
		     * value.  Since that method uses a ThreadLocal
		     * variable, this code is only needed for the
		     * unusual case where the user creates a custom
		     * QueryExp that calls a nested query on another
		     * MBeanServer.
		     */
		    query.setMBeanServer(oldServer);
		}
                if (res) {
		    result.add(oi);
                }
            }
	    return result;
        }
    
private java.util.SetfilterListOfObjects(java.util.Set list, javax.management.QueryExp query)
Applies the specified queries to the set of objects

        Set result = new HashSet();

        // No query ...
        if (query == null ) {
            for (final Iterator i  = list.iterator(); i.hasNext(); ) {
                final NamedObject no = (NamedObject) i.next();
		final Object obj = no.getObject();
		String className = null;

		try {
		    className = meta.getMBeanClassName(obj);
		} catch (JMException x) {
		    if (isDebugOn()) {
			debug("filterListOfObjects",
			      "Can't obtain class name for " +
			      no.getName() + ": " + x);
			debugX("filterListOfObjects",x);
		    }
		}

		result.add(new ObjectInstance(no.getName(), className));
            }
        } else {
            // Access the filter
            for (final Iterator i  = list.iterator(); i.hasNext(); ) {
                final NamedObject no = (NamedObject) i.next();
                final Object obj = no.getObject();
                boolean res = false;
		MBeanServer oldServer = QueryEval.getMBeanServer();
		query.setMBeanServer(server);
                try {
                    res = query.apply(no.getName());
                } catch (Exception e) {
                    res = false;
                } finally {
		    /*
		     * query.setMBeanServer is probably
		     * QueryEval.setMBeanServer so put back the old
		     * value.  Since that method uses a ThreadLocal
		     * variable, this code is only needed for the
		     * unusual case where the user creates a custom
		     * QueryExp that calls a nested query on another
		     * MBeanServer.
		     */
		    query.setMBeanServer(oldServer);
		}
                if (res) {
		    // if the MBean is a dynamic MBean ask its MBeanInfo
		    // for the class name
		    String className = null;
		    try {
			className = meta.getMBeanClassName(obj);
		    } catch (JMException x) {
			if (isDebugOn()) {
			    debug("filterListOfObjects",
				  "Can't obtain class name for " +
				  no.getName() + ": " + x);
			    debugX("filterListOfObjects",x);
			}
		    }
		    result.add(new ObjectInstance(no.getName(), className));
                }
            }
        }
	return result;
    
public java.lang.ObjectgetAttribute(javax.management.ObjectName name, java.lang.String attribute)


        if (name == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("Object name cannot be null"),
                "Exception occured trying to invoke the getter on the MBean");
        }
        if (attribute == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("Attribute cannot be null"),
                "Exception occured trying to invoke the getter on the MBean");
        }

	name = nonDefaultDomain(name);
	
        if (isTraceOn()) {
            trace("getAttribute", "Attribute= " + attribute +
		  ", obj= " + name);
        }

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, attribute, name, "getAttribute");

        return meta.getAttribute(instance, attribute);
    
public javax.management.AttributeListgetAttributes(javax.management.ObjectName name, java.lang.String[] attributes)


        if (name == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("ObjectName name cannot be null"),
                "Exception occured trying to invoke the getter on the MBean");
        }

        if (attributes == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("Attributes cannot be null"),
                "Exception occured trying to invoke the getter on the MBean");
        }

	name = nonDefaultDomain(name);

        if (isTraceOn()) {
            trace("getAttributes", "Object= " + name);
        }

	Object instance = getMBean(name);
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    /* Permission check */
	    String classname = null;
	    try {
		classname = meta.getMBeanClassName(instance);
	    } catch (IntrospectionException e) {
		classname = null;
	    } catch (NotCompliantMBeanException e) {
		classname = null;
	    }

	    // Check if the caller has the right to invoke 'getAttribute'
	    //
	    checkMBeanPermission(classname, null, name, "getAttribute");

	    // Check if the caller has the right to invoke 'getAttribute'
	    // on each specific attribute
	    //
	    ArrayList allowedList = new ArrayList(attributes.length);
	    for (int i = 0; i < attributes.length; i++) {
		try {
		    checkMBeanPermission(classname, attributes[i],
					 name, "getAttribute");
		    allowedList.add(attributes[i]);
		} catch (SecurityException e) {
		    // OK: Do not add this attribute to the list
		}
	    }
	    String[] allowedAttributes =
		(String[]) allowedList.toArray(new String[0]);
	    return meta.getAttributes(instance, allowedAttributes);
	} else {
	    return meta.getAttributes(instance, attributes);
	}
    
public java.lang.ClassLoadergetClassLoader(javax.management.ObjectName loaderName)

Return the named {@link java.lang.ClassLoader}.

param
loaderName The ObjectName of the ClassLoader.
return
The named ClassLoader.
exception
InstanceNotFoundException if the named ClassLoader is not found.


	if (loaderName == null) {
	    checkMBeanPermission(null, null, null, "getClassLoader");
	    return server.getClass().getClassLoader();
	}

        Object instance = getMBean(loaderName);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, loaderName, "getClassLoader");

	/* Check if the given MBean is a ClassLoader */
	if (!(instance instanceof ClassLoader))
	    throw new InstanceNotFoundException(loaderName.toString() +
                                                " is not a classloader");

	return (ClassLoader) instance;
    
public java.lang.ClassLoadergetClassLoaderFor(javax.management.ObjectName mbeanName)

Return the {@link java.lang.ClassLoader} that was used for loading the class of the named MBean.

param
mbeanName The ObjectName of the MBean.
return
The ClassLoader used for that MBean.
exception
InstanceNotFoundException if the named MBean is not found.


	/* Permission check */
        Object instance = getMBean(mbeanName);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, mbeanName, "getClassLoaderFor");

	return instance.getClass().getClassLoader();
    
public java.lang.StringgetDefaultDomain()

        return domain;
    
public java.lang.String[]getDomains()

	/* Permission check */
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    // Check if the caller has the right to invoke 'getDomains'
	    //
	    checkMBeanPermission(null, null, null, "getDomains");
	    
	    // Return domains
	    //
	    String[] domains = repository.getDomains();

	    // Check if the caller has the right to invoke 'getDomains'
	    // on each specific domain in the list.
	    //
	    ArrayList result = new ArrayList(domains.length);
	    for (int i = 0; i < domains.length; i++) {
		try {
		    ObjectName domain = new ObjectName(domains[i] + ":x=x");
		    checkMBeanPermission(null, null, domain, "getDomains");
		    result.add(domains[i]);
		} catch (MalformedObjectNameException e) {
		    // Should never occur... But let's log it just in case.
		    error("getDomains",
			  "Failed to check permission for domain=" + 
			  domains[i] + ". Error is: " + e);
		    debugX("getDomains",e);
		} catch (SecurityException e) {
		    // OK: Do not add this domain to the list
		}
	    }

	    // Make an array from result.
	    //
	    return (String[]) result.toArray(new String[result.size()]);
	} else {
	    return repository.getDomains();
	}
    
private javax.management.NotificationListenergetListener(javax.management.ObjectName listener)

        // ----------------
        // Get listener object
        // ----------------
        final Object instance;
        try {
	    instance = getMBean(listener);
	} catch (InstanceNotFoundException e) {
	    throw new ListenerNotFoundException(e.getMessage()) ;
	}

        if (!(instance instanceof NotificationListener)) {
	    final RuntimeException exc =
		new IllegalArgumentException(listener.getCanonicalName());
	    final String msg =
		"MBean " + listener.getCanonicalName() + " does not " +
		"implement " + NotificationListener.class.getName();
            throw new RuntimeOperationsException(exc, msg);
        }
	return (NotificationListener) instance;
    
private javax.management.NotificationListenergetListenerWrapper(javax.management.NotificationListener l, javax.management.ObjectName name, java.lang.Object mbean, boolean create)

	NotificationListener wrapper = new ListenerWrapper(l, name, mbean);
	synchronized (listenerWrappers) {
	    WeakReference ref = (WeakReference) listenerWrappers.get(wrapper);
	    if (ref != null) {
		NotificationListener existing =
		    (NotificationListener) ref.get();
		if (existing != null)
		    return existing;
	    }
	    if (create) {
		listenerWrappers.put(wrapper, new WeakReference(wrapper));
		return wrapper;
	    } else
		return null;
	}
    
private java.lang.ObjectgetMBean(javax.management.ObjectName name)
Gets a specific MBean controlled by the DefaultMBeanServerInterceptor. The name must have a non-default domain.


        if (name == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("Object name cannot be null"),
			       "Exception occured trying to get an MBean");
        }
        Object obj = null;
        synchronized(this) {
            obj = repository.retrieve(name);
            if (obj == null) {
		if (isTraceOn()) {
		    trace("getMBean", name+": Found no object");
		}
		throw new InstanceNotFoundException(name.toString());
            }
        }
        return obj;
    
public java.lang.IntegergetMBeanCount()

        return (repository.getCount());
    
public javax.management.MBeanInfogetMBeanInfo(javax.management.ObjectName name)


	// ------------------------------
	// ------------------------------

        Object moi = getMBean(name);
	final MBeanInfo mbi = meta.getMBeanInfo(moi);
	if (mbi == null)
	    throw new JMRuntimeException("MBean " + name +
					 "has no MBeanInfo");

	/* Permission check */
	checkMBeanPermission(mbi.getClassName(), null, name, "getMBeanInfo");

	return mbi;
    
public javax.management.ObjectInstancegetObjectInstance(javax.management.ObjectName name)


	name = nonDefaultDomain(name);
        Object obj = getMBean(name);
	final String className;
	try {
	    className = meta.getMBeanClassName(obj);
	} catch (IntrospectionException x) {
	    debugX("getObjectInstance",x);
	    throw new JMRuntimeException("Can't obtain class name for " +
					 name + ": " + x);
	} catch (NotCompliantMBeanException x) {
	    debugX("getObjectInstance",x);
	    throw new JMRuntimeException("Can't obtain class name for " +
					 name + ": " + x);
	}

	/* Permission check */
	checkMBeanPermission(className, null, name, "getObjectInstance");

	return new ObjectInstance(name, className);
    
private voidinitialize(java.lang.String domain, javax.management.MBeanServer outer, javax.management.MBeanServerDelegate delegate, com.sun.jmx.mbeanserver.MBeanInstantiator inst, com.sun.jmx.mbeanserver.MetaData meta, com.sun.jmx.mbeanserver.Repository repos)
Performs the necessary initializations for the MBeanServer. Creates and registers the MetaData service and the MBeanServer identification MBean


	// ------------------------------
	// ------------------------------

	if (!this.domain.equals(repository.getDefaultDomain()))
	    throw new IllegalArgumentException("Domain Name Mismatch");
        try {
            queryByRepo = repository.isFiltering();
        } catch (SecurityException e) {
	    throw e;
        } catch (Exception e) {
            queryByRepo = false;
        }
    
private voidinternal_addObject(java.lang.Object object, javax.management.ObjectName logicalName)
Adds a MBean in the repository


	// ------------------------------
	// ------------------------------

        // Let the repository do the work.

        synchronized(this) {
            try {
                repository.addMBean(object, logicalName);
            }
            catch (InstanceAlreadyExistsException e) {
                if (object instanceof MBeanRegistration ) {
                    meta.postRegisterInvoker(object,false);
                }
                throw e;
            }
        }
        // ---------------------
        // Send create event
        // ---------------------
        if (isTraceOn()) {
            trace("addObject", "Send create notification of object " +
		  logicalName.getCanonicalName());
        }

        sendNotification(MBeanServerNotification.REGISTRATION_NOTIFICATION,
			 logicalName ) ;
    
public java.lang.Objectinvoke(javax.management.ObjectName name, java.lang.String operationName, java.lang.Object[] params, java.lang.String[] signature)


	name = nonDefaultDomain(name);

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, operationName, name, "invoke");

        return meta.invoke(instance, operationName, params, signature);
    
private static booleanisDebugOn()

        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER);
    
public booleanisInstanceOf(javax.management.ObjectName name, java.lang.String className)


	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, name, "isInstanceOf");

	try {
	    return meta.isInstanceOf(instance, className);
	} catch (ReflectionException e) {
	    debugX("isInstanceOf",e);
	    return false;
	}
    
public booleanisRegistered(javax.management.ObjectName name)

        if (name == null) {
            throw new RuntimeOperationsException(
		     new IllegalArgumentException("Object name cannot be null"),
		     "Object name cannot be null");
        }

	name = nonDefaultDomain(name);

//  	/* Permission check */
//  	checkMBeanPermission(null, null, name, "isRegistered");

        synchronized(this) {
            return (repository.contains(name));
        }
    
private static booleanisTraceOn()

        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER);
    
protected javax.management.ObjectInstancemakeObjectInstance(java.lang.String className, java.lang.Object object, javax.management.ObjectName name)
Builds an ObjectInstance.
  • If the given object implements DynamicMBean, then ask its MBeanInfo for the class name.
  • Otherwise, uses the provided className

return
A new ObjectInstance for the given object.
exception
NotCompliantMBeanException if the object implements DynamicMBean but the class name can't be retrieved from its MBeanInfo.


	// if the MBean is a dynamic MBean ask its MBeanInfo for the
	// class name
	if (object instanceof DynamicMBean) {
	    try {
		className = meta.getMBeanClassName(object);
	    } catch (SecurityException x) {
		debugX("makeObjectInstance",x);
		throw x;
	    } catch (IntrospectionException x) {
		debugX("makeObjectInstance",x);
		throw new NotCompliantMBeanException(
			   "Can't obtain class name for " + name + ": " + x);
	    } catch (JMRuntimeException x) {
		debugX("makeObjectInstance",x);
		throw new NotCompliantMBeanException(
			   "Can't obtain class name for " + name + ": " + x);
	    }
	}

	if (className == null) {
	    throw new NotCompliantMBeanException(
			     "The class Name returned is null");
	}

        return(new ObjectInstance(nonDefaultDomain(name), className));
    
protected com.sun.jmx.mbeanserver.MetaDatameta()
Return the MetaData service object used by this interceptor.

	return meta;
    
private javax.management.ObjectNamenonDefaultDomain(javax.management.ObjectName name)

	if (name == null || name.getDomain().length() > 0)
	    return name;

	/* The ObjectName looks like ":a=b", and that's what its
	   toString() will return in this implementation.  So
	   we can just stick the default domain in front of it
	   to get a non-default-domain name.  We depend on the
	   fact that toString() works like that and that it
	   leaves wildcards in place (so we can detect an error
	   if one is supplied where it shouldn't be).  */
	final String completeName = domain + name;

	try {
	    return new ObjectName(completeName);
	} catch (MalformedObjectNameException e) {
	    final String msg =
		"Unexpected default domain problem: " + completeName + ": " +
		e;
	    throw new IllegalArgumentException(msg);
	}
    
public java.util.SetqueryMBeans(javax.management.ObjectName name, javax.management.QueryExp query)

	/* Permission check */
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    // Check if the caller has the right to invoke 'queryMBeans'
	    //
	    checkMBeanPermission(null, null, null, "queryMBeans");

	    // Perform query without "query".
	    //
	    Set list = queryMBeansImpl(name, null);

	    // Check if the caller has the right to invoke 'queryMBeans'
	    // on each specific classname/objectname in the list.
	    //
	    Set allowedList = new HashSet(list.size());
	    for (Iterator i = list.iterator(); i.hasNext(); ) {
		try {
		    ObjectInstance oi = (ObjectInstance) i.next();
		    checkMBeanPermission(oi.getClassName(), null,
					 oi.getObjectName(), "queryMBeans");
		    allowedList.add(oi);
		} catch (SecurityException e) {
		    // OK: Do not add this ObjectInstance to the list
		}
	    }

	    // Apply query to allowed MBeans only.
	    //
            return filterListOfObjectInstances(allowedList, query);
	} else {
	    // Perform query.
	    //
	    return queryMBeansImpl(name, query);
	}
    
private java.util.SetqueryMBeansImpl(javax.management.ObjectName name, javax.management.QueryExp query)

	// Query the MBeans on the repository
	//
        Set list = null;
        synchronized(this) {
            list = repository.query(name, query);
        }
        // The repository performs the filtering
	//
        if (queryByRepo) {
	    return list;
	} else {
            // The filtering will be performed by the MBeanServer
	    //
            return (filterListOfObjects(list, query));
        }
    
public java.util.SetqueryNames(javax.management.ObjectName name, javax.management.QueryExp query)

	/* Permission check */
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    // Check if the caller has the right to invoke 'queryNames'
	    //
	    checkMBeanPermission(null, null, null, "queryNames");

	    // Perform query without "query".
	    //
	    Set list = queryMBeansImpl(name, null);

	    // Check if the caller has the right to invoke 'queryNames'
	    // on each specific classname/objectname in the list.
	    //
	    Set allowedList = new HashSet(list.size());
	    for (Iterator i = list.iterator(); i.hasNext(); ) {
		try {
		    ObjectInstance oi = (ObjectInstance) i.next();
		    checkMBeanPermission(oi.getClassName(), null,
					 oi.getObjectName(), "queryNames");
		    allowedList.add(oi);
		} catch (SecurityException e) {
		    // OK: Do not add this ObjectInstance to the list
		}
	    }

	    // Apply query to allowed MBeans only.
	    //
	    Set queryList = filterListOfObjectInstances(allowedList, query);
	    Set result = new HashSet(queryList.size());
	    for (Iterator i = queryList.iterator(); i.hasNext(); ) {
		ObjectInstance oi = (ObjectInstance) i.next();
		result.add(oi.getObjectName());
	    }
	    return result;
	} else {
	    // Perform query.
	    //
	    Set queryList = queryMBeansImpl(name, query);
	    Set result = new HashSet(queryList.size());
	    for (Iterator i = queryList.iterator(); i.hasNext(); ) {
		ObjectInstance oi = (ObjectInstance) i.next();
		result.add(oi.getObjectName());
	    }
	    return result;
	}
    
protected javax.management.ObjectInstanceregisterCreatedObject(java.lang.String classname, java.lang.Object object, javax.management.ObjectName name)
Register an object from within createMBean(). This method wrapps registerObject() and is only called from within createMBean(). It calls directly registerObject(). Its only purpose is to provide hooks for derived classes.

	return registerObject(classname,object,name);
    
public javax.management.ObjectInstanceregisterMBean(java.lang.Object object, javax.management.ObjectName name)


	// ------------------------------
	// ------------------------------
        Class theClass = object.getClass();

        // Check the JMX compliance of the class
        meta.testCompliance(theClass);

	/* Permission check */
	final String infoClassName;
	try {
	    infoClassName = meta.getMBeanClassName(object);
	} catch (IntrospectionException e) {
	    throw new NotCompliantMBeanException(e.getMessage());
	} 

	checkMBeanPermission(infoClassName, null, name, "registerMBean");
	checkMBeanTrustPermission(theClass);

	return registerObject(infoClassName, object, name);
    
protected javax.management.ObjectInstanceregisterObject(java.lang.String classname, java.lang.Object object, javax.management.ObjectName name)
Register object in the repository, with the given name. This method is called by the various createMBean() flavours and by registerMBean() after all MBean compliance tests have been performed.

This method does not performed any kind of test compliance, and the caller should make sure that the given object is MBean compliant.

This methods performed all the basic steps needed for object registration:

  • If the object implements the MBeanRegistration interface, it invokes preRegister() on the object.
  • Then the object is added to the repository with the given name.
  • Finally, if the object implements the MBeanRegistration interface, it invokes postRegister() on the object.

param
object A reference to a MBean compliant object.
param
name The ObjectName of the object MBean.
return
the actual ObjectName with which the object was registered.
exception
InstanceAlreadyExistsException if an object is already registered with that name.
exception
MBeanRegistrationException if an exception occurs during registration.

      
        if (object == null) {
	    final RuntimeException wrapped =
		new IllegalArgumentException("Cannot add null object");
            throw new RuntimeOperationsException(wrapped,
                        "Exception occured trying to register the MBean");
        }

	name = nonDefaultDomain(name);

        if (isTraceOn()) {
            trace(dbgTag, "registerMBean", "ObjectName = " + name);
        }
	
	ObjectName logicalName = name;

        if (object instanceof MBeanRegistration) {
            logicalName = meta.preRegisterInvoker(object, name, server);
	    if (logicalName != name && logicalName != null) {
		logicalName =
		    ObjectName.getInstance(nonDefaultDomain(logicalName));
	    }
        }

	/* Permission check */
	checkMBeanPermission(classname, null, logicalName, "registerMBean");

	final ObjectInstance result;
        if (logicalName!=null) {
	    result = makeObjectInstance(classname, object, logicalName);
            internal_addObject(object, logicalName);
        } else {
            if (object instanceof MBeanRegistration ) {
                meta.postRegisterInvoker(object, false);
            }
	    final RuntimeException wrapped =
		new IllegalArgumentException("No object name specified");
            throw new RuntimeOperationsException(wrapped,
                        "Exception occured trying to register the MBean");
        }

        if (object instanceof MBeanRegistration)
            meta.postRegisterInvoker(object, true);

        /**
         * Checks if the newly registered MBean is a ClassLoader
	 * If so, tell the ClassLoaderRepository (CLR) about it.  We do
	 * this even if the object is a PrivateClassLoader.  In that
	 * case, the CLR remembers the loader for use when it is
	 * explicitly named (e.g. as the loader in createMBean) but
	 * does not add it to the list that is consulted by
	 * ClassLoaderRepository.loadClass.
         */
        if (object instanceof ClassLoader) {
	    final ModifiableClassLoaderRepository clr =
		instantiator.getClassLoaderRepository();
	    if (clr == null) {
		final RuntimeException wrapped =
		    new IllegalArgumentException(
		     "Dynamic addition of class loaders is not supported");
		throw new RuntimeOperationsException(wrapped,
	   "Exception occured trying to register the MBean as a class loader");
	    }
	    clr.addClassLoader(logicalName, (ClassLoader)object);
        }

	return result;
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener)

	removeNotificationListener(name, listener, null, null, true);
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)

	removeNotificationListener(name, listener, filter, handback, false);
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener)

	NotificationListener instance = getListener(listener);

        if (isTraceOn()) {
            trace("removeNotificationListener", "obj= " + name +
		  " listener= " + listener);
        }
	server.removeNotificationListener(name, instance);
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener, javax.management.NotificationFilter filter, java.lang.Object handback)


	NotificationListener instance = getListener(listener);

        if (isTraceOn()) {
            trace("removeNotificationListener", "obj= " + name +
		  " listener= " + listener);
        }
	server.removeNotificationListener(name, instance, filter, handback);
    
private voidremoveNotificationListener(javax.management.ObjectName name, javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback, boolean removeAll)


        if (isTraceOn()) {
            trace("removeNotificationListener", "obj= " + name);
        }

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, name,
			     "removeNotificationListener");

	/* We could simplify the code by assigning broadcaster after
	   assigning listenerWrapper, but that would change the error
	   behaviour when both the broadcaster and the listener are
	   erroneous.  */
        NotificationBroadcaster broadcaster = null;
	NotificationEmitter emitter = null;
	if (removeAll) {
	    if (!(instance instanceof NotificationBroadcaster)) {
		final RuntimeException exc =
		    new IllegalArgumentException(name.getCanonicalName());
		final String msg =
		    "MBean " + name.getCanonicalName() + " does not " +
		    "implement " + NotificationBroadcaster.class.getName();
		throw new RuntimeOperationsException(exc, msg);
	    }
	    broadcaster = (NotificationBroadcaster) instance;
	} else {
	    if (!(instance instanceof NotificationEmitter)) {
		final RuntimeException exc =
		    new IllegalArgumentException(name.getCanonicalName());
		final String msg =
		    "MBean " + name.getCanonicalName() + " does not " +
		    "implement " + NotificationEmitter.class.getName();
		throw new RuntimeOperationsException(exc, msg);
	    }
	    emitter = (NotificationEmitter) instance;
	}

	NotificationListener listenerWrapper =
	    getListenerWrapper(listener, name, instance, false);

        if (listenerWrapper == null)
            throw new ListenerNotFoundException("Unknown listener");

	if (removeAll)
	    broadcaster.removeNotificationListener(listenerWrapper);
	else {
	    emitter.removeNotificationListener(listenerWrapper,
					       filter,
					       handback);
	}
    
private voidsendNotification(java.lang.String NotifType, javax.management.ObjectName name)
Sends an MBeanServerNotifications with the specified type for the MBean with the specified ObjectName


	// ------------------------------
	// ------------------------------

        // ---------------------
        // Create notification
        // ---------------------
	MBeanServerNotification notif = new
	    MBeanServerNotification(NotifType,_MBSDelegateObjectName,0,name);

	if (isTraceOn()) {
	    trace("sendNotification", NotifType + " " + name);
	}

	delegate.sendNotification(notif);
    
public voidsetAttribute(javax.management.ObjectName name, javax.management.Attribute attribute)


        if (name == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("ObjectName name cannot be null"),
                "Exception occured trying to invoke the setter on the MBean");
        }

        if (attribute == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("Attribute cannot be null"),
                "Exception occured trying to invoke the setter on the MBean");
        }

	name = nonDefaultDomain(name);

        if (isTraceOn()) {
            trace("setAttribute", "Object= " + name + ", attribute=" +
		  attribute.getName());
        }

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, attribute.getName(),
			     name, "setAttribute");

        final Object o = meta.setAttribute(instance, attribute);
    
public javax.management.AttributeListsetAttributes(javax.management.ObjectName name, javax.management.AttributeList attributes)


        if (name == null) {
            throw new RuntimeOperationsException(new
		IllegalArgumentException("ObjectName name cannot be null"),
		"Exception occured trying to invoke the setter on the MBean");
        }

        if (attributes == null) {
            throw new RuntimeOperationsException(new
            IllegalArgumentException("AttributeList  cannot be null"),
	    "Exception occured trying to invoke the setter on the MBean");
        }

	name = nonDefaultDomain(name);

	Object instance = getMBean(name);
	SecurityManager sm = System.getSecurityManager();
	if (sm != null) {
	    /* Permission check */
	    String classname = null;
	    try {
		classname = meta.getMBeanClassName(instance);
	    } catch (IntrospectionException e) {
		classname = null;
	    } catch (NotCompliantMBeanException e) {
		classname = null;
	    }

	    // Check if the caller has the right to invoke 'setAttribute'
	    //
	    checkMBeanPermission(classname, null, name, "setAttribute");

	    // Check if the caller has the right to invoke 'setAttribute'
	    // on each specific attribute
	    //
	    AttributeList allowedAttributes =
		new AttributeList(attributes.size());
	    for (Iterator i = attributes.iterator(); i.hasNext();) {
		try {
		    Attribute attribute = (Attribute) i.next();
		    checkMBeanPermission(classname, attribute.getName(),
					 name, "setAttribute");
		    allowedAttributes.add(attribute);
		} catch (SecurityException e) {
		    // OK: Do not add this attribute to the list
		}
	    }
	    return meta.setAttributes(instance, allowedAttributes);
	} else {
	    return meta.setAttributes(instance, attributes);
	}
    
private static voidtrace(java.lang.String clz, java.lang.String func, java.lang.String info)

        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info);
    
private static voidtrace(java.lang.String func, java.lang.String info)

        trace(dbgTag, func, info);
    
public voidunregisterMBean(javax.management.ObjectName name)

        Object object;

        if (name == null) {
	    final RuntimeException wrapped =
		new IllegalArgumentException("Object name cannot be null");
            throw new RuntimeOperationsException(wrapped,
                      "Exception occured trying to unregister the MBean");
        }

	name = nonDefaultDomain(name);

	/* Permission check */
        Object instance = getMBean(name);
	String classname = null;
	try {
	    classname = meta.getMBeanClassName(instance);
	} catch (IntrospectionException e) {
	    classname = null;
	} catch (NotCompliantMBeanException e) {
	    classname = null;
	}
	checkMBeanPermission(classname, null, name, "unregisterMBean");

	/* We synchronize here to be sure that the preDeregister
	   method will be invoked exactly once, even if more than one
	   thread unregisters the MBean at the same time.  */
        synchronized(this) {
            object = repository.retrieve(name);
            if (object==null) {
                if (isTraceOn()) {
                    trace("unregisterMBean", name+": Found no object");
                }
                throw new InstanceNotFoundException(name.toString());
            }
            if (object instanceof MBeanRegistration) {
                meta.preDeregisterInvoker(object);
            }
            // Let the repository do the work.
            try {
		repository.remove(name);
            }
            catch (InstanceNotFoundException e) {
                throw e;
            }

	    /**
	     * Checks if the unregistered MBean is a ClassLoader
	     * If so, it removes the  MBean from the default loader repository.
	     */

            if (object instanceof ClassLoader
		&& object != server.getClass().getClassLoader()) {
		final ModifiableClassLoaderRepository clr =
		    instantiator.getClassLoaderRepository();
		if (clr != null) clr.removeClassLoader(name);
	    }
	}

	// ---------------------
	// Send deletion event
	// ---------------------
	if (isTraceOn()) {
	    trace("unregisterMBean", "Send delete notification of object "
		  + name.getCanonicalName());
	}
	sendNotification(MBeanServerNotification.UNREGISTRATION_NOTIFICATION,
			 name);

	if (object instanceof MBeanRegistration) {
	    meta.postDeregisterInvoker(object);
	}