1. /*
  2. * @(#)QualifiedAttributeValueExp.java 4.18 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management;
  8. /**
  9. * This class represents indexed attributes used as arguments to relational
  10. * constraints. An QualifiedAttributeValueExp may be used anywhere a
  11. * ValueExp is required.
  12. * @serial include
  13. *
  14. * @since 1.5
  15. */
  16. class QualifiedAttributeValueExp extends AttributeValueExp {
  17. /* Serial version */
  18. private static final long serialVersionUID = 8832517277410933254L;
  19. /**
  20. * @serial The attribute class name
  21. */
  22. private String className;
  23. /**
  24. * Basic Constructor.
  25. */
  26. public QualifiedAttributeValueExp() {
  27. }
  28. /**
  29. * Creates a new QualifiedAttributeValueExp representing the specified object
  30. * attribute, named attr with class name className.
  31. */
  32. public QualifiedAttributeValueExp(String className, String attr) {
  33. super(attr);
  34. this.className = className;
  35. }
  36. /**
  37. * Returns a string representation of the class name of the attribute.
  38. */
  39. public String getAttrClassName() {
  40. return className;
  41. }
  42. /**
  43. * Applies the QualifiedAttributeValueExp to an MBean.
  44. *
  45. * @param name The name of the MBean on which the QualifiedAttributeValueExp will be applied.
  46. *
  47. * @return The ValueExp.
  48. *
  49. * @exception BadStringOperationException
  50. * @exception BadBinaryOpValueExpException
  51. * @exception BadAttributeValueExpException
  52. * @exception InvalidApplicationException
  53. */
  54. public ValueExp apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
  55. BadAttributeValueExpException, InvalidApplicationException {
  56. try {
  57. MBeanServer server = QueryEval.getMBeanServer();
  58. String v = server.getObjectInstance(name).getClassName();
  59. if (v.equals(className)) {
  60. return super.apply(name);
  61. }
  62. throw new InvalidApplicationException("Class name is " + v +
  63. ", should be " + className);
  64. } catch (Exception e) {
  65. throw new InvalidApplicationException("Qualified attribute: " + e);
  66. /* Can happen if MBean disappears between the time we
  67. construct the list of MBeans to query and the time we
  68. evaluate the query on this MBean, or if
  69. getObjectInstance throws SecurityException. */
  70. }
  71. }
  72. /**
  73. * Returns the string representing its value
  74. */
  75. public String toString() {
  76. if (className != null) {
  77. return className + "." + super.toString();
  78. } else {
  79. return super.toString();
  80. }
  81. }
  82. }