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  * @author Hemanth Puttaswamy
  31  *
  32  *  A Convenient class provided to help users extend and implement only
  33  *  getValue(), if there is no need to clear the state and the attribute is not
  34  *  writable.
  35  */
  36 public abstract class MonitoredAttributeBase implements MonitoredAttribute {
  37     String name;
  38     MonitoredAttributeInfo attributeInfo;
  39     /**
  40      * Constructor.
  41      */
  42     public MonitoredAttributeBase( String name, MonitoredAttributeInfo info ) {
  43         this.name = name;
  44         this.attributeInfo = info;
  45     }
  46 
  47 
  48     /**
  49      * A Package Private Constructor for internal use only.
  50      */
  51     MonitoredAttributeBase( String name ) {
  52         this.name = name;
  53     }
  54 
  55 
  56     /**
  57      * A Package Private convenience method for setting MonitoredAttributeInfo
  58      * for this Monitored Attribute.
  59      */
  60     void setMonitoredAttributeInfo( MonitoredAttributeInfo info ) {
  61         this.attributeInfo = info;
  62     }
  63 
  64     /**
  65      *  If the concrete class decides not to provide the implementation of this
  66      *  method, then it's OK. Some of the  examples where we may decide to not
  67      *  provide the implementation is the connection state. Irrespective of
  68      *  the call to clearState, the connection state will be showing the
  69      *  currect state of the connection.
  70      *  NOTE: This method is only used to clear the Monitored Attribute state,
  71      *  not the real state of the system itself.
  72      */
  73     public void clearState( ) {
  74     }
  75 
  76     /**
  77      *  This method should be implemented by the concrete class.
  78      */
  79     public abstract Object getValue( );
  80 
  81     /**
  82      *  This method should be implemented by the concrete class only if the
  83      *  attribute is writable. If the attribute is not writable and if this
  84      *  method called, it will result in an IllegalStateException.
  85      */
  86     public void setValue( Object value ) {
  87         if( !attributeInfo.isWritable() ) {
  88             throw new IllegalStateException(
  89                 "The Attribute " + name + " is not Writable..." );
  90         }
  91         throw new IllegalStateException(
  92             "The method implementation is not provided for the attribute " +
  93             name );
  94     }
  95 
  96 
  97     /**
  98      *  Gets the MonitoredAttributeInfo for the attribute.
  99      */
 100     public MonitoredAttributeInfo getAttributeInfo( ) {
 101         return attributeInfo;
 102     }
 103 
 104     /**
 105      * Gets the name of the attribute.
 106      */
 107     public String getName( ) {
 108         return name;
 109     }
 110 } // end MonitoredAttributeBase