1 /*
   2  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.corba.se.spi.monitoring;
  26 
  27 import java.util.*;
  28 
  29 /**
  30  * <p>
  31  *
  32  * @author Hemanth Puttaswamy
  33  * </p>
  34  * <p>
  35  *  A Convenient class provided to help users extend and implement only
  36  *  getValue(), if there is no need to clear the state and the attribute is not
  37  *  writable.
  38  *
  39  * </p>
  40  */
  41 public abstract class MonitoredAttributeBase implements MonitoredAttribute {
  42     String name;
  43     MonitoredAttributeInfo attributeInfo;
  44     /**
  45      * Constructor.
  46      */
  47     public MonitoredAttributeBase( String name, MonitoredAttributeInfo info ) {
  48         this.name = name;
  49         this.attributeInfo = info;
  50     }
  51 
  52 
  53     /**
  54      * A Package Private Constructor for internal use only.
  55      */
  56     MonitoredAttributeBase( String name ) {
  57         this.name = name;
  58     }
  59 
  60 
  61     /**
  62      * A Package Private convenience method for setting MonitoredAttributeInfo
  63      * for this Monitored Attribute.
  64      */
  65     void setMonitoredAttributeInfo( MonitoredAttributeInfo info ) {
  66         this.attributeInfo = info;
  67     }
  68 
  69     /**
  70      *  If the concrete class decides not to provide the implementation of this
  71      *  method, then it's OK. Some of the  examples where we may decide to not
  72      *  provide the implementation is the connection state. Irrespective of
  73      *  the call to clearState, the connection state will be showing the
  74      *  currect state of the connection.
  75      *  NOTE: This method is only used to clear the Monitored Attribute state,
  76      *  not the real state of the system itself.
  77      */
  78     public void clearState( ) {
  79     }
  80 
  81     /**
  82      *  This method should be implemented by the concrete class.
  83      */
  84     public abstract Object getValue( );
  85 
  86     /**
  87      *  This method should be implemented by the concrete class only if the
  88      *  attribute is writable. If the attribute is not writable and if this
  89      *  method called, it will result in an IllegalStateException.
  90      */
  91     public void setValue( Object value ) {
  92         if( !attributeInfo.isWritable() ) {
  93             throw new IllegalStateException(
  94                 "The Attribute " + name + " is not Writable..." );
  95         }
  96         throw new IllegalStateException(
  97             "The method implementation is not provided for the attribute " +
  98             name );
  99     }
 100 
 101 
 102     /**
 103      *  Gets the MonitoredAttributeInfo for the attribute.
 104      */
 105     public MonitoredAttributeInfo getAttributeInfo( ) {
 106         return attributeInfo;
 107     }
 108 
 109     /**
 110      * Gets the name of the attribute.
 111      */
 112     public String getName( ) {
 113         return name;
 114     }
 115 } // end MonitoredAttributeBase