/** {@inheritDoc} */ MBeanAttributeInfo getInfo() throws IntrospectionException { return new MBeanAttributeInfo(getName(), getDescription(), getter, setter); }
String name = ManagementUtil.filterString(obj, writeAttribute.defaultValue()); if (name.equals("")) { name = capitalize(pd.getName()); return new DefaultManagedAttribute(obj, reader, writer, name, description);
/** * Creates {@link AbstractManagedAttribute}'s for the object and its {@link PropertyDescriptor}'s. * * @param pds * the PropertyDescriptor that should be created AbstractManagedAttributes for * @param obj * the object that the properties can be set and retrieved from * @return a map mapping from the name of the attribute to the AbstractManagedAttribute */ static Map<String, AbstractManagedAttribute> fromPropertyDescriptors(PropertyDescriptor[] pds, Object obj) { Map<String, AbstractManagedAttribute> result = new HashMap<String, AbstractManagedAttribute>(); for (PropertyDescriptor pd : pds) { AbstractManagedAttribute a = fromPropertyDescriptor(pd, obj); if (a != null) { result.put(a.getName(), a); } } return result; } }
/** {@inheritDoc} */ Object getValue() throws ReflectionException { if (getter == null) { throw new IllegalStateException("Attribute is write-only"); } try { return getter.invoke(obj, (Object[]) null); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof RuntimeException) { throw (RuntimeException) t; } else if (t instanceof Error) { throw (Error) t; } else { throw new ReflectionException((Exception) t, "Exception thrown in the getter for the attribute " + getName()); } } catch (IllegalAccessException e) { throw new ReflectionException(e, "Exception thrown trying to" + " invoke the getter for the attribute " + getName()); } }
/** {@inheritDoc} */ public synchronized ManagedGroup add(Object o) { if (o == null) { throw new NullPointerException("o is null"); } mainLock.lock(); try { beforeMutableOperationInner(); if (isRegistered()) { throw new IllegalStateException("Cannot add objects when this group is registered"); } BeanInfo bi; try { bi = Introspector.getBeanInfo(o.getClass()); } catch (java.beans.IntrospectionException e) { // /CLOVER:OFF throw new IllegalArgumentException(e); // cannot happen // /CLOVER:ON } attributes.putAll(DefaultManagedAttribute.fromPropertyDescriptors(bi.getPropertyDescriptors(), o)); ops.putAll(DefaultManagedOperation.fromMethodDescriptors(bi.getMethodDescriptors(), o)); os.add(o); return this; } finally { mainLock.unlock(); } }