📄 lists.java
字号:
/*
* $Header: /home/cvs/jakarta-tomcat-catalina/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/Lists.java,v 1.12 2004/01/25 01:54:15 billbarker Exp $
* $Revision: 1.12 $
* $Date: 2004/01/25 01:54:15 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.webapp.admin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
* General purpose utility methods to create lists of objects that are
* commonly required in building the user interface. In all cases, if there
* are no matching elements, a zero-length list (rather than <code>null</code>)
* is returned.
*
* @author Craig R. McClanahan
* @author Amy Roh
* @version $Revision: 1.12 $ $Date: 2004/01/25 01:54:15 $
*/
public class Lists {
// ----------------------------------------------------------- Constructors
/**
* Protected constructor to prevent instantiation.
*/
protected Lists() { }
// ------------------------------------------------------- Static Variables
/**
* Precomputed list of debug level labels and values.
*/
private static List debugLevels = new ArrayList();
static {
debugLevels.add(new LabelValueBean("0", "0"));
debugLevels.add(new LabelValueBean("1", "1"));
debugLevels.add(new LabelValueBean("2", "2"));
debugLevels.add(new LabelValueBean("3", "3"));
debugLevels.add(new LabelValueBean("4", "4"));
debugLevels.add(new LabelValueBean("5", "5"));
debugLevels.add(new LabelValueBean("6", "6"));
debugLevels.add(new LabelValueBean("7", "7"));
debugLevels.add(new LabelValueBean("8", "8"));
debugLevels.add(new LabelValueBean("9", "9"));
}
/**
* Precomputed list of verbosity level labels and values.
*/
private static List verbosityLevels = new ArrayList();
static {
verbosityLevels.add(new LabelValueBean("0", "0"));
verbosityLevels.add(new LabelValueBean("1", "1"));
verbosityLevels.add(new LabelValueBean("2", "2"));
verbosityLevels.add(new LabelValueBean("3", "3"));
verbosityLevels.add(new LabelValueBean("4", "4"));
}
/**
* Precomputed list of (true,false) labels and values.
*/
private static List booleanValues = new ArrayList();
static {
booleanValues.add(new LabelValueBean("True", "true"));
booleanValues.add(new LabelValueBean("False", "false"));
}
/**
* Precomputed list of clientAuth lables and values.
*/
private static List clientAuthValues = new ArrayList();
static {
clientAuthValues.add(new LabelValueBean("True","true"));
clientAuthValues.add(new LabelValueBean("False","false"));
clientAuthValues.add(new LabelValueBean("Want","want"));
}
// --------------------------------------------------------- Public Methods
/**
* Return a <code>List</code> of {@link LabelValueBean}s for the legal
* settings for <code>debug</code> properties.
*/
public static List getDebugLevels() {
return (debugLevels);
}
/**
* Return a <code>List</code> of {@link LabelValueBean}s for the legal
* settings for <code>verbosity</code> properties.
*/
public static List getVerbosityLevels() {
return (verbosityLevels);
}
/**
* Return a <code>List</code> of {@link LabelValueBean}s for the legal
* settings for <code>boolean</code> properties.
*/
public static List getBooleanValues() {
return (booleanValues);
}
/**
* Return a <code>List</code> of {@link LabelValueBean}s for the legal
* settings for <code>clientAuth</code> properties.
*/
public static List getClientAuthValues() {
return (clientAuthValues);
}
/**
* Return a list of <code>Connector</code> object name strings
* for the specified <code>Service</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param service Object name of the service for which to select connectors
*
* @exception Exception if thrown while retrieving the list
*/
public static List getConnectors(MBeanServer mbserver, ObjectName service)
throws Exception {
StringBuffer sb = new StringBuffer(service.getDomain());
sb.append(":type=Connector,*");
ObjectName search = new ObjectName(sb.toString());
ArrayList connectors = new ArrayList();
Iterator names = mbserver.queryNames(search, null).iterator();
while (names.hasNext()) {
connectors.add(names.next().toString());
}
Collections.sort(connectors);
return (connectors);
}
/**
* Return a list of <code>Connector</code> object name strings
* for the specified <code>Service</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param service Object name of the service for which to select connectors
*
* @exception Exception if thrown while retrieving the list
*/
public static List getConnectors(MBeanServer mbserver, String service)
throws Exception {
return (getConnectors(mbserver, new ObjectName(service)));
}
/**
* Return a list of <code>Context</code> object name strings
* for the specified <code>Host</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param host Object name of the host for which to select contexts
*
* @exception Exception if thrown while retrieving the list
*/
public static List getContexts(MBeanServer mbserver, ObjectName host)
throws Exception {
StringBuffer sb = new StringBuffer(host.getDomain());
sb.append(":j2eeType=WebModule,*");
ObjectName search = new ObjectName(sb.toString());
ArrayList contexts = new ArrayList();
Iterator names = mbserver.queryNames(search, null).iterator();
String name = null;
ObjectName oname = null;
String hostPrefix = "//"+host.getKeyProperty("host");
String hostAttr = null;
while (names.hasNext()) {
name = names.next().toString();
oname = new ObjectName(name);
hostAttr = oname.getKeyProperty("name");
if (hostAttr.startsWith(hostPrefix)) {
contexts.add(name);
}
}
Collections.sort(contexts);
return (contexts);
}
/**
* Return a list of <code>DefaultContext</code> object name strings
* for the specified <code>Host</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param container Object name of the container for which to select default
* contexts
* @param containerType The type of the container for which to select
* default contexts
*
* @exception Exception if thrown while retrieving the list
*/
public static List getDefaultContexts(MBeanServer mbserver, String
container) throws Exception {
return (getDefaultContexts(mbserver, new ObjectName(container)));
}
/**
* Return a list of <code>DefaultContext</code> object name strings
* for the specified <code>Host</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param container Object name of the container for which to select default
* contexts
* @param containerType The type of the container for which to select
* default contexts
*
* @exception Exception if thrown while retrieving the list
*/
public static List getDefaultContexts(MBeanServer mbserver, ObjectName
container) throws Exception {
// FIXME
StringBuffer sb = new StringBuffer(container.getDomain());
sb.append(":type=DefaultContext");
String type = container.getKeyProperty("type");
String host = container.getKeyProperty("host");
if ("Host".equals(type)) {
host = container.getKeyProperty("host");
}
if (host != null) {
sb.append(",host=");
sb.append(host);
}
ObjectName search = new ObjectName(sb.toString());
ArrayList defaultContexts = new ArrayList();
Iterator names = mbserver.queryNames(search, null).iterator();
while (names.hasNext()) {
String name = names.next().toString();
defaultContexts.add(name);
}
Collections.sort(defaultContexts);
return (defaultContexts);
}
/**
* Return a list of <code>Context</code> object name strings
* for the specified <code>Host</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param host Object name of the host for which to select contexts
*
* @exception Exception if thrown while retrieving the list
*/
public static List getContexts(MBeanServer mbserver, String host)
throws Exception {
return (getContexts(mbserver, new ObjectName(host)));
}
/**
* Return a list of <code>Host</code> object name strings
* for the specified <code>Service</code> object name.
*
* @param mbserver MBeanServer from which to retrieve the list
* @param service Object name of the service for which to select hosts
*
* @exception Exception if thrown while retrieving the list
*/
public static List getHosts(MBeanServer mbserver, ObjectName service)
throws Exception {
StringBuffer sb = new StringBuffer(service.getDomain());
sb.append(":type=Host,*");
ObjectName search = new ObjectName(sb.toString());
ArrayList hosts = new ArrayList();
Iterator names = mbserver.queryNames(search, null).iterator();
while (names.hasNext()) {
hosts.add(names.next().toString());
}
Collections.sort(hosts);
return (hosts);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -