0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management;
0N/A
0N/Aimport java.security.AccessController;
0N/A
0N/Aimport com.sun.jmx.mbeanserver.GetPropertyAction;
0N/A
0N/A/**
0N/A * This class represents the name of the Java implementation class of
0N/A * the MBean. It is used for performing queries based on the class of
0N/A * the MBean.
0N/A * @serial include
0N/A *
0N/A * <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.
0N/A *
0N/A * @since 1.5
0N/A */
0N/A@SuppressWarnings("serial") // serialVersionUID is not constant
0N/Aclass ClassAttributeValueExp extends AttributeValueExp {
0N/A
0N/A // Serialization compatibility stuff:
0N/A // Two serial forms are supported in this class. The selected form depends
0N/A // on system property "jmx.serial.form":
0N/A // - "1.0" for JMX 1.0
0N/A // - any other value for JMX 1.1 and higher
0N/A //
0N/A // Serial version for old serial form
0N/A private static final long oldSerialVersionUID = -2212731951078526753L;
0N/A //
0N/A // Serial version for new serial form
0N/A private static final long newSerialVersionUID = -1081892073854801359L;
0N/A
0N/A private static final long serialVersionUID;
0N/A static {
0N/A boolean compat = false;
0N/A try {
0N/A GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
0N/A String form = AccessController.doPrivileged(act);
0N/A compat = (form != null && form.equals("1.0"));
0N/A } catch (Exception e) {
0N/A // OK: exception means no compat with 1.0, too bad
0N/A }
0N/A if (compat)
0N/A serialVersionUID = oldSerialVersionUID;
0N/A else
0N/A serialVersionUID = newSerialVersionUID;
0N/A }
0N/A
0N/A /**
0N/A * @serial The name of the attribute
0N/A *
0N/A * <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.
0N/A */
0N/A private String attr;
0N/A
0N/A /**
0N/A * Basic Constructor.
0N/A */
0N/A public ClassAttributeValueExp() {
0N/A /* Compatibility: we have an attr field that we must hold on to
0N/A for serial compatibility, even though our parent has one too. */
0N/A super("Class");
0N/A attr = "Class";
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Applies the ClassAttributeValueExp on an MBean. Returns the name of
0N/A * the Java implementation class of the MBean.
0N/A *
0N/A * @param name The name of the MBean on which the ClassAttributeValueExp will be applied.
0N/A *
0N/A * @return The ValueExp.
0N/A *
0N/A * @exception BadAttributeValueExpException
0N/A * @exception InvalidApplicationException
0N/A */
0N/A public ValueExp apply(ObjectName name)
0N/A throws BadStringOperationException, BadBinaryOpValueExpException,
0N/A BadAttributeValueExpException, InvalidApplicationException {
0N/A // getAttribute(name);
0N/A Object result = getValue(name);
0N/A if (result instanceof String) {
0N/A return new StringValueExp((String)result);
0N/A } else {
0N/A throw new BadAttributeValueExpException(result);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the string "Class" representing its value
0N/A */
0N/A public String toString() {
0N/A return attr;
0N/A }
0N/A
0N/A
0N/A protected Object getValue(ObjectName name) {
0N/A try {
0N/A // Get the class of the object
0N/A MBeanServer server = QueryEval.getMBeanServer();
0N/A return server.getObjectInstance(name).getClassName();
0N/A } catch (Exception re) {
0N/A return null;
0N/A /* In principle the MBean does exist because otherwise we
0N/A wouldn't be evaluating the query on it. But it could
0N/A potentially have disappeared in between the time we
0N/A discovered it and the time the query is evaluated.
0N/A
0N/A Also, the exception could be a SecurityException.
0N/A
0N/A Returning null from here will cause
0N/A BadAttributeValueExpException, which will in turn cause
0N/A this MBean to be omitted from the query result. */
0N/A }
0N/A }
0N/A
0N/A}