1 24 package org.objectweb.jalisto.se.jmx; 25 26 import javax.management.*; 27 import java.util.Iterator ; 28 29 public abstract class JalistoAbstractDynamicMBean implements DynamicMBean { 30 31 public Object getAttribute(String attributeName) 32 throws AttributeNotFoundException, MBeanException, ReflectionException { 33 34 if (attributeName == null) { 35 throw new RuntimeOperationsException( 36 new IllegalArgumentException ("Attribute name cannot be null"), 37 "Cannot invoke a getter of " + this.getClass().getName() + 38 " with null attribute name"); 39 } 40 41 return internalGetAttribute(attributeName); 42 } 43 44 public AttributeList getAttributes(String [] attributeNames) { 45 if (attributeNames == null) { 47 throw new RuntimeOperationsException( 48 new IllegalArgumentException ("attributeNames[] cannot be null"), 49 "Cannot invoke a getter of " + this.getClass().getName()); 50 } 51 AttributeList resultList = new AttributeList(); 52 53 if (attributeNames.length == 0) 55 return resultList; 56 57 for (int i = 0; i < attributeNames.length; i++) { 59 Object value = null; 60 try { 61 value = getAttribute(attributeNames[i]); 62 } catch (AttributeNotFoundException e) { 63 e.printStackTrace(); 64 } catch (MBeanException e) { 65 e.printStackTrace(); 66 } catch (ReflectionException e) { 67 e.printStackTrace(); 68 } 69 resultList.add(new Attribute(attributeNames[i], value)); 70 } 71 return (resultList); 72 } 73 74 public Object invoke(String operationName, Object [] params, String [] signature) 75 throws MBeanException, ReflectionException { 76 77 if (operationName == null) { 78 throw new RuntimeOperationsException( 79 new IllegalArgumentException ("Operation name cannot be null"), 80 "Cannot invoke a null operation in " + this.getClass().getName()); 81 } 82 83 return internalInvoke(operationName, params, signature); 84 } 85 86 public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { 87 if (attribute == null) { 88 throw new RuntimeOperationsException( 89 new IllegalArgumentException ("Attribute cannot be null"), 90 "Cannot invoke a setter of " + this.getClass().getName() + 91 " with null attribute"); 92 } 93 94 String name = attribute.getName(); 95 Object value = attribute.getValue(); 96 97 if (name == null) { 98 throw new RuntimeOperationsException( 99 new IllegalArgumentException ( 100 "Attribute name cannot be null"), 101 "Cannot invoke the setter of " + this.getClass().getName() + 102 " with null attribute name"); 103 } 104 105 if (!internalSetAttribute(name, value)) { 106 throw(new AttributeNotFoundException("Attribute " + name + 107 " not found in " + this.getClass().getName())); 108 } 109 } 110 111 public AttributeList setAttributes(AttributeList attributeList) { 112 if (attributeList == null) { 113 throw new RuntimeOperationsException( 114 new IllegalArgumentException ("AttributeList attributes cannot be null"), 115 "Cannot invoke a setter of " + this.getClass().getName()); 116 } 117 118 AttributeList resultList = new AttributeList(); 119 120 if (attributeList.isEmpty()) { 121 return resultList; 122 } 123 124 for (Iterator i = attributeList.iterator(); i.hasNext();) { 125 Attribute attr = (Attribute) i.next(); 126 try { 127 setAttribute(attr); 128 String name = attr.getName(); 129 Object value = getAttribute(name); 130 resultList.add(new Attribute(name, value)); 131 } catch (Exception e) { 132 e.printStackTrace(); 133 } 134 } 135 return resultList; 136 } 137 138 abstract public MBeanInfo getMBeanInfo(); 139 140 abstract protected Object internalGetAttribute(String attributeName) 141 throws AttributeNotFoundException, MBeanException, ReflectionException; 142 143 abstract protected boolean internalSetAttribute(String name, Object value) 144 throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException; 145 146 abstract protected Object internalInvoke(String operationName, Object [] params, String [] signature) 147 throws MBeanException, ReflectionException; 148 } 149 | Popular Tags |