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

📄 modelmbeanutil.java

📁 jmx在spring中的实现
💻 JAVA
字号:
/*
======================================================================

  ModelMBeanExtension.java

  Created by Claude Duguay
  Copyright (c) 2005

======================================================================
*/

package com.claudeduguay.mbeans.spring;

import java.lang.reflect.*;

import javax.management.*;
import javax.management.modelmbean.*;

public class ModelMBeanUtil
{
	protected static String toMethodName(String prefix, String name)
	{
		char head = Character.toUpperCase(name.charAt(0));
		String tail = name.substring(1);
		return prefix + head + tail;
	}
	
	protected static String matchType(MBeanNotificationInfo info, String match)
	{
		String[] types = info.getNotifTypes();
		for (String type: types)
		{
			if (type.endsWith(match)) return type;
		}
		return types[0];
	}
	
	public static Method findGetMethod(ModelMBeanInfo modelMBeanInfo, Object managedBean, String attribute)
		throws MBeanException
	{
		try
		{
			ModelMBeanAttributeInfo info = modelMBeanInfo.getAttribute(attribute);
			Descriptor descriptor = info.getDescriptor();
			String methodName = (String)(descriptor.getFieldValue("getMethod"));
			if (methodName == null)
			{
				methodName = toMethodName("get", attribute);
			}
			return managedBean.getClass().getMethod(methodName, new Class[] {});
		}
		catch (NoSuchMethodException e)
		{
			throw new MBeanException(e);
		}
	}
	
	public static Method findSetMethod(ModelMBeanInfo modelMBeanInfo, Object managedBean, String attribute)
		throws MBeanException
	{
		try
		{
			ModelMBeanAttributeInfo info = modelMBeanInfo.getAttribute(attribute);
			Descriptor descriptor = info.getDescriptor();
			String methodName = (String)(descriptor.getFieldValue("setMethod"));
			if (methodName == null)
			{
				methodName = toMethodName("set", attribute);
			}
			Class[] type = {Class.forName(info.getType())};
			return managedBean.getClass().getMethod(methodName, type);
		}
		catch (ClassNotFoundException e)
		{
			throw new MBeanException(e);
		}
		catch (NoSuchMethodException e)
		{
			throw new MBeanException(e);
		}
	}
}

⌨️ 快捷键说明

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