⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmxmbeanserver.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		debug("new", "Unexpected security exception occurred: " + 		      e);       	    }	    throw e;	} catch (Exception e) {	    if (isDebugOn()) {		debug("new", "Unexpected exception occurred: " + 		      e.getClass().getName());       	    }	    throw new		IllegalStateException("Can't register delegate.");	}	/* Add my class loader to the repository	   This can be null if my class loader is the bootstrap	   class loader.  The ClassLoaderRepository knows how	   to handle that case.  */	ClassLoader myLoader = outerShell.getClass().getClassLoader();	final ModifiableClassLoaderRepository loaders = 	    instantiator.getClassLoaderRepository();	if (loaders != null) {	    loaders.addClassLoader(myLoader);	    /* Add the system class loader, so that if the MBean server is	       loaded by the bootstrap class loader we can still load	       MBeans from the classpath using	       createMBean(className, objectName).	       	       If this class (JmxMBeanServer) was not loaded by the	       system class loader or a parent of it, then the caller	       must have RuntimePermission("getClassLoader") for the	       getSystemClassLoader() call to succeed.  If the caller	       does not have that permission, any call to	       Class.getClassLoader() will fail.  Since there are lots	       of those in JMX, we better throw the exception now.	       This permission question is irrelevant when JMX is part	       of J2SE (as of 1.5). */	    ClassLoader systemLoader = ClassLoader.getSystemClassLoader();	    if (systemLoader != myLoader)		loaders.addClassLoader(systemLoader);	}    }    /**     * Return the MBeanServerInterceptor.     * @exception UnsupportedOperationException if      *            {@link MBeanServerInterceptor}s     *            are not enabled on this object.     * @see #interceptorsEnabled     **/    public synchronized MBeanServerInterceptor getMBeanServerInterceptor() {	if (interceptorsEnabled) return mbsInterceptor;	else throw new UnsupportedOperationException(	               "MBeanServerInterceptors are disabled.");    }    /**     * Set the MBeanServerInterceptor.     * @exception UnsupportedOperationException if      *            {@link MBeanServerInterceptor}s     *            are not enabled on this object.     * @see #interceptorsEnabled     **/    public synchronized void 	setMBeanServerInterceptor(MBeanServerInterceptor interceptor) {	if (!interceptorsEnabled) throw new UnsupportedOperationException(	               "MBeanServerInterceptors are disabled.");	if (interceptor == null) throw new	    IllegalArgumentException("MBeanServerInterceptor is null");	mbsInterceptor = interceptor;    }    /**     * <p>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.     */    public ClassLoader getClassLoaderFor(ObjectName mbeanName) 	throws InstanceNotFoundException {	return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName));    }    /**     * <p>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.     */    public ClassLoader getClassLoader(ObjectName loaderName)	throws InstanceNotFoundException {	return mbsInterceptor.getClassLoader(cloneObjectName(loaderName));    }    /**     * <p>Return the ClassLoaderRepository for that MBeanServer.     * @return The ClassLoaderRepository for that MBeanServer.     **/    public ClassLoaderRepository getClassLoaderRepository() {	/* Permission check */	checkMBeanPermission(null, null, null, "getClassLoaderRepository");	return secureClr;    }    public MBeanServerDelegate getMBeanServerDelegate() {	if (!interceptorsEnabled) throw new UnsupportedOperationException(	               "MBeanServerInterceptors are disabled.");	return mBeanServerDelegateObject;    }    // These methods are called by the JMX MBeanServerBuilder.    /**     * This method creates a new MBeanServerDelegate for a new MBeanServer.     * When creating a new MBeanServer the      * {@link javax.management.MBeanServerBuilder} first calls this method     * in order to create a new MBeanServerDelegate.     * <br>Then it calls      * <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code>     * passing the <var>delegate</var> that should be used by the MBeanServer      * implementation.     * <p>Note that the passed <var>delegate</var> might not be directly the      * MBeanServerDelegate that was returned by this method. It could     * be, for instance, a new object wrapping the previously      * returned object.     *     * @return A new {@link javax.management.MBeanServerDelegate}.     **/    public static MBeanServerDelegate newMBeanServerDelegate() {	return new MBeanServerDelegateImpl();    }    /**     * This method creates a new MBeanServer implementation object.     * When creating a new MBeanServer the      * {@link javax.management.MBeanServerBuilder} first calls       * <code>newMBeanServerDelegate()</code> in order to obtain a new      * {@link javax.management.MBeanServerDelegate} for the new      * MBeanServer. Then it calls      * <code>newMBeanServer(defaultDomain,outer,delegate)</code>     * passing the <var>delegate</var> that should be used by the      * MBeanServer  implementation.     * <p>Note that the passed <var>delegate</var> might not be directly the      * MBeanServerDelegate that was returned by this implementation. It could     * be, for instance, a new object wrapping the previously      * returned delegate.     * <p>The <var>outer</var> parameter is a pointer to the MBeanServer that     * should be passed to the {@link javax.management.MBeanRegistration}      * interface when registering MBeans inside the MBeanServer.     * If <var>outer</var> is <code>null</code>, then the MBeanServer      * implementation is free to use its own <code>this</code> pointer when     * invoking the {@link javax.management.MBeanRegistration} interface.     * <p>This makes it possible for a MBeanServer implementation to wrap     * another MBeanServer implementation, in order to implement, e.g,     * security checks, or to prevent access to the actual MBeanServer     * implementation by returning a pointer to a wrapping object.     *     * @param defaultDomain Default domain of the new 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 interceptors If <code>true</code>,      *        {@link MBeanServerInterceptor}s will be enabled (default is     *        <code>false</code>).     *        Note: this parameter is not taken into account by this     *        implementation - the default value <code>false</code> is     *        always used.     * @return A new private implementation of an MBeanServer.     * @see #interceptorsEnabled     * @see javax.management.MBeanServerBuilder     * @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder     **/    public static MBeanServer newMBeanServer(String defaultDomain, 					     MBeanServer outer, 					     MBeanServerDelegate delegate,					     boolean interceptors) {        // This constructor happens to disregard the value of the interceptors        // flag - that is, it always uses the default value - false.        // This is admitedly a bug, but we chose not to fix it for now        // since we would rather not have anybody depending on the Sun private        // interceptor APIs - which is most probably going to be removed and         // replaced by a public (javax) feature in the future.        //	return new JmxMBeanServer(defaultDomain,outer,delegate,interceptors);    }    // JMX OBJECT CLONING    //-------------------    /**     * Clone object name.     */    private ObjectName cloneObjectName(ObjectName name) {	if (name != null) {	    return ObjectName.getInstance(name);	}	return name;    }    /**     * Clone attribute.     */    private Attribute cloneAttribute(Attribute attribute) {	if (attribute != null) {	    if (!attribute.getClass().equals(Attribute.class)) {		return new Attribute(attribute.getName(), attribute.getValue());	    }	}	return attribute;    }    /**     * Clone attribute list.     */    private AttributeList cloneAttributeList(AttributeList list) {	if (list != null) {	    if (!list.getClass().equals(AttributeList.class)) {		// Create new attribute list		//		AttributeList newList = new AttributeList(list.size());		// Iterate through list and replace non JMX attributes		//		for (Iterator i = list.iterator(); i.hasNext(); ) {		    Attribute attribute = (Attribute) i.next();		    newList.add(cloneAttribute(attribute));		}		return newList;	    } else {		// Iterate through list and replace non JMX attributes		//		for (int i = 0; i < list.size(); i++) {		    Attribute attribute = (Attribute) list.get(i);		    if (!attribute.getClass().equals(Attribute.class)) {			list.set(i, cloneAttribute(attribute));		    }		}		return list;	    }	}	return list;    }    // SECURITY CHECKS    //----------------    private static void checkMBeanPermission(String classname,					     String member,					     ObjectName objectName,					     String actions)	throws SecurityException {	SecurityManager sm = System.getSecurityManager();	if (sm != null) {	    Permission perm = new MBeanPermission(classname,						  member,						  objectName,						  actions);	    sm.checkPermission(perm);	}    }    // TRACES & DEBUG    //---------------    private boolean isTraceOn() {        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER);    }    private void trace(String clz, String func, String info) {        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info);    }    private void trace(String func, String info) {        trace(dbgTag, func, info);    }    private boolean isDebugOn() {        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER);    }    private void debug(String clz, String func, String info) {        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info);    }    private void debug(String func, String info) {        debug(dbgTag, func, info);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -