Example usage for javax.management ObjectName toString

List of usage examples for javax.management ObjectName toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Returns a string representation of the object name.

Usage

From source file:catalina.mbeans.MBeanFactory.java

/**
  * Create a new StandardContext.//from  ww  w. j a  v  a  2 s .  c o m
  *
  * @param parent MBean Name of the associated parent component
  * @param path The context path for this Context
  * @param docBase Document base directory (or WAR) for this Context
  *
  * @exception Exception if an MBean cannot be created or registered
  */
public String createStandardContext(String parent, String path, String docBase) throws Exception {

    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(pname.getKeyProperty("host"));

    // Add context to the host
    host.addChild(context);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("StandardContext");

    ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), context);
    return (oname.toString());

}

From source file:catalina.mbeans.MBeanFactory.java

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

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

    // 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("SystemOutLogger");
    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  av a  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

/**
 * Create a new System Error Logger./*  ww w . jav  a2  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 DefaultContext.//from  w w w .  jav  a  2 s .  co  m
 *
 * @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

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

    // Create a new FileLogger instance
    FileLogger fileLogger = new FileLogger();

    // 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(fileLogger);
    } else if (type.equals("Engine")) {
        engine.setLogger(fileLogger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.setLogger(fileLogger);
    }

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

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new AccessLoggerValve.//  www  . j av  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 createAccessLoggerValve(String parent) throws Exception {

    // Create a new AccessLogValve instance
    AccessLogValve accessLogger = new AccessLogValve();

    // 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(accessLogger);
    } else if (type.equals("Engine")) {
        ((StandardEngine) engine).addValve(accessLogger);
    } else if (type.equals("Host")) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        ((StandardHost) host).addValve(accessLogger);
    }

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

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new Web Application Loader./*from w  w  w  . j  a  v a2 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 createWebappLoader(String parent) throws Exception {

    // Create a new WebappLoader instance
    WebappLoader loader = new WebappLoader();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    String type = pname.getKeyProperty("type");
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if ((type != null) && (type.equals("Context"))) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setLoader(loader);
    } else if ((type != null) && (type.equals("DefaultContext"))) {
        String hostName = pname.getKeyProperty("host");
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            loader.setDefaultContext(defaultContext);
            defaultContext.setLoader(loader);
        }
    }

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

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new StandardManager./*from w ww. j av  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 createStandardManager(String parent) throws Exception {

    // Create a new StandardManager instance
    StandardManager manager = new StandardManager();

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    String type = pname.getKeyProperty("type");
    Service service = server.findService(pname.getKeyProperty("service"));
    Engine engine = (Engine) service.getContainer();
    if ((type != null) && (type.equals("Context"))) {
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        String pathStr = getPathStr(pname.getKeyProperty("path"));
        Context context = (Context) host.findChild(pathStr);
        context.setManager(manager);
    } else if ((type != null) && (type.equals("DefaultContext"))) {
        String hostName = pname.getKeyProperty("host");
        DefaultContext defaultContext = null;
        if (hostName == null) {
            defaultContext = engine.getDefaultContext();
        } else {
            Host host = (Host) engine.findChild(hostName);
            defaultContext = host.getDefaultContext();
        }
        if (defaultContext != null) {
            manager.setDefaultContext(defaultContext);
            defaultContext.setManager(manager);
        }
    }

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

}

From source file:catalina.mbeans.MBeanFactory.java

/**
 * Create a new HttpConnector/*from ww  w  . java  2 s.c o m*/
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createHttpConnector(String parent, String address, int port) throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1[] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2[] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.addConnector((Connector) retobj);

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

}