2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind-jmx release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:34:17 PST
file stats: LOC: 250   Methods: 19
NCLOC: 152   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractDynamicMBean.java 80% 89.5% 78.9% 85.1%
coverage coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.hivemind.management.mbeans;
 16   
 17    import javax.management.Attribute;
 18    import javax.management.AttributeList;
 19    import javax.management.AttributeNotFoundException;
 20    import javax.management.DynamicMBean;
 21    import javax.management.InvalidAttributeValueException;
 22    import javax.management.MBeanAttributeInfo;
 23    import javax.management.MBeanConstructorInfo;
 24    import javax.management.MBeanException;
 25    import javax.management.MBeanInfo;
 26    import javax.management.MBeanNotificationInfo;
 27    import javax.management.MBeanOperationInfo;
 28    import javax.management.MBeanRegistration;
 29    import javax.management.MBeanServer;
 30    import javax.management.ObjectName;
 31    import javax.management.ReflectionException;
 32   
 33    /**
 34    * Ancestor for MBeans. Eases implementation of the {@link javax.management.DynamicMBean} interface.
 35    * Provides empty method implementations and implements {@link #getAttributes(String[])} and
 36    * {@link #setAttributes(AttributeList)}
 37    *
 38    * @author Achim Huegen
 39    */
 40    public abstract class AbstractDynamicMBean implements MBeanRegistration, DynamicMBean
 41    {
 42   
 43    private MBeanInfo _mBeanInfo;
 44   
 45    private MBeanServer _mbeanServer;
 46   
 47    /**
 48    * @see javax.management.DynamicMBean#getMBeanInfo()
 49    */
 50  7 public MBeanInfo getMBeanInfo()
 51    {
 52  7 if (_mBeanInfo == null)
 53  3 setMBeanInfo(createMBeanInfo());
 54  7 return _mBeanInfo;
 55    }
 56   
 57    /**
 58    * Sets the MBeanInfo
 59    *
 60    * @param info
 61    * the info
 62    */
 63  3 protected void setMBeanInfo(MBeanInfo info)
 64    {
 65  3 _mBeanInfo = info;
 66    }
 67   
 68    /**
 69    * Delegates the MBeanInfo retrieval to various methods
 70    *
 71    * @return the MBeanInfo of the MBean
 72    */
 73  3 private MBeanInfo createMBeanInfo()
 74    {
 75  3 MBeanAttributeInfo attrs[] = createMBeanAttributeInfo();
 76  3 MBeanConstructorInfo ctors[] = createMBeanConstructorInfo();
 77  3 MBeanOperationInfo opers[] = createMBeanOperationInfo();
 78  3 MBeanNotificationInfo notifs[] = createMBeanNotificationInfo();
 79  3 String className = getMBeanClassName();
 80  3 String description = getMBeanDescription();
 81  3 return new MBeanInfo(className, description, attrs, ctors, opers, notifs);
 82    }
 83   
 84    /**
 85    * Provides the info which attributes the MBean has. Should be overwritten by the descendants
 86    */
 87  0 protected MBeanAttributeInfo[] createMBeanAttributeInfo()
 88    {
 89  0 return null;
 90    }
 91   
 92    /**
 93    * Provides the info which constructors MBean has. Should be overwritten by the descendants
 94    */
 95  2 protected MBeanConstructorInfo[] createMBeanConstructorInfo()
 96    {
 97  2 return null;
 98    }
 99   
 100    /**
 101    * Provides the info which operations can be called on the MBean. Should be overwritten by the
 102    * descendants
 103    */
 104  1 protected MBeanOperationInfo[] createMBeanOperationInfo()
 105    {
 106  1 return null;
 107    }
 108   
 109    /**
 110    * Provides the info which notifications the MBean supports. Should be overwritten by the
 111    * descendants
 112    */
 113  2 protected MBeanNotificationInfo[] createMBeanNotificationInfo()
 114    {
 115  2 return null;
 116    }
 117   
 118  3 protected String getMBeanClassName()
 119    {
 120  3 return getClass().getName();
 121    }
 122   
 123    /**
 124    * @return Textual description of the MBean
 125    */
 126  3 protected String getMBeanDescription()
 127    {
 128  3 return null;
 129    }
 130   
 131    /**
 132    * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
 133    */
 134  0 public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
 135    ReflectionException
 136    {
 137  0 return null;
 138    }
 139   
 140    /**
 141    * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 142    */
 143  0 public void setAttribute(Attribute attribute) throws AttributeNotFoundException,
 144    InvalidAttributeValueException, MBeanException, ReflectionException
 145    {
 146    }
 147   
 148    /**
 149    * Gets a list of attributes using {@link #getAttribute(String)}
 150    *
 151    * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
 152    */
 153  1 public AttributeList getAttributes(String[] attributes)
 154    {
 155  1 AttributeList list = new AttributeList();
 156  1 if (attributes != null)
 157    {
 158  1 for (int i = 0; i < attributes.length; i++)
 159    {
 160  2 String attribute = attributes[i];
 161  2 try
 162    {
 163  2 Object result = getAttribute(attribute);
 164  2 list.add(new Attribute(attribute, result));
 165    }
 166    catch (AttributeNotFoundException ignored)
 167    {
 168    }
 169    catch (MBeanException ignored)
 170    {
 171    }
 172    catch (ReflectionException ignored)
 173    {
 174    }
 175    }
 176   
 177    }
 178  1 return list;
 179    }
 180   
 181    /**
 182    * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
 183    */
 184  1 public AttributeList setAttributes(AttributeList attributes)
 185    {
 186  1 AttributeList list = new AttributeList();
 187   
 188  1 if (attributes != null)
 189    {
 190  1 for (int i = 0; i < attributes.size(); ++i)
 191    {
 192  2 Attribute attribute = (Attribute) attributes.get(i);
 193  2 try
 194    {
 195  2 setAttribute(attribute);
 196  0 list.add(attribute);
 197    }
 198    catch (AttributeNotFoundException ignored)
 199    {
 200    }
 201    catch (InvalidAttributeValueException ignored)
 202    {
 203    }
 204    catch (MBeanException ignored)
 205    {
 206    }
 207    catch (ReflectionException ignored)
 208    {
 209    }
 210    }
 211    }
 212   
 213  1 return list;
 214    }
 215   
 216    /**
 217    * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[],
 218    * java.lang.String[])
 219    */
 220  0 public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException,
 221    ReflectionException
 222    {
 223  0 return null;
 224    }
 225   
 226  7 public ObjectName preRegister(MBeanServer mbeanserver, ObjectName objectname)
 227    {
 228  7 _mbeanServer = mbeanserver;
 229  7 return objectname;
 230    }
 231   
 232  1 public void postRegister(Boolean registrationDone)
 233    {
 234    }
 235   
 236  1 public void preDeregister() throws Exception
 237    {
 238    }
 239   
 240  1 public void postDeregister()
 241    {
 242    }
 243   
 244  9 protected MBeanServer getMBeanServer()
 245    {
 246  9 return _mbeanServer;
 247    }
 248   
 249   
 250    }