Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
It is often desirable to have getClassLoaderFor and isInstanceOf return values based on some object other than the actual MBean object. The classic example is javax.management.StandardMBean, where getClassLoaderFor is utterly uninteresting. We know that some users have resorted to writing Object mbean = new StandardMBean(...) {} to create an anonymous subclass of StandardMBean that is defined by that code's ClassLoader. That is clunky, and not always an option. An example of when you might want to do this is if you want to access resources from the MBean's ClassLoader, for example to control localization or permission checking. If the MBean is an instance of StandardMBean, then what you really want to see is the ClassLoader of the wrapped object, because that's where the resources will live. The proposal is to define a new interface javax.management.GetResource with just one method: public Object getResource(); If an MBean is an instance of GetResource, then MBeanServer.getClassLoaderFor and .isInstanceOf will operate on the object returned by getResource() rather than the MBean object itself. The classes StandardMBean and RequiredModelMBean will implement GetResource. To avoid changing the behavior of existing code, the default getResource() will return the StandardMBean or RequiredModelMBean object itself, but an option will allow the MBean to be configured to return the wrapped object instead.
|