/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.catalina.mbeans;
/** * General helper to dump MBean contents to the log.
*/ publicclass MBeanDumper {
privatestaticfinal Log log = LogFactory.getLog(MBeanDumper.class); protectedstaticfinal StringManager sm = StringManager.getManager(MBeanDumper.class);
privatestaticfinal String CRLF = "\r\n";
/** * The following code to dump MBeans has been copied from JMXProxyServlet. * * @param mbeanServer the MBean server * @param names a set of object names for which to dump the info * * @return a string representation of the MBeans
*/ publicstatic String dumpBeans(MBeanServer mbeanServer, Set<ObjectName> names) {
StringBuilder buf = new StringBuilder(); for (ObjectName oname : names) {
buf.append("Name: ");
buf.append(oname.toString());
buf.append(CRLF);
try {
MBeanInfo minfo = mbeanServer.getMBeanInfo(oname); // can't be null - I think
String code = minfo.getClassName(); if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
code = (String) mbeanServer.getAttribute(oname, "modelerType");
}
buf.append("modelerType: ");
buf.append(code);
buf.append(CRLF);
MBeanAttributeInfo attrs[] = minfo.getAttributes();
Object value = null;
for (MBeanAttributeInfo attr : attrs) { if (!attr.isReadable()) { continue;
}
String attName = attr.getName(); if ("modelerType".equals(attName)) { continue;
} if (attName.indexOf('=') >= 0 || attName.indexOf(':') >= 0 || attName.indexOf(' ') >= 0) { continue;
}
publicstatic String escape(String value) { // The only invalid char is \n // We also need to keep the string short and split it with \nSPACE // XXX TODO int idx = value.indexOf('\n'); if (idx < 0) { return value;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.