alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * TestManagement.java
 *
 * Created on May 29, 2003, 9:32 AM
 */

package org.netbeans.tests.j2eeserver.plugin.jsr77;

import org.netbeans.tests.j2eeserver.plugin.jsr88.*;
import javax.management.j2ee.Management;
import javax.enterprise.deploy.spi.DeploymentManager;
import javax.management.j2ee.ListenerRegistration;
import javax.management.*;
import java.util.*;
import org.openide.ErrorManager;

/**
 *
 * @author  nn136682
 */
public class TestManagement implements Management{
    DepManager dm;
    
    /** Creates a new instance of TestManagement */
    public TestManagement(DeploymentManager dm) {
        this.dm = (DepManager) dm;
    }
    
    java.util.Map queryCache = null;
    Collection applications = null;
    Collection getApplications() {
        if (applications == null) {
            applications = new ArrayList();
            try {
                Hashtable t = new Hashtable();
                t.put("j2eeType", "J2EEApplication");
                t.put("name", "SampleApp");
                t.put("J2EEServer", "Target 1");
                applications.add(new ObjectName("domain1", t));
            } catch(Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        return applications;
    }
    Collection modules = null;
    Collection getModules() {
        if(modules == null) {
            modules = new ArrayList();
            try {
                Hashtable t = new Hashtable();
                t.put("j2eeType", "EJBModule");
                t.put("name", "SampleEjbModule");
                t.put("J2EEServer", "Target 1");
                t.put("J2EEApplication", "SampleApp");
                modules.add(new ObjectName("domain1", t));
            }catch(Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        return modules;
    }
    Collection ejbs = null;
    Collection getEjbs() {
        if (ejbs == null) {
            ejbs = new ArrayList();
            try {
                Hashtable t = new Hashtable();
                t.put("j2eeType", "EntityBean");
                t.put("name", "SampleEJB");
                t.put("EJBModule", "SampleEjbModule");
                t.put("J2EEServer", "Target 1");
                ejbs.add(new ObjectName("domain1", t));
            }catch(Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        return ejbs;
    }
    Collection resources = null;
    Collection getJDBCResources() {
        if (resources == null) {
            resources = new ArrayList();
            try {
                Hashtable t = new Hashtable();
                t.put("j2eeType", "JDBCResource");
                t.put("name", "SampleJdbcResource");
                t.put("J2EEServer", "Target 1");
                resources.add(new ObjectName("domain1", t));
            } catch (Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        return resources;
    }
    Collection jmsResources = null;
    Collection getJMSResources() {
        if (jmsResources == null) {
            jmsResources = new ArrayList();
            try {
                Hashtable t = new Hashtable();
                t.put("j2eeType", "JMSResource");
                t.put("name", "SampleJmsResource");
                t.put("J2EEServer", "Target 1");
                jmsResources.add(new ObjectName("domain1", t));
            } catch (Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        return jmsResources;
    }
    Set findObject(ObjectName query) {
        System.out.println("query="+query);
        if (queryCache == null) {
            queryCache = new java.util.HashMap();
            try {
                queryCache.put(new ObjectName("domain1:j2eeType=J2EEApplication,J2EEServer=Target 1,*"), getApplications());
                queryCache.put(new ObjectName("domain1:J2EEServer=Target 1,J2EEApplication=SampleApp,*"), getModules());
                queryCache.put(new ObjectName("domain1:J2EEServer=Target 1,EJBModule=SampleEjbModule,*"), getEjbs());
                queryCache.put(new ObjectName("domain1:j2eeType=JDBCResource,J2EEServer=Target 1,*"), getJDBCResources());
                queryCache.put(new ObjectName("domain1:j2eeType=JMSResource,J2EEServer=Target 1,*"), getJMSResources());
            } catch(Exception e) {
                ErrorManager.getDefault().notify(e);
            }
        }
        Collection result = (java.util.Collection) queryCache.get(query);
        return (result == null) ? new HashSet(0) : new HashSet(result);
    }
    public Object getAttribute(ObjectName objectName, String str) throws javax.management.MBeanException, javax.management.AttributeNotFoundException, javax.management.InstanceNotFoundException, javax.management.ReflectionException, java.rmi.RemoteException {
        if (objectName.getKeyProperty("j2eeType").equals("J2EEServer") && str.equals("state"))
            return new Integer(dm.getState() == DepManager.RUNNING ? 1 : 3);
            Attribute attr = (Attribute) attributeCache.get(objectName.getKeyProperty("name")+"-"+str);
            if (attr != null)
                return attr.getValue();
            return str+"-value";
    }
    
    public javax.management.AttributeList getAttributes(javax.management.ObjectName objectName, String[] str) throws javax.management.InstanceNotFoundException, javax.management.ReflectionException, java.rmi.RemoteException {
        AttributeList list = new javax.management.AttributeList();
        for (int i=0; i<3; i++)
            list.add(new Attribute("Attribute"+i, "value"+i));
        if (objectName.getKeyProperty("j2eeType").equals("J2EEServer")) {
            list.add(new Attribute("state", new Integer(dm.getState() == DepManager.RUNNING ? 1 : 3)));
        }
        return list;
    }
    
    public String getDefaultDomain() throws java.rmi.RemoteException {
        return "domain1";
    }
    
    public javax.ejb.EJBHome getEJBHome() throws java.rmi.RemoteException {
        return null;
    }
    
    public javax.ejb.Handle getHandle() throws java.rmi.RemoteException {
        return null;
    }
    
    public Integer getMBeanCount() throws java.rmi.RemoteException {
        return new Integer(0);
    }
    MBeanInfo beanInfo = null;
    public MBeanInfo getMBeanInfo(javax.management.ObjectName objectName) throws javax.management.IntrospectionException, javax.management.InstanceNotFoundException, javax.management.ReflectionException, java.rmi.RemoteException {
        if (beanInfo == null) {
            MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[3];
            for (int i=0; i
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.