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

📄 dynamicconfiguration.java

📁 jConfig,JAVA读取XML的开源项目
💻 JAVA
字号:
/*
 * DynamicConfigurationMBean.java
 *
 * Created on 3. Mai 2004, 17:06
 */

package org.jconfig.jmx;

import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;

import org.jconfig.Configuration;
import org.jconfig.ConfigurationManager;
/**
 *
 * @author  mecky
 */
public class DynamicConfiguration implements DynamicConfigurationMBean, MBeanRegistration {
        
    private MBeanServer mBeanServer;
    private String name;
    private ObjectName objectName;
    
    public DynamicConfiguration() {
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
        Configuration config = ConfigurationManager.getConfiguration(name);
        loadConfiguration(name);
    }
    
    public void postDeregister() {
    }
    
    public void postRegister(Boolean booleanParam) {
    }
    
    public void preDeregister() throws java.lang.Exception {
    }
    
    public ObjectName preRegister(MBeanServer mBeanServer, ObjectName objectName) throws java.lang.Exception {
        this.mBeanServer = mBeanServer;
        this.objectName = objectName;
        return objectName;
    }
    
    public ObjectName loadConfiguration(String name) {
        
        System.out.println("loadConfiguration called:"+name);
        
        // test if MBean has been already loaded
        // it can also be tested asking directly to MBeanServer
        /*
        for (int i = 0; i < alAttributes.size(); i++) {
            MBeanAttributeInfo mai = (MBeanAttributeInfo) alAttributes.get(i);
            if (mai.getName().equalsIgnoreCase("configuration=" + name))
                return null; // shoud throw an exception??
        }
        */
        return registerConfigurationMBean(name);
    }
    
    ObjectName registerConfigurationMBean(String name) {
        
        ObjectName configurationObjectName = null;
        try {
            configurationObjectName =
            new ObjectName(objectName.getDomain(), "configuration", name);
            ConfigurationDynamicMBean configurationMBean =
            new ConfigurationDynamicMBean(configurationObjectName, name);
            mBeanServer.registerMBean(configurationMBean, configurationObjectName);
            
            // tenemos un atributo nuevo
            /*
            alAttributes
            .add(new MBeanAttributeInfo(
            "configuration=" + name,
            "javax.management.ObjectName",
            "The " + name + " configuration.",
            true,
            true,
            // this makes the object clickable
            false));
             */
            
        } catch (Exception e) {
            //log.error(
            //	"Could not add configurationMBean for [" + name + "].",
            //	e);
            e.printStackTrace();
        }
        return objectName;
    }
    
}

⌨️ 快捷键说明

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