X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=srcjar_unused%2Forg%2Fapache%2Flog4j%2Fjmx%2FAbstractDynamicMBean.java;fp=srcjar_unused%2Forg%2Fapache%2Flog4j%2Fjmx%2FAbstractDynamicMBean.java;h=d9d010ae5280c6295928eedacddc91f49f4b7dfe;hb=4f30214e8098748469c6a4269ac2ed6c5750e4b0;hp=0000000000000000000000000000000000000000;hpb=9dabc02511e3a334a5749a504f57f69d6c9017bd;p=jalview.git diff --git a/srcjar_unused/org/apache/log4j/jmx/AbstractDynamicMBean.java b/srcjar_unused/org/apache/log4j/jmx/AbstractDynamicMBean.java new file mode 100644 index 0000000..d9d010a --- /dev/null +++ b/srcjar_unused/org/apache/log4j/jmx/AbstractDynamicMBean.java @@ -0,0 +1,189 @@ +/* + * 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.log4j.jmx; + +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Vector; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.DynamicMBean; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.JMException; +import javax.management.MBeanRegistration; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectName; +import javax.management.RuntimeOperationsException; + +import org.apache.log4j.Logger; +import org.apache.log4j.Appender; + +public abstract class AbstractDynamicMBean implements DynamicMBean, + MBeanRegistration { + + String dClassName; + MBeanServer server; + private final Vector mbeanList = new Vector(); + + /** + * Get MBean name. + * @param appender appender, may not be null. + * @return name. + * @since 1.2.16 + */ + static protected String getAppenderName(final Appender appender){ + String name = appender.getName(); + if (name == null || name.trim().length() == 0) { + // try to get some form of a name, because null is not allowed (exception), and empty string certainly isn't useful in JMX.. + name = appender.toString(); + } + return name; + } + + + /** + * Enables the to get the values of several attributes of the Dynamic MBean. + */ + public + AttributeList getAttributes(String[] attributeNames) { + + // Check attributeNames is not null to avoid NullPointerException later on + if (attributeNames == null) { + throw new RuntimeOperationsException( + new IllegalArgumentException("attributeNames[] cannot be null"), + "Cannot invoke a getter of " + dClassName); + } + + AttributeList resultList = new AttributeList(); + + // if attributeNames is empty, return an empty result list + if (attributeNames.length == 0) { + return resultList; + } + + // build the result attribute list + for (int i=0 ; i