Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/management/ClassAttributeValueExp.java
38829 views
/*1* Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;2627import java.security.AccessController;2829import com.sun.jmx.mbeanserver.GetPropertyAction;3031/**32* This class represents the name of the Java implementation class of33* the MBean. It is used for performing queries based on the class of34* the MBean.35* @serial include36*37* <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.38*39* @since 1.540*/41@SuppressWarnings("serial") // serialVersionUID is not constant42class ClassAttributeValueExp extends AttributeValueExp {4344// Serialization compatibility stuff:45// Two serial forms are supported in this class. The selected form depends46// on system property "jmx.serial.form":47// - "1.0" for JMX 1.048// - any other value for JMX 1.1 and higher49//50// Serial version for old serial form51private static final long oldSerialVersionUID = -2212731951078526753L;52//53// Serial version for new serial form54private static final long newSerialVersionUID = -1081892073854801359L;5556private static final long serialVersionUID;57static {58boolean compat = false;59try {60GetPropertyAction act = new GetPropertyAction("jmx.serial.form");61String form = AccessController.doPrivileged(act);62compat = (form != null && form.equals("1.0"));63} catch (Exception e) {64// OK: exception means no compat with 1.0, too bad65}66if (compat)67serialVersionUID = oldSerialVersionUID;68else69serialVersionUID = newSerialVersionUID;70}7172/**73* @serial The name of the attribute74*75* <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.76*/77private String attr;7879/**80* Basic Constructor.81*/82public ClassAttributeValueExp() {83/* Compatibility: we have an attr field that we must hold on to84for serial compatibility, even though our parent has one too. */85super("Class");86attr = "Class";87}888990/**91* Applies the ClassAttributeValueExp on an MBean. Returns the name of92* the Java implementation class of the MBean.93*94* @param name The name of the MBean on which the ClassAttributeValueExp will be applied.95*96* @return The ValueExp.97*98* @exception BadAttributeValueExpException99* @exception InvalidApplicationException100*/101public ValueExp apply(ObjectName name)102throws BadStringOperationException, BadBinaryOpValueExpException,103BadAttributeValueExpException, InvalidApplicationException {104// getAttribute(name);105Object result = getValue(name);106if (result instanceof String) {107return new StringValueExp((String)result);108} else {109throw new BadAttributeValueExpException(result);110}111}112113/**114* Returns the string "Class" representing its value115*/116public String toString() {117return attr;118}119120121protected Object getValue(ObjectName name) {122try {123// Get the class of the object124MBeanServer server = QueryEval.getMBeanServer();125return server.getObjectInstance(name).getClassName();126} catch (Exception re) {127return null;128/* In principle the MBean does exist because otherwise we129wouldn't be evaluating the query on it. But it could130potentially have disappeared in between the time we131discovered it and the time the query is evaluated.132133Also, the exception could be a SecurityException.134135Returning null from here will cause136BadAttributeValueExpException, which will in turn cause137this MBean to be omitted from the query result. */138}139}140141}142143144