0N/A/*
2362N/A * Copyright (c) 1999, 2008, 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/A
0N/A/**
11N/A * <p>Represents attributes used as arguments to relational constraints,
11N/A * where the attribute must be in an MBean of a specified {@linkplain
11N/A * MBeanInfo#getClassName() class}. A QualifiedAttributeValueExp may be used
11N/A * anywhere a ValueExp is required.
11N/A *
0N/A * @serial include
0N/A *
0N/A * @since 1.5
0N/A */
0N/Aclass QualifiedAttributeValueExp extends AttributeValueExp {
0N/A
0N/A
0N/A /* Serial version */
0N/A private static final long serialVersionUID = 8832517277410933254L;
0N/A
0N/A /**
0N/A * @serial The attribute class name
0N/A */
0N/A private String className;
0N/A
0N/A
0N/A /**
0N/A * Basic Constructor.
11N/A * @deprecated see {@link AttributeValueExp#AttributeValueExp()}
0N/A */
11N/A @Deprecated
0N/A public QualifiedAttributeValueExp() {
0N/A }
0N/A
0N/A /**
0N/A * Creates a new QualifiedAttributeValueExp representing the specified object
0N/A * attribute, named attr with class name className.
0N/A */
0N/A public QualifiedAttributeValueExp(String className, String attr) {
0N/A super(attr);
0N/A this.className = className;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of the class name of the attribute.
0N/A */
0N/A public String getAttrClassName() {
0N/A return className;
0N/A }
0N/A
0N/A /**
0N/A * Applies the QualifiedAttributeValueExp to an MBean.
0N/A *
0N/A * @param name The name of the MBean on which the QualifiedAttributeValueExp will be applied.
0N/A *
0N/A * @return The ValueExp.
0N/A *
0N/A * @exception BadStringOperationException
0N/A * @exception BadBinaryOpValueExpException
0N/A * @exception BadAttributeValueExpException
0N/A * @exception InvalidApplicationException
0N/A */
11N/A @Override
0N/A public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
0N/A BadAttributeValueExpException, InvalidApplicationException {
0N/A try {
0N/A MBeanServer server = QueryEval.getMBeanServer();
0N/A String v = server.getObjectInstance(name).getClassName();
0N/A
0N/A if (v.equals(className)) {
0N/A return super.apply(name);
0N/A }
0N/A throw new InvalidApplicationException("Class name is " + v +
0N/A ", should be " + className);
0N/A
0N/A } catch (Exception e) {
0N/A throw new InvalidApplicationException("Qualified attribute: " + e);
0N/A /* Can happen if MBean disappears between the time we
0N/A construct the list of MBeans to query and the time we
0N/A evaluate the query on this MBean, or if
0N/A getObjectInstance throws SecurityException. */
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the string representing its value
0N/A */
11N/A @Override
0N/A public String toString() {
0N/A if (className != null) {
1790N/A return className + "." + super.toString();
0N/A } else {
0N/A return super.toString();
0N/A }
0N/A }
0N/A
0N/A}