Example usage for javax.management ObjectName getKeyProperty

List of usage examples for javax.management ObjectName getKeyProperty

Introduction

In this page you can find the example usage for javax.management ObjectName getKeyProperty.

Prototype

public String getKeyProperty(String property) 

Source Link

Document

Obtains the value associated with a key in a key property.

Usage

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Request Dumper Valve.//www.j a v  a  2s.co  m
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createRequestDumperValve(String parent) throws Exception {

    // Create a new RequestDumperValve instance
    RequestDumperValve valve = new RequestDumperValve();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("RequestDumperValve");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), valve);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Single Sign On Valve.//from  ww w  . j a va  2 s  .  c om
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createSingleSignOn(String parent) throws Exception {

    // Create a new SingleSignOn instance
    SingleSignOn valve = new SingleSignOn();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        ((StandardContext) context).addValve(valve);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(valve);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(valve);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("SingleSignOn");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), valve);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new System Error Logger.//from  w  w w .  ja  va  2  s.c  o  m
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createSystemErrLogger(String parent) throws Exception {

    // Create a new SystemErrLogger instance
    SystemErrLogger logger = new SystemErrLogger();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setLogger(logger);
    } else if (type.equals("Engine")) {
        engine.setLogger(logger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setLogger(logger);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("SystemErrLogger");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), logger);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new  UserDatabaseRealm./*  w w w . j ava 2s. c o  m*/
 *
 * @param parent MBean Name of the associated parent component
 * @param resourceName Global JNDI resource name of the associated
 *  UserDatabase
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createUserDatabaseRealm(String parent, String resourceName) throws Exception {

    // Create a new UserDatabaseRealm instance
    UserDatabaseRealm realm = new UserDatabaseRealm();
    realm.setResourceName(resourceName);
    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if (type.equals("Context")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setRealm(realm);
    } else if (type.equals("Engine")) {
        engine.setRealm(realm);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setRealm(realm);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("UserDatabaseRealm");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), realm);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Loader./*  w  w  w.  ja va 2s  .c  om*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeLoader(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String type = oname.getKeyProperty("type");
    String serviceName = oname.getKeyProperty("service");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    String hostName = oname.getKeyProperty("host");
    if ((type != null) && (type.equals("Loader"))) {
        String contextName = getPathStr(oname.getKeyProperty("path"));
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(contextName);
        // Remove this component from its parent component
        context.setLoader(null);
    } else if ((type != null) && (type.equals("DefaultLoader"))) {
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            // Remove this component from its parent component
            defaultContext.setLoader(null);
        }
    }

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Manager./*from w  w  w  .  ja va 2  s.  c o m*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeManager(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String type = oname.getKeyProperty("type");
    String serviceName = oname.getKeyProperty("service");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    String hostName = oname.getKeyProperty("host");
    if ((type != null) && (type.equals("Manager"))) {
        String contextName = getPathStr(oname.getKeyProperty("path"));
        Host host = (Host) engine.findChild(hostName);
        Context context = (Context) host.findChild(contextName);
        // Remove this component from its parent component
        context.setManager(null);
    } else if ((type != null) && (type.equals("DefaultManager"))) {
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            // Remove this component from its parent component
            defaultContext.setManager(null);
        }
    }

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new DefaultContext./*w w w.  j  a v a 2  s.com*/
 *
 * @param parent MBean Name of the associated parent component
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createDefaultContext(String parent) throws Exception {

    // Create a new StandardDefaultContext instance
    StandardDefaultContext context = new StandardDefaultContext();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    String type = pname.getKeyProperty("type");
    Server server = ServerFactory.getServer();
    String serviceName = pname.getKeyProperty("service");
    if (serviceName == null) {
        serviceName = pname.getKeyProperty("name");
    }
    Service service = server.findService(serviceName);
    Engine engine = (Engine) service.getContainer();
    String hostName = pname.getKeyProperty("host");
    if (hostName == null) { //if DefaultContext is nested in Engine
        context.setParent(engine);
        engine.addDefaultContext(context);
    } else { // if DefaultContext is nested in Host
        Host host = (Host) engine.findChild(hostName);
        context.setParent(host);
        host.addDefaultContext(context);
    }

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("DefaultContext");
    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), context);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Realm./*from  ww w  .  ja  v  a2s  .  c om*/
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeRealm(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    String path = oname.getKeyProperty("path");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if (hostName == null) { // if realm's container is Engine
        Realm realm = engine.getRealm();
        Container container = realm.getContainer();
        if (container instanceof StandardEngine) {
            String sname = ((StandardEngine) container).getService().getName();
            if (sname.equals(serviceName)) {
                engine.setRealm(null);
            }
        }
    } else if (path == null) { // if realm's container is Host
        StandardHost host = (StandardHost) engine.findChild(hostName);
        Realm realm = host.getRealm();
        Container container = realm.getContainer();
        if (container instanceof StandardHost) {
            String hn = ((StandardHost) container).getName();
            StandardEngine se = (StandardEngine) ((StandardHost) container).getParent();
            String sname = se.getService().getName();
            if (sname.equals(serviceName) && hn.equals(hostName)) {
                host.setRealm(null);
            }
        }
    } else { // realm's container is Context
        StandardHost host = (StandardHost) engine.findChild(hostName);
        path = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(path);
        Realm realm = context.getRealm();
        Container container = realm.getContainer();
        if (container instanceof StandardContext) {
            String pathName = ((StandardContext) container).getName();
            StandardHost sh = (StandardHost) ((StandardContext) container).getParent();
            String hn = sh.getName();
            ;
            StandardEngine se = (StandardEngine) sh.getParent();
            String sname = se.getService().getName();
            if ((sname.equals(serviceName) && hn.equals(hostName)) && pathName.equals(path)) {
                context.setRealm(null);
            }
        }
    }
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Logger.//ww w. ja  v a2 s  . c  o  m
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeLogger(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");

    String path = oname.getKeyProperty("path");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if (hostName == null) { // if logger's container is Engine
        Logger logger = engine.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardEngine) {
            String sname = ((StandardEngine) container).getService().getName();
            if (sname.equals(serviceName)) {
                engine.setLogger(null);
            }
        }
    } else if (path == null) { // if logger's container is Host
        StandardHost host = (StandardHost) engine.findChild(hostName);
        Logger logger = host.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardHost) {
            String hn = ((StandardHost) container).getName();
            StandardEngine se = (StandardEngine) ((StandardHost) container).getParent();
            String sname = se.getService().getName();
            if (sname.equals(serviceName) && hn.equals(hostName)) {
                host.setLogger(null);
            }
        }
    } else { // logger's container is Context
        StandardHost host = (StandardHost) engine.findChild(hostName);
        path = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(path);
        Logger logger = context.getLogger();
        Container container = logger.getContainer();
        if (container instanceof StandardContext) {
            String pathName = ((StandardContext) container).getName();
            StandardHost sh = (StandardHost) ((StandardContext) container).getParent();
            String hn = sh.getName();
            ;
            StandardEngine se = (StandardEngine) sh.getParent();
            String sname = se.getService().getName();
            if ((sname.equals(serviceName) && hn.equals(hostName)) && pathName.equals(path)) {
                context.setLogger(null);
            }
        }
    }
}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Remove an existing Valve.// w ww  .ja  v  a2  s  . com
 *
 * @param name MBean Name of the comonent to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeValve(String name) throws Exception {

    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String serviceName = oname.getKeyProperty("service");
    String hostName = oname.getKeyProperty("host");
    String path = oname.getKeyProperty("path");
    String sequence = oname.getKeyProperty("sequence");
    Server server = ServerFactory.getServer();
    Service service = server.findService(serviceName);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if (hostName == null) { // if valve's container is Engine
        Valve[] valves = engine.getValves();
        for (int i = 0; i < valves.length; i++) {
            Container container = ((ValveBase) valves[i]).getContainer();
            if (container instanceof StandardEngine) {
                String sname = ((StandardEngine) container).getService().getName();
                Integer sequenceInt = new Integer(valves[i].hashCode());
                if (sname.equals(serviceName) && sequence.equals(sequenceInt.toString())) {
                    engine.removeValve(valves[i]);
                    break;
                }
            }
        }
    } else if (path == null) { // if valve's container is Host
        StandardHost host = (StandardHost) engine.findChild(hostName);
        Valve[] valves = host.getValves();
        for (int i = 0; i < valves.length; i++) {
            Container container = ((ValveBase) valves[i]).getContainer();
            if (container instanceof StandardHost) {
                String hn = ((StandardHost) container).getName();
                StandardEngine se = (StandardEngine) ((StandardHost) container).getParent();
                String sname = se.getService().getName();
                Integer sequenceInt = new Integer(valves[i].hashCode());
                if ((sname.equals(serviceName) && hn.equals(hostName))
                        && sequence.equals(sequenceInt.toString())) {
                    host.removeValve(valves[i]);
                    break;
                }
            }
        }
    } else { // valve's container is Context
        StandardHost host = (StandardHost) engine.findChild(hostName);
        path = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(path);
        Valve[] valves = context.getValves();
        for (int i = 0; i < valves.length; i++) {
            Container container = ((ValveBase) valves[i]).getContainer();
            if (container instanceof StandardContext) {
                String pathName = ((StandardContext) container).getName();
                StandardHost sh = (StandardHost) ((StandardContext) container).getParent();
                String hn = sh.getName();
                ;
                StandardEngine se = (StandardEngine) sh.getParent();
                String sname = se.getService().getName();
                Integer sequenceInt = new Integer(valves[i].hashCode());
                if (((sname.equals(serviceName) && hn.equals(hostName)) && pathName.equals(path))
                        && sequence.equals(sequenceInt.toString())) {
                    context.removeValve(valves[i]);
                    break;
                }
            }
        }
    }
}