Clover coverage report - Code Coverage for hivemind-jmx release 1.1-beta-2
Coverage timestamp: Tue Jun 28 2005 10:29:45 EDT
file stats: LOC: 221   Methods: 14
NCLOC: 130   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractDynamicMBean.java 80% 88.6% 71.4% 83.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.ReflectionException;
 29   
 30    /**
 31    * Ancestor for MBeans. Eases implementation of the {@link javax.management.DynamicMBean} interface.
 32    * Provides empty method implementations and implements {@link #getAttributes(String[])} and
 33    * {@link #setAttributes(AttributeList)}
 34    *
 35    * @author Achim Huegen
 36    */
 37    public abstract class AbstractDynamicMBean implements DynamicMBean
 38    {
 39   
 40    private MBeanInfo _mBeanInfo;
 41   
 42    /**
 43    * @see javax.management.DynamicMBean#getMBeanInfo()
 44    */
 45  4 public MBeanInfo getMBeanInfo()
 46    {
 47  4 if (_mBeanInfo == null)
 48  2 setMBeanInfo(createMBeanInfo());
 49  4 return _mBeanInfo;
 50    }
 51   
 52    /**
 53    * Sets the MBeanInfo
 54    *
 55    * @param info
 56    * the info
 57    */
 58  2 protected void setMBeanInfo(MBeanInfo info)
 59    {
 60  2 _mBeanInfo = info;
 61    }
 62   
 63    /**
 64    * Delegates the MBeanInfo retrieval to various methods
 65    *
 66    * @return the MBeanInfo of the MBean
 67    */
 68  2 private MBeanInfo createMBeanInfo()
 69    {
 70  2 MBeanAttributeInfo attrs[] = createMBeanAttributeInfo();
 71  2 MBeanConstructorInfo ctors[] = createMBeanConstructorInfo();
 72  2 MBeanOperationInfo opers[] = createMBeanOperationInfo();
 73  2 MBeanNotificationInfo notifs[] = createMBeanNotificationInfo();
 74  2 String className = getMBeanClassName();
 75  2 String description = getMBeanDescription();
 76  2 return new MBeanInfo(className, description, attrs, ctors, opers, notifs);
 77    }
 78   
 79    /**
 80    * Provides the info which attributes the MBean has. Should be overwritten by the descendants
 81    */
 82  0 protected MBeanAttributeInfo[] createMBeanAttributeInfo()
 83    {
 84  0 return null;
 85    }
 86   
 87    /**
 88    * Provides the info which constructors MBean has. Should be overwritten by the descendants
 89    */
 90  1 protected MBeanConstructorInfo[] createMBeanConstructorInfo()
 91    {
 92  1 return null;
 93    }
 94   
 95    /**
 96    * Provides the info which operations can be called on the MBean. Should be overwritten by the
 97    * descendants
 98    */
 99  1 protected MBeanOperationInfo[] createMBeanOperationInfo()
 100    {
 101  1 return null;
 102    }
 103   
 104    /**
 105    * Provides the info which notifications the MBean supports. Should be overwritten by the
 106    * descendants
 107    */
 108  1 protected MBeanNotificationInfo[] createMBeanNotificationInfo()
 109    {
 110  1 return null;
 111    }
 112   
 113  2 protected String getMBeanClassName()
 114    {
 115  2 return getClass().getName();
 116    }
 117   
 118    /**
 119    * @return Textual description of the MBean
 120    */
 121  2 protected String getMBeanDescription()
 122    {
 123  2 return null;
 124    }
 125   
 126    /**
 127    * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
 128    */
 129  0 public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
 130    ReflectionException
 131    {
 132  0 return null;
 133    }
 134   
 135    /**
 136    * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
 137    */
 138  0 public void setAttribute(Attribute attribute) throws AttributeNotFoundException,
 139    InvalidAttributeValueException, MBeanException, ReflectionException
 140    {
 141    }
 142   
 143    /**
 144    * Gets a list of attributes using {@link #getAttribute(String)}
 145    *
 146    * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
 147    */
 148  1 public AttributeList getAttributes(String[] attributes)
 149    {
 150  1 AttributeList list = new AttributeList();
 151  1 if (attributes != null)
 152    {
 153  1 for (int i = 0; i < attributes.length; i++)
 154    {
 155  2 String attribute = attributes[i];
 156  2 try
 157    {
 158  2 Object result = getAttribute(attribute);
 159  2 list.add(new Attribute(attribute, result));
 160    }
 161    catch (AttributeNotFoundException ignored)
 162    {
 163    }
 164    catch (MBeanException ignored)
 165    {
 166    }
 167    catch (ReflectionException ignored)
 168    {
 169    }
 170    }
 171   
 172    }
 173  1 return list;
 174    }
 175   
 176    /**
 177    * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
 178    */
 179  1 public AttributeList setAttributes(AttributeList attributes)
 180    {
 181  1 AttributeList list = new AttributeList();
 182   
 183  1 if (attributes != null)
 184    {
 185  1 for (int i = 0; i < attributes.size(); ++i)
 186    {
 187  2 Attribute attribute = (Attribute) attributes.get(i);
 188  2 try
 189    {
 190  2 setAttribute(attribute);
 191  0 list.add(attribute);
 192    }
 193    catch (AttributeNotFoundException ignored)
 194    {
 195    }
 196    catch (InvalidAttributeValueException ignored)
 197    {
 198    }
 199    catch (MBeanException ignored)
 200    {
 201    }
 202    catch (ReflectionException ignored)
 203    {
 204    }
 205    }
 206    }
 207   
 208  1 return list;
 209    }
 210   
 211    /**
 212    * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[],
 213    * java.lang.String[])
 214    */
 215  0 public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException,
 216    ReflectionException
 217    {
 218  0 return null;
 219    }
 220   
 221    }