1. /*
  2. * @(#)MonitoredAttributeBase.java 1.3 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 com.sun.corba.se.spi.monitoring;
  8. import java.util.*;
  9. /**
  10. * <p>
  11. *
  12. * @author Hemanth Puttaswamy
  13. * </p>
  14. * <p>
  15. * A Convenient class provided to help users extend and implement only
  16. * getValue(), if there is no need to clear the state and the attribute is not
  17. * writable.
  18. *
  19. * </p>
  20. */
  21. public abstract class MonitoredAttributeBase implements MonitoredAttribute {
  22. String name;
  23. MonitoredAttributeInfo attributeInfo;
  24. /**
  25. * Constructor.
  26. */
  27. public MonitoredAttributeBase( String name, MonitoredAttributeInfo info ) {
  28. this.name = name;
  29. this.attributeInfo = info;
  30. }
  31. /**
  32. * A Package Private Constructor for internal use only.
  33. */
  34. MonitoredAttributeBase( String name ) {
  35. this.name = name;
  36. }
  37. /**
  38. * A Package Private convenience method for setting MonitoredAttributeInfo
  39. * for this Monitored Attribute.
  40. */
  41. void setMonitoredAttributeInfo( MonitoredAttributeInfo info ) {
  42. this.attributeInfo = info;
  43. }
  44. /**
  45. * If the concrete class decides not to provide the implementation of this
  46. * method, then it's OK. Some of the examples where we may decide to not
  47. * provide the implementation is the connection state. Irrespective of
  48. * the call to clearState, the connection state will be showing the
  49. * currect state of the connection.
  50. * NOTE: This method is only used to clear the Monitored Attribute state,
  51. * not the real state of the system itself.
  52. */
  53. public void clearState( ) {
  54. }
  55. /**
  56. * This method should be implemented by the concrete class.
  57. */
  58. public abstract Object getValue( );
  59. /**
  60. * This method should be implemented by the concrete class only if the
  61. * attribute is writable. If the attribute is not writable and if this
  62. * method called, it will result in an IllegalStateException.
  63. */
  64. public void setValue( Object value ) {
  65. if( !attributeInfo.isWritable() ) {
  66. throw new IllegalStateException(
  67. "The Attribute " + name + " is not Writable..." );
  68. }
  69. throw new IllegalStateException(
  70. "The method implementation is not provided for the attribute " +
  71. name );
  72. }
  73. /**
  74. * Gets the MonitoredAttributeInfo for the attribute.
  75. */
  76. public MonitoredAttributeInfo getAttributeInfo( ) {
  77. return attributeInfo;
  78. }
  79. /**
  80. * Gets the name of the attribute.
  81. */
  82. public String getName( ) {
  83. return name;
  84. }
  85. } // end MonitoredAttributeBase